From 16e57a98d0d1073317caece57f127bea8a8aeb45 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 18 Oct 2023 13:58:29 +0200 Subject: [PATCH] qemuBlockStorageSourceGetBackendProps: Unify cases for '!onlytarget' and '!legacy' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit At this point only a single code path (for formatting -drive for legacy SD cards) uses the 'legacy' output and that code path doesn't populate the node name. Thus we can unify the code block and simplify the JSON formatters. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_block.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 42c12a5e9b..61adbbfb7b 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1098,32 +1098,28 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src, if (driver && virJSONValueObjectPrependString(fileprops, "driver", driver) < 0) return NULL; - if (!onlytarget) { - if (qemuBlockNodeNameValidate(qemuBlockStorageSourceGetStorageNodename(src)) < 0 || - virJSONValueObjectAdd(&fileprops, - "S:node-name", qemuBlockStorageSourceGetStorageNodename(src), - NULL) < 0) + if (!onlytarget && !legacy) { + g_autoptr(virJSONValue) cache = NULL; + const char *discardstr = "unmap"; + const char *nodename = qemuBlockStorageSourceGetStorageNodename(src); + + if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP) + discardstr = NULL; + + if (qemuBlockNodeNameValidate(nodename) < 0) return NULL; - if (!legacy) { - g_autoptr(virJSONValue) cache = NULL; + if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0) + return NULL; - if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0) - return NULL; - - if (virJSONValueObjectAdd(&fileprops, - "A:cache", &cache, - "T:read-only", ro, - "T:auto-read-only", aro, - NULL) < 0) - return NULL; - - if (!(flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP) && - virJSONValueObjectAdd(&fileprops, - "s:discard", "unmap", - NULL) < 0) - return NULL; - } + if (virJSONValueObjectAdd(&fileprops, + "s:node-name", nodename, + "A:cache", &cache, + "T:read-only", ro, + "T:auto-read-only", aro, + "S:discard", discardstr, + NULL) < 0) + return NULL; } return g_steal_pointer(&fileprops);