* [PATCH 01/23] qemu-img: pass current cmd info into command handlers
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 17:29 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand Michael Tokarev
` (23 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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 <mjt@tls.msk.ru>
---
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);
}
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 01/23] qemu-img: pass current cmd info into command handlers
2024-02-09 21:22 ` [PATCH 01/23] qemu-img: pass current cmd info into command handlers Michael Tokarev
@ 2024-02-20 17:29 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 17:29 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:22AM +0300, Michael Tokarev wrote:
> 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 <mjt@tls.msk.ru>
> ---
> qemu-img.c | 150 ++++++++++++++++++++++++++---------------------------
> 1 file changed, 75 insertions(+), 75 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
2024-02-09 21:22 ` [PATCH 01/23] qemu-img: pass current cmd info into command handlers Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 18:41 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 03/23] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
` (22 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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 <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand
2024-02-09 21:22 ` [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand Michael Tokarev
@ 2024-02-20 18:41 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 18:41 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:23AM +0300, Michael Tokarev wrote:
> 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 <mjt@tls.msk.ru>
> ---
> 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"
I think we want an extra "\n" before & after 'Arguments:'
> + "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"
This comes out as a bit of a wall of dense text.
I think we should have 2 space indent for options, and a further
4 space for continuations, and also put the description on its
own line.
eg so instead of getting:
$ ./build/qemu-img create --help
qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
[--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
Arguments:
-h|--help - print this help and exit
-q|--quiet - quiet operations
-f|--format FMT - specifies format of the new image, default is raw
-o|--options FMT_OPTS - format-specific options ('-o list' for list)
-b|--backing BACKING_FILENAME - stack new image on top of BACKING_FILENAME
(for formats which support stacking)
-F|--backing-format BACKING_FMT - specify format of BACKING_FILENAME
-u|--backing-unsafe - do not fail if BACKING_FMT can not be read
--object OBJDEF - QEMU user-creatable object (eg encryption key)
FILENAME - image file to create. It will be overriden if exists
SIZE - image size with optional suffix: 'b' (byte, default), 'k' or
'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T), or 'E' (exabyte, 1024P)
SIZE is required unless BACKING_IMG is specified, in which case
it will be the same as size of BACKING_IMG
we would get:
$ ./build/qemu-img create --help
qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
[--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
Arguments:
-h|--help
print this help and exit
-q|--quiet
quiet operations
-f|--format FMT
specifies format of the new image, default is raw
-o|--options FMT_OPTS
format-specific options ('-o list' for list)
-b|--backing BACKING_FILENAME
stack new image on top of BACKING_FILENAME
(for formats which support stacking)
-F|--backing-format BACKING_FMT
specify format of BACKING_FILENAME
-u|--backing-unsafe
do not fail if BACKING_FMT can not be read
--object OBJDEF
QEMU user-creatable object (eg encryption key)
FILENAME
image file to create. It will be overriden if exists
SIZE
image size with optional suffix: 'b' (byte, default), 'k' or
'K' (kilobyte, 1024b), 'M' (megabyte, 1024K), 'G' (gigabyte, 1024M),
'T' (terabyte, 1024G), 'P' (petabyte, 1024T), or 'E' (exabyte, 1024P)
SIZE is required unless BACKING_IMG is specified, in which case
it will be the same as size of BACKING_IMG
> +);
> break;
> case 'F':
> base_fmt = optarg;
> --
> 2.39.2
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 03/23] qemu-img: factor out parse_output_format() and use it in the code
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
2024-02-09 21:22 ` [PATCH 01/23] qemu-img: pass current cmd info into command handlers Michael Tokarev
2024-02-09 21:22 ` [PATCH 02/23] qemu-img: refresh options/--help for "create" subcommand Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 17:38 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 04/23] qemu-img: refresh options/--help for "check" command Michael Tokarev
` (21 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Use common code and simplify error message
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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:
{
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 04/23] qemu-img: refresh options/--help for "check" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (2 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 03/23] qemu-img: factor out parse_output_format() and use it in the code Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 05/23] qemu-img: simplify --repair error message Michael Tokarev
` (20 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Add missing long options and --help output.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 05/23] qemu-img: simplify --repair error message
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (3 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 04/23] qemu-img: refresh options/--help for "check" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 17:40 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 06/23] qemu-img: refresh options/--help for "commit" command Michael Tokarev
` (19 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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:
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 05/23] qemu-img: simplify --repair error message
2024-02-09 21:22 ` [PATCH 05/23] qemu-img: simplify --repair error message Michael Tokarev
@ 2024-02-20 17:40 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 17:40 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:26AM +0300, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> 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);
> }
Should we say '--repair/-r expects...' since we don't know which the
user passed
Either way
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 06/23] qemu-img: refresh options/--help for "commit" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (4 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 05/23] qemu-img: simplify --repair error message Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 07/23] qemu-img: refresh options/--help for "compare" command Michael Tokarev
` (18 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Add missing long options and --help output.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 07/23] qemu-img: refresh options/--help for "compare" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (5 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 06/23] qemu-img: refresh options/--help for "commit" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 08/23] qemu-img: refresh options/--help for "convert" command Michael Tokarev
` (17 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 08/23] qemu-img: refresh options/--help for "convert" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (6 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 07/23] qemu-img: refresh options/--help for "compare" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 09/23] qemu-img: refresh options/--help for "info" command Michael Tokarev
` (16 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Add missing long options and --help output.
convert uses -B for --backing, - why not -b?
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 09/23] qemu-img: refresh options/--help for "info" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (7 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 08/23] qemu-img: refresh options/--help for "convert" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 10/23] qemu-img: refresh options/--help for "map" command Michael Tokarev
` (15 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
Add missing long options and --help output.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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:
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 10/23] qemu-img: refresh options/--help for "map" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (8 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 09/23] qemu-img: refresh options/--help for "info" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Michael Tokarev
` (14 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (9 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 10/23] qemu-img: refresh options/--help for "map" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:41 ` Michael Tokarev
2024-02-20 17:41 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand Michael Tokarev
` (13 subsequent siblings)
24 siblings, 2 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
For consistency with other commands, and since it already
accepts --image-opts, allow specifying -f fmt too.
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand
2024-02-09 21:22 ` [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Michael Tokarev
@ 2024-02-09 21:41 ` Michael Tokarev
2024-02-20 17:41 ` Daniel P. Berrangé
1 sibling, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:41 UTC (permalink / raw)
To: qemu-devel, qemu-block
10.02.2024 00:22, Michael Tokarev wrote:
> For consistency with other commands, and since it already
> accepts --image-opts, allow specifying -f fmt too.
>
...
> - c = getopt_long(argc, argv, ":la:c:d:hqU",
> + c = getopt_long(argc, argv, ":la:c:d:fhqU",
> long_options, NULL);
Should be "f:" here, since -f expects an argument. Fixed locally.
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand
2024-02-09 21:22 ` [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Michael Tokarev
2024-02-09 21:41 ` Michael Tokarev
@ 2024-02-20 17:41 ` Daniel P. Berrangé
1 sibling, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 17:41 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:32AM +0300, Michael Tokarev wrote:
> For consistency with other commands, and since it already
> accepts --image-opts, allow specifying -f fmt too.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> docs/tools/qemu-img.rst | 2 +-
> qemu-img-cmds.hx | 4 ++--
> qemu-img.c | 9 ++++++---
> 3 files changed, 9 insertions(+), 6 deletions(-)
With the fix you already mentioned for getopt:
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (10 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 11/23] qemu-img: allow specifying -f fmt for snapshot subcommand Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 17:45 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 13/23] qemu-img: refresh options/--help for "snapshot" command Michael Tokarev
` (12 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand
2024-02-09 21:22 ` [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand Michael Tokarev
@ 2024-02-20 17:45 ` Daniel P. Berrangé
2024-02-20 18:51 ` Michael Tokarev
0 siblings, 1 reply; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 17:45 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:33AM +0300, Michael Tokarev wrote:
> also remove bdrv_oflags handling (only list can use RO mode)
> ---
> qemu-img.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
I'd suggest docs/tools/qemu-img.rst should also be updated to say
Lists all snapshots in the given image (default action)
>
> 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;
> }
> --
> 2.39.2
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand
2024-02-20 17:45 ` Daniel P. Berrangé
@ 2024-02-20 18:51 ` Michael Tokarev
2024-02-21 12:12 ` Michael Tokarev
0 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-20 18:51 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, qemu-block
20.02.2024 20:45, Daniel P. Berrangé wrote:
> On Sat, Feb 10, 2024 at 12:22:33AM +0300, Michael Tokarev wrote:
>> also remove bdrv_oflags handling (only list can use RO mode)
>> ---
>> qemu-img.c | 13 ++++++++-----
>> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> I'd suggest docs/tools/qemu-img.rst should also be updated to say
qemu-img.rst needs to be updated, significantly more than this.
I especially avoided updating this one for now because I'd love
to agree with the options first, more or less, or else it'd be
large double-work. Also, there's an open question still, if
we prefer to keep docs and code in sync manually or to use some
automation like qemu-img-cmdx.hx now. I for one don't see how
this can be done in a reasonable way.
I plan to update it past this series.
Thanks!
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand
2024-02-20 18:51 ` Michael Tokarev
@ 2024-02-21 12:12 ` Michael Tokarev
0 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-21 12:12 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, qemu-block
20.02.2024 21:51, Michael Tokarev wrote:
> 20.02.2024 20:45, Daniel P. Berrangé wrote:
>> On Sat, Feb 10, 2024 at 12:22:33AM +0300, Michael Tokarev wrote:
>>> also remove bdrv_oflags handling (only list can use RO mode)
>>> ---
>>> qemu-img.c | 13 ++++++++-----
>>> 1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> I'd suggest docs/tools/qemu-img.rst should also be updated to say
>
> qemu-img.rst needs to be updated, significantly more than this.
Actually, - yes, you're right in this case. Added. A good suggestion.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 13/23] qemu-img: refresh options/--help for "snapshot" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (11 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 12/23] qemu-img: make -l (list) the default for "snapshot" subcommand Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 14/23] qemu-img: refresh options/--help for "rebase" command Michael Tokarev
` (11 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 14/23] qemu-img: refresh options/--help for "rebase" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (12 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 13/23] qemu-img: refresh options/--help for "snapshot" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 15/23] qemu-img: resize: do not always eat last argument Michael Tokarev
` (10 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 15/23] qemu-img: resize: do not always eat last argument
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (13 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 14/23] qemu-img: refresh options/--help for "rebase" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 17:57 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 16/23] qemu-img: refresh options/--help for "resize" command Michael Tokarev
` (9 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
'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 <mjt@tls.msk.ru>
---
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]) {
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 15/23] qemu-img: resize: do not always eat last argument
2024-02-09 21:22 ` [PATCH 15/23] qemu-img: resize: do not always eat last argument Michael Tokarev
@ 2024-02-20 17:57 ` Daniel P. Berrangé
2024-02-21 12:19 ` Michael Tokarev
0 siblings, 1 reply; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 17:57 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:36AM +0300, Michael Tokarev wrote:
> '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 <mjt@tls.msk.ru>
> ---
> 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;
> }
We already have a variable 'int relative' that is set to '-1'
or '+1' depending on whether we have a -ve or +ve size.
I think it is clearer to follow if we just set 'relative' much
earlier before parsing by moving this chunk of code to before
the getopt:
switch (size[0]) {
case '+':
relative = 1;
size++;
break;
case '-':
relative = -1;
size++;
break;
default:
relative = 0;
break;
}
once we've done that we can simply replace the '-' with '+'
to stop getopt getting upset.
>
> - 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]) {
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 15/23] qemu-img: resize: do not always eat last argument
2024-02-20 17:57 ` Daniel P. Berrangé
@ 2024-02-21 12:19 ` Michael Tokarev
0 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-21 12:19 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, qemu-block
20.02.2024 20:57, Daniel P. Berrangé пишет:
> On Sat, Feb 10, 2024 at 12:22:36AM +0300, Michael Tokarev wrote:
>> '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 <mjt@tls.msk.ru>
>> ---
>> 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;
>> }
>
> We already have a variable 'int relative' that is set to '-1'
> or '+1' depending on whether we have a -ve or +ve size.
>
> I think it is clearer to follow if we just set 'relative' much
> earlier before parsing by moving this chunk of code to before
> the getopt:
Well, we'll also have to repeat the same switch after getopt, since
there, I only test for -[0-9], not +[0-9] or [0-9]. But yes, it
can be done too.
But this is more interesting, - I think we should switch getopt to
use 'return in order' option, and process options together with
getopt, looking at the next option at each iteration, - if it looks
like [+-]size if we already got the filename part. Lemme try to
do that..
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 16/23] qemu-img: refresh options/--help for "resize" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (14 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 15/23] qemu-img: resize: do not always eat last argument Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 17/23] qemu-img: refresh options/--help for "amend" command Michael Tokarev
` (8 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 17/23] qemu-img: refresh options/--help for "amend" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (15 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 16/23] qemu-img: refresh options/--help for "resize" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 18/23] qemu-img: refresh options/--help for "bench" command Michael Tokarev
` (7 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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) {
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 18/23] qemu-img: refresh options/--help for "bench" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (16 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 17/23] qemu-img: refresh options/--help for "amend" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 19/23] qemu-img: refresh options/--help for "bitmap" command Michael Tokarev
` (6 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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':
{
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 19/23] qemu-img: refresh options/--help for "bitmap" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (17 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 18/23] qemu-img: refresh options/--help for "bench" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 20/23] qemu-img: refresh options/--help for "dd" command Michael Tokarev
` (5 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 20/23] qemu-img: refresh options/--help for "dd" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (18 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 19/23] qemu-img: refresh options/--help for "bitmap" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 21/23] qemu-img: refresh options/--help for "measure" command Michael Tokarev
` (4 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 21/23] qemu-img: refresh options/--help for "measure" command
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (19 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 20/23] qemu-img: refresh options/--help for "dd" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-09 21:22 ` [PATCH 22/23] qemu-img: implement short --help, remove global help() function Michael Tokarev
` (3 subsequent siblings)
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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;
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* [PATCH 22/23] qemu-img: implement short --help, remove global help() function
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (20 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 21/23] qemu-img: refresh options/--help for "measure" command Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 18:46 ` Daniel P. Berrangé
2024-02-09 21:22 ` [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
` (2 subsequent siblings)
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
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 <mjt@tls.msk.ru>
---
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=]<pattern>][,events=<file>][,file=<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=]<pattern>][,events=<file>][,file=<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 */
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 22/23] qemu-img: implement short --help, remove global help() function
2024-02-09 21:22 ` [PATCH 22/23] qemu-img: implement short --help, remove global help() function Michael Tokarev
@ 2024-02-20 18:46 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 18:46 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:43AM +0300, Michael Tokarev wrote:
> 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 <mjt@tls.msk.ru>
> ---
> 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=]<pattern>][,events=<file>][,file=<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"
Add '\n'
> +"usage: qemu-img [standard options] command [--help | command options]\n"
Add '\n'
> +"Standard options:\n"
Add '\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=]<pattern>][,events=<file>][,file=<file>]\n"
Similar to sub-command help, I tink it reads better as
" -h|--help\n"
" display this help and exit\n"
"\n"
" -V|--version\n"
" display version info and exit\n"
"\n"
" -T|--trace TRACE\n"
" specify tracing options:\n"
" [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
"\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);
> + }
An extra "\n"
> + c = printf("Supported image formats:");
Add a trailing "\n"
> + 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 */
Basically as an end result we get
qemu-img version 8.2.50 (v8.2.0-1219-g51870ffcbb)
Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers
QEMU disk image utility
usage: qemu-img [standard options] command [--help | command options]
Standard options:
-h|--help
display this help and exit
-V|--version
display version info and exit
-T|--trace TRACE
specify tracing options:
[[enable=]<pattern>][,events=<file>][,file=<file>]
Recognized commands (run qemu-img command --help for command-specific help):
amend - Update format-specific options of the image
bench - Run simple image benchmark
bitmap - Perform modifications of the persistent bitmap in the image
check - Check basic image integrity
commit - Commit image to its backing file
compare - Check if two images have the same contents
convert - Copy one image to another with optional format conversion
create - Create and format new image file
dd - Copy input to output with optional format conversion
info - Display information about image
map - Dump image metadata
measure - Calculate file size requred for a new image
rebase - Change backing file of the image
resize - Resize the image to the new size
snapshot - List or manipulate snapshots within image
Supported image formats:
blkdebug blklogwrites blkverify bochs cloop compress copy-before-write
copy-on-read dmg file ftp ftps gluster host_cdrom host_device http
https io_uring iscsi iser luks nbd nfs null-aio null-co nvme nvme-io_uring
parallels preallocate qcow qcow2 qed quorum raw rbd replication snapshot-access
ssh throttle vdi vhdx virtio-blk-vfio-pci virtio-blk-vhost-user virtio-blk-vhost-vdpa
vmdk vpc vvfat
See <https://qemu.org/contribute/report-a-bug> for how to report bugs.
More information on the QEMU project at <https://qemu.org>.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (21 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 22/23] qemu-img: implement short --help, remove global help() function Michael Tokarev
@ 2024-02-09 21:22 ` Michael Tokarev
2024-02-20 18:48 ` Daniel P. Berrangé
2024-02-09 22:26 ` [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
2024-02-20 18:53 ` Daniel P. Berrangé
24 siblings, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 21:22 UTC (permalink / raw)
To: qemu-devel, qemu-block; +Cc: Michael Tokarev
also add short description to each command and use it in --help
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
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=]<pattern>][,events=<file>][,file=<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);
--
2.39.2
^ permalink raw reply related [flat|nested] 43+ messages in thread
* Re: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-09 21:22 ` [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
@ 2024-02-20 18:48 ` Daniel P. Berrangé
2024-02-20 19:02 ` Michael Tokarev
2024-02-21 16:31 ` Michael Tokarev
0 siblings, 2 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 18:48 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:44AM +0300, Michael Tokarev wrote:
> also add short description to each command and use it in --help
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> 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"
This ends up looking a bit muddled together. I don't think we
need repeat 'qemu-img <cmd>' twice, and could add a little
more whitespace
eg instead of:
$ ./build/qemu-img check --help
qemu-img check: Check basic image integrity. Usage:
qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
[--output human|json] [--object OBJDEF] FILENAME
Arguments:
...snip...
have it look like
$ ./build/qemu-img check --help
Check basic image integrity.
Usage:
qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
[--output human|json] [--object OBJDEF] FILENAME
Arguments:
...snip...
> "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=]<pattern>][,events=<file>][,file=<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);
> --
> 2.39.2
>
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-20 18:48 ` Daniel P. Berrangé
@ 2024-02-20 19:02 ` Michael Tokarev
2024-02-20 19:06 ` Daniel P. Berrangé
2024-02-21 16:31 ` Michael Tokarev
1 sibling, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-20 19:02 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, qemu-block
20.02.2024 21:48, Daniel P. Berrangé:
...
> $ ./build/qemu-img check --help
> Check basic image integrity.
>
> Usage:
>
> qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> [--output human|json] [--object OBJDEF] FILENAME
>
> Arguments:
$ ./build/qemu-img check --help
Check basic image integrity. Usage:
qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
[--output human|json] [--object OBJDEF] FILENAME
Arguments:
...
Or just:
Check basic image integrity:
qemu-img check...
In all cases I tried to make the whole thing as compact as possible,
to (almost) fit on a standard terminal. The extra empty lines between
different arguments makes it almost impossible.
I think if indentation will be larger, it will be easier to read.
Let me experiment a bit..
>> "Arguments:\n"
>> " -h|--help - print this help and exit\n"
btw, the common way is to use comma here, not "|", --
-h,--help - ...
Again, I especially omitted space after "|" to make it
more compact. Maybe for no good.
We've really big amount of options here, conflicting and illogical
in some cases, which's been added without much thinking. All this
makes me think it will be difficult to automate generation of all
this text for both code and docs..
Thanks!
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-20 19:02 ` Michael Tokarev
@ 2024-02-20 19:06 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 19:06 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Tue, Feb 20, 2024 at 10:02:32PM +0300, Michael Tokarev wrote:
> 20.02.2024 21:48, Daniel P. Berrangé:
> ...
> > $ ./build/qemu-img check --help
> > Check basic image integrity.
> >
> > Usage:
> >
> > qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> > [--output human|json] [--object OBJDEF] FILENAME
> >
> > Arguments:
>
> $ ./build/qemu-img check --help
> Check basic image integrity. Usage:
>
> qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> [--output human|json] [--object OBJDEF] FILENAME
>
> Arguments:
> ...
>
> Or just:
>
> Check basic image integrity:
>
> qemu-img check...
>
>
> In all cases I tried to make the whole thing as compact as possible,
> to (almost) fit on a standard terminal. The extra empty lines between
> different arguments makes it almost impossible.
IMHO fitting on a "standard" terminal is OK in terms of width, but
should be a non-goal in terms of height. Readability is more important
than avoiding vertical scroll.
> > > "Arguments:\n"
> > > " -h|--help - print this help and exit\n"
>
> btw, the common way is to use comma here, not "|", --
> -h,--help - ...
>
> Again, I especially omitted space after "|" to make it
> more compact. Maybe for no good.
Yes, a comma with a space would look nicer. If we have the
description on the following line, then there's no width
limit problems there.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-20 18:48 ` Daniel P. Berrangé
2024-02-20 19:02 ` Michael Tokarev
@ 2024-02-21 16:31 ` Michael Tokarev
2024-02-21 16:45 ` Daniel P. Berrangé
1 sibling, 1 reply; 43+ messages in thread
From: Michael Tokarev @ 2024-02-21 16:31 UTC (permalink / raw)
To: Daniel P. Berrangé; +Cc: qemu-devel, qemu-block
20.02.2024 21:48, Daniel P. Berrangé:
> This ends up looking a bit muddled together. I don't think we
> need repeat 'qemu-img <cmd>' twice, and could add a little
> more whitespace
>
> eg instead of:
>
> $ ./build/qemu-img check --help
> qemu-img check: Check basic image integrity. Usage:
> qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> [--output human|json] [--object OBJDEF] FILENAME
> Arguments:
> ...snip...
>
> have it look like
>
> $ ./build/qemu-img check --help
> Check basic image integrity.
>
> Usage:
>
> qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> [--output human|json] [--object OBJDEF] FILENAME
>
> Arguments:
> ...snip...
Here's the current way how `create' help text looks like:
$ ./qemu-img create --help
Create and format qemu image file. Usage:
qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
[--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
Arguments:
-h, --help
print this help and exit
-q, --quiet
quiet operations
-f, --format FMT
specifies format of the new image, default is raw
-o, --options FMT_OPTS
format-specific options ('-o list' for list)
-b, --backing BACKING_FILENAME
stack new image on top of BACKING_FILENAME
(for formats which support stacking)
-F, --backing-format BACKING_FMT
specify format of BACKING_FILENAME
-u, --backing-unsafe
do not fail if BACKING_FMT can not be read
--object OBJDEF
QEMU user-creatable object (eg encryption key)
FILENAME
image file to create. It will be overridden if exists
SIZE
image size with optional suffix (multiplies in 1024)
SIZE is required unless BACKING_IMG is specified,
in which case it will be the same as size of BACKING_IMG
Maybe it's a good idea to add newlines around the "syntax" part,
ie, after "Usage:" and before "Arguments:". I don't think it needs
extra newlines between each argument description though, - this way
it becomes just too long.
What do you think?
Thanks,
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include
2024-02-21 16:31 ` Michael Tokarev
@ 2024-02-21 16:45 ` Daniel P. Berrangé
0 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-21 16:45 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Wed, Feb 21, 2024 at 07:31:42PM +0300, Michael Tokarev wrote:
> 20.02.2024 21:48, Daniel P. Berrangé:
>
> > This ends up looking a bit muddled together. I don't think we
> > need repeat 'qemu-img <cmd>' twice, and could add a little
> > more whitespace
> >
> > eg instead of:
> >
> > $ ./build/qemu-img check --help
> > qemu-img check: Check basic image integrity. Usage:
> > qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> > [--output human|json] [--object OBJDEF] FILENAME
> > Arguments:
> > ...snip...
> >
> > have it look like
> >
> > $ ./build/qemu-img check --help
> > Check basic image integrity.
> >
> > Usage:
> >
> > qemu-img check [-f FMT | --image-opts] [-T CACHE_MODE] [-r] [-u]
> > [--output human|json] [--object OBJDEF] FILENAME
> >
> > Arguments:
> > ...snip...
>
> Here's the current way how `create' help text looks like:
>
> $ ./qemu-img create --help
> Create and format qemu image file. Usage:
> qemu-img create [-f FMT] [-o FMT_OPTS] [-b BACKING_FILENAME [-F BACKING_FMT]]
> [--object OBJDEF] [-u] FILENAME [SIZE[bkKMGTPE]]
> Arguments:
> -h, --help
> print this help and exit
> -q, --quiet
> quiet operations
> -f, --format FMT
> specifies format of the new image, default is raw
> -o, --options FMT_OPTS
> format-specific options ('-o list' for list)
> -b, --backing BACKING_FILENAME
> stack new image on top of BACKING_FILENAME
> (for formats which support stacking)
> -F, --backing-format BACKING_FMT
> specify format of BACKING_FILENAME
> -u, --backing-unsafe
> do not fail if BACKING_FMT can not be read
> --object OBJDEF
> QEMU user-creatable object (eg encryption key)
> FILENAME
> image file to create. It will be overridden if exists
> SIZE
> image size with optional suffix (multiplies in 1024)
> SIZE is required unless BACKING_IMG is specified,
> in which case it will be the same as size of BACKING_IMG
>
> Maybe it's a good idea to add newlines around the "syntax" part,
> ie, after "Usage:" and before "Arguments:". I don't think it needs
> extra newlines between each argument description though, - this way
> it becomes just too long.
>
> What do you think?
I still prefer to have more vertical whitespace, as I find it harder
to read through without it. I was using the typical man page option
/ usage formatting as a guide in my feedback.
Still, it would be useful to see what other maintainers think, as I'm
just one data point.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 00/23] qemu-img: refersh options and --help handling
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (22 preceding siblings ...)
2024-02-09 21:22 ` [PATCH 23/23] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include Michael Tokarev
@ 2024-02-09 22:26 ` Michael Tokarev
2024-02-20 18:53 ` Daniel P. Berrangé
24 siblings, 0 replies; 43+ messages in thread
From: Michael Tokarev @ 2024-02-09 22:26 UTC (permalink / raw)
To: qemu-devel, qemu-block
10.02.2024 00:22, Michael Tokarev wrote:
> Quite big patchset implementing normal, readable qemu-img --help
> (and qemu-img COMMAND --help) output with readable descriptions,
> and adding many long options in the process.
...
I forgot to run checkpatch.pl - minor edits, the result is at
https://gitlab.com/mjt0k/qemu/-/commits/qemu-img-options
/mjt
^ permalink raw reply [flat|nested] 43+ messages in thread
* Re: [PATCH 00/23] qemu-img: refersh options and --help handling
2024-02-09 21:22 [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
` (23 preceding siblings ...)
2024-02-09 22:26 ` [PATCH 00/23] qemu-img: refersh options and --help handling Michael Tokarev
@ 2024-02-20 18:53 ` Daniel P. Berrangé
24 siblings, 0 replies; 43+ messages in thread
From: Daniel P. Berrangé @ 2024-02-20 18:53 UTC (permalink / raw)
To: Michael Tokarev; +Cc: qemu-devel, qemu-block
On Sat, Feb 10, 2024 at 12:22:21AM +0300, Michael Tokarev wrote:
> Quite big patchset implementing normal, readable qemu-img --help
> (and qemu-img COMMAND --help) output with readable descriptions,
> and adding many long options in the process.
>
> In the end I stopped using qemu-img-opts.hx in qemu-img.c, perhaps
> this can be avoided, with only list of commands and their desrciptions
> kept there, but I don't see big advantage here. The same list should
> be included in docs/tools/qemu-img.rst, - this is not done now.
I think it'd be nice for qemu-img.c to be the canonical source
of truth, so we have the getopt short arg, long args, and
help all in the same place & thus much less likely to get
out of sync. Thus I like the approach you've taken here
to stop using the .hx file.
As a later work, it wouldn't be too terrible to have a python
script that parses qemu-img.c to look for 'cmd_help(...)' calls
and extra the help text, which could be used to feed into the
qemu-img.rxt man page generation, thus fully eliminating the
.hx file.
>
> Also each command syntax isn't reflected in the doc for now, because
> I want to give good names for options first, - and there, we've quite
> some inconsistences and questions. For example, measure --output=OFMT
> -O OFMT, - this is priceless :) I've no idea why we have this ugly
> --output=json thing, why not have --json? ;) I gave the desired
> format long name --target-format to avoid clash with --output.
>
> For rebase, src vs tgt probably should be renamed in local variables
> too, and I'm not even sure I've got the caches right. For caches,
> the thing is inconsistent across commands.
>
> For compare, I used --a-format/--b-format (for -f/-F), - this can
> be made --souce-format and --target-format, to compare source (file1)
> with target (file2).
>
> For bitmap, things are scary, I'm not sure what -b SRC_FILENAME
> really means, - for now I gave it --source option, but this does
> not make it more clear, suggestions welcome.
>
> There are many other inconsistencies, I can't fix them all in one
> go.. :)
This is already a massive improvement on the status quo. My
comments were mostly around whitespace/layout tweaks to the
help output.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 43+ messages in thread