Whamcloud - gitweb
LU-16808 lfs: lfs find --printf won't hang on special files 05/50905/6
authorBobi Jam <bobijam@whamcloud.com>
Wed, 10 May 2023 05:11:47 +0000 (13:11 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 20 Jun 2023 03:42:10 +0000 (03:42 +0000)
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 <bobijam@whamcloud.com>
Change-Id: Ic2afff7bbccf73ff94c64c62799f9b37b18d10a1
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50905
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Thomas Bertschinger <bertschinger@lanl.gov>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index 4235273..44a38b9 100755 (executable)
@@ -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"
 
index b9a2f8e..a48313d 100644 (file)
@@ -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;
+                       }
                }
        }