debuggers.hg

view tools/blktap2/drivers/tapdisk-disktype.c @ 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 9009f9f76441
children
line source
1 /*
2 * Copyright (c) 2007, 2010, 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 */
29 #include <stddef.h>
30 #include <string.h>
31 #include <errno.h>
33 #include "tapdisk-disktype.h"
34 #include "tapdisk-message.h"
36 static const disk_info_t aio_disk = {
37 "aio",
38 "raw image (aio)",
39 0,
40 };
42 static const disk_info_t sync_disk = {
43 "sync",
44 "raw image (sync)",
45 0,
46 };
48 static const disk_info_t vmdk_disk = {
49 "vmdk",
50 "vmware image (vmdk)",
51 1,
52 };
54 static const disk_info_t vhdsync_disk = {
55 "vhdsync",
56 "virtual server image (vhd) - synchronous",
57 1,
58 };
60 static const disk_info_t vhd_disk = {
61 "vhd",
62 "virtual server image (vhd)",
63 0,
64 };
67 static const disk_info_t ram_disk = {
68 "ram",
69 "ramdisk image (ram)",
70 1,
71 };
73 static const disk_info_t qcow_disk = {
74 "qcow",
75 "qcow disk (qcow)",
76 0,
77 };
79 static const disk_info_t block_cache_disk = {
80 "bc",
81 "block cache image (bc)",
82 1,
83 };
85 static const disk_info_t vhd_index_disk = {
86 "vhdi",
87 "vhd index image (vhdi)",
88 1,
89 };
91 static const disk_info_t log_disk = {
92 "log",
93 "write logger (log)",
94 0,
95 };
97 static disk_info_t remus_disk = {
98 "remus disk replicator (remus)",
99 "remus",
100 0,
101 };
103 const disk_info_t *tapdisk_disk_types[] = {
104 [DISK_TYPE_AIO] = &aio_disk,
105 [DISK_TYPE_SYNC] = &sync_disk,
106 [DISK_TYPE_VMDK] = &vmdk_disk,
107 [DISK_TYPE_VHDSYNC] = &vhdsync_disk,
108 [DISK_TYPE_VHD] = &vhd_disk,
109 [DISK_TYPE_RAM] = &ram_disk,
110 [DISK_TYPE_QCOW] = &qcow_disk,
111 [DISK_TYPE_BLOCK_CACHE] = &block_cache_disk,
112 [DISK_TYPE_LOG] = &log_disk,
113 [DISK_TYPE_VINDEX] = &vhd_index_disk,
114 [DISK_TYPE_REMUS] = &remus_disk,
115 0,
116 };
118 extern struct tap_disk tapdisk_aio;
119 extern struct tap_disk tapdisk_sync;
120 extern struct tap_disk tapdisk_vmdk;
121 extern struct tap_disk tapdisk_vhdsync;
122 extern struct tap_disk tapdisk_vhd;
123 extern struct tap_disk tapdisk_ram;
124 extern struct tap_disk tapdisk_qcow;
125 extern struct tap_disk tapdisk_block_cache;
126 extern struct tap_disk tapdisk_vhd_index;
127 extern struct tap_disk tapdisk_log;
128 extern struct tap_disk tapdisk_remus;
130 const struct tap_disk *tapdisk_disk_drivers[] = {
131 [DISK_TYPE_AIO] = &tapdisk_aio,
132 #if 0
133 [DISK_TYPE_SYNC] = &tapdisk_sync,
134 [DISK_TYPE_VMDK] = &tapdisk_vmdk,
135 #endif
136 [DISK_TYPE_VHD] = &tapdisk_vhd,
137 [DISK_TYPE_RAM] = &tapdisk_ram,
138 [DISK_TYPE_QCOW] = &tapdisk_qcow,
139 [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache,
140 [DISK_TYPE_VINDEX] = &tapdisk_vhd_index,
141 [DISK_TYPE_LOG] = &tapdisk_log,
142 [DISK_TYPE_REMUS] = &tapdisk_remus,
143 0,
144 };
146 int
147 tapdisk_disktype_find(const char *name)
148 {
149 const disk_info_t *info;
150 int i;
152 for (i = 0; info = tapdisk_disk_types[i], info != NULL; ++i) {
153 if (strcmp(name, info->name))
154 continue;
156 if (!tapdisk_disk_drivers[i])
157 return -ENOSYS;
159 return i;
160 }
162 return -ENOENT;
163 }
165 int
166 tapdisk_disktype_parse_params(const char *params, const char **_path)
167 {
168 char name[DISK_TYPE_NAME_MAX], *ptr;
169 size_t len;
170 int type;
172 ptr = strchr(params, ':');
173 if (!ptr)
174 return -EINVAL;
176 len = ptr - params;
178 if (len > sizeof(name) - 1)
179 return -ENAMETOOLONG;
181 memset(name, 0, sizeof(name));
182 strncpy(name, params, len);
184 type = tapdisk_disktype_find(name);
186 if (type >= 0)
187 *_path = params + len + 1;
189 return type;
190 }
192 int
193 tapdisk_parse_disk_type(const char *params, const char **_path, int *_type)
194 {
195 int type;
197 type = tapdisk_disktype_parse_params(params, _path);
198 if (type < 0)
199 return type;
201 *_type = type;
203 return 0;
204 }