From nobody Wed Nov 5 16:40:53 2025 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 1536227230767459.2375809365485; Thu, 6 Sep 2018 02:47:10 -0700 (PDT) Received: from localhost ([::1]:60499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqsX-000506-KD for importer@patchew.org; Thu, 06 Sep 2018 05:47:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jG-P3 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003Zr-P5 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54011) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q6-3c; Thu, 06 Sep 2018 05:37:34 -0400 Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049y-KT; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiz-0001oB-6U; Thu, 06 Sep 2018 12:37:17 +0300 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=skNL4sSYePvUP93ucpBIl0e+sEgKLp4XpoBrdpEYsaw=; b=Jwk+sWiXcwSyp1JRXd4KIGM9zm1Vaxa/REnwwjf6Ls/81juIA1LGhS1cGFAgvcRqsO+16Q0g4D5zTQ9SJ93jpF56ylTu4dMcPi2n94Fy/9Qkg95lqvqdZP/IW4UBPUzhHRxkSfYgRVm6V96u+pD3Bp8AIJ+I9L/zdTataL2ksxJsma9WBvrcJCb0RwcSl0Az6oqoPBzb0wI4TT0R08fSXti5dSb2FcdXZIZV1UyhXlGgsVoAUKBPdygDUZJmT+ue+H+uzSj59DXYWuSEZJHq5uSwYxheu0IW2cqt85vUKk5xXg6Omwl5bhnY1YaJRQkqC2NWn7HrCAPTfu9Fkn99oA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:10 +0300 Message-Id: <3c1b1ad5e50b71d98e0d6dcdc2ffb02681c600c7.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 10/10] block: Allow changing 'force-share' on reopen 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: Kevin Wolf , Alberto Garcia , qemu-block@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" 'force-share' is one of the basic BlockdevOptions available for all drivers, but it's not handled by bdrv_reopen_prepare() so any attempt to change it results in a "Cannot change the option" error: (qemu) qemu-io virtio0 "reopen -o force-share=3Don" Cannot change the option 'force-share' Since there's no reason why we shouldn't allow changing it and the implementation is simple let's just do it. It's worth noting that after this patch the above reopen call will still return an error -although a different one- if the image is not read-only: (qemu) qemu-io virtio0 "reopen -o force-share=3Don" force-share=3Don can only be used with read-only images Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 30 ++++++++++++++++++++++++------ include/block/block.h | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 808411ebf3..57cc4161a2 100644 --- a/block.c +++ b/block.c @@ -789,6 +789,18 @@ static BlockdevDetectZeroesOptions bdrv_parse_detect_z= eroes(QemuOpts *opts, return detect_zeroes; } =20 +static bool bdrv_parse_force_share(QemuOpts *opts, int flags, Error **errp) +{ + bool value =3D qemu_opt_get_bool_del(opts, BDRV_OPT_FORCE_SHARE, false= ); + + if (value && (flags & BDRV_O_RDWR)) { + error_setg(errp, BDRV_OPT_FORCE_SHARE + "=3Don can only be used with read-only images"); + } + + return value; +} + /** * Set open flags for a given discard mode * @@ -1374,12 +1386,9 @@ static int bdrv_open_common(BlockDriverState *bs, Bl= ockBackend *file, drv =3D bdrv_find_format(driver_name); assert(drv !=3D NULL); =20 - bs->force_share =3D qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, fals= e); - - if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) { - error_setg(errp, - BDRV_OPT_FORCE_SHARE - "=3Don can only be used with read-only images"); + bs->force_share =3D bdrv_parse_force_share(opts, bs->open_flags, &loca= l_err); + if (local_err) { + error_propagate(errp, local_err); ret =3D -EINVAL; goto fail_opts; } @@ -3202,6 +3211,14 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_stat= e, BlockReopenQueue *queue, goto error; } =20 + reopen_state->force_share =3D + bdrv_parse_force_share(opts, reopen_state->flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto error; + } + /* All other options (including node-name and driver) must be unchange= d. * Put them back into the QDict, so that they are checked at the end * of this function. */ @@ -3353,6 +3370,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) bs->open_flags =3D reopen_state->flags; bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); bs->detect_zeroes =3D reopen_state->detect_zeroes; + bs->force_share =3D reopen_state->force_share; =20 /* Remove child references from bs->options and bs->explicit_options. * Child options were already removed in bdrv_reopen_queue_child() */ diff --git a/include/block/block.h b/include/block/block.h index f71fa5a1c4..a49a027c54 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -185,6 +185,7 @@ typedef struct BDRVReopenState { BlockDriverState *bs; int flags; BlockdevDetectZeroesOptions detect_zeroes; + bool force_share; uint64_t perm, shared_perm; QDict *options; QDict *explicit_options; --=20 2.11.0