From 2bb5e14abe88d9c0347b14e8f94eacd677792d1d Mon Sep 17 00:00:00 2001 From: Stephane Thiell Date: Fri, 26 Feb 2021 12:33:04 -0800 Subject: [PATCH] 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). Lustre-change: https://review.whamcloud.com/41337 Lustre-commit: a6a76df19db61a2015f4cc78f88060f249c955f2 Signed-off-by: Stephane Thiell Change-Id: I44726efd5053c593094587e5c8a4652a3a876641 Reviewed-by: Andreas Dilger Reviewed-by: Yang Sheng Reviewed-on: https://review.whamcloud.com/48272 Tested-by: jenkins Tested-by: Maloo --- lustre/tests/sanity.sh | 32 ++++++++++++++++++++++++++++++++ lustre/utils/liblustreapi.c | 8 ++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e72128b..f009551 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index f6f2609..6a8679b 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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); -- 1.8.3.1