render / rpms / libvirt

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