This makes adding new options easier. The only change in command line is
movement of -o or -F options to the end for creating images with backing
stores.
---
src/storage/storage_backend.c | 77 ++++++++++++++++------------------------
1 files changed, 31 insertions(+), 46 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index df79b28..9f598fc 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -810,61 +810,46 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
if (inputvol) {
virCommandAddArgList(cmd, "convert", "-f", inputType,
"-O", type,
inputPath, vol->target.path, NULL);
-
- if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS &&
- (do_encryption || preallocate)) {
- virCommandAddArg(cmd, "-o");
- virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ?
"encryption=on" : "",
- (do_encryption && preallocate) ? ","
: "",
- preallocate ? "preallocation=metadata" :
"");
- } else if (do_encryption) {
- virCommandAddArg(cmd, "-e");
- }
} else if (vol->backingStore.path) {
+ virCommandAddArgList(cmd, "create", "-f", type,
"-b",
+ vol->backingStore.path, vol->target.path, NULL);
+ virCommandAddArgFormat(cmd, "%lluK", size_arg);
+ } else {
virCommandAddArgList(cmd, "create", "-f", type,
- "-b", vol->backingStore.path, NULL);
-
- switch (imgformat) {
- case QEMU_IMG_BACKING_FORMAT_FLAG:
- virCommandAddArgList(cmd, "-F", backingType, vol->target.path,
- NULL);
- virCommandAddArgFormat(cmd, "%lluK", size_arg);
-
- if (do_encryption)
- virCommandAddArg(cmd, "-e");
- break;
+ vol->target.path, NULL);
+ virCommandAddArgFormat(cmd, "%lluK", size_arg);
+ }
- case QEMU_IMG_BACKING_FORMAT_OPTIONS:
+ if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS) {
+ if (inputvol) {
+ if (do_encryption || preallocate) {
+ virCommandAddArg(cmd, "-o");
+ virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ?
"encryption=on" : "",
+ (do_encryption && preallocate) ?
"," : "",
+ preallocate ? "preallocation=metadata" :
"");
+ }
+ } else if (vol->backingStore.path) {
virCommandAddArg(cmd, "-o");
virCommandAddArgFormat(cmd, "backing_fmt=%s%s", backingType,
do_encryption ? ",encryption=on" :
"");
- virCommandAddArg(cmd, vol->target.path);
- virCommandAddArgFormat(cmd, "%lluK", size_arg);
- break;
-
- default:
- VIR_INFO("Unable to set backing store format for %s with %s",
- vol->target.path, create_tool);
-
- virCommandAddArg(cmd, vol->target.path);
- virCommandAddArgFormat(cmd, "%lluK", size_arg);
- if (do_encryption)
- virCommandAddArg(cmd, "-e");
+ } else {
+ if (do_encryption || preallocate) {
+ virCommandAddArg(cmd, "-o");
+ virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ?
"encryption=on" : "",
+ (do_encryption && preallocate) ?
"," : "",
+ preallocate ? "preallocation=metadata" :
"");
+ }
}
} else {
- virCommandAddArgList(cmd, "create", "-f", type,
- vol->target.path, NULL);
- virCommandAddArgFormat(cmd, "%lluK", size_arg);
-
- if (imgformat == QEMU_IMG_BACKING_FORMAT_OPTIONS &&
- (do_encryption || preallocate)) {
- virCommandAddArg(cmd, "-o");
- virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ?
"encryption=on" : "",
- (do_encryption && preallocate) ? ","
: "",
- preallocate ? "preallocation=metadata" :
"");
- } else if (do_encryption) {
- virCommandAddArg(cmd, "-e");
+ if (!inputvol && vol->backingStore.path) {
+ if (imgformat == QEMU_IMG_BACKING_FORMAT_FLAG)
+ virCommandAddArgList(cmd, "-F", backingType, NULL);
+ else
+ VIR_INFO("Unable to set backing store format for %s with %s",
+ vol->target.path, create_tool);
}
+ if (do_encryption)
+ virCommandAddArg(cmd, "-e");
}
ret = virStorageBackendCreateExecCommand(pool, vol, cmd);
--
1.7.8.6