From 3c12ed40d06ffe2f2c871667f31925f8727162a4 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Tue, 31 Aug 2021 08:31:06 -0400
Subject: [PATCH] Handle kernel without device-mapper support

---
 src/util/virdevmapper.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index 2b9e689..158c9d4 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -53,6 +53,9 @@ virDevMapperGetMajor(unsigned int *major)
     VIR_AUTOSTRINGLIST lines = NULL;
     size_t i;
 
+    if (!virFileExists(CONTROL_PATH))
+        return -2;
+
     if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0)
         return -1;
 
@@ -124,8 +127,13 @@ virDMOpen(void)
 
     memset(&dm, 0, sizeof(dm));
 
-    if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0)
+    if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) {
+        if (errno == ENOENT)
+             return -2;
+
+        virReportSystemError(errno, _("Unable to open %s"), CONTROL_PATH);
         return -1;
+    }
 
     if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) {
         virReportSystemError(errno, "%s",
@@ -299,7 +307,16 @@ virDevMapperGetTargets(const char *path,
      * case, we have to stop recursion somewhere. */
 
     if ((controlFD = virDMOpen()) < 0)
+    if ((controlFD = virDMOpen()) < 0) {
+        if (controlFD == -2) {
+             /* The CONTROL_PATH doesn't exist. Probably the
+              * module isn't loaded, yet. Don't error out, just
+              * exit. */
+             return 0;
+        }
+
         return -1;
+    }
 
     return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl);
 }
-- 
2.18.2

