From f47f816a5b1deabc1d501332a1a30af205d22515 Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Wed, 10 May 2023 13:11:47 +0800 Subject: [PATCH] LU-16808 lfs: lfs find --printf won't hang on special files Add O_NONBLOCK flag on opening special files lest it hang. Since '--printf' requires gather_all, and in check_projid case and gather_all case, it open the special file and try to get project id from it, we shouldn't error out on only gather_all case. Signed-off-by: Bobi Jam Change-Id: Ic2afff7bbccf73ff94c64c62799f9b37b18d10a1 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50905 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Andreas Dilger Reviewed-by: Thomas Bertschinger --- lustre/tests/sanity.sh | 16 ++++++++++++++++ lustre/utils/liblustreapi.c | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 4235273..44a38b9 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -7184,6 +7184,22 @@ test_56rc() { } run_test 56rc "check lfs find --mdt-count/--mdt-hash works" +test_56rd() { + local dir=$DIR/$tdir + + test_mkdir $dir + + mkfifo $dir/fifo || error "failed to create fifo file" + found=$($LFS find $dir -t p --printf "%y") + [[ "p" = $found ]] || error "found $found, expect p" + + mknod $dir/chardev c 1 5 || + error "failed to create character device file" + found=$($LFS find $dir -t c --printf "%y") + [[ "c" = $found ]] || error "found $found, expect c" +} +run_test 56rd "check lfs find --printf special files" + test_56s() { # LU-611 #LU-9369 [[ $OSTCOUNT -lt 2 ]] && skip_env "need at least 2 OSTs" diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index b9a2f8e..a48313d 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -5499,20 +5499,22 @@ obd_matches: int projid = 0; if (fd == -2) - fd = open(path, O_RDONLY); + fd = open(path, O_RDONLY | O_NONBLOCK); if (fd > 0) ret = fget_projid(fd, &projid); else ret = -errno; - if (ret) - goto out; - if (projid == param->fp_projid) { - if (param->fp_exclude_projid) - goto decided; - } else { - if (!param->fp_exclude_projid) - goto decided; + if (param->fp_check_projid) { + if (ret) + goto out; + if (projid == param->fp_projid) { + if (param->fp_exclude_projid) + goto decided; + } else { + if (!param->fp_exclude_projid) + goto decided; + } } } -- 1.8.3.1