From patchwork Fri Dec 23 15:26:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 133074 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 E9197B71C5 for ; Sat, 24 Dec 2011 02:28:53 +1100 (EST) Received: from localhost ([::1]:53725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Re73D-0001tu-FT for incoming@patchwork.ozlabs.org; Fri, 23 Dec 2011 10:28:51 -0500 Received: from eggs.gnu.org ([140.186.70.92]:50897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Re72u-0001SH-US for qemu-devel@nongnu.org; Fri, 23 Dec 2011 10:28:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Re72q-0006aQ-OC for qemu-devel@nongnu.org; Fri, 23 Dec 2011 10:28:32 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:65051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Re72q-0006XR-Ab for qemu-devel@nongnu.org; Fri, 23 Dec 2011 10:28:28 -0500 Received: by mail-iy0-f173.google.com with SMTP id j37so17392251iag.4 for ; Fri, 23 Dec 2011 07:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=f+AmjBtq3J8DKegTKgvq0t12pVb7kj2iqI6WQlVpqBc=; b=XTrrbzGIWWo5K4Fjuz+RZ3XPr16709GdSJWlO5RffODc7Ma1Q+m7Yt8UVaVbq6RFfm Gj9YOz1Z+XIL030WcnXJGIXFOGT5idRyz0j7bf8cpASsgUu+WW7qSX33seBDTRhkPeFz aNekR+1UXyWbuvo2b7szl1W+KZtptrtafSZT8= Received: by 10.50.186.226 with SMTP id fn2mr14440839igc.25.1324654107941; Fri, 23 Dec 2011 07:28:27 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id aq5sm42055557igc.5.2011.12.23.07.28.22 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Dec 2011 07:28:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Dec 2011 16:26:14 +0100 Message-Id: <1324653990-20074-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1324653990-20074-1-git-send-email-pbonzini@redhat.com> References: <1324653990-20074-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.173 Cc: Chunyan Liu Subject: [Qemu-devel] [PATCH 10/26] Update ioctl order in nbd_init() to detect EBUSY 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 From: Chunyan Liu Update ioctl(s) in nbd_init() to detect device busy early. Current nbd_init() issues NBD_CLEAR_SOCKET before NBD_SET_SOCKET, if issuing "qemu-nbd -c /dev/nbd0 disk.img" twice, the second time won't detect EBUSY in nbd_init(), but in nbd_client will report EBUSY and do clear socket (the 1st time command will be affacted too because of no socket any more.) No change to previous version. Signed-off-by: Chunyan Liu Signed-off-by: Paolo Bonzini --- nbd.c | 27 +++++++++------------------ 1 files changed, 9 insertions(+), 18 deletions(-) diff --git a/nbd.c b/nbd.c index 7ab1b1f..73fedeb 100644 --- a/nbd.c +++ b/nbd.c @@ -358,6 +358,15 @@ int nbd_receive_negotiate(int csock, const char *name, uint32_t *flags, #ifdef __linux__ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize) { + TRACE("Setting NBD socket"); + + if (ioctl(fd, NBD_SET_SOCK, csock) == -1) { + int serrno = errno; + LOG("Failed to set NBD socket"); + errno = serrno; + return -1; + } + TRACE("Setting block size to %lu", (unsigned long)blocksize); if (ioctl(fd, NBD_SET_BLKSIZE, blocksize) == -1) { @@ -396,24 +405,6 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize) return -1; } - TRACE("Clearing NBD socket"); - - if (ioctl(fd, NBD_CLEAR_SOCK) == -1) { - int serrno = errno; - LOG("Failed clearing NBD socket"); - errno = serrno; - return -1; - } - - TRACE("Setting NBD socket"); - - if (ioctl(fd, NBD_SET_SOCK, csock) == -1) { - int serrno = errno; - LOG("Failed to set NBD socket"); - errno = serrno; - return -1; - } - TRACE("Negotiation ended"); return 0;