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 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
31 MULTIOP=${MULTIOP:-multiop}
32 OPENFILE=${OPENFILE:-openfile}
33 MMAP_CAT=${MMAP_CAT:-mmap_cat}
34 MOUNT_2=${MOUNT_2:-"yes"}
36 MDS_VERSION_CODE=$(lustre_version_code $SINGLEMDS)
38 # script only handles up to 10 MDTs (because of MDT_PREFIX)
39 [ $MDSCOUNT -gt 9 ] &&
40 error "script cannot handle more than 9 MDTs, please fix" && exit
42 check_and_setup_lustre
44 if [[ $MDS_VERSION_CODE -lt $(version_code 2.4.53) ]]; then
45 skip_env "Need MDS version at least 2.4.53"
48 # $RUNAS_ID may get set incorrectly somewhere else
49 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
50 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
52 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 if getent group nobody; then
55 elif getent group nogroup; then
58 error "No generic nobody group"
63 # if there is no CLIENT1 defined, some tests can be ran on localhost
64 CLIENT1=${CLIENT1:-$HOSTNAME}
65 # if CLIENT2 doesn't exist then use CLIENT1 instead
66 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
68 # Exception is the test which need two separate nodes
69 CLIENT2=${CLIENT2:-$CLIENT1}
72 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
73 # the following associated variables are added:
75 # AGTCOUNT: number of agents
76 # AGTDEV{N}: target HSM mount point (root path of the backend)
77 # agt{N}_HOST: hostname of the agent agt{N}
78 # SINGLEAGT: facet of the single agent
80 # The number of agents is initialized as the number of remote client nodes.
81 # By default, only single copytool is started on a remote client/agent. If there
82 # was no remote client, then the copytool will be started on the local client.
88 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
89 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
91 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
92 if [[ $CLIENTCOUNT -gt 1 ]] &&
93 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
94 skip_env "SHARED_DIRECTORY should be accessible"\
99 # We used to put the HSM archive in $SHARED_DIRECTORY but that
100 # meant NFS issues could hose sanity-hsm sessions. So now we
102 for n in $(seq $AGTCOUNT); do
103 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
104 agent=CLIENT$((n + 1))
105 if [[ -z "${!agent}" ]]; then
106 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
109 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
112 export SINGLEAGT=${SINGLEAGT:-agt1}
114 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
115 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
116 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
117 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
118 export HSMTOOL_TESTDIR
119 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
123 # The test only support up to 10 MDTs
124 MDT_PREFIX="mdt.$FSNAME-MDT000"
125 HSM_PARAM="${MDT_PREFIX}0.hsm"
127 # archive is purged at copytool setup
128 HSM_ARCHIVE_PURGE=true
130 # Don't allow copytool error upon start/setup
131 HSMTOOL_NOERROR=false
134 # Get the backend root path for the given agent facet.
137 local dev=AGTDEV$(facet_number $facet)
144 # get MDT device for each mdc
145 for mdtno in $(seq 1 $MDSCOUNT); do
146 local idx=$(($mdtno - 1))
147 MDT[$idx]=$($LCTL get_param -n \
148 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
149 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
154 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
155 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
159 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
161 echo "Killing existing copytools on $hosts"
162 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
163 copytool_continue "$hosts"
167 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
168 local wait_timeout=200
169 local wait_start=$SECONDS
170 local wait_end=$((wait_start + wait_timeout))
171 local sleep_time=100000 # 0.1 second
173 while ((SECONDS < wait_end)); do
174 if ! search_copytools $hosts; then
175 echo "copytools stopped in $((SECONDS - wait_start))s"
179 echo "copytools still running on $hosts"
181 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
182 sleep_time=$(bc <<< "$sleep_time * 2")
185 # try to dump Copytool's stack
186 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
187 "echo t >/proc/sysrq-trigger"
189 echo "copytools failed to stop in ${wait_timeout}s"
194 copytool_monitor_setup() {
195 local facet=${1:-$SINGLEAGT}
196 local agent=$(facet_active_host $facet)
198 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
199 local test_dir=$(do_node $agent "$cmd") ||
200 error "Failed to create tempdir on $agent"
201 export HSMTOOL_MONITOR_DIR=$test_dir
203 # Create the fifo and a monitor (cat dies when copytool dies)
204 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
205 error "failed to create copytool fifo on $agent"
206 cmd="cat $test_dir/fifo > $test_dir/events &"
207 cmd+=" echo \\\$! > $test_dir/monitor_pid"
209 if [[ $PDSH == *Rmrsh* ]]; then
210 # This is required for pdsh -Rmrsh and its handling of remote
212 # Regular ssh and pdsh -Rssh work fine without this
213 # backgrounded subshell nonsense.
214 (do_node $agent "$cmd") &
215 export HSMTOOL_MONITOR_PDSH=$!
217 # Slightly racy, but just making a best-effort to catch obvious
220 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
221 error "Failed to start copytool monitor on $agent"
223 do_node $agent "$cmd"
225 error "Failed to start copytool monitor on $agent"
230 copytool_monitor_cleanup() {
231 local facet=${1:-$SINGLEAGT}
232 local agent=$(facet_active_host $facet)
234 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
235 # Should die when the copytool dies, but just in case.
236 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
237 cmd+=" 2>/dev/null || true"
238 do_node $agent "$cmd"
239 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
240 export HSMTOOL_MONITOR_DIR=
243 # The pdsh should die on its own when the monitor dies. Just
244 # in case, though, try to clean up to avoid any cruft.
245 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
246 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
247 export HSMTOOL_MONITOR_PDSH=
257 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
264 local host="$(facet_host "$1")"
265 local prefix=$TESTLOG_PREFIX
266 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
268 printf "${prefix}.copytool${archive_id}_log.${host}.log"
273 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
278 mkdir -p "$(dirname "$2")" ||
279 error "cannot create directory '$(dirname "$2")'"
280 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
285 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
286 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
287 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
288 [ ${#misc_options[@]} -gt 0 ] &&
289 cmd+=" $(IFS=" " echo "$@")"
290 cmd+=" \"$mountpoint\""
292 echo "Starting copytool $facet on $(facet_host $facet)"
293 stack_trap "do_facet $facet pkill -x '$HSMTOOL_BASE' || true" EXIT
294 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
298 local facet="${1:-$SINGLEAGT}"
300 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
303 # Main entry point to perform copytool related operations
307 # setup setup a copytool to run in the background, that copytool will be
309 # import import a file from an HSM backend
310 # rebind rebind an archived file to a new fid
312 # Although the semantics might suggest otherwise, one does not need to 'setup'
313 # a copytool before a call to 'copytool import' or 'copytool rebind'.
321 local fail_on_error=true
322 local -a misc_options
323 while [ $# -gt 0 ]; do
331 local mountpoint="$1"
335 local archive_id="$1"
339 local bandwidth="$1" # in MB/s
342 local fail_on_error=false
345 # Uncommon(/copytool dependent) option
352 # Use default values if needed
353 local facet=${facet:-$SINGLEAGT}
354 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
355 local hsm_root="$(hsm_root "$facet")"
357 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
358 do_facet $facet mkdir -p "$hsm_root" ||
359 error "mkdir '$hsm_root' failed"
363 local copytool=lhsmtool
367 __${copytool}_${action} "${misc_options[@]}"
368 if [ $? -ne 0 ]; then
373 local host="$(facet_host $facet)"
374 error_msg="Failed to start copytool $facet on '$host'"
377 local src="${misc_options[0]}"
378 local dest="${misc_options[1]}"
379 error_msg="Failed to import '$src' to '$dest'"
382 error_msg="could not rebind file"
386 $fail_on_error && error "$error_msg" || echo "$error_msg"
390 get_copytool_event_log() {
391 local facet=${1:-$SINGLEAGT}
392 local agent=$(facet_active_host $facet)
394 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
395 error "Can't get event log: No monitor directory!"
397 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
398 error "Could not collect event log from $agent"
402 local agents=${1:-$(facet_active_host $SINGLEAGT)}
405 "do_nodesv $agents pkill -CONT -x '$HSMTOOL_BASE' || true" EXIT
406 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
407 echo "Copytool is suspended on $agents"
410 copytool_continue() {
411 local agents=${1:-$(facet_active_host $SINGLEAGT)}
413 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
414 echo "Copytool is continued on $agents"
417 copytool_remove_backend() {
419 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
420 echo "Remove from backend: $fid = $be"
421 do_facet $SINGLEAGT rm -f $be
424 file_creation_failure() {
431 df $MOUNT $MOUNT2 >&2
432 error "Not enough space to create $file with $cmd"
435 error "cannot create $file with $cmd, status=$err"
440 # Creates a file using dd
446 local source=${5:-/dev/zero}
450 if [ -n "$conv" ]; then
454 # Create the directory in case it does not exist
455 mkdir -p "$(dirname "$file")"
456 # Delete the file in case it already exist
459 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
460 path2fid "$file" || error "cannot get FID of '$file'"
463 echo "cannot create file '$file'" >&2;
464 # Let the caller decide what to do on error
469 create_empty_file() {
470 create_file "${1/$DIR/$DIR2}" 1M 0 ||
471 file_creation_failure dd "${1/$DIR/$DIR2}" $?
474 create_small_file() {
475 local source_file=/dev/urandom
478 local conv=${2:-fsync}
480 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
481 file_creation_failure dd "${1/$DIR/$DIR2}" $?
484 create_small_sync_file() {
485 create_small_file "$1" sync
488 create_archive_file() {
489 local file="$(hsm_root)/$1"
491 local source=/dev/urandom
493 # Create the counterpart directory of the archive
494 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
495 error "cannot create archive directory '$(dirname "$file")'"
497 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
498 error "cannot create archive file '$file'"
502 local hsm_root="$(hsm_root)"
503 local file="$hsm_root/$2"
505 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
506 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
507 error "mkdir '$(dirname "$file")' failed"
508 do_facet $SINGLEAGT cp -p "$1" "$file" ||
509 error "cannot copy '$1' to '$file'"
518 if [[ "$value" != "" ]]; then
521 for mdtno in $(seq 1 $MDSCOUNT); do
522 local idx=$(($mdtno - 1))
523 local facet=mds${mdtno}
524 # if $arg include -P option, run 1 set_param per MDT on the MGS
525 # else, run set_param on each MDT
526 [[ $arg = *"-P"* ]] && facet=mgs
527 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
528 [[ $? != 0 ]] && rc=1
538 for mdtno in $(seq 1 $MDSCOUNT); do
539 local idx=$(($mdtno - 1))
540 wait_result mds${mdtno} \
541 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
543 error "$key state is not '$target' on mds${mdtno}"
549 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
557 mdts_set_param "$opt -n" "hsm.$param" "$value"
564 mdts_set_param "" hsm_control "$cmd"
565 mdts_check_param hsm_control "$target" 10
568 cdt_set_sanity_policy() {
569 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
572 mdts_set_param "" hsm.policy "+NRA"
573 mdts_set_param "" hsm.policy "-NBR"
574 CDT_POLICY_HAD_CHANGED=
579 mdts_set_param "" hsm.policy "+NRA"
580 CDT_POLICY_HAD_CHANGED=true
583 cdt_clear_no_retry() {
584 mdts_set_param "" hsm.policy "-NRA"
585 CDT_POLICY_HAD_CHANGED=true
588 cdt_set_non_blocking_restore() {
589 mdts_set_param "" hsm.policy "+NBR"
590 CDT_POLICY_HAD_CHANGED=true
593 cdt_clear_non_blocking_restore() {
594 mdts_set_param "" hsm.policy "-NBR"
595 CDT_POLICY_HAD_CHANGED=true
598 cdt_clear_mount_state() {
599 mdts_set_param "-P -d" hsm_control ""
602 cdt_set_mount_state() {
603 mdts_set_param "-P" hsm_control "$1"
604 # set_param -P is asynchronous operation and could race with set_param.
605 # In such case configs could be retrieved and applied at mgc after
606 # set_param -P completion. Sleep here to avoid race with set_param.
607 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
608 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
609 # and 10 seconds to retrieve config from server.
614 mdts_check_param hsm_control "$1" 20
618 set_test_state disabled disabled
622 set_test_state enabled enabled
626 set_test_state shutdown stopped
630 set_test_state purge enabled
636 cdt_set_sanity_policy
640 local client_count=$1
641 if [[ $CLIENTCOUNT -lt $client_count ]]; then
642 skip "Need $client_count or more clients, have $CLIENTCOUNT"
649 $LFS path2fid $1 | tr -d '[]'
650 return ${PIPESTATUS[0]}
658 if [[ $u == "user" ]]; then
659 st=$($RUNAS $LFS hsm_state $f)
662 st=$($LFS hsm_state $f)
665 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
667 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
671 get_hsm_archive_id() {
674 st=$($LFS hsm_state $f)
675 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
677 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
685 local st=$(get_hsm_flags $f)
686 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
689 check_hsm_flags_user() {
693 local st=$(get_hsm_flags $f user)
694 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
706 if [[ "$3" != 1 ]]; then
710 cp $1 $f || file_creation_failure cp $f $?
712 path2fid $f || error "cannot get fid on $f"
715 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
717 # Note that this might lead to surprising behaviours such as deleting an
718 # important file for the currently running test
719 delete_large_files() {
720 printf "Deleting large files...\n" >&2
721 find $MOUNT -size +10M -delete
722 wait_delete_completed
728 wait_update --verbose $(facet_active_host $facet) "$@"
731 wait_request_state() {
735 # 4th arg (mdt index) is optional
737 local mds=mds$(($mdtidx + 1))
739 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
740 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
742 wait_result $mds "$cmd" "$state" 200 ||
743 error "request on $fid is not $state on $mds"
746 get_request_state() {
750 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
751 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
754 get_request_count() {
758 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
759 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
762 # Ensure the number of HSM request for a given FID is correct
763 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
764 assert_request_count() {
765 local request_count=$(get_request_count $1 $2)
766 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
768 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
775 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
776 [[ -n $fid ]] && cmd+=" | grep '$fid'"
777 cmd+=" | egrep 'WAITING|STARTED'"
779 wait_result $SINGLEMDS "$cmd" "" $timeout ||
780 error "requests did not complete"
783 wait_for_grace_delay() {
784 local val=$(get_hsm_param grace_delay)
788 wait_for_loop_period() {
789 local val=$(get_hsm_param loop_period)
796 # python2.6 in EL6 includes an internal json module
797 local json_parser='import json; import fileinput;'
798 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
799 json_parser+='json.loads([line for line in '
800 json_parser+='fileinput.input()][0]).items()])'
802 echo $raw_event | python -c "$json_parser"
805 get_agent_by_uuid_mdt() {
808 local mds=mds$(($mdtidx + 1))
809 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
813 check_agent_registered_by_mdt() {
816 local mds=mds$(($mdtidx + 1))
817 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
818 if [[ ! -z "$agent" ]]; then
819 echo "found agent $agent on $mds"
821 error "uuid $uuid not found in agent list on $mds"
825 check_agent_unregistered_by_mdt() {
828 local mds=mds$(($mdtidx + 1))
829 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
830 if [[ -z "$agent" ]]; then
831 echo "uuid not found in agent list on $mds"
833 error "uuid found in agent list on $mds: $agent"
837 check_agent_registered() {
840 for mdsno in $(seq 1 $MDSCOUNT); do
841 check_agent_registered_by_mdt $uuid $((mdsno - 1))
845 check_agent_unregistered() {
848 for mdsno in $(seq 1 $MDSCOUNT); do
849 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
854 local agent=${1:-$(facet_active_host $SINGLEAGT)}
856 # Lustre mount-point is mandatory and last parameter on
858 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
860 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
862 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
868 # populate MDT device array
871 # cleanup from previous bad setup
874 # for recovery tests, coordinator needs to be started at mount
876 # the lustre conf must be without hsm on (like for sanity.sh)
877 echo "Set HSM on and start"
878 cdt_set_mount_state enabled
879 cdt_check_state enabled
881 echo "Set sanity-hsm HSM policy"
882 cdt_set_sanity_policy
884 # finished requests are quickly removed from list
885 set_hsm_param grace_delay 10
887 CLIENT_NIDS=( $($LCTL list_nids all) )
889 test_1A() { # was test_1
893 local f=$DIR/$tdir/$tfile
897 check_hsm_flags_user $f "0x00000000"
899 $RUNAS $LFS hsm_set --norelease $f ||
900 error "user could not change hsm flags"
901 check_hsm_flags_user $f "0x00000010"
903 $RUNAS $LFS hsm_clear --norelease $f ||
904 error "user could not clear hsm flags"
905 check_hsm_flags_user $f "0x00000000"
907 # User could not change those flags...
908 $RUNAS $LFS hsm_set --exists $f &&
909 error "user should not set this flag"
910 check_hsm_flags_user $f "0x00000000"
913 $LFS hsm_set --exists $f ||
914 error "root could not change hsm flags"
915 check_hsm_flags_user $f "0x00000001"
917 $LFS hsm_clear --exists $f ||
918 error "root could not clear hsm state"
919 check_hsm_flags_user $f "0x00000000"
922 run_test 1A "lfs hsm flags root/non-root access"
925 local f=$DIR/$tdir/$tfile
926 local fid=$(create_small_file $f)
930 $LFS hsm_archive $f || error "could not archive file"
931 wait_request_state $fid ARCHIVE SUCCEED
933 # Release and check states
934 $LFS hsm_release $f || error "could not release file"
935 echo -n "Verifying released state: "
936 check_hsm_flags $f "0x0000000d"
938 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
940 run_test 1a "mmap & cat a HSM released file"
944 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
945 error "failed to set default stripe"
946 local f=$DIR/$tdir/$tfile
949 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
950 error "failed to create file"
951 local fid=$(path2fid $f)
956 $LFS hsm_archive $f || error "could not archive file"
957 wait_request_state $fid ARCHIVE SUCCEED
960 $LFS hsm_release $f || error "could not release file"
961 echo "verify released state: "
962 check_hsm_flags $f "0x0000000d" && echo "pass"
965 $LFS hsm_restore $f || error "could not restore file"
966 wait_request_state $fid RESTORE SUCCEED
967 echo "verify restored state: "
968 check_hsm_flags $f "0x00000009" && echo "pass"
970 run_test 1b "Archive, Release and Restore composite file"
976 local f=$DIR/$tdir/$tfile
979 # Test whether we can set the maximum archive number.
980 local LOCAL_HSM_ARCHIVE_NUMBER=32
981 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
982 error "root could not change hsm flags"
983 check_hsm_flags_user $f "0x00000001"
984 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
985 local st=$(get_hsm_archive_id $f)
986 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
987 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
989 # Test whether setting archive number 0 results in no change.
990 $LFS hsm_set --exists --archive-id 0 $f ||
991 error "root could not change hsm flags"
992 check_hsm_flags_user $f "0x00000001"
993 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
994 st=$(get_hsm_archive_id $f)
995 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
996 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
998 LOCAL_HSM_ARCHIVE_NUMBER=33
999 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
1000 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
1001 # lustre in the new version supports unlimited archiveID.
1002 # Test whether setting archive number > 32 is supported
1003 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1004 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
1005 check_hsm_flags_user $f "0x00000001"
1007 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1008 st=$(get_hsm_archive_id $f)
1009 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1010 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1012 # old client or old mds can only support at most 32 archiveID
1013 # test whether setting archive number > 32 results in error.
1014 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
1015 error "bitmap archive number is larger than 32"
1016 check_hsm_flags_user $f "0x00000001"
1019 # Test whether setting archive number 16 and archived flag.
1020 LOCAL_HSM_ARCHIVE_NUMBER=16
1021 $LFS hsm_set --exists --archived \
1022 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1023 error "root could not change hsm flags"
1024 check_hsm_flags_user $f "0x00000009"
1025 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1026 st=$(get_hsm_archive_id $f)
1027 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1028 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1030 run_test 1c "Check setting archive-id in lfs hsm_set"
1033 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1034 skip "need MDS version at least 2.10.59"
1037 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1038 error "failed to set default stripe"
1039 local f=$DIR/$tdir/$tfile
1042 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1043 error "failed to create file"
1044 local fid=$(path2fid $f)
1049 $LFS hsm_archive $f || error "could not archive file"
1050 wait_request_state $fid ARCHIVE SUCCEED
1053 $LFS hsm_release $f || error "could not release file"
1054 echo "verify released state: "
1055 check_hsm_flags $f "0x0000000d" && echo "pass"
1058 $LFS hsm_restore $f || error "could not restore file"
1059 wait_request_state $fid RESTORE SUCCEED
1060 echo "verify restored state: "
1061 check_hsm_flags $f "0x00000009" && echo "pass"
1063 run_test 1d "Archive, Release and Restore DoM file"
1066 local f=$DIR/$tdir/$tfile
1068 create_empty_file "$f"
1069 # New files are not dirty
1070 check_hsm_flags $f "0x00000000"
1072 # For test, we simulate an archived file.
1073 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1074 check_hsm_flags $f "0x00000001"
1076 # chmod do not put the file dirty
1077 chmod 600 $f || error "could not chmod test file"
1078 check_hsm_flags $f "0x00000001"
1080 # chown do not put the file dirty
1081 chown $RUNAS_ID $f || error "could not chown test file"
1082 check_hsm_flags $f "0x00000001"
1084 # truncate put the file dirty
1085 $TRUNCATE $f 1 || error "could not truncate test file"
1086 check_hsm_flags $f "0x00000003"
1088 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1089 check_hsm_flags $f "0x00000001"
1091 run_test 2 "Check file dirtyness when doing setattr"
1097 # New files are not dirty
1098 cp -p /etc/passwd $f
1099 check_hsm_flags $f "0x00000000"
1101 # For test, we simulate an archived file.
1102 $LFS hsm_set --exists $f ||
1103 error "user could not change hsm flags"
1104 check_hsm_flags $f "0x00000001"
1106 # Reading a file, does not set dirty
1107 cat $f > /dev/null || error "could not read file"
1108 check_hsm_flags $f "0x00000001"
1110 # Open for write without modifying data, does not set dirty
1111 openfile -f O_WRONLY $f || error "could not open test file"
1112 check_hsm_flags $f "0x00000001"
1114 # Append to a file sets it dirty
1115 cp -p /etc/passwd $f.append || error "could not create file"
1116 $LFS hsm_set --exists $f.append ||
1117 error "user could not change hsm flags"
1118 dd if=/etc/passwd of=$f.append bs=1 count=3\
1119 conv=notrunc oflag=append status=noxfer ||
1120 file_creation_failure dd $f.append $?
1121 check_hsm_flags $f.append "0x00000003"
1123 # Modify a file sets it dirty
1124 cp -p /etc/passwd $f.modify || error "could not create file"
1125 $LFS hsm_set --exists $f.modify ||
1126 error "user could not change hsm flags"
1127 dd if=/dev/zero of=$f.modify bs=1 count=3\
1128 conv=notrunc status=noxfer ||
1129 file_creation_failure dd $f.modify $?
1130 check_hsm_flags $f.modify "0x00000003"
1132 # Open O_TRUNC sets dirty
1133 cp -p /etc/passwd $f.trunc || error "could not create file"
1134 $LFS hsm_set --exists $f.trunc ||
1135 error "user could not change hsm flags"
1136 cp /etc/group $f.trunc || error "could not override a file"
1137 check_hsm_flags $f.trunc "0x00000003"
1139 # Mmapped a file sets dirty
1140 cp -p /etc/passwd $f.mmap || error "could not create file"
1141 $LFS hsm_set --exists $f.mmap ||
1142 error "user could not change hsm flags"
1143 multiop $f.mmap OSMWUc || error "could not mmap a file"
1144 check_hsm_flags $f.mmap "0x00000003"
1146 run_test 3 "Check file dirtyness when opening for write"
1149 local f=$DIR/$tdir/$tfile
1150 local fid=$(create_small_file $f)
1153 local st=$(get_request_state $fid CANCEL)
1154 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1156 run_test 4 "Useless cancel must not be registered"
1159 # test needs a running copytool
1163 local f=$DIR/$tdir/$tfile
1164 local fid=$(copy_file /etc/passwd $f)
1166 wait_request_state $fid ARCHIVE SUCCEED
1168 check_hsm_flags $f "0x00000009"
1170 run_test 8 "Test default archive number"
1172 test_9A() { # was test_9
1173 # we do not use the default one to be sure
1174 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1175 copytool setup --archive-id $archive_id
1177 # give time for CT to register with MDTs
1178 sleep $(($MDSCOUNT*2))
1179 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1180 check_agent_registered $uuid
1183 local f=$DIR/$tdir/$tfile
1184 local fid=$(copy_file /etc/passwd $f)
1185 $LFS hsm_archive --archive $archive_id $f
1186 wait_request_state $fid ARCHIVE SUCCEED
1188 check_hsm_flags $f "0x00000009"
1190 run_test 9A "Use of explicit archive number, with dedicated copytool"
1193 needclients 3 || return 0
1199 # start all of the copytools
1200 for n in $(seq $AGTCOUNT); do
1201 copytool setup --facet agt$n
1205 for n in $(seq $AGTCOUNT); do
1206 file=$DIR/$tdir/$tfile.$n
1207 fid=$(create_small_file $file)
1209 $LFS hsm_archive $file || error "could not archive file $file"
1210 wait_request_state $fid ARCHIVE SUCCEED
1211 check_hsm_flags $file "0x00000009"
1214 run_test 9a "Multiple remote agents"
1217 # test needs a running copytool
1220 mkdir -p $DIR/$tdir/d1
1221 local f=$DIR/$tdir/$tfile
1222 local fid=$(copy_file /etc/hosts $f)
1223 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1224 error "hsm_archive failed"
1225 wait_request_state $fid ARCHIVE SUCCEED
1227 local hsm_root="$(copytool_device $SINGLEAGT)"
1228 local archive="$(do_facet $SINGLEAGT \
1229 find "$hsm_root" -name "$fid" -print0)"
1230 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1232 echo "Verifying content"
1233 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1234 echo "Verifying hsm state "
1235 check_hsm_flags $f "0x00000009"
1237 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1238 local st=$(get_hsm_archive_id $f)
1239 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1240 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1242 run_test 10a "Archive a file"
1245 # test needs a running copytool
1249 local f=$DIR/$tdir/$tfile
1250 local fid=$(copy_file /etc/hosts $f)
1251 $LFS hsm_archive $f || error "archive request failed"
1252 wait_request_state $fid ARCHIVE SUCCEED
1254 $LFS hsm_archive $f || error "archive of non dirty file failed"
1255 local cnt=$(get_request_count $fid ARCHIVE)
1256 [[ "$cnt" == "1" ]] ||
1257 error "archive of non dirty file must not make a request"
1259 run_test 10b "Archive of non dirty file must work without doing request"
1262 # test needs a running copytool
1266 local f=$DIR/$tdir/$tfile
1267 local fid=$(copy_file /etc/hosts $f)
1268 $LFS hsm_set --noarchive $f
1269 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1272 run_test 10c "Check forbidden archive"
1275 # test needs a running copytool
1279 local f=$DIR/$tdir/$tfile
1280 local fid=$(copy_file /etc/hosts $f)
1281 $LFS hsm_archive $f || error "cannot archive $f"
1282 wait_request_state $fid ARCHIVE SUCCEED
1284 local ar=$(get_hsm_archive_id $f)
1285 local dflt=$(get_hsm_param default_archive_id)
1286 [[ $ar == $dflt ]] ||
1287 error "archived file is not on default archive: $ar != $dflt"
1289 run_test 10d "Archive a file on the default archive id"
1293 copy2archive /etc/hosts $tdir/$tfile
1294 local f=$DIR/$tdir/$tfile
1296 copytool import $tdir/$tfile $f
1297 echo -n "Verifying released state: "
1298 check_hsm_flags $f "0x0000000d"
1300 local LSZ=$(stat -c "%s" $f)
1301 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1303 echo "Verifying imported size $LSZ=$ASZ"
1304 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1305 echo -n "Verifying released pattern: "
1306 local PTRN=$($GETSTRIPE -L $f)
1308 [[ $PTRN == released ]] || error "Is not released"
1309 local fid=$(path2fid $f)
1310 echo "Verifying new fid $fid in archive"
1312 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1313 error "No archive for fid $fid"
1315 run_test 11a "Import a file"
1318 # test needs a running copytool
1322 local f=$DIR/$tdir/$tfile
1323 local fid=$(copy_file /etc/hosts $f)
1324 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1325 error "hsm_archive failed"
1326 wait_request_state $fid ARCHIVE SUCCEED
1328 local FILE_HASH=$(md5sum $f)
1331 copytool import $fid $f
1333 echo "$FILE_HASH" | md5sum -c
1335 [[ $? -eq 0 ]] || error "Restored file differs"
1337 run_test 11b "Import a deleted file using its FID"
1340 # test needs a running copytool
1344 copy2archive /etc/hosts $tdir/$tfile
1346 local f=$DIR/$tdir/$tfile
1347 copytool import $tdir/$tfile $f
1348 local f2=$DIR2/$tdir/$tfile
1349 echo "Verifying released state: "
1350 check_hsm_flags $f2 "0x0000000d"
1352 local fid=$(path2fid $f2)
1353 $LFS hsm_restore $f2
1354 wait_request_state $fid RESTORE SUCCEED
1356 echo "Verifying file state: "
1357 check_hsm_flags $f2 "0x00000009"
1359 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1361 [[ $? -eq 0 ]] || error "Restored file differs"
1363 run_test 12a "Restore an imported file explicitly"
1366 # test needs a running copytool
1370 copy2archive /etc/hosts $tdir/$tfile
1372 local f=$DIR/$tdir/$tfile
1373 copytool import $tdir/$tfile $f
1374 echo "Verifying released state: "
1375 check_hsm_flags $f "0x0000000d"
1377 cat $f > /dev/null || error "File read failed"
1379 echo "Verifying file state after restore: "
1380 check_hsm_flags $f "0x00000009"
1382 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1384 [[ $? -eq 0 ]] || error "Restored file differs"
1386 run_test 12b "Restore an imported file implicitly"
1389 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1391 # test needs a running copytool
1394 local f=$DIR/$tdir/$tfile
1396 $LFS setstripe -c 2 "$f"
1397 local fid=$(create_file "$f" 1M 5)
1399 local FILE_CRC=$(md5sum $f)
1401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1402 wait_request_state $fid ARCHIVE SUCCEED
1403 $LFS hsm_release $f || error "release $f failed"
1405 echo "$FILE_CRC" | md5sum -c
1407 [[ $? -eq 0 ]] || error "Restored file differs"
1409 run_test 12c "Restore a file with stripe of 2"
1412 # test needs a running copytool
1417 local f=$DIR/$tdir/$tfile
1418 local fid=$(copy_file /etc/hosts $f)
1419 $LFS hsm_restore $f || error "restore of non archived file failed"
1420 local cnt=$(get_request_count $fid RESTORE)
1421 [[ "$cnt" == "0" ]] ||
1422 error "restore non archived must not make a request"
1423 $LFS hsm_archive $f ||
1424 error "archive request failed"
1425 wait_request_state $fid ARCHIVE SUCCEED
1426 $LFS hsm_restore $f ||
1427 error "restore of non released file failed"
1428 local cnt=$(get_request_count $fid RESTORE)
1429 [[ "$cnt" == "0" ]] ||
1430 error "restore a non dirty file must not make a request"
1432 run_test 12d "Restore of a non archived, non released file must work"\
1433 " without doing request"
1436 # test needs a running copytool
1440 local f=$DIR/$tdir/$tfile
1441 local fid=$(copy_file /etc/hosts $f)
1442 $LFS hsm_archive $f || error "archive request failed"
1443 wait_request_state $fid ARCHIVE SUCCEED
1446 cat /etc/hosts >> $f
1450 $LFS hsm_restore $f && error "restore a dirty file must fail"
1453 run_test 12e "Check forbidden restore"
1456 # test needs a running copytool
1460 local f=$DIR/$tdir/$tfile
1461 local fid=$(copy_file /etc/hosts $f)
1463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1464 wait_request_state $fid ARCHIVE SUCCEED
1465 $LFS hsm_release $f || error "release of $f failed"
1467 wait_request_state $fid RESTORE SUCCEED
1469 echo -n "Verifying file state: "
1470 check_hsm_flags $f "0x00000009"
1472 diff -q /etc/hosts $f
1474 [[ $? -eq 0 ]] || error "Restored file differs"
1476 run_test 12f "Restore a released file explicitly"
1479 # test needs a running copytool
1483 local f=$DIR/$tdir/$tfile
1484 local fid=$(copy_file /etc/hosts $f)
1486 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1487 wait_request_state $fid ARCHIVE SUCCEED
1488 $LFS hsm_release $f || error "release of $f failed"
1490 diff -q /etc/hosts $f
1493 # we check we had a restore done
1494 wait_request_state $fid RESTORE SUCCEED
1496 [[ $st -eq 0 ]] || error "Restored file differs"
1498 run_test 12g "Restore a released file implicitly"
1501 needclients 2 || return 0
1503 # test needs a running copytool
1507 local f=$DIR/$tdir/$tfile
1508 local fid=$(copy_file /etc/hosts $f)
1510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1511 wait_request_state $fid ARCHIVE SUCCEED
1512 $LFS hsm_release $f || error "release of $f failed"
1514 do_node $CLIENT2 diff -q /etc/hosts $f
1517 # we check we had a restore done
1518 wait_request_state $fid RESTORE SUCCEED
1520 [[ $st -eq 0 ]] || error "Restored file differs"
1522 run_test 12h "Restore a released file implicitly from a second node"
1525 # test needs a running copytool
1529 local f=$DIR/$tdir/$tfile
1530 local fid=$(copy_file /etc/passwd $f)
1531 $LFS hsm_archive $f || error "archive of $f failed"
1532 wait_request_state $fid ARCHIVE SUCCEED
1534 $LFS hsm_release $f || error "release of $f failed"
1538 [[ $? -eq 0 ]] || error "Restored file differs"
1540 run_test 12m "Archive/release/implicit restore"
1543 # test needs a running copytool
1547 copy2archive /etc/hosts $tdir/$tfile
1549 local f=$DIR/$tdir/$tfile
1550 copytool import $tdir/$tfile $f
1552 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1553 error "Restored file differs"
1555 $LFS hsm_release $f || error "release of $f failed"
1557 run_test 12n "Import/implicit restore/release"
1560 # test needs a running copytool
1564 local f=$DIR/$tdir/$tfile
1565 local fid=$(copy_file /etc/hosts $f)
1567 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1568 wait_request_state $fid ARCHIVE SUCCEED
1569 $LFS hsm_release $f || error "release of $f failed"
1571 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1572 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1574 # set no retry action mode
1577 diff -q /etc/hosts $f
1580 # we check we had a restore failure
1581 wait_request_state $fid RESTORE FAILED
1583 [[ $st -eq 0 ]] && error "Restore must fail"
1585 # remove no retry action mode
1588 # check file is still released
1589 check_hsm_flags $f "0x0000000d"
1591 # retry w/o failure injection
1592 do_facet $SINGLEMDS lctl set_param fail_loc=0
1594 # to be sure previous RESTORE result is gone
1596 wait_for_grace_delay
1598 diff -q /etc/hosts $f
1601 # we check we had a restore done
1602 wait_request_state $fid RESTORE SUCCEED
1604 [[ $st -eq 0 ]] || error "Restored file differs"
1606 run_test 12o "Layout-swap failure during Restore leaves file released"
1609 # test needs a running copytool
1613 local f=$DIR/$tdir/$tfile
1614 local fid=$(copy_file /etc/hosts $f)
1616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1617 wait_request_state $fid ARCHIVE SUCCEED
1618 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1619 $LFS hsm_release $f || error "cannot release $f"
1620 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1621 $LFS hsm_release $f || error "cannot release $f"
1622 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1624 run_test 12p "implicit restore of a file on copytool mount point"
1627 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1628 skip "need MDS version at least 2.7.58"
1630 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1631 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1632 error "cannot mount $MOUNT3 on $SINGLEAGT"
1634 # test needs a running copytool
1635 copytool setup -m "$MOUNT3"
1637 local f=$DIR/$tdir/$tfile
1638 local f2=$DIR2/$tdir/$tfile
1639 local fid=$(create_small_file $f)
1640 local orig_size=$(stat -c "%s" $f)
1642 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1643 wait_request_state $fid ARCHIVE SUCCEED
1645 $LFS hsm_release $f || error "could not release file"
1646 check_hsm_flags $f "0x0000000d"
1649 wait_copytools || error "copytool failed to stop"
1651 cat $f > /dev/null &
1653 # wait a bit to allow implicit restore request to be handled.
1654 # if not, next stat would also block on layout-lock.
1657 local size=$(stat -c "%s" $f2)
1658 [ $size -eq $orig_size ] ||
1659 error "$f2: wrong size after archive: $size != $orig_size"
1661 copytool setup -m "$MOUNT3"
1665 size=$(stat -c "%s" $f)
1666 [ $size -eq $orig_size ] ||
1667 error "$f: wrong size after restore: $size != $orig_size"
1669 size=$(stat -c "%s" $f2)
1670 [ $size -eq $orig_size ] ||
1671 error "$f2: wrong size after restore: $size != $orig_size"
1675 size=$(stat -c "%s" $f)
1677 error "$f: wrong size after overwrite: $size != 0"
1679 size=$(stat -c "%s" $f2)
1681 error "$f2: wrong size after overwrite: $size != 0"
1683 run_test 12q "file attributes are refreshed after restore"
1687 for i in {1..10}; do
1688 local archive_dir="$(hsm_root)"/subdir/dir.$i
1690 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1691 for j in {1..10}; do
1692 local archive_file="$archive_dir"/file.$j
1694 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1700 copytool import "subdir" "$DIR/$tdir"
1702 # To check the import, the test uses diff with the -r flag
1703 # This is nice, but diff only checks files one by one, and triggering
1704 # an implicit restore for one file at a time will consume as many
1705 # seconds as there are files to compare. To speed this up, a restore
1706 # operation is triggered manually first.
1708 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1710 # Compare the imported data
1711 do_facet $SINGLEAGT \
1712 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1713 error "imported files differ from archived data"
1715 run_test 13 "Recursively import and restore a directory"
1718 # test needs a running copytool
1722 local f=$DIR/$tdir/$tfile
1723 local fid=$(create_small_file $f)
1724 local sum=$(md5sum $f | awk '{print $1}')
1725 $LFS hsm_archive $f || error "could not archive file"
1726 wait_request_state $fid ARCHIVE SUCCEED
1728 # create released file (simulate llapi_hsm_import call)
1729 local fid2=$(create_empty_file "$f")
1730 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1731 $LFS hsm_release $f || error "could not release file"
1733 # rebind the archive to the newly created file
1734 echo "rebind $fid to $fid2"
1736 copytool rebind $fid $fid2
1738 # restore file and compare md5sum
1739 local sum2=$(md5sum $f | awk '{print $1}')
1741 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1743 run_test 14 "Rebind archived file to a new fid"
1746 # test needs a running copytool
1750 local f=$DIR/$tdir/$tfile
1752 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1756 for i in $(seq 1 $count); do
1757 fids[$i]=$(create_small_file $f.$i)
1758 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1759 $LFS hsm_archive $f.$i || error "could not archive file"
1761 wait_all_done $(($count*60))
1763 stack_trap "rm -f $tmpfile" EXIT
1766 for i in $(seq 1 $count); do
1767 local fid2=$(create_empty_file "${f}.${i}")
1768 # add the rebind operation to the list
1769 echo ${fids[$i]} $fid2 >> $tmpfile
1771 # set it released (simulate llapi_hsm_import call)
1772 $LFS hsm_set --archived --exists $f.$i ||
1773 error "could not force hsm flags"
1774 $LFS hsm_release $f.$i || error "could not release file"
1776 nl=$(wc -l < $tmpfile)
1777 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1779 echo "rebind list of files"
1780 copytool rebind "$tmpfile"
1782 # restore files and compare md5sum
1783 for i in $(seq 1 $count); do
1784 local sum2=$(md5sum $f.$i | awk '{print $1}')
1785 [[ $sum2 == ${sums[$i]} ]] ||
1786 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1789 run_test 15 "Rebind a list of files"
1792 # test needs a running copytool
1796 # create a known size file so we can verify transfer speed
1799 dd if=/dev/zero of=$ref bs=1M count=20
1802 local f=$DIR/$tdir/$tfile
1803 local fid=$(copy_file $ref $f)
1805 local start=$(date +%s)
1807 wait_request_state $fid ARCHIVE SUCCEED
1808 local end=$(date +%s)
1809 # Add 1 to account for rounding errors between start and end (LU-8155)
1810 local duration=$((end - start + 1))
1812 [[ $duration -ge $((goal - 1)) ]] ||
1813 error "Transfer is too fast $duration < $goal"
1815 run_test 16 "Test CT bandwith control option"
1818 local f=$DIR/$tdir/$tfile
1819 create_empty_file "$f"
1821 # Could not release a non-archived file
1822 $LFS hsm_release $f && error "release should not succeed"
1824 # For following tests, we must test them with HS_ARCHIVED set
1825 $LFS hsm_set --exists --archived $f || error "could not add flag"
1827 # Could not release a file if no-release is set
1828 $LFS hsm_set --norelease $f || error "could not add flag"
1829 $LFS hsm_release $f && error "release should not succeed"
1830 $LFS hsm_clear --norelease $f || error "could not remove flag"
1832 # Could not release a file if lost
1833 $LFS hsm_set --lost $f || error "could not add flag"
1834 $LFS hsm_release $f && error "release should not succeed"
1835 $LFS hsm_clear --lost $f || error "could not remove flag"
1837 # Could not release a file if dirty
1838 $LFS hsm_set --dirty $f || error "could not add flag"
1839 $LFS hsm_release $f && error "release should not succeed"
1840 $LFS hsm_clear --dirty $f || error "could not remove flag"
1842 run_test 20 "Release is not permitted"
1845 # test needs a running copytool
1848 local f=$DIR/$tdir/test_release
1850 # Create a file and check its states
1851 local fid=$(create_small_file $f)
1852 check_hsm_flags $f "0x00000000"
1854 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1855 # used until file is flushed to disk
1856 if [ $(facet_fstype ost1) == "zfs" ]; then
1857 # this causes an OST_SYNC rpc to be sent
1858 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1859 # clear locks to reread file data
1860 cancel_lru_locks osc
1863 local orig_size=$(stat -c "%s" $f)
1864 local orig_blocks=$(stat -c "%b" $f)
1866 start_full_debug_logging
1868 $LFS hsm_archive $f || error "could not archive file"
1869 wait_request_state $fid ARCHIVE SUCCEED
1871 local blocks=$(stat -c "%b" $f)
1872 [ $blocks -eq $orig_blocks ] ||
1873 error "$f: wrong block number after archive: " \
1874 "$blocks != $orig_blocks"
1875 local size=$(stat -c "%s" $f)
1876 [ $size -eq $orig_size ] ||
1877 error "$f: wrong size after archive: $size != $orig_size"
1879 # Release and check states
1880 $LFS hsm_release $f || error "could not release file"
1881 check_hsm_flags $f "0x0000000d"
1883 blocks=$(stat -c "%b" $f)
1884 [ $blocks -gt 5 ] &&
1885 error "$f: too many blocks after release: $blocks > 5"
1886 size=$(stat -c "%s" $f)
1887 [ $size -ne $orig_size ] &&
1888 error "$f: wrong size after release: $size != $orig_size"
1890 # Check we can release an file without stripe info
1894 check_hsm_flags $f "0x00000000"
1895 $LFS hsm_archive $f || error "could not archive file"
1896 wait_request_state $fid ARCHIVE SUCCEED
1898 # Release and check states
1899 $LFS hsm_release $f || error "could not release file"
1900 check_hsm_flags $f "0x0000000d"
1902 # Release again a file that is already released is OK
1903 $LFS hsm_release $f || fail "second release should succeed"
1904 check_hsm_flags $f "0x0000000d"
1906 stop_full_debug_logging
1908 run_test 21 "Simple release tests"
1911 # test needs a running copytool
1914 local f=$DIR/$tdir/test_release
1915 local swap=$DIR/$tdir/test_swap
1917 # Create a file and check its states
1918 local fid=$(create_small_file $f)
1919 check_hsm_flags $f "0x00000000"
1921 $LFS hsm_archive $f || error "could not archive file"
1922 wait_request_state $fid ARCHIVE SUCCEED
1924 # Release and check states
1925 $LFS hsm_release $f || error "could not release file"
1926 check_hsm_flags $f "0x0000000d"
1928 create_small_file $swap
1929 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1933 run_test 22 "Could not swap a release file"
1936 # test needs a running copytool
1939 local f=$DIR/$tdir/test_mtime
1941 # Create a file and check its states
1942 local fid=$(create_small_file $f)
1943 check_hsm_flags $f "0x00000000"
1945 $LFS hsm_archive $f || error "could not archive file"
1946 wait_request_state $fid ARCHIVE SUCCEED
1948 # Set modification time in the past
1949 touch -m -a -d @978261179 $f
1951 # Release and check states
1952 $LFS hsm_release $f || error "could not release file"
1953 check_hsm_flags $f "0x0000000d"
1955 local MTIME=$(stat -c "%Y" $f)
1956 local ATIME=$(stat -c "%X" $f)
1957 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1958 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1960 run_test 23 "Release does not change a/mtime (utime)"
1963 local file=$DIR/$tdir/$tfile
1972 # test needs a running copytool
1975 fid=$(create_small_file $file)
1977 # Create a file and check its states
1978 check_hsm_flags $file "0x00000000"
1980 # Ensure atime is less than mtime and ctime.
1984 atime0=$(stat -c "%X" $file)
1985 mtime0=$(stat -c "%Y" $file)
1986 ctime0=$(stat -c "%Z" $file)
1988 [ $atime0 -lt $mtime0 ] ||
1989 error "atime $atime0 is not less than mtime $mtime0"
1991 [ $atime0 -lt $ctime0 ] ||
1992 error "atime $atime0 is not less than ctime $ctime0"
1994 # Archive should not change any timestamps.
1995 $LFS hsm_archive $file || error "cannot archive '$file'"
1996 wait_request_state $fid ARCHIVE SUCCEED
1998 atime1=$(stat -c "%X" $file)
1999 mtime1=$(stat -c "%Y" $file)
2000 ctime1=$(stat -c "%Z" $file)
2002 [ $atime0 -eq $atime1 ] ||
2003 error "archive changed atime from $atime0 to $atime1"
2005 [ $mtime0 -eq $mtime1 ] ||
2006 error "archive changed mtime from $mtime0 to $mtime1"
2008 [ $ctime0 -eq $ctime1 ] ||
2009 error "archive changed ctime from $ctime0 to $ctime1"
2011 # Release should not change any timestamps.
2012 $LFS hsm_release $file || error "cannot release '$file'"
2013 check_hsm_flags $file "0x0000000d"
2015 atime1=$(stat -c "%X" $file)
2016 mtime1=$(stat -c "%Y" $file)
2017 ctime1=$(stat -c "%Z" $file)
2019 [ $atime0 -eq $atime1 ] ||
2020 error "release changed atime from $atime0 to $atime1"
2022 [ $mtime0 -eq $mtime1 ] ||
2023 error "release changed mtime from $mtime0 to $mtime1"
2025 [ $ctime0 -eq $ctime1 ] ||
2026 error "release changed ctime from $ctime0 to $ctime1"
2028 # Restore should not change any timestamps.
2029 $LFS hsm_restore $file
2030 wait_request_state $fid RESTORE SUCCEED
2032 atime1=$(stat -c "%X" $file)
2033 mtime1=$(stat -c "%Y" $file)
2034 ctime1=$(stat -c "%Z" $file)
2036 [ $atime0 -eq $atime1 ] ||
2037 error "restore changed atime from $atime0 to $atime1"
2039 [ $mtime0 -eq $mtime1 ] ||
2040 error "restore changed mtime from $mtime0 to $mtime1"
2042 [ $ctime0 -eq $ctime1 ] ||
2043 error "restore changed ctime from $ctime0 to $ctime1"
2046 wait_copytools || error "Copytools failed to stop"
2048 # Once more, after unmount and mount.
2049 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2050 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2052 atime1=$(stat -c "%X" $file)
2053 mtime1=$(stat -c "%Y" $file)
2054 ctime1=$(stat -c "%Z" $file)
2056 [ $atime0 -eq $atime1 ] ||
2057 error "remount changed atime from $atime0 to $atime1"
2059 [ $mtime0 -eq $mtime1 ] ||
2060 error "remount changed mtime from $mtime0 to $mtime1"
2062 [ $ctime0 -eq $ctime1 ] ||
2063 error "remount changed ctime from $ctime0 to $ctime1"
2065 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2068 local file=$DIR/$tdir/$tfile
2074 # Test needs a running copytool.
2077 # Check that root can do HSM actions on a regular user's file.
2078 fid=$(create_small_file $file)
2079 sum0=$(md5sum $file)
2081 chown $RUNAS_ID:$RUNAS_GID $file ||
2082 error "cannot chown '$file' to '$RUNAS_ID'"
2084 chmod ugo-w $DIR/$tdir ||
2085 error "cannot chmod '$DIR/$tdir'"
2087 $LFS hsm_archive $file
2088 wait_request_state $fid ARCHIVE SUCCEED
2090 $LFS hsm_release $file
2091 check_hsm_flags $file "0x0000000d"
2093 $LFS hsm_restore $file
2094 wait_request_state $fid RESTORE SUCCEED
2096 # Check that ordinary user can get HSM state.
2097 $RUNAS $LFS hsm_state $file ||
2098 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2100 $LFS hsm_release $file
2101 check_hsm_flags $file "0x0000000d"
2103 # Check that ordinary user can accessed released file.
2104 sum1=$($RUNAS md5sum $file) ||
2105 error "user '$RUNAS_ID' cannot read '$file'"
2107 [ "$sum0" == "$sum1" ] ||
2108 error "md5sum mismatch for '$file'"
2110 run_test 24b "root can archive, release, and restore user files"
2113 local file=$DIR/$tdir/$tfile
2114 local action=archive
2119 # test needs a running copytool
2124 # Save the default masks and check that cleanup_24c will
2125 # restore the request masks correctly.
2126 user_save=$(get_hsm_param user_request_mask)
2127 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2128 group_save=$(get_hsm_param group_request_mask)
2129 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2130 other_save=$(get_hsm_param other_request_mask)
2131 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2133 [ "$user_save" == RESTORE ] ||
2134 error "user_request_mask is '$user_save' expected 'RESTORE'"
2135 [ "$group_save" == RESTORE ] ||
2136 error "group_request_mask is '$group_save' expected 'RESTORE'"
2137 [ "$other_save" == RESTORE ] ||
2138 error "other_request_mask is '$other_save' expected 'RESTORE'"
2141 create_small_file $file
2142 chown $RUNAS_ID:$GROUP $file ||
2143 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2145 $RUNAS $LFS hsm_$action $file &&
2146 error "$action by user should fail"
2148 set_hsm_param user_request_mask $action
2149 $RUNAS $LFS hsm_$action $file ||
2150 error "$action by user should succeed"
2153 create_small_file $file
2154 chown nobody:$RUNAS_GID $file ||
2155 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2157 $RUNAS $LFS hsm_$action $file &&
2158 error "$action by group should fail"
2160 set_hsm_param group_request_mask $action
2161 $RUNAS $LFS hsm_$action $file ||
2162 error "$action by group should succeed"
2165 create_small_file $file
2166 chown nobody:$GROUP $file ||
2167 error "cannot chown '$file' to 'nobody:$GROUP'"
2169 $RUNAS $LFS hsm_$action $file &&
2170 error "$action by other should fail"
2172 set_hsm_param other_request_mask $action
2173 $RUNAS $LFS hsm_$action $file ||
2174 error "$action by other should succeed"
2176 run_test 24c "check that user,group,other request masks work"
2179 local file1=$DIR/$tdir/$tfile
2180 local file2=$DIR2/$tdir/$tfile
2184 fid1=$(create_small_file $file1)
2187 $LFS getstripe $file1
2189 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2190 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2191 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2193 copytool setup -m "$MOUNT3"
2195 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2196 mount -o remount,ro $MOUNT2
2198 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2200 fid2=$(path2fid $file2)
2201 [ "$fid1" == "$fid2" ] ||
2202 error "FID mismatch '$fid1' != '$fid2'"
2204 $LFS hsm_archive $file2 &&
2205 error "archive should fail on read-only mount"
2206 check_hsm_flags $file1 "0x00000000"
2208 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2209 wait_request_state $fid1 ARCHIVE SUCCEED
2211 $LFS hsm_release $file1
2212 $LFS hsm_restore $file2
2213 wait_request_state $fid1 RESTORE SUCCEED
2215 $LFS hsm_release $file1 || error "cannot release '$file1'"
2216 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2218 $LFS hsm_release $file2 &&
2219 error "release should fail on read-only mount"
2223 run_test 24d "check that read-only mounts are respected"
2228 local f=$DIR/$tdir/$tfile
2231 fid=$(create_small_file $f) || error "cannot create $f"
2232 $LFS hsm_archive $f || error "cannot archive $f"
2233 wait_request_state $fid ARCHIVE SUCCEED
2234 $LFS hsm_release $f || error "cannot release $f"
2235 while ! $LFS hsm_state $f | grep released; do
2239 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2241 run_test 24e "tar succeeds on HSM released files" # LU-6213
2244 # test needs a running copytool
2247 mkdir -p $DIR/$tdir/d1
2248 local f=$DIR/$tdir/$tfile
2249 local fid=$(copy_file /etc/hosts $f)
2252 $LFS hsm_archive $f ||
2253 error "hsm_archive failed"
2254 wait_request_state $fid ARCHIVE SUCCEED
2255 $LFS hsm_release $f || error "cannot release $f"
2256 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2259 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2260 error "Can not recover the tar contents"
2262 echo "Sum0 = $sum0, sum1 = $sum1"
2263 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2265 run_test 24f "root can archive, release, and restore tar files"
2268 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2269 skip "need MDS version 2.11.56 or later"
2271 local file=$DIR/$tdir/$tfile
2274 echo "RUNAS = '$RUNAS'"
2279 chmod ugo+rwx $DIR/$tdir
2281 echo "Please listen carefully as our options have changed." | tee $file
2282 fid=$(path2fid $file)
2285 $LFS hsm_archive $file
2286 wait_request_state $fid ARCHIVE SUCCEED
2287 check_hsm_flags $file 0x00000009 # exists archived
2289 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2290 check_hsm_flags $file 0x0000000b # exists dirty archived
2292 run_test 24g "write by non-owner still sets dirty" # LU-11369
2295 # test needs a running copytool
2299 copy2archive /etc/hosts $tdir/$tfile
2301 local f=$DIR/$tdir/$tfile
2303 copytool import $tdir/$tfile $f
2305 $LFS hsm_set --lost $f
2310 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2312 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2313 " (Operation not permitted)"
2316 # test needs a running copytool
2321 local f=$DIR/$tdir/$tfile
2322 local fid=$(copy_file /etc/passwd $f)
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2325 wait_request_state $fid ARCHIVE SUCCEED
2328 $LFS hsm_set --lost $f
2332 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2334 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2335 " (Operation not permitted)"
2337 test_26A() { # was test_26
2338 # test needs a running copytool
2341 local f=$DIR/$tdir/$tfile
2342 local fid=$(create_empty_file "$f")
2344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2345 wait_request_state $fid ARCHIVE SUCCEED
2348 wait_request_state $fid REMOVE SUCCEED
2350 check_hsm_flags $f "0x00000000"
2352 run_test 26A "Remove the archive of a valid file"
2355 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2356 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2358 # test needs a running copytool
2362 local f=$DIR/$tdir/$tfile
2363 local fid=$(copy_file /etc/passwd $f)
2365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2366 wait_request_state $fid ARCHIVE SUCCEED
2368 local f2=$DIR/$tdir/${tfile}_2
2369 local fid2=$(copy_file /etc/passwd $f2)
2371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2372 wait_request_state $fid2 ARCHIVE SUCCEED
2374 local f3=$DIR/$tdir/${tfile}_3
2375 local fid3=$(copy_file /etc/passwd $f3)
2377 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2378 wait_request_state $fid3 ARCHIVE SUCCEED
2380 # set a long grace_delay vs short loop_period
2381 local orig_loop_period=$(get_hsm_param loop_period)
2382 local orig_grace_delay=$(get_hsm_param grace_delay)
2383 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2384 set_hsm_param loop_period 10
2385 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2386 set_hsm_param grace_delay 100
2390 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2391 set_hsm_param remove_archive_on_last_unlink 1
2393 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2398 wait_request_state $fid2 REMOVE SUCCEED
2400 assert_request_count $fid REMOVE 0 \
2401 "Unexpected archived data remove request for $f"
2402 assert_request_count $fid3 REMOVE 0 \
2403 "Unexpected archived data remove request for $f3"
2405 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2408 # test needs a running copytool
2412 local f=$DIR/$tdir/$tfile
2413 local fid=$(copy_file /etc/passwd $f)
2415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2416 wait_request_state $fid ARCHIVE SUCCEED
2418 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2419 set_hsm_param remove_archive_on_last_unlink 1
2422 cdt_check_state stopped
2426 wait_request_state $fid REMOVE WAITING
2430 # copytool must re-register
2432 wait_copytools || error "copytool failed to stop"
2435 wait_request_state $fid REMOVE SUCCEED
2437 run_test 26b "RAoLU policy when CDT off"
2440 # test needs a running copytool
2444 local f=$DIR/$tdir/$tfile
2445 local fid=$(copy_file /etc/passwd $f)
2447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2448 wait_request_state $fid ARCHIVE SUCCEED
2450 local f2=$DIR/$tdir/${tfile}_2
2451 local fid2=$(copy_file /etc/passwd $f2)
2453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2454 wait_request_state $fid2 ARCHIVE SUCCEED
2456 # set a long grace_delay vs short loop_period
2457 local orig_loop_period=$(get_hsm_param loop_period)
2458 local orig_grace_delay=$(get_hsm_param grace_delay)
2459 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2460 set_hsm_param loop_period 10
2461 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2462 set_hsm_param grace_delay 100
2464 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2465 set_hsm_param remove_archive_on_last_unlink 1
2467 multiop_bg_pause $f O_c || error "open $f failed"
2473 wait_request_state $fid2 REMOVE SUCCEED
2474 assert_request_count $fid REMOVE 0 \
2475 "Unexpected archived data remove request for $f"
2477 kill -USR1 $pid || error "multiop early exit"
2478 # should reach autotest timeout if multiop fails to trap
2479 # signal, close file, and exit ...
2480 wait $pid || error "wait PID $PID failed"
2482 wait_request_state $fid REMOVE SUCCEED
2484 run_test 26c "RAoLU effective when file closed"
2487 # test needs a running copytool
2491 local f=$DIR/$tdir/$tfile
2492 local fid=$(create_small_file $f)
2494 $LFS hsm_archive $f || error "could not archive file"
2495 wait_request_state $fid ARCHIVE SUCCEED
2497 # set a long grace_delay vs short loop_period
2498 local orig_loop_period=$(get_hsm_param loop_period)
2499 local orig_grace_delay=$(get_hsm_param grace_delay)
2500 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2501 set_hsm_param loop_period 10
2502 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2503 set_hsm_param grace_delay 100
2505 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2506 set_hsm_param remove_archive_on_last_unlink 1
2508 multiop_bg_pause $f O_c || error "multiop failed"
2515 wait_request_state $fid REMOVE SUCCEED
2517 client_up || client_up || true
2519 kill -USR1 $MULTIPID
2520 wait $MULTIPID || error "multiop close failed"
2522 run_test 26d "RAoLU when Client eviction"
2525 # test needs a running copytool
2528 create_archive_file $tdir/$tfile
2529 local f=$DIR/$tdir/$tfile
2530 copytool import $tdir/$tfile $f
2531 local fid=$(path2fid $f)
2535 [[ $? != 0 ]] || error "Remove of a released file should fail"
2537 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2540 # test needs a running copytool
2543 local f=$DIR/$tdir/$tfile
2544 local fid=$(create_empty_file "$f")
2546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2547 wait_request_state $fid ARCHIVE SUCCEED
2552 [[ $? != 0 ]] || error "Remove of a released file should fail"
2554 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2557 # test needs a running copytool
2560 local f=$DIR/$tdir/$tfile
2561 local fid=$(create_empty_file "$f")
2563 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2564 wait_request_state $fid ARCHIVE SUCCEED
2573 wait_request_state $fid REMOVE SUCCEED
2575 run_test 28 "Concurrent archive/file remove"
2578 # Tests --mntpath and --archive options
2581 copytool setup -m "$MOUNT" -a $archive_id
2583 # Bad archive number
2584 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2585 grep "Invalid argument" ||
2586 error "unexpected hsm_remove failure (1)"
2588 # mntpath is present but file is given
2589 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2590 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2591 error "unexpected hsm_remove failure (2)"
2593 run_test 29a "Tests --mntpath and --archive options"
2596 # test needs a running copytool
2599 local f=$DIR/$tdir/$tfile
2600 local fid=$(create_small_file $f)
2602 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2603 wait_request_state $fid ARCHIVE SUCCEED
2607 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2608 wait_request_state $fid REMOVE SUCCEED
2610 run_test 29b "Archive/delete/remove by FID from the archive."
2613 # test needs a running copytool
2616 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2617 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2618 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2620 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2621 wait_request_state $fid1 ARCHIVE SUCCEED
2622 wait_request_state $fid2 ARCHIVE SUCCEED
2623 wait_request_state $fid3 ARCHIVE SUCCEED
2625 rm -f $DIR/$tdir/$tfile-[1-3]
2627 echo $fid1 > $DIR/$tdir/list
2628 echo $fid2 >> $DIR/$tdir/list
2629 echo $fid3 >> $DIR/$tdir/list
2631 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2632 --filelist $DIR/$tdir/list
2633 wait_request_state $fid1 REMOVE SUCCEED
2634 wait_request_state $fid2 REMOVE SUCCEED
2635 wait_request_state $fid3 REMOVE SUCCEED
2637 run_test 29c "Archive/delete/remove by FID, using a file list."
2640 # test needs more than one CT
2641 needclients 3 || return 0
2647 # start all of the copytools
2648 for n in $(seq $AGTCOUNT); do
2649 copytool setup -f agt$n -a $n
2653 file=$DIR/$tdir/$tfile
2654 fid=$(create_small_file $file)
2656 $LFS hsm_archive $file
2657 wait_request_state $fid ARCHIVE SUCCEED
2658 check_hsm_flags $file "0x00000009"
2662 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2663 error "cannot hsm_remove '$fid'"
2665 # give time for CDT to handle remove request and create broadcasted
2668 # remove request has been broadcasted ?
2669 local cnt=$(get_request_count $fid REMOVE)
2670 # broadcasted requests + original
2671 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2672 error "remove not broadcasted to all CTs"
2674 # give time for CDT and CTs to handle broadcasted
2675 wait_for_loop_period
2677 # each agent serves one different archive_id, so broadcasted
2678 # hsm_remove request should only succeed once and fail at all others
2682 for n in $(seq $AGTCOUNT); do
2683 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2684 $HSM_PARAM.actions | awk \
2685 '/'$fid'.*action=REMOVE archive#='$n'/ \
2686 {print \\\$13}' | cut -f2 -d=")
2687 if [[ "$res" == "SUCCEED" ]]; then
2689 elif [[ "$res" == "FAILED" ]]; then
2694 [[ $scnt -eq 1 ]] ||
2695 error "one and only CT should have removed successfully"
2697 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2698 error "all but one CT should have failed to remove"
2700 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2701 "request to be sent once for each registered archive_id"
2704 # restore at exec cannot work on agent node (because of Linux kernel
2705 # protection of executables)
2706 needclients 2 || return 0
2708 # test needs a running copytool
2712 copy2archive /bin/true $tdir/$tfile
2714 local f=$DIR/$tdir/true
2715 copytool import $tdir/$tfile $f
2717 local fid=$(path2fid $f)
2719 stack_trap "cdt_clear_no_retry" EXIT
2720 # set no retry action mode
2727 [[ $st == 0 ]] || error "Failed to exec a released file"
2729 run_test 30a "Restore at exec (import case)"
2732 # restore at exec cannot work on agent node (because of Linux kernel
2733 # protection of executables)
2734 needclients 2 || return 0
2736 # test needs a running copytool
2740 local f=$DIR/$tdir/true
2741 local fid=$(copy_file /bin/true $f)
2743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2744 wait_request_state $fid ARCHIVE SUCCEED
2748 stack_trap cdt_clear_no_retry EXIT
2749 # set no retry action mode
2757 [[ $st == 0 ]] || error "Failed to exec a released file"
2759 run_test 30b "Restore at exec (release case)"
2762 needclients 2 || return 0
2764 # test needs a running copytool
2768 local f=$DIR/$tdir/SLEEP
2769 local slp_sum1=$(md5sum /bin/sleep)
2770 local fid=$(copy_file /bin/sleep $f)
2772 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2773 wait_request_state $fid ARCHIVE SUCCEED
2775 check_hsm_flags $f "0x0000000d"
2777 stack_trap cdt_clear_no_retry EXIT
2778 # set no retry action mode
2781 do_node $CLIENT2 "$f 10" &
2785 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2787 [[ $? == 0 ]] || error "Execution failed during run"
2789 if [[ $? != 0 ]]; then
2790 local slp_sum2=$(md5sum /bin/sleep)
2791 # in case sleep file is modified during the test
2792 [[ $slp_sum1 == $slp_sum2 ]] &&
2793 error "Binary overwritten during exec"
2796 check_hsm_flags $f "0x00000009"
2798 run_test 30c "Update during exec of released file must fail"
2800 restore_and_check_size() {
2803 local s=$(stat -c "%s" $f)
2805 local st=$(get_hsm_flags $f)
2809 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2811 n=$(stat -c "%s" $f)
2812 # we echo in both cases to show stat is not hang
2813 if [[ $n != $s ]]; then
2814 echo "size seen is $n != $s"
2817 echo "size seen is right: $n == $s"
2821 st=$(get_hsm_flags $f)
2823 if [[ "$st" = "0x00000009" ]]; then
2826 echo " restore is too long"
2827 wait_request_state $fid RESTORE SUCCEED
2833 # test needs a running copytool
2836 create_archive_file $tdir/$tfile
2837 local f=$DIR/$tdir/$tfile
2838 copytool import $tdir/$tfile $f
2839 local fid=$($LFS path2fid $f)
2842 restore_and_check_size $f $fid
2845 [[ $err -eq 0 ]] || error "File size changed during restore"
2847 run_test 31a "Import a large file and check size during restore"
2851 # test needs a running copytool
2854 local f=$DIR/$tdir/$tfile
2855 local fid=$(create_file "$f" 1MB 39)
2857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2858 wait_request_state $fid ARCHIVE SUCCEED
2861 restore_and_check_size $f $fid
2864 [[ $err -eq 0 ]] || error "File size changed during restore"
2866 run_test 31b "Restore a large unaligned file and check size during restore"
2869 # test needs a running copytool
2872 local f=$DIR/$tdir/$tfile
2873 local fid=$(create_file "$f" 1M 39)
2875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2876 wait_request_state $fid ARCHIVE SUCCEED
2879 restore_and_check_size $f $fid
2882 [[ $err -eq 0 ]] || error "File size changed during restore"
2884 run_test 31c "Restore a large aligned file and check size during restore"
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(create_empty_file "$f")
2892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2893 wait_request_state $fid ARCHIVE SUCCEED
2896 # Prevent restore from completing
2900 md5sum $f >/dev/null &
2903 wait_request_state $fid RESTORE STARTED
2908 # Check restore trigger process was killed
2910 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2912 run_test 33 "Kill a restore waiting process"
2915 # test needs a running copytool
2918 local f=$DIR/$tdir/$tfile
2919 local fid=$(create_empty_file "$f")
2921 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2922 wait_request_state $fid ARCHIVE SUCCEED
2925 # Prevent restore from completing
2928 md5sum $f >/dev/null &
2931 wait_request_state $fid RESTORE STARTED
2933 # rm must not block during restore
2934 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2937 wait_request_state $fid RESTORE SUCCEED
2939 # Check md5sum pgm finished
2940 kill -0 $pid && error "Restore initiatior still running"
2941 wait $pid || error "Restore initiator failed with $?"
2943 # Check the file was actually deleted
2944 [ ! -f "$f" ] || error "$f was not deleted"
2946 run_test 34 "Remove file during restore"
2949 # test needs a running copytool
2952 local f=$DIR/$tdir/$tfile
2953 local f1=$DIR/$tdir/$tfile-1
2954 local fid=$(create_empty_file "$f")
2955 local fid1=$(copy_file /etc/passwd $f1)
2957 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2958 wait_request_state $fid ARCHIVE SUCCEED
2961 # Prevent restore from completing
2964 md5sum $f >/dev/null &
2967 wait_request_state $fid RESTORE STARTED
2969 # mv must not block during restore
2970 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2973 wait_request_state $fid RESTORE SUCCEED
2975 # Check md5sum pgm finished
2976 kill -0 $pid && error "Restore initiatior still running"
2977 wait $pid || error "Restore initiator failed with $?"
2979 local fid2=$(path2fid $f)
2980 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2982 run_test 35 "Overwrite file during restore"
2985 # test needs a running copytool
2988 local f=$DIR/$tdir/$tfile
2989 local fid=$(create_empty_file "$f")
2991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2992 wait_request_state $fid ARCHIVE SUCCEED
2995 # Prevent restore from completing
2998 md5sum $f >/dev/null &
3001 wait_request_state $fid RESTORE STARTED
3003 # mv must not block during restore
3004 timeout --signal=KILL 10 mv "$f" "$f.new" ||
3005 error "mv '$f' '$f.new' failed with rc=$?"
3008 wait_request_state $fid RESTORE SUCCEED
3010 # Check md5sum pgm finished
3011 kill -0 $pid && error "Restore initiator is still running"
3012 wait $pid || error "Restore initiator failed with $?"
3014 run_test 36 "Move file during restore"
3017 # LU-5683: check that an archived dirty file can be rearchived.
3020 local f=$DIR/$tdir/$tfile
3023 fid=$(create_small_file $f) || error "cannot create small file"
3025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3026 wait_request_state $fid ARCHIVE SUCCEED
3027 $LFS hsm_release $f || error "cannot release $f"
3029 # Allow previous archive request to expire from the actions log.
3030 wait_for_grace_delay
3033 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3036 wait_request_state $fid ARCHIVE SUCCEED
3038 run_test 37 "re-archive a dirty file"
3045 for n in $(seq 1 $count); do
3046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3048 echo "$count archive requests submitted"
3052 local stream_count=4
3053 local file_count=100
3055 local f=$DIR/$tdir/$tfile
3059 local max_requests=$(get_hsm_param max_requests)
3061 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3062 # Increase the number of HSM request that can be performed in
3063 # parallel. With the coordinator running once per second, this
3064 # also limits the number of requests per seconds that can be
3065 # performed, so we pick a decent number. But we also need to keep
3066 # that number low because the copytool has no rate limit and will
3067 # fail some requests if if gets too many at once.
3068 set_hsm_param max_requests 300
3070 for i in $(seq 1 $file_count); do
3071 for p in $(seq 1 $stream_count); do
3072 fid=$(copy_file /etc/hosts $f.$p.$i)
3078 # to be sure wait_all_done will not be mislead by previous tests
3080 wait_for_grace_delay
3082 # start archive streams in background (archive files in parallel)
3083 for p in $(seq 1 $stream_count); do
3084 multi_archive $f.$p $file_count &
3087 echo -n "Wait for all requests being enqueued..."
3092 run_test 40 "Parallel archive requests"
3095 # test needs a running copytool
3099 local f=$DIR/$tdir/$tfile
3100 local fid=$(create_small_file $f)
3102 $LFS hsm_archive $f || error "could not archive file"
3103 wait_request_state $fid ARCHIVE SUCCEED
3104 check_hsm_flags $f "0x00000009"
3106 multiop_bg_pause $f O_c || error "multiop failed"
3110 client_up || client_up || true
3112 kill -USR1 $MULTIPID
3113 wait $MULTIPID || error "multiop close failed"
3115 check_hsm_flags $f "0x0000000b"
3117 run_test 52 "Opened for write file on an evicted client should be set dirty"
3120 # test needs a running copytool
3124 local f=$DIR/$tdir/$tfile
3125 local fid=$(create_small_file $f)
3127 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3128 error "could not archive file"
3129 wait_request_state $fid ARCHIVE SUCCEED
3130 check_hsm_flags $f "0x00000009"
3132 multiop_bg_pause $f o_c || error "multiop failed"
3136 client_up || client_up || true
3138 kill -USR1 $MULTIPID
3139 wait $MULTIPID || error "multiop close failed"
3141 check_hsm_flags $f "0x00000009"
3143 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3146 local f=$DIR/$tdir/$tfile
3147 local fid=$(create_file "$f" 1MB 39)
3151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3152 error "could not archive file"
3153 wait_request_state $fid ARCHIVE STARTED
3155 check_hsm_flags $f "0x00000001"
3157 stack_trap "cdt_clear_no_retry" EXIT
3158 # Avoid coordinator resending this request as soon it has failed.
3163 wait_request_state $fid ARCHIVE FAILED
3165 check_hsm_flags $f "0x00000003"
3167 run_test 54 "Write during an archive cancels it"
3170 local f=$DIR/$tdir/$tfile
3171 local fid=$(create_file "$f" 1MB 39)
3175 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3176 error "could not archive file"
3177 wait_request_state $fid ARCHIVE STARTED
3179 check_hsm_flags $f "0x00000001"
3181 stack_trap "cdt_clear_no_retry" EXIT
3182 # Avoid coordinator resending this request as soon it has failed.
3185 $TRUNCATE $f 1024 || error "truncate failed"
3187 wait_request_state $fid ARCHIVE FAILED
3189 check_hsm_flags $f "0x00000003"
3191 run_test 55 "Truncate during an archive cancels it"
3194 local f=$DIR/$tdir/$tfile
3195 local fid=$(create_file "$f" 1MB 39)
3199 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3200 error "could not archive file"
3201 wait_request_state $fid ARCHIVE STARTED
3203 check_hsm_flags $f "0x00000001"
3205 # Change metadata and sync to be sure we are not changing only
3210 wait_request_state $fid ARCHIVE SUCCEED
3212 check_hsm_flags $f "0x00000009"
3214 run_test 56 "Setattr during an archive is ok"
3217 # Need one client for I/O, one for request
3218 needclients 2 || return 0
3220 # test needs a running copytool
3224 local f=$DIR/$tdir/test_archive_remote
3225 # Create a file on a remote node
3226 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3227 "count=2 conv=fsync"
3230 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3231 error "hsm_archive failed"
3232 local fid=$(path2fid $f)
3233 wait_request_state $fid ARCHIVE SUCCEED
3235 # Release and implicit restore it
3236 do_node $CLIENT2 "$LFS hsm_release $f" ||
3237 error "hsm_release failed"
3238 do_node $CLIENT2 "md5sum $f" ||
3239 error "hsm_restore failed"
3241 wait_request_state $fid RESTORE SUCCEED
3243 run_test 57 "Archive a file with dirty cache on another node"
3245 truncate_released_file() {
3249 local sz=$(stat -c %s $src_file)
3250 local f=$DIR/$tdir/$tfile
3251 local fid=$(copy_file $1 $f)
3255 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3256 error "could not archive file"
3257 wait_request_state $fid ARCHIVE SUCCEED
3259 $LFS hsm_release $f || error "could not release file"
3261 $TRUNCATE $f $trunc_to || error "truncate failed"
3264 local sz1=$(stat -c %s $f)
3265 [[ $sz1 == $trunc_to ]] ||
3266 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3269 check_hsm_flags $f "0x0000000b"
3271 local state=$(get_request_state $fid RESTORE)
3272 [[ "$state" == "SUCCEED" ]] ||
3273 error "truncate $sz does not trig restore, state = $state"
3275 $TRUNCATE $ref $trunc_to
3276 cmp $ref $f || error "file data wrong after truncate"
3282 # test needs a running copytool
3287 local sz=$(stat -c %s /etc/passwd)
3289 echo "truncate up from $sz to $((sz*2))"
3290 truncate_released_file /etc/passwd $((sz*2))
3292 echo "truncate down from $sz to $((sz/2))"
3293 truncate_released_file /etc/passwd $((sz/2))
3295 echo "truncate to 0"
3296 truncate_released_file /etc/passwd 0
3298 run_test 58 "Truncate a released file will trigger restore"
3302 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3303 skip "Need MDS version at least 2.7.63"
3306 $MCREATE $DIR/$tfile || error "mcreate failed"
3307 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3308 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3309 fid=$(path2fid $DIR/$tfile)
3310 wait_request_state $fid ARCHIVE SUCCEED
3311 $LFS hsm_release $DIR/$tfile || error "release failed"
3313 run_test 59 "Release stripeless file with non-zero size"
3316 # This test validates the fix for LU-4512. Ensure that the -u
3317 # option changes the progress reporting interval from the
3318 # default (30 seconds) to the user-specified interval.
3319 local f=$DIR/$tdir/$tfile
3320 local fid=$(create_file "$f" 1M 10)
3323 local progress_timeout=$((interval * 4))
3324 copytool setup -b 1 --update-interval $interval
3327 local mdt=${MDT_PREFIX}${mdtidx}
3328 local mds=mds$((mdtidx + 1))
3330 # Wait for copytool to register
3331 wait_update_facet $mds \
3332 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3333 uuid 100 || error "coyptool failed to register with $mdt"
3335 local start_at=$(date +%s)
3336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3337 error "could not archive file"
3339 local agent=$(facet_active_host $SINGLEAGT)
3340 local logfile=$(copytool_logfile $SINGLEAGT)
3342 wait_update $agent \
3343 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3344 error "copytool failed to start"
3346 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3347 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3353 echo -n "Expecting a progress update within $progress_timeout seconds... "
3355 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3356 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3357 echo "$RESULT bytes copied in $WAIT seconds."
3359 elif [ $WAIT -ge $progress_timeout ]; then
3360 error "Timed out waiting for progress update!"
3363 WAIT=$((WAIT + sleep))
3367 local finish_at=$(date +%s)
3368 local elapsed=$((finish_at - start_at))
3370 # Ensure that the progress update occurred within the expected window.
3371 if [ $elapsed -lt $((interval - 1)) ]; then
3372 error "Expected progress update after at least $interval seconds"
3375 echo "Wait for on going archive hsm action to complete"
3376 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3377 echo "File archiving not completed even after 10 secs"
3379 run_test 60 "Changing progress update interval from default"
3382 # test needs a running copytool
3386 local f=$DIR/$tdir/$tfile
3387 local fid=$(copy_file /etc/passwd $f)
3389 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3392 wait_request_state $fid ARCHIVE FAILED
3394 run_test 61 "Waiting archive of a removed file should fail"
3397 # test needs a new running copytool
3398 stack_trap copytool_monitor_cleanup EXIT
3399 copytool_monitor_setup
3400 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3402 # Wait for the copytool to register.
3403 wait_update --verbose $(facet_active_host mds1) \
3404 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3406 error "copytool failed to register with MDT0000"
3409 wait_copytools || error "Copytools failed to stop"
3411 local REGISTER_EVENT
3412 local UNREGISTER_EVENT
3413 while read event; do
3414 local parsed=$(parse_json_event "$event")
3415 if [ -z "$parsed" ]; then
3416 error "Copytool sent malformed event: $event"
3420 if [ $event_type == "REGISTER" ]; then
3421 REGISTER_EVENT=$event
3422 elif [ $event_type == "UNREGISTER" ]; then
3423 UNREGISTER_EVENT=$event
3425 done < <(echo $"$(get_copytool_event_log)")
3427 if [ -z "$REGISTER_EVENT" ]; then
3428 error "Copytool failed to send register event to FIFO"
3431 if [ -z "$UNREGISTER_EVENT" ]; then
3432 error "Copytool failed to send unregister event to FIFO"
3435 echo "Register/Unregister events look OK."
3437 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3440 # Bump progress interval for livelier events.
3443 # test needs a new running copytool
3444 stack_trap copytool_monitor_cleanup EXIT
3445 copytool_monitor_setup
3446 copytool setup --update-interval $interval --event-fifo \
3447 "$HSMTOOL_MONITOR_DIR/fifo"
3449 stack_trap "cdt_clear_no_retry" EXIT
3450 # Just start and stop the copytool to generate events.
3453 local f=$DIR/$tdir/$tfile
3454 local fid=$(create_small_file "$f")
3456 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3457 error "could not archive file"
3458 wait_request_state $fid ARCHIVE SUCCEED
3460 local expected_fields="event_time data_fid source_fid"
3461 expected_fields+=" total_bytes current_bytes"
3464 [ARCHIVE_START]=false
3465 [ARCHIVE_FINISH]=false
3466 [ARCHIVE_RUNNING]=false
3468 while read event; do
3469 # Make sure we're not getting anything from previous events.
3470 for field in $expected_fields; do
3474 local parsed=$(parse_json_event "$event")
3475 if [ -z "$parsed" ]; then
3476 error "Copytool sent malformed event: $event"
3480 events["$event_type"]=true
3482 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3484 # Do some simple checking of the progress update events.
3485 for expected_field in $expected_fields; do
3486 if [ -z ${!expected_field+x} ]; then
3487 error "Missing $expected_field field in event"
3491 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3493 # These should be identical throughout an archive operation
3494 [ $source_fid == $data_fid ] ||
3495 error "Expected source_fid to equal data_fid"
3496 done < <(echo $"$(get_copytool_event_log)")
3498 # Check we received every type of events we were expecting
3499 for event in "${!events[@]}"; do
3500 ${events["$event"]} ||
3501 error "Copytool failed to send '$event' event to FIFO"
3504 echo "Archive events look OK."
3506 run_test 71 "Copytool logs JSON archive events to FIFO"
3509 # Bump progress interval for livelier events.
3512 # test needs a new running copytool
3513 stack_trap copytool_monitor_cleanup EXIT
3514 copytool_monitor_setup
3515 copytool setup --update-interval $interval --event-fifo \
3516 "$HSMTOOL_MONITOR_DIR/fifo"
3517 local test_file=$HSMTOOL_MONITOR_DIR/file
3519 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3521 do_facet $SINGLEAGT "$cmd" ||
3522 error "cannot create $test_file on $SINGLEAGT"
3523 copy2archive $test_file $tdir/$tfile
3526 local f=$DIR/$tdir/$tfile
3527 copytool import $tdir/$tfile $f
3528 f=$DIR2/$tdir/$tfile
3529 echo "Verifying released state: "
3530 check_hsm_flags $f "0x0000000d"
3532 local fid=$(path2fid $f)
3534 wait_request_state $fid RESTORE SUCCEED
3536 local expected_fields="event_time data_fid source_fid"
3537 expected_fields+=" total_bytes current_bytes"
3541 while read event; do
3542 # Make sure we're not getting anything from previous events.
3543 for field in $expected_fields; do
3547 local parsed=$(parse_json_event "$event")
3548 if [ -z "$parsed" ]; then
3549 error "Copytool sent malformed event: $event"
3553 if [ $event_type == "RESTORE_START" ]; then
3555 if [ $source_fid != $data_fid ]; then
3556 error "source_fid should == data_fid at start"
3559 elif [ $event_type == "RESTORE_FINISH" ]; then
3561 if [ $source_fid != $data_fid ]; then
3562 error "source_fid should == data_fid at finish"
3565 elif [ $event_type != "RESTORE_RUNNING" ]; then
3569 # Do some simple checking of the progress update events.
3570 for expected_field in $expected_fields; do
3571 if [ -z ${!expected_field+x} ]; then
3572 error "Missing $expected_field field in event"
3576 if [ $total_bytes -eq 0 ]; then
3577 error "Expected total_bytes to be > 0"
3580 # When a restore starts out, the data fid is the same as the
3581 # source fid. After the restore has gotten going, we learn
3582 # the new data fid. Once the restore has finished, the source
3583 # fid is set to the new data fid.
3585 # We test this because some monitoring software may depend on
3586 # this behavior. If it changes, then the consumers of these
3587 # events may need to be modified.
3588 if [ $source_fid == $data_fid ]; then
3589 error "source_fid should != data_fid during restore"
3591 done < <(echo $"$(get_copytool_event_log)")
3593 if [ -z "$START_EVENT" ]; then
3594 error "Copytool failed to send restore start event to FIFO"
3597 if [ -z "$FINISH_EVENT" ]; then
3598 error "Copytool failed to send restore finish event to FIFO"
3601 echo "Restore events look OK."
3603 run_test 72 "Copytool logs JSON restore events to FIFO"
3606 file_count=51 # Max number of files constrained by LNET message size
3607 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3608 local f=$DIR/$tdir/$tfile
3609 local FILELIST=/tmp/filelist.txt
3613 for i in $(seq 1 $file_count); do
3614 fid=$(copy_file /etc/hosts $f.$i)
3615 echo $f.$i >> $FILELIST
3619 # to be sure wait_all_done will not be mislead by previous tests
3621 wait_for_grace_delay
3622 $LFS hsm_archive --filelist $FILELIST ||
3623 error "cannot archive a file list"
3625 $LFS hsm_release --filelist $FILELIST ||
3626 error "cannot release a file list"
3627 $LFS hsm_restore --filelist $FILELIST ||
3628 error "cannot restore a file list"
3631 run_test 90 "Archive/restore a file list"
3633 double_verify_reset_hsm_param() {
3635 echo "Testing $HSM_PARAM.$p"
3636 local val=$(get_hsm_param $p)
3638 local val2=$(($val * 2))
3639 set_hsm_param $p $val2
3640 val=$(get_hsm_param $p)
3641 [[ $val == $val2 ]] ||
3642 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3643 echo "Set $p to 0 must failed"
3647 set_hsm_param $p $save
3649 if [[ $rc == 0 ]]; then
3650 error "we must not be able to set $HSM_PARAM.$p to 0"
3655 double_verify_reset_hsm_param loop_period
3656 double_verify_reset_hsm_param grace_delay
3657 double_verify_reset_hsm_param active_request_timeout
3658 double_verify_reset_hsm_param max_requests
3659 double_verify_reset_hsm_param default_archive_id
3661 run_test 100 "Set coordinator /proc tunables"
3668 run_test 102 "Verify coordinator control"
3671 # test needs a running copytool
3678 for i in $(seq 1 20); do
3679 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3681 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3685 echo "Current requests"
3686 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3687 $HSM_PARAM.actions |\
3688 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3690 [[ -z "$res" ]] || error "Some request have not been canceled"
3692 run_test 103 "Purge all requests"
3697 local f=$DIR/$tdir/$tfile
3698 local fid=$(create_empty_file "$f")
3700 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3701 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3702 $HSM_PARAM.actions |\
3703 grep $fid | cut -f16 -d=")
3705 [[ "$data1" == "$DATAHEX" ]] ||
3706 error "Data field in records is ($data1) and not ($DATAHEX)"
3710 run_test 104 "Copy tool data field"
3713 local max_requests=$(get_hsm_param max_requests)
3717 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3718 set_hsm_param max_requests 300
3721 for i in $(seq -w 1 10); do
3722 cp /etc/passwd $DIR/$tdir/$i
3723 $LFS hsm_archive $DIR/$tdir/$i
3725 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3726 $HSM_PARAM.actions |\
3727 grep WAITING | wc -l")
3731 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3732 $HSM_PARAM.actions |\
3733 grep WAITING | wc -l")
3736 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3737 error "Requests count after shutdown $reqcnt2 != "\
3738 "before shutdown $reqcnt1"
3740 run_test 105 "Restart of coordinator"
3743 # test needs a running copytool
3746 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3748 check_agent_registered $uuid
3750 search_copytools || error "No copytool found"
3753 wait_copytools || error "Copytool failed to stop"
3755 check_agent_unregistered $uuid
3758 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3759 check_agent_registered $uuid
3761 run_test 106 "Copytool register/unregister"
3764 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3766 # test needs a running copytool
3768 # create and archive file
3770 local f1=$DIR/$tdir/$tfile
3771 local fid=$(copy_file /etc/passwd $f1)
3772 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3773 wait_request_state $fid ARCHIVE SUCCEED
3774 # shutdown and restart MDS
3776 # check the copytool still gets messages from MDT
3777 local f2=$DIR/$tdir/2
3778 local fid=$(copy_file /etc/passwd $f2)
3779 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3780 # main check of this sanity: this request MUST succeed
3781 wait_request_state $fid ARCHIVE SUCCEED
3783 run_test 107 "Copytool re-register after MDS restart"
3785 policy_set_and_test()
3789 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3790 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3791 [[ "$policy" == "$target" ]] ||
3792 error "Wrong policy after '$change': '$policy' != '$target'"
3796 # to force default policy setting if error
3797 CDT_POLICY_HAD_CHANGED=true
3799 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3800 local default="NonBlockingRestore [NoRetryAction]"
3801 [[ "$policy" == "$default" ]] ||
3802 error "default policy has changed,"\
3803 " '$policy' != '$default' update the test"
3804 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3805 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3806 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3807 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3808 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3809 # useless bacause we know but safer for futur changes to use real value
3810 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3811 echo "Next set_param must failed"
3812 policy_set_and_test "wrong" "$policy"
3815 echo "Back to default policy"
3816 cdt_set_sanity_policy
3818 run_test 109 "Policy display/change"
3821 # test needs a running copytool
3826 copy2archive /etc/passwd $tdir/$tfile
3828 local f=$DIR/$tdir/$tfile
3829 copytool import $tdir/$tfile $f
3830 local fid=$(path2fid $f)
3832 cdt_set_non_blocking_restore
3837 wait_request_state $fid RESTORE SUCCEED
3838 cdt_clear_non_blocking_restore
3842 error "md5sum returns $st != 1, "\
3843 "should also perror ENODATA (No data available)"
3845 run_test 110a "Non blocking restore policy (import case)"
3848 # test needs a running copytool
3852 local f=$DIR/$tdir/$tfile
3853 local fid=$(copy_file /etc/passwd $f)
3854 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3855 wait_request_state $fid ARCHIVE SUCCEED
3858 cdt_set_non_blocking_restore
3863 wait_request_state $fid RESTORE SUCCEED
3864 cdt_clear_non_blocking_restore
3868 error "md5sum returns $st != 1, "\
3869 "should also perror ENODATA (No data available)"
3871 run_test 110b "Non blocking restore policy (release case)"
3874 # test needs a running copytool
3878 copy2archive /etc/passwd $tdir/$tfile
3880 local f=$DIR/$tdir/$tfile
3882 copytool import $tdir/$tfile $f
3883 local fid=$(path2fid $f)
3887 copytool_remove_backend $fid
3890 wait_request_state $fid RESTORE FAILED
3897 [[ $st == 0 ]] || error "Restore does not failed"
3899 run_test 111a "No retry policy (import case), restore will error"\
3900 " (No such file or directory)"
3903 # test needs a running copytool
3907 local f=$DIR/$tdir/$tfile
3908 local fid=$(copy_file /etc/passwd $f)
3909 stack_trap cdt_clear_no_retry EXIT
3911 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3912 wait_request_state $fid ARCHIVE SUCCEED
3915 copytool_remove_backend $fid
3918 wait_request_state $fid RESTORE FAILED
3922 [[ $st == 0 ]] || error "Restore does not failed"
3924 run_test 111b "No retry policy (release case), restore will error"\
3925 " (No such file or directory)"
3928 # test needs a running copytool
3932 local f=$DIR/$tdir/$tfile
3933 local fid=$(copy_file /etc/passwd $f)
3935 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3936 local l=$($LFS hsm_action $f)
3938 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3941 wait_request_state $fid ARCHIVE SUCCEED
3944 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3946 run_test 112 "State of recorded request"
3949 local f=$DIR/$tdir/$tfile
3950 local fid=$(create_empty_file "$f")
3954 # Prevent archive from completing
3957 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3958 # wait archive to register at CDT
3959 wait_request_state $fid ARCHIVE STARTED
3961 # Cancel the archive
3962 $LFS hsm_cancel "$f"
3964 wait_request_state $fid ARCHIVE CANCELED
3967 wait_request_state $fid CANCEL SUCCEED
3969 run_test 200 "Register/Cancel archive"
3972 # test needs a running copytool
3975 local f=$DIR/$tdir/$tfile
3976 create_archive_file $tdir/$tfile
3977 copytool import $tdir/$tfile $f
3978 local fid=$(path2fid $f)
3980 # test with cdt on is made in test_222
3983 # wait restore to register at CDT
3984 wait_request_state $fid RESTORE WAITING
3987 wait_request_state $fid RESTORE CANCELED
3988 wait_request_state $fid CANCEL SUCCEED
3990 run_test 201 "Register/Cancel restore"
3993 local f=$DIR/$tdir/$tfile
3994 local fid=$(create_empty_file "$f")
3996 # test needs a running copytool
3999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4000 wait_request_state $fid ARCHIVE SUCCEED
4004 # wait remove to register at CDT
4005 wait_request_state $fid REMOVE STARTED
4008 wait_request_state $fid REMOVE CANCELED
4010 run_test 202 "Register/Cancel remove"
4012 test_220A() { # was test_220
4013 # test needs a running copytool
4018 local f=$DIR/$tdir/$tfile
4019 local fid=$(copy_file /etc/passwd $f)
4023 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4024 wait_request_state $fid ARCHIVE SUCCEED
4026 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4027 error "The expected changelog was not emitted"
4029 run_test 220A "Changelog for archive"
4032 # test needs a running copytool
4037 local f=$DIR/$tdir/$tfile
4038 local fid=$(copy_file /etc/passwd $f)
4042 # block copytool operations to allow for HSM request to be
4043 # submitted and file be unlinked (CDT will find object removed)
4046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4048 # wait request to reach CT
4049 wait_request_state $fid ARCHIVE STARTED
4055 wait_request_state $fid ARCHIVE FAILED
4058 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4059 error "The expected changelog was not emitted"
4061 run_test 220a "Changelog for failed archive"
4064 local f=$DIR/$tdir/$tfile
4065 local fid=$(create_empty_file "$f")
4070 # Prevent archive from completing
4072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4073 wait_request_state $fid ARCHIVE STARTED
4076 wait_request_state $fid ARCHIVE CANCELED
4079 wait_request_state $fid CANCEL SUCCEED
4081 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4082 error "The expected changelog was not emitted"
4084 run_test 221 "Changelog for archive canceled"
4087 # test needs a running copytool
4091 copy2archive /etc/passwd $tdir/$tfile
4093 local f=$DIR/$tdir/$tfile
4094 copytool import $tdir/$tfile $f
4095 local fid=$(path2fid $f)
4100 wait_request_state $fid RESTORE SUCCEED
4102 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4103 error "The expected changelog was not emitted"
4105 run_test 222a "Changelog for explicit restore"
4108 # test needs a running copytool
4112 local f=$DIR/$tdir/$tfile
4113 local fid=$(copy_file /etc/passwd $f)
4116 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4117 wait_request_state $fid ARCHIVE SUCCEED
4122 wait_request_state $fid RESTORE SUCCEED
4124 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4125 error "The expected changelog was not emitted"
4127 run_test 222b "Changelog for implicit restore"
4130 # test needs a running copytool
4134 copy2archive /etc/passwd $tdir/$tfile
4136 local f=$DIR/$tdir/$tfile
4137 copytool import $tdir/$tfile $f
4138 local fid=$(path2fid $f)
4142 # block copytool operations to allow for HSM request to be
4143 # submitted and file be unlinked (CDT will find object removed)
4148 # wait request to reach CT
4149 wait_request_state $fid RESTORE STARTED
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 222c "Changelog for failed explicit restore"
4164 # test needs a running copytool
4168 local f=$DIR/$tdir/$tfile
4169 local fid=$(copy_file /etc/passwd $f)
4172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4173 wait_request_state $fid ARCHIVE SUCCEED
4176 copytool_remove_backend $fid
4179 wait_request_state $fid RESTORE FAILED
4182 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4183 error "The expected changelog was not emitted"
4185 run_test 222d "Changelog for failed implicit restore"
4188 # test needs a running copytool
4191 local f=$DIR/$tdir/$tfile
4192 create_archive_file $tdir/$tfile
4196 copytool import $tdir/$tfile $f
4197 local fid=$(path2fid $f)
4200 wait_request_state $fid RESTORE STARTED
4202 wait_request_state $fid RESTORE CANCELED
4203 wait_request_state $fid CANCEL SUCCEED
4205 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4206 error "The expected changelog was not emitted"
4208 run_test 223a "Changelog for restore canceled (import case)"
4211 local f=$DIR/$tdir/$tfile
4212 local fid=$(create_empty_file "$f")
4217 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4218 wait_request_state $fid ARCHIVE SUCCEED
4221 # Prevent restore from completing
4224 wait_request_state $fid RESTORE STARTED
4227 wait_request_state $fid RESTORE CANCELED
4230 wait_request_state $fid CANCEL SUCCEED
4232 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4233 error "The expected changelog was not emitted"
4235 run_test 223b "Changelog for restore canceled (release case)"
4237 test_224A() { # was test_224
4238 # test needs a running copytool
4243 local f=$DIR/$tdir/$tfile
4244 local fid=$(copy_file /etc/passwd $f)
4247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4248 wait_request_state $fid ARCHIVE SUCCEED
4251 wait_request_state $fid REMOVE SUCCEED
4253 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4254 error "The expected changelog was not emitted"
4256 run_test 224A "Changelog for remove"
4259 # test needs a running copytool
4264 local f=$DIR/$tdir/$tfile
4265 local fid=$(copy_file /etc/passwd $f)
4268 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4269 wait_request_state $fid ARCHIVE SUCCEED
4271 copytool_remove_backend $fid
4273 # block copytool operations to allow for HSM request to be
4274 # submitted and file be unlinked (CDT will find object removed)
4279 # wait for request to reach CT
4280 wait_request_state $fid REMOVE STARTED
4286 wait_request_state $fid REMOVE FAILED
4288 # HE_REMOVE|ENOENT=0x202
4289 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4290 error "The expected changelog was not emitted"
4292 run_test 224a "Changelog for failed remove"
4295 # test is not usable because remove request is too fast
4296 # so it is always finished before cancel can be done ...
4297 echo "Test disabled"
4300 # test needs a running copytool
4303 local f=$DIR/$tdir/$tfile
4304 local fid=$(create_empty_file "$f")
4307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4308 wait_request_state $fid ARCHIVE SUCCEED
4310 # Prevent restore from completing
4315 wait_request_state $fid REMOVE CANCELED
4318 wait_request_state $fid CANCEL SUCCEED
4320 changelog_find -type HSM -target-fid $fid -flags 0x27d
4321 error "The expected changelog was not emitted"
4323 run_test 225 "Changelog for remove canceled"
4326 # test needs a running copytool
4331 local f1=$DIR/$tdir/$tfile-1
4332 local f2=$DIR/$tdir/$tfile-2
4333 local f3=$DIR/$tdir/$tfile-3
4334 local fid1=$(copy_file /etc/passwd $f1)
4335 local fid2=$(copy_file /etc/passwd $f2)
4336 copy_file /etc/passwd $f3
4339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4340 wait_request_state $fid1 ARCHIVE SUCCEED
4342 $LFS hsm_archive $f2
4343 wait_request_state $fid2 ARCHIVE SUCCEED
4345 rm $f1 || error "rm $f1 failed"
4348 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4349 error "The expected changelog was not emitted"
4351 mv $f3 $f2 || error "mv $f3 $f2 failed"
4353 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4354 error "The expected changelog was not emitted"
4356 run_test 226 "changelog for last rm/mv with exiting archive"
4358 # This is just a utility function to clarify what test_227 does
4363 "$LFS" "$action" --$flag "$file" ||
4364 error "Cannot ${action#hsm_} $flag on '$file'"
4366 # Only one changelog should be produced
4367 local entries="$(changelog_find -type HSM -target-fid $fid)"
4368 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4369 error "lfs $action --$flag '$file' produced more than one" \
4372 # Parse the last changelog record
4373 local entry="$(tail -n 1 <<< "$entries")"
4374 eval local -A changelog=$(changelog2array $entry)
4376 # Also check the flags match what is expected
4377 [[ ${changelog[flags]} == $target ]] ||
4378 error "Changelog flag is '${changelog[flags]}', not $target"
4382 local file="$DIR/$tdir/$tfile"
4383 local fid=$(create_empty_file "$file")
4388 for flag in norelease noarchive exists archived lost; do
4389 if [ "$flag" == lost ]; then
4390 # The flag "lost" only works on an archived file
4391 "$LFS" hsm_set --archived "$file"
4395 action="hsm_set" __test_227
4396 action="hsm_clear" __test_227
4399 run_test 227 "changelog when explicit setting of HSM flags"
4402 # test needs a running copytool
4405 local fid=$(create_small_sync_file $DIR/$tfile)
4406 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4407 wait_request_state $fid ARCHIVE SUCCEED
4409 $LFS hsm_release $DIR/$tfile
4410 check_hsm_flags $DIR/$tfile "0x0000000d"
4412 filefrag $DIR/$tfile | grep " 1 extent found" ||
4413 error "filefrag on released file must return only one extent"
4415 # only newer versions of cp detect sparse files by stat/FIEMAP
4417 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4418 error "copying $DIR/$tfile"
4419 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4421 $LFS hsm_release $DIR/$tfile
4422 check_hsm_flags $DIR/$tfile "0x0000000d"
4424 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4426 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4428 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4429 error "comparing untarred $DIR/$tfile"
4431 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4432 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4434 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4437 local file="$DIR/$tdir/$tfile"
4439 # set max_requests to allow one request of each type to be started (3)
4441 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4442 set_hsm_param max_requests 3
4445 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4446 set_hsm_param loop_period 1
4448 # send 1 requests of each kind twice
4451 for action in archive restore remove; do
4452 local filepath="$file"-to-$action
4453 local fid=$(create_empty_file "$filepath")
4454 local fid2=$(create_empty_file "$filepath".bis)
4456 if [ "$action" != archive ]; then
4457 "$LFS" hsm_archive "$filepath"
4458 wait_request_state $fid ARCHIVE SUCCEED
4459 "$LFS" hsm_archive "$filepath".bis
4460 wait_request_state $fid2 ARCHIVE SUCCEED
4462 if [ "$action" == restore ]; then
4463 "$LFS" hsm_release "$filepath"
4464 "$LFS" hsm_release "$filepath".bis
4468 # suspend the copytool to prevent requests from completing
4469 stack_trap "copytool_continue" EXIT
4472 # send `max_requests' requests (one of each kind)
4473 for action in archive restore remove; do
4474 filepath="$file"-to-$action
4475 "$LFS" hsm_${action} "$filepath"
4476 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4479 # send another batch of requests
4480 for action in archive restore remove; do
4481 "$LFS" hsm_${action} "$file-to-$action".bis
4483 # wait for `loop_period' seconds to make sure the coordinator has time
4484 # to register those, even though it should not
4487 # only the first batch of request should be started
4489 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4493 error "expected 3 STARTED requests, found $count"
4495 run_test 250 "Coordinator max request"
4498 local f=$DIR/$tdir/$tfile
4499 local fid=$(create_empty_file "$f")
4502 # to have a short test
4503 local old_to=$(get_hsm_param active_request_timeout)
4504 set_hsm_param active_request_timeout 1
4505 # to be sure the cdt will wake up frequently so
4506 # it will be able to cancel the "old" request
4507 local old_loop=$(get_hsm_param loop_period)
4508 set_hsm_param loop_period 1
4513 # Prevent archive from completing
4515 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4516 wait_request_state $fid ARCHIVE STARTED
4518 # Let the request timeout
4519 wait_request_state $fid ARCHIVE CANCELED
4521 set_hsm_param active_request_timeout $old_to
4522 set_hsm_param loop_period $old_loop
4524 run_test 251 "Coordinator request timeout"
4527 local f=$DIR/$tdir/$tfile
4528 local fid=$(create_empty_file "$f")
4530 # to have a short test
4531 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4532 set_hsm_param loop_period 1
4536 # Prevent archive from completing
4538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4539 wait_request_state $fid ARCHIVE STARTED
4542 stack_trap "set_hsm_param active_request_timeout \
4543 $(get_hsm_param active_request_timeout)" EXIT
4544 set_hsm_param active_request_timeout 1
4546 wait_request_state $fid ARCHIVE CANCELED
4549 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4553 # test needs a running copytool
4557 local f=$DIR/$tdir/$tfile
4559 dd if=/dev/zero of=$f bs=1MB count=10
4560 local fid=$(path2fid $f)
4562 $LFS hsm_archive $f || error "could not archive file"
4563 wait_request_state $fid ARCHIVE SUCCEED
4565 # clear locks to discard inode data
4566 cancel_lru_locks osc
4568 #define OBD_FAIL_MDC_MERGE 0x807
4569 $LCTL set_param fail_loc=0x807
4571 #expect error here, instead of release with wrong size
4574 if ((rc == 0)); then
4575 file_size=$(stat -c '%s' $f)
4576 if ((file_size != 10485760)); then
4577 error "Wrong file size after hsm_release"
4580 echo "could not release file"
4583 run_test 253 "Check for wrong file size after release"
4587 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4588 skip "need MDS version at least 2.10.56"
4590 # Check that the counters are initialized to 0
4592 for request_type in archive restore remove; do
4593 count="$(get_hsm_param ${request_type}_count)" ||
4594 error "Reading ${request_type}_count failed with $?"
4596 [ "$count" -eq 0 ] ||
4597 error "Expected ${request_type}_count to be " \
4601 run_test 254a "Request counters are initialized to zero"
4605 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4606 skip "need MDS version at least 2.10.56"
4608 # The number of request to launch (at least 32)
4609 local request_count=$((RANDOM % 32 + 32))
4610 printf "Will launch %i requests of each type\n" "$request_count"
4612 # Launch a copytool to process requests
4615 # Set hsm.max_requests to allow starting all requests at the same time
4617 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4618 set_hsm_param max_requests "$request_count"
4622 for request_type in archive restore remove; do
4623 printf "Checking %s requests\n" "${request_type}"
4624 # Suspend the copytool to give us time to read the proc files
4627 for ((i = 0; i < $request_count; i++)); do
4628 case $request_type in
4630 create_empty_file "$DIR/$tdir/$tfile-$i" \
4634 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4637 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4640 # Give the coordinator 10 seconds to start every request
4642 while get_hsm_param actions | grep -q WAITING; do
4645 [ $timeout -gt 0 ] ||
4646 error "${request_type^} requests took too " \
4650 count="$(get_hsm_param ${request_type}_count)"
4651 [ "$count" -eq "$request_count" ] ||
4652 error "Expected '$request_count' (!= '$count') " \
4653 "active $request_type requests"
4655 # Let the copytool process the requests
4657 # Give it 10 seconds maximum
4659 while get_hsm_param actions | grep -q STARTED; do
4662 [ $timeout -gt 0 ] ||
4663 error "${request_type^} requests took too " \
4667 count="$(get_hsm_param ${request_type}_count)"
4668 [ "$count" -eq 0 ] ||
4669 error "Expected 0 (!= '$count') " \
4670 "active $request_type requests"
4673 run_test 254b "Request counters are correctly incremented and decremented"
4677 local file="$DIR/$tdir/$tfile"
4678 local fid=$(create_empty_file "$file")
4680 # How do you make sure the coordinator has consumed any outstanding
4681 # event, without triggering an event yourself?
4683 # You wait for a request to disappear from the coordinator's llog.
4685 # Warning: the setup represents 90% of this test
4687 # Create and process an HSM request
4689 "$LFS" hsm_archive "$file"
4690 wait_request_state $fid ARCHIVE SUCCEED
4693 wait_copytools || error "failed to stop copytools"
4695 # Launch a new HSM request
4697 create_empty_file "$file"
4698 "$LFS" hsm_archive "$file"
4702 # Have the completed request be removed as soon as the cdt wakes up
4703 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4704 set_hsm_param grace_delay 1
4705 # (Hopefully, time on the MDS will behave nicely)
4706 do_facet $SINGLEMDS sleep 2 &
4708 # Increase `loop_period' as a mean to prevent the coordinator from
4709 # waking itself up to do some housekeeping.
4710 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4711 set_hsm_param loop_period 1000
4713 wait $! || error "waiting failed"
4715 wait_request_state $fid ARCHIVE ""
4716 # The coordinator will not wake up on its own for ~`loop_period' secs...
4718 # ... Unless a copytool registers. Now the real test begins
4720 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4722 run_test 255 "Copytool registration wakes the coordinator up"
4724 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4725 # break in the future because of that.
4728 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4729 skip "need MDS version 2.11.56 or later"
4731 local -a files=("$DIR/$tdir/$tfile".{0..15})
4734 for file in "${files[@]}"; do
4735 create_small_file "$file"
4738 # Set a few hsm parameters
4740 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4741 set_hsm_param loop_period 1
4743 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4744 set_hsm_param max_requests 3
4748 "$LFS" hsm_archive "${files[0]}"
4749 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4750 "$LFS" hsm_release "${files[0]}"
4754 wait_copytools || error "copytools failed to stop"
4756 # Send several archive requests
4757 for file in "${files[@]:1}"; do
4758 "$LFS" hsm_archive "$file"
4761 # Send one restore request
4762 "$LFS" hsm_restore "${files[0]}"
4767 # Wait for all the requests to complete
4768 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4769 for file in "${files[@]:1}"; do
4770 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4773 # Collect the actions in the order in which the copytool processed them
4775 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4776 "$(copytool_logfile "$SINGLEAGT")")
4779 printf '%s\n' "${actions[@]}"
4782 for action in "${actions[@]:0:3}"; do
4783 [ "$action" == RESTORE ] && return
4786 error "Too many ARCHIVE requests were run before the RESTORE request"
4788 run_test 260a "Restore request have priority over other requests"
4790 # This test is very much tied to the implementation of the current priorisation
4791 # mechanism in the coordinator. It might not make sense to keep it in the future
4794 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4795 skip "need MDS version 2.11.56 or later"
4797 local -a files=("$DIR/$tdir/$tfile".{0..15})
4800 for file in "${files[@]}"; do
4801 create_small_file "$file"
4804 # Set a few hsm parameters
4806 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4807 set_hsm_param loop_period 1
4809 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4810 set_hsm_param max_requests 3
4813 copytool setup --archive-id 2
4814 "$LFS" hsm_archive --archive 2 "${files[0]}"
4815 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4816 "$LFS" hsm_release "${files[0]}"
4820 wait_copytools || error "copytools failed to stop"
4822 # Send several archive requests
4823 for file in "${files[@]:1}"; do
4824 "$LFS" hsm_archive "$file"
4827 # Send one restore request
4828 "$LFS" hsm_restore "${files[0]}"
4832 copytool setup --archive-id 2
4834 # Wait for all the requests to complete
4835 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4836 for file in "${files[@]:1}"; do
4837 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4840 # Collect the actions in the order in which the copytool processed them
4842 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4843 "$(copytool_logfile "$SINGLEAGT")")
4846 printf '%s\n' "${actions[@]}"
4849 for action in "${actions[@]:0:3}"; do
4850 [ "$action" == RESTORE ] && return
4853 error "Too many ARCHIVE requests were run before the RESTORE request"
4855 run_test 260b "Restore request have priority over other requests"
4857 # This test is very much tied to the implementation of the current priorisation
4858 # mechanism in the coordinator. It might not make sense to keep it in the future
4861 local -a files=("$DIR/$tdir/$tfile".{0..15})
4864 for file in "${files[@]}"; do
4865 create_small_file "$file"
4868 # Set a few hsm parameters
4870 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4871 set_hsm_param loop_period 1000
4873 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4874 set_hsm_param max_requests 3
4877 copytool setup --archive-id 2
4878 "$LFS" hsm_archive --archive 2 "${files[0]}"
4879 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4880 "$LFS" hsm_release "${files[0]}"
4884 wait_copytools || error "copytools failed to stop"
4886 # Force the next coordinator run to do housekeeping
4890 "$LFS" hsm_archive "${files[1]}"
4894 copytool setup --archive-id 2
4896 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4897 # The coordinator just did a housekeeping run it won't do another one
4898 # for around `loop_period' seconds => requests will not be reordered
4899 # if it costs too much (ie. when the coordinator has to discard a whole
4902 # Send several archive requests
4903 for file in "${files[@]:2}"; do
4904 "$LFS" hsm_archive "$file"
4907 # Send one restore request
4908 "$LFS" hsm_restore "${files[0]}"
4910 # Wait for all the requests to complete
4911 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4912 for file in "${files[@]:2}"; do
4913 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4916 # Collect the actions in the order in which the copytool processed them
4918 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4919 "$(copytool_logfile "$SINGLEAGT")")
4922 printf '%s\n' "${actions[@]}"
4925 for action in "${actions[@]:0:3}"; do
4926 [ "$action" == RESTORE ] &&
4927 error "Restore requests should not be prioritised" \
4928 "unless the coordinator is doing housekeeping"
4932 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4935 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4937 # the only way to test ondisk conf is to restart MDS ...
4938 echo "Stop coordinator and remove coordinator state at mount"
4941 # clean on disk conf set by default
4942 cdt_clear_mount_state
4943 cdt_check_state stopped
4945 # check cdt still off after umount/remount
4947 cdt_check_state stopped
4949 echo "Set coordinator start at mount, and start coordinator"
4950 cdt_set_mount_state enabled
4953 cdt_check_state enabled
4955 # check cdt still on after umount/remount
4957 cdt_check_state enabled
4959 # we are back to original state (cdt started at mount)
4961 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4964 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4966 local ai=$(get_hsm_param default_archive_id)
4967 local new=$((ai + 1))
4969 set_hsm_param default_archive_id $new -P
4971 local res=$(get_hsm_param default_archive_id)
4974 set_hsm_param default_archive_id "" "-P -d"
4976 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4978 run_test 301 "HSM tunnable are persistent"
4981 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4983 local ai=$(get_hsm_param default_archive_id)
4984 local new=$((ai + 1))
4989 set_hsm_param default_archive_id $new -P
4992 for mdtno in $(seq 1 $MDSCOUNT); do
4997 cdt_check_state enabled
4999 local res=$(get_hsm_param default_archive_id)
5002 set_hsm_param default_archive_id "" "-P -d"
5004 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5006 run_test 302 "HSM tunnable are persistent when CDT is off"
5009 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5015 local dir_mdt0=$DIR/$tdir/mdt0
5016 local dir_mdt1=$DIR/$tdir/mdt1
5018 # create 1 dir per MDT
5019 stack_trap "rm -rf $dir_mdt0" EXIT
5020 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5021 stack_trap "rm -rf $dir_mdt1" EXIT
5022 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5024 # create 1 file in each MDT
5025 local fid1=$(create_small_file $dir_mdt0/$tfile)
5026 local fid2=$(create_small_file $dir_mdt1/$tfile)
5028 # check that hsm request on mdt0 is sent to the right MDS
5029 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5030 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5031 echo "archive successful on mdt0"
5033 # check that hsm request on mdt1 is sent to the right MDS
5034 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5035 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5036 echo "archive successful on mdt1"
5038 run_test 400 "Single request is sent to the right MDT"
5041 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5047 local dir_mdt0=$DIR/$tdir/mdt0
5048 local dir_mdt1=$DIR/$tdir/mdt1
5050 # create 1 dir per MDT
5051 stack_trap "rm -rf $dir_mdt0" EXIT
5052 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5053 stack_trap "rm -rf $dir_mdt1" EXIT
5054 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5056 # create 1 file in each MDT
5057 local fid1=$(create_small_file $dir_mdt0/$tfile)
5058 local fid2=$(create_small_file $dir_mdt1/$tfile)
5060 # check that compound requests are shunt to the rights MDTs
5061 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5062 error "lfs hsm_archive"
5063 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5064 echo "archive successful on mdt0"
5065 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5066 echo "archive successful on mdt1"
5068 run_test 401 "Compound requests split and sent to their respective MDTs"
5070 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5075 local node=$(facet_active_host $facet)
5077 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5078 awk '{print $4}'); do
5079 echo "$3 $mdc on $node"
5080 do_facet $facet "$LCTL --device $mdc $state" || return 1
5085 # deactivate all mdc on agent1
5086 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5088 copytool setup --no-fail
5090 check_agent_unregistered "uuid" # match any agent
5092 # no expected running copytool
5093 search_copytools $agent && error "Copytool start should have failed"
5096 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5098 run_test 402a "Copytool start fails if all MDTs are inactive"
5105 local f=$DIR/$tdir/$tfile
5106 touch $f || error "touch $f failed"
5107 local fid=$(path2fid $f)
5109 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5110 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5113 # give time for CDT to send request and to keep it for retry
5114 wait_for_loop_period
5116 wait_request_state $fid ARCHIVE WAITING
5118 do_facet $SINGLEAGT lctl set_param fail_loc=0
5120 # request should succeed now
5121 wait_request_state $fid ARCHIVE SUCCEED
5123 run_test 402b "CDT must retry request upon slow start of CT"
5126 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5128 local agent=$(facet_active_host $SINGLEAGT)
5130 # deactivate all mdc for MDT0001
5131 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5134 local uuid=$(get_agent_uuid $agent)
5135 # check the agent is registered on MDT0000, and not on MDT0001
5136 check_agent_registered_by_mdt $uuid 0
5137 check_agent_unregistered_by_mdt $uuid 1
5139 # check running copytool process
5140 search_copytools $agent || error "No running copytools on $agent"
5142 # reactivate all mdc for MDT0001
5143 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5145 # make sure the copytool is now registered to all MDTs
5146 check_agent_registered $uuid
5148 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5151 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5155 # create files on both MDT0000 and MDT0001
5158 local dir_mdt0=$DIR/$tdir/mdt0
5159 stack_trap "rm -rf $dir_mdt0" EXIT
5160 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5162 # create 1 file on mdt0
5163 local fid1=$(create_small_file $dir_mdt0/$tfile)
5165 # deactivate all mdc for MDT0001
5166 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5168 # send an HSM request for files in MDT0000
5169 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5171 # check for completion of files in MDT0000
5172 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5173 echo "archive successful on mdt0"
5175 # reactivate all mdc for MDT0001
5176 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5178 run_test 404 "Inactive MDT does not block requests for active MDTs"
5181 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5187 local striped_dir=$DIR/$tdir/striped_dir
5189 # create striped dir on all of MDTs
5190 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5192 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5193 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5194 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5195 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5197 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5198 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5199 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5200 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5202 # check that compound requests are shunt to the rights MDTs
5203 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5204 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5205 error "lfs hsm_archive"
5207 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5208 echo "archive successful on $fid1"
5209 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5210 echo "archive successful on $fid2"
5211 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5212 echo "archive successful on $fid3"
5213 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5214 echo "archive successful on $fid4"
5216 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5217 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5218 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5219 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5221 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5222 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5223 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5224 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5226 run_test 405 "archive and release under striped directory"
5229 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5231 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5232 skip "need MDS version at least 2.7.64"
5237 fid=$(create_small_file $DIR/$tdir/$tfile)
5242 $LFS hsm_archive $DIR/$tdir/$tfile
5243 wait_request_state "$fid" ARCHIVE SUCCEED
5244 $LFS hsm_release $DIR/$tdir/$tfile
5246 # Should migrate $tdir but not $tfile.
5247 $LFS migrate -m1 $DIR/$tdir &&
5248 error "migrating HSM an archived file should fail"
5250 $LFS hsm_restore $DIR/$tdir/$tfile
5251 wait_request_state "$fid" RESTORE SUCCEED
5253 $LFS hsm_remove $DIR/$tdir/$tfile
5254 wait_request_state "$fid" REMOVE SUCCEED
5256 cat $DIR/$tdir/$tfile > /dev/null ||
5257 error "cannot read $DIR/$tdir/$tfile"
5259 $LFS migrate -m1 $DIR/$tdir ||
5260 error "cannot complete migration after HSM remove"
5262 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5263 if ((mdt_index != 1)); then
5264 error "expected MDT index 1, got $mdt_index"
5267 # Refresh fid after migration.
5268 fid=$(path2fid $DIR/$tdir/$tfile)
5271 $LFS hsm_archive $DIR/$tdir/$tfile
5272 wait_request_state "$fid" ARCHIVE SUCCEED 1
5274 lctl set_param debug=+trace
5275 $LFS hsm_release $DIR/$tdir/$tfile ||
5276 error "cannot release $DIR/$tdir/$tfile"
5278 $LFS hsm_restore $DIR/$tdir/$tfile
5279 wait_request_state "$fid" RESTORE SUCCEED 1
5281 cat $DIR/$tdir/$tfile > /dev/null ||
5282 error "cannot read $DIR/$tdir/$tfile"
5284 run_test 406 "attempting to migrate HSM archived files is safe"
5287 local f=$DIR/$tdir/$tfile
5288 local f2=$DIR2/$tdir/$tfile
5289 local fid=$(create_empty_file "$f")
5293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5294 wait_request_state $fid ARCHIVE SUCCEED
5297 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5298 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5300 # Prevent restore from completing
5304 # 1st request holds layout lock while appropriate
5305 # RESTORE record is still not added to llog
5309 # after umount hsm_actions->O/x/x log shouldn't have
5310 # double RESTORE records like below
5311 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5312 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5314 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5318 wait_request_state $fid RESTORE SUCCEED
5320 run_test 407 "Check for double RESTORE records in llog"
5324 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5325 skip "HSM migrate is not supported"
5327 test_mkdir -p $DIR/$tdir
5329 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5330 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5332 llapi_hsm_test -d $DIR/$tdir -b ||
5333 error "One llapi HSM test failed"
5335 llapi_hsm_test -d $DIR/$tdir ||
5336 error "One llapi HSM test failed"
5339 run_test 500 "various LLAPI HSM tests"
5342 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5343 skip "need MDS version at least 2.10.58"
5347 local f=$DIR/$tdir/$tfile
5350 # set changelog_mask to ALL
5351 changelog_chmask "ALL"
5353 chmod 777 $DIR/$tdir
5354 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5355 local fid=$(path2fid $f)
5358 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5359 -gid "$RUNAS_GID") ||
5360 error "No matching CREAT entry"
5362 # Parse the changelog
5363 eval local -A changelog=$(changelog2array $entry)
5364 local nid="${changelog[nid]}"
5367 echo "Got NID '$nid'"
5368 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5369 error "nid '$nid' does not match any client NID:" \
5372 run_test 600 "Changelog fields 'u=' and 'nid='"
5375 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5376 skip "need MDS version at least 2.10.58"
5380 local f=$DIR/$tdir/$tfile
5383 # set changelog_mask to ALL
5384 changelog_chmask "ALL"
5386 touch $f || error "touch $f failed"
5387 local fid=$(path2fid $f)
5390 cat $f || error "cat $f failed"
5392 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5393 error "No matching OPEN entry"
5395 run_test 601 "OPEN Changelog entry"
5398 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5399 skip "need MDS version at least 2.10.58"
5403 local f=$DIR/$tdir/$tfile
5406 # set changelog_mask to ALL
5407 changelog_chmask "ALL"
5409 touch $f || error "touch $f failed"
5410 local fid=$(path2fid $f)
5413 cat $f || error "cat $f failed"
5415 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5419 echo f > $f || error "write $f failed"
5422 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5424 # remove OPEN from changelog_mask
5425 changelog_chmask "-OPEN"
5429 cat $f || error "cat $f failed"
5432 changelog_find -type CLOSE -target-fid $fid &&
5433 error "There should be no CLOSE entry"
5437 echo f > $f || error "write $f failed"
5440 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5442 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5445 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5446 skip "need MDS version at least 2.10.58"
5450 local f=$DIR/$tdir/$tfile
5453 # set changelog_mask to ALL
5454 changelog_chmask "ALL"
5456 touch $f || error "touch $f failed"
5457 local fid=$(path2fid $f)
5459 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5462 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5464 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5465 error "No matching GXATR entry"
5467 run_test 603 "GETXATTR Changelog entry"
5470 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5471 skip "need MDS version at least 2.10.58"
5475 local f=$DIR/$tdir/$tfile
5476 local f2=$DIR2/$tdir/$tfile
5477 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5479 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5480 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5481 do_facet mds1 lctl set_param "$procname=20"
5485 # set changelog_mask to ALL
5486 changelog_chmask "ALL"
5488 touch $f || error "touch $f failed"
5489 local fid=$(path2fid $f)
5495 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5499 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5500 -gid "$RUNAS_GID" -mode "r--") ||
5501 error "No matching NOPEN entry"
5503 # Parse the changelog
5504 eval local -A changelog=$(changelog2array $entry)
5505 local nid="${changelog[nid]}"
5508 echo "Got NID '$nid'"
5509 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5510 error "nid '$nid' does not match any client NID:" \
5515 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5518 changelog_find -type NOPEN -target-fid $fid &&
5519 error "There should be no NOPEN entry"
5521 # Sleep for `changelog_deniednext` seconds
5526 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5529 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5530 -gid "$RUNAS_GID" -mode "r--") ||
5531 error "No matching NOPEN entry"
5533 # Parse the changelog
5534 eval local -A changelog=$(changelog2array $entry)
5535 local nid="${changelog[nid]}"
5538 echo "Got NID '$nid'"
5539 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5540 error "nid '$nid' does not match any client NID:" \
5543 run_test 604 "NOPEN Changelog entry"
5546 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5547 skip "need MDS version at least 2.10.58"
5551 local f=$DIR/$tdir/$tfile
5552 local f2=$DIR2/$tdir/$tfile
5555 # set changelog_mask to ALL
5556 changelog_chmask "ALL"
5558 touch $f || error "touch $f failed"
5559 local fid=$(path2fid $f)
5563 exec 3<> $f || error "open $f failed"
5567 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5571 exec 4<> $f || error "open $f failed"
5574 changelog_find -type OPEN -target-fid $fid &&
5575 error "There should be no OPEN entry"
5577 exec 4>&- || error "close $f failed"
5580 changelog_find -type CLOSE -target-fid $fid &&
5581 error "There should be no CLOSE entry"
5585 # access in rw, so different access mode should generate entries
5586 cat $f || error "cat $f failed"
5589 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5591 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5595 # same access as first one, should not generate new entries
5596 exec 4<> $f || error "open $f failed"
5599 changelog_find -type OPEN -target-fid $fid &&
5600 error "There should be no OPEN entry"
5602 exec 4>&- || error "close $f failed"
5605 changelog_find -type CLOSE -target-fid $fid &&
5606 error "There should be no CLOSE entry"
5610 # access by different user should generate new entries
5611 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5614 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5616 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5620 exec 3>&- || error "close $f failed"
5623 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5625 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5628 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5629 skip "need MDS version at least 2.10.58"
5631 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5632 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5633 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5634 skip_env "missing llog_reader" && return
5635 local fstype=$(facet_fstype mds1)
5639 local f=$DIR/$tdir/$tfile
5642 # set changelog_mask to ALL
5643 changelog_chmask "ALL"
5645 chmod 777 $DIR/$tdir
5646 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5647 local fid=$(path2fid $f)
5648 rm $f || error "rm $f failed"
5650 local mntpt=$(facet_mntpt mds1)
5654 #remount mds1 as ldiskfs or zfs type
5655 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5656 stop mds1 || error "stop mds1 failed"
5657 mount_fstype mds1 || error "remount mds1 failed"
5659 for ((i = 0; i < 1; i++)); do
5660 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5661 local cat_file=$(do_facet mds1 $llog_reader \
5662 $mntpt/changelog_catalog | awk \
5663 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5664 [ -n "$cat_file" ] || error "no catalog file"
5666 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5667 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5668 [ -n "$entry" ] || error "no CREAT entry"
5671 local uidgid=$(echo $entry |
5672 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5673 [ -n "$uidgid" ] || error "uidgid is empty"
5674 echo "Got UID/GID $uidgid"
5675 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5676 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5677 local nid=$(echo $entry |
5678 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5679 [ -n "$nid" ] || error "nid is empty"
5681 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5682 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5684 run_test 606 "llog_reader groks changelog fields"
5687 check_and_cleanup_lustre