|
|
9ae3a8 |
From e8f877d31ff4ffbd7c09744f7244b21c728281be Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 25 Feb 2014 15:00:04 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 6/7] qemu-img: Allow -o help with incomplete argument list
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1393340405-9936-6-git-send-email-kwolf@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 57796
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.0 qemu-kvm PATCH 5/6] qemu-img: Allow -o help with incomplete argument list
|
|
|
9ae3a8 |
Bugzilla: 1065873
|
|
|
9ae3a8 |
RH-Acked-by: Juan Quintela <quintela@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This patch allows using 'qemu-img $subcmd -o help' for the create,
|
|
|
9ae3a8 |
convert and amend subcommands, without specifying the previously
|
|
|
9ae3a8 |
required filename arguments.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Note that it's still allowed and meaningful to specify a filename: An
|
|
|
9ae3a8 |
invocation like 'qemu-img create -o help sheepdog:foo' will also display
|
|
|
9ae3a8 |
options that are provided by the Sheepdog driver.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Jeff Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit a283cb6e58fca846c658360971d23fdd1129db65)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
qemu-img.c | 58 +++++++++++++++++++++++++++++++++++-----------------------
|
|
|
9ae3a8 |
1 file changed, 35 insertions(+), 23 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
qemu-img.c | 58 +++++++++++++++++++++++++++++++++++-----------------------
|
|
|
9ae3a8 |
1 files changed, 35 insertions(+), 23 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/qemu-img.c b/qemu-img.c
|
|
|
9ae3a8 |
index 5002a56..3dc325e 100644
|
|
|
9ae3a8 |
--- a/qemu-img.c
|
|
|
9ae3a8 |
+++ b/qemu-img.c
|
|
|
9ae3a8 |
@@ -244,16 +244,19 @@ static int print_block_option_help(const char *filename, const char *fmt)
|
|
|
9ae3a8 |
return 1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- proto_drv = bdrv_find_protocol(filename, true);
|
|
|
9ae3a8 |
- if (!proto_drv) {
|
|
|
9ae3a8 |
- error_report("Unknown protocol '%s'", filename);
|
|
|
9ae3a8 |
- return 1;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
create_options = append_option_parameters(create_options,
|
|
|
9ae3a8 |
drv->create_options);
|
|
|
9ae3a8 |
- create_options = append_option_parameters(create_options,
|
|
|
9ae3a8 |
- proto_drv->create_options);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (filename) {
|
|
|
9ae3a8 |
+ proto_drv = bdrv_find_protocol(filename, true);
|
|
|
9ae3a8 |
+ if (!proto_drv) {
|
|
|
9ae3a8 |
+ error_report("Unknown protocol '%s'", filename);
|
|
|
9ae3a8 |
+ return 1;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ create_options = append_option_parameters(create_options,
|
|
|
9ae3a8 |
+ proto_drv->create_options);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
print_option_help(create_options);
|
|
|
9ae3a8 |
free_option_parameters(create_options);
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
@@ -390,10 +393,16 @@ static int img_create(int argc, char **argv)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Get the filename */
|
|
|
9ae3a8 |
+ filename = (optind < argc) ? argv[optind] : NULL;
|
|
|
9ae3a8 |
+ if (options && has_help_option(options)) {
|
|
|
9ae3a8 |
+ g_free(options);
|
|
|
9ae3a8 |
+ return print_block_option_help(filename, fmt);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (optind >= argc) {
|
|
|
9ae3a8 |
help();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
- filename = argv[optind++];
|
|
|
9ae3a8 |
+ optind++;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Get image size, if specified */
|
|
|
9ae3a8 |
if (optind < argc) {
|
|
|
9ae3a8 |
@@ -416,11 +425,6 @@ static int img_create(int argc, char **argv)
|
|
|
9ae3a8 |
help();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (options && has_help_option(options)) {
|
|
|
9ae3a8 |
- g_free(options);
|
|
|
9ae3a8 |
- return print_block_option_help(filename, fmt);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
bdrv_img_create(filename, fmt, base_filename, base_fmt,
|
|
|
9ae3a8 |
options, img_size, BDRV_O_FLAGS, &local_err, quiet);
|
|
|
9ae3a8 |
if (error_is_set(&local_err)) {
|
|
|
9ae3a8 |
@@ -1251,17 +1255,18 @@ static int img_convert(int argc, char **argv)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bs_n = argc - optind - 1;
|
|
|
9ae3a8 |
- if (bs_n < 1) {
|
|
|
9ae3a8 |
- help();
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- out_filename = argv[argc - 1];
|
|
|
9ae3a8 |
+ out_filename = bs_n >= 1 ? argv[argc - 1] : NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (options && has_help_option(options)) {
|
|
|
9ae3a8 |
ret = print_block_option_help(out_filename, out_fmt);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ if (bs_n < 1) {
|
|
|
9ae3a8 |
+ help();
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (bs_n > 1 && out_baseimg) {
|
|
|
9ae3a8 |
error_report("-B makes no sense when concatenating multiple input "
|
|
|
9ae3a8 |
"images");
|
|
|
9ae3a8 |
@@ -2639,15 +2644,21 @@ static int img_amend(int argc, char **argv)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (optind != argc - 1) {
|
|
|
9ae3a8 |
+ if (!options) {
|
|
|
9ae3a8 |
help();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (!options) {
|
|
|
9ae3a8 |
- help();
|
|
|
9ae3a8 |
+ filename = (optind == argc - 1) ? argv[argc - 1] : NULL;
|
|
|
9ae3a8 |
+ if (fmt && has_help_option(options)) {
|
|
|
9ae3a8 |
+ /* If a format is explicitly specified (and possibly no filename is
|
|
|
9ae3a8 |
+ * given), print option help here */
|
|
|
9ae3a8 |
+ ret = print_block_option_help(filename, fmt);
|
|
|
9ae3a8 |
+ goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- filename = argv[argc - 1];
|
|
|
9ae3a8 |
+ if (optind != argc - 1) {
|
|
|
9ae3a8 |
+ help();
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
|
|
|
9ae3a8 |
if (!bs) {
|
|
|
9ae3a8 |
@@ -2659,6 +2670,7 @@ static int img_amend(int argc, char **argv)
|
|
|
9ae3a8 |
fmt = bs->drv->format_name;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
if (has_help_option(options)) {
|
|
|
9ae3a8 |
+ /* If the format was auto-detected, print option help here */
|
|
|
9ae3a8 |
ret = print_block_option_help(filename, fmt);
|
|
|
9ae3a8 |
goto out;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|