3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 # bug number for skipped tests: LU-9795 LU-9795
19 ALWAYS_EXCEPT=" 13 402b $ALWAYS_EXCEPT"
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MMAP_CAT=${MMAP_CAT:-mmap_cat}
32 MOUNT_2=${MOUNT_2:-"yes"}
35 # script only handles up to 10 MDTs (because of MDT_PREFIX)
36 [ $MDSCOUNT -gt 9 ] &&
37 error "script cannot handle more than 9 MDTs, please fix" && exit
39 check_and_setup_lustre
41 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
42 skip_env "Need MDS version at least 2.4.53" && exit
45 # $RUNAS_ID may get set incorrectly somewhere else
46 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
47 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
49 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
50 if getent group nobody; then
52 elif getent group nogroup; then
55 error "No generic nobody group"
60 # if there is no CLIENT1 defined, some tests can be ran on localhost
61 CLIENT1=${CLIENT1:-$HOSTNAME}
62 # if CLIENT2 doesn't exist then use CLIENT1 instead
63 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
65 # Exception is the test which need two separate nodes
66 CLIENT2=${CLIENT2:-$CLIENT1}
69 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
70 # the following associated variables are added:
72 # AGTCOUNT: number of agents
73 # AGTDEV{N}: target HSM mount point (root path of the backend)
74 # agt{N}_HOST: hostname of the agent agt{N}
75 # SINGLEAGT: facet of the single agent
77 # The number of agents is initialized as the number of remote client nodes.
78 # By default, only single copytool is started on a remote client/agent. If there
79 # was no remote client, then the copytool will be started on the local client.
85 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
86 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
88 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
89 if [[ $CLIENTCOUNT -gt 1 ]] &&
90 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
91 skip_env "SHARED_DIRECTORY should be accessible"\
96 # We used to put the HSM archive in $SHARED_DIRECTORY but that
97 # meant NFS issues could hose sanity-hsm sessions. So now we
99 for n in $(seq $AGTCOUNT); do
100 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
101 agent=CLIENT$((n + 1))
102 if [[ -z "${!agent}" ]]; then
103 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
106 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
109 export SINGLEAGT=${SINGLEAGT:-agt1}
111 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
112 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
113 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
114 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
115 export HSMTOOL_TESTDIR
116 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
120 # The test only support up to 10 MDTs
121 MDT_PREFIX="mdt.$FSNAME-MDT000"
122 HSM_PARAM="${MDT_PREFIX}0.hsm"
124 # archive is purged at copytool setup
125 HSM_ARCHIVE_PURGE=true
127 # Don't allow copytool error upon start/setup
128 HSMTOOL_NOERROR=false
131 # Get the backend root path for the given agent facet.
134 local dev=AGTDEV$(facet_number $facet)
141 # get MDT device for each mdc
142 for mdtno in $(seq 1 $MDSCOUNT); do
143 local idx=$(($mdtno - 1))
144 MDT[$idx]=$($LCTL get_param -n \
145 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
146 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
151 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
152 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
156 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 echo "Killing existing copytools on $hosts"
159 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
160 copytool_continue "$hosts"
164 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
165 local wait_timeout=200
166 local wait_start=$SECONDS
167 local wait_end=$((wait_start + wait_timeout))
168 local sleep_time=100000 # 0.1 second
170 while ((SECONDS < wait_end)); do
171 if ! search_copytools $hosts; then
172 echo "copytools stopped in $((SECONDS - wait_start))s"
176 echo "copytools still running on $hosts"
178 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
179 sleep_time=$(bc <<< "$sleep_time * 2")
182 # try to dump Copytool's stack
183 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
184 "echo t >/proc/sysrq-trigger"
186 echo "copytools failed to stop in ${wait_timeout}s"
191 copytool_monitor_setup() {
192 local facet=${1:-$SINGLEAGT}
193 local agent=$(facet_active_host $facet)
195 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
196 local test_dir=$(do_node $agent "$cmd") ||
197 error "Failed to create tempdir on $agent"
198 export HSMTOOL_MONITOR_DIR=$test_dir
200 # Create the fifo and a monitor (cat dies when copytool dies)
201 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
202 error "failed to create copytool fifo on $agent"
203 cmd="cat $test_dir/fifo > $test_dir/events &"
204 cmd+=" echo \\\$! > $test_dir/monitor_pid"
206 if [[ $PDSH == *Rmrsh* ]]; then
207 # This is required for pdsh -Rmrsh and its handling of remote
209 # Regular ssh and pdsh -Rssh work fine without this
210 # backgrounded subshell nonsense.
211 (do_node $agent "$cmd") &
212 export HSMTOOL_MONITOR_PDSH=$!
214 # Slightly racy, but just making a best-effort to catch obvious
217 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
218 error "Failed to start copytool monitor on $agent"
220 do_node $agent "$cmd"
222 error "Failed to start copytool monitor on $agent"
227 copytool_monitor_cleanup() {
228 local facet=${1:-$SINGLEAGT}
229 local agent=$(facet_active_host $facet)
231 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
232 # Should die when the copytool dies, but just in case.
233 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
234 cmd+=" 2>/dev/null || true"
235 do_node $agent "$cmd"
236 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
237 export HSMTOOL_MONITOR_DIR=
240 # The pdsh should die on its own when the monitor dies. Just
241 # in case, though, try to clean up to avoid any cruft.
242 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
243 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
244 export HSMTOOL_MONITOR_PDSH=
254 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
261 local host="$(facet_host "$1")"
262 local prefix=$TESTLOG_PREFIX
263 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
265 printf "${prefix}.copytool${archive_id}_log.${host}.log"
270 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
275 mkdir -p "$(dirname "$2")" ||
276 error "cannot create directory '$(dirname "$2")'"
277 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
282 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
283 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
284 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
285 [ ${#misc_options[@]} -gt 0 ] &&
286 cmd+=" $(IFS=" " echo "$@")"
287 cmd+=" \"$mountpoint\""
289 echo "Starting copytool $facet on $(facet_host $facet)"
290 stack_trap "do_facet $facet pkill -x '$HSMTOOL_BASE' || true" EXIT
291 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
295 local facet="${1:-$SINGLEAGT}"
297 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
300 # Main entry point to perform copytool related operations
304 # setup setup a copytool to run in the background, that copytool will be
306 # import import a file from an HSM backend
307 # rebind rebind an archived file to a new fid
309 # Although the semantics might suggest otherwise, one does not need to 'setup'
310 # a copytool before a call to 'copytool import' or 'copytool rebind'.
318 local fail_on_error=true
319 local -a misc_options
320 while [ $# -gt 0 ]; do
328 local mountpoint="$1"
332 local archive_id="$1"
336 local bandwidth="$1" # in MB/s
339 local fail_on_error=false
342 # Uncommon(/copytool dependent) option
349 # Use default values if needed
350 local facet=${facet:-$SINGLEAGT}
351 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
352 local hsm_root="$(hsm_root "$facet")"
354 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
355 do_facet $facet mkdir -p "$hsm_root" ||
356 error "mkdir '$hsm_root' failed"
360 local copytool=lhsmtool
364 __${copytool}_${action} "${misc_options[@]}"
365 if [ $? -ne 0 ]; then
370 local host="$(facet_host $facet)"
371 error_msg="Failed to start copytool $facet on '$host'"
374 local src="${misc_options[0]}"
375 local dest="${misc_options[1]}"
376 error_msg="Failed to import '$src' to '$dest'"
379 error_msg="could not rebind file"
383 $fail_on_error && error "$error_msg" || echo "$error_msg"
387 get_copytool_event_log() {
388 local facet=${1:-$SINGLEAGT}
389 local agent=$(facet_active_host $facet)
391 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
392 error "Can't get event log: No monitor directory!"
394 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
395 error "Could not collect event log from $agent"
399 local agents=${1:-$(facet_active_host $SINGLEAGT)}
402 "do_nodesv $agents pkill -CONT -x '$HSMTOOL_BASE' || true" EXIT
403 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
404 echo "Copytool is suspended on $agents"
407 copytool_continue() {
408 local agents=${1:-$(facet_active_host $SINGLEAGT)}
410 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
411 echo "Copytool is continued on $agents"
414 copytool_remove_backend() {
416 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
417 echo "Remove from backend: $fid = $be"
418 do_facet $SINGLEAGT rm -f $be
421 file_creation_failure() {
428 df $MOUNT $MOUNT2 >&2
429 error "Not enough space to create $file with $cmd"
432 error "cannot create $file with $cmd, status=$err"
437 # Creates a file using dd
443 local source=${5:-/dev/zero}
447 if [ -n "$conv" ]; then
451 # Create the directory in case it does not exist
452 mkdir -p "$(dirname "$file")"
453 # Delete the file in case it already exist
456 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
457 path2fid "$file" || error "cannot get FID of '$file'"
460 echo "cannot create file '$file'" >&2;
461 # Let the caller decide what to do on error
466 create_empty_file() {
467 create_file "${1/$DIR/$DIR2}" 1M 0 ||
468 file_creation_failure dd "${1/$DIR/$DIR2}" $?
471 create_small_file() {
472 local source_file=/dev/urandom
475 local conv=${2:-fsync}
477 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
478 file_creation_failure dd "${1/$DIR/$DIR2}" $?
481 create_small_sync_file() {
482 create_small_file "$1" sync
485 create_archive_file() {
486 local file="$(hsm_root)/$1"
488 local source=/dev/urandom
490 # Create the counterpart directory of the archive
491 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
492 error "cannot create archive directory '$(dirname "$file")'"
494 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
495 error "cannot create archive file '$file'"
499 local hsm_root="$(hsm_root)"
500 local file="$hsm_root/$2"
502 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
503 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
504 error "mkdir '$(dirname "$file")' failed"
505 do_facet $SINGLEAGT cp -p "$1" "$file" ||
506 error "cannot copy '$1' to '$file'"
515 if [[ "$value" != "" ]]; then
518 for mdtno in $(seq 1 $MDSCOUNT); do
519 local idx=$(($mdtno - 1))
520 local facet=mds${mdtno}
521 # if $arg include -P option, run 1 set_param per MDT on the MGS
522 # else, run set_param on each MDT
523 [[ $arg = *"-P"* ]] && facet=mgs
524 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
525 [[ $? != 0 ]] && rc=1
535 for mdtno in $(seq 1 $MDSCOUNT); do
536 local idx=$(($mdtno - 1))
537 wait_result mds${mdtno} \
538 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
540 error "$key state is not '$target' on mds${mdtno}"
546 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
554 mdts_set_param "$opt -n" "hsm.$param" "$value"
561 mdts_set_param "" hsm_control "$cmd"
562 mdts_check_param hsm_control "$target" 10
565 cdt_set_sanity_policy() {
566 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
569 mdts_set_param "" hsm.policy "+NRA"
570 mdts_set_param "" hsm.policy "-NBR"
571 CDT_POLICY_HAD_CHANGED=
576 mdts_set_param "" hsm.policy "+NRA"
577 CDT_POLICY_HAD_CHANGED=true
580 cdt_clear_no_retry() {
581 mdts_set_param "" hsm.policy "-NRA"
582 CDT_POLICY_HAD_CHANGED=true
585 cdt_set_non_blocking_restore() {
586 mdts_set_param "" hsm.policy "+NBR"
587 CDT_POLICY_HAD_CHANGED=true
590 cdt_clear_non_blocking_restore() {
591 mdts_set_param "" hsm.policy "-NBR"
592 CDT_POLICY_HAD_CHANGED=true
595 cdt_clear_mount_state() {
596 mdts_set_param "-P -d" hsm_control ""
599 cdt_set_mount_state() {
600 mdts_set_param "-P" hsm_control "$1"
601 # set_param -P is asynchronous operation and could race with set_param.
602 # In such case configs could be retrieved and applied at mgc after
603 # set_param -P completion. Sleep here to avoid race with set_param.
604 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
605 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
606 # and 10 seconds to retrieve config from server.
611 mdts_check_param hsm_control "$1" 20
615 set_test_state disabled disabled
619 set_test_state enabled enabled
623 set_test_state shutdown stopped
627 set_test_state purge enabled
633 cdt_set_sanity_policy
637 local client_count=$1
638 if [[ $CLIENTCOUNT -lt $client_count ]]; then
639 skip "Need $client_count or more clients, have $CLIENTCOUNT"
646 $LFS path2fid $1 | tr -d '[]'
647 return ${PIPESTATUS[0]}
655 if [[ $u == "user" ]]; then
656 st=$($RUNAS $LFS hsm_state $f)
659 st=$($LFS hsm_state $f)
662 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
664 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
668 get_hsm_archive_id() {
671 st=$($LFS hsm_state $f)
672 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
674 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
682 local st=$(get_hsm_flags $f)
683 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
686 check_hsm_flags_user() {
690 local st=$(get_hsm_flags $f user)
691 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
703 if [[ "$3" != 1 ]]; then
707 cp $1 $f || file_creation_failure cp $f $?
709 path2fid $f || error "cannot get fid on $f"
712 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
714 # Note that this might lead to surprising behaviours such as deleting an
715 # important file for the currently running test
716 delete_large_files() {
717 printf "Deleting large files...\n" >&2
718 find $MOUNT -size +10M -delete
719 wait_delete_completed
725 wait_update --verbose $(facet_active_host $facet) "$@"
728 wait_request_state() {
732 # 4th arg (mdt index) is optional
734 local mds=mds$(($mdtidx + 1))
736 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
737 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
739 wait_result $mds "$cmd" $state 200 ||
740 error "request on $fid is not $state on $mds"
743 get_request_state() {
747 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
748 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
751 get_request_count() {
755 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
756 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
759 # Ensure the number of HSM request for a given FID is correct
760 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
761 assert_request_count() {
762 local request_count=$(get_request_count $1 $2)
763 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
765 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
772 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
773 [[ -n $fid ]] && cmd+=" | grep '$fid'"
774 cmd+=" | egrep 'WAITING|STARTED'"
776 wait_result $SINGLEMDS "$cmd" "" $timeout ||
777 error "requests did not complete"
780 wait_for_grace_delay() {
781 local val=$(get_hsm_param grace_delay)
785 wait_for_loop_period() {
786 local val=$(get_hsm_param loop_period)
793 # python2.6 in EL6 includes an internal json module
794 local json_parser='import json; import fileinput;'
795 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
796 json_parser+='json.loads([line for line in '
797 json_parser+='fileinput.input()][0]).items()])'
799 echo $raw_event | python -c "$json_parser"
802 get_agent_by_uuid_mdt() {
805 local mds=mds$(($mdtidx + 1))
806 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
810 check_agent_registered_by_mdt() {
813 local mds=mds$(($mdtidx + 1))
814 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
815 if [[ ! -z "$agent" ]]; then
816 echo "found agent $agent on $mds"
818 error "uuid $uuid not found in agent list on $mds"
822 check_agent_unregistered_by_mdt() {
825 local mds=mds$(($mdtidx + 1))
826 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
827 if [[ -z "$agent" ]]; then
828 echo "uuid not found in agent list on $mds"
830 error "uuid found in agent list on $mds: $agent"
834 check_agent_registered() {
837 for mdsno in $(seq 1 $MDSCOUNT); do
838 check_agent_registered_by_mdt $uuid $((mdsno - 1))
842 check_agent_unregistered() {
845 for mdsno in $(seq 1 $MDSCOUNT); do
846 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
851 local agent=${1:-$(facet_active_host $SINGLEAGT)}
853 # Lustre mount-point is mandatory and last parameter on
855 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
857 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
859 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
865 # populate MDT device array
868 # cleanup from previous bad setup
871 # for recovery tests, coordinator needs to be started at mount
873 # the lustre conf must be without hsm on (like for sanity.sh)
874 echo "Set HSM on and start"
875 cdt_set_mount_state enabled
876 cdt_check_state enabled
878 echo "Set sanity-hsm HSM policy"
879 cdt_set_sanity_policy
881 # finished requests are quickly removed from list
882 set_hsm_param grace_delay 10
884 CLIENT_NIDS=( $($LCTL list_nids all) )
886 test_1A() { # was test_1
890 local f=$DIR/$tdir/$tfile
894 check_hsm_flags_user $f "0x00000000"
896 $RUNAS $LFS hsm_set --norelease $f ||
897 error "user could not change hsm flags"
898 check_hsm_flags_user $f "0x00000010"
900 $RUNAS $LFS hsm_clear --norelease $f ||
901 error "user could not clear hsm flags"
902 check_hsm_flags_user $f "0x00000000"
904 # User could not change those flags...
905 $RUNAS $LFS hsm_set --exists $f &&
906 error "user should not set this flag"
907 check_hsm_flags_user $f "0x00000000"
910 $LFS hsm_set --exists $f ||
911 error "root could not change hsm flags"
912 check_hsm_flags_user $f "0x00000001"
914 $LFS hsm_clear --exists $f ||
915 error "root could not clear hsm state"
916 check_hsm_flags_user $f "0x00000000"
919 run_test 1A "lfs hsm flags root/non-root access"
922 local f=$DIR/$tdir/$tfile
923 local fid=$(create_small_file $f)
927 $LFS hsm_archive $f || error "could not archive file"
928 wait_request_state $fid ARCHIVE SUCCEED
930 # Release and check states
931 $LFS hsm_release $f || error "could not release file"
932 echo -n "Verifying released state: "
933 check_hsm_flags $f "0x0000000d"
935 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
937 run_test 1a "mmap & cat a HSM released file"
941 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
942 error "failed to set default stripe"
943 local f=$DIR/$tdir/$tfile
946 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
947 error "failed to create file"
948 local fid=$(path2fid $f)
953 $LFS hsm_archive $f || error "could not archive file"
954 wait_request_state $fid ARCHIVE SUCCEED
957 $LFS hsm_release $f || error "could not release file"
958 echo "verify released state: "
959 check_hsm_flags $f "0x0000000d" && echo "pass"
962 $LFS hsm_restore $f || error "could not restore file"
963 wait_request_state $fid RESTORE SUCCEED
964 echo "verify restored state: "
965 check_hsm_flags $f "0x00000009" && echo "pass"
967 run_test 1b "Archive, Release and Restore composite file"
973 local f=$DIR/$tdir/$tfile
976 # Test whether we can set the maximum archive number.
977 local LOCAL_HSM_ARCHIVE_NUMBER=32
978 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
979 error "root could not change hsm flags"
980 check_hsm_flags_user $f "0x00000001"
981 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
982 local st=$(get_hsm_archive_id $f)
983 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
984 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
986 # Test whether setting archive number 0 results in no change.
987 $LFS hsm_set --exists --archive-id 0 $f ||
988 error "root could not change hsm flags"
989 check_hsm_flags_user $f "0x00000001"
990 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
991 st=$(get_hsm_archive_id $f)
992 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
993 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
995 # Test whether setting archive number > 32 results in error.
996 $LFS hsm_set --exists --archive-id 33 $f &&
997 error "archive number is larger than 32"
998 check_hsm_flags_user $f "0x00000001"
1000 # Test whether setting archive number 16 and archived flag.
1001 LOCAL_HSM_ARCHIVE_NUMBER=16
1002 $LFS hsm_set --exists --archived \
1003 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1004 error "root could not change hsm flags"
1005 check_hsm_flags_user $f "0x00000009"
1006 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1007 st=$(get_hsm_archive_id $f)
1008 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1009 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1011 run_test 1c "Check setting archive-id in lfs hsm_set"
1015 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1016 error "failed to set default stripe"
1017 local f=$DIR/$tdir/$tfile
1020 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1021 error "failed to create file"
1022 local fid=$(path2fid $f)
1027 $LFS hsm_archive $f || error "could not archive file"
1028 wait_request_state $fid ARCHIVE SUCCEED
1031 $LFS hsm_release $f || error "could not release file"
1032 echo "verify released state: "
1033 check_hsm_flags $f "0x0000000d" && echo "pass"
1036 $LFS hsm_restore $f || error "could not restore file"
1037 wait_request_state $fid RESTORE SUCCEED
1038 echo "verify restored state: "
1039 check_hsm_flags $f "0x00000009" && echo "pass"
1041 run_test 1d "Archive, Release and Restore DoM file"
1044 local f=$DIR/$tdir/$tfile
1046 create_empty_file "$f"
1047 # New files are not dirty
1048 check_hsm_flags $f "0x00000000"
1050 # For test, we simulate an archived file.
1051 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1052 check_hsm_flags $f "0x00000001"
1054 # chmod do not put the file dirty
1055 chmod 600 $f || error "could not chmod test file"
1056 check_hsm_flags $f "0x00000001"
1058 # chown do not put the file dirty
1059 chown $RUNAS_ID $f || error "could not chown test file"
1060 check_hsm_flags $f "0x00000001"
1062 # truncate put the file dirty
1063 $TRUNCATE $f 1 || error "could not truncate test file"
1064 check_hsm_flags $f "0x00000003"
1066 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1067 check_hsm_flags $f "0x00000001"
1069 run_test 2 "Check file dirtyness when doing setattr"
1075 # New files are not dirty
1076 cp -p /etc/passwd $f
1077 check_hsm_flags $f "0x00000000"
1079 # For test, we simulate an archived file.
1080 $LFS hsm_set --exists $f ||
1081 error "user could not change hsm flags"
1082 check_hsm_flags $f "0x00000001"
1084 # Reading a file, does not set dirty
1085 cat $f > /dev/null || error "could not read file"
1086 check_hsm_flags $f "0x00000001"
1088 # Open for write without modifying data, does not set dirty
1089 openfile -f O_WRONLY $f || error "could not open test file"
1090 check_hsm_flags $f "0x00000001"
1092 # Append to a file sets it dirty
1093 cp -p /etc/passwd $f.append || error "could not create file"
1094 $LFS hsm_set --exists $f.append ||
1095 error "user could not change hsm flags"
1096 dd if=/etc/passwd of=$f.append bs=1 count=3\
1097 conv=notrunc oflag=append status=noxfer ||
1098 file_creation_failure dd $f.append $?
1099 check_hsm_flags $f.append "0x00000003"
1101 # Modify a file sets it dirty
1102 cp -p /etc/passwd $f.modify || error "could not create file"
1103 $LFS hsm_set --exists $f.modify ||
1104 error "user could not change hsm flags"
1105 dd if=/dev/zero of=$f.modify bs=1 count=3\
1106 conv=notrunc status=noxfer ||
1107 file_creation_failure dd $f.modify $?
1108 check_hsm_flags $f.modify "0x00000003"
1110 # Open O_TRUNC sets dirty
1111 cp -p /etc/passwd $f.trunc || error "could not create file"
1112 $LFS hsm_set --exists $f.trunc ||
1113 error "user could not change hsm flags"
1114 cp /etc/group $f.trunc || error "could not override a file"
1115 check_hsm_flags $f.trunc "0x00000003"
1117 # Mmapped a file sets dirty
1118 cp -p /etc/passwd $f.mmap || error "could not create file"
1119 $LFS hsm_set --exists $f.mmap ||
1120 error "user could not change hsm flags"
1121 multiop $f.mmap OSMWUc || error "could not mmap a file"
1122 check_hsm_flags $f.mmap "0x00000003"
1124 run_test 3 "Check file dirtyness when opening for write"
1127 local f=$DIR/$tdir/$tfile
1128 local fid=$(create_small_file $f)
1131 local st=$(get_request_state $fid CANCEL)
1132 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1134 run_test 4 "Useless cancel must not be registered"
1137 # test needs a running copytool
1141 local f=$DIR/$tdir/$tfile
1142 local fid=$(copy_file /etc/passwd $f)
1144 wait_request_state $fid ARCHIVE SUCCEED
1146 check_hsm_flags $f "0x00000009"
1148 run_test 8 "Test default archive number"
1150 test_9A() { # was test_9
1151 # we do not use the default one to be sure
1152 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1153 copytool setup --archive-id $archive_id
1155 # give time for CT to register with MDTs
1156 sleep $(($MDSCOUNT*2))
1157 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1158 check_agent_registered $uuid
1161 local f=$DIR/$tdir/$tfile
1162 local fid=$(copy_file /etc/passwd $f)
1163 $LFS hsm_archive --archive $archive_id $f
1164 wait_request_state $fid ARCHIVE SUCCEED
1166 check_hsm_flags $f "0x00000009"
1168 run_test 9A "Use of explicit archive number, with dedicated copytool"
1171 needclients 3 || return 0
1177 # start all of the copytools
1178 for n in $(seq $AGTCOUNT); do
1179 copytool setup --facet agt$n
1183 for n in $(seq $AGTCOUNT); do
1184 file=$DIR/$tdir/$tfile.$n
1185 fid=$(create_small_file $file)
1187 $LFS hsm_archive $file || error "could not archive file $file"
1188 wait_request_state $fid ARCHIVE SUCCEED
1189 check_hsm_flags $file "0x00000009"
1192 run_test 9a "Multiple remote agents"
1195 # test needs a running copytool
1198 mkdir -p $DIR/$tdir/d1
1199 local f=$DIR/$tdir/$tfile
1200 local fid=$(copy_file /etc/hosts $f)
1201 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1202 error "hsm_archive failed"
1203 wait_request_state $fid ARCHIVE SUCCEED
1205 local hsm_root="$(copytool_device $SINGLEAGT)"
1206 local archive="$(do_facet $SINGLEAGT \
1207 find "$hsm_root" -name "$fid" -print0)"
1208 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1210 echo "Verifying content"
1211 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1212 echo "Verifying hsm state "
1213 check_hsm_flags $f "0x00000009"
1215 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1216 local st=$(get_hsm_archive_id $f)
1217 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1218 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1220 run_test 10a "Archive a file"
1223 # test needs a running copytool
1227 local f=$DIR/$tdir/$tfile
1228 local fid=$(copy_file /etc/hosts $f)
1229 $LFS hsm_archive $f || error "archive request failed"
1230 wait_request_state $fid ARCHIVE SUCCEED
1232 $LFS hsm_archive $f || error "archive of non dirty file failed"
1233 local cnt=$(get_request_count $fid ARCHIVE)
1234 [[ "$cnt" == "1" ]] ||
1235 error "archive of non dirty file must not make a request"
1237 run_test 10b "Archive of non dirty file must work without doing request"
1240 # test needs a running copytool
1244 local f=$DIR/$tdir/$tfile
1245 local fid=$(copy_file /etc/hosts $f)
1246 $LFS hsm_set --noarchive $f
1247 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1250 run_test 10c "Check forbidden archive"
1253 # test needs a running copytool
1257 local f=$DIR/$tdir/$tfile
1258 local fid=$(copy_file /etc/hosts $f)
1259 $LFS hsm_archive $f || error "cannot archive $f"
1260 wait_request_state $fid ARCHIVE SUCCEED
1262 local ar=$(get_hsm_archive_id $f)
1263 local dflt=$(get_hsm_param default_archive_id)
1264 [[ $ar == $dflt ]] ||
1265 error "archived file is not on default archive: $ar != $dflt"
1267 run_test 10d "Archive a file on the default archive id"
1271 copy2archive /etc/hosts $tdir/$tfile
1272 local f=$DIR/$tdir/$tfile
1274 copytool import $tdir/$tfile $f
1275 echo -n "Verifying released state: "
1276 check_hsm_flags $f "0x0000000d"
1278 local LSZ=$(stat -c "%s" $f)
1279 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1281 echo "Verifying imported size $LSZ=$ASZ"
1282 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1283 echo -n "Verifying released pattern: "
1284 local PTRN=$($GETSTRIPE -L $f)
1286 [[ $PTRN == released ]] || error "Is not released"
1287 local fid=$(path2fid $f)
1288 echo "Verifying new fid $fid in archive"
1290 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1291 error "No archive for fid $fid"
1293 run_test 11a "Import a file"
1296 # test needs a running copytool
1300 local f=$DIR/$tdir/$tfile
1301 local fid=$(copy_file /etc/hosts $f)
1302 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1303 error "hsm_archive failed"
1304 wait_request_state $fid ARCHIVE SUCCEED
1306 local FILE_HASH=$(md5sum $f)
1309 copytool import $fid $f
1311 echo "$FILE_HASH" | md5sum -c
1313 [[ $? -eq 0 ]] || error "Restored file differs"
1315 run_test 11b "Import a deleted file using its FID"
1318 # test needs a running copytool
1322 copy2archive /etc/hosts $tdir/$tfile
1324 local f=$DIR/$tdir/$tfile
1325 copytool import $tdir/$tfile $f
1326 local f2=$DIR2/$tdir/$tfile
1327 echo "Verifying released state: "
1328 check_hsm_flags $f2 "0x0000000d"
1330 local fid=$(path2fid $f2)
1331 $LFS hsm_restore $f2
1332 wait_request_state $fid RESTORE SUCCEED
1334 echo "Verifying file state: "
1335 check_hsm_flags $f2 "0x00000009"
1337 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1339 [[ $? -eq 0 ]] || error "Restored file differs"
1341 run_test 12a "Restore an imported file explicitly"
1344 # test needs a running copytool
1348 copy2archive /etc/hosts $tdir/$tfile
1350 local f=$DIR/$tdir/$tfile
1351 copytool import $tdir/$tfile $f
1352 echo "Verifying released state: "
1353 check_hsm_flags $f "0x0000000d"
1355 cat $f > /dev/null || error "File read failed"
1357 echo "Verifying file state after restore: "
1358 check_hsm_flags $f "0x00000009"
1360 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1362 [[ $? -eq 0 ]] || error "Restored file differs"
1364 run_test 12b "Restore an imported file implicitly"
1367 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1369 # test needs a running copytool
1372 local f=$DIR/$tdir/$tfile
1374 $LFS setstripe -c 2 "$f"
1375 local fid=$(create_file "$f" 1M 5)
1377 local FILE_CRC=$(md5sum $f)
1379 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1380 wait_request_state $fid ARCHIVE SUCCEED
1381 $LFS hsm_release $f || error "release $f failed"
1383 echo "$FILE_CRC" | md5sum -c
1385 [[ $? -eq 0 ]] || error "Restored file differs"
1387 run_test 12c "Restore a file with stripe of 2"
1390 # test needs a running copytool
1395 local f=$DIR/$tdir/$tfile
1396 local fid=$(copy_file /etc/hosts $f)
1397 $LFS hsm_restore $f || error "restore of non archived file failed"
1398 local cnt=$(get_request_count $fid RESTORE)
1399 [[ "$cnt" == "0" ]] ||
1400 error "restore non archived must not make a request"
1401 $LFS hsm_archive $f ||
1402 error "archive request failed"
1403 wait_request_state $fid ARCHIVE SUCCEED
1404 $LFS hsm_restore $f ||
1405 error "restore of non released file failed"
1406 local cnt=$(get_request_count $fid RESTORE)
1407 [[ "$cnt" == "0" ]] ||
1408 error "restore a non dirty file must not make a request"
1410 run_test 12d "Restore of a non archived, non released file must work"\
1411 " without doing request"
1414 # test needs a running copytool
1418 local f=$DIR/$tdir/$tfile
1419 local fid=$(copy_file /etc/hosts $f)
1420 $LFS hsm_archive $f || error "archive request failed"
1421 wait_request_state $fid ARCHIVE SUCCEED
1424 cat /etc/hosts >> $f
1428 $LFS hsm_restore $f && error "restore a dirty file must fail"
1431 run_test 12e "Check forbidden restore"
1434 # test needs a running copytool
1438 local f=$DIR/$tdir/$tfile
1439 local fid=$(copy_file /etc/hosts $f)
1441 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1442 wait_request_state $fid ARCHIVE SUCCEED
1443 $LFS hsm_release $f || error "release of $f failed"
1445 wait_request_state $fid RESTORE SUCCEED
1447 echo -n "Verifying file state: "
1448 check_hsm_flags $f "0x00000009"
1450 diff -q /etc/hosts $f
1452 [[ $? -eq 0 ]] || error "Restored file differs"
1454 run_test 12f "Restore a released file explicitly"
1457 # test needs a running copytool
1461 local f=$DIR/$tdir/$tfile
1462 local fid=$(copy_file /etc/hosts $f)
1464 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1465 wait_request_state $fid ARCHIVE SUCCEED
1466 $LFS hsm_release $f || error "release of $f failed"
1468 diff -q /etc/hosts $f
1471 # we check we had a restore done
1472 wait_request_state $fid RESTORE SUCCEED
1474 [[ $st -eq 0 ]] || error "Restored file differs"
1476 run_test 12g "Restore a released file implicitly"
1479 needclients 2 || return 0
1481 # test needs a running copytool
1485 local f=$DIR/$tdir/$tfile
1486 local fid=$(copy_file /etc/hosts $f)
1488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1489 wait_request_state $fid ARCHIVE SUCCEED
1490 $LFS hsm_release $f || error "release of $f failed"
1492 do_node $CLIENT2 diff -q /etc/hosts $f
1495 # we check we had a restore done
1496 wait_request_state $fid RESTORE SUCCEED
1498 [[ $st -eq 0 ]] || error "Restored file differs"
1500 run_test 12h "Restore a released file implicitly from a second node"
1503 # test needs a running copytool
1507 local f=$DIR/$tdir/$tfile
1508 local fid=$(copy_file /etc/passwd $f)
1509 $LFS hsm_archive $f || error "archive of $f failed"
1510 wait_request_state $fid ARCHIVE SUCCEED
1512 $LFS hsm_release $f || error "release of $f failed"
1516 [[ $? -eq 0 ]] || error "Restored file differs"
1518 run_test 12m "Archive/release/implicit restore"
1521 # test needs a running copytool
1525 copy2archive /etc/hosts $tdir/$tfile
1527 local f=$DIR/$tdir/$tfile
1528 copytool import $tdir/$tfile $f
1530 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1531 error "Restored file differs"
1533 $LFS hsm_release $f || error "release of $f failed"
1535 run_test 12n "Import/implicit restore/release"
1538 # test needs a running copytool
1542 local f=$DIR/$tdir/$tfile
1543 local fid=$(copy_file /etc/hosts $f)
1545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1546 wait_request_state $fid ARCHIVE SUCCEED
1547 $LFS hsm_release $f || error "release of $f failed"
1549 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1550 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1552 # set no retry action mode
1555 diff -q /etc/hosts $f
1558 # we check we had a restore failure
1559 wait_request_state $fid RESTORE FAILED
1561 [[ $st -eq 0 ]] && error "Restore must fail"
1563 # remove no retry action mode
1566 # check file is still released
1567 check_hsm_flags $f "0x0000000d"
1569 # retry w/o failure injection
1570 do_facet $SINGLEMDS lctl set_param fail_loc=0
1572 # to be sure previous RESTORE result is gone
1574 wait_for_grace_delay
1576 diff -q /etc/hosts $f
1579 # we check we had a restore done
1580 wait_request_state $fid RESTORE SUCCEED
1582 [[ $st -eq 0 ]] || error "Restored file differs"
1584 run_test 12o "Layout-swap failure during Restore leaves file released"
1587 # test needs a running copytool
1591 local f=$DIR/$tdir/$tfile
1592 local fid=$(copy_file /etc/hosts $f)
1594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1595 wait_request_state $fid ARCHIVE SUCCEED
1596 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1597 $LFS hsm_release $f || error "cannot release $f"
1598 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1599 $LFS hsm_release $f || error "cannot release $f"
1600 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1602 run_test 12p "implicit restore of a file on copytool mount point"
1605 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1606 skip "need MDS version at least 2.7.58" && return 0
1608 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1609 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1610 error "cannot mount $MOUNT3 on $SINGLEAGT"
1612 # test needs a running copytool
1613 copytool setup -m "$MOUNT3"
1615 local f=$DIR/$tdir/$tfile
1616 local f2=$DIR2/$tdir/$tfile
1617 local fid=$(create_small_file $f)
1618 local orig_size=$(stat -c "%s" $f)
1620 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1621 wait_request_state $fid ARCHIVE SUCCEED
1623 $LFS hsm_release $f || error "could not release file"
1624 check_hsm_flags $f "0x0000000d"
1627 wait_copytools || error "copytool failed to stop"
1629 cat $f > /dev/null &
1631 # wait a bit to allow implicit restore request to be handled.
1632 # if not, next stat would also block on layout-lock.
1635 local size=$(stat -c "%s" $f2)
1636 [ $size -eq $orig_size ] ||
1637 error "$f2: wrong size after archive: $size != $orig_size"
1639 copytool setup -m "$MOUNT3"
1643 size=$(stat -c "%s" $f)
1644 [ $size -eq $orig_size ] ||
1645 error "$f: wrong size after restore: $size != $orig_size"
1647 size=$(stat -c "%s" $f2)
1648 [ $size -eq $orig_size ] ||
1649 error "$f2: wrong size after restore: $size != $orig_size"
1653 size=$(stat -c "%s" $f)
1655 error "$f: wrong size after overwrite: $size != 0"
1657 size=$(stat -c "%s" $f2)
1659 error "$f2: wrong size after overwrite: $size != 0"
1661 run_test 12q "file attributes are refreshed after restore"
1665 for i in {1..10}; do
1666 local archive_dir="$(hsm_root)"/subdir/dir.$i
1668 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1669 for j in {1..10}; do
1670 local archive_file="$archive_dir"/file.$j
1672 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1678 copytool import "subdir" "$DIR/$tdir"
1680 # To check the import, the test uses diff with the -r flag
1681 # This is nice, but diff only checks files one by one, and triggering
1682 # an implicit restore for one file at a time will consume as many
1683 # seconds as there are files to compare. To speed this up, a restore
1684 # operation is triggered manually first.
1686 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1688 # Compare the imported data
1689 do_facet $SINGLEAGT \
1690 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1691 error "imported files differ from archived data"
1693 run_test 13 "Recursively import and restore a directory"
1696 # test needs a running copytool
1700 local f=$DIR/$tdir/$tfile
1701 local fid=$(create_small_file $f)
1702 local sum=$(md5sum $f | awk '{print $1}')
1703 $LFS hsm_archive $f || error "could not archive file"
1704 wait_request_state $fid ARCHIVE SUCCEED
1706 # create released file (simulate llapi_hsm_import call)
1707 local fid2=$(create_empty_file "$f")
1708 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1709 $LFS hsm_release $f || error "could not release file"
1711 # rebind the archive to the newly created file
1712 echo "rebind $fid to $fid2"
1714 copytool rebind $fid $fid2
1716 # restore file and compare md5sum
1717 local sum2=$(md5sum $f | awk '{print $1}')
1719 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1721 run_test 14 "Rebind archived file to a new fid"
1724 # test needs a running copytool
1728 local f=$DIR/$tdir/$tfile
1730 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1734 for i in $(seq 1 $count); do
1735 fids[$i]=$(create_small_file $f.$i)
1736 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1737 $LFS hsm_archive $f.$i || error "could not archive file"
1739 wait_all_done $(($count*60))
1741 stack_trap "rm -f $tmpfile" EXIT
1744 for i in $(seq 1 $count); do
1745 local fid2=$(create_empty_file "${f}.${i}")
1746 # add the rebind operation to the list
1747 echo ${fids[$i]} $fid2 >> $tmpfile
1749 # set it released (simulate llapi_hsm_import call)
1750 $LFS hsm_set --archived --exists $f.$i ||
1751 error "could not force hsm flags"
1752 $LFS hsm_release $f.$i || error "could not release file"
1754 nl=$(wc -l < $tmpfile)
1755 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1757 echo "rebind list of files"
1758 copytool rebind "$tmpfile"
1760 # restore files and compare md5sum
1761 for i in $(seq 1 $count); do
1762 local sum2=$(md5sum $f.$i | awk '{print $1}')
1763 [[ $sum2 == ${sums[$i]} ]] ||
1764 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1767 run_test 15 "Rebind a list of files"
1770 # test needs a running copytool
1774 # create a known size file so we can verify transfer speed
1777 dd if=/dev/zero of=$ref bs=1M count=20
1780 local f=$DIR/$tdir/$tfile
1781 local fid=$(copy_file $ref $f)
1783 local start=$(date +%s)
1785 wait_request_state $fid ARCHIVE SUCCEED
1786 local end=$(date +%s)
1787 # Add 1 to account for rounding errors between start and end (LU-8155)
1788 local duration=$((end - start + 1))
1790 [[ $duration -ge $((goal - 1)) ]] ||
1791 error "Transfer is too fast $duration < $goal"
1793 run_test 16 "Test CT bandwith control option"
1796 local f=$DIR/$tdir/$tfile
1797 create_empty_file "$f"
1799 # Could not release a non-archived file
1800 $LFS hsm_release $f && error "release should not succeed"
1802 # For following tests, we must test them with HS_ARCHIVED set
1803 $LFS hsm_set --exists --archived $f || error "could not add flag"
1805 # Could not release a file if no-release is set
1806 $LFS hsm_set --norelease $f || error "could not add flag"
1807 $LFS hsm_release $f && error "release should not succeed"
1808 $LFS hsm_clear --norelease $f || error "could not remove flag"
1810 # Could not release a file if lost
1811 $LFS hsm_set --lost $f || error "could not add flag"
1812 $LFS hsm_release $f && error "release should not succeed"
1813 $LFS hsm_clear --lost $f || error "could not remove flag"
1815 # Could not release a file if dirty
1816 $LFS hsm_set --dirty $f || error "could not add flag"
1817 $LFS hsm_release $f && error "release should not succeed"
1818 $LFS hsm_clear --dirty $f || error "could not remove flag"
1820 run_test 20 "Release is not permitted"
1823 # test needs a running copytool
1826 local f=$DIR/$tdir/test_release
1828 # Create a file and check its states
1829 local fid=$(create_small_file $f)
1830 check_hsm_flags $f "0x00000000"
1832 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1833 # used until file is flushed to disk
1834 if [ $(facet_fstype ost1) == "zfs" ]; then
1835 # this causes an OST_SYNC rpc to be sent
1836 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1837 # clear locks to reread file data
1838 cancel_lru_locks osc
1841 local orig_size=$(stat -c "%s" $f)
1842 local orig_blocks=$(stat -c "%b" $f)
1844 start_full_debug_logging
1846 $LFS hsm_archive $f || error "could not archive file"
1847 wait_request_state $fid ARCHIVE SUCCEED
1849 local blocks=$(stat -c "%b" $f)
1850 [ $blocks -eq $orig_blocks ] ||
1851 error "$f: wrong block number after archive: " \
1852 "$blocks != $orig_blocks"
1853 local size=$(stat -c "%s" $f)
1854 [ $size -eq $orig_size ] ||
1855 error "$f: wrong size after archive: $size != $orig_size"
1857 # Release and check states
1858 $LFS hsm_release $f || error "could not release file"
1859 check_hsm_flags $f "0x0000000d"
1861 blocks=$(stat -c "%b" $f)
1862 [ $blocks -gt 5 ] &&
1863 error "$f: too many blocks after release: $blocks > 5"
1864 size=$(stat -c "%s" $f)
1865 [ $size -ne $orig_size ] &&
1866 error "$f: wrong size after release: $size != $orig_size"
1868 # Check we can release an file without stripe info
1872 check_hsm_flags $f "0x00000000"
1873 $LFS hsm_archive $f || error "could not archive file"
1874 wait_request_state $fid ARCHIVE SUCCEED
1876 # Release and check states
1877 $LFS hsm_release $f || error "could not release file"
1878 check_hsm_flags $f "0x0000000d"
1880 # Release again a file that is already released is OK
1881 $LFS hsm_release $f || fail "second release should succeed"
1882 check_hsm_flags $f "0x0000000d"
1884 stop_full_debug_logging
1886 run_test 21 "Simple release tests"
1889 # test needs a running copytool
1892 local f=$DIR/$tdir/test_release
1893 local swap=$DIR/$tdir/test_swap
1895 # Create a file and check its states
1896 local fid=$(create_small_file $f)
1897 check_hsm_flags $f "0x00000000"
1899 $LFS hsm_archive $f || error "could not archive file"
1900 wait_request_state $fid ARCHIVE SUCCEED
1902 # Release and check states
1903 $LFS hsm_release $f || error "could not release file"
1904 check_hsm_flags $f "0x0000000d"
1906 create_small_file $swap
1907 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1911 run_test 22 "Could not swap a release file"
1914 # test needs a running copytool
1917 local f=$DIR/$tdir/test_mtime
1919 # Create a file and check its states
1920 local fid=$(create_small_file $f)
1921 check_hsm_flags $f "0x00000000"
1923 $LFS hsm_archive $f || error "could not archive file"
1924 wait_request_state $fid ARCHIVE SUCCEED
1926 # Set modification time in the past
1927 touch -m -a -d @978261179 $f
1929 # Release and check states
1930 $LFS hsm_release $f || error "could not release file"
1931 check_hsm_flags $f "0x0000000d"
1933 local MTIME=$(stat -c "%Y" $f)
1934 local ATIME=$(stat -c "%X" $f)
1935 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1936 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1938 run_test 23 "Release does not change a/mtime (utime)"
1941 local file=$DIR/$tdir/$tfile
1950 # test needs a running copytool
1953 fid=$(create_small_file $file)
1955 # Create a file and check its states
1956 check_hsm_flags $file "0x00000000"
1958 # Ensure atime is less than mtime and ctime.
1962 atime0=$(stat -c "%X" $file)
1963 mtime0=$(stat -c "%Y" $file)
1964 ctime0=$(stat -c "%Z" $file)
1966 [ $atime0 -lt $mtime0 ] ||
1967 error "atime $atime0 is not less than mtime $mtime0"
1969 [ $atime0 -lt $ctime0 ] ||
1970 error "atime $atime0 is not less than ctime $ctime0"
1972 # Archive should not change any timestamps.
1973 $LFS hsm_archive $file || error "cannot archive '$file'"
1974 wait_request_state $fid ARCHIVE SUCCEED
1976 atime1=$(stat -c "%X" $file)
1977 mtime1=$(stat -c "%Y" $file)
1978 ctime1=$(stat -c "%Z" $file)
1980 [ $atime0 -eq $atime1 ] ||
1981 error "archive changed atime from $atime0 to $atime1"
1983 [ $mtime0 -eq $mtime1 ] ||
1984 error "archive changed mtime from $mtime0 to $mtime1"
1986 [ $ctime0 -eq $ctime1 ] ||
1987 error "archive changed ctime from $ctime0 to $ctime1"
1989 # Release should not change any timestamps.
1990 $LFS hsm_release $file || error "cannot release '$file'"
1991 check_hsm_flags $file "0x0000000d"
1993 atime1=$(stat -c "%X" $file)
1994 mtime1=$(stat -c "%Y" $file)
1995 ctime1=$(stat -c "%Z" $file)
1997 [ $atime0 -eq $atime1 ] ||
1998 error "release changed atime from $atime0 to $atime1"
2000 [ $mtime0 -eq $mtime1 ] ||
2001 error "release changed mtime from $mtime0 to $mtime1"
2003 [ $ctime0 -eq $ctime1 ] ||
2004 error "release changed ctime from $ctime0 to $ctime1"
2006 # Restore should not change any timestamps.
2007 $LFS hsm_restore $file
2008 wait_request_state $fid RESTORE SUCCEED
2010 atime1=$(stat -c "%X" $file)
2011 mtime1=$(stat -c "%Y" $file)
2012 ctime1=$(stat -c "%Z" $file)
2014 [ $atime0 -eq $atime1 ] ||
2015 error "restore changed atime from $atime0 to $atime1"
2017 [ $mtime0 -eq $mtime1 ] ||
2018 error "restore changed mtime from $mtime0 to $mtime1"
2020 [ $ctime0 -eq $ctime1 ] ||
2021 error "restore changed ctime from $ctime0 to $ctime1"
2024 wait_copytools || error "Copytools failed to stop"
2026 # Once more, after unmount and mount.
2027 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2028 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2030 atime1=$(stat -c "%X" $file)
2031 mtime1=$(stat -c "%Y" $file)
2032 ctime1=$(stat -c "%Z" $file)
2034 [ $atime0 -eq $atime1 ] ||
2035 error "remount changed atime from $atime0 to $atime1"
2037 [ $mtime0 -eq $mtime1 ] ||
2038 error "remount changed mtime from $mtime0 to $mtime1"
2040 [ $ctime0 -eq $ctime1 ] ||
2041 error "remount changed ctime from $ctime0 to $ctime1"
2043 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2046 local file=$DIR/$tdir/$tfile
2052 # Test needs a running copytool.
2055 # Check that root can do HSM actions on a regular user's file.
2056 fid=$(create_small_file $file)
2057 sum0=$(md5sum $file)
2059 chown $RUNAS_ID:$RUNAS_GID $file ||
2060 error "cannot chown '$file' to '$RUNAS_ID'"
2062 chmod ugo-w $DIR/$tdir ||
2063 error "cannot chmod '$DIR/$tdir'"
2065 $LFS hsm_archive $file
2066 wait_request_state $fid ARCHIVE SUCCEED
2068 $LFS hsm_release $file
2069 check_hsm_flags $file "0x0000000d"
2071 $LFS hsm_restore $file
2072 wait_request_state $fid RESTORE SUCCEED
2074 # Check that ordinary user can get HSM state.
2075 $RUNAS $LFS hsm_state $file ||
2076 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2078 $LFS hsm_release $file
2079 check_hsm_flags $file "0x0000000d"
2081 # Check that ordinary user can accessed released file.
2082 sum1=$($RUNAS md5sum $file) ||
2083 error "user '$RUNAS_ID' cannot read '$file'"
2085 [ "$sum0" == "$sum1" ] ||
2086 error "md5sum mismatch for '$file'"
2088 run_test 24b "root can archive, release, and restore user files"
2091 local file=$DIR/$tdir/$tfile
2092 local action=archive
2097 # test needs a running copytool
2102 # Save the default masks and check that cleanup_24c will
2103 # restore the request masks correctly.
2104 user_save=$(get_hsm_param user_request_mask)
2105 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2106 group_save=$(get_hsm_param group_request_mask)
2107 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2108 other_save=$(get_hsm_param other_request_mask)
2109 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2111 [ "$user_save" == RESTORE ] ||
2112 error "user_request_mask is '$user_save' expected 'RESTORE'"
2113 [ "$group_save" == RESTORE ] ||
2114 error "group_request_mask is '$group_save' expected 'RESTORE'"
2115 [ "$other_save" == RESTORE ] ||
2116 error "other_request_mask is '$other_save' expected 'RESTORE'"
2119 create_small_file $file
2120 chown $RUNAS_ID:$GROUP $file ||
2121 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2123 $RUNAS $LFS hsm_$action $file &&
2124 error "$action by user should fail"
2126 set_hsm_param user_request_mask $action
2127 $RUNAS $LFS hsm_$action $file ||
2128 error "$action by user should succeed"
2131 create_small_file $file
2132 chown nobody:$RUNAS_GID $file ||
2133 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2135 $RUNAS $LFS hsm_$action $file &&
2136 error "$action by group should fail"
2138 set_hsm_param group_request_mask $action
2139 $RUNAS $LFS hsm_$action $file ||
2140 error "$action by group should succeed"
2143 create_small_file $file
2144 chown nobody:$GROUP $file ||
2145 error "cannot chown '$file' to 'nobody:$GROUP'"
2147 $RUNAS $LFS hsm_$action $file &&
2148 error "$action by other should fail"
2150 set_hsm_param other_request_mask $action
2151 $RUNAS $LFS hsm_$action $file ||
2152 error "$action by other should succeed"
2154 run_test 24c "check that user,group,other request masks work"
2157 local file1=$DIR/$tdir/$tfile
2158 local file2=$DIR2/$tdir/$tfile
2162 fid1=$(create_small_file $file1)
2165 $LFS getstripe $file1
2167 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2168 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2169 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2171 copytool setup -m "$MOUNT3"
2173 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2174 mount -o remount,ro $MOUNT2
2176 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2178 fid2=$(path2fid $file2)
2179 [ "$fid1" == "$fid2" ] ||
2180 error "FID mismatch '$fid1' != '$fid2'"
2182 $LFS hsm_archive $file2 &&
2183 error "archive should fail on read-only mount"
2184 check_hsm_flags $file1 "0x00000000"
2186 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2187 wait_request_state $fid1 ARCHIVE SUCCEED
2189 $LFS hsm_release $file1
2190 $LFS hsm_restore $file2
2191 wait_request_state $fid1 RESTORE SUCCEED
2193 $LFS hsm_release $file1 || error "cannot release '$file1'"
2194 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2196 $LFS hsm_release $file2 &&
2197 error "release should fail on read-only mount"
2201 run_test 24d "check that read-only mounts are respected"
2206 local f=$DIR/$tdir/$tfile
2209 fid=$(create_small_file $f) || error "cannot create $f"
2210 $LFS hsm_archive $f || error "cannot archive $f"
2211 wait_request_state $fid ARCHIVE SUCCEED
2212 $LFS hsm_release $f || error "cannot release $f"
2213 while ! $LFS hsm_state $f | grep released; do
2217 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2219 run_test 24e "tar succeeds on HSM released files" # LU-6213
2222 # test needs a running copytool
2225 mkdir -p $DIR/$tdir/d1
2226 local f=$DIR/$tdir/$tfile
2227 local fid=$(copy_file /etc/hosts $f)
2230 $LFS hsm_archive $f ||
2231 error "hsm_archive failed"
2232 wait_request_state $fid ARCHIVE SUCCEED
2233 $LFS hsm_release $f || error "cannot release $f"
2234 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2237 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2238 error "Can not recover the tar contents"
2240 echo "Sum0 = $sum0, sum1 = $sum1"
2241 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2243 run_test 24f "root can archive, release, and restore tar files"
2246 local file=$DIR/$tdir/$tfile
2249 echo "RUNAS = '$RUNAS'"
2254 chmod ugo+rwx $DIR/$tdir
2256 echo "Please listen carefully as our options have changed." | tee $file
2257 fid=$(path2fid $file)
2260 $LFS hsm_archive $file
2261 wait_request_state $fid ARCHIVE SUCCEED
2262 check_hsm_flags $file 0x00000009 # exists archived
2264 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2265 check_hsm_flags $file 0x0000000b # exists dirty archived
2267 run_test 24g "write by non-owner still sets dirty" # LU-11369
2270 # test needs a running copytool
2274 copy2archive /etc/hosts $tdir/$tfile
2276 local f=$DIR/$tdir/$tfile
2278 copytool import $tdir/$tfile $f
2280 $LFS hsm_set --lost $f
2285 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2287 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2288 " (Operation not permitted)"
2291 # test needs a running copytool
2296 local f=$DIR/$tdir/$tfile
2297 local fid=$(copy_file /etc/passwd $f)
2299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2300 wait_request_state $fid ARCHIVE SUCCEED
2303 $LFS hsm_set --lost $f
2307 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2309 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2310 " (Operation not permitted)"
2312 test_26A() { # was test_26
2313 # test needs a running copytool
2316 local f=$DIR/$tdir/$tfile
2317 local fid=$(create_empty_file "$f")
2319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2320 wait_request_state $fid ARCHIVE SUCCEED
2323 wait_request_state $fid REMOVE SUCCEED
2325 check_hsm_flags $f "0x00000000"
2327 run_test 26A "Remove the archive of a valid file"
2330 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2331 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2333 # test needs a running copytool
2337 local f=$DIR/$tdir/$tfile
2338 local fid=$(copy_file /etc/passwd $f)
2340 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2341 wait_request_state $fid ARCHIVE SUCCEED
2343 local f2=$DIR/$tdir/${tfile}_2
2344 local fid2=$(copy_file /etc/passwd $f2)
2346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2347 wait_request_state $fid2 ARCHIVE SUCCEED
2349 local f3=$DIR/$tdir/${tfile}_3
2350 local fid3=$(copy_file /etc/passwd $f3)
2352 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2353 wait_request_state $fid3 ARCHIVE SUCCEED
2355 # set a long grace_delay vs short loop_period
2356 local orig_loop_period=$(get_hsm_param loop_period)
2357 local orig_grace_delay=$(get_hsm_param grace_delay)
2358 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2359 set_hsm_param loop_period 10
2360 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2361 set_hsm_param grace_delay 100
2365 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2366 set_hsm_param remove_archive_on_last_unlink 1
2368 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2373 wait_request_state $fid2 REMOVE SUCCEED
2375 assert_request_count $fid REMOVE 0 \
2376 "Unexpected archived data remove request for $f"
2377 assert_request_count $fid3 REMOVE 0 \
2378 "Unexpected archived data remove request for $f3"
2380 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2383 # test needs a running copytool
2387 local f=$DIR/$tdir/$tfile
2388 local fid=$(copy_file /etc/passwd $f)
2390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2391 wait_request_state $fid ARCHIVE SUCCEED
2393 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2394 set_hsm_param remove_archive_on_last_unlink 1
2397 cdt_check_state stopped
2401 wait_request_state $fid REMOVE WAITING
2405 # copytool must re-register
2407 wait_copytools || error "copytool failed to stop"
2410 wait_request_state $fid REMOVE SUCCEED
2412 run_test 26b "RAoLU policy when CDT off"
2415 # test needs a running copytool
2419 local f=$DIR/$tdir/$tfile
2420 local fid=$(copy_file /etc/passwd $f)
2422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2423 wait_request_state $fid ARCHIVE SUCCEED
2425 local f2=$DIR/$tdir/${tfile}_2
2426 local fid2=$(copy_file /etc/passwd $f2)
2428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2429 wait_request_state $fid2 ARCHIVE SUCCEED
2431 # set a long grace_delay vs short loop_period
2432 local orig_loop_period=$(get_hsm_param loop_period)
2433 local orig_grace_delay=$(get_hsm_param grace_delay)
2434 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2435 set_hsm_param loop_period 10
2436 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2437 set_hsm_param grace_delay 100
2439 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2440 set_hsm_param remove_archive_on_last_unlink 1
2442 multiop_bg_pause $f O_c || error "open $f failed"
2448 wait_request_state $fid2 REMOVE SUCCEED
2449 assert_request_count $fid REMOVE 0 \
2450 "Unexpected archived data remove request for $f"
2452 kill -USR1 $pid || error "multiop early exit"
2453 # should reach autotest timeout if multiop fails to trap
2454 # signal, close file, and exit ...
2455 wait $pid || error "wait PID $PID failed"
2457 wait_request_state $fid REMOVE SUCCEED
2459 run_test 26c "RAoLU effective when file closed"
2462 # test needs a running copytool
2466 local f=$DIR/$tdir/$tfile
2467 local fid=$(create_small_file $f)
2469 $LFS hsm_archive $f || error "could not archive file"
2470 wait_request_state $fid ARCHIVE SUCCEED
2472 # set a long grace_delay vs short loop_period
2473 local orig_loop_period=$(get_hsm_param loop_period)
2474 local orig_grace_delay=$(get_hsm_param grace_delay)
2475 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2476 set_hsm_param loop_period 10
2477 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2478 set_hsm_param grace_delay 100
2480 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2481 set_hsm_param remove_archive_on_last_unlink 1
2483 multiop_bg_pause $f O_c || error "multiop failed"
2490 wait_request_state $fid REMOVE SUCCEED
2492 client_up || client_up || true
2494 kill -USR1 $MULTIPID
2495 wait $MULTIPID || error "multiop close failed"
2497 run_test 26d "RAoLU when Client eviction"
2500 # test needs a running copytool
2503 create_archive_file $tdir/$tfile
2504 local f=$DIR/$tdir/$tfile
2505 copytool import $tdir/$tfile $f
2506 local fid=$(path2fid $f)
2510 [[ $? != 0 ]] || error "Remove of a released file should fail"
2512 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2515 # test needs a running copytool
2518 local f=$DIR/$tdir/$tfile
2519 local fid=$(create_empty_file "$f")
2521 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2522 wait_request_state $fid ARCHIVE SUCCEED
2527 [[ $? != 0 ]] || error "Remove of a released file should fail"
2529 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2532 # test needs a running copytool
2535 local f=$DIR/$tdir/$tfile
2536 local fid=$(create_empty_file "$f")
2538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2539 wait_request_state $fid ARCHIVE SUCCEED
2548 wait_request_state $fid REMOVE SUCCEED
2550 run_test 28 "Concurrent archive/file remove"
2553 # Tests --mntpath and --archive options
2556 copytool setup -m "$MOUNT" -a $archive_id
2558 # Bad archive number
2559 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2560 grep "Invalid argument" ||
2561 error "unexpected hsm_remove failure (1)"
2563 # mntpath is present but file is given
2564 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2565 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2566 error "unexpected hsm_remove failure (2)"
2568 run_test 29a "Tests --mntpath and --archive options"
2571 # test needs a running copytool
2574 local f=$DIR/$tdir/$tfile
2575 local fid=$(create_small_file $f)
2577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2578 wait_request_state $fid ARCHIVE SUCCEED
2582 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2583 wait_request_state $fid REMOVE SUCCEED
2585 run_test 29b "Archive/delete/remove by FID from the archive."
2588 # test needs a running copytool
2591 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2592 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2593 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2595 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2596 wait_request_state $fid1 ARCHIVE SUCCEED
2597 wait_request_state $fid2 ARCHIVE SUCCEED
2598 wait_request_state $fid3 ARCHIVE SUCCEED
2600 rm -f $DIR/$tdir/$tfile-[1-3]
2602 echo $fid1 > $DIR/$tdir/list
2603 echo $fid2 >> $DIR/$tdir/list
2604 echo $fid3 >> $DIR/$tdir/list
2606 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2607 --filelist $DIR/$tdir/list
2608 wait_request_state $fid1 REMOVE SUCCEED
2609 wait_request_state $fid2 REMOVE SUCCEED
2610 wait_request_state $fid3 REMOVE SUCCEED
2612 run_test 29c "Archive/delete/remove by FID, using a file list."
2615 # test needs more than one CT
2616 needclients 3 || return 0
2622 # start all of the copytools
2623 for n in $(seq $AGTCOUNT); do
2624 copytool setup -f agt$n -a $n
2628 file=$DIR/$tdir/$tfile
2629 fid=$(create_small_file $file)
2631 $LFS hsm_archive $file
2632 wait_request_state $fid ARCHIVE SUCCEED
2633 check_hsm_flags $file "0x00000009"
2637 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2638 error "cannot hsm_remove '$fid'"
2640 # give time for CDT to handle remove request and create broadcasted
2643 # remove request has been broadcasted ?
2644 local cnt=$(get_request_count $fid REMOVE)
2645 # broadcasted requests + original
2646 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2647 error "remove not broadcasted to all CTs"
2649 # give time for CDT and CTs to handle broadcasted
2650 wait_for_loop_period
2652 # each agent serves one different archive_id, so broadcasted
2653 # hsm_remove request should only succeed once and fail at all others
2657 for n in $(seq $AGTCOUNT); do
2658 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2659 $HSM_PARAM.actions | awk \
2660 '/'$fid'.*action=REMOVE archive#='$n'/ \
2661 {print \\\$13}' | cut -f2 -d=")
2662 if [[ "$res" == "SUCCEED" ]]; then
2664 elif [[ "$res" == "FAILED" ]]; then
2669 [[ $scnt -eq 1 ]] ||
2670 error "one and only CT should have removed successfully"
2672 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2673 error "all but one CT should have failed to remove"
2675 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2676 "request to be sent once for each registered archive_id"
2679 # restore at exec cannot work on agent node (because of Linux kernel
2680 # protection of executables)
2681 needclients 2 || return 0
2683 # test needs a running copytool
2687 copy2archive /bin/true $tdir/$tfile
2689 local f=$DIR/$tdir/true
2690 copytool import $tdir/$tfile $f
2692 local fid=$(path2fid $f)
2694 stack_trap "cdt_clear_no_retry" EXIT
2695 # set no retry action mode
2702 [[ $st == 0 ]] || error "Failed to exec a released file"
2704 run_test 30a "Restore at exec (import case)"
2707 # restore at exec cannot work on agent node (because of Linux kernel
2708 # protection of executables)
2709 needclients 2 || return 0
2711 # test needs a running copytool
2715 local f=$DIR/$tdir/true
2716 local fid=$(copy_file /bin/true $f)
2718 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2719 wait_request_state $fid ARCHIVE SUCCEED
2723 stack_trap cdt_clear_no_retry EXIT
2724 # set no retry action mode
2732 [[ $st == 0 ]] || error "Failed to exec a released file"
2734 run_test 30b "Restore at exec (release case)"
2737 needclients 2 || return 0
2739 # test needs a running copytool
2743 local f=$DIR/$tdir/SLEEP
2744 local slp_sum1=$(md5sum /bin/sleep)
2745 local fid=$(copy_file /bin/sleep $f)
2747 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2748 wait_request_state $fid ARCHIVE SUCCEED
2750 check_hsm_flags $f "0x0000000d"
2752 stack_trap cdt_clear_no_retry EXIT
2753 # set no retry action mode
2756 do_node $CLIENT2 "$f 10" &
2760 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2762 [[ $? == 0 ]] || error "Execution failed during run"
2764 if [[ $? != 0 ]]; then
2765 local slp_sum2=$(md5sum /bin/sleep)
2766 # in case sleep file is modified during the test
2767 [[ $slp_sum1 == $slp_sum2 ]] &&
2768 error "Binary overwritten during exec"
2771 check_hsm_flags $f "0x00000009"
2773 run_test 30c "Update during exec of released file must fail"
2775 restore_and_check_size() {
2778 local s=$(stat -c "%s" $f)
2780 local st=$(get_hsm_flags $f)
2784 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2786 n=$(stat -c "%s" $f)
2787 # we echo in both cases to show stat is not hang
2788 if [[ $n != $s ]]; then
2789 echo "size seen is $n != $s"
2792 echo "size seen is right: $n == $s"
2796 st=$(get_hsm_flags $f)
2798 if [[ "$st" = "0x00000009" ]]; then
2801 echo " restore is too long"
2802 wait_request_state $fid RESTORE SUCCEED
2808 # test needs a running copytool
2811 create_archive_file $tdir/$tfile
2812 local f=$DIR/$tdir/$tfile
2813 copytool import $tdir/$tfile $f
2814 local fid=$($LFS path2fid $f)
2817 restore_and_check_size $f $fid
2820 [[ $err -eq 0 ]] || error "File size changed during restore"
2822 run_test 31a "Import a large file and check size during restore"
2826 # test needs a running copytool
2829 local f=$DIR/$tdir/$tfile
2830 local fid=$(create_file "$f" 1MB 39)
2832 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2833 wait_request_state $fid ARCHIVE SUCCEED
2836 restore_and_check_size $f $fid
2839 [[ $err -eq 0 ]] || error "File size changed during restore"
2841 run_test 31b "Restore a large unaligned file and check size during restore"
2844 # test needs a running copytool
2847 local f=$DIR/$tdir/$tfile
2848 local fid=$(create_file "$f" 1M 39)
2850 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2851 wait_request_state $fid ARCHIVE SUCCEED
2854 restore_and_check_size $f $fid
2857 [[ $err -eq 0 ]] || error "File size changed during restore"
2859 run_test 31c "Restore a large aligned file and check size during restore"
2862 local f=$DIR/$tdir/$tfile
2863 local fid=$(create_empty_file "$f")
2867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2868 wait_request_state $fid ARCHIVE SUCCEED
2871 # Prevent restore from completing
2875 md5sum $f >/dev/null &
2878 wait_request_state $fid RESTORE STARTED
2883 # Check restore trigger process was killed
2885 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2887 run_test 33 "Kill a restore waiting process"
2890 # test needs a running copytool
2893 local f=$DIR/$tdir/$tfile
2894 local fid=$(create_empty_file "$f")
2896 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2897 wait_request_state $fid ARCHIVE SUCCEED
2900 # Prevent restore from completing
2903 md5sum $f >/dev/null &
2906 wait_request_state $fid RESTORE STARTED
2908 # rm must not block during restore
2909 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2912 wait_request_state $fid RESTORE SUCCEED
2914 # Check md5sum pgm finished
2915 kill -0 $pid && error "Restore initiatior still running"
2916 wait $pid || error "Restore initiator failed with $?"
2918 # Check the file was actually deleted
2919 [ ! -f "$f" ] || error "$f was not deleted"
2921 run_test 34 "Remove file during restore"
2924 # test needs a running copytool
2927 local f=$DIR/$tdir/$tfile
2928 local f1=$DIR/$tdir/$tfile-1
2929 local fid=$(create_empty_file "$f")
2930 local fid1=$(copy_file /etc/passwd $f1)
2932 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2933 wait_request_state $fid ARCHIVE SUCCEED
2936 # Prevent restore from completing
2939 md5sum $f >/dev/null &
2942 wait_request_state $fid RESTORE STARTED
2944 # mv must not block during restore
2945 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2948 wait_request_state $fid RESTORE SUCCEED
2950 # Check md5sum pgm finished
2951 kill -0 $pid && error "Restore initiatior still running"
2952 wait $pid || error "Restore initiator failed with $?"
2954 local fid2=$(path2fid $f)
2955 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2957 run_test 35 "Overwrite file during restore"
2960 # test needs a running copytool
2963 local f=$DIR/$tdir/$tfile
2964 local fid=$(create_empty_file "$f")
2966 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2967 wait_request_state $fid ARCHIVE SUCCEED
2970 # Prevent restore from completing
2973 md5sum $f >/dev/null &
2976 wait_request_state $fid RESTORE STARTED
2978 # mv must not block during restore
2979 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2980 error "mv '$f' '$f.new' failed with rc=$?"
2983 wait_request_state $fid RESTORE SUCCEED
2985 # Check md5sum pgm finished
2986 kill -0 $pid && error "Restore initiator is still running"
2987 wait $pid || error "Restore initiator failed with $?"
2989 run_test 36 "Move file during restore"
2992 # LU-5683: check that an archived dirty file can be rearchived.
2995 local f=$DIR/$tdir/$tfile
2998 fid=$(create_small_file $f) || error "cannot create small file"
3000 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3001 wait_request_state $fid ARCHIVE SUCCEED
3002 $LFS hsm_release $f || error "cannot release $f"
3004 # Allow previous archive request to expire from the actions log.
3005 wait_for_grace_delay
3008 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3010 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3011 wait_request_state $fid ARCHIVE SUCCEED
3013 run_test 37 "re-archive a dirty file"
3020 for n in $(seq 1 $count); do
3021 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3023 echo "$count archive requests submitted"
3027 local stream_count=4
3028 local file_count=100
3030 local f=$DIR/$tdir/$tfile
3034 local max_requests=$(get_hsm_param max_requests)
3036 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3037 # Increase the number of HSM request that can be performed in
3038 # parallel. With the coordinator running once per second, this
3039 # also limits the number of requests per seconds that can be
3040 # performed, so we pick a decent number. But we also need to keep
3041 # that number low because the copytool has no rate limit and will
3042 # fail some requests if if gets too many at once.
3043 set_hsm_param max_requests 300
3045 for i in $(seq 1 $file_count); do
3046 for p in $(seq 1 $stream_count); do
3047 fid=$(copy_file /etc/hosts $f.$p.$i)
3053 # to be sure wait_all_done will not be mislead by previous tests
3055 wait_for_grace_delay
3057 # start archive streams in background (archive files in parallel)
3058 for p in $(seq 1 $stream_count); do
3059 multi_archive $f.$p $file_count &
3062 echo -n "Wait for all requests being enqueued..."
3067 run_test 40 "Parallel archive requests"
3070 # test needs a running copytool
3074 local f=$DIR/$tdir/$tfile
3075 local fid=$(create_small_file $f)
3077 $LFS hsm_archive $f || error "could not archive file"
3078 wait_request_state $fid ARCHIVE SUCCEED
3079 check_hsm_flags $f "0x00000009"
3081 multiop_bg_pause $f O_c || error "multiop failed"
3085 client_up || client_up || true
3087 kill -USR1 $MULTIPID
3088 wait $MULTIPID || error "multiop close failed"
3090 check_hsm_flags $f "0x0000000b"
3092 run_test 52 "Opened for write file on an evicted client should be set dirty"
3095 # test needs a running copytool
3099 local f=$DIR/$tdir/$tfile
3100 local fid=$(create_small_file $f)
3102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3103 error "could not archive file"
3104 wait_request_state $fid ARCHIVE SUCCEED
3105 check_hsm_flags $f "0x00000009"
3107 multiop_bg_pause $f o_c || error "multiop failed"
3111 client_up || client_up || true
3113 kill -USR1 $MULTIPID
3114 wait $MULTIPID || error "multiop close failed"
3116 check_hsm_flags $f "0x00000009"
3118 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3121 local f=$DIR/$tdir/$tfile
3122 local fid=$(create_file "$f" 1MB 39)
3126 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3127 error "could not archive file"
3128 wait_request_state $fid ARCHIVE STARTED
3130 check_hsm_flags $f "0x00000001"
3132 stack_trap "cdt_clear_no_retry" EXIT
3133 # Avoid coordinator resending this request as soon it has failed.
3138 wait_request_state $fid ARCHIVE FAILED
3140 check_hsm_flags $f "0x00000003"
3142 run_test 54 "Write during an archive cancels it"
3145 local f=$DIR/$tdir/$tfile
3146 local fid=$(create_file "$f" 1MB 39)
3150 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3151 error "could not archive file"
3152 wait_request_state $fid ARCHIVE STARTED
3154 check_hsm_flags $f "0x00000001"
3156 stack_trap "cdt_clear_no_retry" EXIT
3157 # Avoid coordinator resending this request as soon it has failed.
3160 $TRUNCATE $f 1024 || error "truncate failed"
3162 wait_request_state $fid ARCHIVE FAILED
3164 check_hsm_flags $f "0x00000003"
3166 run_test 55 "Truncate during an archive cancels it"
3169 local f=$DIR/$tdir/$tfile
3170 local fid=$(create_file "$f" 1MB 39)
3174 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3175 error "could not archive file"
3176 wait_request_state $fid ARCHIVE STARTED
3178 check_hsm_flags $f "0x00000001"
3180 # Change metadata and sync to be sure we are not changing only
3185 wait_request_state $fid ARCHIVE SUCCEED
3187 check_hsm_flags $f "0x00000009"
3189 run_test 56 "Setattr during an archive is ok"
3192 # Need one client for I/O, one for request
3193 needclients 2 || return 0
3195 # test needs a running copytool
3199 local f=$DIR/$tdir/test_archive_remote
3200 # Create a file on a remote node
3201 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3202 "count=2 conv=fsync"
3205 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3206 error "hsm_archive failed"
3207 local fid=$(path2fid $f)
3208 wait_request_state $fid ARCHIVE SUCCEED
3210 # Release and implicit restore it
3211 do_node $CLIENT2 "$LFS hsm_release $f" ||
3212 error "hsm_release failed"
3213 do_node $CLIENT2 "md5sum $f" ||
3214 error "hsm_restore failed"
3216 wait_request_state $fid RESTORE SUCCEED
3218 run_test 57 "Archive a file with dirty cache on another node"
3220 truncate_released_file() {
3224 local sz=$(stat -c %s $src_file)
3225 local f=$DIR/$tdir/$tfile
3226 local fid=$(copy_file $1 $f)
3230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3231 error "could not archive file"
3232 wait_request_state $fid ARCHIVE SUCCEED
3234 $LFS hsm_release $f || error "could not release file"
3236 $TRUNCATE $f $trunc_to || error "truncate failed"
3239 local sz1=$(stat -c %s $f)
3240 [[ $sz1 == $trunc_to ]] ||
3241 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3244 check_hsm_flags $f "0x0000000b"
3246 local state=$(get_request_state $fid RESTORE)
3247 [[ "$state" == "SUCCEED" ]] ||
3248 error "truncate $sz does not trig restore, state = $state"
3250 $TRUNCATE $ref $trunc_to
3251 cmp $ref $f || error "file data wrong after truncate"
3257 # test needs a running copytool
3262 local sz=$(stat -c %s /etc/passwd)
3264 echo "truncate up from $sz to $((sz*2))"
3265 truncate_released_file /etc/passwd $((sz*2))
3267 echo "truncate down from $sz to $((sz/2))"
3268 truncate_released_file /etc/passwd $((sz/2))
3270 echo "truncate to 0"
3271 truncate_released_file /etc/passwd 0
3273 run_test 58 "Truncate a released file will trigger restore"
3277 local server_version=$(lustre_version_code $SINGLEMDS)
3278 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3279 skip "Need MDS version at least 2.7.63" && return
3282 $MCREATE $DIR/$tfile || error "mcreate failed"
3283 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3284 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3285 fid=$(path2fid $DIR/$tfile)
3286 wait_request_state $fid ARCHIVE SUCCEED
3287 $LFS hsm_release $DIR/$tfile || error "release failed"
3289 run_test 59 "Release stripeless file with non-zero size"
3292 # This test validates the fix for LU-4512. Ensure that the -u
3293 # option changes the progress reporting interval from the
3294 # default (30 seconds) to the user-specified interval.
3295 local f=$DIR/$tdir/$tfile
3296 local fid=$(create_file "$f" 1M 10)
3299 local progress_timeout=$((interval * 4))
3300 copytool setup -b 1 --update-interval $interval
3303 local mdt=${MDT_PREFIX}${mdtidx}
3304 local mds=mds$((mdtidx + 1))
3306 # Wait for copytool to register
3307 wait_update_facet $mds \
3308 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3309 uuid 100 || error "coyptool failed to register with $mdt"
3311 local start_at=$(date +%s)
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3313 error "could not archive file"
3315 local agent=$(facet_active_host $SINGLEAGT)
3316 local logfile=$(copytool_logfile $SINGLEAGT)
3318 wait_update $agent \
3319 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3320 error "copytool failed to start"
3322 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3323 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3329 echo -n "Expecting a progress update within $progress_timeout seconds... "
3331 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3332 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3333 echo "$RESULT bytes copied in $WAIT seconds."
3335 elif [ $WAIT -ge $progress_timeout ]; then
3336 error "Timed out waiting for progress update!"
3339 WAIT=$((WAIT + sleep))
3343 local finish_at=$(date +%s)
3344 local elapsed=$((finish_at - start_at))
3346 # Ensure that the progress update occurred within the expected window.
3347 if [ $elapsed -lt $((interval - 1)) ]; then
3348 error "Expected progress update after at least $interval seconds"
3351 echo "Wait for on going archive hsm action to complete"
3352 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3353 echo "File archiving not completed even after 10 secs"
3355 run_test 60 "Changing progress update interval from default"
3358 # test needs a running copytool
3362 local f=$DIR/$tdir/$tfile
3363 local fid=$(copy_file /etc/passwd $f)
3365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3368 wait_request_state $fid ARCHIVE FAILED
3370 run_test 61 "Waiting archive of a removed file should fail"
3373 # test needs a new running copytool
3374 stack_trap copytool_monitor_cleanup EXIT
3375 copytool_monitor_setup
3376 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3378 # Wait for the copytool to register.
3379 wait_update --verbose $(facet_active_host mds1) \
3380 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3382 error "copytool failed to register with MDT0000"
3385 wait_copytools || error "Copytools failed to stop"
3387 local REGISTER_EVENT
3388 local UNREGISTER_EVENT
3389 while read event; do
3390 local parsed=$(parse_json_event "$event")
3391 if [ -z "$parsed" ]; then
3392 error "Copytool sent malformed event: $event"
3396 if [ $event_type == "REGISTER" ]; then
3397 REGISTER_EVENT=$event
3398 elif [ $event_type == "UNREGISTER" ]; then
3399 UNREGISTER_EVENT=$event
3401 done < <(echo $"$(get_copytool_event_log)")
3403 if [ -z "$REGISTER_EVENT" ]; then
3404 error "Copytool failed to send register event to FIFO"
3407 if [ -z "$UNREGISTER_EVENT" ]; then
3408 error "Copytool failed to send unregister event to FIFO"
3411 echo "Register/Unregister events look OK."
3413 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3416 # Bump progress interval for livelier events.
3419 # test needs a new running copytool
3420 stack_trap copytool_monitor_cleanup EXIT
3421 copytool_monitor_setup
3422 copytool setup --update-interval $interval --event-fifo \
3423 "$HSMTOOL_MONITOR_DIR/fifo"
3425 stack_trap "cdt_clear_no_retry" EXIT
3426 # Just start and stop the copytool to generate events.
3429 local f=$DIR/$tdir/$tfile
3430 local fid=$(create_small_file "$f")
3432 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3433 error "could not archive file"
3434 wait_request_state $fid ARCHIVE SUCCEED
3436 local expected_fields="event_time data_fid source_fid"
3437 expected_fields+=" total_bytes current_bytes"
3440 [ARCHIVE_START]=false
3441 [ARCHIVE_FINISH]=false
3442 [ARCHIVE_RUNNING]=false
3444 while read event; do
3445 # Make sure we're not getting anything from previous events.
3446 for field in $expected_fields; do
3450 local parsed=$(parse_json_event "$event")
3451 if [ -z "$parsed" ]; then
3452 error "Copytool sent malformed event: $event"
3456 events["$event_type"]=true
3458 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3460 # Do some simple checking of the progress update events.
3461 for expected_field in $expected_fields; do
3462 if [ -z ${!expected_field+x} ]; then
3463 error "Missing $expected_field field in event"
3467 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3469 # These should be identical throughout an archive operation
3470 [ $source_fid == $data_fid ] ||
3471 error "Expected source_fid to equal data_fid"
3472 done < <(echo $"$(get_copytool_event_log)")
3474 # Check we received every type of events we were expecting
3475 for event in "${!events[@]}"; do
3476 ${events["$event"]} ||
3477 error "Copytool failed to send '$event' event to FIFO"
3480 echo "Archive events look OK."
3482 run_test 71 "Copytool logs JSON archive events to FIFO"
3485 # Bump progress interval for livelier events.
3488 # test needs a new running copytool
3489 stack_trap copytool_monitor_cleanup EXIT
3490 copytool_monitor_setup
3491 copytool setup --update-interval $interval --event-fifo \
3492 "$HSMTOOL_MONITOR_DIR/fifo"
3493 local test_file=$HSMTOOL_MONITOR_DIR/file
3495 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3497 do_facet $SINGLEAGT "$cmd" ||
3498 error "cannot create $test_file on $SINGLEAGT"
3499 copy2archive $test_file $tdir/$tfile
3502 local f=$DIR/$tdir/$tfile
3503 copytool import $tdir/$tfile $f
3504 f=$DIR2/$tdir/$tfile
3505 echo "Verifying released state: "
3506 check_hsm_flags $f "0x0000000d"
3508 local fid=$(path2fid $f)
3510 wait_request_state $fid RESTORE SUCCEED
3512 local expected_fields="event_time data_fid source_fid"
3513 expected_fields+=" total_bytes current_bytes"
3517 while read event; do
3518 # Make sure we're not getting anything from previous events.
3519 for field in $expected_fields; do
3523 local parsed=$(parse_json_event "$event")
3524 if [ -z "$parsed" ]; then
3525 error "Copytool sent malformed event: $event"
3529 if [ $event_type == "RESTORE_START" ]; then
3531 if [ $source_fid != $data_fid ]; then
3532 error "source_fid should == data_fid at start"
3535 elif [ $event_type == "RESTORE_FINISH" ]; then
3537 if [ $source_fid != $data_fid ]; then
3538 error "source_fid should == data_fid at finish"
3541 elif [ $event_type != "RESTORE_RUNNING" ]; then
3545 # Do some simple checking of the progress update events.
3546 for expected_field in $expected_fields; do
3547 if [ -z ${!expected_field+x} ]; then
3548 error "Missing $expected_field field in event"
3552 if [ $total_bytes -eq 0 ]; then
3553 error "Expected total_bytes to be > 0"
3556 # When a restore starts out, the data fid is the same as the
3557 # source fid. After the restore has gotten going, we learn
3558 # the new data fid. Once the restore has finished, the source
3559 # fid is set to the new data fid.
3561 # We test this because some monitoring software may depend on
3562 # this behavior. If it changes, then the consumers of these
3563 # events may need to be modified.
3564 if [ $source_fid == $data_fid ]; then
3565 error "source_fid should != data_fid during restore"
3567 done < <(echo $"$(get_copytool_event_log)")
3569 if [ -z "$START_EVENT" ]; then
3570 error "Copytool failed to send restore start event to FIFO"
3573 if [ -z "$FINISH_EVENT" ]; then
3574 error "Copytool failed to send restore finish event to FIFO"
3577 echo "Restore events look OK."
3579 run_test 72 "Copytool logs JSON restore events to FIFO"
3582 file_count=51 # Max number of files constrained by LNET message size
3583 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3584 local f=$DIR/$tdir/$tfile
3585 local FILELIST=/tmp/filelist.txt
3589 for i in $(seq 1 $file_count); do
3590 fid=$(copy_file /etc/hosts $f.$i)
3591 echo $f.$i >> $FILELIST
3595 # to be sure wait_all_done will not be mislead by previous tests
3597 wait_for_grace_delay
3598 $LFS hsm_archive --filelist $FILELIST ||
3599 error "cannot archive a file list"
3601 $LFS hsm_release --filelist $FILELIST ||
3602 error "cannot release a file list"
3603 $LFS hsm_restore --filelist $FILELIST ||
3604 error "cannot restore a file list"
3607 run_test 90 "Archive/restore a file list"
3609 double_verify_reset_hsm_param() {
3611 echo "Testing $HSM_PARAM.$p"
3612 local val=$(get_hsm_param $p)
3614 local val2=$(($val * 2))
3615 set_hsm_param $p $val2
3616 val=$(get_hsm_param $p)
3617 [[ $val == $val2 ]] ||
3618 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3619 echo "Set $p to 0 must failed"
3623 set_hsm_param $p $save
3625 if [[ $rc == 0 ]]; then
3626 error "we must not be able to set $HSM_PARAM.$p to 0"
3631 double_verify_reset_hsm_param loop_period
3632 double_verify_reset_hsm_param grace_delay
3633 double_verify_reset_hsm_param active_request_timeout
3634 double_verify_reset_hsm_param max_requests
3635 double_verify_reset_hsm_param default_archive_id
3637 run_test 100 "Set coordinator /proc tunables"
3644 run_test 102 "Verify coordinator control"
3647 # test needs a running copytool
3654 for i in $(seq 1 20); do
3655 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3657 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3661 echo "Current requests"
3662 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3663 $HSM_PARAM.actions |\
3664 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3666 [[ -z "$res" ]] || error "Some request have not been canceled"
3668 run_test 103 "Purge all requests"
3673 local f=$DIR/$tdir/$tfile
3674 local fid=$(create_empty_file "$f")
3676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3677 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3678 $HSM_PARAM.actions |\
3679 grep $fid | cut -f16 -d=")
3681 [[ "$data1" == "$DATAHEX" ]] ||
3682 error "Data field in records is ($data1) and not ($DATAHEX)"
3686 run_test 104 "Copy tool data field"
3689 local max_requests=$(get_hsm_param max_requests)
3693 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3694 set_hsm_param max_requests 300
3697 for i in $(seq -w 1 10); do
3698 cp /etc/passwd $DIR/$tdir/$i
3699 $LFS hsm_archive $DIR/$tdir/$i
3701 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3702 $HSM_PARAM.actions |\
3703 grep WAITING | wc -l")
3707 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3708 $HSM_PARAM.actions |\
3709 grep WAITING | wc -l")
3712 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3713 error "Requests count after shutdown $reqcnt2 != "\
3714 "before shutdown $reqcnt1"
3716 run_test 105 "Restart of coordinator"
3719 # test needs a running copytool
3722 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3724 check_agent_registered $uuid
3726 search_copytools || error "No copytool found"
3729 wait_copytools || error "Copytool failed to stop"
3731 check_agent_unregistered $uuid
3734 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3735 check_agent_registered $uuid
3737 run_test 106 "Copytool register/unregister"
3740 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3742 # test needs a running copytool
3744 # create and archive file
3746 local f1=$DIR/$tdir/$tfile
3747 local fid=$(copy_file /etc/passwd $f1)
3748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3749 wait_request_state $fid ARCHIVE SUCCEED
3750 # shutdown and restart MDS
3752 # check the copytool still gets messages from MDT
3753 local f2=$DIR/$tdir/2
3754 local fid=$(copy_file /etc/passwd $f2)
3755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3756 # main check of this sanity: this request MUST succeed
3757 wait_request_state $fid ARCHIVE SUCCEED
3759 run_test 107 "Copytool re-register after MDS restart"
3761 policy_set_and_test()
3765 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3766 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3767 [[ "$policy" == "$target" ]] ||
3768 error "Wrong policy after '$change': '$policy' != '$target'"
3772 # to force default policy setting if error
3773 CDT_POLICY_HAD_CHANGED=true
3775 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3776 local default="NonBlockingRestore [NoRetryAction]"
3777 [[ "$policy" == "$default" ]] ||
3778 error "default policy has changed,"\
3779 " '$policy' != '$default' update the test"
3780 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3781 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3782 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3783 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3784 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3785 # useless bacause we know but safer for futur changes to use real value
3786 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3787 echo "Next set_param must failed"
3788 policy_set_and_test "wrong" "$policy"
3791 echo "Back to default policy"
3792 cdt_set_sanity_policy
3794 run_test 109 "Policy display/change"
3797 # test needs a running copytool
3802 copy2archive /etc/passwd $tdir/$tfile
3804 local f=$DIR/$tdir/$tfile
3805 copytool import $tdir/$tfile $f
3806 local fid=$(path2fid $f)
3808 cdt_set_non_blocking_restore
3813 wait_request_state $fid RESTORE SUCCEED
3814 cdt_clear_non_blocking_restore
3818 error "md5sum returns $st != 1, "\
3819 "should also perror ENODATA (No data available)"
3821 run_test 110a "Non blocking restore policy (import case)"
3824 # test needs a running copytool
3828 local f=$DIR/$tdir/$tfile
3829 local fid=$(copy_file /etc/passwd $f)
3830 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3831 wait_request_state $fid ARCHIVE SUCCEED
3834 cdt_set_non_blocking_restore
3839 wait_request_state $fid RESTORE SUCCEED
3840 cdt_clear_non_blocking_restore
3844 error "md5sum returns $st != 1, "\
3845 "should also perror ENODATA (No data available)"
3847 run_test 110b "Non blocking restore policy (release case)"
3850 # test needs a running copytool
3854 copy2archive /etc/passwd $tdir/$tfile
3856 local f=$DIR/$tdir/$tfile
3858 copytool import $tdir/$tfile $f
3859 local fid=$(path2fid $f)
3863 copytool_remove_backend $fid
3866 wait_request_state $fid RESTORE FAILED
3873 [[ $st == 0 ]] || error "Restore does not failed"
3875 run_test 111a "No retry policy (import case), restore will error"\
3876 " (No such file or directory)"
3879 # test needs a running copytool
3883 local f=$DIR/$tdir/$tfile
3884 local fid=$(copy_file /etc/passwd $f)
3885 stack_trap cdt_clear_no_retry EXIT
3887 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3888 wait_request_state $fid ARCHIVE SUCCEED
3891 copytool_remove_backend $fid
3894 wait_request_state $fid RESTORE FAILED
3898 [[ $st == 0 ]] || error "Restore does not failed"
3900 run_test 111b "No retry policy (release case), restore will error"\
3901 " (No such file or directory)"
3904 # test needs a running copytool
3908 local f=$DIR/$tdir/$tfile
3909 local fid=$(copy_file /etc/passwd $f)
3911 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3912 local l=$($LFS hsm_action $f)
3914 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3917 wait_request_state $fid ARCHIVE SUCCEED
3920 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3922 run_test 112 "State of recorded request"
3925 local f=$DIR/$tdir/$tfile
3926 local fid=$(create_empty_file "$f")
3930 # Prevent archive from completing
3933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3934 # wait archive to register at CDT
3935 wait_request_state $fid ARCHIVE STARTED
3937 # Cancel the archive
3938 $LFS hsm_cancel "$f"
3940 wait_request_state $fid ARCHIVE CANCELED
3943 wait_request_state $fid CANCEL SUCCEED
3945 run_test 200 "Register/Cancel archive"
3948 # test needs a running copytool
3951 local f=$DIR/$tdir/$tfile
3952 create_archive_file $tdir/$tfile
3953 copytool import $tdir/$tfile $f
3954 local fid=$(path2fid $f)
3956 # test with cdt on is made in test_222
3959 # wait restore to register at CDT
3960 wait_request_state $fid RESTORE WAITING
3963 wait_request_state $fid RESTORE CANCELED
3964 wait_request_state $fid CANCEL SUCCEED
3966 run_test 201 "Register/Cancel restore"
3969 local f=$DIR/$tdir/$tfile
3970 local fid=$(create_empty_file "$f")
3972 # test needs a running copytool
3975 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3976 wait_request_state $fid ARCHIVE SUCCEED
3980 # wait remove to register at CDT
3981 wait_request_state $fid REMOVE STARTED
3984 wait_request_state $fid REMOVE CANCELED
3986 run_test 202 "Register/Cancel remove"
3988 test_220A() { # was test_220
3989 # test needs a running copytool
3994 local f=$DIR/$tdir/$tfile
3995 local fid=$(copy_file /etc/passwd $f)
3999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4000 wait_request_state $fid ARCHIVE SUCCEED
4002 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4003 error "The expected changelog was not emitted"
4005 run_test 220A "Changelog for archive"
4008 # test needs a running copytool
4013 local f=$DIR/$tdir/$tfile
4014 local fid=$(copy_file /etc/passwd $f)
4018 # block copytool operations to allow for HSM request to be
4019 # submitted and file be unlinked (CDT will find object removed)
4022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4024 # wait request to reach CT
4025 wait_request_state $fid ARCHIVE STARTED
4031 wait_request_state $fid ARCHIVE FAILED
4034 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4035 error "The expected changelog was not emitted"
4037 run_test 220a "Changelog for failed archive"
4040 local f=$DIR/$tdir/$tfile
4041 local fid=$(create_empty_file "$f")
4046 # Prevent archive from completing
4048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4049 wait_request_state $fid ARCHIVE STARTED
4052 wait_request_state $fid ARCHIVE CANCELED
4055 wait_request_state $fid CANCEL SUCCEED
4057 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4058 error "The expected changelog was not emitted"
4060 run_test 221 "Changelog for archive canceled"
4063 # test needs a running copytool
4067 copy2archive /etc/passwd $tdir/$tfile
4069 local f=$DIR/$tdir/$tfile
4070 copytool import $tdir/$tfile $f
4071 local fid=$(path2fid $f)
4076 wait_request_state $fid RESTORE SUCCEED
4078 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4079 error "The expected changelog was not emitted"
4081 run_test 222a "Changelog for explicit restore"
4084 # test needs a running copytool
4088 local f=$DIR/$tdir/$tfile
4089 local fid=$(copy_file /etc/passwd $f)
4092 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4093 wait_request_state $fid ARCHIVE SUCCEED
4098 wait_request_state $fid RESTORE SUCCEED
4100 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4101 error "The expected changelog was not emitted"
4103 run_test 222b "Changelog for implicit restore"
4106 # test needs a running copytool
4110 copy2archive /etc/passwd $tdir/$tfile
4112 local f=$DIR/$tdir/$tfile
4113 copytool import $tdir/$tfile $f
4114 local fid=$(path2fid $f)
4118 # block copytool operations to allow for HSM request to be
4119 # submitted and file be unlinked (CDT will find object removed)
4124 # wait request to reach CT
4125 wait_request_state $fid RESTORE STARTED
4131 wait_request_state $fid RESTORE FAILED
4134 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4135 error "The expected changelog was not emitted"
4137 run_test 222c "Changelog for failed explicit restore"
4140 # test needs a running copytool
4144 local f=$DIR/$tdir/$tfile
4145 local fid=$(copy_file /etc/passwd $f)
4148 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4149 wait_request_state $fid ARCHIVE SUCCEED
4152 copytool_remove_backend $fid
4155 wait_request_state $fid RESTORE FAILED
4158 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4159 error "The expected changelog was not emitted"
4161 run_test 222d "Changelog for failed implicit restore"
4164 # test needs a running copytool
4167 local f=$DIR/$tdir/$tfile
4168 create_archive_file $tdir/$tfile
4172 copytool import $tdir/$tfile $f
4173 local fid=$(path2fid $f)
4176 wait_request_state $fid RESTORE STARTED
4178 wait_request_state $fid RESTORE CANCELED
4179 wait_request_state $fid CANCEL SUCCEED
4181 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4182 error "The expected changelog was not emitted"
4184 run_test 223a "Changelog for restore canceled (import case)"
4187 local f=$DIR/$tdir/$tfile
4188 local fid=$(create_empty_file "$f")
4193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4194 wait_request_state $fid ARCHIVE SUCCEED
4197 # Prevent restore from completing
4200 wait_request_state $fid RESTORE STARTED
4203 wait_request_state $fid RESTORE CANCELED
4206 wait_request_state $fid CANCEL SUCCEED
4208 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4209 error "The expected changelog was not emitted"
4211 run_test 223b "Changelog for restore canceled (release case)"
4213 test_224A() { # was test_224
4214 # test needs a running copytool
4219 local f=$DIR/$tdir/$tfile
4220 local fid=$(copy_file /etc/passwd $f)
4223 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4224 wait_request_state $fid ARCHIVE SUCCEED
4227 wait_request_state $fid REMOVE SUCCEED
4229 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4230 error "The expected changelog was not emitted"
4232 run_test 224A "Changelog for remove"
4235 # test needs a running copytool
4240 local f=$DIR/$tdir/$tfile
4241 local fid=$(copy_file /etc/passwd $f)
4244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4245 wait_request_state $fid ARCHIVE SUCCEED
4247 copytool_remove_backend $fid
4249 # block copytool operations to allow for HSM request to be
4250 # submitted and file be unlinked (CDT will find object removed)
4255 # wait for request to reach CT
4256 wait_request_state $fid REMOVE STARTED
4262 wait_request_state $fid REMOVE FAILED
4264 # HE_REMOVE|ENOENT=0x202
4265 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4266 error "The expected changelog was not emitted"
4268 run_test 224a "Changelog for failed remove"
4271 # test is not usable because remove request is too fast
4272 # so it is always finished before cancel can be done ...
4273 echo "Test disabled"
4276 # test needs a running copytool
4279 local f=$DIR/$tdir/$tfile
4280 local fid=$(create_empty_file "$f")
4283 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4284 wait_request_state $fid ARCHIVE SUCCEED
4286 # Prevent restore from completing
4291 wait_request_state $fid REMOVE CANCELED
4294 wait_request_state $fid CANCEL SUCCEED
4296 changelog_find -type HSM -target-fid $fid -flags 0x27d
4297 error "The expected changelog was not emitted"
4299 run_test 225 "Changelog for remove canceled"
4302 # test needs a running copytool
4307 local f1=$DIR/$tdir/$tfile-1
4308 local f2=$DIR/$tdir/$tfile-2
4309 local f3=$DIR/$tdir/$tfile-3
4310 local fid1=$(copy_file /etc/passwd $f1)
4311 local fid2=$(copy_file /etc/passwd $f2)
4312 copy_file /etc/passwd $f3
4315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4316 wait_request_state $fid1 ARCHIVE SUCCEED
4318 $LFS hsm_archive $f2
4319 wait_request_state $fid2 ARCHIVE SUCCEED
4321 rm $f1 || error "rm $f1 failed"
4324 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4325 error "The expected changelog was not emitted"
4327 mv $f3 $f2 || error "mv $f3 $f2 failed"
4329 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4330 error "The expected changelog was not emitted"
4332 run_test 226 "changelog for last rm/mv with exiting archive"
4334 # This is just a utility function to clarify what test_227 does
4339 "$LFS" "$action" --$flag "$file" ||
4340 error "Cannot ${action#hsm_} $flag on '$file'"
4342 # Only one changelog should be produced
4343 local entries="$(changelog_find -type HSM -target-fid $fid)"
4344 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4345 error "lfs $action --$flag '$file' produced more than one" \
4348 # Parse the last changelog record
4349 local entry="$(tail -n 1 <<< "$entries")"
4350 eval local -A changelog=$(changelog2array $entry)
4352 # Also check the flags match what is expected
4353 [[ ${changelog[flags]} == $target ]] ||
4354 error "Changelog flag is '${changelog[flags]}', not $target"
4358 local file="$DIR/$tdir/$tfile"
4359 local fid=$(create_empty_file "$file")
4364 for flag in norelease noarchive exists archived lost; do
4365 if [ "$flag" == lost ]; then
4366 # The flag "lost" only works on an archived file
4367 "$LFS" hsm_set --archived "$file"
4371 action="hsm_set" __test_227
4372 action="hsm_clear" __test_227
4375 run_test 227 "changelog when explicit setting of HSM flags"
4378 # test needs a running copytool
4381 local fid=$(create_small_sync_file $DIR/$tfile)
4382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4383 wait_request_state $fid ARCHIVE SUCCEED
4385 $LFS hsm_release $DIR/$tfile
4386 check_hsm_flags $DIR/$tfile "0x0000000d"
4388 filefrag $DIR/$tfile | grep " 1 extent found" ||
4389 error "filefrag on released file must return only one extent"
4391 # only newer versions of cp detect sparse files by stat/FIEMAP
4393 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4394 error "copying $DIR/$tfile"
4395 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4397 $LFS hsm_release $DIR/$tfile
4398 check_hsm_flags $DIR/$tfile "0x0000000d"
4400 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4402 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4404 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4405 error "comparing untarred $DIR/$tfile"
4407 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4408 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4410 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4413 # test needs a running copytool
4417 local maxrequest=$(get_hsm_param max_requests)
4418 local rqcnt=$(($maxrequest * 3))
4422 for i in $(seq -w 1 $rqcnt); do
4424 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4426 # we do it in 2 steps, so all requests arrive at the same time
4427 for i in $(seq -w 1 $rqcnt); do
4428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4433 while [[ $cnt != 0 || $wt != 0 ]]; do
4435 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4436 $HSM_PARAM.actions |\
4437 grep STARTED | grep -v CANCEL | wc -l")
4438 [[ $cnt -le $maxrequest ]] ||
4439 error "$cnt > $maxrequest too many started requests"
4440 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4441 $HSM_PARAM.actions |\
4442 grep WAITING | wc -l")
4443 echo "max=$maxrequest started=$cnt waiting=$wt"
4446 run_test 250 "Coordinator max request"
4449 local f=$DIR/$tdir/$tfile
4450 local fid=$(create_empty_file "$f")
4453 # to have a short test
4454 local old_to=$(get_hsm_param active_request_timeout)
4455 set_hsm_param active_request_timeout 1
4456 # to be sure the cdt will wake up frequently so
4457 # it will be able to cancel the "old" request
4458 local old_loop=$(get_hsm_param loop_period)
4459 set_hsm_param loop_period 1
4464 # Prevent archive from completing
4466 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4467 wait_request_state $fid ARCHIVE STARTED
4469 # Let the request timeout
4470 wait_request_state $fid ARCHIVE CANCELED
4472 set_hsm_param active_request_timeout $old_to
4473 set_hsm_param loop_period $old_loop
4475 run_test 251 "Coordinator request timeout"
4478 local f=$DIR/$tdir/$tfile
4479 local fid=$(create_empty_file "$f")
4481 # to have a short test
4482 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4483 set_hsm_param loop_period 1
4487 # Prevent archive from completing
4489 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4490 wait_request_state $fid ARCHIVE STARTED
4493 stack_trap "set_hsm_param active_request_timeout \
4494 $(get_hsm_param active_request_timeout)" EXIT
4495 set_hsm_param active_request_timeout 1
4497 wait_request_state $fid ARCHIVE CANCELED
4500 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4504 # test needs a running copytool
4508 local f=$DIR/$tdir/$tfile
4510 dd if=/dev/zero of=$f bs=1MB count=10
4511 local fid=$(path2fid $f)
4513 $LFS hsm_archive $f || error "could not archive file"
4514 wait_request_state $fid ARCHIVE SUCCEED
4516 # clear locks to discard inode data
4517 cancel_lru_locks osc
4519 #define OBD_FAIL_MDC_MERGE 0x807
4520 $LCTL set_param fail_loc=0x807
4522 #expect error here, instead of release with wrong size
4525 if ((rc == 0)); then
4526 file_size=$(stat -c '%s' $f)
4527 if ((file_size != 10485760)); then
4528 error "Wrong file size after hsm_release"
4531 echo "could not release file"
4534 run_test 253 "Check for wrong file size after release"
4538 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4539 skip "need MDS version at least 2.10.56" && return
4541 # Check that the counters are initialized to 0
4543 for request_type in archive restore remove; do
4544 count="$(get_hsm_param ${request_type}_count)" ||
4545 error "Reading ${request_type}_count failed with $?"
4547 [ "$count" -eq 0 ] ||
4548 error "Expected ${request_type}_count to be " \
4552 run_test 254a "Request counters are initialized to zero"
4556 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4557 skip "need MDS version at least 2.10.56" && return
4559 # The number of request to launch (at least 32)
4560 local request_count=$((RANDOM % 32 + 32))
4561 printf "Will launch %i requests of each type\n" "$request_count"
4563 # Launch a copytool to process requests
4566 # Set hsm.max_requests to allow starting all requests at the same time
4568 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4569 set_hsm_param max_requests "$request_count"
4573 for request_type in archive restore remove; do
4574 printf "Checking %s requests\n" "${request_type}"
4575 # Suspend the copytool to give us time to read the proc files
4578 for ((i = 0; i < $request_count; i++)); do
4579 case $request_type in
4581 create_empty_file "$DIR/$tdir/$tfile-$i" \
4585 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4588 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4591 # Give the coordinator 10 seconds to start every request
4593 while get_hsm_param actions | grep -q WAITING; do
4596 [ $timeout -gt 0 ] ||
4597 error "${request_type^} requests took too " \
4601 count="$(get_hsm_param ${request_type}_count)"
4602 [ "$count" -eq "$request_count" ] ||
4603 error "Expected '$request_count' (!= '$count') " \
4604 "active $request_type requests"
4606 # Let the copytool process the requests
4608 # Give it 10 seconds maximum
4610 while get_hsm_param actions | grep -q STARTED; do
4613 [ $timeout -gt 0 ] ||
4614 error "${request_type^} requests took too " \
4618 count="$(get_hsm_param ${request_type}_count)"
4619 [ "$count" -eq 0 ] ||
4620 error "Expected 0 (!= '$count') " \
4621 "active $request_type requests"
4624 run_test 254b "Request counters are correctly incremented and decremented"
4626 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4627 # break in the future because of that.
4630 local -a files=("$DIR/$tdir/$tfile".{0..15})
4633 for file in "${files[@]}"; do
4634 create_small_file "$file"
4637 # Set a few hsm parameters
4639 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4640 set_hsm_param loop_period 1
4642 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4643 set_hsm_param max_requests 3
4647 "$LFS" hsm_archive "${files[0]}"
4648 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4649 "$LFS" hsm_release "${files[0]}"
4653 wait_copytools || error "copytools failed to stop"
4655 # Send several archive requests
4656 for file in "${files[@]:1}"; do
4657 "$LFS" hsm_archive "$file"
4660 # Send one restore request
4661 "$LFS" hsm_restore "${files[0]}"
4666 # Wait for all the requests to complete
4667 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4668 for file in "${files[@]:1}"; do
4669 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4672 # Collect the actions in the order in which the copytool processed them
4674 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4675 "$(copytool_logfile "$SINGLEAGT")")
4678 printf '%s\n' "${actions[@]}"
4681 for action in "${actions[@]:0:3}"; do
4682 [ "$action" == RESTORE ] && return
4685 error "Too many ARCHIVE requests were run before the RESTORE request"
4687 run_test 260a "Restore request have priority over other requests"
4689 # This test is very much tied to the implementation of the current priorisation
4690 # mechanism in the coordinator. It might not make sense to keep it in the future
4693 local -a files=("$DIR/$tdir/$tfile".{0..15})
4696 for file in "${files[@]}"; do
4697 create_small_file "$file"
4700 # Set a few hsm parameters
4702 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4703 set_hsm_param loop_period 1
4705 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4706 set_hsm_param max_requests 3
4709 copytool setup --archive-id 2
4710 "$LFS" hsm_archive --archive 2 "${files[0]}"
4711 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4712 "$LFS" hsm_release "${files[0]}"
4716 wait_copytools || error "copytools failed to stop"
4718 # Send several archive requests
4719 for file in "${files[@]:1}"; do
4720 "$LFS" hsm_archive "$file"
4723 # Send one restore request
4724 "$LFS" hsm_restore "${files[0]}"
4728 copytool setup --archive-id 2
4730 # Wait for all the requests to complete
4731 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4732 for file in "${files[@]:1}"; do
4733 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4736 # Collect the actions in the order in which the copytool processed them
4738 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4739 "$(copytool_logfile "$SINGLEAGT")")
4742 printf '%s\n' "${actions[@]}"
4745 for action in "${actions[@]:0:3}"; do
4746 [ "$action" == RESTORE ] && return
4749 error "Too many ARCHIVE requests were run before the RESTORE request"
4751 run_test 260b "Restore request have priority over other requests"
4753 # This test is very much tied to the implementation of the current priorisation
4754 # mechanism in the coordinator. It might not make sense to keep it in the future
4757 local -a files=("$DIR/$tdir/$tfile".{0..15})
4760 for file in "${files[@]}"; do
4761 create_small_file "$file"
4764 # Set a few hsm parameters
4766 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4767 set_hsm_param loop_period 10
4769 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4770 set_hsm_param max_requests 3
4773 copytool setup --archive-id 2
4774 "$LFS" hsm_archive --archive 2 "${files[0]}"
4775 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4776 "$LFS" hsm_release "${files[0]}"
4780 wait_copytools || error "copytools failed to stop"
4782 "$LFS" hsm_archive "${files[1]}"
4786 copytool setup --archive-id 2
4788 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4790 # Send several archive requests
4791 for file in "${files[@]:2}"; do
4792 "$LFS" hsm_archive "$file"
4795 # Send one restore request
4796 "$LFS" hsm_restore "${files[0]}"
4798 # Wait for all the requests to complete
4799 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4800 for file in "${files[@]:2}"; do
4801 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4804 # Collect the actions in the order in which the copytool processed them
4806 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4807 "$(copytool_logfile "$SINGLEAGT")")
4810 printf '%s\n' "${actions[@]}"
4813 for action in "${actions[@]:0:3}"; do
4814 [ "$action" == RESTORE ] &&
4815 error "Restore requests should not be prioritised" \
4816 "unless the coordinator is doing housekeeping"
4820 run_test 260c "Restore request have priority over other requests"
4823 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4825 # the only way to test ondisk conf is to restart MDS ...
4826 echo "Stop coordinator and remove coordinator state at mount"
4829 # clean on disk conf set by default
4830 cdt_clear_mount_state
4831 cdt_check_state stopped
4833 # check cdt still off after umount/remount
4835 cdt_check_state stopped
4837 echo "Set coordinator start at mount, and start coordinator"
4838 cdt_set_mount_state enabled
4841 cdt_check_state enabled
4843 # check cdt still on after umount/remount
4845 cdt_check_state enabled
4847 # we are back to original state (cdt started at mount)
4849 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4852 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4854 local ai=$(get_hsm_param default_archive_id)
4855 local new=$((ai + 1))
4857 set_hsm_param default_archive_id $new -P
4859 local res=$(get_hsm_param default_archive_id)
4862 set_hsm_param default_archive_id "" "-P -d"
4864 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4866 run_test 301 "HSM tunnable are persistent"
4869 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4871 local ai=$(get_hsm_param default_archive_id)
4872 local new=$((ai + 1))
4877 set_hsm_param default_archive_id $new -P
4880 for mdtno in $(seq 1 $MDSCOUNT); do
4885 cdt_check_state enabled
4887 local res=$(get_hsm_param default_archive_id)
4890 set_hsm_param default_archive_id "" "-P -d"
4892 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4894 run_test 302 "HSM tunnable are persistent when CDT is off"
4897 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4903 local dir_mdt0=$DIR/$tdir/mdt0
4904 local dir_mdt1=$DIR/$tdir/mdt1
4906 # create 1 dir per MDT
4907 stack_trap "rm -rf $dir_mdt0" EXIT
4908 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4909 stack_trap "rm -rf $dir_mdt1" EXIT
4910 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4912 # create 1 file in each MDT
4913 local fid1=$(create_small_file $dir_mdt0/$tfile)
4914 local fid2=$(create_small_file $dir_mdt1/$tfile)
4916 # check that hsm request on mdt0 is sent to the right MDS
4917 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4918 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4919 echo "archive successful on mdt0"
4921 # check that hsm request on mdt1 is sent to the right MDS
4922 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4923 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4924 echo "archive successful on mdt1"
4926 run_test 400 "Single request is sent to the right MDT"
4929 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4935 local dir_mdt0=$DIR/$tdir/mdt0
4936 local dir_mdt1=$DIR/$tdir/mdt1
4938 # create 1 dir per MDT
4939 stack_trap "rm -rf $dir_mdt0" EXIT
4940 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4941 stack_trap "rm -rf $dir_mdt1" EXIT
4942 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4944 # create 1 file in each MDT
4945 local fid1=$(create_small_file $dir_mdt0/$tfile)
4946 local fid2=$(create_small_file $dir_mdt1/$tfile)
4948 # check that compound requests are shunt to the rights MDTs
4949 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4950 error "lfs hsm_archive"
4951 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4952 echo "archive successful on mdt0"
4953 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4954 echo "archive successful on mdt1"
4956 run_test 401 "Compound requests split and sent to their respective MDTs"
4958 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4963 local node=$(facet_active_host $facet)
4965 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4966 awk '{print $4}'); do
4967 echo "$3 $mdc on $node"
4968 do_facet $facet "$LCTL --device $mdc $state" || return 1
4973 # deactivate all mdc on agent1
4974 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4976 copytool setup --no-fail
4978 check_agent_unregistered "uuid" # match any agent
4980 # no expected running copytool
4981 search_copytools $agent && error "Copytool start should have failed"
4984 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4986 run_test 402a "Copytool start fails if all MDTs are inactive"
4993 local f=$DIR/$tdir/$tfile
4994 touch $f || error "touch $f failed"
4995 local fid=$(path2fid $f)
4997 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4998 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5001 # give time for CDT to send request and to keep it for retry
5002 wait_for_loop_period
5004 wait_request_state $fid ARCHIVE WAITING
5006 do_facet $SINGLEAGT lctl set_param fail_loc=0
5008 # request should succeed now
5009 wait_request_state $fid ARCHIVE SUCCEED
5011 run_test 402b "CDT must retry request upon slow start of CT"
5014 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5016 local agent=$(facet_active_host $SINGLEAGT)
5018 # deactivate all mdc for MDT0001
5019 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5022 local uuid=$(get_agent_uuid $agent)
5023 # check the agent is registered on MDT0000, and not on MDT0001
5024 check_agent_registered_by_mdt $uuid 0
5025 check_agent_unregistered_by_mdt $uuid 1
5027 # check running copytool process
5028 search_copytools $agent || error "No running copytools on $agent"
5030 # reactivate all mdc for MDT0001
5031 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5033 # make sure the copytool is now registered to all MDTs
5034 check_agent_registered $uuid
5036 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5039 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5043 # create files on both MDT0000 and MDT0001
5046 local dir_mdt0=$DIR/$tdir/mdt0
5047 stack_trap "rm -rf $dir_mdt0" EXIT
5048 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5050 # create 1 file on mdt0
5051 local fid1=$(create_small_file $dir_mdt0/$tfile)
5053 # deactivate all mdc for MDT0001
5054 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5056 # send an HSM request for files in MDT0000
5057 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5059 # check for completion of files in MDT0000
5060 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5061 echo "archive successful on mdt0"
5063 # reactivate all mdc for MDT0001
5064 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5066 run_test 404 "Inactive MDT does not block requests for active MDTs"
5069 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5075 local striped_dir=$DIR/$tdir/striped_dir
5077 # create striped dir on all of MDTs
5078 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5080 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5081 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5082 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5083 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5085 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5086 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5087 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5088 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5090 # check that compound requests are shunt to the rights MDTs
5091 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5092 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5093 error "lfs hsm_archive"
5095 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5096 echo "archive successful on $fid1"
5097 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5098 echo "archive successful on $fid2"
5099 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5100 echo "archive successful on $fid3"
5101 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5102 echo "archive successful on $fid4"
5104 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5105 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5106 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5107 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5109 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5110 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5111 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5112 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5114 run_test 405 "archive and release under striped directory"
5117 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5119 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5120 skip "need MDS version at least 2.7.64" && return 0
5125 fid=$(create_small_file $DIR/$tdir/$tfile)
5130 $LFS hsm_archive $DIR/$tdir/$tfile
5131 wait_request_state "$fid" ARCHIVE SUCCEED
5132 $LFS hsm_release $DIR/$tdir/$tfile
5134 # Should migrate $tdir but not $tfile.
5135 $LFS migrate -m1 $DIR/$tdir &&
5136 error "migrating HSM an archived file should fail"
5138 $LFS hsm_restore $DIR/$tdir/$tfile
5139 wait_request_state "$fid" RESTORE SUCCEED
5141 $LFS hsm_remove $DIR/$tdir/$tfile
5142 wait_request_state "$fid" REMOVE SUCCEED
5144 cat $DIR/$tdir/$tfile > /dev/null ||
5145 error "cannot read $DIR/$tdir/$tfile"
5147 $LFS migrate -m1 $DIR/$tdir ||
5148 error "cannot complete migration after HSM remove"
5150 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5151 if ((mdt_index != 1)); then
5152 error "expected MDT index 1, got $mdt_index"
5155 # Refresh fid after migration.
5156 fid=$(path2fid $DIR/$tdir/$tfile)
5159 $LFS hsm_archive $DIR/$tdir/$tfile
5160 wait_request_state "$fid" ARCHIVE SUCCEED 1
5162 lctl set_param debug=+trace
5163 $LFS hsm_release $DIR/$tdir/$tfile ||
5164 error "cannot release $DIR/$tdir/$tfile"
5166 $LFS hsm_restore $DIR/$tdir/$tfile
5167 wait_request_state "$fid" RESTORE SUCCEED 1
5169 cat $DIR/$tdir/$tfile > /dev/null ||
5170 error "cannot read $DIR/$tdir/$tfile"
5172 run_test 406 "attempting to migrate HSM archived files is safe"
5175 local f=$DIR/$tdir/$tfile
5176 local f2=$DIR2/$tdir/$tfile
5177 local fid=$(create_empty_file "$f")
5181 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5182 wait_request_state $fid ARCHIVE SUCCEED
5185 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5186 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5188 # Prevent restore from completing
5192 # 1st request holds layout lock while appropriate
5193 # RESTORE record is still not added to llog
5197 # after umount hsm_actions->O/x/x log shouldn't have
5198 # double RESTORE records like below
5199 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5200 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5202 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5206 wait_request_state $fid RESTORE SUCCEED
5208 run_test 407 "Check for double RESTORE records in llog"
5212 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5213 skip "HSM migrate is not supported" && return
5215 test_mkdir -p $DIR/$tdir
5216 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5218 run_test 500 "various LLAPI HSM tests"
5221 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5222 skip "need MDS version at least 2.10.58" && return 0
5226 local f=$DIR/$tdir/$tfile
5229 # set changelog_mask to ALL
5230 changelog_chmask "ALL"
5232 chmod 777 $DIR/$tdir
5233 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5234 local fid=$(path2fid $f)
5237 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5238 -gid "$RUNAS_GID") ||
5239 error "No matching CREAT entry"
5241 # Parse the changelog
5242 eval local -A changelog=$(changelog2array $entry)
5243 local nid="${changelog[nid]}"
5246 echo "Got NID '$nid'"
5247 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5248 error "nid '$nid' does not match any client NID:" \
5251 run_test 600 "Changelog fields 'u=' and 'nid='"
5254 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5255 skip "need MDS version at least 2.10.58" && return 0
5259 local f=$DIR/$tdir/$tfile
5262 # set changelog_mask to ALL
5263 changelog_chmask "ALL"
5265 touch $f || error "touch $f failed"
5266 local fid=$(path2fid $f)
5269 cat $f || error "cat $f failed"
5271 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5272 error "No matching OPEN entry"
5274 run_test 601 "OPEN Changelog entry"
5277 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5278 skip "need MDS version at least 2.10.58" && return 0
5282 local f=$DIR/$tdir/$tfile
5285 # set changelog_mask to ALL
5286 changelog_chmask "ALL"
5288 touch $f || error "touch $f failed"
5289 local fid=$(path2fid $f)
5292 cat $f || error "cat $f failed"
5294 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5298 echo f > $f || error "write $f failed"
5301 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5303 # remove OPEN from changelog_mask
5304 changelog_chmask "-OPEN"
5308 cat $f || error "cat $f failed"
5311 changelog_find -type CLOSE -target-fid $fid &&
5312 error "There should be no CLOSE entry"
5316 echo f > $f || error "write $f failed"
5319 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5321 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5324 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5325 skip "need MDS version at least 2.10.58" && return 0
5329 local f=$DIR/$tdir/$tfile
5332 # set changelog_mask to ALL
5333 changelog_chmask "ALL"
5335 touch $f || error "touch $f failed"
5336 local fid=$(path2fid $f)
5338 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5341 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5343 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5344 error "No matching GXATR entry"
5346 run_test 603 "GETXATTR Changelog entry"
5349 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5350 skip "need MDS version at least 2.10.58" && return 0
5354 local f=$DIR/$tdir/$tfile
5355 local f2=$DIR2/$tdir/$tfile
5356 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5358 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5359 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5360 do_facet mds1 lctl set_param "$procname=20"
5364 # set changelog_mask to ALL
5365 changelog_chmask "ALL"
5367 touch $f || error "touch $f failed"
5368 local fid=$(path2fid $f)
5374 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5378 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5379 -gid "$RUNAS_GID" -mode "r--") ||
5380 error "No matching NOPEN entry"
5382 # Parse the changelog
5383 eval local -A changelog=$(changelog2array $entry)
5384 local nid="${changelog[nid]}"
5387 echo "Got NID '$nid'"
5388 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5389 error "nid '$nid' does not match any client NID:" \
5394 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5397 changelog_find -type NOPEN -target-fid $fid &&
5398 error "There should be no NOPEN entry"
5400 # Sleep for `changelog_deniednext` seconds
5405 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5408 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5409 -gid "$RUNAS_GID" -mode "r--") ||
5410 error "No matching NOPEN entry"
5412 # Parse the changelog
5413 eval local -A changelog=$(changelog2array $entry)
5414 local nid="${changelog[nid]}"
5417 echo "Got NID '$nid'"
5418 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5419 error "nid '$nid' does not match any client NID:" \
5422 run_test 604 "NOPEN Changelog entry"
5425 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5426 skip "need MDS version at least 2.10.58" && return 0
5430 local f=$DIR/$tdir/$tfile
5431 local f2=$DIR2/$tdir/$tfile
5434 # set changelog_mask to ALL
5435 changelog_chmask "ALL"
5437 touch $f || error "touch $f failed"
5438 local fid=$(path2fid $f)
5442 exec 3<> $f || error "open $f failed"
5446 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5450 exec 4<> $f || error "open $f failed"
5453 changelog_find -type OPEN -target-fid $fid &&
5454 error "There should be no OPEN entry"
5456 exec 4>&- || error "close $f failed"
5459 changelog_find -type CLOSE -target-fid $fid &&
5460 error "There should be no CLOSE entry"
5464 # access in rw, so different access mode should generate entries
5465 cat $f || error "cat $f failed"
5468 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5470 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5474 # same access as first one, should not generate new entries
5475 exec 4<> $f || error "open $f failed"
5478 changelog_find -type OPEN -target-fid $fid &&
5479 error "There should be no OPEN entry"
5481 exec 4>&- || error "close $f failed"
5484 changelog_find -type CLOSE -target-fid $fid &&
5485 error "There should be no CLOSE entry"
5489 # access by different user should generate new entries
5490 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5493 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5495 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5499 exec 3>&- || error "close $f failed"
5502 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5504 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5507 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5508 skip "need MDS version at least 2.10.58" && return 0
5510 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5511 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5512 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5513 skip_env "missing llog_reader" && return
5514 local fstype=$(facet_fstype mds1)
5518 local f=$DIR/$tdir/$tfile
5521 # set changelog_mask to ALL
5522 changelog_chmask "ALL"
5524 chmod 777 $DIR/$tdir
5525 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5526 local fid=$(path2fid $f)
5527 rm $f || error "rm $f failed"
5529 local mntpt=$(facet_mntpt mds1)
5533 #remount mds1 as ldiskfs or zfs type
5534 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5535 stop mds1 || error "stop mds1 failed"
5536 mount_fstype mds1 || error "remount mds1 failed"
5538 for ((i = 0; i < 1; i++)); do
5539 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5540 local cat_file=$(do_facet mds1 $llog_reader \
5541 $mntpt/changelog_catalog | awk \
5542 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5543 [ -n "$cat_file" ] || error "no catalog file"
5545 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5546 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5547 [ -n "$entry" ] || error "no CREAT entry"
5550 local uidgid=$(echo $entry |
5551 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5552 [ -n "$uidgid" ] || error "uidgid is empty"
5553 echo "Got UID/GID $uidgid"
5554 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5555 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5556 local nid=$(echo $entry |
5557 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5558 [ -n "$nid" ] || error "nid is empty"
5560 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5561 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5563 run_test 606 "llog_reader groks changelog fields"
5566 check_and_cleanup_lustre