From patchwork Mon Dec 3 22:08:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 203482 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 4CBA42C007E for ; Tue, 4 Dec 2012 10:04:10 +1100 (EST) Received: from localhost ([::1]:48224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfeJE-0008Pl-8s for incoming@patchwork.ozlabs.org; Mon, 03 Dec 2012 17:16:16 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50069) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfeIi-0007Zs-A1 for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:15:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfeIg-000368-Sc for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:15:44 -0500 Received: from mail-ia0-f173.google.com ([209.85.210.173]:49594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfeId-0002mU-8Z; Mon, 03 Dec 2012 17:15:39 -0500 Received: by mail-ia0-f173.google.com with SMTP id w21so2526528iac.4 for ; Mon, 03 Dec 2012 14:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=5AD5GbEXoI9K5tdugAPwd1c35WNIc5YLLFkjO76u51E=; b=TpCXnqhnuT6jyTDHj4AZR7nDkbmykXi6lPQVZiXUdXWNQTGWvN+H9l57wYouV6rBir 6MNmAdKCO4D5oZBwuUm97hx6WK1glj44LhFb0+Dtgajn9z9y/6FHTbL5jsDTtehY9S7X CTDFgaV6Ztvu0knwdlfsv1U+9+03aMXH7GLr8aSGJJZumSt4UvWNRF5fOIauQxEfmnzZ mf6HNUZvEca5eKomHQToY/uPgxbWuvFJW30sKoG7CwYF/7Y6lmWW8+NHiNPzRXZYPc/b ImgbwfBsFjkk3yfN35IlQ2bnxLF0MwBDBe1xgLQz8CZ/t0voR4k16a4lQst+khj8WB90 br3g== Received: by 10.50.7.232 with SMTP id m8mr550074iga.48.1354572939012; Mon, 03 Dec 2012 14:15:39 -0800 (PST) Received: from localhost ([32.97.110.59]) by mx.google.com with ESMTPS id az6sm8133630igb.11.2012.12.03.14.15.38 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 03 Dec 2012 14:15:38 -0800 (PST) From: Michael Roth To: qemu-stable@nongnu.org Date: Mon, 3 Dec 2012 16:08:43 -0600 Message-Id: <1354572547-21271-20-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.173 Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 19/43] 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 Roth --- nbd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/nbd.c b/nbd.c index 206f75c..19f6cd8 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;