From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539795127426437.9046321911853; Wed, 17 Oct 2018 09:52:07 -0700 (PDT) Received: from localhost ([::1]:38168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCp3G-0006Ui-8j for importer@patchew.org; Wed, 17 Oct 2018 12:52:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouT-0007YS-30 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-00042U-Pl for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45132) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou8-0002NA-UK; Wed, 17 Oct 2018 12:42:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CDF20308421D; Wed, 17 Oct 2018 16:42:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C02C189C0; Wed, 17 Oct 2018 16:42:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:52 +0200 Message-Id: <20181017164200.22344-2-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 17 Oct 2018 16:42:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/9] block: Update flags in bdrv_set_read_only() 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To fully change the read-only state of a node, we must not only change bs->read_only, but also update bs->open_flags. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block.c b/block.c index 0d6e5f1a76..d7bd6d29b4 100644 --- a/block.c +++ b/block.c @@ -281,6 +281,13 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read= _only, Error **errp) } =20 bs->read_only =3D read_only; + + if (read_only) { + bs->open_flags &=3D ~BDRV_O_RDWR; + } else { + bs->open_flags |=3D BDRV_O_RDWR; + } + return 0; } =20 --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794730322149.01244818889984; Wed, 17 Oct 2018 09:45:30 -0700 (PDT) Received: from localhost ([::1]:38129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCowq-0001AB-LG for importer@patchew.org; Wed, 17 Oct 2018 12:45:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouL-00078B-BT for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-00041f-Jn for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou9-0002QY-7U; Wed, 17 Oct 2018 12:42:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86C0D5F744; Wed, 17 Oct 2018 16:42:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F6061359; Wed, 17 Oct 2018 16:42:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:53 +0200 Message-Id: <20181017164200.22344-3-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 17 Oct 2018 16:42:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/9] block: Add auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If a management application builds the block graph node by node, the protocol layer doesn't inherit its read-only option from the format layer any more, so it must be set explicitly. Backing files should work on read-only storage, but at the same time, a block job like commit should be able to reopen them read-write if they are on read-write storage. However, without option inheritance, reopen only changes the read-only option for the root node (typically the format layer), but not the protocol layer, so reopening fails (the format layer wants to get write permissions, but the protocol layer is still read-only). A simple workaround for the problem in the management tool would be to open the protocol layer always read-write and to make only the format layer read-only for backing files. However, sometimes the file is actually stored on read-only storage and we don't know whether the image can be opened read-write (for example, for NBD it depends on the server we're trying to connect to). This adds an option that makes QEMU try to open the image read-write, but allows it to degrade to a read-only mode without returning an error. The documentation for this option is consciously phrased in a way that allows QEMU to switch to a better model eventually: Instead of trying when the image is first opened, making the read-only flag dynamic and changing it automatically whenever the first BLK_PERM_WRITE user is attached or the last one is detached would be much more useful behaviour. Unfortunately, this more useful behaviour is also a lot harder to implement, and libvirt needs a solution now before it can switch to -blockdev, so let's start with this easier approach for now. Instead of adding a new auto-read-only option, turning the existing read-only into an enum (with a bool alternate for compatibility) was considered, but it complicated the implementation to the point that it didn't seem to be worth it. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- qapi/block-core.json | 7 +++++++ include/block/block.h | 2 ++ block.c | 17 +++++++++++++++++ block/vvfat.c | 1 + 4 files changed, 27 insertions(+) diff --git a/qapi/block-core.json b/qapi/block-core.json index cfb37f8c1d..2ac4e69e68 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3651,6 +3651,12 @@ # either generally or in certain configurations. In this c= ase, # the default value does not work and the option must be # specified explicitly. +# @auto-read-only: if true and @read-only is false, QEMU may automatically +# decide not to open the image read-write as requested, b= ut +# fall back to read-only instead (and switch between the = modes +# later), e.g. depending on whether the image file is wri= table +# or whether a writing user is attached to the node +# (default: false, since 3.1) # @detect-zeroes: detect and optimize zero writes (Since 2.1) # (default: off) # @force-share: force share all permission on added nodes. @@ -3666,6 +3672,7 @@ '*discard': 'BlockdevDiscardOptions', '*cache': 'BlockdevCacheOptions', '*read-only': 'bool', + '*auto-read-only': 'bool', '*force-share': 'bool', '*detect-zeroes': 'BlockdevDetectZeroesOptions' }, 'discriminator': 'driver', diff --git a/include/block/block.h b/include/block/block.h index b189cf422e..580b3716c3 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -115,6 +115,7 @@ typedef struct HDGeometry { select an appropriate protocol drive= r, ignoring the format layer */ #define BDRV_O_NO_IO 0x10000 /* don't initialize for I/O */ +#define BDRV_O_AUTO_RDONLY 0x20000 /* degrade to read-only if opening read= -write fails */ =20 #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_NO_FLUSH) =20 @@ -125,6 +126,7 @@ typedef struct HDGeometry { #define BDRV_OPT_CACHE_DIRECT "cache.direct" #define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush" #define BDRV_OPT_READ_ONLY "read-only" +#define BDRV_OPT_AUTO_READ_ONLY "auto-read-only" #define BDRV_OPT_DISCARD "discard" #define BDRV_OPT_FORCE_SHARE "force-share" =20 diff --git a/block.c b/block.c index d7bd6d29b4..ed73522cc6 100644 --- a/block.c +++ b/block.c @@ -930,6 +930,7 @@ static void bdrv_inherited_options(int *child_flags, QD= ict *child_options, =20 /* Inherit the read-only option from the parent if it's not set */ qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); + qdict_copy_default(child_options, parent_options, BDRV_OPT_AUTO_READ_O= NLY); =20 /* Our block drivers take care to send flushes and respect unmap polic= y, * so we can default to enable both on lower layers regardless of the @@ -1053,6 +1054,7 @@ static void bdrv_backing_options(int *child_flags, QD= ict *child_options, =20 /* backing files always opened read-only */ qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); + qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); flags &=3D ~BDRV_O_COPY_ON_READ; =20 /* snapshot=3Don is handled on the top layer */ @@ -1142,6 +1144,10 @@ static void update_flags_from_options(int *flags, Qe= muOpts *opts) *flags |=3D BDRV_O_RDWR; } =20 + assert(qemu_opt_find(opts, BDRV_OPT_AUTO_READ_ONLY)); + if (qemu_opt_get_bool_del(opts, BDRV_OPT_AUTO_READ_ONLY, false)) { + *flags |=3D BDRV_O_AUTO_RDONLY; + } } =20 static void update_options_from_flags(QDict *options, int flags) @@ -1156,6 +1162,10 @@ static void update_options_from_flags(QDict *options= , int flags) if (!qdict_haskey(options, BDRV_OPT_READ_ONLY)) { qdict_put_bool(options, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR)= ); } + if (!qdict_haskey(options, BDRV_OPT_AUTO_READ_ONLY)) { + qdict_put_bool(options, BDRV_OPT_AUTO_READ_ONLY, + flags & BDRV_O_AUTO_RDONLY); + } } =20 static void bdrv_assign_node_name(BlockDriverState *bs, @@ -1328,6 +1338,11 @@ QemuOptsList bdrv_runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "Node is opened in read-only mode", }, + { + .name =3D BDRV_OPT_AUTO_READ_ONLY, + .type =3D QEMU_OPT_BOOL, + .help =3D "Node can become read-only if opening read-write fai= ls", + }, { .name =3D "detect-zeroes", .type =3D QEMU_OPT_STRING, @@ -2486,6 +2501,8 @@ BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef = *ref, Error **errp) qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); qdict_set_default_str(qdict, BDRV_OPT_READ_ONLY, "off"); + qdict_set_default_str(qdict, BDRV_OPT_AUTO_READ_ONLY, "off"); + } =20 bs =3D bdrv_open_inherit(NULL, reference, qdict, 0, NULL, NULL, errp); diff --git a/block/vvfat.c b/block/vvfat.c index f2e7d501cf..98ba5e2bac 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -3130,6 +3130,7 @@ static void vvfat_qcow_options(int *child_flags, QDic= t *child_options, int parent_flags, QDict *parent_options) { qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "off"); + qdict_set_default_str(child_options, BDRV_OPT_AUTO_READ_ONLY, "off"); qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on"); } =20 --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794894168298.24097844339417; Wed, 17 Oct 2018 09:48:14 -0700 (PDT) Received: from localhost ([::1]:38144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCozV-0003MO-08 for importer@patchew.org; Wed, 17 Oct 2018 12:48:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouT-0007YW-3k for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouK-0004Fm-Ef for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou7-0002Ut-08; Wed, 17 Oct 2018 12:42:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 412243082133; Wed, 17 Oct 2018 16:42:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0E8F60160; Wed, 17 Oct 2018 16:42:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:54 +0200 Message-Id: <20181017164200.22344-4-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Oct 2018 16:42:11 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/9] block: Require auto-read-only for existing fallbacks 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some block drivers have traditionally changed their node to read-only mode without asking the user. This behaviour has been marked deprecated since 2.11, expecting users to provide an explicit read-only=3Don option. Now that we have auto-read-only=3Don, enable these drivers to make use of the option. This is the only use of bdrv_set_read_only(), so we can make it a bit more specific and turn it into a bdrv_apply_auto_read_only() that is more convenient for drivers to use. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/block.h | 3 ++- block.c | 42 +++++++++++++++++++++++++++--------------- block/bochs.c | 17 ++++++----------- block/cloop.c | 16 +++++----------- block/dmg.c | 16 +++++----------- block/rbd.c | 14 ++++---------- block/vvfat.c | 10 ++-------- 7 files changed, 51 insertions(+), 67 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 580b3716c3..7f5453b45b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -438,7 +438,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, 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); +int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, + Error **errp); bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); diff --git a/block.c b/block.c index ed73522cc6..a97e324f39 100644 --- a/block.c +++ b/block.c @@ -266,29 +266,41 @@ int bdrv_can_set_read_only(BlockDriverState *bs, bool= read_only, return 0; } =20 -/* TODO Remove (deprecated since 2.11) - * Block drivers are not supposed to automatically change bs->read_only. - * Instead, they should just check whether they can provide what the user - * explicitly requested and error out if read-write is requested, but they= can - * only provide read-only access. */ -int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp) +/* + * Called by a driver that can only provide a read-only image. + * + * Returns 0 if the node is already read-only or it could switch the node = to + * read-only because BDRV_O_AUTO_RDONLY is set. + * + * Returns -EACCES if the node is read-write and BDRV_O_AUTO_RDONLY is not= set + * or bdrv_can_set_read_only() forbids making the node read-only. If @errm= sg + * is not NULL, it is used as the error message for the Error object. + */ +int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, + Error **errp) { int ret =3D 0; =20 - ret =3D bdrv_can_set_read_only(bs, read_only, false, errp); - if (ret < 0) { - return ret; + if (!(bs->open_flags & BDRV_O_RDWR)) { + return 0; + } + if (!(bs->open_flags & BDRV_O_AUTO_RDONLY)) { + goto fail; } =20 - bs->read_only =3D read_only; - - if (read_only) { - bs->open_flags &=3D ~BDRV_O_RDWR; - } else { - bs->open_flags |=3D BDRV_O_RDWR; + ret =3D bdrv_can_set_read_only(bs, true, false, NULL); + if (ret < 0) { + goto fail; } =20 + bs->read_only =3D true; + bs->open_flags &=3D ~BDRV_O_RDWR; + return 0; + +fail: + error_setg(errp, "%s", errmsg ?: "Image is read-only"); + return -EACCES; } =20 void bdrv_get_full_backing_filename_from_filename(const char *backed, diff --git a/block/bochs.c b/block/bochs.c index 50c630047b..22e7d44211 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -105,23 +105,18 @@ static int bochs_open(BlockDriverState *bs, QDict *op= tions, int flags, struct bochs_header bochs; int ret; =20 + /* No write support yet */ + ret =3D bdrv_apply_auto_read_only(bs, NULL, errp); + if (ret < 0) { + return ret; + } + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { return -EINVAL; } =20 - if (!bdrv_is_read_only(bs)) { - error_report("Opening bochs images without an explicit read-only= =3Don " - "option is deprecated. Future versions will refuse to= " - "open the image instead of automatically marking the " - "image read-only."); - ret =3D bdrv_set_read_only(bs, true, errp); /* no write support ye= t */ - if (ret < 0) { - return ret; - } - } - ret =3D bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)); if (ret < 0) { return ret; diff --git a/block/cloop.c b/block/cloop.c index 2be68987bd..df2b85f723 100644 --- a/block/cloop.c +++ b/block/cloop.c @@ -67,23 +67,17 @@ static int cloop_open(BlockDriverState *bs, QDict *opti= ons, int flags, uint32_t offsets_size, max_compressed_block_size =3D 1, i; int ret; =20 + ret =3D bdrv_apply_auto_read_only(bs, NULL, errp); + if (ret < 0) { + return ret; + } + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { return -EINVAL; } =20 - if (!bdrv_is_read_only(bs)) { - error_report("Opening cloop images without an explicit read-only= =3Don " - "option is deprecated. Future versions will refuse to= " - "open the image instead of automatically marking the " - "image read-only."); - ret =3D bdrv_set_read_only(bs, true, errp); - if (ret < 0) { - return ret; - } - } - /* read header */ ret =3D bdrv_pread(bs->file, 128, &s->block_size, 4); if (ret < 0) { diff --git a/block/dmg.c b/block/dmg.c index c9b3c519c4..1d9283ba2f 100644 --- a/block/dmg.c +++ b/block/dmg.c @@ -413,23 +413,17 @@ static int dmg_open(BlockDriverState *bs, QDict *opti= ons, int flags, int64_t offset; int ret; =20 + ret =3D bdrv_apply_auto_read_only(bs, NULL, errp); + if (ret < 0) { + return ret; + } + bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { return -EINVAL; } =20 - if (!bdrv_is_read_only(bs)) { - error_report("Opening dmg images without an explicit read-only=3Do= n " - "option is deprecated. Future versions will refuse to= " - "open the image instead of automatically marking the " - "image read-only."); - ret =3D bdrv_set_read_only(bs, true, errp); - if (ret < 0) { - return ret; - } - } - block_module_load_one("dmg-bz2"); =20 s->n_chunks =3D 0; diff --git a/block/rbd.c b/block/rbd.c index 014c68d629..ee0b4a6941 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -780,16 +780,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict = *options, int flags, /* If we are using an rbd snapshot, we must be r/o, otherwise * leave as-is */ if (s->snap !=3D NULL) { - if (!bdrv_is_read_only(bs)) { - error_report("Opening rbd snapshots without an explicit " - "read-only=3Don option is deprecated. Future vers= ions " - "will refuse to open the image instead of " - "automatically marking the image read-only."); - r =3D bdrv_set_read_only(bs, true, &local_err); - if (r < 0) { - error_propagate(errp, local_err); - goto failed_open; - } + r =3D bdrv_apply_auto_read_only(bs, "rbd snapshots are read-only",= errp); + if (r < 0) { + rbd_close(s->image); + goto failed_open; } } =20 diff --git a/block/vvfat.c b/block/vvfat.c index 98ba5e2bac..e4df255d58 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1262,15 +1262,9 @@ static int vvfat_open(BlockDriverState *bs, QDict *o= ptions, int flags, "Unable to set VVFAT to 'rw' when drive is read-onl= y"); goto fail; } - } else if (!bdrv_is_read_only(bs)) { - error_report("Opening non-rw vvfat images without an explicit " - "read-only=3Don option is deprecated. Future versions= " - "will refuse to open the image instead of " - "automatically marking the image read-only."); - /* read only is the default for safety */ - ret =3D bdrv_set_read_only(bs, true, &local_err); + } else { + ret =3D bdrv_apply_auto_read_only(bs, NULL, errp); if (ret < 0) { - error_propagate(errp, local_err); goto fail; } } --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794719868832.3690304895001; Wed, 17 Oct 2018 09:45:19 -0700 (PDT) Received: from localhost ([::1]:38127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCowT-0000bS-07 for importer@patchew.org; Wed, 17 Oct 2018 12:45:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouJ-00070U-07 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-000406-4f for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou7-0002Yp-SZ; Wed, 17 Oct 2018 12:42:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B12F30C9F0C; Wed, 17 Oct 2018 16:42:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AC6460160; Wed, 17 Oct 2018 16:42:11 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:55 +0200 Message-Id: <20181017164200.22344-5-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Oct 2018 16:42:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 4/9] nbd: Support auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If read-only=3Doff, but auto-read-only=3Don is given, open a read-write NBD connection if the server provides a read-write export, but instead of erroring out for read-only exports, just degrade to read-only. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/nbd-client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 9686ecbd5e..76e9ca3abe 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -992,11 +992,11 @@ int nbd_client_init(BlockDriverState *bs, logout("Failed to negotiate with the NBD server\n"); return ret; } - if (client->info.flags & NBD_FLAG_READ_ONLY && - !bdrv_is_read_only(bs)) { - error_setg(errp, - "request for write access conflicts with read-only expo= rt"); - return -EACCES; + if (client->info.flags & NBD_FLAG_READ_ONLY) { + ret =3D bdrv_apply_auto_read_only(bs, "NBD export is read-only", e= rrp); + if (ret < 0) { + return ret; + } } if (client->info.flags & NBD_FLAG_SEND_FUA) { bs->supported_write_flags =3D BDRV_REQ_FUA; --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539795029573435.04754132554785; Wed, 17 Oct 2018 09:50:29 -0700 (PDT) Received: from localhost ([::1]:38156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCp1g-0005P1-Cn for importer@patchew.org; Wed, 17 Oct 2018 12:50:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouJ-00072x-K1 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-00041A-EO for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35300) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou9-0002cn-Mi; Wed, 17 Oct 2018 12:42:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B236730B8FB9; Wed, 17 Oct 2018 16:42:14 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CB5760160; Wed, 17 Oct 2018 16:42:13 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:56 +0200 Message-Id: <20181017164200.22344-6-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 17 Oct 2018 16:42:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 5/9] file-posix: Support auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If read-only=3Doff, but auto-read-only=3Don is given, open the file read-write if we have the permissions, but instead of erroring out for read-only files, just degrade to read-only. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/file-posix.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 2da3a76355..0c1b81ce4b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -527,9 +527,22 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, =20 s->fd =3D -1; fd =3D qemu_open(filename, s->open_flags, 0644); - if (fd < 0) { - ret =3D -errno; - error_setg_errno(errp, errno, "Could not open '%s'", filename); + ret =3D fd < 0 ? -errno : 0; + + if (ret =3D=3D -EACCES || ret =3D=3D -EROFS) { + /* Try to degrade to read-only, but if it doesn't work, still use = the + * normal error message. */ + if (bdrv_apply_auto_read_only(bs, NULL, NULL) =3D=3D 0) { + bdrv_flags &=3D ~BDRV_O_RDWR; + raw_parse_flags(bdrv_flags, &s->open_flags); + assert(!(s->open_flags & O_CREAT)); + fd =3D qemu_open(filename, s->open_flags); + ret =3D fd < 0 ? -errno : 0; + } + } + + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not open '%s'", filename); if (ret =3D=3D -EROFS) { ret =3D -EACCES; } --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794881871981.2269911557828; Wed, 17 Oct 2018 09:48:01 -0700 (PDT) Received: from localhost ([::1]:38143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCozI-00038y-Ld for importer@patchew.org; Wed, 17 Oct 2018 12:48:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouJ-000717-6x for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-000410-D9 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44276) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou9-0002jB-7E; Wed, 17 Oct 2018 12:42:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DF53CD185; Wed, 17 Oct 2018 16:42:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0754761359; Wed, 17 Oct 2018 16:42:14 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:57 +0200 Message-Id: <20181017164200.22344-7-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 17 Oct 2018 16:42:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 6/9] curl: Support auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If read-only=3Doff, but auto-read-only=3Don is given, just degrade to read-only. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/curl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/curl.c b/block/curl.c index fabb2b4da7..db5d2bd8ef 100644 --- a/block/curl.c +++ b/block/curl.c @@ -684,10 +684,10 @@ static int curl_open(BlockDriverState *bs, QDict *opt= ions, int flags, const char *protocol_delimiter; int ret; =20 - - if (flags & BDRV_O_RDWR) { - error_setg(errp, "curl block device does not support writes"); - return -EROFS; + ret =3D bdrv_apply_auto_read_only(bs, "curl driver does not support wr= ites", + errp); + if (ret < 0) { + return ret; } =20 if (!libcurl_initialized) { --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539795057983228.86449812265755; Wed, 17 Oct 2018 09:50:57 -0700 (PDT) Received: from localhost ([::1]:38159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCp1z-0005Zj-Bd for importer@patchew.org; Wed, 17 Oct 2018 12:50:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouT-0007YR-2w for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouI-00048S-Hl for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou9-0002qf-2q; Wed, 17 Oct 2018 12:42:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74C5730001E3; Wed, 17 Oct 2018 16:42:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56A6C61359; Wed, 17 Oct 2018 16:42:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:58 +0200 Message-Id: <20181017164200.22344-8-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 17 Oct 2018 16:42:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 7/9] gluster: Support auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If read-only=3Doff, but auto-read-only=3Don is given, open the file read-write if we have the permissions, but instead of erroring out for read-only files, just degrade to read-only. Signed-off-by: Kevin Wolf Reviewed-by: Niels de Vos --- block/gluster.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/gluster.c b/block/gluster.c index 4fd55a9cc5..5e300c96c8 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -849,8 +849,16 @@ static int qemu_gluster_open(BlockDriverState *bs, QD= ict *options, qemu_gluster_parse_flags(bdrv_flags, &open_flags); =20 s->fd =3D glfs_open(s->glfs, gconf->path, open_flags); - if (!s->fd) { - ret =3D -errno; + ret =3D s->fd ? 0 : -errno; + + if (ret =3D=3D -EACCES || ret =3D=3D -EROFS) { + /* Try to degrade to read-only, but if it doesn't work, still use = the + * normal error message. */ + if (bdrv_apply_auto_read_only(bs, NULL, NULL) =3D=3D 0) { + open_flags =3D (open_flags & ~O_RDWR) | O_RDONLY; + s->fd =3D glfs_open(s->glfs, gconf->path, open_flags); + ret =3D s->fd ? 0 : -errno; + } } =20 s->supports_seek_data =3D qemu_gluster_test_seek(s->fd); --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794903185232.12668057818132; Wed, 17 Oct 2018 09:48:23 -0700 (PDT) Received: from localhost ([::1]:38145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCozd-0003aW-Kw for importer@patchew.org; Wed, 17 Oct 2018 12:48:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouT-0007YU-3J for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:43:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouK-0004Eb-34 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44082) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCouA-0002sy-7g; Wed, 17 Oct 2018 12:42:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C3BB315009D; Wed, 17 Oct 2018 16:42:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id C02EE61359; Wed, 17 Oct 2018 16:42:22 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:41:59 +0200 Message-Id: <20181017164200.22344-9-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 17 Oct 2018 16:42:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 8/9] iscsi: Support auto-read-only option 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If read-only=3Doff, but auto-read-only=3Don is given, open the volume read-write if we have the permissions, but instead of erroring out for read-only volumes, just degrade to read-only. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block/iscsi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index bb69faf34a..130ae26f5f 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1878,9 +1878,11 @@ static int iscsi_open(BlockDriverState *bs, QDict *o= ptions, int flags, /* Check the write protect flag of the LUN if we want to write */ if (iscsilun->type =3D=3D TYPE_DISK && (flags & BDRV_O_RDWR) && iscsilun->write_protected) { - error_setg(errp, "Cannot open a write protected LUN as read-write"= ); - ret =3D -EACCES; - goto out; + ret =3D bdrv_apply_auto_read_only(bs, "LUN is write protected", er= rp); + if (ret < 0) { + goto out; + } + flags &=3D ~BDRV_O_RDWR; } =20 iscsi_readcapacity_sync(iscsilun, &local_err); --=20 2.19.1 From nobody Thu Nov 6 06:14: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; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539794744873950.2741945337717; Wed, 17 Oct 2018 09:45:44 -0700 (PDT) Received: from localhost ([::1]:38131 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCox2-0001Hz-E7 for importer@patchew.org; Wed, 17 Oct 2018 12:45:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCouJ-000713-48 for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCouG-00040P-6x for qemu-devel@nongnu.org; Wed, 17 Oct 2018 12:42:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43640) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCou9-0002vu-L5; Wed, 17 Oct 2018 12:42:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA9513082B24; Wed, 17 Oct 2018 16:42:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-213.ams2.redhat.com [10.36.117.213]) by smtp.corp.redhat.com (Postfix) with ESMTP id 766BF69FDD; Wed, 17 Oct 2018 16:42:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 17 Oct 2018 18:42:00 +0200 Message-Id: <20181017164200.22344-10-kwolf@redhat.com> In-Reply-To: <20181017164200.22344-1-kwolf@redhat.com> References: <20181017164200.22344-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 17 Oct 2018 16:42:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 9/9] block: Make auto-read-only=on default for -drive 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: kwolf@redhat.com, pkrempa@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" While we want machine interfaces like -blockdev and QMP blockdev-add to add as little auto-detection as possible so that management tools are explicit about their needs, -drive is a convenience option for human users. Enabling auto-read-only=3Don by default there enables users to use read-only images for read-only guest devices without having to specify read-only=3Don explicitly. If they try to attach the image to a read-write device, they will still get an error message. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- blockdev.c | 1 + 1 file changed, 1 insertion(+) diff --git a/blockdev.c b/blockdev.c index a8755bd908..ab57a8a53a 100644 --- a/blockdev.c +++ b/blockdev.c @@ -590,6 +590,7 @@ static BlockBackend *blockdev_init(const char *file, QD= ict *bs_opts, qdict_set_default_str(bs_opts, BDRV_OPT_CACHE_NO_FLUSH, "off"); qdict_set_default_str(bs_opts, BDRV_OPT_READ_ONLY, read_only ? "on" : "off"); + qdict_set_default_str(bs_opts, BDRV_OPT_AUTO_READ_ONLY, "on"); assert((bdrv_flags & BDRV_O_CACHE_MASK) =3D=3D 0); =20 if (runstate_check(RUN_STATE_INMIGRATE)) { --=20 2.19.1