All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@suse.de>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Cc: Jim Fehlig <jfehlig@novell.com>
Subject: [PATCH 3/4] blktapctrl: Fix too early close of pipes
Date: Thu, 12 Mar 2009 19:33:11 +0100	[thread overview]
Message-ID: <49B95567.7080403@suse.de> (raw)
In-Reply-To: <49B9544C.4030006@suse.de>

[-- 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

  parent reply	other threads:[~2009-03-12 18:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2009-03-12 18:33 ` [PATCH 4/4] blktap: Move error signaling to blktapctrl Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49B95567.7080403@suse.de \
    --to=kwolf@suse.de \
    --cc=jfehlig@novell.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.