render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7b551b
From b38ab86a0a2cf3453d37a5fe96b2e022d8a1d48a Mon Sep 17 00:00:00 2001
7b551b
Message-Id: <b38ab86a0a2cf3453d37a5fe96b2e022d8a1d48a@dist-git>
7b551b
From: Michal Privoznik <mprivozn@redhat.com>
7b551b
Date: Tue, 25 Aug 2020 17:16:07 +0200
7b551b
Subject: [PATCH] virdevmapper: Ignore all errors when opening
7b551b
 /dev/mapper/control
7b551b
7b551b
So far, only ENOENT is ignored (to deal with kernels without
7b551b
devmapper). However, as reported on the list, under certain
7b551b
scenarios a different error can occur. For instance, when libvirt
7b551b
is running inside a container which doesn't have permissions to
7b551b
talk to the devmapper. If this is the case, then open() returns
7b551b
-1 and sets errno=EPERM.
7b551b
7b551b
Assuming that multipath devices are fairly narrow use case and
7b551b
using them in a restricted container is even more narrow the best
7b551b
fix seems to be to ignore all open errors BUT produce a warning
7b551b
on failure. To avoid flooding logs with warnings on kernels
7b551b
without devmapper the level is reduced to a plain debug message.
7b551b
7b551b
Reported-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7b551b
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
7b551b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7b551b
(cherry picked from commit 53d9af1e7924757e3b5f661131dd707d7110d094)
7b551b
7b551b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1860421
7b551b
7b551b
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7b551b
Message-Id: <e1b69d69e7d242829995208c6d59ed0477208920.1598364552.git.mprivozn@redhat.com>
7b551b
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
7b551b
---
7b551b
 src/util/virdevmapper.c | 23 +++++++++++++++--------
7b551b
 1 file changed, 15 insertions(+), 8 deletions(-)
7b551b
7b551b
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
7b551b
index a81e2edee4..ee2fab5ae3 100644
7b551b
--- a/src/util/virdevmapper.c
7b551b
+++ b/src/util/virdevmapper.c
7b551b
@@ -35,9 +35,12 @@
7b551b
 # include "viralloc.h"
7b551b
 # include "virstring.h"
7b551b
 # include "virfile.h"
7b551b
+# include "virlog.h"
7b551b
 
7b551b
 # define VIR_FROM_THIS VIR_FROM_STORAGE
7b551b
 
7b551b
+VIR_LOG_INIT("util.virdevmapper");
7b551b
+
7b551b
 # define PROC_DEVICES "/proc/devices"
7b551b
 # define DM_NAME "device-mapper"
7b551b
 # define DEV_DM_DIR "/dev/" DM_DIR
7b551b
@@ -130,11 +133,15 @@ virDMOpen(void)
7b551b
     memset(&dm, 0, sizeof(dm));
7b551b
 
7b551b
     if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) {
7b551b
-        if (errno == ENOENT)
7b551b
-            return -2;
7b551b
-
7b551b
-        virReportSystemError(errno, _("Unable to open %s"), CONTROL_PATH);
7b551b
-        return -1;
7b551b
+        /* We can't talk to devmapper. Produce a warning and let
7b551b
+         * the caller decide what to do next. */
7b551b
+        if (errno == ENOENT) {
7b551b
+            VIR_DEBUG("device mapper not available");
7b551b
+        } else {
7b551b
+            VIR_WARN("unable to open %s: %s",
7b551b
+                     CONTROL_PATH, g_strerror(errno));
7b551b
+        }
7b551b
+        return -2;
7b551b
     }
7b551b
 
7b551b
     if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) {
7b551b
@@ -310,9 +317,9 @@ virDevMapperGetTargets(const char *path,
7b551b
 
7b551b
     if ((controlFD = virDMOpen()) < 0) {
7b551b
         if (controlFD == -2) {
7b551b
-            /* The CONTROL_PATH doesn't exist. Probably the
7b551b
-             * module isn't loaded, yet. Don't error out, just
7b551b
-             * exit. */
7b551b
+            /* The CONTROL_PATH doesn't exist or is unusable.
7b551b
+             * Probably the module isn't loaded, yet. Don't error
7b551b
+             * out, just exit. */
7b551b
             return 0;
7b551b
         }
7b551b
 
7b551b
-- 
7b551b
2.28.0
7b551b