debuggers.hg

view tools/blktap2/drivers/tapdisk-queue.h @ 20916:f2ef85551a09

blktap2: Sort out tapdisk AIO init.

Move event callbacks registration into tapdisk-queue. This should also
obsoletes the dummy pollfd pipe in the synchronous I/O case.

Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 29 08:54:22 2010 +0000 (2010-01-29)
parents 1c627434605e
children 218026df8d5f
line source
1 /*
2 * Copyright (c) 2008, XenSource Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of XenSource Inc. nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
20 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
29 #ifndef TAPDISK_QUEUE_H
30 #define TAPDISK_QUEUE_H
32 #include <libaio.h>
34 #include "io-optimize.h"
35 #include "scheduler.h"
37 struct tiocb;
38 struct tfilter;
40 typedef void (*td_queue_callback_t)(void *arg, struct tiocb *, int err);
43 struct tiocb {
44 td_queue_callback_t cb;
45 void *arg;
47 struct iocb iocb;
48 struct tiocb *next;
49 };
51 struct tlist {
52 struct tiocb *head;
53 struct tiocb *tail;
54 };
56 struct tqueue {
57 int size;
58 int sync;
60 int poll_fd;
61 event_id_t event;
62 io_context_t aio_ctx;
63 struct opioctx opioctx;
65 int queued;
66 struct iocb **iocbs;
67 struct io_event *aio_events;
69 /* number of iocbs pending in the aio layer */
70 int iocbs_pending;
72 /* number of tiocbs pending in the queue --
73 * this is likely to be larger than iocbs_pending
74 * due to request coalescing */
75 int tiocbs_pending;
77 /* iocbs may be deferred if the aio ring is full.
78 * tapdisk_queue_complete will ensure deferred
79 * iocbs are queued as slots become available. */
80 struct tlist deferred;
81 int tiocbs_deferred;
83 /* optional tapdisk filter */
84 struct tfilter *filter;
86 uint64_t deferrals;
87 };
89 /*
90 * Interface for request producer (i.e., tapdisk)
91 * NB: the following functions may cause additional tiocbs to be queued:
92 * - tapdisk_submit_tiocbs
93 * - tapdisk_cancel_tiocbs
94 * - tapdisk_complete_tiocbs
95 * The *_all_tiocbs variants will handle the first two cases;
96 * be sure to call submit after calling complete in the third case.
97 */
98 #define tapdisk_queue_count(q) ((q)->queued)
99 #define tapdisk_queue_empty(q) ((q)->queued == 0)
100 #define tapdisk_queue_full(q) \
101 (((q)->tiocbs_pending + (q)->queued) >= (q)->size)
102 int tapdisk_init_queue(struct tqueue *, int size, int sync, struct tfilter *);
103 void tapdisk_free_queue(struct tqueue *);
104 void tapdisk_debug_queue(struct tqueue *);
105 void tapdisk_queue_tiocb(struct tqueue *, struct tiocb *);
106 int tapdisk_submit_tiocbs(struct tqueue *);
107 int tapdisk_submit_all_tiocbs(struct tqueue *);
108 int tapdisk_cancel_tiocbs(struct tqueue *);
109 int tapdisk_cancel_all_tiocbs(struct tqueue *);
110 void tapdisk_prep_tiocb(struct tiocb *, int, int, char *, size_t,
111 long long, td_queue_callback_t, void *);
113 #endif