[PATCH 13/22] qemuBlockStorageSourceGetBackendProps: Unify cases for '!onlytarget' and '!legacy'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_block.c | 40 ++++++++++++++++++----------------------
 1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 41038fb994..ca68b9ab66 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1097,32 +1097,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);
-- 
2.41.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux