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)
2180 trap cleanup_test_24d EXIT
2181 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2182 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2183 copytool_setup $SINGLEAGT "$MOUNT3" ||
2184 error "unable to setup a copytool for the test"
2186 mount -o remount,ro $MOUNT2
2188 fid2=$(path2fid $file2)
2189 [ "$fid1" == "$fid2" ] ||
2190 error "FID mismatch '$fid1' != '$fid2'"
2192 $LFS hsm_archive $file2 &&
2193 error "archive should fail on read-only mount"
2194 check_hsm_flags $file1 "0x00000000"
2196 $LFS hsm_archive $file1
2197 wait_request_state $fid1 ARCHIVE SUCCEED
2199 $LFS hsm_release $file1
2200 $LFS hsm_restore $file2
2201 wait_request_state $fid1 RESTORE SUCCEED
2203 $LFS hsm_release $file1 || error "cannot release '$file1'"
2204 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2206 $LFS hsm_release $file2 &&
2207 error "release should fail on read-only mount"
2212 run_test 24d "check that read-only mounts are respected"
2219 local f=$DIR/$tdir/$tfile
2222 fid=$(make_small $f) || error "cannot create $f"
2223 $LFS hsm_archive $f || error "cannot archive $f"
2224 wait_request_state $fid ARCHIVE SUCCEED
2225 $LFS hsm_release $f || error "cannot release $f"
2226 while ! $LFS hsm_state $f | grep released; do
2230 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2234 run_test 24e "tar succeeds on HSM released files" # LU-6213
2238 # test needs a running copytool
2241 mkdir -p $DIR/$tdir/d1
2242 local f=$DIR/$tdir/$tfile
2243 local fid=$(copy_file /etc/hosts $f)
2246 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2247 error "hsm_archive failed"
2248 wait_request_state $fid ARCHIVE SUCCEED
2249 $LFS hsm_release $f || error "cannot release $f"
2250 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2253 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2254 error "Can not recover the tar contents"
2256 echo "Sum0 = $sum0, sum1 = $sum1"
2257 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2261 run_test 24f "root can archive, release, and restore tar files"
2264 # test needs a running copytool
2268 copy2archive /etc/hosts $tdir/$tfile
2270 local f=$DIR/$tdir/$tfile
2272 import_file $tdir/$tfile $f
2274 $LFS hsm_set --lost $f
2279 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2283 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2284 " (Operation not permitted)"
2287 # test needs a running copytool
2292 local f=$DIR/$tdir/$tfile
2293 local fid=$(copy_file /etc/passwd $f)
2295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2296 wait_request_state $fid ARCHIVE SUCCEED
2299 $LFS hsm_set --lost $f
2303 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2307 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2308 " (Operation not permitted)"
2311 # test needs a running copytool
2315 local f=$DIR/$tdir/$tfile
2317 fid=$(make_custom_file_for_progress $f 39 1000000)
2318 [ $? != 0 ] && skip "not enough free space" && return
2320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2321 wait_request_state $fid ARCHIVE SUCCEED
2324 wait_request_state $fid REMOVE SUCCEED
2326 check_hsm_flags $f "0x00000000"
2330 run_test 26 "Remove the archive of a valid file"
2333 # test needs a running copytool
2337 make_archive $tdir/$tfile
2338 local f=$DIR/$tdir/$tfile
2339 import_file $tdir/$tfile $f
2340 local fid=$(path2fid $f)
2344 [[ $? != 0 ]] || error "Remove of a released file should fail"
2348 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2351 # test needs a running copytool
2355 local f=$DIR/$tdir/$tfile
2357 fid=$(make_custom_file_for_progress $f 39 1000000)
2358 [ $? != 0 ] && skip "not enough free space" && return
2360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2361 wait_request_state $fid ARCHIVE SUCCEED
2366 [[ $? != 0 ]] || error "Remove of a released file should fail"
2370 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2373 # test needs a running copytool
2377 local f=$DIR/$tdir/$tfile
2379 fid=$(make_custom_file_for_progress $f 39 1000000)
2380 [ $? != 0 ] && skip "not enough free space" && return
2382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2383 wait_request_state $fid ARCHIVE SUCCEED
2392 wait_request_state $fid REMOVE SUCCEED
2396 run_test 28 "Concurrent archive/file remove"
2399 # Tests --mntpath and --archive options
2402 copytool_setup $SINGLEAGT $MOUNT $archive_id
2404 # Bad archive number
2405 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2406 grep "Invalid argument" ||
2407 error "unexpected hsm_remove failure (1)"
2409 # mntpath is present but file is given
2410 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2411 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2412 error "unexpected hsm_remove failure (2)"
2416 run_test 29a "Tests --mntpath and --archive options"
2419 # test needs a running copytool
2423 local f=$DIR/$tdir/$tfile
2424 local fid=$(make_small $f)
2426 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2427 wait_request_state $fid ARCHIVE SUCCEED
2431 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2432 wait_request_state $fid REMOVE SUCCEED
2436 run_test 29b "Archive/delete/remove by FID from the archive."
2439 # test needs a running copytool
2443 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2444 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2445 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2448 wait_request_state $fid1 ARCHIVE SUCCEED
2449 wait_request_state $fid2 ARCHIVE SUCCEED
2450 wait_request_state $fid3 ARCHIVE SUCCEED
2452 rm -f $DIR/$tdir/$tfile-[1-3]
2454 echo $fid1 > $DIR/$tdir/list
2455 echo $fid2 >> $DIR/$tdir/list
2456 echo $fid3 >> $DIR/$tdir/list
2458 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2459 --filelist $DIR/$tdir/list
2460 wait_request_state $fid1 REMOVE SUCCEED
2461 wait_request_state $fid2 REMOVE SUCCEED
2462 wait_request_state $fid3 REMOVE SUCCEED
2466 run_test 29c "Archive/delete/remove by FID, using a file list."
2469 # test needs more than one CT
2470 needclients 3 || return 0
2476 copytool_cleanup $(comma_list $(agts_nodes))
2478 # start all of the copytools
2479 for n in $(seq $AGTCOUNT); do
2480 copytool_setup agt$n $MOUNT2 $n
2483 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2486 file=$DIR/$tdir/$tfile
2487 fid=$(make_small $file)
2489 $LFS hsm_archive $file
2490 wait_request_state $fid ARCHIVE SUCCEED
2491 check_hsm_flags $file "0x00000009"
2495 $LFS hsm_remove -a 0 $fid
2497 # give time for CDT to handle remove request and create broadcasted
2500 # remove request has been broadcasted ?
2501 local cnt=$(get_request_count $fid REMOVE)
2502 # broadcasted requests + original
2503 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2504 error "remove not broadcasted to all CTs"
2506 # give time for CDT and CTs to handle broadcasted
2507 wait_for_loop_period
2509 # each agent serves one different archive_id, so broadcasted
2510 # hsm_remove request should only succeed once and fail at all others
2514 for n in $(seq $AGTCOUNT); do
2515 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2516 $HSM_PARAM.actions | awk \
2517 '/'$fid'.*action=REMOVE archive#='$n'/ \
2518 {print \\\$13}' | cut -f2 -d=")
2519 if [[ "$res" == "SUCCEED" ]]; then
2521 elif [[ "$res" == "FAILED" ]]; then
2526 [[ $scnt -ne 1 ]] &&
2527 error "one and only CT should have removed successfully"
2529 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2530 error "all but one CT should have failed to remove"
2533 copytool_cleanup $(comma_list $(agts_nodes))
2536 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2537 "request to be sent once for each registered archive_id"
2540 # restore at exec cannot work on agent node (because of Linux kernel
2541 # protection of executables)
2542 needclients 2 || return 0
2544 # test needs a running copytool
2548 copy2archive /bin/true $tdir/$tfile
2550 local f=$DIR/$tdir/true
2551 import_file $tdir/$tfile $f
2553 local fid=$(path2fid $f)
2555 # set no retry action mode
2561 # remove no try action mode
2565 [[ $st == 0 ]] || error "Failed to exec a released file"
2569 run_test 30a "Restore at exec (import case)"
2572 # restore at exec cannot work on agent node (because of Linux kernel
2573 # protection of executables)
2574 needclients 2 || return 0
2576 # test needs a running copytool
2580 local f=$DIR/$tdir/true
2581 local fid=$(copy_file /bin/true $f)
2583 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2584 wait_request_state $fid ARCHIVE SUCCEED
2587 # set no retry action mode
2593 # remove no try action mode
2597 [[ $st == 0 ]] || error "Failed to exec a released file"
2601 run_test 30b "Restore at exec (release case)"
2604 needclients 2 || return 0
2606 # test needs a running copytool
2610 local f=$DIR/$tdir/SLEEP
2611 local slp_sum1=$(md5sum /bin/sleep)
2612 local fid=$(copy_file /bin/sleep $f)
2614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2615 wait_request_state $fid ARCHIVE SUCCEED
2617 check_hsm_flags $f "0x0000000d"
2618 # set no retry action mode
2620 do_node $CLIENT2 "$f 10" &
2624 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2626 [[ $? == 0 ]] || error "Execution failed during run"
2628 if [[ $? != 0 ]]; then
2629 local slp_sum2=$(md5sum /bin/sleep)
2630 # in case sleep file is modified during the test
2631 [[ $slp_sum1 == $slp_sum2 ]] &&
2632 error "Binary overwritten during exec"
2636 # remove no try action mode
2638 check_hsm_flags $f "0x00000009"
2642 run_test 30c "Update during exec of released file must fail"
2644 restore_and_check_size() {
2647 local s=$(stat -c "%s" $f)
2649 local st=$(get_hsm_flags $f)
2653 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2655 n=$(stat -c "%s" $f)
2656 # we echo in both cases to show stat is not hang
2657 if [[ $n != $s ]]; then
2658 echo "size seen is $n != $s"
2661 echo "size seen is right: $n == $s"
2665 st=$(get_hsm_flags $f)
2667 if [[ "$st" = "0x00000009" ]]; then
2670 echo " restore is too long"
2671 wait_request_state $fid RESTORE SUCCEED
2677 # test needs a running copytool
2682 make_archive $tdir/$tfile
2683 local f=$DIR/$tdir/$tfile
2684 import_file $tdir/$tfile $f
2685 local fid=$($LFS path2fid $f)
2686 HSM_ARCHIVE_PURGE=false copytool_setup
2688 restore_and_check_size $f $fid
2691 [[ $err -eq 0 ]] || error "File size changed during restore"
2695 run_test 31a "Import a large file and check size during restore"
2699 # test needs a running copytool
2704 local f=$DIR/$tdir/$tfile
2706 fid=$(make_custom_file_for_progress $f 39 1000000)
2707 [ $? != 0 ] && skip "not enough free space" && return
2709 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2710 wait_request_state $fid ARCHIVE SUCCEED
2713 restore_and_check_size $f $fid
2716 [[ $err -eq 0 ]] || error "File size changed during restore"
2720 run_test 31b "Restore a large unaligned file and check size during restore"
2723 # test needs a running copytool
2728 local f=$DIR/$tdir/$tfile
2730 fid=$(make_custom_file_for_progress $f 33 1048576)
2731 [ $? != 0 ] && skip "not enough free space" && return
2733 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2734 wait_request_state $fid ARCHIVE SUCCEED
2737 restore_and_check_size $f $fid
2740 [[ $err -eq 0 ]] || error "File size changed during restore"
2744 run_test 31c "Restore a large aligned file and check size during restore"
2747 # test needs a running copytool
2752 local f=$DIR/$tdir/$tfile
2754 fid=$(make_custom_file_for_progress $f 39 1000000)
2755 [ $? != 0 ] && skip "not enough free space" && return
2757 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2758 wait_request_state $fid ARCHIVE SUCCEED
2761 # to be sure wait_all_done will not be mislead by previous tests
2764 wait_for_grace_delay
2765 # Also raise grace_delay significantly so the Canceled
2766 # Restore action will stay enough long avail.
2767 local old_grace=$(get_hsm_param grace_delay)
2768 set_hsm_param grace_delay 100
2770 md5sum $f >/dev/null &
2772 wait_request_state $fid RESTORE STARTED
2777 # Check restore trigger process was killed
2778 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2782 # instead of waiting+checking both Restore and Cancel ops
2783 # sequentially, wait for both to be finished and then check
2785 wait_all_done 100 $fid
2786 local rstate=$(get_request_state $fid RESTORE)
2787 local cstate=$(get_request_state $fid CANCEL)
2789 # restore orig grace_delay.
2790 set_hsm_param grace_delay $old_grace
2792 if [[ "$rstate" == "CANCELED" ]] ; then
2793 [[ "$cstate" == "SUCCEED" ]] ||
2794 error "Restore state is CANCELED and Cancel state " \
2795 "is not SUCCEED but $cstate"
2796 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2797 elif [[ "$rstate" == "SUCCEED" ]] ; then
2798 [[ "$cstate" == "FAILED" ]] ||
2799 error "Restore state is SUCCEED and Cancel state " \
2800 "is not FAILED but $cstate"
2801 echo "Restore state is SUCCEED, Cancel state is FAILED"
2803 error "Restore state is $rstate and Cancel state is $cstate"
2807 error "Cannot kill process waiting for restore ($killed)"
2811 run_test 33 "Kill a restore waiting process"
2814 # test needs a running copytool
2819 local f=$DIR/$tdir/$tfile
2821 fid=$(make_custom_file_for_progress $f 39 1000000)
2822 [ $? != 0 ] && skip "not enough free space" && return
2824 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2825 wait_request_state $fid ARCHIVE SUCCEED
2828 md5sum $f >/dev/null &
2830 wait_request_state $fid RESTORE STARTED
2832 rm $f || error "rm $f failed"
2833 # rm must not block during restore
2834 wait_request_state $fid RESTORE STARTED
2836 wait_request_state $fid RESTORE SUCCEED
2837 # check md5sum pgm finished
2838 local there=$(ps -o pid,comm hp $pid >/dev/null)
2839 [[ -z $there ]] || error "Restore initiator does not exit"
2841 local rc=$(wait $pid)
2842 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2846 run_test 34 "Remove file during restore"
2849 # test needs a running copytool
2854 local f=$DIR/$tdir/$tfile
2855 local f1=$DIR/$tdir/$tfile-1
2857 fid=$(make_custom_file_for_progress $f 39 1000000)
2858 [ $? != 0 ] && skip "not enough free space" && return
2860 local fid1=$(copy_file /etc/passwd $f1)
2861 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2862 wait_request_state $fid ARCHIVE SUCCEED
2865 md5sum $f >/dev/null &
2867 wait_request_state $fid RESTORE STARTED
2869 mv $f1 $f || error "mv $f1 $f failed"
2870 # mv must not block during restore
2871 wait_request_state $fid RESTORE STARTED
2873 wait_request_state $fid RESTORE SUCCEED
2874 # check md5sum pgm finished
2875 local there=$(ps -o pid,comm hp $pid >/dev/null)
2876 [[ -z $there ]] || error "Restore initiator does not exit"
2878 local rc=$(wait $pid)
2879 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2882 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2886 run_test 35 "Overwrite file during restore"
2889 # test needs a running copytool
2894 local f=$DIR/$tdir/$tfile
2896 fid=$(make_custom_file_for_progress $f 39 1000000)
2897 [ $? != 0 ] && skip "not enough free space" && return
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2900 wait_request_state $fid ARCHIVE SUCCEED
2903 md5sum $f >/dev/null &
2905 wait_request_state $fid RESTORE STARTED
2908 # rm must not block during restore
2909 wait_request_state $fid RESTORE STARTED
2911 wait_request_state $fid RESTORE SUCCEED
2912 # check md5sum pgm finished
2913 local there=$(ps -o pid,comm hp $pid >/dev/null)
2915 error "Restore initiator does not exit"
2917 local rc=$(wait $pid)
2919 error "Restore initiator failed with $rc"
2923 run_test 36 "Move file during restore"
2926 # LU-5683: check that an archived dirty file can be rearchived.
2928 copytool_setup $SINGLEAGT $MOUNT2
2931 local f=$DIR/$tdir/$tfile
2934 fid=$(make_small $f) || error "cannot create small file"
2936 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2937 wait_request_state $fid ARCHIVE SUCCEED
2938 $LFS hsm_release $f || error "cannot release $f"
2940 # Allow previous archive request to expire from the actions log.
2941 wait_for_grace_delay
2944 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2947 wait_request_state $fid ARCHIVE SUCCEED
2951 run_test 37 "re-archive a dirty file"
2958 for n in $(seq 1 $count); do
2959 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2961 echo "$count archive requests submitted"
2965 local stream_count=4
2966 local file_count=100
2968 local f=$DIR/$tdir/$tfile
2973 for i in $(seq 1 $file_count); do
2974 for p in $(seq 1 $stream_count); do
2975 fid=$(copy_file /etc/hosts $f.$p.$i)
2978 # force copytool to use a local/temp archive dir to ensure best
2979 # performance vs remote/NFS mounts used in auto-tests
2980 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2983 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2985 # to be sure wait_all_done will not be mislead by previous tests
2987 wait_for_grace_delay
2989 # start archive streams in background (archive files in parallel)
2990 for p in $(seq 1 $stream_count); do
2991 multi_archive $f.$p $file_count &
2994 echo -n "Wait for all requests being enqueued..."
3000 run_test 40 "Parallel archive requests"
3003 # test needs a running copytool
3007 local f=$DIR/$tdir/$tfile
3008 local fid=$(copy_file /etc/motd $f 1)
3010 $LFS hsm_archive $f || error "could not archive file"
3011 wait_request_state $fid ARCHIVE SUCCEED
3012 check_hsm_flags $f "0x00000009"
3014 multiop_bg_pause $f O_c || error "multiop failed"
3018 client_up || client_up || true
3020 kill -USR1 $MULTIPID
3021 wait $MULTIPID || error "multiop close failed"
3023 check_hsm_flags $f "0x0000000b"
3027 run_test 52 "Opened for write file on an evicted client should be set dirty"
3030 # test needs a running copytool
3034 local f=$DIR/$tdir/$tfile
3035 local fid=$(copy_file /etc/motd $f 1)
3037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3038 error "could not archive file"
3039 wait_request_state $fid ARCHIVE SUCCEED
3040 check_hsm_flags $f "0x00000009"
3042 multiop_bg_pause $f o_c || error "multiop failed"
3046 client_up || client_up || true
3048 kill -USR1 $MULTIPID
3049 wait $MULTIPID || error "multiop close failed"
3051 check_hsm_flags $f "0x00000009"
3055 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3058 # test needs a running copytool
3062 local f=$DIR/$tdir/$tfile
3063 local fid=$(make_custom_file_for_progress $f 39 1000000)
3065 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3066 error "could not archive file"
3067 wait_request_state $fid ARCHIVE STARTED
3069 check_hsm_flags $f "0x00000001"
3071 # Avoid coordinator resending this request as soon it has failed.
3076 wait_request_state $fid ARCHIVE FAILED
3078 check_hsm_flags $f "0x00000003"
3083 run_test 54 "Write during an archive cancels it"
3086 # test needs a running copytool
3090 local f=$DIR/$tdir/$tfile
3091 local fid=$(make_custom_file_for_progress $f 39 1000000)
3093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3094 error "could not archive file"
3095 wait_request_state $fid ARCHIVE STARTED
3097 check_hsm_flags $f "0x00000001"
3099 # Avoid coordinator resending this request as soon it has failed.
3102 $TRUNCATE $f 1024 || error "truncate failed"
3104 wait_request_state $fid ARCHIVE FAILED
3106 check_hsm_flags $f "0x00000003"
3111 run_test 55 "Truncate during an archive cancels it"
3114 # test needs a running copytool
3118 local f=$DIR/$tdir/$tfile
3120 fid=$(make_custom_file_for_progress $f 39 1000000)
3121 [ $? != 0 ] && skip "not enough free space" && return
3123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3124 error "could not archive file"
3125 wait_request_state $fid ARCHIVE STARTED
3127 check_hsm_flags $f "0x00000001"
3129 # Change metadata and sync to be sure we are not changing only
3134 wait_request_state $fid ARCHIVE SUCCEED
3136 check_hsm_flags $f "0x00000009"
3140 run_test 56 "Setattr during an archive is ok"
3143 # Need one client for I/O, one for request
3144 needclients 2 || return 0
3146 # test needs a running copytool
3150 local f=$DIR/$tdir/test_archive_remote
3151 # Create a file on a remote node
3152 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3153 "count=2 conv=fsync"
3156 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3157 error "hsm_archive failed"
3158 local fid=$(path2fid $f)
3159 wait_request_state $fid ARCHIVE SUCCEED
3161 # Release and implicit restore it
3162 do_node $CLIENT2 "$LFS hsm_release $f" ||
3163 error "hsm_release failed"
3164 do_node $CLIENT2 "md5sum $f" ||
3165 error "hsm_restore failed"
3167 wait_request_state $fid RESTORE SUCCEED
3171 run_test 57 "Archive a file with dirty cache on another node"
3173 truncate_released_file() {
3177 local sz=$(stat -c %s $src_file)
3178 local f=$DIR/$tdir/$tfile
3179 local fid=$(copy_file $1 $f)
3183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3184 error "could not archive file"
3185 wait_request_state $fid ARCHIVE SUCCEED
3187 $LFS hsm_release $f || error "could not release file"
3189 $TRUNCATE $f $trunc_to || error "truncate failed"
3192 local sz1=$(stat -c %s $f)
3193 [[ $sz1 == $trunc_to ]] ||
3194 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3197 check_hsm_flags $f "0x0000000b"
3199 local state=$(get_request_state $fid RESTORE)
3200 [[ "$state" == "SUCCEED" ]] ||
3201 error "truncate $sz does not trig restore, state = $state"
3203 $TRUNCATE $ref $trunc_to
3204 cmp $ref $f || error "file data wrong after truncate"
3210 # test needs a running copytool
3215 local sz=$(stat -c %s /etc/passwd)
3217 echo "truncate up from $sz to $((sz*2))"
3218 truncate_released_file /etc/passwd $((sz*2))
3220 echo "truncate down from $sz to $((sz/2))"
3221 truncate_released_file /etc/passwd $((sz/2))
3223 echo "truncate to 0"
3224 truncate_released_file /etc/passwd 0
3228 run_test 58 "Truncate a released file will trigger restore"
3232 local server_version=$(lustre_version_code $SINGLEMDS)
3233 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3234 skip "Need MDS version at least 2.7.63" && return
3237 $MCREATE $DIR/$tfile || error "mcreate failed"
3238 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3239 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3240 fid=$(path2fid $DIR/$tfile)
3241 wait_request_state $fid ARCHIVE SUCCEED
3242 $LFS hsm_release $DIR/$tfile || error "release failed"
3245 run_test 59 "Release stripeless file with non-zero size"
3248 # This test validates the fix for LU-4512. Ensure that the -u
3249 # option changes the progress reporting interval from the
3250 # default (30 seconds) to the user-specified interval.
3252 local progress_timeout=$((interval * 4))
3254 # test needs a new running copytool
3256 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3259 local f=$DIR/$tdir/$tfile
3261 fid=$(make_custom_file_for_progress $f 10)
3262 [ $? != 0 ] && skip "not enough free space" && return
3265 local mdt=${MDT_PREFIX}${mdtidx}
3266 local mds=mds$((mdtidx + 1))
3268 # Wait for copytool to register
3269 wait_update_facet $mds \
3270 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3271 uuid 100 || error "coyptool failed to register with $mdt"
3273 local start_at=$(date +%s)
3274 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3275 error "could not archive file"
3277 local agent=$(facet_active_host $SINGLEAGT)
3278 local prefix=$TESTLOG_PREFIX
3279 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3280 local copytool_log=$prefix.copytool_log.$agent.log
3283 wait_update $agent \
3284 "grep -o start.copy $copytool_log" "start copy" 100 ||
3285 error "copytool failed to start"
3287 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3288 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3294 echo -n "Expecting a progress update within $progress_timeout seconds... "
3296 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3297 if [ $RESULT -gt 0 ]; then
3298 echo "$RESULT bytes copied in $WAIT seconds."
3300 elif [ $WAIT -ge $progress_timeout ]; then
3301 error "Timed out waiting for progress update!"
3304 WAIT=$((WAIT + sleep))
3308 local finish_at=$(date +%s)
3309 local elapsed=$((finish_at - start_at))
3311 # Ensure that the progress update occurred within the expected window.
3312 if [ $elapsed -lt $((interval - 1)) ]; then
3313 error "Expected progress update after at least $interval seconds"
3316 echo "Wait for on going archive hsm action to complete"
3317 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3318 echo "File archiving not completed even after 10 secs"
3323 run_test 60 "Changing progress update interval from default"
3326 # test needs a new running copytool
3328 copytool_monitor_setup
3329 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3331 # Just start and stop the copytool to generate events.
3334 # Wait for the copytool to register.
3335 wait_update --verbose $(facet_active_host mds1) \
3336 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3338 error "copytool failed to register with MDT0000"
3342 local REGISTER_EVENT
3343 local UNREGISTER_EVENT
3344 while read event; do
3345 local parsed=$(parse_json_event "$event")
3346 if [ -z "$parsed" ]; then
3347 error "Copytool sent malformed event: $event"
3351 if [ $event_type == "REGISTER" ]; then
3352 REGISTER_EVENT=$event
3353 elif [ $event_type == "UNREGISTER" ]; then
3354 UNREGISTER_EVENT=$event
3356 done < <(echo $"$(get_copytool_event_log)")
3358 if [ -z "$REGISTER_EVENT" ]; then
3359 error "Copytool failed to send register event to FIFO"
3362 if [ -z "$UNREGISTER_EVENT" ]; then
3363 error "Copytool failed to send unregister event to FIFO"
3366 copytool_monitor_cleanup
3367 echo "Register/Unregister events look OK."
3369 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3372 # Bump progress interval for livelier events.
3375 # test needs a new running copytool
3377 copytool_monitor_setup
3378 HSMTOOL_UPDATE_INTERVAL=$interval \
3379 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3382 local f=$DIR/$tdir/$tfile
3384 fid=$(make_custom_file_for_progress $f 39 1000000)
3385 [ $? != 0 ] && skip "not enough free space" && return
3387 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3388 error "could not archive file"
3389 wait_request_state $fid ARCHIVE SUCCEED
3391 local expected_fields="event_time data_fid source_fid"
3392 expected_fields+=" total_bytes current_bytes"
3396 while read event; do
3397 # Make sure we're not getting anything from previous events.
3398 for field in $expected_fields; do
3402 local parsed=$(parse_json_event "$event")
3403 if [ -z "$parsed" ]; then
3404 error "Copytool sent malformed event: $event"
3408 if [ $event_type == "ARCHIVE_START" ]; then
3411 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3414 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3418 # Do some simple checking of the progress update events.
3419 for expected_field in $expected_fields; do
3420 if [ -z ${!expected_field+x} ]; then
3421 error "Missing $expected_field field in event"
3425 if [ $total_bytes -eq 0 ]; then
3426 error "Expected total_bytes to be > 0"
3429 # These should be identical throughout an archive
3431 if [ $source_fid != $data_fid ]; then
3432 error "Expected source_fid to equal data_fid"
3434 done < <(echo $"$(get_copytool_event_log)")
3436 if [ -z "$START_EVENT" ]; then
3437 error "Copytool failed to send archive start event to FIFO"
3440 if [ -z "$FINISH_EVENT" ]; then
3441 error "Copytool failed to send archive finish event to FIFO"
3444 echo "Archive events look OK."
3448 copytool_monitor_cleanup
3450 run_test 71 "Copytool logs JSON archive events to FIFO"
3453 # Bump progress interval for livelier events.
3456 # test needs a new running copytool
3458 copytool_monitor_setup
3459 HSMTOOL_UPDATE_INTERVAL=$interval \
3460 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3461 local test_file=$HSMTOOL_MONITOR_DIR/file
3463 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3465 do_facet $SINGLEAGT "$cmd" ||
3466 error "cannot create $test_file on $SINGLEAGT"
3467 copy2archive $test_file $tdir/$tfile
3470 local f=$DIR/$tdir/$tfile
3471 import_file $tdir/$tfile $f
3472 f=$DIR2/$tdir/$tfile
3473 echo "Verifying released state: "
3474 check_hsm_flags $f "0x0000000d"
3476 local fid=$(path2fid $f)
3478 wait_request_state $fid RESTORE SUCCEED
3480 local expected_fields="event_time data_fid source_fid"
3481 expected_fields+=" total_bytes current_bytes"
3485 while read event; do
3486 # Make sure we're not getting anything from previous events.
3487 for field in $expected_fields; do
3491 local parsed=$(parse_json_event "$event")
3492 if [ -z "$parsed" ]; then
3493 error "Copytool sent malformed event: $event"
3497 if [ $event_type == "RESTORE_START" ]; then
3499 if [ $source_fid != $data_fid ]; then
3500 error "source_fid should == data_fid at start"
3503 elif [ $event_type == "RESTORE_FINISH" ]; then
3505 if [ $source_fid != $data_fid ]; then
3506 error "source_fid should == data_fid at finish"
3509 elif [ $event_type != "RESTORE_RUNNING" ]; then
3513 # Do some simple checking of the progress update events.
3514 for expected_field in $expected_fields; do
3515 if [ -z ${!expected_field+x} ]; then
3516 error "Missing $expected_field field in event"
3520 if [ $total_bytes -eq 0 ]; then
3521 error "Expected total_bytes to be > 0"
3524 # When a restore starts out, the data fid is the same as the
3525 # source fid. After the restore has gotten going, we learn
3526 # the new data fid. Once the restore has finished, the source
3527 # fid is set to the new data fid.
3529 # We test this because some monitoring software may depend on
3530 # this behavior. If it changes, then the consumers of these
3531 # events may need to be modified.
3532 if [ $source_fid == $data_fid ]; then
3533 error "source_fid should != data_fid during restore"
3535 done < <(echo $"$(get_copytool_event_log)")
3537 if [ -z "$START_EVENT" ]; then
3538 error "Copytool failed to send restore start event to FIFO"
3541 if [ -z "$FINISH_EVENT" ]; then
3542 error "Copytool failed to send restore finish event to FIFO"
3545 echo "Restore events look OK."
3549 copytool_monitor_cleanup
3553 run_test 72 "Copytool logs JSON restore events to FIFO"
3556 file_count=51 # Max number of files constrained by LNET message size
3557 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3558 local f=$DIR/$tdir/$tfile
3559 local FILELIST=/tmp/filelist.txt
3563 for i in $(seq 1 $file_count); do
3564 fid=$(copy_file /etc/hosts $f.$i)
3565 echo $f.$i >> $FILELIST
3567 # force copytool to use a local/temp archive dir to ensure best
3568 # performance vs remote/NFS mounts used in auto-tests
3569 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3572 local dai=$(get_hsm_param default_archive_id)
3573 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3575 # to be sure wait_all_done will not be mislead by previous tests
3577 wait_for_grace_delay
3578 $LFS hsm_archive --filelist $FILELIST ||
3579 error "cannot archive a file list"
3581 $LFS hsm_release --filelist $FILELIST ||
3582 error "cannot release a file list"
3583 $LFS hsm_restore --filelist $FILELIST ||
3584 error "cannot restore a file list"
3588 run_test 90 "Archive/restore a file list"
3590 double_verify_reset_hsm_param() {
3592 echo "Testing $HSM_PARAM.$p"
3593 local val=$(get_hsm_param $p)
3595 local val2=$(($val * 2))
3596 set_hsm_param $p $val2
3597 val=$(get_hsm_param $p)
3598 [[ $val == $val2 ]] ||
3599 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3600 echo "Set $p to 0 must failed"
3604 set_hsm_param $p $save
3606 if [[ $rc == 0 ]]; then
3607 error "we must not be able to set $HSM_PARAM.$p to 0"
3612 double_verify_reset_hsm_param loop_period
3613 double_verify_reset_hsm_param grace_delay
3614 double_verify_reset_hsm_param active_request_timeout
3615 double_verify_reset_hsm_param max_requests
3616 double_verify_reset_hsm_param default_archive_id
3618 run_test 100 "Set coordinator /proc tunables"
3625 run_test 102 "Verify coordinator control"
3628 # test needs a running copytool
3635 for i in $(seq 1 20); do
3636 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3642 echo "Current requests"
3643 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3644 $HSM_PARAM.actions |\
3645 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3647 [[ -z "$res" ]] || error "Some request have not been canceled"
3651 run_test 103 "Purge all requests"
3656 # test needs a running copytool
3660 local f=$DIR/$tdir/$tfile
3662 fid=$(make_custom_file_for_progress $f 39 1000000)
3663 [ $? != 0 ] && skip "not enough free space" && return
3665 # if cdt is on, it can serve too quickly the request
3667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3668 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3669 $HSM_PARAM.actions |\
3670 grep $fid | cut -f16 -d=")
3673 [[ "$data1" == "$DATAHEX" ]] ||
3674 error "Data field in records is ($data1) and not ($DATAHEX)"
3678 run_test 104 "Copy tool data field"
3685 for i in $(seq -w 1 10); do
3686 cp /etc/passwd $DIR/$tdir/$i
3687 $LFS hsm_archive $DIR/$tdir/$i
3689 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3690 $HSM_PARAM.actions |\
3691 grep WAITING | wc -l")
3694 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3695 $HSM_PARAM.actions |\
3696 grep WAITING | wc -l")
3699 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3700 error "Requests count after shutdown $reqcnt2 != "\
3701 "before shutdown $reqcnt1"
3703 run_test 105 "Restart of coordinator"
3706 # test needs a running copytool
3709 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3711 check_agent_registered $uuid
3713 search_copytools || error "No copytool found"
3716 check_agent_unregistered $uuid
3719 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3720 check_agent_registered $uuid
3724 run_test 106 "Copytool register/unregister"
3727 # test needs a running copytool
3729 # create and archive file
3731 local f1=$DIR/$tdir/$tfile
3732 local fid=$(copy_file /etc/passwd $f1)
3733 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3734 wait_request_state $fid ARCHIVE SUCCEED
3735 # shutdown and restart MDS
3737 # check the copytool still gets messages from MDT
3738 local f2=$DIR/$tdir/2
3739 local fid=$(copy_file /etc/passwd $f2)
3740 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3741 # main check of this sanity: this request MUST succeed
3742 wait_request_state $fid ARCHIVE SUCCEED
3745 run_test 107 "Copytool re-register after MDS restart"
3747 policy_set_and_test()
3751 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3752 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3753 [[ "$policy" == "$target" ]] ||
3754 error "Wrong policy after '$change': '$policy' != '$target'"
3758 # to force default policy setting if error
3759 CDT_POLICY_HAD_CHANGED=true
3761 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3762 local default="NonBlockingRestore [NoRetryAction]"
3763 [[ "$policy" == "$default" ]] ||
3764 error "default policy has changed,"\
3765 " '$policy' != '$default' update the test"
3766 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3767 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3768 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3769 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3770 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3771 # useless bacause we know but safer for futur changes to use real value
3772 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3773 echo "Next set_param must failed"
3774 policy_set_and_test "wrong" "$policy"
3777 echo "Back to default policy"
3778 cdt_set_sanity_policy
3780 run_test 109 "Policy display/change"
3783 # test needs a running copytool
3788 copy2archive /etc/passwd $tdir/$tfile
3790 local f=$DIR/$tdir/$tfile
3791 import_file $tdir/$tfile $f
3792 local fid=$(path2fid $f)
3794 cdt_set_non_blocking_restore
3799 wait_request_state $fid RESTORE SUCCEED
3800 cdt_clear_non_blocking_restore
3804 error "md5sum returns $st != 1, "\
3805 "should also perror ENODATA (No data available)"
3809 run_test 110a "Non blocking restore policy (import case)"
3812 # test needs a running copytool
3816 local f=$DIR/$tdir/$tfile
3817 local fid=$(copy_file /etc/passwd $f)
3818 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3819 wait_request_state $fid ARCHIVE SUCCEED
3822 cdt_set_non_blocking_restore
3827 wait_request_state $fid RESTORE SUCCEED
3828 cdt_clear_non_blocking_restore
3832 error "md5sum returns $st != 1, "\
3833 "should also perror ENODATA (No data available)"
3837 run_test 110b "Non blocking restore policy (release case)"
3840 # test needs a running copytool
3844 copy2archive /etc/passwd $tdir/$tfile
3846 local f=$DIR/$tdir/$tfile
3848 import_file $tdir/$tfile $f
3849 local fid=$(path2fid $f)
3853 copytool_remove_backend $fid
3856 wait_request_state $fid RESTORE FAILED
3863 [[ $st == 0 ]] || error "Restore does not failed"
3867 run_test 111a "No retry policy (import case), restore will error"\
3868 " (No such file or directory)"
3871 # test needs a running copytool
3875 local f=$DIR/$tdir/$tfile
3876 local fid=$(copy_file /etc/passwd $f)
3878 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3879 wait_request_state $fid ARCHIVE SUCCEED
3882 copytool_remove_backend $fid
3885 wait_request_state $fid RESTORE FAILED
3892 [[ $st == 0 ]] || error "Restore does not failed"
3896 run_test 111b "No retry policy (release case), restore will error"\
3897 " (No such file or directory)"
3900 # test needs a running copytool
3904 local f=$DIR/$tdir/$tfile
3905 local fid=$(copy_file /etc/passwd $f)
3907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3908 local l=$($LFS hsm_action $f)
3910 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3914 wait_request_state $fid ARCHIVE SUCCEED
3917 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3921 run_test 112 "State of recorded request"
3924 # test needs a running copytool
3928 local f=$DIR/$tdir/$tfile
3930 fid=$(make_custom_file_for_progress $f 103 1048576)
3931 [ $? != 0 ] && skip "not enough free space" && return
3933 # test with cdt on is made in test_221
3935 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3936 # wait archive to register at CDT
3937 wait_request_state $fid ARCHIVE WAITING
3940 wait_request_state $fid ARCHIVE CANCELED
3941 wait_request_state $fid CANCEL SUCCEED
3945 run_test 200 "Register/Cancel archive"
3948 # test needs a running copytool
3952 local f=$DIR/$tdir/$tfile
3953 make_archive $tdir/$tfile
3954 import_file $tdir/$tfile $f
3955 local fid=$(path2fid $f)
3957 # test with cdt on is made in test_222
3960 # wait restore to register at CDT
3961 wait_request_state $fid RESTORE WAITING
3964 wait_request_state $fid RESTORE CANCELED
3965 wait_request_state $fid CANCEL SUCCEED
3969 run_test 201 "Register/Cancel restore"
3972 # test needs a running copytool
3976 local f=$DIR/$tdir/$tfile
3978 fid=$(make_custom_file_for_progress $f 39 1000000)
3979 [ $? != 0 ] && skip "not enough free space" && return
3981 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3982 wait_request_state $fid ARCHIVE SUCCEED
3986 # wait remove to register at CDT
3987 wait_request_state $fid REMOVE WAITING
3990 wait_request_state $fid REMOVE CANCELED
3994 run_test 202 "Register/Cancel remove"
3997 # test needs a running copytool
4002 local f=$DIR/$tdir/$tfile
4003 local fid=$(copy_file /etc/passwd $f)
4007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4008 wait_request_state $fid ARCHIVE SUCCEED
4010 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4014 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4018 run_test 220 "Changelog for archive"
4021 # test needs a running copytool
4026 local f=$DIR/$tdir/$tfile
4027 local fid=$(copy_file /etc/passwd $f)
4031 # block copytool operations to allow for HSM request to be
4032 # submitted and file be unlinked (CDT will find object removed)
4035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4041 wait_request_state $fid ARCHIVE FAILED
4043 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4048 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4052 run_test 220a "Changelog for failed archive"
4055 # test needs a running copytool
4060 local f=$DIR/$tdir/$tfile
4062 fid=$(make_custom_file_for_progress $f 103 1048576)
4063 [ $? != 0 ] && skip "not enough free space" && return
4067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4068 wait_request_state $fid ARCHIVE STARTED
4070 wait_request_state $fid ARCHIVE CANCELED
4071 wait_request_state $fid CANCEL SUCCEED
4073 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4076 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4080 run_test 221 "Changelog for archive canceled"
4083 # test needs a running copytool
4087 copy2archive /etc/passwd $tdir/$tfile
4089 local f=$DIR/$tdir/$tfile
4090 import_file $tdir/$tfile $f
4091 local fid=$(path2fid $f)
4096 wait_request_state $fid RESTORE SUCCEED
4098 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4101 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4105 run_test 222a "Changelog for explicit restore"
4108 # test needs a running copytool
4112 local f=$DIR/$tdir/$tfile
4113 local fid=$(copy_file /etc/passwd $f)
4116 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4117 wait_request_state $fid ARCHIVE SUCCEED
4122 wait_request_state $fid RESTORE SUCCEED
4124 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4127 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4131 run_test 222b "Changelog for implicit restore"
4134 # test needs a running copytool
4138 copy2archive /etc/passwd $tdir/$tfile
4140 local f=$DIR/$tdir/$tfile
4141 import_file $tdir/$tfile $f
4142 local fid=$(path2fid $f)
4146 # block copytool operations to allow for HSM request to be
4147 # submitted and file be unlinked (CDT will find object removed)
4155 wait_request_state $fid RESTORE FAILED
4157 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4161 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4165 run_test 222c "Changelog for failed explicit restore"
4168 # test needs a running copytool
4172 local f=$DIR/$tdir/$tfile
4173 local fid=$(copy_file /etc/passwd $f)
4176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4177 wait_request_state $fid ARCHIVE SUCCEED
4180 copytool_remove_backend $fid
4183 wait_request_state $fid RESTORE FAILED
4185 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4189 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4193 run_test 222d "Changelog for failed implicit restore"
4196 # test needs a running copytool
4201 local f=$DIR/$tdir/$tfile
4202 make_archive $tdir/$tfile
4206 import_file $tdir/$tfile $f
4207 local fid=$(path2fid $f)
4210 wait_request_state $fid RESTORE STARTED
4212 wait_request_state $fid RESTORE CANCELED
4213 wait_request_state $fid CANCEL SUCCEED
4215 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4218 [[ $flags == $target ]] ||
4219 error "Changelog flag is $flags not $target"
4223 run_test 223a "Changelog for restore canceled (import case)"
4226 # test needs a running copytool
4231 local f=$DIR/$tdir/$tfile
4233 fid=$(make_custom_file_for_progress $f 39 1000000)
4234 [ $? != 0 ] && skip "not enough free space" && return
4237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4238 wait_request_state $fid ARCHIVE SUCCEED
4241 wait_request_state $fid RESTORE STARTED
4243 wait_request_state $fid RESTORE CANCELED
4244 wait_request_state $fid CANCEL SUCCEED
4246 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4249 [[ $flags == $target ]] ||
4250 error "Changelog flag is $flags not $target"
4254 run_test 223b "Changelog for restore canceled (release case)"
4257 # test needs a running copytool
4262 local f=$DIR/$tdir/$tfile
4263 local fid=$(copy_file /etc/passwd $f)
4266 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4267 wait_request_state $fid ARCHIVE SUCCEED
4270 wait_request_state $fid REMOVE SUCCEED
4272 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4275 [[ $flags == $target ]] ||
4276 error "Changelog flag is $flags not $target"
4280 run_test 224 "Changelog for remove"
4283 # test needs a running copytool
4288 local f=$DIR/$tdir/$tfile
4289 local fid=$(copy_file /etc/passwd $f)
4292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4293 wait_request_state $fid ARCHIVE SUCCEED
4295 copytool_remove_backend $fid
4297 # block copytool operations to allow for HSM request to be
4298 # submitted and file be unlinked (CDT will find object removed)
4306 wait_request_state $fid REMOVE FAILED
4308 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4312 [[ $flags == $target ]] ||
4313 error "Changelog flag is $flags not $target"
4317 run_test 224a "Changelog for failed remove"
4320 # test needs a running copytool
4323 # test is not usable because remove request is too fast
4324 # so it is always finished before cancel can be done ...
4325 echo "Test disabled"
4330 local f=$DIR/$tdir/$tfile
4332 fid=$(make_custom_file_for_progress $f 39 1000000)
4333 [ $? != 0 ] && skip "not enough free space" && return
4336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4337 wait_request_state $fid ARCHIVE SUCCEED
4339 # if cdt is on, it can serve too quickly the request
4344 wait_request_state $fid REMOVE CANCELED
4345 wait_request_state $fid CANCEL SUCCEED
4347 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4348 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4349 tail -n 1 | awk '{print $5}')
4352 [[ $flags == $target ]] ||
4353 error "Changelog flag is $flags not $target"
4357 run_test 225 "Changelog for remove canceled"
4360 # test needs a running copytool
4365 local f1=$DIR/$tdir/$tfile-1
4366 local f2=$DIR/$tdir/$tfile-2
4367 local f3=$DIR/$tdir/$tfile-3
4368 local fid1=$(copy_file /etc/passwd $f1)
4369 local fid2=$(copy_file /etc/passwd $f2)
4370 copy_file /etc/passwd $f3
4373 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4374 wait_request_state $fid1 ARCHIVE SUCCEED
4376 $LFS hsm_archive $f2
4377 wait_request_state $fid2 ARCHIVE SUCCEED
4379 rm $f1 || error "rm $f1 failed"
4381 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4384 [[ $flags == $target ]] ||
4385 error "Changelog flag is $flags not $target"
4387 mv $f3 $f2 || error "mv $f3 $f2 failed"
4389 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4392 [[ $flags == $target ]] ||
4393 error "Changelog flag is $flags not $target"
4397 run_test 226 "changelog for last rm/mv with exiting archive"
4399 check_flags_changes() {
4407 $LFS hsm_set --$hsm_flag $f ||
4408 error "Cannot set $hsm_flag on $f"
4409 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4410 local seen=${#flags[*]}
4412 [[ $seen == $cnt ]] ||
4413 error "set $hsm_flag: Changelog events $seen != $cnt"
4414 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4415 error "set $hsm_flag: Changelog flags are "\
4416 "${flags[$((cnt - 1))]} not $target"
4418 $LFS hsm_clear --$hsm_flag $f ||
4419 error "Cannot clear $hsm_flag on $f"
4420 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4423 [[ $cnt == $seen ]] ||
4424 error "clear $hsm_flag: Changelog events $seen != $cnt"
4426 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4427 error "clear $hsm_flag: Changelog flag is "\
4428 "${flags[$((cnt - 1))]} not $target"
4432 # test needs a running copytool
4439 for i in norelease noarchive exists archived
4441 local f=$DIR/$tdir/$tfile-$i
4442 local fid=$(copy_file /etc/passwd $f)
4443 check_flags_changes $f $fid $i 0 1
4446 f=$DIR/$tdir/$tfile---lost
4447 fid=$(copy_file /etc/passwd $f)
4448 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4449 wait_request_state $fid ARCHIVE SUCCEED
4450 check_flags_changes $f $fid lost 3 1
4454 run_test 227 "changelog when explicit setting of HSM flags"
4457 # test needs a running copytool
4460 local fid=$(make_small_sync $DIR/$tfile)
4461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4462 wait_request_state $fid ARCHIVE SUCCEED
4464 $LFS hsm_release $DIR/$tfile
4465 check_hsm_flags $DIR/$tfile "0x0000000d"
4467 filefrag $DIR/$tfile | grep " 1 extent found" ||
4468 error "filefrag on released file must return only one extent"
4470 # only newer versions of cp detect sparse files by stat/FIEMAP
4472 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4473 error "copying $DIR/$tfile"
4474 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4476 $LFS hsm_release $DIR/$tfile
4477 check_hsm_flags $DIR/$tfile "0x0000000d"
4479 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4481 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4483 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4484 error "comparing untarred $DIR/$tfile"
4486 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4487 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4490 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4493 # test needs a running copytool
4497 local maxrequest=$(get_hsm_param max_requests)
4498 local rqcnt=$(($maxrequest * 3))
4502 for i in $(seq -w 1 $rqcnt); do
4504 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4506 # we do it in 2 steps, so all requests arrive at the same time
4507 for i in $(seq -w 1 $rqcnt); do
4508 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4513 while [[ $cnt != 0 || $wt != 0 ]]; do
4515 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4516 $HSM_PARAM.actions |\
4517 grep STARTED | grep -v CANCEL | wc -l")
4518 [[ $cnt -le $maxrequest ]] ||
4519 error "$cnt > $maxrequest too many started requests"
4520 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4521 $HSM_PARAM.actions |\
4522 grep WAITING | wc -l")
4523 echo "max=$maxrequest started=$cnt waiting=$wt"
4528 run_test 250 "Coordinator max request"
4531 # test needs a running copytool
4535 local f=$DIR/$tdir/$tfile
4537 fid=$(make_custom_file_for_progress $f 103 1048576)
4538 [ $? != 0 ] && skip "not enough free space" && return
4541 # to have a short test
4542 local old_to=$(get_hsm_param active_request_timeout)
4543 set_hsm_param active_request_timeout 4
4544 # to be sure the cdt will wake up frequently so
4545 # it will be able to cancel the "old" request
4546 local old_loop=$(get_hsm_param loop_period)
4547 set_hsm_param loop_period 2
4550 # clear locks to avoid extra delay caused by flush/cancel
4551 # and thus prevent early copytool death to timeout.
4552 cancel_lru_locks osc
4554 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4555 wait_request_state $fid ARCHIVE STARTED
4557 wait_request_state $fid ARCHIVE CANCELED
4559 set_hsm_param active_request_timeout $old_to
4560 set_hsm_param loop_period $old_loop
4564 run_test 251 "Coordinator request timeout"
4567 # the only way to test ondisk conf is to restart MDS ...
4568 echo "Stop coordinator and remove coordinator state at mount"
4571 # clean on disk conf set by default
4572 cdt_clear_mount_state
4573 cdt_check_state stopped
4575 # check cdt still off after umount/remount
4577 cdt_check_state stopped
4579 echo "Set coordinator start at mount, and start coordinator"
4580 cdt_set_mount_state enabled
4583 cdt_check_state enabled
4585 # check cdt still on after umount/remount
4587 cdt_check_state enabled
4589 # we are back to original state (cdt started at mount)
4591 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4594 local ai=$(get_hsm_param default_archive_id)
4595 local new=$((ai + 1))
4597 set_hsm_param default_archive_id $new -P
4599 local res=$(get_hsm_param default_archive_id)
4602 set_hsm_param default_archive_id "" "-P -d"
4604 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4606 run_test 301 "HSM tunnable are persistent"
4609 local ai=$(get_hsm_param default_archive_id)
4610 local new=$((ai + 1))
4615 set_hsm_param default_archive_id $new -P
4618 for mdtno in $(seq 1 $MDSCOUNT); do
4623 cdt_check_state enabled
4625 local res=$(get_hsm_param default_archive_id)
4628 set_hsm_param default_archive_id "" "-P -d"
4630 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4632 run_test 302 "HSM tunnable are persistent when CDT is off"
4635 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4641 local dir_mdt0=$DIR/$tdir/mdt0
4642 local dir_mdt1=$DIR/$tdir/mdt1
4644 # create 1 dir per MDT
4645 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4646 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4648 # create 1 file in each MDT
4649 local fid1=$(make_small $dir_mdt0/$tfile)
4650 local fid2=$(make_small $dir_mdt1/$tfile)
4652 # check that hsm request on mdt0 is sent to the right MDS
4653 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4654 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4655 echo "archive successful on mdt0"
4657 # check that hsm request on mdt1 is sent to the right MDS
4658 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4659 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4660 echo "archive successful on mdt1"
4663 # clean test files and directories
4664 rm -rf $dir_mdt0 $dir_mdt1
4666 run_test 400 "Single request is sent to the right MDT"
4669 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4675 local dir_mdt0=$DIR/$tdir/mdt0
4676 local dir_mdt1=$DIR/$tdir/mdt1
4678 # create 1 dir per MDT
4679 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4680 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4682 # create 1 file in each MDT
4683 local fid1=$(make_small $dir_mdt0/$tfile)
4684 local fid2=$(make_small $dir_mdt1/$tfile)
4686 # check that compound requests are shunt to the rights MDTs
4687 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4688 error "lfs hsm_archive"
4689 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4690 echo "archive successful on mdt0"
4691 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4692 echo "archive successful on mdt1"
4695 # clean test files and directories
4696 rm -rf $dir_mdt0 $dir_mdt1
4698 run_test 401 "Compound requests split and sent to their respective MDTs"
4700 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4705 local node=$(facet_active_host $facet)
4707 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4708 awk '{print $4}'); do
4709 echo "$3 $mdc on $node"
4710 do_facet $facet "$LCTL --device $mdc $state" || return 1
4715 # make sure there is no running copytool
4718 # deactivate all mdc on agent1
4719 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4721 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4723 check_agent_unregistered "uuid" # match any agent
4725 # no expected running copytool
4726 search_copytools $agent && error "Copytool start should have failed"
4729 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4731 run_test 402a "Copytool start fails if all MDTs are inactive"
4738 local f=$DIR/$tdir/$tfile
4739 touch $f || error "touch $f failed"
4740 local fid=$(path2fid $f)
4742 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4743 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4744 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4746 # give time for CDT to send request and to keep it for retry
4747 wait_for_loop_period
4749 wait_request_state $fid ARCHIVE WAITING
4751 do_facet $SINGLEAGT lctl set_param fail_loc=0
4753 # request should succeed now
4754 wait_request_state $fid ARCHIVE SUCCEED
4758 run_test 402b "CDT must retry request upon slow start of CT"
4761 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4763 # make sure there is no running copytool
4766 local agent=$(facet_active_host $SINGLEAGT)
4768 # deactivate all mdc for MDT0001
4769 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4772 local uuid=$(get_agent_uuid $agent)
4773 # check the agent is registered on MDT0000, and not on MDT0001
4774 check_agent_registered_by_mdt $uuid 0
4775 check_agent_unregistered_by_mdt $uuid 1
4777 # check running copytool process
4778 search_copytools $agent || error "No running copytools on $agent"
4780 # reactivate all mdc for MDT0001
4781 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4783 # make sure the copytool is now registered to all MDTs
4784 check_agent_registered $uuid
4788 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4791 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4795 # create files on both MDT0000 and MDT0001
4798 local dir_mdt0=$DIR/$tdir/mdt0
4799 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4801 # create 1 file on mdt0
4802 local fid1=$(make_small $dir_mdt0/$tfile)
4804 # deactivate all mdc for MDT0001
4805 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4807 # send an HSM request for files in MDT0000
4808 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4810 # check for completion of files in MDT0000
4811 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4812 echo "archive successful on mdt0"
4814 # reactivate all mdc for MDT0001
4815 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4818 # clean test files and directories
4821 run_test 404 "Inactive MDT does not block requests for active MDTs"
4824 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4830 local striped_dir=$DIR/$tdir/striped_dir
4832 # create striped dir on all of MDTs
4833 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4835 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4836 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4837 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4838 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4840 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4841 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4842 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4843 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4845 # check that compound requests are shunt to the rights MDTs
4846 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4847 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4848 error "lfs hsm_archive"
4850 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4851 echo "archive successful on $fid1"
4852 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4853 echo "archive successful on $fid2"
4854 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4855 echo "archive successful on $fid3"
4856 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4857 echo "archive successful on $fid4"
4859 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4860 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4861 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4862 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4864 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4865 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4866 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4867 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4871 run_test 405 "archive and release under striped directory"
4874 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4876 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4877 skip "need MDS version at least 2.7.64" && return 0
4884 fid=$(make_small $DIR/$tdir/$tfile)
4887 $LFS hsm_archive $DIR/$tdir/$tfile
4888 wait_request_state "$fid" ARCHIVE SUCCEED
4889 $LFS hsm_release $DIR/$tdir/$tfile
4891 # Should migrate $tdir but not $tfile.
4892 $LFS mv -M1 $DIR/$tdir &&
4893 error "migrating HSM an archived file should fail"
4895 $LFS hsm_restore $DIR/$tdir/$tfile
4896 wait_request_state "$fid" RESTORE SUCCEED
4898 $LFS hsm_remove $DIR/$tdir/$tfile
4899 wait_request_state "$fid" REMOVE SUCCEED
4901 cat $DIR/$tdir/$tfile > /dev/null ||
4902 error "cannot read $DIR/$tdir/$tfile"
4904 $LFS mv -M1 $DIR/$tdir ||
4905 error "cannot complete migration after HSM remove"
4907 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4908 if ((mdt_index != 1)); then
4909 error "expected MDT index 1, got $mdt_index"
4912 # Refresh fid after migration.
4913 fid=$(path2fid $DIR/$tdir/$tfile)
4916 $LFS hsm_archive $DIR/$tdir/$tfile
4917 wait_request_state "$fid" ARCHIVE SUCCEED 1
4919 lctl set_param debug=+trace
4920 $LFS hsm_release $DIR/$tdir/$tfile ||
4921 error "cannot release $DIR/$tdir/$tfile"
4923 $LFS hsm_restore $DIR/$tdir/$tfile
4924 wait_request_state "$fid" RESTORE SUCCEED 1
4926 cat $DIR/$tdir/$tfile > /dev/null ||
4927 error "cannot read $DIR/$tdir/$tfile"
4931 run_test 406 "attempting to migrate HSM archived files is safe"
4935 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4936 skip "HSM migrate is not supported" && return
4938 # Stop the existing copytool
4941 test_mkdir -p $DIR/$tdir
4942 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4944 run_test 500 "various LLAPI HSM tests"
4949 check_and_cleanup_lustre