debuggers.hg

view tools/blktap/lib/blktaplib.h @ 16564:1b863ae2bf1e

blktap: cleanups for *BSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Dec 05 09:59:23 2007 +0000 (2007-12-05)
parents ad9a79db3839
children f07a7ba63885
line source
1 /* blktaplib.h
2 *
3 * Blktap library userspace code.
4 *
5 * (c) 2005 Andrew Warfield and Julian Chesterfield
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation; or, when distributed
10 * separately from the Linux kernel or incorporated into other
11 * software packages, subject to the following license:
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy
14 * of this source file (the "Software"), to deal in the Software without
15 * restriction, including without limitation the rights to use, copy, modify,
16 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
17 * and to permit persons to whom the Software is furnished to do so, subject to
18 * the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in
21 * all copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 * IN THE SOFTWARE.
30 */
32 #ifndef __BLKTAPLIB_H__
33 #define __BLKTAPLIB_H__
35 #include <xenctrl.h>
36 #include <sys/param.h>
37 #include <sys/user.h>
38 #include <xen/xen.h>
39 #include <xen/io/blkif.h>
40 #include <xen/io/ring.h>
41 #include <xs.h>
42 #include <sys/types.h>
43 #include <unistd.h>
45 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, XC_PAGE_SIZE)
47 /* size of the extra VMA area to map in attached pages. */
48 #define BLKTAP_VMA_PAGES BLK_RING_SIZE
50 /* blktap IOCTLs: These must correspond with the blktap driver ioctls*/
51 #define BLKTAP_IOCTL_KICK_FE 1
52 #define BLKTAP_IOCTL_KICK_BE 2
53 #define BLKTAP_IOCTL_SETMODE 3
54 #define BLKTAP_IOCTL_SENDPID 4
55 #define BLKTAP_IOCTL_NEWINTF 5
56 #define BLKTAP_IOCTL_MINOR 6
57 #define BLKTAP_IOCTL_MAJOR 7
58 #define BLKTAP_QUERY_ALLOC_REQS 8
59 #define BLKTAP_IOCTL_FREEINTF 9
60 #define BLKTAP_IOCTL_PRINT_IDXS 100
62 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
63 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
64 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
65 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
67 #define BLKTAP_MODE_INTERPOSE \
68 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
70 static inline int BLKTAP_MODE_VALID(unsigned long arg)
71 {
72 return (
73 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
74 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
75 ( arg == BLKTAP_MODE_INTERPOSE ) );
76 }
78 #define MAX_REQUESTS BLK_RING_SIZE
80 #define BLKTAP_IOCTL_KICK 1
81 #define MAX_PENDING_REQS BLK_RING_SIZE
82 #define BLKTAP_DEV_DIR "/dev/xen"
83 #define BLKTAP_DEV_NAME "blktap"
84 #define BLKTAP_DEV_MINOR 0
85 #define BLKTAP_CTRL_DIR "/var/run/tap"
87 extern int blktap_major;
89 #define BLKTAP_RING_PAGES 1 /* Front */
90 #define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
92 struct blkif;
94 typedef struct {
95 blkif_request_t req;
96 struct blkif *blkif;
97 int submitting;
98 int secs_pending;
99 int16_t status;
100 } pending_req_t;
102 struct blkif_ops {
103 unsigned long long (*get_size)(struct blkif *blkif);
104 unsigned long (*get_secsize)(struct blkif *blkif);
105 unsigned int (*get_info)(struct blkif *blkif);
106 };
108 typedef struct blkif {
109 domid_t domid;
110 long int handle;
112 long int pdev;
113 long int readonly;
115 enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
117 struct blkif_ops *ops;
118 struct blkif *hash_next;
120 void *prv; /* device-specific data */
121 void *info; /*Image parameter passing */
122 pending_req_t pending_list[MAX_REQUESTS];
123 int devnum;
124 int fds[2];
125 int be_id;
126 int major;
127 int minor;
128 pid_t tappid;
129 int drivertype;
130 uint16_t cookie;
131 } blkif_t;
133 typedef struct blkif_info {
134 char *params;
135 } blkif_info_t;
137 void register_new_devmap_hook(int (*fn)(blkif_t *blkif));
138 void register_new_unmap_hook(int (*fn)(blkif_t *blkif));
139 void register_new_blkif_hook(int (*fn)(blkif_t *blkif));
140 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
141 blkif_t *alloc_blkif(domid_t domid);
142 int blkif_init(blkif_t *blkif, long int handle, long int pdev,
143 long int readonly);
144 void free_blkif(blkif_t *blkif);
145 void __init_blkif(void);
147 typedef struct busy_state {
148 int seg_idx;
149 blkif_request_t *req;
150 } busy_state_t;
152 typedef struct tapdev_info {
153 int fd;
154 char *mem;
155 blkif_sring_t *sring;
156 blkif_back_ring_t fe_ring;
157 unsigned long vstart;
158 blkif_t *blkif;
159 busy_state_t busy;
160 } tapdev_info_t;
162 typedef struct domid_translate {
163 unsigned short domid;
164 unsigned short busid;
165 } domid_translate_t ;
167 typedef struct image {
168 unsigned long long size;
169 unsigned long secsize;
170 unsigned int info;
171 } image_t;
173 /* 16-byte message header, immediately followed by message payload. */
174 typedef struct msg_hdr {
175 uint16_t type;
176 uint16_t len;
177 uint16_t drivertype;
178 uint16_t cookie;
179 uint8_t readonly;
180 uint8_t pad[7];
181 } msg_hdr_t;
183 typedef struct msg_newdev {
184 uint8_t devnum;
185 uint16_t domid;
186 } msg_newdev_t;
188 typedef struct msg_pid {
189 pid_t pid;
190 } msg_pid_t;
192 #define READ 0
193 #define WRITE 1
195 /*Control Messages between manager and tapdev*/
196 #define CTLMSG_PARAMS 1
197 #define CTLMSG_IMG 2
198 #define CTLMSG_IMG_FAIL 3
199 #define CTLMSG_NEWDEV 4
200 #define CTLMSG_NEWDEV_RSP 5
201 #define CTLMSG_NEWDEV_FAIL 6
202 #define CTLMSG_CLOSE 7
203 #define CTLMSG_CLOSE_RSP 8
204 #define CTLMSG_PID 9
205 #define CTLMSG_PID_RSP 10
207 /* xenstore/xenbus: */
208 #define DOMNAME "Domain-0"
209 int setup_probe_watch(struct xs_handle *h);
210 int xs_fire_next_watch(struct xs_handle *h);
213 /* Abitrary values, must match the underlying driver... */
214 #define MAX_TAP_DEV 100
216 /* Accessing attached data page mappings */
217 #define MMAP_PAGES \
218 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
219 #define MMAP_VADDR(_vstart,_req,_seg) \
220 ((_vstart) + \
221 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) + \
222 ((_seg) * getpagesize()))
224 /* Defines that are only used by library clients */
226 #ifndef __COMPILING_BLKTAP_LIB
228 static char *blkif_op_name[] = {
229 [BLKIF_OP_READ] = "READ",
230 [BLKIF_OP_WRITE] = "WRITE",
231 };
233 #endif /* __COMPILING_BLKTAP_LIB */
235 #endif /* __BLKTAPLIB_H__ */