aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2/include/blktaplib.h
blob: c2860b7c3bce664cf7d6fd2ec4d2460f24113b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* blktaplib.h
 *
 * Blktap library userspace code.
 *
 * Copyright (c) 2007, XenSource Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of XenSource Inc. nor the names of its contributors
 *       may be used to endorse or promote products derived from this software
 *       without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __BLKTAPLIB_H__
#define __BLKTAPLIB_H__

#include <syslog.h>
#include <sys/time.h>
#include <xenctrl.h>
#include <xen/io/blkif.h>

#define BLK_RING_SIZE __CONST_RING_SIZE(blkif, XC_PAGE_SIZE)

/* size of the extra VMA area to map in attached pages. */
#define BLKTAP_VMA_PAGES BLK_RING_SIZE

/* blktap IOCTLs: These must correspond with the blktap driver ioctls */
#define BLKTAP_IOCTL_KICK_FE         1
#define BLKTAP_IOCTL_KICK_BE         2
#define BLKTAP_IOCTL_SETMODE         3
#define BLKTAP_IOCTL_SENDPID	     4
#define BLKTAP_IOCTL_NEWINTF	     5
#define BLKTAP_IOCTL_MINOR	     6
#define BLKTAP_IOCTL_MAJOR	     7
#define BLKTAP_QUERY_ALLOC_REQS      8
#define BLKTAP_IOCTL_FREEINTF	     9
#define BLKTAP_IOCTL_PRINT_IDXS      100 
#define BLKTAP_IOCTL_BACKDEV_SETUP   200

#define PRIO_SPECIAL_IO             -9999 

/* blktap switching modes: (Set with BLKTAP_IOCTL_SETMODE)             */
#define BLKTAP_MODE_PASSTHROUGH      0x00000000  /* default            */
#define BLKTAP_MODE_INTERCEPT_FE     0x00000001
#define BLKTAP_MODE_INTERCEPT_BE     0x00000002

#define BLKTAP_MODE_INTERPOSE \
           (BLKTAP_MODE_INTERCEPT_FE | BLKTAP_MODE_INTERCEPT_BE)

static inline int BLKTAP_MODE_VALID(unsigned long arg)
{
	return (
		( arg == BLKTAP_MODE_PASSTHROUGH  ) ||
		( arg == BLKTAP_MODE_INTERCEPT_FE ) ||
		( arg == BLKTAP_MODE_INTERPOSE    ) );
}

#define MAX_REQUESTS            BLK_RING_SIZE

#define BLKTAP_IOCTL_KICK       1
#define MAX_PENDING_REQS	BLK_RING_SIZE
#define BLKTAP_DEV_DIR          "/dev/xen"
#define BLKTAP_DEV_NAME         "blktap"
#define BACKDEV_NAME            "backdev"
#define BLKTAP_DEV_MINOR        0
#define BLKTAP_CTRL_DIR         "/var/run/tap"

extern int blktap_major;

#define BLKTAP_RING_PAGES       1 /* Front */
#define BLKTAP_MMAP_REGION_SIZE (BLKTAP_RING_PAGES + MMAP_PAGES)

struct blkif;
struct blkif_info;

typedef struct {
	blkif_request_t  req;
	int              submitting;
	int              secs_pending;
        int16_t          status;
	int              num_retries;
	struct timeval   last_try;
} pending_req_t;

typedef struct blkif {
	domid_t domid;
	long int handle;
	
	long int pdev;
	long int readonly;
	
	enum { DISCONNECTED, DISCONNECTING, CONNECTED } state;
	
	struct blkif_ops *ops;
	struct blkif *hash_next;
	
	void *prv;  /* device-specific data */
	struct blkif_info *info; /*Image parameter passing */
	pending_req_t pending_list[MAX_REQUESTS];
	int devnum;
	int fds[2];
	int be_id;
	char *backend_path;
	int major;
	int minor;
	pid_t tappid;
	int drivertype;
	uint16_t cookie;
	int err;
} blkif_t;

typedef struct blkif_info {
	char *params;
	int   readonly;
	int   storage;
} blkif_info_t;

typedef struct tapdev_info {
	int fd;
	char *mem;
	blkif_sring_t *sring;
	blkif_back_ring_t  fe_ring;
	unsigned long vstart;
	blkif_t *blkif;
} tapdev_info_t;

typedef struct domid_translate {
	unsigned short domid;
	unsigned short busid;
} domid_translate_t ;

typedef struct image {
	unsigned long long size;
	unsigned long secsize;
	unsigned int info;
} image_t;

typedef struct msg_hdr {
	uint16_t   type;
	uint16_t   len;
	uint16_t   drivertype;
	uint16_t   cookie;
} msg_hdr_t;

typedef struct msg_params {
	uint8_t    readonly;
	int        path_off;
	int        path_len;
	int        storage;
} msg_params_t;

typedef struct msg_newdev {
	uint8_t     devnum;
	uint16_t    domid;
} msg_newdev_t;

typedef struct msg_pid {
	pid_t     pid;
} msg_pid_t;

typedef struct msg_cp {
	int       cp_uuid_off;
	int       cp_uuid_len;
	int       cp_drivertype;
} msg_cp_t;

typedef struct msg_lock {
	int       ro;
	int       enforce;
	int       uuid_off;
	int       uuid_len;
} msg_lock_t;

#define READ 0
#define WRITE 1

/*Control Messages between manager and tapdev*/
#define CTLMSG_PARAMS          1
#define CTLMSG_IMG             2
#define CTLMSG_IMG_FAIL        3
#define CTLMSG_NEWDEV          4
#define CTLMSG_NEWDEV_RSP      5
#define CTLMSG_NEWDEV_FAIL     6
#define CTLMSG_CLOSE           7
#define CTLMSG_CLOSE_RSP       8
#define CTLMSG_PID             9
#define CTLMSG_PID_RSP         10
#define CTLMSG_CHECKPOINT      11
#define CTLMSG_CHECKPOINT_RSP  12
#define CTLMSG_LOCK            13
#define CTLMSG_LOCK_RSP        14
#define CTLMSG_PAUSE           15
#define CTLMSG_PAUSE_RSP       16
#define CTLMSG_RESUME          17
#define CTLMSG_RESUME_RSP      18

#define TAPDISK_STORAGE_TYPE_NFS       1
#define TAPDISK_STORAGE_TYPE_EXT       2
#define TAPDISK_STORAGE_TYPE_LVM       3
#define TAPDISK_STORAGE_TYPE_DEFAULT   TAPDISK_STORAGE_TYPE_EXT

/* Abitrary values, must match the underlying driver... */
#define MAX_TAP_DEV 256

/* Accessing attached data page mappings */
#define MMAP_PAGES                                                    \
    (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
#define MMAP_VADDR(_vstart,_req,_seg)                                 \
    ((_vstart) +                                                      \
     ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * getpagesize()) +      \
     ((_seg) * getpagesize()))

/* Defines that are only used by library clients */

#ifndef __COMPILING_BLKTAP_LIB

static char *blkif_op_name[] = {
	[BLKIF_OP_READ]       = "READ",
	[BLKIF_OP_WRITE]      = "WRITE",
};

#endif /* __COMPILING_BLKTAP_LIB */

#endif /* __BLKTAPLIB_H__ */