WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] blktap2: Fix tapdisk disktype issues.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] blktap2: Fix tapdisk disktype issues.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Jun 2010 00:00:52 -0700
Delivery-date: Wed, 09 Jun 2010 00:01:32 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1275980621 -3600
# Node ID 9009f9f76441e37077258fd9d7b4d84cfc42599d
# Parent  0391f15da2f31841de082a45e081009081fe9ab0
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@xxxxxxxxxx>
Signed-off-by: Jake Wires <jake.wires@xxxxxxxxxx>
---
 tools/blktap2/drivers/disktypes.h        |  197 -----------------------------
 tools/blktap2/drivers/Makefile           |    1 
 tools/blktap2/drivers/block-qcow.c       |    1 
 tools/blktap2/drivers/block-remus.c      |    1 
 tools/blktap2/drivers/block-vhd.c        |    1 
 tools/blktap2/drivers/img2qcow.c         |    1 
 tools/blktap2/drivers/qcow2raw.c         |    1 
 tools/blktap2/drivers/tapdisk-diff.c     |   21 +--
 tools/blktap2/drivers/tapdisk-disktype.c |  204 +++++++++++++++++++++++++++++++
 tools/blktap2/drivers/tapdisk-disktype.h |   62 +++++++++
 tools/blktap2/drivers/tapdisk-driver.c   |    5 
 tools/blktap2/drivers/tapdisk-driver.h   |    2 
 tools/blktap2/drivers/tapdisk-image.c    |    2 
 tools/blktap2/drivers/tapdisk-image.h    |    2 
 tools/blktap2/drivers/tapdisk-server.c   |   13 -
 tools/blktap2/drivers/tapdisk-stream.c   |   10 +
 tools/blktap2/drivers/tapdisk-utils.c    |   40 ------
 tools/blktap2/drivers/tapdisk-utils.h    |    1 
 tools/blktap2/drivers/tapdisk-vbd.c      |   29 ++--
 tools/blktap2/drivers/tapdisk-vbd.h      |    2 
 tools/blktap2/drivers/tapdisk.h          |    1 
 tools/blktap2/drivers/tapdisk2.c         |    3 
 tools/blktap2/include/tapdisk-message.h  |    2 
 23 files changed, 315 insertions(+), 287 deletions(-)

diff -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/Makefile
--- a/tools/blktap2/drivers/Makefile    Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/Makefile    Tue Jun 08 08:03:41 2010 +0100
@@ -65,6 +65,7 @@ TAP-OBJS-y  += tapdisk-vbd.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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/block-qcow.c
--- a/tools/blktap2/drivers/block-qcow.c        Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/block-qcow.c        Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/block-remus.c
--- a/tools/blktap2/drivers/block-remus.c       Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/block-remus.c       Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/block-vhd.c
--- a/tools/blktap2/drivers/block-vhd.c Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/block-vhd.c Tue Jun 08 08:03:41 2010 +0100
@@ -58,6 +58,7 @@
 #include "tapdisk.h"
 #include "tapdisk-driver.h"
 #include "tapdisk-interface.h"
+#include "tapdisk-disktype.h"
 
 unsigned int SPB;
 
diff -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/disktypes.h
--- a/tools/blktap2/drivers/disktypes.h Tue Jun 08 08:02:56 2010 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/img2qcow.c
--- a/tools/blktap2/drivers/img2qcow.c  Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/img2qcow.c  Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/qcow2raw.c
--- a/tools/blktap2/drivers/qcow2raw.c  Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/qcow2raw.c  Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-diff.c
--- a/tools/blktap2/drivers/tapdisk-diff.c      Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-diff.c      Tue Jun 08 08:03:41 2010 +0100
@@ -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 @@ tapdisk_stream_open(struct tapdisk_strea
 tapdisk_stream_open(struct tapdisk_stream *s, const char *arg)
 {
        int err, type;
-       char *path;
-
-       err = tapdisk_parse_disk_type(arg, &path, &type);
-       if (err)
-               return err;
+       const char *path;
+
+       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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-disktype.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/drivers/tapdisk-disktype.c  Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-disktype.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/blktap2/drivers/tapdisk-disktype.h  Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-driver.c
--- a/tools/blktap2/drivers/tapdisk-driver.c    Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-driver.c    Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-driver.h
--- a/tools/blktap2/drivers/tapdisk-driver.h    Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-driver.h    Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-image.c
--- a/tools/blktap2/drivers/tapdisk-image.c     Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-image.c     Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-image.h
--- a/tools/blktap2/drivers/tapdisk-image.h     Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-image.h     Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-server.c
--- a/tools/blktap2/drivers/tapdisk-server.c    Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-server.c    Tue Jun 08 08:03:41 2010 +0100
@@ -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"
@@ -45,18 +44,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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-stream.c
--- a/tools/blktap2/drivers/tapdisk-stream.c    Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-stream.c    Tue Jun 08 08:03:41 2010 +0100
@@ -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 @@ main(int argc, char *argv[])
 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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-utils.c
--- a/tools/blktap2/drivers/tapdisk-utils.c     Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-utils.c     Tue Jun 08 08:03:41 2010 +0100
@@ -40,7 +40,6 @@
 
 #include "blk.h"
 #include "tapdisk.h"
-#include "disktypes.h"
 #include "blktaplib.h"
 #include "tapdisk-log.h"
 #include "tapdisk-utils.h"
@@ -106,45 +105,6 @@ tapdisk_namedup(char **dup, const char *
                return -ENOMEM;
 
        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*/
diff -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-utils.h
--- a/tools/blktap2/drivers/tapdisk-utils.h     Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-utils.h     Tue Jun 08 08:03:41 2010 +0100
@@ -36,7 +36,6 @@ void tapdisk_stop_logging(void);
 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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-vbd.c
--- a/tools/blktap2/drivers/tapdisk-vbd.c       Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-vbd.c       Tue Jun 08 08:03:41 2010 +0100
@@ -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)
-{
-       char *name;
+tapdisk_vbd_open_level(td_vbd_t *vbd, const char* params, int driver_type, 
td_disk_info_t *parent_info, td_flag_t flags)
+{
+       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, ch
        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 @@ static int
 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, cons
                     uint16_t drivertype, uint16_t storage, td_flag_t flags)
 {
        int i, err;
-       struct tap_disk *ops;
-
-       ops = tapdisk_server_find_driver_interface(drivertype);
+       const struct tap_disk *ops;
+
+       ops = tapdisk_disk_drivers[drivertype];
        if (!ops)
                return -EINVAL;
        DPRINTF("Loaded %s driver for vbd %u %s 0x%08x\n",
@@ -1573,7 +1571,8 @@ tapdisk_vbd_resume_ring(td_vbd_t *vbd)
 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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk-vbd.h
--- a/tools/blktap2/drivers/tapdisk-vbd.h       Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk-vbd.h       Tue Jun 08 08:03:41 2010 +0100
@@ -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 -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk.h
--- a/tools/blktap2/drivers/tapdisk.h   Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk.h   Tue Jun 08 08:03:41 2010 +0100
@@ -61,7 +61,6 @@
 
 #include "list.h"
 #include "blktaplib.h"
-#include "disktypes.h"
 #include "tapdisk-log.h"
 #include "tapdisk-utils.h"
 
diff -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/drivers/tapdisk2.c
--- a/tools/blktap2/drivers/tapdisk2.c  Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/drivers/tapdisk2.c  Tue Jun 08 08:03:41 2010 +0100
@@ -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 @@ static int
 static int
 tapdisk2_create_device(const char *params)
 {
-       char *path;
+       const char *path;
        int err, type;
 
        chdir("/");
diff -r 0391f15da2f3 -r 9009f9f76441 tools/blktap2/include/tapdisk-message.h
--- a/tools/blktap2/include/tapdisk-message.h   Tue Jun 08 08:02:56 2010 +0100
+++ b/tools/blktap2/include/tapdisk-message.h   Tue Jun 08 08:03:41 2010 +0100
@@ -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 {
 struct tapdisk_message {
        uint16_t                         type;
        uint16_t                         cookie;
-       uint16_t                         drivertype;
 
        union {
                pid_t                    tapdisk_pid;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] blktap2: Fix tapdisk disktype issues., Xen patchbot-unstable <=