From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Wolf Subject: [PATCH 3/4] blktapctrl: Fix too early close of pipes Date: Thu, 12 Mar 2009 19:33:11 +0100 Message-ID: <49B95567.7080403@suse.de> References: <49B9544C.4030006@suse.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010706080905030401030606" Return-path: In-Reply-To: <49B9544C.4030006@suse.de> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" Cc: Jim Fehlig List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. --------------010706080905030401030606 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit 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 --------------010706080905030401030606 Content-Type: text/x-patch; name="blktapctrl-close-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="blktapctrl-close-fix.patch" 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 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]); } --------------010706080905030401030606 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------010706080905030401030606--