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