From patchwork Mon Feb 4 10:40:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 217924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3F3542C02AB for ; Tue, 5 Feb 2013 00:36:53 +1100 (EST) Received: from localhost ([::1]:58322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2JhU-0002uX-DC for incoming@patchwork.ozlabs.org; Mon, 04 Feb 2013 05:55:00 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2JhJ-0002u0-PK for qemu-devel@nongnu.org; Mon, 04 Feb 2013 05:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U2JhI-0004go-JP for qemu-devel@nongnu.org; Mon, 04 Feb 2013 05:54:49 -0500 Received: from isrv.corpit.ru ([86.62.121.231]:49048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U2JhI-0004gY-Bp; Mon, 04 Feb 2013 05:54:48 -0500 Received: from gandalf.tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by isrv.corpit.ru (Postfix) with ESMTP id 9A033A03F9; Mon, 4 Feb 2013 14:54:47 +0400 (MSK) Received: by gandalf.tls.msk.ru (Postfix, from userid 1000) id DE37953B; Mon, 4 Feb 2013 14:41:28 +0400 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Date: Mon, 4 Feb 2013 14:40:50 +0400 Message-Id: <1359974470-17044-41-git-send-email-mjt@msgid.tls.msk.ru> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359974470-17044-1-git-send-email-mjt@msgid.tls.msk.ru> References: <1359974470-17044-1-git-send-email-mjt@msgid.tls.msk.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 86.62.121.231 Cc: Paolo Bonzini , Michael Tokarev , qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 40/60] nbd: fixes to read-only handling 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: Paolo Bonzini We do not need BLKROSET if the kernel supports setting flags. Also, always do BLKROSET even for a read-write export, otherwise the read-only state remains "sticky" after the invocation of "qemu-nbd -r". Signed-off-by: Paolo Bonzini (cherry picked from commit c8969eded252058e90e91f12f75f32aceae46ec9) Signed-off-by: Michael Tokarev --- nbd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/nbd.c b/nbd.c index dc0adf9..6702b06 100644 --- a/nbd.c +++ b/nbd.c @@ -399,24 +399,23 @@ int nbd_init(int fd, int csock, uint32_t flags, off_t size, size_t blocksize) return -serrno; } - if (flags & NBD_FLAG_READ_ONLY) { - int read_only = 1; - TRACE("Setting readonly attribute"); - - if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { + if (ioctl(fd, NBD_SET_FLAGS, flags) < 0) { + if (errno == ENOTTY) { + int read_only = (flags & NBD_FLAG_READ_ONLY) != 0; + TRACE("Setting readonly attribute"); + + if (ioctl(fd, BLKROSET, (unsigned long) &read_only) < 0) { + int serrno = errno; + LOG("Failed setting read-only attribute"); + return -serrno; + } + } else { int serrno = errno; - LOG("Failed setting read-only attribute"); + LOG("Failed setting flags"); return -serrno; } } - if (ioctl(fd, NBD_SET_FLAGS, flags) < 0 - && errno != ENOTTY) { - int serrno = errno; - LOG("Failed setting flags"); - return -serrno; - } - TRACE("Negotiation ended"); return 0;