render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
404507
From ebf7011f8358288cccba7017fb5337e2d70fdc3b Mon Sep 17 00:00:00 2001
404507
Message-Id: <ebf7011f8358288cccba7017fb5337e2d70fdc3b@dist-git>
404507
From: Peter Krempa <pkrempa@redhat.com>
404507
Date: Fri, 1 Dec 2017 15:57:00 +0100
404507
Subject: [PATCH] storage: Extract error reporting for broken chains
404507
404507
Simplify reporting the error if backing chain is broken for further
404507
callers by extracting it into a separate function.
404507
404507
(cherry picked from commit b4daf6af9adba96fc5e0bd68d49602a67639b053)
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1509110
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 src/storage/storage_source.c | 47 +++++++++++++++++++++++++++++++-------------
404507
 src/storage/storage_source.h |  4 ++++
404507
 2 files changed, 37 insertions(+), 14 deletions(-)
404507
404507
diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c
404507
index 419fa3d43f..469d3a00bc 100644
404507
--- a/src/storage/storage_source.c
404507
+++ b/src/storage/storage_source.c
404507
@@ -389,6 +389,38 @@ virStorageFileChown(const virStorageSource *src,
404507
 }
404507
 
404507
 
404507
+/**
404507
+ * virStorageFileReportBrokenChain:
404507
+ *
404507
+ * @errcode: errno when accessing @src
404507
+ * @src: inaccessible file in the backing chain of @parent
404507
+ * @parent: root virStorageSource being checked
404507
+ *
404507
+ * Reports the correct error message if @src is missing in the backing chain
404507
+ * for @parent.
404507
+ */
404507
+void
404507
+virStorageFileReportBrokenChain(int errcode,
404507
+                                virStorageSourcePtr src,
404507
+                                virStorageSourcePtr parent)
404507
+{
404507
+    unsigned int access_user = src->drv->uid;
404507
+    unsigned int access_group = src->drv->gid;
404507
+
404507
+    if (src == parent) {
404507
+        virReportSystemError(errcode,
404507
+                             _("Cannot access storage file '%s' "
404507
+                               "(as uid:%u, gid:%u)"),
404507
+                             src->path, access_user, access_group);
404507
+    } else {
404507
+        virReportSystemError(errcode,
404507
+                             _("Cannot access backing file '%s' "
404507
+                               "of storage file '%s' (as uid:%u, gid:%u)"),
404507
+                             src->path, parent->path, access_user, access_group);
404507
+    }
404507
+}
404507
+
404507
+
404507
 /* Recursive workhorse for virStorageFileGetMetadata.  */
404507
 static int
404507
 virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
404507
@@ -418,20 +450,7 @@ virStorageFileGetMetadataRecurse(virStorageSourcePtr src,
404507
         return -1;
404507
 
404507
     if (virStorageFileAccess(src, F_OK) < 0) {
404507
-        if (src == parent) {
404507
-            virReportSystemError(errno,
404507
-                                 _("Cannot access storage file '%s' "
404507
-                                   "(as uid:%u, gid:%u)"),
404507
-                                 src->path, (unsigned int)uid,
404507
-                                 (unsigned int)gid);
404507
-        } else {
404507
-            virReportSystemError(errno,
404507
-                                 _("Cannot access backing file '%s' "
404507
-                                   "of storage file '%s' (as uid:%u, gid:%u)"),
404507
-                                 src->path, parent->path,
404507
-                                 (unsigned int)uid, (unsigned int)gid);
404507
-        }
404507
-
404507
+        virStorageFileReportBrokenChain(errno, src, parent);
404507
         goto cleanup;
404507
     }
404507
 
404507
diff --git a/src/storage/storage_source.h b/src/storage/storage_source.h
404507
index 6462baf6ae..a20346a12c 100644
404507
--- a/src/storage/storage_source.h
404507
+++ b/src/storage/storage_source.h
404507
@@ -51,4 +51,8 @@ int virStorageFileGetMetadata(virStorageSourcePtr src,
404507
 char *virStorageFileGetBackingStoreStr(virStorageSourcePtr src)
404507
     ATTRIBUTE_NONNULL(1);
404507
 
404507
+void virStorageFileReportBrokenChain(int errcode,
404507
+                                     virStorageSourcePtr src,
404507
+                                     virStorageSourcePtr parent);
404507
+
404507
 #endif /* __VIR_STORAGE_SOURCE_H__ */
404507
-- 
404507
2.15.1
404507