--- src/storage/storage_backend.c | 36 ++++++++++++++++++------------------ 1 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 9f598fc..a7e9493 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -669,6 +669,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, bool do_encryption = (vol->target.encryption != NULL); unsigned long long int size_arg; bool preallocate = false; + char *options; + virBuffer buf = VIR_BUFFER_INITIALIZER; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, -1); @@ -821,25 +823,23 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, } 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" : ""); - } else { - if (do_encryption || preallocate) { - virCommandAddArg(cmd, "-o"); - virCommandAddArgFormat(cmd, "%s%s%s", do_encryption ? "encryption=on" : "", - (do_encryption && preallocate) ? "," : "", - preallocate ? "preallocation=metadata" : ""); - } + if (do_encryption) + virBufferAddLit(&buf, ",encryption=on"); + + if (!inputvol && vol->backingStore.path) + virBufferAsprintf(&buf, ",backing_fmt=%s", backingType); + else if (preallocate) + virBufferAddLit(&buf, ",preallocation=metadata"); + + if (virBufferError(&buf) > 0) { + virReportOOMError(); + goto cleanup; } + + if ((options = virBufferContentAndReset(&buf))) + virCommandAddArgList(cmd, "-o", &(options[1]), NULL); + + VIR_FREE(options); } else { if (!inputvol && vol->backingStore.path) { if (imgformat == QEMU_IMG_BACKING_FORMAT_FLAG) -- 1.7.8.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list