--- qemu/qemu-img.c 2018/04/24 17:20:53 1.1.1.8 +++ qemu/qemu-img.c 2018/04/24 17:34:36 1.1.1.9 @@ -71,16 +71,10 @@ static void help(void) "\n" "Command parameters:\n" " 'filename' is a disk image filename\n" - " 'base_image' is the read-only disk image which is used as base for a copy on\n" - " write image; the copy on write image only stores the modified data\n" - " 'output_base_image' forces the output image to be created as a copy on write\n" - " image of the specified base image; 'output_base_image' should have the same\n" - " content as the input's base image, however the path, image format, etc may\n" - " differ\n" " 'fmt' is the disk image format. It is guessed automatically in most cases\n" - " 'size' is the disk image size in kilobytes. Optional suffixes\n" - " 'M' (megabyte, 1024 * 1024) and 'G' (gigabyte, 1024 * 1024 * 1024) are\n" - " supported any 'k' or 'K' is ignored\n" + " 'size' is the disk image size in bytes. Optional suffixes\n" + " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n" + " and T (terabyte, 1024G) are 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" @@ -297,13 +291,16 @@ static int img_create(int argc, char **a return 0; } + /* Create parameter list with default values */ + param = parse_option_parameters("", drv->create_options, param); + set_option_parameter_int(param, BLOCK_OPT_SIZE, -1); + + /* Parse -o options */ if (options) { param = parse_option_parameters(options, drv->create_options, param); if (param == NULL) { error("Invalid options for file format '%s'.", fmt); } - } else { - param = parse_option_parameters("", drv->create_options, param); } /* Get the filename */ @@ -321,7 +318,7 @@ static int img_create(int argc, char **a // The size for the image must always be specified, with one exception: // If we are using a backing file, we can obtain the size from there - if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == 0) { + if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == -1) { QEMUOptionParameter *backing_file = get_option_parameter(param, BLOCK_OPT_BACKING_FILE); @@ -530,7 +527,7 @@ static int is_allocated_sectors(const ui return v; } -#define IO_BUF_SIZE 65536 +#define IO_BUF_SIZE (2 * 1024 * 1024) static int img_convert(int argc, char **argv) { @@ -610,6 +607,7 @@ static int img_convert(int argc, char ** if (options && !strcmp(options, "?")) { print_option_help(drv->create_options); + free(bs); return 0; } @@ -746,7 +744,7 @@ static int img_convert(int argc, char ** if (n > bs_offset + bs_sectors - sector_num) n = bs_offset + bs_sectors - sector_num; - if (strcmp(drv->format_name, "host_device")) { + if (!drv->no_zero_init) { /* If the output image is being created as a copy on write image, assume that sectors which are unallocated in the input image are present in both the output's and input's base images (no @@ -779,7 +777,7 @@ static int img_convert(int argc, char ** If the output is to a host device, we also write out sectors that are entirely 0, since whatever data was already there is garbage, not 0s. */ - if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg || + if (drv->no_zero_init || out_baseimg || is_allocated_sectors(buf1, n, &n1)) { if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) error("error while writing");