debuggers.hg

view tools/blktap2/include/blktaplib.h @ 21051:0d85c05b1554

blktap: provide a variant of __RING_SIZE() that is an integer constant expression

Without this new variant, gcc 4.5 won't compile where this is being
used to specify array sizes. See also c/s 20975.

Signed-off-by: Charles Arnold <carnold@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Mar 06 13:31:03 2010 +0000 (2010-03-06)
parents 218026df8d5f
children a5032d7a87e0
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)
46 #define PERROR(_f, _a...) EPRINTF(_f ": %s", ##_a, strerror(errno))
48 #define BLK_RING_SIZE __CONST_RING_SIZE(blkif, XC_PAGE_SIZE)
50 /* size of the extra VMA area to map in attached pages. */
51 #define BLKTAP_VMA_PAGES BLK_RING_SIZE
53 /* blktap IOCTLs: These must correspond with the blktap driver ioctls */
54 #define BLKTAP_IOCTL_KICK_FE 1
55 #define BLKTAP_IOCTL_KICK_BE 2
56 #define BLKTAP_IOCTL_SETMODE 3
57 #define BLKTAP_IOCTL_SENDPID 4
58 #define BLKTAP_IOCTL_NEWINTF 5
59 #define BLKTAP_IOCTL_MINOR 6
60 #define BLKTAP_IOCTL_MAJOR 7
61 #define BLKTAP_QUERY_ALLOC_REQS 8
62 #define BLKTAP_IOCTL_FREEINTF 9
63 #define BLKTAP_IOCTL_PRINT_IDXS 100
64 #define BLKTAP_IOCTL_BACKDEV_SETUP 200
66 #define PRIO_SPECIAL_IO -9999
68 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
69 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
70 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
71 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
73 #define BLKTAP_MODE_INTERPOSE \
74 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
76 static inline int BLKTAP_MODE_VALID(unsigned long arg)
77 {
78 return (
79 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
80 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
81 ( arg == BLKTAP_MODE_INTERPOSE ) );
82 }
84 #define MAX_REQUESTS BLK_RING_SIZE
86 #define BLKTAP_IOCTL_KICK 1
87 #define MAX_PENDING_REQS BLK_RING_SIZE
88 #define BLKTAP_DEV_DIR "/dev/xen"
89 #define BLKTAP_DEV_NAME "blktap"
90 #define BACKDEV_NAME "backdev"
91 #define BLKTAP_DEV_MINOR 0
92 #define BLKTAP_CTRL_DIR "/var/run/tap"
94 extern int blktap_major;
96 #define BLKTAP_RING_PAGES 1 /* Front */
97 #define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
99 struct blkif;
100 struct blkif_info;
102 typedef struct {
103 blkif_request_t req;
104 int submitting;
105 int secs_pending;
106 int16_t status;
107 int num_retries;
108 struct timeval last_try;
109 } pending_req_t;
111 typedef struct blkif {
112 domid_t domid;
113 long int handle;
115 long int pdev;
116 long int readonly;
118 enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
120 struct blkif_ops *ops;
121 struct blkif *hash_next;
123 void *prv; /* device-specific data */
124 struct blkif_info *info; /*Image parameter passing */
125 pending_req_t pending_list[MAX_REQUESTS];
126 int devnum;
127 int fds[2];
128 int be_id;
129 char *backend_path;
130 int major;
131 int minor;
132 pid_t tappid;
133 int drivertype;
134 uint16_t cookie;
135 int err;
136 } blkif_t;
138 typedef struct blkif_info {
139 char *params;
140 int readonly;
141 int storage;
142 } blkif_info_t;
144 typedef struct tapdev_info {
145 int fd;
146 char *mem;
147 blkif_sring_t *sring;
148 blkif_back_ring_t fe_ring;
149 unsigned long vstart;
150 blkif_t *blkif;
151 } tapdev_info_t;
153 typedef struct domid_translate {
154 unsigned short domid;
155 unsigned short busid;
156 } domid_translate_t ;
158 typedef struct image {
159 unsigned long long size;
160 unsigned long secsize;
161 unsigned int info;
162 } image_t;
164 typedef struct msg_hdr {
165 uint16_t type;
166 uint16_t len;
167 uint16_t drivertype;
168 uint16_t cookie;
169 } msg_hdr_t;
171 typedef struct msg_params {
172 uint8_t readonly;
173 int path_off;
174 int path_len;
175 int storage;
176 } msg_params_t;
178 typedef struct msg_newdev {
179 uint8_t devnum;
180 uint16_t domid;
181 } msg_newdev_t;
183 typedef struct msg_pid {
184 pid_t pid;
185 } msg_pid_t;
187 typedef struct msg_cp {
188 int cp_uuid_off;
189 int cp_uuid_len;
190 int cp_drivertype;
191 } msg_cp_t;
193 typedef struct msg_lock {
194 int ro;
195 int enforce;
196 int uuid_off;
197 int uuid_len;
198 } msg_lock_t;
200 #define READ 0
201 #define WRITE 1
203 /*Control Messages between manager and tapdev*/
204 #define CTLMSG_PARAMS 1
205 #define CTLMSG_IMG 2
206 #define CTLMSG_IMG_FAIL 3
207 #define CTLMSG_NEWDEV 4
208 #define CTLMSG_NEWDEV_RSP 5
209 #define CTLMSG_NEWDEV_FAIL 6
210 #define CTLMSG_CLOSE 7
211 #define CTLMSG_CLOSE_RSP 8
212 #define CTLMSG_PID 9
213 #define CTLMSG_PID_RSP 10
214 #define CTLMSG_CHECKPOINT 11
215 #define CTLMSG_CHECKPOINT_RSP 12
216 #define CTLMSG_LOCK 13
217 #define CTLMSG_LOCK_RSP 14
218 #define CTLMSG_PAUSE 15
219 #define CTLMSG_PAUSE_RSP 16
220 #define CTLMSG_RESUME 17
221 #define CTLMSG_RESUME_RSP 18
223 #define TAPDISK_STORAGE_TYPE_NFS 1
224 #define TAPDISK_STORAGE_TYPE_EXT 2
225 #define TAPDISK_STORAGE_TYPE_LVM 3
226 #define TAPDISK_STORAGE_TYPE_DEFAULT TAPDISK_STORAGE_TYPE_EXT
228 /* Abitrary values, must match the underlying driver... */
229 #define MAX_TAP_DEV 256
231 /* Accessing attached data page mappings */
232 #define MMAP_PAGES \
233 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
234 #define MMAP_VADDR(_vstart,_req,_seg) \
235 ((_vstart) + \
236 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) + \
237 ((_seg) * getpagesize()))
239 /* Defines that are only used by library clients */
241 #ifndef __COMPILING_BLKTAP_LIB
243 static char *blkif_op_name[] = {
244 [BLKIF_OP_READ] = "READ",
245 [BLKIF_OP_WRITE] = "WRITE",
246 };
248 #endif /* __COMPILING_BLKTAP_LIB */
250 #endif /* __BLKTAPLIB_H__ */