From patchwork Fri Feb 9 21:22:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0881C48297 for ; Fri, 9 Feb 2024 21:26:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKl-0006bg-2m; Fri, 09 Feb 2024 16:22: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 1rYYKj-0006ap-AX; Fri, 09 Feb 2024 16:22: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 1rYYKg-00005r-PR; Fri, 09 Feb 2024 16:22:53 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 5A69C4BF59; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 4605577ED3; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123142 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 01/23] qemu-img: pass current cmd info into command handlers Date: Sat, 10 Feb 2024 00:22:22 +0300 Message-Id: <8127d97c2403720d23d241f5bffa8de8ebc3e04d.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In order to be able to give correct --help output, pass current cmd information (img_cmd_t structure) 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 cmd info will be useful in --help output as well. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrangé --- qemu-img.c | 150 ++++++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7668f86769..05f80b6e5b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -60,7 +60,7 @@ 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; enum { @@ -101,8 +101,8 @@ static void format_print(void *opaque, const char *name) printf(" %s", name); } -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 img_cmd_t *ccmd, const char *fmt, ...) { va_list ap; @@ -110,20 +110,20 @@ void error_exit(const char *fmt, ...) error_vreport(fmt, ap); va_end(ap); - error_printf("Try 'qemu-img --help' for more information\n"); + error_printf("Try 'qemu-img %s --help' for more information\n", ccmd ? ccmd->name : ""); exit(EXIT_FAILURE); } static G_NORETURN -void missing_argument(const char *option) +void missing_argument(const img_cmd_t *ccmd, const char *option) { - error_exit("missing argument for option '%s'", option); + error_exit(ccmd, "missing argument for option '%s'", option); } static G_NORETURN -void unrecognized_option(const char *option) +void unrecognized_option(const img_cmd_t *ccmd, const char *option) { - error_exit("unrecognized option '%s'", option); + error_exit(ccmd, "unrecognized option '%s'", option); } /* Please keep in synch with docs/tools/qemu-img.rst */ @@ -508,7 +508,7 @@ static int64_t cvtnum(const char *name, const char *value) return cvtnum_full(name, value, 0, INT64_MAX); } -static int img_create(int argc, char **argv) +static int img_create(const img_cmd_t *ccmd, int argc, char **argv) { int c; uint64_t img_size = -1; @@ -534,10 +534,10 @@ static int img_create(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -576,7 +576,7 @@ static int img_create(int argc, char **argv) } if (optind >= argc) { - error_exit("Expecting image file name"); + error_exit(ccmd, "Expecting image file name"); } optind++; @@ -591,7 +591,7 @@ static int img_create(int argc, char **argv) img_size = (uint64_t)sval; } if (optind != argc) { - error_exit("Unexpected argument: %s", argv[optind]); + error_exit(ccmd, "Unexpected argument: %s", argv[optind]); } 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 img_cmd_t *ccmd, int argc, char **argv) { int c, ret; OutputFormat output_format = OFORMAT_HUMAN; @@ -754,10 +754,10 @@ static int img_check(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, 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 = BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit("Unknown option value for -r " + error_exit(ccmd, "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 != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[optind++]; @@ -948,7 +948,7 @@ static void run_block_job(BlockJob *job, Error **errp) } } -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; @@ -979,10 +979,10 @@ static int img_commit(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -1028,7 +1028,7 @@ static int img_commit(int argc, char **argv) } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[optind++]; @@ -1355,7 +1355,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_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 = NULL, *fmt2 = NULL, *cache, *filename1, *filename2; 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(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -1449,7 +1449,7 @@ static int img_compare(int argc, char **argv) if (optind != argc - 2) { - error_exit("Expecting two image file names"); + error_exit(ccmd, "Expecting two image file names"); } filename1 = argv[optind++]; filename2 = argv[optind++]; @@ -2231,7 +2231,7 @@ static void set_rate_limit(BlockBackend *blk, int64_t rate_limit) blk_set_io_limits(blk, &cfg); } -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 = BDRV_O_NO_SHARE; const char *fmt = NULL, *out_fmt = NULL, *cache = "unsafe", @@ -2284,10 +2284,10 @@ static int img_convert(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -2999,7 +2999,7 @@ err: return NULL; } -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 = OFORMAT_HUMAN; @@ -3030,10 +3030,10 @@ static int img_info(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -3059,7 +3059,7 @@ static int img_info(int argc, char **argv) } } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[optind++]; @@ -3224,7 +3224,7 @@ static inline bool entry_mergeable(const MapEntry *curr, const MapEntry *next) return true; } -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 = OFORMAT_HUMAN; @@ -3261,10 +3261,10 @@ static int img_map(int argc, char **argv) } switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -3299,7 +3299,7 @@ static int img_map(int argc, char **argv) } } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[optind]; @@ -3373,7 +3373,7 @@ out: #define SNAPSHOT_APPLY 3 #define SNAPSHOT_DELETE 4 -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; @@ -3404,17 +3404,17 @@ static int img_snapshot(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); return 0; case 'l': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(ccmd, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action = SNAPSHOT_LIST; @@ -3422,7 +3422,7 @@ static int img_snapshot(int argc, char **argv) break; case 'a': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(ccmd, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action = SNAPSHOT_APPLY; @@ -3430,7 +3430,7 @@ static int img_snapshot(int argc, char **argv) break; case 'c': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(ccmd, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action = SNAPSHOT_CREATE; @@ -3438,7 +3438,7 @@ static int img_snapshot(int argc, char **argv) break; case 'd': if (action) { - error_exit("Cannot mix '-l', '-a', '-c', '-d'"); + error_exit(ccmd, "Cannot mix '-l', '-a', '-c', '-d'"); return 0; } action = SNAPSHOT_DELETE; @@ -3460,7 +3460,7 @@ static int img_snapshot(int argc, char **argv) } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[optind++]; @@ -3531,7 +3531,7 @@ static int img_snapshot(int argc, char **argv) return 0; } -static int img_rebase(int argc, char **argv) +static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv) { BlockBackend *blk = NULL, *blk_old_backing = NULL, *blk_new_backing = NULL; uint8_t *buf_old = NULL; @@ -3575,10 +3575,10 @@ static int img_rebase(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -3627,10 +3627,10 @@ static int img_rebase(int argc, char **argv) } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } if (!unsafe && !out_baseimg) { - error_exit("Must specify backing file (-b) or use unsafe mode (-u)"); + error_exit(ccmd, "Must specify backing file (-b) or use unsafe mode (-u)"); } filename = argv[optind++]; @@ -4024,7 +4024,7 @@ out: return 0; } -static int img_resize(int argc, char **argv) +static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) { Error *err = NULL; int c, ret, relative; @@ -4054,7 +4054,7 @@ static int img_resize(int argc, char **argv) /* Remove size from argv manually so that negative numbers are not treated * as options by getopt. */ if (argc < 3) { - error_exit("Not enough arguments"); + error_exit(ccmd, "Not enough arguments"); return 1; } @@ -4078,10 +4078,10 @@ static int img_resize(int argc, char **argv) } switch(c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -4112,7 +4112,7 @@ static int img_resize(int argc, char **argv) } } if (optind != argc - 1) { - error_exit("Expecting image file name and size"); + error_exit(ccmd, "Expecting image file name and size"); } filename = argv[optind++]; @@ -4237,7 +4237,7 @@ static int print_amend_option_help(const char *format) return 0; } -static int img_amend(int argc, char **argv) +static int img_amend(const img_cmd_t *ccmd, int argc, char **argv) { Error *err = NULL; int c, ret = 0; @@ -4270,10 +4270,10 @@ static int img_amend(int argc, char **argv) switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -4309,7 +4309,7 @@ static int img_amend(int argc, char **argv) } if (!options) { - error_exit("Must specify options (-o)"); + error_exit(ccmd, "Must specify options (-o)"); } if (quiet) { @@ -4501,7 +4501,7 @@ static void bench_cb(void *opaque, int ret) } } -static int img_bench(int argc, char **argv) +static int img_bench(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret = 0; const char *fmt = NULL, *filename; @@ -4544,10 +4544,10 @@ static int img_bench(int argc, char **argv) switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -4671,7 +4671,7 @@ static int img_bench(int argc, char **argv) } if (optind != argc - 1) { - error_exit("Expecting one image file name"); + error_exit(ccmd, "Expecting one image file name"); } filename = argv[argc - 1]; @@ -4771,7 +4771,7 @@ typedef struct ImgBitmapAction { QSIMPLEQ_ENTRY(ImgBitmapAction) next; } ImgBitmapAction; -static int img_bitmap(int argc, char **argv) +static int img_bitmap(const img_cmd_t *ccmd, int argc, char **argv) { Error *err = NULL; int c, ret = 1; @@ -4813,10 +4813,10 @@ static int img_bitmap(int argc, char **argv) switch (c) { case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -5071,7 +5071,7 @@ static int img_dd_skip(const char *arg, return 0; } -static int img_dd(int argc, char **argv) +static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) { int ret = 0; char *arg = NULL; @@ -5133,10 +5133,10 @@ static int img_dd(int argc, char **argv) fmt = optarg; break; case ':': - missing_argument(argv[optind - 1]); + missing_argument(ccmd, argv[optind - 1]); break; case '?': - unrecognized_option(argv[optind - 1]); + unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': help(); @@ -5339,7 +5339,7 @@ static void dump_json_block_measure_info(BlockMeasureInfo *info) g_string_free(str, true); } -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[] = { {"help", no_argument, 0, 'h'}, @@ -5567,7 +5567,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"); } qemu_add_opts(&qemu_source_opts); @@ -5576,10 +5576,10 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, "+:hVT:", long_options, NULL)) != -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(); @@ -5612,10 +5612,10 @@ int main(int argc, char **argv) /* find the command */ for (cmd = img_cmds; cmd->name != NULL; cmd++) { if (!strcmp(cmdname, cmd->name)) { - return cmd->handler(argc, argv); + return cmd->handler(cmd, argc, argv); } } /* not found */ - error_exit("Command not found: %s", cmdname); + error_exit(NULL, "Command not found: %s", cmdname); } From patchwork Fri Feb 9 21:22:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6BB7CC48297 for ; Fri, 9 Feb 2024 21:23:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKn-0006cW-8H; Fri, 09 Feb 2024 16:22: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 1rYYKl-0006cJ-K8; Fri, 09 Feb 2024 16:22: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 1rYYKk-00006Y-07; Fri, 09 Feb 2024 16:22:55 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 676644BF5A; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 549BB77ED4; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123145 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand Date: Sat, 10 Feb 2024 00:22:23 +0300 Message-Id: <43c69e56b65b39da7c9bd878fd9c6fad4f788c1a.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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' subcommand. Signed-off-by: Michael Tokarev --- qemu-img.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 05f80b6e5b..7edfc56572 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -126,6 +126,25 @@ void unrecognized_option(const img_cmd_t *ccmd, const char *option) error_exit(ccmd, "unrecognized option '%s'", option); } +/* + * 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 starting with \t + * desrciption is indented by one char + */ +static G_NORETURN +void cmd_help(const img_cmd_t *ccmd, + const char *syntax, const char *arguments) +{ + printf("qemu-img %s %s" + "Arguments:\n" + " -h|--help - print this help and exit\n" + "%s", + ccmd->name, syntax, arguments); + exit(EXIT_SUCCESS); +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -524,7 +543,13 @@ static int img_create(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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 = getopt_long(argc, argv, ":F:b:f:ho:qu", @@ -540,7 +565,25 @@ static int img_create(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - 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_FILENAME - stack new image on top of BACKING_FILENAME\n" +" (for formats which support stacking)\n" +" -F|--backing-format BACKING_FMT - specify format of BACKING_FILENAME\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" +" FILENAME - image file to create. It will be overriden if exists\n" +" SIZE - image size with optional suffix: 'b' (byte, default), 'k' or\n" +" 'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),\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 = optarg; From patchwork Fri Feb 9 21:22:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D47BC4829B for ; Fri, 9 Feb 2024 21:26:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKq-0006eF-3j; Fri, 09 Feb 2024 16:23: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 1rYYKn-0006cn-AR; Fri, 09 Feb 2024 16:22: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 1rYYKl-00006j-I1; Fri, 09 Feb 2024 16:22:57 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 760F94BF5B; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 61B0977ED5; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123148 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 03/23] qemu-img: factor out parse_output_format() and use it in the code Date: Sat, 10 Feb 2024 00:22:24 +0300 Message-Id: <9e3bda580761ee2d7ef0f67b2378f460cba3dff5.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Use common code and simplify error message Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrangé --- qemu-img.c | 63 ++++++++++++++++-------------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7edfc56572..4e962843da 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -145,6 +145,17 @@ void cmd_help(const img_cmd_t *ccmd, exit(EXIT_SUCCESS); } +static OutputFormat parse_output_format(const img_cmd_t *ccmd, const char *arg) +{ + if (!strcmp(arg, "json")) { + return OFORMAT_JSON; + } else if (!strcmp(arg, "human")) { + return OFORMAT_HUMAN; + } else { + error_exit(ccmd, "--output expects 'human' or 'json' not '%s'", arg); + } +} + /* Please keep in synch with docs/tools/qemu-img.rst */ static G_NORETURN void help(void) @@ -763,7 +774,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) { int c, ret; OutputFormat output_format = OFORMAT_HUMAN; - const char *filename, *fmt, *output, *cache; + const char *filename, *fmt, *cache; BlockBackend *blk; BlockDriverState *bs; int fix = 0; @@ -775,7 +786,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) bool force_share = false; fmt = NULL; - output = NULL; cache = BDRV_DEFAULT_CACHE; for(;;) { @@ -821,7 +831,7 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) } break; case OPTION_OUTPUT: - output = optarg; + output_format = parse_output_format(ccmd, optarg); break; case 'T': cache = optarg; @@ -845,15 +855,6 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) } filename = argv[optind++]; - if (output && !strcmp(output, "json")) { - output_format = OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format = OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument."); - return 1; - } - ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); @@ -3047,13 +3048,12 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) int c; OutputFormat output_format = OFORMAT_HUMAN; bool chain = false; - const char *filename, *fmt, *output; + const char *filename, *fmt; BlockGraphInfoList *list; bool image_opts = false; bool force_share = false; fmt = NULL; - output = NULL; for(;;) { int option_index = 0; static const struct option long_options[] = { @@ -3088,7 +3088,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) force_share = true; break; case OPTION_OUTPUT: - output = optarg; + output_format = parse_output_format(ccmd, optarg); break; case OPTION_BACKING_CHAIN: chain = true; @@ -3106,15 +3106,6 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) } filename = argv[optind++]; - if (output && !strcmp(output, "json")) { - output_format = OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format = OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument."); - return 1; - } - list = collect_image_info_list(image_opts, filename, fmt, chain, force_share); if (!list) { @@ -3273,7 +3264,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, char **argv) OutputFormat output_format = OFORMAT_HUMAN; BlockBackend *blk; BlockDriverState *bs; - const char *filename, *fmt, *output; + const char *filename, *fmt; int64_t length; MapEntry curr = { .length = 0 }, next; int ret = 0; @@ -3283,7 +3274,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, char **argv) int64_t max_length = -1; fmt = NULL; - output = NULL; for (;;) { int option_index = 0; static const struct option long_options[] = { @@ -3319,7 +3309,7 @@ static int img_map(const img_cmd_t *ccmd, int argc, char **argv) force_share = true; break; case OPTION_OUTPUT: - output = optarg; + output_format = parse_output_format(ccmd, optarg); break; case 's': start_offset = cvtnum("start offset", optarg); @@ -3346,15 +3336,6 @@ static int img_map(const img_cmd_t *ccmd, int argc, char **argv) } filename = argv[optind]; - if (output && !strcmp(output, "json")) { - output_format = OFORMAT_JSON; - } else if (output && !strcmp(output, "human")) { - output_format = OFORMAT_HUMAN; - } else if (output) { - error_report("--output must be used with human or json as argument."); - return 1; - } - blk = img_open(image_opts, filename, fmt, 0, false, false, force_share); if (!blk) { return 1; @@ -5454,15 +5435,7 @@ static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) image_opts = true; break; case OPTION_OUTPUT: - if (!strcmp(optarg, "json")) { - output_format = OFORMAT_JSON; - } else if (!strcmp(optarg, "human")) { - output_format = OFORMAT_HUMAN; - } else { - error_report("--output must be used with human or json " - "as argument."); - goto out; - } + output_format = parse_output_format(ccmd, optarg); break; case OPTION_SIZE: { From patchwork Fri Feb 9 21:22:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E21B0C4828F for ; Fri, 9 Feb 2024 21:26:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKq-0006eI-BU; Fri, 09 Feb 2024 16:23: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 1rYYKo-0006dE-DF; Fri, 09 Feb 2024 16:22:58 -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 1rYYKn-000079-0I; Fri, 09 Feb 2024 16:22:58 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 8346B4BF5C; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 703C477ED6; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123151 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 04/23] qemu-img: refresh options/--help for "check" command Date: Sat, 10 Feb 2024 00:22:25 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. 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 4e962843da..3ae07bfae0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -792,7 +792,9 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) int option_index = 0; static const struct option long_options[] = { {"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}, @@ -813,7 +815,22 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - 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_CACHE ")\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 = optarg; From patchwork Fri Feb 9 21:22:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D7A7C4829B for ; Fri, 9 Feb 2024 21:24:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKr-0006f5-W6; Fri, 09 Feb 2024 16:23:02 -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 1rYYKq-0006eH-50; Fri, 09 Feb 2024 16:23:00 -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 1rYYKo-00007U-Mj; Fri, 09 Feb 2024 16:22:59 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 90C794BF5D; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 7DADF77ED7; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123154 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 05/23] qemu-img: simplify --repair error message Date: Sat, 10 Feb 2024 00:22:26 +0300 Message-Id: <33b6a64202469681f7b27892f2c1c5fe4884a60e.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 3ae07bfae0..ad7fa033b1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -843,8 +843,8 @@ static int img_check(const img_cmd_t *ccmd, int argc, char **argv) } else if (!strcmp(optarg, "all")) { fix = BDRV_FIX_LEAKS | BDRV_FIX_ERRORS; } else { - error_exit(ccmd, "Unknown option value for -r " - "(expecting 'leaks' or 'all'): %s", optarg); + error_exit(ccmd, + "--repair expects 'leaks' or 'all' not '%s'", optarg); } break; case OPTION_OUTPUT: From patchwork Fri Feb 9 21:22:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DB8CC4829E for ; Fri, 9 Feb 2024 21:23:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKt-0006go-T7; Fri, 09 Feb 2024 16:23:04 -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 1rYYKr-0006f3-9x; Fri, 09 Feb 2024 16:23:01 -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 1rYYKp-00007h-TZ; Fri, 09 Feb 2024 16:23:01 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 9E92E4BF5E; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 8B61877ED8; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123157 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 06/23] qemu-img: refresh options/--help for "commit" command Date: Sat, 10 Feb 2024 00:22:27 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index ad7fa033b1..eabf45c423 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1029,8 +1029,15 @@ static int img_commit(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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 = getopt_long(argc, argv, ":f:ht:b:dpqr:", @@ -1046,7 +1053,23 @@ static int img_commit(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operations\n" +" -p|--progress - show operation progress\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_CACHE ")\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" +" -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 = optarg; From patchwork Fri Feb 9 21:22:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C59DCC48297 for ; Fri, 9 Feb 2024 21:26:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKv-0006hm-7v; Fri, 09 Feb 2024 16:23:05 -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 1rYYKs-0006g7-Uv; Fri, 09 Feb 2024 16:23:02 -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 1rYYKr-00008K-GN; Fri, 09 Feb 2024 16:23:02 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id AC4C14BF5F; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 98B6777ED9; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123160 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 07/23] qemu-img: refresh options/--help for "compare" command Date: Sat, 10 Feb 2024 00:22:28 +0300 Message-Id: <32ee62053c54a36ca56582f021d71f49a1c35b7b.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Michael Tokarev --- qemu-img.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index eabf45c423..8f16ee9deb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1464,9 +1464,17 @@ static int img_compare(const img_cmd_t *ccmd, int argc, char **argv) for (;;) { static const struct option long_options[] = { {"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 = getopt_long(argc, argv, ":hf:F:T:pqsU", @@ -1482,7 +1490,22 @@ static int img_compare(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operation\n" +" -p|--progress - show operation progress\n" +" -f|--a-format FMT - specify FILENAME1 image format explicitly\n" +" -F|--b-format FMT - specify FILENAME2 image format explicitly\n" +" --image-opts - indicates that FILENAMEs are complete image specifications\n" +" instead of file names (incompatible with --a-format and --b-format)\n" +" -s|--strict - strict mode, also check if sizes are equal\n" +" -T|--cache - CACHE_MODE cache mode when opening images (" BDRV_DEFAULT_CACHE ")\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME1, FILENAME2 - image files (or specifications) to compare\n" +); break; case 'f': fmt1 = optarg; From patchwork Fri Feb 9 21:22:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7841DC4828F for ; Fri, 9 Feb 2024 21:23:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKw-0006i1-OW; Fri, 09 Feb 2024 16:23:06 -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 1rYYKu-0006hJ-Cb; Fri, 09 Feb 2024 16:23:04 -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 1rYYKs-00008d-N7; Fri, 09 Feb 2024 16:23:04 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id C5A174BF60; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id A68EC77EDA; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123163 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 08/23] qemu-img: refresh options/--help for "convert" command Date: Sat, 10 Feb 2024 00:22:29 +0300 Message-Id: <4962a298d3f4adbeb93726fc5f505d963c684442.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. convert uses -B for --backing, - why not -b? Signed-off-by: Michael Tokarev --- qemu-img.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 8f16ee9deb..d4dafebff9 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2374,14 +2374,29 @@ static int img_convert(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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 = getopt_long(argc, argv, ":hf:O:B:CcF:o:l:S:pt:T:qnm:WUr:", @@ -2397,7 +2412,42 @@ static int img_convert(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': - help(); + cmd_help(ccmd, +"[-f SRC_FMT|--image-opts] [-T SRC_CACHE] [--bitmaps [--skip-broken-bitmaps]]\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 - quiet operations\n" +" -p|--progress - show operation progress\n" +" -f|--source-format SRC_FMT - specify SRC_FILENAME source image format explicitly\n" +" --source-image-opts - 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 - specify source snapshot parameters\n" +" -T|--source-cache SRC_CACHE - cache mode when opening source image (" BDRV_DEFAULT_CACHE ")\n" +" -O|--target-format TGT_FMT - specify TGT_FILENAME image format (default is raw)\n" +" --target-image-opts - 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 - TARGET_FMT-specific options\n" +" -c|--compress - create compressed output image (qcow and qcow2 format only)\n" +" -t|--target-cache TGT_CACHE - cache mode when opening output image (unsafe)\n" +" -B|--backing BACKING_FILENAME - create output to be a CoW on top of BACKING_FILENAME\n" +" -F|--backing-format BACKING_FMT - specify BACKING_FILENAME image format explicitly\n" +" -n|--no-create - omit target volume creation (eg on rbd)\n" +" --target-is-zero\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" +" -r|--rate RATE - I/O rate limit\n" +" -m|--parallel NUM_COROUTINES - specify parallelism (default 8)\n" +" -C|--copy-range-offloading - use copy_range offloading\n" +" --salvage\n" +" -W|--oob-writes - enable out-of-order writes to improve performance\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" SRC_FILENAME - source image file name (or specification with --image-opts)\n" +" TGT_FILENAME - target (output) image file name\n" +); break; case 'f': fmt = optarg; From patchwork Fri Feb 9 21:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B369C4828F for ; Fri, 9 Feb 2024 21:23:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKy-0006j8-6t; Fri, 09 Feb 2024 16:23: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 1rYYKv-0006ho-Qh; Fri, 09 Feb 2024 16:23:05 -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 1rYYKu-00008r-CC; Fri, 09 Feb 2024 16:23:05 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id D35334BF61; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id BFE1277EDB; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123166 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 09/23] qemu-img: refresh options/--help for "info" command Date: Sat, 10 Feb 2024 00:22:30 +0300 Message-Id: <34047bb7a1ebf37cb6cf41a4610f248ebccc5b13.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. Signed-off-by: Michael Tokarev --- qemu-img.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d4dafebff9..a1a0ba99f0 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -65,7 +65,6 @@ typedef struct img_cmd_t { enum { OPTION_OUTPUT = 256, - OPTION_BACKING_CHAIN = 257, OPTION_OBJECT = 258, OPTION_IMAGE_OPTS = 259, OPTION_PATTERN = 260, @@ -3173,13 +3172,13 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) {"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 = getopt_long(argc, argv, ":f:hU", + c = getopt_long(argc, argv, ":f:hbU", long_options, &option_index); if (c == -1) { break; @@ -3192,7 +3191,20 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - 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" +" -b|--backing-chain - display information about backing chaing\n" +" (in case the image is stacked\n" +" -U|--force-share - open image in shared mode for concurrent access\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" --output human|json - specify output format name (default human)\n" +" FILENAME - image file name (or specification with --image-opts)\n" +); break; case 'f': fmt = optarg; @@ -3203,7 +3215,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv) case OPTION_OUTPUT: output_format = parse_output_format(ccmd, optarg); break; - case OPTION_BACKING_CHAIN: + case 'b': chain = true; break; case OPTION_OBJECT: From patchwork Fri Feb 9 21:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 709C2C4829B for ; Fri, 9 Feb 2024 21:23:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYKz-0006jR-3u; Fri, 09 Feb 2024 16:23:09 -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 1rYYKx-0006iV-3q; Fri, 09 Feb 2024 16:23:07 -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 1rYYKv-000094-NG; Fri, 09 Feb 2024 16:23:06 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id E0FDE4BF62; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id CDD8D77EDC; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123169 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 10/23] qemu-img: refresh options/--help for "map" command Date: Sat, 10 Feb 2024 00:22:31 +0300 Message-Id: <3ccba14f375afbe54447ae24005533af53ecd537.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index a1a0ba99f0..5af0b8ec18 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3425,7 +3425,20 @@ static int img_map(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - 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" +" --start-offset OFFSET\n" +" --max-length LENGTH\n" +" --output human|json - specify output format name (default human)\n" +" -U|--force-share - open image in shared mode for concurrent access\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - image file name (or specification with --image-opts)\n" +); break; case 'f': fmt = optarg; From patchwork Fri Feb 9 21:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7453DC4828F for ; Fri, 9 Feb 2024 21:24:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLN-0006tY-Ge; Fri, 09 Feb 2024 16:23: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 1rYYLJ-0006ph-69; Fri, 09 Feb 2024 16:23:29 -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 1rYYLH-00009H-67; Fri, 09 Feb 2024 16:23:28 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id EE0894BF63; Sat, 10 Feb 2024 00:24:03 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id DAC7D77EDD; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123172 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Date: Sat, 10 Feb 2024 00:22:32 +0300 Message-Id: <04b076064ec3f49976cf935aa15ddb6ed47262c5.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org For consistency with other commands, and since it already accepts --image-opts, allow specifying -f fmt too. Signed-off-by: Michael Tokarev --- 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. -.. 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 List, apply, create or delete snapshots in image *FILENAME*. 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 DEF("snapshot", img_snapshot, - "snapshot [--object objectdef] [--image-opts] [-U] [-q] [-l | -a snapshot | -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 DEF("rebase", img_rebase, diff --git a/qemu-img.c b/qemu-img.c index 5af0b8ec18..1e09b78d00 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3540,7 +3540,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) BlockBackend *blk; BlockDriverState *bs; QEMUSnapshotInfo sn; - char *filename, *snapshot_name = NULL; + char *filename, *fmt = NULL, *snapshot_name = NULL; int c, ret = 0, bdrv_oflags; int action = 0; bool quiet = false; @@ -3559,7 +3559,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, ":la:c:d:hqU", + c = getopt_long(argc, argv, ":la:c:d:fhqU", long_options, NULL); if (c == -1) { break; @@ -3574,6 +3574,9 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) case 'h': help(); return 0; + case 'f': + fmt = optarg; + break; case 'l': if (action) { error_exit(ccmd, "Cannot mix '-l', '-a', '-c', '-d'"); @@ -3627,7 +3630,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) filename = argv[optind++]; /* Open the image */ - blk = img_open(image_opts, filename, NULL, bdrv_oflags, false, quiet, + blk = img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, force_share); if (!blk) { return 1; From patchwork Fri Feb 9 21:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3719CC4828F for ; Fri, 9 Feb 2024 21:23:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLa-0007Ii-FT; Fri, 09 Feb 2024 16:23:46 -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 1rYYLY-0007FM-L2; Fri, 09 Feb 2024 16:23:44 -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 1rYYLJ-00009S-4S; Fri, 09 Feb 2024 16:23:44 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 070A04BF64; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id E809C77EDE; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123175 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand Date: Sat, 10 Feb 2024 00:22:33 +0300 Message-Id: <71d69214d43897e5649fed00804a5969b0fd718b.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org also remove bdrv_oflags handling (only list can use RO mode) --- qemu-img.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1e09b78d00..d9dfff2f07 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3541,7 +3541,7 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) BlockDriverState *bs; QEMUSnapshotInfo sn; char *filename, *fmt = NULL, *snapshot_name = NULL; - int c, ret = 0, bdrv_oflags; + int c, ret = 0; int action = 0; bool quiet = false; Error *err = NULL; @@ -3549,7 +3549,6 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) bool force_share = false; int64_t rt; - bdrv_oflags = BDRV_O_RDWR; /* Parse commandline parameters */ for(;;) { static const struct option long_options[] = { @@ -3583,7 +3582,6 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) return 0; } action = SNAPSHOT_LIST; - bdrv_oflags &= ~BDRV_O_RDWR; /* no need for RW */ break; case 'a': if (action) { @@ -3629,9 +3627,14 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) } filename = argv[optind++]; + if (!action) { + action = SNAPSHOT_LIST; + } + /* Open the image */ - blk = img_open(image_opts, filename, fmt, bdrv_oflags, false, quiet, - force_share); + blk = img_open(image_opts, filename, fmt, + action == SNAPSHOT_LIST ? 0 : BDRV_O_RDWR, + false, quiet, force_share); if (!blk) { return 1; } From patchwork Fri Feb 9 21:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 273C4C48297 for ; Fri, 9 Feb 2024 21:24:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLR-000709-W0; Fri, 09 Feb 2024 16:23:38 -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 1rYYLO-0006ue-0V; Fri, 09 Feb 2024 16:23:34 -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 1rYYLL-0000CL-H4; Fri, 09 Feb 2024 16:23:32 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 13FC84BF65; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 011E777EDF; Sat, 10 Feb 2024 00:22:47 +0300 (MSK) Received: (nullmailer pid 1123178 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 13/23] qemu-img: refresh options/--help for "snapshot" command Date: Sat, 10 Feb 2024 00:22:34 +0300 Message-Id: <1696eb10959944f45030e6dc9563ebebc43643eb.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d9dfff2f07..67e6a7797d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3553,9 +3553,15 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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, 'l'}, + {"apply", no_argument, 0, 'a'}, + {"create", no_argument, 0, 'c'}, + {"delete", no_argument, 0, 'd'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":la:c:d:fhqU", @@ -3571,8 +3577,24 @@ static int img_snapshot(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operations\n" +" -f|--format FMT - specify FILENAME format explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -U|--force-share - open image in shared mode for concurrent access\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" Operation, one of:\n" +" -l|--list - list snapshots in FILENAME (the default)\n" +" -c|--create SNAPSHOT - create named snapshot\n" +" -a|--apply SNAPSHOT - apply named snapshot to the base\n" +" -d|--delete SNAPSHOT - delete named snapshot\n" +" FILENAME - image file name (or specification with --image-opts)\n" +); + break; case 'f': fmt = optarg; break; From patchwork Fri Feb 9 21:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1716FC48297 for ; Fri, 9 Feb 2024 21:25:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLR-00075H-U0; Fri, 09 Feb 2024 16:23:38 -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 1rYYLQ-0006zM-Fr; Fri, 09 Feb 2024 16:23: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 1rYYLO-0000Cg-SV; Fri, 09 Feb 2024 16:23:36 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 2147A4BF66; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 0E23677EE0; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123181 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 14/23] qemu-img: refresh options/--help for "rebase" command Date: Sat, 10 Feb 2024 00:22:35 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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. --- qemu-img.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 67e6a7797d..69d41e0a92 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3752,10 +3752,18 @@ static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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 = getopt_long(argc, argv, ":hf:F:b:upt:T:qUc", @@ -3771,7 +3779,27 @@ static int img_rebase(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, argv[optind - 1]); break; 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 - quiet operation\n" +" -p|--progress - show progress indicator\n" +" -f|--format FMT - specify FILENAME 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 - cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" -b|--backing BACKING_FILENAME|\"\" - rebase onto this file (or no backing file)\n" +" -F|--backing-format BACKING_FMT - specify format for BACKING_FILENAME\n" +" -T|--backing-cache CACHE - cache mode for BACKING_FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" -u|--backing-unsafe - do not fail if BACKING_FILENAME can not be read\n" +" -c|--compress - compress image (when image supports this)\n" +" -U|--force-share - open image in shared mode for concurrent access\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - image file name (or specification with --image-opts)\n" +); return 0; case 'f': fmt = optarg; From patchwork Fri Feb 9 21:22:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 546EDC4829B for ; Fri, 9 Feb 2024 21:24:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLU-0007Al-Vr; Fri, 09 Feb 2024 16:23:41 -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 1rYYLT-00079A-Cs; Fri, 09 Feb 2024 16:23: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 1rYYLR-0000Cw-T1; Fri, 09 Feb 2024 16:23:39 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 2EA934BF67; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 1B87F77EE1; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123184 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 15/23] qemu-img: resize: do not always eat last argument Date: Sat, 10 Feb 2024 00:22:36 +0300 Message-Id: <7e0e7cb2470d572e8c0a48ba85c993be3bdb1c07.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 'qemu-img resize --help' does not work, since it wants more arguments. Only eat last option at the beginning if it starts like -N.., and allow getopt() to do its work, and eat it up at the end if not already eaten. This will not allow to mix options and size anyway, but it is better than now. Signed-off-by: Michael Tokarev --- qemu-img.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 69d41e0a92..929a25a021 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4271,13 +4271,13 @@ static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) /* Remove size from argv manually so that negative numbers are not treated * as options by getopt. */ - if (argc < 3) { - error_exit(ccmd, "Not enough arguments"); - return 1; + if (argc > 1 && argv[argc - 1][0] == '-' + && argv[argc-1][1] >= '0' && argv[argc-1][1] <= '9') { + size = argv[--argc]; + } else { + size = NULL; } - size = argv[--argc]; - /* Parse getopt arguments */ fmt = NULL; for(;;) { @@ -4329,10 +4329,13 @@ static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) break; } } - if (optind != argc - 1) { + if (optind + 1 + (size == NULL) != argc) { error_exit(ccmd, "Expecting image file name and size"); } filename = argv[optind++]; + if (!size) { + size = argv[optind++]; + } /* Choose grow, shrink, or absolute resize mode */ switch (size[0]) { From patchwork Fri Feb 9 21:22:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36F4CC48297 for ; Fri, 9 Feb 2024 21:24:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLY-0007Ei-17; Fri, 09 Feb 2024 16:23: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 1rYYLW-0007EA-9v; Fri, 09 Feb 2024 16:23:42 -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 1rYYLU-0000D9-PD; Fri, 09 Feb 2024 16:23:42 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 3B74F4BF68; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 287DC77EE2; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123187 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 16/23] qemu-img: refresh options/--help for "resize" command Date: Sat, 10 Feb 2024 00:22:37 +0300 Message-Id: <4025c554219a66f0b539df7d15bdd1874317cacb.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 929a25a021..e552401074 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4283,7 +4283,9 @@ static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) for(;;) { static const struct option long_options[] = { {"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}, @@ -4302,8 +4304,21 @@ static int img_resize(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operation\n" +" -f|--format FMT - specify FILENAME format explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" --shrink - allow operation when new size is smaller than original\n" +" --preallocation PREALLOC - specify preallocation type for the new areas\n" +" --object OBJDEF - QEMU user-creatable object (eg encryption key)\n" +" FILENAME - image file (specification) to resize\n" +" SIZE - new image size or amount by which to shrink/grow\n" +); + return 0; case 'f': fmt = optarg; break; From patchwork Fri Feb 9 21:22:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9598C48297 for ; Fri, 9 Feb 2024 21:26:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLv-00009F-Si; Fri, 09 Feb 2024 16:24: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 1rYYLt-00006a-4S; Fri, 09 Feb 2024 16:24:05 -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 1rYYLr-0000DM-Mv; Fri, 09 Feb 2024 16:24:04 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 486E94BF69; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 3558377EE3; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123190 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 17/23] qemu-img: refresh options/--help for "amend" command Date: Sat, 10 Feb 2024 00:22:38 +0300 Message-Id: <6f4e3f9ae4b0b08322bab26485207c81d1c4e76f.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index e552401074..f598eba3a8 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4493,7 +4493,12 @@ static int img_amend(const img_cmd_t *ccmd, int argc, char **argv) for (;;) { static const struct option long_options[] = { {"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} @@ -4512,7 +4517,18 @@ static int img_amend(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operation\n" +" -p|--progres - show progress\n" +" -f|--format FMT - specify FILENAME 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 - cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" --force - allow certain unsafe operations\n" +); break; case 'o': if (accumulate_options(&options, optarg) < 0) { From patchwork Fri Feb 9 21:22:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551898 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13263C48297 for ; Fri, 9 Feb 2024 21:26:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYLx-0000AF-VR; Fri, 09 Feb 2024 16:24:10 -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 1rYYLv-000096-Lp; Fri, 09 Feb 2024 16:24:07 -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 1rYYLu-0000Dc-3x; Fri, 09 Feb 2024 16:24:07 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 55AE34BF6A; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 4284577EE4; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123193 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 18/23] qemu-img: refresh options/--help for "bench" command Date: Sat, 10 Feb 2024 00:22:39 +0300 Message-Id: <412cd5a3af866763a22ec17a5eea99aa2b6564da.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index f598eba3a8..3be365cd07 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4781,9 +4781,19 @@ static int img_bench(const img_cmd_t *ccmd, int argc, char **argv) for (;;) { static const struct option long_options[] = { {"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} @@ -4802,7 +4812,29 @@ static int img_bench(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 - quiet operations\n" +" -f|--format FMT - specify FILENAME 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 - cache mode for FILENAME (" BDRV_DEFAULT_CACHE ")\n" +" -c|--count COUNT - number of I/O requests to perform\n" +" -s|--buffer-size BUFFER_SIZE - size of each I/O request\n" +" -d|--depth DEPTH - number of requests to perform in parallel\n" +" -o|--offset OFFSET - start first request at this OFFSET\n" +" -S|--step-size STEP_SIZE - each next request offset increment\n" +" -i|--aio AIO - async-io backend (threads, native, io_uring)\n" +" -n|--native - use native AIO backend if possible\n" +" -w|--write - perform write test (default is read)\n" +" --pattern PATTERN - write this pattern instead of zeros\n" +" --flush-interval FLUSH_INTERVAL - issue flush after this number of requests\n" +" --no-drain - do not wait when flushing pending requests\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +); break; case 'c': { From patchwork Fri Feb 9 21:22:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9EAEBC4828F for ; Fri, 9 Feb 2024 21:25:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYMF-0000TE-6I; Fri, 09 Feb 2024 16:24: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 1rYYLv-00009R-VM; Fri, 09 Feb 2024 16:24:08 -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 1rYYLu-0000Eg-GU; Fri, 09 Feb 2024 16:24:07 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 6373F4BF6B; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 5039977EE5; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123196 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 19/23] qemu-img: refresh options/--help for "bitmap" command Date: Sat, 10 Feb 2024 00:22:40 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 3be365cd07..9a0cd05d42 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5103,7 +5103,24 @@ static int img_bitmap(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, 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 OBJDEF]\n" +" FILENAME BITMAP\n" +, +" -f|--format FMT - specify FILENAME format explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" --add - creates BITMAP, enables to record future edits\n" +" -g|--granularity GRANULARITY - sets non-default granularity for --add\n" +" --remove - removes BITMAP\n" +" --clear - clears BITMAP\n" +" --enable, --disable - starts and stops recording future edits to BITMAP\n" +" --merge SRC_FILENAME - merges contents of SRC_FILENAME bitmap into BITMAP\n" +" -b|--source-file SRC_FILENAME - select alternative source file for --merge\n" +" -F|--source-format SRC_FMT - specify format for SRC_FILENAME explicitly\n" +); break; case 'b': src_filename = optarg; From patchwork Fri Feb 9 21:22:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF59CC48297 for ; Fri, 9 Feb 2024 21:27:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYMH-0000la-0x; Fri, 09 Feb 2024 16:24:29 -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 1rYYLy-0000Ek-Fm; Fri, 09 Feb 2024 16:24:11 -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 1rYYLx-0000Eu-0c; Fri, 09 Feb 2024 16:24:10 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 70AD94BF6C; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 5D86777EE6; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123199 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 20/23] qemu-img: refresh options/--help for "dd" command Date: Sat, 10 Feb 2024 00:22:41 +0300 Message-Id: <6a731eabb363cc93289ace19eed055f5e06c71cd.1707513011.git.mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. --- qemu-img.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 9a0cd05d42..db1f80e15d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -5417,6 +5417,8 @@ static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) const struct option long_options[] = { { "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 } @@ -5427,12 +5429,6 @@ static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) break; } switch (c) { - case 'O': - out_fmt = optarg; - break; - case 'f': - fmt = optarg; - break; case ':': missing_argument(ccmd, argv[optind - 1]); break; @@ -5440,7 +5436,26 @@ static int img_dd(const img_cmd_t *ccmd, int argc, char **argv) unrecognized_option(ccmd, argv[optind - 1]); break; case 'h': - help(); + cmd_help(ccmd, +"[-f FMT|--image-opts] [-O OUTPUT_FMT] [-U]\n" +" [bs=BLOCK_SIZE] [count=BLOCKS] if=INPUT of=OUTPUT\n" +, +" -f|--format FMT - specify format for INPUT explicitly\n" +" --image-opts - indicates that INPUT is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -O|--output-format OUTPUT_FMT - format of the OUTPUT (default raw)\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +" bs=BLOCK_SIZE - size of I/O block (default 512)\n" +" count=COUNT - number of blocks to convert (default whole INPUT)\n" +" if=INPUT - input file name or image specification (with --image-opts)\n" +" of=OUTPUT - output file name to create\n" +); + break; + case 'O': + out_fmt = optarg; + break; + case 'f': + fmt = optarg; break; case 'U': force_share = true; From patchwork Fri Feb 9 21:22:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 39C99C48297 for ; Fri, 9 Feb 2024 21:25:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYML-0001Iq-Aj; Fri, 09 Feb 2024 16:24: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 1rYYMI-00016T-Vl; Fri, 09 Feb 2024 16:24: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 1rYYMH-0000F2-C5; Fri, 09 Feb 2024 16:24:30 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 7E0D54BF6D; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 6AF3277EE7; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123203 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 21/23] qemu-img: refresh options/--help for "measure" command Date: Sat, 10 Feb 2024 00:22:42 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add missing long options and --help output. Also add -s short option for --size (and remove OPTION_SIZE). --- qemu-img.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index db1f80e15d..e2c8855ff5 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -71,7 +71,6 @@ enum { OPTION_FLUSH_INTERVAL = 261, OPTION_NO_DRAIN = 262, OPTION_TARGET_IMAGE_OPTS = 263, - OPTION_SIZE = 264, OPTION_PREALLOCATION = 265, OPTION_SHRINK = 266, OPTION_SALVAGE = 267, @@ -5657,15 +5656,6 @@ static void dump_json_block_measure_info(BlockMeasureInfo *info) static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) { - static const struct option long_options[] = { - {"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 = OFORMAT_HUMAN; BlockBackend *in_blk = NULL; BlockDriver *drv; @@ -5686,12 +5676,41 @@ static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) int ret = 1; int c; + static const struct option long_options[] = { + {"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 = getopt_long(argc, argv, "hf:O:o:l:U", long_options, NULL)) != -1) { switch (c) { case '?': + unrecognized_option(ccmd, argv[optind - 1]); 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 - desired target/output image format (default raw)\n" +" -s|--size SIZE - measure file size for given image size\n" +" FILENAME - measure file size required to convert from FILENAME\n" +" -f|--format - specify format of FILENAME explicitly\n" +" --image-opts - indicates that FILENAME is a complete image specification\n" +" instead of a file name (incompatible with --format)\n" +" -l|--snapshot SNAPSHOT - use this snapshot in FILENAME as source\n" +" --output human|json - output format\n" +" -U|--force-share - open images in shared mode for concurrent access\n" +); break; case 'f': fmt = optarg; @@ -5729,7 +5748,7 @@ static int img_measure(const img_cmd_t *ccmd, int argc, char **argv) case OPTION_OUTPUT: output_format = parse_output_format(ccmd, optarg); break; - case OPTION_SIZE: + case 's': { int64_t sval; From patchwork Fri Feb 9 21:22:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3EFAC4828F for ; Fri, 9 Feb 2024 21:24:52 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYMO-0001fM-Bz; Fri, 09 Feb 2024 16:24:36 -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 1rYYMM-0001SB-8U; Fri, 09 Feb 2024 16:24:34 -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 1rYYMJ-0000Gp-TX; Fri, 09 Feb 2024 16:24:33 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 8C8B74BF6E; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 781AD77EE8; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123206 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 22/23] qemu-img: implement short --help, remove global help() function Date: Sat, 10 Feb 2024 00:22:43 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 74 chars. Signed-off-by: Michael Tokarev --- qemu-img.c | 148 +++++++++++------------------------------------------ 1 file changed, 30 insertions(+), 118 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index e2c8855ff5..d9c5c6078b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -94,11 +94,6 @@ typedef enum OutputFormat { /* Default to cache=writeback as data integrity is not important for qemu-img */ #define BDRV_DEFAULT_CACHE "writeback" -static void format_print(void *opaque, const char *name) -{ - printf(" %s", name); -} - static G_NORETURN G_GNUC_PRINTF(2, 3) void error_exit(const img_cmd_t *ccmd, const char *fmt, ...) { @@ -154,114 +149,6 @@ static OutputFormat parse_output_format(const img_cmd_t *ccmd, const char *arg) } } -/* Please keep in synch with docs/tools/qemu-img.rst */ -static G_NORETURN -void help(void) -{ - const char *help_msg = - 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=]][,events=][,file=]\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. The most common\n" - " object type is a 'secret', which is used to supply passwords 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 image, the valid\n" - " options are: 'none', 'writeback' (default, except for convert), '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' (gigabyte, 1024M),\n" - " 'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 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 options in a\n" - " name=value format. Use -o help for an overview of the options supported by\n" - " the used format\n" - " 'snapshot_param' is param used for internal snapshot, format\n" - " is 'snapshot.id=[ID],snapshot.name=[NAME]', or\n" - " '[ID_OR_NAME]'\n" - " '-c' indicates that target image must be compressed (qcow format only)\n" - " '-u' allows unsafe backing chains. For rebasing, it is assumed 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 renaming the\n" - " backing file). For image creation, allow creating without 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 image during\n" - " conversion. If the number of bytes is 0, the source will 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 one 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 during 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 wrong fix or\n" - " hiding corruption that has already occurred.\n" - "\n" - "Parameters to convert subcommand:\n" - " '--bitmaps' copies all top-level persistent bitmaps to destination\n" - " '-m' specifies how many coroutines work in parallel during the convert\n" - " process (defaults to 8)\n" - " '-W' allow to write to the target out of order rather than sequential\n" - "\n" - "Parameters to snapshot subcommand:\n" - " 'snapshot' is the name of the snapshot to create, apply or delete\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 sector allocation\n" - "\n" - "Parameters to dd subcommand:\n" - " 'bs=BYTES' read and write up to BYTES bytes at a time " - "(default: 512)\n" - " 'count=N' copy only N input blocks\n" - " 'if=FILE' read from FILE\n" - " 'of=FILE' write to FILE\n" - " 'skip=N' 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 ','. @@ -5866,6 +5753,16 @@ static const img_cmd_t img_cmds[] = { { NULL, NULL, }, }; +static void format_print(void *opaque, const char *name) +{ + int *np = opaque; + *np += printf(" %s", name); + if (*np > 74) { + printf("\n "); + *np = 1; + } +} + int main(int argc, char **argv) { const img_cmd_t *cmd; @@ -5893,10 +5790,6 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); bdrv_init(); - if (argc < 2) { - error_exit(NULL, "Not enough arguments"); - } - qemu_add_opts(&qemu_source_opts); qemu_add_opts(&qemu_trace_opts); @@ -5909,7 +5802,22 @@ int main(int argc, char **argv) unrecognized_option(NULL, argv[optind - 1]); return 0; case 'h': - help(); + printf( +QEMU_IMG_VERSION +"QEMU disk image utility\n" +"usage: qemu-img [standard options] command [--help | command options]\n" +"Standard options:\n" +" -h|--help - display this help and exit\n" +" -V|--version - display version info and exit\n" +" -T|--trace TRACE - specify tracing options:\n" +" [[enable=]][,events=][,file=]\n" +"Recognized commands (run qemu-img command --help for command-specific help):\n"); + for (cmd = img_cmds; cmd->name != NULL; cmd++) { + printf(" %s\n", cmd->name); + } + c = printf("Supported image formats:"); + bdrv_iterate_format(format_print, &c, false); + printf("\n" QEMU_HELP_BOTTOM "\n"); return 0; case 'V': printf(QEMU_IMG_VERSION); @@ -5920,6 +5828,10 @@ int main(int argc, char **argv) } } + if (argc < 2) { + error_exit(NULL, "Not enough arguments"); + } + cmdname = argv[optind]; /* reset getopt_long scanning */ From patchwork Fri Feb 9 21:22:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 13551899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1332EC4828F for ; Fri, 9 Feb 2024 21:26:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYYMO-0001l9-Se; Fri, 09 Feb 2024 16:24:37 -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 1rYYMM-0001SC-8W; Fri, 09 Feb 2024 16:24:34 -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 1rYYMK-0000Ha-Dh; Fri, 09 Feb 2024 16:24:33 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 9A2EC4BF6F; Sat, 10 Feb 2024 00:24:04 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 868B177EE9; Sat, 10 Feb 2024 00:22:48 +0300 (MSK) Received: (nullmailer pid 1123209 invoked by uid 1000); Fri, 09 Feb 2024 21:22:47 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Michael Tokarev Subject: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Date: Sat, 10 Feb 2024 00:22:44 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org also add short description to each command and use it in --help Signed-off-by: Michael Tokarev --- qemu-img.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d9c5c6078b..e57076738e 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; enum { @@ -130,11 +131,12 @@ static G_NORETURN void cmd_help(const img_cmd_t *ccmd, const char *syntax, const char *arguments) { - printf("qemu-img %s %s" + printf("qemu-img %s: %s. Usage:\n" + "qemu-img %s %s" "Arguments:\n" " -h|--help - print this help and exit\n" "%s", - ccmd->name, syntax, arguments); + ccmd->name, ccmd->description, ccmd->name, syntax, arguments); exit(EXIT_SUCCESS); } @@ -5746,10 +5748,36 @@ out: } static const img_cmd_t img_cmds[] = { -#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, }, }; @@ -5813,7 +5841,7 @@ QEMU_IMG_VERSION " [[enable=]][,events=][,file=]\n" "Recognized commands (run qemu-img command --help for command-specific help):\n"); for (cmd = img_cmds; cmd->name != NULL; cmd++) { - printf(" %s\n", cmd->name); + printf(" %s - %s\n", cmd->name, cmd->description); } c = printf("Supported image formats:"); bdrv_iterate_format(format_print, &c, false);