3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
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 $HSM_ARCHIVE_PURGE; then
262 echo "Purging archive on $agent"
263 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
266 echo "Starting copytool $facet on $agent"
267 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
268 error "mkdir '$hsm_root/$HSMTMP' failed"
269 # bandwidth is limited to 1MB/s so the copy time is known and
270 # independent of hardware
271 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
272 cmd+=" --hsm-root $hsm_root/$HSMTMP"
273 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
274 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
275 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
276 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
277 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
278 cmd+=" --bandwidth 1 $lustre_mntpnt"
280 # Redirect the standard output and error to a log file which
281 # can be uploaded to Maloo.
282 local prefix=$TESTLOG_PREFIX
283 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
284 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
286 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
287 if [[ $? != 0 ]]; then
288 [[ $HSMTOOL_NOERROR == true ]] ||
289 error "start copytool $facet on $agent failed"
290 echo "start copytool $facet on $agent failed"
296 get_copytool_event_log() {
297 local facet=${1:-$SINGLEAGT}
298 local agent=$(facet_active_host $facet)
300 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
301 error "Can't get event log: No monitor directory!"
303 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
304 error "Could not collect event log from $agent"
309 local agt_facet=$SINGLEAGT
310 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
311 local hsm_root=$(copytool_device $agt_facet)
313 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
320 kill_copytools $agt_hosts
321 wait_copytools $agt_hosts || error "copytools failed to stop"
323 # Clean all CDTs orphans requests from previous tests that
324 # would otherwise need to timeout to clear.
325 for ((i = 0; i < MDSCOUNT; i++)); do
327 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
328 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
330 # Skip already stopping or stopped CDTs.
331 [[ "${state[$i]}" =~ ^stop ]] && continue
333 do_facet $facet "$LCTL set_param $param=shutdown"
336 for ((i = 0; i < MDSCOUNT; i++)); do
337 # Only check and restore CDTs that we stopped in the first loop.
338 [[ "${state[$i]}" =~ ^stop ]] && continue
341 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
343 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
344 error "$facet CDT state is not stopped"
346 # Restore old CDT state.
347 do_facet $facet "$LCTL set_param $param=${state[$i]}"
350 for ((i = 0; i < MDSCOUNT; i++)); do
351 # Only check CDTs that we stopped in the first loop.
352 [[ "${state[$i]}" =~ ^stop ]] && continue
355 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
357 # Check that the old CDT state was restored.
358 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
359 20 || error "$facet CDT state is not '${state[$i]}'"
362 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
363 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
368 local agents=${1:-$(facet_active_host $SINGLEAGT)}
370 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
371 echo "Copytool is suspended on $agents"
374 copytool_continue() {
375 local agents=${1:-$(facet_active_host $SINGLEAGT)}
377 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
378 echo "Copytool is continued on $agents"
381 copytool_remove_backend() {
383 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
384 echo "Remove from backend: $fid = $be"
385 do_facet $SINGLEAGT rm -f $be
389 do_facet $SINGLEAGT \
390 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
391 --import $1 $2 $MOUNT" ||
392 error "import of $1 to $2 failed"
396 local file=$HSM_ARCHIVE/$1
397 do_facet $SINGLEAGT mkdir -p $(dirname $file)
398 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
399 file_creation_failure dd $file $?
403 local file=$HSM_ARCHIVE/$2
404 do_facet $SINGLEAGT mkdir -p $(dirname $file)
405 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
414 if [[ "$value" != "" ]]; then
417 for mdtno in $(seq 1 $MDSCOUNT); do
418 local idx=$(($mdtno - 1))
419 local facet=mds${mdtno}
420 # if $arg include -P option, run 1 set_param per MDT on the MGS
421 # else, run set_param on each MDT
422 [[ $arg = *"-P"* ]] && facet=mgs
423 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
424 [[ $? != 0 ]] && rc=1
434 for mdtno in $(seq 1 $MDSCOUNT); do
435 local idx=$(($mdtno - 1))
436 wait_result mds${mdtno} \
437 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
439 error "$key state is not '$target' on mds${mdtno}"
446 for mdtno in $(seq 1 $MDSCOUNT); do
447 local idx=$(($mdtno - 1))
448 local cl_user=$(do_facet mds${mdtno} $LCTL \
449 --device ${MDT[$idx]} \
450 changelog_register -n)
452 do_facet mds${mdtno} lctl set_param \
453 mdd.${MDT[$idx]}.changelog_mask="+hsm"
454 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
458 changelog_cleanup() {
460 for mdtno in $(seq 1 $MDSCOUNT); do
461 local idx=$(($mdtno - 1))
462 [[ -z ${CL_USERS[$idx]} ]] && continue
463 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
464 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
465 changelog_deregister ${CL_USERS[$idx]}
470 changelog_get_flags() {
475 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
480 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
488 mdts_set_param "$opt -n" "hsm.$param" "$value"
495 mdts_set_param "" hsm_control "$cmd"
496 mdts_check_param hsm_control "$target" 10
499 cdt_set_sanity_policy() {
500 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
503 mdts_set_param "" hsm.policy "+NRA"
504 mdts_set_param "" hsm.policy "-NBR"
505 CDT_POLICY_HAD_CHANGED=
510 mdts_set_param "" hsm.policy "+NRA"
511 CDT_POLICY_HAD_CHANGED=true
514 cdt_clear_no_retry() {
515 mdts_set_param "" hsm.policy "-NRA"
516 CDT_POLICY_HAD_CHANGED=true
519 cdt_set_non_blocking_restore() {
520 mdts_set_param "" hsm.policy "+NBR"
521 CDT_POLICY_HAD_CHANGED=true
524 cdt_clear_non_blocking_restore() {
525 mdts_set_param "" hsm.policy "-NBR"
526 CDT_POLICY_HAD_CHANGED=true
529 cdt_clear_mount_state() {
530 mdts_set_param "-P -d" hsm_control ""
533 cdt_set_mount_state() {
534 mdts_set_param "-P" hsm_control "$1"
535 # set_param -P is asynchronous operation and could race with set_param.
536 # In such case configs could be retrieved and applied at mgc after
537 # set_param -P completion. Sleep here to avoid race with set_param.
538 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
539 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
540 # and 10 seconds to retrieve config from server.
545 mdts_check_param hsm_control "$1" 20
549 set_test_state disabled disabled
553 set_test_state enabled enabled
557 set_test_state shutdown stopped
561 set_test_state purge enabled
567 cdt_set_sanity_policy
571 local client_count=$1
572 if [[ $CLIENTCOUNT -lt $client_count ]]; then
573 skip "Need $client_count or more clients, have $CLIENTCOUNT"
580 $LFS path2fid $1 | tr -d '[]'
581 return ${PIPESTATUS[0]}
589 if [[ $u == "user" ]]; then
590 st=$($RUNAS $LFS hsm_state $f)
593 st=$($LFS hsm_state $f)
596 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
598 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
602 get_hsm_archive_id() {
605 st=$($LFS hsm_state $f)
606 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
608 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
617 local st=$(get_hsm_flags $f)
618 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
621 check_hsm_flags_user() {
625 local st=$(get_hsm_flags $f user)
626 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
629 file_creation_failure() {
634 df $MOUNT $MOUNT2 >&2
635 error "cannot create $f with $cmd, status=$err"
647 if [[ "$3" != 1 ]]; then
651 cp $1 $f || file_creation_failure cp $f $?
653 path2fid $f || error "cannot get fid on $f"
657 local file2=${1/$DIR/$DIR2}
658 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
659 file_creation_failure dd $file2 $?
661 path2fid $1 || error "cannot get fid on $1"
665 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
666 file_creation_failure dd $1 $?
667 path2fid $1 || error "cannot get fid on $1"
670 cleanup_large_files() {
671 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
673 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
676 check_enough_free_space() {
679 local need=$((nb * unit /1024))
680 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
681 (( $need >= $free )) && return 1
685 make_custom_file_for_progress() {
686 local file2=${1/$DIR/$DIR2}
687 local fsize=${2:-"39"}
688 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
691 [[ $fsize -gt 0 ]] || error "Invalid file size"
692 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
695 check_enough_free_space $fsize $blksz || return $?
696 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
697 file_creation_failure dd $file2 $?
698 path2fid $1 || error "cannot get fid on $1"
704 wait_update --verbose $(facet_active_host $facet) "$@"
707 wait_request_state() {
711 # 4th arg (mdt index) is optional
713 local mds=mds$(($mdtidx + 1))
715 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
716 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
718 wait_result $mds "$cmd" $state 200 ||
719 error "request on $fid is not $state on $mds"
722 get_request_state() {
726 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
727 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
730 get_request_count() {
734 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
735 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
742 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
743 [[ -n $fid ]] && cmd+=" | grep '$fid'"
744 cmd+=" | egrep 'WAITING|STARTED'"
746 wait_result $SINGLEMDS "$cmd" "" $timeout ||
747 error "requests did not complete"
750 wait_for_grace_delay() {
751 local val=$(get_hsm_param grace_delay)
755 wait_for_loop_period() {
756 local val=$(get_hsm_param loop_period)
763 # python2.6 in EL6 includes an internal json module
764 local json_parser='import json; import fileinput;'
765 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
766 json_parser+='json.loads([line for line in '
767 json_parser+='fileinput.input()][0]).items()])'
769 echo $raw_event | python -c "$json_parser"
772 get_agent_by_uuid_mdt() {
775 local mds=mds$(($mdtidx + 1))
776 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
780 check_agent_registered_by_mdt() {
783 local mds=mds$(($mdtidx + 1))
784 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
785 if [[ ! -z "$agent" ]]; then
786 echo "found agent $agent on $mds"
788 error "uuid $uuid not found in agent list on $mds"
792 check_agent_unregistered_by_mdt() {
795 local mds=mds$(($mdtidx + 1))
796 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
797 if [[ -z "$agent" ]]; then
798 echo "uuid not found in agent list on $mds"
800 error "uuid found in agent list on $mds: $agent"
804 check_agent_registered() {
807 for mdsno in $(seq 1 $MDSCOUNT); do
808 check_agent_registered_by_mdt $uuid $((mdsno - 1))
812 check_agent_unregistered() {
815 for mdsno in $(seq 1 $MDSCOUNT); do
816 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
821 local agent=${1:-$(facet_active_host $SINGLEAGT)}
823 # Lustre mount-point is mandatory and last parameter on
825 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
827 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
829 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
835 # populate MDT device array
838 # cleanup from previous bad setup
841 # for recovery tests, coordinator needs to be started at mount
843 # the lustre conf must be without hsm on (like for sanity.sh)
844 echo "Set HSM on and start"
845 cdt_set_mount_state enabled
846 cdt_check_state enabled
848 echo "Set sanity-hsm HSM policy"
849 cdt_set_sanity_policy
851 # finished requests are quickly removed from list
852 set_hsm_param grace_delay 10
858 local f=$DIR/$tdir/$tfile
862 check_hsm_flags_user $f "0x00000000"
864 $RUNAS $LFS hsm_set --norelease $f ||
865 error "user could not change hsm flags"
866 check_hsm_flags_user $f "0x00000010"
868 $RUNAS $LFS hsm_clear --norelease $f ||
869 error "user could not clear hsm flags"
870 check_hsm_flags_user $f "0x00000000"
872 # User could not change those flags...
873 $RUNAS $LFS hsm_set --exists $f &&
874 error "user should not set this flag"
875 check_hsm_flags_user $f "0x00000000"
878 $LFS hsm_set --exists $f ||
879 error "root could not change hsm flags"
880 check_hsm_flags_user $f "0x00000001"
882 $LFS hsm_clear --exists $f ||
883 error "root could not clear hsm state"
884 check_hsm_flags_user $f "0x00000000"
887 run_test 1 "lfs hsm flags root/non-root access"
891 local f=$DIR/$tdir/$tfile
892 local fid=$(make_small $f)
896 $LFS hsm_archive $f || error "could not archive file"
897 wait_request_state $fid ARCHIVE SUCCEED
899 # Release and check states
900 $LFS hsm_release $f || error "could not release file"
901 echo -n "Verifying released state: "
902 check_hsm_flags $f "0x0000000d"
904 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
908 run_test 1a "mmap & cat a HSM released file"
912 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
913 error "failed to set default stripe"
914 local f=$DIR/$tdir/$tfile
917 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
918 error "failed to create file"
919 local fid=$(path2fid $f)
924 $LFS hsm_archive $f || error "could not archive file"
925 wait_request_state $fid ARCHIVE SUCCEED
928 $LFS hsm_release $f || error "could not release file"
929 echo "verify released state: "
930 check_hsm_flags $f "0x0000000d" && echo "pass"
933 $LFS hsm_restore $f || error "could not restore file"
934 wait_request_state $fid RESTORE SUCCEED
935 echo "verify restored state: "
936 check_hsm_flags $f "0x00000009" && echo "pass"
940 run_test 1b "Archive, Release & Restore composite file"
944 local f=$DIR/$tdir/$tfile
946 # New files are not dirty
947 check_hsm_flags $f "0x00000000"
949 # For test, we simulate an archived file.
950 $LFS hsm_set --exists $f || error "user could not change hsm flags"
951 check_hsm_flags $f "0x00000001"
953 # chmod do not put the file dirty
954 chmod 600 $f || error "could not chmod test file"
955 check_hsm_flags $f "0x00000001"
957 # chown do not put the file dirty
958 chown $RUNAS_ID $f || error "could not chown test file"
959 check_hsm_flags $f "0x00000001"
961 # truncate put the file dirty
962 $TRUNCATE $f 1 || error "could not truncate test file"
963 check_hsm_flags $f "0x00000003"
965 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
966 check_hsm_flags $f "0x00000001"
968 run_test 2 "Check file dirtyness when doing setattr"
974 # New files are not dirty
976 check_hsm_flags $f "0x00000000"
978 # For test, we simulate an archived file.
979 $LFS hsm_set --exists $f ||
980 error "user could not change hsm flags"
981 check_hsm_flags $f "0x00000001"
983 # Reading a file, does not set dirty
984 cat $f > /dev/null || error "could not read file"
985 check_hsm_flags $f "0x00000001"
987 # Open for write without modifying data, does not set dirty
988 openfile -f O_WRONLY $f || error "could not open test file"
989 check_hsm_flags $f "0x00000001"
991 # Append to a file sets it dirty
992 cp -p /etc/passwd $f.append || error "could not create file"
993 $LFS hsm_set --exists $f.append ||
994 error "user could not change hsm flags"
995 dd if=/etc/passwd of=$f.append bs=1 count=3\
996 conv=notrunc oflag=append status=noxfer ||
997 file_creation_failure dd $f.append $?
998 check_hsm_flags $f.append "0x00000003"
1000 # Modify a file sets it dirty
1001 cp -p /etc/passwd $f.modify || error "could not create file"
1002 $LFS hsm_set --exists $f.modify ||
1003 error "user could not change hsm flags"
1004 dd if=/dev/zero of=$f.modify bs=1 count=3\
1005 conv=notrunc status=noxfer ||
1006 file_creation_failure dd $f.modify $?
1007 check_hsm_flags $f.modify "0x00000003"
1009 # Open O_TRUNC sets dirty
1010 cp -p /etc/passwd $f.trunc || error "could not create file"
1011 $LFS hsm_set --exists $f.trunc ||
1012 error "user could not change hsm flags"
1013 cp /etc/group $f.trunc || error "could not override a file"
1014 check_hsm_flags $f.trunc "0x00000003"
1016 # Mmapped a file sets dirty
1017 cp -p /etc/passwd $f.mmap || error "could not create file"
1018 $LFS hsm_set --exists $f.mmap ||
1019 error "user could not change hsm flags"
1020 multiop $f.mmap OSMWUc || error "could not mmap a file"
1021 check_hsm_flags $f.mmap "0x00000003"
1023 run_test 3 "Check file dirtyness when opening for write"
1027 local f=$DIR/$tdir/$tfile
1028 local fid=$(make_small $f)
1031 local st=$(get_request_state $fid CANCEL)
1032 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1034 run_test 4 "Useless cancel must not be registered"
1037 # test needs a running copytool
1041 local f=$DIR/$tdir/$tfile
1042 local fid=$(copy_file /etc/passwd $f)
1044 wait_request_state $fid ARCHIVE SUCCEED
1046 check_hsm_flags $f "0x00000009"
1050 run_test 8 "Test default archive number"
1053 # we do not use the default one to be sure
1054 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1056 copytool_setup $SINGLEAGT $MOUNT $new_an
1058 # give time for CT to register with MDTs
1059 sleep $(($MDSCOUNT*2))
1060 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1061 check_agent_registered $uuid
1064 local f=$DIR/$tdir/$tfile
1065 local fid=$(copy_file /etc/passwd $f)
1066 $LFS hsm_archive --archive $new_an $f
1067 wait_request_state $fid ARCHIVE SUCCEED
1069 check_hsm_flags $f "0x00000009"
1073 run_test 9 "Use of explicit archive number, with dedicated copytool"
1076 needclients 3 || return 0
1082 copytool_cleanup $(comma_list $(agts_nodes))
1084 # start all of the copytools
1085 for n in $(seq $AGTCOUNT); do
1086 copytool_setup agt$n
1089 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1092 for n in $(seq $AGTCOUNT); do
1093 file=$DIR/$tdir/$tfile.$n
1094 fid=$(make_small $file)
1096 $LFS hsm_archive $file || error "could not archive file $file"
1097 wait_request_state $fid ARCHIVE SUCCEED
1098 check_hsm_flags $file "0x00000009"
1102 copytool_cleanup $(comma_list $(agts_nodes))
1104 run_test 9a "Multiple remote agents"
1107 # test needs a running copytool
1110 mkdir -p $DIR/$tdir/d1
1111 local f=$DIR/$tdir/$tfile
1112 local fid=$(copy_file /etc/hosts $f)
1113 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1114 error "hsm_archive failed"
1115 wait_request_state $fid ARCHIVE SUCCEED
1117 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1118 error "fid $fid not in archive $HSM_ARCHIVE"
1119 echo "Verifying content"
1120 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1121 echo "Verifying hsm state "
1122 check_hsm_flags $f "0x00000009"
1124 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1125 local st=$(get_hsm_archive_id $f)
1126 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1127 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1132 run_test 10a "Archive a file"
1135 # test needs a running copytool
1139 local f=$DIR/$tdir/$tfile
1140 local fid=$(copy_file /etc/hosts $f)
1141 $LFS hsm_archive $f || error "archive request failed"
1142 wait_request_state $fid ARCHIVE SUCCEED
1144 $LFS hsm_archive $f || error "archive of non dirty file failed"
1145 local cnt=$(get_request_count $fid ARCHIVE)
1146 [[ "$cnt" == "1" ]] ||
1147 error "archive of non dirty file must not make a request"
1151 run_test 10b "Archive of non dirty file must work without doing request"
1154 # test needs a running copytool
1158 local f=$DIR/$tdir/$tfile
1159 local fid=$(copy_file /etc/hosts $f)
1160 $LFS hsm_set --noarchive $f
1161 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1165 run_test 10c "Check forbidden archive"
1168 # test needs a running copytool
1172 local f=$DIR/$tdir/$tfile
1173 local fid=$(copy_file /etc/hosts $f)
1174 $LFS hsm_archive $f || error "cannot archive $f"
1175 wait_request_state $fid ARCHIVE SUCCEED
1177 local ar=$(get_hsm_archive_id $f)
1178 local dflt=$(get_hsm_param default_archive_id)
1179 [[ $ar == $dflt ]] ||
1180 error "archived file is not on default archive: $ar != $dflt"
1184 run_test 10d "Archive a file on the default archive id"
1188 copy2archive /etc/hosts $tdir/$tfile
1189 local f=$DIR/$tdir/$tfile
1191 import_file $tdir/$tfile $f
1192 echo -n "Verifying released state: "
1193 check_hsm_flags $f "0x0000000d"
1195 local LSZ=$(stat -c "%s" $f)
1196 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1198 echo "Verifying imported size $LSZ=$ASZ"
1199 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1200 echo -n "Verifying released pattern: "
1201 local PTRN=$($GETSTRIPE -L $f)
1203 [[ $PTRN == 80000001 ]] || error "Is not released"
1204 local fid=$(path2fid $f)
1205 echo "Verifying new fid $fid in archive"
1207 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1208 error "fid $fid not in archive $HSM_ARCHIVE"
1210 run_test 11a "Import a file"
1213 # test needs a running copytool
1217 local f=$DIR/$tdir/$tfile
1218 local fid=$(copy_file /etc/hosts $f)
1219 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1220 error "hsm_archive failed"
1221 wait_request_state $fid ARCHIVE SUCCEED
1223 local FILE_HASH=$(md5sum $f)
1228 echo "$FILE_HASH" | md5sum -c
1230 [[ $? -eq 0 ]] || error "Restored file differs"
1234 run_test 11b "Import a deleted file using its FID"
1237 # test needs a running copytool
1241 copy2archive /etc/hosts $tdir/$tfile
1243 local f=$DIR/$tdir/$tfile
1244 import_file $tdir/$tfile $f
1245 local f2=$DIR2/$tdir/$tfile
1246 echo "Verifying released state: "
1247 check_hsm_flags $f2 "0x0000000d"
1249 local fid=$(path2fid $f2)
1250 $LFS hsm_restore $f2
1251 wait_request_state $fid RESTORE SUCCEED
1253 echo "Verifying file state: "
1254 check_hsm_flags $f2 "0x00000009"
1256 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1258 [[ $? -eq 0 ]] || error "Restored file differs"
1262 run_test 12a "Restore an imported file explicitly"
1265 # test needs a running copytool
1269 copy2archive /etc/hosts $tdir/$tfile
1271 local f=$DIR/$tdir/$tfile
1272 import_file $tdir/$tfile $f
1273 echo "Verifying released state: "
1274 check_hsm_flags $f "0x0000000d"
1276 cat $f > /dev/null || error "File read failed"
1278 echo "Verifying file state after restore: "
1279 check_hsm_flags $f "0x00000009"
1281 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1283 [[ $? -eq 0 ]] || error "Restored file differs"
1287 run_test 12b "Restore an imported file implicitly"
1290 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1292 # test needs a running copytool
1296 local f=$DIR/$tdir/$tfile
1297 $LFS setstripe -c 2 $f
1299 fid=$(make_custom_file_for_progress $f 5)
1300 [ $? != 0 ] && skip "not enough free space" && return
1302 local FILE_CRC=$(md5sum $f)
1304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1305 wait_request_state $fid ARCHIVE SUCCEED
1306 $LFS hsm_release $f || error "release $f failed"
1308 echo "$FILE_CRC" | md5sum -c
1310 [[ $? -eq 0 ]] || error "Restored file differs"
1314 run_test 12c "Restore a file with stripe of 2"
1317 # test needs a running copytool
1322 local f=$DIR/$tdir/$tfile
1323 local fid=$(copy_file /etc/hosts $f)
1324 $LFS hsm_restore $f || error "restore of non archived file failed"
1325 local cnt=$(get_request_count $fid RESTORE)
1326 [[ "$cnt" == "0" ]] ||
1327 error "restore non archived must not make a request"
1328 $LFS hsm_archive $f ||
1329 error "archive request failed"
1330 wait_request_state $fid ARCHIVE SUCCEED
1331 $LFS hsm_restore $f ||
1332 error "restore of non released file failed"
1333 local cnt=$(get_request_count $fid RESTORE)
1334 [[ "$cnt" == "0" ]] ||
1335 error "restore a non dirty file must not make a request"
1339 run_test 12d "Restore of a non archived, non released file must work"\
1340 " without doing request"
1343 # test needs a running copytool
1346 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1347 local f=$DIR/$tdir/$tfile
1348 local fid=$(copy_file /etc/hosts $f)
1349 $LFS hsm_archive $f || error "archive request failed"
1350 wait_request_state $fid ARCHIVE SUCCEED
1353 cat /etc/hosts >> $f
1357 $LFS hsm_restore $f && error "restore a dirty file must fail"
1361 run_test 12e "Check forbidden restore"
1364 # test needs a running copytool
1368 local f=$DIR/$tdir/$tfile
1369 local fid=$(copy_file /etc/hosts $f)
1371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1372 wait_request_state $fid ARCHIVE SUCCEED
1373 $LFS hsm_release $f || error "release of $f failed"
1375 wait_request_state $fid RESTORE SUCCEED
1377 echo -n "Verifying file state: "
1378 check_hsm_flags $f "0x00000009"
1380 diff -q /etc/hosts $f
1382 [[ $? -eq 0 ]] || error "Restored file differs"
1386 run_test 12f "Restore a released file explicitly"
1389 # test needs a running copytool
1393 local f=$DIR/$tdir/$tfile
1394 local fid=$(copy_file /etc/hosts $f)
1396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1397 wait_request_state $fid ARCHIVE SUCCEED
1398 $LFS hsm_release $f || error "release of $f failed"
1400 diff -q /etc/hosts $f
1403 # we check we had a restore done
1404 wait_request_state $fid RESTORE SUCCEED
1406 [[ $st -eq 0 ]] || error "Restored file differs"
1410 run_test 12g "Restore a released file implicitly"
1413 needclients 2 || return 0
1415 # test needs a running copytool
1419 local f=$DIR/$tdir/$tfile
1420 local fid=$(copy_file /etc/hosts $f)
1422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1423 wait_request_state $fid ARCHIVE SUCCEED
1424 $LFS hsm_release $f || error "release of $f failed"
1426 do_node $CLIENT2 diff -q /etc/hosts $f
1429 # we check we had a restore done
1430 wait_request_state $fid RESTORE SUCCEED
1432 [[ $st -eq 0 ]] || error "Restored file differs"
1436 run_test 12h "Restore a released file implicitly from a second node"
1439 # test needs a running copytool
1443 local f=$DIR/$tdir/$tfile
1444 local fid=$(copy_file /etc/passwd $f)
1445 $LFS hsm_archive $f || error "archive of $f failed"
1446 wait_request_state $fid ARCHIVE SUCCEED
1448 $LFS hsm_release $f || error "release of $f failed"
1452 [[ $? -eq 0 ]] || error "Restored file differs"
1456 run_test 12m "Archive/release/implicit restore"
1459 # test needs a running copytool
1463 copy2archive /etc/hosts $tdir/$tfile
1465 local f=$DIR/$tdir/$tfile
1466 import_file $tdir/$tfile $f
1468 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1469 error "Restored file differs"
1471 $LFS hsm_release $f || error "release of $f failed"
1475 run_test 12n "Import/implicit restore/release"
1478 # test needs a running copytool
1482 local f=$DIR/$tdir/$tfile
1483 local fid=$(copy_file /etc/hosts $f)
1485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1486 wait_request_state $fid ARCHIVE SUCCEED
1487 $LFS hsm_release $f || error "release of $f failed"
1489 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1490 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1492 # set no retry action mode
1495 diff -q /etc/hosts $f
1498 # we check we had a restore failure
1499 wait_request_state $fid RESTORE FAILED
1501 [[ $st -eq 0 ]] && error "Restore must fail"
1503 # remove no retry action mode
1506 # check file is still released
1507 check_hsm_flags $f "0x0000000d"
1509 # retry w/o failure injection
1510 do_facet $SINGLEMDS lctl set_param fail_loc=0
1512 # to be sure previous RESTORE result is gone
1514 wait_for_grace_delay
1516 diff -q /etc/hosts $f
1519 # we check we had a restore done
1520 wait_request_state $fid RESTORE SUCCEED
1522 [[ $st -eq 0 ]] || error "Restored file differs"
1526 run_test 12o "Layout-swap failure during Restore leaves file released"
1529 # test needs a running copytool
1533 local f=$DIR/$tdir/$tfile
1534 local fid=$(copy_file /etc/hosts $f)
1536 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1537 wait_request_state $fid ARCHIVE SUCCEED
1538 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1539 $LFS hsm_release $f || error "cannot release $f"
1540 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1541 $LFS hsm_release $f || error "cannot release $f"
1542 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1546 run_test 12p "implicit restore of a file on copytool mount point"
1548 cleanup_test_12q() {
1550 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1551 error "cannot umount $MOUNT3 on $SINGLEAGT"
1555 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1556 skip "need MDS version at least 2.7.58" && return 0
1558 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1559 error "cannot mount $MOUNT3 on $SINGLEAGT"
1561 trap cleanup_test_12q EXIT
1563 # test needs a running copytool
1564 copytool_setup $SINGLEAGT $MOUNT3
1567 local f=$DIR/$tdir/$tfile
1568 local f2=$DIR2/$tdir/$tfile
1569 local fid=$(make_small $f)
1570 local orig_size=$(stat -c "%s" $f)
1572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1573 wait_request_state $fid ARCHIVE SUCCEED
1575 $LFS hsm_release $f || error "could not release file"
1576 check_hsm_flags $f "0x0000000d"
1579 wait_copytools || error "copytool failed to stop"
1581 cat $f > /dev/null &
1583 # wait a bit to allow implicit restore request to be handled.
1584 # if not, next stat would also block on layout-lock.
1587 local size=$(stat -c "%s" $f2)
1588 [ $size -eq $orig_size ] ||
1589 error "$f2: wrong size after archive: $size != $orig_size"
1591 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1595 size=$(stat -c "%s" $f)
1596 [ $size -eq $orig_size ] ||
1597 error "$f: wrong size after restore: $size != $orig_size"
1599 size=$(stat -c "%s" $f2)
1600 [ $size -eq $orig_size ] ||
1601 error "$f2: wrong size after restore: $size != $orig_size"
1605 size=$(stat -c "%s" $f)
1607 error "$f: wrong size after overwrite: $size != 0"
1609 size=$(stat -c "%s" $f2)
1611 error "$f2: wrong size after overwrite: $size != 0"
1614 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1615 error "cannot umount $MOUNT3 on $SINGLEAGT"
1617 run_test 12q "file attributes are refreshed after restore"
1620 # test needs a running copytool
1623 local ARC_SUBDIR="import.orig"
1627 # populate directory to be imported
1628 for d in $(seq 1 10); do
1629 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1630 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1631 for f in $(seq 1 10); do
1632 CURR_FILE="$CURR_DIR/$tfile.$f"
1633 # write file-specific data
1634 do_facet $SINGLEAGT \
1635 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1636 "file=$CURR_FILE > $CURR_FILE"
1640 import_file "$ARC_SUBDIR" $DIR/$tdir
1641 # diff lustre content and origin (triggers file restoration)
1642 # there must be 10x10 identical files, and no difference
1643 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1644 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1645 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1646 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1648 [ $cnt_diff -eq 0 ] ||
1649 error "$cnt_diff imported files differ from read data"
1650 [ $cnt_ok -eq 100 ] ||
1651 error "not enough identical files ($cnt_ok != 100)"
1655 run_test 13 "Recursively import and restore a directory"
1658 # test needs a running copytool
1663 local f=$DIR/$tdir/$tfile
1664 local fid=$(make_small $f)
1665 local sum=$(md5sum $f | awk '{print $1}')
1666 $LFS hsm_archive $f || error "could not archive file"
1667 wait_request_state $fid ARCHIVE SUCCEED
1671 # create released file (simulate llapi_hsm_import call)
1673 local fid2=$(path2fid $f)
1674 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1675 $LFS hsm_release $f || error "could not release file"
1677 # rebind the archive to the newly created file
1678 echo "rebind $fid to $fid2"
1680 do_facet $SINGLEAGT \
1681 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1682 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1684 # restore file and compare md5sum
1685 local sum2=$(md5sum $f | awk '{print $1}')
1687 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1691 run_test 14 "Rebind archived file to a new fid"
1694 # test needs a running copytool
1699 local f=$DIR/$tdir/$tfile
1701 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1705 for i in $(seq 1 $count); do
1706 fids[$i]=$(make_small $f.$i)
1707 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1708 $LFS hsm_archive $f.$i || error "could not archive file"
1710 wait_all_done $(($count*60))
1714 for i in $(seq 1 $count); do
1717 local fid2=$(path2fid $f.$i)
1718 # add the rebind operation to the list
1719 echo ${fids[$i]} $fid2 >> $tmpfile
1721 # set it released (simulate llapi_hsm_import call)
1722 $LFS hsm_set --archived --exists $f.$i ||
1723 error "could not force hsm flags"
1724 $LFS hsm_release $f.$i || error "could not release file"
1726 nl=$(wc -l < $tmpfile)
1727 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1729 echo "rebind list of files"
1730 do_facet $SINGLEAGT \
1731 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1732 --rebind $tmpfile $DIR" || error "could not rebind file list"
1734 # restore files and compare md5sum
1735 for i in $(seq 1 $count); do
1736 local sum2=$(md5sum $f.$i | awk '{print $1}')
1737 [[ $sum2 == ${sums[$i]} ]] ||
1738 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1744 run_test 15 "Rebind a list of files"
1747 # test needs a running copytool
1751 # create a known size file so we can verify transfer speed
1754 dd if=/dev/zero of=$ref bs=1M count=20
1757 local f=$DIR/$tdir/$tfile
1758 local fid=$(copy_file $ref $f)
1760 local start=$(date +%s)
1762 wait_request_state $fid ARCHIVE SUCCEED
1763 local end=$(date +%s)
1764 # Add 1 to account for rounding errors between start and end (LU-8155)
1765 local duration=$((end - start + 1))
1767 [[ $duration -ge $((goal - 1)) ]] ||
1768 error "Transfer is too fast $duration < $goal"
1772 run_test 16 "Test CT bandwith control option"
1777 local f=$DIR/$tdir/$tfile
1778 touch $f || error "touch $f failed"
1780 # Could not release a non-archived file
1781 $LFS hsm_release $f && error "release should not succeed"
1783 # For following tests, we must test them with HS_ARCHIVED set
1784 $LFS hsm_set --exists --archived $f || error "could not add flag"
1786 # Could not release a file if no-release is set
1787 $LFS hsm_set --norelease $f || error "could not add flag"
1788 $LFS hsm_release $f && error "release should not succeed"
1789 $LFS hsm_clear --norelease $f || error "could not remove flag"
1791 # Could not release a file if lost
1792 $LFS hsm_set --lost $f || error "could not add flag"
1793 $LFS hsm_release $f && error "release should not succeed"
1794 $LFS hsm_clear --lost $f || error "could not remove flag"
1796 # Could not release a file if dirty
1797 $LFS hsm_set --dirty $f || error "could not add flag"
1798 $LFS hsm_release $f && error "release should not succeed"
1799 $LFS hsm_clear --dirty $f || error "could not remove flag"
1801 run_test 20 "Release is not permitted"
1804 # test needs a running copytool
1808 local f=$DIR/$tdir/test_release
1810 # Create a file and check its states
1811 local fid=$(make_small $f)
1812 check_hsm_flags $f "0x00000000"
1814 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1815 # used until file is flushed to disk
1816 if [ $(facet_fstype ost1) == "zfs" ]; then
1817 # this causes an OST_SYNC rpc to be sent
1818 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1819 # clear locks to reread file data
1820 cancel_lru_locks osc
1823 local orig_size=$(stat -c "%s" $f)
1824 local orig_blocks=$(stat -c "%b" $f)
1826 start_full_debug_logging
1828 $LFS hsm_archive $f || error "could not archive file"
1829 wait_request_state $fid ARCHIVE SUCCEED
1831 local blocks=$(stat -c "%b" $f)
1832 [ $blocks -eq $orig_blocks ] ||
1833 error "$f: wrong block number after archive: " \
1834 "$blocks != $orig_blocks"
1835 local size=$(stat -c "%s" $f)
1836 [ $size -eq $orig_size ] ||
1837 error "$f: wrong size after archive: $size != $orig_size"
1839 # Release and check states
1840 $LFS hsm_release $f || error "could not release file"
1841 check_hsm_flags $f "0x0000000d"
1843 blocks=$(stat -c "%b" $f)
1844 [ $blocks -gt 5 ] &&
1845 error "$f: too many blocks after release: $blocks > 5"
1846 size=$(stat -c "%s" $f)
1847 [ $size -ne $orig_size ] &&
1848 error "$f: wrong size after release: $size != $orig_size"
1850 # Check we can release an file without stripe info
1854 check_hsm_flags $f "0x00000000"
1855 $LFS hsm_archive $f || error "could not archive file"
1856 wait_request_state $fid ARCHIVE SUCCEED
1858 # Release and check states
1859 $LFS hsm_release $f || error "could not release file"
1860 check_hsm_flags $f "0x0000000d"
1862 # Release again a file that is already released is OK
1863 $LFS hsm_release $f || fail "second release should succeed"
1864 check_hsm_flags $f "0x0000000d"
1866 stop_full_debug_logging
1870 run_test 21 "Simple release tests"
1873 # test needs a running copytool
1878 local f=$DIR/$tdir/test_release
1879 local swap=$DIR/$tdir/test_swap
1881 # Create a file and check its states
1882 local fid=$(make_small $f)
1883 check_hsm_flags $f "0x00000000"
1885 $LFS hsm_archive $f || error "could not archive file"
1886 wait_request_state $fid ARCHIVE SUCCEED
1888 # Release and check states
1889 $LFS hsm_release $f || error "could not release file"
1890 check_hsm_flags $f "0x0000000d"
1893 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1898 run_test 22 "Could not swap a release file"
1901 # test needs a running copytool
1906 local f=$DIR/$tdir/test_mtime
1908 # Create a file and check its states
1909 local fid=$(make_small $f)
1910 check_hsm_flags $f "0x00000000"
1912 $LFS hsm_archive $f || error "could not archive file"
1913 wait_request_state $fid ARCHIVE SUCCEED
1915 # Set modification time in the past
1916 touch -m -a -d @978261179 $f
1918 # Release and check states
1919 $LFS hsm_release $f || error "could not release file"
1920 check_hsm_flags $f "0x0000000d"
1922 local MTIME=$(stat -c "%Y" $f)
1923 local ATIME=$(stat -c "%X" $f)
1924 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1925 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1929 run_test 23 "Release does not change a/mtime (utime)"
1932 local file=$DIR/$tdir/$tfile
1941 # test needs a running copytool
1946 fid=$(make_small $file)
1948 # Create a file and check its states
1949 check_hsm_flags $file "0x00000000"
1951 # Ensure atime is less than mtime and ctime.
1955 atime0=$(stat -c "%X" $file)
1956 mtime0=$(stat -c "%Y" $file)
1957 ctime0=$(stat -c "%Z" $file)
1959 [ $atime0 -lt $mtime0 ] ||
1960 error "atime $atime0 is not less than mtime $mtime0"
1962 [ $atime0 -lt $ctime0 ] ||
1963 error "atime $atime0 is not less than ctime $ctime0"
1965 # Archive should not change any timestamps.
1966 $LFS hsm_archive $file || error "cannot archive '$file'"
1967 wait_request_state $fid ARCHIVE SUCCEED
1969 atime1=$(stat -c "%X" $file)
1970 mtime1=$(stat -c "%Y" $file)
1971 ctime1=$(stat -c "%Z" $file)
1973 [ $atime0 -eq $atime1 ] ||
1974 error "archive changed atime from $atime0 to $atime1"
1976 [ $mtime0 -eq $mtime1 ] ||
1977 error "archive changed mtime from $mtime0 to $mtime1"
1979 [ $ctime0 -eq $ctime1 ] ||
1980 error "archive changed ctime from $ctime0 to $ctime1"
1982 # Release should not change any timestamps.
1983 $LFS hsm_release $file || error "cannot release '$file'"
1984 check_hsm_flags $file "0x0000000d"
1986 atime1=$(stat -c "%X" $file)
1987 mtime1=$(stat -c "%Y" $file)
1988 ctime1=$(stat -c "%Z" $file)
1990 [ $atime0 -eq $atime1 ] ||
1991 error "release changed atime from $atime0 to $atime1"
1993 [ $mtime0 -eq $mtime1 ] ||
1994 error "release changed mtime from $mtime0 to $mtime1"
1996 [ $ctime0 -eq $ctime1 ] ||
1997 error "release changed ctime from $ctime0 to $ctime1"
1999 # Restore should not change any timestamps.
2000 $LFS hsm_restore $file
2001 wait_request_state $fid RESTORE SUCCEED
2003 atime1=$(stat -c "%X" $file)
2004 mtime1=$(stat -c "%Y" $file)
2005 ctime1=$(stat -c "%Z" $file)
2007 [ $atime0 -eq $atime1 ] ||
2008 error "restore changed atime from $atime0 to $atime1"
2010 [ $mtime0 -eq $mtime1 ] ||
2011 error "restore changed mtime from $mtime0 to $mtime1"
2013 [ $ctime0 -eq $ctime1 ] ||
2014 error "restore changed ctime from $ctime0 to $ctime1"
2018 # Once more, after unmount and mount.
2019 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2020 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2022 atime1=$(stat -c "%X" $file)
2023 mtime1=$(stat -c "%Y" $file)
2024 ctime1=$(stat -c "%Z" $file)
2026 [ $atime0 -eq $atime1 ] ||
2027 error "remount changed atime from $atime0 to $atime1"
2029 [ $mtime0 -eq $mtime1 ] ||
2030 error "remount changed mtime from $mtime0 to $mtime1"
2032 [ $ctime0 -eq $ctime1 ] ||
2033 error "remount changed ctime from $ctime0 to $ctime1"
2035 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2038 local file=$DIR/$tdir/$tfile
2044 # Test needs a running copytool.
2048 # Check that root can do HSM actions on a regular user's file.
2050 fid=$(make_small $file)
2051 sum0=$(md5sum $file)
2053 chown $RUNAS_ID:$RUNAS_GID $file ||
2054 error "cannot chown '$file' to '$RUNAS_ID'"
2056 chmod ugo-w $DIR/$tdir ||
2057 error "cannot chmod '$DIR/$tdir'"
2059 $LFS hsm_archive $file
2060 wait_request_state $fid ARCHIVE SUCCEED
2062 $LFS hsm_release $file
2063 check_hsm_flags $file "0x0000000d"
2065 $LFS hsm_restore $file
2066 wait_request_state $fid RESTORE SUCCEED
2068 # Check that ordinary user can get HSM state.
2069 $RUNAS $LFS hsm_state $file ||
2070 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2072 $LFS hsm_release $file
2073 check_hsm_flags $file "0x0000000d"
2075 # Check that ordinary user can accessed released file.
2076 sum1=$($RUNAS md5sum $file) ||
2077 error "user '$RUNAS_ID' cannot read '$file'"
2079 [ "$sum0" == "$sum1" ] ||
2080 error "md5sum mismatch for '$file'"
2084 run_test 24b "root can archive, release, and restore user files"
2086 cleanup_test_24c() {
2088 set_hsm_param user_request_mask RESTORE
2089 set_hsm_param group_request_mask RESTORE
2090 set_hsm_param other_request_mask RESTORE
2094 local file=$DIR/$tdir/$tfile
2095 local action=archive
2100 # test needs a running copytool
2105 # Save the default masks and check that cleanup_24c will
2106 # restore the request masks correctly.
2107 user_save=$(get_hsm_param user_request_mask)
2108 group_save=$(get_hsm_param group_request_mask)
2109 other_save=$(get_hsm_param other_request_mask)
2111 [ "$user_save" == RESTORE ] ||
2112 error "user_request_mask is '$user_save' expected 'RESTORE'"
2113 [ "$group_save" == RESTORE ] ||
2114 error "group_request_mask is '$group_save' expected 'RESTORE'"
2115 [ "$other_save" == RESTORE ] ||
2116 error "other_request_mask is '$other_save' expected 'RESTORE'"
2118 trap cleanup_test_24c EXIT
2123 chown $RUNAS_ID:nobody $file ||
2124 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2126 $RUNAS $LFS hsm_$action $file &&
2127 error "$action by user should fail"
2129 set_hsm_param user_request_mask $action
2130 $RUNAS $LFS hsm_$action $file ||
2131 error "$action by user should succeed"
2136 chown nobody:$RUNAS_GID $file ||
2137 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2139 $RUNAS $LFS hsm_$action $file &&
2140 error "$action by group should fail"
2142 set_hsm_param group_request_mask $action
2143 $RUNAS $LFS hsm_$action $file ||
2144 error "$action by group should succeed"
2149 chown nobody:nobody $file ||
2150 error "cannot chown '$file' to 'nobody:nobody'"
2152 $RUNAS $LFS hsm_$action $file &&
2153 error "$action by other should fail"
2155 set_hsm_param other_request_mask $action
2156 $RUNAS $LFS hsm_$action $file ||
2157 error "$action by other should succeed"
2162 run_test 24c "check that user,group,other request masks work"
2164 cleanup_test_24d() {
2166 mount -o remount,rw $MOUNT2
2167 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2171 local file1=$DIR/$tdir/$tfile
2172 local file2=$DIR2/$tdir/$tfile
2178 fid1=$(make_small $file1)
2181 $LFS getstripe $file1
2183 trap cleanup_test_24d EXIT
2184 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2185 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2186 copytool_setup $SINGLEAGT "$MOUNT3" ||
2187 error "unable to setup a copytool for the test"
2189 mount -o remount,ro $MOUNT2
2191 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2192 start_full_debug_logging
2194 fid2=$(path2fid $file2)
2195 [ "$fid1" == "$fid2" ] ||
2196 error "FID mismatch '$fid1' != '$fid2'"
2198 $LFS hsm_archive $file2 &&
2199 error "archive should fail on read-only mount"
2200 check_hsm_flags $file1 "0x00000000"
2202 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2203 wait_request_state $fid1 ARCHIVE SUCCEED
2205 stop_full_debug_logging
2207 $LFS hsm_release $file1
2208 $LFS hsm_restore $file2
2209 wait_request_state $fid1 RESTORE SUCCEED
2211 $LFS hsm_release $file1 || error "cannot release '$file1'"
2212 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2214 $LFS hsm_release $file2 &&
2215 error "release should fail on read-only mount"
2220 run_test 24d "check that read-only mounts are respected"
2227 local f=$DIR/$tdir/$tfile
2230 fid=$(make_small $f) || error "cannot create $f"
2231 $LFS hsm_archive $f || error "cannot archive $f"
2232 wait_request_state $fid ARCHIVE SUCCEED
2233 $LFS hsm_release $f || error "cannot release $f"
2234 while ! $LFS hsm_state $f | grep released; do
2238 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2242 run_test 24e "tar succeeds on HSM released files" # LU-6213
2246 # test needs a running copytool
2249 mkdir -p $DIR/$tdir/d1
2250 local f=$DIR/$tdir/$tfile
2251 local fid=$(copy_file /etc/hosts $f)
2254 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2255 error "hsm_archive failed"
2256 wait_request_state $fid ARCHIVE SUCCEED
2257 $LFS hsm_release $f || error "cannot release $f"
2258 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2261 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2262 error "Can not recover the tar contents"
2264 echo "Sum0 = $sum0, sum1 = $sum1"
2265 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2269 run_test 24f "root can archive, release, and restore tar files"
2272 # test needs a running copytool
2276 copy2archive /etc/hosts $tdir/$tfile
2278 local f=$DIR/$tdir/$tfile
2280 import_file $tdir/$tfile $f
2282 $LFS hsm_set --lost $f
2287 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2291 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2292 " (Operation not permitted)"
2295 # test needs a running copytool
2300 local f=$DIR/$tdir/$tfile
2301 local fid=$(copy_file /etc/passwd $f)
2303 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2304 wait_request_state $fid ARCHIVE SUCCEED
2307 $LFS hsm_set --lost $f
2311 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2315 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2316 " (Operation not permitted)"
2319 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2325 fid=$(make_custom_file_for_progress $f 39 1000000)
2326 [ $? != 0 ] && skip "not enough free space" && return
2328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2329 wait_request_state $fid ARCHIVE SUCCEED
2332 wait_request_state $fid REMOVE SUCCEED
2334 check_hsm_flags $f "0x00000000"
2338 run_test 26 "Remove the archive of a valid file"
2341 # test needs a running copytool
2345 make_archive $tdir/$tfile
2346 local f=$DIR/$tdir/$tfile
2347 import_file $tdir/$tfile $f
2348 local fid=$(path2fid $f)
2352 [[ $? != 0 ]] || error "Remove of a released file should fail"
2356 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2359 # test needs a running copytool
2363 local f=$DIR/$tdir/$tfile
2365 fid=$(make_custom_file_for_progress $f 39 1000000)
2366 [ $? != 0 ] && skip "not enough free space" && return
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2369 wait_request_state $fid ARCHIVE SUCCEED
2374 [[ $? != 0 ]] || error "Remove of a released file should fail"
2378 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2381 # test needs a running copytool
2385 local f=$DIR/$tdir/$tfile
2387 fid=$(make_custom_file_for_progress $f 39 1000000)
2388 [ $? != 0 ] && skip "not enough free space" && return
2390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2391 wait_request_state $fid ARCHIVE SUCCEED
2400 wait_request_state $fid REMOVE SUCCEED
2404 run_test 28 "Concurrent archive/file remove"
2407 # Tests --mntpath and --archive options
2410 copytool_setup $SINGLEAGT $MOUNT $archive_id
2412 # Bad archive number
2413 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2414 grep "Invalid argument" ||
2415 error "unexpected hsm_remove failure (1)"
2417 # mntpath is present but file is given
2418 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2419 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2420 error "unexpected hsm_remove failure (2)"
2424 run_test 29a "Tests --mntpath and --archive options"
2427 # test needs a running copytool
2431 local f=$DIR/$tdir/$tfile
2432 local fid=$(make_small $f)
2434 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2435 wait_request_state $fid ARCHIVE SUCCEED
2439 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2440 wait_request_state $fid REMOVE SUCCEED
2444 run_test 29b "Archive/delete/remove by FID from the archive."
2447 # test needs a running copytool
2451 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2452 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2453 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2456 wait_request_state $fid1 ARCHIVE SUCCEED
2457 wait_request_state $fid2 ARCHIVE SUCCEED
2458 wait_request_state $fid3 ARCHIVE SUCCEED
2460 rm -f $DIR/$tdir/$tfile-[1-3]
2462 echo $fid1 > $DIR/$tdir/list
2463 echo $fid2 >> $DIR/$tdir/list
2464 echo $fid3 >> $DIR/$tdir/list
2466 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2467 --filelist $DIR/$tdir/list
2468 wait_request_state $fid1 REMOVE SUCCEED
2469 wait_request_state $fid2 REMOVE SUCCEED
2470 wait_request_state $fid3 REMOVE SUCCEED
2474 run_test 29c "Archive/delete/remove by FID, using a file list."
2477 # test needs more than one CT
2478 needclients 3 || return 0
2484 copytool_cleanup $(comma_list $(agts_nodes))
2486 # start all of the copytools
2487 for n in $(seq $AGTCOUNT); do
2488 copytool_setup agt$n $MOUNT2 $n
2491 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2494 file=$DIR/$tdir/$tfile
2495 fid=$(make_small $file)
2497 $LFS hsm_archive $file
2498 wait_request_state $fid ARCHIVE SUCCEED
2499 check_hsm_flags $file "0x00000009"
2503 $LFS hsm_remove -a 0 $fid
2505 # give time for CDT to handle remove request and create broadcasted
2508 # remove request has been broadcasted ?
2509 local cnt=$(get_request_count $fid REMOVE)
2510 # broadcasted requests + original
2511 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2512 error "remove not broadcasted to all CTs"
2514 # give time for CDT and CTs to handle broadcasted
2515 wait_for_loop_period
2517 # each agent serves one different archive_id, so broadcasted
2518 # hsm_remove request should only succeed once and fail at all others
2522 for n in $(seq $AGTCOUNT); do
2523 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2524 $HSM_PARAM.actions | awk \
2525 '/'$fid'.*action=REMOVE archive#='$n'/ \
2526 {print \\\$13}' | cut -f2 -d=")
2527 if [[ "$res" == "SUCCEED" ]]; then
2529 elif [[ "$res" == "FAILED" ]]; then
2534 [[ $scnt -ne 1 ]] &&
2535 error "one and only CT should have removed successfully"
2537 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2538 error "all but one CT should have failed to remove"
2541 copytool_cleanup $(comma_list $(agts_nodes))
2544 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2545 "request to be sent once for each registered archive_id"
2548 # restore at exec cannot work on agent node (because of Linux kernel
2549 # protection of executables)
2550 needclients 2 || return 0
2552 # test needs a running copytool
2556 copy2archive /bin/true $tdir/$tfile
2558 local f=$DIR/$tdir/true
2559 import_file $tdir/$tfile $f
2561 local fid=$(path2fid $f)
2563 # set no retry action mode
2569 # remove no try action mode
2573 [[ $st == 0 ]] || error "Failed to exec a released file"
2577 run_test 30a "Restore at exec (import case)"
2580 # restore at exec cannot work on agent node (because of Linux kernel
2581 # protection of executables)
2582 needclients 2 || return 0
2584 # test needs a running copytool
2588 local f=$DIR/$tdir/true
2589 local fid=$(copy_file /bin/true $f)
2591 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2592 wait_request_state $fid ARCHIVE SUCCEED
2595 # set no retry action mode
2601 # remove no try action mode
2605 [[ $st == 0 ]] || error "Failed to exec a released file"
2609 run_test 30b "Restore at exec (release case)"
2612 needclients 2 || return 0
2614 # test needs a running copytool
2618 local f=$DIR/$tdir/SLEEP
2619 local slp_sum1=$(md5sum /bin/sleep)
2620 local fid=$(copy_file /bin/sleep $f)
2622 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2623 wait_request_state $fid ARCHIVE SUCCEED
2625 check_hsm_flags $f "0x0000000d"
2626 # set no retry action mode
2628 do_node $CLIENT2 "$f 10" &
2632 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2634 [[ $? == 0 ]] || error "Execution failed during run"
2636 if [[ $? != 0 ]]; then
2637 local slp_sum2=$(md5sum /bin/sleep)
2638 # in case sleep file is modified during the test
2639 [[ $slp_sum1 == $slp_sum2 ]] &&
2640 error "Binary overwritten during exec"
2644 # remove no try action mode
2646 check_hsm_flags $f "0x00000009"
2650 run_test 30c "Update during exec of released file must fail"
2652 restore_and_check_size() {
2655 local s=$(stat -c "%s" $f)
2657 local st=$(get_hsm_flags $f)
2661 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2663 n=$(stat -c "%s" $f)
2664 # we echo in both cases to show stat is not hang
2665 if [[ $n != $s ]]; then
2666 echo "size seen is $n != $s"
2669 echo "size seen is right: $n == $s"
2673 st=$(get_hsm_flags $f)
2675 if [[ "$st" = "0x00000009" ]]; then
2678 echo " restore is too long"
2679 wait_request_state $fid RESTORE SUCCEED
2685 # test needs a running copytool
2690 make_archive $tdir/$tfile
2691 local f=$DIR/$tdir/$tfile
2692 import_file $tdir/$tfile $f
2693 local fid=$($LFS path2fid $f)
2694 HSM_ARCHIVE_PURGE=false copytool_setup
2696 restore_and_check_size $f $fid
2699 [[ $err -eq 0 ]] || error "File size changed during restore"
2703 run_test 31a "Import a large file and check size during restore"
2707 # test needs a running copytool
2712 local f=$DIR/$tdir/$tfile
2714 fid=$(make_custom_file_for_progress $f 39 1000000)
2715 [ $? != 0 ] && skip "not enough free space" && return
2717 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2718 wait_request_state $fid ARCHIVE SUCCEED
2721 restore_and_check_size $f $fid
2724 [[ $err -eq 0 ]] || error "File size changed during restore"
2728 run_test 31b "Restore a large unaligned file and check size during restore"
2731 # test needs a running copytool
2736 local f=$DIR/$tdir/$tfile
2738 fid=$(make_custom_file_for_progress $f 33 1048576)
2739 [ $? != 0 ] && skip "not enough free space" && return
2741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2742 wait_request_state $fid ARCHIVE SUCCEED
2745 restore_and_check_size $f $fid
2748 [[ $err -eq 0 ]] || error "File size changed during restore"
2752 run_test 31c "Restore a large aligned file and check size during restore"
2755 # test needs a running copytool
2760 local f=$DIR/$tdir/$tfile
2762 fid=$(make_custom_file_for_progress $f 39 1000000)
2763 [ $? != 0 ] && skip "not enough free space" && return
2765 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2766 wait_request_state $fid ARCHIVE SUCCEED
2769 # to be sure wait_all_done will not be mislead by previous tests
2772 wait_for_grace_delay
2773 # Also raise grace_delay significantly so the Canceled
2774 # Restore action will stay enough long avail.
2775 local old_grace=$(get_hsm_param grace_delay)
2776 set_hsm_param grace_delay 100
2778 md5sum $f >/dev/null &
2780 wait_request_state $fid RESTORE STARTED
2785 # Check restore trigger process was killed
2786 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2790 # instead of waiting+checking both Restore and Cancel ops
2791 # sequentially, wait for both to be finished and then check
2793 wait_all_done 100 $fid
2794 local rstate=$(get_request_state $fid RESTORE)
2795 local cstate=$(get_request_state $fid CANCEL)
2797 # restore orig grace_delay.
2798 set_hsm_param grace_delay $old_grace
2800 if [[ "$rstate" == "CANCELED" ]] ; then
2801 [[ "$cstate" == "SUCCEED" ]] ||
2802 error "Restore state is CANCELED and Cancel state " \
2803 "is not SUCCEED but $cstate"
2804 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2805 elif [[ "$rstate" == "SUCCEED" ]] ; then
2806 [[ "$cstate" == "FAILED" ]] ||
2807 error "Restore state is SUCCEED and Cancel state " \
2808 "is not FAILED but $cstate"
2809 echo "Restore state is SUCCEED, Cancel state is FAILED"
2811 error "Restore state is $rstate and Cancel state is $cstate"
2815 error "Cannot kill process waiting for restore ($killed)"
2819 run_test 33 "Kill a restore waiting process"
2822 # test needs a running copytool
2827 local f=$DIR/$tdir/$tfile
2829 fid=$(make_custom_file_for_progress $f 39 1000000)
2830 [ $? != 0 ] && skip "not enough free space" && return
2832 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2833 wait_request_state $fid ARCHIVE SUCCEED
2836 md5sum $f >/dev/null &
2838 wait_request_state $fid RESTORE STARTED
2840 rm $f || error "rm $f failed"
2841 # rm must not block during restore
2842 wait_request_state $fid RESTORE STARTED
2844 wait_request_state $fid RESTORE SUCCEED
2845 # check md5sum pgm finished
2846 local there=$(ps -o pid,comm hp $pid >/dev/null)
2847 [[ -z $there ]] || error "Restore initiator does not exit"
2849 local rc=$(wait $pid)
2850 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2854 run_test 34 "Remove file during restore"
2857 # test needs a running copytool
2862 local f=$DIR/$tdir/$tfile
2863 local f1=$DIR/$tdir/$tfile-1
2865 fid=$(make_custom_file_for_progress $f 39 1000000)
2866 [ $? != 0 ] && skip "not enough free space" && return
2868 local fid1=$(copy_file /etc/passwd $f1)
2869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2870 wait_request_state $fid ARCHIVE SUCCEED
2873 md5sum $f >/dev/null &
2875 wait_request_state $fid RESTORE STARTED
2877 mv $f1 $f || error "mv $f1 $f failed"
2878 # mv must not block during restore
2879 wait_request_state $fid RESTORE STARTED
2881 wait_request_state $fid RESTORE SUCCEED
2882 # check md5sum pgm finished
2883 local there=$(ps -o pid,comm hp $pid >/dev/null)
2884 [[ -z $there ]] || error "Restore initiator does not exit"
2886 local rc=$(wait $pid)
2887 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2890 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2894 run_test 35 "Overwrite file during restore"
2897 # test needs a running copytool
2902 local f=$DIR/$tdir/$tfile
2904 fid=$(make_custom_file_for_progress $f 39 1000000)
2905 [ $? != 0 ] && skip "not enough free space" && return
2907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2908 wait_request_state $fid ARCHIVE SUCCEED
2911 md5sum $f >/dev/null &
2913 wait_request_state $fid RESTORE STARTED
2916 # rm must not block during restore
2917 wait_request_state $fid RESTORE STARTED
2919 wait_request_state $fid RESTORE SUCCEED
2920 # check md5sum pgm finished
2921 local there=$(ps -o pid,comm hp $pid >/dev/null)
2923 error "Restore initiator does not exit"
2925 local rc=$(wait $pid)
2927 error "Restore initiator failed with $rc"
2931 run_test 36 "Move file during restore"
2934 # LU-5683: check that an archived dirty file can be rearchived.
2936 copytool_setup $SINGLEAGT $MOUNT2
2939 local f=$DIR/$tdir/$tfile
2942 fid=$(make_small $f) || error "cannot create small file"
2944 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2945 wait_request_state $fid ARCHIVE SUCCEED
2946 $LFS hsm_release $f || error "cannot release $f"
2948 # Allow previous archive request to expire from the actions log.
2949 wait_for_grace_delay
2952 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2954 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2955 wait_request_state $fid ARCHIVE SUCCEED
2959 run_test 37 "re-archive a dirty file"
2966 for n in $(seq 1 $count); do
2967 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2969 echo "$count archive requests submitted"
2973 local stream_count=4
2974 local file_count=100
2976 local f=$DIR/$tdir/$tfile
2981 for i in $(seq 1 $file_count); do
2982 for p in $(seq 1 $stream_count); do
2983 fid=$(copy_file /etc/hosts $f.$p.$i)
2986 # force copytool to use a local/temp archive dir to ensure best
2987 # performance vs remote/NFS mounts used in auto-tests
2988 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2991 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2993 # to be sure wait_all_done will not be mislead by previous tests
2995 wait_for_grace_delay
2997 # start archive streams in background (archive files in parallel)
2998 for p in $(seq 1 $stream_count); do
2999 multi_archive $f.$p $file_count &
3002 echo -n "Wait for all requests being enqueued..."
3008 run_test 40 "Parallel archive requests"
3011 # test needs a running copytool
3015 local f=$DIR/$tdir/$tfile
3016 local fid=$(copy_file /etc/motd $f 1)
3018 $LFS hsm_archive $f || error "could not archive file"
3019 wait_request_state $fid ARCHIVE SUCCEED
3020 check_hsm_flags $f "0x00000009"
3022 multiop_bg_pause $f O_c || error "multiop failed"
3026 client_up || client_up || true
3028 kill -USR1 $MULTIPID
3029 wait $MULTIPID || error "multiop close failed"
3031 check_hsm_flags $f "0x0000000b"
3035 run_test 52 "Opened for write file on an evicted client should be set dirty"
3038 # test needs a running copytool
3042 local f=$DIR/$tdir/$tfile
3043 local fid=$(copy_file /etc/motd $f 1)
3045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3046 error "could not archive file"
3047 wait_request_state $fid ARCHIVE SUCCEED
3048 check_hsm_flags $f "0x00000009"
3050 multiop_bg_pause $f o_c || error "multiop failed"
3054 client_up || client_up || true
3056 kill -USR1 $MULTIPID
3057 wait $MULTIPID || error "multiop close failed"
3059 check_hsm_flags $f "0x00000009"
3063 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3066 # test needs a running copytool
3070 local f=$DIR/$tdir/$tfile
3071 local fid=$(make_custom_file_for_progress $f 39 1000000)
3073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3074 error "could not archive file"
3075 wait_request_state $fid ARCHIVE STARTED
3077 check_hsm_flags $f "0x00000001"
3079 # Avoid coordinator resending this request as soon it has failed.
3084 wait_request_state $fid ARCHIVE FAILED
3086 check_hsm_flags $f "0x00000003"
3091 run_test 54 "Write during an archive cancels it"
3094 # test needs a running copytool
3098 local f=$DIR/$tdir/$tfile
3099 local fid=$(make_custom_file_for_progress $f 39 1000000)
3101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3102 error "could not archive file"
3103 wait_request_state $fid ARCHIVE STARTED
3105 check_hsm_flags $f "0x00000001"
3107 # Avoid coordinator resending this request as soon it has failed.
3110 $TRUNCATE $f 1024 || error "truncate failed"
3112 wait_request_state $fid ARCHIVE FAILED
3114 check_hsm_flags $f "0x00000003"
3119 run_test 55 "Truncate during an archive cancels it"
3122 # test needs a running copytool
3126 local f=$DIR/$tdir/$tfile
3128 fid=$(make_custom_file_for_progress $f 39 1000000)
3129 [ $? != 0 ] && skip "not enough free space" && return
3131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3132 error "could not archive file"
3133 wait_request_state $fid ARCHIVE STARTED
3135 check_hsm_flags $f "0x00000001"
3137 # Change metadata and sync to be sure we are not changing only
3142 wait_request_state $fid ARCHIVE SUCCEED
3144 check_hsm_flags $f "0x00000009"
3148 run_test 56 "Setattr during an archive is ok"
3151 # Need one client for I/O, one for request
3152 needclients 2 || return 0
3154 # test needs a running copytool
3158 local f=$DIR/$tdir/test_archive_remote
3159 # Create a file on a remote node
3160 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3161 "count=2 conv=fsync"
3164 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3165 error "hsm_archive failed"
3166 local fid=$(path2fid $f)
3167 wait_request_state $fid ARCHIVE SUCCEED
3169 # Release and implicit restore it
3170 do_node $CLIENT2 "$LFS hsm_release $f" ||
3171 error "hsm_release failed"
3172 do_node $CLIENT2 "md5sum $f" ||
3173 error "hsm_restore failed"
3175 wait_request_state $fid RESTORE SUCCEED
3179 run_test 57 "Archive a file with dirty cache on another node"
3181 truncate_released_file() {
3185 local sz=$(stat -c %s $src_file)
3186 local f=$DIR/$tdir/$tfile
3187 local fid=$(copy_file $1 $f)
3191 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3192 error "could not archive file"
3193 wait_request_state $fid ARCHIVE SUCCEED
3195 $LFS hsm_release $f || error "could not release file"
3197 $TRUNCATE $f $trunc_to || error "truncate failed"
3200 local sz1=$(stat -c %s $f)
3201 [[ $sz1 == $trunc_to ]] ||
3202 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3205 check_hsm_flags $f "0x0000000b"
3207 local state=$(get_request_state $fid RESTORE)
3208 [[ "$state" == "SUCCEED" ]] ||
3209 error "truncate $sz does not trig restore, state = $state"
3211 $TRUNCATE $ref $trunc_to
3212 cmp $ref $f || error "file data wrong after truncate"
3218 # test needs a running copytool
3223 local sz=$(stat -c %s /etc/passwd)
3225 echo "truncate up from $sz to $((sz*2))"
3226 truncate_released_file /etc/passwd $((sz*2))
3228 echo "truncate down from $sz to $((sz/2))"
3229 truncate_released_file /etc/passwd $((sz/2))
3231 echo "truncate to 0"
3232 truncate_released_file /etc/passwd 0
3236 run_test 58 "Truncate a released file will trigger restore"
3240 local server_version=$(lustre_version_code $SINGLEMDS)
3241 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3242 skip "Need MDS version at least 2.7.63" && return
3245 $MCREATE $DIR/$tfile || error "mcreate failed"
3246 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3247 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3248 fid=$(path2fid $DIR/$tfile)
3249 wait_request_state $fid ARCHIVE SUCCEED
3250 $LFS hsm_release $DIR/$tfile || error "release failed"
3253 run_test 59 "Release stripeless file with non-zero size"
3256 # This test validates the fix for LU-4512. Ensure that the -u
3257 # option changes the progress reporting interval from the
3258 # default (30 seconds) to the user-specified interval.
3260 local progress_timeout=$((interval * 4))
3262 # test needs a new running copytool
3264 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3267 local f=$DIR/$tdir/$tfile
3269 fid=$(make_custom_file_for_progress $f 10)
3270 [ $? != 0 ] && skip "not enough free space" && return
3273 local mdt=${MDT_PREFIX}${mdtidx}
3274 local mds=mds$((mdtidx + 1))
3276 # Wait for copytool to register
3277 wait_update_facet $mds \
3278 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3279 uuid 100 || error "coyptool failed to register with $mdt"
3281 local start_at=$(date +%s)
3282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3283 error "could not archive file"
3285 local agent=$(facet_active_host $SINGLEAGT)
3286 local prefix=$TESTLOG_PREFIX
3287 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3288 local copytool_log=$prefix.copytool_log.$agent.log
3291 wait_update $agent \
3292 "grep -o start.copy $copytool_log" "start copy" 100 ||
3293 error "copytool failed to start"
3295 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3296 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3302 echo -n "Expecting a progress update within $progress_timeout seconds... "
3304 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3305 if [ $RESULT -gt 0 ]; then
3306 echo "$RESULT bytes copied in $WAIT seconds."
3308 elif [ $WAIT -ge $progress_timeout ]; then
3309 error "Timed out waiting for progress update!"
3312 WAIT=$((WAIT + sleep))
3316 local finish_at=$(date +%s)
3317 local elapsed=$((finish_at - start_at))
3319 # Ensure that the progress update occurred within the expected window.
3320 if [ $elapsed -lt $((interval - 1)) ]; then
3321 error "Expected progress update after at least $interval seconds"
3324 echo "Wait for on going archive hsm action to complete"
3325 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3326 echo "File archiving not completed even after 10 secs"
3331 run_test 60 "Changing progress update interval from default"
3334 # test needs a new running copytool
3336 copytool_monitor_setup
3337 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3339 # Just start and stop the copytool to generate events.
3342 # Wait for the copytool to register.
3343 wait_update --verbose $(facet_active_host mds1) \
3344 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3346 error "copytool failed to register with MDT0000"
3350 local REGISTER_EVENT
3351 local UNREGISTER_EVENT
3352 while read event; do
3353 local parsed=$(parse_json_event "$event")
3354 if [ -z "$parsed" ]; then
3355 error "Copytool sent malformed event: $event"
3359 if [ $event_type == "REGISTER" ]; then
3360 REGISTER_EVENT=$event
3361 elif [ $event_type == "UNREGISTER" ]; then
3362 UNREGISTER_EVENT=$event
3364 done < <(echo $"$(get_copytool_event_log)")
3366 if [ -z "$REGISTER_EVENT" ]; then
3367 error "Copytool failed to send register event to FIFO"
3370 if [ -z "$UNREGISTER_EVENT" ]; then
3371 error "Copytool failed to send unregister event to FIFO"
3374 copytool_monitor_cleanup
3375 echo "Register/Unregister events look OK."
3377 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3380 # Bump progress interval for livelier events.
3383 # test needs a new running copytool
3385 copytool_monitor_setup
3386 HSMTOOL_UPDATE_INTERVAL=$interval \
3387 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3390 local f=$DIR/$tdir/$tfile
3392 fid=$(make_custom_file_for_progress $f 39 1000000)
3393 [ $? != 0 ] && skip "not enough free space" && return
3395 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3396 error "could not archive file"
3397 wait_request_state $fid ARCHIVE SUCCEED
3399 local expected_fields="event_time data_fid source_fid"
3400 expected_fields+=" total_bytes current_bytes"
3404 while read event; do
3405 # Make sure we're not getting anything from previous events.
3406 for field in $expected_fields; do
3410 local parsed=$(parse_json_event "$event")
3411 if [ -z "$parsed" ]; then
3412 error "Copytool sent malformed event: $event"
3416 if [ $event_type == "ARCHIVE_START" ]; then
3419 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3422 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3426 # Do some simple checking of the progress update events.
3427 for expected_field in $expected_fields; do
3428 if [ -z ${!expected_field+x} ]; then
3429 error "Missing $expected_field field in event"
3433 if [ $total_bytes -eq 0 ]; then
3434 error "Expected total_bytes to be > 0"
3437 # These should be identical throughout an archive
3439 if [ $source_fid != $data_fid ]; then
3440 error "Expected source_fid to equal data_fid"
3442 done < <(echo $"$(get_copytool_event_log)")
3444 if [ -z "$START_EVENT" ]; then
3445 error "Copytool failed to send archive start event to FIFO"
3448 if [ -z "$FINISH_EVENT" ]; then
3449 error "Copytool failed to send archive finish event to FIFO"
3452 echo "Archive events look OK."
3456 copytool_monitor_cleanup
3458 run_test 71 "Copytool logs JSON archive events to FIFO"
3461 # Bump progress interval for livelier events.
3464 # test needs a new running copytool
3466 copytool_monitor_setup
3467 HSMTOOL_UPDATE_INTERVAL=$interval \
3468 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3469 local test_file=$HSMTOOL_MONITOR_DIR/file
3471 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3473 do_facet $SINGLEAGT "$cmd" ||
3474 error "cannot create $test_file on $SINGLEAGT"
3475 copy2archive $test_file $tdir/$tfile
3478 local f=$DIR/$tdir/$tfile
3479 import_file $tdir/$tfile $f
3480 f=$DIR2/$tdir/$tfile
3481 echo "Verifying released state: "
3482 check_hsm_flags $f "0x0000000d"
3484 local fid=$(path2fid $f)
3486 wait_request_state $fid RESTORE SUCCEED
3488 local expected_fields="event_time data_fid source_fid"
3489 expected_fields+=" total_bytes current_bytes"
3493 while read event; do
3494 # Make sure we're not getting anything from previous events.
3495 for field in $expected_fields; do
3499 local parsed=$(parse_json_event "$event")
3500 if [ -z "$parsed" ]; then
3501 error "Copytool sent malformed event: $event"
3505 if [ $event_type == "RESTORE_START" ]; then
3507 if [ $source_fid != $data_fid ]; then
3508 error "source_fid should == data_fid at start"
3511 elif [ $event_type == "RESTORE_FINISH" ]; then
3513 if [ $source_fid != $data_fid ]; then
3514 error "source_fid should == data_fid at finish"
3517 elif [ $event_type != "RESTORE_RUNNING" ]; then
3521 # Do some simple checking of the progress update events.
3522 for expected_field in $expected_fields; do
3523 if [ -z ${!expected_field+x} ]; then
3524 error "Missing $expected_field field in event"
3528 if [ $total_bytes -eq 0 ]; then
3529 error "Expected total_bytes to be > 0"
3532 # When a restore starts out, the data fid is the same as the
3533 # source fid. After the restore has gotten going, we learn
3534 # the new data fid. Once the restore has finished, the source
3535 # fid is set to the new data fid.
3537 # We test this because some monitoring software may depend on
3538 # this behavior. If it changes, then the consumers of these
3539 # events may need to be modified.
3540 if [ $source_fid == $data_fid ]; then
3541 error "source_fid should != data_fid during restore"
3543 done < <(echo $"$(get_copytool_event_log)")
3545 if [ -z "$START_EVENT" ]; then
3546 error "Copytool failed to send restore start event to FIFO"
3549 if [ -z "$FINISH_EVENT" ]; then
3550 error "Copytool failed to send restore finish event to FIFO"
3553 echo "Restore events look OK."
3557 copytool_monitor_cleanup
3561 run_test 72 "Copytool logs JSON restore events to FIFO"
3564 file_count=51 # Max number of files constrained by LNET message size
3565 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3566 local f=$DIR/$tdir/$tfile
3567 local FILELIST=/tmp/filelist.txt
3571 for i in $(seq 1 $file_count); do
3572 fid=$(copy_file /etc/hosts $f.$i)
3573 echo $f.$i >> $FILELIST
3575 # force copytool to use a local/temp archive dir to ensure best
3576 # performance vs remote/NFS mounts used in auto-tests
3577 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3580 local dai=$(get_hsm_param default_archive_id)
3581 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3583 # to be sure wait_all_done will not be mislead by previous tests
3585 wait_for_grace_delay
3586 $LFS hsm_archive --filelist $FILELIST ||
3587 error "cannot archive a file list"
3589 $LFS hsm_release --filelist $FILELIST ||
3590 error "cannot release a file list"
3591 $LFS hsm_restore --filelist $FILELIST ||
3592 error "cannot restore a file list"
3596 run_test 90 "Archive/restore a file list"
3598 double_verify_reset_hsm_param() {
3600 echo "Testing $HSM_PARAM.$p"
3601 local val=$(get_hsm_param $p)
3603 local val2=$(($val * 2))
3604 set_hsm_param $p $val2
3605 val=$(get_hsm_param $p)
3606 [[ $val == $val2 ]] ||
3607 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3608 echo "Set $p to 0 must failed"
3612 set_hsm_param $p $save
3614 if [[ $rc == 0 ]]; then
3615 error "we must not be able to set $HSM_PARAM.$p to 0"
3620 double_verify_reset_hsm_param loop_period
3621 double_verify_reset_hsm_param grace_delay
3622 double_verify_reset_hsm_param active_request_timeout
3623 double_verify_reset_hsm_param max_requests
3624 double_verify_reset_hsm_param default_archive_id
3626 run_test 100 "Set coordinator /proc tunables"
3633 run_test 102 "Verify coordinator control"
3636 # test needs a running copytool
3643 for i in $(seq 1 20); do
3644 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3646 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3650 echo "Current requests"
3651 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3652 $HSM_PARAM.actions |\
3653 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3655 [[ -z "$res" ]] || error "Some request have not been canceled"
3659 run_test 103 "Purge all requests"
3664 # test needs a running copytool
3668 local f=$DIR/$tdir/$tfile
3670 fid=$(make_custom_file_for_progress $f 39 1000000)
3671 [ $? != 0 ] && skip "not enough free space" && return
3673 # if cdt is on, it can serve too quickly the request
3675 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3676 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3677 $HSM_PARAM.actions |\
3678 grep $fid | cut -f16 -d=")
3681 [[ "$data1" == "$DATAHEX" ]] ||
3682 error "Data field in records is ($data1) and not ($DATAHEX)"
3686 run_test 104 "Copy tool data field"
3693 for i in $(seq -w 1 10); do
3694 cp /etc/passwd $DIR/$tdir/$i
3695 $LFS hsm_archive $DIR/$tdir/$i
3697 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3698 $HSM_PARAM.actions |\
3699 grep WAITING | wc -l")
3702 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3703 $HSM_PARAM.actions |\
3704 grep WAITING | wc -l")
3707 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3708 error "Requests count after shutdown $reqcnt2 != "\
3709 "before shutdown $reqcnt1"
3711 run_test 105 "Restart of coordinator"
3714 # test needs a running copytool
3717 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3719 check_agent_registered $uuid
3721 search_copytools || error "No copytool found"
3724 check_agent_unregistered $uuid
3727 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3728 check_agent_registered $uuid
3732 run_test 106 "Copytool register/unregister"
3735 # test needs a running copytool
3737 # create and archive file
3739 local f1=$DIR/$tdir/$tfile
3740 local fid=$(copy_file /etc/passwd $f1)
3741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3742 wait_request_state $fid ARCHIVE SUCCEED
3743 # shutdown and restart MDS
3745 # check the copytool still gets messages from MDT
3746 local f2=$DIR/$tdir/2
3747 local fid=$(copy_file /etc/passwd $f2)
3748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3749 # main check of this sanity: this request MUST succeed
3750 wait_request_state $fid ARCHIVE SUCCEED
3753 run_test 107 "Copytool re-register after MDS restart"
3755 policy_set_and_test()
3759 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3760 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3761 [[ "$policy" == "$target" ]] ||
3762 error "Wrong policy after '$change': '$policy' != '$target'"
3766 # to force default policy setting if error
3767 CDT_POLICY_HAD_CHANGED=true
3769 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3770 local default="NonBlockingRestore [NoRetryAction]"
3771 [[ "$policy" == "$default" ]] ||
3772 error "default policy has changed,"\
3773 " '$policy' != '$default' update the test"
3774 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3775 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3776 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3777 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3778 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3779 # useless bacause we know but safer for futur changes to use real value
3780 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3781 echo "Next set_param must failed"
3782 policy_set_and_test "wrong" "$policy"
3785 echo "Back to default policy"
3786 cdt_set_sanity_policy
3788 run_test 109 "Policy display/change"
3791 # test needs a running copytool
3796 copy2archive /etc/passwd $tdir/$tfile
3798 local f=$DIR/$tdir/$tfile
3799 import_file $tdir/$tfile $f
3800 local fid=$(path2fid $f)
3802 cdt_set_non_blocking_restore
3807 wait_request_state $fid RESTORE SUCCEED
3808 cdt_clear_non_blocking_restore
3812 error "md5sum returns $st != 1, "\
3813 "should also perror ENODATA (No data available)"
3817 run_test 110a "Non blocking restore policy (import case)"
3820 # test needs a running copytool
3824 local f=$DIR/$tdir/$tfile
3825 local fid=$(copy_file /etc/passwd $f)
3826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3827 wait_request_state $fid ARCHIVE SUCCEED
3830 cdt_set_non_blocking_restore
3835 wait_request_state $fid RESTORE SUCCEED
3836 cdt_clear_non_blocking_restore
3840 error "md5sum returns $st != 1, "\
3841 "should also perror ENODATA (No data available)"
3845 run_test 110b "Non blocking restore policy (release case)"
3848 # test needs a running copytool
3852 copy2archive /etc/passwd $tdir/$tfile
3854 local f=$DIR/$tdir/$tfile
3856 import_file $tdir/$tfile $f
3857 local fid=$(path2fid $f)
3861 copytool_remove_backend $fid
3864 wait_request_state $fid RESTORE FAILED
3871 [[ $st == 0 ]] || error "Restore does not failed"
3875 run_test 111a "No retry policy (import case), restore will error"\
3876 " (No such file or directory)"
3879 # test needs a running copytool
3883 local f=$DIR/$tdir/$tfile
3884 local fid=$(copy_file /etc/passwd $f)
3886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3887 wait_request_state $fid ARCHIVE SUCCEED
3890 copytool_remove_backend $fid
3893 wait_request_state $fid RESTORE FAILED
3900 [[ $st == 0 ]] || error "Restore does not failed"
3904 run_test 111b "No retry policy (release case), restore will error"\
3905 " (No such file or directory)"
3908 # test needs a running copytool
3912 local f=$DIR/$tdir/$tfile
3913 local fid=$(copy_file /etc/passwd $f)
3915 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3916 local l=$($LFS hsm_action $f)
3918 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3922 wait_request_state $fid ARCHIVE SUCCEED
3925 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3929 run_test 112 "State of recorded request"
3932 # test needs a running copytool
3936 local f=$DIR/$tdir/$tfile
3938 fid=$(make_custom_file_for_progress $f 103 1048576)
3939 [ $? != 0 ] && skip "not enough free space" && return
3941 # test with cdt on is made in test_221
3943 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3944 # wait archive to register at CDT
3945 wait_request_state $fid ARCHIVE WAITING
3948 wait_request_state $fid ARCHIVE CANCELED
3949 wait_request_state $fid CANCEL SUCCEED
3953 run_test 200 "Register/Cancel archive"
3956 # test needs a running copytool
3960 local f=$DIR/$tdir/$tfile
3961 make_archive $tdir/$tfile
3962 import_file $tdir/$tfile $f
3963 local fid=$(path2fid $f)
3965 # test with cdt on is made in test_222
3968 # wait restore to register at CDT
3969 wait_request_state $fid RESTORE WAITING
3972 wait_request_state $fid RESTORE CANCELED
3973 wait_request_state $fid CANCEL SUCCEED
3977 run_test 201 "Register/Cancel restore"
3980 # test needs a running copytool
3984 local f=$DIR/$tdir/$tfile
3986 fid=$(make_custom_file_for_progress $f 39 1000000)
3987 [ $? != 0 ] && skip "not enough free space" && return
3989 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3990 wait_request_state $fid ARCHIVE SUCCEED
3994 # wait remove to register at CDT
3995 wait_request_state $fid REMOVE WAITING
3998 wait_request_state $fid REMOVE CANCELED
4002 run_test 202 "Register/Cancel remove"
4005 # test needs a running copytool
4010 local f=$DIR/$tdir/$tfile
4011 local fid=$(copy_file /etc/passwd $f)
4015 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4016 wait_request_state $fid ARCHIVE SUCCEED
4018 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4022 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4026 run_test 220 "Changelog for archive"
4029 # test needs a running copytool
4034 local f=$DIR/$tdir/$tfile
4035 local fid=$(copy_file /etc/passwd $f)
4039 # block copytool operations to allow for HSM request to be
4040 # submitted and file be unlinked (CDT will find object removed)
4043 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4049 wait_request_state $fid ARCHIVE FAILED
4051 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4056 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4060 run_test 220a "Changelog for failed archive"
4063 # test needs a running copytool
4068 local f=$DIR/$tdir/$tfile
4070 fid=$(make_custom_file_for_progress $f 103 1048576)
4071 [ $? != 0 ] && skip "not enough free space" && return
4075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4076 wait_request_state $fid ARCHIVE STARTED
4078 wait_request_state $fid ARCHIVE CANCELED
4079 wait_request_state $fid CANCEL SUCCEED
4081 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4084 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4088 run_test 221 "Changelog for archive canceled"
4091 # test needs a running copytool
4095 copy2archive /etc/passwd $tdir/$tfile
4097 local f=$DIR/$tdir/$tfile
4098 import_file $tdir/$tfile $f
4099 local fid=$(path2fid $f)
4104 wait_request_state $fid RESTORE SUCCEED
4106 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4109 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4113 run_test 222a "Changelog for explicit restore"
4116 # test needs a running copytool
4120 local f=$DIR/$tdir/$tfile
4121 local fid=$(copy_file /etc/passwd $f)
4124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4125 wait_request_state $fid ARCHIVE SUCCEED
4130 wait_request_state $fid RESTORE SUCCEED
4132 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4135 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4139 run_test 222b "Changelog for implicit restore"
4142 # test needs a running copytool
4146 copy2archive /etc/passwd $tdir/$tfile
4148 local f=$DIR/$tdir/$tfile
4149 import_file $tdir/$tfile $f
4150 local fid=$(path2fid $f)
4154 # block copytool operations to allow for HSM request to be
4155 # submitted and file be unlinked (CDT will find object removed)
4163 wait_request_state $fid RESTORE FAILED
4165 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4169 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4173 run_test 222c "Changelog for failed explicit restore"
4176 # test needs a running copytool
4180 local f=$DIR/$tdir/$tfile
4181 local fid=$(copy_file /etc/passwd $f)
4184 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4185 wait_request_state $fid ARCHIVE SUCCEED
4188 copytool_remove_backend $fid
4191 wait_request_state $fid RESTORE FAILED
4193 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4197 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4201 run_test 222d "Changelog for failed implicit restore"
4204 # test needs a running copytool
4209 local f=$DIR/$tdir/$tfile
4210 make_archive $tdir/$tfile
4214 import_file $tdir/$tfile $f
4215 local fid=$(path2fid $f)
4218 wait_request_state $fid RESTORE STARTED
4220 wait_request_state $fid RESTORE CANCELED
4221 wait_request_state $fid CANCEL SUCCEED
4223 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4226 [[ $flags == $target ]] ||
4227 error "Changelog flag is $flags not $target"
4231 run_test 223a "Changelog for restore canceled (import case)"
4234 # test needs a running copytool
4239 local f=$DIR/$tdir/$tfile
4241 fid=$(make_custom_file_for_progress $f 39 1000000)
4242 [ $? != 0 ] && skip "not enough free space" && return
4245 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4246 wait_request_state $fid ARCHIVE SUCCEED
4249 wait_request_state $fid RESTORE STARTED
4251 wait_request_state $fid RESTORE CANCELED
4252 wait_request_state $fid CANCEL SUCCEED
4254 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4257 [[ $flags == $target ]] ||
4258 error "Changelog flag is $flags not $target"
4262 run_test 223b "Changelog for restore canceled (release case)"
4265 # test needs a running copytool
4270 local f=$DIR/$tdir/$tfile
4271 local fid=$(copy_file /etc/passwd $f)
4274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4275 wait_request_state $fid ARCHIVE SUCCEED
4278 wait_request_state $fid REMOVE SUCCEED
4280 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4283 [[ $flags == $target ]] ||
4284 error "Changelog flag is $flags not $target"
4288 run_test 224 "Changelog for remove"
4291 # test needs a running copytool
4296 local f=$DIR/$tdir/$tfile
4297 local fid=$(copy_file /etc/passwd $f)
4300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4301 wait_request_state $fid ARCHIVE SUCCEED
4303 copytool_remove_backend $fid
4305 # block copytool operations to allow for HSM request to be
4306 # submitted and file be unlinked (CDT will find object removed)
4314 wait_request_state $fid REMOVE FAILED
4316 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4320 [[ $flags == $target ]] ||
4321 error "Changelog flag is $flags not $target"
4325 run_test 224a "Changelog for failed remove"
4328 # test needs a running copytool
4331 # test is not usable because remove request is too fast
4332 # so it is always finished before cancel can be done ...
4333 echo "Test disabled"
4338 local f=$DIR/$tdir/$tfile
4340 fid=$(make_custom_file_for_progress $f 39 1000000)
4341 [ $? != 0 ] && skip "not enough free space" && return
4344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4345 wait_request_state $fid ARCHIVE SUCCEED
4347 # if cdt is on, it can serve too quickly the request
4352 wait_request_state $fid REMOVE CANCELED
4353 wait_request_state $fid CANCEL SUCCEED
4355 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4356 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4357 tail -n 1 | awk '{print $5}')
4360 [[ $flags == $target ]] ||
4361 error "Changelog flag is $flags not $target"
4365 run_test 225 "Changelog for remove canceled"
4368 # test needs a running copytool
4373 local f1=$DIR/$tdir/$tfile-1
4374 local f2=$DIR/$tdir/$tfile-2
4375 local f3=$DIR/$tdir/$tfile-3
4376 local fid1=$(copy_file /etc/passwd $f1)
4377 local fid2=$(copy_file /etc/passwd $f2)
4378 copy_file /etc/passwd $f3
4381 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4382 wait_request_state $fid1 ARCHIVE SUCCEED
4384 $LFS hsm_archive $f2
4385 wait_request_state $fid2 ARCHIVE SUCCEED
4387 rm $f1 || error "rm $f1 failed"
4389 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4392 [[ $flags == $target ]] ||
4393 error "Changelog flag is $flags not $target"
4395 mv $f3 $f2 || error "mv $f3 $f2 failed"
4397 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4400 [[ $flags == $target ]] ||
4401 error "Changelog flag is $flags not $target"
4405 run_test 226 "changelog for last rm/mv with exiting archive"
4407 check_flags_changes() {
4415 $LFS hsm_set --$hsm_flag $f ||
4416 error "Cannot set $hsm_flag on $f"
4417 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4418 local seen=${#flags[*]}
4420 [[ $seen == $cnt ]] ||
4421 error "set $hsm_flag: Changelog events $seen != $cnt"
4422 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4423 error "set $hsm_flag: Changelog flags are "\
4424 "${flags[$((cnt - 1))]} not $target"
4426 $LFS hsm_clear --$hsm_flag $f ||
4427 error "Cannot clear $hsm_flag on $f"
4428 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4431 [[ $cnt == $seen ]] ||
4432 error "clear $hsm_flag: Changelog events $seen != $cnt"
4434 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4435 error "clear $hsm_flag: Changelog flag is "\
4436 "${flags[$((cnt - 1))]} not $target"
4440 # test needs a running copytool
4447 for i in norelease noarchive exists archived
4449 local f=$DIR/$tdir/$tfile-$i
4450 local fid=$(copy_file /etc/passwd $f)
4451 check_flags_changes $f $fid $i 0 1
4454 f=$DIR/$tdir/$tfile---lost
4455 fid=$(copy_file /etc/passwd $f)
4456 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4457 wait_request_state $fid ARCHIVE SUCCEED
4458 check_flags_changes $f $fid lost 3 1
4462 run_test 227 "changelog when explicit setting of HSM flags"
4465 # test needs a running copytool
4468 local fid=$(make_small_sync $DIR/$tfile)
4469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4470 wait_request_state $fid ARCHIVE SUCCEED
4472 $LFS hsm_release $DIR/$tfile
4473 check_hsm_flags $DIR/$tfile "0x0000000d"
4475 filefrag $DIR/$tfile | grep " 1 extent found" ||
4476 error "filefrag on released file must return only one extent"
4478 # only newer versions of cp detect sparse files by stat/FIEMAP
4480 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4481 error "copying $DIR/$tfile"
4482 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4484 $LFS hsm_release $DIR/$tfile
4485 check_hsm_flags $DIR/$tfile "0x0000000d"
4487 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4489 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4491 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4492 error "comparing untarred $DIR/$tfile"
4494 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4495 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4498 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4501 # test needs a running copytool
4505 local maxrequest=$(get_hsm_param max_requests)
4506 local rqcnt=$(($maxrequest * 3))
4510 for i in $(seq -w 1 $rqcnt); do
4512 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4514 # we do it in 2 steps, so all requests arrive at the same time
4515 for i in $(seq -w 1 $rqcnt); do
4516 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4521 while [[ $cnt != 0 || $wt != 0 ]]; do
4523 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4524 $HSM_PARAM.actions |\
4525 grep STARTED | grep -v CANCEL | wc -l")
4526 [[ $cnt -le $maxrequest ]] ||
4527 error "$cnt > $maxrequest too many started requests"
4528 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4529 $HSM_PARAM.actions |\
4530 grep WAITING | wc -l")
4531 echo "max=$maxrequest started=$cnt waiting=$wt"
4536 run_test 250 "Coordinator max request"
4539 # test needs a running copytool
4543 local f=$DIR/$tdir/$tfile
4545 fid=$(make_custom_file_for_progress $f 103 1048576)
4546 [ $? != 0 ] && skip "not enough free space" && return
4549 # to have a short test
4550 local old_to=$(get_hsm_param active_request_timeout)
4551 set_hsm_param active_request_timeout 4
4552 # to be sure the cdt will wake up frequently so
4553 # it will be able to cancel the "old" request
4554 local old_loop=$(get_hsm_param loop_period)
4555 set_hsm_param loop_period 2
4558 # clear locks to avoid extra delay caused by flush/cancel
4559 # and thus prevent early copytool death to timeout.
4560 cancel_lru_locks osc
4562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4563 wait_request_state $fid ARCHIVE STARTED
4565 wait_request_state $fid ARCHIVE CANCELED
4567 set_hsm_param active_request_timeout $old_to
4568 set_hsm_param loop_period $old_loop
4572 run_test 251 "Coordinator request timeout"
4575 # the only way to test ondisk conf is to restart MDS ...
4576 echo "Stop coordinator and remove coordinator state at mount"
4579 # clean on disk conf set by default
4580 cdt_clear_mount_state
4581 cdt_check_state stopped
4583 # check cdt still off after umount/remount
4585 cdt_check_state stopped
4587 echo "Set coordinator start at mount, and start coordinator"
4588 cdt_set_mount_state enabled
4591 cdt_check_state enabled
4593 # check cdt still on after umount/remount
4595 cdt_check_state enabled
4597 # we are back to original state (cdt started at mount)
4599 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4602 local ai=$(get_hsm_param default_archive_id)
4603 local new=$((ai + 1))
4605 set_hsm_param default_archive_id $new -P
4607 local res=$(get_hsm_param default_archive_id)
4610 set_hsm_param default_archive_id "" "-P -d"
4612 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4614 run_test 301 "HSM tunnable are persistent"
4617 local ai=$(get_hsm_param default_archive_id)
4618 local new=$((ai + 1))
4623 set_hsm_param default_archive_id $new -P
4626 for mdtno in $(seq 1 $MDSCOUNT); do
4631 cdt_check_state enabled
4633 local res=$(get_hsm_param default_archive_id)
4636 set_hsm_param default_archive_id "" "-P -d"
4638 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4640 run_test 302 "HSM tunnable are persistent when CDT is off"
4643 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4649 local dir_mdt0=$DIR/$tdir/mdt0
4650 local dir_mdt1=$DIR/$tdir/mdt1
4652 # create 1 dir per MDT
4653 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4654 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4656 # create 1 file in each MDT
4657 local fid1=$(make_small $dir_mdt0/$tfile)
4658 local fid2=$(make_small $dir_mdt1/$tfile)
4660 # check that hsm request on mdt0 is sent to the right MDS
4661 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4662 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4663 echo "archive successful on mdt0"
4665 # check that hsm request on mdt1 is sent to the right MDS
4666 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4667 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4668 echo "archive successful on mdt1"
4671 # clean test files and directories
4672 rm -rf $dir_mdt0 $dir_mdt1
4674 run_test 400 "Single request is sent to the right MDT"
4677 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4683 local dir_mdt0=$DIR/$tdir/mdt0
4684 local dir_mdt1=$DIR/$tdir/mdt1
4686 # create 1 dir per MDT
4687 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4688 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4690 # create 1 file in each MDT
4691 local fid1=$(make_small $dir_mdt0/$tfile)
4692 local fid2=$(make_small $dir_mdt1/$tfile)
4694 # check that compound requests are shunt to the rights MDTs
4695 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4696 error "lfs hsm_archive"
4697 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4698 echo "archive successful on mdt0"
4699 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4700 echo "archive successful on mdt1"
4703 # clean test files and directories
4704 rm -rf $dir_mdt0 $dir_mdt1
4706 run_test 401 "Compound requests split and sent to their respective MDTs"
4708 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4713 local node=$(facet_active_host $facet)
4715 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4716 awk '{print $4}'); do
4717 echo "$3 $mdc on $node"
4718 do_facet $facet "$LCTL --device $mdc $state" || return 1
4723 # make sure there is no running copytool
4726 # deactivate all mdc on agent1
4727 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4729 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4731 check_agent_unregistered "uuid" # match any agent
4733 # no expected running copytool
4734 search_copytools $agent && error "Copytool start should have failed"
4737 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4739 run_test 402a "Copytool start fails if all MDTs are inactive"
4746 local f=$DIR/$tdir/$tfile
4747 touch $f || error "touch $f failed"
4748 local fid=$(path2fid $f)
4750 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4751 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4752 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4754 # give time for CDT to send request and to keep it for retry
4755 wait_for_loop_period
4757 wait_request_state $fid ARCHIVE WAITING
4759 do_facet $SINGLEAGT lctl set_param fail_loc=0
4761 # request should succeed now
4762 wait_request_state $fid ARCHIVE SUCCEED
4766 run_test 402b "CDT must retry request upon slow start of CT"
4769 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4771 # make sure there is no running copytool
4774 local agent=$(facet_active_host $SINGLEAGT)
4776 # deactivate all mdc for MDT0001
4777 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4780 local uuid=$(get_agent_uuid $agent)
4781 # check the agent is registered on MDT0000, and not on MDT0001
4782 check_agent_registered_by_mdt $uuid 0
4783 check_agent_unregistered_by_mdt $uuid 1
4785 # check running copytool process
4786 search_copytools $agent || error "No running copytools on $agent"
4788 # reactivate all mdc for MDT0001
4789 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4791 # make sure the copytool is now registered to all MDTs
4792 check_agent_registered $uuid
4796 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4799 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4803 # create files on both MDT0000 and MDT0001
4806 local dir_mdt0=$DIR/$tdir/mdt0
4807 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4809 # create 1 file on mdt0
4810 local fid1=$(make_small $dir_mdt0/$tfile)
4812 # deactivate all mdc for MDT0001
4813 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4815 # send an HSM request for files in MDT0000
4816 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4818 # check for completion of files in MDT0000
4819 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4820 echo "archive successful on mdt0"
4822 # reactivate all mdc for MDT0001
4823 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4826 # clean test files and directories
4829 run_test 404 "Inactive MDT does not block requests for active MDTs"
4832 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4838 local striped_dir=$DIR/$tdir/striped_dir
4840 # create striped dir on all of MDTs
4841 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4843 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4844 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4845 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4846 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4848 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4849 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4850 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4851 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4853 # check that compound requests are shunt to the rights MDTs
4854 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4855 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4856 error "lfs hsm_archive"
4858 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4859 echo "archive successful on $fid1"
4860 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4861 echo "archive successful on $fid2"
4862 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4863 echo "archive successful on $fid3"
4864 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4865 echo "archive successful on $fid4"
4867 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4868 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4869 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4870 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4872 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4873 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4874 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4875 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4879 run_test 405 "archive and release under striped directory"
4882 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4884 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4885 skip "need MDS version at least 2.7.64" && return 0
4892 fid=$(make_small $DIR/$tdir/$tfile)
4895 $LFS hsm_archive $DIR/$tdir/$tfile
4896 wait_request_state "$fid" ARCHIVE SUCCEED
4897 $LFS hsm_release $DIR/$tdir/$tfile
4899 # Should migrate $tdir but not $tfile.
4900 $LFS mv -M1 $DIR/$tdir &&
4901 error "migrating HSM an archived file should fail"
4903 $LFS hsm_restore $DIR/$tdir/$tfile
4904 wait_request_state "$fid" RESTORE SUCCEED
4906 $LFS hsm_remove $DIR/$tdir/$tfile
4907 wait_request_state "$fid" REMOVE SUCCEED
4909 cat $DIR/$tdir/$tfile > /dev/null ||
4910 error "cannot read $DIR/$tdir/$tfile"
4912 $LFS mv -M1 $DIR/$tdir ||
4913 error "cannot complete migration after HSM remove"
4915 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4916 if ((mdt_index != 1)); then
4917 error "expected MDT index 1, got $mdt_index"
4920 # Refresh fid after migration.
4921 fid=$(path2fid $DIR/$tdir/$tfile)
4924 $LFS hsm_archive $DIR/$tdir/$tfile
4925 wait_request_state "$fid" ARCHIVE SUCCEED 1
4927 lctl set_param debug=+trace
4928 $LFS hsm_release $DIR/$tdir/$tfile ||
4929 error "cannot release $DIR/$tdir/$tfile"
4931 $LFS hsm_restore $DIR/$tdir/$tfile
4932 wait_request_state "$fid" RESTORE SUCCEED 1
4934 cat $DIR/$tdir/$tfile > /dev/null ||
4935 error "cannot read $DIR/$tdir/$tfile"
4939 run_test 406 "attempting to migrate HSM archived files is safe"
4943 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4944 skip "HSM migrate is not supported" && return
4946 # Stop the existing copytool
4949 test_mkdir -p $DIR/$tdir
4950 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4952 run_test 500 "various LLAPI HSM tests"
4957 check_and_cleanup_lustre