From nobody Thu Nov 6 14:10:26 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.zoho.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 1489459239937583.9091733268929; Mon, 13 Mar 2017 19:40:39 -0700 (PDT) Received: from localhost ([::1]:56057 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncO6-0002SB-Hu for importer@patchew.org; Mon, 13 Mar 2017 22:40:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncNE-0002OY-9p for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cncND-0008Aw-HE for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cncNB-00089P-AZ; Mon, 13 Mar 2017 22:39:41 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7131881F01; Tue, 14 Mar 2017 02:39:41 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-40.pek2.redhat.com [10.72.8.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2E2da4v010132; Mon, 13 Mar 2017 22:39:39 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 14 Mar 2017 10:39:31 +0800 Message-Id: <20170314023933.12118-2-famz@redhat.com> In-Reply-To: <20170314023933.12118-1-famz@redhat.com> References: <20170314023933.12118-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 14 Mar 2017 02:39:41 +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 RFC 1/3] block: Introduce BDRV_O_UNSAFE_READ 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 , qemu-block@nongnu.org, Max Reitz 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 flag clears out the "consistent read" permission that blk_new_open requests. Signed-off-by: Fam Zheng Reviewed-by: Eric Blake --- block/block-backend.c | 2 +- include/block/block.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 5742c09..99428ee 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -197,7 +197,7 @@ BlockBackend *blk_new_open(const char *filename, const = char *reference, * caller of blk_new_open() doesn't make use of the permissions, but t= hey * shouldn't hurt either. We can still share everything here because t= he * guest devices will add their own blockers if they can't share. */ - perm =3D BLK_PERM_CONSISTENT_READ; + perm =3D flags & BDRV_O_UNSAFE_READ ? 0 : BLK_PERM_CONSISTENT_READ; if (flags & BDRV_O_RDWR) { perm |=3D BLK_PERM_WRITE; } diff --git a/include/block/block.h b/include/block/block.h index 5149260..d43b563 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -98,6 +98,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_UNSAFE_READ 0x20000 /* don't require consistent read */ =20 #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_NO_FLUSH) =20 --=20 2.9.3 From nobody Thu Nov 6 14:10:26 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.zoho.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 1489459248397239.09479709971163; Mon, 13 Mar 2017 19:40:48 -0700 (PDT) Received: from localhost ([::1]:56059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncOF-0002Xh-3c for importer@patchew.org; Mon, 13 Mar 2017 22:40:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncNL-0002UL-A1 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cncNJ-0008Dy-2t for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cncNE-0008Aq-1u; Mon, 13 Mar 2017 22:39:44 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 313DF37E64; Tue, 14 Mar 2017 02:39:44 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-40.pek2.redhat.com [10.72.8.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2E2da4w010132; Mon, 13 Mar 2017 22:39:42 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 14 Mar 2017 10:39:32 +0800 Message-Id: <20170314023933.12118-3-famz@redhat.com> In-Reply-To: <20170314023933.12118-1-famz@redhat.com> References: <20170314023933.12118-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 14 Mar 2017 02:39:44 +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 RFC 2/3] qemu-img: Add --unsafe-read option to subcommands 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 , qemu-block@nongnu.org, Max Reitz 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" Signed-off-by: Fam Zheng --- qemu-img.c | 148 +++++++++++++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 114 insertions(+), 34 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 98b836b..3aaa254 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -273,12 +273,15 @@ static int img_open_password(BlockBackend *blk, const= char *filename, =20 static BlockBackend *img_open_opts(const char *optstr, QemuOpts *opts, int flags, bool writeth= rough, - bool quiet) + bool quiet, bool unsafe) { QDict *options; Error *local_err =3D NULL; BlockBackend *blk; options =3D qemu_opts_to_qdict(opts, NULL); + if (unsafe) { + flags |=3D BDRV_O_UNSAFE_READ; + } blk =3D blk_new_open(NULL, NULL, options, flags, &local_err); if (!blk) { error_reportf_err(local_err, "Could not open '%s': ", optstr); @@ -295,7 +298,7 @@ static BlockBackend *img_open_opts(const char *optstr, =20 static BlockBackend *img_open_file(const char *filename, const char *fmt, int flags, - bool writethrough, bool quiet) + bool writethrough, bool quiet, bool uns= afe) { BlockBackend *blk; Error *local_err =3D NULL; @@ -306,6 +309,9 @@ static BlockBackend *img_open_file(const char *filename, qdict_put(options, "driver", qstring_from_str(fmt)); } =20 + if (unsafe) { + flags |=3D BDRV_O_UNSAFE_READ; + } blk =3D blk_new_open(filename, NULL, options, flags, &local_err); if (!blk) { error_reportf_err(local_err, "Could not open '%s': ", filename); @@ -324,7 +330,7 @@ static BlockBackend *img_open_file(const char *filename, static BlockBackend *img_open(bool image_opts, const char *filename, const char *fmt, int flags, bool writethroug= h, - bool quiet) + bool quiet, bool unsafe) { BlockBackend *blk; if (image_opts) { @@ -338,9 +344,9 @@ static BlockBackend *img_open(bool image_opts, if (!opts) { return NULL; } - blk =3D img_open_opts(filename, opts, flags, writethrough, quiet); + blk =3D img_open_opts(filename, opts, flags, writethrough, quiet, = unsafe); } else { - blk =3D img_open_file(filename, fmt, flags, writethrough, quiet); + blk =3D img_open_file(filename, fmt, flags, writethrough, quiet, u= nsafe); } return blk; } @@ -635,6 +641,7 @@ static int img_check(int argc, char **argv) ImageCheck *check; bool quiet =3D false; bool image_opts =3D false; + bool unsafe_read =3D false; =20 fmt =3D NULL; output =3D NULL; @@ -649,9 +656,10 @@ static int img_check(int argc, char **argv) {"output", required_argument, 0, OPTION_OUTPUT}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:r:T:q", + c =3D getopt_long(argc, argv, "hf:r:T:qU", long_options, &option_index); if (c =3D=3D -1) { break; @@ -685,6 +693,9 @@ static int img_check(int argc, char **argv) case 'q': quiet =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -724,7 +735,8 @@ static int img_check(int argc, char **argv) return 1; } =20 - blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet= ); + blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet, + unsafe_read); if (!blk) { return 1; } @@ -844,6 +856,7 @@ static int img_commit(int argc, char **argv) CommonBlockJobCBInfo cbi; bool image_opts =3D false; AioContext *aio_context; + bool unsafe_read =3D false; =20 fmt =3D NULL; cache =3D BDRV_DEFAULT_CACHE; @@ -853,9 +866,10 @@ static int img_commit(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:ht:b:dpq", + c =3D getopt_long(argc, argv, "f:ht:b:dpqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -885,6 +899,9 @@ static int img_commit(int argc, char **argv) case 'q': quiet =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -922,7 +939,8 @@ static int img_commit(int argc, char **argv) return 1; } =20 - blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet= ); + blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet, + unsafe_read); if (!blk) { return 1; } @@ -1181,6 +1199,7 @@ static int img_compare(int argc, char **argv) int c, pnum; uint64_t progress_base; bool image_opts =3D false; + bool unsafe_read =3D false; =20 cache =3D BDRV_DEFAULT_CACHE; for (;;) { @@ -1188,9 +1207,10 @@ static int img_compare(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:T:pqs", + c =3D getopt_long(argc, argv, "hf:F:T:pqsU", long_options, NULL); if (c =3D=3D -1) { break; @@ -1218,6 +1238,9 @@ static int img_compare(int argc, char **argv) case 's': strict =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -1263,13 +1286,15 @@ static int img_compare(int argc, char **argv) goto out3; } =20 - blk1 =3D img_open(image_opts, filename1, fmt1, flags, writethrough, qu= iet); + blk1 =3D img_open(image_opts, filename1, fmt1, flags, writethrough, qu= iet, + unsafe_read); if (!blk1) { ret =3D 2; goto out3; } =20 - blk2 =3D img_open(image_opts, filename2, fmt2, flags, writethrough, qu= iet); + blk2 =3D img_open(image_opts, filename2, fmt2, flags, writethrough, qu= iet, + unsafe_read); if (!blk2) { ret =3D 2; goto out2; @@ -1911,6 +1936,7 @@ static int img_convert(int argc, char **argv) bool image_opts =3D false; bool wr_in_order =3D true; long num_coroutines =3D 8; + bool unsafe_read =3D false; =20 fmt =3D NULL; out_fmt =3D "raw"; @@ -1924,9 +1950,10 @@ static int img_convert(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qnm:W", + c =3D getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qnm:WU", long_options, NULL); if (c =3D=3D -1) { break; @@ -2030,6 +2057,9 @@ static int img_convert(int argc, char **argv) case 'W': wr_in_order =3D false; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: opts =3D qemu_opts_parse_noisily(&qemu_object_opts, optarg, true); @@ -2097,7 +2127,8 @@ static int img_convert(int argc, char **argv) total_sectors =3D 0; for (bs_i =3D 0; bs_i < bs_n; bs_i++) { blk[bs_i] =3D img_open(image_opts, argv[optind + bs_i], - fmt, src_flags, src_writethrough, quiet); + fmt, src_flags, src_writethrough, quiet, + unsafe_read); if (!blk[bs_i]) { ret =3D -1; goto out; @@ -2242,7 +2273,8 @@ static int img_convert(int argc, char **argv) * the bdrv_create() call which takes different params. * Not critical right now, so fix can wait... */ - out_blk =3D img_open_file(out_filename, out_fmt, flags, writethrough, = quiet); + out_blk =3D img_open_file(out_filename, out_fmt, flags, writethrough, = quiet, + unsafe_read); if (!out_blk) { ret =3D -1; goto out; @@ -2413,7 +2445,7 @@ static gboolean str_equal_func(gconstpointer a, gcons= tpointer b) static ImageInfoList *collect_image_info_list(bool image_opts, const char *filename, const char *fmt, - bool chain) + bool chain, bool unsafe) { ImageInfoList *head =3D NULL; ImageInfoList **last =3D &head; @@ -2436,7 +2468,8 @@ static ImageInfoList *collect_image_info_list(bool im= age_opts, g_hash_table_insert(filenames, (gpointer)filename, NULL); =20 blk =3D img_open(image_opts, filename, fmt, - BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false); + BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false, + unsafe); if (!blk) { goto err; } @@ -2488,6 +2521,7 @@ static int img_info(int argc, char **argv) const char *filename, *fmt, *output; ImageInfoList *list; bool image_opts =3D false; + bool unsafe_read =3D false; =20 fmt =3D NULL; output =3D NULL; @@ -2500,9 +2534,10 @@ static int img_info(int argc, char **argv) {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, "f:hU", long_options, &option_index); if (c =3D=3D -1) { break; @@ -2515,6 +2550,9 @@ static int img_info(int argc, char **argv) case 'f': fmt =3D optarg; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OUTPUT: output =3D optarg; break; @@ -2554,7 +2592,8 @@ static int img_info(int argc, char **argv) return 1; } =20 - list =3D collect_image_info_list(image_opts, filename, fmt, chain); + list =3D collect_image_info_list(image_opts, filename, fmt, chain, + unsafe_read); if (!list) { return 1; } @@ -2700,6 +2739,7 @@ static int img_map(int argc, char **argv) MapEntry curr =3D { .length =3D 0 }, next; int ret =3D 0; bool image_opts =3D false; + bool unsafe_read =3D false; =20 fmt =3D NULL; output =3D NULL; @@ -2711,9 +2751,10 @@ static int img_map(int argc, char **argv) {"output", required_argument, 0, OPTION_OUTPUT}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:h", + c =3D getopt_long(argc, argv, "f:hU", long_options, &option_index); if (c =3D=3D -1) { break; @@ -2726,6 +2767,9 @@ static int img_map(int argc, char **argv) case 'f': fmt =3D optarg; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OUTPUT: output =3D optarg; break; @@ -2762,7 +2806,7 @@ static int img_map(int argc, char **argv) return 1; } =20 - blk =3D img_open(image_opts, filename, fmt, 0, false, false); + blk =3D img_open(image_opts, filename, fmt, 0, false, false, unsafe_re= ad); if (!blk) { return 1; } @@ -2825,6 +2869,7 @@ static int img_snapshot(int argc, char **argv) bool quiet =3D false; Error *err =3D NULL; bool image_opts =3D false; + bool unsafe_read =3D false; =20 bdrv_oflags =3D BDRV_O_RDWR; /* Parse commandline parameters */ @@ -2833,9 +2878,10 @@ static int img_snapshot(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "la:c:d:hq", + c =3D getopt_long(argc, argv, "la:c:d:hqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -2880,6 +2926,9 @@ static int img_snapshot(int argc, char **argv) case 'q': quiet =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -2906,7 +2955,8 @@ static int img_snapshot(int argc, char **argv) } =20 /* Open the image */ - blk =3D img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet= ); + blk =3D img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, + unsafe_read); if (!blk) { return 1; } @@ -2970,6 +3020,7 @@ static int img_rebase(int argc, char **argv) int c, flags, src_flags, ret; bool writethrough, src_writethrough; int unsafe =3D 0; + int unsafe_read =3D 0; int progress =3D 0; bool quiet =3D false; Error *local_err =3D NULL; @@ -2986,9 +3037,10 @@ static int img_rebase(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hf:F:b:upt:T:q", + c =3D getopt_long(argc, argv, "hf:F:b:upt:T:qU", long_options, NULL); if (c =3D=3D -1) { break; @@ -3033,6 +3085,9 @@ static int img_rebase(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + case 'U': + unsafe_read =3D 1; + break; } } =20 @@ -3081,7 +3136,8 @@ static int img_rebase(int argc, char **argv) * Ignore the old backing file for unsafe rebase in case we want to co= rrect * the reference to a renamed or moved backing file. */ - blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet= ); + blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet, + unsafe_read); if (!blk) { ret =3D -1; goto out; @@ -3106,6 +3162,9 @@ static int img_rebase(int argc, char **argv) qdict_put(options, "driver", qstring_from_str(bs->backing_form= at)); } =20 + if (unsafe_read) { + src_flags |=3D BDRV_O_UNSAFE_READ; + } bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name)); blk_old_backing =3D blk_new_open(backing_name, NULL, options, src_flags, &local_err); @@ -3321,6 +3380,7 @@ static int img_resize(int argc, char **argv) bool quiet =3D false; BlockBackend *blk =3D NULL; QemuOpts *param; + bool unsafe_read =3D true; =20 static QemuOptsList resize_options =3D { .name =3D "resize_options", @@ -3353,9 +3413,10 @@ static int img_resize(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "f:hq", + c =3D getopt_long(argc, argv, "f:hqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -3371,6 +3432,9 @@ static int img_resize(int argc, char **argv) case 'q': quiet =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -3423,7 +3487,8 @@ static int img_resize(int argc, char **argv) qemu_opts_del(param); =20 blk =3D img_open(image_opts, filename, fmt, - BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet); + BDRV_O_RDWR | BDRV_O_RESIZE, false, quiet, + unsafe_read); if (!blk) { ret =3D -1; goto out; @@ -3484,6 +3549,7 @@ static int img_amend(int argc, char **argv) BlockBackend *blk =3D NULL; BlockDriverState *bs =3D NULL; bool image_opts =3D false; + bool unsafe_read =3D false; =20 cache =3D BDRV_DEFAULT_CACHE; for (;;) { @@ -3491,9 +3557,10 @@ static int img_amend(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "ho:f:t:pq", + c =3D getopt_long(argc, argv, "ho:f:t:pqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -3581,7 +3648,8 @@ static int img_amend(int argc, char **argv) goto out; } =20 - blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet= ); + blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet, + unsafe_read); if (!blk) { ret =3D -1; goto out; @@ -3749,6 +3817,7 @@ static int img_bench(int argc, char **argv) bool writethrough =3D false; struct timeval t1, t2; int i; + bool unsafe_read =3D false; =20 for (;;) { static const struct option long_options[] =3D { @@ -3757,9 +3826,10 @@ static int img_bench(int argc, char **argv) {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"pattern", required_argument, 0, OPTION_PATTERN}, {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, + {"unsafe-read", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "hc:d:f:no:qs:S:t:w", long_options, = NULL); + c =3D getopt_long(argc, argv, "hc:d:f:no:qs:S:t:wU", long_options,= NULL); if (c =3D=3D -1) { break; } @@ -3848,6 +3918,9 @@ static int img_bench(int argc, char **argv) flags |=3D BDRV_O_RDWR; is_write =3D true; break; + case 'U': + unsafe_read =3D true; + break; case OPTION_PATTERN: { unsigned long res; @@ -3895,7 +3968,8 @@ static int img_bench(int argc, char **argv) goto out; } =20 - blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet= ); + blk =3D img_open(image_opts, filename, fmt, flags, writethrough, quiet, + unsafe_read); if (!blk) { ret =3D -1; goto out; @@ -4062,6 +4136,7 @@ static int img_dd(int argc, char **argv) const char *fmt =3D NULL; int64_t size =3D 0; int64_t block_count =3D 0, out_pos, in_pos; + bool unsafe_read =3D false; struct DdInfo dd =3D { .flags =3D 0, .count =3D 0, @@ -4090,10 +4165,11 @@ static int img_dd(int argc, char **argv) const struct option long_options[] =3D { { "help", no_argument, 0, 'h'}, { "image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + { "unsafe-read", no_argument, 0, 'U'}, { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, "hf:O:", long_options, NULL))) { + while ((c =3D getopt_long(argc, argv, "hf:O:U", long_options, NULL))) { if (c =3D=3D EOF) { break; } @@ -4111,6 +4187,9 @@ static int img_dd(int argc, char **argv) case 'h': help(); break; + case 'U': + unsafe_read =3D true; + break; case OPTION_IMAGE_OPTS: image_opts =3D true; break; @@ -4155,7 +4234,8 @@ static int img_dd(int argc, char **argv) ret =3D -1; goto out; } - blk1 =3D img_open(image_opts, in.filename, fmt, 0, false, false); + blk1 =3D img_open(image_opts, in.filename, fmt, 0, false, false, + unsafe_read); =20 if (!blk1) { ret =3D -1; @@ -4223,7 +4303,7 @@ static int img_dd(int argc, char **argv) } =20 blk2 =3D img_open(image_opts, out.filename, out_fmt, BDRV_O_RDWR, - false, false); + false, false, unsafe_read); =20 if (!blk2) { ret =3D -1; --=20 2.9.3 From nobody Thu Nov 6 14:10:26 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.zoho.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 1489459339829444.3613645977922; Mon, 13 Mar 2017 19:42:19 -0700 (PDT) Received: from localhost ([::1]:56070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncPi-00040x-Fz for importer@patchew.org; Mon, 13 Mar 2017 22:42:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cncNM-0002Uz-AN for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cncNL-0008GC-7v for qemu-devel@nongnu.org; Mon, 13 Mar 2017 22:39:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52976) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cncNG-0008CW-H6; Mon, 13 Mar 2017 22:39:46 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A191B369C4; Tue, 14 Mar 2017 02:39:46 +0000 (UTC) Received: from lemon.redhat.com (ovpn-8-40.pek2.redhat.com [10.72.8.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2E2da4x010132; Mon, 13 Mar 2017 22:39:44 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 14 Mar 2017 10:39:33 +0800 Message-Id: <20170314023933.12118-4-famz@redhat.com> In-Reply-To: <20170314023933.12118-1-famz@redhat.com> References: <20170314023933.12118-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 14 Mar 2017 02:39:46 +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 RFC 3/3] qemu-io: Add --unsafe-read 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: Kevin Wolf , qemu-block@nongnu.org, Max Reitz 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" Signed-off-by: Fam Zheng --- qemu-io.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 427cbae..f3616ee 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -53,7 +53,8 @@ static const cmdinfo_t close_cmd =3D { .oneline =3D "close the current open file", }; =20 -static int openfile(char *name, int flags, bool writethrough, QDict *opts) +static int openfile(char *name, int flags, bool writethrough, bool unsafe_= read, + QDict *opts) { Error *local_err =3D NULL; BlockDriverState *bs; @@ -64,6 +65,9 @@ static int openfile(char *name, int flags, bool writethro= ugh, QDict *opts) return 1; } =20 + if (unsafe_read) { + flags |=3D BDRV_O_UNSAFE_READ; + } qemuio_blk =3D blk_new_open(name, NULL, opts, flags, &local_err); if (!qemuio_blk) { error_reportf_err(local_err, "can't open%s%s: ", @@ -108,6 +112,7 @@ static void open_help(void) " -r, -- open file read-only\n" " -s, -- use snapshot file\n" " -n, -- disable host cache, short for -t none\n" +" -U, -- accept unsafe opening of the image even if it's in use by another= process\n" " -k, -- use kernel AIO implementation (on Linux only)\n" " -t, -- use the given cache mode for the image\n" " -d, -- use the given discard mode for the image\n" @@ -124,7 +129,7 @@ static const cmdinfo_t open_cmd =3D { .argmin =3D 1, .argmax =3D -1, .flags =3D CMD_NOFILE_OK, - .args =3D "[-rsnk] [-t cache] [-d discard] [-o options] [path]", + .args =3D "[-rsnkU] [-t cache] [-d discard] [-o options] [path]", .oneline =3D "open the file specified by path", .help =3D open_help, }; @@ -147,8 +152,9 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) int c; QemuOpts *qopts; QDict *opts; + bool unsafe_read =3D false; =20 - while ((c =3D getopt(argc, argv, "snro:kt:d:")) !=3D -1) { + while ((c =3D getopt(argc, argv, "snro:kt:d:U")) !=3D -1) { switch (c) { case 's': flags |=3D BDRV_O_SNAPSHOT; @@ -188,6 +194,9 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) return 0; } break; + case 'U': + unsafe_read =3D true; + break; default: qemu_opts_reset(&empty_opts); return qemuio_command_usage(&open_cmd); @@ -211,9 +220,9 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) qemu_opts_reset(&empty_opts); =20 if (optind =3D=3D argc - 1) { - return openfile(argv[optind], flags, writethrough, opts); + return openfile(argv[optind], flags, writethrough, unsafe_read, op= ts); } else if (optind =3D=3D argc) { - return openfile(NULL, flags, writethrough, opts); + return openfile(NULL, flags, writethrough, unsafe_read, opts); } else { QDECREF(opts); return qemuio_command_usage(&open_cmd); @@ -452,6 +461,7 @@ int main(int argc, char **argv) { "trace", required_argument, NULL, 'T' }, { "object", required_argument, NULL, OPTION_OBJECT }, { "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS }, + { "unsafe-read", no_argument, 0, 'U'}, { NULL, 0, NULL, 0 } }; int c; @@ -462,6 +472,7 @@ int main(int argc, char **argv) QDict *opts =3D NULL; const char *format =3D NULL; char *trace_file =3D NULL; + bool unsafe_read =3D false; =20 #ifdef CONFIG_POSIX signal(SIGPIPE, SIG_IGN); @@ -524,6 +535,9 @@ int main(int argc, char **argv) case 'h': usage(progname); exit(0); + case 'U': + unsafe_read =3D true; + break; case OPTION_OBJECT: { QemuOpts *qopts; qopts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -595,7 +609,7 @@ int main(int argc, char **argv) exit(1); } opts =3D qemu_opts_to_qdict(qopts, NULL); - if (openfile(NULL, flags, writethrough, opts)) { + if (openfile(NULL, flags, writethrough, unsafe_read, opts)) { exit(1); } } else { @@ -603,7 +617,7 @@ int main(int argc, char **argv) opts =3D qdict_new(); qdict_put(opts, "driver", qstring_from_str(format)); } - if (openfile(argv[optind], flags, writethrough, opts)) { + if (openfile(argv[optind], flags, writethrough, unsafe_read, o= pts)) { exit(1); } } --=20 2.9.3