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

3cf992
From fb3d8e295473034a271f09c6ce46f9500fcfa2c5 Mon Sep 17 00:00:00 2001
3cf992
Message-Id: <fb3d8e295473034a271f09c6ce46f9500fcfa2c5@dist-git>
3cf992
From: Michal Privoznik <mprivozn@redhat.com>
3cf992
Date: Mon, 8 Mar 2021 12:57:34 +0100
3cf992
Subject: [PATCH] virdevmapper: Ignore all errors when opening
3cf992
 /dev/mapper/control
3cf992
MIME-Version: 1.0
3cf992
Content-Type: text/plain; charset=UTF-8
3cf992
Content-Transfer-Encoding: 8bit
3cf992
3cf992
So far, only ENOENT is ignored (to deal with kernels without
3cf992
devmapper). However, as reported on the list, under certain
3cf992
scenarios a different error can occur. For instance, when libvirt
3cf992
is running inside a container which doesn't have permissions to
3cf992
talk to the devmapper. If this is the case, then open() returns
3cf992
-1 and sets errno=EPERM.
3cf992
3cf992
Assuming that multipath devices are fairly narrow use case and
3cf992
using them in a restricted container is even more narrow the best
3cf992
fix seems to be to ignore all open errors BUT produce a warning
3cf992
on failure. To avoid flooding logs with warnings on kernels
3cf992
without devmapper the level is reduced to a plain debug message.
3cf992
3cf992
Reported-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3cf992
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3cf992
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3cf992
(cherry picked from commit 53d9af1e7924757e3b5f661131dd707d7110d094)
3cf992
3cf992
I had to replace g_strerror() from the original commit with
3cf992
virStrerror() which is what we use in downstream.
3cf992
3cf992
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1933557
3cf992
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3cf992
Message-Id: <8e45903b261c50d92cea4bf3d87f724a262c928f.1615203117.git.mprivozn@redhat.com>
3cf992
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3cf992
---
3cf992
 src/util/virdevmapper.c | 25 +++++++++++++++++--------
3cf992
 1 file changed, 17 insertions(+), 8 deletions(-)
3cf992
3cf992
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
3cf992
index a76fe95922..a04d9650a6 100644
3cf992
--- a/src/util/virdevmapper.c
3cf992
+++ b/src/util/virdevmapper.c
3cf992
@@ -38,9 +38,12 @@
3cf992
 # include "viralloc.h"
3cf992
 # include "virstring.h"
3cf992
 # include "virfile.h"
3cf992
+# include "virlog.h"
3cf992
 
3cf992
 # define VIR_FROM_THIS VIR_FROM_STORAGE
3cf992
 
3cf992
+VIR_LOG_INIT("util.virdevmapper");
3cf992
+
3cf992
 # define PROC_DEVICES "/proc/devices"
3cf992
 # define DM_NAME "device-mapper"
3cf992
 # define DEV_DM_DIR "/dev/" DM_DIR
3cf992
@@ -134,11 +137,17 @@ virDMOpen(void)
3cf992
     memset(&dm, 0, sizeof(dm));
3cf992
 
3cf992
     if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) {
3cf992
-        if (errno == ENOENT)
3cf992
-            return -2;
3cf992
-
3cf992
-        virReportSystemError(errno, _("Unable to open %s"), CONTROL_PATH);
3cf992
-        return -1;
3cf992
+        char ebuf[1024];
3cf992
+
3cf992
+        /* We can't talk to devmapper. Produce a warning and let
3cf992
+         * the caller decide what to do next. */
3cf992
+        if (errno == ENOENT) {
3cf992
+            VIR_DEBUG("device mapper not available");
3cf992
+        } else {
3cf992
+            VIR_WARN("unable to open %s: %s",
3cf992
+                     CONTROL_PATH, virStrerror(errno, ebuf, sizeof(ebuf)));
3cf992
+        }
3cf992
+        return -2;
3cf992
     }
3cf992
 
3cf992
     if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) {
3cf992
@@ -323,9 +332,9 @@ virDevMapperGetTargets(const char *path,
3cf992
 
3cf992
     if ((controlFD = virDMOpen()) < 0) {
3cf992
         if (controlFD == -2) {
3cf992
-            /* The CONTROL_PATH doesn't exist. Probably the
3cf992
-             * module isn't loaded, yet. Don't error out, just
3cf992
-             * exit. */
3cf992
+            /* The CONTROL_PATH doesn't exist or is unusable.
3cf992
+             * Probably the module isn't loaded, yet. Don't error
3cf992
+             * out, just exit. */
3cf992
             return 0;
3cf992
         }
3cf992
 
3cf992
-- 
3cf992
2.31.0
3cf992