Skip to contentSkip to conversation

blktap3/vhd: Full VHD support

PATCH New Thanos Makatos 1 participant 3 messages May 14, 2013

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 blktap3/vhd: Import VHD support

This patch imports the VHD driver from blktap2, with all changes coming from blktap2.5.

tools/blktap3/drivers/Makefile +1 -0
@@ -95,6 +95,7 @@ LIBSRING := sring/libsring.a
 #MISC-OBJS-y := atomicio.o
 
 BLK-OBJS-y  := block-aio.o
+BLK-OBJS-y  += block-vhd.o
 # FIXME The following exist in blktap2 but not in blktap2.5.
 #BLK-OBJS-y += aes.o
 #BLK-OBJS-y += md5.o
tools/blktap3/drivers/block-vhd.c renamed from tools/blktap2/drivers/block-vhd.c +204 -85

653 lines not on this page · raw message

#2 lore raw

PATCH 1/1 blktap3/vhd: Assorted improvements

In reply to Thanos Makatos

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

tools/blktap3/drivers/tapdisk-control.c +4 -2
@@ -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;
 
tools/blktap3/drivers/tapdisk-disktype.c +57 -22

117 lines not on this page · raw message

tools/blktap3/drivers/tapdisk-disktype.h +19 -17
@@ -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)
tools/blktap3/drivers/tapdisk-driver.c +1 -1
@@ -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;
 
tools/blktap3/drivers/tapdisk-interface.c +4 -0
@@ -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)
tools/blktap3/drivers/tapdisk-server.c +5 -2
@@ -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;
 }
tools/blktap3/tapback/backend.c +3 -0
@@ -205,6 +205,9 @@ tapback_backend_create_device(const domi
         if (err) {
             WARN("failed to open %s on tapdisk pid=%d: %s\n", device->params,
                     device->tap.pid, strerror(-err));
+            /* TODO The error handler assumes that there a device has been
+             * opened, so tapdisk will complain that there is no such image.
+             */
             goto out;
         }
         DBG("opened %s on tapdisk pid=%d\n", device->params, device->tap.pid);