render / rpms / libvirt

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