Whamcloud - gitweb
LU-14179 lfs: avoid lfs find error with long paths
authorStephane Thiell <sthiell@stanford.edu>
Fri, 26 Feb 2021 20:33:04 +0000 (12:33 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 23 Aug 2022 19:25:58 +0000 (19:25 +0000)
Test that files created in a directory having an absolute path length
of up to PATH_MAX-1 are properly found with lfs find. This change
might not cover other very deep directory tree (above PATH_MAX).

Lustre-change: https://review.whamcloud.com/41337
Lustre-commit: a6a76df19db61a2015f4cc78f88060f249c955f2

Signed-off-by: Stephane Thiell <sthiell@stanford.edu>
Change-Id: I44726efd5053c593094587e5c8a4652a3a876641
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/48272
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index e72128b..f009551 100755 (executable)
@@ -7771,6 +7771,38 @@ test_56ca() {
 }
 run_test 56ca "check lfs find --mirror-count|-N and --mirror-state"
 
+test_56da() { # LU-14179
+       local path=$DIR/$tdir
+
+       test_mkdir $path
+       cd $path
+
+       local longdir=$(str_repeat 'a' 255)
+
+       for i in {1..15}; do
+               path=$path/$longdir
+               test_mkdir $longdir
+               cd $longdir
+       done
+
+       local len=${#path}
+       local lastdir=$(str_repeat 'a' $((4096 - 1 - $len - 1)))
+
+       test_mkdir $lastdir
+       cd $lastdir
+       # PATH_MAX-1
+       (( ${#PWD} == 4095 )) || error "bad PWD length ${#PWD}, expect 4095"
+
+       # NAME_MAX
+       touch $(str_repeat 'f' 255)
+
+       $LFS find $DIR/$tdir --type d |& grep "lfs find: error" &&
+               error "lfs find reported an error"
+
+       rm -rf $DIR/$tdir
+}
+run_test 56da "test lfs find with long paths"
+
 test_57a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
        # note test will not do anything if MDS is not local
index f6f2609..6a8679b 100644 (file)
@@ -2194,8 +2194,8 @@ static int llapi_semantic_traverse(char *path, int size, DIR *parent,
                path[len] = 0;
                if ((len + dent->d_reclen + 2) > size) {
                        llapi_err_noerrno(LLAPI_MSG_ERROR,
-                                         "error: %s: string buffer too small",
-                                         __func__);
+                                         "error: %s: string buffer too small for %s",
+                                         __func__, path);
                        break;
                }
                strcat(path, "/");
@@ -2266,7 +2266,7 @@ static int param_callback(char *path, semantic_func_t sem_init,
                return ret;
        }
 
-       buf = (char *)malloc(PATH_MAX + 1);
+       buf = (char *)malloc(2 * PATH_MAX);
        if (!buf)
                return -ENOMEM;
 
@@ -2277,7 +2277,7 @@ static int param_callback(char *path, semantic_func_t sem_init,
 
        param->fp_depth = 0;
 
-       ret = llapi_semantic_traverse(buf, PATH_MAX + 1, NULL, sem_init,
+       ret = llapi_semantic_traverse(buf, 2 * PATH_MAX, NULL, sem_init,
                                      sem_fini, param, NULL);
 out:
        find_param_fini(param);