From 6e6e55f5c2e5b520d6506c2716287ba3b5d1bbc8 Mon Sep 17 00:00:00 2001 From: John Snow Date: Mon, 17 Jul 2017 20:34:22 -0400 Subject: qemu-img: Check for backing image if specified during create Or, rather, force the open of a backing image if one was specified for creation. Using a similar -unsafe option as rebase, allow qemu-img to ignore the backing file validation if possible. It may not always be possible, as in the existing case when a filesize for the new image was not specified. This is accomplished by shifting around the conditionals in bdrv_img_create, such that a backing file is always opened unless we provide BDRV_O_NO_BACKING. qemu-img is adjusted to pass this new flag when -u is provided to create. Sorry for the heinous looking diffstat, but it's mostly whitespace. Inspired by: https://bugzilla.redhat.com/show_bug.cgi?id=1213786 Signed-off-by: John Snow Signed-off-by: Kevin Wolf --- qemu-img.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'qemu-img.c') diff --git a/qemu-img.c b/qemu-img.c index 182e697f81..eb32b93e90 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -150,9 +150,11 @@ static void QEMU_NORETURN help(void) " 'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n" " instead\n" " '-c' indicates that target image must be compressed (qcow format only)\n" - " '-u' enables unsafe rebasing. It is assumed that old and new backing file\n" - " match exactly. The image doesn't need a working backing file before\n" - " rebasing in this case (useful for renaming the backing file)\n" + " '-u' allows unsafe backing chains. For rebasing, it is assumed that old and\n" + " new backing file match exactly. The image doesn't need a working\n" + " backing file before rebasing in this case (useful for renaming the\n" + " backing file). For image creation, allow creating without attempting\n" + " to open the backing file.\n" " '-h' with or without a command shows this help and lists the supported formats\n" " '-p' show progress of command (only certain commands)\n" " '-q' use Quiet mode - do not print any output (except errors)\n" @@ -429,6 +431,7 @@ static int img_create(int argc, char **argv) char *options = NULL; Error *local_err = NULL; bool quiet = false; + int flags = 0; for(;;) { static const struct option long_options[] = { @@ -436,7 +439,7 @@ static int img_create(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c = getopt_long(argc, argv, ":F:b:f:ho:q", + c = getopt_long(argc, argv, ":F:b:f:ho:qu", long_options, NULL); if (c == -1) { break; @@ -476,6 +479,9 @@ static int img_create(int argc, char **argv) case 'q': quiet = true; break; + case 'u': + flags |= BDRV_O_NO_BACKING; + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -528,7 +534,7 @@ static int img_create(int argc, char **argv) } bdrv_img_create(filename, fmt, base_filename, base_fmt, - options, img_size, 0, quiet, &local_err); + options, img_size, flags, quiet, &local_err); if (local_err) { error_reportf_err(local_err, "%s: ", filename); goto fail; -- cgit v1.2.1