Whamcloud - gitweb
LU-18738 utils: avoid statx() of root of mounted FS 35/58135/2
authorOlaf Faaland <faaland1@llnl.gov>
Tue, 18 Feb 2025 04:46:38 +0000 (20:46 -0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 28 Feb 2025 08:16:30 +0000 (08:16 +0000)
When looking for a specific mounted lustre file system by path, avoid
the stat() or statx() call on lustre file systems whose mountpoints do
not match the given path.

This avoids hangs if the client is disconnected from MDT0 of other
mounted file systems, but the desired file system is reachable.

Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Change-Id: I1c67214f107ae2afe34d050470155807063bda51
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58135
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Reviewed-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/liblustreapi_root.c

index 4bf8617..e413d49 100644 (file)
@@ -47,6 +47,7 @@
 #include <sys/sysmacros.h> /* for makedev() */
 #include <sys/types.h>
 #include <unistd.h>
+#include <assert.h>
 
 #include <libcfs/util/ioctl.h>
 #include <lustre/lustreapi.h>
@@ -210,6 +211,11 @@ static int get_root_path_slow(int want, char *fsname, int *outfd, char *path,
 
                fsnamelen = ptr_end - ptr;
 
+               /* avoid stat/statx call if path does not match mountpoint */
+               if (path && (strlen(path) >= mntlen) &&
+                   (strncmp(mnt.mnt_dir, path, mntlen) != 0))
+                       continue;
+
                /* ignore unaccessible filesystem */
                if (get_file_dev(mnt.mnt_dir, &devmnt))
                        continue;
@@ -233,10 +239,11 @@ static int get_root_path_slow(int want, char *fsname, int *outfd, char *path,
                        break;
                }
 
-               /* Otherwise find the longest matching path */
-               if (path && strlen(path) >= mntlen &&
-                   (strncmp(mnt.mnt_dir, path, mntlen) == 0) &&
-                   (strlen(path) == mntlen || path[mntlen] == '/')) {
+               /*
+                * Otherwise find the longest matching path beginning of path
+                * and mnt_dir already verified to be the same.
+                */
+               if (path && (strlen(path) == mntlen || path[mntlen] == '/')) {
                        rc = 0;
                        break;
                }
@@ -312,6 +319,8 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index,
 {
        int rc = -ENODEV;
 
+       assert(fsname || path);
+
        if (!(want & WANT_INDEX))
                rc = get_root_path_fast(want, fsname, outfd, path, dev, nid);
        if (rc)