Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2016, Citrix Systems, Inc.
3 : : *
4 : : * All rights reserved.
5 : : *
6 : : * Redistribution and use in source and binary forms, with or without
7 : : * modification, are permitted provided that the following conditions are met:
8 : : *
9 : : * 1. Redistributions of source code must retain the above copyright
10 : : * notice, this list of conditions and the following disclaimer.
11 : : * 2. Redistributions in binary form must reproduce the above copyright
12 : : * notice, this list of conditions and the following disclaimer in the
13 : : * documentation and/or other materials provided with the distribution.
14 : : * 3. Neither the name of the copyright holder nor the names of its
15 : : * contributors may be used to endorse or promote products derived from
16 : : * this software without specific prior written permission.
17 : : *
18 : : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 : : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 : : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 : : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22 : : * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 : : * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 : : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 : : * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 : : * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 : : * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 : : * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 : : */
30 : :
31 : : #ifdef HAVE_CONFIG_H
32 : : #include "config.h"
33 : : #endif
34 : :
35 : : #include <stddef.h>
36 : : #include <string.h>
37 : : #include <errno.h>
38 : :
39 : : #include "tapdisk-disktype.h"
40 : : #include "util.h"
41 : :
42 : : static const disk_info_t aio_disk = {
43 : : "aio",
44 : : "raw image (aio)",
45 : : 0,
46 : : };
47 : :
48 : : static const disk_info_t sync_disk = {
49 : : "sync",
50 : : "raw image (sync)",
51 : : 0,
52 : : };
53 : :
54 : : static const disk_info_t vmdk_disk = {
55 : : "vmdk",
56 : : "vmware image (vmdk)",
57 : : 1,
58 : : };
59 : :
60 : : static const disk_info_t vhdsync_disk = {
61 : : "vhdsync",
62 : : "virtual server image (vhd) - synchronous",
63 : : 1,
64 : : };
65 : :
66 : : static const disk_info_t vhd_disk = {
67 : : "vhd",
68 : : "virtual server image (vhd)",
69 : : 0,
70 : : };
71 : :
72 : :
73 : : static const disk_info_t ram_disk = {
74 : : "ram",
75 : : "ramdisk image (ram)",
76 : : 1,
77 : : };
78 : :
79 : : static const disk_info_t qcow_disk = {
80 : : "qcow",
81 : : "qcow disk (qcow)",
82 : : 0,
83 : : };
84 : :
85 : : static const disk_info_t block_cache_disk = {
86 : : "bc",
87 : : "block cache image (bc)",
88 : : 1,
89 : : };
90 : :
91 : : static const disk_info_t vhd_index_disk = {
92 : : "vhdi",
93 : : "vhd index image (vhdi)",
94 : : 1,
95 : : };
96 : :
97 : : static const disk_info_t log_disk = {
98 : : "log",
99 : : "write logger (log)",
100 : : DISK_TYPE_FILTER,
101 : : };
102 : :
103 : : static disk_info_t remus_disk = {
104 : : "remus disk replicator (remus)",
105 : : "remus",
106 : : 0,
107 : : };
108 : :
109 : : static const disk_info_t lcache_disk = {
110 : : "lc",
111 : : "local parent cache (lc)",
112 : : DISK_TYPE_FILTER,
113 : : };
114 : :
115 : : static const disk_info_t llpcache_disk = {
116 : : "llp",
117 : : "local leaf cache, persistent (llp)",
118 : : 0,
119 : : };
120 : :
121 : : static const disk_info_t llecache_disk = {
122 : : "lle",
123 : : "local leaf cache, ephemeral (lle)",
124 : : 0,
125 : : };
126 : :
127 : : static const disk_info_t valve_disk = {
128 : : "valve",
129 : : "group rate limiting (valve)",
130 : : DISK_TYPE_FILTER,
131 : : };
132 : :
133 : : static const disk_info_t nbd_disk = {
134 : : "nbd",
135 : : "export to a NBD server",
136 : : 0,
137 : : };
138 : :
139 : : const disk_info_t *tapdisk_disk_types[] = {
140 : : [DISK_TYPE_AIO] = &aio_disk,
141 : : [DISK_TYPE_SYNC] = &sync_disk,
142 : : [DISK_TYPE_VMDK] = &vmdk_disk,
143 : : [DISK_TYPE_VHDSYNC] = &vhdsync_disk,
144 : : [DISK_TYPE_VHD] = &vhd_disk,
145 : : [DISK_TYPE_RAM] = &ram_disk,
146 : : [DISK_TYPE_QCOW] = &qcow_disk,
147 : : [DISK_TYPE_BLOCK_CACHE] = &block_cache_disk,
148 : : [DISK_TYPE_VINDEX] = &vhd_index_disk,
149 : : [DISK_TYPE_LOG] = &log_disk,
150 : : [DISK_TYPE_REMUS] = &remus_disk,
151 : : [DISK_TYPE_LCACHE] = &lcache_disk,
152 : : [DISK_TYPE_VALVE] = &valve_disk,
153 : : [DISK_TYPE_LLPCACHE] = &llpcache_disk,
154 : : [DISK_TYPE_LLECACHE] = &llecache_disk,
155 : : [DISK_TYPE_NBD] = &nbd_disk,
156 : : 0,
157 : : };
158 : :
159 : : extern struct tap_disk tapdisk_aio;
160 : : #if 0
161 : : extern struct tap_disk tapdisk_sync;
162 : : extern struct tap_disk tapdisk_vmdk;
163 : : extern struct tap_disk tapdisk_vhdsync;
164 : : #endif
165 : : extern struct tap_disk tapdisk_vhd;
166 : : extern struct tap_disk tapdisk_ram;
167 : : #if 0
168 : : extern struct tap_disk tapdisk_qcow;
169 : : #endif
170 : : extern struct tap_disk tapdisk_block_cache;
171 : : extern struct tap_disk tapdisk_vhd_index;
172 : : extern struct tap_disk tapdisk_log;
173 : : extern struct tap_disk tapdisk_lcache;
174 : : extern struct tap_disk tapdisk_llpcache;
175 : : extern struct tap_disk tapdisk_llecache;
176 : : extern struct tap_disk tapdisk_valve;
177 : : extern struct tap_disk tapdisk_nbd;
178 : :
179 : : const struct tap_disk *tapdisk_disk_drivers[] = {
180 : : [DISK_TYPE_AIO] = &tapdisk_aio,
181 : : #if 0
182 : : [DISK_TYPE_SYNC] = &tapdisk_sync,
183 : : [DISK_TYPE_VMDK] = &tapdisk_vmdk,
184 : : [DISK_TYPE_VHDSYNC] = &tapdisk_vhdsync_disk
185 : : #endif
186 : : [DISK_TYPE_VHD] = &tapdisk_vhd,
187 : : [DISK_TYPE_RAM] = &tapdisk_ram,
188 : : #if 0
189 : : [DISK_TYPE_QCOW] = &tapdisk_qcow,
190 : : #endif
191 : : [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache,
192 : : [DISK_TYPE_VINDEX] = &tapdisk_vhd_index,
193 : : [DISK_TYPE_LOG] = &tapdisk_log,
194 : : [DISK_TYPE_LCACHE] = &tapdisk_lcache,
195 : : [DISK_TYPE_LLPCACHE] = &tapdisk_llpcache,
196 : : [DISK_TYPE_LLECACHE] = &tapdisk_llecache,
197 : : [DISK_TYPE_VALVE] = &tapdisk_valve,
198 : : [DISK_TYPE_NBD] = &tapdisk_nbd,
199 : : 0,
200 : : };
201 : :
202 : : int
203 : 0 : tapdisk_disktype_find(const char *name)
204 : : {
205 : : int i;
206 : :
207 [ # # ]: 0 : for (i = 0; i < ARRAY_SIZE(tapdisk_disk_types); i++) {
208 : 0 : const disk_info_t *info = tapdisk_disk_types[i];
209 : :
210 [ # # ]: 0 : if (!info)
211 : 0 : continue;
212 : :
213 [ # # ]: 0 : if (strcmp(name, info->name))
214 : 0 : continue;
215 : :
216 [ # # ]: 0 : if (!tapdisk_disk_drivers[i])
217 : : return -ENOSYS;
218 : :
219 : 0 : return i;
220 : : }
221 : :
222 : : return -ENOENT;
223 : : }
224 : :
225 : : int
226 : 0 : tapdisk_disktype_parse_params(const char *params, const char **_path)
227 : : {
228 : : char name[DISK_TYPE_NAME_MAX], *ptr;
229 : : size_t len;
230 : : int type;
231 : :
232 : 0 : ptr = strchr(params, ':');
233 [ # # ]: 0 : if (!ptr)
234 : 0 : return -EINVAL;
235 : :
236 : 0 : len = ptr - params;
237 : :
238 [ # # ]: 0 : if (len > sizeof(name) - 1)
239 : : return -ENAMETOOLONG;
240 : :
241 : : memset(name, 0, sizeof(name));
242 : : /* Copy just the first part of the params substring to name */
243 : : strncpy(name, params, len);
244 : :
245 : 0 : type = tapdisk_disktype_find(name);
246 : :
247 : 0 : *_path = params + len + 1;
248 : :
249 : 0 : return type;
250 : : }
|