From nobody Sat Apr 27 11:37:44 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501772728305751.7507947327557; Thu, 3 Aug 2017 08:05:28 -0700 (PDT) Received: from localhost ([::1]:51221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHgk-00042W-Hf for importer@patchew.org; Thu, 03 Aug 2017 11:05:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHek-0002bV-E1 for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddHef-0006XM-LH for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46904) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddHeb-0006Js-3t; Thu, 03 Aug 2017 11:03:13 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11B907F6BA; Thu, 3 Aug 2017 15:03:12 +0000 (UTC) Received: from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com [10.33.200.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03FFD80F76; Thu, 3 Aug 2017 15:03:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 11B907F6BA Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 3 Aug 2017 17:02:57 +0200 Message-Id: <20170803150301.10177-2-kwolf@redhat.com> In-Reply-To: <20170803150301.10177-1-kwolf@redhat.com> References: <20170803150301.10177-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 03 Aug 2017 15:03:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 1/5] block: Fix order in bdrv_replace_child() 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commit 8ee03995 refactored the code incorrectly and broke the release of permissions on the old BDS. Instead of changing the permissions to the new required values after removing the old BDS from the list of children, it only re-obtains the permissions it already had. Change the order of operations so that the old BDS is removed again before calculating the new required permissions. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index ce9cce7b3c..ab908cdc50 100644 --- a/block.c +++ b/block.c @@ -1933,6 +1933,8 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) BlockDriverState *old_bs =3D child->bs; uint64_t perm, shared_perm; =20 + bdrv_replace_child_noperm(child, new_bs); + if (old_bs) { /* Update permissions for old node. This is guaranteed to succeed * because we're just taking a parent away, so we're loosening @@ -1942,8 +1944,6 @@ static void bdrv_replace_child(BdrvChild *child, Bloc= kDriverState *new_bs) bdrv_set_perm(old_bs, perm, shared_perm); } =20 - bdrv_replace_child_noperm(child, new_bs); - if (new_bs) { bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm); bdrv_set_perm(new_bs, perm, shared_perm); --=20 2.13.3 From nobody Sat Apr 27 11:37:44 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501772726597298.2066462490965; Thu, 3 Aug 2017 08:05:26 -0700 (PDT) Received: from localhost ([::1]:51220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHgj-00040K-45 for importer@patchew.org; Thu, 03 Aug 2017 11:05:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHeh-0002Xn-1C for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddHef-0006XJ-MF for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddHec-0006Mf-AU; Thu, 03 Aug 2017 11:03:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DF1C4E334; Thu, 3 Aug 2017 15:03:13 +0000 (UTC) Received: from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com [10.33.200.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 526F380F6E; Thu, 3 Aug 2017 15:03:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4DF1C4E334 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 3 Aug 2017 17:02:58 +0200 Message-Id: <20170803150301.10177-3-kwolf@redhat.com> In-Reply-To: <20170803150301.10177-1-kwolf@redhat.com> References: <20170803150301.10177-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 03 Aug 2017 15:03:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 2/5] block: Allow reopen rw without BDRV_O_ALLOW_RDWR 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BDRV_O_ALLOW_RDWR is a flag that tells whether qemu can internally reopen a node read-write temporarily because the user requested read-write for the top-level image, but qemu decided that read-only is enough for this node (a backing file). bdrv_reopen() is different, it is also used for cases where the user changed their mind and wants to update the options. There is no reason to forbid making a node read-write in that case. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow --- include/block/block.h | 3 ++- block.c | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 34770bb33a..ab80195378 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -436,7 +436,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, =20 bool bdrv_is_read_only(BlockDriverState *bs); bool bdrv_is_writable(BlockDriverState *bs); -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **e= rrp); +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_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); diff --git a/block.c b/block.c index ab908cdc50..2711c3dd3b 100644 --- a/block.c +++ b/block.c @@ -246,7 +246,8 @@ bool bdrv_is_writable(BlockDriverState *bs) return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE); } =20 -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **e= rrp) +int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, + bool ignore_allow_rdw, Error **errp) { /* Do not set read_only if copy_on_read is enabled */ if (bs->copy_on_read && read_only) { @@ -256,7 +257,9 @@ int bdrv_can_set_read_only(BlockDriverState *bs, bool r= ead_only, Error **errp) } =20 /* Do not clear read_only if it is prohibited */ - if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) { + if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR) && + !ignore_allow_rdw) + { error_setg(errp, "Node '%s' is read only", bdrv_get_device_or_node_name(bs)); return -EPERM; @@ -269,7 +272,7 @@ int bdrv_set_read_only(BlockDriverState *bs, bool read_= only, Error **errp) { int ret =3D 0; =20 - ret =3D bdrv_can_set_read_only(bs, read_only, errp); + ret =3D bdrv_can_set_read_only(bs, read_only, false, errp); if (ret < 0) { return ret; } @@ -2907,7 +2910,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state= , BlockReopenQueue *queue, * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RD= WR is * not set, or if the BDS still has copy_on_read enabled */ read_only =3D !(reopen_state->flags & BDRV_O_RDWR); - ret =3D bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err= ); + ret =3D bdrv_can_set_read_only(reopen_state->bs, read_only, true, &loc= al_err); if (local_err) { error_propagate(errp, local_err); goto error; --=20 2.13.3 From nobody Sat Apr 27 11:37:44 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501772873563727.171820154494; Thu, 3 Aug 2017 08:07:53 -0700 (PDT) Received: from localhost ([::1]:51417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHj5-0006Us-Vk for importer@patchew.org; Thu, 03 Aug 2017 11:07:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHeh-0002Xo-1A for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddHeg-0006YV-2D for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddHed-0006QC-OS; Thu, 03 Aug 2017 11:03:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78394883C7; Thu, 3 Aug 2017 15:03:14 +0000 (UTC) Received: from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com [10.33.200.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9044780F76; Thu, 3 Aug 2017 15:03:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 78394883C7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 3 Aug 2017 17:02:59 +0200 Message-Id: <20170803150301.10177-4-kwolf@redhat.com> In-Reply-To: <20170803150301.10177-1-kwolf@redhat.com> References: <20170803150301.10177-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 03 Aug 2017 15:03:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 3/5] block: Set BDRV_O_ALLOW_RDWR during rw 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reopening an image should be consistent with opening it, so we should set BDRV_O_ALLOW_RDWR for any image that is reopened read-write like in bdrv_open_inherit(). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow --- block.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 2711c3dd3b..3615a6809e 100644 --- a/block.c +++ b/block.c @@ -2729,8 +2729,11 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, bdrv_join_options(bs, options, old_options); QDECREF(old_options); =20 - /* bdrv_open() masks this flag out */ + /* bdrv_open_inherit() sets and clears some additional flags internall= y */ flags &=3D ~BDRV_O_PROTOCOL; + if (flags & BDRV_O_RDWR) { + flags |=3D BDRV_O_ALLOW_RDWR; + } =20 QLIST_FOREACH(child, &bs->children, next) { QDict *new_child_options; --=20 2.13.3 From nobody Sat Apr 27 11:37:44 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501772970660302.4279614955334; Thu, 3 Aug 2017 08:09:30 -0700 (PDT) Received: from localhost ([::1]:51622 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHkf-0008IO-AB for importer@patchew.org; Thu, 03 Aug 2017 11:09:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHei-0002Zd-I3 for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddHeh-0006cG-91 for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddHee-0006SD-IV; Thu, 03 Aug 2017 11:03:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 796087F3E4; Thu, 3 Aug 2017 15:03:15 +0000 (UTC) Received: from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com [10.33.200.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1EB680E7C; Thu, 3 Aug 2017 15:03:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 796087F3E4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 3 Aug 2017 17:03:00 +0200 Message-Id: <20170803150301.10177-5-kwolf@redhat.com> In-Reply-To: <20170803150301.10177-1-kwolf@redhat.com> References: <20170803150301.10177-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 03 Aug 2017 15:03:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 4/5] qemu-io: Allow reopen read-write 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows qemu-iotests to test the switch between read-only and read-write mode for block devices. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow --- qemu-io-cmds.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 3eb42c6728..2811a89099 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1920,6 +1920,7 @@ static void reopen_help(void) " 'reopen -o lazy-refcounts=3Don' - activates lazy refcount writeback on a= qcow2 image\n" "\n" " -r, -- Reopen the image read-only\n" +" -w, -- Reopen the image read-write\n" " -c, -- Change the cache mode to the given value\n" " -o, -- Changes block driver options (cf. 'open' command)\n" "\n"); @@ -1942,7 +1943,7 @@ static const cmdinfo_t reopen_cmd =3D { .argmin =3D 0, .argmax =3D -1, .cfunc =3D reopen_f, - .args =3D "[-r] [-c cache] [-o options]", + .args =3D "[(-r|-w)] [-c cache] [-o options]", .oneline =3D "reopens an image with new options", .help =3D reopen_help, }; @@ -1955,11 +1956,12 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) int c; int flags =3D bs->open_flags; bool writethrough =3D !blk_enable_write_cache(blk); + bool has_rw_option =3D false; =20 BlockReopenQueue *brq; Error *local_err =3D NULL; =20 - while ((c =3D getopt(argc, argv, "c:o:r")) !=3D -1) { + while ((c =3D getopt(argc, argv, "c:o:rw")) !=3D -1) { switch (c) { case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { @@ -1974,7 +1976,20 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) } break; case 'r': + if (has_rw_option) { + error_report("Only one -r/-w option may be given"); + return 0; + } flags &=3D ~BDRV_O_RDWR; + has_rw_option =3D true; + break; + case 'w': + if (has_rw_option) { + error_report("Only one -r/-w option may be given"); + return 0; + } + flags |=3D BDRV_O_RDWR; + has_rw_option =3D true; break; default: qemu_opts_reset(&reopen_opts); --=20 2.13.3 From nobody Sat Apr 27 11:37:44 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150177275699417.648216113951776; Thu, 3 Aug 2017 08:05:56 -0700 (PDT) Received: from localhost ([::1]:51226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHhC-0004YR-Fp for importer@patchew.org; Thu, 03 Aug 2017 11:05:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddHep-0002fN-Qz for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddHeo-0006zT-NT for qemu-devel@nongnu.org; Thu, 03 Aug 2017 11:03:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34284) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddHef-0006VU-LZ; Thu, 03 Aug 2017 11:03:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93E8361484; Thu, 3 Aug 2017 15:03:16 +0000 (UTC) Received: from dhcp-200-186.str.redhat.com (dhcp-200-186.str.redhat.com [10.33.200.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id B66F480E19; Thu, 3 Aug 2017 15:03:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93E8361484 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=kwolf@redhat.com From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 3 Aug 2017 17:03:01 +0200 Message-Id: <20170803150301.10177-6-kwolf@redhat.com> In-Reply-To: <20170803150301.10177-1-kwolf@redhat.com> References: <20170803150301.10177-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 03 Aug 2017 15:03:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 5/5] qemu-iotests: Test reopen between read-only and read-write 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, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This serves as a regression test for the bugs that were just fixed for bdrv_reopen() between read-only and read-write mode. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow --- tests/qemu-iotests/187 | 69 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/187.out | 18 ++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 88 insertions(+) create mode 100755 tests/qemu-iotests/187 create mode 100644 tests/qemu-iotests/187.out diff --git a/tests/qemu-iotests/187 b/tests/qemu-iotests/187 new file mode 100755 index 0000000000..7bb783363c --- /dev/null +++ b/tests/qemu-iotests/187 @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Test switching between read-only and read-write +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dkwolf@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_IMG.2" + rm -f "$TEST_IMG.3" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +size=3D64M +_make_test_img $size + +echo +echo "Start from read-only" +echo + +$QEMU_IO -r -c 'write 0 64k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -r -c 'reopen -w' -c 'write 0 64k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -r -c 'reopen -w' -c 'reopen -r' -c 'write 0 64k' $TEST_IMG | _fi= lter_qemu_io + +echo +echo "Start from read-write" +echo + +$QEMU_IO -c 'write 0 64k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'reopen -r' -c 'write 0 64k' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'reopen -r' -c 'reopen -w' -c 'write 0 64k' $TEST_IMG | _filte= r_qemu_io + + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/187.out b/tests/qemu-iotests/187.out new file mode 100644 index 0000000000..68fb944cd5 --- /dev/null +++ b/tests/qemu-iotests/187.out @@ -0,0 +1,18 @@ +QA output created by 187 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 + +Start from read-only + +Block node is read-only +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Block node is read-only + +Start from read-write + +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +write failed: Operation not permitted +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 823811076d..1848077932 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -182,6 +182,7 @@ 183 rw auto migration 185 rw auto 186 rw auto +187 rw auto 188 rw auto quick 189 rw auto 190 rw auto quick --=20 2.13.3