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