# bug number for skipped test:
# UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
# skip test cases failed before landing - Jinshan
-ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 12a 12b 12n 13 24 30a 31a 34 35 36 58 59"
+
+ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 12a 12b 12n 13 30a 31a 34 35 36"
ALWAYS_EXCEPT="$ALWAYS_EXCEPT 110a 200 201 221 222a 223a 223b 225"
LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
cleanup() {
copytool_cleanup
changelog_cleanup
+ cdt_set_sanity_policy
}
search_and_kill_copytool() {
}
cdt_set_sanity_policy() {
- # clear all
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-gc
+ if [[ "$CDT_POLICY_HAD_CHANGED" ]]
+ then
+ # clear all
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
+ CDT_POLICY_HAD_CHANGED=
+ fi
}
cdt_set_no_retry() {
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nra
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NRA
+ CDT_POLICY_HAD_CHANGED=true
}
cdt_clear_no_retry() {
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nra
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NRA
+ CDT_POLICY_HAD_CHANGED=true
}
-cdt_set_no_blocking_restore() {
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+nbr
+cdt_set_non_blocking_restore() {
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=+NBR
+ CDT_POLICY_HAD_CHANGED=true
}
-cdt_clear_no_blocking_restore() {
- do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-nbr
+cdt_clear_non_blocking_restore() {
+ do_facet $SINGLEMDS $LCTL set_param $HSM_PARAM.policy=-NBR
+ CDT_POLICY_HAD_CHANGED=true
}
cdt_clear_mount_state() {
cdt_set_sanity_policy
}
-need2clients() {
- if [[ $CLIENTCOUNT -lt 2 ]]; then
- skip "Need two or more clients, have $CLIENTCOUNT"
+needclients() {
+ local clnt_count=$1
+ if [[ $CLIENTCOUNT -lt $clnt_count ]]; then
+ skip "Need $clnt_count or more clients, have $CLIENTCOUNT"
return 1
fi
return 0
path2fid $1 || error "cannot get fid on $1"
}
+cleanup_large_files() {
+ local ratio=$(df $MOUNT |awk '{print $5}' |sed 's/%//g' |grep -v Use)
+ [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
+}
+
make_large_for_striping() {
local file2=${1/$DIR/$DIR2}
local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
+
+ cleanup_large_files
+
dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
error "cannot create $file2"
path2fid $1 || error "cannot get fid on $1"
make_large_for_progress() {
local file2=${1/$DIR/$DIR2}
+
+ cleanup_large_files
+
# big file is large enough, so copy time is > 30s
# so copytool make 1 progress
# size is not a multiple of 1M to avoid stripe
make_large_for_progress_aligned() {
local file2=${1/$DIR/$DIR2}
+
+ cleanup_large_files
+
# big file is large enough, so copy time is > 30s
# so copytool make 1 progress
# size is a multiple of 1M to have stripe
make_large_for_cancel() {
local file2=${1/$DIR/$DIR2}
+
+ cleanup_large_files
+
# Copy timeout is 100s. 105MB => 105s
dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
error "cannot create $file2"
echo "Start copytool"
copytool_setup
+echo "Set sanity-hsm HSM policy"
+cdt_set_sanity_policy
+
# finished requests are quickly removed from list
set_hsm_param grace_delay 10
run_test 9 "Use of explict archive number, with dedicated copytool"
test_9a() {
- [[ $CLIENTCOUNT -ge 3 ]] ||
- { skip "Need three or more clients"; return 0; }
+ needclients 3 || return 0
local n
local file
$LFS hsm_archive $file || error "could not archive file $file"
wait_request_state $fid ARCHIVE SUCCEED
- check_hsm_flags $file "0x00000001"
+ check_hsm_flags $file "0x00000009"
done
trap - EXIT
}
run_test 10c "Check forbidden archive"
+test_10d() {
+ # test needs a running copytool
+ copytool_setup
+
+ mkdir -p $DIR/$tdir
+ local f=$DIR/$tdir/$tfile
+ local fid=$(copy_file /etc/hosts $f)
+ $LFS hsm_archive $f || error "cannot archive $f"
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ local ar=$(get_hsm_archive_id $f)
+ local dflt=$(get_hsm_param archive_id)
+ [[ $ar == $dflt ]] ||
+ error "archived file is not on default archive: $ar != $dflt"
+
+ copytool_cleanup
+}
+run_test 10d "Archive a file on the default archive id"
+
test_11() {
mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
cp /etc/hosts $HSM_ARCHIVE/$tdir/$tfile
run_test 12g "Restore a released file implicitly"
test_12h() {
- need2clients || return 0
+ needclients 2 || return 0
# test needs a running copytool
copytool_setup
}
run_test 23 "Release does not change a/mtime (utime)"
-test_24() {
+test_24a() {
+ local file=$DIR/$tdir/$tfile
+ local fid
+ local atime0
+ local atime1
+ local mtime0
+ local mtime1
+ local ctime0
+ local ctime1
+
# test needs a running copytool
copytool_setup
mkdir -p $DIR/$tdir
-
- local f=$DIR/$tdir/test_mtime
+ rm -f $file
+ fid=$(make_small $file)
# Create a file and check its states
- local fid=$(make_small $f)
- check_hsm_flags $f "0x00000000"
+ check_hsm_flags $file "0x00000000"
- # make mtime is different
+ # Ensure atime is less than mtime and ctime.
sleep 1
- echo "append" >> $f
- local MTIME=$(stat -c "%Y" $f)
- local ATIME=$(stat -c "%X" $f)
+ echo >> $file
- $LFS hsm_archive $f || error "could not archive file"
+ atime0=$(stat -c "%X" $file)
+ mtime0=$(stat -c "%Y" $file)
+ ctime0=$(stat -c "%Z" $file)
+
+ [ $atime0 -lt $mtime0 ] ||
+ error "atime $atime0 is not less than mtime $mtime0"
+
+ [ $atime0 -lt $ctime0 ] ||
+ error "atime $atime0 is not less than ctime $ctime0"
+
+ # Archive should not change any timestamps.
+ $LFS hsm_archive $file || error "cannot archive '$file'"
wait_request_state $fid ARCHIVE SUCCEED
- # Release and check states
- $LFS hsm_release $f || error "could not release file"
- check_hsm_flags $f "0x0000000d"
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "archive changed atime from $atime0 to $atime1"
- [ "$(stat -c "%Y" $f)" -eq "$MTIME" ] ||
- error "mtime should be $MTIME"
+ [ $mtime0 -eq $mtime1 ] ||
+ error "archive changed mtime from $mtime0 to $mtime1"
- [ "$(stat -c "%X" $f)" -eq "$ATIME" ] ||
- error "atime should be $ATIME"
+ [ $ctime0 -eq $ctime1 ] ||
+ error "archive changed ctime from $ctime0 to $ctime1"
+
+ # Release should not change any timestamps.
+ $LFS hsm_release $file || error "cannot release '$file'"
+ check_hsm_flags $file "0x0000000d"
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "release changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "release changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -eq $ctime1 ] ||
+ error "release changed ctime from $ctime0 to $ctime1"
+
+ # Restore should not change atime or mtime and should not
+ # decrease ctime.
+ $LFS hsm_restore $file
+ wait_request_state $fid RESTORE SUCCEED
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "restore changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "restore changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -le $ctime1 ] ||
+ error "restore changed ctime from $ctime0 to $ctime1"
+
+ copytool_cleanup
+
+ # Once more, after unmount and mount.
+ umount_client $MOUNT || error "cannot unmount '$MOUNT'"
+ mount_client $MOUNT || error "cannot mount '$MOUNT'"
+
+ atime1=$(stat -c "%X" $file)
+ mtime1=$(stat -c "%Y" $file)
+ ctime1=$(stat -c "%Z" $file)
+
+ [ $atime0 -eq $atime1 ] ||
+ error "remount changed atime from $atime0 to $atime1"
+
+ [ $mtime0 -eq $mtime1 ] ||
+ error "remount changed mtime from $mtime0 to $mtime1"
+
+ [ $ctime0 -le $ctime1 ] ||
+ error "remount changed ctime from $ctime0 to $ctime1"
+}
+run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
+
+test_24b() {
+ local file=$DIR/$tdir/$tfile
+ local fid
+ local sum0
+ local sum1
+ # LU-3811
+
+ # Test needs a running copytool.
+ copytool_setup
+ mkdir -p $DIR/$tdir
+
+ # Check that root can do HSM actions on a ordinary user's file.
+ rm -f $file
+ fid=$(make_small $file)
+ sum0=$(md5sum $file)
+
+ chown $RUNAS_ID:$RUNAS_GID $file ||
+ error "cannot chown '$file' to '$RUNAS_ID'"
+
+ chmod ugo-w $DIR/$tdir ||
+ error "cannot chmod '$DIR/$tdir'"
+
+ $LFS hsm_archive $file
+ wait_request_state $fid ARCHIVE SUCCEED
+
+ $LFS hsm_release $file ||
+ check_hsm_flags $file "0x0000000d"
+
+ $LFS hsm_restore $file
+ wait_request_state $fid RESTORE SUCCEED
+
+ # Check that ordinary user can get HSM state.
+ $RUNAS $LFS hsm_state $file ||
+ error "user '$RUNAS_ID' cannot get HSM state of '$file'"
+
+ $LFS hsm_release $file ||
+ check_hsm_flags $file "0x0000000d"
+
+ # Check that ordinary user can accessed released file.
+ sum1=$($RUNAS md5sum $file) ||
+ error "user '$RUNAS_ID' cannot read '$file'"
+
+ [ "$sum0" == "$sum1" ] ||
+ error "md5sum mismatch for '$file'"
copytool_cleanup
}
-run_test 24 "Release does not change a/mtime (i/o)"
+run_test 24b "root can archive, release, and restore user files"
test_25a() {
# test needs a running copytool
test_30a() {
# restore at exec cannot work on agent node (because of Linux kernel
# protection of executables)
- need2clients || return 0
+ needclients 2 || return 0
# test needs a running copytool
copytool_setup
test_30b() {
# restore at exec cannot work on agent node (because of Linux kernel
# protection of executables)
- need2clients || return 0
+ needclients 2 || return 0
# test needs a running copytool
copytool_setup
test_57() {
# Need one client for I/O, one for request
- need2clients || return 0
+ needclients 2 || return 0
# test needs a running copytool
copytool_setup
}
run_test 57 "Archive a file with dirty cache on another node"
-test_58() {
- # test needs a running copytool
- copytool_setup
+truncate_released_file() {
+ local src_file=$1
+ local trunc_to=$2
- mkdir -p $DIR/$tdir
+ local sz=$(stat -c %s $src_file)
local f=$DIR/$tdir/$tfile
- local fid=$(make_small $f)
+ local fid=$(copy_file $1 $f)
+ local ref=$f-ref
+ cp $f $f-ref
$LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
error "could not archive file"
$LFS hsm_release $f || error "could not release file"
- $TRUNCATE $f 0 || error "truncate failed"
+ $TRUNCATE $f $trunc_to || error "truncate failed"
sync
- local sz=$(stat -c %s $f)
- [[ $sz == 0 ]] || error "size after truncate is $sz != 0"
+ local sz1=$(stat -c %s $f)
+ [[ $sz1 == $trunc_to ]] ||
+ error "size after trunc: $sz1 expect $trunc_to, original $sz"
$LFS hsm_state $f
-
check_hsm_flags $f "0x0000000b"
local state=$(get_request_state $fid RESTORE)
- [[ "$state" == "" ]] ||
- error "truncate 0 trigs a restore, state = $state"
+ [[ "$state" == "SUCCEED" ]] ||
+ error "truncate $sz does not trig restore, state = $state"
- copytool_cleanup
+ $TRUNCATE $ref $trunc_to
+ cmp $ref $f || error "file data wrong after truncate"
+
+ rm -f $f $f-ref
}
-run_test 58 "Truncate 0 on a released file must not trigger restore"
-test_59() {
+test_58() {
# test needs a running copytool
copytool_setup
mkdir -p $DIR/$tdir
- local f=$DIR/$tdir/$tfile
- local fid=$(copy_file /etc/passwd $f)
- local ref=$f-ref
- cp $f $ref
- local sz=$(stat -c %s $ref)
- sz=$((sz / 2))
- $TRUNCATE $ref $sz
-
- $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
- error "could not archive file"
- wait_request_state $fid ARCHIVE SUCCEED
- $LFS hsm_release $f || error "could not release file"
-
- $TRUNCATE $f $sz || error "truncate failed"
- sync
-
- local sz1=$(stat -c %s $f)
- [[ $sz1 == $sz ]] || error "size after truncate is $sz1 != $sz"
-
- $LFS hsm_state $f
+ local sz=$(stat -c %s /etc/passwd)
- check_hsm_flags $f "0x0000000b"
+ echo "truncate up from $sz to $((sz*2))"
+ truncate_released_file /etc/passwd $((sz*2))
- local state=$(get_request_state $fid RESTORE)
- [[ "$state" == "SUCCEED" ]] ||
- error "truncate $sz does not trig a successfull restore,"\
- " state = $state"
+ echo "truncate down from $sz to $((sz/2))"
+ truncate_released_file /etc/passwd $((sz/2))
- cmp $ref $f || error "file data wrong after truncate"
+ echo "truncate to 0"
+ truncate_released_file /etc/passwd 0
copytool_cleanup
}
-run_test 59 "Truncate != 0 on a released file"
+run_test 58 "Truncate a released file will trigger restore"
test_90() {
file_count=57
}
run_test 90 "Archive/restore a file list"
-double_verify_reset_ham_param() {
+double_verify_reset_hsm_param() {
local p=$1
echo "Testing $HSM_PARAM.$p"
local val=$(get_hsm_param $p)
}
test_100() {
- double_verify_reset_ham_param loop_period
- double_verify_reset_ham_param grace_delay
- double_verify_reset_ham_param request_timeout
- double_verify_reset_ham_param max_requests
+ double_verify_reset_hsm_param loop_period
+ double_verify_reset_hsm_param grace_delay
+ double_verify_reset_hsm_param request_timeout
+ double_verify_reset_hsm_param max_requests
+ double_verify_reset_hsm_param archive_id
}
run_test 100 "Set coordinator /proc tunables"
}
run_test 107 "Copytool re-register after MDS restart"
+policy_set_and_test()
+{
+ local change="$1"
+ local target="$2"
+ do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
+ local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
+ [[ "$policy" == "$target" ]] ||
+ error "Wrong policy after '$change': '$policy' != '$target'"
+}
+
+test_109() {
+ # to force default policy setting if error
+ CDT_POLICY_HAD_CHANGED=true
+
+ local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
+ local default="NonBlockingRestore [NoRetryAction]"
+ [[ "$policy" == "$default" ]] ||
+ error "default policy has changed,"\
+ " '$policy' != '$default' update the test"
+ policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
+ policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
+ policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
+ policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
+ policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
+ # useless bacause we know but safer for futur changes to use real value
+ local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
+ echo "Next set_param must failed"
+ policy_set_and_test "wrong" "$policy"
+
+ # return to default
+ echo "Back to default policy"
+ cdt_set_sanity_policy
+}
+run_test 109 "Policy display/change"
+
test_110a() {
# test needs a running copytool
copytool_setup
import_file $tdir/$tfile $f
local fid=$(path2fid $f)
- cdt_set_no_blocking_restore
+ cdt_set_non_blocking_restore
md5sum $f
local st=$?
# cleanup
wait_request_state $fid RESTORE SUCCEED
- cdt_clear_no_blocking_restore
+ cdt_clear_non_blocking_restore
# Test result
[[ $st == 1 ]] ||
wait_request_state $fid ARCHIVE SUCCEED
$LFS hsm_release $f
- cdt_set_no_blocking_restore
+ cdt_set_non_blocking_restore
md5sum $f
local st=$?
# cleanup
wait_request_state $fid RESTORE SUCCEED
- cdt_clear_no_blocking_restore
+ cdt_clear_non_blocking_restore
# Test result
[[ $st == 1 ]] ||