[PATCH 08/22] qemuBlockStorageSourceGetBlockdevGetCacheProps: Return the cache object rather than appending it

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

 



Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_block.c  | 29 ++++++++++++++++-------------
 src/qemu/qemu_domain.c |  2 +-
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 0f47b5b37f..41038fb994 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -913,24 +913,20 @@ qemuBlockStorageSourceGetVhostVdpaProps(virStorageSource *src)

 static int
 qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSource *src,
-                                               virJSONValue *props)
+                                               virJSONValue **cache)
 {
-    g_autoptr(virJSONValue) cacheobj = NULL;
     bool direct = false;
     bool noflush = false;

     if (!qemuDomainDiskCachemodeFlags(src->cachemode, NULL, &direct, &noflush))
         return 0;

-    if (virJSONValueObjectAdd(&cacheobj,
+    if (virJSONValueObjectAdd(cache,
                               "b:direct", direct,
                               "b:no-flush", noflush,
                               NULL) < 0)
         return -1;

-    if (virJSONValueObjectAppend(props, "cache", &cacheobj) < 0)
-        return -1;
-
     return 0;
 }

@@ -1109,10 +1105,13 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
             return NULL;

         if (!legacy) {
-            if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, fileprops) < 0)
+            g_autoptr(virJSONValue) cache = 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)
@@ -1278,10 +1277,14 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSource *src)
     int detectZeroesMode = virDomainDiskGetDetectZeroesMode(src->discard,
                                                             src->detect_zeroes);
     g_autoptr(virJSONValue) props = NULL;
+    g_autoptr(virJSONValue) cache = NULL;

     if (qemuBlockNodeNameValidate(qemuBlockStorageSourceGetFormatNodename(src)) < 0)
         return NULL;

+    if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
+        return NULL;
+
     if (src->discard)
         discard = virDomainDiskDiscardTypeToString(src->discard);

@@ -1297,12 +1300,10 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSource *src)
                               "b:read-only", src->readonly,
                               "S:discard", discard,
                               "S:detect-zeroes", detectZeroes,
+                              "A:cache", &cache,
                               NULL) < 0)
         return NULL;

-    if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
-        return NULL;
-
     return g_steal_pointer(&props);
 }

@@ -1439,10 +1440,14 @@ static virJSONValue *
 qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src)
 {
     g_autoptr(virJSONValue) props = NULL;
+    g_autoptr(virJSONValue) cache = NULL;

     if (qemuBlockNodeNameValidate(src->sliceStorage->nodename) < 0)
         return NULL;

+    if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
+        return NULL;
+
     if (virJSONValueObjectAdd(&props,
                               "s:driver", "raw",
                               "s:node-name", src->sliceStorage->nodename,
@@ -1451,12 +1456,10 @@ qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src)
                               "s:file", qemuBlockStorageSourceGetStorageNodename(src),
                               "b:auto-read-only", true,
                               "s:discard", "unmap",
+                              "A:cache", &cache,
                               NULL) < 0)
         return NULL;

-    if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
-        return NULL;
-
     return g_steal_pointer(&props);
 }

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0b36a49bdf..ae19ce884b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11442,7 +11442,7 @@ qemuDomainDiskCachemodeFlags(virDomainDiskCache cachemode,
      * directsync   â?? false             true           false
      * unsafe       â?? true              false          true
      */
-    switch ((virDomainDiskCache) cachemode) {
+    switch (cachemode) {
     case VIR_DOMAIN_DISK_CACHE_DISABLE: /* 'none' */
         *writeback = true;
         *direct = true;
-- 
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