render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
3cf992
From 8474f0f611f4372bd4f98c6df92f50566f631db0 Mon Sep 17 00:00:00 2001
3cf992
Message-Id: <8474f0f611f4372bd4f98c6df92f50566f631db0@dist-git>
3cf992
From: Michal Privoznik <mprivozn@redhat.com>
3cf992
Date: Mon, 8 Mar 2021 12:57:33 +0100
3cf992
Subject: [PATCH] virdevmapper: Handle kernel without device-mapper support
3cf992
MIME-Version: 1.0
3cf992
Content-Type: text/plain; charset=UTF-8
3cf992
Content-Transfer-Encoding: 8bit
3cf992
3cf992
In one of my latest patch (v6.6.0~30) I was trying to remove
3cf992
libdevmapper use in favor of our own implementation. However, the
3cf992
code did not take into account that device mapper can be not
3cf992
compiled into the kernel (e.g. be a separate module that's not
3cf992
loaded) in which case /proc/devices won't have the device-mapper
3cf992
major number and thus virDevMapperGetTargets() and/or
3cf992
virIsDevMapperDevice() fails.
3cf992
3cf992
However, such failure is safe to ignore, because if device mapper
3cf992
is missing then there can't be any multipath devices and thus we
3cf992
don't need to allow the deps in CGroups, nor create them in the
3cf992
domain private namespace, etc.
3cf992
3cf992
Fixes: 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e
3cf992
Reported-by: Andrea Bolognani <abologna@redhat.com>
3cf992
Reported-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3cf992
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3cf992
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3cf992
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3cf992
Tested-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
3cf992
(cherry picked from commit feb8564a3cc63bc8f68284063d53ec0d2d81a1cc)
3cf992
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1933557
3cf992
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3cf992
Message-Id: <11f41c0fd7b7c8365e24398173cb0bb2f8e785de.1615203117.git.mprivozn@redhat.com>
3cf992
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3cf992
---
3cf992
 src/util/virdevmapper.c | 20 ++++++++++++++++++--
3cf992
 1 file changed, 18 insertions(+), 2 deletions(-)
3cf992
3cf992
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
3cf992
index 725de736c1..a76fe95922 100644
3cf992
--- a/src/util/virdevmapper.c
3cf992
+++ b/src/util/virdevmapper.c
3cf992
@@ -57,6 +57,9 @@ virDevMapperGetMajor(unsigned int *major)
3cf992
     VIR_AUTOSTRINGLIST lines = NULL;
3cf992
     size_t i;
3cf992
 
3cf992
+    if (!virFileExists(CONTROL_PATH))
3cf992
+        return -2;
3cf992
+
3cf992
     if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0)
3cf992
         return -1;
3cf992
 
3cf992
@@ -130,8 +133,13 @@ virDMOpen(void)
3cf992
 
3cf992
     memset(&dm, 0, sizeof(dm));
3cf992
 
3cf992
-    if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0)
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
+    }
3cf992
 
3cf992
     if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) {
3cf992
         virReportSystemError(errno, "%s",
3cf992
@@ -313,8 +321,16 @@ virDevMapperGetTargets(const char *path,
3cf992
      * consist of devices or yet another targets. If that's the
3cf992
      * case, we have to stop recursion somewhere. */
3cf992
 
3cf992
-    if ((controlFD = virDMOpen()) < 0)
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
+            return 0;
3cf992
+        }
3cf992
+
3cf992
         return -1;
3cf992
+    }
3cf992
 
3cf992
     return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl);
3cf992
 }
3cf992
-- 
3cf992
2.31.0
3cf992