Whamcloud - gitweb
LU-13688 tests: remove duplicate HSM functions
[fs/lustre-release.git] / lustre / tests / sanity-pcc.sh
index a209f1b..3ed0599 100644 (file)
@@ -11,8 +11,9 @@ SRCDIR=$(dirname $0)
 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
 
 ONLY=${ONLY:-"$*"}
+ALWAYS_EXCEPT="$SANITY_PCC_EXCEPT "
 # bug number for skipped test:
-ALWAYS_EXCEPT=""
+ALWAYS_EXCEPT+=""
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
@@ -26,7 +27,6 @@ init_logging
 
 MULTIOP=${MULTIOP:-multiop}
 OPENFILE=${OPENFILE:-openfile}
-MMAP_CAT=${MMAP_CAT:-mmap_cat}
 MOUNT_2=${MOUNT_2:-"yes"}
 FAIL_ON_ERROR=false
 
@@ -36,8 +36,8 @@ FAIL_ON_ERROR=false
 
 check_and_setup_lustre
 
-if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.12.52) ]]; then
-       skip_env "Need MDS version at least 2.12.52" && exit
+if [[ "$MDS1_VERSION" -lt $(version_code 2.12.52) ]]; then
+       skip "Need MDS version at least 2.12.52"
 fi
 
 # $RUNAS_ID may get set incorrectly somewhere else
@@ -681,6 +681,7 @@ test_4() {
        local loopfile="$TMP/$tfile"
        local mntpt="/mnt/pcc.$tdir"
        local hsm_root="$mntpt/$tdir"
+       local excepts="-e 6 -e 7 -e 8 -e 9"
 
        ! is_project_quota_supported &&
                skip "project quota is not supported" && return
@@ -694,13 +695,26 @@ test_4() {
        lfs project -sp $project_id $DIR/$tdir ||
                error "lfs project -sp $project_id $DIR/$tdir failed"
 
-       # mmap_sanity tst7 failed on the local ext4 filesystem.
-       # It seems that Lustre filesystem does special process for tst 7.
-       # Thus, we exclude tst7 from the PCC testing.
-       $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir -e 7 ||
+       # 1. mmap_sanity tst7 failed on the local ext4 filesystem.
+       #    It seems that Lustre filesystem does special process for tst 7.
+       # 2. There is a mmap problem for PCC when multiple clients read/write
+       #    on a shared mmapped file for mmap_sanity tst 6.
+       # 3. Current CentOS8 kernel does not strictly obey POSIX syntax for
+       #    mmap() within the maping but beyond current end of the underlying
+       #    files: It does not send SIGBUS signals to the process.
+       # 4. For negative file offset, sanity_mmap also failed on 48 bits
+       #    ldiksfs backend due to too large offset: "Value too large for
+       #    defined data type".
+       # mmap_sanity tst7/tst8/tst9 all failed on Lustre and local ext4.
+       # Thus, we exclude sanity tst6/tst7/tst8/tst9 from the PCC testing.
+       $LUSTRE/tests/mmap_sanity -d $DIR/$tdir -m $DIR2/$tdir $excepts ||
                error "mmap_sanity test failed"
        sync; sleep 1; sync
 
+       # Revoke the layout lock, the PCC-cached file will be
+       # detached automatically.
+       do_facet $SINGLEAGT $LCTL \
+               set_param ldlm.namespaces.*mdc*.lru_size=clear
        rm -rf $DIR/$tdir || error "failed to remove $DIR/$tdir"
 }
 run_test 4 "Auto cache test for mmap"
@@ -1373,6 +1387,104 @@ test_17() {
 }
 run_test 17 "Test auto attach for layout refresh"
 
+test_18() {
+       local agt_host=$(facet_active_host $SINGLEAGT)
+       local loopfile="$TMP/$tfile"
+       local mntpt="/mnt/pcc.$tdir"
+       local hsm_root="$mntpt/$tdir"
+       local file=$DIR/$tfile
+       local oldmd5
+       local newmd5
+
+       setup_loopdev $SINGLEAGT $loopfile $mntpt 50
+       copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
+       setup_pcc_mapping $SINGLEAGT \
+               "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
+
+       do_facet $SINGLEAGT $LCTL pcc list $MOUNT
+       do_facet $SINGLEAGT dd if=/dev/urandom of=$file bs=1M count=4 ||
+               error "failed to write $file"
+       do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+               error "failed to attach $file"
+       do_facet $SINGLEAGT $LFS pcc state $file
+       check_lpcc_state $file "readwrite"
+       do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
+               error "failed to detach $file"
+       do_facet $SINGLEAGT $LFS pcc state $file
+       $CHECKSTAT -s 4194304 $file
+       dd if=/dev/zero of=$DIR2/$tfile seek=1k bs=1k count=1 ||
+               error "failed to write $DIR2/$tfile"
+       oldmd5=$(md5sum $DIR2/$tfile | awk '{print $1}')
+       $CHECKSTAT -s 1049600 $DIR2/$tfile || error "$DIR2/$tfile size wrong"
+
+       local lpcc_path=$(lpcc_fid2path $hsm_root $file)
+
+       do_facet $SINGLEAGT $LFS pcc state $file
+       check_file_size $SINGLEAGT $lpcc_path 4194304
+       do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+               error "failed to attach $file"
+       check_lpcc_sizes $SINGLEAGT $lpcc_path $file 1049600
+       newmd5=$(do_facet $SINGLEAGT md5sum $file | awk '{print $1}')
+       [ "$oldmd5" == "$newmd5" ] || error "md5sum differ: $oldmd5 != $newmd5"
+       do_facet $SINGLEAGT $LFS pcc detach $file ||
+               error "failed to detach $file"
+}
+run_test 18 "Verify size correctness after re-attach the file"
+
+test_19() {
+       local agt_host=$(facet_active_host $SINGLEAGT)
+       local loopfile="$TMP/$tfile"
+       local mntpt="/mnt/pcc.$tdir"
+       local hsm_root="$mntpt/$tdir"
+       local file=$DIR/$tfile
+
+       setup_loopdev $SINGLEAGT $loopfile $mntpt 50
+       copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
+       setup_pcc_mapping $SINGLEAGT \
+               "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER\ auto_attach=0"
+
+       do_facet $SINGLEAGT "echo -n QQQQQ > $file" || error "echo $file failed"
+       lpcc_path=$(lpcc_fid2path $hsm_root $file)
+       do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+               error "Failed to attach $file"
+       check_lpcc_state $file "readwrite"
+       check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
+       do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
+               error "Failed to detach $file"
+       do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+               error "Failed to attach $file"
+       check_lpcc_sizes $SINGLEAGT $file $lpcc_path 5
+       do_facet $SINGLEAGT $LFS pcc detach --keep $file ||
+               error "Failed to detach $file"
+}
+run_test 19 "Verify the file re-attach works as expected"
+
+test_20() {
+       local agt_host=$(facet_active_host $SINGLEAGT)
+       local loopfile="$TMP/$tfile"
+       local mntpt="/mnt/pcc.$tdir"
+       local hsm_root="$mntpt/$tdir"
+       local file=$DIR/$tfile
+
+       setup_loopdev $SINGLEAGT $loopfile $mntpt 50
+       copytool setup -m "$MOUNT" -a "$HSM_ARCHIVE_NUMBER"
+       setup_pcc_mapping $SINGLEAGT \
+               "projid={100}\ rwid=$HSM_ARCHIVE_NUMBER"
+
+       do_facet $SINGLEAGT "echo -n QQQQQ > $file" ||
+               error "echo $file failed"
+       do_facet $SINGLEAGT $LFS pcc attach -i $HSM_ARCHIVE_NUMBER $file ||
+               error "Failed to attach $file"
+       do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
+       check_lpcc_state $file "readwrite"
+       do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
+       do_facet $SINGLEAGT "echo 3 > /proc/sys/vm/drop_caches"
+       check_lpcc_state $file "readwrite"
+       do_facet $SINGLEAGT $LFS pcc detach $file ||
+               error "Failed to detach $file"
+}
+run_test 20 "Auto attach works after the inode was once evicted from cache"
+
 complete $SECONDS
 check_and_cleanup_lustre
 exit_status