diff options
author | Kevin Wolf <kwolf@redhat.com> | 2019-11-26 16:45:49 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2019-12-18 11:20:57 +0100 |
commit | f6dc1c31d3801dcbdf0c56574f9ff4f05180810c (patch) | |
tree | a55c541dd526950abc4d6197c4b24068f7291556 /block.c | |
parent | 0da7d13a4c2ff8ac40aeb1bd24c5564c82624555 (diff) | |
download | qemu-f6dc1c31d3801dcbdf0c56574f9ff4f05180810c.zip qemu-f6dc1c31d3801dcbdf0c56574f9ff4f05180810c.tar.gz qemu-f6dc1c31d3801dcbdf0c56574f9ff4f05180810c.tar.bz2 |
block: Error out on image creation with conflicting size options
If both the create options (qemu-img create -o ...) and the size
parameter were given, the size parameter was silently ignored. Instead,
make specifying two sizes an error.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -5751,12 +5751,11 @@ void bdrv_img_create(const char *filename, const char *fmt, return; } + /* Create parameter list */ create_opts = qemu_opts_append(create_opts, drv->create_opts); create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); - /* Create parameter list with default values */ opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); - qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort); /* Parse -o options */ if (options) { @@ -5766,6 +5765,13 @@ void bdrv_img_create(const char *filename, const char *fmt, } } + if (!qemu_opt_get(opts, BLOCK_OPT_SIZE)) { + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size, &error_abort); + } else if (img_size != UINT64_C(-1)) { + error_setg(errp, "The image size must be specified only once"); + goto out; + } + if (base_filename) { qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &local_err); if (local_err) { |