libvirt/SOURCES/libvirt-util-storage-Store-backing-store-format-in-virStorageSource.patch
2021-09-10 11:57:33 +00:00

156 lines
5.8 KiB
Diff

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