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