~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/blktap/lib/blktaplib.h

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
31
 
 
32
#ifndef __BLKTAPLIB_H__
 
33
#define __BLKTAPLIB_H__
 
34
 
 
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>
 
44
 
 
45
#define BLK_RING_SIZE __CONST_RING_SIZE(blkif, XC_PAGE_SIZE)
 
46
 
 
47
/* size of the extra VMA area to map in attached pages. */
 
48
#define BLKTAP_VMA_PAGES BLK_RING_SIZE
 
49
 
 
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_NEWINTF_EXT     50
 
61
#define BLKTAP_IOCTL_PRINT_IDXS      100   
 
62
 
 
63
/* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE)             */
 
64
#define BLKTAP_MODE_PASSTHROUGH      0x00000000  /* default            */
 
65
#define BLKTAP_MODE_INTERCEPT_FE     0x00000001
 
66
#define BLKTAP_MODE_INTERCEPT_BE     0x00000002
 
67
 
 
68
#define BLKTAP_MODE_INTERPOSE \
 
69
           (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)
 
70
 
 
71
static inline int BLKTAP_MODE_VALID(unsigned long arg)
 
72
{
 
73
        return (
 
74
                ( arg == BLKTAP_MODE_PASSTHROUGH  ) ||
 
75
                ( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
 
76
                ( arg == BLKTAP_MODE_INTERPOSE    ) );
 
77
}
 
78
 
 
79
#define MAX_REQUESTS            BLK_RING_SIZE
 
80
 
 
81
#define BLKTAP_IOCTL_KICK 1
 
82
#define MAX_PENDING_REQS        BLK_RING_SIZE
 
83
#define BLKTAP_DEV_DIR   "/dev/xen"
 
84
#define BLKTAP_DEV_NAME  "blktap"
 
85
#define BLKTAP_DEV_MINOR 0
 
86
#define BLKTAP_CTRL_DIR   "/var/run/tap"
 
87
 
 
88
extern int blktap_major;
 
89
 
 
90
#define BLKTAP_RING_PAGES       1 /* Front */
 
91
#define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)
 
92
 
 
93
struct blkif;
 
94
 
 
95
typedef struct {
 
96
        blkif_request_t  req;
 
97
        struct blkif    *blkif;
 
98
        int              submitting;
 
99
        int              secs_pending;
 
100
        int16_t          status;
 
101
} pending_req_t;
 
102
 
 
103
struct blkif_ops {
 
104
        unsigned long long (*get_size)(struct blkif *blkif);
 
105
        unsigned long (*get_secsize)(struct blkif *blkif);
 
106
        unsigned int (*get_info)(struct blkif *blkif);
 
107
};
 
108
 
 
109
typedef struct blkif {
 
110
        domid_t domid;
 
111
        long int handle;
 
112
        
 
113
        long int pdev;
 
114
        long int readonly;
 
115
        
 
116
        enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
 
117
        
 
118
        struct blkif_ops *ops;
 
119
        struct blkif *hash_next;
 
120
        
 
121
        void *prv;  /* device-specific data */
 
122
        void *info; /*Image parameter passing */
 
123
        pending_req_t pending_list[MAX_REQUESTS];
 
124
        int devnum;
 
125
        int fds[2];
 
126
        int be_id;
 
127
        int major;
 
128
        int minor;
 
129
        pid_t tappid;
 
130
        int drivertype;
 
131
        uint16_t cookie;
 
132
} blkif_t;
 
133
 
 
134
typedef struct blkif_info {
 
135
        char *params;
 
136
} blkif_info_t;
 
137
 
 
138
void register_new_devmap_hook(int (*fn)(blkif_t *blkif));
 
139
void register_new_unmap_hook(int (*fn)(blkif_t *blkif));
 
140
void register_new_blkif_hook(int (*fn)(blkif_t *blkif));
 
141
blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle);
 
142
blkif_t *alloc_blkif(domid_t domid);
 
143
int blkif_init(blkif_t *blkif, long int handle, long int pdev, 
 
144
               long int readonly);
 
145
void free_blkif(blkif_t *blkif);
 
146
void __init_blkif(void);
 
147
 
 
148
typedef struct busy_state {
 
149
        int seg_idx;
 
150
        blkif_request_t *req;
 
151
} busy_state_t;
 
152
 
 
153
typedef struct tapdev_info {
 
154
        int fd;
 
155
        char *mem;
 
156
        blkif_sring_t *sring;
 
157
        blkif_back_ring_t  fe_ring;
 
158
        unsigned long vstart;
 
159
        blkif_t *blkif;
 
160
        busy_state_t busy;
 
161
} tapdev_info_t;
 
162
 
 
163
typedef struct domid_translate {
 
164
        unsigned short domid;
 
165
        unsigned short busid;
 
166
} domid_translate_t ;
 
167
 
 
168
typedef struct domid_translate_ext {
 
169
        unsigned short domid;
 
170
        uint32_t busid;
 
171
} domid_translate_ext_t ;
 
172
 
 
173
typedef struct image {
 
174
        unsigned long long size;
 
175
        unsigned long secsize;
 
176
        unsigned int info;
 
177
} image_t;
 
178
 
 
179
/* 16-byte message header, immediately followed by message payload. */
 
180
typedef struct msg_hdr {
 
181
        uint16_t   type;
 
182
        uint16_t   len;
 
183
        uint16_t   drivertype;
 
184
        uint16_t   cookie;
 
185
        uint8_t    readonly;
 
186
        uint8_t    pad[7];
 
187
} msg_hdr_t;
 
188
 
 
189
typedef struct msg_newdev {
 
190
        uint8_t     devnum;
 
191
        uint16_t    domid;
 
192
} msg_newdev_t;
 
193
 
 
194
typedef struct msg_pid {
 
195
        pid_t     pid;
 
196
} msg_pid_t;
 
197
 
 
198
#define READ 0
 
199
#define WRITE 1
 
200
 
 
201
/*Control Messages between manager and tapdev*/
 
202
#define CTLMSG_PARAMS      1
 
203
#define CTLMSG_IMG         2
 
204
#define CTLMSG_IMG_FAIL    3
 
205
#define CTLMSG_NEWDEV      4
 
206
#define CTLMSG_NEWDEV_RSP  5
 
207
#define CTLMSG_NEWDEV_FAIL 6
 
208
#define CTLMSG_CLOSE       7
 
209
#define CTLMSG_CLOSE_RSP   8
 
210
#define CTLMSG_PID         9
 
211
#define CTLMSG_PID_RSP     10
 
212
 
 
213
/* disk driver types */
 
214
#define MAX_DISK_TYPES     20
 
215
 
 
216
#define DISK_TYPE_AIO      0
 
217
#define DISK_TYPE_SYNC     1
 
218
#define DISK_TYPE_VMDK     2
 
219
#define DISK_TYPE_RAM      3
 
220
#define DISK_TYPE_QCOW     4
 
221
#define DISK_TYPE_QCOW2    5
 
222
 
 
223
/* xenstore/xenbus: */
 
224
#define DOMNAME "Domain-0"
 
225
int setup_probe_watch(struct xs_handle *h);
 
226
 
 
227
 
 
228
/* Abitrary values, must match the underlying driver... */
 
229
#define MAX_TAP_DEV 100
 
230
 
 
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()))
 
238
 
 
239
 
 
240
#endif /* __BLKTAPLIB_H__ */