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 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
173 local sleep_time=100000 # 0.1 second
175 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
183 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
184 sleep_time=$(bc <<< "$sleep_time * 2")
187 # try to dump Copytool's stack
188 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
189 "echo t >/proc/sysrq-trigger"
191 echo "copytools failed to stop in ${wait_timeout}s"
196 copytool_monitor_setup() {
197 local facet=${1:-$SINGLEAGT}
198 local agent=$(facet_active_host $facet)
200 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
201 local test_dir=$(do_node $agent "$cmd") ||
202 error "Failed to create tempdir on $agent"
203 export HSMTOOL_MONITOR_DIR=$test_dir
205 # Create the fifo and a monitor (cat dies when copytool dies)
206 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
207 error "failed to create copytool fifo on $agent"
208 cmd="cat $test_dir/fifo > $test_dir/events &"
209 cmd+=" echo \\\$! > $test_dir/monitor_pid"
211 if [[ $PDSH == *Rmrsh* ]]; then
212 # This is required for pdsh -Rmrsh and its handling of remote
214 # Regular ssh and pdsh -Rssh work fine without this
215 # backgrounded subshell nonsense.
216 (do_node $agent "$cmd") &
217 export HSMTOOL_MONITOR_PDSH=$!
219 # Slightly racy, but just making a best-effort to catch obvious
222 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
223 error "Failed to start copytool monitor on $agent"
225 do_node $agent "$cmd"
227 error "Failed to start copytool monitor on $agent"
232 copytool_monitor_cleanup() {
233 local facet=${1:-$SINGLEAGT}
234 local agent=$(facet_active_host $facet)
236 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
237 # Should die when the copytool dies, but just in case.
238 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
239 cmd+=" 2>/dev/null || true"
240 do_node $agent "$cmd"
241 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
242 export HSMTOOL_MONITOR_DIR=
245 # The pdsh should die on its own when the monitor dies. Just
246 # in case, though, try to clean up to avoid any cruft.
247 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
248 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
249 export HSMTOOL_MONITOR_PDSH=
254 local facet=${1:-$SINGLEAGT}
255 # Use MOUNT2 by default if defined
256 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
258 local hsm_root=${4:-$(copytool_device $facet)}
260 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
262 local agent=$(facet_active_host $facet)
264 if $HSM_ARCHIVE_PURGE; then
265 echo "Purging archive on $agent"
266 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
269 echo "Starting copytool $facet on $agent"
270 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
271 error "mkdir '$hsm_root/$HSMTMP' failed"
272 # bandwidth is limited to 1MB/s so the copy time is known and
273 # independent of hardware
274 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
275 cmd+=" --hsm-root $hsm_root/$HSMTMP"
276 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
277 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
278 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
279 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
280 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
281 cmd+=" --bandwidth 1 $lustre_mntpnt"
283 # Redirect the standard output and error to a log file which
284 # can be uploaded to Maloo.
285 local prefix=$TESTLOG_PREFIX
286 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
287 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
289 stack_trap cleanup EXIT
290 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
291 if [[ $? != 0 ]]; then
292 [[ $HSMTOOL_NOERROR == true ]] ||
293 error "start copytool $facet on $agent failed"
294 echo "start copytool $facet on $agent failed"
298 get_copytool_event_log() {
299 local facet=${1:-$SINGLEAGT}
300 local agent=$(facet_active_host $facet)
302 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
303 error "Can't get event log: No monitor directory!"
305 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
306 error "Could not collect event log from $agent"
311 local agt_facet=$SINGLEAGT
312 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
313 local hsm_root=$(copytool_device $agt_facet)
315 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
322 kill_copytools $agt_hosts
323 wait_copytools $agt_hosts || error "copytools failed to stop"
325 # Clean all CDTs orphans requests from previous tests that
326 # would otherwise need to timeout to clear.
327 for ((i = 0; i < MDSCOUNT; i++)); do
329 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
330 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
332 # Skip already stopping or stopped CDTs.
333 [[ "${state[$i]}" =~ ^stop ]] && continue
335 do_facet $facet "$LCTL set_param $param=shutdown"
338 for ((i = 0; i < MDSCOUNT; i++)); do
339 # Only check and restore CDTs that we stopped in the first loop.
340 [[ "${state[$i]}" =~ ^stop ]] && continue
343 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
345 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
346 error "$facet CDT state is not stopped"
348 # Restore old CDT state.
349 do_facet $facet "$LCTL set_param $param=${state[$i]}"
352 for ((i = 0; i < MDSCOUNT; i++)); do
353 # Only check CDTs that we stopped in the first loop.
354 [[ "${state[$i]}" =~ ^stop ]] && continue
357 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
359 # Check that the old CDT state was restored.
360 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
361 20 || error "$facet CDT state is not '${state[$i]}'"
364 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
365 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
370 local agents=${1:-$(facet_active_host $SINGLEAGT)}
372 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
373 echo "Copytool is suspended on $agents"
376 copytool_continue() {
377 local agents=${1:-$(facet_active_host $SINGLEAGT)}
379 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
380 echo "Copytool is continued on $agents"
383 copytool_remove_backend() {
385 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
386 echo "Remove from backend: $fid = $be"
387 do_facet $SINGLEAGT rm -f $be
391 mkdir -p "$(dirname "$2")" ||
392 error "cannot create directory '$(dirname "$2")'"
394 do_facet $SINGLEAGT \
395 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
396 --import $1 $2 $MOUNT" ||
397 error "import of $1 to $2 failed"
400 file_creation_failure() {
407 df $MOUNT $MOUNT2 >&2
408 error "Not enough space to create $file with $cmd"
411 error "cannot create $file with $cmd, status=$err"
416 # Creates a file using dd
422 local source=${5:-/dev/zero}
426 if [ -n "$conv" ]; then
430 # Create the directory in case it does not exist
431 mkdir -p "$(dirname "$file")"
432 # Delete the file in case it already exist
435 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
436 path2fid "$file" || error "cannot get FID of '$file'"
439 echo "cannot create file '$file'" >&2;
440 # Let the caller decide what to do on error
445 create_empty_file() {
446 create_file "${1/$DIR/$DIR2}" 1M 0 ||
447 file_creation_failure dd "${1/$DIR/$DIR2}" $?
450 create_small_file() {
451 local source_file=/dev/urandom
454 local conv=${2:-fsync}
456 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
457 file_creation_failure dd "${1/$DIR/$DIR2}" $?
460 create_small_sync_file() {
461 create_small_file "$1" sync
464 create_archive_file() {
465 local file="$HSM_ARCHIVE/$1"
467 local source=/dev/urandom
469 # Create the counterpart directory of the archive
470 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
471 error "cannot create archive directory '$(dirname "$file")'"
473 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
474 error "cannot create archive file '$file'"
478 local file=$HSM_ARCHIVE/$2
479 do_facet $SINGLEAGT mkdir -p $(dirname $file)
480 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
489 if [[ "$value" != "" ]]; then
492 for mdtno in $(seq 1 $MDSCOUNT); do
493 local idx=$(($mdtno - 1))
494 local facet=mds${mdtno}
495 # if $arg include -P option, run 1 set_param per MDT on the MGS
496 # else, run set_param on each MDT
497 [[ $arg = *"-P"* ]] && facet=mgs
498 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
499 [[ $? != 0 ]] && rc=1
509 for mdtno in $(seq 1 $MDSCOUNT); do
510 local idx=$(($mdtno - 1))
511 wait_result mds${mdtno} \
512 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
514 error "$key state is not '$target' on mds${mdtno}"
521 for mdtno in $(seq 1 $MDSCOUNT); do
522 local idx=$(($mdtno - 1))
523 local cl_user=$(do_facet mds${mdtno} $LCTL \
524 --device ${MDT[$idx]} \
525 changelog_register -n)
527 do_facet mds${mdtno} lctl set_param \
528 mdd.${MDT[$idx]}.changelog_mask="+hsm"
529 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
533 changelog_cleanup() {
535 for mdtno in $(seq 1 $MDSCOUNT); do
536 local idx=$(($mdtno - 1))
537 [[ -z ${CL_USERS[$idx]} ]] && continue
538 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
539 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
540 changelog_deregister ${CL_USERS[$idx]}
545 changelog_get_flags() {
550 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
555 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
563 mdts_set_param "$opt -n" "hsm.$param" "$value"
570 mdts_set_param "" hsm_control "$cmd"
571 mdts_check_param hsm_control "$target" 10
574 cdt_set_sanity_policy() {
575 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
578 mdts_set_param "" hsm.policy "+NRA"
579 mdts_set_param "" hsm.policy "-NBR"
580 CDT_POLICY_HAD_CHANGED=
585 mdts_set_param "" hsm.policy "+NRA"
586 CDT_POLICY_HAD_CHANGED=true
589 cdt_clear_no_retry() {
590 mdts_set_param "" hsm.policy "-NRA"
591 CDT_POLICY_HAD_CHANGED=true
594 cdt_set_non_blocking_restore() {
595 mdts_set_param "" hsm.policy "+NBR"
596 CDT_POLICY_HAD_CHANGED=true
599 cdt_clear_non_blocking_restore() {
600 mdts_set_param "" hsm.policy "-NBR"
601 CDT_POLICY_HAD_CHANGED=true
604 cdt_clear_mount_state() {
605 mdts_set_param "-P -d" hsm_control ""
608 cdt_set_mount_state() {
609 mdts_set_param "-P" hsm_control "$1"
610 # set_param -P is asynchronous operation and could race with set_param.
611 # In such case configs could be retrieved and applied at mgc after
612 # set_param -P completion. Sleep here to avoid race with set_param.
613 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
614 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
615 # and 10 seconds to retrieve config from server.
620 mdts_check_param hsm_control "$1" 20
624 set_test_state disabled disabled
628 set_test_state enabled enabled
632 set_test_state shutdown stopped
636 set_test_state purge enabled
642 cdt_set_sanity_policy
646 local client_count=$1
647 if [[ $CLIENTCOUNT -lt $client_count ]]; then
648 skip "Need $client_count or more clients, have $CLIENTCOUNT"
655 $LFS path2fid $1 | tr -d '[]'
656 return ${PIPESTATUS[0]}
664 if [[ $u == "user" ]]; then
665 st=$($RUNAS $LFS hsm_state $f)
668 st=$($LFS hsm_state $f)
671 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
673 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
677 get_hsm_archive_id() {
680 st=$($LFS hsm_state $f)
681 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
683 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
691 local st=$(get_hsm_flags $f)
692 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
695 check_hsm_flags_user() {
699 local st=$(get_hsm_flags $f user)
700 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
712 if [[ "$3" != 1 ]]; then
716 cp $1 $f || file_creation_failure cp $f $?
718 path2fid $f || error "cannot get fid on $f"
721 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
723 # Note that this might lead to surprising behaviours such as deleting an
724 # important file for the currently running test
725 delete_large_files() {
726 printf "Deleting large files...\n" >&2
727 find $MOUNT -size +10M -delete
728 wait_delete_completed
731 make_custom_file_for_progress() {
732 local count=${2:-"39"}
733 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
736 [[ $count -gt 0 ]] || error "Invalid file size"
737 [[ $bs -gt 0 ]] || error "Invalid stripe size"
739 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
740 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
741 echo "It might be due to a lack of space in the filesystem" >&2
742 delete_large_files >&2
743 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
744 file_creation_failure dd "${1/$DIR/$DIR2}" $?
751 wait_update --verbose $(facet_active_host $facet) "$@"
754 wait_request_state() {
758 # 4th arg (mdt index) is optional
760 local mds=mds$(($mdtidx + 1))
762 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
763 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
765 wait_result $mds "$cmd" $state 200 ||
766 error "request on $fid is not $state on $mds"
769 get_request_state() {
773 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
774 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
777 get_request_count() {
781 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
782 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
785 # Ensure the number of HSM request for a given FID is correct
786 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
787 assert_request_count() {
788 local request_count=$(get_request_count $1 $2)
789 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
791 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
798 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
799 [[ -n $fid ]] && cmd+=" | grep '$fid'"
800 cmd+=" | egrep 'WAITING|STARTED'"
802 wait_result $SINGLEMDS "$cmd" "" $timeout ||
803 error "requests did not complete"
806 wait_for_grace_delay() {
807 local val=$(get_hsm_param grace_delay)
811 wait_for_loop_period() {
812 local val=$(get_hsm_param loop_period)
819 # python2.6 in EL6 includes an internal json module
820 local json_parser='import json; import fileinput;'
821 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
822 json_parser+='json.loads([line for line in '
823 json_parser+='fileinput.input()][0]).items()])'
825 echo $raw_event | python -c "$json_parser"
828 get_agent_by_uuid_mdt() {
831 local mds=mds$(($mdtidx + 1))
832 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
836 check_agent_registered_by_mdt() {
839 local mds=mds$(($mdtidx + 1))
840 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
841 if [[ ! -z "$agent" ]]; then
842 echo "found agent $agent on $mds"
844 error "uuid $uuid not found in agent list on $mds"
848 check_agent_unregistered_by_mdt() {
851 local mds=mds$(($mdtidx + 1))
852 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
853 if [[ -z "$agent" ]]; then
854 echo "uuid not found in agent list on $mds"
856 error "uuid found in agent list on $mds: $agent"
860 check_agent_registered() {
863 for mdsno in $(seq 1 $MDSCOUNT); do
864 check_agent_registered_by_mdt $uuid $((mdsno - 1))
868 check_agent_unregistered() {
871 for mdsno in $(seq 1 $MDSCOUNT); do
872 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
877 local agent=${1:-$(facet_active_host $SINGLEAGT)}
879 # Lustre mount-point is mandatory and last parameter on
881 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
883 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
885 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
891 # populate MDT device array
894 # cleanup from previous bad setup
897 # for recovery tests, coordinator needs to be started at mount
899 # the lustre conf must be without hsm on (like for sanity.sh)
900 echo "Set HSM on and start"
901 cdt_set_mount_state enabled
902 cdt_check_state enabled
904 echo "Set sanity-hsm HSM policy"
905 cdt_set_sanity_policy
907 # finished requests are quickly removed from list
908 set_hsm_param grace_delay 10
914 local f=$DIR/$tdir/$tfile
918 check_hsm_flags_user $f "0x00000000"
920 $RUNAS $LFS hsm_set --norelease $f ||
921 error "user could not change hsm flags"
922 check_hsm_flags_user $f "0x00000010"
924 $RUNAS $LFS hsm_clear --norelease $f ||
925 error "user could not clear hsm flags"
926 check_hsm_flags_user $f "0x00000000"
928 # User could not change those flags...
929 $RUNAS $LFS hsm_set --exists $f &&
930 error "user should not set this flag"
931 check_hsm_flags_user $f "0x00000000"
934 $LFS hsm_set --exists $f ||
935 error "root could not change hsm flags"
936 check_hsm_flags_user $f "0x00000001"
938 $LFS hsm_clear --exists $f ||
939 error "root could not clear hsm state"
940 check_hsm_flags_user $f "0x00000000"
943 run_test 1 "lfs hsm flags root/non-root access"
946 local f=$DIR/$tdir/$tfile
947 local fid=$(create_small_file $f)
951 $LFS hsm_archive $f || error "could not archive file"
952 wait_request_state $fid ARCHIVE SUCCEED
954 # Release and check states
955 $LFS hsm_release $f || error "could not release file"
956 echo -n "Verifying released state: "
957 check_hsm_flags $f "0x0000000d"
959 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
963 run_test 1a "mmap & cat a HSM released file"
967 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
968 error "failed to set default stripe"
969 local f=$DIR/$tdir/$tfile
972 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
973 error "failed to create file"
974 local fid=$(path2fid $f)
979 $LFS hsm_archive $f || error "could not archive file"
980 wait_request_state $fid ARCHIVE SUCCEED
983 $LFS hsm_release $f || error "could not release file"
984 echo "verify released state: "
985 check_hsm_flags $f "0x0000000d" && echo "pass"
988 $LFS hsm_restore $f || error "could not restore file"
989 wait_request_state $fid RESTORE SUCCEED
990 echo "verify restored state: "
991 check_hsm_flags $f "0x00000009" && echo "pass"
995 run_test 1b "Archive, Release & Restore composite file"
1001 local f=$DIR/$tdir/$tfile
1004 # Test whether we can set the maximum archive number.
1005 local LOCAL_HSM_ARCHIVE_NUMBER=32
1006 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1007 error "root could not change hsm flags"
1008 check_hsm_flags_user $f "0x00000001"
1009 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1010 local st=$(get_hsm_archive_id $f)
1011 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1012 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1014 # Test whether setting archive number 0 results in no change.
1015 $LFS hsm_set --exists --archive-id 0 $f ||
1016 error "root could not change hsm flags"
1017 check_hsm_flags_user $f "0x00000001"
1018 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1019 st=$(get_hsm_archive_id $f)
1020 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1021 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1023 # Test whether setting archive number > 32 results in error.
1024 $LFS hsm_set --exists --archive-id 33 $f &&
1025 error "archive number is larger than 32"
1026 check_hsm_flags_user $f "0x00000001"
1028 # Test whether setting archive number 16 and archived flag.
1029 LOCAL_HSM_ARCHIVE_NUMBER=16
1030 $LFS hsm_set --exists --archived \
1031 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1032 error "root could not change hsm flags"
1033 check_hsm_flags_user $f "0x00000009"
1034 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1035 st=$(get_hsm_archive_id $f)
1036 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1037 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1039 run_test 1c "Check setting archive-id in lfs hsm_set"
1042 local f=$DIR/$tdir/$tfile
1044 create_empty_file "$f"
1045 # New files are not dirty
1046 check_hsm_flags $f "0x00000000"
1048 # For test, we simulate an archived file.
1049 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1050 check_hsm_flags $f "0x00000001"
1052 # chmod do not put the file dirty
1053 chmod 600 $f || error "could not chmod test file"
1054 check_hsm_flags $f "0x00000001"
1056 # chown do not put the file dirty
1057 chown $RUNAS_ID $f || error "could not chown test file"
1058 check_hsm_flags $f "0x00000001"
1060 # truncate put the file dirty
1061 $TRUNCATE $f 1 || error "could not truncate test file"
1062 check_hsm_flags $f "0x00000003"
1064 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1065 check_hsm_flags $f "0x00000001"
1067 run_test 2 "Check file dirtyness when doing setattr"
1073 # New files are not dirty
1074 cp -p /etc/passwd $f
1075 check_hsm_flags $f "0x00000000"
1077 # For test, we simulate an archived file.
1078 $LFS hsm_set --exists $f ||
1079 error "user could not change hsm flags"
1080 check_hsm_flags $f "0x00000001"
1082 # Reading a file, does not set dirty
1083 cat $f > /dev/null || error "could not read file"
1084 check_hsm_flags $f "0x00000001"
1086 # Open for write without modifying data, does not set dirty
1087 openfile -f O_WRONLY $f || error "could not open test file"
1088 check_hsm_flags $f "0x00000001"
1090 # Append to a file sets it dirty
1091 cp -p /etc/passwd $f.append || error "could not create file"
1092 $LFS hsm_set --exists $f.append ||
1093 error "user could not change hsm flags"
1094 dd if=/etc/passwd of=$f.append bs=1 count=3\
1095 conv=notrunc oflag=append status=noxfer ||
1096 file_creation_failure dd $f.append $?
1097 check_hsm_flags $f.append "0x00000003"
1099 # Modify a file sets it dirty
1100 cp -p /etc/passwd $f.modify || error "could not create file"
1101 $LFS hsm_set --exists $f.modify ||
1102 error "user could not change hsm flags"
1103 dd if=/dev/zero of=$f.modify bs=1 count=3\
1104 conv=notrunc status=noxfer ||
1105 file_creation_failure dd $f.modify $?
1106 check_hsm_flags $f.modify "0x00000003"
1108 # Open O_TRUNC sets dirty
1109 cp -p /etc/passwd $f.trunc || error "could not create file"
1110 $LFS hsm_set --exists $f.trunc ||
1111 error "user could not change hsm flags"
1112 cp /etc/group $f.trunc || error "could not override a file"
1113 check_hsm_flags $f.trunc "0x00000003"
1115 # Mmapped a file sets dirty
1116 cp -p /etc/passwd $f.mmap || error "could not create file"
1117 $LFS hsm_set --exists $f.mmap ||
1118 error "user could not change hsm flags"
1119 multiop $f.mmap OSMWUc || error "could not mmap a file"
1120 check_hsm_flags $f.mmap "0x00000003"
1122 run_test 3 "Check file dirtyness when opening for write"
1125 local f=$DIR/$tdir/$tfile
1126 local fid=$(create_small_file $f)
1129 local st=$(get_request_state $fid CANCEL)
1130 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1132 run_test 4 "Useless cancel must not be registered"
1135 # test needs a running copytool
1139 local f=$DIR/$tdir/$tfile
1140 local fid=$(copy_file /etc/passwd $f)
1142 wait_request_state $fid ARCHIVE SUCCEED
1144 check_hsm_flags $f "0x00000009"
1148 run_test 8 "Test default archive number"
1151 # we do not use the default one to be sure
1152 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1154 copytool_setup $SINGLEAGT $MOUNT $new_an
1156 # give time for CT to register with MDTs
1157 sleep $(($MDSCOUNT*2))
1158 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1159 check_agent_registered $uuid
1162 local f=$DIR/$tdir/$tfile
1163 local fid=$(copy_file /etc/passwd $f)
1164 $LFS hsm_archive --archive $new_an $f
1165 wait_request_state $fid ARCHIVE SUCCEED
1167 check_hsm_flags $f "0x00000009"
1171 run_test 9 "Use of explicit archive number, with dedicated copytool"
1174 needclients 3 || return 0
1180 copytool_cleanup $(comma_list $(agts_nodes))
1182 # start all of the copytools
1183 for n in $(seq $AGTCOUNT); do
1184 copytool_setup agt$n
1187 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1189 for n in $(seq $AGTCOUNT); do
1190 file=$DIR/$tdir/$tfile.$n
1191 fid=$(create_small_file $file)
1193 $LFS hsm_archive $file || error "could not archive file $file"
1194 wait_request_state $fid ARCHIVE SUCCEED
1195 check_hsm_flags $file "0x00000009"
1199 copytool_cleanup $(comma_list $(agts_nodes))
1201 run_test 9a "Multiple remote agents"
1204 # test needs a running copytool
1207 mkdir -p $DIR/$tdir/d1
1208 local f=$DIR/$tdir/$tfile
1209 local fid=$(copy_file /etc/hosts $f)
1210 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1211 error "hsm_archive failed"
1212 wait_request_state $fid ARCHIVE SUCCEED
1214 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1215 error "fid $fid not in archive $HSM_ARCHIVE"
1216 echo "Verifying content"
1217 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1218 echo "Verifying hsm state "
1219 check_hsm_flags $f "0x00000009"
1221 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1222 local st=$(get_hsm_archive_id $f)
1223 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1224 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1229 run_test 10a "Archive a file"
1232 # test needs a running copytool
1236 local f=$DIR/$tdir/$tfile
1237 local fid=$(copy_file /etc/hosts $f)
1238 $LFS hsm_archive $f || error "archive request failed"
1239 wait_request_state $fid ARCHIVE SUCCEED
1241 $LFS hsm_archive $f || error "archive of non dirty file failed"
1242 local cnt=$(get_request_count $fid ARCHIVE)
1243 [[ "$cnt" == "1" ]] ||
1244 error "archive of non dirty file must not make a request"
1248 run_test 10b "Archive of non dirty file must work without doing request"
1251 # test needs a running copytool
1255 local f=$DIR/$tdir/$tfile
1256 local fid=$(copy_file /etc/hosts $f)
1257 $LFS hsm_set --noarchive $f
1258 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1262 run_test 10c "Check forbidden archive"
1265 # test needs a running copytool
1269 local f=$DIR/$tdir/$tfile
1270 local fid=$(copy_file /etc/hosts $f)
1271 $LFS hsm_archive $f || error "cannot archive $f"
1272 wait_request_state $fid ARCHIVE SUCCEED
1274 local ar=$(get_hsm_archive_id $f)
1275 local dflt=$(get_hsm_param default_archive_id)
1276 [[ $ar == $dflt ]] ||
1277 error "archived file is not on default archive: $ar != $dflt"
1281 run_test 10d "Archive a file on the default archive id"
1285 copy2archive /etc/hosts $tdir/$tfile
1286 local f=$DIR/$tdir/$tfile
1288 import_file $tdir/$tfile $f
1289 echo -n "Verifying released state: "
1290 check_hsm_flags $f "0x0000000d"
1292 local LSZ=$(stat -c "%s" $f)
1293 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1295 echo "Verifying imported size $LSZ=$ASZ"
1296 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1297 echo -n "Verifying released pattern: "
1298 local PTRN=$($GETSTRIPE -L $f)
1300 [[ $PTRN == released ]] || error "Is not released"
1301 local fid=$(path2fid $f)
1302 echo "Verifying new fid $fid in archive"
1304 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1305 error "fid $fid not in archive $HSM_ARCHIVE"
1307 run_test 11a "Import a file"
1310 # test needs a running copytool
1314 local f=$DIR/$tdir/$tfile
1315 local fid=$(copy_file /etc/hosts $f)
1316 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1317 error "hsm_archive failed"
1318 wait_request_state $fid ARCHIVE SUCCEED
1320 local FILE_HASH=$(md5sum $f)
1325 echo "$FILE_HASH" | md5sum -c
1327 [[ $? -eq 0 ]] || error "Restored file differs"
1331 run_test 11b "Import a deleted file using its FID"
1334 # test needs a running copytool
1338 copy2archive /etc/hosts $tdir/$tfile
1340 local f=$DIR/$tdir/$tfile
1341 import_file $tdir/$tfile $f
1342 local f2=$DIR2/$tdir/$tfile
1343 echo "Verifying released state: "
1344 check_hsm_flags $f2 "0x0000000d"
1346 local fid=$(path2fid $f2)
1347 $LFS hsm_restore $f2
1348 wait_request_state $fid RESTORE SUCCEED
1350 echo "Verifying file state: "
1351 check_hsm_flags $f2 "0x00000009"
1353 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1355 [[ $? -eq 0 ]] || error "Restored file differs"
1359 run_test 12a "Restore an imported file explicitly"
1362 # test needs a running copytool
1366 copy2archive /etc/hosts $tdir/$tfile
1368 local f=$DIR/$tdir/$tfile
1369 import_file $tdir/$tfile $f
1370 echo "Verifying released state: "
1371 check_hsm_flags $f "0x0000000d"
1373 cat $f > /dev/null || error "File read failed"
1375 echo "Verifying file state after restore: "
1376 check_hsm_flags $f "0x00000009"
1378 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1380 [[ $? -eq 0 ]] || error "Restored file differs"
1384 run_test 12b "Restore an imported file implicitly"
1387 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1389 # test needs a running copytool
1392 local f=$DIR/$tdir/$tfile
1394 $LFS setstripe -c 2 "$f"
1396 fid=$(make_custom_file_for_progress $f 5)
1397 [ $? != 0 ] && skip "not enough free space" && return
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"
1411 run_test 12c "Restore a file with stripe of 2"
1414 # test needs a running copytool
1419 local f=$DIR/$tdir/$tfile
1420 local fid=$(copy_file /etc/hosts $f)
1421 $LFS hsm_restore $f || error "restore of non archived file failed"
1422 local cnt=$(get_request_count $fid RESTORE)
1423 [[ "$cnt" == "0" ]] ||
1424 error "restore non archived must not make a request"
1425 $LFS hsm_archive $f ||
1426 error "archive request failed"
1427 wait_request_state $fid ARCHIVE SUCCEED
1428 $LFS hsm_restore $f ||
1429 error "restore of non released file failed"
1430 local cnt=$(get_request_count $fid RESTORE)
1431 [[ "$cnt" == "0" ]] ||
1432 error "restore a non dirty file must not make a request"
1436 run_test 12d "Restore of a non archived, non released file must work"\
1437 " without doing request"
1440 # test needs a running copytool
1443 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1444 local f=$DIR/$tdir/$tfile
1445 local fid=$(copy_file /etc/hosts $f)
1446 $LFS hsm_archive $f || error "archive request failed"
1447 wait_request_state $fid ARCHIVE SUCCEED
1450 cat /etc/hosts >> $f
1454 $LFS hsm_restore $f && error "restore a dirty file must fail"
1458 run_test 12e "Check forbidden restore"
1461 # test needs a running copytool
1465 local f=$DIR/$tdir/$tfile
1466 local fid=$(copy_file /etc/hosts $f)
1468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1469 wait_request_state $fid ARCHIVE SUCCEED
1470 $LFS hsm_release $f || error "release of $f failed"
1472 wait_request_state $fid RESTORE SUCCEED
1474 echo -n "Verifying file state: "
1475 check_hsm_flags $f "0x00000009"
1477 diff -q /etc/hosts $f
1479 [[ $? -eq 0 ]] || error "Restored file differs"
1483 run_test 12f "Restore a released file explicitly"
1486 # test needs a running copytool
1490 local f=$DIR/$tdir/$tfile
1491 local fid=$(copy_file /etc/hosts $f)
1493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1494 wait_request_state $fid ARCHIVE SUCCEED
1495 $LFS hsm_release $f || error "release of $f failed"
1497 diff -q /etc/hosts $f
1500 # we check we had a restore done
1501 wait_request_state $fid RESTORE SUCCEED
1503 [[ $st -eq 0 ]] || error "Restored file differs"
1507 run_test 12g "Restore a released file implicitly"
1510 needclients 2 || return 0
1512 # test needs a running copytool
1516 local f=$DIR/$tdir/$tfile
1517 local fid=$(copy_file /etc/hosts $f)
1519 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1520 wait_request_state $fid ARCHIVE SUCCEED
1521 $LFS hsm_release $f || error "release of $f failed"
1523 do_node $CLIENT2 diff -q /etc/hosts $f
1526 # we check we had a restore done
1527 wait_request_state $fid RESTORE SUCCEED
1529 [[ $st -eq 0 ]] || error "Restored file differs"
1533 run_test 12h "Restore a released file implicitly from a second node"
1536 # test needs a running copytool
1540 local f=$DIR/$tdir/$tfile
1541 local fid=$(copy_file /etc/passwd $f)
1542 $LFS hsm_archive $f || error "archive of $f failed"
1543 wait_request_state $fid ARCHIVE SUCCEED
1545 $LFS hsm_release $f || error "release of $f failed"
1549 [[ $? -eq 0 ]] || error "Restored file differs"
1553 run_test 12m "Archive/release/implicit restore"
1556 # test needs a running copytool
1560 copy2archive /etc/hosts $tdir/$tfile
1562 local f=$DIR/$tdir/$tfile
1563 import_file $tdir/$tfile $f
1565 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1566 error "Restored file differs"
1568 $LFS hsm_release $f || error "release of $f failed"
1572 run_test 12n "Import/implicit restore/release"
1575 # test needs a running copytool
1579 local f=$DIR/$tdir/$tfile
1580 local fid=$(copy_file /etc/hosts $f)
1582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1583 wait_request_state $fid ARCHIVE SUCCEED
1584 $LFS hsm_release $f || error "release of $f failed"
1586 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1587 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1589 # set no retry action mode
1592 diff -q /etc/hosts $f
1595 # we check we had a restore failure
1596 wait_request_state $fid RESTORE FAILED
1598 [[ $st -eq 0 ]] && error "Restore must fail"
1600 # remove no retry action mode
1603 # check file is still released
1604 check_hsm_flags $f "0x0000000d"
1606 # retry w/o failure injection
1607 do_facet $SINGLEMDS lctl set_param fail_loc=0
1609 # to be sure previous RESTORE result is gone
1611 wait_for_grace_delay
1613 diff -q /etc/hosts $f
1616 # we check we had a restore done
1617 wait_request_state $fid RESTORE SUCCEED
1619 [[ $st -eq 0 ]] || error "Restored file differs"
1623 run_test 12o "Layout-swap failure during Restore leaves file released"
1626 # test needs a running copytool
1630 local f=$DIR/$tdir/$tfile
1631 local fid=$(copy_file /etc/hosts $f)
1633 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1634 wait_request_state $fid ARCHIVE SUCCEED
1635 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1636 $LFS hsm_release $f || error "cannot release $f"
1637 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1638 $LFS hsm_release $f || error "cannot release $f"
1639 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1643 run_test 12p "implicit restore of a file on copytool mount point"
1645 cleanup_test_12q() {
1647 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1648 error "cannot umount $MOUNT3 on $SINGLEAGT"
1652 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1653 skip "need MDS version at least 2.7.58" && return 0
1655 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1656 error "cannot mount $MOUNT3 on $SINGLEAGT"
1658 trap cleanup_test_12q EXIT
1660 # test needs a running copytool
1661 copytool_setup $SINGLEAGT $MOUNT3
1663 local f=$DIR/$tdir/$tfile
1664 local f2=$DIR2/$tdir/$tfile
1665 local fid=$(create_small_file $f)
1666 local orig_size=$(stat -c "%s" $f)
1668 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1669 wait_request_state $fid ARCHIVE SUCCEED
1671 $LFS hsm_release $f || error "could not release file"
1672 check_hsm_flags $f "0x0000000d"
1675 wait_copytools || error "copytool failed to stop"
1677 cat $f > /dev/null &
1679 # wait a bit to allow implicit restore request to be handled.
1680 # if not, next stat would also block on layout-lock.
1683 local size=$(stat -c "%s" $f2)
1684 [ $size -eq $orig_size ] ||
1685 error "$f2: wrong size after archive: $size != $orig_size"
1687 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1691 size=$(stat -c "%s" $f)
1692 [ $size -eq $orig_size ] ||
1693 error "$f: wrong size after restore: $size != $orig_size"
1695 size=$(stat -c "%s" $f2)
1696 [ $size -eq $orig_size ] ||
1697 error "$f2: wrong size after restore: $size != $orig_size"
1701 size=$(stat -c "%s" $f)
1703 error "$f: wrong size after overwrite: $size != 0"
1705 size=$(stat -c "%s" $f2)
1707 error "$f2: wrong size after overwrite: $size != 0"
1710 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1711 error "cannot umount $MOUNT3 on $SINGLEAGT"
1713 run_test 12q "file attributes are refreshed after restore"
1716 # test needs a running copytool
1719 local ARC_SUBDIR="import.orig"
1723 # populate directory to be imported
1724 for d in $(seq 1 10); do
1725 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1726 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1727 for f in $(seq 1 10); do
1728 CURR_FILE="$CURR_DIR/$tfile.$f"
1729 # write file-specific data
1730 do_facet $SINGLEAGT \
1731 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1732 "file=$CURR_FILE > $CURR_FILE"
1736 import_file "$ARC_SUBDIR" $DIR/$tdir
1737 # diff lustre content and origin (triggers file restoration)
1738 # there must be 10x10 identical files, and no difference
1739 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1740 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1741 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1742 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1744 [ $cnt_diff -eq 0 ] ||
1745 error "$cnt_diff imported files differ from read data"
1746 [ $cnt_ok -eq 100 ] ||
1747 error "not enough identical files ($cnt_ok != 100)"
1751 run_test 13 "Recursively import and restore a directory"
1754 # test needs a running copytool
1758 local f=$DIR/$tdir/$tfile
1759 local fid=$(create_small_file $f)
1760 local sum=$(md5sum $f | awk '{print $1}')
1761 $LFS hsm_archive $f || error "could not archive file"
1762 wait_request_state $fid ARCHIVE SUCCEED
1764 # create released file (simulate llapi_hsm_import call)
1765 local fid2=$(create_empty_file "$f")
1766 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1767 $LFS hsm_release $f || error "could not release file"
1769 # rebind the archive to the newly created file
1770 echo "rebind $fid to $fid2"
1772 do_facet $SINGLEAGT \
1773 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1774 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1776 # restore file and compare md5sum
1777 local sum2=$(md5sum $f | awk '{print $1}')
1779 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1783 run_test 14 "Rebind archived file to a new fid"
1786 # test needs a running copytool
1790 local f=$DIR/$tdir/$tfile
1792 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1796 for i in $(seq 1 $count); do
1797 fids[$i]=$(create_small_file $f.$i)
1798 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1799 $LFS hsm_archive $f.$i || error "could not archive file"
1801 wait_all_done $(($count*60))
1805 for i in $(seq 1 $count); do
1806 local fid2=$(create_empty_file "${f}.${i}")
1807 # add the rebind operation to the list
1808 echo ${fids[$i]} $fid2 >> $tmpfile
1810 # set it released (simulate llapi_hsm_import call)
1811 $LFS hsm_set --archived --exists $f.$i ||
1812 error "could not force hsm flags"
1813 $LFS hsm_release $f.$i || error "could not release file"
1815 nl=$(wc -l < $tmpfile)
1816 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1818 echo "rebind list of files"
1819 do_facet $SINGLEAGT \
1820 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1821 --rebind $tmpfile $DIR" || error "could not rebind file list"
1823 # restore files and compare md5sum
1824 for i in $(seq 1 $count); do
1825 local sum2=$(md5sum $f.$i | awk '{print $1}')
1826 [[ $sum2 == ${sums[$i]} ]] ||
1827 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1833 run_test 15 "Rebind a list of files"
1836 # test needs a running copytool
1840 # create a known size file so we can verify transfer speed
1843 dd if=/dev/zero of=$ref bs=1M count=20
1846 local f=$DIR/$tdir/$tfile
1847 local fid=$(copy_file $ref $f)
1849 local start=$(date +%s)
1851 wait_request_state $fid ARCHIVE SUCCEED
1852 local end=$(date +%s)
1853 # Add 1 to account for rounding errors between start and end (LU-8155)
1854 local duration=$((end - start + 1))
1856 [[ $duration -ge $((goal - 1)) ]] ||
1857 error "Transfer is too fast $duration < $goal"
1861 run_test 16 "Test CT bandwith control option"
1864 local f=$DIR/$tdir/$tfile
1865 create_empty_file "$f"
1867 # Could not release a non-archived file
1868 $LFS hsm_release $f && error "release should not succeed"
1870 # For following tests, we must test them with HS_ARCHIVED set
1871 $LFS hsm_set --exists --archived $f || error "could not add flag"
1873 # Could not release a file if no-release is set
1874 $LFS hsm_set --norelease $f || error "could not add flag"
1875 $LFS hsm_release $f && error "release should not succeed"
1876 $LFS hsm_clear --norelease $f || error "could not remove flag"
1878 # Could not release a file if lost
1879 $LFS hsm_set --lost $f || error "could not add flag"
1880 $LFS hsm_release $f && error "release should not succeed"
1881 $LFS hsm_clear --lost $f || error "could not remove flag"
1883 # Could not release a file if dirty
1884 $LFS hsm_set --dirty $f || error "could not add flag"
1885 $LFS hsm_release $f && error "release should not succeed"
1886 $LFS hsm_clear --dirty $f || error "could not remove flag"
1888 run_test 20 "Release is not permitted"
1891 # test needs a running copytool
1894 local f=$DIR/$tdir/test_release
1896 # Create a file and check its states
1897 local fid=$(create_small_file $f)
1898 check_hsm_flags $f "0x00000000"
1900 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1901 # used until file is flushed to disk
1902 if [ $(facet_fstype ost1) == "zfs" ]; then
1903 # this causes an OST_SYNC rpc to be sent
1904 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1905 # clear locks to reread file data
1906 cancel_lru_locks osc
1909 local orig_size=$(stat -c "%s" $f)
1910 local orig_blocks=$(stat -c "%b" $f)
1912 start_full_debug_logging
1914 $LFS hsm_archive $f || error "could not archive file"
1915 wait_request_state $fid ARCHIVE SUCCEED
1917 local blocks=$(stat -c "%b" $f)
1918 [ $blocks -eq $orig_blocks ] ||
1919 error "$f: wrong block number after archive: " \
1920 "$blocks != $orig_blocks"
1921 local size=$(stat -c "%s" $f)
1922 [ $size -eq $orig_size ] ||
1923 error "$f: wrong size after archive: $size != $orig_size"
1925 # Release and check states
1926 $LFS hsm_release $f || error "could not release file"
1927 check_hsm_flags $f "0x0000000d"
1929 blocks=$(stat -c "%b" $f)
1930 [ $blocks -gt 5 ] &&
1931 error "$f: too many blocks after release: $blocks > 5"
1932 size=$(stat -c "%s" $f)
1933 [ $size -ne $orig_size ] &&
1934 error "$f: wrong size after release: $size != $orig_size"
1936 # Check we can release an file without stripe info
1940 check_hsm_flags $f "0x00000000"
1941 $LFS hsm_archive $f || error "could not archive file"
1942 wait_request_state $fid ARCHIVE SUCCEED
1944 # Release and check states
1945 $LFS hsm_release $f || error "could not release file"
1946 check_hsm_flags $f "0x0000000d"
1948 # Release again a file that is already released is OK
1949 $LFS hsm_release $f || fail "second release should succeed"
1950 check_hsm_flags $f "0x0000000d"
1952 stop_full_debug_logging
1956 run_test 21 "Simple release tests"
1959 # test needs a running copytool
1962 local f=$DIR/$tdir/test_release
1963 local swap=$DIR/$tdir/test_swap
1965 # Create a file and check its states
1966 local fid=$(create_small_file $f)
1967 check_hsm_flags $f "0x00000000"
1969 $LFS hsm_archive $f || error "could not archive file"
1970 wait_request_state $fid ARCHIVE SUCCEED
1972 # Release and check states
1973 $LFS hsm_release $f || error "could not release file"
1974 check_hsm_flags $f "0x0000000d"
1976 create_small_file $swap
1977 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1982 run_test 22 "Could not swap a release file"
1985 # test needs a running copytool
1988 local f=$DIR/$tdir/test_mtime
1990 # Create a file and check its states
1991 local fid=$(create_small_file $f)
1992 check_hsm_flags $f "0x00000000"
1994 $LFS hsm_archive $f || error "could not archive file"
1995 wait_request_state $fid ARCHIVE SUCCEED
1997 # Set modification time in the past
1998 touch -m -a -d @978261179 $f
2000 # Release and check states
2001 $LFS hsm_release $f || error "could not release file"
2002 check_hsm_flags $f "0x0000000d"
2004 local MTIME=$(stat -c "%Y" $f)
2005 local ATIME=$(stat -c "%X" $f)
2006 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2007 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2011 run_test 23 "Release does not change a/mtime (utime)"
2014 local file=$DIR/$tdir/$tfile
2023 # test needs a running copytool
2026 fid=$(create_small_file $file)
2028 # Create a file and check its states
2029 check_hsm_flags $file "0x00000000"
2031 # Ensure atime is less than mtime and ctime.
2035 atime0=$(stat -c "%X" $file)
2036 mtime0=$(stat -c "%Y" $file)
2037 ctime0=$(stat -c "%Z" $file)
2039 [ $atime0 -lt $mtime0 ] ||
2040 error "atime $atime0 is not less than mtime $mtime0"
2042 [ $atime0 -lt $ctime0 ] ||
2043 error "atime $atime0 is not less than ctime $ctime0"
2045 # Archive should not change any timestamps.
2046 $LFS hsm_archive $file || error "cannot archive '$file'"
2047 wait_request_state $fid ARCHIVE SUCCEED
2049 atime1=$(stat -c "%X" $file)
2050 mtime1=$(stat -c "%Y" $file)
2051 ctime1=$(stat -c "%Z" $file)
2053 [ $atime0 -eq $atime1 ] ||
2054 error "archive changed atime from $atime0 to $atime1"
2056 [ $mtime0 -eq $mtime1 ] ||
2057 error "archive changed mtime from $mtime0 to $mtime1"
2059 [ $ctime0 -eq $ctime1 ] ||
2060 error "archive changed ctime from $ctime0 to $ctime1"
2062 # Release should not change any timestamps.
2063 $LFS hsm_release $file || error "cannot release '$file'"
2064 check_hsm_flags $file "0x0000000d"
2066 atime1=$(stat -c "%X" $file)
2067 mtime1=$(stat -c "%Y" $file)
2068 ctime1=$(stat -c "%Z" $file)
2070 [ $atime0 -eq $atime1 ] ||
2071 error "release changed atime from $atime0 to $atime1"
2073 [ $mtime0 -eq $mtime1 ] ||
2074 error "release changed mtime from $mtime0 to $mtime1"
2076 [ $ctime0 -eq $ctime1 ] ||
2077 error "release changed ctime from $ctime0 to $ctime1"
2079 # Restore should not change any timestamps.
2080 $LFS hsm_restore $file
2081 wait_request_state $fid RESTORE SUCCEED
2083 atime1=$(stat -c "%X" $file)
2084 mtime1=$(stat -c "%Y" $file)
2085 ctime1=$(stat -c "%Z" $file)
2087 [ $atime0 -eq $atime1 ] ||
2088 error "restore changed atime from $atime0 to $atime1"
2090 [ $mtime0 -eq $mtime1 ] ||
2091 error "restore changed mtime from $mtime0 to $mtime1"
2093 [ $ctime0 -eq $ctime1 ] ||
2094 error "restore changed ctime from $ctime0 to $ctime1"
2098 # Once more, after unmount and mount.
2099 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2100 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2102 atime1=$(stat -c "%X" $file)
2103 mtime1=$(stat -c "%Y" $file)
2104 ctime1=$(stat -c "%Z" $file)
2106 [ $atime0 -eq $atime1 ] ||
2107 error "remount changed atime from $atime0 to $atime1"
2109 [ $mtime0 -eq $mtime1 ] ||
2110 error "remount changed mtime from $mtime0 to $mtime1"
2112 [ $ctime0 -eq $ctime1 ] ||
2113 error "remount changed ctime from $ctime0 to $ctime1"
2115 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2118 local file=$DIR/$tdir/$tfile
2124 # Test needs a running copytool.
2127 # Check that root can do HSM actions on a regular user's file.
2128 fid=$(create_small_file $file)
2129 sum0=$(md5sum $file)
2131 chown $RUNAS_ID:$RUNAS_GID $file ||
2132 error "cannot chown '$file' to '$RUNAS_ID'"
2134 chmod ugo-w $DIR/$tdir ||
2135 error "cannot chmod '$DIR/$tdir'"
2137 $LFS hsm_archive $file
2138 wait_request_state $fid ARCHIVE SUCCEED
2140 $LFS hsm_release $file
2141 check_hsm_flags $file "0x0000000d"
2143 $LFS hsm_restore $file
2144 wait_request_state $fid RESTORE SUCCEED
2146 # Check that ordinary user can get HSM state.
2147 $RUNAS $LFS hsm_state $file ||
2148 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2150 $LFS hsm_release $file
2151 check_hsm_flags $file "0x0000000d"
2153 # Check that ordinary user can accessed released file.
2154 sum1=$($RUNAS md5sum $file) ||
2155 error "user '$RUNAS_ID' cannot read '$file'"
2157 [ "$sum0" == "$sum1" ] ||
2158 error "md5sum mismatch for '$file'"
2162 run_test 24b "root can archive, release, and restore user files"
2164 cleanup_test_24c() {
2166 set_hsm_param user_request_mask RESTORE
2167 set_hsm_param group_request_mask RESTORE
2168 set_hsm_param other_request_mask RESTORE
2172 local file=$DIR/$tdir/$tfile
2173 local action=archive
2178 # test needs a running copytool
2183 # Save the default masks and check that cleanup_24c will
2184 # restore the request masks correctly.
2185 user_save=$(get_hsm_param user_request_mask)
2186 group_save=$(get_hsm_param group_request_mask)
2187 other_save=$(get_hsm_param other_request_mask)
2189 [ "$user_save" == RESTORE ] ||
2190 error "user_request_mask is '$user_save' expected 'RESTORE'"
2191 [ "$group_save" == RESTORE ] ||
2192 error "group_request_mask is '$group_save' expected 'RESTORE'"
2193 [ "$other_save" == RESTORE ] ||
2194 error "other_request_mask is '$other_save' expected 'RESTORE'"
2196 trap cleanup_test_24c EXIT
2199 create_small_file $file
2200 chown $RUNAS_ID:nobody $file ||
2201 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2203 $RUNAS $LFS hsm_$action $file &&
2204 error "$action by user should fail"
2206 set_hsm_param user_request_mask $action
2207 $RUNAS $LFS hsm_$action $file ||
2208 error "$action by user should succeed"
2211 create_small_file $file
2212 chown nobody:$RUNAS_GID $file ||
2213 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2215 $RUNAS $LFS hsm_$action $file &&
2216 error "$action by group should fail"
2218 set_hsm_param group_request_mask $action
2219 $RUNAS $LFS hsm_$action $file ||
2220 error "$action by group should succeed"
2223 create_small_file $file
2224 chown nobody:nobody $file ||
2225 error "cannot chown '$file' to 'nobody:nobody'"
2227 $RUNAS $LFS hsm_$action $file &&
2228 error "$action by other should fail"
2230 set_hsm_param other_request_mask $action
2231 $RUNAS $LFS hsm_$action $file ||
2232 error "$action by other should succeed"
2237 run_test 24c "check that user,group,other request masks work"
2239 cleanup_test_24d() {
2240 mount -o remount,rw $MOUNT2
2241 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2245 local file1=$DIR/$tdir/$tfile
2246 local file2=$DIR2/$tdir/$tfile
2250 fid1=$(create_small_file $file1)
2253 $LFS getstripe $file1
2255 trap cleanup_test_24d EXIT
2256 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2257 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2258 copytool_setup $SINGLEAGT "$MOUNT3" ||
2259 error "unable to setup a copytool for the test"
2261 mount -o remount,ro $MOUNT2
2263 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2265 fid2=$(path2fid $file2)
2266 [ "$fid1" == "$fid2" ] ||
2267 error "FID mismatch '$fid1' != '$fid2'"
2269 $LFS hsm_archive $file2 &&
2270 error "archive should fail on read-only mount"
2271 check_hsm_flags $file1 "0x00000000"
2273 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2274 wait_request_state $fid1 ARCHIVE SUCCEED
2276 $LFS hsm_release $file1
2277 $LFS hsm_restore $file2
2278 wait_request_state $fid1 RESTORE SUCCEED
2280 $LFS hsm_release $file1 || error "cannot release '$file1'"
2281 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2283 $LFS hsm_release $file2 &&
2284 error "release should fail on read-only mount"
2288 run_test 24d "check that read-only mounts are respected"
2293 local f=$DIR/$tdir/$tfile
2296 fid=$(create_small_file $f) || error "cannot create $f"
2297 $LFS hsm_archive $f || error "cannot archive $f"
2298 wait_request_state $fid ARCHIVE SUCCEED
2299 $LFS hsm_release $f || error "cannot release $f"
2300 while ! $LFS hsm_state $f | grep released; do
2304 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2308 run_test 24e "tar succeeds on HSM released files" # LU-6213
2312 # test needs a running copytool
2315 mkdir -p $DIR/$tdir/d1
2316 local f=$DIR/$tdir/$tfile
2317 local fid=$(copy_file /etc/hosts $f)
2320 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2321 error "hsm_archive failed"
2322 wait_request_state $fid ARCHIVE SUCCEED
2323 $LFS hsm_release $f || error "cannot release $f"
2324 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2327 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2328 error "Can not recover the tar contents"
2330 echo "Sum0 = $sum0, sum1 = $sum1"
2331 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2335 run_test 24f "root can archive, release, and restore tar files"
2338 # test needs a running copytool
2342 copy2archive /etc/hosts $tdir/$tfile
2344 local f=$DIR/$tdir/$tfile
2346 import_file $tdir/$tfile $f
2348 $LFS hsm_set --lost $f
2353 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2357 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2358 " (Operation not permitted)"
2361 # test needs a running copytool
2366 local f=$DIR/$tdir/$tfile
2367 local fid=$(copy_file /etc/passwd $f)
2369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2370 wait_request_state $fid ARCHIVE SUCCEED
2373 $LFS hsm_set --lost $f
2377 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2381 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2382 " (Operation not permitted)"
2385 # test needs a running copytool
2388 local f=$DIR/$tdir/$tfile
2390 fid=$(make_custom_file_for_progress $f 39 1000000)
2391 [ $? != 0 ] && skip "not enough free space" && return
2393 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2394 wait_request_state $fid ARCHIVE SUCCEED
2397 wait_request_state $fid REMOVE SUCCEED
2399 check_hsm_flags $f "0x00000000"
2403 run_test 26 "Remove the archive of a valid file"
2405 cleanup_test_26a() {
2407 set_hsm_param remove_archive_on_last_unlink 0
2408 set_hsm_param loop_period $orig_loop_period
2409 set_hsm_param grace_delay $orig_grace_delay
2414 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2415 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2417 # test needs a running copytool
2421 local f=$DIR/$tdir/$tfile
2422 local fid=$(copy_file /etc/passwd $f)
2424 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2425 wait_request_state $fid ARCHIVE SUCCEED
2427 local f2=$DIR/$tdir/${tfile}_2
2428 local fid2=$(copy_file /etc/passwd $f2)
2430 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2431 wait_request_state $fid2 ARCHIVE SUCCEED
2433 local f3=$DIR/$tdir/${tfile}_3
2434 local fid3=$(copy_file /etc/passwd $f3)
2436 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2437 wait_request_state $fid3 ARCHIVE SUCCEED
2439 trap cleanup_test_26a EXIT
2441 # set a long grace_delay vs short loop_period
2442 local orig_loop_period=$(get_hsm_param loop_period)
2443 local orig_grace_delay=$(get_hsm_param grace_delay)
2444 set_hsm_param loop_period 10
2445 set_hsm_param grace_delay 100
2449 set_hsm_param remove_archive_on_last_unlink 1
2451 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2456 set_hsm_param remove_archive_on_last_unlink 0
2458 wait_request_state $fid2 REMOVE SUCCEED
2460 assert_request_count $fid REMOVE 0 \
2461 "Unexpected archived data remove request for $f"
2462 assert_request_count $fid3 REMOVE 0 \
2463 "Unexpected archived data remove request for $f3"
2467 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2469 cleanup_test_26b() {
2471 set_hsm_param remove_archive_on_last_unlink 0
2477 # test needs a running copytool
2481 local f=$DIR/$tdir/$tfile
2482 local fid=$(copy_file /etc/passwd $f)
2484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2485 wait_request_state $fid ARCHIVE SUCCEED
2487 trap cleanup_test_26b EXIT
2489 set_hsm_param remove_archive_on_last_unlink 1
2492 cdt_check_state stopped
2496 set_hsm_param remove_archive_on_last_unlink 0
2498 wait_request_state $fid REMOVE WAITING
2501 # copytool must re-register
2503 wait_copytools || error "copytool failed to stop"
2504 HSM_ARCHIVE_PURGE=false copytool_setup
2506 wait_request_state $fid REMOVE SUCCEED
2510 run_test 26b "RAoLU policy when CDT off"
2512 cleanup_test_26c() {
2514 set_hsm_param remove_archive_on_last_unlink 0
2515 set_hsm_param loop_period $orig_loop_period
2516 set_hsm_param grace_delay $orig_grace_delay
2522 # test needs a running copytool
2526 local f=$DIR/$tdir/$tfile
2527 local fid=$(copy_file /etc/passwd $f)
2529 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2530 wait_request_state $fid ARCHIVE SUCCEED
2532 local f2=$DIR/$tdir/${tfile}_2
2533 local fid2=$(copy_file /etc/passwd $f2)
2535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2536 wait_request_state $fid2 ARCHIVE SUCCEED
2538 trap cleanup_test_26c EXIT
2540 # set a long grace_delay vs short loop_period
2541 local orig_loop_period=$(get_hsm_param loop_period)
2542 local orig_grace_delay=$(get_hsm_param grace_delay)
2543 set_hsm_param loop_period 10
2544 set_hsm_param grace_delay 100
2546 set_hsm_param remove_archive_on_last_unlink 1
2548 multiop_bg_pause $f O_c || error "open $f failed"
2554 wait_request_state $fid2 REMOVE SUCCEED
2555 assert_request_count $fid REMOVE 0 \
2556 "Unexpected archived data remove request for $f"
2558 kill -USR1 $pid || error "multiop early exit"
2559 # should reach autotest timeout if multiop fails to trap
2560 # signal, close file, and exit ...
2563 set_hsm_param remove_archive_on_last_unlink 0
2565 wait_request_state $fid REMOVE SUCCEED
2569 run_test 26c "RAoLU effective when file closed"
2571 cleanup_test_26d() {
2573 set_hsm_param remove_archive_on_last_unlink 0
2574 set_hsm_param loop_period $orig_loop_period
2575 set_hsm_param grace_delay $orig_grace_delay
2581 # test needs a running copytool
2585 local f=$DIR/$tdir/$tfile
2586 local fid=$(copy_file /etc/motd $f 1)
2588 $LFS hsm_archive $f || error "could not archive file"
2589 wait_request_state $fid ARCHIVE SUCCEED
2591 trap cleanup_test_26d EXIT
2593 # set a long grace_delay vs short loop_period
2594 local orig_loop_period=$(get_hsm_param loop_period)
2595 local orig_grace_delay=$(get_hsm_param grace_delay)
2596 set_hsm_param loop_period 10
2597 set_hsm_param grace_delay 100
2599 set_hsm_param remove_archive_on_last_unlink 1
2601 multiop_bg_pause $f O_c || error "multiop failed"
2608 set_hsm_param remove_archive_on_last_unlink 0
2610 wait_request_state $fid REMOVE SUCCEED
2612 client_up || client_up || true
2614 kill -USR1 $MULTIPID
2615 wait $MULTIPID || error "multiop close failed"
2619 run_test 26d "RAoLU when Client eviction"
2622 # test needs a running copytool
2625 create_archive_file $tdir/$tfile
2626 local f=$DIR/$tdir/$tfile
2627 import_file $tdir/$tfile $f
2628 local fid=$(path2fid $f)
2632 [[ $? != 0 ]] || error "Remove of a released file should fail"
2636 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2639 # test needs a running copytool
2642 local f=$DIR/$tdir/$tfile
2644 fid=$(make_custom_file_for_progress $f 39 1000000)
2645 [ $? != 0 ] && skip "not enough free space" && return
2647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2648 wait_request_state $fid ARCHIVE SUCCEED
2653 [[ $? != 0 ]] || error "Remove of a released file should fail"
2657 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2660 # test needs a running copytool
2663 local f=$DIR/$tdir/$tfile
2665 fid=$(make_custom_file_for_progress $f 39 1000000)
2666 [ $? != 0 ] && skip "not enough free space" && return
2668 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2669 wait_request_state $fid ARCHIVE SUCCEED
2678 wait_request_state $fid REMOVE SUCCEED
2682 run_test 28 "Concurrent archive/file remove"
2685 # Tests --mntpath and --archive options
2688 copytool_setup $SINGLEAGT $MOUNT $archive_id
2690 # Bad archive number
2691 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2692 grep "Invalid argument" ||
2693 error "unexpected hsm_remove failure (1)"
2695 # mntpath is present but file is given
2696 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2697 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2698 error "unexpected hsm_remove failure (2)"
2702 run_test 29a "Tests --mntpath and --archive options"
2705 # test needs a running copytool
2708 local f=$DIR/$tdir/$tfile
2709 local fid=$(create_small_file $f)
2711 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2712 wait_request_state $fid ARCHIVE SUCCEED
2716 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2717 wait_request_state $fid REMOVE SUCCEED
2721 run_test 29b "Archive/delete/remove by FID from the archive."
2724 # test needs a running copytool
2727 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2728 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2729 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2731 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2732 wait_request_state $fid1 ARCHIVE SUCCEED
2733 wait_request_state $fid2 ARCHIVE SUCCEED
2734 wait_request_state $fid3 ARCHIVE SUCCEED
2736 rm -f $DIR/$tdir/$tfile-[1-3]
2738 echo $fid1 > $DIR/$tdir/list
2739 echo $fid2 >> $DIR/$tdir/list
2740 echo $fid3 >> $DIR/$tdir/list
2742 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2743 --filelist $DIR/$tdir/list
2744 wait_request_state $fid1 REMOVE SUCCEED
2745 wait_request_state $fid2 REMOVE SUCCEED
2746 wait_request_state $fid3 REMOVE SUCCEED
2750 run_test 29c "Archive/delete/remove by FID, using a file list."
2753 # test needs more than one CT
2754 needclients 3 || return 0
2760 copytool_cleanup $(comma_list $(agts_nodes))
2762 # start all of the copytools
2763 for n in $(seq $AGTCOUNT); do
2764 copytool_setup agt$n $MOUNT2 $n
2767 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2769 file=$DIR/$tdir/$tfile
2770 fid=$(create_small_file $file)
2772 $LFS hsm_archive $file
2773 wait_request_state $fid ARCHIVE SUCCEED
2774 check_hsm_flags $file "0x00000009"
2778 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2779 error "cannot hsm_remove '$fid'"
2781 # give time for CDT to handle remove request and create broadcasted
2784 # remove request has been broadcasted ?
2785 local cnt=$(get_request_count $fid REMOVE)
2786 # broadcasted requests + original
2787 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2788 error "remove not broadcasted to all CTs"
2790 # give time for CDT and CTs to handle broadcasted
2791 wait_for_loop_period
2793 # each agent serves one different archive_id, so broadcasted
2794 # hsm_remove request should only succeed once and fail at all others
2798 for n in $(seq $AGTCOUNT); do
2799 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2800 $HSM_PARAM.actions | awk \
2801 '/'$fid'.*action=REMOVE archive#='$n'/ \
2802 {print \\\$13}' | cut -f2 -d=")
2803 if [[ "$res" == "SUCCEED" ]]; then
2805 elif [[ "$res" == "FAILED" ]]; then
2810 [[ $scnt -ne 1 ]] &&
2811 error "one and only CT should have removed successfully"
2813 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2814 error "all but one CT should have failed to remove"
2817 copytool_cleanup $(comma_list $(agts_nodes))
2820 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2821 "request to be sent once for each registered archive_id"
2824 # restore at exec cannot work on agent node (because of Linux kernel
2825 # protection of executables)
2826 needclients 2 || return 0
2828 # test needs a running copytool
2832 copy2archive /bin/true $tdir/$tfile
2834 local f=$DIR/$tdir/true
2835 import_file $tdir/$tfile $f
2837 local fid=$(path2fid $f)
2839 # set no retry action mode
2845 # remove no try action mode
2849 [[ $st == 0 ]] || error "Failed to exec a released file"
2853 run_test 30a "Restore at exec (import case)"
2856 # restore at exec cannot work on agent node (because of Linux kernel
2857 # protection of executables)
2858 needclients 2 || return 0
2860 # test needs a running copytool
2864 local f=$DIR/$tdir/true
2865 local fid=$(copy_file /bin/true $f)
2867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2868 wait_request_state $fid ARCHIVE SUCCEED
2871 # set no retry action mode
2877 # remove no try action mode
2881 [[ $st == 0 ]] || error "Failed to exec a released file"
2885 run_test 30b "Restore at exec (release case)"
2888 needclients 2 || return 0
2890 # test needs a running copytool
2894 local f=$DIR/$tdir/SLEEP
2895 local slp_sum1=$(md5sum /bin/sleep)
2896 local fid=$(copy_file /bin/sleep $f)
2898 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2899 wait_request_state $fid ARCHIVE SUCCEED
2901 check_hsm_flags $f "0x0000000d"
2902 # set no retry action mode
2904 do_node $CLIENT2 "$f 10" &
2908 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2910 [[ $? == 0 ]] || error "Execution failed during run"
2912 if [[ $? != 0 ]]; then
2913 local slp_sum2=$(md5sum /bin/sleep)
2914 # in case sleep file is modified during the test
2915 [[ $slp_sum1 == $slp_sum2 ]] &&
2916 error "Binary overwritten during exec"
2920 # remove no try action mode
2922 check_hsm_flags $f "0x00000009"
2926 run_test 30c "Update during exec of released file must fail"
2928 restore_and_check_size() {
2931 local s=$(stat -c "%s" $f)
2933 local st=$(get_hsm_flags $f)
2937 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2939 n=$(stat -c "%s" $f)
2940 # we echo in both cases to show stat is not hang
2941 if [[ $n != $s ]]; then
2942 echo "size seen is $n != $s"
2945 echo "size seen is right: $n == $s"
2949 st=$(get_hsm_flags $f)
2951 if [[ "$st" = "0x00000009" ]]; then
2954 echo " restore is too long"
2955 wait_request_state $fid RESTORE SUCCEED
2961 # test needs a running copytool
2964 create_archive_file $tdir/$tfile
2965 local f=$DIR/$tdir/$tfile
2966 import_file $tdir/$tfile $f
2967 local fid=$($LFS path2fid $f)
2968 HSM_ARCHIVE_PURGE=false copytool_setup
2970 restore_and_check_size $f $fid
2973 [[ $err -eq 0 ]] || error "File size changed during restore"
2977 run_test 31a "Import a large file and check size during restore"
2981 # test needs a running copytool
2984 local f=$DIR/$tdir/$tfile
2986 fid=$(make_custom_file_for_progress $f 39 1000000)
2987 [ $? != 0 ] && skip "not enough free space" && return
2989 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2990 wait_request_state $fid ARCHIVE SUCCEED
2993 restore_and_check_size $f $fid
2996 [[ $err -eq 0 ]] || error "File size changed during restore"
3000 run_test 31b "Restore a large unaligned file and check size during restore"
3003 # test needs a running copytool
3006 local f=$DIR/$tdir/$tfile
3008 fid=$(make_custom_file_for_progress $f 33 1048576)
3009 [ $? != 0 ] && skip "not enough free space" && return
3011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3012 wait_request_state $fid ARCHIVE SUCCEED
3015 restore_and_check_size $f $fid
3018 [[ $err -eq 0 ]] || error "File size changed during restore"
3022 run_test 31c "Restore a large aligned file and check size during restore"
3025 # test needs a running copytool
3028 local f=$DIR/$tdir/$tfile
3030 fid=$(make_custom_file_for_progress $f 39 1000000)
3031 [ $? != 0 ] && skip "not enough free space" && return
3033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3034 wait_request_state $fid ARCHIVE SUCCEED
3037 # to be sure wait_all_done will not be mislead by previous tests
3040 wait_for_grace_delay
3041 # Also raise grace_delay significantly so the Canceled
3042 # Restore action will stay enough long avail.
3043 local old_grace=$(get_hsm_param grace_delay)
3044 set_hsm_param grace_delay 100
3046 md5sum $f >/dev/null &
3048 wait_request_state $fid RESTORE STARTED
3053 # Check restore trigger process was killed
3054 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3058 # instead of waiting+checking both Restore and Cancel ops
3059 # sequentially, wait for both to be finished and then check
3061 wait_all_done 100 $fid
3062 local rstate=$(get_request_state $fid RESTORE)
3063 local cstate=$(get_request_state $fid CANCEL)
3065 # restore orig grace_delay.
3066 set_hsm_param grace_delay $old_grace
3068 if [[ "$rstate" == "CANCELED" ]] ; then
3069 [[ "$cstate" == "SUCCEED" ]] ||
3070 error "Restore state is CANCELED and Cancel state " \
3071 "is not SUCCEED but $cstate"
3072 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3073 elif [[ "$rstate" == "SUCCEED" ]] ; then
3074 [[ "$cstate" == "FAILED" ]] ||
3075 error "Restore state is SUCCEED and Cancel state " \
3076 "is not FAILED but $cstate"
3077 echo "Restore state is SUCCEED, Cancel state is FAILED"
3079 error "Restore state is $rstate and Cancel state is $cstate"
3083 error "Cannot kill process waiting for restore ($killed)"
3087 run_test 33 "Kill a restore waiting process"
3090 # test needs a running copytool
3093 local f=$DIR/$tdir/$tfile
3095 fid=$(make_custom_file_for_progress $f 39 1000000)
3096 [ $? != 0 ] && skip "not enough free space" && return
3098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3099 wait_request_state $fid ARCHIVE SUCCEED
3102 md5sum $f >/dev/null &
3104 wait_request_state $fid RESTORE STARTED
3106 rm $f || error "rm $f failed"
3107 # rm must not block during restore
3108 wait_request_state $fid RESTORE STARTED
3110 wait_request_state $fid RESTORE SUCCEED
3111 # check md5sum pgm finished
3112 local there=$(ps -o pid,comm hp $pid >/dev/null)
3113 [[ -z $there ]] || error "Restore initiator does not exit"
3115 wait $pid || error "Restore initiator failed with $?"
3119 run_test 34 "Remove file during restore"
3122 # test needs a running copytool
3125 local f=$DIR/$tdir/$tfile
3126 local f1=$DIR/$tdir/$tfile-1
3128 fid=$(make_custom_file_for_progress $f 39 1000000)
3129 [ $? != 0 ] && skip "not enough free space" && return
3131 local fid1=$(copy_file /etc/passwd $f1)
3132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3133 wait_request_state $fid ARCHIVE SUCCEED
3136 md5sum $f >/dev/null &
3138 wait_request_state $fid RESTORE STARTED
3140 mv $f1 $f || error "mv $f1 $f failed"
3141 # mv must not block during restore
3142 wait_request_state $fid RESTORE STARTED
3144 wait_request_state $fid RESTORE SUCCEED
3145 # check md5sum pgm finished
3146 local there=$(ps -o pid,comm hp $pid >/dev/null)
3147 [[ -z $there ]] || error "Restore initiator does not exit"
3149 wait $pid || error "Restore initiator failed with $?"
3152 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3156 run_test 35 "Overwrite file during restore"
3159 # test needs a running copytool
3162 local f=$DIR/$tdir/$tfile
3164 fid=$(make_custom_file_for_progress $f 39 1000000)
3165 [ $? != 0 ] && skip "not enough free space" && return
3167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3168 wait_request_state $fid ARCHIVE SUCCEED
3171 md5sum $f >/dev/null &
3173 wait_request_state $fid RESTORE STARTED
3176 # rm must not block during restore
3177 wait_request_state $fid RESTORE STARTED
3179 wait_request_state $fid RESTORE SUCCEED
3180 # check md5sum pgm finished
3181 local there=$(ps -o pid,comm hp $pid >/dev/null)
3183 error "Restore initiator does not exit"
3185 wait $pid || error "Restore initiator failed with $?"
3189 run_test 36 "Move file during restore"
3192 # LU-5683: check that an archived dirty file can be rearchived.
3194 copytool_setup $SINGLEAGT $MOUNT2
3196 local f=$DIR/$tdir/$tfile
3199 fid=$(create_small_file $f) || error "cannot create small file"
3201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3202 wait_request_state $fid ARCHIVE SUCCEED
3203 $LFS hsm_release $f || error "cannot release $f"
3205 # Allow previous archive request to expire from the actions log.
3206 wait_for_grace_delay
3209 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3212 wait_request_state $fid ARCHIVE SUCCEED
3216 run_test 37 "re-archive a dirty file"
3223 for n in $(seq 1 $count); do
3224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3226 echo "$count archive requests submitted"
3231 set_hsm_param max_requests $max_requests
3236 local stream_count=4
3237 local file_count=100
3239 local f=$DIR/$tdir/$tfile
3243 local max_requests=$(get_hsm_param max_requests)
3245 # Increase the number of HSM request that can be performed in
3246 # parallel. With the coordinator running once per second, this
3247 # also limits the number of requests per seconds that can be
3248 # performed, so we pick a decent number. But we also need to keep
3249 # that number low because the copytool has no rate limit and will
3250 # fail some requests if if gets too many at once.
3251 set_hsm_param max_requests 300
3253 trap cleanup_test_40 EXIT
3255 for i in $(seq 1 $file_count); do
3256 for p in $(seq 1 $stream_count); do
3257 fid=$(copy_file /etc/hosts $f.$p.$i)
3260 # force copytool to use a local/temp archive dir to ensure best
3261 # performance vs remote/NFS mounts used in auto-tests
3262 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3265 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3267 # to be sure wait_all_done will not be mislead by previous tests
3269 wait_for_grace_delay
3271 # start archive streams in background (archive files in parallel)
3272 for p in $(seq 1 $stream_count); do
3273 multi_archive $f.$p $file_count &
3276 echo -n "Wait for all requests being enqueued..."
3283 run_test 40 "Parallel archive requests"
3286 # test needs a running copytool
3290 local f=$DIR/$tdir/$tfile
3291 local fid=$(copy_file /etc/motd $f 1)
3293 $LFS hsm_archive $f || error "could not archive file"
3294 wait_request_state $fid ARCHIVE SUCCEED
3295 check_hsm_flags $f "0x00000009"
3297 multiop_bg_pause $f O_c || error "multiop failed"
3301 client_up || client_up || true
3303 kill -USR1 $MULTIPID
3304 wait $MULTIPID || error "multiop close failed"
3306 check_hsm_flags $f "0x0000000b"
3310 run_test 52 "Opened for write file on an evicted client should be set dirty"
3313 # test needs a running copytool
3317 local f=$DIR/$tdir/$tfile
3318 local fid=$(copy_file /etc/motd $f 1)
3320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3321 error "could not archive file"
3322 wait_request_state $fid ARCHIVE SUCCEED
3323 check_hsm_flags $f "0x00000009"
3325 multiop_bg_pause $f o_c || error "multiop failed"
3329 client_up || client_up || true
3331 kill -USR1 $MULTIPID
3332 wait $MULTIPID || error "multiop close failed"
3334 check_hsm_flags $f "0x00000009"
3338 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3341 # test needs a running copytool
3344 local f=$DIR/$tdir/$tfile
3345 local fid=$(make_custom_file_for_progress $f 39 1000000)
3347 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3348 error "could not archive file"
3349 wait_request_state $fid ARCHIVE STARTED
3351 check_hsm_flags $f "0x00000001"
3353 # Avoid coordinator resending this request as soon it has failed.
3358 wait_request_state $fid ARCHIVE FAILED
3360 check_hsm_flags $f "0x00000003"
3365 run_test 54 "Write during an archive cancels it"
3368 # test needs a running copytool
3371 local f=$DIR/$tdir/$tfile
3372 local fid=$(make_custom_file_for_progress $f 39 1000000)
3374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3375 error "could not archive file"
3376 wait_request_state $fid ARCHIVE STARTED
3378 check_hsm_flags $f "0x00000001"
3380 # Avoid coordinator resending this request as soon it has failed.
3383 $TRUNCATE $f 1024 || error "truncate failed"
3385 wait_request_state $fid ARCHIVE FAILED
3387 check_hsm_flags $f "0x00000003"
3392 run_test 55 "Truncate during an archive cancels it"
3395 # test needs a running copytool
3398 local f=$DIR/$tdir/$tfile
3400 fid=$(make_custom_file_for_progress $f 39 1000000)
3401 [ $? != 0 ] && skip "not enough free space" && return
3403 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3404 error "could not archive file"
3405 wait_request_state $fid ARCHIVE STARTED
3407 check_hsm_flags $f "0x00000001"
3409 # Change metadata and sync to be sure we are not changing only
3414 wait_request_state $fid ARCHIVE SUCCEED
3416 check_hsm_flags $f "0x00000009"
3420 run_test 56 "Setattr during an archive is ok"
3423 # Need one client for I/O, one for request
3424 needclients 2 || return 0
3426 # test needs a running copytool
3430 local f=$DIR/$tdir/test_archive_remote
3431 # Create a file on a remote node
3432 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3433 "count=2 conv=fsync"
3436 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3437 error "hsm_archive failed"
3438 local fid=$(path2fid $f)
3439 wait_request_state $fid ARCHIVE SUCCEED
3441 # Release and implicit restore it
3442 do_node $CLIENT2 "$LFS hsm_release $f" ||
3443 error "hsm_release failed"
3444 do_node $CLIENT2 "md5sum $f" ||
3445 error "hsm_restore failed"
3447 wait_request_state $fid RESTORE SUCCEED
3451 run_test 57 "Archive a file with dirty cache on another node"
3453 truncate_released_file() {
3457 local sz=$(stat -c %s $src_file)
3458 local f=$DIR/$tdir/$tfile
3459 local fid=$(copy_file $1 $f)
3463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3464 error "could not archive file"
3465 wait_request_state $fid ARCHIVE SUCCEED
3467 $LFS hsm_release $f || error "could not release file"
3469 $TRUNCATE $f $trunc_to || error "truncate failed"
3472 local sz1=$(stat -c %s $f)
3473 [[ $sz1 == $trunc_to ]] ||
3474 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3477 check_hsm_flags $f "0x0000000b"
3479 local state=$(get_request_state $fid RESTORE)
3480 [[ "$state" == "SUCCEED" ]] ||
3481 error "truncate $sz does not trig restore, state = $state"
3483 $TRUNCATE $ref $trunc_to
3484 cmp $ref $f || error "file data wrong after truncate"
3490 # test needs a running copytool
3495 local sz=$(stat -c %s /etc/passwd)
3497 echo "truncate up from $sz to $((sz*2))"
3498 truncate_released_file /etc/passwd $((sz*2))
3500 echo "truncate down from $sz to $((sz/2))"
3501 truncate_released_file /etc/passwd $((sz/2))
3503 echo "truncate to 0"
3504 truncate_released_file /etc/passwd 0
3508 run_test 58 "Truncate a released file will trigger restore"
3512 local server_version=$(lustre_version_code $SINGLEMDS)
3513 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3514 skip "Need MDS version at least 2.7.63" && return
3517 $MCREATE $DIR/$tfile || error "mcreate failed"
3518 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3519 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3520 fid=$(path2fid $DIR/$tfile)
3521 wait_request_state $fid ARCHIVE SUCCEED
3522 $LFS hsm_release $DIR/$tfile || error "release failed"
3525 run_test 59 "Release stripeless file with non-zero size"
3528 # This test validates the fix for LU-4512. Ensure that the -u
3529 # option changes the progress reporting interval from the
3530 # default (30 seconds) to the user-specified interval.
3532 local progress_timeout=$((interval * 4))
3534 # test needs a new running copytool
3536 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3538 local f=$DIR/$tdir/$tfile
3540 fid=$(make_custom_file_for_progress $f 10)
3541 [ $? != 0 ] && skip "not enough free space" && return
3544 local mdt=${MDT_PREFIX}${mdtidx}
3545 local mds=mds$((mdtidx + 1))
3547 # Wait for copytool to register
3548 wait_update_facet $mds \
3549 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3550 uuid 100 || error "coyptool failed to register with $mdt"
3552 local start_at=$(date +%s)
3553 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3554 error "could not archive file"
3556 local agent=$(facet_active_host $SINGLEAGT)
3557 local prefix=$TESTLOG_PREFIX
3558 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3559 local copytool_log=$prefix.copytool_log.$agent.log
3562 wait_update $agent \
3563 "grep -o start.copy $copytool_log" "start copy" 100 ||
3564 error "copytool failed to start"
3566 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3567 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3573 echo -n "Expecting a progress update within $progress_timeout seconds... "
3575 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3576 if [ $RESULT -gt 0 ]; then
3577 echo "$RESULT bytes copied in $WAIT seconds."
3579 elif [ $WAIT -ge $progress_timeout ]; then
3580 error "Timed out waiting for progress update!"
3583 WAIT=$((WAIT + sleep))
3587 local finish_at=$(date +%s)
3588 local elapsed=$((finish_at - start_at))
3590 # Ensure that the progress update occurred within the expected window.
3591 if [ $elapsed -lt $((interval - 1)) ]; then
3592 error "Expected progress update after at least $interval seconds"
3595 echo "Wait for on going archive hsm action to complete"
3596 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3597 echo "File archiving not completed even after 10 secs"
3602 run_test 60 "Changing progress update interval from default"
3605 # test needs a running copytool
3609 local f=$DIR/$tdir/$tfile
3610 local fid=$(copy_file /etc/passwd $f)
3612 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3615 wait_request_state $fid ARCHIVE FAILED
3619 run_test 61 "Waiting archive of a removed file should fail"
3622 local agent=$(facet_active_host $SINGLEAGT)
3627 local f=$DIR/$tdir/$tfile
3629 fid=$(make_custom_file_for_progress $f 20)
3630 [ $? != 0 ] && skip "not enough free space" && return
3632 local file_hash_before_archive=$(md5sum $f)
3634 wait_request_state $fid ARCHIVE SUCCEED
3637 # Run md5sum in the back ground
3639 wait_request_state $fid RESTORE STARTED
3641 # Kill copytool while md5sum is running
3642 kill_copytools $agent
3643 wait_copytools $agent || error "copytools failed to stop"
3645 echo "Copytool is stopped on $agent"
3647 wait_request_state $fid RESTORE CANCELED
3649 HSM_ARCHIVE_PURGE=false copytool_setup
3650 # md5sum triggers hsm_restore action
3651 local file_hash_after_archive=$(md5sum $f)
3652 wait_request_state $fid RESTORE SUCCEED
3654 [ "$file_hash_before_archive" = \
3655 "$file_hash_after_archive" ] ||
3656 error "Restore incomplete"
3660 run_test 62 "Stopping a copytool should cancel its requests"
3663 # test needs a new running copytool
3665 copytool_monitor_setup
3666 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3668 # Just start and stop the copytool to generate events.
3671 # Wait for the copytool to register.
3672 wait_update --verbose $(facet_active_host mds1) \
3673 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3675 error "copytool failed to register with MDT0000"
3679 local REGISTER_EVENT
3680 local UNREGISTER_EVENT
3681 while read event; do
3682 local parsed=$(parse_json_event "$event")
3683 if [ -z "$parsed" ]; then
3684 error "Copytool sent malformed event: $event"
3688 if [ $event_type == "REGISTER" ]; then
3689 REGISTER_EVENT=$event
3690 elif [ $event_type == "UNREGISTER" ]; then
3691 UNREGISTER_EVENT=$event
3693 done < <(echo $"$(get_copytool_event_log)")
3695 if [ -z "$REGISTER_EVENT" ]; then
3696 error "Copytool failed to send register event to FIFO"
3699 if [ -z "$UNREGISTER_EVENT" ]; then
3700 error "Copytool failed to send unregister event to FIFO"
3703 copytool_monitor_cleanup
3704 echo "Register/Unregister events look OK."
3706 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3709 # Bump progress interval for livelier events.
3712 # test needs a new running copytool
3714 copytool_monitor_setup
3715 HSMTOOL_UPDATE_INTERVAL=$interval \
3716 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3718 local f=$DIR/$tdir/$tfile
3720 fid=$(make_custom_file_for_progress $f 39 1000000)
3721 [ $? != 0 ] && skip "not enough free space" && return
3723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3724 error "could not archive file"
3725 wait_request_state $fid ARCHIVE SUCCEED
3727 local expected_fields="event_time data_fid source_fid"
3728 expected_fields+=" total_bytes current_bytes"
3732 while read event; do
3733 # Make sure we're not getting anything from previous events.
3734 for field in $expected_fields; do
3738 local parsed=$(parse_json_event "$event")
3739 if [ -z "$parsed" ]; then
3740 error "Copytool sent malformed event: $event"
3744 if [ $event_type == "ARCHIVE_START" ]; then
3747 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3750 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3754 # Do some simple checking of the progress update events.
3755 for expected_field in $expected_fields; do
3756 if [ -z ${!expected_field+x} ]; then
3757 error "Missing $expected_field field in event"
3761 if [ $total_bytes -eq 0 ]; then
3762 error "Expected total_bytes to be > 0"
3765 # These should be identical throughout an archive
3767 if [ $source_fid != $data_fid ]; then
3768 error "Expected source_fid to equal data_fid"
3770 done < <(echo $"$(get_copytool_event_log)")
3772 if [ -z "$START_EVENT" ]; then
3773 error "Copytool failed to send archive start event to FIFO"
3776 if [ -z "$FINISH_EVENT" ]; then
3777 error "Copytool failed to send archive finish event to FIFO"
3780 echo "Archive events look OK."
3784 copytool_monitor_cleanup
3786 run_test 71 "Copytool logs JSON archive events to FIFO"
3789 # Bump progress interval for livelier events.
3792 # test needs a new running copytool
3794 copytool_monitor_setup
3795 HSMTOOL_UPDATE_INTERVAL=$interval \
3796 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3797 local test_file=$HSMTOOL_MONITOR_DIR/file
3799 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3801 do_facet $SINGLEAGT "$cmd" ||
3802 error "cannot create $test_file on $SINGLEAGT"
3803 copy2archive $test_file $tdir/$tfile
3806 local f=$DIR/$tdir/$tfile
3807 import_file $tdir/$tfile $f
3808 f=$DIR2/$tdir/$tfile
3809 echo "Verifying released state: "
3810 check_hsm_flags $f "0x0000000d"
3812 local fid=$(path2fid $f)
3814 wait_request_state $fid RESTORE SUCCEED
3816 local expected_fields="event_time data_fid source_fid"
3817 expected_fields+=" total_bytes current_bytes"
3821 while read event; do
3822 # Make sure we're not getting anything from previous events.
3823 for field in $expected_fields; do
3827 local parsed=$(parse_json_event "$event")
3828 if [ -z "$parsed" ]; then
3829 error "Copytool sent malformed event: $event"
3833 if [ $event_type == "RESTORE_START" ]; then
3835 if [ $source_fid != $data_fid ]; then
3836 error "source_fid should == data_fid at start"
3839 elif [ $event_type == "RESTORE_FINISH" ]; then
3841 if [ $source_fid != $data_fid ]; then
3842 error "source_fid should == data_fid at finish"
3845 elif [ $event_type != "RESTORE_RUNNING" ]; then
3849 # Do some simple checking of the progress update events.
3850 for expected_field in $expected_fields; do
3851 if [ -z ${!expected_field+x} ]; then
3852 error "Missing $expected_field field in event"
3856 if [ $total_bytes -eq 0 ]; then
3857 error "Expected total_bytes to be > 0"
3860 # When a restore starts out, the data fid is the same as the
3861 # source fid. After the restore has gotten going, we learn
3862 # the new data fid. Once the restore has finished, the source
3863 # fid is set to the new data fid.
3865 # We test this because some monitoring software may depend on
3866 # this behavior. If it changes, then the consumers of these
3867 # events may need to be modified.
3868 if [ $source_fid == $data_fid ]; then
3869 error "source_fid should != data_fid during restore"
3871 done < <(echo $"$(get_copytool_event_log)")
3873 if [ -z "$START_EVENT" ]; then
3874 error "Copytool failed to send restore start event to FIFO"
3877 if [ -z "$FINISH_EVENT" ]; then
3878 error "Copytool failed to send restore finish event to FIFO"
3881 echo "Restore events look OK."
3885 copytool_monitor_cleanup
3889 run_test 72 "Copytool logs JSON restore events to FIFO"
3892 file_count=51 # Max number of files constrained by LNET message size
3893 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3894 local f=$DIR/$tdir/$tfile
3895 local FILELIST=/tmp/filelist.txt
3899 for i in $(seq 1 $file_count); do
3900 fid=$(copy_file /etc/hosts $f.$i)
3901 echo $f.$i >> $FILELIST
3903 # force copytool to use a local/temp archive dir to ensure best
3904 # performance vs remote/NFS mounts used in auto-tests
3905 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3908 local dai=$(get_hsm_param default_archive_id)
3909 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3911 # to be sure wait_all_done will not be mislead by previous tests
3913 wait_for_grace_delay
3914 $LFS hsm_archive --filelist $FILELIST ||
3915 error "cannot archive a file list"
3917 $LFS hsm_release --filelist $FILELIST ||
3918 error "cannot release a file list"
3919 $LFS hsm_restore --filelist $FILELIST ||
3920 error "cannot restore a file list"
3924 run_test 90 "Archive/restore a file list"
3926 double_verify_reset_hsm_param() {
3928 echo "Testing $HSM_PARAM.$p"
3929 local val=$(get_hsm_param $p)
3931 local val2=$(($val * 2))
3932 set_hsm_param $p $val2
3933 val=$(get_hsm_param $p)
3934 [[ $val == $val2 ]] ||
3935 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3936 echo "Set $p to 0 must failed"
3940 set_hsm_param $p $save
3942 if [[ $rc == 0 ]]; then
3943 error "we must not be able to set $HSM_PARAM.$p to 0"
3948 double_verify_reset_hsm_param loop_period
3949 double_verify_reset_hsm_param grace_delay
3950 double_verify_reset_hsm_param active_request_timeout
3951 double_verify_reset_hsm_param max_requests
3952 double_verify_reset_hsm_param default_archive_id
3954 run_test 100 "Set coordinator /proc tunables"
3961 run_test 102 "Verify coordinator control"
3964 # test needs a running copytool
3971 for i in $(seq 1 20); do
3972 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3974 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3978 echo "Current requests"
3979 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3980 $HSM_PARAM.actions |\
3981 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3983 [[ -z "$res" ]] || error "Some request have not been canceled"
3987 run_test 103 "Purge all requests"
3993 local f=$DIR/$tdir/$tfile
3995 fid=$(make_custom_file_for_progress $f 39 1000000)
3996 [ $? != 0 ] && skip "not enough free space" && return
3998 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3999 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4000 $HSM_PARAM.actions |\
4001 grep $fid | cut -f16 -d=")
4003 [[ "$data1" == "$DATAHEX" ]] ||
4004 error "Data field in records is ($data1) and not ($DATAHEX)"
4009 wait_request_state $fid ARCHIVE SUCCEED
4013 run_test 104 "Copy tool data field"
4015 cleanup_test_105() {
4017 set_hsm_param max_requests $max_requests
4022 local max_requests=$(get_hsm_param max_requests)
4026 set_hsm_param max_requests 300
4028 trap cleanup_test_105 EXIT
4031 for i in $(seq -w 1 10); do
4032 cp /etc/passwd $DIR/$tdir/$i
4033 $LFS hsm_archive $DIR/$tdir/$i
4035 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4036 $HSM_PARAM.actions |\
4037 grep WAITING | wc -l")
4041 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4042 $HSM_PARAM.actions |\
4043 grep WAITING | wc -l")
4046 [[ "$reqcnt1" == "$reqcnt2" ]] ||
4047 error "Requests count after shutdown $reqcnt2 != "\
4048 "before shutdown $reqcnt1"
4052 run_test 105 "Restart of coordinator"
4055 # test needs a running copytool
4058 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4060 check_agent_registered $uuid
4062 search_copytools || error "No copytool found"
4065 check_agent_unregistered $uuid
4068 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4069 check_agent_registered $uuid
4073 run_test 106 "Copytool register/unregister"
4076 # test needs a running copytool
4078 # create and archive file
4080 local f1=$DIR/$tdir/$tfile
4081 local fid=$(copy_file /etc/passwd $f1)
4082 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4083 wait_request_state $fid ARCHIVE SUCCEED
4084 # shutdown and restart MDS
4086 # check the copytool still gets messages from MDT
4087 local f2=$DIR/$tdir/2
4088 local fid=$(copy_file /etc/passwd $f2)
4089 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
4090 # main check of this sanity: this request MUST succeed
4091 wait_request_state $fid ARCHIVE SUCCEED
4094 run_test 107 "Copytool re-register after MDS restart"
4096 policy_set_and_test()
4100 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
4101 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4102 [[ "$policy" == "$target" ]] ||
4103 error "Wrong policy after '$change': '$policy' != '$target'"
4107 # to force default policy setting if error
4108 CDT_POLICY_HAD_CHANGED=true
4110 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4111 local default="NonBlockingRestore [NoRetryAction]"
4112 [[ "$policy" == "$default" ]] ||
4113 error "default policy has changed,"\
4114 " '$policy' != '$default' update the test"
4115 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
4116 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
4117 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
4118 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
4119 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4120 # useless bacause we know but safer for futur changes to use real value
4121 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4122 echo "Next set_param must failed"
4123 policy_set_and_test "wrong" "$policy"
4126 echo "Back to default policy"
4127 cdt_set_sanity_policy
4129 run_test 109 "Policy display/change"
4132 # test needs a running copytool
4137 copy2archive /etc/passwd $tdir/$tfile
4139 local f=$DIR/$tdir/$tfile
4140 import_file $tdir/$tfile $f
4141 local fid=$(path2fid $f)
4143 cdt_set_non_blocking_restore
4148 wait_request_state $fid RESTORE SUCCEED
4149 cdt_clear_non_blocking_restore
4153 error "md5sum returns $st != 1, "\
4154 "should also perror ENODATA (No data available)"
4158 run_test 110a "Non blocking restore policy (import case)"
4161 # test needs a running copytool
4165 local f=$DIR/$tdir/$tfile
4166 local fid=$(copy_file /etc/passwd $f)
4167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4168 wait_request_state $fid ARCHIVE SUCCEED
4171 cdt_set_non_blocking_restore
4176 wait_request_state $fid RESTORE SUCCEED
4177 cdt_clear_non_blocking_restore
4181 error "md5sum returns $st != 1, "\
4182 "should also perror ENODATA (No data available)"
4186 run_test 110b "Non blocking restore policy (release case)"
4189 # test needs a running copytool
4193 copy2archive /etc/passwd $tdir/$tfile
4195 local f=$DIR/$tdir/$tfile
4197 import_file $tdir/$tfile $f
4198 local fid=$(path2fid $f)
4202 copytool_remove_backend $fid
4205 wait_request_state $fid RESTORE FAILED
4212 [[ $st == 0 ]] || error "Restore does not failed"
4216 run_test 111a "No retry policy (import case), restore will error"\
4217 " (No such file or directory)"
4220 # test needs a running copytool
4224 local f=$DIR/$tdir/$tfile
4225 local fid=$(copy_file /etc/passwd $f)
4227 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4228 wait_request_state $fid ARCHIVE SUCCEED
4231 copytool_remove_backend $fid
4234 wait_request_state $fid RESTORE FAILED
4241 [[ $st == 0 ]] || error "Restore does not failed"
4245 run_test 111b "No retry policy (release case), restore will error"\
4246 " (No such file or directory)"
4249 # test needs a running copytool
4253 local f=$DIR/$tdir/$tfile
4254 local fid=$(copy_file /etc/passwd $f)
4256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4257 local l=$($LFS hsm_action $f)
4259 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4263 wait_request_state $fid ARCHIVE SUCCEED
4266 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4270 run_test 112 "State of recorded request"
4273 # test needs a running copytool
4276 local f=$DIR/$tdir/$tfile
4278 fid=$(make_custom_file_for_progress $f 103 1048576)
4279 [ $? != 0 ] && skip "not enough free space" && return
4281 # test with cdt on is made in test_221
4283 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4284 # wait archive to register at CDT
4285 wait_request_state $fid ARCHIVE WAITING
4288 wait_request_state $fid ARCHIVE CANCELED
4289 wait_request_state $fid CANCEL SUCCEED
4293 run_test 200 "Register/Cancel archive"
4296 # test needs a running copytool
4299 local f=$DIR/$tdir/$tfile
4300 create_archive_file $tdir/$tfile
4301 import_file $tdir/$tfile $f
4302 local fid=$(path2fid $f)
4304 # test with cdt on is made in test_222
4307 # wait restore to register at CDT
4308 wait_request_state $fid RESTORE WAITING
4311 wait_request_state $fid RESTORE CANCELED
4312 wait_request_state $fid CANCEL SUCCEED
4316 run_test 201 "Register/Cancel restore"
4319 # test needs a running copytool
4322 local f=$DIR/$tdir/$tfile
4324 fid=$(make_custom_file_for_progress $f 39 1000000)
4325 [ $? != 0 ] && skip "not enough free space" && return
4327 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4328 wait_request_state $fid ARCHIVE SUCCEED
4332 # wait remove to register at CDT
4333 wait_request_state $fid REMOVE WAITING
4336 wait_request_state $fid REMOVE CANCELED
4340 run_test 202 "Register/Cancel remove"
4343 # test needs a running copytool
4348 local f=$DIR/$tdir/$tfile
4349 local fid=$(copy_file /etc/passwd $f)
4353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4354 wait_request_state $fid ARCHIVE SUCCEED
4356 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4360 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4364 run_test 220 "Changelog for archive"
4367 # test needs a running copytool
4372 local f=$DIR/$tdir/$tfile
4373 local fid=$(copy_file /etc/passwd $f)
4377 # block copytool operations to allow for HSM request to be
4378 # submitted and file be unlinked (CDT will find object removed)
4381 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4383 # wait request to reach CT
4384 wait_request_state $fid ARCHIVE STARTED
4390 wait_request_state $fid ARCHIVE FAILED
4392 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4397 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4401 run_test 220a "Changelog for failed archive"
4404 # test needs a running copytool
4407 local f=$DIR/$tdir/$tfile
4409 fid=$(make_custom_file_for_progress $f 103 1048576)
4410 [ $? != 0 ] && skip "not enough free space" && return
4414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4415 wait_request_state $fid ARCHIVE STARTED
4417 wait_request_state $fid ARCHIVE CANCELED
4418 wait_request_state $fid CANCEL SUCCEED
4420 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4423 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4427 run_test 221 "Changelog for archive canceled"
4430 # test needs a running copytool
4434 copy2archive /etc/passwd $tdir/$tfile
4436 local f=$DIR/$tdir/$tfile
4437 import_file $tdir/$tfile $f
4438 local fid=$(path2fid $f)
4443 wait_request_state $fid RESTORE SUCCEED
4445 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4448 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4452 run_test 222a "Changelog for explicit restore"
4455 # test needs a running copytool
4459 local f=$DIR/$tdir/$tfile
4460 local fid=$(copy_file /etc/passwd $f)
4463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4464 wait_request_state $fid ARCHIVE SUCCEED
4469 wait_request_state $fid RESTORE SUCCEED
4471 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4474 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4478 run_test 222b "Changelog for implicit restore"
4481 # test needs a running copytool
4485 copy2archive /etc/passwd $tdir/$tfile
4487 local f=$DIR/$tdir/$tfile
4488 import_file $tdir/$tfile $f
4489 local fid=$(path2fid $f)
4493 # block copytool operations to allow for HSM request to be
4494 # submitted and file be unlinked (CDT will find object removed)
4499 # wait request to reach CT
4500 wait_request_state $fid RESTORE STARTED
4506 wait_request_state $fid RESTORE FAILED
4508 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4512 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4516 run_test 222c "Changelog for failed explicit restore"
4519 # test needs a running copytool
4523 local f=$DIR/$tdir/$tfile
4524 local fid=$(copy_file /etc/passwd $f)
4527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4528 wait_request_state $fid ARCHIVE SUCCEED
4531 copytool_remove_backend $fid
4534 wait_request_state $fid RESTORE FAILED
4536 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4540 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4544 run_test 222d "Changelog for failed implicit restore"
4547 # test needs a running copytool
4550 local f=$DIR/$tdir/$tfile
4551 create_archive_file $tdir/$tfile
4555 import_file $tdir/$tfile $f
4556 local fid=$(path2fid $f)
4559 wait_request_state $fid RESTORE STARTED
4561 wait_request_state $fid RESTORE CANCELED
4562 wait_request_state $fid CANCEL SUCCEED
4564 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4567 [[ $flags == $target ]] ||
4568 error "Changelog flag is $flags not $target"
4572 run_test 223a "Changelog for restore canceled (import case)"
4575 # test needs a running copytool
4578 local f=$DIR/$tdir/$tfile
4580 fid=$(make_custom_file_for_progress $f 39 1000000)
4581 [ $? != 0 ] && skip "not enough free space" && return
4584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4585 wait_request_state $fid ARCHIVE SUCCEED
4588 wait_request_state $fid RESTORE STARTED
4590 wait_request_state $fid RESTORE CANCELED
4591 wait_request_state $fid CANCEL SUCCEED
4593 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4596 [[ $flags == $target ]] ||
4597 error "Changelog flag is $flags not $target"
4601 run_test 223b "Changelog for restore canceled (release case)"
4604 # test needs a running copytool
4609 local f=$DIR/$tdir/$tfile
4610 local fid=$(copy_file /etc/passwd $f)
4613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4614 wait_request_state $fid ARCHIVE SUCCEED
4617 wait_request_state $fid REMOVE SUCCEED
4619 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4622 [[ $flags == $target ]] ||
4623 error "Changelog flag is $flags not $target"
4627 run_test 224 "Changelog for remove"
4630 # test needs a running copytool
4635 local f=$DIR/$tdir/$tfile
4636 local fid=$(copy_file /etc/passwd $f)
4639 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4640 wait_request_state $fid ARCHIVE SUCCEED
4642 copytool_remove_backend $fid
4644 # block copytool operations to allow for HSM request to be
4645 # submitted and file be unlinked (CDT will find object removed)
4650 # wait for request to reach CT
4651 wait_request_state $fid REMOVE STARTED
4657 wait_request_state $fid REMOVE FAILED
4659 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4663 [[ $flags == $target ]] ||
4664 error "Changelog flag is $flags not $target"
4668 run_test 224a "Changelog for failed remove"
4671 # test needs a running copytool
4674 # test is not usable because remove request is too fast
4675 # so it is always finished before cancel can be done ...
4676 echo "Test disabled"
4680 local f=$DIR/$tdir/$tfile
4682 fid=$(make_custom_file_for_progress $f 39 1000000)
4683 [ $? != 0 ] && skip "not enough free space" && return
4686 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4687 wait_request_state $fid ARCHIVE SUCCEED
4689 # if cdt is on, it can serve too quickly the request
4694 wait_request_state $fid REMOVE CANCELED
4695 wait_request_state $fid CANCEL SUCCEED
4697 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4698 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4699 tail -n 1 | awk '{print $5}')
4702 [[ $flags == $target ]] ||
4703 error "Changelog flag is $flags not $target"
4707 run_test 225 "Changelog for remove canceled"
4710 # test needs a running copytool
4715 local f1=$DIR/$tdir/$tfile-1
4716 local f2=$DIR/$tdir/$tfile-2
4717 local f3=$DIR/$tdir/$tfile-3
4718 local fid1=$(copy_file /etc/passwd $f1)
4719 local fid2=$(copy_file /etc/passwd $f2)
4720 copy_file /etc/passwd $f3
4723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4724 wait_request_state $fid1 ARCHIVE SUCCEED
4726 $LFS hsm_archive $f2
4727 wait_request_state $fid2 ARCHIVE SUCCEED
4729 rm $f1 || error "rm $f1 failed"
4731 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4734 [[ $flags == $target ]] ||
4735 error "Changelog flag is $flags not $target"
4737 mv $f3 $f2 || error "mv $f3 $f2 failed"
4739 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4742 [[ $flags == $target ]] ||
4743 error "Changelog flag is $flags not $target"
4747 run_test 226 "changelog for last rm/mv with exiting archive"
4749 check_flags_changes() {
4757 $LFS hsm_set --$hsm_flag $f ||
4758 error "Cannot set $hsm_flag on $f"
4759 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4760 local seen=${#flags[*]}
4762 [[ $seen == $cnt ]] ||
4763 error "set $hsm_flag: Changelog events $seen != $cnt"
4764 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4765 error "set $hsm_flag: Changelog flags are "\
4766 "${flags[$((cnt - 1))]} not $target"
4768 $LFS hsm_clear --$hsm_flag $f ||
4769 error "Cannot clear $hsm_flag on $f"
4770 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4773 [[ $cnt == $seen ]] ||
4774 error "clear $hsm_flag: Changelog events $seen != $cnt"
4776 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4777 error "clear $hsm_flag: Changelog flag is "\
4778 "${flags[$((cnt - 1))]} not $target"
4782 # test needs a running copytool
4789 for i in norelease noarchive exists archived
4791 local f=$DIR/$tdir/$tfile-$i
4792 local fid=$(copy_file /etc/passwd $f)
4793 check_flags_changes $f $fid $i 0 1
4796 f=$DIR/$tdir/$tfile---lost
4797 fid=$(copy_file /etc/passwd $f)
4798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4799 wait_request_state $fid ARCHIVE SUCCEED
4800 check_flags_changes $f $fid lost 3 1
4804 run_test 227 "changelog when explicit setting of HSM flags"
4807 # test needs a running copytool
4810 local fid=$(create_small_sync_file $DIR/$tfile)
4811 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4812 wait_request_state $fid ARCHIVE SUCCEED
4814 $LFS hsm_release $DIR/$tfile
4815 check_hsm_flags $DIR/$tfile "0x0000000d"
4817 filefrag $DIR/$tfile | grep " 1 extent found" ||
4818 error "filefrag on released file must return only one extent"
4820 # only newer versions of cp detect sparse files by stat/FIEMAP
4822 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4823 error "copying $DIR/$tfile"
4824 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4826 $LFS hsm_release $DIR/$tfile
4827 check_hsm_flags $DIR/$tfile "0x0000000d"
4829 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4831 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4833 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4834 error "comparing untarred $DIR/$tfile"
4836 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4837 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4840 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4843 # test needs a running copytool
4847 local maxrequest=$(get_hsm_param max_requests)
4848 local rqcnt=$(($maxrequest * 3))
4852 for i in $(seq -w 1 $rqcnt); do
4854 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4856 # we do it in 2 steps, so all requests arrive at the same time
4857 for i in $(seq -w 1 $rqcnt); do
4858 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4863 while [[ $cnt != 0 || $wt != 0 ]]; do
4865 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4866 $HSM_PARAM.actions |\
4867 grep STARTED | grep -v CANCEL | wc -l")
4868 [[ $cnt -le $maxrequest ]] ||
4869 error "$cnt > $maxrequest too many started requests"
4870 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4871 $HSM_PARAM.actions |\
4872 grep WAITING | wc -l")
4873 echo "max=$maxrequest started=$cnt waiting=$wt"
4878 run_test 250 "Coordinator max request"
4881 # test needs a running copytool
4884 local f=$DIR/$tdir/$tfile
4886 fid=$(make_custom_file_for_progress $f 103 1048576)
4887 [ $? != 0 ] && skip "not enough free space" && return
4890 # to have a short test
4891 local old_to=$(get_hsm_param active_request_timeout)
4892 set_hsm_param active_request_timeout 4
4893 # to be sure the cdt will wake up frequently so
4894 # it will be able to cancel the "old" request
4895 local old_loop=$(get_hsm_param loop_period)
4896 set_hsm_param loop_period 2
4899 # clear locks to avoid extra delay caused by flush/cancel
4900 # and thus prevent early copytool death to timeout.
4901 cancel_lru_locks osc
4903 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4904 wait_request_state $fid ARCHIVE STARTED
4906 wait_request_state $fid ARCHIVE CANCELED
4908 set_hsm_param active_request_timeout $old_to
4909 set_hsm_param loop_period $old_loop
4913 run_test 251 "Coordinator request timeout"
4916 # test needs a running copytool
4920 local f=$DIR/$tdir/$tfile
4921 local fid=$(make_custom_file_for_progress $f 103 1048576)
4924 # to have a short test
4925 local old_to=$(get_hsm_param active_request_timeout)
4926 set_hsm_param active_request_timeout 20
4927 # to be sure the cdt will wake up frequently so
4928 # it will be able to cancel the "old" request
4929 local old_loop=$(get_hsm_param loop_period)
4930 set_hsm_param loop_period 2
4933 # clear locks to avoid extra delay caused by flush/cancel
4934 # and thus prevent early copytool death to timeout.
4935 cancel_lru_locks osc
4937 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4938 wait_request_state $fid ARCHIVE STARTED
4941 # wait but less than active_request_timeout+grace_delay
4943 wait_request_state $fid ARCHIVE CANCELED
4945 set_hsm_param active_request_timeout $old_to
4946 set_hsm_param loop_period $old_loop
4950 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4954 # test needs a running copytool
4958 local f=$DIR/$tdir/$tfile
4960 dd if=/dev/zero of=$f bs=1MB count=10
4961 local fid=$(path2fid $f)
4963 $LFS hsm_archive $f || error "could not archive file"
4964 wait_request_state $fid ARCHIVE SUCCEED
4966 # clear locks to discard inode data
4967 cancel_lru_locks osc
4969 #define OBD_FAIL_MDC_MERGE 0x807
4970 $LCTL set_param fail_loc=0x807
4972 #expect error here, instead of release with wrong size
4975 if ((rc == 0)); then
4976 file_size=$(stat -c '%s' $f)
4977 if ((file_size != 10485760)); then
4978 error "Wrong file size after hsm_release"
4981 echo "could not release file"
4985 run_test 253 "Check for wrong file size after release"
4988 # the only way to test ondisk conf is to restart MDS ...
4989 echo "Stop coordinator and remove coordinator state at mount"
4992 # clean on disk conf set by default
4993 cdt_clear_mount_state
4994 cdt_check_state stopped
4996 # check cdt still off after umount/remount
4998 cdt_check_state stopped
5000 echo "Set coordinator start at mount, and start coordinator"
5001 cdt_set_mount_state enabled
5004 cdt_check_state enabled
5006 # check cdt still on after umount/remount
5008 cdt_check_state enabled
5010 # we are back to original state (cdt started at mount)
5012 run_test 300 "On disk coordinator state kept between MDT umount/mount"
5015 local ai=$(get_hsm_param default_archive_id)
5016 local new=$((ai + 1))
5018 set_hsm_param default_archive_id $new -P
5020 local res=$(get_hsm_param default_archive_id)
5023 set_hsm_param default_archive_id "" "-P -d"
5025 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5027 run_test 301 "HSM tunnable are persistent"
5030 local ai=$(get_hsm_param default_archive_id)
5031 local new=$((ai + 1))
5036 set_hsm_param default_archive_id $new -P
5039 for mdtno in $(seq 1 $MDSCOUNT); do
5044 cdt_check_state enabled
5046 local res=$(get_hsm_param default_archive_id)
5049 set_hsm_param default_archive_id "" "-P -d"
5051 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5053 run_test 302 "HSM tunnable are persistent when CDT is off"
5056 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5062 local dir_mdt0=$DIR/$tdir/mdt0
5063 local dir_mdt1=$DIR/$tdir/mdt1
5065 # create 1 dir per MDT
5066 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5067 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5069 # create 1 file in each MDT
5070 local fid1=$(create_small_file $dir_mdt0/$tfile)
5071 local fid2=$(create_small_file $dir_mdt1/$tfile)
5073 # check that hsm request on mdt0 is sent to the right MDS
5074 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5075 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5076 echo "archive successful on mdt0"
5078 # check that hsm request on mdt1 is sent to the right MDS
5079 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5080 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5081 echo "archive successful on mdt1"
5084 # clean test files and directories
5085 rm -rf $dir_mdt0 $dir_mdt1
5087 run_test 400 "Single request is sent to the right MDT"
5090 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5096 local dir_mdt0=$DIR/$tdir/mdt0
5097 local dir_mdt1=$DIR/$tdir/mdt1
5099 # create 1 dir per MDT
5100 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5101 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5103 # create 1 file in each MDT
5104 local fid1=$(create_small_file $dir_mdt0/$tfile)
5105 local fid2=$(create_small_file $dir_mdt1/$tfile)
5107 # check that compound requests are shunt to the rights MDTs
5108 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5109 error "lfs hsm_archive"
5110 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5111 echo "archive successful on mdt0"
5112 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5113 echo "archive successful on mdt1"
5116 # clean test files and directories
5117 rm -rf $dir_mdt0 $dir_mdt1
5119 run_test 401 "Compound requests split and sent to their respective MDTs"
5121 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5126 local node=$(facet_active_host $facet)
5128 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5129 awk '{print $4}'); do
5130 echo "$3 $mdc on $node"
5131 do_facet $facet "$LCTL --device $mdc $state" || return 1
5136 # make sure there is no running copytool
5139 # deactivate all mdc on agent1
5140 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5142 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
5144 check_agent_unregistered "uuid" # match any agent
5146 # no expected running copytool
5147 search_copytools $agent && error "Copytool start should have failed"
5150 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5152 run_test 402a "Copytool start fails if all MDTs are inactive"
5159 local f=$DIR/$tdir/$tfile
5160 touch $f || error "touch $f failed"
5161 local fid=$(path2fid $f)
5163 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5164 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5167 # give time for CDT to send request and to keep it for retry
5168 wait_for_loop_period
5170 wait_request_state $fid ARCHIVE WAITING
5172 do_facet $SINGLEAGT lctl set_param fail_loc=0
5174 # request should succeed now
5175 wait_request_state $fid ARCHIVE SUCCEED
5179 run_test 402b "CDT must retry request upon slow start of CT"
5182 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5184 # make sure there is no running copytool
5187 local agent=$(facet_active_host $SINGLEAGT)
5189 # deactivate all mdc for MDT0001
5190 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5193 local uuid=$(get_agent_uuid $agent)
5194 # check the agent is registered on MDT0000, and not on MDT0001
5195 check_agent_registered_by_mdt $uuid 0
5196 check_agent_unregistered_by_mdt $uuid 1
5198 # check running copytool process
5199 search_copytools $agent || error "No running copytools on $agent"
5201 # reactivate all mdc for MDT0001
5202 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5204 # make sure the copytool is now registered to all MDTs
5205 check_agent_registered $uuid
5209 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5212 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5216 # create files on both MDT0000 and MDT0001
5219 local dir_mdt0=$DIR/$tdir/mdt0
5220 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5222 # create 1 file on mdt0
5223 local fid1=$(create_small_file $dir_mdt0/$tfile)
5225 # deactivate all mdc for MDT0001
5226 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5228 # send an HSM request for files in MDT0000
5229 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5231 # check for completion of files in MDT0000
5232 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5233 echo "archive successful on mdt0"
5235 # reactivate all mdc for MDT0001
5236 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5239 # clean test files and directories
5242 run_test 404 "Inactive MDT does not block requests for active MDTs"
5245 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5251 local striped_dir=$DIR/$tdir/striped_dir
5253 # create striped dir on all of MDTs
5254 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5256 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5257 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5258 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5259 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5261 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5262 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5263 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5264 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5266 # check that compound requests are shunt to the rights MDTs
5267 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5268 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5269 error "lfs hsm_archive"
5271 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5272 echo "archive successful on $fid1"
5273 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5274 echo "archive successful on $fid2"
5275 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5276 echo "archive successful on $fid3"
5277 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5278 echo "archive successful on $fid4"
5280 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5281 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5282 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5283 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5285 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5286 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5287 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5288 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5292 run_test 405 "archive and release under striped directory"
5295 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5297 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5298 skip "need MDS version at least 2.7.64" && return 0
5304 fid=$(create_small_file $DIR/$tdir/$tfile)
5307 $LFS hsm_archive $DIR/$tdir/$tfile
5308 wait_request_state "$fid" ARCHIVE SUCCEED
5309 $LFS hsm_release $DIR/$tdir/$tfile
5311 # Should migrate $tdir but not $tfile.
5312 $LFS mv -M1 $DIR/$tdir &&
5313 error "migrating HSM an archived file should fail"
5315 $LFS hsm_restore $DIR/$tdir/$tfile
5316 wait_request_state "$fid" RESTORE SUCCEED
5318 $LFS hsm_remove $DIR/$tdir/$tfile
5319 wait_request_state "$fid" REMOVE SUCCEED
5321 cat $DIR/$tdir/$tfile > /dev/null ||
5322 error "cannot read $DIR/$tdir/$tfile"
5324 $LFS mv -M1 $DIR/$tdir ||
5325 error "cannot complete migration after HSM remove"
5327 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5328 if ((mdt_index != 1)); then
5329 error "expected MDT index 1, got $mdt_index"
5332 # Refresh fid after migration.
5333 fid=$(path2fid $DIR/$tdir/$tfile)
5336 $LFS hsm_archive $DIR/$tdir/$tfile
5337 wait_request_state "$fid" ARCHIVE SUCCEED 1
5339 lctl set_param debug=+trace
5340 $LFS hsm_release $DIR/$tdir/$tfile ||
5341 error "cannot release $DIR/$tdir/$tfile"
5343 $LFS hsm_restore $DIR/$tdir/$tfile
5344 wait_request_state "$fid" RESTORE SUCCEED 1
5346 cat $DIR/$tdir/$tfile > /dev/null ||
5347 error "cannot read $DIR/$tdir/$tfile"
5351 run_test 406 "attempting to migrate HSM archived files is safe"
5354 needclients 2 || return 0
5355 # test needs a running copytool
5360 local f=$DIR/$tdir/$tfile
5361 local f2=$DIR2/$tdir/$tfile
5363 fid=$(make_custom_file_for_progress $f 39 1000000)
5364 [ $? != 0 ] && skip "not enough free space" && return
5366 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5367 wait_request_state $fid ARCHIVE SUCCEED
5370 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5371 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5374 # 1st request holds layout lock while appropriate
5375 # RESTORE record is still not added to llog
5379 # after umount hsm_actions->O/x/x log shouldn't have
5380 # double RESTORE records like below
5381 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5382 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5384 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5387 wait_request_state $fid RESTORE SUCCEED
5390 run_test 407 "Check for double RESTORE records in llog"
5394 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5395 skip "HSM migrate is not supported" && return
5397 # Stop the existing copytool
5400 test_mkdir -p $DIR/$tdir
5401 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5403 run_test 500 "various LLAPI HSM tests"
5408 check_and_cleanup_lustre