ia64/xen-unstable

view tools/blktap/blktaplib.h @ 8740:3d7ea7972b39

Update patches for linux 2.6.15.

Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Thu Feb 02 17:16:00 2006 +0000 (2006-02-02)
parents ff95b53bd39a
children
line source
1 /* blktaplib.h
2 *
3 * userland accessors to the block tap.
4 *
5 * Sept 2/05 -- I'm scaling this back to only support block remappings
6 * to user in a backend domain. Passthrough and interposition can be readded
7 * once transitive grants are available.
8 */
10 #ifndef __BLKTAPLIB_H__
11 #define __BLKTAPLIB_H__
13 #include <xenctrl.h>
14 #include <sys/user.h>
15 #include <xen/xen.h>
16 #include <xen/io/blkif.h>
17 #include <xen/io/ring.h>
18 #include <xen/io/domain_controller.h>
19 #include <xs.h>
21 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
23 /* /dev/xen/blktap resides at device number major=10, minor=202 */
24 #define BLKTAP_MINOR 202
26 /* size of the extra VMA area to map in attached pages. */
27 #define BLKTAP_VMA_PAGES BLK_RING_SIZE
29 /* blktap IOCTLs: */
30 #define BLKTAP_IOCTL_KICK_FE 1
31 #define BLKTAP_IOCTL_KICK_BE 2
32 #define BLKTAP_IOCTL_SETMODE 3
33 #define BLKTAP_IOCTL_PRINT_IDXS 100
35 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
36 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
37 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
38 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
39 #define BLKTAP_MODE_COPY_FE 0x00000004
40 #define BLKTAP_MODE_COPY_BE 0x00000008
41 #define BLKTAP_MODE_COPY_FE_PAGES 0x00000010
42 #define BLKTAP_MODE_COPY_BE_PAGES 0x00000020
44 #define BLKTAP_MODE_INTERPOSE \
45 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
47 #define BLKTAP_MODE_COPY_BOTH \
48 (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
50 #define BLKTAP_MODE_COPY_BOTH_PAGES \
51 (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
53 static inline int BLKTAP_MODE_VALID(unsigned long arg)
54 {
55 return (
56 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
57 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
58 ( arg == BLKTAP_MODE_INTERPOSE ) );
59 /*
60 return (
61 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
62 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
63 ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
64 ( arg == BLKTAP_MODE_INTERPOSE ) ||
65 ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
66 ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
67 ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
68 );
69 */
70 }
72 /* Return values for handling messages in hooks. */
73 #define BLKTAP_PASS 0 /* Keep passing this request as normal. */
74 #define BLKTAP_RESPOND 1 /* Request is now a reply. Return it. */
75 #define BLKTAP_STOLEN 2 /* Hook has stolen request. */
77 //#define domid_t unsigned short
79 inline unsigned int ID_TO_IDX(unsigned long id);
80 inline domid_t ID_TO_DOM(unsigned long id);
82 int blktap_attach_poll(int fd, short events, int (*func)(int));
83 void blktap_detach_poll(int fd);
84 int blktap_listen(void);
86 struct blkif;
88 typedef struct request_hook_st {
89 char *name;
90 int (*func)(struct blkif *, blkif_request_t *, int);
91 struct request_hook_st *next;
92 } request_hook_t;
94 typedef struct response_hook_st {
95 char *name;
96 int (*func)(struct blkif *, blkif_response_t *, int);
97 struct response_hook_st *next;
98 } response_hook_t;
100 struct blkif_ops {
101 long int (*get_size)(struct blkif *blkif);
102 long int (*get_secsize)(struct blkif *blkif);
103 unsigned (*get_info)(struct blkif *blkif);
104 };
106 typedef struct blkif {
107 domid_t domid;
108 long int handle;
110 long int pdev;
111 long int readonly;
113 enum { DISCONNECTED, CONNECTED } state;
115 struct blkif_ops *ops;
116 request_hook_t *request_hook_chain;
117 response_hook_t *response_hook_chain;
119 struct blkif *hash_next;
121 void *prv; /* device-specific data */
122 } blkif_t;
124 void register_new_blkif_hook(int (*fn)(blkif_t *blkif));
125 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
126 blkif_t *alloc_blkif(domid_t domid);
127 int blkif_init(blkif_t *blkif, long int handle, long int pdev,
128 long int readonly);
129 void free_blkif(blkif_t *blkif);
130 void __init_blkif(void);
133 /* xenstore/xenbus: */
134 extern int add_blockdevice_probe_watch(struct xs_handle *h,
135 const char *domname);
136 int xs_fire_next_watch(struct xs_handle *h);
139 void blkif_print_hooks(blkif_t *blkif);
140 void blkif_register_request_hook(blkif_t *blkif, char *name,
141 int (*rh)(blkif_t *, blkif_request_t *, int));
142 void blkif_register_response_hook(blkif_t *blkif, char *name,
143 int (*rh)(blkif_t *, blkif_response_t *, int));
144 void blkif_inject_response(blkif_t *blkif, blkif_response_t *);
145 void blktap_kick_responses(void);
147 /* this must match the underlying driver... */
148 #define MAX_PENDING_REQS 64
150 /* Accessing attached data page mappings */
151 #define MMAP_PAGES \
152 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
153 #define MMAP_VADDR(_req,_seg) \
154 (mmap_vstart + \
155 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) + \
156 ((_seg) * PAGE_SIZE))
158 extern unsigned long mmap_vstart;
160 /* Defines that are only used by library clients */
162 #ifndef __COMPILING_BLKTAP_LIB
164 static char *blkif_op_name[] = {
165 [BLKIF_OP_READ] = "READ",
166 [BLKIF_OP_WRITE] = "WRITE",
167 };
169 #endif /* __COMPILING_BLKTAP_LIB */
171 #endif /* __BLKTAPLIB_H__ */