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>
This commit is contained in:
		
							parent
							
								
									f425c27872
								
							
						
					
					
						commit
						db08adf526
					
				
							
								
								
									
										12
									
								
								block/cow.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								block/cow.c
									
									
									
									
									
								
							| @ -262,8 +262,16 @@ static void cow_flush(BlockDriverState *bs) | ||||
| } | ||||
| 
 | ||||
| static QEMUOptionParameter cow_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { BLOCK_OPT_BACKING_FILE,   OPT_STRING }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_BACKING_FILE, | ||||
|         .type = OPT_STRING, | ||||
|         .help = "File name of a base image" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								block/qcow.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								block/qcow.c
									
									
									
									
									
								
							| @ -909,9 +909,21 @@ static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) | ||||
| 
 | ||||
| 
 | ||||
| static QEMUOptionParameter qcow_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { BLOCK_OPT_BACKING_FILE,   OPT_STRING }, | ||||
|     { BLOCK_OPT_ENCRYPT,        OPT_FLAG }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_BACKING_FILE, | ||||
|         .type = OPT_STRING, | ||||
|         .help = "File name of a base image" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_ENCRYPT, | ||||
|         .type = OPT_FLAG, | ||||
|         .help = "Encrypt the image" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -2981,11 +2981,31 @@ static int qcow_get_buffer(BlockDriverState *bs, uint8_t *buf, | ||||
| } | ||||
| 
 | ||||
| static QEMUOptionParameter qcow_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { BLOCK_OPT_BACKING_FILE,   OPT_STRING }, | ||||
|     { BLOCK_OPT_BACKING_FMT,    OPT_STRING }, | ||||
|     { BLOCK_OPT_ENCRYPT,        OPT_FLAG }, | ||||
|     { BLOCK_OPT_CLUSTER_SIZE,   OPT_SIZE }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_BACKING_FILE, | ||||
|         .type = OPT_STRING, | ||||
|         .help = "File name of a base image" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_BACKING_FMT, | ||||
|         .type = OPT_STRING, | ||||
|         .help = "Image format of the base image" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_ENCRYPT, | ||||
|         .type = OPT_FLAG, | ||||
|         .help = "Encrypt the image" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_CLUSTER_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "qcow2 cluster size" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -858,7 +858,11 @@ static void raw_flush(BlockDriverState *bs) | ||||
| 
 | ||||
| 
 | ||||
| static QEMUOptionParameter raw_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -234,7 +234,11 @@ static int raw_create(const char *filename, QEMUOptionParameter *options) | ||||
| } | ||||
| 
 | ||||
| static QEMUOptionParameter raw_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								block/vmdk.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								block/vmdk.c
									
									
									
									
									
								
							| @ -828,9 +828,21 @@ static void vmdk_flush(BlockDriverState *bs) | ||||
| 
 | ||||
| 
 | ||||
| static QEMUOptionParameter vmdk_create_options[] = { | ||||
|     { BLOCK_OPT_SIZE,           OPT_SIZE }, | ||||
|     { BLOCK_OPT_BACKING_FILE,   OPT_STRING }, | ||||
|     { BLOCK_OPT_COMPAT6,        OPT_FLAG }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_BACKING_FILE, | ||||
|         .type = OPT_STRING, | ||||
|         .help = "File name of a base image" | ||||
|     }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_COMPAT6, | ||||
|         .type = OPT_FLAG, | ||||
|         .help = "VMDK version 6 image" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -594,7 +594,11 @@ static void vpc_close(BlockDriverState *bs) | ||||
| } | ||||
| 
 | ||||
| static QEMUOptionParameter vpc_create_options[] = { | ||||
|     { "size", OPT_SIZE }, | ||||
|     { | ||||
|         .name = BLOCK_OPT_SIZE, | ||||
|         .type = OPT_SIZE, | ||||
|         .help = "Virtual disk size" | ||||
|     }, | ||||
|     { NULL } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										18
									
								
								qemu-img.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								qemu-img.c
									
									
									
									
									
								
							| @ -281,15 +281,17 @@ static int img_create(int argc, char **argv) | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|     if (optind >= argc) | ||||
|         help(); | ||||
|     filename = argv[optind++]; | ||||
| 
 | ||||
|     /* Find driver and parse its options */ | ||||
|     drv = bdrv_find_format(fmt); | ||||
|     if (!drv) | ||||
|         error("Unknown file format '%s'", fmt); | ||||
| 
 | ||||
|     if (options && !strcmp(options, "?")) { | ||||
|         print_option_help(drv->create_options); | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     if (options) { | ||||
|         param = parse_option_parameters(options, drv->create_options, param); | ||||
|         if (param == NULL) { | ||||
| @ -299,6 +301,11 @@ static int img_create(int argc, char **argv) | ||||
|         param = parse_option_parameters("", drv->create_options, param); | ||||
|     } | ||||
| 
 | ||||
|     /* Get the filename */ | ||||
|     if (optind >= argc) | ||||
|         help(); | ||||
|     filename = argv[optind++]; | ||||
| 
 | ||||
|     /* Add size to parameters */ | ||||
|     if (optind < argc) { | ||||
|         set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]); | ||||
| @ -596,6 +603,11 @@ static int img_convert(int argc, char **argv) | ||||
|     if (!drv) | ||||
|         error("Unknown file format '%s'", out_fmt); | ||||
| 
 | ||||
|     if (options && !strcmp(options, "?")) { | ||||
|         print_option_help(drv->create_options); | ||||
|         return 0; | ||||
|     } | ||||
| 
 | ||||
|     if (options) { | ||||
|         param = parse_option_parameters(options, drv->create_options, param); | ||||
|         if (param == NULL) { | ||||
|  | ||||
| @ -347,3 +347,16 @@ void print_option_parameters(QEMUOptionParameter *list) | ||||
|         list++; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  * Prints an overview of all available options | ||||
|  */ | ||||
| void print_option_help(QEMUOptionParameter *list) | ||||
| { | ||||
|     printf("Supported options:\n"); | ||||
|     while (list && list->name) { | ||||
|         printf("%-16s %s\n", list->name, | ||||
|             list->help ? list->help : "No description available"); | ||||
|         list++; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -40,6 +40,7 @@ typedef struct QEMUOptionParameter { | ||||
|         uint64_t n; | ||||
|         char* s; | ||||
|     } value; | ||||
|     const char *help; | ||||
| } QEMUOptionParameter; | ||||
| 
 | ||||
| 
 | ||||
| @ -63,5 +64,6 @@ QEMUOptionParameter *parse_option_parameters(const char *param, | ||||
|     QEMUOptionParameter *list, QEMUOptionParameter *dest); | ||||
| void free_option_parameters(QEMUOptionParameter *list); | ||||
| void print_option_parameters(QEMUOptionParameter *list); | ||||
| void print_option_help(QEMUOptionParameter *list); | ||||
| 
 | ||||
| #endif | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Kevin Wolf
						Kevin Wolf