From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17085504844651022.4753895671464; Wed, 21 Feb 2024 13:21:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxY-0002P4-S2; Wed, 21 Feb 2024 16:16:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxE-00020x-Ac; Wed, 21 Feb 2024 16:16:37 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxB-0000jK-22; Wed, 21 Feb 2024 16:16:35 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id EC8214F7E8; Thu, 22 Feb 2024 00:16:44 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 9E4B7869A1; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335247 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 01/28] qemu-img: stop printing error twice in a few places Date: Thu, 22 Feb 2024 00:15:42 +0300 Message-Id: <20240221211622.2335170-1-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550486141100001 Content-Type: text/plain; charset="utf-8" Currently we have: ./qemu-img resize none +10 qemu-img: Could not open 'none': Could not open 'none': No such file or d= irectory stop printing the message twice, - local_err already has all the info, no need to prepend additional text there. There are a few other places like this, but I'm unsure about these. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7668f86769..5a756be600 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -404,7 +404,7 @@ static BlockBackend *img_open_file(const char *filename, } blk =3D blk_new_open(filename, NULL, options, flags, &local_err); if (!blk) { - error_reportf_err(local_err, "Could not open '%s': ", filename); + error_report_err(local_err); return NULL; } blk_set_enable_write_cache(blk, !writethrough); @@ -597,7 +597,7 @@ static int img_create(int argc, char **argv) bdrv_img_create(filename, fmt, base_filename, base_fmt, options, img_size, flags, quiet, &local_err); if (local_err) { - error_reportf_err(local_err, "%s: ", filename); + error_report_err(local_err); goto fail; } =20 @@ -5253,9 +5253,7 @@ static int img_dd(int argc, char **argv) =20 ret =3D bdrv_create(drv, out.filename, opts, &local_err); if (ret < 0) { - error_reportf_err(local_err, - "%s: error while creating output image: ", - out.filename); + error_report_err(local_err); ret =3D -1; goto out; } --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550246771245.87053931796504; Wed, 21 Feb 2024 13:17:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxj-0002e8-0x; Wed, 21 Feb 2024 16:17:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxC-00020U-RR; Wed, 21 Feb 2024 16:16:36 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxB-0000jJ-0u; Wed, 21 Feb 2024 16:16:34 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 012274F7E9; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id ABAE7869A2; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335250 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 02/28] qemu-img: measure: convert img_size to signed, simplify handling Date: Thu, 22 Feb 2024 00:15:43 +0300 Message-Id: <20240221211622.2335170-2-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550247417100003 Content-Type: text/plain; charset="utf-8" qemu_opt_set_number() expects signed int64_t. Use int64_t instead of uint64_t for img_size, use -1 as "unset" value instead of UINT64_MAX, and do not require temporary sval for conversion from string. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 5a756be600..ae14ed833d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5362,7 +5362,7 @@ static int img_measure(int argc, char **argv) QemuOpts *sn_opts =3D NULL; QemuOptsList *create_opts =3D NULL; bool image_opts =3D false; - uint64_t img_size =3D UINT64_MAX; + int64_t img_size =3D -1; BlockMeasureInfo *info =3D NULL; Error *local_err =3D NULL; int ret =3D 1; @@ -5420,16 +5420,11 @@ static int img_measure(int argc, char **argv) } break; case OPTION_SIZE: - { - int64_t sval; - - sval =3D cvtnum("image size", optarg); - if (sval < 0) { + img_size =3D cvtnum("image size", optarg); + if (img_size < 0) { goto out; } - img_size =3D (uint64_t)sval; - } - break; + break; } } =20 @@ -5444,11 +5439,11 @@ static int img_measure(int argc, char **argv) error_report("--image-opts, -f, and -l require a filename argument= ."); goto out; } - if (filename && img_size !=3D UINT64_MAX) { + if (filename && img_size !=3D -1) { error_report("--size N cannot be used together with a filename."); goto out; } - if (!filename && img_size =3D=3D UINT64_MAX) { + if (!filename && img_size =3D=3D -1) { error_report("Either --size N or one filename must be specified."); goto out; } @@ -5496,7 +5491,7 @@ static int img_measure(int argc, char **argv) goto out; } } - if (img_size !=3D UINT64_MAX) { + if (img_size !=3D -1) { qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort); } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550287531554.6831981972254; Wed, 21 Feb 2024 13:18:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxS-0002E8-3z; Wed, 21 Feb 2024 16:16:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxG-00024F-A2; Wed, 21 Feb 2024 16:16:39 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxE-0000kl-DD; Wed, 21 Feb 2024 16:16:37 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0C1114F7EA; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id B89E6869A3; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335253 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 03/28] qemu-img: create: convert img_size to signed, simplify handling Date: Thu, 22 Feb 2024 00:15:44 +0300 Message-Id: <20240221211622.2335170-3-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550289525100001 Content-Type: text/plain; charset="utf-8" Initializing an unsigned as -1, or using temporary sval for conversion is awkward. Since we don't allow other "negative" values anyway, use signed value and pass it to bdrv_img_create() (where it is properly converted to unsigned), simplifying code. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ae14ed833d..df425b2517 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -511,7 +511,7 @@ static int64_t cvtnum(const char *name, const char *val= ue) static int img_create(int argc, char **argv) { int c; - uint64_t img_size =3D -1; + int64_t img_size =3D -1; const char *fmt =3D "raw"; const char *base_fmt =3D NULL; const char *filename; @@ -582,13 +582,10 @@ static int img_create(int argc, char **argv) =20 /* Get image size, if specified */ if (optind < argc) { - int64_t sval; - - sval =3D cvtnum("image size", argv[optind++]); - if (sval < 0) { + img_size =3D cvtnum("image size", argv[optind++]); + if (img_size < 0) { goto fail; } - img_size =3D (uint64_t)sval; } if (optind !=3D argc) { error_exit("Unexpected argument: %s", argv[optind]); --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550605527916.1292355268482; Wed, 21 Feb 2024 13:23:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxT-0002GX-4O; Wed, 21 Feb 2024 16:16:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxI-00024g-Rj; Wed, 21 Feb 2024 16:16:43 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxF-0000lD-Ma; Wed, 21 Feb 2024 16:16:40 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 1A6044F7EB; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id C5703869A4; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335256 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 04/28] qemu-img: global option processing and error printing Date: Thu, 22 Feb 2024 00:15:45 +0300 Message-Id: <20240221211622.2335170-4-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550606544100002 Content-Type: text/plain; charset="utf-8" In order to correctly print executable name in various error messages, pass argv[0] to error_exit() function. This way, error messages will refer to actual executable name, which may be different from 'qemu-img'. For subcommands, pass whole argv[] array, so argv[0] is the executable name, not subcommand name. In order to do that, avoid resetting optind but continue with the next option. Also don't require at least 3 options on the command line: it makes no sense with options before subcommand. Before invoking a subcommand, replace argv[0] to include the subcommand name. Introduce tryhelp() function which just prints try 'command-name --help' for more info and exits. When tryhelp() is called from within a subcommand handler, the message will look like: try 'command-name subcommand --help' for more info qemu-img uses getopt_long() with ':' as the first char in optstring parameter, which means it doesn't print error messages but return ':' or '?' instead, and qemu-img uses unrecognized_option() or missing_argument() function to print error messages. But it doesn't quite work: $ ./qemu-img -xx qemu-img: unrecognized option './qemu-img' so the aim is to let getopt_long() to print regular error messages instead (removing ':' prefix from optstring) and remove handling of '?' and ':' "options" entirely. With concatenated argv[0] and the subcommand, it all finally does the right thing in all cases. This will be done in subsequent changes command by command, with main() done last. unrecognized_option() and missing_argument() functions prototypes aren't changed by this patch, since they're called from many places and will be removed a few patches later. Only artifical "qemu-img" argv0 is provided in there for now. Signed-off-by: Michael Tokarev --- qemu-img.c | 75 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index df425b2517..44dbf5be4f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -101,8 +101,15 @@ static void format_print(void *opaque, const char *nam= e) printf(" %s", name); } =20 -static G_NORETURN G_GNUC_PRINTF(1, 2) -void error_exit(const char *fmt, ...) +static G_NORETURN +void tryhelp(const char *argv0) +{ + error_printf("Try '%s --help' for more info\n", argv0); + exit(EXIT_FAILURE); +} + +static G_NORETURN G_GNUC_PRINTF(2, 3) +void error_exit(const char *argv0, const char *fmt, ...) { va_list ap; =20 @@ -110,20 +117,19 @@ void error_exit(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); =20 - error_printf("Try 'qemu-img --help' for more information\n"); - exit(EXIT_FAILURE); + tryhelp(argv0); } =20 static G_NORETURN void missing_argument(const char *option) { - error_exit("missing argument for option '%s'", option); + error_exit("qemu-img", "missing argument for option '%s'", option); } =20 static G_NORETURN void unrecognized_option(const char *option) { - error_exit("unrecognized option '%s'", option); + error_exit("qemu-img", "unrecognized option '%s'", option); } =20 /* Please keep in synch with docs/tools/qemu-img.rst */ @@ -576,7 +582,7 @@ static int img_create(int argc, char **argv) } =20 if (optind >=3D argc) { - error_exit("Expecting image file name"); + error_exit(argv[0], "Expecting image file name"); } optind++; =20 @@ -588,7 +594,7 @@ static int img_create(int argc, char **argv) } } if (optind !=3D argc) { - error_exit("Unexpected argument: %s", argv[optind]); + error_exit(argv[0], "Unexpected argument: %s", argv[optind]); } =20 bdrv_img_create(filename, fmt, base_filename, base_fmt, @@ -770,7 +776,7 @@ static int img_check(int argc, char **argv) } else if (!strcmp(optarg, "all")) { fix =3D BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit("Unknown option value for -r " + error_exit(argv[0], "Unknown option value for -r " "(expecting 'leaks' or 'all'): %s", optarg); } break; @@ -795,7 +801,7 @@ static int img_check(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -1025,7 +1031,7 @@ static int img_commit(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -1446,7 +1452,7 @@ static int img_compare(int argc, char **argv) =20 =20 if (optind !=3D argc - 2) { - error_exit("Expecting two image file names"); + error_exit(argv[0], "Expecting two image file names"); } filename1 =3D argv[optind++]; filename2 =3D argv[optind++]; @@ -3056,7 +3062,7 @@ static int img_info(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -3296,7 +3302,7 @@ static int img_map(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind]; =20 @@ -3411,7 +3417,7 @@ static int img_snapshot(int argc, char **argv) return 0; case 'l': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_LIST; @@ -3419,7 +3425,7 @@ static int img_snapshot(int argc, char **argv) break; case 'a': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_APPLY; @@ -3427,7 +3433,7 @@ static int img_snapshot(int argc, char **argv) break; case 'c': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_CREATE; @@ -3435,7 +3441,7 @@ static int img_snapshot(int argc, char **argv) break; case 'd': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_DELETE; @@ -3457,7 +3463,7 @@ static int img_snapshot(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -3624,10 +3630,11 @@ static int img_rebase(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } if (!unsafe && !out_baseimg) { - error_exit("Must specify backing file (-b) or use unsafe mode (-u)= "); + error_exit(argv[0], + "Must specify backing file (-b) or use unsafe mode (-u)= "); } filename =3D argv[optind++]; =20 @@ -4051,7 +4058,7 @@ static int img_resize(int argc, char **argv) /* Remove size from argv manually so that negative numbers are not tre= ated * as options by getopt. */ if (argc < 3) { - error_exit("Not enough arguments"); + error_exit(argv[0], "Not enough arguments"); return 1; } =20 @@ -4109,7 +4116,7 @@ static int img_resize(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting image file name and size"); + error_exit(argv[0], "Expecting image file name and size"); } filename =3D argv[optind++]; =20 @@ -4306,7 +4313,7 @@ static int img_amend(int argc, char **argv) } =20 if (!options) { - error_exit("Must specify options (-o)"); + error_exit(argv[0], "Must specify options (-o)"); } =20 if (quiet) { @@ -4668,7 +4675,7 @@ static int img_bench(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(argv[0], "Expecting one image file name"); } filename =3D argv[argc - 1]; =20 @@ -5556,9 +5563,6 @@ int main(int argc, char **argv) =20 module_call_init(MODULE_INIT_QOM); bdrv_init(); - if (argc < 2) { - error_exit("Not enough arguments"); - } =20 qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); @@ -5583,15 +5587,11 @@ int main(int argc, char **argv) } } =20 - cmdname =3D argv[optind]; - - /* reset getopt_long scanning */ - argc -=3D optind; - if (argc < 1) { - return 0; + if (optind >=3D argc) { + error_exit(argv[0], "Not enough arguments"); } - argv +=3D optind; - qemu_reset_optind(); + + cmdname =3D argv[optind++]; =20 if (!trace_init_backends()) { exit(1); @@ -5602,10 +5602,11 @@ int main(int argc, char **argv) /* find the command */ for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { + argv[0] =3D g_strdup_printf("%s %s", argv[0], cmdname); return cmd->handler(argc, argv); } } =20 /* not found */ - error_exit("Command not found: %s", cmdname); + error_exit(argv[0], "Command not found: %s", cmdname); } --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550231289598.6427855961172; Wed, 21 Feb 2024 13:17:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxb-0002Yo-M4; Wed, 21 Feb 2024 16:16:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxK-000252-Oe; Wed, 21 Feb 2024 16:16:43 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxH-0000lj-UI; Wed, 21 Feb 2024 16:16:42 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 28D744F7EC; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id D39D4869A5; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335259 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 05/28] qemu-img: pass current cmd info into command handlers Date: Thu, 22 Feb 2024 00:15:46 +0300 Message-Id: <20240221211622.2335170-5-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550237118100001 Content-Type: text/plain; charset="utf-8" This info will be used to generate --help output. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 44dbf5be4f..38ac0f1845 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -60,7 +60,7 @@ =20 typedef struct img_cmd_t { const char *name; - int (*handler)(int argc, char **argv); + int (*handler)(const struct img_cmd_t *ccmd, int argc, char **argv); } img_cmd_t; =20 enum { @@ -514,7 +514,7 @@ static int64_t cvtnum(const char *name, const char *val= ue) return cvtnum_full(name, value, 0, INT64_MAX); } =20 -static int img_create(int argc, char **argv) +static int img_create(const img_cmd_t *ccmd, int argc, char **argv) { int c; int64_t img_size =3D -1; @@ -719,7 +719,7 @@ static int collect_image_check(BlockDriverState *bs, * 3 - Check completed, image has leaked clusters, but is good otherwise * 63 - Checks are not supported by the image format */ -static int img_check(int argc, char **argv) +static int img_check(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -951,7 +951,7 @@ static void run_block_job(BlockJob *job, Error **errp) } } =20 -static int img_commit(int argc, char **argv) +static int img_commit(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret, flags; const char *filename, *fmt, *cache, *base; @@ -1358,7 +1358,7 @@ static int check_empty_sectors(BlockBackend *blk, int= 64_t offset, * 1 - Images differ * >1 - Error occurred */ -static int img_compare(int argc, char **argv) +static int img_compare(const img_cmd_t *ccmd, int argc, char **argv) { const char *fmt1 =3D NULL, *fmt2 =3D NULL, *cache, *filename1, *filena= me2; BlockBackend *blk1, *blk2; @@ -2234,7 +2234,7 @@ static void set_rate_limit(BlockBackend *blk, int64_t= rate_limit) blk_set_io_limits(blk, &cfg); } =20 -static int img_convert(int argc, char **argv) +static int img_convert(const img_cmd_t *ccmd, int argc, char **argv) { int c, bs_i, flags, src_flags =3D BDRV_O_NO_SHARE; const char *fmt =3D NULL, *out_fmt =3D NULL, *cache =3D "unsafe", @@ -3002,7 +3002,7 @@ err: return NULL; } =20 -static int img_info(int argc, char **argv) +static int img_info(const img_cmd_t *ccmd, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3227,7 +3227,7 @@ static inline bool entry_mergeable(const MapEntry *cu= rr, const MapEntry *next) return true; } =20 -static int img_map(int argc, char **argv) +static int img_map(const img_cmd_t *ccmd, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3376,7 +3376,7 @@ out: #define SNAPSHOT_APPLY 3 #define SNAPSHOT_DELETE 4 =20 -static int img_snapshot(int argc, char **argv) +static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) { BlockBackend *blk; BlockDriverState *bs; @@ -3534,7 +3534,7 @@ static int img_snapshot(int argc, char **argv) return 0; } =20 -static int img_rebase(int argc, char **argv) +static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv) { BlockBackend *blk =3D NULL, *blk_old_backing =3D NULL, *blk_new_backin= g =3D NULL; uint8_t *buf_old =3D NULL; @@ -4028,7 +4028,7 @@ out: return 0; } =20 -static int img_resize(int argc, char **argv) +static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret, relative; @@ -4241,7 +4241,7 @@ static int print_amend_option_help(const char *format) return 0; } =20 -static int img_amend(int argc, char **argv) +static int img_amend(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 0; @@ -4505,7 +4505,7 @@ static void bench_cb(void *opaque, int ret) } } =20 -static int img_bench(int argc, char **argv) +static int img_bench(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret =3D 0; const char *fmt =3D NULL, *filename; @@ -4775,7 +4775,7 @@ typedef struct ImgBitmapAction { QSIMPLEQ_ENTRY(ImgBitmapAction) next; } ImgBitmapAction; =20 -static int img_bitmap(int argc, char **argv) +static int img_bitmap(const img_cmd_t *ccmd, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 1; @@ -5075,7 +5075,7 @@ static int img_dd_skip(const char *arg, return 0; } =20 -static int img_dd(int argc, char **argv) +static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) { int ret =3D 0; char *arg =3D NULL; @@ -5341,7 +5341,7 @@ static void dump_json_block_measure_info(BlockMeasure= Info *info) g_string_free(str, true); } =20 -static int img_measure(int argc, char **argv) +static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, @@ -5603,7 +5603,7 @@ int main(int argc, char **argv) for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { argv[0] =3D g_strdup_printf("%s %s", argv[0], cmdname); - return cmd->handler(argc, argv); + return cmd->handler(cmd, argc, argv); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550612372212.53299202103528; Wed, 21 Feb 2024 13:23:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxc-0002aN-6i; Wed, 21 Feb 2024 16:17:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxM-00026T-84; Wed, 21 Feb 2024 16:16:46 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxK-0000mF-9P; Wed, 21 Feb 2024 16:16:43 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 4187D4F7ED; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id E1D5C869A6; Thu, 22 Feb 2024 00:16:22 +0300 (MSK) Received: (nullmailer pid 2335262 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 06/28] qemu-img: create: refresh options/--help Date: Thu, 22 Feb 2024 00:15:47 +0300 Message-Id: <20240221211622.2335170-6-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550614553100001 Content-Type: text/plain; charset="utf-8" Create helper function cmd_help() to display command-specific help text, and use it to print --help for 'create' subcommand. Add missing long options (eg --format) in img_create(). Remove usage of missing_argument()/unrecognized_option() in img_create(). Signed-off-by: Michael Tokarev --- qemu-img.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 38ac0f1845..7e4c993b9c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -132,6 +132,31 @@ void unrecognized_option(const char *option) error_exit("qemu-img", "unrecognized option '%s'", option); } =20 +/* + * Print --help output for a command and exit. + * syntax and description are multi-line with trailing EOL + * (to allow easy extending of the text) + * syntax has each subsequent line indented by 8 chars. + * desrciption is indented by 2 chars for argument on each own line, + * and with 5 chars for argument description (like -h arg below). + */ +static G_NORETURN +void cmd_help(const img_cmd_t *ccmd, + const char *syntax, const char *arguments) +{ + printf( +"Usage:\n" +" %s %s %s" +"\n" +"Arguments:\n" +" -h, --help\n" +" print this help and exit\n" +"%s\n", + "qemu-img", ccmd->name, + syntax, arguments); + exit(EXIT_SUCCESS); +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -530,23 +555,48 @@ static int img_create(const img_cmd_t *ccmd, int argc= , char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, + {"backing", required_argument, 0, 'b'}, + {"backing-format", required_argument, 0, 'F'}, + {"backing-unsafe", no_argument, 0, 'u'}, + {"options", required_argument, 0, 'o'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":F:b:f:ho:qu", + c =3D getopt_long(argc, argv, "F:b:f:ho:qu", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]\n" +" [--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]\n" +, +" -q, --quiet\n" +" quiet operations\n" +" -f, --format FMT\n" +" specifies format of the new image, default is raw\n" +" -o, --options FMT_OPTS\n" +" format-specific options ('-o list' for list)\n" +" -b, --backing BACKING_FILENAME\n" +" stack new image on top of BACKING_FILENAME\n" +" (for formats which support stacking)\n" +" -F, --backing-format BACKING_FMT\n" +" specify format of BACKING_FILENAME\n" +" -u, --backing-unsafe\n" +" do not fail if BACKING_FMT can not be read\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" image file to create. It will be overridden if exists\n" +" SIZE\n" +" image size with optional suffix (multiplies in 1024)\n" +" SIZE is required unless BACKING_IMG is specified,\n" +" in which case it will be the same as size of BACKING_IMG\n" +); break; case 'F': base_fmt =3D optarg; @@ -571,6 +621,8 @@ static int img_create(const img_cmd_t *ccmd, int argc, = char **argv) case OPTION_OBJECT: user_creatable_process_cmdline(optarg); break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550319659995.7858307515977; Wed, 21 Feb 2024 13:18:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxr-0002nf-Ks; Wed, 21 Feb 2024 16:17:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxO-00028R-Lw; Wed, 21 Feb 2024 16:16:48 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxM-0000mS-8a; Wed, 21 Feb 2024 16:16:46 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 511E44F7EE; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 06B24869A7; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335265 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 07/28] qemu-img: factor out parse_output_format() and use it in the code Date: Thu, 22 Feb 2024 00:15:48 +0300 Message-Id: <20240221211622.2335170-7-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550321631100001 Use common code and simplify error message Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 63 ++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7e4c993b9c..01894c097b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -157,6 +157,17 @@ void cmd_help(const img_cmd_t *ccmd, exit(EXIT_SUCCESS); } =20 +static OutputFormat parse_output_format(const char *argv0, const char *arg) +{ + if (!strcmp(arg, "json")) { + return OFORMAT_JSON; + } else if (!strcmp(arg, "human")) { + return OFORMAT_HUMAN; + } else { + error_exit(argv0, "--output expects 'human' or 'json' not '%s'", a= rg); + } +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -775,7 +786,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) { int c, ret; OutputFormat output_format =3D OFORMAT_HUMAN; - const char *filename, *fmt, *output, *cache; + const char *filename, *fmt, *cache; BlockBackend *blk; BlockDriverState *bs; int fix =3D 0; @@ -787,7 +798,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) bool force_share =3D false; =20 fmt =3D NULL; - output =3D NULL; cache =3D BDRV_DEFAULT_CACHE; =20 for(;;) { @@ -833,7 +843,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) } break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case 'T': cache =3D optarg; @@ -857,15 +867,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, = char **argv) } filename =3D argv[optind++]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - ret =3D bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -3059,13 +3060,12 @@ static int img_info(const img_cmd_t *ccmd, int argc= , char **argv) int c; OutputFormat output_format =3D OFORMAT_HUMAN; bool chain =3D false; - const char *filename, *fmt, *output; + const char *filename, *fmt; BlockGraphInfoList *list; bool image_opts =3D false; bool force_share =3D false; =20 fmt =3D NULL; - output =3D NULL; for(;;) { int option_index =3D 0; static const struct option long_options[] =3D { @@ -3100,7 +3100,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, = char **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case OPTION_BACKING_CHAIN: chain =3D true; @@ -3118,15 +3118,6 @@ static int img_info(const img_cmd_t *ccmd, int argc,= char **argv) } filename =3D argv[optind++]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - list =3D collect_image_info_list(image_opts, filename, fmt, chain, force_share); if (!list) { @@ -3285,7 +3276,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) OutputFormat output_format =3D OFORMAT_HUMAN; BlockBackend *blk; BlockDriverState *bs; - const char *filename, *fmt, *output; + const char *filename, *fmt; int64_t length; MapEntry curr =3D { .length =3D 0 }, next; int ret =3D 0; @@ -3295,7 +3286,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) int64_t max_length =3D -1; =20 fmt =3D NULL; - output =3D NULL; for (;;) { int option_index =3D 0; static const struct option long_options[] =3D { @@ -3331,7 +3321,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(argv[0], optarg); break; case 's': start_offset =3D cvtnum("start offset", optarg); @@ -3358,15 +3348,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, = char **argv) } filename =3D argv[optind]; =20 - if (output && !strcmp(output, "json")) { - output_format =3D OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format =3D OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument= ."); - return 1; - } - blk =3D img_open(image_opts, filename, fmt, 0, false, false, force_sha= re); if (!blk) { return 1; @@ -5465,15 +5446,7 @@ static int img_measure(const img_cmd_t *ccmd, int ar= gc, char **argv) image_opts =3D true; break; case OPTION_OUTPUT: - if (!strcmp(optarg, "json")) { - output_format =3D OFORMAT_JSON; - } else if (!strcmp(optarg, "human")) { - output_format =3D OFORMAT_HUMAN; - } else { - error_report("--output must be used with human or json " - "as argument."); - goto out; - } + output_format =3D parse_output_format(argv[0], optarg); break; case OPTION_SIZE: img_size =3D cvtnum("image size", optarg); --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550462619620.5733048586762; Wed, 21 Feb 2024 13:21:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxt-0002qy-S9; Wed, 21 Feb 2024 16:17:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxQ-0002CO-CO; Wed, 21 Feb 2024 16:16:48 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxN-0000mx-Ko; Wed, 21 Feb 2024 16:16:47 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 5E7484F7EF; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 16916869A8; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335268 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 08/28] qemu-img: check: refresh options/--help Date: Thu, 22 Feb 2024 00:15:49 +0300 Message-Id: <20240221211622.2335170-8-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550464072100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 01894c097b..69fa9701e9 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -804,7 +804,9 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) int option_index =3D 0; static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"format", required_argument, 0, 'f'}, + {"cache", required_argument, 0, 'T'}, {"repair", required_argument, 0, 'r'}, {"output", required_argument, 0, OPTION_OUTPUT}, {"object", required_argument, 0, OPTION_OBJECT}, @@ -812,20 +814,38 @@ static int img_check(const img_cmd_t *ccmd, int argc,= char **argv) {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:r:T:qU", + c =3D getopt_long(argc, argv, "hf:r:T:qU", long_options, &option_index); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]\n" +" [--output human|json] [--object OBJDEF] FILENAME\n" +, +" -q, --quiet\n" +" quiet operations\n" +" -f, --format FMT\n" +" specifies format of the image explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -T, --cache CACHE_MODE\n" +" image cache mode (" BDRV_DEFAULT_CACHE ")\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --output human|json\n" +" output format\n" +" -r, --repair leaks|all\n" +" repair particular aspect of the image\n" +" (image will be open in read-write mode, incompatible with --force-sh= are)\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" the image file (or image specification) to operate on\n" +); break; case 'f': fmt =3D optarg; @@ -860,6 +880,8 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550388891341.88009253377663; Wed, 21 Feb 2024 13:19:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxv-0002tA-9s; Wed, 21 Feb 2024 16:17:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxS-0002Fc-Af; Wed, 21 Feb 2024 16:16:50 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxQ-0000nK-Gf; Wed, 21 Feb 2024 16:16:49 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6CB4A4F7F0; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 237CE869A9; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335271 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 09/28] qemu-img: simplify --repair error message Date: Thu, 22 Feb 2024 00:15:50 +0300 Message-Id: <20240221211622.2335170-9-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550389806100001 Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 69fa9701e9..eba13724b0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -858,8 +858,9 @@ static int img_check(const img_cmd_t *ccmd, int argc, c= har **argv) } else if (!strcmp(optarg, "all")) { fix =3D BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit(argv[0], "Unknown option value for -r " - "(expecting 'leaks' or 'all'): %s", optarg); + error_exit(argv[0], + "--repair (-r) expects 'leaks' or 'all' not '%s= '", + optarg); } break; case OPTION_OUTPUT: --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550391407972.9426663076786; Wed, 21 Feb 2024 13:19:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxt-0002ry-Sq; Wed, 21 Feb 2024 16:17:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxV-0002KA-Kd; Wed, 21 Feb 2024 16:16:53 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxT-0000ng-Kv; Wed, 21 Feb 2024 16:16:53 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 798844F7F1; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 31BF5869AA; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335274 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 10/28] qemu-img: commit: refresh options/--help Date: Thu, 22 Feb 2024 00:15:51 +0300 Message-Id: <20240221211622.2335170-10-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550391821100005 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index eba13724b0..1271217272 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1047,24 +1047,50 @@ static int img_commit(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 't'}, + {"drop", no_argument, 0, 'd'}, + {"base", required_argument, 0, 'b'}, + {"progress", no_argument, 0, 'p'}, + {"rate", required_argument, 0, 'r'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:ht:b:dpqr:", + c =3D getopt_long(argc, argv, "f:ht:b:dpqr:", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [-t CACHE_MODE] [-b BASE_IMG] [-d]\n" +" [-r RATE] [--object OBJDEF] FILENAME\n" +, +" -q, --quiet\n" +" quiet operations\n" +" -p, --progress\n" +" show operation progress\n" +" -f, --format FMT\n" +" specify FILENAME image format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -t, --cache CACHE_MODE image cache mode (" BDRV_DEFAULT_CACHE ")\n" +" -d, --drop\n" +" skip emptying FILENAME on completion\n" +" -b, --base BASE_IMG\n" +" image in the backing chain to which to commit changes\n" +" instead of the previous one (implies --drop)\n" +" -r, --rate RATE\n" +" I/O rate limit\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" name of the image file to operate on\n" +); break; case 'f': fmt =3D optarg; @@ -1098,6 +1124,8 @@ static int img_commit(const img_cmd_t *ccmd, int argc= , char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550356595104.18500148137161; Wed, 21 Feb 2024 13:19:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcty0-0002vV-E5; Wed, 21 Feb 2024 16:17:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxi-0002eb-RR; Wed, 21 Feb 2024 16:17:06 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxU-0000oM-3N; Wed, 21 Feb 2024 16:17:06 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 862D84F7F2; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3E9BD869AB; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335277 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 11/28] qemu-img: compare: refresh options/--help Date: Thu, 22 Feb 2024 00:15:52 +0300 Message-Id: <20240221211622.2335170-11-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550357776100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Tokarev --- qemu-img.c | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1271217272..fd61b25ea7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1487,25 +1487,52 @@ static int img_compare(const img_cmd_t *ccmd, int a= rgc, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"cache", required_argument, 0, 'T'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"a-format", required_argument, 0, 'f'}, + {"left-format", required_argument, 0, 'f'}, + {"b-format", required_argument, 0, 'F'}, + {"right-format", required_argument, 0, 'F'}, {"force-share", no_argument, 0, 'U'}, + {"strict", no_argument, 0, 's'}, + {"progress", no_argument, 0, 'p'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:F:T:pqsU", + c =3D getopt_long(argc, argv, "hf:F:T:pqsU", long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[--image-opts | [-f FMT] [-F FMT]] [-s]\n" +" [-T CACHE] [-U] [--object OBJDEF] FILENAME1 FILENAME2\n" +, +" -q, --quiet\n" +" quiet operation\n" +" -p, --progress\n" +" show operation progress\n" +" -f, --a-format FMT\n" +" specify FILENAME1 image format explicitly\n" +" -F, --b-format FMT\n" +" specify FILENAME2 image format explicitly\n" +" --image-opts\n" +" indicates that FILENAMEs are complete image specifications\n" +" instead of file names (incompatible with --a-format and --b-format)\= n" +" -s, --strict\n" +" strict mode, also check if sizes are equal\n" +" -T, --cache CACHE_MODE\n" +" images caching mode (" BDRV_DEFAULT_CACHE ")\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME1, FILENAME2\n" +" image files (or specifications) to compare\n" +); break; case 'f': fmt1 =3D optarg; @@ -1546,6 +1573,8 @@ static int img_compare(const img_cmd_t *ccmd, int arg= c, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550341185192.0382737234919; Wed, 21 Feb 2024 13:19:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxy-0002ts-0M; Wed, 21 Feb 2024 16:17:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxZ-0002Ue-0d; Wed, 21 Feb 2024 16:16:57 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxX-0000pQ-2j; Wed, 21 Feb 2024 16:16:56 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 946BA4F7F3; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 4B47F869AC; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335280 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 12/28] qemu-img: convert: refresh options/--help Date: Thu, 22 Feb 2024 00:15:53 +0300 Message-Id: <20240221211622.2335170-12-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550341721100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. convert uses -B for --backing, - why not -b? Signed-off-by: Michael Tokarev --- qemu-img.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index fd61b25ea7..911cdc159c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2403,30 +2403,100 @@ static int img_convert(const img_cmd_t *ccmd, int = argc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"source-image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"source-format", required_argument, 0, 'f'}, + {"source-cache", required_argument, 0, 'T'}, + {"snapshot", required_argument, 0, 'l'}, + {"sparse-size", required_argument, 0, 'S'}, + {"output-format", required_argument, 0, 'O'}, + {"options", required_argument, 0, 'o'}, + {"output-cache", required_argument, 0, 't'}, + {"backing", required_argument, 0, 'B'}, + {"backing-format", required_argument, 0, 'F'}, {"force-share", no_argument, 0, 'U'}, {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, {"salvage", no_argument, 0, OPTION_SALVAGE}, {"target-is-zero", no_argument, 0, OPTION_TARGET_IS_ZERO}, {"bitmaps", no_argument, 0, OPTION_BITMAPS}, {"skip-broken-bitmaps", no_argument, 0, OPTION_SKIP_BROKEN}, + {"rate", required_argument, 0, 'r'}, + {"parallel", required_argument, 0, 'm'}, + {"oob-writes", no_argument, 0, 'W'}, + {"copy-range-offloading", no_argument, 0, 'C'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:", + c =3D getopt_long(argc, argv, "hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:", long_options, NULL); if (c =3D=3D -1) { break; } - switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; + switch (c) { case 'h': - help(); + cmd_help(ccmd, +"[-f SRC_FMT|--image-opts] [-T SRC_CACHE] [--bitmaps [--skip-broken-bitmap= s]]\n" +" [-o TGT_OPTS|--target-image-opts] [-t TGT_CACHE] [-n]\n" +" [-B BACKING_FILENAME [-F BACKING_FMT]]\n" +" SRC_FILENAME [SRC_FILENAME2 [...]] TGT_FILENAME\n" +, +" -q, --quiet\n" +" quiet operations\n" +" -p, --progress\n" +" show operation progress\n" +" -f, --source-format SRC_FMT\n" +" specify SRC_FILENAME source image format explicitly\n" +" --source-image-opts\n" +" indicates that SRC_FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --source-format)\n" +" -l, --source-snapshot SNAPSHOT_PARAMS\n" +" specify source snapshot parameters\n" +" -T, --source-cache SRC_CACHE\n" +" source image(s) cache mode (" BDRV_DEFAULT_CACHE ")\n" +" -O, --target-format TGT_FMT\n" +" specify TGT_FILENAME image format (default is raw)\n" +" --target-image-opts\n" +" indicates that TGT_FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --output-format)\n" +" -o, --target-options TGT_OPTS\n" +" TARGET_FMT-specific options\n" +" -c, --compress\n" +" create compressed output image (qcow and qcow2 format only)\n" +" -t, --target-cache TGT_CACHE\n" +" cache mode when opening output image (unsafe)\n" +" -B, --backing BACKING_FILENAME\n" +" create output to be a CoW on top of BACKING_FILENAME\n" +" -F, --backing-format BACKING_FMT\n" +" specify BACKING_FILENAME image format explicitly\n" +" -n, --no-create\n" +" omit target volume creation (eg on rbd)\n" +" --target-is-zero\n" +" -S, --sparse-size SPARSE_SIZE\n" +" XXX todo\n" +" --bitmaps\n" +" also copy any persistent bitmaps present in source\n" +" --skip-broken-bitmaps\n" +" skip (do not error out) any broken bitmaps\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" -r, --rate RATE\n" +" I/O rate limit\n" +" -m, --parallel NUM_COROUTINES\n" +" specify parallelism (default 8)\n" +" -C, --copy-range-offloading\n" +" use copy_range offloading\n" +" --salvage\n" +" XXX todo\n" +" -W, --oob-writes\n" +" enable out-of-order writes to improve performance\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" SRC_FILENAME\n" +" source image file name (or specification with --image-opts)\n" +" TGT_FILENAME\n" +" target (output) image file name\n" +); break; case 'f': fmt =3D optarg; @@ -2545,6 +2615,8 @@ static int img_convert(const img_cmd_t *ccmd, int arg= c, char **argv) case OPTION_SKIP_BROKEN: skip_broken =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550599753719.7739501217668; Wed, 21 Feb 2024 13:23:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctxz-0002uy-Rr; Wed, 21 Feb 2024 16:17:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxy-0002uH-6O; Wed, 21 Feb 2024 16:17:22 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxu-0000qR-EL; Wed, 21 Feb 2024 16:17:21 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id A13E24F7F4; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 597F9869AD; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335283 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 13/28] qemu-img: info: refresh options/--help Date: Thu, 22 Feb 2024 00:15:54 +0300 Message-Id: <20240221211622.2335170-13-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550600507100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Also add -b short option for --backing-chain, and remove now-unused OPTION_BACKING_CHAIN. While at it, remove unused option_index variable. Signed-off-by: Michael Tokarev --- qemu-img.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 911cdc159c..cc51da31cf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -65,7 +65,6 @@ typedef struct img_cmd_t { =20 enum { OPTION_OUTPUT =3D 256, - OPTION_BACKING_CHAIN =3D 257, OPTION_OBJECT =3D 258, OPTION_IMAGE_OPTS =3D 259, OPTION_PATTERN =3D 260, @@ -3219,31 +3218,44 @@ static int img_info(const img_cmd_t *ccmd, int argc= , char **argv) =20 fmt =3D NULL; for(;;) { - int option_index =3D 0; static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, {"output", required_argument, 0, OPTION_OUTPUT}, - {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, + {"backing-chain", no_argument, 0, 'b'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hU", - long_options, &option_index); + c =3D getopt_long(argc, argv, "f:hbU", + long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [-b] [-U] [--object OBJDEF]\n" +" [--output human|json] FILENAME\n" +, +" -f, --format FMT\n" +" specify FILENAME image format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -b, --backing-chain\n" +" display information about backing chaing\n" +" (in case the image is stacked\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" --output human|json\n" +" specify output format name (default human)\n" +" FILENAME\n" +" image file name (or specification with --image-opts)\n" +); break; case 'f': fmt =3D optarg; @@ -3254,7 +3266,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, = char **argv) case OPTION_OUTPUT: output_format =3D parse_output_format(argv[0], optarg); break; - case OPTION_BACKING_CHAIN: + case 'b': chain =3D true; break; case OPTION_OBJECT: @@ -3263,6 +3275,8 @@ static int img_info(const img_cmd_t *ccmd, int argc, = char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170855031560883.26916327349727; Wed, 21 Feb 2024 13:18:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcty3-00033q-QX; Wed, 21 Feb 2024 16:17:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxp-0002k6-3Z; Wed, 21 Feb 2024 16:17:14 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxn-0000uP-GY; Wed, 21 Feb 2024 16:17:12 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id AEAA04F7F6; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 66581869AE; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335286 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 14/28] qemu-img: map: refresh options/--help Date: Thu, 22 Feb 2024 00:15:55 +0300 Message-Id: <20240221211622.2335170-14-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550317589100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. While at it, remove unused option_index variable. Signed-off-by: Michael Tokarev --- qemu-img.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index cc51da31cf..3f719bbecf 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3453,7 +3453,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) =20 fmt =3D NULL; for (;;) { - int option_index =3D 0; static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, {"format", required_argument, 0, 'f'}, @@ -3465,20 +3464,33 @@ static int img_map(const img_cmd_t *ccmd, int argc,= char **argv) {"max-length", required_argument, 0, 'l'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:s:l:hU", - long_options, &option_index); + c =3D getopt_long(argc, argv, "f:s:l:hU", + long_options, NULL); if (c =3D=3D -1) { break; } switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [--object OBJDEF] [--output human|json]\n" +" [--start-offset OFFSET] [--max-length LENGTH] [-U] FILENAME\n" +, +" -f, --format FMT\n" +" specify FILENAME image format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" --start-offset OFFSET\n" +" --max-length LENGTH\n" +" --output human|json\n" +" specify output format name (default human)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" image file name (or specification with --image-opts)\n" +); break; case 'f': fmt =3D optarg; @@ -3507,6 +3519,8 @@ static int img_map(const img_cmd_t *ccmd, int argc, c= har **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } if (optind !=3D argc - 1) { --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708551049083773.2486602055608; Wed, 21 Feb 2024 13:30:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyV-000421-DU; Wed, 21 Feb 2024 16:17:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyF-0003OL-5z; Wed, 21 Feb 2024 16:17:40 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyB-0000uo-KJ; Wed, 21 Feb 2024 16:17:38 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id BCEC14F7F7; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 73579869AF; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335289 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 15/28] qemu-img: snapshot: allow specifying -f fmt Date: Thu, 22 Feb 2024 00:15:56 +0300 Message-Id: <20240221211622.2335170-15-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708551049987100003 For consistency with other commands, and since it already accepts --image-opts, allow specifying -f fmt too. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/tools/qemu-img.rst | 2 +- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 3653adb963..9b628c4da5 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -663,7 +663,7 @@ Command description: bitmap support, or 0 if bitmaps are supported but there is nothing to copy. =20 -.. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -= a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME +.. option:: snapshot [--object OBJECTDEF] [-f FMT | --image-opts] [-U] [-q= ] [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME =20 List, apply, create or delete snapshots in image *FILENAME*. =20 diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index c9dd70a892..2c5a8a28f9 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -84,9 +84,9 @@ SRST ERST =20 DEF("snapshot", img_snapshot, - "snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snaps= hot | -c snapshot | -d snapshot] filename") + "snapshot [--object objectdef] [-f fmt | --image-opts] [-U] [-q] [-l |= -a snapshot | -c snapshot | -d snapshot] filename") SRST -.. option:: snapshot [--object OBJECTDEF] [--image-opts] [-U] [-q] [-l | -= a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME +.. option:: snapshot [--object OBJECTDEF] [-f FMT | --image-opts] [-U] [-q= ] [-l | -a SNAPSHOT | -c SNAPSHOT | -d SNAPSHOT] FILENAME ERST =20 DEF("rebase", img_rebase, diff --git a/qemu-img.c b/qemu-img.c index 3f719bbecf..85c37d491d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3594,7 +3594,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) BlockBackend *blk; BlockDriverState *bs; QEMUSnapshotInfo sn; - char *filename, *snapshot_name =3D NULL; + char *filename, *fmt =3D NULL, *snapshot_name =3D NULL; int c, ret =3D 0, bdrv_oflags; int action =3D 0; bool quiet =3D false; @@ -3613,7 +3613,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":la:c:d:hqU", + c =3D getopt_long(argc, argv, ":la:c:d:f:hqU", long_options, NULL); if (c =3D=3D -1) { break; @@ -3628,6 +3628,9 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) case 'h': help(); return 0; + case 'f': + fmt =3D optarg; + break; case 'l': if (action) { error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); @@ -3681,7 +3684,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) filename =3D argv[optind++]; =20 /* Open the image */ - blk =3D img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, + blk =3D img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, force_share); if (!blk) { return 1; --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550800269209.50227520571036; Wed, 21 Feb 2024 13:26:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyL-0003OJ-3b; Wed, 21 Feb 2024 16:17:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcty1-0002vf-Cg; Wed, 21 Feb 2024 16:17:25 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctxz-0000vS-I0; Wed, 21 Feb 2024 16:17:25 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id CB3F54F7F8; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 819CA869B0; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335292 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 16/28] qemu-img: snapshot: make -l (list) the default, simplify option handling Date: Thu, 22 Feb 2024 00:15:57 +0300 Message-Id: <20240221211622.2335170-16-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550801002100001 Content-Type: text/plain; charset="utf-8" When no -l/-a/-c/-d specified, assume -l (list). Use the same values for SNAPSHOT_LIST/etc constants as the option chars (lacd), this makes it possible to simplify option handling a lot, combining cases for 4 options into one. Also remove bdrv_oflags handling (only list can use RO mode). Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/tools/qemu-img.rst | 2 +- qemu-img.c | 52 ++++++++++++++--------------------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 9b628c4da5..df184d15b9 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -256,7 +256,7 @@ Parameters to snapshot subcommand: =20 .. option:: -l =20 - Lists all snapshots in the given image + Lists all snapshots in the given image (default action) =20 Command description: =20 diff --git a/qemu-img.c b/qemu-img.c index 85c37d491d..ee35768af8 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3584,10 +3584,11 @@ out: return ret < 0; } =20 -#define SNAPSHOT_LIST 1 -#define SNAPSHOT_CREATE 2 -#define SNAPSHOT_APPLY 3 -#define SNAPSHOT_DELETE 4 +/* the same as options */ +#define SNAPSHOT_LIST 'l' +#define SNAPSHOT_CREATE 'c' +#define SNAPSHOT_APPLY 'a' +#define SNAPSHOT_DELETE 'd' =20 static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) { @@ -3595,7 +3596,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) BlockDriverState *bs; QEMUSnapshotInfo sn; char *filename, *fmt =3D NULL, *snapshot_name =3D NULL; - int c, ret =3D 0, bdrv_oflags; + int c, ret =3D 0; int action =3D 0; bool quiet =3D false; Error *err =3D NULL; @@ -3603,7 +3604,6 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) bool force_share =3D false; int64_t rt; =20 - bdrv_oflags =3D BDRV_O_RDWR; /* Parse commandline parameters */ for(;;) { static const struct option long_options[] =3D { @@ -3631,36 +3631,15 @@ static int img_snapshot(const img_cmd_t *ccmd, int = argc, char **argv) case 'f': fmt =3D optarg; break; - case 'l': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_LIST; - bdrv_oflags &=3D ~BDRV_O_RDWR; /* no need for RW */ - break; - case 'a': + case SNAPSHOT_LIST: + case SNAPSHOT_APPLY: + case SNAPSHOT_CREATE: + case SNAPSHOT_DELETE: if (action) { error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } - action =3D SNAPSHOT_APPLY; - snapshot_name =3D optarg; - break; - case 'c': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_CREATE; - snapshot_name =3D optarg; - break; - case 'd': - if (action) { - error_exit(argv[0], "Cannot mix '-l', '-a', '-c', '-d'"); - return 0; - } - action =3D SNAPSHOT_DELETE; + action =3D c; snapshot_name =3D optarg; break; case 'q': @@ -3683,9 +3662,14 @@ static int img_snapshot(const img_cmd_t *ccmd, int a= rgc, char **argv) } filename =3D argv[optind++]; =20 + if (!action) { + action =3D SNAPSHOT_LIST; + } + /* Open the image */ - blk =3D img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, - force_share); + blk =3D img_open(image_opts, filename, fmt, + action =3D=3D SNAPSHOT_LIST ? 0 : BDRV_O_RDWR, + false, quiet, force_share); if (!blk) { return 1; } --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550846366927.8467833019291; Wed, 21 Feb 2024 13:27:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyU-0003yb-Su; Wed, 21 Feb 2024 16:17:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyP-0003WH-Qf; Wed, 21 Feb 2024 16:17:50 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyN-0000w9-5l; Wed, 21 Feb 2024 16:17:49 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D7DAC4F7F9; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 8FB5A869B1; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335295 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 17/28] qemu-img: snapshot: refresh options/--help Date: Thu, 22 Feb 2024 00:15:58 +0300 Message-Id: <20240221211622.2335170-17-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550847114100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ee35768af8..ce939708d4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3608,26 +3608,51 @@ static int img_snapshot(const img_cmd_t *ccmd, int = argc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"list", no_argument, 0, SNAPSHOT_LIST}, + {"apply", no_argument, 0, SNAPSHOT_APPLY}, + {"create", no_argument, 0, SNAPSHOT_CREATE}, + {"delete", no_argument, 0, SNAPSHOT_DELETE}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":la:c:d:f:hqU", + c =3D getopt_long(argc, argv, "la:c:d:f:hqU", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - return 0; + cmd_help(ccmd, +"[-f FMT | --image-opts] [-l | -a|-c|-d SNAPSHOT]\n" +" [-U] [--object OBJDEF] FILENAME\n" +, +" -q, --quiet\n" +" quiet operations\n" +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" Operation, one of:\n" +" -l, --list\n" +" list snapshots in FILENAME (the default)\n" +" -c, --create SNAPSHOT\n" +" create named snapshot\n" +" -a, --apply SNAPSHOT\n" +" apply named snapshot to the base\n" +" -d, --delete SNAPSHOT\n" +" delete named snapshot\n" +" FILENAME - image file name (or specification with --image-opts)\n" +); + break; case 'f': fmt =3D optarg; break; @@ -3654,6 +3679,8 @@ static int img_snapshot(const img_cmd_t *ccmd, int ar= gc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708551049446611.7978967174838; Wed, 21 Feb 2024 13:30:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyZ-0004ZL-4G; Wed, 21 Feb 2024 16:17:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyM-0003Vu-K0; Wed, 21 Feb 2024 16:17:50 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyH-0000xy-O0; Wed, 21 Feb 2024 16:17:46 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id E5E294F7FA; Thu, 22 Feb 2024 00:16:45 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 9C7B1869B2; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335298 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 18/28] qemu-img: rebase: refresh options/--help Date: Thu, 22 Feb 2024 00:15:59 +0300 Message-Id: <20240221211622.2335170-18-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708551049921100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Options added: --format, --cache - for the image in question --backing, --backing-format, --backing-cache, --backing-unsafe - for the new backing file (was eg CACHE vs SRC_CACHE, which is unclear). Probably should rename local variables. Signed-off-by: Michael Tokarev --- qemu-img.c | 55 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ce939708d4..2a4bff2872 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3792,26 +3792,61 @@ static int img_rebase(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, + {"progress", no_argument, 0, 'p'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"format", required_argument, 0, 'f'}, + {"cache", required_argument, 0, 't'}, {"compress", no_argument, 0, 'c'}, + {"backing", required_argument, 0, 'b'}, + {"backing-format", required_argument, 0, 'F'}, + {"backing-cache", required_argument, 0, 'T'}, + {"backing-unsafe", no_argument, 0, 'u'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:F:b:upt:T:qUc", + c =3D getopt_long(argc, argv, "hf:F:b:upt:T:qUc", long_options, NULL); if (c =3D=3D -1) { break; } - switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; + switch (c) { case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [-t CACHE] [-q] [-U] [-p]\n" +" [-b BACKING_FILENAME [-F BACKING_FMT] [-T BACKING_CACHE]] [-u]\n" +" [--object OBJDEF] [-c] FILENAME\n" +"Rebases FILENAME on top of BACKING_FILENAME or no backing file\n" +, +" -q, --quiet\n" +" quiet operation\n" +" -p, --progress\n" +" show progress indicator\n" +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -t, --cache CACHE\n" +" cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" -b, --backing BACKING_FILENAME|\"\"\n" +" rebase onto this file (or no backing file)\n" +" -F, --backing-format BACKING_FMT\n" +" specify format for BACKING_FILENAME\n" +" -T, --backing-cache CACHE\n" +" BACKING_FILENAME cache mode (" BDRV_DEFAULT_CACHE ")\n" +" -u, --backing-unsafe\n" +" do not fail if BACKING_FILENAME can not be read\n" +" -c, --compress\n" +" compress image (when image supports this)\n" +" -U, --force-share\n" +" open image in shared mode for concurrent access\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" image file name (or specification with --image-opts)\n" +); return 0; case 'f': fmt =3D optarg; @@ -3849,6 +3884,8 @@ static int img_rebase(const img_cmd_t *ccmd, int argc= , char **argv) case 'c': compress =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550303426407.79840785234023; Wed, 21 Feb 2024 13:18:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyS-0003l0-TV; Wed, 21 Feb 2024 16:17:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyQ-0003Wf-8o; Wed, 21 Feb 2024 16:17:50 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyO-0000zP-71; Wed, 21 Feb 2024 16:17:49 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 0A55A4F7FB; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id AA8EA869B3; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335301 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 19/28] qemu-img: resize: do not always eat last argument Date: Thu, 22 Feb 2024 00:16:00 +0300 Message-Id: <20240221211622.2335170-19-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550305574100001 Content-Type: text/plain; charset="utf-8" 'qemu-img resize --help' does not work, since it wants more arguments. Also it -size is only recognized as a very last argument, but it is common for tools to handle other options after positional arguments too. Tell getopt_long() to return non-options together with options, and process filename and size in the loop, and check if there's an argument right after filename which looks like -N (number), and treat it as size (decrement). This way we can handle --help, and we can also have options after filename and size, and `--' will be handled fine too. The only case which is not handled right is when there's an option between filename and size, and size is given as decrement, - in this case -size will be treated as option, not as size. Signed-off-by: Michael Tokarev --- qemu-img.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 2a4bff2872..c8b0b68d67 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4296,7 +4296,7 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) { Error *err =3D NULL; int c, ret, relative; - const char *filename, *fmt, *size; + const char *filename =3D NULL, *fmt =3D NULL, *size =3D NULL; int64_t n, total_size, current_size; bool quiet =3D false; BlockBackend *blk =3D NULL; @@ -4319,17 +4319,7 @@ static int img_resize(const img_cmd_t *ccmd, int arg= c, char **argv) bool image_opts =3D false; bool shrink =3D false; =20 - /* Remove size from argv manually so that negative numbers are not tre= ated - * as options by getopt. */ - if (argc < 3) { - error_exit(argv[0], "Not enough arguments"); - return 1; - } - - size =3D argv[--argc]; - /* Parse getopt arguments */ - fmt =3D NULL; for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, @@ -4339,7 +4329,7 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) {"shrink", no_argument, 0, OPTION_SHRINK}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":f:hq", + c =3D getopt_long(argc, argv, "-:f:hq", long_options, NULL); if (c =3D=3D -1) { break; @@ -4377,12 +4367,35 @@ static int img_resize(const img_cmd_t *ccmd, int ar= gc, char **argv) case OPTION_SHRINK: shrink =3D true; break; + case 1: /* a non-optional argument */ + if (!filename) { + filename =3D optarg; + /* see if we have -size (number) next to filename */ + if (optind < argc) { + size =3D argv[optind]; + if (size[0] =3D=3D '-' && size[1] >=3D '0' && size[1] = <=3D '9') { + ++optind; + } else { + size =3D NULL; + } + } + } else if (!size) { + size =3D optarg; + } else { + error_exit(argv[0], "Extra argument(s) in command line"); + } + break; } } - if (optind !=3D argc - 1) { + if (!filename && optind < argc) { + filename =3D argv[optind++]; + } + if (!size && optind < argc) { + size =3D argv[optind++]; + } + if (!filename || !size || optind < argc) { error_exit(argv[0], "Expecting image file name and size"); } - filename =3D argv[optind++]; =20 /* Choose grow, shrink, or absolute resize mode */ switch (size[0]) { --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550605018996.3633607096857; Wed, 21 Feb 2024 13:23:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyZ-0004bS-7l; Wed, 21 Feb 2024 16:18:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyV-00045N-UJ; Wed, 21 Feb 2024 16:17:55 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyS-0000zy-Cf; Wed, 21 Feb 2024 16:17:55 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 16BFB4F7FC; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id C2D3A869B4; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335304 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 20/28] qemu-img: resize: refresh options/--help Date: Thu, 22 Feb 2024 00:16:01 +0300 Message-Id: <20240221211622.2335170-20-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550606507100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c8b0b68d67..45fbef5d37 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4323,27 +4323,44 @@ static int img_resize(const img_cmd_t *ccmd, int ar= gc, char **argv) for(;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"preallocation", required_argument, 0, OPTION_PREALLOCATION}, {"shrink", no_argument, 0, OPTION_SHRINK}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, "-:f:hq", + c =3D getopt_long(argc, argv, "-f:hq", long_options, NULL); if (c =3D=3D -1) { break; } switch(c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); - break; + cmd_help(ccmd, +"[-f FMT | --image-opts] [--preallocation PREALLOC] [--shrink]\n" +" [--object OBJECTDEF] [-q] FILENAME [+|-]SIZE\n" +, +" -q, --quiet\n" +" quiet operation\n" +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" --shrink\n" +" allow operation when new size is smaller than original\n" +" --preallocation PREALLOC\n" +" specify preallocation type for the new areas\n" +" --object OBJDEF\n" +" QEMU user-creatable object (eg encryption key)\n" +" FILENAME\n" +" image file (specification) to resize\n" +" SIZE\n" +" new image size or amount by which to shrink/grow\n" +); + return 0; case 'f': fmt =3D optarg; break; @@ -4385,6 +4402,8 @@ static int img_resize(const img_cmd_t *ccmd, int argc= , char **argv) error_exit(argv[0], "Extra argument(s) in command line"); } break; + default: + tryhelp(argv[0]); } } if (!filename && optind < argc) { --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550490288518.6426620777723; Wed, 21 Feb 2024 13:21:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyt-0006jT-Ck; Wed, 21 Feb 2024 16:18:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyq-0006Vk-I1; Wed, 21 Feb 2024 16:18:16 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyl-000105-SR; Wed, 21 Feb 2024 16:18:16 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 23A7F4F7FD; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id CF9C2869B5; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335307 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 21/28] qemu-img: amend: refresh options/--help Date: Thu, 22 Feb 2024 00:16:02 +0300 Message-Id: <20240221211622.2335170-21-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550492211100003 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 45fbef5d37..0d17738fb6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4557,26 +4557,42 @@ static int img_amend(const img_cmd_t *ccmd, int arg= c, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, + {"quiet", no_argument, 0, 'q'}, + {"progress", no_argument, 0, 'p'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"format", required_argument, 0, 'f'}, + {"cache", required_argument, 0, 't'}, + {"options", required_argument, 0, 'o'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force", no_argument, 0, OPTION_FORCE}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":ho:f:t:pq", + c =3D getopt_long(argc, argv, "ho:f:t:pq", long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [t CACHE] [--force] [-p] [-q]\n" +" [--object OBJDEF -o OPTIONS FILENAME\n" +, +" -q, --quiet\n" +" quiet operation\n" +" -p, --progres\n" +" show progress\n" +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -t, --cache CACHE\n" +" cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" --force\n" +" allow certain unsafe operations\n" +); break; case 'o': if (accumulate_options(&options, optarg) < 0) { @@ -4605,6 +4621,8 @@ static int img_amend(const img_cmd_t *ccmd, int argc,= char **argv) case OPTION_FORCE: force =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550356422643.8943515365489; Wed, 21 Feb 2024 13:19:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctyy-0007G8-U4; Wed, 21 Feb 2024 16:18:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyt-0006p0-Sa; Wed, 21 Feb 2024 16:18:19 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyr-00011I-FI; Wed, 21 Feb 2024 16:18:19 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 31EB94F7FE; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id DC756869B6; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335310 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 22/28] qemu-img: bench: refresh options/--help Date: Thu, 22 Feb 2024 00:16:03 +0300 Message-Id: <20240221211622.2335170-22-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550357774100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 64 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 0d17738fb6..8455832d34 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4847,28 +4847,70 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) for (;;) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, - {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL= }, + {"format", required_argument, 0, 'f'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"cache", required_argument, 0, 't'}, + {"count", required_argument, 0, 'c'}, + {"depth", required_argument, 0, 'd'}, + {"offset", required_argument, 0, 'o'}, + {"buffer-size", required_argument, 0, 's'}, + {"step-size", required_argument, 0, 'S'}, + {"aio", required_argument, 0, 'i'}, + {"native", no_argument, 0, 'n'}, + {"write", no_argument, 0, 'w'}, {"pattern", required_argument, 0, OPTION_PATTERN}, + {"flush-interval", required_argument, 0, OPTION_FLUSH_INTERVAL= }, {"no-drain", no_argument, 0, OPTION_NO_DRAIN}, {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hc:d:f:ni:o:qs:S:t:wU", long_optio= ns, - NULL); + c =3D getopt_long(argc, argv, "hc:d:f:ni:o:qs:S:t:wU", + long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT | --image-opts] [-t CACHE] [-c COUNT] [-d DEPTH]\n" +" [-o OFFSET] [-s BUFFER_SIZE] [-S STEP_SIZE] [-i AIO] [-n]\n" +" [-w [--pattern PATTERN] [--flush-interval INTERVAL [--no-drain]]]= \n" +, +" -q, --quiet\n" +" quiet operations\n" +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -t, --cache CACHE\n" +" cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" -c, --count COUNT\n" +" number of I/O requests to perform\n" +" -s, --buffer-size BUFFER_SIZE\n" +" size of each I/O request\n" +" -d, --depth DEPTH\n" +" number of requests to perform in parallel\n" +" -o, --offset OFFSET\n" +" start first request at this OFFSET\n" +" -S, --step-size STEP_SIZE\n" +" each next request offset increment\n" +" -i, --aio AIO\n" +" async-io backend (threads, native, io_uring)\n" +" -n, --native\n" +" use native AIO backend if possible\n" +" -w, --write\n" +" perform write test (default is read)\n" +" --pattern PATTERN\n" +" write this pattern byte instead of zero\n" +" --flush-interval FLUSH_INTERVAL\n" +" issue flush after this number of requests\n" +" --no-drain\n" +" do not wait when flushing pending requests\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +); break; case 'c': { @@ -4985,6 +5027,8 @@ static int img_bench(const img_cmd_t *ccmd, int argc,= char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550509576589.2172001578698; Wed, 21 Feb 2024 13:21:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctz1-0007YR-Ip; Wed, 21 Feb 2024 16:18:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyu-0006rt-8L; Wed, 21 Feb 2024 16:18:20 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctys-00016N-AS; Wed, 21 Feb 2024 16:18:19 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3EB294F7FF; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id EABD8869B7; Thu, 22 Feb 2024 00:16:23 +0300 (MSK) Received: (nullmailer pid 2335313 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 23/28] qemu-img: bitmap: refresh options/--help Date: Thu, 22 Feb 2024 00:16:04 +0300 Message-Id: <20240221211622.2335170-23-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550510216100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 8455832d34..e4027ece20 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5168,20 +5168,42 @@ static int img_bitmap(const img_cmd_t *ccmd, int ar= gc, char **argv) {"source-format", required_argument, 0, 'F'}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":b:f:F:g:h", long_options, NULL); + c =3D getopt_long(argc, argv, "b:f:F:g:h", + long_options, NULL); if (c =3D=3D -1) { break; } =20 switch (c) { - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; case 'h': - help(); + cmd_help(ccmd, +"( --merge SOURCE | --add | --remove | --clear |\n" +" --enable | --disable ).. [-f FMT | --image-opts]\n" +" [ -b SRC_FILENAME [-F SOURCE_FMT]] [-g GRANULARITY] [--object OBJ= DEF]\n" +" FILENAME BITMAP\n" +, +" -f, --format FMT\n" +" specify FILENAME format explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" --add\n" +" creates BITMAP, enables to record future edits\n" +" -g, --granularity GRANULARITY\n" +" sets non-default granularity for --add\n" +" --remove\n" +" removes BITMAP\n" +" --clear\n" +" clears BITMAP\n" +" --enable, --disable\n" +" starts and stops recording future edits to BITMAP\n" +" --merge SRC_FILENAME\n" +" merges contents of SRC_FILENAME bitmap into BITMAP\n" +" -b, --source-file SRC_FILENAME\n" +" select alternative source file for --merge\n" +" -F, --source-format SRC_FMT\n" +" specify format for SRC_FILENAME explicitly\n" +); break; case 'b': src_filename =3D optarg; @@ -5237,6 +5259,8 @@ static int img_bitmap(const img_cmd_t *ccmd, int argc= , char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550405680433.2407193078783; Wed, 21 Feb 2024 13:20:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctz1-0007Xx-Io; Wed, 21 Feb 2024 16:18:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyx-0007B0-4Y; Wed, 21 Feb 2024 16:18:24 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyv-00017X-9C; Wed, 21 Feb 2024 16:18:22 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 4B71B4F800; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 03738869B8; Thu, 22 Feb 2024 00:16:24 +0300 (MSK) Received: (nullmailer pid 2335316 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 24/28] qemu-img: dd: refresh options/--help Date: Thu, 22 Feb 2024 00:16:05 +0300 Message-Id: <20240221211622.2335170-24-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550407899100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e4027ece20..af7841573c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5502,31 +5502,48 @@ static int img_dd(const img_cmd_t *ccmd, int argc, = char **argv) const struct option long_options[] =3D { { "help", no_argument, 0, 'h'}, { "object", required_argument, 0, OPTION_OBJECT}, + { "format", required_argument, 0, 'f'}, + { "output-format", required_argument, 0, 'O'}, { "image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, { "force-share", no_argument, 0, 'U'}, { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, ":hf:O:U", long_options, NULL)))= { + while ((c =3D getopt_long(argc, argv, "hf:O:U", long_options, NULL))) { if (c =3D=3D EOF) { break; } switch (c) { + case 'h': + cmd_help(ccmd, +"[-f FMT|--image-opts] [-O OUTPUT_FMT] [-U]\n" +" [bs=3DBLOCK_SIZE] [count=3DBLOCKS] if=3DINPUT of=3DOUTPUT\n" +, +" -f, --format FMT\n" +" specify format for INPUT explicitly\n" +" --image-opts\n" +" indicates that INPUT is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -O, --output-format OUTPUT_FMT\n" +" format of the OUTPUT (default raw)\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +" bs=3DBLOCK_SIZE[kKMGTP]\n" +" size of I/O block (default 512)\n" +" count=3DCOUNT\n" +" number of blocks to convert (default whole INPUT)\n" +" if=3DINPUT\n" +" input file name (or image specification with --image-opts)\n" +" of=3DOUTPUT\n" +" output file name to create\n" +); + break; case 'O': out_fmt =3D optarg; break; case 'f': fmt =3D optarg; break; - case ':': - missing_argument(argv[optind - 1]); - break; - case '?': - unrecognized_option(argv[optind - 1]); - break; - case 'h': - help(); - break; case 'U': force_share =3D true; break; @@ -5536,6 +5553,8 @@ static int img_dd(const img_cmd_t *ccmd, int argc, ch= ar **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550472366426.76505596628374; Wed, 21 Feb 2024 13:21:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctz5-0007oc-As; Wed, 21 Feb 2024 16:18:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyy-0007Gd-O5; Wed, 21 Feb 2024 16:18:24 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctyv-00017j-Ke; Wed, 21 Feb 2024 16:18:24 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 650364F801; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 1063D869B9; Thu, 22 Feb 2024 00:16:24 +0300 (MSK) Received: (nullmailer pid 2335319 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 25/28] qemu-img: measure: refresh options/--help Date: Thu, 22 Feb 2024 00:16:06 +0300 Message-Id: <20240221211622.2335170-25-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550474181100001 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Also add -s short option for --size (and remove OPTION_SIZE). Signed-off-by: Michael Tokarev --- qemu-img.c | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index af7841573c..d72e1f565b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -71,7 +71,6 @@ enum { OPTION_FLUSH_INTERVAL =3D 261, OPTION_NO_DRAIN =3D 262, OPTION_TARGET_IMAGE_OPTS =3D 263, - OPTION_SIZE =3D 264, OPTION_PREALLOCATION =3D 265, OPTION_SHRINK =3D 266, OPTION_SALVAGE =3D 267, @@ -5744,15 +5743,6 @@ static void dump_json_block_measure_info(BlockMeasur= eInfo *info) =20 static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) { - static const struct option long_options[] =3D { - {"help", no_argument, 0, 'h'}, - {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, - {"object", required_argument, 0, OPTION_OBJECT}, - {"output", required_argument, 0, OPTION_OUTPUT}, - {"size", required_argument, 0, OPTION_SIZE}, - {"force-share", no_argument, 0, 'U'}, - {0, 0, 0, 0} - }; OutputFormat output_format =3D OFORMAT_HUMAN; BlockBackend *in_blk =3D NULL; BlockDriver *drv; @@ -5773,12 +5763,47 @@ static int img_measure(const img_cmd_t *ccmd, int a= rgc, char **argv) int ret =3D 1; int c; =20 + static const struct option long_options[] =3D { + {"help", no_argument, 0, 'h'}, + {"target-format", required_argument, 0, 'O'}, + {"format", required_argument, 0, 'f'}, + {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"options", required_argument, 0, 'o'}, + {"snapshot", required_argument, 0, 'l'}, + {"object", required_argument, 0, OPTION_OBJECT}, + {"output", required_argument, 0, OPTION_OUTPUT}, + {"size", required_argument, 0, 's'}, + {"force-share", no_argument, 0, 'U'}, + {0, 0, 0, 0} + }; + while ((c =3D getopt_long(argc, argv, "hf:O:o:l:U", long_options, NULL)) !=3D -1) { switch (c) { - case '?': case 'h': - help(); + cmd_help(ccmd, +"[-f FMT|--image-opts] [-o OPTIONS] [-O OUTPUT_FMT]\n" +" [--output OFMT] [--object OBJDEF] [-l SNAPSHOT_PARAM]\n" +" (--size SIZE | FILENAME)\n" +, +" -O, --target-format FMT\n" +" desired target/output image format (default raw)\n" +" -s, --size SIZE\n" +" measure file size for given image size\n" +" FILENAME\n" +" measure file size required to convert from FILENAME\n" +" -f, --format\n" +" specify format of FILENAME explicitly\n" +" --image-opts\n" +" indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -l, --snapshot SNAPSHOT\n" +" use this snapshot in FILENAME as source\n" +" --output human|json\n" +" output format\n" +" -U, --force-share\n" +" open images in shared mode for concurrent access\n" +); break; case 'f': fmt =3D optarg; @@ -5816,12 +5841,14 @@ static int img_measure(const img_cmd_t *ccmd, int a= rgc, char **argv) case OPTION_OUTPUT: output_format =3D parse_output_format(argv[0], optarg); break; - case OPTION_SIZE: + case 's': img_size =3D cvtnum("image size", optarg); if (img_size < 0) { goto out; } break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550731517373.0074767117061; Wed, 21 Feb 2024 13:25:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctzY-0001xh-9v; Wed, 21 Feb 2024 16:19:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzL-00010D-Le; Wed, 21 Feb 2024 16:18:47 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzJ-00018S-3W; Wed, 21 Feb 2024 16:18:47 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 71FFE4F802; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 28B74869BA; Thu, 22 Feb 2024 00:16:24 +0300 (MSK) Received: (nullmailer pid 2335322 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 26/28] qemu-img: implement short --help, remove global help() function Date: Thu, 22 Feb 2024 00:16:07 +0300 Message-Id: <20240221211622.2335170-26-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550732849100001 Content-Type: text/plain; charset="utf-8" now once all individual subcommands has --help support, remove the large unreadable help() thing and replace it with small global --help, which refers to individual command --help for more info. While at it, also line-wrap list of formats after 75 chars. Since missing_argument() and unrecognized_option() are now unused, remove them. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 172 ++++++++++++----------------------------------------- 1 file changed, 39 insertions(+), 133 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d72e1f565b..ea284dca2d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -94,11 +94,6 @@ typedef enum OutputFormat { /* Default to cache=3Dwriteback as data integrity is not important for qem= u-img */ #define BDRV_DEFAULT_CACHE "writeback" =20 -static void format_print(void *opaque, const char *name) -{ - printf(" %s", name); -} - static G_NORETURN void tryhelp(const char *argv0) { @@ -118,18 +113,6 @@ void error_exit(const char *argv0, const char *fmt, ..= .) tryhelp(argv0); } =20 -static G_NORETURN -void missing_argument(const char *option) -{ - error_exit("qemu-img", "missing argument for option '%s'", option); -} - -static G_NORETURN -void unrecognized_option(const char *option) -{ - error_exit("qemu-img", "unrecognized option '%s'", option); -} - /* * Print --help output for a command and exit. * syntax and description are multi-line with trailing EOL @@ -166,114 +149,6 @@ static OutputFormat parse_output_format(const char *a= rgv0, const char *arg) } } =20 -/* Please keep in synch with docs/tools/qemu-img.rst */ -static G_NORETURN -void help(void) -{ - const char *help_msg =3D - QEMU_IMG_VERSION - "usage: qemu-img [standard options] command [command options]\n" - "QEMU disk image utility\n" - "\n" - " '-h', '--help' display this help and exit\n" - " '-V', '--version' output version information and exit\n" - " '-T', '--trace' [[enable=3D]][,events=3D][,file=3D]\n" - " specify tracing options\n" - "\n" - "Command syntax:\n" -#define DEF(option, callback, arg_string) \ - " " arg_string "\n" -#include "qemu-img-cmds.h" -#undef DEF - "\n" - "Command parameters:\n" - " 'filename' is a disk image filename\n" - " 'objectdef' is a QEMU user creatable object definition. See = the qemu(1)\n" - " manual page for a description of the object properties. Th= e most common\n" - " object type is a 'secret', which is used to supply passwor= ds and/or\n" - " encryption keys.\n" - " 'fmt' is the disk image format. It is guessed automatically = in most cases\n" - " 'cache' is the cache mode used to write the output disk imag= e, the valid\n" - " options are: 'none', 'writeback' (default, except for conv= ert), 'writethrough',\n" - " 'directsync' and 'unsafe' (default for convert)\n" - " 'src_cache' is the cache mode used to read input disk images= , the valid\n" - " options are the same as for the 'cache' option\n" - " 'size' is the disk image size in bytes. Optional suffixes\n" - " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (g= igabyte, 1024M),\n" - " 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exab= yte, 1024P) are\n" - " supported. 'b' is ignored.\n" - " 'output_filename' is the destination disk image filename\n" - " 'output_fmt' is the destination format\n" - " 'options' is a comma separated list of format specific optio= ns in a\n" - " name=3Dvalue format. Use -o help for an overview of the op= tions supported by\n" - " the used format\n" - " 'snapshot_param' is param used for internal snapshot, format= \n" - " is 'snapshot.id=3D[ID],snapshot.name=3D[NAME]', or\n" - " '[ID_OR_NAME]'\n" - " '-c' indicates that target image must be compressed (qcow fo= rmat only)\n" - " '-u' allows unsafe backing chains. For rebasing, it is assum= ed that old and\n" - " new backing file match exactly. The image doesn't need = a working\n" - " backing file before rebasing in this case (useful for r= enaming the\n" - " backing file). For image creation, allow creating witho= ut attempting\n" - " to open the backing file.\n" - " '-h' with or without a command shows this help and lists the= supported formats\n" - " '-p' show progress of command (only certain commands)\n" - " '-q' use Quiet mode - do not print any output (except errors= )\n" - " '-S' indicates the consecutive number of bytes (defaults to = 4k) that must\n" - " contain only zeros for qemu-img to create a sparse imag= e during\n" - " conversion. If the number of bytes is 0, the source wil= l not be scanned for\n" - " unallocated or zero sectors, and the destination image = will always be\n" - " fully allocated\n" - " '--output' takes the format in which the output must be done= (human or json)\n" - " '-n' skips the target volume creation (useful if the volume = is created\n" - " prior to running qemu-img)\n" - "\n" - "Parameters to bitmap subcommand:\n" - " 'bitmap' is the name of the bitmap to manipulate, through on= e or more\n" - " actions from '--add', '--remove', '--clear', '--enable'= , '--disable',\n" - " or '--merge source'\n" - " '-g granularity' sets the granularity for '--add' actions\n" - " '-b source' and '-F src_fmt' tell '--merge' actions to find = the source\n" - " bitmaps from an alternative file\n" - "\n" - "Parameters to check subcommand:\n" - " '-r' tries to repair any inconsistencies that are found duri= ng the check.\n" - " '-r leaks' repairs only cluster leaks, whereas '-r all'= fixes all\n" - " kinds of errors, with a higher risk of choosing the wro= ng fix or\n" - " hiding corruption that has already occurred.\n" - "\n" - "Parameters to convert subcommand:\n" - " '--bitmaps' copies all top-level persistent bitmaps to desti= nation\n" - " '-m' specifies how many coroutines work in parallel during t= he convert\n" - " process (defaults to 8)\n" - " '-W' allow to write to the target out of order rather than s= equential\n" - "\n" - "Parameters to snapshot subcommand:\n" - " 'snapshot' is the name of the snapshot to create, apply or d= elete\n" - " '-a' applies a snapshot (revert disk to saved state)\n" - " '-c' creates a snapshot\n" - " '-d' deletes a snapshot\n" - " '-l' lists all snapshots in the given image\n" - "\n" - "Parameters to compare subcommand:\n" - " '-f' first image format\n" - " '-F' second image format\n" - " '-s' run in Strict mode - fail on different image size or se= ctor allocation\n" - "\n" - "Parameters to dd subcommand:\n" - " 'bs=3DBYTES' read and write up to BYTES bytes at a time " - "(default: 512)\n" - " 'count=3DN' copy only N input blocks\n" - " 'if=3DFILE' read from FILE\n" - " 'of=3DFILE' write to FILE\n" - " 'skip=3DN' skip N bs-sized blocks at the start of input\n"; - - printf("%s\nSupported formats:", help_msg); - bdrv_iterate_format(format_print, NULL, false); - printf("\n\n" QEMU_HELP_BOTTOM "\n"); - exit(EXIT_SUCCESS); -} - /* * Is @list safe for accumulate_options()? * It is when multiple of them can be joined together separated by ','. @@ -5956,6 +5831,16 @@ static const img_cmd_t img_cmds[] =3D { { NULL, NULL, }, }; =20 +static void format_print(void *opaque, const char *name) +{ + int *np =3D opaque; + if (*np + strlen(name) > 75) { + printf("\n "); + *np =3D 1; + } + *np +=3D printf(" %s", name); +} + int main(int argc, char **argv) { const img_cmd_t *cmd; @@ -5987,16 +5872,35 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); =20 - while ((c =3D getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != =3D -1) { + while ((c =3D getopt_long(argc, argv, "+hVT:", long_options, NULL)) != =3D -1) { switch (c) { - case ':': - missing_argument(argv[optind - 1]); - return 0; - case '?': - unrecognized_option(argv[optind - 1]); - return 0; case 'h': - help(); + printf( +QEMU_IMG_VERSION +"QEMU disk image utility. Usage:\n" +"\n" +" qemu-img [standard options] COMMAND [--help | command options]\n" +"\n" +"Standard options:\n" +" -h, --help\n" +" display this help and exit\n" +" -V, --version\n" +" display version info and exit\n" +" -T,--trace TRACE\n" +" specify tracing options:\n" +" [[enable=3D]][,events=3D][,file=3D]\n" +"\n" +"Recognized commands (run qemu-img COMMAND --help for command-specific hel= p):\n\n"); + for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { + printf(" %s\n", cmd->name); + } + printf("\nSupported image formats:\n"); + c =3D 99; /* force a newline */ + bdrv_iterate_format(format_print, &c, false); + if (c) { + printf("\n"); + } + printf("\n" QEMU_HELP_BOTTOM "\n"); return 0; case 'V': printf(QEMU_IMG_VERSION); @@ -6004,6 +5908,8 @@ int main(int argc, char **argv) case 'T': trace_opt_parse(optarg); break; + default: + tryhelp(argv[0]); } } =20 --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550687738982.3474452641871; Wed, 21 Feb 2024 13:24:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctzl-0003jQ-Mv; Wed, 21 Feb 2024 16:19:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzN-0001Np-Nn; Wed, 21 Feb 2024 16:18:53 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzL-00018y-Ez; Wed, 21 Feb 2024 16:18:49 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 7F3AE4F803; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 370C5869BB; Thu, 22 Feb 2024 00:16:24 +0300 (MSK) Received: (nullmailer pid 2335325 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 27/28] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Date: Thu, 22 Feb 2024 00:16:08 +0300 Message-Id: <20240221211622.2335170-27-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550688703100001 Content-Type: text/plain; charset="utf-8" also add short description to each command and use it in --help Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ea284dca2d..299e34e470 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -61,6 +61,7 @@ typedef struct img_cmd_t { const char *name; int (*handler)(const struct img_cmd_t *ccmd, int argc, char **argv); + const char *description; } img_cmd_t; =20 enum { @@ -126,14 +127,14 @@ void cmd_help(const img_cmd_t *ccmd, const char *syntax, const char *arguments) { printf( -"Usage:\n" +"%s. Usage:\n" " %s %s %s" "\n" "Arguments:\n" " -h, --help\n" " print this help and exit\n" "%s\n", - "qemu-img", ccmd->name, + ccmd->description, "qemu-img", ccmd->name, syntax, arguments); exit(EXIT_SUCCESS); } @@ -5824,10 +5825,36 @@ out: } =20 static const img_cmd_t img_cmds[] =3D { -#define DEF(option, callback, arg_string) \ - { option, callback }, -#include "qemu-img-cmds.h" -#undef DEF + { "amend", img_amend, + "Update format-specific options of the image" }, + { "bench", img_bench, + "Run simple image benchmark" }, + { "bitmap", img_bitmap, + "Perform modifications of the persistent bitmap in the image" }, + { "check", img_check, + "Check basic image integrity" }, + { "commit", img_commit, + "Commit image to its backing file" }, + { "compare", img_compare, + "Check if two images have the same contents" }, + { "convert", img_convert, + "Copy one image to another with optional format conversion" }, + { "create", img_create, + "Create and format new image file" }, + { "dd", img_dd, + "Copy input to output with optional format conversion" }, + { "info", img_info, + "Display information about image" }, + { "map", img_map, + "Dump image metadata" }, + { "measure", img_measure, + "Calculate file size requred for a new image" }, + { "rebase", img_rebase, + "Change backing file of the image" }, + { "resize", img_resize, + "Resize the image to the new size" }, + { "snapshot", img_snapshot, + "List or manipulate snapshots within image" }, { NULL, NULL, }, }; =20 @@ -5892,7 +5919,7 @@ QEMU_IMG_VERSION "\n" "Recognized commands (run qemu-img COMMAND --help for command-specific hel= p):\n\n"); for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { - printf(" %s\n", cmd->name); + printf(" %s - %s\n", cmd->name, cmd->description); } printf("\nSupported image formats:\n"); c =3D 99; /* force a newline */ --=20 2.39.2 From nobody Tue Nov 26 08:42:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708550497871415.9157111070084; Wed, 21 Feb 2024 13:21:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rctzg-0002vn-H0; Wed, 21 Feb 2024 16:19:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzQ-0001Vy-4F; Wed, 21 Feb 2024 16:18:55 -0500 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rctzN-0001FE-44; Wed, 21 Feb 2024 16:18:51 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 8D1CA4F804; Thu, 22 Feb 2024 00:16:46 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 43C22869BC; Thu, 22 Feb 2024 00:16:24 +0300 (MSK) Received: (nullmailer pid 2335328 invoked by uid 1000); Wed, 21 Feb 2024 21:16:22 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places Date: Thu, 22 Feb 2024 00:16:09 +0300 Message-Id: <20240221211622.2335170-28-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1708550498213100008 Content-Type: text/plain; charset="utf-8" cvtnum() expects input string to specify some sort of size (optionally with KMG... suffix). However, there are a lot of other number conversions in there (using qemu_strtol &Co), also, not all conversions which use cvtnum, actually expects size, - like dd count=3Dnn. Add bool issize argument to cvtnum() to specify if it should treat the argument as a size or something else, - this changes conversion routine in use and error text. Use the new cvtnum() in more places (like where strtol were used), since it never return negative number in successful conversion. When it makes sense, also specify upper or lower bounds at the same time. This simplifies option processing in multiple places, removing the need of local temporary variables and longer error reporting code. While at it, fix errors, like depth in measure must be >=3D 1, while the previous code allowed it to be 0. In a few places, change unsigned variables (like of type size_t) to be signed instead, - to avoid the need of temporary conversion variable. All these variables are okay to be signed, we never assign <0 value to them except of the cases of conversion error, where we return immediately. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrang=C3=A9 --- qemu-img.c | 118 ++++++++++++++++++++--------------------------------- 1 file changed, 44 insertions(+), 74 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 299e34e470..a066c4cfc4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -397,18 +397,23 @@ static int add_old_style_options(const char *fmt, Qem= uOpts *opts, return 0; } =20 -static int64_t cvtnum_full(const char *name, const char *value, int64_t mi= n, - int64_t max) +static int64_t cvtnum_full(const char *name, const char *value, + bool issize, int64_t min, int64_t max) { int err; uint64_t res; =20 - err =3D qemu_strtosz(value, NULL, &res); + err =3D issize ? qemu_strtosz(value, NULL, &res) : + qemu_strtou64(value, NULL, 0, &res); if (err < 0 && err !=3D -ERANGE) { - error_report("Invalid %s specified. You may use " - "k, M, G, T, P or E suffixes for", name); - error_report("kilobytes, megabytes, gigabytes, terabytes, " - "petabytes and exabytes."); + if (issize) { + error_report("Invalid %s specified. You may use " + "k, M, G, T, P or E suffixes for", name); + error_report("kilobytes, megabytes, gigabytes, terabytes, " + "petabytes and exabytes."); + } else { + error_report("Invalid %s specified.", name); + } return err; } if (err =3D=3D -ERANGE || res > max || res < min) { @@ -419,9 +424,9 @@ static int64_t cvtnum_full(const char *name, const char= *value, int64_t min, return res; } =20 -static int64_t cvtnum(const char *name, const char *value) +static int64_t cvtnum(const char *name, const char *value, bool issize) { - return cvtnum_full(name, value, 0, INT64_MAX); + return cvtnum_full(name, value, issize, 0, INT64_MAX); } =20 static int img_create(const img_cmd_t *ccmd, int argc, char **argv) @@ -525,7 +530,7 @@ static int img_create(const img_cmd_t *ccmd, int argc, = char **argv) =20 /* Get image size, if specified */ if (optind < argc) { - img_size =3D cvtnum("image size", argv[optind++]); + img_size =3D cvtnum("image size", argv[optind++], true); if (img_size < 0) { goto fail; } @@ -987,7 +992,7 @@ static int img_commit(const img_cmd_t *ccmd, int argc, = char **argv) quiet =3D true; break; case 'r': - rate_limit =3D cvtnum("rate limit", optarg); + rate_limit =3D cvtnum("rate limit", optarg, true); if (rate_limit < 0) { return 1; } @@ -2412,7 +2417,7 @@ static int img_convert(const img_cmd_t *ccmd, int arg= c, char **argv) { int64_t sval; =20 - sval =3D cvtnum("buffer size for sparse output", optarg); + sval =3D cvtnum("buffer size for sparse output", optarg, true); if (sval < 0) { goto fail_getopt; } else if (!QEMU_IS_ALIGNED(sval, BDRV_SECTOR_SIZE) || @@ -2444,10 +2449,9 @@ static int img_convert(const img_cmd_t *ccmd, int ar= gc, char **argv) skip_create =3D true; break; case 'm': - if (qemu_strtol(optarg, NULL, 0, &s.num_coroutines) || - s.num_coroutines < 1 || s.num_coroutines > MAX_COROUTINES)= { - error_report("Invalid number of coroutines. Allowed number= of" - " coroutines is between 1 and %d", MAX_COROUT= INES); + s.num_coroutines =3D cvtnum_full("number of coroutines", optar= g, + false, 1, MAX_COROUTINES); + if (s.num_coroutines < 0) { goto fail_getopt; } break; @@ -2458,7 +2462,7 @@ static int img_convert(const img_cmd_t *ccmd, int arg= c, char **argv) force_share =3D true; break; case 'r': - rate_limit =3D cvtnum("rate limit", optarg); + rate_limit =3D cvtnum("rate limit", optarg, true); if (rate_limit < 0) { goto fail_getopt; } @@ -3377,13 +3381,13 @@ static int img_map(const img_cmd_t *ccmd, int argc,= char **argv) output_format =3D parse_output_format(argv[0], optarg); break; case 's': - start_offset =3D cvtnum("start offset", optarg); + start_offset =3D cvtnum("start offset", optarg, true); if (start_offset < 0) { return 1; } break; case 'l': - max_length =3D cvtnum("max length", optarg); + max_length =3D cvtnum("max length", optarg, true); if (max_length < 0) { return 1; } @@ -4704,9 +4708,9 @@ static int img_bench(const img_cmd_t *ccmd, int argc,= char **argv) int count =3D 75000; int depth =3D 64; int64_t offset =3D 0; - size_t bufsize =3D 4096; + ssize_t bufsize =3D 4096; int pattern =3D 0; - size_t step =3D 0; + ssize_t step =3D 0; int flush_interval =3D 0; bool drain_on_flush =3D true; int64_t image_size; @@ -4788,27 +4792,17 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) ); break; case 'c': - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { - error_report("Invalid request count specified"); + count =3D cvtnum_full("request count", optarg, false, 1, INT_M= AX); + if (count < 0) { return 1; } - count =3D res; break; - } case 'd': - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { - error_report("Invalid queue depth specified"); + depth =3D cvtnum_full("queue depth", optarg, false, 1, INT_MAX= ); + if (depth < 0) { return 1; } - depth =3D res; break; - } case 'f': fmt =3D optarg; break; @@ -4824,41 +4818,26 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) } break; case 'o': - { - offset =3D cvtnum("offset", optarg); + offset =3D cvtnum("offset", optarg, true); if (offset < 0) { return 1; } break; - } - break; case 'q': quiet =3D true; break; case 's': - { - int64_t sval; - - sval =3D cvtnum_full("buffer size", optarg, 0, INT_MAX); - if (sval < 0) { + bufsize =3D cvtnum_full("buffer size", optarg, true, 1, INT_MA= X); + if (bufsize < 0) { return 1; } - - bufsize =3D sval; break; - } case 'S': - { - int64_t sval; - - sval =3D cvtnum_full("step_size", optarg, 0, INT_MAX); - if (sval < 0) { + step =3D cvtnum_full("step size", optarg, true, 0, INT_MAX); + if (step < 0) { return 1; } - - step =3D sval; break; - } case 't': ret =3D bdrv_parse_cache_mode(optarg, &flags, &writethrough); if (ret < 0) { @@ -4875,27 +4854,18 @@ static int img_bench(const img_cmd_t *ccmd, int arg= c, char **argv) force_share =3D true; break; case OPTION_PATTERN: - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > 0xff) { - error_report("Invalid pattern byte specified"); + pattern =3D cvtnum_full("pattern byte", optarg, false, 0, 0xff= ); + if (pattern < 0) { return 1; } - pattern =3D res; break; - } case OPTION_FLUSH_INTERVAL: - { - unsigned long res; - - if (qemu_strtoul(optarg, NULL, 0, &res) < 0 || res > INT_MAX) { - error_report("Invalid flush interval specified"); + flush_interval =3D cvtnum_full("flush interval", optarg, + false, 0, INT_MAX); + if (flush_interval < 0) { return 1; } - flush_interval =3D res; break; - } case OPTION_NO_DRAIN: drain_on_flush =3D false; break; @@ -5090,7 +5060,7 @@ static int img_bitmap(const img_cmd_t *ccmd, int argc= , char **argv) src_fmt =3D optarg; break; case 'g': - granularity =3D cvtnum("granularity", optarg); + granularity =3D cvtnum("granularity", optarg, false); if (granularity < 0) { return 1; } @@ -5278,7 +5248,7 @@ static int img_dd_bs(const char *arg, { int64_t res; =20 - res =3D cvtnum_full("bs", arg, 1, INT_MAX); + res =3D cvtnum_full("bs", arg, true, 1, INT_MAX); =20 if (res < 0) { return 1; @@ -5292,7 +5262,7 @@ static int img_dd_count(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - dd->count =3D cvtnum("count", arg); + dd->count =3D cvtnum("count", arg, false); =20 if (dd->count < 0) { return 1; @@ -5323,7 +5293,7 @@ static int img_dd_skip(const char *arg, struct DdIo *in, struct DdIo *out, struct DdInfo *dd) { - in->offset =3D cvtnum("skip", arg); + in->offset =3D cvtnum("skip", arg, false); =20 if (in->offset < 0) { return 1; @@ -5718,7 +5688,7 @@ static int img_measure(const img_cmd_t *ccmd, int arg= c, char **argv) output_format =3D parse_output_format(argv[0], optarg); break; case 's': - img_size =3D cvtnum("image size", optarg); + img_size =3D cvtnum("image size", optarg, true); if (img_size < 0) { goto out; } --=20 2.39.2