[PATCH] virdevmapper: Always use device name for finding targets

From: Bhavin Gandhi <bhavin192@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 <bhavin192@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

On 03/07/2025 00:39, Bhavin via Devel wrote:
From: Bhavin Gandhi <bhavin192@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 <bhavin192@geeksocket.in>
ping! Can anyone take a look at this patch? It fixes a bug when libvirt manages qemu-pr-helper in a multipath setup.

On Thu, Jul 03, 2025 at 12:39:33AM +0530, Bhavin via Devel wrote:
From: Bhavin Gandhi <bhavin192@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 <bhavin192@geeksocket.in> --- src/util/virdevmapper.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> and pushed, thank you for your contribution. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (3)
-
Bhavin
-
Bhavin Gandhi
-
Daniel P. Berrangé