From: Bhavin Gandhi Date: Wed, 2 Jul 2025 19:09:33 +0000 (+0530) Subject: virdevmapper: Always use device name for finding targets X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf8c7af771f1e2de24b28c2d04b6113796937f7f;p=thirdparty%2Flibvirt.git virdevmapper: Always use device name for finding targets 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 Reviewed-by: Daniel P. Berrangé Signed-off-by: Bhavin Gandhi --- 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;