]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuBlockStorageSourceGetBackendProps: Unify cases for '!onlytarget' and '!legacy'
authorPeter Krempa <pkrempa@redhat.com>
Wed, 18 Oct 2023 11:58:29 +0000 (13:58 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 2 Nov 2023 14:24:09 +0000 (15:24 +0100)
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>
src/qemu/qemu_block.c

index 42c12a5e9bed7e3d7eb32e3b3be09d1a505c3183..61adbbfb7bcbb6a61889e8300e1a43de582ca5a6 100644 (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)
-            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);