qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/4] qemu-nbd: do not start the block layer in the parent
Date: Fri, 28 Oct 2011 12:17:57 +0200	[thread overview]
Message-ID: <1319797077-25441-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1319797077-25441-1-git-send-email-pbonzini@redhat.com>

Forking and threading do not behave very well together.  With qemu-nbd in
-c mode it could happen that the thread pool is started in the parent, and
the children (the one actually doing the I/O) is left without working I/O.
Fix this by only running bdrv_init in the child process.

Reported-by: Pierre Riteau <Pierre.Riteau@irisa.fr>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-nbd.c |   31 ++++++++++++++-----------------
 1 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 5031158..962952c 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -371,21 +371,6 @@ int main(int argc, char **argv)
 	return 0;
     }
 
-    bdrv_init();
-
-    bs = bdrv_new("hda");
-
-    if ((ret = bdrv_open(bs, argv[optind], flags, NULL)) < 0) {
-        errno = -ret;
-        err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
-    }
-
-    fd_size = bs->total_sectors * 512;
-
-    if (partition != -1 &&
-        find_partition(bs, partition, &dev_offset, &fd_size))
-        err(EXIT_FAILURE, "Could not find partition %d", partition);
-
     if (device) {
         pid_t pid;
         int sock;
@@ -418,7 +403,6 @@ int main(int argc, char **argv)
             size_t blocksize;
 
             ret = 0;
-            bdrv_close(bs);
 
             do {
                 sock = unix_socket_outgoing(socket);
@@ -473,8 +457,21 @@ int main(int argc, char **argv)
         /* children */
     }
 
+    bdrv_init();
+    bs = bdrv_new("hda");
+    if ((ret = bdrv_open(bs, argv[optind], flags, NULL)) < 0) {
+        errno = -ret;
+        err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
+    }
+
+    fd_size = bs->total_sectors * 512;
+
+    if (partition != -1 &&
+        find_partition(bs, partition, &dev_offset, &fd_size)) {
+        err(EXIT_FAILURE, "Could not find partition %d", partition);
+    }
+
     sharing_fds = g_malloc((shared + 1) * sizeof(int));
-
     if (socket) {
         sharing_fds[0] = unix_socket_incoming(socket);
     } else {
-- 
1.7.6.4

  parent reply	other threads:[~2011-10-28 10:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28 10:17 [Qemu-devel] [PATCH 0/4] fix qemu-nbd -c Paolo Bonzini
2011-10-28 10:17 ` [Qemu-devel] [PATCH 1/4] qemu-nbd: exit if the child exits before a socket connection is established Paolo Bonzini
2011-10-28 10:17 ` [Qemu-devel] [PATCH 2/4] qemu-nbd: include our own err/errx implementation Paolo Bonzini
2011-10-28 10:17 ` [Qemu-devel] [PATCH 3/4] qemu-nbd: report errors to syslog when daemonized Paolo Bonzini
2011-10-28 10:17 ` Paolo Bonzini [this message]
2011-10-28 11:56   ` [Qemu-devel] [PATCH 4/4] qemu-nbd: do not start the block layer in the parent Pierre Riteau
2011-10-28 11:57     ` Paolo Bonzini
2011-10-28 12:16       ` Pierre Riteau
2011-10-28 12:17         ` Paolo Bonzini
2011-11-04  9:46           ` Paolo Bonzini
2011-11-04 10:31             ` Kevin Wolf
2011-11-04 11:10               ` Paolo Bonzini
2011-11-04 11:22                 ` Kevin Wolf
2011-11-04 11:25                   ` Paolo Bonzini

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=1319797077-25441-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).