From nobody Tue Feb 10 19:14:28 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; 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 --- 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