From d3547505218da25c710c530778abd7aeda9dd37d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 12 Sep 2023 16:36:31 +0200 Subject: [PATCH] qemu: block: Refactor logic in qemuBlockStorageSourceGetBlockdevProps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restructure the conditions so that we can use virJSONValueObjectAdd with a clearer logic for backing store control. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_block.c | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 7e870baa2f..9b6d901e8c 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1309,38 +1309,40 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSource *src, virStorageSource *backingStore) { g_autoptr(virJSONValue) props = NULL; + const char *backingFormatterStr = NULL; + const char *backingNodename = NULL; const char *storagenode = src->nodestorage; if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) storagenode = src->sliceStorage->nodename; + if (virStorageSourceIsBacking(backingStore) && + src->format < VIR_STORAGE_FILE_BACKING) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("storage format '%1$s' does not support backing store"), + virStorageFileFormatTypeToString(src->format)); + return NULL; + } + + if (backingStore && + src->format >= VIR_STORAGE_FILE_BACKING) { + if (virStorageSourceIsBacking(backingStore)) { + backingFormatterStr = "s:backing"; + backingNodename = backingStore->nodeformat; + } else { + /* chain is terminated, indicate that no detection should happen in qemu */ + backingFormatterStr = "n:backing"; + } + } + if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src))) return NULL; - if (virJSONValueObjectAppendString(props, "file", storagenode) < 0) - return NULL; - - if (backingStore) { - if (src->format >= VIR_STORAGE_FILE_BACKING) { - if (virStorageSourceIsBacking(backingStore)) { - if (virJSONValueObjectAppendString(props, "backing", - backingStore->nodeformat) < 0) - return NULL; - } else { - /* chain is terminated, indicate that no detection should happen - * in qemu */ - if (virJSONValueObjectAppendNull(props, "backing") < 0) - return NULL; - } - } else { - if (virStorageSourceIsBacking(backingStore)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("storage format '%1$s' does not support backing store"), - virStorageFileFormatTypeToString(src->format)); - return NULL; - } - } - } + if (virJSONValueObjectAdd(&props, + "s:file", storagenode, + backingFormatterStr, backingNodename, + NULL) < 0) + return 0; return g_steal_pointer(&props); }