d76c62
From 80cb87e61c8e48d2714c9369c14a880352114d20 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <80cb87e61c8e48d2714c9369c14a880352114d20@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Fri, 28 Feb 2020 10:24:37 +0100
d76c62
Subject: [PATCH] util: storage: Store backing store format in virStorageSource
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
We store the backing file string in the structure so we should also
d76c62
store the format so that callers can be simplified.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 62539c5f7d6a994b9cbd677564e7206cab1c5a45)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1798148
d76c62
Message-Id: <6f884591ac16f32370925bdb7746c655c7c87302.1582881363.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/util/virstoragefile.c | 35 +++++++++++++++++------------------
d76c62
 src/util/virstoragefile.h |  1 +
d76c62
 2 files changed, 18 insertions(+), 18 deletions(-)
d76c62
d76c62
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
d76c62
index 391e2ce86f..d594ee3695 100644
d76c62
--- a/src/util/virstoragefile.c
d76c62
+++ b/src/util/virstoragefile.c
d76c62
@@ -935,15 +935,11 @@ virStorageFileGetEncryptionPayloadOffset(const struct FileEncryptionInfo *info,
d76c62
 static int
d76c62
 virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
d76c62
                                   char *buf,
d76c62
-                                  size_t len,
d76c62
-                                  int *backingFormat)
d76c62
+                                  size_t len)
d76c62
 {
d76c62
-    int dummy;
d76c62
+    int format;
d76c62
     size_t i;
d76c62
 
d76c62
-    if (!backingFormat)
d76c62
-        backingFormat = &dummy;
d76c62
-
d76c62
     VIR_DEBUG("path=%s, buf=%p, len=%zu, meta->format=%d",
d76c62
               meta->path, buf, len, meta->format);
d76c62
 
d76c62
@@ -1009,8 +1005,10 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
d76c62
     VIR_FREE(meta->backingStoreRaw);
d76c62
     if (fileTypeInfo[meta->format].getBackingStore != NULL) {
d76c62
         int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw,
d76c62
-                                                               backingFormat,
d76c62
+                                                               &format,
d76c62
                                                                buf, len);
d76c62
+        meta->backingStoreRawFormat = format;
d76c62
+
d76c62
         if (store == BACKING_STORE_INVALID)
d76c62
             return 0;
d76c62
 
d76c62
@@ -1135,20 +1133,18 @@ virStorageFileGetMetadataFromBuf(const char *path,
d76c62
                                  int *backingFormat)
d76c62
 {
d76c62
     virStorageSourcePtr ret = NULL;
d76c62
-    int dummy;
d76c62
-
d76c62
-    if (!backingFormat)
d76c62
-        backingFormat = &dummy;
d76c62
 
d76c62
     if (!(ret = virStorageFileMetadataNew(path, format)))
d76c62
         return NULL;
d76c62
 
d76c62
-    if (virStorageFileGetMetadataInternal(ret, buf, len,
d76c62
-                                          backingFormat) < 0) {
d76c62
+    if (virStorageFileGetMetadataInternal(ret, buf, len) < 0) {
d76c62
         virObjectUnref(ret);
d76c62
         return NULL;
d76c62
     }
d76c62
 
d76c62
+    if (backingFormat)
d76c62
+        *backingFormat = ret->backingStoreRawFormat;
d76c62
+
d76c62
     return ret;
d76c62
 }
d76c62
 
d76c62
@@ -1211,9 +1207,12 @@ virStorageFileGetMetadataFromFD(const char *path,
d76c62
         return NULL;
d76c62
     }
d76c62
 
d76c62
-    if (virStorageFileGetMetadataInternal(meta, buf, len, backingFormat) < 0)
d76c62
+    if (virStorageFileGetMetadataInternal(meta, buf, len) < 0)
d76c62
         return NULL;
d76c62
 
d76c62
+    if (backingFormat)
d76c62
+        *backingFormat = meta->backingStoreRawFormat;
d76c62
+
d76c62
     if (S_ISREG(sb.st_mode))
d76c62
         meta->type = VIR_STORAGE_TYPE_FILE;
d76c62
     else if (S_ISBLK(sb.st_mode))
d76c62
@@ -2293,6 +2292,7 @@ virStorageSourceCopy(const virStorageSource *src,
d76c62
     def->volume = g_strdup(src->volume);
d76c62
     def->relPath = g_strdup(src->relPath);
d76c62
     def->backingStoreRaw = g_strdup(src->backingStoreRaw);
d76c62
+    def->backingStoreRawFormat = src->backingStoreRawFormat;
d76c62
     def->externalDataStoreRaw = g_strdup(src->externalDataStoreRaw);
d76c62
     def->snapshot = g_strdup(src->snapshot);
d76c62
     def->configFile = g_strdup(src->configFile);
d76c62
@@ -5000,7 +5000,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
d76c62
                                  unsigned int depth)
d76c62
 {
d76c62
     size_t headerLen;
d76c62
-    int backingFormat;
d76c62
     int rv;
d76c62
     g_autofree char *buf = NULL;
d76c62
     g_autoptr(virStorageSource) backingStore = NULL;
d76c62
@@ -5018,7 +5017,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
d76c62
                                                    &buf, &headerLen, cycle) < 0)
d76c62
         return -1;
d76c62
 
d76c62
-    if (virStorageFileGetMetadataInternal(src, buf, headerLen, &backingFormat) < 0)
d76c62
+    if (virStorageFileGetMetadataInternal(src, buf, headerLen) < 0)
d76c62
         return -1;
d76c62
 
d76c62
     if (src->backingStoreRaw) {
d76c62
@@ -5029,7 +5028,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
d76c62
         if (rv == 1)
d76c62
             return 0;
d76c62
 
d76c62
-        backingStore->format = backingFormat;
d76c62
+        backingStore->format = src->backingStoreRawFormat;
d76c62
 
d76c62
         if (backingStore->format == VIR_STORAGE_FILE_AUTO) {
d76c62
             /* Assuming the backing store to be raw can lead to failures. We do
d76c62
@@ -5180,7 +5179,7 @@ virStorageFileGetBackingStoreStr(virStorageSourcePtr src,
d76c62
     if (!(tmp = virStorageSourceCopy(src, false)))
d76c62
         return -1;
d76c62
 
d76c62
-    if (virStorageFileGetMetadataInternal(tmp, buf, headerLen, NULL) < 0)
d76c62
+    if (virStorageFileGetMetadataInternal(tmp, buf, headerLen) < 0)
d76c62
         return -1;
d76c62
 
d76c62
     *backing = g_steal_pointer(&tmp->backingStoreRaw);
d76c62
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
d76c62
index 2a684fd746..ecba418bb3 100644
d76c62
--- a/src/util/virstoragefile.h
d76c62
+++ b/src/util/virstoragefile.h
d76c62
@@ -330,6 +330,7 @@ struct _virStorageSource {
d76c62
     /* Name of the child backing store recorded in metadata of the
d76c62
      * current file.  */
d76c62
     char *backingStoreRaw;
d76c62
+    virStorageFileFormat backingStoreRawFormat;
d76c62
     /* Name of the child data file recorded in metadata of the current file. */
d76c62
     char *externalDataStoreRaw;
d76c62
 
d76c62
-- 
d76c62
2.25.1
d76c62