]> xenbits.xensource.com Git - xen.git/commitdiff
blktap2: Fix tapdisk disktype issues.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 8 Jun 2010 07:03:41 +0000 (08:03 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 8 Jun 2010 07:03:41 +0000 (08:03 +0100)
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>
23 files changed:
tools/blktap2/drivers/Makefile
tools/blktap2/drivers/block-qcow.c
tools/blktap2/drivers/block-remus.c
tools/blktap2/drivers/block-vhd.c
tools/blktap2/drivers/disktypes.h [deleted file]
tools/blktap2/drivers/img2qcow.c
tools/blktap2/drivers/qcow2raw.c
tools/blktap2/drivers/tapdisk-diff.c
tools/blktap2/drivers/tapdisk-disktype.c [new file with mode: 0644]
tools/blktap2/drivers/tapdisk-disktype.h [new file with mode: 0644]
tools/blktap2/drivers/tapdisk-driver.c
tools/blktap2/drivers/tapdisk-driver.h
tools/blktap2/drivers/tapdisk-image.c
tools/blktap2/drivers/tapdisk-image.h
tools/blktap2/drivers/tapdisk-server.c
tools/blktap2/drivers/tapdisk-stream.c
tools/blktap2/drivers/tapdisk-utils.c
tools/blktap2/drivers/tapdisk-utils.h
tools/blktap2/drivers/tapdisk-vbd.c
tools/blktap2/drivers/tapdisk-vbd.h
tools/blktap2/drivers/tapdisk.h
tools/blktap2/drivers/tapdisk2.c
tools/blktap2/include/tapdisk-message.h

index 56ddfd94d3f244710839fc38e3a25b3cc7bf043e..88d3a8c8b5fc4cf799982d3322f74856f26f4d21 100644 (file)
@@ -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
index 3e15d15682835f6501242db99cc309e6d97cf661..ac55ac938742f0bb32203477ecd407164f6ef2aa 100644 (file)
@@ -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"
index f6da984e274f5a0f0589410aef4d1f696411d62a..0af8189ae77d68b0841be8f0e0ea145734d56444 100644 (file)
@@ -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;
index 83db6e38ba1c4f3b5b9bf08a075e67b5f584fe95..649664a8a51cf3ccbd4f382cb857c36f76c826c8 100644 (file)
@@ -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 (file)
index 74a98d2..0000000
+++ /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
index 08f3335dbbf9e165802a4dff2685d80e596b777f..17a89296f991ca01cddf7ac716c26f0a9d5aaf37 100644 (file)
@@ -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"
 
index e581b1e40e2369c893dbae72b37ff56c06d46ae2..04cb26eae4ebe26db57d9cf3d1d2b0651e6aa228 100644 (file)
@@ -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
index 2c4994888da105c2ac3687f6c1064384f4e68773..1d2ba8e682bc65ce3896421688a26c373f18956e 100644 (file)
@@ -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 (file)
index 0000000..98379a6
--- /dev/null
@@ -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 (file)
index 0000000..61adc21
--- /dev/null
@@ -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
index ca5629ab7334fb14f651a5eda7f753b354108009..aa1ed15f40ad6a96676f132c9a02bb08b70ff006 100644 (file)
 
 #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;
 
index de0a9be23343c7eeb56c742a9d9a05982f952a29..42de05db1d620dde11d6a165a4df28113e7cd893 100644 (file)
@@ -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;
 };
index 2193ceddc660dec88082594d2d5bd3bf7631fb15..042cdd5ad2e447b6b2fff99641d69264eb07afd1 100644 (file)
@@ -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;
index 33b1b851c358e1f9918a56701a9ce67fbef97107..60375aeab213f57e21a3ba11416d1c105cabb3c4 100644 (file)
@@ -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);
index 869fa239a1a0f33330b8adb28ca63e7b27153f8e..73e9717815eb726878dda0eb019926fca97f76f3 100644 (file)
@@ -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"
 #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)
 {
index 4e0f9a8f12c0f8ffa9ea7fd1b73c1be4ffa770eb..1795abddfd9b98c6236d030221ef5f514e2f16ec 100644 (file)
@@ -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;
        }
index 757c0bdc775e82418eb3ab96dcaf59d4f5b30bb1..1b15f12154267c7179a6a12888f0e965a997fdd0 100644 (file)
@@ -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)
index 5e08aa83265c7ad626ceabcdced787f4a1e94b68..7b7c3d5e92524d75d66415c34bac9d725afcde79 100644 (file)
@@ -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);
 
index fee1bad68fcc7b92f56d7fdd9b4f880e04190df6..65300acbf97a36d82ba04e7c4bb8729145e80dfc 100644 (file)
@@ -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));
 
index 033a6b796d1a28b3f6cdeade2b7003984980d88a..3d26942582b69bebcc980e0498a5de85afb04faf 100644 (file)
@@ -80,7 +80,7 @@ struct td_vbd_request {
 };
 
 struct td_vbd_driver_info {
-       char                       *params;
+       const char                 *params;
        int                         type;
        struct list_head            next;
 };
index 460bc88d975e76a964ab4c7614b3148d4ac1e647..6625de0001e17edfafb314b9cb0123dbdda161a7 100644 (file)
@@ -61,7 +61,6 @@
 
 #include "list.h"
 #include "blktaplib.h"
-#include "disktypes.h"
 #include "tapdisk-log.h"
 #include "tapdisk-utils.h"
 
index 237b856dde7ef4cf346764515fb47908ab839427..0eb10cb5e546c320f9cafa7ca4e3e4951af4f209 100644 (file)
@@ -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("/");
index 1a86dcb6a31280a291ad321397374ab2f17e146f..dc622bd71d4f78be688488ba43e148333c77384b 100644 (file)
@@ -28,6 +28,7 @@
 #define _TAPDISK_MESSAGE_H_
 
 #include <inttypes.h>
+#include <sys/types.h>
 
 #define TAPDISK_MESSAGE_MAX_PATH_LENGTH  256
 #define TAPDISK_MESSAGE_STRING_LENGTH    256
@@ -67,7 +68,6 @@ struct tapdisk_message_string {
 struct tapdisk_message {
        uint16_t                         type;
        uint16_t                         cookie;
-       uint16_t                         drivertype;
 
        union {
                pid_t                    tapdisk_pid;