Blame SOURCES/libvirt-virdevmapper-Ignore-all-errors-when-opening-dev-mapper-control.patch

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