From: Bhavin Gandhi <bhavin...@geeksocket.in>

DM_TABLE_DEPS expects a device name in dm_ioctl.name. In one of the
cases, full path of the device was getting returned causing the ioctl
call to fail with `ENXIO (No such device or address)`.

Also rename the function and variable names to better reflect that we
are dealing with DM device names and not paths.

This got introduced in 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/790

Signed-off-by: Bhavin Gandhi <bhavin...@geeksocket.in>
---
 src/util/virdevmapper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index d0eae671ab..42c86d89cf 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -164,7 +164,7 @@ virDMOpen(void)
 
 
 static char *
-virDMSanitizepath(const char *path)
+virDMGetDeviceName(const char *path)
 {
     g_autofree char *dmDirPath = NULL;
     struct dirent *ent = NULL;
@@ -205,7 +205,7 @@ virDMSanitizepath(const char *path)
 
         if (stat(tmp, &sb[1]) == 0 &&
             sb[0].st_rdev == sb[1].st_rdev) {
-            return g_steal_pointer(&tmp);
+            return g_strdup(ent->d_name);
         }
     }
 
@@ -219,7 +219,7 @@ virDevMapperGetTargetsImpl(int controlFD,
                            GSList **devPaths,
                            unsigned int ttl)
 {
-    g_autofree char *sanitizedPath = NULL;
+    g_autofree char *deviceName = NULL;
     g_autofree char *buf = NULL;
     struct dm_ioctl dm = { 0 };
     struct dm_target_deps *deps = NULL;
@@ -233,10 +233,10 @@ virDevMapperGetTargetsImpl(int controlFD,
     if (!virIsDevMapperDevice(path))
         return 0;
 
-    if (!(sanitizedPath = virDMSanitizepath(path)))
+    if (!(deviceName = virDMGetDeviceName(path)))
         return 0;
 
-    if (virStrcpy(dm.name, sanitizedPath, DM_NAME_LEN) < 0) {
+    if (virStrcpy(dm.name, deviceName, DM_NAME_LEN) < 0) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                        _("Resolved device mapper name too long"));
         return -1;
-- 
2.49.0

Reply via email to