From 588850bbeb258bfaf4b0e9b002efa1d2ebf05790 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Mon, 23 Jun 2025 22:46:25 -0600 Subject: [PATCH] LU-19123 utils: allow 'lfs project' on bad symlinks Running 'lfs project' on a bad symlink reports an error: # ln -s foo /myth/tmp/projid-900/symlink # lfs project -p 1000 /myth/tmp/projid-900/symlink lfs: failed to stat '/myth/tmp/projid-900/symlink': No such file or directory # ln -s symlink3 /myth/tmp/projid-900/symlink3 # lfs project -p 1000 /myth/tmp/projid-900/symlink3 lfs: failed to stat '/myth/tmp/projid-900/symlink3': Too many levels of symbolic links Opening the symlink with open(O_NOFOLLOW) avoids following the symlink and allows the project ID to be set on the symlink itself. Fixes: 501e5b2c8a ("LU-18027 lfs: lfs find handling special files") Signed-off-by: Andreas Dilger Change-Id: Ibe0504c63270306a68329d8b165e7b83276695c8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/59905 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Sergey Cheremencev Reviewed-by: Li Dongyang Reviewed-by: Oleg Drokin --- lustre/tests/sanity-quota.sh | 6 ++++-- lustre/utils/lfs_project.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 4a59233..ea95b4f 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -5035,18 +5035,20 @@ test_64() { touch $dir1/file ln -s $dir1/file $dir1/file_link + ln -s bad $dir1/bad_link + ln -s self $dir1/self_link mkfifo $dir1/fifo $LFS project -srp $TSTPRJID $dir1 >&/dev/null || error "set project should succeed" used=$(getquota -p $TSTPRJID global curinodes) - [ $used -eq 4 ] || error "expected 4 got $used" + (( $used == 6 )) || error "expected 4 got $used" $LFS project -rC $dir1 >&/dev/null || error "clear project should succeed" used=$(getquota -p $TSTPRJID global curinodes) - [ $used -eq 0 ] || error "expected 0 got $used" + (( $used == 0 )) || error "expected 0 got $used" } run_test 64 "lfs project on non dir/files should succeed" diff --git a/lustre/utils/lfs_project.c b/lustre/utils/lfs_project.c index 1a8ff78..e47ecbd 100644 --- a/lustre/utils/lfs_project.c +++ b/lustre/utils/lfs_project.c @@ -103,7 +103,7 @@ new_api: strncpy(bname_path, pathname, PATH_MAX); dname = dirname(dname_path); bname = basename(bname_path); - fd = open(dname, O_RDONLY | O_NOCTTY | O_NDELAY); + fd = open(dname, O_RDONLY | O_NOCTTY | O_NDELAY | O_NOFOLLOW); if (fd < 0) { ret = -errno; goto out; -- 1.8.3.1