fbe740
From 47842f81b667134e873f4380dfb432ca86a1e50d Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <47842f81b667134e873f4380dfb432ca86a1e50d@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Tue, 24 Mar 2020 16:26:00 +0100
fbe740
Subject: [PATCH] qemuBlockGetBackingStoreString: Add 'pretty' argument
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Add support for pretty-printing of the JSON variant of the output for
fbe740
consumption in tests. All current callers pass 'false'.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
(cherry picked from commit a83c1dc70e724b9313436c63f57ea24023fd7076)
fbe740
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804617
fbe740
Message-Id: <9b133a1d7bf6304e0dc9017222bdc09640c11518.1585063415.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_block.c  | 8 +++++---
fbe740
 src/qemu/qemu_block.h  | 3 ++-
fbe740
 src/qemu/qemu_driver.c | 4 ++--
fbe740
 3 files changed, 9 insertions(+), 6 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
fbe740
index 5697d4fc73..279b4a38b8 100644
fbe740
--- a/src/qemu/qemu_block.c
fbe740
+++ b/src/qemu/qemu_block.c
fbe740
@@ -2014,13 +2014,15 @@ qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefPtr disk)
fbe740
 /**
fbe740
  * qemuBlockGetBackingStoreString:
fbe740
  * @src: storage source to get the string for
fbe740
+ * @pretty: pretty-print the JSON (if applicable, used by tests)
fbe740
  *
fbe740
  * Formats a string used in the backing store field of a disk image which
fbe740
  * supports backing store. Non-local storage may result in use of the json:
fbe740
  * pseudo protocol for any complex configuration.
fbe740
  */
fbe740
 char *
fbe740
-qemuBlockGetBackingStoreString(virStorageSourcePtr src)
fbe740
+qemuBlockGetBackingStoreString(virStorageSourcePtr src,
fbe740
+                               bool pretty)
fbe740
 {
fbe740
     int actualType = virStorageSourceGetActualType(src);
fbe740
     g_autoptr(virJSONValue) backingProps = NULL;
fbe740
@@ -2087,7 +2089,7 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
fbe740
         props = sliceProps;
fbe740
     }
fbe740
 
fbe740
-    if (!(backingJSON = virJSONValueToString(props, false)))
fbe740
+    if (!(backingJSON = virJSONValueToString(props, pretty)))
fbe740
         return NULL;
fbe740
 
fbe740
     ret = g_strdup_printf("json:%s", backingJSON);
fbe740
@@ -2115,7 +2117,7 @@ qemuBlockStorageSourceCreateAddBacking(virStorageSourcePtr backing,
fbe740
             backingFormatStr = virStorageFileFormatTypeToString(backing->format);
fbe740
     }
fbe740
 
fbe740
-    if (!(backingFileStr = qemuBlockGetBackingStoreString(backing)))
fbe740
+    if (!(backingFileStr = qemuBlockGetBackingStoreString(backing, false)))
fbe740
         return -1;
fbe740
 
fbe740
     if (virJSONValueObjectAdd(props,
fbe740
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
fbe740
index 75b25bfea5..506957c3d5 100644
fbe740
--- a/src/qemu/qemu_block.h
fbe740
+++ b/src/qemu/qemu_block.h
fbe740
@@ -178,7 +178,8 @@ qemuBlockSnapshotAddBlockdev(virJSONValuePtr actions,
fbe740
                              virStorageSourcePtr newsrc);
fbe740
 
fbe740
 char *
fbe740
-qemuBlockGetBackingStoreString(virStorageSourcePtr src)
fbe740
+qemuBlockGetBackingStoreString(virStorageSourcePtr src,
fbe740
+                               bool pretty)
fbe740
     ATTRIBUTE_NONNULL(1);
fbe740
 
fbe740
 int
fbe740
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
fbe740
index 175a1961c2..3c3c7b6041 100644
fbe740
--- a/src/qemu/qemu_driver.c
fbe740
+++ b/src/qemu/qemu_driver.c
fbe740
@@ -17773,7 +17773,7 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm,
fbe740
         if (baseSource) {
fbe740
             nodebase = baseSource->nodeformat;
fbe740
             if (!backingPath &&
fbe740
-                !(backingPath = qemuBlockGetBackingStoreString(baseSource)))
fbe740
+                !(backingPath = qemuBlockGetBackingStoreString(baseSource, false)))
fbe740
                 goto endjob;
fbe740
         }
fbe740
         device = disk->src->nodeformat;
fbe740
@@ -18941,7 +18941,7 @@ qemuDomainBlockCommit(virDomainPtr dom,
fbe740
         nodebase = baseSource->nodeformat;
fbe740
         device = qemuDomainDiskGetTopNodename(disk);
fbe740
         if (!backingPath && top_parent &&
fbe740
-            !(backingPath = qemuBlockGetBackingStoreString(baseSource)))
fbe740
+            !(backingPath = qemuBlockGetBackingStoreString(baseSource, false)))
fbe740
             goto endjob;
fbe740
 
fbe740
         if (bitmapDisableActions) {
fbe740
-- 
fbe740
2.26.0
fbe740