From nobody Tue Nov 26 12:21:49 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 1707328792924325.9607287444825; Wed, 7 Feb 2024 09:59:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmBr-0003Q1-HY; Wed, 07 Feb 2024 12:58: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 1rXmBl-0003OC-JH; Wed, 07 Feb 2024 12:58: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 1rXmBi-0003z7-M0; Wed, 07 Feb 2024 12:58:25 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 977A04B3D0; Wed, 7 Feb 2024 20:59:31 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 90633763A0; Wed, 7 Feb 2024 20:58:19 +0300 (MSK) Received: (nullmailer pid 296918 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 1/8] qemu-img: pass current cmdname into command handlers Date: Wed, 7 Feb 2024 20:58:10 +0300 Message-Id: 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: 1707328793479100004 Content-Type: text/plain; charset="utf-8" In order to be able to give correct --help output, pass current cmdname to command handlers and to common error reporting functions. After the change, in case of command-line error, qemu-img will now print: Try 'qemu-img create --help' for more information. Current cmdname will be useful in --help output as well. Signed-off-by: Michael Tokarev --- qemu-img.c | 150 ++++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index bcbf51402d..a634747701 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 char *cmdname, int argc, char **argv); } img_cmd_t; =20 enum { @@ -101,8 +101,8 @@ static void format_print(void *opaque, const char *name) printf(" %s", name); } =20 -static G_NORETURN G_GNUC_PRINTF(1, 2) -void error_exit(const char *fmt, ...) +static G_NORETURN G_GNUC_PRINTF(2, 3) +void error_exit(const char *cmdname, const char *fmt, ...) { va_list ap; =20 @@ -110,20 +110,20 @@ void error_exit(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); =20 - error_printf("Try 'qemu-img --help' for more information\n"); + error_printf("Try 'qemu-img %s --help' for more information\n", cmdnam= e ? cmdname : ""); exit(EXIT_FAILURE); } =20 static G_NORETURN -void missing_argument(const char *option) +void missing_argument(const char *cmdname, const char *option) { - error_exit("missing argument for option '%s'", option); + error_exit(cmdname, "missing argument for option '%s'", option); } =20 static G_NORETURN -void unrecognized_option(const char *option) +void unrecognized_option(const char *cmdname, const char *option) { - error_exit("unrecognized option '%s'", option); + error_exit(cmdname, "unrecognized option '%s'", option); } =20 /* Please keep in synch with docs/tools/qemu-img.rst */ @@ -508,7 +508,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 char *cmdname, int argc, char **argv) { int c; uint64_t img_size =3D -1; @@ -534,10 +534,10 @@ static int img_create(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -576,7 +576,7 @@ static int img_create(int argc, char **argv) } =20 if (optind >=3D argc) { - error_exit("Expecting image file name"); + error_exit(cmdname, "Expecting image file name"); } optind++; =20 @@ -591,7 +591,7 @@ static int img_create(int argc, char **argv) img_size =3D (uint64_t)sval; } if (optind !=3D argc) { - error_exit("Unexpected argument: %s", argv[optind]); + error_exit(cmdname, "Unexpected argument: %s", argv[optind]); } =20 bdrv_img_create(filename, fmt, base_filename, base_fmt, @@ -716,7 +716,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 char *cmdname, int argc, char **argv) { int c, ret; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -754,10 +754,10 @@ static int img_check(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -773,7 +773,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(cmdname, "Unknown option value for -r " "(expecting 'leaks' or 'all'): %s", optarg); } break; @@ -798,7 +798,7 @@ static int img_check(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -948,7 +948,7 @@ static void run_block_job(BlockJob *job, Error **errp) } } =20 -static int img_commit(int argc, char **argv) +static int img_commit(const char *cmdname, int argc, char **argv) { int c, ret, flags; const char *filename, *fmt, *cache, *base; @@ -979,10 +979,10 @@ static int img_commit(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -1028,7 +1028,7 @@ static int img_commit(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -1355,7 +1355,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 char *cmdname, int argc, char **argv) { const char *fmt1 =3D NULL, *fmt2 =3D NULL, *cache, *filename1, *filena= me2; BlockBackend *blk1, *blk2; @@ -1392,10 +1392,10 @@ static int img_compare(int argc, char **argv) } switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -1449,7 +1449,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(cmdname, "Expecting two image file names"); } filename1 =3D argv[optind++]; filename2 =3D argv[optind++]; @@ -2231,7 +2231,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 char *cmdname, 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", @@ -2284,10 +2284,10 @@ static int img_convert(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -2999,7 +2999,7 @@ err: return NULL; } =20 -static int img_info(int argc, char **argv) +static int img_info(const char *cmdname, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3030,10 +3030,10 @@ static int img_info(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -3059,7 +3059,7 @@ static int img_info(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -3224,7 +3224,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 char *cmdname, int argc, char **argv) { int c; OutputFormat output_format =3D OFORMAT_HUMAN; @@ -3261,10 +3261,10 @@ static int img_map(int argc, char **argv) } switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -3299,7 +3299,7 @@ static int img_map(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } filename =3D argv[optind]; =20 @@ -3373,7 +3373,7 @@ out: #define SNAPSHOT_APPLY 3 #define SNAPSHOT_DELETE 4 =20 -static int img_snapshot(int argc, char **argv) +static int img_snapshot(const char *cmdname, int argc, char **argv) { BlockBackend *blk; BlockDriverState *bs; @@ -3404,10 +3404,10 @@ static int img_snapshot(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -3417,7 +3417,7 @@ static int img_snapshot(int argc, char **argv) break; case 'l': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(cmdname, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_LIST; @@ -3425,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(cmdname, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_APPLY; @@ -3433,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(cmdname, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_CREATE; @@ -3441,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(cmdname, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action =3D SNAPSHOT_DELETE; @@ -3463,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(cmdname, "Expecting one image file name"); } filename =3D argv[optind++]; =20 @@ -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 char *cmdname, 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; @@ -3578,10 +3578,10 @@ static int img_rebase(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -3630,10 +3630,10 @@ static int img_rebase(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } if (!unsafe && !out_baseimg) { - error_exit("Must specify backing file (-b) or use unsafe mode (-u)= "); + error_exit(cmdname, "Must specify backing file (-b) or use unsafe = mode (-u)"); } filename =3D argv[optind++]; =20 @@ -4027,7 +4027,7 @@ out: return 0; } =20 -static int img_resize(int argc, char **argv) +static int img_resize(const char *cmdname, int argc, char **argv) { Error *err =3D NULL; int c, ret, relative; @@ -4057,7 +4057,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(cmdname, "Not enough arguments"); return 1; } =20 @@ -4081,10 +4081,10 @@ static int img_resize(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -4115,7 +4115,7 @@ static int img_resize(int argc, char **argv) } } if (optind !=3D argc - 1) { - error_exit("Expecting image file name and size"); + error_exit(cmdname, "Expecting image file name and size"); } filename =3D argv[optind++]; =20 @@ -4240,7 +4240,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 char *cmdname, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 0; @@ -4273,10 +4273,10 @@ static int img_amend(int argc, char **argv) =20 switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -4312,7 +4312,7 @@ static int img_amend(int argc, char **argv) } =20 if (!options) { - error_exit("Must specify options (-o)"); + error_exit(cmdname, "Must specify options (-o)"); } =20 if (quiet) { @@ -4504,7 +4504,7 @@ static void bench_cb(void *opaque, int ret) } } =20 -static int img_bench(int argc, char **argv) +static int img_bench(const char *cmdname, int argc, char **argv) { int c, ret =3D 0; const char *fmt =3D NULL, *filename; @@ -4547,10 +4547,10 @@ static int img_bench(int argc, char **argv) =20 switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -4674,7 +4674,7 @@ static int img_bench(int argc, char **argv) } =20 if (optind !=3D argc - 1) { - error_exit("Expecting one image file name"); + error_exit(cmdname, "Expecting one image file name"); } filename =3D argv[argc - 1]; =20 @@ -4774,7 +4774,7 @@ typedef struct ImgBitmapAction { QSIMPLEQ_ENTRY(ImgBitmapAction) next; } ImgBitmapAction; =20 -static int img_bitmap(int argc, char **argv) +static int img_bitmap(const char *cmdname, int argc, char **argv) { Error *err =3D NULL; int c, ret =3D 1; @@ -4816,10 +4816,10 @@ static int img_bitmap(int argc, char **argv) =20 switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -5074,7 +5074,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 char *cmdname, int argc, char **argv) { int ret =3D 0; char *arg =3D NULL; @@ -5136,10 +5136,10 @@ static int img_dd(int argc, char **argv) fmt =3D optarg; break; case ':': - missing_argument(argv[optind - 1]); + missing_argument(cmdname, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': help(); @@ -5342,7 +5342,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 char *cmdname, int argc, char **argv) { static const struct option long_options[] =3D { {"help", no_argument, 0, 'h'}, @@ -5570,7 +5570,7 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); bdrv_init(); if (argc < 2) { - error_exit("Not enough arguments"); + error_exit(NULL, "Not enough arguments"); } =20 qemu_add_opts(&qemu_source_opts); @@ -5579,10 +5579,10 @@ int main(int argc, char **argv) while ((c =3D getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != =3D -1) { switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(NULL, argv[optind - 1]); return 0; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(NULL, argv[optind - 1]); return 0; case 'h': help(); @@ -5615,10 +5615,10 @@ int main(int argc, char **argv) /* find the command */ for (cmd =3D img_cmds; cmd->name !=3D NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { - return cmd->handler(argc, argv); + return cmd->handler(cmdname, argc, argv); } } =20 /* not found */ - error_exit("Command not found: %s", cmdname); + error_exit(NULL, "Command not found: %s", cmdname); } --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 170732879282691.49883083299437; Wed, 7 Feb 2024 09:59:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmBs-0003VD-3P; Wed, 07 Feb 2024 12:58:33 -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 1rXmBm-0003P2-AV; Wed, 07 Feb 2024 12:58:26 -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 1rXmBk-0003zf-Nm; Wed, 07 Feb 2024 12:58:26 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 5E52E4B3D1; Wed, 7 Feb 2024 20:59:32 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 8D9DA763A1; Wed, 7 Feb 2024 20:58:20 +0300 (MSK) Received: (nullmailer pid 296922 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 2/8] qemu-img: refresh options/--help for "create" subcommand Date: Wed, 7 Feb 2024 20:58:11 +0300 Message-Id: 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: 1707328793434100001 Content-Type: text/plain; charset="utf-8" Add missing long options (eg --format). Create helper function cmd_help() to display command-specific help text, and use it to print --help for create. Signed-off-by: Michael Tokarev --- qemu-img.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index a634747701..b94622fadb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -126,6 +126,16 @@ void unrecognized_option(const char *cmdname, const ch= ar *option) error_exit(cmdname, "unrecognized option '%s'", option); } =20 +static G_NORETURN +void cmd_help(const char *cmdname, const char *syntax, + const char *description, const char *arguments) +{ + printf("qemu-img %s %s\n%s.\n" + " -h|--help - print this help and exit\n%s", + cmdname, syntax, description, arguments); + exit(EXIT_SUCCESS); +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -524,7 +534,13 @@ static int img_create(const char *cmdname, int argc, c= har **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", @@ -540,7 +556,22 @@ static int img_create(const char *cmdname, int argc, c= har **argv) unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': - help(); + cmd_help(cmdname, "[OPTIONS] FILE [SIZE[bkKMGTPE]]", + "Creates and initializes a new image", +" -q|--quiet - quiet operations\n" +" -f|--format FMT - specifies format of the new image, default is raw\n" +" -o|--options FMT_OPTS - format-specific options ('-o list' for list)\n" +" -b|--backing BACKING_IMG - stack new image on top of BACKING_IMG\n" +" (for formats which support stacking)\n" +" -F|--backing-format BACKING_FMT - specify format of BACKING_IMG\n" +" -u|--backing-unsafe - do not fail if BACKING_FMT can not be read\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILE - image file to create. FILE will be overriden if exists\n" +" SIZE - image size with optional suffix: 'b' (byte, default),\n" +" 'k' or 'K' (kilobyte, *1024), 'M' (megabyte, *1024K), 'G' (gigabyte, *1= 024M),\n" +" 'T' (terabyte, *1024G), 'P' (petabyte, *1024T), or 'E' (exabyte, *1024P= )\n" +" SIZE is required unless BACKING_IMG is specified, in which case\n" +" it will be the same as size of BACKING_IMG\n"); break; case 'F': base_fmt =3D optarg; --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328804451425.49069609426874; Wed, 7 Feb 2024 10:00:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmC8-0003cX-49; Wed, 07 Feb 2024 12:58:48 -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 1rXmBq-0003Rq-FG; Wed, 07 Feb 2024 12:58:31 -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 1rXmBn-000402-Gf; Wed, 07 Feb 2024 12:58:29 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 433104B3D2; Wed, 7 Feb 2024 20:59:33 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3FC36763A2; Wed, 7 Feb 2024 20:58:21 +0300 (MSK) Received: (nullmailer pid 296925 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 3/8] qemu-img: factor out parse_output_format() and use it in the code Date: Wed, 7 Feb 2024 20:58:12 +0300 Message-Id: <0ac80579cb2fb3138beaf88fb3261e05a6b81800.1707328606.git.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: 1707328805491100002 Content-Type: text/plain; charset="utf-8" Use common code and simplify error message Signed-off-by: Michael Tokarev --- qemu-img.c | 63 ++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index b94622fadb..f851b290cc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -136,6 +136,17 @@ void cmd_help(const char *cmdname, const char *syntax, exit(EXIT_SUCCESS); } =20 +static OutputFormat parse_output_format(const char *cmdname, const char *a= rg) +{ + if (!strcmp(arg, "json")) { + return OFORMAT_JSON; + } else if (!strcmp(arg, "human")) { + return OFORMAT_HUMAN; + } else { + error_exit(cmdname, "--output expects 'human' or 'json' not '%s'",= arg); + } +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -751,7 +762,7 @@ static int img_check(const char *cmdname, int argc, cha= r **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; @@ -763,7 +774,6 @@ static int img_check(const char *cmdname, int argc, cha= r **argv) bool force_share =3D false; =20 fmt =3D NULL; - output =3D NULL; cache =3D BDRV_DEFAULT_CACHE; =20 for(;;) { @@ -809,7 +819,7 @@ static int img_check(const char *cmdname, int argc, cha= r **argv) } break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(cmdname, optarg); break; case 'T': cache =3D optarg; @@ -833,15 +843,6 @@ static int img_check(const char *cmdname, int argc, ch= ar **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); @@ -3035,13 +3036,12 @@ static int img_info(const char *cmdname, 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 { @@ -3076,7 +3076,7 @@ static int img_info(const char *cmdname, int argc, ch= ar **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(cmdname, optarg); break; case OPTION_BACKING_CHAIN: chain =3D true; @@ -3094,15 +3094,6 @@ static int img_info(const char *cmdname, int argc, c= har **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) { @@ -3261,7 +3252,7 @@ static int img_map(const char *cmdname, int argc, cha= r **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; @@ -3271,7 +3262,6 @@ static int img_map(const char *cmdname, int argc, cha= r **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 { @@ -3307,7 +3297,7 @@ static int img_map(const char *cmdname, int argc, cha= r **argv) force_share =3D true; break; case OPTION_OUTPUT: - output =3D optarg; + output_format =3D parse_output_format(cmdname, optarg); break; case 's': start_offset =3D cvtnum("start offset", optarg); @@ -3334,15 +3324,6 @@ static int img_map(const char *cmdname, int argc, ch= ar **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; @@ -5445,15 +5426,7 @@ static int img_measure(const char *cmdname, int argc= , 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(cmdname, optarg); break; case OPTION_SIZE: { --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328792738201.70425891370712; Wed, 7 Feb 2024 09:59:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmC4-0003bm-6t; Wed, 07 Feb 2024 12:58:44 -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 1rXmBq-0003Rr-F2; Wed, 07 Feb 2024 12:58:31 -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 1rXmBn-00040C-MG; Wed, 07 Feb 2024 12:58:28 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 2D9474B3D3; Wed, 7 Feb 2024 20:59:34 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3E98B763A3; Wed, 7 Feb 2024 20:58:22 +0300 (MSK) Received: (nullmailer pid 296928 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 4/8] qemu-img: refresh options/--help for "check" command Date: Wed, 7 Feb 2024 20:58:13 +0300 Message-Id: <0087ee8eaeedc608b44411732354bc980962f530.1707328606.git.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: 1707328793438100002 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index f851b290cc..e7d5b1b24b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -780,7 +780,9 @@ static int img_check(const char *cmdname, int argc, cha= r **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}, @@ -801,7 +803,20 @@ static int img_check(const char *cmdname, int argc, ch= ar **argv) unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': - help(); + cmd_help(cmdname, "[OPTIONS] FILENAME", + "Checks image file validity", +" -q|--quiet - quiet operations\n" +" -f|--format FMT - specifies format of the image explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification= \n" +" instead of a file name (incompatible with --format)\n" +" -T|--cache CACHE_MODE - cache mode when opening image (" BDRV_DEFAULT_CA= CHE ")\n" +" -U|--force-share - open image in shared mode for concurrent access\n" +" --output human|json - output format\n" +" -r|--repair leaks|all - repair particular aspect of the image\n" +" (image will be open in read-write mode, incompatible with --force-share= )\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - the image file (or image specification) to operate on\n" +); break; case 'f': fmt =3D optarg; --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328743945338.7280330965224; Wed, 7 Feb 2024 09:59:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmC9-0003iS-4G; Wed, 07 Feb 2024 12:58:49 -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 1rXmBt-0003WF-Ds; Wed, 07 Feb 2024 12:58:33 -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 1rXmBr-00041j-Vh; Wed, 07 Feb 2024 12:58:33 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id C75724B3D4; Wed, 7 Feb 2024 20:59:34 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 02734763A4; Wed, 7 Feb 2024 20:58:22 +0300 (MSK) Received: (nullmailer pid 296931 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 5/8] qemu-img: simplify --repair error message Date: Wed, 7 Feb 2024 20:58:14 +0300 Message-Id: <30941c389c32d0432d6d065c146a02b02189c55a.1707328606.git.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: 1707328745265100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Tokarev --- qemu-img.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e7d5b1b24b..31c1891b43 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -829,8 +829,8 @@ static int img_check(const char *cmdname, int argc, cha= r **argv) } else if (!strcmp(optarg, "all")) { fix =3D BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit(cmdname, "Unknown option value for -r " - "(expecting 'leaks' or 'all'): %s", optarg); + error_exit(cmdname, + "--repair expects 'leaks' or 'all' not '%s'", o= ptarg); } break; case OPTION_OUTPUT: --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328753015188.9081341907911; Wed, 7 Feb 2024 09:59:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmC9-0003iR-4e; Wed, 07 Feb 2024 12:58: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 1rXmBu-0003WY-3x; Wed, 07 Feb 2024 12:58:35 -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 1rXmBr-00041k-Vg; Wed, 07 Feb 2024 12:58:33 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 7FF2A4B3D5; Wed, 7 Feb 2024 20:59:35 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id A8540763A5; Wed, 7 Feb 2024 20:58:23 +0300 (MSK) Received: (nullmailer pid 296934 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 6/8] qemu-img: refresh options/--help for "commit" command Date: Wed, 7 Feb 2024 20:58:15 +0300 Message-Id: <76c05bdf1bd337f75b11ea4e33d201a29aa57ecd.1707328606.git.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: 1707328755249100003 Content-Type: text/plain; charset="utf-8" Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 31c1891b43..7ff63aeea2 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1015,8 +1015,15 @@ static int img_commit(const char *cmdname, 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}, + {"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:", @@ -1032,7 +1039,20 @@ static int img_commit(const char *cmdname, int argc,= char **argv) unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': - help(); + cmd_help(cmdname, "[OPTIONS] FILENAME", + "Commit changes recorded in FILENAME to its base imag= e", +" -q|--quiet - quiet operations\n" +" -f|--format FMT - specify FILENAME image format explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification= \n" +" instead of a file name (incompatible with --format)\n" +" -t|--cache CACHE_MODE cache mode when opening image (" BDRV_DEFAULT_CACH= E ")\n" +" -d|--drop - skip emptying FILENAME on completion\n" +" -b|--base BASE_IMG - image in the backing chain to which to commit\n" +" changes instead of the previous one (implies --drop)\n" +" -p|--progress - show operation progress\n" +" -r|--rate RATE - I/O rate limit\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - name of the image file to operate on\n"); break; case 'f': fmt =3D optarg; --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328792594972.7747714483717; Wed, 7 Feb 2024 09:59:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmCY-0004FT-3B; Wed, 07 Feb 2024 12:59:14 -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 1rXmBx-0003ZB-Lh; Wed, 07 Feb 2024 12:58: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 1rXmBv-000446-EO; Wed, 07 Feb 2024 12:58:36 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3BAE84B3D6; Wed, 7 Feb 2024 20:59:36 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 58AFB763A6; Wed, 7 Feb 2024 20:58:24 +0300 (MSK) Received: (nullmailer pid 296937 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 7/8] qemu-img: refresh options/--help for "compare" command Date: Wed, 7 Feb 2024 20:58:16 +0300 Message-Id: <26f7115bd518de2b85955520ff714035ba21aee1.1707328606.git.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: 1707328793438100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Tokarev --- qemu-img.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 7ff63aeea2..ea3fe95169 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1447,9 +1447,15 @@ static int img_compare(const char *cmdname, 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}, + {"cache", required_argument, 0, 'T'}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"format", required_argument, 0, 'f'}, + {"format2?", 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", @@ -1465,7 +1471,18 @@ static int img_compare(const char *cmdname, int argc= , char **argv) unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': - help(); + cmd_help(cmdname, "[OPTIONS] FILENAME1 FILENAME2", + "Check if two images have the same content", +" -q|--quiet - quiet operation\n" +" -T|--cache - CACHE_MODE cache mode when opening images (" BDRV_DEFAULT_C= ACHE ")\n" +" instead of file names (incompatible with --format)\n" +" -f|--format FMT - specify FILENAME1 image format explicitly\n" +" -F|--format2? FMT - specify FILENAME2 image format explicitly\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +" -s|--strict - strict mode, also check if sizes are equal\n" +" -p|--progress - show operation progress\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME1, FILENAME2 - image files to compare\n"); break; case 'f': fmt1 =3D optarg; --=20 2.39.2 From nobody Tue Nov 26 12:21:49 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 1707328804856746.1434585851179; Wed, 7 Feb 2024 10:00:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXmCZ-0004X8-Gc; Wed, 07 Feb 2024 12:59: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 1rXmBx-0003ZC-NN; Wed, 07 Feb 2024 12:58: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 1rXmBw-00044F-5d; Wed, 07 Feb 2024 12:58:37 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 322EF4B3D7; Wed, 7 Feb 2024 20:59:37 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 249A8763A7; Wed, 7 Feb 2024 20:58:25 +0300 (MSK) Received: (nullmailer pid 296940 invoked by uid 1000); Wed, 07 Feb 2024 17:58:19 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 8/8] qemu-img: refresh options/--help for "convert" command Date: Wed, 7 Feb 2024 20:58:17 +0300 Message-Id: <5692d04003f710ca003b492c167bee683033e280.1707328606.git.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: 1707328805474100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michael Tokarev --- qemu-img.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index ea3fe95169..c8fba27e35 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2351,14 +2351,28 @@ static int img_convert(const char *cmdname, int arg= c, 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-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:", @@ -2374,7 +2388,37 @@ static int img_convert(const char *cmdname, int argc= , char **argv) unrecognized_option(cmdname, argv[optind - 1]); break; case 'h': - help(); + cmd_help(cmdname, "[OPTIONS] FILENAME [FILENAME2 [...]] OUTPUT= _FILENAME", + "Convert image FILENAME (or a snapshot) to new image = OUTPUT_FILENAME", +" -q|--quiet - quiet operations\n" +" -f|--source-format SFMT - specify FILENAME source image format explicitl= y\n" +" --image-opts - indicates that FILENAME is a complete image specification= \n" +" instead of a file name (incompatible with --source-format)\n" +" -T|--source-cache CACHE_MODE - cache mode when opening source image (" B= DRV_DEFAULT_CACHE ")\n" +" -O|--output-format OFMT - specify OUTPUT_FILENAME image format (default = is raw)\n" +" --target-image-opts - indicates that OUTPUT_FILENAME is a complete image= specification\n" +" instead of a file name (incompatible with --output-format)\n" +" -o|--options OPTS - OFMT-specific options\n" +" -c|--compress - create compressed output image (qcow and qcow2 format on= ly)\n" +" -t|--output-cache CACHE_MODE - cache mode when opening output image (" B= DRV_DEFAULT_CACHE ")\n" +" -B|--backing BACKING_FILENAME - create output to be a CoW on top of BACK= ING_FILENAME\n" +" -F|--backing-format BFMT - specify BACKING_FILENAME image format explici= tly\n" +" --target-is-zero\n" +" -l|--snapshot SNAPSHOT_PARAMS\n" +" -S|--sparse-size SPARSE_SIZE\n" +" --bitmaps - also copy any persistent bitmaps present in source\n" +" --skip-broken-bitmaps - skip (do not error out) any broken bitmaps\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +" -p|--progress - show operation progress\n" +" -r|--rate RATE\n" +" -m|--parallel NUM_COROUTINES - specify parallelism (default 8)\n" +" -C|--copy-range-offloading - use copy_range offloading\n" +" --salvage\n" +" -W - enable out-of-order writes to improve performance\n" +" -n|--no-create - omit target volume creation (eg on rbd)\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - source image file name\n" +" OUTPUT_FILENAME - destination (output) image file name\n"); break; case 'f': fmt =3D optarg; --=20 2.39.2