render / rpms / libvirt

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