|
|
a41c76 |
From 811785bdc008e9d0df7e6f3e723c5f67b40cf6de Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <811785bdc008e9d0df7e6f3e723c5f67b40cf6de@dist-git>
|
|
|
a41c76 |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Date: Fri, 28 Feb 2020 10:24:33 +0100
|
|
|
a41c76 |
Subject: [PATCH] virStorageFileGetMetadataRecurse: Extract storage access
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
Extract the code that directly deals with storage. This allows further
|
|
|
a41c76 |
simplification and clarification of virStorageFileGetMetadataRecurse.
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit 01adad0932a583b1e2183dd4401bddd8607e77c3)
|
|
|
a41c76 |
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1798148
|
|
|
a41c76 |
Message-Id: <716c58c00cec06dd469b079df124bc896665f169.1582881363.git.pkrempa@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
src/util/virstoragefile.c | 71 ++++++++++++++++++++++++++-------------
|
|
|
a41c76 |
1 file changed, 47 insertions(+), 24 deletions(-)
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
|
|
|
a41c76 |
index 46d55eda96..7295cebd08 100644
|
|
|
a41c76 |
--- a/src/util/virstoragefile.c
|
|
|
a41c76 |
+++ b/src/util/virstoragefile.c
|
|
|
a41c76 |
@@ -4955,31 +4955,18 @@ virStorageFileReportBrokenChain(int errcode,
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
-/* Recursive workhorse for virStorageFileGetMetadata. */
|
|
|
a41c76 |
static int
|
|
|
a41c76 |
-virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
a41c76 |
- virStorageSourcePtr parent,
|
|
|
a41c76 |
- uid_t uid, gid_t gid,
|
|
|
a41c76 |
- bool report_broken,
|
|
|
a41c76 |
- virHashTablePtr cycle,
|
|
|
a41c76 |
- unsigned int depth)
|
|
|
a41c76 |
+virStorageFileGetMetadataRecurseReadHeader(virStorageSourcePtr src,
|
|
|
a41c76 |
+ virStorageSourcePtr parent,
|
|
|
a41c76 |
+ uid_t uid,
|
|
|
a41c76 |
+ gid_t gid,
|
|
|
a41c76 |
+ char **buf,
|
|
|
a41c76 |
+ size_t *headerLen,
|
|
|
a41c76 |
+ virHashTablePtr cycle)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
int ret = -1;
|
|
|
a41c76 |
const char *uniqueName;
|
|
|
a41c76 |
- ssize_t headerLen;
|
|
|
a41c76 |
- int backingFormat;
|
|
|
a41c76 |
- int rv;
|
|
|
a41c76 |
- g_autofree char *buf = NULL;
|
|
|
a41c76 |
- g_autoptr(virStorageSource) backingStore = NULL;
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- VIR_DEBUG("path=%s format=%d uid=%u gid=%u",
|
|
|
a41c76 |
- NULLSTR(src->path), src->format,
|
|
|
a41c76 |
- (unsigned int)uid, (unsigned int)gid);
|
|
|
a41c76 |
-
|
|
|
a41c76 |
- /* exit if we can't load information about the current image */
|
|
|
a41c76 |
- rv = virStorageFileSupportsBackingChainTraversal(src);
|
|
|
a41c76 |
- if (rv <= 0)
|
|
|
a41c76 |
- return rv;
|
|
|
a41c76 |
+ ssize_t len;
|
|
|
a41c76 |
|
|
|
a41c76 |
if (virStorageFileInitAs(src, uid, gid) < 0)
|
|
|
a41c76 |
return -1;
|
|
|
a41c76 |
@@ -5002,10 +4989,47 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
a41c76 |
if (virHashAddEntry(cycle, uniqueName, NULL) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
- if ((headerLen = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER,
|
|
|
a41c76 |
- &buf)) < 0)
|
|
|
a41c76 |
+ if ((len = virStorageFileRead(src, 0, VIR_STORAGE_MAX_HEADER, buf)) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
|
|
|
a41c76 |
+ *headerLen = len;
|
|
|
a41c76 |
+ ret = 0;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ virStorageFileDeinit(src);
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+/* Recursive workhorse for virStorageFileGetMetadata. */
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
a41c76 |
+ virStorageSourcePtr parent,
|
|
|
a41c76 |
+ uid_t uid, gid_t gid,
|
|
|
a41c76 |
+ bool report_broken,
|
|
|
a41c76 |
+ virHashTablePtr cycle,
|
|
|
a41c76 |
+ unsigned int depth)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+ size_t headerLen;
|
|
|
a41c76 |
+ int backingFormat;
|
|
|
a41c76 |
+ int rv;
|
|
|
a41c76 |
+ g_autofree char *buf = NULL;
|
|
|
a41c76 |
+ g_autoptr(virStorageSource) backingStore = NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ VIR_DEBUG("path=%s format=%d uid=%u gid=%u",
|
|
|
a41c76 |
+ NULLSTR(src->path), src->format,
|
|
|
a41c76 |
+ (unsigned int)uid, (unsigned int)gid);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* exit if we can't load information about the current image */
|
|
|
a41c76 |
+ rv = virStorageFileSupportsBackingChainTraversal(src);
|
|
|
a41c76 |
+ if (rv <= 0)
|
|
|
a41c76 |
+ return rv;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virStorageFileGetMetadataRecurseReadHeader(src, parent, uid, gid,
|
|
|
a41c76 |
+ &buf, &headerLen, cycle) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
if (virStorageFileGetMetadataInternal(src, buf, headerLen,
|
|
|
a41c76 |
&backingFormat) < 0)
|
|
|
a41c76 |
goto cleanup;
|
|
|
a41c76 |
@@ -5081,7 +5105,6 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
|
|
|
a41c76 |
ret = 0;
|
|
|
a41c76 |
|
|
|
a41c76 |
cleanup:
|
|
|
a41c76 |
- virStorageFileDeinit(src);
|
|
|
a41c76 |
return ret;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.1
|
|
|
a41c76 |
|