Whamcloud - gitweb
LU-15431 llite: skip fast reads if layout is invalid 82/46282/39
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 24 Jan 2022 13:10:03 +0000 (16:10 +0300)
committerOleg Drokin <green@whamcloud.com>
Fri, 14 Jul 2023 02:50:08 +0000 (02:50 +0000)
don't let fast reads from the pagecache if the layout
is not valid.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ie4357a184faf9a5d0e33804270d3cb0cb7e67bb7
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/46282
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Patrick Farrell <pfarrell@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/file.c
lustre/tests/sanity-flr.sh

index 8762331..1217f72 100644 (file)
@@ -1986,6 +1986,7 @@ out:
 static ssize_t
 ll_do_fast_read(struct kiocb *iocb, struct iov_iter *iter)
 {
 static ssize_t
 ll_do_fast_read(struct kiocb *iocb, struct iov_iter *iter)
 {
+       struct ll_inode_info *lli = ll_i2info(file_inode(iocb->ki_filp));
        ssize_t result;
 
        if (!ll_sbi_has_fast_read(ll_i2sbi(file_inode(iocb->ki_filp))))
        ssize_t result;
 
        if (!ll_sbi_has_fast_read(ll_i2sbi(file_inode(iocb->ki_filp))))
@@ -1996,6 +1997,9 @@ ll_do_fast_read(struct kiocb *iocb, struct iov_iter *iter)
        if (iocb->ki_filp->f_flags & O_DIRECT)
                return 0;
 
        if (iocb->ki_filp->f_flags & O_DIRECT)
                return 0;
 
+       if (ll_layout_version_get(lli) == CL_LAYOUT_GEN_NONE)
+               return 0;
+
        result = generic_file_read_iter(iocb, iter);
 
        /* If the first page is not in cache, generic_file_aio_read() will be
        result = generic_file_read_iter(iocb, iter);
 
        /* If the first page is not in cache, generic_file_aio_read() will be
index 439211f..38bea3b 100644 (file)
@@ -4266,6 +4266,97 @@ test_208b() {
 }
 run_test 208b "mirror selection to prefer non-rotational devices for writes"
 
 }
 run_test 208b "mirror selection to prefer non-rotational devices for writes"
 
+test_209a() {
+       local tf=$DIR/$tfile
+       local tmpfile="$TMP/$TESTSUITE-$TESTNAME-multiop.output"
+       local p="$TMP/$TESTSUITE-$TESTNAME.parameters"
+       local osts=$(comma_list $(osts_nodes))
+
+       stack_trap "rm -f $tmpfile"
+
+       mkdir -p $MOUNT2 && mount_client $MOUNT2
+       stack_trap "umount_client $MOUNT2"
+
+       # to make replica on ost1 preferred for new writes
+       save_lustre_params $(get_facets OST) osd*.*OST*.nonrotational > $p
+       stack_trap "restore_lustre_params < $p; rm -f $p"
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST*.nonrotational=0
+       do_nodes $osts \
+               $LCTL set_param osd*.*OST0001*.nonrotational=1
+
+       $LFS setstripe -c1 -i0 $tf || errro "can't create $tf"
+       echo "AAAA" >$tf
+       $LFS mirror extend -N -o1 $tf || error "can't make replica"
+       log "replicated file created"
+
+       cancel_lru_locks mdc
+       cancel_lru_locks osc
+
+       log "open(O_RDONLY) and first read from OST"
+       $MULTIOP $tf vvoO_RDONLY:r4_z0r4_z0r4c >$tmpfile &
+       PID=$!
+       sleep 1
+       log "first read complete"
+
+       echo "BBBB" | dd bs=1 count=4 of=$DIR2/$tfile conv=notrunc ||
+               error "can't write BBBB"
+       log "BBBB written which made replica on ost1 stale"
+
+       log "fast read from pagecache in the original process"
+       kill -USR1 $PID
+       sleep 1
+
+       log "read via $DIR2 new open(2)"
+       $MULTIOP $DIR2/$tfile vvoO_RDONLY:r4c
+
+       log "fast read from pagecache after 5s in the original process"
+       sleep 5
+       kill -USR1 $PID
+       wait $PID
+       cat $tmpfile
+       local nr=$(grep "BBBB" $tmpfile | wc -l)
+       (( nr == 2 )) || {
+               cat $tmpfile
+               error "$nr != 2"
+       }
+
+       log "read via new open(2)"
+       $MULTIOP $tf vvoO_RDONLY:r4c
+}
+run_test 209a "skip fast reads after layout invalidation"
+
+function sum_ost_reads() {
+       $LCTL get_param -n osc.$FSNAME-OST*-osc-[-0-9a-f]*.stats |
+               awk '/^ost_read/{sum=sum+$2}END{print sum}'
+}
+
+test_209b() {
+       local tf=$DIR/$tfile
+
+       dd if=/dev/zero of=$tf bs=4k count=2 || error "can't create file"
+       cancel_lru_locks osc
+       echo "the very first read"
+       cat $tf >/dev/null || error "can't read"
+
+       # cancel layout lock
+       cancel_lru_locks mdc
+
+       # now read again, data must be in the cache, so no ost reads
+       $LCTL set_param osc.*.stats=clear >/dev/null
+       echo "read with warm cache"
+       cat $tf >/dev/null || error "can't read"
+       nr=$(sum_ost_reads)
+       (( nr == 0 )) || error "reads with warm cache"
+
+       # now verify we can catch reads at all
+       cancel_lru_locks osc
+       cat $tf >/dev/null || error "can't read"
+       nr=$(sum_ost_reads)
+       (( nr > 0 )) || error "no reads with cold cache"
+}
+run_test 209b "pagecache can be used after LL cancellation"
+
 complete_test $SECONDS
 check_and_cleanup_lustre
 exit_status
 complete_test $SECONDS
 check_and_cleanup_lustre
 exit_status