From patchwork Mon Jul 23 20:16:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 10540931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99BD914BC for ; Mon, 23 Jul 2018 20:42:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89B452849D for ; Mon, 23 Jul 2018 20:42:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E3A8284A5; Mon, 23 Jul 2018 20:42:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B0B82849D for ; Mon, 23 Jul 2018 20:42:32 +0000 (UTC) Received: from localhost ([::1]:36470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhf5-0005j4-7W for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 Jul 2018 16:42:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhJ9-0002J8-KC for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:19:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhhJ8-0003tF-5G for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:19:51 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:35587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhhJ7-0003sv-Vc; Mon, 23 Jul 2018 16:19:50 -0400 Received: by mail-oi0-x244.google.com with SMTP id i12-v6so3498569oik.2; Mon, 23 Jul 2018 13:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=pCk61jNpASXSU8QTX4bas5qw8IAILTpMH8w0PEvfmEA=; b=VYla2jS0+BJGVTlCGwA1kRthH1XvAUyA32HruGjIjFEBecUB3BZIc6ft3D2NFtb2el nosGYicVX/4fbYBSUKztPxEKRmkXkxE/2uT6Gquqz9QNOP5Dna3Wohf30DtnmrhdmB0u 9Crudyueg5nNpiHNYnq87he7b7Yg1OjfvRaDwClRe2oOf4/Exq8whuApszdfhyuXgrsd DCk1HlVOS6k6RL2BiqgFtfAcdFcQX6+jy05ky4+J4z/xW28KbfF6iPuyx/WjiYXsWIrz 8OhdjoS6AZkKpzkT6YwG88nyoUPKpEXu68S3Pfpd1Vw/D/EaFE4pKkB9Omei2AZ81C2M LkXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=pCk61jNpASXSU8QTX4bas5qw8IAILTpMH8w0PEvfmEA=; b=FERy8G+7bJaXdPDgXlMelDBsYVatU0PhInNcEwuiTFb279ofCIODa2uixLH+LcGE1K w89cf52aOGnD4WPCY7P1nYkHvfU48xvTKMgNR55IM9XjwcmvRR9fXLWOftabJM/yswBH SYB6UvCqQKw3cz2ytNCodiQr0YZIf2LTnt+0Hwn9cNbz7XB68VBf5pHQxblYQvBRI9I8 hfbtnm41XAgBf2hrBiVJMaRnR6kOBwT18T9Rb595FnEoMFX++ACYyMmJOpUEP5VxtKdu 4inonyF6Qh4dNeUUqDkC+1CGlb2+Lcm87P4ZZjFloOjn6FiyuBhPbwhas+oI/bu8uj5S 5hkA== X-Gm-Message-State: AOUpUlHBuoSlQ5+P3/xJnWxfd0y/NAx7iNBvvSNosHNZMxsneBbmiYNJ 07Es8jBHtP2KZ3yA18opeic2ldlPRqc= X-Google-Smtp-Source: AAOMgpeaI776ucPrS5PCR9x02QRkJY9ifJSFoImF87dl0EB18FTT7LiX4u1ydkH0O0R1VcAYEmMyvA== X-Received: by 2002:aca:be56:: with SMTP id o83-v6mr270674oif.301.1532377188838; Mon, 23 Jul 2018 13:19:48 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id i204-v6sm19818274oia.41.2018.07.23.13.19.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 13:19:47 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 15:16:47 -0500 Message-Id: <20180723201748.25573-39-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> References: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::244 Subject: [Qemu-devel] [PATCH 38/99] block: Make bdrv_is_writable() public X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-stable@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Max Reitz This is a useful function for the whole block layer, so make it public. At the same time, users outside of block.c probably do not need to make use of the reopen functionality, so rename the current function to bdrv_is_writable_after_reopen() create a new bdrv_is_writable() function that just passes NULL to it for the reopen queue. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20180606193702.7113-2-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Jeff Cody Signed-off-by: Max Reitz (cherry picked from commit cc022140972f8b6ac3973c12ccf9dd6b1d2fd200) Signed-off-by: Michael Roth --- block.c | 17 ++++++++++++++--- include/block/block.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index a2caadf0a0..9af22179ce 100644 --- a/block.c +++ b/block.c @@ -1620,13 +1620,24 @@ static int bdrv_reopen_get_flags(BlockReopenQueue *q, BlockDriverState *bs) /* Returns whether the image file can be written to after the reopen queue @q * has been successfully applied, or right now if @q is NULL. */ -static bool bdrv_is_writable(BlockDriverState *bs, BlockReopenQueue *q) +static bool bdrv_is_writable_after_reopen(BlockDriverState *bs, + BlockReopenQueue *q) { int flags = bdrv_reopen_get_flags(q, bs); return (flags & (BDRV_O_RDWR | BDRV_O_INACTIVE)) == BDRV_O_RDWR; } +/* + * Return whether the BDS can be written to. This is not necessarily + * the same as !bdrv_is_read_only(bs), as inactivated images may not + * be written to but do not count as read-only images. + */ +bool bdrv_is_writable(BlockDriverState *bs) +{ + return bdrv_is_writable_after_reopen(bs, NULL); +} + static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *reopen_queue, @@ -1664,7 +1675,7 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, /* Write permissions never work with read-only images */ if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && - !bdrv_is_writable(bs, q)) + !bdrv_is_writable_after_reopen(bs, q)) { error_setg(errp, "Block node is read-only"); return -EPERM; @@ -1956,7 +1967,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, &perm, &shared); /* Format drivers may touch metadata even if the guest doesn't write */ - if (bdrv_is_writable(bs, reopen_queue)) { + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE; } diff --git a/include/block/block.h b/include/block/block.h index cdec3639a3..68a667a742 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -400,6 +400,7 @@ bool bdrv_is_read_only(BlockDriverState *bs); int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, bool ignore_allow_rdw, Error **errp); int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); +bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); void bdrv_lock_medium(BlockDriverState *bs, bool locked);