ia64/xen-unstable

view tools/blktap2/include/blktaplib.h @ 19647:1c627434605e

blktap2: a completely rewritten blktap implementation

Benefits to blktap2 over the old version of blktap:

* Isolation from xenstore - Blktap devices are now created directly on
the linux dom0 command line, rather than being spawned in response
to XenStore events. This is handy for debugging, makes blktap
generally easier to work with, and is a step toward a generic
user-level block device implementation that is not Xen-specific.

* Improved tapdisk infrastructure: simpler request forwarding, new
request scheduler, request merging, more efficient use of AIO.

* Improved tapdisk error handling and memory management. No
allocations on the block data path, IO retry logic to protect
guests
transient block device failures. This has been tested and is known
to work on weird environments such as NFS soft mounts.

* Pause and snapshot of live virtual disks (see xmsnap script).

* VHD support. The VHD code in this release has been rigorously
tested, and represents a very mature implementation of the VHD
image
format.

* No more duplication of mechanism with blkback. The blktap kernel
module has changed dramatically from the original blktap. Blkback
is now always used to talk to Xen guests, blktap just presents a
Linux gendisk that blkback can export. This is done while
preserving the zero-copy data path from domU to physical device.

These patches deprecate the old blktap code, which can hopefully be
removed from the tree completely at some point in the future.

Signed-off-by: Jake Wires <jake.wires@citrix.com>
Signed-off-by: Dutch Meyer <dmeyer@cs.ubc.ca>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 11:52:31 2009 +0100 (2009-05-26)
parents
children
line source
1 /* blktaplib.h
2 *
3 * Blktap library userspace code.
4 *
5 * Copyright (c) 2007, XenSource Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of XenSource Inc. nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
32 #ifndef __BLKTAPLIB_H__
33 #define __BLKTAPLIB_H__
35 #include <syslog.h>
36 #include <xenctrl.h>
37 #include <xen/io/blkif.h>
39 #if 1
40 #define DPRINTF(_f, _a...) syslog(LOG_INFO, _f, ##_a)
41 #else
42 #define DPRINTF(_f, _a...) ((void)0)
43 #endif
45 #define EPRINTF(_f, _a...) syslog(LOG_ERR, "tap-err:%s: " _f, __func__, ##_a)
47 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, XC_PAGE_SIZE)
49 /* size of the extra VMA area to map in attached pages. */
50 #define BLKTAP_VMA_PAGES BLK_RING_SIZE
52 /* blktap IOCTLs: These must correspond with the blktap driver ioctls */
53 #define BLKTAP_IOCTL_KICK_FE 1
54 #define BLKTAP_IOCTL_KICK_BE 2
55 #define BLKTAP_IOCTL_SETMODE 3
56 #define BLKTAP_IOCTL_SENDPID 4
57 #define BLKTAP_IOCTL_NEWINTF 5
58 #define BLKTAP_IOCTL_MINOR 6
59 #define BLKTAP_IOCTL_MAJOR 7
60 #define BLKTAP_QUERY_ALLOC_REQS 8
61 #define BLKTAP_IOCTL_FREEINTF 9
62 #define BLKTAP_IOCTL_PRINT_IDXS 100
63 #define BLKTAP_IOCTL_BACKDEV_SETUP 200
65 #define PRIO_SPECIAL_IO -9999
67 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
68 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
69 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
70 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
72 #define BLKTAP_MODE_INTERPOSE \
73 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
75 static inline int BLKTAP_MODE_VALID(unsigned long arg)
76 {
77 return (
78 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
79 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
80 ( arg == BLKTAP_MODE_INTERPOSE ) );
81 }
83 #define MAX_REQUESTS BLK_RING_SIZE
85 #define BLKTAP_IOCTL_KICK 1
86 #define MAX_PENDING_REQS BLK_RING_SIZE
87 #define BLKTAP_DEV_DIR "/dev/xen"
88 #define BLKTAP_DEV_NAME "blktap"
89 #define BACKDEV_NAME "backdev"
90 #define BLKTAP_DEV_MINOR 0
91 #define BLKTAP_CTRL_DIR "/var/run/tap"
93 extern int blktap_major;
95 #define BLKTAP_RING_PAGES 1 /* Front */
96 #define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
98 struct blkif;
99 struct blkif_info;
101 typedef struct {
102 blkif_request_t req;
103 int submitting;
104 int secs_pending;
105 int16_t status;
106 int num_retries;
107 struct timeval last_try;
108 } pending_req_t;
110 typedef struct blkif {
111 domid_t domid;
112 long int handle;
114 long int pdev;
115 long int readonly;
117 enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
119 struct blkif_ops *ops;
120 struct blkif *hash_next;
122 void *prv; /* device-specific data */
123 struct blkif_info *info; /*Image parameter passing */
124 pending_req_t pending_list[MAX_REQUESTS];
125 int devnum;
126 int fds[2];
127 int be_id;
128 char *backend_path;
129 int major;
130 int minor;
131 pid_t tappid;
132 int drivertype;
133 uint16_t cookie;
134 int err;
135 } blkif_t;
137 typedef struct blkif_info {
138 char *params;
139 int readonly;
140 int storage;
141 } blkif_info_t;
143 typedef struct tapdev_info {
144 int fd;
145 char *mem;
146 blkif_sring_t *sring;
147 blkif_back_ring_t fe_ring;
148 unsigned long vstart;
149 blkif_t *blkif;
150 } tapdev_info_t;
152 typedef struct domid_translate {
153 unsigned short domid;
154 unsigned short busid;
155 } domid_translate_t ;
157 typedef struct image {
158 unsigned long long size;
159 unsigned long secsize;
160 unsigned int info;
161 } image_t;
163 typedef struct msg_hdr {
164 uint16_t type;
165 uint16_t len;
166 uint16_t drivertype;
167 uint16_t cookie;
168 } msg_hdr_t;
170 typedef struct msg_params {
171 uint8_t readonly;
172 int path_off;
173 int path_len;
174 int storage;
175 } msg_params_t;
177 typedef struct msg_newdev {
178 uint8_t devnum;
179 uint16_t domid;
180 } msg_newdev_t;
182 typedef struct msg_pid {
183 pid_t pid;
184 } msg_pid_t;
186 typedef struct msg_cp {
187 int cp_uuid_off;
188 int cp_uuid_len;
189 int cp_drivertype;
190 } msg_cp_t;
192 typedef struct msg_lock {
193 int ro;
194 int enforce;
195 int uuid_off;
196 int uuid_len;
197 } msg_lock_t;
199 #define READ 0
200 #define WRITE 1
202 /*Control Messages between manager and tapdev*/
203 #define CTLMSG_PARAMS 1
204 #define CTLMSG_IMG 2
205 #define CTLMSG_IMG_FAIL 3
206 #define CTLMSG_NEWDEV 4
207 #define CTLMSG_NEWDEV_RSP 5
208 #define CTLMSG_NEWDEV_FAIL 6
209 #define CTLMSG_CLOSE 7
210 #define CTLMSG_CLOSE_RSP 8
211 #define CTLMSG_PID 9
212 #define CTLMSG_PID_RSP 10
213 #define CTLMSG_CHECKPOINT 11
214 #define CTLMSG_CHECKPOINT_RSP 12
215 #define CTLMSG_LOCK 13
216 #define CTLMSG_LOCK_RSP 14
217 #define CTLMSG_PAUSE 15
218 #define CTLMSG_PAUSE_RSP 16
219 #define CTLMSG_RESUME 17
220 #define CTLMSG_RESUME_RSP 18
222 #define TAPDISK_STORAGE_TYPE_NFS 1
223 #define TAPDISK_STORAGE_TYPE_EXT 2
224 #define TAPDISK_STORAGE_TYPE_LVM 3
225 #define TAPDISK_STORAGE_TYPE_DEFAULT TAPDISK_STORAGE_TYPE_EXT
227 /* Abitrary values, must match the underlying driver... */
228 #define MAX_TAP_DEV 256
230 /* Accessing attached data page mappings */
231 #define MMAP_PAGES \
232 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
233 #define MMAP_VADDR(_vstart,_req,_seg) \
234 ((_vstart) + \
235 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) + \
236 ((_seg) * getpagesize()))
238 /* Defines that are only used by library clients */
240 #ifndef __COMPILING_BLKTAP_LIB
242 static char *blkif_op_name[] = {
243 [BLKIF_OP_READ] = "READ",
244 [BLKIF_OP_WRITE] = "WRITE",
245 };
247 #endif /* __COMPILING_BLKTAP_LIB */
249 #endif /* __BLKTAPLIB_H__ */