984721
From a3ac7f49d3592fb9acdf2c4de6f2bf7329745faa Mon Sep 17 00:00:00 2001
984721
Message-Id: <a3ac7f49d3592fb9acdf2c4de6f2bf7329745faa@dist-git>
984721
From: Michal Privoznik <mprivozn@redhat.com>
984721
Date: Fri, 19 Jun 2020 11:43:15 +0200
984721
Subject: [PATCH] virDevMapperGetTargetsImpl: Check for dm major properly
984721
MIME-Version: 1.0
984721
Content-Type: text/plain; charset=UTF-8
984721
Content-Transfer-Encoding: 8bit
984721
984721
In v6.4.0-rc1~143 I've introduced a check that is supposed to
984721
return from the function early, if given path is not a dm target.
984721
While the idea is still valid, the implementation had a flaw.
984721
It calls stat() over given path and the uses major(sb.st_dev) to
984721
learn the major of the device. This is then passed to
984721
dm_is_dm_major() which returns true or false depending whether
984721
the device is under devmapper's control or not.
984721
984721
The problem with this approach is in how the major of the device
984721
is obtained - paths managed by devmapper are special files and
984721
thus we want to be using st_rdev instead of st_dev to obtain the
984721
major number. Well, that's what virIsDevMapperDevice() does
984721
already so might as well us that.
984721
984721
Fixes: 01626c668ecfbe465d18799ac4628e6127ea1d47
984721
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1839992
984721
984721
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
984721
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
984721
(cherry picked from commit d53ab9f54ea8d6cc1e5c3b04c4eb743cae9518ce)
984721
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
984721
Message-Id: <fb00a1a9a25223788506821f4403b0b4e6481b94.1592559697.git.mprivozn@redhat.com>
984721
Reviewed-by: Ján Tomko <jtomko@redhat.com>
984721
---
984721
 src/util/virdevmapper.c | 9 +--------
984721
 1 file changed, 1 insertion(+), 8 deletions(-)
984721
984721
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
984721
index 944baad562..c69830ac70 100644
984721
--- a/src/util/virdevmapper.c
984721
+++ b/src/util/virdevmapper.c
984721
@@ -69,7 +69,6 @@ virDevMapperGetTargetsImpl(const char *path,
984721
                            char ***devPaths_ret,
984721
                            unsigned int ttl)
984721
 {
984721
-    struct stat sb;
984721
     struct dm_task *dmt = NULL;
984721
     struct dm_deps *deps;
984721
     struct dm_info info;
984721
@@ -88,13 +87,7 @@ virDevMapperGetTargetsImpl(const char *path,
984721
         return ret;
984721
     }
984721
 
984721
-    if (stat(path, &sb) < 0) {
984721
-        if (errno == ENOENT)
984721
-            return 0;
984721
-        return -1;
984721
-    }
984721
-
984721
-    if (!dm_is_dm_major(major(sb.st_dev)))
984721
+    if (!virIsDevMapperDevice(path))
984721
         return 0;
984721
 
984721
     if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
984721
-- 
984721
2.27.0
984721