[PATCH merged] qemu: fix symlink path comparison in namespace setup
From: sayaoailun <guojianwei007@126.com> When comparing symlink targets in qemuNamespaceMknodOne(), the code directly compares the raw symlink target (which may be a relative path) with data->target (which was normalized to an absolute path in qemuNamespaceMknodItemInit()). This causes false mismatches when the symlink uses a relative path. Fix this by normalizing the symlink target to an absolute path before comparison, using the same logic as qemuNamespaceMknodItemInit(). This fixes VM startup failure with LVM volumes that use relative symlinks, which reported 'Unable to remove symlink: Device or resource busy'. Signed-off-by: sayaoailun <guojianwei007@126.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_namespace.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 4a063064f1..29fec2af45 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1031,9 +1031,26 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data) if (isLink) { g_autofree char *target = NULL; + bool targetMatches = false; - if ((target = g_file_read_link(data->file, NULL)) && - STREQ(target, data->target)) { + if ((target = g_file_read_link(data->file, NULL))) { + /* Normalize relative path to absolute path for comparison, + * using the same logic as qemuNamespaceMknodItemInit(). */ + if (!g_path_is_absolute(target)) { + g_autofree char *fileTmp = g_strdup(data->file); + char *c = NULL; + + if ((c = strrchr(fileTmp, '/'))) + *(c + 1) = '\0'; + + target = g_strdup_printf("%s%s", fileTmp, target); + } + + if (STREQ(target, data->target)) + targetMatches = true; + } + + if (targetMatches) { VIR_DEBUG("Skipping symlink %s -> %s which exists and points to correct target", data->file, data->target); } else { -- 2.56.0
participants (1)
-
Michal Privoznik