ia64/xen-unstable

view tools/blktap/drivers/tapdisk.h @ 15783:c93e2a822d6f

[xen, xencomm] xencomm multiple page support
Current implementation doesn't allow struct xencomm_desc::address
array to be more than single page. On IA64 it causes 64GB+ domain
creation failure. This patch generalizes xencomm to allow multipage

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Tue Aug 28 15:32:27 2007 +0100 (2007-08-28)
parents e9bd3267ff23
children b6cc74f275fd
line source
1 /* tapdisk.h
2 *
3 * Generic disk interface for blktap-based image adapters.
4 *
5 * (c) 2006 Andrew Warfield and Julian Chesterfield
6 *
7 * Some notes on the tap_disk interface:
8 *
9 * tap_disk aims to provide a generic interface to easily implement new
10 * types of image accessors. The structure-of-function-calls is similar
11 * to disk interfaces used in qemu/denali/etc, with the significant
12 * difference being the expectation of asynchronous rather than synchronous
13 * I/O. The asynchronous interface is intended to allow lots of requests to
14 * be pipelined through a disk, without the disk requiring any of its own
15 * threads of control. As such, a batch of requests is delivered to the disk
16 * using:
17 *
18 * td_queue_[read,write]()
19 *
20 * and passing in a completion callback, which the disk is responsible for
21 * tracking. The end of a back is marked with a call to:
22 *
23 * td_submit()
24 *
25 * The disk implementation must provide a file handle, which is used to
26 * indicate that it needs to do work. tapdisk will add this file handle
27 * (returned from td_get_fd()) to it's poll set, and will call into the disk
28 * using td_do_callbacks() whenever there is data pending.
29 *
30 * Two disk implementations demonstrate how this interface may be used to
31 * implement disks with both asynchronous and synchronous calls. block-aio.c
32 * maps this interface down onto the linux libaio calls, while block-sync uses
33 * normal posix read/write.
34 *
35 * A few things to realize about the sync case, which doesn't need to defer
36 * io completions:
37 *
38 * - td_queue_[read,write]() call read/write directly, and then call the
39 * callback immediately. The MUST then return a value greater than 0
40 * in order to tell tapdisk that requests have finished early, and to
41 * force responses to be kicked to the clents.
42 *
43 * - The fd used for poll is an otherwise unused pipe, which allows poll to
44 * be safely called without ever returning anything.
45 *
46 * NOTE: tapdisk uses the number of sectors submitted per request as a
47 * ref count. Plugins must use the callback function to communicate the
48 * completion--or error--of every sector submitted to them.
49 *
50 * td_get_parent_id returns:
51 * 0 if parent id successfully retrieved
52 * TD_NO_PARENT if no parent exists
53 * -errno on error
54 */
56 #ifndef TAPDISK_H_
57 #define TAPDISK_H_
59 #include <stdint.h>
60 #include <syslog.h>
61 #include "blktaplib.h"
63 /*If enabled, log all debug messages to syslog*/
64 #if 1
65 #define DPRINTF(_f, _a...) syslog( LOG_DEBUG, _f , ## _a )
66 #else
67 #define DPRINTF(_f, _a...) ((void)0)
68 #endif
70 /* Things disks need to know about, these should probably be in a higher-level
71 * header. */
72 #define MAX_SEGMENTS_PER_REQ 11
73 #define SECTOR_SHIFT 9
74 #define DEFAULT_SECTOR_SIZE 512
76 #define MAX_IOFD 2
78 #define BLK_NOT_ALLOCATED 99
79 #define TD_NO_PARENT 1
81 typedef uint32_t td_flag_t;
83 #define TD_RDONLY 1
85 struct td_state;
86 struct tap_disk;
88 struct disk_id {
89 char *name;
90 int drivertype;
91 };
93 struct disk_driver {
94 int early;
95 char *name;
96 void *private;
97 td_flag_t flags;
98 int io_fd[MAX_IOFD];
99 struct tap_disk *drv;
100 struct td_state *td_state;
101 struct disk_driver *next;
102 };
104 /* This structure represents the state of an active virtual disk. */
105 struct td_state {
106 struct disk_driver *disks;
107 void *blkif;
108 void *image;
109 void *ring_info;
110 void *fd_entry;
111 unsigned long sector_size;
112 unsigned long long size;
113 unsigned int info;
114 };
116 /* Prototype of the callback to activate as requests complete. */
117 typedef int (*td_callback_t)(struct disk_driver *dd, int res, uint64_t sector,
118 int nb_sectors, int id, void *private);
120 /* Structure describing the interface to a virtual disk implementation. */
121 /* See note at the top of this file describing this interface. */
122 struct tap_disk {
123 const char *disk_type;
124 int private_data_size;
125 int (*td_open) (struct disk_driver *dd,
126 const char *name, td_flag_t flags);
127 int (*td_queue_read) (struct disk_driver *dd, uint64_t sector,
128 int nb_sectors, char *buf, td_callback_t cb,
129 int id, void *prv);
130 int (*td_queue_write) (struct disk_driver *dd, uint64_t sector,
131 int nb_sectors, char *buf, td_callback_t cb,
132 int id, void *prv);
133 int (*td_submit) (struct disk_driver *dd);
134 int (*td_close) (struct disk_driver *dd);
135 int (*td_do_callbacks) (struct disk_driver *dd, int sid);
136 int (*td_get_parent_id) (struct disk_driver *dd, struct disk_id *id);
137 int (*td_validate_parent)(struct disk_driver *dd,
138 struct disk_driver *p, td_flag_t flags);
139 };
141 typedef struct disk_info {
142 int idnum;
143 char name[50]; /* e.g. "RAMDISK" */
144 char handle[10]; /* xend handle, e.g. 'ram' */
145 int single_handler; /* is there a single controller for all */
146 /* instances of disk type? */
147 #ifdef TAPDISK
148 struct tap_disk *drv;
149 #endif
150 } disk_info_t;
152 void debug_fe_ring(struct td_state *s);
154 extern struct tap_disk tapdisk_aio;
155 extern struct tap_disk tapdisk_sync;
156 extern struct tap_disk tapdisk_vmdk;
157 extern struct tap_disk tapdisk_ram;
158 extern struct tap_disk tapdisk_qcow;
160 #define MAX_DISK_TYPES 20
162 #define DISK_TYPE_AIO 0
163 #define DISK_TYPE_SYNC 1
164 #define DISK_TYPE_VMDK 2
165 #define DISK_TYPE_RAM 3
166 #define DISK_TYPE_QCOW 4
169 /*Define Individual Disk Parameters here */
170 static disk_info_t aio_disk = {
171 DISK_TYPE_AIO,
172 "raw image (aio)",
173 "aio",
174 0,
175 #ifdef TAPDISK
176 &tapdisk_aio,
177 #endif
178 };
180 static disk_info_t sync_disk = {
181 DISK_TYPE_SYNC,
182 "raw image (sync)",
183 "sync",
184 0,
185 #ifdef TAPDISK
186 &tapdisk_sync,
187 #endif
188 };
190 static disk_info_t vmdk_disk = {
191 DISK_TYPE_VMDK,
192 "vmware image (vmdk)",
193 "vmdk",
194 1,
195 #ifdef TAPDISK
196 &tapdisk_vmdk,
197 #endif
198 };
200 static disk_info_t ram_disk = {
201 DISK_TYPE_RAM,
202 "ramdisk image (ram)",
203 "ram",
204 1,
205 #ifdef TAPDISK
206 &tapdisk_ram,
207 #endif
208 };
210 static disk_info_t qcow_disk = {
211 DISK_TYPE_QCOW,
212 "qcow disk (qcow)",
213 "qcow",
214 0,
215 #ifdef TAPDISK
216 &tapdisk_qcow,
217 #endif
218 };
220 /*Main disk info array */
221 static disk_info_t *dtypes[] = {
222 &aio_disk,
223 &sync_disk,
224 &vmdk_disk,
225 &ram_disk,
226 &qcow_disk,
227 };
229 typedef struct driver_list_entry {
230 struct blkif *blkif;
231 struct driver_list_entry **pprev, *next;
232 } driver_list_entry_t;
234 typedef struct fd_list_entry {
235 int cookie;
236 int tap_fd;
237 struct td_state *s;
238 struct fd_list_entry **pprev, *next;
239 } fd_list_entry_t;
241 int qcow_create(const char *filename, uint64_t total_size,
242 const char *backing_file, int flags);
243 #endif /*TAPDISK_H_*/