Whamcloud - gitweb
LU-19123 utils: allow 'lfs project' on bad symlinks 05/59905/3
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 24 Jun 2025 04:46:25 +0000 (22:46 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 8 Jul 2025 03:59:47 +0000 (03:59 +0000)
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 <adilger@whamcloud.com>
Change-Id: Ibe0504c63270306a68329d8b165e7b83276695c8
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/59905
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Sergey Cheremencev <scherementsev@ddn.com>
Reviewed-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity-quota.sh
lustre/utils/lfs_project.c

index 4a59233..ea95b4f 100755 (executable)
@@ -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"
 
index 1a8ff78..e47ecbd 100644 (file)
@@ -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;