All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Various blktap related patches (xen part)
@ 2009-03-12 18:28 Kevin Wolf
  2009-03-12 18:31 ` [PATCH 1/4] blktapctrl: Select backend by prefix Kevin Wolf
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Kevin Wolf @ 2009-03-12 18:28 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig

The following patch series is the xen repository part of some blktap
related patches that accumulated during SLES 11 development. A qemu-xen
part will follow once these are checked in, so the dependencies are met.

The main point is restoring the possibility to use qemu-dm as a backend
for blktap devices (and mid-term letting tapdisk die with its duplicated
code), but at least the error handling addresses general concerns.

As an overview, we have the following patches:

1) blktapctrl: Select backend by prefix
2) blktap: Export disk type constants for ioemu
3) blktapctrl: Fix too early close of pipes
4) blktap: Move error signaling to blktapctrl

Kevin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] blktapctrl: Select backend by prefix
  2009-03-12 18:28 [PATCH 0/4] Various blktap related patches (xen part) Kevin Wolf
@ 2009-03-12 18:31 ` Kevin Wolf
  2009-03-12 18:32 ` [PATCH 2/4] blktap: Export disk type constants for ioemu Kevin Wolf
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2009-03-12 18:31 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig

[-- Attachment #1: Type: text/plain, Size: 400 bytes --]

This patch adds support for specifying the backend (tapdisk or ioemu)
to blktapctrl. Images can be specified e.g. as tap:tapdisk:aio,
tap:ioemu:qcow2 or tap:vmdk. When omitting the backend, a default is
chosen based on the image type (currently always tapdisk because ioemu
as a backend is broken until a follow-up patch series against qemu-xen
is applied)

Signed-off-by: Kevin Wolf <kwolf@suse.de>

[-- Attachment #2: blktapctrl-select-backend.patch --]
[-- Type: text/x-patch, Size: 6490 bytes --]

blktapctrl: Select backend by prefix

This patch adds support for specifying the backend (tapdisk or ioemu)
to blktapctrl. Images can be specified e.g. as tap:tapdisk:aio,
tap:ioemu:qcow2 or tap:vmdk. When omitting the backend, a default is
chosen based on the image type (currently always tapdisk because ioemu
as a backend is broken until a follow-up patch series against qemu-xen
is applied)

Signed-off-by: Kevin Wolf <kwolf@suse.de>

Index: xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
===================================================================
--- xen-unstable.hg.orig/tools/blktap/drivers/blktapctrl.c
+++ xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
@@ -148,7 +148,8 @@ static int get_tapdisk_pid(blkif_t *blki
  *   return 0 on success, -1 on error.
  */
 
-static int test_path(char *path, char **dev, int *type, blkif_t **blkif)
+static int test_path(char *path, char **dev, int *type, blkif_t **blkif,
+	int* use_ioemu)
 {
 	char *ptr, handle[10];
 	int i, size, found = 0;
@@ -158,6 +159,17 @@ static int test_path(char *path, char **
 	*type = MAX_DISK_TYPES + 1;
         *blkif = NULL;
 
+	if (!strncmp(path, "tapdisk:", strlen("tapdisk:"))) {
+		*use_ioemu = 0;
+		path += strlen("tapdisk:");
+	} else if (!strncmp(path, "ioemu:", strlen("ioemu:"))) {
+		*use_ioemu = 1;
+		path += strlen("ioemu:");
+	} else {
+		// Use the default for the image type
+		*use_ioemu = -1;
+	}
+
 	if ( (ptr = strstr(path, ":"))!=NULL) {
 		handle_len = (ptr - path);
 		memcpy(handle, path, handle_len);
@@ -174,6 +186,8 @@ static int test_path(char *path, char **
                         }
 
 			if (found) {
+				if (*use_ioemu == -1)
+					*use_ioemu = dtypes[i]->use_ioemu;
 				*type = dtypes[i]->idnum;
                         
                         if (dtypes[i]->single_handler == 1) {
@@ -185,6 +199,7 @@ static int test_path(char *path, char **
                                         *blkif = active_disks[dtypes[i]
                                                              ->idnum]->blkif;
                         }
+
                         return 0;
                 }
             }
@@ -504,7 +519,8 @@ static int connect_qemu(blkif_t *blkif,
 	static int tapdisk_ioemu_pid = 0;
 	static int dom0_readfd = 0;
 	static int dom0_writefd = 0;
-	
+	int refresh_pid = 0;
+
 	if (asprintf(&rdctldev, BLKTAP_CTRL_DIR "/qemu-read-%d", domid) < 0)
 		return -1;
 
@@ -523,15 +539,23 @@ static int connect_qemu(blkif_t *blkif,
 		if (tapdisk_ioemu_pid == 0 || kill(tapdisk_ioemu_pid, 0)) {
 			/* No device model and tapdisk-ioemu doesn't run yet */
 			DPRINTF("Launching tapdisk-ioemu\n");
-			tapdisk_ioemu_pid = launch_tapdisk_ioemu();
+			launch_tapdisk_ioemu();
 			
 			dom0_readfd = open_ctrl_socket(wrctldev);
 			dom0_writefd = open_ctrl_socket(rdctldev);
+
+			refresh_pid = 1;
 		}
 
 		DPRINTF("Using tapdisk-ioemu connection\n");
 		blkif->fds[READ] = dom0_readfd;
 		blkif->fds[WRITE] = dom0_writefd;
+
+		if (refresh_pid) {
+			get_tapdisk_pid(blkif);
+			tapdisk_ioemu_pid = blkif->tappid;
+		}
+
 	} else if (access(rdctldev, R_OK | W_OK) == 0) {
 		/* Use existing pipe to the device model */
 		DPRINTF("Using qemu-dm connection\n");
@@ -605,13 +629,14 @@ static int blktapctrl_new_blkif(blkif_t
 	image_t *image;
 	blkif_t *exist = NULL;
 	static uint16_t next_cookie = 0;
+	int use_ioemu;
 
 	DPRINTF("Received a poll for a new vbd\n");
 	if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
 		if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
 			return -1;
 
-		if (test_path(blk->params, &ptr, &type, &exist) != 0) {
+		if (test_path(blk->params, &ptr, &type, &exist, &use_ioemu) != 0) {
                         DPRINTF("Error in blktap device string(%s).\n",
                                 blk->params);
                         goto fail;
@@ -620,7 +645,7 @@ static int blktapctrl_new_blkif(blkif_t
 		blkif->cookie = next_cookie++;
 
 		if (!exist) {
-			if (type == DISK_TYPE_IOEMU) {
+			if (use_ioemu) {
 				if (connect_qemu(blkif, blkif->domid))
 					goto fail;
 			} else {
Index: xen-unstable.hg/tools/blktap/drivers/tapdisk.h
===================================================================
--- xen-unstable.hg.orig/tools/blktap/drivers/tapdisk.h
+++ xen-unstable.hg/tools/blktap/drivers/tapdisk.h
@@ -145,6 +145,8 @@ typedef struct disk_info {
 	char handle[10];     /* xend handle, e.g. 'ram' */
 	int  single_handler; /* is there a single controller for all */
 	                     /* instances of disk type? */
+	int  use_ioemu;      /* backend provider: 0 = tapdisk; 1 = ioemu */
+
 #ifdef TAPDISK
 	struct tap_disk *drv;	
 #endif
@@ -167,7 +169,6 @@ extern struct tap_disk tapdisk_qcow2;
 #define DISK_TYPE_RAM      3
 #define DISK_TYPE_QCOW     4
 #define DISK_TYPE_QCOW2    5
-#define DISK_TYPE_IOEMU    6
 
 
 /*Define Individual Disk Parameters here */
@@ -176,6 +177,7 @@ static disk_info_t aio_disk = {
 	"raw image (aio)",
 	"aio",
 	0,
+	0,
 #ifdef TAPDISK
 	&tapdisk_aio,
 #endif
@@ -186,6 +188,7 @@ static disk_info_t sync_disk = {
 	"raw image (sync)",
 	"sync",
 	0,
+	0,
 #ifdef TAPDISK
 	&tapdisk_sync,
 #endif
@@ -196,6 +199,7 @@ static disk_info_t vmdk_disk = {
 	"vmware image (vmdk)",
 	"vmdk",
 	1,
+	0,
 #ifdef TAPDISK
 	&tapdisk_vmdk,
 #endif
@@ -206,6 +210,7 @@ static disk_info_t ram_disk = {
 	"ramdisk image (ram)",
 	"ram",
 	1,
+	0,
 #ifdef TAPDISK
 	&tapdisk_ram,
 #endif
@@ -216,6 +221,7 @@ static disk_info_t qcow_disk = {
 	"qcow disk (qcow)",
 	"qcow",
 	0,
+	0,
 #ifdef TAPDISK
 	&tapdisk_qcow,
 #endif
@@ -226,21 +232,12 @@ static disk_info_t qcow2_disk = {
 	"qcow2 disk (qcow2)",
 	"qcow2",
 	0,
+	0,
 #ifdef TAPDISK
 	&tapdisk_qcow2,
 #endif
 };
 
-static disk_info_t ioemu_disk = {
-	DISK_TYPE_IOEMU,
-	"ioemu disk",
-	"ioemu",
-	1,
-#ifdef TAPDISK
-	NULL
-#endif
-};
-
 /*Main disk info array */
 static disk_info_t *dtypes[] = {
 	&aio_disk,
@@ -249,7 +246,6 @@ static disk_info_t *dtypes[] = {
 	&ram_disk,
 	&qcow_disk,
 	&qcow2_disk,
-	&ioemu_disk,
 };
 
 typedef struct driver_list_entry {
Index: xen-unstable.hg/tools/python/xen/xend/server/BlktapController.py
===================================================================
--- xen-unstable.hg.orig/tools/python/xen/xend/server/BlktapController.py
+++ xen-unstable.hg/tools/python/xen/xend/server/BlktapController.py
@@ -15,7 +15,8 @@ blktap_disk_types = [
     'qcow',
     'qcow2',
 
-    'ioemu'
+    'ioemu',
+    'tapdisk',
     ]
 
 class BlktapController(BlkifController):

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] blktap: Export disk type constants for ioemu
  2009-03-12 18:28 [PATCH 0/4] Various blktap related patches (xen part) Kevin Wolf
  2009-03-12 18:31 ` [PATCH 1/4] blktapctrl: Select backend by prefix Kevin Wolf
@ 2009-03-12 18:32 ` Kevin Wolf
  2009-03-12 18:33 ` [PATCH 3/4] blktapctrl: Fix too early close of pipes Kevin Wolf
  2009-03-12 18:33 ` [PATCH 4/4] blktap: Move error signaling to blktapctrl Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2009-03-12 18:32 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

Currently all disk types that are supported are defined in a header file
private to blktapctrl and tapdisk. When restoring ioemu as a backend for
blktap these constants are needed by ioemu, so move them to a more
public header file.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

[-- Attachment #2: libblktap-export-disk-types.patch --]
[-- Type: text/x-patch, Size: 1652 bytes --]

blktap: Export disk type constants for ioemu

Currently all disk types that are supported are defined in a header file
private to blktapctrl and tapdisk. When restoring ioemu as a backend for
blktap these constants are needed by ioemu, so move them to a more public
header file.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

Index: xen-unstable.hg/tools/blktap/drivers/tapdisk.h
===================================================================
--- xen-unstable.hg.orig/tools/blktap/drivers/tapdisk.h
+++ xen-unstable.hg/tools/blktap/drivers/tapdisk.h
@@ -161,15 +161,6 @@ extern struct tap_disk tapdisk_ram;
 extern struct tap_disk tapdisk_qcow;
 extern struct tap_disk tapdisk_qcow2;
 
-#define MAX_DISK_TYPES     20
-
-#define DISK_TYPE_AIO      0
-#define DISK_TYPE_SYNC     1
-#define DISK_TYPE_VMDK     2
-#define DISK_TYPE_RAM      3
-#define DISK_TYPE_QCOW     4
-#define DISK_TYPE_QCOW2    5
-
 
 /*Define Individual Disk Parameters here */
 static disk_info_t aio_disk = {
Index: xen-unstable.hg/tools/blktap/lib/blktaplib.h
===================================================================
--- xen-unstable.hg.orig/tools/blktap/lib/blktaplib.h
+++ xen-unstable.hg/tools/blktap/lib/blktaplib.h
@@ -210,6 +210,16 @@ typedef struct msg_pid {
 #define CTLMSG_PID         9
 #define CTLMSG_PID_RSP     10
 
+/* disk driver types */
+#define MAX_DISK_TYPES     20
+
+#define DISK_TYPE_AIO      0
+#define DISK_TYPE_SYNC     1
+#define DISK_TYPE_VMDK     2
+#define DISK_TYPE_RAM      3
+#define DISK_TYPE_QCOW     4
+#define DISK_TYPE_QCOW2    5
+
 /* xenstore/xenbus: */
 #define DOMNAME "Domain-0"
 int setup_probe_watch(struct xs_handle *h);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] blktapctrl: Fix too early close of pipes
  2009-03-12 18:28 [PATCH 0/4] Various blktap related patches (xen part) Kevin Wolf
  2009-03-12 18:31 ` [PATCH 1/4] blktapctrl: Select backend by prefix Kevin Wolf
  2009-03-12 18:32 ` [PATCH 2/4] blktap: Export disk type constants for ioemu Kevin Wolf
@ 2009-03-12 18:33 ` Kevin Wolf
  2009-03-12 18:33 ` [PATCH 4/4] blktap: Move error signaling to blktapctrl Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2009-03-12 18:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig

[-- Attachment #1: Type: text/plain, Size: 446 bytes --]

Connections to ioemu have single_handler set, so they are closed as
soon as all images of a certain type are closed. This is wrong with
ioemu: All images that belong to the same domain are handled by the
same backend process (usually qemu-dm, but also tapdisk-ioemu for
domains without device model), regardless of the image type.

This patch checks for the same-domain condition for ioemu connections.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

[-- Attachment #2: blktapctrl-close-fix.patch --]
[-- Type: text/x-patch, Size: 2010 bytes --]

blktapctrl: Fix too early close of pipes

Connections to ioemu have single_handler set, so they are closed as
soon as all images of a certain type are closed. This is wrong with
ioemu: All images that belong to the same domain are handled by the
same backend process (usually qemu-dm, but also tapdisk-ioemu for
domains without device model), regardless of the image type.

This patch checks for the same-domain condition for ioemu connections.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

Index: xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
===================================================================
--- xen-unstable.hg.orig/tools/blktap/drivers/blktapctrl.c
+++ xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
@@ -231,6 +231,24 @@ static void add_disktype(blkif_t *blkif,
 	entry->pprev = pprev;
 }
 
+static int qemu_instance_has_disks(pid_t pid)
+{
+	int i;
+	int count = 0;
+	driver_list_entry_t *entry;
+
+	for (i = 0; i < MAX_DISK_TYPES; i++) {
+		entry = active_disks[i];
+		while (entry) {
+			if ((entry->blkif->tappid == pid) && dtypes[i]->use_ioemu)
+				count++;
+			entry = entry->next;
+		}
+	}
+
+	return (count != 0);
+}
+
 static int del_disktype(blkif_t *blkif)
 {
 	driver_list_entry_t *entry, **pprev;
@@ -255,6 +273,14 @@ static int del_disktype(blkif_t *blkif)
 	DPRINTF("DEL_DISKTYPE: Freeing entry\n");
 	free(entry);
 
+	/*
+	 * When using ioemu, all disks of one VM are connected to the same
+	 * qemu-dm instance. We may close the file handle only if there is
+	 * no other disk left for this domain.
+	 */
+	if (dtypes[type]->use_ioemu)
+		return !qemu_instance_has_disks(blkif->tappid);
+
 	/* Caller should close() if no single controller, or list is empty. */
 	return (!dtypes[type]->single_handler || (active_disks[type] == NULL));
 }
@@ -721,6 +747,7 @@ static int unmap_blktapctrl(blkif_t *blk
 	}
 
 	if (del_disktype(blkif)) {
+		DPRINTF("Closing communication pipe to pid %d\n", blkif->tappid);
 		close(blkif->fds[WRITE]);
 		close(blkif->fds[READ]);
 	}

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] blktap: Move error signaling to blktapctrl
  2009-03-12 18:28 [PATCH 0/4] Various blktap related patches (xen part) Kevin Wolf
                   ` (2 preceding siblings ...)
  2009-03-12 18:33 ` [PATCH 3/4] blktapctrl: Fix too early close of pipes Kevin Wolf
@ 2009-03-12 18:33 ` Kevin Wolf
  3 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2009-03-12 18:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig

[-- Attachment #1: Type: text/plain, Size: 397 bytes --]

Until now the udev script for blktap devices needs to decide if to
signal success or failure to xend. As this script runs completely
independent of blktapctrl and tapdisk/ioemu which do the real work,
the udev script can't even theoretically know if tapdisk is happy.

This patch removes the udev script and replaces its checks by new
ones in libblktap.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

[-- Attachment #2: blktap-error-handling.patch --]
[-- Type: text/x-patch, Size: 9715 bytes --]

blktap: Move error signaling to blktapctrl

Until now the udev script for blktap devices needs to decide if to
signal success or failure to xend. As this script runs completely
independent of blktapctrl and tapdisk/ioemu which do the real work,
the udev script can't even theoretically know if tapdisk is happy.

This patch removes the udev script and replaces its checks by new
ones in libblktap.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

Index: xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
===================================================================
--- xen-unstable.hg.orig/tools/blktap/drivers/blktapctrl.c
+++ xen-unstable.hg/tools/blktap/drivers/blktapctrl.c
@@ -659,9 +659,6 @@ static int blktapctrl_new_blkif(blkif_t
 
 	DPRINTF("Received a poll for a new vbd\n");
 	if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
-		if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
-			return -1;
-
 		if (test_path(blk->params, &ptr, &type, &exist, &use_ioemu) != 0) {
                         DPRINTF("Error in blktap device string(%s).\n",
                                 blk->params);
@@ -685,10 +682,6 @@ static int blktapctrl_new_blkif(blkif_t
 			blkif->fds[WRITE] = exist->fds[WRITE];
 		}
 
-		add_disktype(blkif, type);
-		blkif->major = major;
-		blkif->minor = minor;
-
 		image = (image_t *)malloc(sizeof(image_t));
 		blkif->prv = (void *)image;
 		blkif->ops = &tapdisk_ops;
@@ -712,11 +705,18 @@ static int blktapctrl_new_blkif(blkif_t
 			goto fail;
 		}
 
+		if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
+			return -1;
+
+		blkif->major = major;
+		blkif->minor = minor;
+
+		add_disktype(blkif, type);
+
 	} else return -1;
 
 	return 0;
 fail:
-	ioctl(ctlfd, BLKTAP_IOCTL_FREEINTF, minor);
 	return -EINVAL;
 }
 
Index: xen-unstable.hg/tools/blktap/lib/xenbus.c
===================================================================
--- xen-unstable.hg.orig/tools/blktap/lib/xenbus.c
+++ xen-unstable.hg/tools/blktap/lib/xenbus.c
@@ -48,6 +48,7 @@
 #include <poll.h>
 #include <time.h>
 #include <sys/time.h>
+#include <unistd.h>
 #include "blktaplib.h"
 #include "list.h"
 #include "xs_api.h"
@@ -149,6 +150,137 @@ static int backend_remove(struct xs_hand
 	return 0;
 }
 
+static int check_sharing(struct xs_handle *h, struct backend_info *be)
+{
+	char *dom_uuid;
+	char *cur_dom_uuid;
+	char *path;
+	char *mode;
+	char *params;
+	char **domains;
+	char **devices;
+	int i, j;
+	unsigned int num_dom, num_dev;
+	blkif_info_t *info;
+	int ret = 0;
+
+	/* If the mode contains '!' or doesn't contain 'w' don't check anything */
+	xs_gather(h, be->backpath, "mode", NULL, &mode, NULL);
+	if (strchr(mode, '!'))
+		goto out;
+	if (strchr(mode, 'w') == NULL)
+		goto out;
+
+	/* Get the UUID of the domain we want to attach to */
+	if (asprintf(&path, "/local/domain/%ld", be->frontend_id) == -1)
+		goto fail;
+	xs_gather(h, path, "vm", NULL, &dom_uuid, NULL);
+	free(path);
+
+	/* Iterate through the devices of all VMs */
+	domains = xs_directory(h, XBT_NULL, "backend/tap", &num_dom);
+	if (domains == NULL)
+		num_dom = 0;
+
+	for (i = 0; !ret && (i < num_dom); i++) {
+
+		/* If it's the same VM, no action needed */
+		if (asprintf(&path, "/local/domain/%s", domains[i]) == -1) {
+			ret = -1;
+			break;
+		}
+		xs_gather(h, path, "vm", NULL, &cur_dom_uuid, NULL);
+		free(path);
+
+		if (!strcmp(cur_dom_uuid, dom_uuid)) {
+			free(cur_dom_uuid);
+			continue;
+		}
+
+		/* Check the devices */
+		if (asprintf(&path, "backend/tap/%s", domains[i]) == -1) {
+			ret = -1;
+			free(cur_dom_uuid);
+			break;
+		}
+		devices = xs_directory(h, XBT_NULL, path, &num_dev);
+		if (devices == NULL)
+			num_dev = 0;
+		free(path);
+
+		for (j = 0; !ret && (j < num_dev); j++) {
+			if (asprintf(&path, "backend/tap/%s/%s", domains[i], devices[j]) == -1) {
+				ret = -1;
+				break;
+			}
+			xs_gather(h, path, "params", NULL, &params, NULL);
+			free(path);
+
+			info =  be->blkif->info;
+			if (strcmp(params, info->params)) {
+				ret = -1;
+			}
+
+			free(params);
+		}
+
+		free(cur_dom_uuid);
+		free(devices);
+	}
+	free(domains);
+	free(dom_uuid);
+	goto out;
+
+fail:
+	ret = -1;
+out:
+	free(mode);
+	return ret;
+}
+
+static int check_image(struct xs_handle *h, struct backend_info *be,
+	const char** errmsg)
+{
+	const char *tmp;
+	const char *path;
+	int mode;
+	blkif_t *blkif = be->blkif;
+	blkif_info_t *info = blkif->info;
+
+	/* Strip off the image type */
+	path = info->params;
+
+	if (!strncmp(path, "tapdisk:", strlen("tapdisk:"))) {
+		path += strlen("tapdisk:");
+	} else if (!strncmp(path, "ioemu:", strlen("ioemu:"))) {
+		path += strlen("ioemu:");
+	}
+
+	tmp = strchr(path, ':');
+	if (tmp != NULL)
+		path = tmp + 1;
+
+	/* Check if the image exists and access is permitted */
+	mode = R_OK;
+	if (!be->readonly)
+		mode |= W_OK;
+	if (access(path, mode)) {
+		if (errno == ENOENT)
+			*errmsg = "File not found.";
+		else
+			*errmsg = "Insufficient file permissions.";
+		return -1;
+	}
+
+	/* Check that the image is not attached to a different VM */
+	if (check_sharing(h, be)) {
+		*errmsg = "File already in use by other domain";
+		return -1;
+	}
+
+	return 0;
+}
+
 static void ueblktap_setup(struct xs_handle *h, char *bepath)
 {
 	struct backend_info *be;
@@ -156,6 +288,7 @@ static void ueblktap_setup(struct xs_han
 	int len, er, deverr;
 	long int pdev = 0, handle;
 	blkif_info_t *blk;
+	const char* errmsg = NULL;
 	
 	be = be_lookup_be(bepath);
 	if (be == NULL)
@@ -211,6 +344,9 @@ static void ueblktap_setup(struct xs_han
 			be->pdev = pdev;
 		}
 
+		if (check_image(h, be, &errmsg))
+			goto fail;
+
 		er = blkif_init(be->blkif, handle, be->pdev, be->readonly);
 		if (er != 0) {
 			DPRINTF("Unable to open device %s\n",blk->params);
@@ -246,12 +382,21 @@ static void ueblktap_setup(struct xs_han
 	}
 
 	be->blkif->state = CONNECTED;
+	xs_printf(h, be->backpath, "hotplug-status", "connected");
+
 	DPRINTF("[SETUP] Complete\n\n");
 	goto close;
 	
 fail:
-	if ( (be != NULL) && (be->blkif != NULL) ) 
+	if (be) {
+		if (errmsg == NULL)
+			errmsg = "Setting up the backend failed. See the log "
+				"files in /var/log/xen/ for details.";
+		xs_printf(h, be->backpath, "hotplug-error", errmsg);
+		xs_printf(h, be->backpath, "hotplug-status", "error");
+
 		backend_remove(h, be);
+	}
 close:
 	if (path)
 		free(path);
@@ -286,7 +431,8 @@ static void ueblktap_probe(struct xs_han
 	len = strsep_len(bepath, '/', 7);
 	if (len < 0) 
 		goto free_be;
-	bepath[len] = '\0';
+	if (bepath[len] != '\0')
+		goto free_be;
 	
 	be = malloc(sizeof(*be));
 	if (!be) {
Index: xen-unstable.hg/tools/hotplug/Linux/xen-backend.rules
===================================================================
--- xen-unstable.hg.orig/tools/hotplug/Linux/xen-backend.rules
+++ xen-unstable.hg/tools/hotplug/Linux/xen-backend.rules
@@ -1,4 +1,3 @@
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif*", ACTION=="online", RUN+="$env{script} online"
Index: xen-unstable.hg/tools/hotplug/Linux/blktap
===================================================================
--- xen-unstable.hg.orig/tools/hotplug/Linux/blktap
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2005, XenSource Ltd.
-
-dir=$(dirname "$0")
-. "$dir/xen-hotplug-common.sh"
-. "$dir/block-common.sh"
-
-findCommand "$@"
-
-##
-# check_blktap_sharing file mode
-#
-# Perform the sharing check for the given blktap and mode.
-#
-check_blktap_sharing()
-{
-    local file="$1"
-    local mode="$2"
-
-    local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
-    for dom in $(xenstore-list "$base_path")
-    do
-        for dev in $(xenstore-list "$base_path/$dom")
-        do
-            params=$(xenstore_read "$base_path/$dom/$dev/params" | cut -d: -f2)
-            if [ "$file" = "$params" ]
-            then
-
-                if [ "$mode" = 'w' ]
-                then
-                    if ! same_vm "$dom" 
-                    then
-                        echo 'guest'
-                        return
-                    fi
-                else 
-                    local m=$(xenstore_read "$base_path/$dom/$dev/mode")
-                    m=$(canonicalise_mode "$m")
-
-                    if [ "$m" = 'w' ] 
-                    then
-                        if ! same_vm "$dom"
-                        then
-                            echo 'guest'
-                            return
-                        fi
-                    fi
-                fi
-            fi
-        done
-    done
-
-    echo 'ok'
-}
-
-
-t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
-if [ -n "$t" ]
-then
-    p=$(xenstore_read "$XENBUS_PATH/params")
-    # if we have a ':', chew from head including :
-    if echo $p | grep -q \:
-    then
-        p=${p#*:}
-    fi
-fi
-# some versions of readlink cannot be passed a regular file
-if [ -L "$p" ]; then
-    file=$(readlink -f "$p") || fatal "$p link does not exist."
-else
-    file="$p"
-fi
-
-if [ "$command" = 'add' ]
-then
-    [ -e "$file" ] || { fatal $file does not exist; }
-
-    FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
-    FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
-    mode=$(xenstore_read "$XENBUS_PATH/mode")
-    mode=$(canonicalise_mode "$mode")
-
-    if [ "$mode" != '!' ] 
-    then
-        result=$(check_blktap_sharing "$file" "$mode")
-        [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
-    fi
-
-    success
-fi
-
-exit 0

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-03-12 18:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-12 18:28 [PATCH 0/4] Various blktap related patches (xen part) Kevin Wolf
2009-03-12 18:31 ` [PATCH 1/4] blktapctrl: Select backend by prefix Kevin Wolf
2009-03-12 18:32 ` [PATCH 2/4] blktap: Export disk type constants for ioemu Kevin Wolf
2009-03-12 18:33 ` [PATCH 3/4] blktapctrl: Fix too early close of pipes Kevin Wolf
2009-03-12 18:33 ` [PATCH 4/4] blktap: Move error signaling to blktapctrl Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.