From nobody Mon Feb 9 23:01:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529372796041931.8338213567708; Mon, 18 Jun 2018 18:46:36 -0700 (PDT) Received: from localhost ([::1]:38369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5j9-00025i-6r for importer@patchew.org; Mon, 18 Jun 2018 21:46:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5gZ-0008So-IS for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:43:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5gY-0007d1-M4 for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:43:55 -0400 Received: from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]:46050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5gY-0007cm-GF; Mon, 18 Jun 2018 21:43:54 -0400 Received: by mail-oi0-x22c.google.com with SMTP id 188-v6so16657168oid.12; Mon, 18 Jun 2018 18:43:54 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id r40-v6sm14668917otr.62.2018.06.18.18.43.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:43:52 -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=h69UsiZQnsE422HEk04j0thL55/eYRX9JPKYC00mlD4=; b=qCgSK4oE4gVcWQuzQGAc4/A+eBsblzFh42SMOjZv0VGBWqKUVpsHAvLS8fDCIyLsOI nOTV8b1ezhynm7ZbLJ2/0s9QKs1Q0MaoOAGH66+qzmNk+4CwzAaTllKpVwzaF7l597LX 1iulqsMzavlVBQEM8QsHv2GJQW4b/Lo/I2XdN6jonkETMyw2P5Pt2dt3qq8THjGYCIPX ynpRRt5Kgt7ZUctevyEyi1oT/l9VEjVt5XUbg1xoRmfeF/gW/Ntnnqz6AOXw/ZxpRX8d JwFteWQOC/aGKjpfmITdPUHjAt37brK6mc/2RLCYRb/gHEuyxV3dMV0VVIImTvfhbO+R APSA== 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=h69UsiZQnsE422HEk04j0thL55/eYRX9JPKYC00mlD4=; b=fM1eh6GlgiDu0vLSDjtGFGr+94gk+lKg6qsqXA4FtJimd/1yjd9J9WWTKcHT3bwFBq Uammn1IWNyld3tJ7xcSLafzT5inJbAbacFu+3Z22HxGKN0Wy/TBl5GmLporoLkFuZ9G3 MinAID22NpJ4n8h5NbohRBIoz0hngAyh2AU24ESnc94r1FktIia/ur/qORC8HoUtxhHB 9lifgdV1WwEVWCTxZW2zTVj6d/nlchU891psduKJ7cYZ/d97chVBZIvzbYFrCieonlxx cx0fg2B3Z2Rvrtv9kKH/A7Tc1CRumy1uQfACkwjYV9SlaedaT0bu4GdqjbdIwob4vOtz Zh/g== X-Gm-Message-State: APt69E1OdbJjyL2ajcDI55Fc9mNBU6vu0KuvZyR+IX2blfPrcRhXSdw0 YhdeoMLsMbyT4rrz+6uAIBBjhGyJ X-Google-Smtp-Source: ADUXVKJJ8wJQadfkVGqDN23ZAYBv7zm/FgutlWZyrenp1I7Izc0ioDOS2oVFVIe2PQyJ6+SZH2It7g== X-Received: by 2002:aca:3f87:: with SMTP id m129-v6mr8786946oia.58.1529372633301; Mon, 18 Jun 2018 18:43:53 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:43:07 -0500 Message-Id: <20180619014319.28272-102-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-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::22c Subject: [Qemu-devel] [PATCH 101/113] 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 f236431da1..24dd28d51d 100644 --- a/block.c +++ b/block.c @@ -1596,13 +1596,24 @@ static int bdrv_reopen_get_flags(BlockReopenQueue *= q, BlockDriverState *bs) =20 /* 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 =3D bdrv_reopen_get_flags(q, bs); =20 return (flags & (BDRV_O_RDWR | BDRV_O_INACTIVE)) =3D=3D BDRV_O_RDWR; } =20 +/* + * 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, @@ -1640,7 +1651,7 @@ static int bdrv_check_perm(BlockDriverState *bs, Bloc= kReopenQueue *q, =20 /* 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; @@ -1930,7 +1941,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, = BdrvChild *c, &perm, &shared); =20 /* Format drivers may touch metadata even if the guest doesn't wri= te */ - if (bdrv_is_writable(bs, reopen_queue)) { + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { perm |=3D BLK_PERM_WRITE | BLK_PERM_RESIZE; } =20 diff --git a/include/block/block.h b/include/block/block.h index c05cac57e5..f9e90beb21 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -437,6 +437,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); --=20 2.11.0