Whamcloud - gitweb
LU-14179 lfs: avoid lfs find error with long paths 37/41337/8
authorStephane Thiell <sthiell@stanford.edu>
Fri, 26 Feb 2021 20:33:04 +0000 (12:33 -0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 22 Mar 2021 16:25:58 +0000 (16: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).

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

index 865cac4..33d2696 100755 (executable)
@@ -7756,6 +7756,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 2508895..60fd7ea 100644 (file)
@@ -2220,8 +2220,8 @@ static int llapi_semantic_traverse(char *path, int size, int 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, "/");
@@ -2296,7 +2296,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;
 
@@ -2307,8 +2307,8 @@ static int param_callback(char *path, semantic_func_t sem_init,
 
        param->fp_depth = 0;
 
-       ret = llapi_semantic_traverse(buf, PATH_MAX + 1, -1, sem_init,
-                                      sem_fini, param, NULL);
+       ret = llapi_semantic_traverse(buf, 2 * PATH_MAX, -1, sem_init,
+                                     sem_fini, param, NULL);
 out:
        find_param_fini(param);
        free(buf);