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: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
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))
174 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"
184 # try to dump Copytool's stack
185 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
186 "echo t >/proc/sysrq-trigger"
188 echo "copytools failed to stop in ${wait_timeout}s"
193 copytool_monitor_setup() {
194 local facet=${1:-$SINGLEAGT}
195 local agent=$(facet_active_host $facet)
197 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
198 local test_dir=$(do_node $agent "$cmd") ||
199 error "Failed to create tempdir on $agent"
200 export HSMTOOL_MONITOR_DIR=$test_dir
202 # Create the fifo and a monitor (cat dies when copytool dies)
203 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
204 error "failed to create copytool fifo on $agent"
205 cmd="cat $test_dir/fifo > $test_dir/events &"
206 cmd+=" echo \\\$! > $test_dir/monitor_pid"
208 if [[ $PDSH == *Rmrsh* ]]; then
209 # This is required for pdsh -Rmrsh and its handling of remote
211 # Regular ssh and pdsh -Rssh work fine without this
212 # backgrounded subshell nonsense.
213 (do_node $agent "$cmd") &
214 export HSMTOOL_MONITOR_PDSH=$!
216 # Slightly racy, but just making a best-effort to catch obvious
219 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
220 error "Failed to start copytool monitor on $agent"
222 do_node $agent "$cmd"
224 error "Failed to start copytool monitor on $agent"
229 copytool_monitor_cleanup() {
230 local facet=${1:-$SINGLEAGT}
231 local agent=$(facet_active_host $facet)
233 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
234 # Should die when the copytool dies, but just in case.
235 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
236 cmd+=" 2>/dev/null || true"
237 do_node $agent "$cmd"
238 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
239 export HSMTOOL_MONITOR_DIR=
242 # The pdsh should die on its own when the monitor dies. Just
243 # in case, though, try to clean up to avoid any cruft.
244 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
245 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
246 export HSMTOOL_MONITOR_PDSH=
251 local facet=${1:-$SINGLEAGT}
252 # Use MOUNT2 by default if defined
253 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
255 local hsm_root=${4:-$(copytool_device $facet)}
257 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
259 local agent=$(facet_active_host $facet)
261 if [[ -z "$arc_id" ]] &&
262 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
263 echo "Only wakeup running copytool $facet on $agent"
267 if $HSM_ARCHIVE_PURGE; then
268 echo "Purging archive on $agent"
269 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
272 echo "Starting copytool $facet on $agent"
273 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
274 error "mkdir '$hsm_root/$HSMTMP' failed"
275 # bandwidth is limited to 1MB/s so the copy time is known and
276 # independent of hardware
277 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
278 cmd+=" --hsm-root $hsm_root/$HSMTMP"
279 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
280 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
281 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
282 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
283 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
284 cmd+=" --bandwidth 1 $lustre_mntpnt"
286 # Redirect the standard output and error to a log file which
287 # can be uploaded to Maloo.
288 local prefix=$TESTLOG_PREFIX
289 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
290 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
292 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
293 if [[ $? != 0 ]]; then
294 [[ $HSMTOOL_NOERROR == true ]] ||
295 error "start copytool $facet on $agent failed"
296 echo "start copytool $facet on $agent failed"
302 get_copytool_event_log() {
303 local facet=${1:-$SINGLEAGT}
304 local agent=$(facet_active_host $facet)
306 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
307 error "Can't get event log: No monitor directory!"
309 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
310 error "Could not collect event log from $agent"
315 local agt_facet=$SINGLEAGT
316 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
317 local hsm_root=$(copytool_device $agt_facet)
319 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
326 kill_copytools $agt_hosts
327 wait_copytools $agt_hosts || error "copytools failed to stop"
329 # Clean all CDTs orphans requests from previous tests that
330 # would otherwise need to timeout to clear.
331 for ((i = 0; i < MDSCOUNT; i++)); do
333 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
334 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
336 # Skip already stopping or stopped CDTs.
337 [[ "${state[$i]}" =~ ^stop ]] && continue
339 do_facet $facet "$LCTL set_param $param=shutdown"
342 for ((i = 0; i < MDSCOUNT; i++)); do
343 # Only check and restore CDTs that we stopped in the first loop.
344 [[ "${state[$i]}" =~ ^stop ]] && continue
347 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
349 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
350 error "$facet CDT state is not stopped"
352 # Restore old CDT state.
353 do_facet $facet "$LCTL set_param $param=${state[$i]}"
356 for ((i = 0; i < MDSCOUNT; i++)); do
357 # Only check CDTs that we stopped in the first loop.
358 [[ "${state[$i]}" =~ ^stop ]] && continue
361 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
363 # Check that the old CDT state was restored.
364 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
365 20 || error "$facet CDT state is not '${state[$i]}'"
368 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
369 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
374 local agents=${1:-$(facet_active_host $SINGLEAGT)}
376 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
377 echo "Copytool is suspended on $agents"
380 copytool_remove_backend() {
382 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
383 echo "Remove from backend: $fid = $be"
384 do_facet $SINGLEAGT rm -f $be
388 do_facet $SINGLEAGT \
389 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
390 --import $1 $2 $MOUNT" ||
391 error "import of $1 to $2 failed"
395 local file=$HSM_ARCHIVE/$1
396 do_facet $SINGLEAGT mkdir -p $(dirname $file)
397 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
398 file_creation_failure dd $file $?
402 local file=$HSM_ARCHIVE/$2
403 do_facet $SINGLEAGT mkdir -p $(dirname $file)
404 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
413 if [[ "$value" != "" ]]; then
416 for mdtno in $(seq 1 $MDSCOUNT); do
417 local idx=$(($mdtno - 1))
418 local facet=mds${mdtno}
419 # if $arg include -P option, run 1 set_param per MDT on the MGS
420 # else, run set_param on each MDT
421 [[ $arg = *"-P"* ]] && facet=mgs
422 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
423 [[ $? != 0 ]] && rc=1
433 for mdtno in $(seq 1 $MDSCOUNT); do
434 local idx=$(($mdtno - 1))
435 wait_result mds${mdtno} \
436 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
438 error "$key state is not '$target' on mds${mdtno}"
445 for mdtno in $(seq 1 $MDSCOUNT); do
446 local idx=$(($mdtno - 1))
447 local cl_user=$(do_facet mds${mdtno} $LCTL \
448 --device ${MDT[$idx]} \
449 changelog_register -n)
451 do_facet mds${mdtno} lctl set_param \
452 mdd.${MDT[$idx]}.changelog_mask="+hsm"
453 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
457 changelog_cleanup() {
459 for mdtno in $(seq 1 $MDSCOUNT); do
460 local idx=$(($mdtno - 1))
461 [[ -z ${CL_USERS[$idx]} ]] && continue
462 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
463 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
464 changelog_deregister ${CL_USERS[$idx]}
469 changelog_get_flags() {
474 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
479 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
487 mdts_set_param "$opt -n" "hsm.$param" "$value"
494 mdts_set_param "" hsm_control "$cmd"
495 mdts_check_param hsm_control "$target" 10
498 cdt_set_sanity_policy() {
499 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
502 mdts_set_param "" hsm.policy "+NRA"
503 mdts_set_param "" hsm.policy "-NBR"
504 CDT_POLICY_HAD_CHANGED=
509 mdts_set_param "" hsm.policy "+NRA"
510 CDT_POLICY_HAD_CHANGED=true
513 cdt_clear_no_retry() {
514 mdts_set_param "" hsm.policy "-NRA"
515 CDT_POLICY_HAD_CHANGED=true
518 cdt_set_non_blocking_restore() {
519 mdts_set_param "" hsm.policy "+NBR"
520 CDT_POLICY_HAD_CHANGED=true
523 cdt_clear_non_blocking_restore() {
524 mdts_set_param "" hsm.policy "-NBR"
525 CDT_POLICY_HAD_CHANGED=true
528 cdt_clear_mount_state() {
529 mdts_set_param "-P -d" hsm_control ""
532 cdt_set_mount_state() {
533 mdts_set_param "-P" hsm_control "$1"
534 # set_param -P is asynchronous operation and could race with set_param.
535 # In such case configs could be retrieved and applied at mgc after
536 # set_param -P completion. Sleep here to avoid race with set_param.
537 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
538 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
539 # and 10 seconds to retrieve config from server.
544 mdts_check_param hsm_control "$1" 20
548 set_test_state disabled disabled
552 set_test_state enabled enabled
556 set_test_state shutdown stopped
560 set_test_state purge enabled
566 cdt_set_sanity_policy
570 local client_count=$1
571 if [[ $CLIENTCOUNT -lt $client_count ]]; then
572 skip "Need $client_count or more clients, have $CLIENTCOUNT"
579 $LFS path2fid $1 | tr -d '[]'
580 return ${PIPESTATUS[0]}
588 if [[ $u == "user" ]]; then
589 st=$($RUNAS $LFS hsm_state $f)
592 st=$($LFS hsm_state $f)
595 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
597 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
601 get_hsm_archive_id() {
604 st=$($LFS hsm_state $f)
605 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
607 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
616 local st=$(get_hsm_flags $f)
617 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
620 check_hsm_flags_user() {
624 local st=$(get_hsm_flags $f user)
625 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
628 file_creation_failure() {
633 df $MOUNT $MOUNT2 >&2
634 error "cannot create $f with $cmd, status=$err"
646 if [[ "$3" != 1 ]]; then
650 cp $1 $f || file_creation_failure cp $f $?
652 path2fid $f || error "cannot get fid on $f"
656 local file2=${1/$DIR/$DIR2}
657 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
658 file_creation_failure dd $file2 $?
660 path2fid $1 || error "cannot get fid on $1"
664 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
665 file_creation_failure dd $1 $?
666 path2fid $1 || error "cannot get fid on $1"
669 cleanup_large_files() {
670 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
672 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
675 check_enough_free_space() {
678 local need=$((nb * unit /1024))
679 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
680 (( $need >= $free )) && return 1
684 make_large_for_striping() {
685 local file2=${1/$DIR/$DIR2}
686 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
690 check_enough_free_space 5 $sz
691 [ $? != 0 ] && return $?
693 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
694 file_creation_failure dd $file2 $?
696 path2fid $1 || error "cannot get fid on $1"
699 make_large_for_progress() {
700 local file2=${1/$DIR/$DIR2}
704 check_enough_free_space 39 1000000
705 [ $? != 0 ] && return $?
707 # big file is large enough, so copy time is > 30s
708 # so copytool make 1 progress
709 # size is not a multiple of 1M to avoid stripe
711 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
712 file_creation_failure dd $file2 $?
714 path2fid $1 || error "cannot get fid on $1"
717 make_large_for_progress_aligned() {
718 local file2=${1/$DIR/$DIR2}
722 check_enough_free_space 33 1048576
723 [ $? != 0 ] && return $?
725 # big file is large enough, so copy time is > 30s
726 # so copytool make 1 progress
727 # size is a multiple of 1M to have stripe
729 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
730 file_creation_failure dd $file2 $?
731 path2fid $1 || error "cannot get fid on $1"
734 make_large_for_cancel() {
735 local file2=${1/$DIR/$DIR2}
739 check_enough_free_space 103 1048576
740 [ $? != 0 ] && return $?
742 # Copy timeout is 100s. 105MB => 105s
743 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
744 file_creation_failure dd $file2 $?
745 path2fid $1 || error "cannot get fid on $1"
751 wait_update --verbose $(facet_active_host $facet) "$@"
754 wait_request_state() {
758 # 4th arg (mdt index) is optional
760 local mds=mds$(($mdtidx + 1))
762 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
763 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
765 wait_result $mds "$cmd" $state 200 ||
766 error "request on $fid is not $state on $mds"
769 get_request_state() {
773 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
774 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
777 get_request_count() {
781 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
782 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
789 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
790 [[ -n $fid ]] && cmd+=" | grep '$fid'"
791 cmd+=" | egrep 'WAITING|STARTED'"
793 wait_result $SINGLEMDS "$cmd" "" $timeout ||
794 error "requests did not complete"
797 wait_for_grace_delay() {
798 local val=$(get_hsm_param grace_delay)
805 # python2.6 in EL6 includes an internal json module
806 local json_parser='import json; import fileinput;'
807 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
808 json_parser+='json.loads([line for line in '
809 json_parser+='fileinput.input()][0]).items()])'
811 echo $raw_event | python -c "$json_parser"
814 get_agent_by_uuid_mdt() {
817 local mds=mds$(($mdtidx + 1))
818 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
822 check_agent_registered_by_mdt() {
825 local mds=mds$(($mdtidx + 1))
826 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
827 if [[ ! -z "$agent" ]]; then
828 echo "found agent $agent on $mds"
830 error "uuid $uuid not found in agent list on $mds"
834 check_agent_unregistered_by_mdt() {
837 local mds=mds$(($mdtidx + 1))
838 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
839 if [[ -z "$agent" ]]; then
840 echo "uuid not found in agent list on $mds"
842 error "uuid found in agent list on $mds: $agent"
846 check_agent_registered() {
849 for mdsno in $(seq 1 $MDSCOUNT); do
850 check_agent_registered_by_mdt $uuid $((mdsno - 1))
854 check_agent_unregistered() {
857 for mdsno in $(seq 1 $MDSCOUNT); do
858 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
863 local agent=${1:-$(facet_active_host $SINGLEAGT)}
865 # Lustre mount-point is mandatory and last parameter on
867 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
869 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
871 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
877 # populate MDT device array
880 # cleanup from previous bad setup
883 # for recovery tests, coordinator needs to be started at mount
885 # the lustre conf must be without hsm on (like for sanity.sh)
886 echo "Set HSM on and start"
887 cdt_set_mount_state enabled
888 cdt_check_state enabled
890 echo "Start copytool"
893 echo "Set sanity-hsm HSM policy"
894 cdt_set_sanity_policy
896 # finished requests are quickly removed from list
897 set_hsm_param grace_delay 10
903 local f=$DIR/$tdir/$tfile
907 check_hsm_flags_user $f "0x00000000"
909 $RUNAS $LFS hsm_set --norelease $f ||
910 error "user could not change hsm flags"
911 check_hsm_flags_user $f "0x00000010"
913 $RUNAS $LFS hsm_clear --norelease $f ||
914 error "user could not clear hsm flags"
915 check_hsm_flags_user $f "0x00000000"
917 # User could not change those flags...
918 $RUNAS $LFS hsm_set --exists $f &&
919 error "user should not set this flag"
920 check_hsm_flags_user $f "0x00000000"
923 $LFS hsm_set --exists $f ||
924 error "root could not change hsm flags"
925 check_hsm_flags_user $f "0x00000001"
927 $LFS hsm_clear --exists $f ||
928 error "root could not clear hsm state"
929 check_hsm_flags_user $f "0x00000000"
932 run_test 1 "lfs hsm flags root/non-root access"
936 local f=$DIR/$tdir/$tfile
937 local fid=$(make_small $f)
939 $LFS hsm_archive $f || error "could not archive file"
940 wait_request_state $fid ARCHIVE SUCCEED
942 # Release and check states
943 $LFS hsm_release $f || error "could not release file"
944 echo -n "Verifying released state: "
945 check_hsm_flags $f "0x0000000d"
947 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
949 run_test 1a "mmap & cat a HSM released file"
953 local f=$DIR/$tdir/$tfile
955 # New files are not dirty
956 check_hsm_flags $f "0x00000000"
958 # For test, we simulate an archived file.
959 $LFS hsm_set --exists $f || error "user could not change hsm flags"
960 check_hsm_flags $f "0x00000001"
962 # chmod do not put the file dirty
963 chmod 600 $f || error "could not chmod test file"
964 check_hsm_flags $f "0x00000001"
966 # chown do not put the file dirty
967 chown $RUNAS_ID $f || error "could not chown test file"
968 check_hsm_flags $f "0x00000001"
970 # truncate put the file dirty
971 $TRUNCATE $f 1 || error "could not truncate test file"
972 check_hsm_flags $f "0x00000003"
974 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
975 check_hsm_flags $f "0x00000001"
977 run_test 2 "Check file dirtyness when doing setattr"
983 # New files are not dirty
985 check_hsm_flags $f "0x00000000"
987 # For test, we simulate an archived file.
988 $LFS hsm_set --exists $f ||
989 error "user could not change hsm flags"
990 check_hsm_flags $f "0x00000001"
992 # Reading a file, does not set dirty
993 cat $f > /dev/null || error "could not read file"
994 check_hsm_flags $f "0x00000001"
996 # Open for write without modifying data, does not set dirty
997 openfile -f O_WRONLY $f || error "could not open test file"
998 check_hsm_flags $f "0x00000001"
1000 # Append to a file sets it dirty
1001 cp -p /etc/passwd $f.append || error "could not create file"
1002 $LFS hsm_set --exists $f.append ||
1003 error "user could not change hsm flags"
1004 dd if=/etc/passwd of=$f.append bs=1 count=3\
1005 conv=notrunc oflag=append status=noxfer ||
1006 file_creation_failure dd $f.append $?
1007 check_hsm_flags $f.append "0x00000003"
1009 # Modify a file sets it dirty
1010 cp -p /etc/passwd $f.modify || error "could not create file"
1011 $LFS hsm_set --exists $f.modify ||
1012 error "user could not change hsm flags"
1013 dd if=/dev/zero of=$f.modify bs=1 count=3\
1014 conv=notrunc status=noxfer ||
1015 file_creation_failure dd $f.modify $?
1016 check_hsm_flags $f.modify "0x00000003"
1018 # Open O_TRUNC sets dirty
1019 cp -p /etc/passwd $f.trunc || error "could not create file"
1020 $LFS hsm_set --exists $f.trunc ||
1021 error "user could not change hsm flags"
1022 cp /etc/group $f.trunc || error "could not override a file"
1023 check_hsm_flags $f.trunc "0x00000003"
1025 # Mmapped a file sets dirty
1026 cp -p /etc/passwd $f.mmap || error "could not create file"
1027 $LFS hsm_set --exists $f.mmap ||
1028 error "user could not change hsm flags"
1029 multiop $f.mmap OSMWUc || error "could not mmap a file"
1030 check_hsm_flags $f.mmap "0x00000003"
1032 run_test 3 "Check file dirtyness when opening for write"
1036 local f=$DIR/$tdir/$tfile
1037 local fid=$(make_small $f)
1040 local st=$(get_request_state $fid CANCEL)
1041 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1043 run_test 4 "Useless cancel must not be registered"
1046 # test needs a running copytool
1050 local f=$DIR/$tdir/$tfile
1051 local fid=$(copy_file /etc/passwd $f)
1053 wait_request_state $fid ARCHIVE SUCCEED
1055 check_hsm_flags $f "0x00000009"
1059 run_test 8 "Test default archive number"
1062 # we do not use the default one to be sure
1063 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1065 copytool_setup $SINGLEAGT $MOUNT $new_an
1067 # give time for CT to register with MDTs
1068 sleep $(($MDSCOUNT*2))
1069 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1070 check_agent_registered $uuid
1073 local f=$DIR/$tdir/$tfile
1074 local fid=$(copy_file /etc/passwd $f)
1075 $LFS hsm_archive --archive $new_an $f
1076 wait_request_state $fid ARCHIVE SUCCEED
1078 check_hsm_flags $f "0x00000009"
1082 run_test 9 "Use of explicit archive number, with dedicated copytool"
1085 needclients 3 || return 0
1091 copytool_cleanup $(comma_list $(agts_nodes))
1093 # start all of the copytools
1094 for n in $(seq $AGTCOUNT); do
1095 copytool_setup agt$n
1098 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1101 for n in $(seq $AGTCOUNT); do
1102 file=$DIR/$tdir/$tfile.$n
1103 fid=$(make_small $file)
1105 $LFS hsm_archive $file || error "could not archive file $file"
1106 wait_request_state $fid ARCHIVE SUCCEED
1107 check_hsm_flags $file "0x00000009"
1111 copytool_cleanup $(comma_list $(agts_nodes))
1113 run_test 9a "Multiple remote agents"
1116 # test needs a running copytool
1119 mkdir -p $DIR/$tdir/d1
1120 local f=$DIR/$tdir/$tfile
1121 local fid=$(copy_file /etc/hosts $f)
1122 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1123 error "hsm_archive failed"
1124 wait_request_state $fid ARCHIVE SUCCEED
1126 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1127 error "fid $fid not in archive $HSM_ARCHIVE"
1128 echo "Verifying content"
1129 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1130 echo "Verifying hsm state "
1131 check_hsm_flags $f "0x00000009"
1133 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1134 local st=$(get_hsm_archive_id $f)
1135 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1136 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1141 run_test 10a "Archive a file"
1144 # test needs a running copytool
1148 local f=$DIR/$tdir/$tfile
1149 local fid=$(copy_file /etc/hosts $f)
1150 $LFS hsm_archive $f || error "archive request failed"
1151 wait_request_state $fid ARCHIVE SUCCEED
1153 $LFS hsm_archive $f || error "archive of non dirty file failed"
1154 local cnt=$(get_request_count $fid ARCHIVE)
1155 [[ "$cnt" == "1" ]] ||
1156 error "archive of non dirty file must not make a request"
1160 run_test 10b "Archive of non dirty file must work without doing request"
1163 # test needs a running copytool
1167 local f=$DIR/$tdir/$tfile
1168 local fid=$(copy_file /etc/hosts $f)
1169 $LFS hsm_set --noarchive $f
1170 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1174 run_test 10c "Check forbidden archive"
1177 # test needs a running copytool
1181 local f=$DIR/$tdir/$tfile
1182 local fid=$(copy_file /etc/hosts $f)
1183 $LFS hsm_archive $f || error "cannot archive $f"
1184 wait_request_state $fid ARCHIVE SUCCEED
1186 local ar=$(get_hsm_archive_id $f)
1187 local dflt=$(get_hsm_param default_archive_id)
1188 [[ $ar == $dflt ]] ||
1189 error "archived file is not on default archive: $ar != $dflt"
1193 run_test 10d "Archive a file on the default archive id"
1197 copy2archive /etc/hosts $tdir/$tfile
1198 local f=$DIR/$tdir/$tfile
1200 import_file $tdir/$tfile $f
1201 echo -n "Verifying released state: "
1202 check_hsm_flags $f "0x0000000d"
1204 local LSZ=$(stat -c "%s" $f)
1205 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1207 echo "Verifying imported size $LSZ=$ASZ"
1208 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1209 echo -n "Verifying released pattern: "
1210 local PTRN=$($GETSTRIPE -L $f)
1212 [[ $PTRN == 80000001 ]] || error "Is not released"
1213 local fid=$(path2fid $f)
1214 echo "Verifying new fid $fid in archive"
1216 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1217 error "fid $fid not in archive $HSM_ARCHIVE"
1219 run_test 11a "Import a file"
1222 # test needs a running copytool
1226 local f=$DIR/$tdir/$tfile
1227 local fid=$(copy_file /etc/hosts $f)
1228 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1229 error "hsm_archive failed"
1230 wait_request_state $fid ARCHIVE SUCCEED
1232 local FILE_HASH=$(md5sum $f)
1237 echo "$FILE_HASH" | md5sum -c
1239 [[ $? -eq 0 ]] || error "Restored file differs"
1243 run_test 11b "Import a deleted file using its FID"
1246 # test needs a running copytool
1250 copy2archive /etc/hosts $tdir/$tfile
1252 local f=$DIR/$tdir/$tfile
1253 import_file $tdir/$tfile $f
1254 local f2=$DIR2/$tdir/$tfile
1255 echo "Verifying released state: "
1256 check_hsm_flags $f2 "0x0000000d"
1258 local fid=$(path2fid $f2)
1259 $LFS hsm_restore $f2
1260 wait_request_state $fid RESTORE SUCCEED
1262 echo "Verifying file state: "
1263 check_hsm_flags $f2 "0x00000009"
1265 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1267 [[ $? -eq 0 ]] || error "Restored file differs"
1271 run_test 12a "Restore an imported file explicitly"
1274 # test needs a running copytool
1278 copy2archive /etc/hosts $tdir/$tfile
1280 local f=$DIR/$tdir/$tfile
1281 import_file $tdir/$tfile $f
1282 echo "Verifying released state: "
1283 check_hsm_flags $f "0x0000000d"
1285 cat $f > /dev/null || error "File read failed"
1287 echo "Verifying file state after restore: "
1288 check_hsm_flags $f "0x00000009"
1290 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1292 [[ $? -eq 0 ]] || error "Restored file differs"
1296 run_test 12b "Restore an imported file implicitly"
1299 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1301 # test needs a running copytool
1305 local f=$DIR/$tdir/$tfile
1306 $LFS setstripe -c 2 $f
1308 fid=$(make_large_for_striping $f)
1309 [ $? != 0 ] && skip "not enough free space" && return
1311 local FILE_CRC=$(md5sum $f)
1313 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1314 wait_request_state $fid ARCHIVE SUCCEED
1315 $LFS hsm_release $f || error "release $f failed"
1317 echo "$FILE_CRC" | md5sum -c
1319 [[ $? -eq 0 ]] || error "Restored file differs"
1323 run_test 12c "Restore a file with stripe of 2"
1326 # test needs a running copytool
1331 local f=$DIR/$tdir/$tfile
1332 local fid=$(copy_file /etc/hosts $f)
1333 $LFS hsm_restore $f || error "restore of non archived file failed"
1334 local cnt=$(get_request_count $fid RESTORE)
1335 [[ "$cnt" == "0" ]] ||
1336 error "restore non archived must not make a request"
1337 $LFS hsm_archive $f ||
1338 error "archive request failed"
1339 wait_request_state $fid ARCHIVE SUCCEED
1340 $LFS hsm_restore $f ||
1341 error "restore of non released file failed"
1342 local cnt=$(get_request_count $fid RESTORE)
1343 [[ "$cnt" == "0" ]] ||
1344 error "restore a non dirty file must not make a request"
1348 run_test 12d "Restore of a non archived, non released file must work"\
1349 " without doing request"
1352 # test needs a running copytool
1355 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1356 local f=$DIR/$tdir/$tfile
1357 local fid=$(copy_file /etc/hosts $f)
1358 $LFS hsm_archive $f || error "archive request failed"
1359 wait_request_state $fid ARCHIVE SUCCEED
1362 cat /etc/hosts >> $f
1366 $LFS hsm_restore $f && error "restore a dirty file must fail"
1370 run_test 12e "Check forbidden restore"
1373 # test needs a running copytool
1377 local f=$DIR/$tdir/$tfile
1378 local fid=$(copy_file /etc/hosts $f)
1380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1381 wait_request_state $fid ARCHIVE SUCCEED
1382 $LFS hsm_release $f || error "release of $f failed"
1384 wait_request_state $fid RESTORE SUCCEED
1386 echo -n "Verifying file state: "
1387 check_hsm_flags $f "0x00000009"
1389 diff -q /etc/hosts $f
1391 [[ $? -eq 0 ]] || error "Restored file differs"
1395 run_test 12f "Restore a released file explicitly"
1398 # test needs a running copytool
1402 local f=$DIR/$tdir/$tfile
1403 local fid=$(copy_file /etc/hosts $f)
1405 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1406 wait_request_state $fid ARCHIVE SUCCEED
1407 $LFS hsm_release $f || error "release of $f failed"
1409 diff -q /etc/hosts $f
1412 # we check we had a restore done
1413 wait_request_state $fid RESTORE SUCCEED
1415 [[ $st -eq 0 ]] || error "Restored file differs"
1419 run_test 12g "Restore a released file implicitly"
1422 needclients 2 || return 0
1424 # test needs a running copytool
1428 local f=$DIR/$tdir/$tfile
1429 local fid=$(copy_file /etc/hosts $f)
1431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1432 wait_request_state $fid ARCHIVE SUCCEED
1433 $LFS hsm_release $f || error "release of $f failed"
1435 do_node $CLIENT2 diff -q /etc/hosts $f
1438 # we check we had a restore done
1439 wait_request_state $fid RESTORE SUCCEED
1441 [[ $st -eq 0 ]] || error "Restored file differs"
1445 run_test 12h "Restore a released file implicitly from a second node"
1448 # test needs a running copytool
1452 local f=$DIR/$tdir/$tfile
1453 local fid=$(copy_file /etc/passwd $f)
1454 $LFS hsm_archive $f || error "archive of $f failed"
1455 wait_request_state $fid ARCHIVE SUCCEED
1457 $LFS hsm_release $f || error "release of $f failed"
1461 [[ $? -eq 0 ]] || error "Restored file differs"
1465 run_test 12m "Archive/release/implicit restore"
1468 # test needs a running copytool
1472 copy2archive /etc/hosts $tdir/$tfile
1474 local f=$DIR/$tdir/$tfile
1475 import_file $tdir/$tfile $f
1477 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1478 error "Restored file differs"
1480 $LFS hsm_release $f || error "release of $f failed"
1484 run_test 12n "Import/implicit restore/release"
1487 # test needs a running copytool
1491 local f=$DIR/$tdir/$tfile
1492 local fid=$(copy_file /etc/hosts $f)
1494 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1495 wait_request_state $fid ARCHIVE SUCCEED
1496 $LFS hsm_release $f || error "release of $f failed"
1498 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1499 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1501 # set no retry action mode
1504 diff -q /etc/hosts $f
1507 # we check we had a restore failure
1508 wait_request_state $fid RESTORE FAILED
1510 [[ $st -eq 0 ]] && error "Restore must fail"
1512 # remove no retry action mode
1515 # check file is still released
1516 check_hsm_flags $f "0x0000000d"
1518 # retry w/o failure injection
1519 do_facet $SINGLEMDS lctl set_param fail_loc=0
1521 # to be sure previous RESTORE result is gone
1523 wait_for_grace_delay
1525 diff -q /etc/hosts $f
1528 # we check we had a restore done
1529 wait_request_state $fid RESTORE SUCCEED
1531 [[ $st -eq 0 ]] || error "Restored file differs"
1535 run_test 12o "Layout-swap failure during Restore leaves file released"
1538 # test needs a running copytool
1542 local f=$DIR/$tdir/$tfile
1543 local fid=$(copy_file /etc/hosts $f)
1545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1546 wait_request_state $fid ARCHIVE SUCCEED
1547 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1548 $LFS hsm_release $f || error "cannot release $f"
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"
1555 run_test 12p "implicit restore of a file on copytool mount point"
1557 cleanup_test_12q() {
1559 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1560 error "cannot umount $MOUNT3 on $SINGLEAGT"
1564 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1565 skip "need MDS version at least 2.7.58" && return 0
1567 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1568 error "cannot mount $MOUNT3 on $SINGLEAGT"
1570 trap cleanup_test_12q EXIT
1572 # test needs a running copytool
1573 copytool_setup $SINGLEAGT $MOUNT3
1576 local f=$DIR/$tdir/$tfile
1577 local f2=$DIR2/$tdir/$tfile
1578 local fid=$(make_small $f)
1579 local orig_size=$(stat -c "%s" $f)
1581 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1582 wait_request_state $fid ARCHIVE SUCCEED
1584 $LFS hsm_release $f || error "could not release file"
1585 check_hsm_flags $f "0x0000000d"
1588 wait_copytools || error "copytool failed to stop"
1590 cat $f > /dev/null &
1592 # wait a bit to allow implicit restore request to be handled.
1593 # if not, next stat would also block on layout-lock.
1596 local size=$(stat -c "%s" $f2)
1597 [ $size -eq $orig_size ] ||
1598 error "$f2: wrong size after archive: $size != $orig_size"
1600 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1604 size=$(stat -c "%s" $f)
1605 [ $size -eq $orig_size ] ||
1606 error "$f: wrong size after restore: $size != $orig_size"
1608 size=$(stat -c "%s" $f2)
1609 [ $size -eq $orig_size ] ||
1610 error "$f2: wrong size after restore: $size != $orig_size"
1614 size=$(stat -c "%s" $f)
1616 error "$f: wrong size after overwrite: $size != 0"
1618 size=$(stat -c "%s" $f2)
1620 error "$f2: wrong size after overwrite: $size != 0"
1623 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1624 error "cannot umount $MOUNT3 on $SINGLEAGT"
1626 run_test 12q "file attributes are refreshed after restore"
1629 # test needs a running copytool
1632 local ARC_SUBDIR="import.orig"
1636 # populate directory to be imported
1637 for d in $(seq 1 10); do
1638 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1639 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1640 for f in $(seq 1 10); do
1641 CURR_FILE="$CURR_DIR/$tfile.$f"
1642 # write file-specific data
1643 do_facet $SINGLEAGT \
1644 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1645 "file=$CURR_FILE > $CURR_FILE"
1649 import_file "$ARC_SUBDIR" $DIR/$tdir
1650 # diff lustre content and origin (triggers file restoration)
1651 # there must be 10x10 identical files, and no difference
1652 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1653 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1654 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1655 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1657 [ $cnt_diff -eq 0 ] ||
1658 error "$cnt_diff imported files differ from read data"
1659 [ $cnt_ok -eq 100 ] ||
1660 error "not enough identical files ($cnt_ok != 100)"
1664 run_test 13 "Recursively import and restore a directory"
1667 # test needs a running copytool
1672 local f=$DIR/$tdir/$tfile
1673 local fid=$(make_small $f)
1674 local sum=$(md5sum $f | awk '{print $1}')
1675 $LFS hsm_archive $f || error "could not archive file"
1676 wait_request_state $fid ARCHIVE SUCCEED
1680 # create released file (simulate llapi_hsm_import call)
1682 local fid2=$(path2fid $f)
1683 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1684 $LFS hsm_release $f || error "could not release file"
1686 # rebind the archive to the newly created file
1687 echo "rebind $fid to $fid2"
1689 do_facet $SINGLEAGT \
1690 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1691 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1693 # restore file and compare md5sum
1694 local sum2=$(md5sum $f | awk '{print $1}')
1696 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1700 run_test 14 "Rebind archived file to a new fid"
1703 # test needs a running copytool
1708 local f=$DIR/$tdir/$tfile
1710 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1714 for i in $(seq 1 $count); do
1715 fids[$i]=$(make_small $f.$i)
1716 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1717 $LFS hsm_archive $f.$i || error "could not archive file"
1719 wait_all_done $(($count*60))
1723 for i in $(seq 1 $count); do
1726 local fid2=$(path2fid $f.$i)
1727 # add the rebind operation to the list
1728 echo ${fids[$i]} $fid2 >> $tmpfile
1730 # set it released (simulate llapi_hsm_import call)
1731 $LFS hsm_set --archived --exists $f.$i ||
1732 error "could not force hsm flags"
1733 $LFS hsm_release $f.$i || error "could not release file"
1735 nl=$(wc -l < $tmpfile)
1736 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1738 echo "rebind list of files"
1739 do_facet $SINGLEAGT \
1740 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1741 --rebind $tmpfile $DIR" || error "could not rebind file list"
1743 # restore files and compare md5sum
1744 for i in $(seq 1 $count); do
1745 local sum2=$(md5sum $f.$i | awk '{print $1}')
1746 [[ $sum2 == ${sums[$i]} ]] ||
1747 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1753 run_test 15 "Rebind a list of files"
1756 # test needs a running copytool
1760 # create a known size file so we can verify transfer speed
1763 dd if=/dev/zero of=$ref bs=1M count=20
1766 local f=$DIR/$tdir/$tfile
1767 local fid=$(copy_file $ref $f)
1769 local start=$(date +%s)
1771 wait_request_state $fid ARCHIVE SUCCEED
1772 local end=$(date +%s)
1773 # Add 1 to account for rounding errors between start and end (LU-8155)
1774 local duration=$((end - start + 1))
1776 [[ $duration -ge $goal ]] ||
1777 error "Transfer is too fast $duration < $goal"
1781 run_test 16 "Test CT bandwith control option"
1786 local f=$DIR/$tdir/$tfile
1787 touch $f || error "touch $f failed"
1789 # Could not release a non-archived file
1790 $LFS hsm_release $f && error "release should not succeed"
1792 # For following tests, we must test them with HS_ARCHIVED set
1793 $LFS hsm_set --exists --archived $f || error "could not add flag"
1795 # Could not release a file if no-release is set
1796 $LFS hsm_set --norelease $f || error "could not add flag"
1797 $LFS hsm_release $f && error "release should not succeed"
1798 $LFS hsm_clear --norelease $f || error "could not remove flag"
1800 # Could not release a file if lost
1801 $LFS hsm_set --lost $f || error "could not add flag"
1802 $LFS hsm_release $f && error "release should not succeed"
1803 $LFS hsm_clear --lost $f || error "could not remove flag"
1805 # Could not release a file if dirty
1806 $LFS hsm_set --dirty $f || error "could not add flag"
1807 $LFS hsm_release $f && error "release should not succeed"
1808 $LFS hsm_clear --dirty $f || error "could not remove flag"
1810 run_test 20 "Release is not permitted"
1813 # test needs a running copytool
1817 local f=$DIR/$tdir/test_release
1819 # Create a file and check its states
1820 local fid=$(make_small $f)
1821 check_hsm_flags $f "0x00000000"
1823 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1824 # used until file is flushed to disk
1825 if [ $(facet_fstype ost1) == "zfs" ]; then
1826 # this causes an OST_SYNC rpc to be sent
1827 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1828 # clear locks to reread file data
1829 cancel_lru_locks osc
1832 local orig_size=$(stat -c "%s" $f)
1833 local orig_blocks=$(stat -c "%b" $f)
1835 start_full_debug_logging
1837 $LFS hsm_archive $f || error "could not archive file"
1838 wait_request_state $fid ARCHIVE SUCCEED
1840 local blocks=$(stat -c "%b" $f)
1841 [ $blocks -eq $orig_blocks ] ||
1842 error "$f: wrong block number after archive: " \
1843 "$blocks != $orig_blocks"
1844 local size=$(stat -c "%s" $f)
1845 [ $size -eq $orig_size ] ||
1846 error "$f: wrong size after archive: $size != $orig_size"
1848 # Release and check states
1849 $LFS hsm_release $f || error "could not release file"
1850 check_hsm_flags $f "0x0000000d"
1852 blocks=$(stat -c "%b" $f)
1853 [ $blocks -gt 5 ] &&
1854 error "$f: too many blocks after release: $blocks > 5"
1855 size=$(stat -c "%s" $f)
1856 [ $size -ne $orig_size ] &&
1857 error "$f: wrong size after release: $size != $orig_size"
1859 # Check we can release an file without stripe info
1863 check_hsm_flags $f "0x00000000"
1864 $LFS hsm_archive $f || error "could not archive file"
1865 wait_request_state $fid ARCHIVE SUCCEED
1867 # Release and check states
1868 $LFS hsm_release $f || error "could not release file"
1869 check_hsm_flags $f "0x0000000d"
1871 # Release again a file that is already released is OK
1872 $LFS hsm_release $f || fail "second release should succeed"
1873 check_hsm_flags $f "0x0000000d"
1875 stop_full_debug_logging
1879 run_test 21 "Simple release tests"
1882 # test needs a running copytool
1887 local f=$DIR/$tdir/test_release
1888 local swap=$DIR/$tdir/test_swap
1890 # Create a file and check its states
1891 local fid=$(make_small $f)
1892 check_hsm_flags $f "0x00000000"
1894 $LFS hsm_archive $f || error "could not archive file"
1895 wait_request_state $fid ARCHIVE SUCCEED
1897 # Release and check states
1898 $LFS hsm_release $f || error "could not release file"
1899 check_hsm_flags $f "0x0000000d"
1902 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1907 run_test 22 "Could not swap a release file"
1910 # test needs a running copytool
1915 local f=$DIR/$tdir/test_mtime
1917 # Create a file and check its states
1918 local fid=$(make_small $f)
1919 check_hsm_flags $f "0x00000000"
1921 $LFS hsm_archive $f || error "could not archive file"
1922 wait_request_state $fid ARCHIVE SUCCEED
1924 # Set modification time in the past
1925 touch -m -a -d @978261179 $f
1927 # Release and check states
1928 $LFS hsm_release $f || error "could not release file"
1929 check_hsm_flags $f "0x0000000d"
1931 local MTIME=$(stat -c "%Y" $f)
1932 local ATIME=$(stat -c "%X" $f)
1933 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1934 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1938 run_test 23 "Release does not change a/mtime (utime)"
1941 local file=$DIR/$tdir/$tfile
1950 # test needs a running copytool
1955 fid=$(make_small $file)
1957 # Create a file and check its states
1958 check_hsm_flags $file "0x00000000"
1960 # Ensure atime is less than mtime and ctime.
1964 atime0=$(stat -c "%X" $file)
1965 mtime0=$(stat -c "%Y" $file)
1966 ctime0=$(stat -c "%Z" $file)
1968 [ $atime0 -lt $mtime0 ] ||
1969 error "atime $atime0 is not less than mtime $mtime0"
1971 [ $atime0 -lt $ctime0 ] ||
1972 error "atime $atime0 is not less than ctime $ctime0"
1974 # Archive should not change any timestamps.
1975 $LFS hsm_archive $file || error "cannot archive '$file'"
1976 wait_request_state $fid ARCHIVE SUCCEED
1978 atime1=$(stat -c "%X" $file)
1979 mtime1=$(stat -c "%Y" $file)
1980 ctime1=$(stat -c "%Z" $file)
1982 [ $atime0 -eq $atime1 ] ||
1983 error "archive changed atime from $atime0 to $atime1"
1985 [ $mtime0 -eq $mtime1 ] ||
1986 error "archive changed mtime from $mtime0 to $mtime1"
1988 [ $ctime0 -eq $ctime1 ] ||
1989 error "archive changed ctime from $ctime0 to $ctime1"
1991 # Release should not change any timestamps.
1992 $LFS hsm_release $file || error "cannot release '$file'"
1993 check_hsm_flags $file "0x0000000d"
1995 atime1=$(stat -c "%X" $file)
1996 mtime1=$(stat -c "%Y" $file)
1997 ctime1=$(stat -c "%Z" $file)
1999 [ $atime0 -eq $atime1 ] ||
2000 error "release changed atime from $atime0 to $atime1"
2002 [ $mtime0 -eq $mtime1 ] ||
2003 error "release changed mtime from $mtime0 to $mtime1"
2005 [ $ctime0 -eq $ctime1 ] ||
2006 error "release changed ctime from $ctime0 to $ctime1"
2008 # Restore should not change any timestamps.
2009 $LFS hsm_restore $file
2010 wait_request_state $fid RESTORE SUCCEED
2012 atime1=$(stat -c "%X" $file)
2013 mtime1=$(stat -c "%Y" $file)
2014 ctime1=$(stat -c "%Z" $file)
2016 [ $atime0 -eq $atime1 ] ||
2017 error "restore changed atime from $atime0 to $atime1"
2019 [ $mtime0 -eq $mtime1 ] ||
2020 error "restore changed mtime from $mtime0 to $mtime1"
2022 [ $ctime0 -eq $ctime1 ] ||
2023 error "restore changed ctime from $ctime0 to $ctime1"
2027 # Once more, after unmount and mount.
2028 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2029 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2031 atime1=$(stat -c "%X" $file)
2032 mtime1=$(stat -c "%Y" $file)
2033 ctime1=$(stat -c "%Z" $file)
2035 [ $atime0 -eq $atime1 ] ||
2036 error "remount changed atime from $atime0 to $atime1"
2038 [ $mtime0 -eq $mtime1 ] ||
2039 error "remount changed mtime from $mtime0 to $mtime1"
2041 [ $ctime0 -eq $ctime1 ] ||
2042 error "remount changed ctime from $ctime0 to $ctime1"
2044 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2047 local file=$DIR/$tdir/$tfile
2053 # Test needs a running copytool.
2057 # Check that root can do HSM actions on a regular user's file.
2059 fid=$(make_small $file)
2060 sum0=$(md5sum $file)
2062 chown $RUNAS_ID:$RUNAS_GID $file ||
2063 error "cannot chown '$file' to '$RUNAS_ID'"
2065 chmod ugo-w $DIR/$tdir ||
2066 error "cannot chmod '$DIR/$tdir'"
2068 $LFS hsm_archive $file
2069 wait_request_state $fid ARCHIVE SUCCEED
2071 $LFS hsm_release $file
2072 check_hsm_flags $file "0x0000000d"
2074 $LFS hsm_restore $file
2075 wait_request_state $fid RESTORE SUCCEED
2077 # Check that ordinary user can get HSM state.
2078 $RUNAS $LFS hsm_state $file ||
2079 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2081 $LFS hsm_release $file
2082 check_hsm_flags $file "0x0000000d"
2084 # Check that ordinary user can accessed released file.
2085 sum1=$($RUNAS md5sum $file) ||
2086 error "user '$RUNAS_ID' cannot read '$file'"
2088 [ "$sum0" == "$sum1" ] ||
2089 error "md5sum mismatch for '$file'"
2093 run_test 24b "root can archive, release, and restore user files"
2095 cleanup_test_24c() {
2097 set_hsm_param user_request_mask RESTORE
2098 set_hsm_param group_request_mask RESTORE
2099 set_hsm_param other_request_mask RESTORE
2103 local file=$DIR/$tdir/$tfile
2104 local action=archive
2109 # test needs a running copytool
2114 # Save the default masks and check that cleanup_24c will
2115 # restore the request masks correctly.
2116 user_save=$(get_hsm_param user_request_mask)
2117 group_save=$(get_hsm_param group_request_mask)
2118 other_save=$(get_hsm_param other_request_mask)
2120 [ "$user_save" == RESTORE ] ||
2121 error "user_request_mask is '$user_save' expected 'RESTORE'"
2122 [ "$group_save" == RESTORE ] ||
2123 error "group_request_mask is '$group_save' expected 'RESTORE'"
2124 [ "$other_save" == RESTORE ] ||
2125 error "other_request_mask is '$other_save' expected 'RESTORE'"
2127 trap cleanup_test_24c EXIT
2132 chown $RUNAS_ID:nobody $file ||
2133 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2135 set_hsm_param user_request_mask ""
2136 $RUNAS $LFS hsm_$action $file &&
2137 error "$action by user should fail"
2139 set_hsm_param user_request_mask $action
2140 $RUNAS $LFS hsm_$action $file ||
2141 error "$action by user should succeed"
2146 chown nobody:$RUNAS_GID $file ||
2147 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2149 set_hsm_param group_request_mask ""
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 set_hsm_param other_request_mask ""
2164 $RUNAS $LFS hsm_$action $file &&
2165 error "$action by other should fail"
2167 set_hsm_param other_request_mask $action
2168 $RUNAS $LFS hsm_$action $file ||
2169 error "$action by other should succeed"
2174 run_test 24c "check that user,group,other request masks work"
2176 cleanup_test_24d() {
2178 mount -o remount,rw $MOUNT2
2182 local file1=$DIR/$tdir/$tfile
2183 local file2=$DIR2/$tdir/$tfile
2191 fid1=$(make_small $file1)
2193 trap cleanup_test_24d EXIT
2195 mount -o remount,ro $MOUNT2
2197 fid2=$(path2fid $file2)
2198 [ "$fid1" == "$fid2" ] ||
2199 error "FID mismatch '$fid1' != '$fid2'"
2201 $LFS hsm_archive $file2 &&
2202 error "archive should fail on read-only mount"
2203 check_hsm_flags $file1 "0x00000000"
2205 $LFS hsm_archive $file1
2206 wait_request_state $fid1 ARCHIVE SUCCEED
2208 $LFS hsm_release $file1
2209 $LFS hsm_restore $file2
2210 wait_request_state $fid1 RESTORE SUCCEED
2212 $LFS hsm_release $file1 || error "cannot release '$file1'"
2213 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2215 $LFS hsm_release $file2 &&
2216 error "release should fail on read-only mount"
2221 run_test 24d "check that read-only mounts are respected"
2228 local f=$DIR/$tdir/$tfile
2231 fid=$(make_small $f) || error "cannot create $f"
2232 $LFS hsm_archive $f || error "cannot archive $f"
2233 wait_request_state $fid ARCHIVE SUCCEED
2234 $LFS hsm_release $f || error "cannot release $f"
2235 while ! $LFS hsm_state $f | grep released; do
2239 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2243 run_test 24e "tar succeeds on HSM released files" # LU-6213
2247 # test needs a running copytool
2250 mkdir -p $DIR/$tdir/d1
2251 local f=$DIR/$tdir/$tfile
2252 local fid=$(copy_file /etc/hosts $f)
2255 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2256 error "hsm_archive failed"
2257 wait_request_state $fid ARCHIVE SUCCEED
2258 $LFS hsm_release $f || error "cannot release $f"
2259 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2262 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2263 error "Can not recover the tar contents"
2265 echo "Sum0 = $sum0, sum1 = $sum1"
2266 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2270 run_test 24f "root can archive, release, and restore tar files"
2273 # test needs a running copytool
2277 copy2archive /etc/hosts $tdir/$tfile
2279 local f=$DIR/$tdir/$tfile
2281 import_file $tdir/$tfile $f
2283 $LFS hsm_set --lost $f
2288 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2292 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2293 " (Operation not permitted)"
2296 # test needs a running copytool
2301 local f=$DIR/$tdir/$tfile
2302 local fid=$(copy_file /etc/passwd $f)
2304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2305 wait_request_state $fid ARCHIVE SUCCEED
2308 $LFS hsm_set --lost $f
2312 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2316 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2317 " (Operation not permitted)"
2320 # test needs a running copytool
2324 local f=$DIR/$tdir/$tfile
2326 fid=$(make_large_for_progress $f)
2327 [ $? != 0 ] && skip "not enough free space" && return
2329 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2330 wait_request_state $fid ARCHIVE SUCCEED
2333 wait_request_state $fid REMOVE SUCCEED
2335 check_hsm_flags $f "0x00000000"
2339 run_test 26 "Remove the archive of a valid file"
2342 # test needs a running copytool
2346 make_archive $tdir/$tfile
2347 local f=$DIR/$tdir/$tfile
2348 import_file $tdir/$tfile $f
2349 local fid=$(path2fid $f)
2353 [[ $? != 0 ]] || error "Remove of a released file should fail"
2357 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2360 # test needs a running copytool
2364 local f=$DIR/$tdir/$tfile
2366 fid=$(make_large_for_progress $f)
2367 [ $? != 0 ] && skip "not enough free space" && return
2369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2370 wait_request_state $fid ARCHIVE SUCCEED
2375 [[ $? != 0 ]] || error "Remove of a released file should fail"
2379 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2382 # test needs a running copytool
2386 local f=$DIR/$tdir/$tfile
2388 fid=$(make_large_for_progress $f)
2389 [ $? != 0 ] && skip "not enough free space" && return
2391 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2392 wait_request_state $fid ARCHIVE SUCCEED
2401 wait_request_state $fid REMOVE SUCCEED
2405 run_test 28 "Concurrent archive/file remove"
2408 # Tests --mntpath and --archive options
2411 copytool_setup $SINGLEAGT $MOUNT $archive_id
2413 # Bad archive number
2414 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2415 grep "Invalid argument" ||
2416 error "unexpected hsm_remove failure (1)"
2418 # mntpath is present but file is given
2419 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2420 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2421 error "unexpected hsm_remove failure (2)"
2425 run_test 29a "Tests --mntpath and --archive options"
2428 # test needs a running copytool
2432 local f=$DIR/$tdir/$tfile
2433 local fid=$(make_small $f)
2435 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2436 wait_request_state $fid ARCHIVE SUCCEED
2440 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2441 wait_request_state $fid REMOVE SUCCEED
2445 run_test 29b "Archive/delete/remove by FID from the archive."
2448 # test needs a running copytool
2452 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2453 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2454 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2456 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2457 wait_request_state $fid1 ARCHIVE SUCCEED
2458 wait_request_state $fid2 ARCHIVE SUCCEED
2459 wait_request_state $fid3 ARCHIVE SUCCEED
2461 rm -f $DIR/$tdir/$tfile-[1-3]
2463 echo $fid1 > $DIR/$tdir/list
2464 echo $fid2 >> $DIR/$tdir/list
2465 echo $fid3 >> $DIR/$tdir/list
2467 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2468 --filelist $DIR/$tdir/list
2469 wait_request_state $fid1 REMOVE SUCCEED
2470 wait_request_state $fid2 REMOVE SUCCEED
2471 wait_request_state $fid3 REMOVE SUCCEED
2475 run_test 29c "Archive/delete/remove by FID, using a file list."
2478 # restore at exec cannot work on agent node (because of Linux kernel
2479 # protection of executables)
2480 needclients 2 || return 0
2482 # test needs a running copytool
2486 copy2archive /bin/true $tdir/$tfile
2488 local f=$DIR/$tdir/true
2489 import_file $tdir/$tfile $f
2491 local fid=$(path2fid $f)
2493 # set no retry action mode
2499 # remove no try action mode
2503 [[ $st == 0 ]] || error "Failed to exec a released file"
2507 run_test 30a "Restore at exec (import case)"
2510 # restore at exec cannot work on agent node (because of Linux kernel
2511 # protection of executables)
2512 needclients 2 || return 0
2514 # test needs a running copytool
2518 local f=$DIR/$tdir/true
2519 local fid=$(copy_file /bin/true $f)
2521 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2522 wait_request_state $fid ARCHIVE SUCCEED
2525 # set no retry action mode
2531 # remove no try action mode
2535 [[ $st == 0 ]] || error "Failed to exec a released file"
2539 run_test 30b "Restore at exec (release case)"
2542 needclients 2 || return 0
2544 # test needs a running copytool
2548 local f=$DIR/$tdir/SLEEP
2549 local slp_sum1=$(md5sum /bin/sleep)
2550 local fid=$(copy_file /bin/sleep $f)
2552 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2553 wait_request_state $fid ARCHIVE SUCCEED
2555 check_hsm_flags $f "0x0000000d"
2556 # set no retry action mode
2558 do_node $CLIENT2 "$f 10" &
2562 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2564 [[ $? == 0 ]] || error "Execution failed during run"
2566 if [[ $? != 0 ]]; then
2567 local slp_sum2=$(md5sum /bin/sleep)
2568 # in case sleep file is modified during the test
2569 [[ $slp_sum1 == $slp_sum2 ]] &&
2570 error "Binary overwritten during exec"
2574 # remove no try action mode
2576 check_hsm_flags $f "0x00000009"
2580 run_test 30c "Update during exec of released file must fail"
2582 restore_and_check_size() {
2585 local s=$(stat -c "%s" $f)
2587 local st=$(get_hsm_flags $f)
2591 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2593 n=$(stat -c "%s" $f)
2594 # we echo in both cases to show stat is not
2596 if [[ $n != $s ]]; then
2597 echo "size seen is $n != $s"
2600 echo "size seen is right: $n == $s"
2602 st=$(get_hsm_flags $f)
2606 if [[ $cpt -lt 10 ]]; then
2609 echo " restore is too long"
2610 wait_request_state $fid RESTORE SUCCEED
2616 # test needs a running copytool
2621 make_archive $tdir/$tfile
2622 local f=$DIR/$tdir/$tfile
2623 import_file $tdir/$tfile $f
2624 local fid=$($LFS path2fid $f)
2625 HSM_ARCHIVE_PURGE=false copytool_setup
2627 restore_and_check_size $f $fid
2630 [[ $err -eq 0 ]] || error "File size changed during restore"
2634 run_test 31a "Import a large file and check size during restore"
2638 # test needs a running copytool
2643 local f=$DIR/$tdir/$tfile
2645 fid=$(make_large_for_progress $f)
2646 [ $? != 0 ] && skip "not enough free space" && return
2648 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2649 wait_request_state $fid ARCHIVE SUCCEED
2652 restore_and_check_size $f $fid
2655 [[ $err -eq 0 ]] || error "File size changed during restore"
2659 run_test 31b "Restore a large unaligned file and check size during restore"
2662 # test needs a running copytool
2667 local f=$DIR/$tdir/$tfile
2669 fid=$(make_large_for_progress_aligned $f)
2670 [ $? != 0 ] && skip "not enough free space" && return
2672 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2673 wait_request_state $fid ARCHIVE SUCCEED
2676 restore_and_check_size $f $fid
2679 [[ $err -eq 0 ]] || error "File size changed during restore"
2683 run_test 31c "Restore a large aligned file and check size during restore"
2686 # test needs a running copytool
2691 local f=$DIR/$tdir/$tfile
2693 fid=$(make_large_for_progress $f)
2694 [ $? != 0 ] && skip "not enough free space" && return
2696 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2697 wait_request_state $fid ARCHIVE SUCCEED
2700 # to be sure wait_all_done will not be mislead by previous tests
2703 wait_for_grace_delay
2704 # Also raise grace_delay significantly so the Canceled
2705 # Restore action will stay enough long avail.
2706 local old_grace=$(get_hsm_param grace_delay)
2707 set_hsm_param grace_delay 100
2709 md5sum $f >/dev/null &
2711 wait_request_state $fid RESTORE STARTED
2716 # Check restore trigger process was killed
2717 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2721 # instead of waiting+checking both Restore and Cancel ops
2722 # sequentially, wait for both to be finished and then check
2724 wait_all_done 100 $fid
2725 local rstate=$(get_request_state $fid RESTORE)
2726 local cstate=$(get_request_state $fid CANCEL)
2728 # restore orig grace_delay.
2729 set_hsm_param grace_delay $old_grace
2731 if [[ "$rstate" == "CANCELED" ]] ; then
2732 [[ "$cstate" == "SUCCEED" ]] ||
2733 error "Restore state is CANCELED and Cancel state " \
2734 "is not SUCCEED but $cstate"
2735 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2736 elif [[ "$rstate" == "SUCCEED" ]] ; then
2737 [[ "$cstate" == "FAILED" ]] ||
2738 error "Restore state is SUCCEED and Cancel state " \
2739 "is not FAILED but $cstate"
2740 echo "Restore state is SUCCEED, Cancel state is FAILED"
2742 error "Restore state is $rstate and Cancel state is $cstate"
2746 error "Cannot kill process waiting for restore ($killed)"
2750 run_test 33 "Kill a restore waiting process"
2753 # test needs a running copytool
2758 local f=$DIR/$tdir/$tfile
2760 fid=$(make_large_for_progress $f)
2761 [ $? != 0 ] && skip "not enough free space" && return
2763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2764 wait_request_state $fid ARCHIVE SUCCEED
2767 md5sum $f >/dev/null &
2769 wait_request_state $fid RESTORE STARTED
2771 rm $f || error "rm $f failed"
2772 # rm must not block during restore
2773 wait_request_state $fid RESTORE STARTED
2775 wait_request_state $fid RESTORE SUCCEED
2776 # check md5sum pgm finished
2777 local there=$(ps -o pid,comm hp $pid >/dev/null)
2778 [[ -z $there ]] || error "Restore initiator does not exit"
2780 local rc=$(wait $pid)
2781 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2785 run_test 34 "Remove file during restore"
2788 # test needs a running copytool
2793 local f=$DIR/$tdir/$tfile
2794 local f1=$DIR/$tdir/$tfile-1
2796 fid=$(make_large_for_progress $f)
2797 [ $? != 0 ] && skip "not enough free space" && return
2799 local fid1=$(copy_file /etc/passwd $f1)
2800 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2801 wait_request_state $fid ARCHIVE SUCCEED
2804 md5sum $f >/dev/null &
2806 wait_request_state $fid RESTORE STARTED
2808 mv $f1 $f || error "mv $f1 $f failed"
2809 # mv must not block during restore
2810 wait_request_state $fid RESTORE STARTED
2812 wait_request_state $fid RESTORE SUCCEED
2813 # check md5sum pgm finished
2814 local there=$(ps -o pid,comm hp $pid >/dev/null)
2815 [[ -z $there ]] || error "Restore initiator does not exit"
2817 local rc=$(wait $pid)
2818 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2821 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2825 run_test 35 "Overwrite file during restore"
2828 # test needs a running copytool
2833 local f=$DIR/$tdir/$tfile
2835 fid=$(make_large_for_progress $f)
2836 [ $? != 0 ] && skip "not enough free space" && return
2838 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2839 wait_request_state $fid ARCHIVE SUCCEED
2842 md5sum $f >/dev/null &
2844 wait_request_state $fid RESTORE STARTED
2847 # rm must not block during restore
2848 wait_request_state $fid RESTORE STARTED
2850 wait_request_state $fid RESTORE SUCCEED
2851 # check md5sum pgm finished
2852 local there=$(ps -o pid,comm hp $pid >/dev/null)
2854 error "Restore initiator does not exit"
2856 local rc=$(wait $pid)
2858 error "Restore initiator failed with $rc"
2862 run_test 36 "Move file during restore"
2865 # LU-5683: check that an archived dirty file can be rearchived.
2867 copytool_setup $SINGLEAGT $MOUNT2
2870 local f=$DIR/$tdir/$tfile
2873 fid=$(make_small $f) || error "cannot create small file"
2875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2876 wait_request_state $fid ARCHIVE SUCCEED
2877 $LFS hsm_release $f || error "cannot release $f"
2880 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2882 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2883 wait_request_state $fid ARCHIVE SUCCEED
2887 run_test 37 "re-archive a dirty file"
2894 for n in $(seq 1 $count); do
2895 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2897 echo "$count archive requests submitted"
2901 local stream_count=4
2902 local file_count=100
2904 local f=$DIR/$tdir/$tfile
2909 for i in $(seq 1 $file_count); do
2910 for p in $(seq 1 $stream_count); do
2911 fid=$(copy_file /etc/hosts $f.$p.$i)
2914 # force copytool to use a local/temp archive dir to ensure best
2915 # performance vs remote/NFS mounts used in auto-tests
2916 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2919 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2921 # to be sure wait_all_done will not be mislead by previous tests
2923 wait_for_grace_delay
2925 # start archive streams in background (archive files in parallel)
2926 for p in $(seq 1 $stream_count); do
2927 multi_archive $f.$p $file_count &
2930 echo -n "Wait for all requests being enqueued..."
2936 run_test 40 "Parallel archive requests"
2939 # test needs a running copytool
2943 local f=$DIR/$tdir/$tfile
2944 local fid=$(copy_file /etc/motd $f 1)
2946 $LFS hsm_archive $f || error "could not archive file"
2947 wait_request_state $fid ARCHIVE SUCCEED
2948 check_hsm_flags $f "0x00000009"
2950 multiop_bg_pause $f O_c || error "multiop failed"
2954 client_up || client_up || true
2956 kill -USR1 $MULTIPID
2957 wait $MULTIPID || error "multiop close failed"
2959 check_hsm_flags $f "0x0000000b"
2963 run_test 52 "Opened for write file on an evicted client should be set dirty"
2966 # test needs a running copytool
2970 local f=$DIR/$tdir/$tfile
2971 local fid=$(copy_file /etc/motd $f 1)
2973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2974 error "could not archive file"
2975 wait_request_state $fid ARCHIVE SUCCEED
2976 check_hsm_flags $f "0x00000009"
2978 multiop_bg_pause $f o_c || error "multiop failed"
2982 client_up || client_up || true
2984 kill -USR1 $MULTIPID
2985 wait $MULTIPID || error "multiop close failed"
2987 check_hsm_flags $f "0x00000009"
2991 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2994 # test needs a running copytool
2998 local f=$DIR/$tdir/$tfile
2999 local fid=$(make_large_for_progress $f)
3001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3002 error "could not archive file"
3003 wait_request_state $fid ARCHIVE STARTED
3005 check_hsm_flags $f "0x00000001"
3007 # Avoid coordinator resending this request as soon it has failed.
3012 wait_request_state $fid ARCHIVE FAILED
3014 check_hsm_flags $f "0x00000003"
3019 run_test 54 "Write during an archive cancels it"
3022 # test needs a running copytool
3026 local f=$DIR/$tdir/$tfile
3027 local fid=$(make_large_for_progress $f)
3029 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3030 error "could not archive file"
3031 wait_request_state $fid ARCHIVE STARTED
3033 check_hsm_flags $f "0x00000001"
3035 # Avoid coordinator resending this request as soon it has failed.
3038 $TRUNCATE $f 1024 || error "truncate failed"
3040 wait_request_state $fid ARCHIVE FAILED
3042 check_hsm_flags $f "0x00000003"
3047 run_test 55 "Truncate during an archive cancels it"
3050 # test needs a running copytool
3054 local f=$DIR/$tdir/$tfile
3056 fid=$(make_large_for_progress $f)
3057 [ $? != 0 ] && skip "not enough free space" && return
3059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3060 error "could not archive file"
3061 wait_request_state $fid ARCHIVE STARTED
3063 check_hsm_flags $f "0x00000001"
3065 # Change metadata and sync to be sure we are not changing only
3070 wait_request_state $fid ARCHIVE SUCCEED
3072 check_hsm_flags $f "0x00000009"
3076 run_test 56 "Setattr during an archive is ok"
3079 # Need one client for I/O, one for request
3080 needclients 2 || return 0
3082 # test needs a running copytool
3086 local f=$DIR/$tdir/test_archive_remote
3087 # Create a file on a remote node
3088 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3089 "count=2 conv=fsync"
3092 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3093 error "hsm_archive failed"
3094 local fid=$(path2fid $f)
3095 wait_request_state $fid ARCHIVE SUCCEED
3097 # Release and implicit restore it
3098 do_node $CLIENT2 "$LFS hsm_release $f" ||
3099 error "hsm_release failed"
3100 do_node $CLIENT2 "md5sum $f" ||
3101 error "hsm_restore failed"
3103 wait_request_state $fid RESTORE SUCCEED
3107 run_test 57 "Archive a file with dirty cache on another node"
3109 truncate_released_file() {
3113 local sz=$(stat -c %s $src_file)
3114 local f=$DIR/$tdir/$tfile
3115 local fid=$(copy_file $1 $f)
3119 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3120 error "could not archive file"
3121 wait_request_state $fid ARCHIVE SUCCEED
3123 $LFS hsm_release $f || error "could not release file"
3125 $TRUNCATE $f $trunc_to || error "truncate failed"
3128 local sz1=$(stat -c %s $f)
3129 [[ $sz1 == $trunc_to ]] ||
3130 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3133 check_hsm_flags $f "0x0000000b"
3135 local state=$(get_request_state $fid RESTORE)
3136 [[ "$state" == "SUCCEED" ]] ||
3137 error "truncate $sz does not trig restore, state = $state"
3139 $TRUNCATE $ref $trunc_to
3140 cmp $ref $f || error "file data wrong after truncate"
3146 # test needs a running copytool
3151 local sz=$(stat -c %s /etc/passwd)
3153 echo "truncate up from $sz to $((sz*2))"
3154 truncate_released_file /etc/passwd $((sz*2))
3156 echo "truncate down from $sz to $((sz/2))"
3157 truncate_released_file /etc/passwd $((sz/2))
3159 echo "truncate to 0"
3160 truncate_released_file /etc/passwd 0
3164 run_test 58 "Truncate a released file will trigger restore"
3168 local server_version=$(lustre_version_code $SINGLEMDS)
3169 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3170 skip "Need MDS version at least 2.7.63" && return
3173 $MCREATE $DIR/$tfile || error "mcreate failed"
3174 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3175 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3176 fid=$(path2fid $DIR/$tfile)
3177 wait_request_state $fid ARCHIVE SUCCEED
3178 $LFS hsm_release $DIR/$tfile || error "release failed"
3181 run_test 59 "Release stripeless file with non-zero size"
3184 # This test validates the fix for LU-4512. Ensure that the -u
3185 # option changes the progress reporting interval from the
3186 # default (30 seconds) to the user-specified interval.
3188 local progress_timeout=$((interval * 4))
3190 # test needs a new running copytool
3192 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3195 local f=$DIR/$tdir/$tfile
3197 fid=$(make_large_for_progress $f)
3198 [ $? != 0 ] && skip "not enough free space" && return
3201 local mdt=${MDT_PREFIX}${mdtidx}
3202 local mds=mds$((mdtidx + 1))
3204 # Wait for copytool to register
3205 wait_update_facet $mds \
3206 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3207 uuid 100 || error "coyptool failed to register with $mdt"
3209 local start_at=$(date +%s)
3210 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3211 error "could not archive file"
3213 local agent=$(facet_active_host $SINGLEAGT)
3214 local prefix=$TESTLOG_PREFIX
3215 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3216 local copytool_log=$prefix.copytool_log.$agent.log
3219 wait_update $agent \
3220 "grep -o start.copy $copytool_log" "start copy" 100 ||
3221 error "copytool failed to start"
3223 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3224 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3230 echo -n "Expecting a progress update within $progress_timeout seconds... "
3232 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3233 if [ $RESULT -gt 0 ]; then
3234 echo "$RESULT bytes copied in $WAIT seconds."
3236 elif [ $WAIT -ge $progress_timeout ]; then
3237 error "Timed out waiting for progress update!"
3240 WAIT=$((WAIT + sleep))
3244 local finish_at=$(date +%s)
3245 local elapsed=$((finish_at - start_at))
3247 # Ensure that the progress update occurred within the expected window.
3248 if [ $elapsed -lt $((interval - 1)) ]; then
3249 error "Expected progress update after at least $interval seconds"
3255 run_test 60 "Changing progress update interval from default"
3258 # test needs a new running copytool
3260 copytool_monitor_setup
3261 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3263 # Just start and stop the copytool to generate events.
3266 # Wait for the copytool to register.
3267 wait_update --verbose $(facet_active_host mds1) \
3268 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3270 error "copytool failed to register with MDT0000"
3274 local REGISTER_EVENT
3275 local UNREGISTER_EVENT
3276 while read event; do
3277 local parsed=$(parse_json_event "$event")
3278 if [ -z "$parsed" ]; then
3279 error "Copytool sent malformed event: $event"
3283 if [ $event_type == "REGISTER" ]; then
3284 REGISTER_EVENT=$event
3285 elif [ $event_type == "UNREGISTER" ]; then
3286 UNREGISTER_EVENT=$event
3288 done < <(echo $"$(get_copytool_event_log)")
3290 if [ -z "$REGISTER_EVENT" ]; then
3291 error "Copytool failed to send register event to FIFO"
3294 if [ -z "$UNREGISTER_EVENT" ]; then
3295 error "Copytool failed to send unregister event to FIFO"
3298 copytool_monitor_cleanup
3299 echo "Register/Unregister events look OK."
3301 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3304 # Bump progress interval for livelier events.
3307 # test needs a new running copytool
3309 copytool_monitor_setup
3310 HSMTOOL_UPDATE_INTERVAL=$interval \
3311 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3314 local f=$DIR/$tdir/$tfile
3316 fid=$(make_large_for_progress $f)
3317 [ $? != 0 ] && skip "not enough free space" && return
3319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3320 error "could not archive file"
3321 wait_request_state $fid ARCHIVE SUCCEED
3323 local expected_fields="event_time data_fid source_fid"
3324 expected_fields+=" total_bytes current_bytes"
3328 while read event; do
3329 # Make sure we're not getting anything from previous events.
3330 for field in $expected_fields; do
3334 local parsed=$(parse_json_event "$event")
3335 if [ -z "$parsed" ]; then
3336 error "Copytool sent malformed event: $event"
3340 if [ $event_type == "ARCHIVE_START" ]; then
3343 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3346 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3350 # Do some simple checking of the progress update events.
3351 for expected_field in $expected_fields; do
3352 if [ -z ${!expected_field+x} ]; then
3353 error "Missing $expected_field field in event"
3357 if [ $total_bytes -eq 0 ]; then
3358 error "Expected total_bytes to be > 0"
3361 # These should be identical throughout an archive
3363 if [ $source_fid != $data_fid ]; then
3364 error "Expected source_fid to equal data_fid"
3366 done < <(echo $"$(get_copytool_event_log)")
3368 if [ -z "$START_EVENT" ]; then
3369 error "Copytool failed to send archive start event to FIFO"
3372 if [ -z "$FINISH_EVENT" ]; then
3373 error "Copytool failed to send archive finish event to FIFO"
3376 echo "Archive events look OK."
3380 copytool_monitor_cleanup
3382 run_test 71 "Copytool logs JSON archive events to FIFO"
3385 # Bump progress interval for livelier events.
3388 # test needs a new running copytool
3390 copytool_monitor_setup
3391 HSMTOOL_UPDATE_INTERVAL=$interval \
3392 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3393 local test_file=$HSMTOOL_MONITOR_DIR/file
3395 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3397 do_facet $SINGLEAGT "$cmd" ||
3398 error "cannot create $test_file on $SINGLEAGT"
3399 copy2archive $test_file $tdir/$tfile
3402 local f=$DIR/$tdir/$tfile
3403 import_file $tdir/$tfile $f
3404 f=$DIR2/$tdir/$tfile
3405 echo "Verifying released state: "
3406 check_hsm_flags $f "0x0000000d"
3408 local fid=$(path2fid $f)
3410 wait_request_state $fid RESTORE SUCCEED
3412 local expected_fields="event_time data_fid source_fid"
3413 expected_fields+=" total_bytes current_bytes"
3417 while read event; do
3418 # Make sure we're not getting anything from previous events.
3419 for field in $expected_fields; do
3423 local parsed=$(parse_json_event "$event")
3424 if [ -z "$parsed" ]; then
3425 error "Copytool sent malformed event: $event"
3429 if [ $event_type == "RESTORE_START" ]; then
3431 if [ $source_fid != $data_fid ]; then
3432 error "source_fid should == data_fid at start"
3435 elif [ $event_type == "RESTORE_FINISH" ]; then
3437 if [ $source_fid != $data_fid ]; then
3438 error "source_fid should == data_fid at finish"
3441 elif [ $event_type != "RESTORE_RUNNING" ]; then
3445 # Do some simple checking of the progress update events.
3446 for expected_field in $expected_fields; do
3447 if [ -z ${!expected_field+x} ]; then
3448 error "Missing $expected_field field in event"
3452 if [ $total_bytes -eq 0 ]; then
3453 error "Expected total_bytes to be > 0"
3456 # When a restore starts out, the data fid is the same as the
3457 # source fid. After the restore has gotten going, we learn
3458 # the new data fid. Once the restore has finished, the source
3459 # fid is set to the new data fid.
3461 # We test this because some monitoring software may depend on
3462 # this behavior. If it changes, then the consumers of these
3463 # events may need to be modified.
3464 if [ $source_fid == $data_fid ]; then
3465 error "source_fid should != data_fid during restore"
3467 done < <(echo $"$(get_copytool_event_log)")
3469 if [ -z "$START_EVENT" ]; then
3470 error "Copytool failed to send restore start event to FIFO"
3473 if [ -z "$FINISH_EVENT" ]; then
3474 error "Copytool failed to send restore finish event to FIFO"
3477 echo "Restore events look OK."
3481 copytool_monitor_cleanup
3485 run_test 72 "Copytool logs JSON restore events to FIFO"
3488 file_count=51 # Max number of files constrained by LNET message size
3489 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3490 local f=$DIR/$tdir/$tfile
3491 local FILELIST=/tmp/filelist.txt
3495 for i in $(seq 1 $file_count); do
3496 fid=$(copy_file /etc/hosts $f.$i)
3497 echo $f.$i >> $FILELIST
3499 # force copytool to use a local/temp archive dir to ensure best
3500 # performance vs remote/NFS mounts used in auto-tests
3501 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3504 local dai=$(get_hsm_param default_archive_id)
3505 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3507 # to be sure wait_all_done will not be mislead by previous tests
3509 wait_for_grace_delay
3510 $LFS hsm_archive --filelist $FILELIST ||
3511 error "cannot archive a file list"
3513 $LFS hsm_release --filelist $FILELIST ||
3514 error "cannot release a file list"
3515 $LFS hsm_restore --filelist $FILELIST ||
3516 error "cannot restore a file list"
3520 run_test 90 "Archive/restore a file list"
3522 double_verify_reset_hsm_param() {
3524 echo "Testing $HSM_PARAM.$p"
3525 local val=$(get_hsm_param $p)
3527 local val2=$(($val * 2))
3528 set_hsm_param $p $val2
3529 val=$(get_hsm_param $p)
3530 [[ $val == $val2 ]] ||
3531 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3532 echo "Set $p to 0 must failed"
3536 set_hsm_param $p $save
3538 if [[ $rc == 0 ]]; then
3539 error "we must not be able to set $HSM_PARAM.$p to 0"
3544 double_verify_reset_hsm_param loop_period
3545 double_verify_reset_hsm_param grace_delay
3546 double_verify_reset_hsm_param active_request_timeout
3547 double_verify_reset_hsm_param max_requests
3548 double_verify_reset_hsm_param default_archive_id
3550 run_test 100 "Set coordinator /proc tunables"
3557 run_test 102 "Verify coordinator control"
3560 # test needs a running copytool
3567 for i in $(seq 1 20); do
3568 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3574 echo "Current requests"
3575 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3576 $HSM_PARAM.actions |\
3577 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3579 [[ -z "$res" ]] || error "Some request have not been canceled"
3583 run_test 103 "Purge all requests"
3588 # test needs a running copytool
3592 local f=$DIR/$tdir/$tfile
3594 fid=$(make_large_for_progress $f)
3595 [ $? != 0 ] && skip "not enough free space" && return
3597 # if cdt is on, it can serve too quickly the request
3599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3600 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3601 $HSM_PARAM.actions |\
3602 grep $fid | cut -f16 -d=")
3605 [[ "$data1" == "$DATAHEX" ]] ||
3606 error "Data field in records is ($data1) and not ($DATAHEX)"
3610 run_test 104 "Copy tool data field"
3617 for i in $(seq -w 1 10); do
3618 cp /etc/passwd $DIR/$tdir/$i
3619 $LFS hsm_archive $DIR/$tdir/$i
3621 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3622 $HSM_PARAM.actions |\
3623 grep WAITING | wc -l")
3626 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3627 $HSM_PARAM.actions |\
3628 grep WAITING | wc -l")
3631 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3632 error "Requests count after shutdown $reqcnt2 != "\
3633 "before shutdown $reqcnt1"
3635 run_test 105 "Restart of coordinator"
3638 # test needs a running copytool
3641 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3643 check_agent_registered $uuid
3645 search_copytools || error "No copytool found"
3648 check_agent_unregistered $uuid
3651 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3652 check_agent_registered $uuid
3656 run_test 106 "Copytool register/unregister"
3659 # test needs a running copytool
3661 # create and archive file
3663 local f1=$DIR/$tdir/$tfile
3664 local fid=$(copy_file /etc/passwd $f1)
3665 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3666 wait_request_state $fid ARCHIVE SUCCEED
3667 # shutdown and restart MDS
3669 # check the copytool still gets messages from MDT
3670 local f2=$DIR/$tdir/2
3671 local fid=$(copy_file /etc/passwd $f2)
3672 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3673 # main check of this sanity: this request MUST succeed
3674 wait_request_state $fid ARCHIVE SUCCEED
3677 run_test 107 "Copytool re-register after MDS restart"
3679 policy_set_and_test()
3683 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3684 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3685 [[ "$policy" == "$target" ]] ||
3686 error "Wrong policy after '$change': '$policy' != '$target'"
3690 # to force default policy setting if error
3691 CDT_POLICY_HAD_CHANGED=true
3693 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3694 local default="NonBlockingRestore [NoRetryAction]"
3695 [[ "$policy" == "$default" ]] ||
3696 error "default policy has changed,"\
3697 " '$policy' != '$default' update the test"
3698 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3699 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3700 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3701 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3702 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3703 # useless bacause we know but safer for futur changes to use real value
3704 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3705 echo "Next set_param must failed"
3706 policy_set_and_test "wrong" "$policy"
3709 echo "Back to default policy"
3710 cdt_set_sanity_policy
3712 run_test 109 "Policy display/change"
3715 # test needs a running copytool
3720 copy2archive /etc/passwd $tdir/$tfile
3722 local f=$DIR/$tdir/$tfile
3723 import_file $tdir/$tfile $f
3724 local fid=$(path2fid $f)
3726 cdt_set_non_blocking_restore
3731 wait_request_state $fid RESTORE SUCCEED
3732 cdt_clear_non_blocking_restore
3736 error "md5sum returns $st != 1, "\
3737 "should also perror ENODATA (No data available)"
3741 run_test 110a "Non blocking restore policy (import case)"
3744 # test needs a running copytool
3748 local f=$DIR/$tdir/$tfile
3749 local fid=$(copy_file /etc/passwd $f)
3750 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3751 wait_request_state $fid ARCHIVE SUCCEED
3754 cdt_set_non_blocking_restore
3759 wait_request_state $fid RESTORE SUCCEED
3760 cdt_clear_non_blocking_restore
3764 error "md5sum returns $st != 1, "\
3765 "should also perror ENODATA (No data available)"
3769 run_test 110b "Non blocking restore policy (release case)"
3772 # test needs a running copytool
3776 copy2archive /etc/passwd $tdir/$tfile
3778 local f=$DIR/$tdir/$tfile
3780 import_file $tdir/$tfile $f
3781 local fid=$(path2fid $f)
3785 copytool_remove_backend $fid
3788 wait_request_state $fid RESTORE FAILED
3795 [[ $st == 0 ]] || error "Restore does not failed"
3799 run_test 111a "No retry policy (import case), restore will error"\
3800 " (No such file or directory)"
3803 # test needs a running copytool
3807 local f=$DIR/$tdir/$tfile
3808 local fid=$(copy_file /etc/passwd $f)
3810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3811 wait_request_state $fid ARCHIVE SUCCEED
3814 copytool_remove_backend $fid
3817 wait_request_state $fid RESTORE FAILED
3824 [[ $st == 0 ]] || error "Restore does not failed"
3828 run_test 111b "No retry policy (release case), restore will error"\
3829 " (No such file or directory)"
3832 # test needs a running copytool
3836 local f=$DIR/$tdir/$tfile
3837 local fid=$(copy_file /etc/passwd $f)
3839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3840 local l=$($LFS hsm_action $f)
3842 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3846 wait_request_state $fid ARCHIVE SUCCEED
3849 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3853 run_test 112 "State of recorded request"
3856 # test needs a running copytool
3860 local f=$DIR/$tdir/$tfile
3862 fid=$(make_large_for_cancel $f)
3863 [ $? != 0 ] && skip "not enough free space" && return
3865 # test with cdt on is made in test_221
3867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3868 # wait archive to register at CDT
3869 wait_request_state $fid ARCHIVE WAITING
3872 wait_request_state $fid ARCHIVE CANCELED
3873 wait_request_state $fid CANCEL SUCCEED
3877 run_test 200 "Register/Cancel archive"
3880 # test needs a running copytool
3884 local f=$DIR/$tdir/$tfile
3885 make_archive $tdir/$tfile
3886 import_file $tdir/$tfile $f
3887 local fid=$(path2fid $f)
3889 # test with cdt on is made in test_222
3892 # wait restore to register at CDT
3893 wait_request_state $fid RESTORE WAITING
3896 wait_request_state $fid RESTORE CANCELED
3897 wait_request_state $fid CANCEL SUCCEED
3901 run_test 201 "Register/Cancel restore"
3904 # test needs a running copytool
3908 local f=$DIR/$tdir/$tfile
3910 fid=$(make_large_for_progress $f)
3911 [ $? != 0 ] && skip "not enough free space" && return
3913 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3914 wait_request_state $fid ARCHIVE SUCCEED
3918 # wait remove to register at CDT
3919 wait_request_state $fid REMOVE WAITING
3922 wait_request_state $fid REMOVE CANCELED
3926 run_test 202 "Register/Cancel remove"
3929 # test needs a running copytool
3934 local f=$DIR/$tdir/$tfile
3935 local fid=$(copy_file /etc/passwd $f)
3939 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3940 wait_request_state $fid ARCHIVE SUCCEED
3942 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3946 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3950 run_test 220 "Changelog for archive"
3953 # test needs a running copytool
3958 local f=$DIR/$tdir/$tfile
3960 fid=$(make_large_for_cancel $f)
3961 [ $? != 0 ] && skip "not enough free space" && return
3965 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3966 wait_request_state $fid ARCHIVE STARTED
3968 wait_request_state $fid ARCHIVE CANCELED
3969 wait_request_state $fid CANCEL SUCCEED
3971 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3974 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3978 run_test 221 "Changelog for archive canceled"
3981 # test needs a running copytool
3985 copy2archive /etc/passwd $tdir/$tfile
3987 local f=$DIR/$tdir/$tfile
3988 import_file $tdir/$tfile $f
3989 local fid=$(path2fid $f)
3994 wait_request_state $fid RESTORE SUCCEED
3996 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3999 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4003 run_test 222a "Changelog for explicit restore"
4006 # test needs a running copytool
4010 local f=$DIR/$tdir/$tfile
4011 local fid=$(copy_file /etc/passwd $f)
4014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4015 wait_request_state $fid ARCHIVE SUCCEED
4020 wait_request_state $fid RESTORE SUCCEED
4022 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4025 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4029 run_test 222b "Changelog for implicit restore"
4032 # test needs a running copytool
4037 local f=$DIR/$tdir/$tfile
4038 make_archive $tdir/$tfile
4042 import_file $tdir/$tfile $f
4043 local fid=$(path2fid $f)
4046 wait_request_state $fid RESTORE STARTED
4048 wait_request_state $fid RESTORE CANCELED
4049 wait_request_state $fid CANCEL SUCCEED
4051 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4054 [[ $flags == $target ]] ||
4055 error "Changelog flag is $flags not $target"
4059 run_test 223a "Changelog for restore canceled (import case)"
4062 # test needs a running copytool
4067 local f=$DIR/$tdir/$tfile
4069 fid=$(make_large_for_progress $f)
4070 [ $? != 0 ] && skip "not enough free space" && return
4073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4074 wait_request_state $fid ARCHIVE SUCCEED
4077 wait_request_state $fid RESTORE STARTED
4079 wait_request_state $fid RESTORE CANCELED
4080 wait_request_state $fid CANCEL SUCCEED
4082 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4085 [[ $flags == $target ]] ||
4086 error "Changelog flag is $flags not $target"
4090 run_test 223b "Changelog for restore canceled (release case)"
4093 # test needs a running copytool
4098 local f=$DIR/$tdir/$tfile
4099 local fid=$(copy_file /etc/passwd $f)
4102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4103 wait_request_state $fid ARCHIVE SUCCEED
4106 wait_request_state $fid REMOVE SUCCEED
4108 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4111 [[ $flags == $target ]] ||
4112 error "Changelog flag is $flags not $target"
4116 run_test 224 "Changelog for remove"
4119 # test needs a running copytool
4122 # test is not usable because remove request is too fast
4123 # so it is always finished before cancel can be done ...
4124 echo "Test disabled"
4129 local f=$DIR/$tdir/$tfile
4131 fid=$(make_large_for_progress $f)
4132 [ $? != 0 ] && skip "not enough free space" && return
4135 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4136 wait_request_state $fid ARCHIVE SUCCEED
4138 # if cdt is on, it can serve too quickly the request
4143 wait_request_state $fid REMOVE CANCELED
4144 wait_request_state $fid CANCEL SUCCEED
4146 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4147 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4148 tail -n 1 | awk '{print $5}')
4151 [[ $flags == $target ]] ||
4152 error "Changelog flag is $flags not $target"
4156 run_test 225 "Changelog for remove canceled"
4159 # test needs a running copytool
4164 local f1=$DIR/$tdir/$tfile-1
4165 local f2=$DIR/$tdir/$tfile-2
4166 local f3=$DIR/$tdir/$tfile-3
4167 local fid1=$(copy_file /etc/passwd $f1)
4168 local fid2=$(copy_file /etc/passwd $f2)
4169 copy_file /etc/passwd $f3
4172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4173 wait_request_state $fid1 ARCHIVE SUCCEED
4175 $LFS hsm_archive $f2
4176 wait_request_state $fid2 ARCHIVE SUCCEED
4178 rm $f1 || error "rm $f1 failed"
4180 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4183 [[ $flags == $target ]] ||
4184 error "Changelog flag is $flags not $target"
4186 mv $f3 $f2 || error "mv $f3 $f2 failed"
4188 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4191 [[ $flags == $target ]] ||
4192 error "Changelog flag is $flags not $target"
4196 run_test 226 "changelog for last rm/mv with exiting archive"
4198 check_flags_changes() {
4206 $LFS hsm_set --$hsm_flag $f ||
4207 error "Cannot set $hsm_flag on $f"
4208 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4209 local seen=${#flags[*]}
4211 [[ $seen == $cnt ]] ||
4212 error "set $hsm_flag: Changelog events $seen != $cnt"
4213 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4214 error "set $hsm_flag: Changelog flags are "\
4215 "${flags[$((cnt - 1))]} not $target"
4217 $LFS hsm_clear --$hsm_flag $f ||
4218 error "Cannot clear $hsm_flag on $f"
4219 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4222 [[ $cnt == $seen ]] ||
4223 error "clear $hsm_flag: Changelog events $seen != $cnt"
4225 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4226 error "clear $hsm_flag: Changelog flag is "\
4227 "${flags[$((cnt - 1))]} not $target"
4231 # test needs a running copytool
4238 for i in norelease noarchive exists archived
4240 local f=$DIR/$tdir/$tfile-$i
4241 local fid=$(copy_file /etc/passwd $f)
4242 check_flags_changes $f $fid $i 0 1
4245 f=$DIR/$tdir/$tfile---lost
4246 fid=$(copy_file /etc/passwd $f)
4247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4248 wait_request_state $fid ARCHIVE SUCCEED
4249 check_flags_changes $f $fid lost 3 1
4253 run_test 227 "changelog when explicit setting of HSM flags"
4256 # test needs a running copytool
4259 local fid=$(make_small_sync $DIR/$tfile)
4260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4261 wait_request_state $fid ARCHIVE SUCCEED
4263 $LFS hsm_release $DIR/$tfile
4264 check_hsm_flags $DIR/$tfile "0x0000000d"
4266 filefrag $DIR/$tfile | grep " 1 extent found" ||
4267 error "filefrag on released file must return only one extent"
4269 # only newer versions of cp detect sparse files by stat/FIEMAP
4271 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4272 error "copying $DIR/$tfile"
4273 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4275 $LFS hsm_release $DIR/$tfile
4276 check_hsm_flags $DIR/$tfile "0x0000000d"
4278 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4280 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4282 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4283 error "comparing untarred $DIR/$tfile"
4285 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4286 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4289 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4292 # test needs a running copytool
4296 local maxrequest=$(get_hsm_param max_requests)
4297 local rqcnt=$(($maxrequest * 3))
4301 for i in $(seq -w 1 $rqcnt); do
4303 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4305 # we do it in 2 steps, so all requests arrive at the same time
4306 for i in $(seq -w 1 $rqcnt); do
4307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4312 while [[ $cnt != 0 || $wt != 0 ]]; do
4314 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4315 $HSM_PARAM.actions |\
4316 grep STARTED | grep -v CANCEL | wc -l")
4317 [[ $cnt -le $maxrequest ]] ||
4318 error "$cnt > $maxrequest too many started requests"
4319 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4320 $HSM_PARAM.actions |\
4321 grep WAITING | wc -l")
4322 echo "max=$maxrequest started=$cnt waiting=$wt"
4327 run_test 250 "Coordinator max request"
4330 # test needs a running copytool
4334 local f=$DIR/$tdir/$tfile
4336 fid=$(make_large_for_cancel $f)
4337 [ $? != 0 ] && skip "not enough free space" && return
4340 # to have a short test
4341 local old_to=$(get_hsm_param active_request_timeout)
4342 set_hsm_param active_request_timeout 4
4343 # to be sure the cdt will wake up frequently so
4344 # it will be able to cancel the "old" request
4345 local old_loop=$(get_hsm_param loop_period)
4346 set_hsm_param loop_period 2
4349 # clear locks to avoid extra delay caused by flush/cancel
4350 # and thus prevent early copytool death to timeout.
4351 cancel_lru_locks osc
4353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4354 wait_request_state $fid ARCHIVE STARTED
4356 wait_request_state $fid ARCHIVE CANCELED
4358 set_hsm_param active_request_timeout $old_to
4359 set_hsm_param loop_period $old_loop
4363 run_test 251 "Coordinator request timeout"
4366 # the only way to test ondisk conf is to restart MDS ...
4367 echo "Stop coordinator and remove coordinator state at mount"
4370 # clean on disk conf set by default
4371 cdt_clear_mount_state
4372 cdt_check_state stopped
4374 # check cdt still off after umount/remount
4376 cdt_check_state stopped
4378 echo "Set coordinator start at mount, and start coordinator"
4379 cdt_set_mount_state enabled
4382 cdt_check_state enabled
4384 # check cdt still on after umount/remount
4386 cdt_check_state enabled
4388 # we are back to original state (cdt started at mount)
4390 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4393 local ai=$(get_hsm_param default_archive_id)
4394 local new=$((ai + 1))
4396 set_hsm_param default_archive_id $new -P
4398 local res=$(get_hsm_param default_archive_id)
4401 set_hsm_param default_archive_id "" "-P -d"
4403 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4405 run_test 301 "HSM tunnable are persistent"
4408 local ai=$(get_hsm_param default_archive_id)
4409 local new=$((ai + 1))
4414 set_hsm_param default_archive_id $new -P
4417 for mdtno in $(seq 1 $MDSCOUNT); do
4422 cdt_check_state enabled
4424 local res=$(get_hsm_param default_archive_id)
4427 set_hsm_param default_archive_id "" "-P -d"
4429 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4431 run_test 302 "HSM tunnable are persistent when CDT is off"
4434 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4440 local dir_mdt0=$DIR/$tdir/mdt0
4441 local dir_mdt1=$DIR/$tdir/mdt1
4443 # create 1 dir per MDT
4444 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4445 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4447 # create 1 file in each MDT
4448 local fid1=$(make_small $dir_mdt0/$tfile)
4449 local fid2=$(make_small $dir_mdt1/$tfile)
4451 # check that hsm request on mdt0 is sent to the right MDS
4452 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4453 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4454 echo "archive successful on mdt0"
4456 # check that hsm request on mdt1 is sent to the right MDS
4457 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4458 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4459 echo "archive successful on mdt1"
4462 # clean test files and directories
4463 rm -rf $dir_mdt0 $dir_mdt1
4465 run_test 400 "Single request is sent to the right MDT"
4468 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4474 local dir_mdt0=$DIR/$tdir/mdt0
4475 local dir_mdt1=$DIR/$tdir/mdt1
4477 # create 1 dir per MDT
4478 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4479 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4481 # create 1 file in each MDT
4482 local fid1=$(make_small $dir_mdt0/$tfile)
4483 local fid2=$(make_small $dir_mdt1/$tfile)
4485 # check that compound requests are shunt to the rights MDTs
4486 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4487 error "lfs hsm_archive"
4488 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4489 echo "archive successful on mdt0"
4490 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4491 echo "archive successful on mdt1"
4494 # clean test files and directories
4495 rm -rf $dir_mdt0 $dir_mdt1
4497 run_test 401 "Compound requests split and sent to their respective MDTs"
4499 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4504 local node=$(facet_active_host $facet)
4506 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4507 awk '{print $4}'); do
4508 echo "$3 $mdc on $node"
4509 do_facet $facet "$LCTL --device $mdc $state" || return 1
4514 # make sure there is no running copytool
4517 # deactivate all mdc on agent1
4518 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4520 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4522 check_agent_unregistered "uuid" # match any agent
4524 # no expected running copytool
4525 search_copytools $agent && error "Copytool start should have failed"
4528 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4530 run_test 402 "Copytool start fails if all MDTs are inactive"
4533 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4535 # make sure there is no running copytool
4538 local agent=$(facet_active_host $SINGLEAGT)
4540 # deactivate all mdc for MDT0001
4541 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4544 local uuid=$(get_agent_uuid $agent)
4545 # check the agent is registered on MDT0000, and not on MDT0001
4546 check_agent_registered_by_mdt $uuid 0
4547 check_agent_unregistered_by_mdt $uuid 1
4549 # check running copytool process
4550 search_copytools $agent || error "No running copytools on $agent"
4552 # reactivate all mdc for MDT0001
4553 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4555 # make sure the copytool is now registered to all MDTs
4556 check_agent_registered $uuid
4560 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4563 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4567 # create files on both MDT0000 and MDT0001
4570 local dir_mdt0=$DIR/$tdir/mdt0
4571 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4573 # create 1 file on mdt0
4574 local fid1=$(make_small $dir_mdt0/$tfile)
4576 # deactivate all mdc for MDT0001
4577 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4579 # send an HSM request for files in MDT0000
4580 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4582 # check for completion of files in MDT0000
4583 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4584 echo "archive successful on mdt0"
4586 # reactivate all mdc for MDT0001
4587 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4590 # clean test files and directories
4593 run_test 404 "Inactive MDT does not block requests for active MDTs"
4596 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4602 local striped_dir=$DIR/$tdir/striped_dir
4604 # create striped dir on all of MDTs
4605 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4607 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4608 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4609 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4610 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4612 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4613 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4614 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4615 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4617 # check that compound requests are shunt to the rights MDTs
4618 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4619 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4620 error "lfs hsm_archive"
4622 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4623 echo "archive successful on $fid1"
4624 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4625 echo "archive successful on $fid2"
4626 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4627 echo "archive successful on $fid3"
4628 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4629 echo "archive successful on $fid4"
4631 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4632 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4633 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4634 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4636 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4637 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4638 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4639 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4643 run_test 405 "archive and release under striped directory"
4646 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4648 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4649 skip "need MDS version at least 2.7.64" && return 0
4656 fid=$(make_small $DIR/$tdir/$tfile)
4659 $LFS hsm_archive $DIR/$tdir/$tfile
4660 wait_request_state "$fid" ARCHIVE SUCCEED
4661 $LFS hsm_release $DIR/$tdir/$tfile
4663 # Should migrate $tdir but not $tfile.
4664 $LFS mv -M1 $DIR/$tdir &&
4665 error "migrating HSM an archived file should fail"
4667 $LFS hsm_restore $DIR/$tdir/$tfile
4668 wait_request_state "$fid" RESTORE SUCCEED
4670 $LFS hsm_remove $DIR/$tdir/$tfile
4671 wait_request_state "$fid" REMOVE SUCCEED
4673 cat $DIR/$tdir/$tfile > /dev/null ||
4674 error "cannot read $DIR/$tdir/$tfile"
4676 $LFS mv -M1 $DIR/$tdir ||
4677 error "cannot complete migration after HSM remove"
4679 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4680 if ((mdt_index != 1)); then
4681 error "expected MDT index 1, got $mdt_index"
4684 # Refresh fid after migration.
4685 fid=$(path2fid $DIR/$tdir/$tfile)
4688 $LFS hsm_archive $DIR/$tdir/$tfile
4689 wait_request_state "$fid" ARCHIVE SUCCEED 1
4691 lctl set_param debug=+trace
4692 $LFS hsm_release $DIR/$tdir/$tfile ||
4693 error "cannot release $DIR/$tdir/$tfile"
4695 $LFS hsm_restore $DIR/$tdir/$tfile
4696 wait_request_state "$fid" RESTORE SUCCEED 1
4698 cat $DIR/$tdir/$tfile > /dev/null ||
4699 error "cannot read $DIR/$tdir/$tfile"
4703 run_test 406 "attempting to migrate HSM archived files is safe"
4707 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4708 skip "HSM migrate is not supported" && return
4710 # Stop the existing copytool
4713 test_mkdir -p $DIR/$tdir
4714 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4716 run_test 500 "various LLAPI HSM tests"
4721 check_and_cleanup_lustre