[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2 of 2 RESEND] blktap3/vhd: Assorted improvements



This patch introduces a few extra checks in the code path that tell whether a
particular Virtual Disk Image driver is available.

Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxx>

diff --git a/tools/blktap3/drivers/tapdisk-control.c 
b/tools/blktap3/drivers/tapdisk-control.c
--- a/tools/blktap3/drivers/tapdisk-control.c
+++ b/tools/blktap3/drivers/tapdisk-control.c
@@ -586,7 +586,7 @@ tapdisk_control_open_image(
         tapdisk_message_t *request, tapdisk_message_t * const response)
 {
        int err;
-       td_vbd_t *vbd;
+       td_vbd_t *vbd = NULL;
        td_flag_t flags;
     td_disk_info_t info;
     int prt_path_len;
@@ -663,7 +663,9 @@ out:
         response->u.image.sector_size = info.sector_size;
         response->u.image.info = info.info;
         response->type = TAPDISK_MESSAGE_OPEN_RSP;
-    }
+    } else
+        if (vbd)
+            tapdisk_server_remove_vbd(vbd);
 
        return err;
 
diff --git a/tools/blktap3/drivers/tapdisk-disktype.c 
b/tools/blktap3/drivers/tapdisk-disktype.c
--- a/tools/blktap3/drivers/tapdisk-disktype.c
+++ b/tools/blktap3/drivers/tapdisk-disktype.c
@@ -148,7 +148,7 @@ const disk_info_t *tapdisk_disk_types[] 
 extern struct tap_disk tapdisk_aio;
 
 /*
- * TODO Why commented out?
+ * XXX Commented out in blktap2.5.
  */
 #if 0
 extern struct tap_disk tapdisk_sync;
@@ -160,7 +160,7 @@ extern struct tap_disk tapdisk_vhd;
 extern struct tap_disk tapdisk_ram;
 
 /*
- * TODO Why commented out?
+ * XXX Commented out in blktap2.5.
  */
 #if 0
 extern struct tap_disk tapdisk_qcow;
@@ -169,39 +169,74 @@ extern struct tap_disk tapdisk_qcow;
 extern struct tap_disk tapdisk_vhd_index;
 
 /*
- * TODO Why commented out?
+ * XXX Commented out in blktap2.5.
  */
 #if 0
 extern struct tap_disk tapdisk_log;
 #endif
 
-const struct tap_disk *tapdisk_disk_drivers[] = {
-       [DISK_TYPE_AIO]         = &tapdisk_aio,
+const struct tap_disk *
+tapdisk_disk_driver_get(const enum disk_type dt)
+{
+    static const struct tap_disk *tapdisk_disk_drivers[] = {
+        [DISK_TYPE_AIO]         = &tapdisk_aio,
 
-/*
- * TODO Why commented out?
- */
+        /*
+         * XXX Commented out in blktap2.5.
+         */
 #if 0
-       [DISK_TYPE_SYNC]        = &tapdisk_sync,
-       [DISK_TYPE_VMDK]        = &tapdisk_vmdk,
-    [DISK_TYPE_VHDSYNC] = &tapdisk_vhdsync_disk
+        [DISK_TYPE_SYNC]        = &tapdisk_sync,
+        [DISK_TYPE_VMDK]        = &tapdisk_vmdk,
+        [DISK_TYPE_VHDSYNC] = &tapdisk_vhdsync_disk
+#endif
+        [DISK_TYPE_VHD]         = &tapdisk_vhd,
+
+        /*
+         * TODO Commeneted out to simplify the upstreaming process.
+         */
+#if 0
+        [DISK_TYPE_RAM]         = &tapdisk_ram,
 #endif
 
-/*
- * TODO Why commented out?
- */
+        /*
+         * XXX Commented out in blktap2.5.
+         */
 #if 0
-       [DISK_TYPE_QCOW]        = &tapdisk_qcow,
+        [DISK_TYPE_QCOW]        = &tapdisk_qcow,
 #endif
 
-/*
- * TODO Why commented out?
- */
+        /*
+         * TODO Commeneted out to simplify the upstreaming process.
+         */
 #if 0
-       [DISK_TYPE_LOG]         = &tapdisk_log,
+        [DISK_TYPE_BLOCK_CACHE] = &tapdisk_block_cache,
+           [DISK_TYPE_VINDEX]      = &tapdisk_vhd_index,
 #endif
-       0,
-};
+
+        /*
+         * XXX Commented out in blktap2.5.
+         */
+#if 0
+        [DISK_TYPE_LOG]         = &tapdisk_log,
+#endif
+
+        /*
+         * TODO Commeneted out to simplify the upstreaming process.
+         */
+#if 0
+        [DISK_TYPE_LCACHE]      = &tapdisk_lcache,
+        [DISK_TYPE_LLPCACHE]    = &tapdisk_llpcache,
+        [DISK_TYPE_LLECACHE]    = &tapdisk_llecache,
+        [DISK_TYPE_VALVE]       = &tapdisk_valve,
+        [DISK_TYPE_NBD]         = &tapdisk_nbd,
+#endif
+    };
+
+    if (dt < 0 || dt > ARRAY_SIZE(tapdisk_disk_drivers))
+        return NULL;
+    else
+        return tapdisk_disk_drivers[dt];
+}
 
 int
 tapdisk_disktype_find(const char *name)
@@ -217,7 +252,7 @@ tapdisk_disktype_find(const char *name)
                if (strcmp(name, info->name))
                        continue;
 
-               if (!tapdisk_disk_drivers[i])
+               if (!tapdisk_disk_driver_get(i))
                        return -ENOSYS;
 
                return i;
diff --git a/tools/blktap3/drivers/tapdisk-disktype.h 
b/tools/blktap3/drivers/tapdisk-disktype.h
--- a/tools/blktap3/drivers/tapdisk-disktype.h
+++ b/tools/blktap3/drivers/tapdisk-disktype.h
@@ -29,32 +29,34 @@
 #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_VINDEX      8
-#define DISK_TYPE_LOG         9
-#define DISK_TYPE_REMUS       10
-#define DISK_TYPE_LCACHE      11
-#define DISK_TYPE_LLECACHE    12
-#define DISK_TYPE_LLPCACHE    13
-#define DISK_TYPE_VALVE       14
+enum disk_type {
+    DISK_TYPE_AIO,
+    DISK_TYPE_SYNC,
+    DISK_TYPE_VMDK,
+    DISK_TYPE_VHDSYNC,
+    DISK_TYPE_VHD,
+    DISK_TYPE_RAM,
+    DISK_TYPE_QCOW,
+    DISK_TYPE_BLOCK_CACHE,
+    DISK_TYPE_VINDEX,
+    DISK_TYPE_LOG,
+    DISK_TYPE_REMUS,
+    DISK_TYPE_LCACHE,
+    DISK_TYPE_LLECACHE,
+    DISK_TYPE_LLPCACHE,
+    DISK_TYPE_VALVE};
 
 #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; 
+       unsigned int    flags;
 } disk_info_t;
 
 extern const disk_info_t     *tapdisk_disk_types[];
-extern const struct tap_disk *tapdisk_disk_drivers[];
+const struct tap_disk *
+tapdisk_disk_driver_get(const enum disk_type dt);
 
 /* one single controller for all instances of disk type */
 #define DISK_TYPE_SINGLE_CONTROLLER (1<<0)
diff --git a/tools/blktap3/drivers/tapdisk-driver.c 
b/tools/blktap3/drivers/tapdisk-driver.c
--- a/tools/blktap3/drivers/tapdisk-driver.c
+++ b/tools/blktap3/drivers/tapdisk-driver.c
@@ -73,7 +73,7 @@ tapdisk_driver_allocate(int type, const 
        td_driver_t *driver;
        const struct tap_disk *ops;
 
-       ops = tapdisk_disk_drivers[type];
+       ops = tapdisk_disk_driver_get(type);
        if (!ops)
                return NULL;
 
diff --git a/tools/blktap3/drivers/tapdisk-interface.c 
b/tools/blktap3/drivers/tapdisk-interface.c
--- a/tools/blktap3/drivers/tapdisk-interface.c
+++ b/tools/blktap3/drivers/tapdisk-interface.c
@@ -67,6 +67,8 @@ int
        int err;
        td_driver_t *driver;
 
+    assert(image);
+
        driver = image->driver;
        if (!driver) {
                driver = tapdisk_driver_allocate(image->type,
@@ -80,6 +82,8 @@ int
        }
 
        if (!td_flag_test(driver->state, TD_DRIVER_OPEN)) {
+        assert(driver->ops);
+        assert(driver->ops->td_open);
                err = driver->ops->td_open(driver, image->name, image->flags);
                if (err) {
                        if (!image->driver)
diff --git a/tools/blktap3/drivers/tapdisk-server.c 
b/tools/blktap3/drivers/tapdisk-server.c
--- a/tools/blktap3/drivers/tapdisk-server.c
+++ b/tools/blktap3/drivers/tapdisk-server.c
@@ -90,8 +90,11 @@ tapdisk_server_get_vbd(const char *param
     assert(params);
 
        tapdisk_server_for_each_vbd(vbd, tmp)
-               if (!strcmp(vbd->name, params))
-                       return vbd;
+        if (vbd->name) {
+            /* TODO VBDs without name? Should this be treated as a bug? */
+               if (!strcmp(vbd->name, params))
+                       return vbd;
+        }
 
        return NULL;
 }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.