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