Commit db08adf526ce78eea7ae5f24e30b8caa1af4cf24
Committed by
Blue Swirl
1 parent
f425c278
qemu-img: Print available options with -o ?
This patch adds a small help text to each of the options in the block drivers which can be displayed by using qemu-img create -f fmt -o ? Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Showing
10 changed files
with
110 additions
and
19 deletions
block/cow.c
| @@ -262,8 +262,16 @@ static void cow_flush(BlockDriverState *bs) | @@ -262,8 +262,16 @@ static void cow_flush(BlockDriverState *bs) | ||
| 262 | } | 262 | } |
| 263 | 263 | ||
| 264 | static QEMUOptionParameter cow_create_options[] = { | 264 | static QEMUOptionParameter cow_create_options[] = { |
| 265 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | ||
| 266 | - { BLOCK_OPT_BACKING_FILE, OPT_STRING }, | 265 | + { |
| 266 | + .name = BLOCK_OPT_SIZE, | ||
| 267 | + .type = OPT_SIZE, | ||
| 268 | + .help = "Virtual disk size" | ||
| 269 | + }, | ||
| 270 | + { | ||
| 271 | + .name = BLOCK_OPT_BACKING_FILE, | ||
| 272 | + .type = OPT_STRING, | ||
| 273 | + .help = "File name of a base image" | ||
| 274 | + }, | ||
| 267 | { NULL } | 275 | { NULL } |
| 268 | }; | 276 | }; |
| 269 | 277 |
block/qcow.c
| @@ -909,9 +909,21 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) | @@ -909,9 +909,21 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) | ||
| 909 | 909 | ||
| 910 | 910 | ||
| 911 | static QEMUOptionParameter qcow_create_options[] = { | 911 | static QEMUOptionParameter qcow_create_options[] = { |
| 912 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | ||
| 913 | - { BLOCK_OPT_BACKING_FILE, OPT_STRING }, | ||
| 914 | - { BLOCK_OPT_ENCRYPT, OPT_FLAG }, | 912 | + { |
| 913 | + .name = BLOCK_OPT_SIZE, | ||
| 914 | + .type = OPT_SIZE, | ||
| 915 | + .help = "Virtual disk size" | ||
| 916 | + }, | ||
| 917 | + { | ||
| 918 | + .name = BLOCK_OPT_BACKING_FILE, | ||
| 919 | + .type = OPT_STRING, | ||
| 920 | + .help = "File name of a base image" | ||
| 921 | + }, | ||
| 922 | + { | ||
| 923 | + .name = BLOCK_OPT_ENCRYPT, | ||
| 924 | + .type = OPT_FLAG, | ||
| 925 | + .help = "Encrypt the image" | ||
| 926 | + }, | ||
| 915 | { NULL } | 927 | { NULL } |
| 916 | }; | 928 | }; |
| 917 | 929 |
block/qcow2.c
| @@ -2981,11 +2981,31 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, | @@ -2981,11 +2981,31 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, | ||
| 2981 | } | 2981 | } |
| 2982 | 2982 | ||
| 2983 | static QEMUOptionParameter qcow_create_options[] = { | 2983 | static QEMUOptionParameter qcow_create_options[] = { |
| 2984 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | ||
| 2985 | - { BLOCK_OPT_BACKING_FILE, OPT_STRING }, | ||
| 2986 | - { BLOCK_OPT_BACKING_FMT, OPT_STRING }, | ||
| 2987 | - { BLOCK_OPT_ENCRYPT, OPT_FLAG }, | ||
| 2988 | - { BLOCK_OPT_CLUSTER_SIZE, OPT_SIZE }, | 2984 | + { |
| 2985 | + .name = BLOCK_OPT_SIZE, | ||
| 2986 | + .type = OPT_SIZE, | ||
| 2987 | + .help = "Virtual disk size" | ||
| 2988 | + }, | ||
| 2989 | + { | ||
| 2990 | + .name = BLOCK_OPT_BACKING_FILE, | ||
| 2991 | + .type = OPT_STRING, | ||
| 2992 | + .help = "File name of a base image" | ||
| 2993 | + }, | ||
| 2994 | + { | ||
| 2995 | + .name = BLOCK_OPT_BACKING_FMT, | ||
| 2996 | + .type = OPT_STRING, | ||
| 2997 | + .help = "Image format of the base image" | ||
| 2998 | + }, | ||
| 2999 | + { | ||
| 3000 | + .name = BLOCK_OPT_ENCRYPT, | ||
| 3001 | + .type = OPT_FLAG, | ||
| 3002 | + .help = "Encrypt the image" | ||
| 3003 | + }, | ||
| 3004 | + { | ||
| 3005 | + .name = BLOCK_OPT_CLUSTER_SIZE, | ||
| 3006 | + .type = OPT_SIZE, | ||
| 3007 | + .help = "qcow2 cluster size" | ||
| 3008 | + }, | ||
| 2989 | { NULL } | 3009 | { NULL } |
| 2990 | }; | 3010 | }; |
| 2991 | 3011 |
block/raw-posix.c
| @@ -858,7 +858,11 @@ static void raw_flush(BlockDriverState *bs) | @@ -858,7 +858,11 @@ static void raw_flush(BlockDriverState *bs) | ||
| 858 | 858 | ||
| 859 | 859 | ||
| 860 | static QEMUOptionParameter raw_create_options[] = { | 860 | static QEMUOptionParameter raw_create_options[] = { |
| 861 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | 861 | + { |
| 862 | + .name = BLOCK_OPT_SIZE, | ||
| 863 | + .type = OPT_SIZE, | ||
| 864 | + .help = "Virtual disk size" | ||
| 865 | + }, | ||
| 862 | { NULL } | 866 | { NULL } |
| 863 | }; | 867 | }; |
| 864 | 868 |
block/raw-win32.c
| @@ -234,7 +234,11 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) | @@ -234,7 +234,11 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) | ||
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | static QEMUOptionParameter raw_create_options[] = { | 236 | static QEMUOptionParameter raw_create_options[] = { |
| 237 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | 237 | + { |
| 238 | + .name = BLOCK_OPT_SIZE, | ||
| 239 | + .type = OPT_SIZE, | ||
| 240 | + .help = "Virtual disk size" | ||
| 241 | + }, | ||
| 238 | { NULL } | 242 | { NULL } |
| 239 | }; | 243 | }; |
| 240 | 244 |
block/vmdk.c
| @@ -828,9 +828,21 @@ static void vmdk_flush(BlockDriverState *bs) | @@ -828,9 +828,21 @@ static void vmdk_flush(BlockDriverState *bs) | ||
| 828 | 828 | ||
| 829 | 829 | ||
| 830 | static QEMUOptionParameter vmdk_create_options[] = { | 830 | static QEMUOptionParameter vmdk_create_options[] = { |
| 831 | - { BLOCK_OPT_SIZE, OPT_SIZE }, | ||
| 832 | - { BLOCK_OPT_BACKING_FILE, OPT_STRING }, | ||
| 833 | - { BLOCK_OPT_COMPAT6, OPT_FLAG }, | 831 | + { |
| 832 | + .name = BLOCK_OPT_SIZE, | ||
| 833 | + .type = OPT_SIZE, | ||
| 834 | + .help = "Virtual disk size" | ||
| 835 | + }, | ||
| 836 | + { | ||
| 837 | + .name = BLOCK_OPT_BACKING_FILE, | ||
| 838 | + .type = OPT_STRING, | ||
| 839 | + .help = "File name of a base image" | ||
| 840 | + }, | ||
| 841 | + { | ||
| 842 | + .name = BLOCK_OPT_COMPAT6, | ||
| 843 | + .type = OPT_FLAG, | ||
| 844 | + .help = "VMDK version 6 image" | ||
| 845 | + }, | ||
| 834 | { NULL } | 846 | { NULL } |
| 835 | }; | 847 | }; |
| 836 | 848 |
block/vpc.c
| @@ -594,7 +594,11 @@ static void vpc_close(BlockDriverState *bs) | @@ -594,7 +594,11 @@ static void vpc_close(BlockDriverState *bs) | ||
| 594 | } | 594 | } |
| 595 | 595 | ||
| 596 | static QEMUOptionParameter vpc_create_options[] = { | 596 | static QEMUOptionParameter vpc_create_options[] = { |
| 597 | - { "size", OPT_SIZE }, | 597 | + { |
| 598 | + .name = BLOCK_OPT_SIZE, | ||
| 599 | + .type = OPT_SIZE, | ||
| 600 | + .help = "Virtual disk size" | ||
| 601 | + }, | ||
| 598 | { NULL } | 602 | { NULL } |
| 599 | }; | 603 | }; |
| 600 | 604 |
qemu-img.c
| @@ -281,15 +281,17 @@ static int img_create(int argc, char **argv) | @@ -281,15 +281,17 @@ static int img_create(int argc, char **argv) | ||
| 281 | break; | 281 | break; |
| 282 | } | 282 | } |
| 283 | } | 283 | } |
| 284 | - if (optind >= argc) | ||
| 285 | - help(); | ||
| 286 | - filename = argv[optind++]; | ||
| 287 | 284 | ||
| 288 | /* Find driver and parse its options */ | 285 | /* Find driver and parse its options */ |
| 289 | drv = bdrv_find_format(fmt); | 286 | drv = bdrv_find_format(fmt); |
| 290 | if (!drv) | 287 | if (!drv) |
| 291 | error("Unknown file format '%s'", fmt); | 288 | error("Unknown file format '%s'", fmt); |
| 292 | 289 | ||
| 290 | + if (options && !strcmp(options, "?")) { | ||
| 291 | + print_option_help(drv->create_options); | ||
| 292 | + return 0; | ||
| 293 | + } | ||
| 294 | + | ||
| 293 | if (options) { | 295 | if (options) { |
| 294 | param = parse_option_parameters(options, drv->create_options, param); | 296 | param = parse_option_parameters(options, drv->create_options, param); |
| 295 | if (param == NULL) { | 297 | if (param == NULL) { |
| @@ -299,6 +301,11 @@ static int img_create(int argc, char **argv) | @@ -299,6 +301,11 @@ static int img_create(int argc, char **argv) | ||
| 299 | param = parse_option_parameters("", drv->create_options, param); | 301 | param = parse_option_parameters("", drv->create_options, param); |
| 300 | } | 302 | } |
| 301 | 303 | ||
| 304 | + /* Get the filename */ | ||
| 305 | + if (optind >= argc) | ||
| 306 | + help(); | ||
| 307 | + filename = argv[optind++]; | ||
| 308 | + | ||
| 302 | /* Add size to parameters */ | 309 | /* Add size to parameters */ |
| 303 | if (optind < argc) { | 310 | if (optind < argc) { |
| 304 | set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]); | 311 | set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]); |
| @@ -596,6 +603,11 @@ static int img_convert(int argc, char **argv) | @@ -596,6 +603,11 @@ static int img_convert(int argc, char **argv) | ||
| 596 | if (!drv) | 603 | if (!drv) |
| 597 | error("Unknown file format '%s'", out_fmt); | 604 | error("Unknown file format '%s'", out_fmt); |
| 598 | 605 | ||
| 606 | + if (options && !strcmp(options, "?")) { | ||
| 607 | + print_option_help(drv->create_options); | ||
| 608 | + return 0; | ||
| 609 | + } | ||
| 610 | + | ||
| 599 | if (options) { | 611 | if (options) { |
| 600 | param = parse_option_parameters(options, drv->create_options, param); | 612 | param = parse_option_parameters(options, drv->create_options, param); |
| 601 | if (param == NULL) { | 613 | if (param == NULL) { |
qemu-option.c
| @@ -347,3 +347,16 @@ void print_option_parameters(QEMUOptionParameter *list) | @@ -347,3 +347,16 @@ void print_option_parameters(QEMUOptionParameter *list) | ||
| 347 | list++; | 347 | list++; |
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| 350 | + | ||
| 351 | +/* | ||
| 352 | + * Prints an overview of all available options | ||
| 353 | + */ | ||
| 354 | +void print_option_help(QEMUOptionParameter *list) | ||
| 355 | +{ | ||
| 356 | + printf("Supported options:\n"); | ||
| 357 | + while (list && list->name) { | ||
| 358 | + printf("%-16s %s\n", list->name, | ||
| 359 | + list->help ? list->help : "No description available"); | ||
| 360 | + list++; | ||
| 361 | + } | ||
| 362 | +} |
qemu-option.h
| @@ -40,6 +40,7 @@ typedef struct QEMUOptionParameter { | @@ -40,6 +40,7 @@ typedef struct QEMUOptionParameter { | ||
| 40 | uint64_t n; | 40 | uint64_t n; |
| 41 | char* s; | 41 | char* s; |
| 42 | } value; | 42 | } value; |
| 43 | + const char *help; | ||
| 43 | } QEMUOptionParameter; | 44 | } QEMUOptionParameter; |
| 44 | 45 | ||
| 45 | 46 | ||
| @@ -63,5 +64,6 @@ QEMUOptionParameter *parse_option_parameters(const char *param, | @@ -63,5 +64,6 @@ QEMUOptionParameter *parse_option_parameters(const char *param, | ||
| 63 | QEMUOptionParameter *list, QEMUOptionParameter *dest); | 64 | QEMUOptionParameter *list, QEMUOptionParameter *dest); |
| 64 | void free_option_parameters(QEMUOptionParameter *list); | 65 | void free_option_parameters(QEMUOptionParameter *list); |
| 65 | void print_option_parameters(QEMUOptionParameter *list); | 66 | void print_option_parameters(QEMUOptionParameter *list); |
| 67 | +void print_option_help(QEMUOptionParameter *list); | ||
| 66 | 68 | ||
| 67 | #endif | 69 | #endif |