Blob Blame History Raw
From 47842f81b667134e873f4380dfb432ca86a1e50d Mon Sep 17 00:00:00 2001
Message-Id: <47842f81b667134e873f4380dfb432ca86a1e50d@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 24 Mar 2020 16:26:00 +0100
Subject: [PATCH] qemuBlockGetBackingStoreString: Add 'pretty' argument
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add support for pretty-printing of the JSON variant of the output for
consumption in tests. All current callers pass 'false'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit a83c1dc70e724b9313436c63f57ea24023fd7076)

https://bugzilla.redhat.com/show_bug.cgi?id=1804617
Message-Id: <9b133a1d7bf6304e0dc9017222bdc09640c11518.1585063415.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_block.c  | 8 +++++---
 src/qemu/qemu_block.h  | 3 ++-
 src/qemu/qemu_driver.c | 4 ++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 5697d4fc73..279b4a38b8 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -2014,13 +2014,15 @@ qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefPtr disk)
 /**
  * qemuBlockGetBackingStoreString:
  * @src: storage source to get the string for
+ * @pretty: pretty-print the JSON (if applicable, used by tests)
  *
  * Formats a string used in the backing store field of a disk image which
  * supports backing store. Non-local storage may result in use of the json:
  * pseudo protocol for any complex configuration.
  */
 char *
-qemuBlockGetBackingStoreString(virStorageSourcePtr src)
+qemuBlockGetBackingStoreString(virStorageSourcePtr src,
+                               bool pretty)
 {
     int actualType = virStorageSourceGetActualType(src);
     g_autoptr(virJSONValue) backingProps = NULL;
@@ -2087,7 +2089,7 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
         props = sliceProps;
     }
 
-    if (!(backingJSON = virJSONValueToString(props, false)))
+    if (!(backingJSON = virJSONValueToString(props, pretty)))
         return NULL;
 
     ret = g_strdup_printf("json:%s", backingJSON);
@@ -2115,7 +2117,7 @@ qemuBlockStorageSourceCreateAddBacking(virStorageSourcePtr backing,
             backingFormatStr = virStorageFileFormatTypeToString(backing->format);
     }
 
-    if (!(backingFileStr = qemuBlockGetBackingStoreString(backing)))
+    if (!(backingFileStr = qemuBlockGetBackingStoreString(backing, false)))
         return -1;
 
     if (virJSONValueObjectAdd(props,
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 75b25bfea5..506957c3d5 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -178,7 +178,8 @@ qemuBlockSnapshotAddBlockdev(virJSONValuePtr actions,
                              virStorageSourcePtr newsrc);
 
 char *
-qemuBlockGetBackingStoreString(virStorageSourcePtr src)
+qemuBlockGetBackingStoreString(virStorageSourcePtr src,
+                               bool pretty)
     ATTRIBUTE_NONNULL(1);
 
 int
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 175a1961c2..3c3c7b6041 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17773,7 +17773,7 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm,
         if (baseSource) {
             nodebase = baseSource->nodeformat;
             if (!backingPath &&
-                !(backingPath = qemuBlockGetBackingStoreString(baseSource)))
+                !(backingPath = qemuBlockGetBackingStoreString(baseSource, false)))
                 goto endjob;
         }
         device = disk->src->nodeformat;
@@ -18941,7 +18941,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
         nodebase = baseSource->nodeformat;
         device = qemuDomainDiskGetTopNodename(disk);
         if (!backingPath && top_parent &&
-            !(backingPath = qemuBlockGetBackingStoreString(baseSource)))
+            !(backingPath = qemuBlockGetBackingStoreString(baseSource, false)))
             goto endjob;
 
         if (bitmapDisableActions) {
-- 
2.26.0