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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-10-18 13:58:29 +02:00
parent ca4cb3d7dc
commit 16e57a98d0

View File

@ -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);