debuggers.hg

view tools/blktap2/drivers/tapdisk.h @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents a5032d7a87e0
children
line source
1 /*
2 * Copyright (c) 2007, XenSource Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of XenSource Inc. nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
20 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Some notes on the tap_disk interface:
29 *
30 * tap_disk aims to provide a generic interface to easily implement new
31 * types of image accessors. The structure-of-function-calls is similar
32 * to disk interfaces used in qemu/denali/etc, with the significant
33 * difference being the expectation of asynchronous rather than synchronous
34 * I/O. The asynchronous interface is intended to allow lots of requests to
35 * be pipelined through a disk, without the disk requiring any of its own
36 * threads of control. As such, a batch of requests is delivered to the disk
37 * using:
38 *
39 * td_queue_[read,write]()
40 *
41 * and passing in a completion callback, which the disk is responsible for
42 * tracking. Disks should transform these requests as necessary and return
43 * the resulting iocbs to tapdisk using td_prep_[read,write]() and
44 * td_queue_tiocb().
45 *
46 * NOTE: tapdisk uses the number of sectors submitted per request as a
47 * ref count. Plugins must use the callback function to communicate the
48 * completion -- or error -- of every sector submitted to them.
49 *
50 * td_get_parent_id returns:
51 * 0 if parent id successfully retrieved
52 * TD_NO_PARENT if no parent exists
53 * -errno on error
54 */
56 #ifndef _TAPDISK_H_
57 #define _TAPDISK_H_
59 #include <time.h>
60 #include <stdint.h>
62 #include "list.h"
63 #include "blktaplib.h"
64 #include "tapdisk-log.h"
65 #include "tapdisk-utils.h"
67 #define DPRINTF(_f, _a...) syslog(LOG_INFO, _f, ##_a)
68 #define EPRINTF(_f, _a...) syslog(LOG_ERR, "tap-err:%s: " _f, __func__, ##_a)
69 #define PERROR(_f, _a...) EPRINTF(_f ": %s", ##_a, strerror(errno))
71 #define MAX_SEGMENTS_PER_REQ 11
72 #define SECTOR_SHIFT 9
73 #define DEFAULT_SECTOR_SIZE 512
75 #define TAPDISK_DATA_REQUESTS (MAX_REQUESTS * MAX_SEGMENTS_PER_REQ)
77 //#define BLK_NOT_ALLOCATED (-99)
78 #define TD_NO_PARENT 1
80 #define MAX_RAMDISK_SIZE 1024000 /*500MB disk limit*/
82 #define TD_OP_READ 0
83 #define TD_OP_WRITE 1
85 #define TD_OPEN_QUIET 0x00001
86 #define TD_OPEN_QUERY 0x00002
87 #define TD_OPEN_RDONLY 0x00004
88 #define TD_OPEN_STRICT 0x00008
89 #define TD_OPEN_SHAREABLE 0x00010
90 #define TD_OPEN_ADD_CACHE 0x00020
91 #define TD_OPEN_VHD_INDEX 0x00040
92 #define TD_OPEN_LOG_DIRTY 0x00080
94 #define TD_CREATE_SPARSE 0x00001
95 #define TD_CREATE_MULTITYPE 0x00002
97 #define td_flag_set(word, flag) ((word) |= (flag))
98 #define td_flag_clear(word, flag) ((word) &= ~(flag))
99 #define td_flag_test(word, flag) ((word) & (flag))
101 typedef uint16_t td_uuid_t;
102 typedef uint32_t td_flag_t;
103 typedef uint64_t td_sector_t;
104 typedef struct td_disk_id td_disk_id_t;
105 typedef struct td_disk_info td_disk_info_t;
106 typedef struct td_request td_request_t;
107 typedef struct td_driver_handle td_driver_t;
108 typedef struct td_image_handle td_image_t;
110 struct td_disk_id {
111 char *name;
112 int drivertype;
113 };
115 struct td_disk_info {
116 td_sector_t size;
117 uint64_t sector_size;
118 uint32_t info;
119 };
121 struct td_request {
122 int op;
123 char *buf;
124 td_sector_t sec;
125 int secs;
127 uint8_t blocked; /* blocked on a dependency */
129 td_image_t *image;
131 void * /*td_callback_t*/ cb;
132 void *cb_data;
134 uint64_t id;
135 int sidx;
136 void *private;
138 #ifdef MEMSHR
139 uint64_t memshr_hnd;
140 #endif
141 };
143 /*
144 * Prototype of the callback to activate as requests complete.
145 */
146 typedef void (*td_callback_t)(td_request_t, int);
148 /*
149 * Structure describing the interface to a virtual disk implementation.
150 * See note at the top of this file describing this interface.
151 */
152 struct tap_disk {
153 const char *disk_type;
154 td_flag_t flags;
155 int private_data_size;
156 int (*td_open) (td_driver_t *, const char *, td_flag_t);
157 int (*td_close) (td_driver_t *);
158 int (*td_get_parent_id) (td_driver_t *, td_disk_id_t *);
159 int (*td_validate_parent) (td_driver_t *, td_driver_t *, td_flag_t);
160 void (*td_queue_read) (td_driver_t *, td_request_t);
161 void (*td_queue_write) (td_driver_t *, td_request_t);
162 void (*td_debug) (td_driver_t *);
163 };
165 #endif