From 971bf36247ce11f18d7b68dfcc364f74d3603b37 Mon Sep 17 00:00:00 2001 From: "Olaf P. Faaland" Date: Fri, 21 Feb 2025 21:29:55 -0800 Subject: [PATCH] LU-18738 utils: avoid statx() of root of mounted FS 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. Lustre-change: https://review.whamcloud.com/58135 Lustre-commit: 2da8542e7069af71566a5d36d53fdc840a63228a Signed-off-by: Olaf Faaland Change-Id: I1c67214f107ae2afe34d050470155807063bda51 Reviewed-by: Andreas Dilger Reviewed-by: Li Xi Reviewed-by: Etienne AUJAMES Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58321 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Gian-Carlo DeFazio Reviewed-by: Oleg Drokin --- lustre/utils/liblustreapi.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 8b596af..5efb1a6 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -73,6 +73,7 @@ #include #include +#include #include #include #include @@ -1351,6 +1352,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; @@ -1374,10 +1380,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; } @@ -1436,6 +1443,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) -- 1.8.3.1