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 do_facet $SINGLEAGT \
392 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
393 --import $1 $2 $MOUNT" ||
394 error "import of $1 to $2 failed"
398 local file=$HSM_ARCHIVE/$1
399 do_facet $SINGLEAGT mkdir -p $(dirname $file)
400 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
401 file_creation_failure dd $file $?
405 local file=$HSM_ARCHIVE/$2
406 do_facet $SINGLEAGT mkdir -p $(dirname $file)
407 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
416 if [[ "$value" != "" ]]; then
419 for mdtno in $(seq 1 $MDSCOUNT); do
420 local idx=$(($mdtno - 1))
421 local facet=mds${mdtno}
422 # if $arg include -P option, run 1 set_param per MDT on the MGS
423 # else, run set_param on each MDT
424 [[ $arg = *"-P"* ]] && facet=mgs
425 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
426 [[ $? != 0 ]] && rc=1
436 for mdtno in $(seq 1 $MDSCOUNT); do
437 local idx=$(($mdtno - 1))
438 wait_result mds${mdtno} \
439 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
441 error "$key state is not '$target' on mds${mdtno}"
448 for mdtno in $(seq 1 $MDSCOUNT); do
449 local idx=$(($mdtno - 1))
450 local cl_user=$(do_facet mds${mdtno} $LCTL \
451 --device ${MDT[$idx]} \
452 changelog_register -n)
454 do_facet mds${mdtno} lctl set_param \
455 mdd.${MDT[$idx]}.changelog_mask="+hsm"
456 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
460 changelog_cleanup() {
462 for mdtno in $(seq 1 $MDSCOUNT); do
463 local idx=$(($mdtno - 1))
464 [[ -z ${CL_USERS[$idx]} ]] && continue
465 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
466 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
467 changelog_deregister ${CL_USERS[$idx]}
472 changelog_get_flags() {
477 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
482 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
490 mdts_set_param "$opt -n" "hsm.$param" "$value"
497 mdts_set_param "" hsm_control "$cmd"
498 mdts_check_param hsm_control "$target" 10
501 cdt_set_sanity_policy() {
502 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
505 mdts_set_param "" hsm.policy "+NRA"
506 mdts_set_param "" hsm.policy "-NBR"
507 CDT_POLICY_HAD_CHANGED=
512 mdts_set_param "" hsm.policy "+NRA"
513 CDT_POLICY_HAD_CHANGED=true
516 cdt_clear_no_retry() {
517 mdts_set_param "" hsm.policy "-NRA"
518 CDT_POLICY_HAD_CHANGED=true
521 cdt_set_non_blocking_restore() {
522 mdts_set_param "" hsm.policy "+NBR"
523 CDT_POLICY_HAD_CHANGED=true
526 cdt_clear_non_blocking_restore() {
527 mdts_set_param "" hsm.policy "-NBR"
528 CDT_POLICY_HAD_CHANGED=true
531 cdt_clear_mount_state() {
532 mdts_set_param "-P -d" hsm_control ""
535 cdt_set_mount_state() {
536 mdts_set_param "-P" hsm_control "$1"
537 # set_param -P is asynchronous operation and could race with set_param.
538 # In such case configs could be retrieved and applied at mgc after
539 # set_param -P completion. Sleep here to avoid race with set_param.
540 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
541 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
542 # and 10 seconds to retrieve config from server.
547 mdts_check_param hsm_control "$1" 20
551 set_test_state disabled disabled
555 set_test_state enabled enabled
559 set_test_state shutdown stopped
563 set_test_state purge enabled
569 cdt_set_sanity_policy
573 local client_count=$1
574 if [[ $CLIENTCOUNT -lt $client_count ]]; then
575 skip "Need $client_count or more clients, have $CLIENTCOUNT"
582 $LFS path2fid $1 | tr -d '[]'
583 return ${PIPESTATUS[0]}
591 if [[ $u == "user" ]]; then
592 st=$($RUNAS $LFS hsm_state $f)
595 st=$($LFS hsm_state $f)
598 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
600 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
604 get_hsm_archive_id() {
607 st=$($LFS hsm_state $f)
608 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
610 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
619 local st=$(get_hsm_flags $f)
620 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
623 check_hsm_flags_user() {
627 local st=$(get_hsm_flags $f user)
628 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
631 file_creation_failure() {
636 df $MOUNT $MOUNT2 >&2
637 error "cannot create $f with $cmd, status=$err"
649 if [[ "$3" != 1 ]]; then
653 cp $1 $f || file_creation_failure cp $f $?
655 path2fid $f || error "cannot get fid on $f"
659 local file2=${1/$DIR/$DIR2}
660 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
661 file_creation_failure dd $file2 $?
663 path2fid $1 || error "cannot get fid on $1"
667 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
668 file_creation_failure dd $1 $?
669 path2fid $1 || error "cannot get fid on $1"
672 cleanup_large_files() {
673 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
675 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
678 check_enough_free_space() {
681 local need=$((nb * unit /1024))
682 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
683 (( $need >= $free )) && return 1
687 make_custom_file_for_progress() {
688 local file2=${1/$DIR/$DIR2}
689 local fsize=${2:-"39"}
690 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
693 [[ $fsize -gt 0 ]] || error "Invalid file size"
694 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
697 check_enough_free_space $fsize $blksz || return $?
698 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
699 file_creation_failure dd $file2 $?
700 path2fid $1 || error "cannot get fid on $1"
706 wait_update --verbose $(facet_active_host $facet) "$@"
709 wait_request_state() {
713 # 4th arg (mdt index) is optional
715 local mds=mds$(($mdtidx + 1))
717 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
718 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
720 wait_result $mds "$cmd" $state 200 ||
721 error "request on $fid is not $state on $mds"
724 get_request_state() {
728 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
729 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
732 get_request_count() {
736 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
737 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
740 # Ensure the number of HSM request for a given FID is correct
741 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
742 assert_request_count() {
743 local request_count=$(get_request_count $1 $2)
744 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
746 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
753 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
754 [[ -n $fid ]] && cmd+=" | grep '$fid'"
755 cmd+=" | egrep 'WAITING|STARTED'"
757 wait_result $SINGLEMDS "$cmd" "" $timeout ||
758 error "requests did not complete"
761 wait_for_grace_delay() {
762 local val=$(get_hsm_param grace_delay)
766 wait_for_loop_period() {
767 local val=$(get_hsm_param loop_period)
774 # python2.6 in EL6 includes an internal json module
775 local json_parser='import json; import fileinput;'
776 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
777 json_parser+='json.loads([line for line in '
778 json_parser+='fileinput.input()][0]).items()])'
780 echo $raw_event | python -c "$json_parser"
783 get_agent_by_uuid_mdt() {
786 local mds=mds$(($mdtidx + 1))
787 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
791 check_agent_registered_by_mdt() {
794 local mds=mds$(($mdtidx + 1))
795 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
796 if [[ ! -z "$agent" ]]; then
797 echo "found agent $agent on $mds"
799 error "uuid $uuid not found in agent list on $mds"
803 check_agent_unregistered_by_mdt() {
806 local mds=mds$(($mdtidx + 1))
807 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
808 if [[ -z "$agent" ]]; then
809 echo "uuid not found in agent list on $mds"
811 error "uuid found in agent list on $mds: $agent"
815 check_agent_registered() {
818 for mdsno in $(seq 1 $MDSCOUNT); do
819 check_agent_registered_by_mdt $uuid $((mdsno - 1))
823 check_agent_unregistered() {
826 for mdsno in $(seq 1 $MDSCOUNT); do
827 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
832 local agent=${1:-$(facet_active_host $SINGLEAGT)}
834 # Lustre mount-point is mandatory and last parameter on
836 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
838 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
840 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
846 # populate MDT device array
849 # cleanup from previous bad setup
852 # for recovery tests, coordinator needs to be started at mount
854 # the lustre conf must be without hsm on (like for sanity.sh)
855 echo "Set HSM on and start"
856 cdt_set_mount_state enabled
857 cdt_check_state enabled
859 echo "Set sanity-hsm HSM policy"
860 cdt_set_sanity_policy
862 # finished requests are quickly removed from list
863 set_hsm_param grace_delay 10
869 local f=$DIR/$tdir/$tfile
873 check_hsm_flags_user $f "0x00000000"
875 $RUNAS $LFS hsm_set --norelease $f ||
876 error "user could not change hsm flags"
877 check_hsm_flags_user $f "0x00000010"
879 $RUNAS $LFS hsm_clear --norelease $f ||
880 error "user could not clear hsm flags"
881 check_hsm_flags_user $f "0x00000000"
883 # User could not change those flags...
884 $RUNAS $LFS hsm_set --exists $f &&
885 error "user should not set this flag"
886 check_hsm_flags_user $f "0x00000000"
889 $LFS hsm_set --exists $f ||
890 error "root could not change hsm flags"
891 check_hsm_flags_user $f "0x00000001"
893 $LFS hsm_clear --exists $f ||
894 error "root could not clear hsm state"
895 check_hsm_flags_user $f "0x00000000"
898 run_test 1 "lfs hsm flags root/non-root access"
902 local f=$DIR/$tdir/$tfile
903 local fid=$(make_small $f)
907 $LFS hsm_archive $f || error "could not archive file"
908 wait_request_state $fid ARCHIVE SUCCEED
910 # Release and check states
911 $LFS hsm_release $f || error "could not release file"
912 echo -n "Verifying released state: "
913 check_hsm_flags $f "0x0000000d"
915 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
919 run_test 1a "mmap & cat a HSM released file"
923 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
924 error "failed to set default stripe"
925 local f=$DIR/$tdir/$tfile
928 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
929 error "failed to create file"
930 local fid=$(path2fid $f)
935 $LFS hsm_archive $f || error "could not archive file"
936 wait_request_state $fid ARCHIVE SUCCEED
939 $LFS hsm_release $f || error "could not release file"
940 echo "verify released state: "
941 check_hsm_flags $f "0x0000000d" && echo "pass"
944 $LFS hsm_restore $f || error "could not restore file"
945 wait_request_state $fid RESTORE SUCCEED
946 echo "verify restored state: "
947 check_hsm_flags $f "0x00000009" && echo "pass"
951 run_test 1b "Archive, Release & Restore composite file"
955 local f=$DIR/$tdir/$tfile
957 # New files are not dirty
958 check_hsm_flags $f "0x00000000"
960 # For test, we simulate an archived file.
961 $LFS hsm_set --exists $f || error "user could not change hsm flags"
962 check_hsm_flags $f "0x00000001"
964 # chmod do not put the file dirty
965 chmod 600 $f || error "could not chmod test file"
966 check_hsm_flags $f "0x00000001"
968 # chown do not put the file dirty
969 chown $RUNAS_ID $f || error "could not chown test file"
970 check_hsm_flags $f "0x00000001"
972 # truncate put the file dirty
973 $TRUNCATE $f 1 || error "could not truncate test file"
974 check_hsm_flags $f "0x00000003"
976 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
977 check_hsm_flags $f "0x00000001"
979 run_test 2 "Check file dirtyness when doing setattr"
985 # New files are not dirty
987 check_hsm_flags $f "0x00000000"
989 # For test, we simulate an archived file.
990 $LFS hsm_set --exists $f ||
991 error "user could not change hsm flags"
992 check_hsm_flags $f "0x00000001"
994 # Reading a file, does not set dirty
995 cat $f > /dev/null || error "could not read file"
996 check_hsm_flags $f "0x00000001"
998 # Open for write without modifying data, does not set dirty
999 openfile -f O_WRONLY $f || error "could not open test file"
1000 check_hsm_flags $f "0x00000001"
1002 # Append to a file sets it dirty
1003 cp -p /etc/passwd $f.append || error "could not create file"
1004 $LFS hsm_set --exists $f.append ||
1005 error "user could not change hsm flags"
1006 dd if=/etc/passwd of=$f.append bs=1 count=3\
1007 conv=notrunc oflag=append status=noxfer ||
1008 file_creation_failure dd $f.append $?
1009 check_hsm_flags $f.append "0x00000003"
1011 # Modify a file sets it dirty
1012 cp -p /etc/passwd $f.modify || error "could not create file"
1013 $LFS hsm_set --exists $f.modify ||
1014 error "user could not change hsm flags"
1015 dd if=/dev/zero of=$f.modify bs=1 count=3\
1016 conv=notrunc status=noxfer ||
1017 file_creation_failure dd $f.modify $?
1018 check_hsm_flags $f.modify "0x00000003"
1020 # Open O_TRUNC sets dirty
1021 cp -p /etc/passwd $f.trunc || error "could not create file"
1022 $LFS hsm_set --exists $f.trunc ||
1023 error "user could not change hsm flags"
1024 cp /etc/group $f.trunc || error "could not override a file"
1025 check_hsm_flags $f.trunc "0x00000003"
1027 # Mmapped a file sets dirty
1028 cp -p /etc/passwd $f.mmap || error "could not create file"
1029 $LFS hsm_set --exists $f.mmap ||
1030 error "user could not change hsm flags"
1031 multiop $f.mmap OSMWUc || error "could not mmap a file"
1032 check_hsm_flags $f.mmap "0x00000003"
1034 run_test 3 "Check file dirtyness when opening for write"
1038 local f=$DIR/$tdir/$tfile
1039 local fid=$(make_small $f)
1042 local st=$(get_request_state $fid CANCEL)
1043 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1045 run_test 4 "Useless cancel must not be registered"
1048 # test needs a running copytool
1052 local f=$DIR/$tdir/$tfile
1053 local fid=$(copy_file /etc/passwd $f)
1055 wait_request_state $fid ARCHIVE SUCCEED
1057 check_hsm_flags $f "0x00000009"
1061 run_test 8 "Test default archive number"
1064 # we do not use the default one to be sure
1065 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1067 copytool_setup $SINGLEAGT $MOUNT $new_an
1069 # give time for CT to register with MDTs
1070 sleep $(($MDSCOUNT*2))
1071 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1072 check_agent_registered $uuid
1075 local f=$DIR/$tdir/$tfile
1076 local fid=$(copy_file /etc/passwd $f)
1077 $LFS hsm_archive --archive $new_an $f
1078 wait_request_state $fid ARCHIVE SUCCEED
1080 check_hsm_flags $f "0x00000009"
1084 run_test 9 "Use of explicit archive number, with dedicated copytool"
1087 needclients 3 || return 0
1093 copytool_cleanup $(comma_list $(agts_nodes))
1095 # start all of the copytools
1096 for n in $(seq $AGTCOUNT); do
1097 copytool_setup agt$n
1100 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1103 for n in $(seq $AGTCOUNT); do
1104 file=$DIR/$tdir/$tfile.$n
1105 fid=$(make_small $file)
1107 $LFS hsm_archive $file || error "could not archive file $file"
1108 wait_request_state $fid ARCHIVE SUCCEED
1109 check_hsm_flags $file "0x00000009"
1113 copytool_cleanup $(comma_list $(agts_nodes))
1115 run_test 9a "Multiple remote agents"
1118 # test needs a running copytool
1121 mkdir -p $DIR/$tdir/d1
1122 local f=$DIR/$tdir/$tfile
1123 local fid=$(copy_file /etc/hosts $f)
1124 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1125 error "hsm_archive failed"
1126 wait_request_state $fid ARCHIVE SUCCEED
1128 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1129 error "fid $fid not in archive $HSM_ARCHIVE"
1130 echo "Verifying content"
1131 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1132 echo "Verifying hsm state "
1133 check_hsm_flags $f "0x00000009"
1135 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1136 local st=$(get_hsm_archive_id $f)
1137 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1138 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1143 run_test 10a "Archive a file"
1146 # test needs a running copytool
1150 local f=$DIR/$tdir/$tfile
1151 local fid=$(copy_file /etc/hosts $f)
1152 $LFS hsm_archive $f || error "archive request failed"
1153 wait_request_state $fid ARCHIVE SUCCEED
1155 $LFS hsm_archive $f || error "archive of non dirty file failed"
1156 local cnt=$(get_request_count $fid ARCHIVE)
1157 [[ "$cnt" == "1" ]] ||
1158 error "archive of non dirty file must not make a request"
1162 run_test 10b "Archive of non dirty file must work without doing request"
1165 # test needs a running copytool
1169 local f=$DIR/$tdir/$tfile
1170 local fid=$(copy_file /etc/hosts $f)
1171 $LFS hsm_set --noarchive $f
1172 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1176 run_test 10c "Check forbidden archive"
1179 # test needs a running copytool
1183 local f=$DIR/$tdir/$tfile
1184 local fid=$(copy_file /etc/hosts $f)
1185 $LFS hsm_archive $f || error "cannot archive $f"
1186 wait_request_state $fid ARCHIVE SUCCEED
1188 local ar=$(get_hsm_archive_id $f)
1189 local dflt=$(get_hsm_param default_archive_id)
1190 [[ $ar == $dflt ]] ||
1191 error "archived file is not on default archive: $ar != $dflt"
1195 run_test 10d "Archive a file on the default archive id"
1199 copy2archive /etc/hosts $tdir/$tfile
1200 local f=$DIR/$tdir/$tfile
1202 import_file $tdir/$tfile $f
1203 echo -n "Verifying released state: "
1204 check_hsm_flags $f "0x0000000d"
1206 local LSZ=$(stat -c "%s" $f)
1207 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1209 echo "Verifying imported size $LSZ=$ASZ"
1210 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1211 echo -n "Verifying released pattern: "
1212 local PTRN=$($GETSTRIPE -L $f)
1214 [[ $PTRN == released ]] || error "Is not released"
1215 local fid=$(path2fid $f)
1216 echo "Verifying new fid $fid in archive"
1218 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1219 error "fid $fid not in archive $HSM_ARCHIVE"
1221 run_test 11a "Import a file"
1224 # test needs a running copytool
1228 local f=$DIR/$tdir/$tfile
1229 local fid=$(copy_file /etc/hosts $f)
1230 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1231 error "hsm_archive failed"
1232 wait_request_state $fid ARCHIVE SUCCEED
1234 local FILE_HASH=$(md5sum $f)
1239 echo "$FILE_HASH" | md5sum -c
1241 [[ $? -eq 0 ]] || error "Restored file differs"
1245 run_test 11b "Import a deleted file using its FID"
1248 # test needs a running copytool
1252 copy2archive /etc/hosts $tdir/$tfile
1254 local f=$DIR/$tdir/$tfile
1255 import_file $tdir/$tfile $f
1256 local f2=$DIR2/$tdir/$tfile
1257 echo "Verifying released state: "
1258 check_hsm_flags $f2 "0x0000000d"
1260 local fid=$(path2fid $f2)
1261 $LFS hsm_restore $f2
1262 wait_request_state $fid RESTORE SUCCEED
1264 echo "Verifying file state: "
1265 check_hsm_flags $f2 "0x00000009"
1267 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1269 [[ $? -eq 0 ]] || error "Restored file differs"
1273 run_test 12a "Restore an imported file explicitly"
1276 # test needs a running copytool
1280 copy2archive /etc/hosts $tdir/$tfile
1282 local f=$DIR/$tdir/$tfile
1283 import_file $tdir/$tfile $f
1284 echo "Verifying released state: "
1285 check_hsm_flags $f "0x0000000d"
1287 cat $f > /dev/null || error "File read failed"
1289 echo "Verifying file state after restore: "
1290 check_hsm_flags $f "0x00000009"
1292 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1294 [[ $? -eq 0 ]] || error "Restored file differs"
1298 run_test 12b "Restore an imported file implicitly"
1301 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1303 # test needs a running copytool
1307 local f=$DIR/$tdir/$tfile
1308 $LFS setstripe -c 2 $f
1310 fid=$(make_custom_file_for_progress $f 5)
1311 [ $? != 0 ] && skip "not enough free space" && return
1313 local FILE_CRC=$(md5sum $f)
1315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1316 wait_request_state $fid ARCHIVE SUCCEED
1317 $LFS hsm_release $f || error "release $f failed"
1319 echo "$FILE_CRC" | md5sum -c
1321 [[ $? -eq 0 ]] || error "Restored file differs"
1325 run_test 12c "Restore a file with stripe of 2"
1328 # test needs a running copytool
1333 local f=$DIR/$tdir/$tfile
1334 local fid=$(copy_file /etc/hosts $f)
1335 $LFS hsm_restore $f || error "restore of non archived file failed"
1336 local cnt=$(get_request_count $fid RESTORE)
1337 [[ "$cnt" == "0" ]] ||
1338 error "restore non archived must not make a request"
1339 $LFS hsm_archive $f ||
1340 error "archive request failed"
1341 wait_request_state $fid ARCHIVE SUCCEED
1342 $LFS hsm_restore $f ||
1343 error "restore of non released file failed"
1344 local cnt=$(get_request_count $fid RESTORE)
1345 [[ "$cnt" == "0" ]] ||
1346 error "restore a non dirty file must not make a request"
1350 run_test 12d "Restore of a non archived, non released file must work"\
1351 " without doing request"
1354 # test needs a running copytool
1357 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1358 local f=$DIR/$tdir/$tfile
1359 local fid=$(copy_file /etc/hosts $f)
1360 $LFS hsm_archive $f || error "archive request failed"
1361 wait_request_state $fid ARCHIVE SUCCEED
1364 cat /etc/hosts >> $f
1368 $LFS hsm_restore $f && error "restore a dirty file must fail"
1372 run_test 12e "Check forbidden restore"
1375 # test needs a running copytool
1379 local f=$DIR/$tdir/$tfile
1380 local fid=$(copy_file /etc/hosts $f)
1382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1383 wait_request_state $fid ARCHIVE SUCCEED
1384 $LFS hsm_release $f || error "release of $f failed"
1386 wait_request_state $fid RESTORE SUCCEED
1388 echo -n "Verifying file state: "
1389 check_hsm_flags $f "0x00000009"
1391 diff -q /etc/hosts $f
1393 [[ $? -eq 0 ]] || error "Restored file differs"
1397 run_test 12f "Restore a released file explicitly"
1400 # test needs a running copytool
1404 local f=$DIR/$tdir/$tfile
1405 local fid=$(copy_file /etc/hosts $f)
1407 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1408 wait_request_state $fid ARCHIVE SUCCEED
1409 $LFS hsm_release $f || error "release of $f failed"
1411 diff -q /etc/hosts $f
1414 # we check we had a restore done
1415 wait_request_state $fid RESTORE SUCCEED
1417 [[ $st -eq 0 ]] || error "Restored file differs"
1421 run_test 12g "Restore a released file implicitly"
1424 needclients 2 || return 0
1426 # test needs a running copytool
1430 local f=$DIR/$tdir/$tfile
1431 local fid=$(copy_file /etc/hosts $f)
1433 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1434 wait_request_state $fid ARCHIVE SUCCEED
1435 $LFS hsm_release $f || error "release of $f failed"
1437 do_node $CLIENT2 diff -q /etc/hosts $f
1440 # we check we had a restore done
1441 wait_request_state $fid RESTORE SUCCEED
1443 [[ $st -eq 0 ]] || error "Restored file differs"
1447 run_test 12h "Restore a released file implicitly from a second node"
1450 # test needs a running copytool
1454 local f=$DIR/$tdir/$tfile
1455 local fid=$(copy_file /etc/passwd $f)
1456 $LFS hsm_archive $f || error "archive of $f failed"
1457 wait_request_state $fid ARCHIVE SUCCEED
1459 $LFS hsm_release $f || error "release of $f failed"
1463 [[ $? -eq 0 ]] || error "Restored file differs"
1467 run_test 12m "Archive/release/implicit restore"
1470 # test needs a running copytool
1474 copy2archive /etc/hosts $tdir/$tfile
1476 local f=$DIR/$tdir/$tfile
1477 import_file $tdir/$tfile $f
1479 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1480 error "Restored file differs"
1482 $LFS hsm_release $f || error "release of $f failed"
1486 run_test 12n "Import/implicit restore/release"
1489 # test needs a running copytool
1493 local f=$DIR/$tdir/$tfile
1494 local fid=$(copy_file /etc/hosts $f)
1496 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1497 wait_request_state $fid ARCHIVE SUCCEED
1498 $LFS hsm_release $f || error "release of $f failed"
1500 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1501 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1503 # set no retry action mode
1506 diff -q /etc/hosts $f
1509 # we check we had a restore failure
1510 wait_request_state $fid RESTORE FAILED
1512 [[ $st -eq 0 ]] && error "Restore must fail"
1514 # remove no retry action mode
1517 # check file is still released
1518 check_hsm_flags $f "0x0000000d"
1520 # retry w/o failure injection
1521 do_facet $SINGLEMDS lctl set_param fail_loc=0
1523 # to be sure previous RESTORE result is gone
1525 wait_for_grace_delay
1527 diff -q /etc/hosts $f
1530 # we check we had a restore done
1531 wait_request_state $fid RESTORE SUCCEED
1533 [[ $st -eq 0 ]] || error "Restored file differs"
1537 run_test 12o "Layout-swap failure during Restore leaves file released"
1540 # test needs a running copytool
1544 local f=$DIR/$tdir/$tfile
1545 local fid=$(copy_file /etc/hosts $f)
1547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1548 wait_request_state $fid ARCHIVE SUCCEED
1549 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1550 $LFS hsm_release $f || error "cannot release $f"
1551 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1552 $LFS hsm_release $f || error "cannot release $f"
1553 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1557 run_test 12p "implicit restore of a file on copytool mount point"
1559 cleanup_test_12q() {
1561 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1562 error "cannot umount $MOUNT3 on $SINGLEAGT"
1566 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1567 skip "need MDS version at least 2.7.58" && return 0
1569 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1570 error "cannot mount $MOUNT3 on $SINGLEAGT"
1572 trap cleanup_test_12q EXIT
1574 # test needs a running copytool
1575 copytool_setup $SINGLEAGT $MOUNT3
1578 local f=$DIR/$tdir/$tfile
1579 local f2=$DIR2/$tdir/$tfile
1580 local fid=$(make_small $f)
1581 local orig_size=$(stat -c "%s" $f)
1583 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1584 wait_request_state $fid ARCHIVE SUCCEED
1586 $LFS hsm_release $f || error "could not release file"
1587 check_hsm_flags $f "0x0000000d"
1590 wait_copytools || error "copytool failed to stop"
1592 cat $f > /dev/null &
1594 # wait a bit to allow implicit restore request to be handled.
1595 # if not, next stat would also block on layout-lock.
1598 local size=$(stat -c "%s" $f2)
1599 [ $size -eq $orig_size ] ||
1600 error "$f2: wrong size after archive: $size != $orig_size"
1602 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1606 size=$(stat -c "%s" $f)
1607 [ $size -eq $orig_size ] ||
1608 error "$f: wrong size after restore: $size != $orig_size"
1610 size=$(stat -c "%s" $f2)
1611 [ $size -eq $orig_size ] ||
1612 error "$f2: wrong size after restore: $size != $orig_size"
1616 size=$(stat -c "%s" $f)
1618 error "$f: wrong size after overwrite: $size != 0"
1620 size=$(stat -c "%s" $f2)
1622 error "$f2: wrong size after overwrite: $size != 0"
1625 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1626 error "cannot umount $MOUNT3 on $SINGLEAGT"
1628 run_test 12q "file attributes are refreshed after restore"
1631 # test needs a running copytool
1634 local ARC_SUBDIR="import.orig"
1638 # populate directory to be imported
1639 for d in $(seq 1 10); do
1640 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1641 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1642 for f in $(seq 1 10); do
1643 CURR_FILE="$CURR_DIR/$tfile.$f"
1644 # write file-specific data
1645 do_facet $SINGLEAGT \
1646 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1647 "file=$CURR_FILE > $CURR_FILE"
1651 import_file "$ARC_SUBDIR" $DIR/$tdir
1652 # diff lustre content and origin (triggers file restoration)
1653 # there must be 10x10 identical files, and no difference
1654 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1655 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1656 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1657 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1659 [ $cnt_diff -eq 0 ] ||
1660 error "$cnt_diff imported files differ from read data"
1661 [ $cnt_ok -eq 100 ] ||
1662 error "not enough identical files ($cnt_ok != 100)"
1666 run_test 13 "Recursively import and restore a directory"
1669 # test needs a running copytool
1674 local f=$DIR/$tdir/$tfile
1675 local fid=$(make_small $f)
1676 local sum=$(md5sum $f | awk '{print $1}')
1677 $LFS hsm_archive $f || error "could not archive file"
1678 wait_request_state $fid ARCHIVE SUCCEED
1682 # create released file (simulate llapi_hsm_import call)
1684 local fid2=$(path2fid $f)
1685 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1686 $LFS hsm_release $f || error "could not release file"
1688 # rebind the archive to the newly created file
1689 echo "rebind $fid to $fid2"
1691 do_facet $SINGLEAGT \
1692 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1693 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1695 # restore file and compare md5sum
1696 local sum2=$(md5sum $f | awk '{print $1}')
1698 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1702 run_test 14 "Rebind archived file to a new fid"
1705 # test needs a running copytool
1710 local f=$DIR/$tdir/$tfile
1712 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1716 for i in $(seq 1 $count); do
1717 fids[$i]=$(make_small $f.$i)
1718 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1719 $LFS hsm_archive $f.$i || error "could not archive file"
1721 wait_all_done $(($count*60))
1725 for i in $(seq 1 $count); do
1728 local fid2=$(path2fid $f.$i)
1729 # add the rebind operation to the list
1730 echo ${fids[$i]} $fid2 >> $tmpfile
1732 # set it released (simulate llapi_hsm_import call)
1733 $LFS hsm_set --archived --exists $f.$i ||
1734 error "could not force hsm flags"
1735 $LFS hsm_release $f.$i || error "could not release file"
1737 nl=$(wc -l < $tmpfile)
1738 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1740 echo "rebind list of files"
1741 do_facet $SINGLEAGT \
1742 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1743 --rebind $tmpfile $DIR" || error "could not rebind file list"
1745 # restore files and compare md5sum
1746 for i in $(seq 1 $count); do
1747 local sum2=$(md5sum $f.$i | awk '{print $1}')
1748 [[ $sum2 == ${sums[$i]} ]] ||
1749 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1755 run_test 15 "Rebind a list of files"
1758 # test needs a running copytool
1762 # create a known size file so we can verify transfer speed
1765 dd if=/dev/zero of=$ref bs=1M count=20
1768 local f=$DIR/$tdir/$tfile
1769 local fid=$(copy_file $ref $f)
1771 local start=$(date +%s)
1773 wait_request_state $fid ARCHIVE SUCCEED
1774 local end=$(date +%s)
1775 # Add 1 to account for rounding errors between start and end (LU-8155)
1776 local duration=$((end - start + 1))
1778 [[ $duration -ge $((goal - 1)) ]] ||
1779 error "Transfer is too fast $duration < $goal"
1783 run_test 16 "Test CT bandwith control option"
1788 local f=$DIR/$tdir/$tfile
1789 touch $f || error "touch $f failed"
1791 # Could not release a non-archived file
1792 $LFS hsm_release $f && error "release should not succeed"
1794 # For following tests, we must test them with HS_ARCHIVED set
1795 $LFS hsm_set --exists --archived $f || error "could not add flag"
1797 # Could not release a file if no-release is set
1798 $LFS hsm_set --norelease $f || error "could not add flag"
1799 $LFS hsm_release $f && error "release should not succeed"
1800 $LFS hsm_clear --norelease $f || error "could not remove flag"
1802 # Could not release a file if lost
1803 $LFS hsm_set --lost $f || error "could not add flag"
1804 $LFS hsm_release $f && error "release should not succeed"
1805 $LFS hsm_clear --lost $f || error "could not remove flag"
1807 # Could not release a file if dirty
1808 $LFS hsm_set --dirty $f || error "could not add flag"
1809 $LFS hsm_release $f && error "release should not succeed"
1810 $LFS hsm_clear --dirty $f || error "could not remove flag"
1812 run_test 20 "Release is not permitted"
1815 # test needs a running copytool
1819 local f=$DIR/$tdir/test_release
1821 # Create a file and check its states
1822 local fid=$(make_small $f)
1823 check_hsm_flags $f "0x00000000"
1825 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1826 # used until file is flushed to disk
1827 if [ $(facet_fstype ost1) == "zfs" ]; then
1828 # this causes an OST_SYNC rpc to be sent
1829 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1830 # clear locks to reread file data
1831 cancel_lru_locks osc
1834 local orig_size=$(stat -c "%s" $f)
1835 local orig_blocks=$(stat -c "%b" $f)
1837 start_full_debug_logging
1839 $LFS hsm_archive $f || error "could not archive file"
1840 wait_request_state $fid ARCHIVE SUCCEED
1842 local blocks=$(stat -c "%b" $f)
1843 [ $blocks -eq $orig_blocks ] ||
1844 error "$f: wrong block number after archive: " \
1845 "$blocks != $orig_blocks"
1846 local size=$(stat -c "%s" $f)
1847 [ $size -eq $orig_size ] ||
1848 error "$f: wrong size after archive: $size != $orig_size"
1850 # Release and check states
1851 $LFS hsm_release $f || error "could not release file"
1852 check_hsm_flags $f "0x0000000d"
1854 blocks=$(stat -c "%b" $f)
1855 [ $blocks -gt 5 ] &&
1856 error "$f: too many blocks after release: $blocks > 5"
1857 size=$(stat -c "%s" $f)
1858 [ $size -ne $orig_size ] &&
1859 error "$f: wrong size after release: $size != $orig_size"
1861 # Check we can release an file without stripe info
1865 check_hsm_flags $f "0x00000000"
1866 $LFS hsm_archive $f || error "could not archive file"
1867 wait_request_state $fid ARCHIVE SUCCEED
1869 # Release and check states
1870 $LFS hsm_release $f || error "could not release file"
1871 check_hsm_flags $f "0x0000000d"
1873 # Release again a file that is already released is OK
1874 $LFS hsm_release $f || fail "second release should succeed"
1875 check_hsm_flags $f "0x0000000d"
1877 stop_full_debug_logging
1881 run_test 21 "Simple release tests"
1884 # test needs a running copytool
1889 local f=$DIR/$tdir/test_release
1890 local swap=$DIR/$tdir/test_swap
1892 # Create a file and check its states
1893 local fid=$(make_small $f)
1894 check_hsm_flags $f "0x00000000"
1896 $LFS hsm_archive $f || error "could not archive file"
1897 wait_request_state $fid ARCHIVE SUCCEED
1899 # Release and check states
1900 $LFS hsm_release $f || error "could not release file"
1901 check_hsm_flags $f "0x0000000d"
1904 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1909 run_test 22 "Could not swap a release file"
1912 # test needs a running copytool
1917 local f=$DIR/$tdir/test_mtime
1919 # Create a file and check its states
1920 local fid=$(make_small $f)
1921 check_hsm_flags $f "0x00000000"
1923 $LFS hsm_archive $f || error "could not archive file"
1924 wait_request_state $fid ARCHIVE SUCCEED
1926 # Set modification time in the past
1927 touch -m -a -d @978261179 $f
1929 # Release and check states
1930 $LFS hsm_release $f || error "could not release file"
1931 check_hsm_flags $f "0x0000000d"
1933 local MTIME=$(stat -c "%Y" $f)
1934 local ATIME=$(stat -c "%X" $f)
1935 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1936 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1940 run_test 23 "Release does not change a/mtime (utime)"
1943 local file=$DIR/$tdir/$tfile
1952 # test needs a running copytool
1957 fid=$(make_small $file)
1959 # Create a file and check its states
1960 check_hsm_flags $file "0x00000000"
1962 # Ensure atime is less than mtime and ctime.
1966 atime0=$(stat -c "%X" $file)
1967 mtime0=$(stat -c "%Y" $file)
1968 ctime0=$(stat -c "%Z" $file)
1970 [ $atime0 -lt $mtime0 ] ||
1971 error "atime $atime0 is not less than mtime $mtime0"
1973 [ $atime0 -lt $ctime0 ] ||
1974 error "atime $atime0 is not less than ctime $ctime0"
1976 # Archive should not change any timestamps.
1977 $LFS hsm_archive $file || error "cannot archive '$file'"
1978 wait_request_state $fid ARCHIVE SUCCEED
1980 atime1=$(stat -c "%X" $file)
1981 mtime1=$(stat -c "%Y" $file)
1982 ctime1=$(stat -c "%Z" $file)
1984 [ $atime0 -eq $atime1 ] ||
1985 error "archive changed atime from $atime0 to $atime1"
1987 [ $mtime0 -eq $mtime1 ] ||
1988 error "archive changed mtime from $mtime0 to $mtime1"
1990 [ $ctime0 -eq $ctime1 ] ||
1991 error "archive changed ctime from $ctime0 to $ctime1"
1993 # Release should not change any timestamps.
1994 $LFS hsm_release $file || error "cannot release '$file'"
1995 check_hsm_flags $file "0x0000000d"
1997 atime1=$(stat -c "%X" $file)
1998 mtime1=$(stat -c "%Y" $file)
1999 ctime1=$(stat -c "%Z" $file)
2001 [ $atime0 -eq $atime1 ] ||
2002 error "release changed atime from $atime0 to $atime1"
2004 [ $mtime0 -eq $mtime1 ] ||
2005 error "release changed mtime from $mtime0 to $mtime1"
2007 [ $ctime0 -eq $ctime1 ] ||
2008 error "release changed ctime from $ctime0 to $ctime1"
2010 # Restore should not change any timestamps.
2011 $LFS hsm_restore $file
2012 wait_request_state $fid RESTORE SUCCEED
2014 atime1=$(stat -c "%X" $file)
2015 mtime1=$(stat -c "%Y" $file)
2016 ctime1=$(stat -c "%Z" $file)
2018 [ $atime0 -eq $atime1 ] ||
2019 error "restore changed atime from $atime0 to $atime1"
2021 [ $mtime0 -eq $mtime1 ] ||
2022 error "restore changed mtime from $mtime0 to $mtime1"
2024 [ $ctime0 -eq $ctime1 ] ||
2025 error "restore changed ctime from $ctime0 to $ctime1"
2029 # Once more, after unmount and mount.
2030 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2031 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2033 atime1=$(stat -c "%X" $file)
2034 mtime1=$(stat -c "%Y" $file)
2035 ctime1=$(stat -c "%Z" $file)
2037 [ $atime0 -eq $atime1 ] ||
2038 error "remount changed atime from $atime0 to $atime1"
2040 [ $mtime0 -eq $mtime1 ] ||
2041 error "remount changed mtime from $mtime0 to $mtime1"
2043 [ $ctime0 -eq $ctime1 ] ||
2044 error "remount changed ctime from $ctime0 to $ctime1"
2046 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2049 local file=$DIR/$tdir/$tfile
2055 # Test needs a running copytool.
2059 # Check that root can do HSM actions on a regular user's file.
2061 fid=$(make_small $file)
2062 sum0=$(md5sum $file)
2064 chown $RUNAS_ID:$RUNAS_GID $file ||
2065 error "cannot chown '$file' to '$RUNAS_ID'"
2067 chmod ugo-w $DIR/$tdir ||
2068 error "cannot chmod '$DIR/$tdir'"
2070 $LFS hsm_archive $file
2071 wait_request_state $fid ARCHIVE SUCCEED
2073 $LFS hsm_release $file
2074 check_hsm_flags $file "0x0000000d"
2076 $LFS hsm_restore $file
2077 wait_request_state $fid RESTORE SUCCEED
2079 # Check that ordinary user can get HSM state.
2080 $RUNAS $LFS hsm_state $file ||
2081 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2083 $LFS hsm_release $file
2084 check_hsm_flags $file "0x0000000d"
2086 # Check that ordinary user can accessed released file.
2087 sum1=$($RUNAS md5sum $file) ||
2088 error "user '$RUNAS_ID' cannot read '$file'"
2090 [ "$sum0" == "$sum1" ] ||
2091 error "md5sum mismatch for '$file'"
2095 run_test 24b "root can archive, release, and restore user files"
2097 cleanup_test_24c() {
2099 set_hsm_param user_request_mask RESTORE
2100 set_hsm_param group_request_mask RESTORE
2101 set_hsm_param other_request_mask RESTORE
2105 local file=$DIR/$tdir/$tfile
2106 local action=archive
2111 # test needs a running copytool
2116 # Save the default masks and check that cleanup_24c will
2117 # restore the request masks correctly.
2118 user_save=$(get_hsm_param user_request_mask)
2119 group_save=$(get_hsm_param group_request_mask)
2120 other_save=$(get_hsm_param other_request_mask)
2122 [ "$user_save" == RESTORE ] ||
2123 error "user_request_mask is '$user_save' expected 'RESTORE'"
2124 [ "$group_save" == RESTORE ] ||
2125 error "group_request_mask is '$group_save' expected 'RESTORE'"
2126 [ "$other_save" == RESTORE ] ||
2127 error "other_request_mask is '$other_save' expected 'RESTORE'"
2129 trap cleanup_test_24c EXIT
2134 chown $RUNAS_ID:nobody $file ||
2135 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2137 $RUNAS $LFS hsm_$action $file &&
2138 error "$action by user should fail"
2140 set_hsm_param user_request_mask $action
2141 $RUNAS $LFS hsm_$action $file ||
2142 error "$action by user should succeed"
2147 chown nobody:$RUNAS_GID $file ||
2148 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2150 $RUNAS $LFS hsm_$action $file &&
2151 error "$action by group should fail"
2153 set_hsm_param group_request_mask $action
2154 $RUNAS $LFS hsm_$action $file ||
2155 error "$action by group should succeed"
2160 chown nobody:nobody $file ||
2161 error "cannot chown '$file' to 'nobody:nobody'"
2163 $RUNAS $LFS hsm_$action $file &&
2164 error "$action by other should fail"
2166 set_hsm_param other_request_mask $action
2167 $RUNAS $LFS hsm_$action $file ||
2168 error "$action by other should succeed"
2173 run_test 24c "check that user,group,other request masks work"
2175 cleanup_test_24d() {
2176 mount -o remount,rw $MOUNT2
2177 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2181 local file1=$DIR/$tdir/$tfile
2182 local file2=$DIR2/$tdir/$tfile
2188 fid1=$(make_small $file1)
2191 $LFS getstripe $file1
2193 trap cleanup_test_24d EXIT
2194 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2195 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2196 copytool_setup $SINGLEAGT "$MOUNT3" ||
2197 error "unable to setup a copytool for the test"
2199 mount -o remount,ro $MOUNT2
2201 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2203 fid2=$(path2fid $file2)
2204 [ "$fid1" == "$fid2" ] ||
2205 error "FID mismatch '$fid1' != '$fid2'"
2207 $LFS hsm_archive $file2 &&
2208 error "archive should fail on read-only mount"
2209 check_hsm_flags $file1 "0x00000000"
2211 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2212 wait_request_state $fid1 ARCHIVE SUCCEED
2214 $LFS hsm_release $file1
2215 $LFS hsm_restore $file2
2216 wait_request_state $fid1 RESTORE SUCCEED
2218 $LFS hsm_release $file1 || error "cannot release '$file1'"
2219 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2221 $LFS hsm_release $file2 &&
2222 error "release should fail on read-only mount"
2226 run_test 24d "check that read-only mounts are respected"
2233 local f=$DIR/$tdir/$tfile
2236 fid=$(make_small $f) || error "cannot create $f"
2237 $LFS hsm_archive $f || error "cannot archive $f"
2238 wait_request_state $fid ARCHIVE SUCCEED
2239 $LFS hsm_release $f || error "cannot release $f"
2240 while ! $LFS hsm_state $f | grep released; do
2244 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2248 run_test 24e "tar succeeds on HSM released files" # LU-6213
2252 # test needs a running copytool
2255 mkdir -p $DIR/$tdir/d1
2256 local f=$DIR/$tdir/$tfile
2257 local fid=$(copy_file /etc/hosts $f)
2260 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2261 error "hsm_archive failed"
2262 wait_request_state $fid ARCHIVE SUCCEED
2263 $LFS hsm_release $f || error "cannot release $f"
2264 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2267 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2268 error "Can not recover the tar contents"
2270 echo "Sum0 = $sum0, sum1 = $sum1"
2271 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2275 run_test 24f "root can archive, release, and restore tar files"
2278 # test needs a running copytool
2282 copy2archive /etc/hosts $tdir/$tfile
2284 local f=$DIR/$tdir/$tfile
2286 import_file $tdir/$tfile $f
2288 $LFS hsm_set --lost $f
2293 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2297 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2298 " (Operation not permitted)"
2301 # test needs a running copytool
2306 local f=$DIR/$tdir/$tfile
2307 local fid=$(copy_file /etc/passwd $f)
2309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2310 wait_request_state $fid ARCHIVE SUCCEED
2313 $LFS hsm_set --lost $f
2317 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2321 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2322 " (Operation not permitted)"
2325 # test needs a running copytool
2329 local f=$DIR/$tdir/$tfile
2331 fid=$(make_custom_file_for_progress $f 39 1000000)
2332 [ $? != 0 ] && skip "not enough free space" && return
2334 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2335 wait_request_state $fid ARCHIVE SUCCEED
2338 wait_request_state $fid REMOVE SUCCEED
2340 check_hsm_flags $f "0x00000000"
2344 run_test 26 "Remove the archive of a valid file"
2346 cleanup_test_26a() {
2348 set_hsm_param remove_archive_on_last_unlink 0
2349 set_hsm_param loop_period $orig_loop_period
2350 set_hsm_param grace_delay $orig_grace_delay
2355 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2356 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2358 # test needs a running copytool
2362 local f=$DIR/$tdir/$tfile
2363 local fid=$(copy_file /etc/passwd $f)
2365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2366 wait_request_state $fid ARCHIVE SUCCEED
2368 local f2=$DIR/$tdir/${tfile}_2
2369 local fid2=$(copy_file /etc/passwd $f2)
2371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2372 wait_request_state $fid2 ARCHIVE SUCCEED
2374 local f3=$DIR/$tdir/${tfile}_3
2375 local fid3=$(copy_file /etc/passwd $f3)
2377 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2378 wait_request_state $fid3 ARCHIVE SUCCEED
2380 trap cleanup_test_26a EXIT
2382 # set a long grace_delay vs short loop_period
2383 local orig_loop_period=$(get_hsm_param loop_period)
2384 local orig_grace_delay=$(get_hsm_param grace_delay)
2385 set_hsm_param loop_period 10
2386 set_hsm_param grace_delay 100
2390 set_hsm_param remove_archive_on_last_unlink 1
2392 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2397 set_hsm_param remove_archive_on_last_unlink 0
2399 wait_request_state $fid2 REMOVE SUCCEED
2401 assert_request_count $fid REMOVE 0 \
2402 "Unexpected archived data remove request for $f"
2403 assert_request_count $fid3 REMOVE 0 \
2404 "Unexpected archived data remove request for $f3"
2408 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2410 cleanup_test_26b() {
2412 set_hsm_param remove_archive_on_last_unlink 0
2418 # test needs a running copytool
2422 local f=$DIR/$tdir/$tfile
2423 local fid=$(copy_file /etc/passwd $f)
2425 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2426 wait_request_state $fid ARCHIVE SUCCEED
2428 trap cleanup_test_26b EXIT
2430 set_hsm_param remove_archive_on_last_unlink 1
2433 cdt_check_state stopped
2437 set_hsm_param remove_archive_on_last_unlink 0
2439 wait_request_state $fid REMOVE WAITING
2442 # copytool must re-register
2444 wait_copytools || error "copytool failed to stop"
2445 HSM_ARCHIVE_PURGE=false copytool_setup
2447 wait_request_state $fid REMOVE SUCCEED
2451 run_test 26b "RAoLU policy when CDT off"
2453 cleanup_test_26c() {
2455 set_hsm_param remove_archive_on_last_unlink 0
2456 set_hsm_param loop_period $orig_loop_period
2457 set_hsm_param grace_delay $orig_grace_delay
2463 # test needs a running copytool
2467 local f=$DIR/$tdir/$tfile
2468 local fid=$(copy_file /etc/passwd $f)
2470 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2471 wait_request_state $fid ARCHIVE SUCCEED
2473 local f2=$DIR/$tdir/${tfile}_2
2474 local fid2=$(copy_file /etc/passwd $f2)
2476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2477 wait_request_state $fid2 ARCHIVE SUCCEED
2479 trap cleanup_test_26c EXIT
2481 # set a long grace_delay vs short loop_period
2482 local orig_loop_period=$(get_hsm_param loop_period)
2483 local orig_grace_delay=$(get_hsm_param grace_delay)
2484 set_hsm_param loop_period 10
2485 set_hsm_param grace_delay 100
2487 set_hsm_param remove_archive_on_last_unlink 1
2489 multiop_bg_pause $f O_c || error "open $f failed"
2495 wait_request_state $fid2 REMOVE SUCCEED
2496 assert_request_count $fid REMOVE 0 \
2497 "Unexpected archived data remove request for $f"
2499 kill -USR1 $pid || error "multiop early exit"
2500 # should reach autotest timeout if multiop fails to trap
2501 # signal, close file, and exit ...
2504 set_hsm_param remove_archive_on_last_unlink 0
2506 wait_request_state $fid REMOVE SUCCEED
2510 run_test 26c "RAoLU effective when file closed"
2512 cleanup_test_26d() {
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/motd $f 1)
2529 $LFS hsm_archive $f || error "could not archive file"
2530 wait_request_state $fid ARCHIVE SUCCEED
2532 trap cleanup_test_26d EXIT
2534 # set a long grace_delay vs short loop_period
2535 local orig_loop_period=$(get_hsm_param loop_period)
2536 local orig_grace_delay=$(get_hsm_param grace_delay)
2537 set_hsm_param loop_period 10
2538 set_hsm_param grace_delay 100
2540 set_hsm_param remove_archive_on_last_unlink 1
2542 multiop_bg_pause $f O_c || error "multiop failed"
2549 set_hsm_param remove_archive_on_last_unlink 0
2551 wait_request_state $fid REMOVE SUCCEED
2553 client_up || client_up || true
2555 kill -USR1 $MULTIPID
2556 wait $MULTIPID || error "multiop close failed"
2560 run_test 26d "RAoLU when Client eviction"
2563 # test needs a running copytool
2567 make_archive $tdir/$tfile
2568 local f=$DIR/$tdir/$tfile
2569 import_file $tdir/$tfile $f
2570 local fid=$(path2fid $f)
2574 [[ $? != 0 ]] || error "Remove of a released file should fail"
2578 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2581 # test needs a running copytool
2585 local f=$DIR/$tdir/$tfile
2587 fid=$(make_custom_file_for_progress $f 39 1000000)
2588 [ $? != 0 ] && skip "not enough free space" && return
2590 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2591 wait_request_state $fid ARCHIVE SUCCEED
2596 [[ $? != 0 ]] || error "Remove of a released file should fail"
2600 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2603 # test needs a running copytool
2607 local f=$DIR/$tdir/$tfile
2609 fid=$(make_custom_file_for_progress $f 39 1000000)
2610 [ $? != 0 ] && skip "not enough free space" && return
2612 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2613 wait_request_state $fid ARCHIVE SUCCEED
2622 wait_request_state $fid REMOVE SUCCEED
2626 run_test 28 "Concurrent archive/file remove"
2629 # Tests --mntpath and --archive options
2632 copytool_setup $SINGLEAGT $MOUNT $archive_id
2634 # Bad archive number
2635 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2636 grep "Invalid argument" ||
2637 error "unexpected hsm_remove failure (1)"
2639 # mntpath is present but file is given
2640 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2641 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2642 error "unexpected hsm_remove failure (2)"
2646 run_test 29a "Tests --mntpath and --archive options"
2649 # test needs a running copytool
2653 local f=$DIR/$tdir/$tfile
2654 local fid=$(make_small $f)
2656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2657 wait_request_state $fid ARCHIVE SUCCEED
2661 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2662 wait_request_state $fid REMOVE SUCCEED
2666 run_test 29b "Archive/delete/remove by FID from the archive."
2669 # test needs a running copytool
2673 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2674 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2675 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2677 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2678 wait_request_state $fid1 ARCHIVE SUCCEED
2679 wait_request_state $fid2 ARCHIVE SUCCEED
2680 wait_request_state $fid3 ARCHIVE SUCCEED
2682 rm -f $DIR/$tdir/$tfile-[1-3]
2684 echo $fid1 > $DIR/$tdir/list
2685 echo $fid2 >> $DIR/$tdir/list
2686 echo $fid3 >> $DIR/$tdir/list
2688 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2689 --filelist $DIR/$tdir/list
2690 wait_request_state $fid1 REMOVE SUCCEED
2691 wait_request_state $fid2 REMOVE SUCCEED
2692 wait_request_state $fid3 REMOVE SUCCEED
2696 run_test 29c "Archive/delete/remove by FID, using a file list."
2699 # test needs more than one CT
2700 needclients 3 || return 0
2706 copytool_cleanup $(comma_list $(agts_nodes))
2708 # start all of the copytools
2709 for n in $(seq $AGTCOUNT); do
2710 copytool_setup agt$n $MOUNT2 $n
2713 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2716 file=$DIR/$tdir/$tfile
2717 fid=$(make_small $file)
2719 $LFS hsm_archive $file
2720 wait_request_state $fid ARCHIVE SUCCEED
2721 check_hsm_flags $file "0x00000009"
2725 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2726 error "cannot hsm_remove '$fid'"
2728 # give time for CDT to handle remove request and create broadcasted
2731 # remove request has been broadcasted ?
2732 local cnt=$(get_request_count $fid REMOVE)
2733 # broadcasted requests + original
2734 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2735 error "remove not broadcasted to all CTs"
2737 # give time for CDT and CTs to handle broadcasted
2738 wait_for_loop_period
2740 # each agent serves one different archive_id, so broadcasted
2741 # hsm_remove request should only succeed once and fail at all others
2745 for n in $(seq $AGTCOUNT); do
2746 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2747 $HSM_PARAM.actions | awk \
2748 '/'$fid'.*action=REMOVE archive#='$n'/ \
2749 {print \\\$13}' | cut -f2 -d=")
2750 if [[ "$res" == "SUCCEED" ]]; then
2752 elif [[ "$res" == "FAILED" ]]; then
2757 [[ $scnt -ne 1 ]] &&
2758 error "one and only CT should have removed successfully"
2760 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2761 error "all but one CT should have failed to remove"
2764 copytool_cleanup $(comma_list $(agts_nodes))
2767 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2768 "request to be sent once for each registered archive_id"
2771 # restore at exec cannot work on agent node (because of Linux kernel
2772 # protection of executables)
2773 needclients 2 || return 0
2775 # test needs a running copytool
2779 copy2archive /bin/true $tdir/$tfile
2781 local f=$DIR/$tdir/true
2782 import_file $tdir/$tfile $f
2784 local fid=$(path2fid $f)
2786 # set no retry action mode
2792 # remove no try action mode
2796 [[ $st == 0 ]] || error "Failed to exec a released file"
2800 run_test 30a "Restore at exec (import case)"
2803 # restore at exec cannot work on agent node (because of Linux kernel
2804 # protection of executables)
2805 needclients 2 || return 0
2807 # test needs a running copytool
2811 local f=$DIR/$tdir/true
2812 local fid=$(copy_file /bin/true $f)
2814 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2815 wait_request_state $fid ARCHIVE SUCCEED
2818 # set no retry action mode
2824 # remove no try action mode
2828 [[ $st == 0 ]] || error "Failed to exec a released file"
2832 run_test 30b "Restore at exec (release case)"
2835 needclients 2 || return 0
2837 # test needs a running copytool
2841 local f=$DIR/$tdir/SLEEP
2842 local slp_sum1=$(md5sum /bin/sleep)
2843 local fid=$(copy_file /bin/sleep $f)
2845 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2846 wait_request_state $fid ARCHIVE SUCCEED
2848 check_hsm_flags $f "0x0000000d"
2849 # set no retry action mode
2851 do_node $CLIENT2 "$f 10" &
2855 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2857 [[ $? == 0 ]] || error "Execution failed during run"
2859 if [[ $? != 0 ]]; then
2860 local slp_sum2=$(md5sum /bin/sleep)
2861 # in case sleep file is modified during the test
2862 [[ $slp_sum1 == $slp_sum2 ]] &&
2863 error "Binary overwritten during exec"
2867 # remove no try action mode
2869 check_hsm_flags $f "0x00000009"
2873 run_test 30c "Update during exec of released file must fail"
2875 restore_and_check_size() {
2878 local s=$(stat -c "%s" $f)
2880 local st=$(get_hsm_flags $f)
2884 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2886 n=$(stat -c "%s" $f)
2887 # we echo in both cases to show stat is not hang
2888 if [[ $n != $s ]]; then
2889 echo "size seen is $n != $s"
2892 echo "size seen is right: $n == $s"
2896 st=$(get_hsm_flags $f)
2898 if [[ "$st" = "0x00000009" ]]; then
2901 echo " restore is too long"
2902 wait_request_state $fid RESTORE SUCCEED
2908 # test needs a running copytool
2913 make_archive $tdir/$tfile
2914 local f=$DIR/$tdir/$tfile
2915 import_file $tdir/$tfile $f
2916 local fid=$($LFS path2fid $f)
2917 HSM_ARCHIVE_PURGE=false copytool_setup
2919 restore_and_check_size $f $fid
2922 [[ $err -eq 0 ]] || error "File size changed during restore"
2926 run_test 31a "Import a large file and check size during restore"
2930 # test needs a running copytool
2935 local f=$DIR/$tdir/$tfile
2937 fid=$(make_custom_file_for_progress $f 39 1000000)
2938 [ $? != 0 ] && skip "not enough free space" && return
2940 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2941 wait_request_state $fid ARCHIVE SUCCEED
2944 restore_and_check_size $f $fid
2947 [[ $err -eq 0 ]] || error "File size changed during restore"
2951 run_test 31b "Restore a large unaligned file and check size during restore"
2954 # test needs a running copytool
2959 local f=$DIR/$tdir/$tfile
2961 fid=$(make_custom_file_for_progress $f 33 1048576)
2962 [ $? != 0 ] && skip "not enough free space" && return
2964 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2965 wait_request_state $fid ARCHIVE SUCCEED
2968 restore_and_check_size $f $fid
2971 [[ $err -eq 0 ]] || error "File size changed during restore"
2975 run_test 31c "Restore a large aligned file and check size during restore"
2978 # test needs a running copytool
2983 local f=$DIR/$tdir/$tfile
2985 fid=$(make_custom_file_for_progress $f 39 1000000)
2986 [ $? != 0 ] && skip "not enough free space" && return
2988 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2989 wait_request_state $fid ARCHIVE SUCCEED
2992 # to be sure wait_all_done will not be mislead by previous tests
2995 wait_for_grace_delay
2996 # Also raise grace_delay significantly so the Canceled
2997 # Restore action will stay enough long avail.
2998 local old_grace=$(get_hsm_param grace_delay)
2999 set_hsm_param grace_delay 100
3001 md5sum $f >/dev/null &
3003 wait_request_state $fid RESTORE STARTED
3008 # Check restore trigger process was killed
3009 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3013 # instead of waiting+checking both Restore and Cancel ops
3014 # sequentially, wait for both to be finished and then check
3016 wait_all_done 100 $fid
3017 local rstate=$(get_request_state $fid RESTORE)
3018 local cstate=$(get_request_state $fid CANCEL)
3020 # restore orig grace_delay.
3021 set_hsm_param grace_delay $old_grace
3023 if [[ "$rstate" == "CANCELED" ]] ; then
3024 [[ "$cstate" == "SUCCEED" ]] ||
3025 error "Restore state is CANCELED and Cancel state " \
3026 "is not SUCCEED but $cstate"
3027 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3028 elif [[ "$rstate" == "SUCCEED" ]] ; then
3029 [[ "$cstate" == "FAILED" ]] ||
3030 error "Restore state is SUCCEED and Cancel state " \
3031 "is not FAILED but $cstate"
3032 echo "Restore state is SUCCEED, Cancel state is FAILED"
3034 error "Restore state is $rstate and Cancel state is $cstate"
3038 error "Cannot kill process waiting for restore ($killed)"
3042 run_test 33 "Kill a restore waiting process"
3045 # test needs a running copytool
3050 local f=$DIR/$tdir/$tfile
3052 fid=$(make_custom_file_for_progress $f 39 1000000)
3053 [ $? != 0 ] && skip "not enough free space" && return
3055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3056 wait_request_state $fid ARCHIVE SUCCEED
3059 md5sum $f >/dev/null &
3061 wait_request_state $fid RESTORE STARTED
3063 rm $f || error "rm $f failed"
3064 # rm must not block during restore
3065 wait_request_state $fid RESTORE STARTED
3067 wait_request_state $fid RESTORE SUCCEED
3068 # check md5sum pgm finished
3069 local there=$(ps -o pid,comm hp $pid >/dev/null)
3070 [[ -z $there ]] || error "Restore initiator does not exit"
3072 wait $pid || error "Restore initiator failed with $?"
3076 run_test 34 "Remove file during restore"
3079 # test needs a running copytool
3084 local f=$DIR/$tdir/$tfile
3085 local f1=$DIR/$tdir/$tfile-1
3087 fid=$(make_custom_file_for_progress $f 39 1000000)
3088 [ $? != 0 ] && skip "not enough free space" && return
3090 local fid1=$(copy_file /etc/passwd $f1)
3091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3092 wait_request_state $fid ARCHIVE SUCCEED
3095 md5sum $f >/dev/null &
3097 wait_request_state $fid RESTORE STARTED
3099 mv $f1 $f || error "mv $f1 $f failed"
3100 # mv must not block during restore
3101 wait_request_state $fid RESTORE STARTED
3103 wait_request_state $fid RESTORE SUCCEED
3104 # check md5sum pgm finished
3105 local there=$(ps -o pid,comm hp $pid >/dev/null)
3106 [[ -z $there ]] || error "Restore initiator does not exit"
3108 wait $pid || error "Restore initiator failed with $?"
3111 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3115 run_test 35 "Overwrite file during restore"
3118 # test needs a running copytool
3123 local f=$DIR/$tdir/$tfile
3125 fid=$(make_custom_file_for_progress $f 39 1000000)
3126 [ $? != 0 ] && skip "not enough free space" && return
3128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3129 wait_request_state $fid ARCHIVE SUCCEED
3132 md5sum $f >/dev/null &
3134 wait_request_state $fid RESTORE STARTED
3137 # rm must not block during restore
3138 wait_request_state $fid RESTORE STARTED
3140 wait_request_state $fid RESTORE SUCCEED
3141 # check md5sum pgm finished
3142 local there=$(ps -o pid,comm hp $pid >/dev/null)
3144 error "Restore initiator does not exit"
3146 wait $pid || error "Restore initiator failed with $?"
3150 run_test 36 "Move file during restore"
3153 # LU-5683: check that an archived dirty file can be rearchived.
3155 copytool_setup $SINGLEAGT $MOUNT2
3158 local f=$DIR/$tdir/$tfile
3161 fid=$(make_small $f) || error "cannot create small file"
3163 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3164 wait_request_state $fid ARCHIVE SUCCEED
3165 $LFS hsm_release $f || error "cannot release $f"
3167 # Allow previous archive request to expire from the actions log.
3168 wait_for_grace_delay
3171 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3174 wait_request_state $fid ARCHIVE SUCCEED
3178 run_test 37 "re-archive a dirty file"
3185 for n in $(seq 1 $count); do
3186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3188 echo "$count archive requests submitted"
3193 set_hsm_param max_requests $max_requests
3198 local stream_count=4
3199 local file_count=100
3201 local f=$DIR/$tdir/$tfile
3205 local max_requests=$(get_hsm_param max_requests)
3207 # Increase the number of HSM request that can be performed in
3208 # parallel. With the coordinator running once per second, this
3209 # also limits the number of requests per seconds that can be
3210 # performed, so we pick a decent number. But we also need to keep
3211 # that number low because the copytool has no rate limit and will
3212 # fail some requests if if gets too many at once.
3213 set_hsm_param max_requests 300
3215 trap cleanup_test_40 EXIT
3217 for i in $(seq 1 $file_count); do
3218 for p in $(seq 1 $stream_count); do
3219 fid=$(copy_file /etc/hosts $f.$p.$i)
3222 # force copytool to use a local/temp archive dir to ensure best
3223 # performance vs remote/NFS mounts used in auto-tests
3224 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3227 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3229 # to be sure wait_all_done will not be mislead by previous tests
3231 wait_for_grace_delay
3233 # start archive streams in background (archive files in parallel)
3234 for p in $(seq 1 $stream_count); do
3235 multi_archive $f.$p $file_count &
3238 echo -n "Wait for all requests being enqueued..."
3245 run_test 40 "Parallel archive requests"
3248 # test needs a running copytool
3252 local f=$DIR/$tdir/$tfile
3253 local fid=$(copy_file /etc/motd $f 1)
3255 $LFS hsm_archive $f || error "could not archive file"
3256 wait_request_state $fid ARCHIVE SUCCEED
3257 check_hsm_flags $f "0x00000009"
3259 multiop_bg_pause $f O_c || error "multiop failed"
3263 client_up || client_up || true
3265 kill -USR1 $MULTIPID
3266 wait $MULTIPID || error "multiop close failed"
3268 check_hsm_flags $f "0x0000000b"
3272 run_test 52 "Opened for write file on an evicted client should be set dirty"
3275 # test needs a running copytool
3279 local f=$DIR/$tdir/$tfile
3280 local fid=$(copy_file /etc/motd $f 1)
3282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3283 error "could not archive file"
3284 wait_request_state $fid ARCHIVE SUCCEED
3285 check_hsm_flags $f "0x00000009"
3287 multiop_bg_pause $f o_c || error "multiop failed"
3291 client_up || client_up || true
3293 kill -USR1 $MULTIPID
3294 wait $MULTIPID || error "multiop close failed"
3296 check_hsm_flags $f "0x00000009"
3300 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3303 # test needs a running copytool
3307 local f=$DIR/$tdir/$tfile
3308 local fid=$(make_custom_file_for_progress $f 39 1000000)
3310 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3311 error "could not archive file"
3312 wait_request_state $fid ARCHIVE STARTED
3314 check_hsm_flags $f "0x00000001"
3316 # Avoid coordinator resending this request as soon it has failed.
3321 wait_request_state $fid ARCHIVE FAILED
3323 check_hsm_flags $f "0x00000003"
3328 run_test 54 "Write during an archive cancels it"
3331 # test needs a running copytool
3335 local f=$DIR/$tdir/$tfile
3336 local fid=$(make_custom_file_for_progress $f 39 1000000)
3338 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3339 error "could not archive file"
3340 wait_request_state $fid ARCHIVE STARTED
3342 check_hsm_flags $f "0x00000001"
3344 # Avoid coordinator resending this request as soon it has failed.
3347 $TRUNCATE $f 1024 || error "truncate failed"
3349 wait_request_state $fid ARCHIVE FAILED
3351 check_hsm_flags $f "0x00000003"
3356 run_test 55 "Truncate during an archive cancels it"
3359 # test needs a running copytool
3363 local f=$DIR/$tdir/$tfile
3365 fid=$(make_custom_file_for_progress $f 39 1000000)
3366 [ $? != 0 ] && skip "not enough free space" && return
3368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3369 error "could not archive file"
3370 wait_request_state $fid ARCHIVE STARTED
3372 check_hsm_flags $f "0x00000001"
3374 # Change metadata and sync to be sure we are not changing only
3379 wait_request_state $fid ARCHIVE SUCCEED
3381 check_hsm_flags $f "0x00000009"
3385 run_test 56 "Setattr during an archive is ok"
3388 # Need one client for I/O, one for request
3389 needclients 2 || return 0
3391 # test needs a running copytool
3395 local f=$DIR/$tdir/test_archive_remote
3396 # Create a file on a remote node
3397 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3398 "count=2 conv=fsync"
3401 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3402 error "hsm_archive failed"
3403 local fid=$(path2fid $f)
3404 wait_request_state $fid ARCHIVE SUCCEED
3406 # Release and implicit restore it
3407 do_node $CLIENT2 "$LFS hsm_release $f" ||
3408 error "hsm_release failed"
3409 do_node $CLIENT2 "md5sum $f" ||
3410 error "hsm_restore failed"
3412 wait_request_state $fid RESTORE SUCCEED
3416 run_test 57 "Archive a file with dirty cache on another node"
3418 truncate_released_file() {
3422 local sz=$(stat -c %s $src_file)
3423 local f=$DIR/$tdir/$tfile
3424 local fid=$(copy_file $1 $f)
3428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3429 error "could not archive file"
3430 wait_request_state $fid ARCHIVE SUCCEED
3432 $LFS hsm_release $f || error "could not release file"
3434 $TRUNCATE $f $trunc_to || error "truncate failed"
3437 local sz1=$(stat -c %s $f)
3438 [[ $sz1 == $trunc_to ]] ||
3439 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3442 check_hsm_flags $f "0x0000000b"
3444 local state=$(get_request_state $fid RESTORE)
3445 [[ "$state" == "SUCCEED" ]] ||
3446 error "truncate $sz does not trig restore, state = $state"
3448 $TRUNCATE $ref $trunc_to
3449 cmp $ref $f || error "file data wrong after truncate"
3455 # test needs a running copytool
3460 local sz=$(stat -c %s /etc/passwd)
3462 echo "truncate up from $sz to $((sz*2))"
3463 truncate_released_file /etc/passwd $((sz*2))
3465 echo "truncate down from $sz to $((sz/2))"
3466 truncate_released_file /etc/passwd $((sz/2))
3468 echo "truncate to 0"
3469 truncate_released_file /etc/passwd 0
3473 run_test 58 "Truncate a released file will trigger restore"
3477 local server_version=$(lustre_version_code $SINGLEMDS)
3478 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3479 skip "Need MDS version at least 2.7.63" && return
3482 $MCREATE $DIR/$tfile || error "mcreate failed"
3483 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3484 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3485 fid=$(path2fid $DIR/$tfile)
3486 wait_request_state $fid ARCHIVE SUCCEED
3487 $LFS hsm_release $DIR/$tfile || error "release failed"
3490 run_test 59 "Release stripeless file with non-zero size"
3493 # This test validates the fix for LU-4512. Ensure that the -u
3494 # option changes the progress reporting interval from the
3495 # default (30 seconds) to the user-specified interval.
3497 local progress_timeout=$((interval * 4))
3499 # test needs a new running copytool
3501 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3504 local f=$DIR/$tdir/$tfile
3506 fid=$(make_custom_file_for_progress $f 10)
3507 [ $? != 0 ] && skip "not enough free space" && return
3510 local mdt=${MDT_PREFIX}${mdtidx}
3511 local mds=mds$((mdtidx + 1))
3513 # Wait for copytool to register
3514 wait_update_facet $mds \
3515 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3516 uuid 100 || error "coyptool failed to register with $mdt"
3518 local start_at=$(date +%s)
3519 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3520 error "could not archive file"
3522 local agent=$(facet_active_host $SINGLEAGT)
3523 local prefix=$TESTLOG_PREFIX
3524 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3525 local copytool_log=$prefix.copytool_log.$agent.log
3528 wait_update $agent \
3529 "grep -o start.copy $copytool_log" "start copy" 100 ||
3530 error "copytool failed to start"
3532 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3533 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3539 echo -n "Expecting a progress update within $progress_timeout seconds... "
3541 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3542 if [ $RESULT -gt 0 ]; then
3543 echo "$RESULT bytes copied in $WAIT seconds."
3545 elif [ $WAIT -ge $progress_timeout ]; then
3546 error "Timed out waiting for progress update!"
3549 WAIT=$((WAIT + sleep))
3553 local finish_at=$(date +%s)
3554 local elapsed=$((finish_at - start_at))
3556 # Ensure that the progress update occurred within the expected window.
3557 if [ $elapsed -lt $((interval - 1)) ]; then
3558 error "Expected progress update after at least $interval seconds"
3561 echo "Wait for on going archive hsm action to complete"
3562 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3563 echo "File archiving not completed even after 10 secs"
3568 run_test 60 "Changing progress update interval from default"
3571 # test needs a running copytool
3575 local f=$DIR/$tdir/$tfile
3576 local fid=$(copy_file /etc/passwd $f)
3578 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3581 wait_request_state $fid ARCHIVE FAILED
3585 run_test 61 "Waiting archive of a removed file should fail"
3588 # test needs a new running copytool
3590 copytool_monitor_setup
3591 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3593 # Just start and stop the copytool to generate events.
3596 # Wait for the copytool to register.
3597 wait_update --verbose $(facet_active_host mds1) \
3598 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3600 error "copytool failed to register with MDT0000"
3604 local REGISTER_EVENT
3605 local UNREGISTER_EVENT
3606 while read event; do
3607 local parsed=$(parse_json_event "$event")
3608 if [ -z "$parsed" ]; then
3609 error "Copytool sent malformed event: $event"
3613 if [ $event_type == "REGISTER" ]; then
3614 REGISTER_EVENT=$event
3615 elif [ $event_type == "UNREGISTER" ]; then
3616 UNREGISTER_EVENT=$event
3618 done < <(echo $"$(get_copytool_event_log)")
3620 if [ -z "$REGISTER_EVENT" ]; then
3621 error "Copytool failed to send register event to FIFO"
3624 if [ -z "$UNREGISTER_EVENT" ]; then
3625 error "Copytool failed to send unregister event to FIFO"
3628 copytool_monitor_cleanup
3629 echo "Register/Unregister events look OK."
3631 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3634 # Bump progress interval for livelier events.
3637 # test needs a new running copytool
3639 copytool_monitor_setup
3640 HSMTOOL_UPDATE_INTERVAL=$interval \
3641 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3644 local f=$DIR/$tdir/$tfile
3646 fid=$(make_custom_file_for_progress $f 39 1000000)
3647 [ $? != 0 ] && skip "not enough free space" && return
3649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3650 error "could not archive file"
3651 wait_request_state $fid ARCHIVE SUCCEED
3653 local expected_fields="event_time data_fid source_fid"
3654 expected_fields+=" total_bytes current_bytes"
3658 while read event; do
3659 # Make sure we're not getting anything from previous events.
3660 for field in $expected_fields; do
3664 local parsed=$(parse_json_event "$event")
3665 if [ -z "$parsed" ]; then
3666 error "Copytool sent malformed event: $event"
3670 if [ $event_type == "ARCHIVE_START" ]; then
3673 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3676 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3680 # Do some simple checking of the progress update events.
3681 for expected_field in $expected_fields; do
3682 if [ -z ${!expected_field+x} ]; then
3683 error "Missing $expected_field field in event"
3687 if [ $total_bytes -eq 0 ]; then
3688 error "Expected total_bytes to be > 0"
3691 # These should be identical throughout an archive
3693 if [ $source_fid != $data_fid ]; then
3694 error "Expected source_fid to equal data_fid"
3696 done < <(echo $"$(get_copytool_event_log)")
3698 if [ -z "$START_EVENT" ]; then
3699 error "Copytool failed to send archive start event to FIFO"
3702 if [ -z "$FINISH_EVENT" ]; then
3703 error "Copytool failed to send archive finish event to FIFO"
3706 echo "Archive events look OK."
3710 copytool_monitor_cleanup
3712 run_test 71 "Copytool logs JSON archive events to FIFO"
3715 # Bump progress interval for livelier events.
3718 # test needs a new running copytool
3720 copytool_monitor_setup
3721 HSMTOOL_UPDATE_INTERVAL=$interval \
3722 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3723 local test_file=$HSMTOOL_MONITOR_DIR/file
3725 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3727 do_facet $SINGLEAGT "$cmd" ||
3728 error "cannot create $test_file on $SINGLEAGT"
3729 copy2archive $test_file $tdir/$tfile
3732 local f=$DIR/$tdir/$tfile
3733 import_file $tdir/$tfile $f
3734 f=$DIR2/$tdir/$tfile
3735 echo "Verifying released state: "
3736 check_hsm_flags $f "0x0000000d"
3738 local fid=$(path2fid $f)
3740 wait_request_state $fid RESTORE SUCCEED
3742 local expected_fields="event_time data_fid source_fid"
3743 expected_fields+=" total_bytes current_bytes"
3747 while read event; do
3748 # Make sure we're not getting anything from previous events.
3749 for field in $expected_fields; do
3753 local parsed=$(parse_json_event "$event")
3754 if [ -z "$parsed" ]; then
3755 error "Copytool sent malformed event: $event"
3759 if [ $event_type == "RESTORE_START" ]; then
3761 if [ $source_fid != $data_fid ]; then
3762 error "source_fid should == data_fid at start"
3765 elif [ $event_type == "RESTORE_FINISH" ]; then
3767 if [ $source_fid != $data_fid ]; then
3768 error "source_fid should == data_fid at finish"
3771 elif [ $event_type != "RESTORE_RUNNING" ]; then
3775 # Do some simple checking of the progress update events.
3776 for expected_field in $expected_fields; do
3777 if [ -z ${!expected_field+x} ]; then
3778 error "Missing $expected_field field in event"
3782 if [ $total_bytes -eq 0 ]; then
3783 error "Expected total_bytes to be > 0"
3786 # When a restore starts out, the data fid is the same as the
3787 # source fid. After the restore has gotten going, we learn
3788 # the new data fid. Once the restore has finished, the source
3789 # fid is set to the new data fid.
3791 # We test this because some monitoring software may depend on
3792 # this behavior. If it changes, then the consumers of these
3793 # events may need to be modified.
3794 if [ $source_fid == $data_fid ]; then
3795 error "source_fid should != data_fid during restore"
3797 done < <(echo $"$(get_copytool_event_log)")
3799 if [ -z "$START_EVENT" ]; then
3800 error "Copytool failed to send restore start event to FIFO"
3803 if [ -z "$FINISH_EVENT" ]; then
3804 error "Copytool failed to send restore finish event to FIFO"
3807 echo "Restore events look OK."
3811 copytool_monitor_cleanup
3815 run_test 72 "Copytool logs JSON restore events to FIFO"
3818 file_count=51 # Max number of files constrained by LNET message size
3819 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3820 local f=$DIR/$tdir/$tfile
3821 local FILELIST=/tmp/filelist.txt
3825 for i in $(seq 1 $file_count); do
3826 fid=$(copy_file /etc/hosts $f.$i)
3827 echo $f.$i >> $FILELIST
3829 # force copytool to use a local/temp archive dir to ensure best
3830 # performance vs remote/NFS mounts used in auto-tests
3831 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3834 local dai=$(get_hsm_param default_archive_id)
3835 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3837 # to be sure wait_all_done will not be mislead by previous tests
3839 wait_for_grace_delay
3840 $LFS hsm_archive --filelist $FILELIST ||
3841 error "cannot archive a file list"
3843 $LFS hsm_release --filelist $FILELIST ||
3844 error "cannot release a file list"
3845 $LFS hsm_restore --filelist $FILELIST ||
3846 error "cannot restore a file list"
3850 run_test 90 "Archive/restore a file list"
3852 double_verify_reset_hsm_param() {
3854 echo "Testing $HSM_PARAM.$p"
3855 local val=$(get_hsm_param $p)
3857 local val2=$(($val * 2))
3858 set_hsm_param $p $val2
3859 val=$(get_hsm_param $p)
3860 [[ $val == $val2 ]] ||
3861 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3862 echo "Set $p to 0 must failed"
3866 set_hsm_param $p $save
3868 if [[ $rc == 0 ]]; then
3869 error "we must not be able to set $HSM_PARAM.$p to 0"
3874 double_verify_reset_hsm_param loop_period
3875 double_verify_reset_hsm_param grace_delay
3876 double_verify_reset_hsm_param active_request_timeout
3877 double_verify_reset_hsm_param max_requests
3878 double_verify_reset_hsm_param default_archive_id
3880 run_test 100 "Set coordinator /proc tunables"
3887 run_test 102 "Verify coordinator control"
3890 # test needs a running copytool
3897 for i in $(seq 1 20); do
3898 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3900 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3904 echo "Current requests"
3905 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3906 $HSM_PARAM.actions |\
3907 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3909 [[ -z "$res" ]] || error "Some request have not been canceled"
3913 run_test 103 "Purge all requests"
3920 local f=$DIR/$tdir/$tfile
3922 fid=$(make_custom_file_for_progress $f 39 1000000)
3923 [ $? != 0 ] && skip "not enough free space" && return
3925 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3926 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3927 $HSM_PARAM.actions |\
3928 grep $fid | cut -f16 -d=")
3930 [[ "$data1" == "$DATAHEX" ]] ||
3931 error "Data field in records is ($data1) and not ($DATAHEX)"
3936 wait_request_state $fid ARCHIVE SUCCEED
3940 run_test 104 "Copy tool data field"
3942 cleanup_test_105() {
3944 set_hsm_param max_requests $max_requests
3949 local max_requests=$(get_hsm_param max_requests)
3953 set_hsm_param max_requests 300
3955 trap cleanup_test_105 EXIT
3958 for i in $(seq -w 1 10); do
3959 cp /etc/passwd $DIR/$tdir/$i
3960 $LFS hsm_archive $DIR/$tdir/$i
3962 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3963 $HSM_PARAM.actions |\
3964 grep WAITING | wc -l")
3968 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3969 $HSM_PARAM.actions |\
3970 grep WAITING | wc -l")
3973 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3974 error "Requests count after shutdown $reqcnt2 != "\
3975 "before shutdown $reqcnt1"
3979 run_test 105 "Restart of coordinator"
3982 # test needs a running copytool
3985 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3987 check_agent_registered $uuid
3989 search_copytools || error "No copytool found"
3992 check_agent_unregistered $uuid
3995 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3996 check_agent_registered $uuid
4000 run_test 106 "Copytool register/unregister"
4003 # test needs a running copytool
4005 # create and archive file
4007 local f1=$DIR/$tdir/$tfile
4008 local fid=$(copy_file /etc/passwd $f1)
4009 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4010 wait_request_state $fid ARCHIVE SUCCEED
4011 # shutdown and restart MDS
4013 # check the copytool still gets messages from MDT
4014 local f2=$DIR/$tdir/2
4015 local fid=$(copy_file /etc/passwd $f2)
4016 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
4017 # main check of this sanity: this request MUST succeed
4018 wait_request_state $fid ARCHIVE SUCCEED
4021 run_test 107 "Copytool re-register after MDS restart"
4023 policy_set_and_test()
4027 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
4028 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4029 [[ "$policy" == "$target" ]] ||
4030 error "Wrong policy after '$change': '$policy' != '$target'"
4034 # to force default policy setting if error
4035 CDT_POLICY_HAD_CHANGED=true
4037 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4038 local default="NonBlockingRestore [NoRetryAction]"
4039 [[ "$policy" == "$default" ]] ||
4040 error "default policy has changed,"\
4041 " '$policy' != '$default' update the test"
4042 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
4043 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
4044 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
4045 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
4046 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4047 # useless bacause we know but safer for futur changes to use real value
4048 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4049 echo "Next set_param must failed"
4050 policy_set_and_test "wrong" "$policy"
4053 echo "Back to default policy"
4054 cdt_set_sanity_policy
4056 run_test 109 "Policy display/change"
4059 # test needs a running copytool
4064 copy2archive /etc/passwd $tdir/$tfile
4066 local f=$DIR/$tdir/$tfile
4067 import_file $tdir/$tfile $f
4068 local fid=$(path2fid $f)
4070 cdt_set_non_blocking_restore
4075 wait_request_state $fid RESTORE SUCCEED
4076 cdt_clear_non_blocking_restore
4080 error "md5sum returns $st != 1, "\
4081 "should also perror ENODATA (No data available)"
4085 run_test 110a "Non blocking restore policy (import case)"
4088 # test needs a running copytool
4092 local f=$DIR/$tdir/$tfile
4093 local fid=$(copy_file /etc/passwd $f)
4094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4095 wait_request_state $fid ARCHIVE SUCCEED
4098 cdt_set_non_blocking_restore
4103 wait_request_state $fid RESTORE SUCCEED
4104 cdt_clear_non_blocking_restore
4108 error "md5sum returns $st != 1, "\
4109 "should also perror ENODATA (No data available)"
4113 run_test 110b "Non blocking restore policy (release case)"
4116 # test needs a running copytool
4120 copy2archive /etc/passwd $tdir/$tfile
4122 local f=$DIR/$tdir/$tfile
4124 import_file $tdir/$tfile $f
4125 local fid=$(path2fid $f)
4129 copytool_remove_backend $fid
4132 wait_request_state $fid RESTORE FAILED
4139 [[ $st == 0 ]] || error "Restore does not failed"
4143 run_test 111a "No retry policy (import case), restore will error"\
4144 " (No such file or directory)"
4147 # test needs a running copytool
4151 local f=$DIR/$tdir/$tfile
4152 local fid=$(copy_file /etc/passwd $f)
4154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4155 wait_request_state $fid ARCHIVE SUCCEED
4158 copytool_remove_backend $fid
4161 wait_request_state $fid RESTORE FAILED
4168 [[ $st == 0 ]] || error "Restore does not failed"
4172 run_test 111b "No retry policy (release case), restore will error"\
4173 " (No such file or directory)"
4176 # test needs a running copytool
4180 local f=$DIR/$tdir/$tfile
4181 local fid=$(copy_file /etc/passwd $f)
4183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4184 local l=$($LFS hsm_action $f)
4186 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4190 wait_request_state $fid ARCHIVE SUCCEED
4193 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4197 run_test 112 "State of recorded request"
4200 # test needs a running copytool
4204 local f=$DIR/$tdir/$tfile
4206 fid=$(make_custom_file_for_progress $f 103 1048576)
4207 [ $? != 0 ] && skip "not enough free space" && return
4209 # test with cdt on is made in test_221
4211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4212 # wait archive to register at CDT
4213 wait_request_state $fid ARCHIVE WAITING
4216 wait_request_state $fid ARCHIVE CANCELED
4217 wait_request_state $fid CANCEL SUCCEED
4221 run_test 200 "Register/Cancel archive"
4224 # test needs a running copytool
4228 local f=$DIR/$tdir/$tfile
4229 make_archive $tdir/$tfile
4230 import_file $tdir/$tfile $f
4231 local fid=$(path2fid $f)
4233 # test with cdt on is made in test_222
4236 # wait restore to register at CDT
4237 wait_request_state $fid RESTORE WAITING
4240 wait_request_state $fid RESTORE CANCELED
4241 wait_request_state $fid CANCEL SUCCEED
4245 run_test 201 "Register/Cancel restore"
4248 # test needs a running copytool
4252 local f=$DIR/$tdir/$tfile
4254 fid=$(make_custom_file_for_progress $f 39 1000000)
4255 [ $? != 0 ] && skip "not enough free space" && return
4257 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4258 wait_request_state $fid ARCHIVE SUCCEED
4262 # wait remove to register at CDT
4263 wait_request_state $fid REMOVE WAITING
4266 wait_request_state $fid REMOVE CANCELED
4270 run_test 202 "Register/Cancel remove"
4273 # test needs a running copytool
4278 local f=$DIR/$tdir/$tfile
4279 local fid=$(copy_file /etc/passwd $f)
4283 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4284 wait_request_state $fid ARCHIVE SUCCEED
4286 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4290 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4294 run_test 220 "Changelog for archive"
4297 # test needs a running copytool
4302 local f=$DIR/$tdir/$tfile
4303 local fid=$(copy_file /etc/passwd $f)
4307 # block copytool operations to allow for HSM request to be
4308 # submitted and file be unlinked (CDT will find object removed)
4311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4313 # wait request to reach CT
4314 wait_request_state $fid ARCHIVE STARTED
4320 wait_request_state $fid ARCHIVE FAILED
4322 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4327 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4331 run_test 220a "Changelog for failed archive"
4334 # test needs a running copytool
4339 local f=$DIR/$tdir/$tfile
4341 fid=$(make_custom_file_for_progress $f 103 1048576)
4342 [ $? != 0 ] && skip "not enough free space" && return
4346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4347 wait_request_state $fid ARCHIVE STARTED
4349 wait_request_state $fid ARCHIVE CANCELED
4350 wait_request_state $fid CANCEL SUCCEED
4352 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4355 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4359 run_test 221 "Changelog for archive canceled"
4362 # test needs a running copytool
4366 copy2archive /etc/passwd $tdir/$tfile
4368 local f=$DIR/$tdir/$tfile
4369 import_file $tdir/$tfile $f
4370 local fid=$(path2fid $f)
4375 wait_request_state $fid RESTORE SUCCEED
4377 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4380 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4384 run_test 222a "Changelog for explicit restore"
4387 # test needs a running copytool
4391 local f=$DIR/$tdir/$tfile
4392 local fid=$(copy_file /etc/passwd $f)
4395 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4396 wait_request_state $fid ARCHIVE SUCCEED
4401 wait_request_state $fid RESTORE SUCCEED
4403 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4406 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4410 run_test 222b "Changelog for implicit restore"
4413 # test needs a running copytool
4417 copy2archive /etc/passwd $tdir/$tfile
4419 local f=$DIR/$tdir/$tfile
4420 import_file $tdir/$tfile $f
4421 local fid=$(path2fid $f)
4425 # block copytool operations to allow for HSM request to be
4426 # submitted and file be unlinked (CDT will find object removed)
4431 # wait request to reach CT
4432 wait_request_state $fid RESTORE STARTED
4438 wait_request_state $fid RESTORE FAILED
4440 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4444 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4448 run_test 222c "Changelog for failed explicit restore"
4451 # test needs a running copytool
4455 local f=$DIR/$tdir/$tfile
4456 local fid=$(copy_file /etc/passwd $f)
4459 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4460 wait_request_state $fid ARCHIVE SUCCEED
4463 copytool_remove_backend $fid
4466 wait_request_state $fid RESTORE FAILED
4468 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4472 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4476 run_test 222d "Changelog for failed implicit restore"
4479 # test needs a running copytool
4484 local f=$DIR/$tdir/$tfile
4485 make_archive $tdir/$tfile
4489 import_file $tdir/$tfile $f
4490 local fid=$(path2fid $f)
4493 wait_request_state $fid RESTORE STARTED
4495 wait_request_state $fid RESTORE CANCELED
4496 wait_request_state $fid CANCEL SUCCEED
4498 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4501 [[ $flags == $target ]] ||
4502 error "Changelog flag is $flags not $target"
4506 run_test 223a "Changelog for restore canceled (import case)"
4509 # test needs a running copytool
4514 local f=$DIR/$tdir/$tfile
4516 fid=$(make_custom_file_for_progress $f 39 1000000)
4517 [ $? != 0 ] && skip "not enough free space" && return
4520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4521 wait_request_state $fid ARCHIVE SUCCEED
4524 wait_request_state $fid RESTORE STARTED
4526 wait_request_state $fid RESTORE CANCELED
4527 wait_request_state $fid CANCEL SUCCEED
4529 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4532 [[ $flags == $target ]] ||
4533 error "Changelog flag is $flags not $target"
4537 run_test 223b "Changelog for restore canceled (release case)"
4540 # test needs a running copytool
4545 local f=$DIR/$tdir/$tfile
4546 local fid=$(copy_file /etc/passwd $f)
4549 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4550 wait_request_state $fid ARCHIVE SUCCEED
4553 wait_request_state $fid REMOVE SUCCEED
4555 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4558 [[ $flags == $target ]] ||
4559 error "Changelog flag is $flags not $target"
4563 run_test 224 "Changelog for remove"
4566 # test needs a running copytool
4571 local f=$DIR/$tdir/$tfile
4572 local fid=$(copy_file /etc/passwd $f)
4575 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4576 wait_request_state $fid ARCHIVE SUCCEED
4578 copytool_remove_backend $fid
4580 # block copytool operations to allow for HSM request to be
4581 # submitted and file be unlinked (CDT will find object removed)
4586 # wait for request to reach CT
4587 wait_request_state $fid REMOVE STARTED
4593 wait_request_state $fid REMOVE FAILED
4595 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4599 [[ $flags == $target ]] ||
4600 error "Changelog flag is $flags not $target"
4604 run_test 224a "Changelog for failed remove"
4607 # test needs a running copytool
4610 # test is not usable because remove request is too fast
4611 # so it is always finished before cancel can be done ...
4612 echo "Test disabled"
4617 local f=$DIR/$tdir/$tfile
4619 fid=$(make_custom_file_for_progress $f 39 1000000)
4620 [ $? != 0 ] && skip "not enough free space" && return
4623 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4624 wait_request_state $fid ARCHIVE SUCCEED
4626 # if cdt is on, it can serve too quickly the request
4631 wait_request_state $fid REMOVE CANCELED
4632 wait_request_state $fid CANCEL SUCCEED
4634 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4635 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4636 tail -n 1 | awk '{print $5}')
4639 [[ $flags == $target ]] ||
4640 error "Changelog flag is $flags not $target"
4644 run_test 225 "Changelog for remove canceled"
4647 # test needs a running copytool
4652 local f1=$DIR/$tdir/$tfile-1
4653 local f2=$DIR/$tdir/$tfile-2
4654 local f3=$DIR/$tdir/$tfile-3
4655 local fid1=$(copy_file /etc/passwd $f1)
4656 local fid2=$(copy_file /etc/passwd $f2)
4657 copy_file /etc/passwd $f3
4660 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4661 wait_request_state $fid1 ARCHIVE SUCCEED
4663 $LFS hsm_archive $f2
4664 wait_request_state $fid2 ARCHIVE SUCCEED
4666 rm $f1 || error "rm $f1 failed"
4668 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4671 [[ $flags == $target ]] ||
4672 error "Changelog flag is $flags not $target"
4674 mv $f3 $f2 || error "mv $f3 $f2 failed"
4676 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4679 [[ $flags == $target ]] ||
4680 error "Changelog flag is $flags not $target"
4684 run_test 226 "changelog for last rm/mv with exiting archive"
4686 check_flags_changes() {
4694 $LFS hsm_set --$hsm_flag $f ||
4695 error "Cannot set $hsm_flag on $f"
4696 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4697 local seen=${#flags[*]}
4699 [[ $seen == $cnt ]] ||
4700 error "set $hsm_flag: Changelog events $seen != $cnt"
4701 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4702 error "set $hsm_flag: Changelog flags are "\
4703 "${flags[$((cnt - 1))]} not $target"
4705 $LFS hsm_clear --$hsm_flag $f ||
4706 error "Cannot clear $hsm_flag on $f"
4707 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4710 [[ $cnt == $seen ]] ||
4711 error "clear $hsm_flag: Changelog events $seen != $cnt"
4713 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4714 error "clear $hsm_flag: Changelog flag is "\
4715 "${flags[$((cnt - 1))]} not $target"
4719 # test needs a running copytool
4726 for i in norelease noarchive exists archived
4728 local f=$DIR/$tdir/$tfile-$i
4729 local fid=$(copy_file /etc/passwd $f)
4730 check_flags_changes $f $fid $i 0 1
4733 f=$DIR/$tdir/$tfile---lost
4734 fid=$(copy_file /etc/passwd $f)
4735 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4736 wait_request_state $fid ARCHIVE SUCCEED
4737 check_flags_changes $f $fid lost 3 1
4741 run_test 227 "changelog when explicit setting of HSM flags"
4744 # test needs a running copytool
4747 local fid=$(make_small_sync $DIR/$tfile)
4748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4749 wait_request_state $fid ARCHIVE SUCCEED
4751 $LFS hsm_release $DIR/$tfile
4752 check_hsm_flags $DIR/$tfile "0x0000000d"
4754 filefrag $DIR/$tfile | grep " 1 extent found" ||
4755 error "filefrag on released file must return only one extent"
4757 # only newer versions of cp detect sparse files by stat/FIEMAP
4759 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4760 error "copying $DIR/$tfile"
4761 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4763 $LFS hsm_release $DIR/$tfile
4764 check_hsm_flags $DIR/$tfile "0x0000000d"
4766 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4768 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4770 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4771 error "comparing untarred $DIR/$tfile"
4773 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4774 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4777 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4780 # test needs a running copytool
4784 local maxrequest=$(get_hsm_param max_requests)
4785 local rqcnt=$(($maxrequest * 3))
4789 for i in $(seq -w 1 $rqcnt); do
4791 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4793 # we do it in 2 steps, so all requests arrive at the same time
4794 for i in $(seq -w 1 $rqcnt); do
4795 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4800 while [[ $cnt != 0 || $wt != 0 ]]; do
4802 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4803 $HSM_PARAM.actions |\
4804 grep STARTED | grep -v CANCEL | wc -l")
4805 [[ $cnt -le $maxrequest ]] ||
4806 error "$cnt > $maxrequest too many started requests"
4807 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4808 $HSM_PARAM.actions |\
4809 grep WAITING | wc -l")
4810 echo "max=$maxrequest started=$cnt waiting=$wt"
4815 run_test 250 "Coordinator max request"
4818 # test needs a running copytool
4822 local f=$DIR/$tdir/$tfile
4824 fid=$(make_custom_file_for_progress $f 103 1048576)
4825 [ $? != 0 ] && skip "not enough free space" && return
4828 # to have a short test
4829 local old_to=$(get_hsm_param active_request_timeout)
4830 set_hsm_param active_request_timeout 4
4831 # to be sure the cdt will wake up frequently so
4832 # it will be able to cancel the "old" request
4833 local old_loop=$(get_hsm_param loop_period)
4834 set_hsm_param loop_period 2
4837 # clear locks to avoid extra delay caused by flush/cancel
4838 # and thus prevent early copytool death to timeout.
4839 cancel_lru_locks osc
4841 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4842 wait_request_state $fid ARCHIVE STARTED
4844 wait_request_state $fid ARCHIVE CANCELED
4846 set_hsm_param active_request_timeout $old_to
4847 set_hsm_param loop_period $old_loop
4851 run_test 251 "Coordinator request timeout"
4854 # test needs a running copytool
4858 local f=$DIR/$tdir/$tfile
4859 local fid=$(make_custom_file_for_progress $f 103 1048576)
4862 # to have a short test
4863 local old_to=$(get_hsm_param active_request_timeout)
4864 set_hsm_param active_request_timeout 20
4865 # to be sure the cdt will wake up frequently so
4866 # it will be able to cancel the "old" request
4867 local old_loop=$(get_hsm_param loop_period)
4868 set_hsm_param loop_period 2
4871 # clear locks to avoid extra delay caused by flush/cancel
4872 # and thus prevent early copytool death to timeout.
4873 cancel_lru_locks osc
4875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4876 wait_request_state $fid ARCHIVE STARTED
4879 # wait but less than active_request_timeout+grace_delay
4881 wait_request_state $fid ARCHIVE CANCELED
4883 set_hsm_param active_request_timeout $old_to
4884 set_hsm_param loop_period $old_loop
4888 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4891 # the only way to test ondisk conf is to restart MDS ...
4892 echo "Stop coordinator and remove coordinator state at mount"
4895 # clean on disk conf set by default
4896 cdt_clear_mount_state
4897 cdt_check_state stopped
4899 # check cdt still off after umount/remount
4901 cdt_check_state stopped
4903 echo "Set coordinator start at mount, and start coordinator"
4904 cdt_set_mount_state enabled
4907 cdt_check_state enabled
4909 # check cdt still on after umount/remount
4911 cdt_check_state enabled
4913 # we are back to original state (cdt started at mount)
4915 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4918 local ai=$(get_hsm_param default_archive_id)
4919 local new=$((ai + 1))
4921 set_hsm_param default_archive_id $new -P
4923 local res=$(get_hsm_param default_archive_id)
4926 set_hsm_param default_archive_id "" "-P -d"
4928 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4930 run_test 301 "HSM tunnable are persistent"
4933 local ai=$(get_hsm_param default_archive_id)
4934 local new=$((ai + 1))
4939 set_hsm_param default_archive_id $new -P
4942 for mdtno in $(seq 1 $MDSCOUNT); do
4947 cdt_check_state enabled
4949 local res=$(get_hsm_param default_archive_id)
4952 set_hsm_param default_archive_id "" "-P -d"
4954 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4956 run_test 302 "HSM tunnable are persistent when CDT is off"
4959 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4965 local dir_mdt0=$DIR/$tdir/mdt0
4966 local dir_mdt1=$DIR/$tdir/mdt1
4968 # create 1 dir per MDT
4969 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4970 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4972 # create 1 file in each MDT
4973 local fid1=$(make_small $dir_mdt0/$tfile)
4974 local fid2=$(make_small $dir_mdt1/$tfile)
4976 # check that hsm request on mdt0 is sent to the right MDS
4977 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4978 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4979 echo "archive successful on mdt0"
4981 # check that hsm request on mdt1 is sent to the right MDS
4982 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4983 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4984 echo "archive successful on mdt1"
4987 # clean test files and directories
4988 rm -rf $dir_mdt0 $dir_mdt1
4990 run_test 400 "Single request is sent to the right MDT"
4993 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4999 local dir_mdt0=$DIR/$tdir/mdt0
5000 local dir_mdt1=$DIR/$tdir/mdt1
5002 # create 1 dir per MDT
5003 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5004 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5006 # create 1 file in each MDT
5007 local fid1=$(make_small $dir_mdt0/$tfile)
5008 local fid2=$(make_small $dir_mdt1/$tfile)
5010 # check that compound requests are shunt to the rights MDTs
5011 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5012 error "lfs hsm_archive"
5013 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5014 echo "archive successful on mdt0"
5015 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5016 echo "archive successful on mdt1"
5019 # clean test files and directories
5020 rm -rf $dir_mdt0 $dir_mdt1
5022 run_test 401 "Compound requests split and sent to their respective MDTs"
5024 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5029 local node=$(facet_active_host $facet)
5031 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5032 awk '{print $4}'); do
5033 echo "$3 $mdc on $node"
5034 do_facet $facet "$LCTL --device $mdc $state" || return 1
5039 # make sure there is no running copytool
5042 # deactivate all mdc on agent1
5043 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5045 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
5047 check_agent_unregistered "uuid" # match any agent
5049 # no expected running copytool
5050 search_copytools $agent && error "Copytool start should have failed"
5053 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5055 run_test 402a "Copytool start fails if all MDTs are inactive"
5062 local f=$DIR/$tdir/$tfile
5063 touch $f || error "touch $f failed"
5064 local fid=$(path2fid $f)
5066 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5067 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5068 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5070 # give time for CDT to send request and to keep it for retry
5071 wait_for_loop_period
5073 wait_request_state $fid ARCHIVE WAITING
5075 do_facet $SINGLEAGT lctl set_param fail_loc=0
5077 # request should succeed now
5078 wait_request_state $fid ARCHIVE SUCCEED
5082 run_test 402b "CDT must retry request upon slow start of CT"
5085 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5087 # make sure there is no running copytool
5090 local agent=$(facet_active_host $SINGLEAGT)
5092 # deactivate all mdc for MDT0001
5093 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5096 local uuid=$(get_agent_uuid $agent)
5097 # check the agent is registered on MDT0000, and not on MDT0001
5098 check_agent_registered_by_mdt $uuid 0
5099 check_agent_unregistered_by_mdt $uuid 1
5101 # check running copytool process
5102 search_copytools $agent || error "No running copytools on $agent"
5104 # reactivate all mdc for MDT0001
5105 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5107 # make sure the copytool is now registered to all MDTs
5108 check_agent_registered $uuid
5112 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5115 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5119 # create files on both MDT0000 and MDT0001
5122 local dir_mdt0=$DIR/$tdir/mdt0
5123 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5125 # create 1 file on mdt0
5126 local fid1=$(make_small $dir_mdt0/$tfile)
5128 # deactivate all mdc for MDT0001
5129 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5131 # send an HSM request for files in MDT0000
5132 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5134 # check for completion of files in MDT0000
5135 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5136 echo "archive successful on mdt0"
5138 # reactivate all mdc for MDT0001
5139 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5142 # clean test files and directories
5145 run_test 404 "Inactive MDT does not block requests for active MDTs"
5148 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5154 local striped_dir=$DIR/$tdir/striped_dir
5156 # create striped dir on all of MDTs
5157 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5159 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
5160 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
5161 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
5162 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
5164 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5165 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5166 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5167 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5169 # check that compound requests are shunt to the rights MDTs
5170 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5171 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5172 error "lfs hsm_archive"
5174 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5175 echo "archive successful on $fid1"
5176 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5177 echo "archive successful on $fid2"
5178 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5179 echo "archive successful on $fid3"
5180 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5181 echo "archive successful on $fid4"
5183 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5184 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5185 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5186 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5188 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5189 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5190 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5191 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5195 run_test 405 "archive and release under striped directory"
5198 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5200 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5201 skip "need MDS version at least 2.7.64" && return 0
5208 fid=$(make_small $DIR/$tdir/$tfile)
5211 $LFS hsm_archive $DIR/$tdir/$tfile
5212 wait_request_state "$fid" ARCHIVE SUCCEED
5213 $LFS hsm_release $DIR/$tdir/$tfile
5215 # Should migrate $tdir but not $tfile.
5216 $LFS mv -M1 $DIR/$tdir &&
5217 error "migrating HSM an archived file should fail"
5219 $LFS hsm_restore $DIR/$tdir/$tfile
5220 wait_request_state "$fid" RESTORE SUCCEED
5222 $LFS hsm_remove $DIR/$tdir/$tfile
5223 wait_request_state "$fid" REMOVE SUCCEED
5225 cat $DIR/$tdir/$tfile > /dev/null ||
5226 error "cannot read $DIR/$tdir/$tfile"
5228 $LFS mv -M1 $DIR/$tdir ||
5229 error "cannot complete migration after HSM remove"
5231 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5232 if ((mdt_index != 1)); then
5233 error "expected MDT index 1, got $mdt_index"
5236 # Refresh fid after migration.
5237 fid=$(path2fid $DIR/$tdir/$tfile)
5240 $LFS hsm_archive $DIR/$tdir/$tfile
5241 wait_request_state "$fid" ARCHIVE SUCCEED 1
5243 lctl set_param debug=+trace
5244 $LFS hsm_release $DIR/$tdir/$tfile ||
5245 error "cannot release $DIR/$tdir/$tfile"
5247 $LFS hsm_restore $DIR/$tdir/$tfile
5248 wait_request_state "$fid" RESTORE SUCCEED 1
5250 cat $DIR/$tdir/$tfile > /dev/null ||
5251 error "cannot read $DIR/$tdir/$tfile"
5255 run_test 406 "attempting to migrate HSM archived files is safe"
5258 needclients 2 || return 0
5259 # test needs a running copytool
5264 local f=$DIR/$tdir/$tfile
5265 local f2=$DIR2/$tdir/$tfile
5267 fid=$(make_custom_file_for_progress $f 39 1000000)
5268 [ $? != 0 ] && skip "not enough free space" && return
5270 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5271 wait_request_state $fid ARCHIVE SUCCEED
5274 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5275 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5278 # 1st request holds layout lock while appropriate
5279 # RESTORE record is still not added to llog
5283 # after umount hsm_actions->O/x/x log shouldn't have
5284 # double RESTORE records like below
5285 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5286 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5288 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5291 wait_request_state $fid RESTORE SUCCEED
5294 run_test 407 "Check for double RESTORE records in llog"
5298 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5299 skip "HSM migrate is not supported" && return
5301 # Stop the existing copytool
5304 test_mkdir -p $DIR/$tdir
5305 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5307 run_test 500 "various LLAPI HSM tests"
5312 check_and_cleanup_lustre