From: Peter Krempa Date: Wed, 18 Oct 2023 11:58:29 +0000 (+0200) Subject: qemuBlockStorageSourceGetBackendProps: Unify cases for '!onlytarget' and '!legacy' X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=16e57a98d0d1073317caece57f127bea8a8aeb45;p=libvirt.git qemuBlockStorageSourceGetBackendProps: Unify cases for '!onlytarget' and '!legacy' 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 --- 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) - return NULL; + if (!onlytarget && !legacy) { + g_autoptr(virJSONValue) cache = NULL; + const char *discardstr = "unmap"; + const char *nodename = qemuBlockStorageSourceGetStorageNodename(src); - if (!legacy) { - g_autoptr(virJSONValue) cache = NULL; + if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP) + discardstr = NULL; - if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0) - return NULL; + if (qemuBlockNodeNameValidate(nodename) < 0) + return NULL; - if (virJSONValueObjectAdd(&fileprops, - "A:cache", &cache, - "T:read-only", ro, - "T:auto-read-only", aro, - NULL) < 0) - return NULL; + if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 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);