From: Stephane Thiell Date: Fri, 26 Feb 2021 20:33:04 +0000 (-0800) Subject: LU-14179 lfs: avoid lfs find error with long paths X-Git-Tag: 2.14.51~9 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a6a76df19db61a2015f4cc78f88060f249c955f2 LU-14179 lfs: avoid lfs find error with long paths 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 Change-Id: I44726efd5053c593094587e5c8a4652a3a876641 Reviewed-on: https://review.whamcloud.com/41337 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 865cac4..33d2696 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 2508895..60fd7ea 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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);