aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap2/drivers
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-06-08 08:03:41 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-06-08 08:03:41 +0100
commit7b4dea5546ccfc984b33ab0e184bc054c02bd9f2 (patch)
tree25a7e58fa856298b165b1d1d8bf4246ec3ecca6e /tools/blktap2/drivers
parentf867b85581b3722c211e8a6bd082e9d39c79b02c (diff)
downloadxen-7b4dea5546ccfc984b33ab0e184bc054c02bd9f2.tar.gz
xen-7b4dea5546ccfc984b33ab0e184bc054c02bd9f2.tar.bz2
xen-7b4dea5546ccfc984b33ab0e184bc054c02bd9f2.zip
blktap2: Fix tapdisk disktype issues.
Stop coercing drivers/disktype code into the tool stack. Make both blktapctrl and tap-ctl transfer type/path pairs as "<type>:<path>" strings. Remove the message.disktype integer altogether. Signed-off-by: Daniel Stodden <daniel.stodden@citrix.com> Signed-off-by: Jake Wires <jake.wires@citrix.com>
Diffstat (limited to 'tools/blktap2/drivers')
-rw-r--r--tools/blktap2/drivers/Makefile1
-rw-r--r--tools/blktap2/drivers/block-qcow.c1
-rw-r--r--tools/blktap2/drivers/block-remus.c1
-rw-r--r--tools/blktap2/drivers/block-vhd.c1
-rw-r--r--tools/blktap2/drivers/disktypes.h197
-rw-r--r--tools/blktap2/drivers/img2qcow.c1
-rw-r--r--tools/blktap2/drivers/qcow2raw.c1
-rw-r--r--tools/blktap2/drivers/tapdisk-diff.c19
-rw-r--r--tools/blktap2/drivers/tapdisk-disktype.c204
-rw-r--r--tools/blktap2/drivers/tapdisk-disktype.h62
-rw-r--r--tools/blktap2/drivers/tapdisk-driver.c5
-rw-r--r--tools/blktap2/drivers/tapdisk-driver.h2
-rw-r--r--tools/blktap2/drivers/tapdisk-image.c2
-rw-r--r--tools/blktap2/drivers/tapdisk-image.h2
-rw-r--r--tools/blktap2/drivers/tapdisk-server.c13
-rw-r--r--tools/blktap2/drivers/tapdisk-stream.c10
-rw-r--r--tools/blktap2/drivers/tapdisk-utils.c40
-rw-r--r--tools/blktap2/drivers/tapdisk-utils.h1
-rw-r--r--tools/blktap2/drivers/tapdisk-vbd.c25
-rw-r--r--tools/blktap2/drivers/tapdisk-vbd.h2
-rw-r--r--tools/blktap2/drivers/tapdisk.h1
-rw-r--r--tools/blktap2/drivers/tapdisk2.c3
22 files changed, 311 insertions, 283 deletions
diff --git a/tools/blktap2/drivers/Makefile b/tools/blktap2/drivers/Makefile
index 56ddfd94d3..88d3a8c8b5 100644
--- a/tools/blktap2/drivers/Makefile
+++ b/tools/blktap2/drivers/Makefile
@@ -65,6 +65,7 @@ TAP-OBJS-y := scheduler.o
TAP-OBJS-y += tapdisk-vbd.o
TAP-OBJS-y += tapdisk-image.o
TAP-OBJS-y += tapdisk-driver.o
+TAP-OBJS-y += tapdisk-disktype.o
TAP-OBJS-y += tapdisk-interface.o
TAP-OBJS-y += tapdisk-server.o
TAP-OBJS-y += tapdisk-queue.o
diff --git a/tools/blktap2/drivers/block-qcow.c b/tools/blktap2/drivers/block-qcow.c
index 3e15d15682..ac55ac9387 100644
--- a/tools/blktap2/drivers/block-qcow.c
+++ b/tools/blktap2/drivers/block-qcow.c
@@ -41,6 +41,7 @@
#include "tapdisk.h"
#include "tapdisk-driver.h"
#include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
#include "qcow.h"
#include "blk.h"
#include "atomicio.h"
diff --git a/tools/blktap2/drivers/block-remus.c b/tools/blktap2/drivers/block-remus.c
index f6da984e27..0af8189ae7 100644
--- a/tools/blktap2/drivers/block-remus.c
+++ b/tools/blktap2/drivers/block-remus.c
@@ -98,6 +98,7 @@ struct req_ring {
*/
td_vbd_t *device_vbd = NULL;
td_image_t *remus_image = NULL;
+struct tap_disk tapdisk_remus;
struct ramdisk {
size_t sector_size;
diff --git a/tools/blktap2/drivers/block-vhd.c b/tools/blktap2/drivers/block-vhd.c
index 83db6e38ba..649664a8a5 100644
--- a/tools/blktap2/drivers/block-vhd.c
+++ b/tools/blktap2/drivers/block-vhd.c
@@ -58,6 +58,7 @@
#include "tapdisk.h"
#include "tapdisk-driver.h"
#include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
unsigned int SPB;
diff --git a/tools/blktap2/drivers/disktypes.h b/tools/blktap2/drivers/disktypes.h
deleted file mode 100644
index 74a98d2c34..0000000000
--- a/tools/blktap2/drivers/disktypes.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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 __DISKTYPES_H__
-#define __DISKTYPES_H__
-
-typedef struct disk_info {
- int idnum;
- char name[50]; /* e.g. "RAMDISK" */
- char handle[10]; /* xend handle, e.g. 'ram' */
- int single_handler; /* is there a single controller for all */
- /* instances of disk type? */
-#ifdef TAPDISK
- struct tap_disk *drv;
-#endif
-} disk_info_t;
-
-extern struct tap_disk tapdisk_aio;
-/* extern struct tap_disk tapdisk_sync; */
-/* extern struct tap_disk tapdisk_vmdk; */
-/* extern struct tap_disk tapdisk_vhdsync; */
-extern struct tap_disk tapdisk_vhd;
-extern struct tap_disk tapdisk_ram;
- extern struct tap_disk tapdisk_qcow;
-extern struct tap_disk tapdisk_block_cache;
-extern struct tap_disk tapdisk_log;
-extern struct tap_disk tapdisk_remus;
-
-#define MAX_DISK_TYPES 20
-
-#define DISK_TYPE_AIO 0
-#define DISK_TYPE_SYNC 1
-#define DISK_TYPE_VMDK 2
-#define DISK_TYPE_VHDSYNC 3
-#define DISK_TYPE_VHD 4
-#define DISK_TYPE_RAM 5
-#define DISK_TYPE_QCOW 6
-#define DISK_TYPE_BLOCK_CACHE 7
-#define DISK_TYPE_LOG 9
-#define DISK_TYPE_REMUS 10
-
-/*Define Individual Disk Parameters here */
-static disk_info_t null_disk = {
- -1,
- "null disk",
- "null",
- 0,
-#ifdef TAPDISK
- 0,
-#endif
-};
-
-static disk_info_t aio_disk = {
- DISK_TYPE_AIO,
- "raw image (aio)",
- "aio",
- 0,
-#ifdef TAPDISK
- &tapdisk_aio,
-#endif
-};
-/*
-static disk_info_t sync_disk = {
- DISK_TYPE_SYNC,
- "raw image (sync)",
- "sync",
- 0,
-#ifdef TAPDISK
- &tapdisk_sync,
-#endif
-};
-
-static disk_info_t vmdk_disk = {
- DISK_TYPE_VMDK,
- "vmware image (vmdk)",
- "vmdk",
- 1,
-#ifdef TAPDISK
- &tapdisk_vmdk,
-#endif
-};
-
-static disk_info_t vhdsync_disk = {
- DISK_TYPE_VHDSYNC,
- "virtual server image (vhd) - synchronous",
- "vhdsync",
- 1,
-#ifdef TAPDISK
- &tapdisk_vhdsync,
-#endif
-};
-*/
-
-static disk_info_t vhd_disk = {
- DISK_TYPE_VHD,
- "virtual server image (vhd)",
- "vhd",
- 0,
-#ifdef TAPDISK
- &tapdisk_vhd,
-#endif
-};
-
-
-static disk_info_t ram_disk = {
- DISK_TYPE_RAM,
- "ramdisk image (ram)",
- "ram",
- 1,
-#ifdef TAPDISK
- &tapdisk_ram,
-#endif
-};
-
-
-static disk_info_t qcow_disk = {
- DISK_TYPE_QCOW,
- "qcow disk (qcow)",
- "qcow",
- 0,
-#ifdef TAPDISK
- &tapdisk_qcow,
-#endif
-};
-
-
-static disk_info_t block_cache_disk = {
- DISK_TYPE_BLOCK_CACHE,
- "block cache image (bc)",
- "bc",
- 1,
-#ifdef TAPDISK
- &tapdisk_block_cache,
-#endif
-};
-
-static disk_info_t log_disk = {
- DISK_TYPE_LOG,
- "write logger (log)",
- "log",
- 0,
-#ifdef TAPDISK
- &tapdisk_log,
-#endif
-};
-
-static disk_info_t remus_disk = {
- DISK_TYPE_REMUS,
- "remus disk replicator (remus)",
- "remus",
- 0,
-#ifdef TAPDISK
- &tapdisk_remus,
-#endif
-};
-
-/*Main disk info array */
-static disk_info_t *dtypes[] = {
- &aio_disk,
- &null_disk, /* &sync_disk, */
- &null_disk, /* &vmdk_disk, */
- &null_disk, /* &vhdsync_disk, */
- &vhd_disk,
- &ram_disk,
- &qcow_disk,
- &block_cache_disk,
- &null_disk,
- &log_disk,
- &remus_disk,
-};
-
-#endif
diff --git a/tools/blktap2/drivers/img2qcow.c b/tools/blktap2/drivers/img2qcow.c
index 08f3335dbb..17a89296f9 100644
--- a/tools/blktap2/drivers/img2qcow.c
+++ b/tools/blktap2/drivers/img2qcow.c
@@ -48,6 +48,7 @@
#include "tapdisk-server.h"
#include "tapdisk-driver.h"
#include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
#include "qcow.h"
#include "blk.h"
diff --git a/tools/blktap2/drivers/qcow2raw.c b/tools/blktap2/drivers/qcow2raw.c
index e581b1e40e..04cb26eae4 100644
--- a/tools/blktap2/drivers/qcow2raw.c
+++ b/tools/blktap2/drivers/qcow2raw.c
@@ -47,6 +47,7 @@
#include "tapdisk-server.h"
#include "tapdisk-driver.h"
#include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
#include "qcow.h"
#if 1
diff --git a/tools/blktap2/drivers/tapdisk-diff.c b/tools/blktap2/drivers/tapdisk-diff.c
index 2c4994888d..1d2ba8e682 100644
--- a/tools/blktap2/drivers/tapdisk-diff.c
+++ b/tools/blktap2/drivers/tapdisk-diff.c
@@ -38,6 +38,7 @@
#include "scheduler.h"
#include "tapdisk-vbd.h"
#include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
#include "libvhd.h"
#define POLL_READ 0
@@ -670,11 +671,11 @@ static int
tapdisk_stream_open(struct tapdisk_stream *s, const char *arg)
{
int err, type;
- char *path;
+ const char *path;
- err = tapdisk_parse_disk_type(arg, &path, &type);
- if (err)
- return err;
+ type = tapdisk_disktype_parse_params(arg, &path);
+ if (type < 0)
+ return type;
tapdisk_stream_initialize(s);
@@ -716,7 +717,8 @@ main(int argc, char *argv[])
{
int c, err, type1;
const char *arg1 = NULL, *arg2 = NULL;
- char *path1;
+ const disk_info_t *info;
+ const char *path1;
err = 0;
@@ -741,9 +743,10 @@ main(int argc, char *argv[])
if (!arg1 || !arg2)
goto fail_usage;
- err = tapdisk_parse_disk_type(arg1, &path1, &type1);
- if (err)
- return err;
+ type1 = tapdisk_disktype_parse_params(arg1, &path1);
+ if (type1 < 0)
+ return type1;
+
if (type1 != DISK_TYPE_VHD) {
printf("error: first VDI is not VHD\n");
return EINVAL;
diff --git a/tools/blktap2/drivers/tapdisk-disktype.c b/tools/blktap2/drivers/tapdisk-disktype.c
new file mode 100644
index 0000000000..98379a6d8b
--- /dev/null
+++ b/tools/blktap2/drivers/tapdisk-disktype.c
@@ -0,0 +1,204 @@
+/*
+ * Copyright (c) 2007, 2010, 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.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+
+#include "tapdisk-disktype.h"
+#include "tapdisk-message.h"
+
+static const disk_info_t aio_disk = {
+ "aio",
+ "raw image (aio)",
+ 0,
+};
+
+static const disk_info_t sync_disk = {
+ "sync",
+ "raw image (sync)",
+ 0,
+};
+
+static const disk_info_t vmdk_disk = {
+ "vmdk",
+ "vmware image (vmdk)",
+ 1,
+};
+
+static const disk_info_t vhdsync_disk = {
+ "vhdsync",
+ "virtual server image (vhd) - synchronous",
+ 1,
+};
+
+static const disk_info_t vhd_disk = {
+ "vhd",
+ "virtual server image (vhd)",
+ 0,
+};
+
+
+static const disk_info_t ram_disk = {
+ "ram",
+ "ramdisk image (ram)",
+ 1,
+};
+
+static const disk_info_t qcow_disk = {
+ "qcow",
+ "qcow disk (qcow)",
+ 0,
+};
+
+static const disk_info_t block_cache_disk = {
+ "bc",
+ "block cache image (bc)",
+ 1,
+};
+
+static const disk_info_t vhd_index_disk = {
+ "vhdi",
+ "vhd index image (vhdi)",
+ 1,
+};
+
+static const disk_info_t log_disk = {
+ "log",
+ "write logger (log)",
+ 0,
+};
+
+static disk_info_t remus_disk = {
+ "remus disk replicator (remus)",
+ "remus",
+ 0,
+};
+
+const disk_info_t *tapdisk_disk_types[] = {
+ [DISK_TYPE_AIO] = &aio_disk,
+ [DISK_TYPE_SYNC] = &sync_disk,
+ [DISK_TYPE_VMDK] = &vmdk_disk,
+ [DISK_TYPE_VHDSYNC] = &vhdsync_disk,
+ [DISK_TYPE_VHD] = &vhd_disk,
+ [DISK_TYPE_RAM] = &ram_disk,
+ [DISK_TYPE_QCOW] = &qcow_disk,
+ [DISK_TYPE_BLOCK_CACHE] = &block_cache_disk,
+ [DISK_TYPE_LOG] = &log_disk,
+ [DISK_TYPE_VINDEX] = &vhd_index_disk,
+ [DISK_TYPE_REMUS] = &remus_disk,
+ 0,
+};
+
+extern struct tap_disk tapdisk_aio;
+extern struct tap_disk tapdisk_sync;
+extern struct tap_disk tapdisk_vmdk;
+extern struct tap_disk tapdisk_vhdsync;
+extern struct tap_disk tapdisk_vhd;
+extern struct tap_disk tapdisk_ram;
+extern struct tap_disk tapdisk_qcow;
+extern struct tap_disk tapdisk_block_cache;
+extern struct tap_disk tapdisk_vhd_index;
+extern struct tap_disk tapdisk_log;
+extern struct tap_disk tapdisk_remus;
+
+const struct tap_disk *tapdisk_disk_drivers[] = {
+ [DISK_TYPE_AIO] = &tapdisk_aio,
+#if 0
+ [DISK_TYPE_SYNC] = &tapdisk_sync,
+ [DISK_TYPE_VMDK] = &tapdisk_vmdk,
+#endif
+ [DISK_TYPE_VHD] = &tapdisk_vhd,
+ [DISK_TYPE_RAM] = &tapdisk_ram,
+ [DISK_TYPE_QCOW] = &tapdisk_qcow,
+ [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache,
+ [DISK_TYPE_VINDEX] = &tapdisk_vhd_index,
+ [DISK_TYPE_LOG] = &tapdisk_log,
+ [DISK_TYPE_REMUS] = &tapdisk_remus,
+ 0,
+};
+
+int
+tapdisk_disktype_find(const char *name)
+{
+ const disk_info_t *info;
+ int i;
+
+ for (i = 0; info = tapdisk_disk_types[i], info != NULL; ++i) {
+ if (strcmp(name, info->name))
+ continue;
+
+ if (!tapdisk_disk_drivers[i])
+ return -ENOSYS;
+
+ return i;
+ }
+
+ return -ENOENT;
+}
+
+int
+tapdisk_disktype_parse_params(const char *params, const char **_path)
+{
+ char name[DISK_TYPE_NAME_MAX], *ptr;
+ size_t len;
+ int type;
+
+ ptr = strchr(params, ':');
+ if (!ptr)
+ return -EINVAL;
+
+ len = ptr - params;
+
+ if (len > sizeof(name) - 1)
+ return -ENAMETOOLONG;
+
+ memset(name, 0, sizeof(name));
+ strncpy(name, params, len);
+
+ type = tapdisk_disktype_find(name);
+
+ if (type >= 0)
+ *_path = params + len + 1;
+
+ return type;
+}
+
+int
+tapdisk_parse_disk_type(const char *params, const char **_path, int *_type)
+{
+ int type;
+
+ type = tapdisk_disktype_parse_params(params, _path);
+ if (type < 0)
+ return type;
+
+ *_type = type;
+
+ return 0;
+}
diff --git a/tools/blktap2/drivers/tapdisk-disktype.h b/tools/blktap2/drivers/tapdisk-disktype.h
new file mode 100644
index 0000000000..61adc21e55
--- /dev/null
+++ b/tools/blktap2/drivers/tapdisk-disktype.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2007, 2010, 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 __DISKTYPES_H__
+#define __DISKTYPES_H__
+
+#define DISK_TYPE_AIO 0
+#define DISK_TYPE_SYNC 1
+#define DISK_TYPE_VMDK 2
+#define DISK_TYPE_VHDSYNC 3
+#define DISK_TYPE_VHD 4
+#define DISK_TYPE_RAM 5
+#define DISK_TYPE_QCOW 6
+#define DISK_TYPE_BLOCK_CACHE 7
+#define DISK_TYPE_LOG 9
+#define DISK_TYPE_REMUS 10
+#define DISK_TYPE_VINDEX 11
+
+#define DISK_TYPE_NAME_MAX 32
+
+typedef struct disk_info {
+ const char *name; /* driver name, e.g. 'aio' */
+ char *desc; /* e.g. "raw image" */
+ unsigned int flags;
+} disk_info_t;
+
+extern const disk_info_t *tapdisk_disk_types[];
+extern const struct tap_disk *tapdisk_disk_drivers[];
+
+/* one single controller for all instances of disk type */
+#define DISK_TYPE_SINGLE_CONTROLLER (1<<0)
+
+int tapdisk_disktype_find(const char *name);
+int tapdisk_disktype_parse_params(const char *params, const char **_path);
+int tapdisk_parse_disk_type(const char *, const char **, int *);
+
+#endif
diff --git a/tools/blktap2/drivers/tapdisk-driver.c b/tools/blktap2/drivers/tapdisk-driver.c
index ca5629ab73..aa1ed15f40 100644
--- a/tools/blktap2/drivers/tapdisk-driver.c
+++ b/tools/blktap2/drivers/tapdisk-driver.c
@@ -29,15 +29,16 @@
#include "tapdisk-driver.h"
#include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
td_driver_t *
tapdisk_driver_allocate(int type, char *name, td_flag_t flags, int storage)
{
int err;
td_driver_t *driver;
- struct tap_disk *ops;
+ const struct tap_disk *ops;
- ops = tapdisk_server_find_driver_interface(type);
+ ops = tapdisk_disk_drivers[type];
if (!ops)
return NULL;
diff --git a/tools/blktap2/drivers/tapdisk-driver.h b/tools/blktap2/drivers/tapdisk-driver.h
index de0a9be233..42de05db1d 100644
--- a/tools/blktap2/drivers/tapdisk-driver.h
+++ b/tools/blktap2/drivers/tapdisk-driver.h
@@ -47,7 +47,7 @@ struct td_driver_handle {
td_disk_info_t info;
void *data;
- struct tap_disk *ops;
+ const struct tap_disk *ops;
struct list_head next;
};
diff --git a/tools/blktap2/drivers/tapdisk-image.c b/tools/blktap2/drivers/tapdisk-image.c
index 2193ceddc6..042cdd5ad2 100644
--- a/tools/blktap2/drivers/tapdisk-image.c
+++ b/tools/blktap2/drivers/tapdisk-image.c
@@ -39,7 +39,7 @@
#define ERR(_err, _f, _a...) tlog_error(_err, _f, ##_a)
td_image_t *
-tapdisk_image_allocate(char *file, int type, int storage,
+tapdisk_image_allocate(const char *file, int type, int storage,
td_flag_t flags, void *private)
{
int err;
diff --git a/tools/blktap2/drivers/tapdisk-image.h b/tools/blktap2/drivers/tapdisk-image.h
index 33b1b851c3..60375aeab2 100644
--- a/tools/blktap2/drivers/tapdisk-image.h
+++ b/tools/blktap2/drivers/tapdisk-image.h
@@ -47,7 +47,7 @@ struct td_image_handle {
struct list_head next;
};
-td_image_t *tapdisk_image_allocate(char *, int, int, td_flag_t, void *);
+td_image_t *tapdisk_image_allocate(const char *, int, int, td_flag_t, void *);
void tapdisk_image_free(td_image_t *);
int tapdisk_image_check_td_request(td_image_t *, td_request_t);
diff --git a/tools/blktap2/drivers/tapdisk-server.c b/tools/blktap2/drivers/tapdisk-server.c
index 869fa239a1..73e9717815 100644
--- a/tools/blktap2/drivers/tapdisk-server.c
+++ b/tools/blktap2/drivers/tapdisk-server.c
@@ -32,7 +32,6 @@
#include <sys/ioctl.h>
#include <sys/signal.h>
-#define TAPDISK
#include "tapdisk-utils.h"
#include "tapdisk-server.h"
#include "tapdisk-driver.h"
@@ -46,18 +45,6 @@
#define tapdisk_server_for_each_vbd(vbd, tmp) \
list_for_each_entry_safe(vbd, tmp, &server.vbds, next)
-struct tap_disk *
-tapdisk_server_find_driver_interface(int type)
-{
- int n;
-
- n = sizeof(dtypes) / sizeof(struct disk_info_t *);
- if (type >= n)
- return NULL;
-
- return dtypes[type]->drv;
-}
-
td_image_t *
tapdisk_server_get_shared_image(td_image_t *image)
{
diff --git a/tools/blktap2/drivers/tapdisk-stream.c b/tools/blktap2/drivers/tapdisk-stream.c
index 4e0f9a8f12..1795abddfd 100644
--- a/tools/blktap2/drivers/tapdisk-stream.c
+++ b/tools/blktap2/drivers/tapdisk-stream.c
@@ -37,6 +37,7 @@
#include "scheduler.h"
#include "tapdisk-vbd.h"
#include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
#define POLL_READ 0
#define POLL_WRITE 1
@@ -545,7 +546,9 @@ int
main(int argc, char *argv[])
{
int c, err, type;
- char *params, *path;
+ const char *params;
+ const disk_info_t *info;
+ const char *path;
uint64_t count, skip;
struct tapdisk_stream stream;
@@ -575,8 +578,9 @@ main(int argc, char *argv[])
if (!params)
usage(argv[0], EINVAL);
- err = tapdisk_parse_disk_type(params, &path, &type);
- if (err) {
+ type = tapdisk_disktype_parse_params(params, &path);
+ if (type < 0) {
+ err = type;
fprintf(stderr, "invalid argument %s: %d\n", params, err);
return err;
}
diff --git a/tools/blktap2/drivers/tapdisk-utils.c b/tools/blktap2/drivers/tapdisk-utils.c
index 757c0bdc77..1b15f12154 100644
--- a/tools/blktap2/drivers/tapdisk-utils.c
+++ b/tools/blktap2/drivers/tapdisk-utils.c
@@ -40,7 +40,6 @@
#include "blk.h"
#include "tapdisk.h"
-#include "disktypes.h"
#include "blktaplib.h"
#include "tapdisk-log.h"
#include "tapdisk-utils.h"
@@ -108,45 +107,6 @@ tapdisk_namedup(char **dup, const char *name)
return 0;
}
-int
-tapdisk_parse_disk_type(const char *params, char **_path, int *_type)
-{
- int i, err, size, handle_len;
- char *ptr, *path, handle[10];
-
- if (strlen(params) + 1 >= MAX_NAME_LEN)
- return -ENAMETOOLONG;
-
- ptr = strchr(params, ':');
- if (!ptr)
- return -EINVAL;
-
- path = ptr + 1;
-
- handle_len = ptr - params;
- if (handle_len > sizeof(handle))
- return -ENAMETOOLONG;
-
- memcpy(handle, params, handle_len);
- handle[handle_len] = '\0';
-
- size = sizeof(dtypes) / sizeof(disk_info_t *);
- for (i = 0; i < size; i++) {
- if (strncmp(handle, dtypes[i]->handle, handle_len))
- continue;
-
- if (dtypes[i]->idnum == -1)
- return -ENODEV;
-
- *_type = dtypes[i]->idnum;
- *_path = path;
-
- return 0;
- }
-
- return -ENODEV;
-}
-
/*Get Image size, secsize*/
int
tapdisk_get_image_size(int fd, uint64_t *_sectors, uint32_t *_sector_size)
diff --git a/tools/blktap2/drivers/tapdisk-utils.h b/tools/blktap2/drivers/tapdisk-utils.h
index 5e08aa8326..7b7c3d5e92 100644
--- a/tools/blktap2/drivers/tapdisk-utils.h
+++ b/tools/blktap2/drivers/tapdisk-utils.h
@@ -36,7 +36,6 @@ void tapdisk_start_logging(const char *);
void tapdisk_stop_logging(void);
int tapdisk_set_resource_limits(void);
int tapdisk_namedup(char **, const char *);
-int tapdisk_parse_disk_type(const char *, char **, int *);
int tapdisk_get_image_size(int, uint64_t *, uint32_t *);
int tapdisk_linux_version(void);
diff --git a/tools/blktap2/drivers/tapdisk-vbd.c b/tools/blktap2/drivers/tapdisk-vbd.c
index fee1bad68f..65300acbf9 100644
--- a/tools/blktap2/drivers/tapdisk-vbd.c
+++ b/tools/blktap2/drivers/tapdisk-vbd.c
@@ -43,6 +43,7 @@
#include "tapdisk-driver.h"
#include "tapdisk-server.h"
#include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
#include "tapdisk-vbd.h"
#include "blktap2.h"
@@ -282,9 +283,9 @@ fail:
/* TODO: ugh, lets not call it parent info... */
static struct list_head *
-tapdisk_vbd_open_level(td_vbd_t *vbd, char* params, int driver_type, td_disk_info_t *parent_info, td_flag_t flags)
+tapdisk_vbd_open_level(td_vbd_t *vbd, const char* params, int driver_type, td_disk_info_t *parent_info, td_flag_t flags)
{
- char *name;
+ const char *name;
int type, err;
td_image_t *image;
td_disk_id_t id;
@@ -294,19 +295,16 @@ tapdisk_vbd_open_level(td_vbd_t *vbd, char* params, int driver_type, td_disk_inf
images = calloc(1, sizeof(struct list_head));
INIT_LIST_HEAD(images);
- name = params;
- type = driver_type;
+ name = params;
+ id.name = NULL;
+ type = driver_type;
for (;;) {
err = -ENOMEM;
image = tapdisk_image_allocate(name, type,
vbd->storage, flags, vbd);
- /* free 'name' if it was created by td_get_parent_id() */
- if (name != params) {
- free(name);
- name = NULL;
- }
+ free(id.name);
if (!image)
return NULL;
@@ -382,7 +380,7 @@ tapdisk_vbd_open_level(td_vbd_t *vbd, char* params, int driver_type, td_disk_inf
static int
__tapdisk_vbd_open_vdi(td_vbd_t *vbd, td_flag_t extra_flags)
{
- char *file;
+ const char *file;
int err, type;
td_flag_t flags;
td_disk_id_t id;
@@ -524,9 +522,9 @@ tapdisk_vbd_open_vdi(td_vbd_t *vbd, const char *path,
uint16_t drivertype, uint16_t storage, td_flag_t flags)
{
int i, err;
- struct tap_disk *ops;
+ const struct tap_disk *ops;
- ops = tapdisk_server_find_driver_interface(drivertype);
+ ops = tapdisk_disk_drivers[drivertype];
if (!ops)
return -EINVAL;
DPRINTF("Loaded %s driver for vbd %u %s 0x%08x\n",
@@ -1573,7 +1571,8 @@ static int
tapdisk_vbd_resume_ring(td_vbd_t *vbd)
{
int i, err, type;
- char *path, message[BLKTAP2_MAX_MESSAGE_LEN];
+ char message[BLKTAP2_MAX_MESSAGE_LEN];
+ const char *path;
memset(message, 0, sizeof(message));
diff --git a/tools/blktap2/drivers/tapdisk-vbd.h b/tools/blktap2/drivers/tapdisk-vbd.h
index 033a6b796d..3d26942582 100644
--- a/tools/blktap2/drivers/tapdisk-vbd.h
+++ b/tools/blktap2/drivers/tapdisk-vbd.h
@@ -80,7 +80,7 @@ struct td_vbd_request {
};
struct td_vbd_driver_info {
- char *params;
+ const char *params;
int type;
struct list_head next;
};
diff --git a/tools/blktap2/drivers/tapdisk.h b/tools/blktap2/drivers/tapdisk.h
index 460bc88d97..6625de0001 100644
--- a/tools/blktap2/drivers/tapdisk.h
+++ b/tools/blktap2/drivers/tapdisk.h
@@ -61,7 +61,6 @@
#include "list.h"
#include "blktaplib.h"
-#include "disktypes.h"
#include "tapdisk-log.h"
#include "tapdisk-utils.h"
diff --git a/tools/blktap2/drivers/tapdisk2.c b/tools/blktap2/drivers/tapdisk2.c
index 237b856dde..0eb10cb5e5 100644
--- a/tools/blktap2/drivers/tapdisk2.c
+++ b/tools/blktap2/drivers/tapdisk2.c
@@ -43,6 +43,7 @@
#include "tapdisk-vbd.h"
#include "tapdisk-utils.h"
#include "tapdisk-server.h"
+#include "tapdisk-disktype.h"
#define TAPDISK2_VBD 0
@@ -327,7 +328,7 @@ tapdisk2_set_child_fds(void)
static int
tapdisk2_create_device(const char *params)
{
- char *path;
+ const char *path;
int err, type;
chdir("/");