Blob Blame History Raw
From a3ac7f49d3592fb9acdf2c4de6f2bf7329745faa Mon Sep 17 00:00:00 2001
Message-Id: <a3ac7f49d3592fb9acdf2c4de6f2bf7329745faa@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Fri, 19 Jun 2020 11:43:15 +0200
Subject: [PATCH] virDevMapperGetTargetsImpl: Check for dm major properly
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In v6.4.0-rc1~143 I've introduced a check that is supposed to
return from the function early, if given path is not a dm target.
While the idea is still valid, the implementation had a flaw.
It calls stat() over given path and the uses major(sb.st_dev) to
learn the major of the device. This is then passed to
dm_is_dm_major() which returns true or false depending whether
the device is under devmapper's control or not.

The problem with this approach is in how the major of the device
is obtained - paths managed by devmapper are special files and
thus we want to be using st_rdev instead of st_dev to obtain the
major number. Well, that's what virIsDevMapperDevice() does
already so might as well us that.

Fixes: 01626c668ecfbe465d18799ac4628e6127ea1d47
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1839992

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit d53ab9f54ea8d6cc1e5c3b04c4eb743cae9518ce)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <fb00a1a9a25223788506821f4403b0b4e6481b94.1592559697.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/virdevmapper.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index 944baad562..c69830ac70 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -69,7 +69,6 @@ virDevMapperGetTargetsImpl(const char *path,
                            char ***devPaths_ret,
                            unsigned int ttl)
 {
-    struct stat sb;
     struct dm_task *dmt = NULL;
     struct dm_deps *deps;
     struct dm_info info;
@@ -88,13 +87,7 @@ virDevMapperGetTargetsImpl(const char *path,
         return ret;
     }
 
-    if (stat(path, &sb) < 0) {
-        if (errno == ENOENT)
-            return 0;
-        return -1;
-    }
-
-    if (!dm_is_dm_major(major(sb.st_dev)))
+    if (!virIsDevMapperDevice(path))
         return 0;
 
     if (!(dmt = dm_task_create(DM_DEVICE_DEPS))) {
-- 
2.27.0