Received: from eggs.gnu.org ([140.186.70.92]:35235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjVw-0000El-7M for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJjVt-0001Nq-3p for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:16 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:47140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJjVt-0001NO-0C for qemu-devel@nongnu.org; Fri, 28 Oct 2011 06:18:13 -0400 Received: by mail-qw0-f45.google.com with SMTP id c12so4323622qad.4 for ; Fri, 28 Oct 2011 03:18:12 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 28 Oct 2011 12:17:57 +0200 Message-Id: <1319797077-25441-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1319797077-25441-1-git-send-email-pbonzini@redhat.com> References: <1319797077-25441-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 4/4] qemu-nbd: do not start the block layer in the parent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Signed-off-by: Paolo Bonzini --- 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