aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2009-03-12 18:46:26 +0000
committerKeir Fraser <keir.fraser@citrix.com>2009-03-12 18:46:26 +0000
commit3dc413c7bd82ddb93a3c7e25d15002a15e0e250c (patch)
tree2e6482e13d091719d02626053495fc6b90940132 /tools/blktap
parent57871f919d89cc3f323dabcb76dd5344595e756e (diff)
downloadxen-3dc413c7bd82ddb93a3c7e25d15002a15e0e250c.tar.gz
xen-3dc413c7bd82ddb93a3c7e25d15002a15e0e250c.tar.bz2
xen-3dc413c7bd82ddb93a3c7e25d15002a15e0e250c.zip
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>
Diffstat (limited to 'tools/blktap')
-rw-r--r--tools/blktap/drivers/blktapctrl.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/blktap/drivers/blktapctrl.c b/tools/blktap/drivers/blktapctrl.c
index b7ee572837..21cdfe5239 100644
--- a/tools/blktap/drivers/blktapctrl.c
+++ b/tools/blktap/drivers/blktapctrl.c
@@ -231,6 +231,24 @@ static void add_disktype(blkif_t *blkif, int type)
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 *blkif)
}
if (del_disktype(blkif)) {
+ DPRINTF("Closing communication pipe to pid %d\n", blkif->tappid);
close(blkif->fds[WRITE]);
close(blkif->fds[READ]);
}