From patchwork Sat Jan 14 11:41:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 136074 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 24A02B6F65 for ; Sat, 14 Jan 2012 22:45:21 +1100 (EST) Received: from localhost ([::1]:54929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm22x-0000S8-7v for incoming@patchwork.ozlabs.org; Sat, 14 Jan 2012 06:45:19 -0500 Received: from eggs.gnu.org ([140.186.70.92]:40308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm22k-0000Pp-R8 for qemu-devel@nongnu.org; Sat, 14 Jan 2012 06:45:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rm22h-0005zC-DQ for qemu-devel@nongnu.org; Sat, 14 Jan 2012 06:45:06 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:47184) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rm22g-0005yT-Fe for qemu-devel@nongnu.org; Sat, 14 Jan 2012 06:45:02 -0500 Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id AC075A081B; Sat, 14 Jan 2012 15:44:59 +0400 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id 493513DE; Sat, 14 Jan 2012 15:44:59 +0400 (MSK) From: Michael Tokarev Date: Sat, 14 Jan 2012 15:41:35 +0400 To: qemu-devel@nongnu.org Message-Id: <20120114114459.493513DE@gandalf.tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 86.62.121.231 Cc: Paolo Bonzini , mjt@tls.msk.ru Subject: [Qemu-devel] [PATCH] use different fd variables for device and socket, unbreak qemu-nbd -c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org commit a61c67828dea7c64edaf226cadb45b4ffcc1d411 Author: Paolo Bonzini Date: Mon Sep 12 17:28:11 2011 +0200 qemu-nbd: use common main loop Using a single main loop for sockets will help yielding from the socket coroutine back to the main loop, and later reentering it. changed code to use local variable "fd" in qemu-nbd.c:main() in two places: for /dev/nbd device and for control socket. The result is that qemu-nbd -c $device does not work anymore. Use two variables - devfs and sockfd - for the two purposes, instead of one fd. Signed-Off-By: Michael Tokarev --- qemu-nbd.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index eb61c33..e76c782 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -301,7 +301,7 @@ int main(int argc, char **argv) int flags = BDRV_O_RDWR; int partition = -1; int ret; - int fd; + int sockfd, devfd; int persistent = 0; pthread_t client_thread; @@ -401,13 +401,13 @@ int main(int argc, char **argv) } if (disconnect) { - fd = open(argv[optind], O_RDWR); - if (fd == -1) + sockfd = open(argv[optind], O_RDWR); + if (sockfd == -1) err(EXIT_FAILURE, "Cannot open %s", argv[optind]); - nbd_disconnect(fd); + nbd_disconnect(sockfd); - close(fd); + close(sockfd); printf("%s disconnected\n", argv[optind]); @@ -470,8 +470,8 @@ int main(int argc, char **argv) /* Open before spawning new threads. In the future, we may * drop privileges after opening. */ - fd = open(device, O_RDWR); - if (fd == -1) { + devfd = open(device, O_RDWR); + if (devfd == -1) { err(EXIT_FAILURE, "Failed to open %s", device); } @@ -501,19 +501,19 @@ int main(int argc, char **argv) exp = nbd_export_new(bs, dev_offset, fd_size, nbdflags); if (sockpath) { - fd = unix_socket_incoming(sockpath); + sockfd = unix_socket_incoming(sockpath); } else { - fd = tcp_socket_incoming(bindto, port); + sockfd = tcp_socket_incoming(bindto, port); } - if (fd == -1) { + if (sockfd == -1) { return 1; } if (device) { int ret; - ret = pthread_create(&client_thread, NULL, nbd_client_thread, &fd); + ret = pthread_create(&client_thread, NULL, nbd_client_thread, &devfd); if (ret != 0) { errx(EXIT_FAILURE, "Failed to create client thread: %s", strerror(ret)); @@ -524,8 +524,8 @@ int main(int argc, char **argv) } qemu_init_main_loop(); - qemu_set_fd_handler2(fd, nbd_can_accept, nbd_accept, NULL, - (void *)(uintptr_t)fd); + qemu_set_fd_handler2(sockfd, nbd_can_accept, nbd_accept, NULL, + (void *)(uintptr_t)sockfd); do { main_loop_wait(false);