ia64/xen-unstable

view tools/blktap/blktaplib.h @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children ff95b53bd39a
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 /* /dev/xen/blktap resides at device number major=10, minor=202 */
22 #define BLKTAP_MINOR 202
24 /* size of the extra VMA area to map in attached pages. */
25 #define BLKTAP_VMA_PAGES BLKIF_RING_SIZE
27 /* blktap IOCTLs: */
28 #define BLKTAP_IOCTL_KICK_FE 1
29 #define BLKTAP_IOCTL_KICK_BE 2
30 #define BLKTAP_IOCTL_SETMODE 3
31 #define BLKTAP_IOCTL_PRINT_IDXS 100
33 /* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE) */
34 #define BLKTAP_MODE_PASSTHROUGH 0x00000000 /* default */
35 #define BLKTAP_MODE_INTERCEPT_FE 0x00000001
36 #define BLKTAP_MODE_INTERCEPT_BE 0x00000002
37 #define BLKTAP_MODE_COPY_FE 0x00000004
38 #define BLKTAP_MODE_COPY_BE 0x00000008
39 #define BLKTAP_MODE_COPY_FE_PAGES 0x00000010
40 #define BLKTAP_MODE_COPY_BE_PAGES 0x00000020
42 #define BLKTAP_MODE_INTERPOSE \
43 (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
45 #define BLKTAP_MODE_COPY_BOTH \
46 (BLKTAP_MODE_COPY_FE | BLKTAP_MODE_COPY_BE)
48 #define BLKTAP_MODE_COPY_BOTH_PAGES \
49 (BLKTAP_MODE_COPY_FE_PAGES | BLKTAP_MODE_COPY_BE_PAGES)
51 static inline int BLKTAP_MODE_VALID(unsigned long arg)
52 {
53 return (
54 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
55 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
56 ( arg == BLKTAP_MODE_INTERPOSE ) );
57 /*
58 return (
59 ( arg == BLKTAP_MODE_PASSTHROUGH ) ||
60 ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
61 ( arg == BLKTAP_MODE_INTERCEPT_BE ) ||
62 ( arg == BLKTAP_MODE_INTERPOSE ) ||
63 ( (arg & ~BLKTAP_MODE_COPY_FE_PAGES) == BLKTAP_MODE_COPY_FE ) ||
64 ( (arg & ~BLKTAP_MODE_COPY_BE_PAGES) == BLKTAP_MODE_COPY_BE ) ||
65 ( (arg & ~BLKTAP_MODE_COPY_BOTH_PAGES) == BLKTAP_MODE_COPY_BOTH )
66 );
67 */
68 }
70 /* Return values for handling messages in hooks. */
71 #define BLKTAP_PASS 0 /* Keep passing this request as normal. */
72 #define BLKTAP_RESPOND 1 /* Request is now a reply. Return it. */
73 #define BLKTAP_STOLEN 2 /* Hook has stolen request. */
75 //#define domid_t unsigned short
77 inline unsigned int ID_TO_IDX(unsigned long id);
78 inline domid_t ID_TO_DOM(unsigned long id);
80 int blktap_attach_poll(int fd, short events, int (*func)(int));
81 void blktap_detach_poll(int fd);
82 int blktap_listen(void);
84 struct blkif;
86 typedef struct request_hook_st {
87 char *name;
88 int (*func)(struct blkif *, blkif_request_t *, int);
89 struct request_hook_st *next;
90 } request_hook_t;
92 typedef struct response_hook_st {
93 char *name;
94 int (*func)(struct blkif *, blkif_response_t *, int);
95 struct response_hook_st *next;
96 } response_hook_t;
98 struct blkif_ops {
99 long int (*get_size)(struct blkif *blkif);
100 long int (*get_secsize)(struct blkif *blkif);
101 unsigned (*get_info)(struct blkif *blkif);
102 };
104 typedef struct blkif {
105 domid_t domid;
106 long int handle;
108 long int pdev;
109 long int readonly;
111 enum { DISCONNECTED, CONNECTED } state;
113 struct blkif_ops *ops;
114 request_hook_t *request_hook_chain;
115 response_hook_t *response_hook_chain;
117 struct blkif *hash_next;
119 void *prv; /* device-specific data */
120 } blkif_t;
122 void register_new_blkif_hook(int (*fn)(blkif_t *blkif));
123 blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
124 blkif_t *alloc_blkif(domid_t domid);
125 int blkif_init(blkif_t *blkif, long int handle, long int pdev,
126 long int readonly);
127 void free_blkif(blkif_t *blkif);
128 void __init_blkif(void);
131 /* xenstore/xenbus: */
132 extern int add_blockdevice_probe_watch(struct xs_handle *h,
133 const char *domname);
134 int xs_fire_next_watch(struct xs_handle *h);
137 void blkif_print_hooks(blkif_t *blkif);
138 void blkif_register_request_hook(blkif_t *blkif, char *name,
139 int (*rh)(blkif_t *, blkif_request_t *, int));
140 void blkif_register_response_hook(blkif_t *blkif, char *name,
141 int (*rh)(blkif_t *, blkif_response_t *, int));
142 void blkif_inject_response(blkif_t *blkif, blkif_response_t *);
143 void blktap_kick_responses(void);
145 /* this must match the underlying driver... */
146 #define MAX_PENDING_REQS 64
148 /* Accessing attached data page mappings */
149 #define MMAP_PAGES \
150 (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
151 #define MMAP_VADDR(_req,_seg) \
152 (mmap_vstart + \
153 ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) + \
154 ((_seg) * PAGE_SIZE))
156 extern unsigned long mmap_vstart;
158 /* Defines that are only used by library clients */
160 #ifndef __COMPILING_BLKTAP_LIB
162 static char *blkif_op_name[] = {
163 [BLKIF_OP_READ] = "READ",
164 [BLKIF_OP_WRITE] = "WRITE",
165 };
167 #endif /* __COMPILING_BLKTAP_LIB */
169 #endif /* __BLKTAPLIB_H__ */