[PATCH] Fix get_pathname() not handling stacked mounts

This get_pathname() issue can be duplicated as follow:

sudo mkdir -p /tmp/test
sudo mount -t tmpfs tmpfs /tmp/test
sudo mount --make-private /tmp/test
sudo mount --bind /tmp/test /tmp/test
sudo mount --bind /tmp/test /tmp/test
sudo mount -o remount,ro /tmp/test

$ sudo crash /usr/lib/debug/boot/vmlinux-$(uname -r)
crash> mount | grep /tmp/test
ffff9648e7febc00 ffff9648d91ac800 tmpfs  tmpfs     /tmp/test 
ffff9648c9281380 ffff9648d91ac800 tmpfs  tmpfs     /tmp/test/
ffff9648c8e9a700 ffff9648d91ac800 tmpfs  tmpfs     /         

The last mount is not printed properly, and this is impacting diagnostic
when looking at vmcore from complex containers mount environments.

Signed-off-by: Georges Aureau <[email protected]>
--
diff --git a/filesys.c b/filesys.c
index 8d13807..af6d616 100644
--- a/filesys.c
+++ b/filesys.c
@@ -3140,6 +3154,7 @@ get_pathname(ulong dentry, char *pathname, int length, 
int full, ulong vfsmnt)
        tmp_vfsmnt = vfsmnt;
 
        do {
+       more_vfsmnt:
                tmp_dentry = parent;
 
                dentry_buf = fill_dentry_cache(tmp_dentry);
@@ -3195,6 +3210,7 @@ get_pathname(ulong dentry, char *pathname, int length, 
int full, ulong vfsmnt)
                                                break;
                                        else
                                                tmp_vfsmnt = mnt_parent;
+                                       goto more_vfsmnt;
                                }
                        } else if (VALID_STRUCT(mount)) {
                                if (tmp_vfsmnt) {
@@ -3213,6 +3229,7 @@ get_pathname(ulong dentry, char *pathname, int length, 
int full, ulong vfsmnt)
                                                break;
                                        else
                                                tmp_vfsmnt = mnt_parent + 
OFFSET(mount_mnt);
+                                       goto more_vfsmnt;
                                }
                        }
                        else {
@@ -3222,6 +3239,9 @@ get_pathname(ulong dentry, char *pathname, int length, 
int full, ulong vfsmnt)
                }
                                                
        } while (tmp_dentry != parent && parent);
+       if (!STREQ(pathname, "/") && LASTCHAR(pathname) == '/') {
+               LASTCHAR(pathname) = '\0';
+       }
 
        if (mnt_buf)
                FREEBUF(mnt_buf);
--
Crash-utility mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

Reply via email to