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 local f=$DIR/$tdir/$tfile
914 # New files are not dirty
915 check_hsm_flags $f "0x00000000"
917 # For test, we simulate an archived file.
918 $LFS hsm_set --exists $f || error "user could not change hsm flags"
919 check_hsm_flags $f "0x00000001"
921 # chmod do not put the file dirty
922 chmod 600 $f || error "could not chmod test file"
923 check_hsm_flags $f "0x00000001"
925 # chown do not put the file dirty
926 chown $RUNAS_ID $f || error "could not chown test file"
927 check_hsm_flags $f "0x00000001"
929 # truncate put the file dirty
930 $TRUNCATE $f 1 || error "could not truncate test file"
931 check_hsm_flags $f "0x00000003"
933 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
934 check_hsm_flags $f "0x00000001"
936 run_test 2 "Check file dirtyness when doing setattr"
942 # New files are not dirty
944 check_hsm_flags $f "0x00000000"
946 # For test, we simulate an archived file.
947 $LFS hsm_set --exists $f ||
948 error "user could not change hsm flags"
949 check_hsm_flags $f "0x00000001"
951 # Reading a file, does not set dirty
952 cat $f > /dev/null || error "could not read file"
953 check_hsm_flags $f "0x00000001"
955 # Open for write without modifying data, does not set dirty
956 openfile -f O_WRONLY $f || error "could not open test file"
957 check_hsm_flags $f "0x00000001"
959 # Append to a file sets it dirty
960 cp -p /etc/passwd $f.append || error "could not create file"
961 $LFS hsm_set --exists $f.append ||
962 error "user could not change hsm flags"
963 dd if=/etc/passwd of=$f.append bs=1 count=3\
964 conv=notrunc oflag=append status=noxfer ||
965 file_creation_failure dd $f.append $?
966 check_hsm_flags $f.append "0x00000003"
968 # Modify a file sets it dirty
969 cp -p /etc/passwd $f.modify || error "could not create file"
970 $LFS hsm_set --exists $f.modify ||
971 error "user could not change hsm flags"
972 dd if=/dev/zero of=$f.modify bs=1 count=3\
973 conv=notrunc status=noxfer ||
974 file_creation_failure dd $f.modify $?
975 check_hsm_flags $f.modify "0x00000003"
977 # Open O_TRUNC sets dirty
978 cp -p /etc/passwd $f.trunc || error "could not create file"
979 $LFS hsm_set --exists $f.trunc ||
980 error "user could not change hsm flags"
981 cp /etc/group $f.trunc || error "could not override a file"
982 check_hsm_flags $f.trunc "0x00000003"
984 # Mmapped a file sets dirty
985 cp -p /etc/passwd $f.mmap || error "could not create file"
986 $LFS hsm_set --exists $f.mmap ||
987 error "user could not change hsm flags"
988 multiop $f.mmap OSMWUc || error "could not mmap a file"
989 check_hsm_flags $f.mmap "0x00000003"
991 run_test 3 "Check file dirtyness when opening for write"
995 local f=$DIR/$tdir/$tfile
996 local fid=$(make_small $f)
999 local st=$(get_request_state $fid CANCEL)
1000 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1002 run_test 4 "Useless cancel must not be registered"
1005 # test needs a running copytool
1009 local f=$DIR/$tdir/$tfile
1010 local fid=$(copy_file /etc/passwd $f)
1012 wait_request_state $fid ARCHIVE SUCCEED
1014 check_hsm_flags $f "0x00000009"
1018 run_test 8 "Test default archive number"
1021 # we do not use the default one to be sure
1022 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1024 copytool_setup $SINGLEAGT $MOUNT $new_an
1026 # give time for CT to register with MDTs
1027 sleep $(($MDSCOUNT*2))
1028 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1029 check_agent_registered $uuid
1032 local f=$DIR/$tdir/$tfile
1033 local fid=$(copy_file /etc/passwd $f)
1034 $LFS hsm_archive --archive $new_an $f
1035 wait_request_state $fid ARCHIVE SUCCEED
1037 check_hsm_flags $f "0x00000009"
1041 run_test 9 "Use of explicit archive number, with dedicated copytool"
1044 needclients 3 || return 0
1050 copytool_cleanup $(comma_list $(agts_nodes))
1052 # start all of the copytools
1053 for n in $(seq $AGTCOUNT); do
1054 copytool_setup agt$n
1057 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1060 for n in $(seq $AGTCOUNT); do
1061 file=$DIR/$tdir/$tfile.$n
1062 fid=$(make_small $file)
1064 $LFS hsm_archive $file || error "could not archive file $file"
1065 wait_request_state $fid ARCHIVE SUCCEED
1066 check_hsm_flags $file "0x00000009"
1070 copytool_cleanup $(comma_list $(agts_nodes))
1072 run_test 9a "Multiple remote agents"
1075 # test needs a running copytool
1078 mkdir -p $DIR/$tdir/d1
1079 local f=$DIR/$tdir/$tfile
1080 local fid=$(copy_file /etc/hosts $f)
1081 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1082 error "hsm_archive failed"
1083 wait_request_state $fid ARCHIVE SUCCEED
1085 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1086 error "fid $fid not in archive $HSM_ARCHIVE"
1087 echo "Verifying content"
1088 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1089 echo "Verifying hsm state "
1090 check_hsm_flags $f "0x00000009"
1092 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1093 local st=$(get_hsm_archive_id $f)
1094 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1095 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1100 run_test 10a "Archive a file"
1103 # test needs a running copytool
1107 local f=$DIR/$tdir/$tfile
1108 local fid=$(copy_file /etc/hosts $f)
1109 $LFS hsm_archive $f || error "archive request failed"
1110 wait_request_state $fid ARCHIVE SUCCEED
1112 $LFS hsm_archive $f || error "archive of non dirty file failed"
1113 local cnt=$(get_request_count $fid ARCHIVE)
1114 [[ "$cnt" == "1" ]] ||
1115 error "archive of non dirty file must not make a request"
1119 run_test 10b "Archive of non dirty file must work without doing request"
1122 # test needs a running copytool
1126 local f=$DIR/$tdir/$tfile
1127 local fid=$(copy_file /etc/hosts $f)
1128 $LFS hsm_set --noarchive $f
1129 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1133 run_test 10c "Check forbidden archive"
1136 # test needs a running copytool
1140 local f=$DIR/$tdir/$tfile
1141 local fid=$(copy_file /etc/hosts $f)
1142 $LFS hsm_archive $f || error "cannot archive $f"
1143 wait_request_state $fid ARCHIVE SUCCEED
1145 local ar=$(get_hsm_archive_id $f)
1146 local dflt=$(get_hsm_param default_archive_id)
1147 [[ $ar == $dflt ]] ||
1148 error "archived file is not on default archive: $ar != $dflt"
1152 run_test 10d "Archive a file on the default archive id"
1156 copy2archive /etc/hosts $tdir/$tfile
1157 local f=$DIR/$tdir/$tfile
1159 import_file $tdir/$tfile $f
1160 echo -n "Verifying released state: "
1161 check_hsm_flags $f "0x0000000d"
1163 local LSZ=$(stat -c "%s" $f)
1164 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1166 echo "Verifying imported size $LSZ=$ASZ"
1167 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1168 echo -n "Verifying released pattern: "
1169 local PTRN=$($GETSTRIPE -L $f)
1171 [[ $PTRN == 80000001 ]] || error "Is not released"
1172 local fid=$(path2fid $f)
1173 echo "Verifying new fid $fid in archive"
1175 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1176 error "fid $fid not in archive $HSM_ARCHIVE"
1178 run_test 11a "Import a file"
1181 # test needs a running copytool
1185 local f=$DIR/$tdir/$tfile
1186 local fid=$(copy_file /etc/hosts $f)
1187 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1188 error "hsm_archive failed"
1189 wait_request_state $fid ARCHIVE SUCCEED
1191 local FILE_HASH=$(md5sum $f)
1196 echo "$FILE_HASH" | md5sum -c
1198 [[ $? -eq 0 ]] || error "Restored file differs"
1202 run_test 11b "Import a deleted file using its FID"
1205 # test needs a running copytool
1209 copy2archive /etc/hosts $tdir/$tfile
1211 local f=$DIR/$tdir/$tfile
1212 import_file $tdir/$tfile $f
1213 local f2=$DIR2/$tdir/$tfile
1214 echo "Verifying released state: "
1215 check_hsm_flags $f2 "0x0000000d"
1217 local fid=$(path2fid $f2)
1218 $LFS hsm_restore $f2
1219 wait_request_state $fid RESTORE SUCCEED
1221 echo "Verifying file state: "
1222 check_hsm_flags $f2 "0x00000009"
1224 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1226 [[ $? -eq 0 ]] || error "Restored file differs"
1230 run_test 12a "Restore an imported file explicitly"
1233 # test needs a running copytool
1237 copy2archive /etc/hosts $tdir/$tfile
1239 local f=$DIR/$tdir/$tfile
1240 import_file $tdir/$tfile $f
1241 echo "Verifying released state: "
1242 check_hsm_flags $f "0x0000000d"
1244 cat $f > /dev/null || error "File read failed"
1246 echo "Verifying file state after restore: "
1247 check_hsm_flags $f "0x00000009"
1249 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1251 [[ $? -eq 0 ]] || error "Restored file differs"
1255 run_test 12b "Restore an imported file implicitly"
1258 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1260 # test needs a running copytool
1264 local f=$DIR/$tdir/$tfile
1265 $LFS setstripe -c 2 $f
1267 fid=$(make_custom_file_for_progress $f 5)
1268 [ $? != 0 ] && skip "not enough free space" && return
1270 local FILE_CRC=$(md5sum $f)
1272 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1273 wait_request_state $fid ARCHIVE SUCCEED
1274 $LFS hsm_release $f || error "release $f failed"
1276 echo "$FILE_CRC" | md5sum -c
1278 [[ $? -eq 0 ]] || error "Restored file differs"
1282 run_test 12c "Restore a file with stripe of 2"
1285 # test needs a running copytool
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/hosts $f)
1292 $LFS hsm_restore $f || error "restore of non archived file failed"
1293 local cnt=$(get_request_count $fid RESTORE)
1294 [[ "$cnt" == "0" ]] ||
1295 error "restore non archived must not make a request"
1296 $LFS hsm_archive $f ||
1297 error "archive request failed"
1298 wait_request_state $fid ARCHIVE SUCCEED
1299 $LFS hsm_restore $f ||
1300 error "restore of non released file failed"
1301 local cnt=$(get_request_count $fid RESTORE)
1302 [[ "$cnt" == "0" ]] ||
1303 error "restore a non dirty file must not make a request"
1307 run_test 12d "Restore of a non archived, non released file must work"\
1308 " without doing request"
1311 # test needs a running copytool
1314 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1315 local f=$DIR/$tdir/$tfile
1316 local fid=$(copy_file /etc/hosts $f)
1317 $LFS hsm_archive $f || error "archive request failed"
1318 wait_request_state $fid ARCHIVE SUCCEED
1321 cat /etc/hosts >> $f
1325 $LFS hsm_restore $f && error "restore a dirty file must fail"
1329 run_test 12e "Check forbidden restore"
1332 # test needs a running copytool
1336 local f=$DIR/$tdir/$tfile
1337 local fid=$(copy_file /etc/hosts $f)
1339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1340 wait_request_state $fid ARCHIVE SUCCEED
1341 $LFS hsm_release $f || error "release of $f failed"
1343 wait_request_state $fid RESTORE SUCCEED
1345 echo -n "Verifying file state: "
1346 check_hsm_flags $f "0x00000009"
1348 diff -q /etc/hosts $f
1350 [[ $? -eq 0 ]] || error "Restored file differs"
1354 run_test 12f "Restore a released file explicitly"
1357 # test needs a running copytool
1361 local f=$DIR/$tdir/$tfile
1362 local fid=$(copy_file /etc/hosts $f)
1364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1365 wait_request_state $fid ARCHIVE SUCCEED
1366 $LFS hsm_release $f || error "release of $f failed"
1368 diff -q /etc/hosts $f
1371 # we check we had a restore done
1372 wait_request_state $fid RESTORE SUCCEED
1374 [[ $st -eq 0 ]] || error "Restored file differs"
1378 run_test 12g "Restore a released file implicitly"
1381 needclients 2 || return 0
1383 # test needs a running copytool
1387 local f=$DIR/$tdir/$tfile
1388 local fid=$(copy_file /etc/hosts $f)
1390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1391 wait_request_state $fid ARCHIVE SUCCEED
1392 $LFS hsm_release $f || error "release of $f failed"
1394 do_node $CLIENT2 diff -q /etc/hosts $f
1397 # we check we had a restore done
1398 wait_request_state $fid RESTORE SUCCEED
1400 [[ $st -eq 0 ]] || error "Restored file differs"
1404 run_test 12h "Restore a released file implicitly from a second node"
1407 # test needs a running copytool
1411 local f=$DIR/$tdir/$tfile
1412 local fid=$(copy_file /etc/passwd $f)
1413 $LFS hsm_archive $f || error "archive of $f failed"
1414 wait_request_state $fid ARCHIVE SUCCEED
1416 $LFS hsm_release $f || error "release of $f failed"
1420 [[ $? -eq 0 ]] || error "Restored file differs"
1424 run_test 12m "Archive/release/implicit restore"
1427 # test needs a running copytool
1431 copy2archive /etc/hosts $tdir/$tfile
1433 local f=$DIR/$tdir/$tfile
1434 import_file $tdir/$tfile $f
1436 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1437 error "Restored file differs"
1439 $LFS hsm_release $f || error "release of $f failed"
1443 run_test 12n "Import/implicit restore/release"
1446 # test needs a running copytool
1450 local f=$DIR/$tdir/$tfile
1451 local fid=$(copy_file /etc/hosts $f)
1453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1454 wait_request_state $fid ARCHIVE SUCCEED
1455 $LFS hsm_release $f || error "release of $f failed"
1457 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1458 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1460 # set no retry action mode
1463 diff -q /etc/hosts $f
1466 # we check we had a restore failure
1467 wait_request_state $fid RESTORE FAILED
1469 [[ $st -eq 0 ]] && error "Restore must fail"
1471 # remove no retry action mode
1474 # check file is still released
1475 check_hsm_flags $f "0x0000000d"
1477 # retry w/o failure injection
1478 do_facet $SINGLEMDS lctl set_param fail_loc=0
1480 # to be sure previous RESTORE result is gone
1482 wait_for_grace_delay
1484 diff -q /etc/hosts $f
1487 # we check we had a restore done
1488 wait_request_state $fid RESTORE SUCCEED
1490 [[ $st -eq 0 ]] || error "Restored file differs"
1494 run_test 12o "Layout-swap failure during Restore leaves file released"
1497 # test needs a running copytool
1501 local f=$DIR/$tdir/$tfile
1502 local fid=$(copy_file /etc/hosts $f)
1504 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1505 wait_request_state $fid ARCHIVE SUCCEED
1506 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1507 $LFS hsm_release $f || error "cannot release $f"
1508 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1509 $LFS hsm_release $f || error "cannot release $f"
1510 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1514 run_test 12p "implicit restore of a file on copytool mount point"
1516 cleanup_test_12q() {
1518 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1519 error "cannot umount $MOUNT3 on $SINGLEAGT"
1523 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1524 skip "need MDS version at least 2.7.58" && return 0
1526 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1527 error "cannot mount $MOUNT3 on $SINGLEAGT"
1529 trap cleanup_test_12q EXIT
1531 # test needs a running copytool
1532 copytool_setup $SINGLEAGT $MOUNT3
1535 local f=$DIR/$tdir/$tfile
1536 local f2=$DIR2/$tdir/$tfile
1537 local fid=$(make_small $f)
1538 local orig_size=$(stat -c "%s" $f)
1540 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1541 wait_request_state $fid ARCHIVE SUCCEED
1543 $LFS hsm_release $f || error "could not release file"
1544 check_hsm_flags $f "0x0000000d"
1547 wait_copytools || error "copytool failed to stop"
1549 cat $f > /dev/null &
1551 # wait a bit to allow implicit restore request to be handled.
1552 # if not, next stat would also block on layout-lock.
1555 local size=$(stat -c "%s" $f2)
1556 [ $size -eq $orig_size ] ||
1557 error "$f2: wrong size after archive: $size != $orig_size"
1559 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1563 size=$(stat -c "%s" $f)
1564 [ $size -eq $orig_size ] ||
1565 error "$f: wrong size after restore: $size != $orig_size"
1567 size=$(stat -c "%s" $f2)
1568 [ $size -eq $orig_size ] ||
1569 error "$f2: wrong size after restore: $size != $orig_size"
1573 size=$(stat -c "%s" $f)
1575 error "$f: wrong size after overwrite: $size != 0"
1577 size=$(stat -c "%s" $f2)
1579 error "$f2: wrong size after overwrite: $size != 0"
1582 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1583 error "cannot umount $MOUNT3 on $SINGLEAGT"
1585 run_test 12q "file attributes are refreshed after restore"
1588 # test needs a running copytool
1591 local ARC_SUBDIR="import.orig"
1595 # populate directory to be imported
1596 for d in $(seq 1 10); do
1597 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1598 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1599 for f in $(seq 1 10); do
1600 CURR_FILE="$CURR_DIR/$tfile.$f"
1601 # write file-specific data
1602 do_facet $SINGLEAGT \
1603 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1604 "file=$CURR_FILE > $CURR_FILE"
1608 import_file "$ARC_SUBDIR" $DIR/$tdir
1609 # diff lustre content and origin (triggers file restoration)
1610 # there must be 10x10 identical files, and no difference
1611 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1612 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1613 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1614 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1616 [ $cnt_diff -eq 0 ] ||
1617 error "$cnt_diff imported files differ from read data"
1618 [ $cnt_ok -eq 100 ] ||
1619 error "not enough identical files ($cnt_ok != 100)"
1623 run_test 13 "Recursively import and restore a directory"
1626 # test needs a running copytool
1631 local f=$DIR/$tdir/$tfile
1632 local fid=$(make_small $f)
1633 local sum=$(md5sum $f | awk '{print $1}')
1634 $LFS hsm_archive $f || error "could not archive file"
1635 wait_request_state $fid ARCHIVE SUCCEED
1639 # create released file (simulate llapi_hsm_import call)
1641 local fid2=$(path2fid $f)
1642 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1643 $LFS hsm_release $f || error "could not release file"
1645 # rebind the archive to the newly created file
1646 echo "rebind $fid to $fid2"
1648 do_facet $SINGLEAGT \
1649 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1650 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1652 # restore file and compare md5sum
1653 local sum2=$(md5sum $f | awk '{print $1}')
1655 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1659 run_test 14 "Rebind archived file to a new fid"
1662 # test needs a running copytool
1667 local f=$DIR/$tdir/$tfile
1669 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1673 for i in $(seq 1 $count); do
1674 fids[$i]=$(make_small $f.$i)
1675 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1676 $LFS hsm_archive $f.$i || error "could not archive file"
1678 wait_all_done $(($count*60))
1682 for i in $(seq 1 $count); do
1685 local fid2=$(path2fid $f.$i)
1686 # add the rebind operation to the list
1687 echo ${fids[$i]} $fid2 >> $tmpfile
1689 # set it released (simulate llapi_hsm_import call)
1690 $LFS hsm_set --archived --exists $f.$i ||
1691 error "could not force hsm flags"
1692 $LFS hsm_release $f.$i || error "could not release file"
1694 nl=$(wc -l < $tmpfile)
1695 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1697 echo "rebind list of files"
1698 do_facet $SINGLEAGT \
1699 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1700 --rebind $tmpfile $DIR" || error "could not rebind file list"
1702 # restore files and compare md5sum
1703 for i in $(seq 1 $count); do
1704 local sum2=$(md5sum $f.$i | awk '{print $1}')
1705 [[ $sum2 == ${sums[$i]} ]] ||
1706 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1712 run_test 15 "Rebind a list of files"
1715 # test needs a running copytool
1719 # create a known size file so we can verify transfer speed
1722 dd if=/dev/zero of=$ref bs=1M count=20
1725 local f=$DIR/$tdir/$tfile
1726 local fid=$(copy_file $ref $f)
1728 local start=$(date +%s)
1730 wait_request_state $fid ARCHIVE SUCCEED
1731 local end=$(date +%s)
1732 # Add 1 to account for rounding errors between start and end (LU-8155)
1733 local duration=$((end - start + 1))
1735 [[ $duration -ge $((goal - 1)) ]] ||
1736 error "Transfer is too fast $duration < $goal"
1740 run_test 16 "Test CT bandwith control option"
1745 local f=$DIR/$tdir/$tfile
1746 touch $f || error "touch $f failed"
1748 # Could not release a non-archived file
1749 $LFS hsm_release $f && error "release should not succeed"
1751 # For following tests, we must test them with HS_ARCHIVED set
1752 $LFS hsm_set --exists --archived $f || error "could not add flag"
1754 # Could not release a file if no-release is set
1755 $LFS hsm_set --norelease $f || error "could not add flag"
1756 $LFS hsm_release $f && error "release should not succeed"
1757 $LFS hsm_clear --norelease $f || error "could not remove flag"
1759 # Could not release a file if lost
1760 $LFS hsm_set --lost $f || error "could not add flag"
1761 $LFS hsm_release $f && error "release should not succeed"
1762 $LFS hsm_clear --lost $f || error "could not remove flag"
1764 # Could not release a file if dirty
1765 $LFS hsm_set --dirty $f || error "could not add flag"
1766 $LFS hsm_release $f && error "release should not succeed"
1767 $LFS hsm_clear --dirty $f || error "could not remove flag"
1769 run_test 20 "Release is not permitted"
1772 # test needs a running copytool
1776 local f=$DIR/$tdir/test_release
1778 # Create a file and check its states
1779 local fid=$(make_small $f)
1780 check_hsm_flags $f "0x00000000"
1782 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1783 # used until file is flushed to disk
1784 if [ $(facet_fstype ost1) == "zfs" ]; then
1785 # this causes an OST_SYNC rpc to be sent
1786 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1787 # clear locks to reread file data
1788 cancel_lru_locks osc
1791 local orig_size=$(stat -c "%s" $f)
1792 local orig_blocks=$(stat -c "%b" $f)
1794 start_full_debug_logging
1796 $LFS hsm_archive $f || error "could not archive file"
1797 wait_request_state $fid ARCHIVE SUCCEED
1799 local blocks=$(stat -c "%b" $f)
1800 [ $blocks -eq $orig_blocks ] ||
1801 error "$f: wrong block number after archive: " \
1802 "$blocks != $orig_blocks"
1803 local size=$(stat -c "%s" $f)
1804 [ $size -eq $orig_size ] ||
1805 error "$f: wrong size after archive: $size != $orig_size"
1807 # Release and check states
1808 $LFS hsm_release $f || error "could not release file"
1809 check_hsm_flags $f "0x0000000d"
1811 blocks=$(stat -c "%b" $f)
1812 [ $blocks -gt 5 ] &&
1813 error "$f: too many blocks after release: $blocks > 5"
1814 size=$(stat -c "%s" $f)
1815 [ $size -ne $orig_size ] &&
1816 error "$f: wrong size after release: $size != $orig_size"
1818 # Check we can release an file without stripe info
1822 check_hsm_flags $f "0x00000000"
1823 $LFS hsm_archive $f || error "could not archive file"
1824 wait_request_state $fid ARCHIVE SUCCEED
1826 # Release and check states
1827 $LFS hsm_release $f || error "could not release file"
1828 check_hsm_flags $f "0x0000000d"
1830 # Release again a file that is already released is OK
1831 $LFS hsm_release $f || fail "second release should succeed"
1832 check_hsm_flags $f "0x0000000d"
1834 stop_full_debug_logging
1838 run_test 21 "Simple release tests"
1841 # test needs a running copytool
1846 local f=$DIR/$tdir/test_release
1847 local swap=$DIR/$tdir/test_swap
1849 # Create a file and check its states
1850 local fid=$(make_small $f)
1851 check_hsm_flags $f "0x00000000"
1853 $LFS hsm_archive $f || error "could not archive file"
1854 wait_request_state $fid ARCHIVE SUCCEED
1856 # Release and check states
1857 $LFS hsm_release $f || error "could not release file"
1858 check_hsm_flags $f "0x0000000d"
1861 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1866 run_test 22 "Could not swap a release file"
1869 # test needs a running copytool
1874 local f=$DIR/$tdir/test_mtime
1876 # Create a file and check its states
1877 local fid=$(make_small $f)
1878 check_hsm_flags $f "0x00000000"
1880 $LFS hsm_archive $f || error "could not archive file"
1881 wait_request_state $fid ARCHIVE SUCCEED
1883 # Set modification time in the past
1884 touch -m -a -d @978261179 $f
1886 # Release and check states
1887 $LFS hsm_release $f || error "could not release file"
1888 check_hsm_flags $f "0x0000000d"
1890 local MTIME=$(stat -c "%Y" $f)
1891 local ATIME=$(stat -c "%X" $f)
1892 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1893 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1897 run_test 23 "Release does not change a/mtime (utime)"
1900 local file=$DIR/$tdir/$tfile
1909 # test needs a running copytool
1914 fid=$(make_small $file)
1916 # Create a file and check its states
1917 check_hsm_flags $file "0x00000000"
1919 # Ensure atime is less than mtime and ctime.
1923 atime0=$(stat -c "%X" $file)
1924 mtime0=$(stat -c "%Y" $file)
1925 ctime0=$(stat -c "%Z" $file)
1927 [ $atime0 -lt $mtime0 ] ||
1928 error "atime $atime0 is not less than mtime $mtime0"
1930 [ $atime0 -lt $ctime0 ] ||
1931 error "atime $atime0 is not less than ctime $ctime0"
1933 # Archive should not change any timestamps.
1934 $LFS hsm_archive $file || error "cannot archive '$file'"
1935 wait_request_state $fid ARCHIVE SUCCEED
1937 atime1=$(stat -c "%X" $file)
1938 mtime1=$(stat -c "%Y" $file)
1939 ctime1=$(stat -c "%Z" $file)
1941 [ $atime0 -eq $atime1 ] ||
1942 error "archive changed atime from $atime0 to $atime1"
1944 [ $mtime0 -eq $mtime1 ] ||
1945 error "archive changed mtime from $mtime0 to $mtime1"
1947 [ $ctime0 -eq $ctime1 ] ||
1948 error "archive changed ctime from $ctime0 to $ctime1"
1950 # Release should not change any timestamps.
1951 $LFS hsm_release $file || error "cannot release '$file'"
1952 check_hsm_flags $file "0x0000000d"
1954 atime1=$(stat -c "%X" $file)
1955 mtime1=$(stat -c "%Y" $file)
1956 ctime1=$(stat -c "%Z" $file)
1958 [ $atime0 -eq $atime1 ] ||
1959 error "release changed atime from $atime0 to $atime1"
1961 [ $mtime0 -eq $mtime1 ] ||
1962 error "release changed mtime from $mtime0 to $mtime1"
1964 [ $ctime0 -eq $ctime1 ] ||
1965 error "release changed ctime from $ctime0 to $ctime1"
1967 # Restore should not change any timestamps.
1968 $LFS hsm_restore $file
1969 wait_request_state $fid RESTORE SUCCEED
1971 atime1=$(stat -c "%X" $file)
1972 mtime1=$(stat -c "%Y" $file)
1973 ctime1=$(stat -c "%Z" $file)
1975 [ $atime0 -eq $atime1 ] ||
1976 error "restore changed atime from $atime0 to $atime1"
1978 [ $mtime0 -eq $mtime1 ] ||
1979 error "restore changed mtime from $mtime0 to $mtime1"
1981 [ $ctime0 -eq $ctime1 ] ||
1982 error "restore changed ctime from $ctime0 to $ctime1"
1986 # Once more, after unmount and mount.
1987 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1988 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1990 atime1=$(stat -c "%X" $file)
1991 mtime1=$(stat -c "%Y" $file)
1992 ctime1=$(stat -c "%Z" $file)
1994 [ $atime0 -eq $atime1 ] ||
1995 error "remount changed atime from $atime0 to $atime1"
1997 [ $mtime0 -eq $mtime1 ] ||
1998 error "remount changed mtime from $mtime0 to $mtime1"
2000 [ $ctime0 -eq $ctime1 ] ||
2001 error "remount changed ctime from $ctime0 to $ctime1"
2003 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2006 local file=$DIR/$tdir/$tfile
2012 # Test needs a running copytool.
2016 # Check that root can do HSM actions on a regular user's file.
2018 fid=$(make_small $file)
2019 sum0=$(md5sum $file)
2021 chown $RUNAS_ID:$RUNAS_GID $file ||
2022 error "cannot chown '$file' to '$RUNAS_ID'"
2024 chmod ugo-w $DIR/$tdir ||
2025 error "cannot chmod '$DIR/$tdir'"
2027 $LFS hsm_archive $file
2028 wait_request_state $fid ARCHIVE SUCCEED
2030 $LFS hsm_release $file
2031 check_hsm_flags $file "0x0000000d"
2033 $LFS hsm_restore $file
2034 wait_request_state $fid RESTORE SUCCEED
2036 # Check that ordinary user can get HSM state.
2037 $RUNAS $LFS hsm_state $file ||
2038 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2040 $LFS hsm_release $file
2041 check_hsm_flags $file "0x0000000d"
2043 # Check that ordinary user can accessed released file.
2044 sum1=$($RUNAS md5sum $file) ||
2045 error "user '$RUNAS_ID' cannot read '$file'"
2047 [ "$sum0" == "$sum1" ] ||
2048 error "md5sum mismatch for '$file'"
2052 run_test 24b "root can archive, release, and restore user files"
2054 cleanup_test_24c() {
2056 set_hsm_param user_request_mask RESTORE
2057 set_hsm_param group_request_mask RESTORE
2058 set_hsm_param other_request_mask RESTORE
2062 local file=$DIR/$tdir/$tfile
2063 local action=archive
2068 # test needs a running copytool
2073 # Save the default masks and check that cleanup_24c will
2074 # restore the request masks correctly.
2075 user_save=$(get_hsm_param user_request_mask)
2076 group_save=$(get_hsm_param group_request_mask)
2077 other_save=$(get_hsm_param other_request_mask)
2079 [ "$user_save" == RESTORE ] ||
2080 error "user_request_mask is '$user_save' expected 'RESTORE'"
2081 [ "$group_save" == RESTORE ] ||
2082 error "group_request_mask is '$group_save' expected 'RESTORE'"
2083 [ "$other_save" == RESTORE ] ||
2084 error "other_request_mask is '$other_save' expected 'RESTORE'"
2086 trap cleanup_test_24c EXIT
2091 chown $RUNAS_ID:nobody $file ||
2092 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2094 $RUNAS $LFS hsm_$action $file &&
2095 error "$action by user should fail"
2097 set_hsm_param user_request_mask $action
2098 $RUNAS $LFS hsm_$action $file ||
2099 error "$action by user should succeed"
2104 chown nobody:$RUNAS_GID $file ||
2105 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2107 $RUNAS $LFS hsm_$action $file &&
2108 error "$action by group should fail"
2110 set_hsm_param group_request_mask $action
2111 $RUNAS $LFS hsm_$action $file ||
2112 error "$action by group should succeed"
2117 chown nobody:nobody $file ||
2118 error "cannot chown '$file' to 'nobody:nobody'"
2120 $RUNAS $LFS hsm_$action $file &&
2121 error "$action by other should fail"
2123 set_hsm_param other_request_mask $action
2124 $RUNAS $LFS hsm_$action $file ||
2125 error "$action by other should succeed"
2130 run_test 24c "check that user,group,other request masks work"
2132 cleanup_test_24d() {
2134 mount -o remount,rw $MOUNT2
2135 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2139 local file1=$DIR/$tdir/$tfile
2140 local file2=$DIR2/$tdir/$tfile
2146 fid1=$(make_small $file1)
2148 trap cleanup_test_24d EXIT
2149 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2150 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2151 copytool_setup $SINGLEAGT "$MOUNT3" ||
2152 error "unable to setup a copytool for the test"
2154 mount -o remount,ro $MOUNT2
2156 fid2=$(path2fid $file2)
2157 [ "$fid1" == "$fid2" ] ||
2158 error "FID mismatch '$fid1' != '$fid2'"
2160 $LFS hsm_archive $file2 &&
2161 error "archive should fail on read-only mount"
2162 check_hsm_flags $file1 "0x00000000"
2164 $LFS hsm_archive $file1
2165 wait_request_state $fid1 ARCHIVE SUCCEED
2167 $LFS hsm_release $file1
2168 $LFS hsm_restore $file2
2169 wait_request_state $fid1 RESTORE SUCCEED
2171 $LFS hsm_release $file1 || error "cannot release '$file1'"
2172 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2174 $LFS hsm_release $file2 &&
2175 error "release should fail on read-only mount"
2180 run_test 24d "check that read-only mounts are respected"
2187 local f=$DIR/$tdir/$tfile
2190 fid=$(make_small $f) || error "cannot create $f"
2191 $LFS hsm_archive $f || error "cannot archive $f"
2192 wait_request_state $fid ARCHIVE SUCCEED
2193 $LFS hsm_release $f || error "cannot release $f"
2194 while ! $LFS hsm_state $f | grep released; do
2198 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2202 run_test 24e "tar succeeds on HSM released files" # LU-6213
2206 # test needs a running copytool
2209 mkdir -p $DIR/$tdir/d1
2210 local f=$DIR/$tdir/$tfile
2211 local fid=$(copy_file /etc/hosts $f)
2214 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2215 error "hsm_archive failed"
2216 wait_request_state $fid ARCHIVE SUCCEED
2217 $LFS hsm_release $f || error "cannot release $f"
2218 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2221 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2222 error "Can not recover the tar contents"
2224 echo "Sum0 = $sum0, sum1 = $sum1"
2225 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2229 run_test 24f "root can archive, release, and restore tar files"
2232 # test needs a running copytool
2236 copy2archive /etc/hosts $tdir/$tfile
2238 local f=$DIR/$tdir/$tfile
2240 import_file $tdir/$tfile $f
2242 $LFS hsm_set --lost $f
2247 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2251 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2252 " (Operation not permitted)"
2255 # test needs a running copytool
2260 local f=$DIR/$tdir/$tfile
2261 local fid=$(copy_file /etc/passwd $f)
2263 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2264 wait_request_state $fid ARCHIVE SUCCEED
2267 $LFS hsm_set --lost $f
2271 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2275 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2276 " (Operation not permitted)"
2279 # test needs a running copytool
2283 local f=$DIR/$tdir/$tfile
2285 fid=$(make_custom_file_for_progress $f 39 1000000)
2286 [ $? != 0 ] && skip "not enough free space" && return
2288 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2289 wait_request_state $fid ARCHIVE SUCCEED
2292 wait_request_state $fid REMOVE SUCCEED
2294 check_hsm_flags $f "0x00000000"
2298 run_test 26 "Remove the archive of a valid file"
2301 # test needs a running copytool
2305 make_archive $tdir/$tfile
2306 local f=$DIR/$tdir/$tfile
2307 import_file $tdir/$tfile $f
2308 local fid=$(path2fid $f)
2312 [[ $? != 0 ]] || error "Remove of a released file should fail"
2316 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2319 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2325 fid=$(make_custom_file_for_progress $f 39 1000000)
2326 [ $? != 0 ] && skip "not enough free space" && return
2328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2329 wait_request_state $fid ARCHIVE SUCCEED
2334 [[ $? != 0 ]] || error "Remove of a released file should fail"
2338 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2341 # test needs a running copytool
2345 local f=$DIR/$tdir/$tfile
2347 fid=$(make_custom_file_for_progress $f 39 1000000)
2348 [ $? != 0 ] && skip "not enough free space" && return
2350 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2351 wait_request_state $fid ARCHIVE SUCCEED
2360 wait_request_state $fid REMOVE SUCCEED
2364 run_test 28 "Concurrent archive/file remove"
2367 # Tests --mntpath and --archive options
2370 copytool_setup $SINGLEAGT $MOUNT $archive_id
2372 # Bad archive number
2373 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2374 grep "Invalid argument" ||
2375 error "unexpected hsm_remove failure (1)"
2377 # mntpath is present but file is given
2378 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2379 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2380 error "unexpected hsm_remove failure (2)"
2384 run_test 29a "Tests --mntpath and --archive options"
2387 # test needs a running copytool
2391 local f=$DIR/$tdir/$tfile
2392 local fid=$(make_small $f)
2394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2395 wait_request_state $fid ARCHIVE SUCCEED
2399 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2400 wait_request_state $fid REMOVE SUCCEED
2404 run_test 29b "Archive/delete/remove by FID from the archive."
2407 # test needs a running copytool
2411 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2412 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2413 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2416 wait_request_state $fid1 ARCHIVE SUCCEED
2417 wait_request_state $fid2 ARCHIVE SUCCEED
2418 wait_request_state $fid3 ARCHIVE SUCCEED
2420 rm -f $DIR/$tdir/$tfile-[1-3]
2422 echo $fid1 > $DIR/$tdir/list
2423 echo $fid2 >> $DIR/$tdir/list
2424 echo $fid3 >> $DIR/$tdir/list
2426 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2427 --filelist $DIR/$tdir/list
2428 wait_request_state $fid1 REMOVE SUCCEED
2429 wait_request_state $fid2 REMOVE SUCCEED
2430 wait_request_state $fid3 REMOVE SUCCEED
2434 run_test 29c "Archive/delete/remove by FID, using a file list."
2437 # test needs more than one CT
2438 needclients 3 || return 0
2444 copytool_cleanup $(comma_list $(agts_nodes))
2446 # start all of the copytools
2447 for n in $(seq $AGTCOUNT); do
2448 copytool_setup agt$n $MOUNT2 $n
2451 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2454 file=$DIR/$tdir/$tfile
2455 fid=$(make_small $file)
2457 $LFS hsm_archive $file
2458 wait_request_state $fid ARCHIVE SUCCEED
2459 check_hsm_flags $file "0x00000009"
2463 $LFS hsm_remove -a 0 $fid
2465 # give time for CDT to handle remove request and create broadcasted
2468 # remove request has been broadcasted ?
2469 local cnt=$(get_request_count $fid REMOVE)
2470 # broadcasted requests + original
2471 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2472 error "remove not broadcasted to all CTs"
2474 # give time for CDT and CTs to handle broadcasted
2475 wait_for_loop_period
2477 # each agent serves one different archive_id, so broadcasted
2478 # hsm_remove request should only succeed once and fail at all others
2482 for n in $(seq $AGTCOUNT); do
2483 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2484 $HSM_PARAM.actions | awk \
2485 '/'$fid'.*action=REMOVE archive#='$n'/ \
2486 {print \\\$13}' | cut -f2 -d=")
2487 if [[ "$res" == "SUCCEED" ]]; then
2489 elif [[ "$res" == "FAILED" ]]; then
2494 [[ $scnt -ne 1 ]] &&
2495 error "one and only CT should have removed successfully"
2497 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2498 error "all but one CT should have failed to remove"
2501 copytool_cleanup $(comma_list $(agts_nodes))
2504 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2505 "request to be sent once for each registered archive_id"
2508 # restore at exec cannot work on agent node (because of Linux kernel
2509 # protection of executables)
2510 needclients 2 || return 0
2512 # test needs a running copytool
2516 copy2archive /bin/true $tdir/$tfile
2518 local f=$DIR/$tdir/true
2519 import_file $tdir/$tfile $f
2521 local fid=$(path2fid $f)
2523 # set no retry action mode
2529 # remove no try action mode
2533 [[ $st == 0 ]] || error "Failed to exec a released file"
2537 run_test 30a "Restore at exec (import case)"
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 local f=$DIR/$tdir/true
2549 local fid=$(copy_file /bin/true $f)
2551 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2552 wait_request_state $fid ARCHIVE SUCCEED
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 30b "Restore at exec (release case)"
2572 needclients 2 || return 0
2574 # test needs a running copytool
2578 local f=$DIR/$tdir/SLEEP
2579 local slp_sum1=$(md5sum /bin/sleep)
2580 local fid=$(copy_file /bin/sleep $f)
2582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2583 wait_request_state $fid ARCHIVE SUCCEED
2585 check_hsm_flags $f "0x0000000d"
2586 # set no retry action mode
2588 do_node $CLIENT2 "$f 10" &
2592 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2594 [[ $? == 0 ]] || error "Execution failed during run"
2596 if [[ $? != 0 ]]; then
2597 local slp_sum2=$(md5sum /bin/sleep)
2598 # in case sleep file is modified during the test
2599 [[ $slp_sum1 == $slp_sum2 ]] &&
2600 error "Binary overwritten during exec"
2604 # remove no try action mode
2606 check_hsm_flags $f "0x00000009"
2610 run_test 30c "Update during exec of released file must fail"
2612 restore_and_check_size() {
2615 local s=$(stat -c "%s" $f)
2617 local st=$(get_hsm_flags $f)
2621 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2623 n=$(stat -c "%s" $f)
2624 # we echo in both cases to show stat is not hang
2625 if [[ $n != $s ]]; then
2626 echo "size seen is $n != $s"
2629 echo "size seen is right: $n == $s"
2633 st=$(get_hsm_flags $f)
2635 if [[ "$st" = "0x00000009" ]]; then
2638 echo " restore is too long"
2639 wait_request_state $fid RESTORE SUCCEED
2645 # test needs a running copytool
2650 make_archive $tdir/$tfile
2651 local f=$DIR/$tdir/$tfile
2652 import_file $tdir/$tfile $f
2653 local fid=$($LFS path2fid $f)
2654 HSM_ARCHIVE_PURGE=false copytool_setup
2656 restore_and_check_size $f $fid
2659 [[ $err -eq 0 ]] || error "File size changed during restore"
2663 run_test 31a "Import a large file and check size during restore"
2667 # test needs a running copytool
2672 local f=$DIR/$tdir/$tfile
2674 fid=$(make_custom_file_for_progress $f 39 1000000)
2675 [ $? != 0 ] && skip "not enough free space" && return
2677 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2678 wait_request_state $fid ARCHIVE SUCCEED
2681 restore_and_check_size $f $fid
2684 [[ $err -eq 0 ]] || error "File size changed during restore"
2688 run_test 31b "Restore a large unaligned file and check size during restore"
2691 # test needs a running copytool
2696 local f=$DIR/$tdir/$tfile
2698 fid=$(make_custom_file_for_progress $f 33 1048576)
2699 [ $? != 0 ] && skip "not enough free space" && return
2701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2702 wait_request_state $fid ARCHIVE SUCCEED
2705 restore_and_check_size $f $fid
2708 [[ $err -eq 0 ]] || error "File size changed during restore"
2712 run_test 31c "Restore a large aligned file and check size during restore"
2715 # test needs a running copytool
2720 local f=$DIR/$tdir/$tfile
2722 fid=$(make_custom_file_for_progress $f 39 1000000)
2723 [ $? != 0 ] && skip "not enough free space" && return
2725 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2726 wait_request_state $fid ARCHIVE SUCCEED
2729 # to be sure wait_all_done will not be mislead by previous tests
2732 wait_for_grace_delay
2733 # Also raise grace_delay significantly so the Canceled
2734 # Restore action will stay enough long avail.
2735 local old_grace=$(get_hsm_param grace_delay)
2736 set_hsm_param grace_delay 100
2738 md5sum $f >/dev/null &
2740 wait_request_state $fid RESTORE STARTED
2745 # Check restore trigger process was killed
2746 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2750 # instead of waiting+checking both Restore and Cancel ops
2751 # sequentially, wait for both to be finished and then check
2753 wait_all_done 100 $fid
2754 local rstate=$(get_request_state $fid RESTORE)
2755 local cstate=$(get_request_state $fid CANCEL)
2757 # restore orig grace_delay.
2758 set_hsm_param grace_delay $old_grace
2760 if [[ "$rstate" == "CANCELED" ]] ; then
2761 [[ "$cstate" == "SUCCEED" ]] ||
2762 error "Restore state is CANCELED and Cancel state " \
2763 "is not SUCCEED but $cstate"
2764 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2765 elif [[ "$rstate" == "SUCCEED" ]] ; then
2766 [[ "$cstate" == "FAILED" ]] ||
2767 error "Restore state is SUCCEED and Cancel state " \
2768 "is not FAILED but $cstate"
2769 echo "Restore state is SUCCEED, Cancel state is FAILED"
2771 error "Restore state is $rstate and Cancel state is $cstate"
2775 error "Cannot kill process waiting for restore ($killed)"
2779 run_test 33 "Kill a restore waiting process"
2782 # test needs a running copytool
2787 local f=$DIR/$tdir/$tfile
2789 fid=$(make_custom_file_for_progress $f 39 1000000)
2790 [ $? != 0 ] && skip "not enough free space" && return
2792 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2793 wait_request_state $fid ARCHIVE SUCCEED
2796 md5sum $f >/dev/null &
2798 wait_request_state $fid RESTORE STARTED
2800 rm $f || error "rm $f failed"
2801 # rm must not block during restore
2802 wait_request_state $fid RESTORE STARTED
2804 wait_request_state $fid RESTORE SUCCEED
2805 # check md5sum pgm finished
2806 local there=$(ps -o pid,comm hp $pid >/dev/null)
2807 [[ -z $there ]] || error "Restore initiator does not exit"
2809 local rc=$(wait $pid)
2810 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2814 run_test 34 "Remove file during restore"
2817 # test needs a running copytool
2822 local f=$DIR/$tdir/$tfile
2823 local f1=$DIR/$tdir/$tfile-1
2825 fid=$(make_custom_file_for_progress $f 39 1000000)
2826 [ $? != 0 ] && skip "not enough free space" && return
2828 local fid1=$(copy_file /etc/passwd $f1)
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2830 wait_request_state $fid ARCHIVE SUCCEED
2833 md5sum $f >/dev/null &
2835 wait_request_state $fid RESTORE STARTED
2837 mv $f1 $f || error "mv $f1 $f failed"
2838 # mv must not block during restore
2839 wait_request_state $fid RESTORE STARTED
2841 wait_request_state $fid RESTORE SUCCEED
2842 # check md5sum pgm finished
2843 local there=$(ps -o pid,comm hp $pid >/dev/null)
2844 [[ -z $there ]] || error "Restore initiator does not exit"
2846 local rc=$(wait $pid)
2847 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2850 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2854 run_test 35 "Overwrite file during restore"
2857 # test needs a running copytool
2862 local f=$DIR/$tdir/$tfile
2864 fid=$(make_custom_file_for_progress $f 39 1000000)
2865 [ $? != 0 ] && skip "not enough free space" && return
2867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2868 wait_request_state $fid ARCHIVE SUCCEED
2871 md5sum $f >/dev/null &
2873 wait_request_state $fid RESTORE STARTED
2876 # rm must not block during restore
2877 wait_request_state $fid RESTORE STARTED
2879 wait_request_state $fid RESTORE SUCCEED
2880 # check md5sum pgm finished
2881 local there=$(ps -o pid,comm hp $pid >/dev/null)
2883 error "Restore initiator does not exit"
2885 local rc=$(wait $pid)
2887 error "Restore initiator failed with $rc"
2891 run_test 36 "Move file during restore"
2894 # LU-5683: check that an archived dirty file can be rearchived.
2896 copytool_setup $SINGLEAGT $MOUNT2
2899 local f=$DIR/$tdir/$tfile
2902 fid=$(make_small $f) || error "cannot create small file"
2904 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2905 wait_request_state $fid ARCHIVE SUCCEED
2906 $LFS hsm_release $f || error "cannot release $f"
2908 # Allow previous archive request to expire from the actions log.
2909 wait_for_grace_delay
2912 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2914 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2915 wait_request_state $fid ARCHIVE SUCCEED
2919 run_test 37 "re-archive a dirty file"
2926 for n in $(seq 1 $count); do
2927 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2929 echo "$count archive requests submitted"
2933 local stream_count=4
2934 local file_count=100
2936 local f=$DIR/$tdir/$tfile
2941 for i in $(seq 1 $file_count); do
2942 for p in $(seq 1 $stream_count); do
2943 fid=$(copy_file /etc/hosts $f.$p.$i)
2946 # force copytool to use a local/temp archive dir to ensure best
2947 # performance vs remote/NFS mounts used in auto-tests
2948 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2951 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2953 # to be sure wait_all_done will not be mislead by previous tests
2955 wait_for_grace_delay
2957 # start archive streams in background (archive files in parallel)
2958 for p in $(seq 1 $stream_count); do
2959 multi_archive $f.$p $file_count &
2962 echo -n "Wait for all requests being enqueued..."
2968 run_test 40 "Parallel archive requests"
2971 # test needs a running copytool
2975 local f=$DIR/$tdir/$tfile
2976 local fid=$(copy_file /etc/motd $f 1)
2978 $LFS hsm_archive $f || error "could not archive file"
2979 wait_request_state $fid ARCHIVE SUCCEED
2980 check_hsm_flags $f "0x00000009"
2982 multiop_bg_pause $f O_c || error "multiop failed"
2986 client_up || client_up || true
2988 kill -USR1 $MULTIPID
2989 wait $MULTIPID || error "multiop close failed"
2991 check_hsm_flags $f "0x0000000b"
2995 run_test 52 "Opened for write file on an evicted client should be set dirty"
2998 # test needs a running copytool
3002 local f=$DIR/$tdir/$tfile
3003 local fid=$(copy_file /etc/motd $f 1)
3005 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3006 error "could not archive file"
3007 wait_request_state $fid ARCHIVE SUCCEED
3008 check_hsm_flags $f "0x00000009"
3010 multiop_bg_pause $f o_c || error "multiop failed"
3014 client_up || client_up || true
3016 kill -USR1 $MULTIPID
3017 wait $MULTIPID || error "multiop close failed"
3019 check_hsm_flags $f "0x00000009"
3023 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3026 # test needs a running copytool
3030 local f=$DIR/$tdir/$tfile
3031 local fid=$(make_custom_file_for_progress $f 39 1000000)
3033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3034 error "could not archive file"
3035 wait_request_state $fid ARCHIVE STARTED
3037 check_hsm_flags $f "0x00000001"
3039 # Avoid coordinator resending this request as soon it has failed.
3044 wait_request_state $fid ARCHIVE FAILED
3046 check_hsm_flags $f "0x00000003"
3051 run_test 54 "Write during an archive cancels it"
3054 # test needs a running copytool
3058 local f=$DIR/$tdir/$tfile
3059 local fid=$(make_custom_file_for_progress $f 39 1000000)
3061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3062 error "could not archive file"
3063 wait_request_state $fid ARCHIVE STARTED
3065 check_hsm_flags $f "0x00000001"
3067 # Avoid coordinator resending this request as soon it has failed.
3070 $TRUNCATE $f 1024 || error "truncate failed"
3072 wait_request_state $fid ARCHIVE FAILED
3074 check_hsm_flags $f "0x00000003"
3079 run_test 55 "Truncate during an archive cancels it"
3082 # test needs a running copytool
3086 local f=$DIR/$tdir/$tfile
3088 fid=$(make_custom_file_for_progress $f 39 1000000)
3089 [ $? != 0 ] && skip "not enough free space" && return
3091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3092 error "could not archive file"
3093 wait_request_state $fid ARCHIVE STARTED
3095 check_hsm_flags $f "0x00000001"
3097 # Change metadata and sync to be sure we are not changing only
3102 wait_request_state $fid ARCHIVE SUCCEED
3104 check_hsm_flags $f "0x00000009"
3108 run_test 56 "Setattr during an archive is ok"
3111 # Need one client for I/O, one for request
3112 needclients 2 || return 0
3114 # test needs a running copytool
3118 local f=$DIR/$tdir/test_archive_remote
3119 # Create a file on a remote node
3120 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3121 "count=2 conv=fsync"
3124 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3125 error "hsm_archive failed"
3126 local fid=$(path2fid $f)
3127 wait_request_state $fid ARCHIVE SUCCEED
3129 # Release and implicit restore it
3130 do_node $CLIENT2 "$LFS hsm_release $f" ||
3131 error "hsm_release failed"
3132 do_node $CLIENT2 "md5sum $f" ||
3133 error "hsm_restore failed"
3135 wait_request_state $fid RESTORE SUCCEED
3139 run_test 57 "Archive a file with dirty cache on another node"
3141 truncate_released_file() {
3145 local sz=$(stat -c %s $src_file)
3146 local f=$DIR/$tdir/$tfile
3147 local fid=$(copy_file $1 $f)
3151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3152 error "could not archive file"
3153 wait_request_state $fid ARCHIVE SUCCEED
3155 $LFS hsm_release $f || error "could not release file"
3157 $TRUNCATE $f $trunc_to || error "truncate failed"
3160 local sz1=$(stat -c %s $f)
3161 [[ $sz1 == $trunc_to ]] ||
3162 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3165 check_hsm_flags $f "0x0000000b"
3167 local state=$(get_request_state $fid RESTORE)
3168 [[ "$state" == "SUCCEED" ]] ||
3169 error "truncate $sz does not trig restore, state = $state"
3171 $TRUNCATE $ref $trunc_to
3172 cmp $ref $f || error "file data wrong after truncate"
3178 # test needs a running copytool
3183 local sz=$(stat -c %s /etc/passwd)
3185 echo "truncate up from $sz to $((sz*2))"
3186 truncate_released_file /etc/passwd $((sz*2))
3188 echo "truncate down from $sz to $((sz/2))"
3189 truncate_released_file /etc/passwd $((sz/2))
3191 echo "truncate to 0"
3192 truncate_released_file /etc/passwd 0
3196 run_test 58 "Truncate a released file will trigger restore"
3200 local server_version=$(lustre_version_code $SINGLEMDS)
3201 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3202 skip "Need MDS version at least 2.7.63" && return
3205 $MCREATE $DIR/$tfile || error "mcreate failed"
3206 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3207 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3208 fid=$(path2fid $DIR/$tfile)
3209 wait_request_state $fid ARCHIVE SUCCEED
3210 $LFS hsm_release $DIR/$tfile || error "release failed"
3213 run_test 59 "Release stripeless file with non-zero size"
3216 # This test validates the fix for LU-4512. Ensure that the -u
3217 # option changes the progress reporting interval from the
3218 # default (30 seconds) to the user-specified interval.
3220 local progress_timeout=$((interval * 4))
3222 # test needs a new running copytool
3224 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3227 local f=$DIR/$tdir/$tfile
3229 fid=$(make_custom_file_for_progress $f 10)
3230 [ $? != 0 ] && skip "not enough free space" && return
3233 local mdt=${MDT_PREFIX}${mdtidx}
3234 local mds=mds$((mdtidx + 1))
3236 # Wait for copytool to register
3237 wait_update_facet $mds \
3238 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3239 uuid 100 || error "coyptool failed to register with $mdt"
3241 local start_at=$(date +%s)
3242 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3243 error "could not archive file"
3245 local agent=$(facet_active_host $SINGLEAGT)
3246 local prefix=$TESTLOG_PREFIX
3247 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3248 local copytool_log=$prefix.copytool_log.$agent.log
3251 wait_update $agent \
3252 "grep -o start.copy $copytool_log" "start copy" 100 ||
3253 error "copytool failed to start"
3255 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3256 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3262 echo -n "Expecting a progress update within $progress_timeout seconds... "
3264 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3265 if [ $RESULT -gt 0 ]; then
3266 echo "$RESULT bytes copied in $WAIT seconds."
3268 elif [ $WAIT -ge $progress_timeout ]; then
3269 error "Timed out waiting for progress update!"
3272 WAIT=$((WAIT + sleep))
3276 local finish_at=$(date +%s)
3277 local elapsed=$((finish_at - start_at))
3279 # Ensure that the progress update occurred within the expected window.
3280 if [ $elapsed -lt $((interval - 1)) ]; then
3281 error "Expected progress update after at least $interval seconds"
3284 echo "Wait for on going archive hsm action to complete"
3285 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3286 echo "File archiving not completed even after 10 secs"
3291 run_test 60 "Changing progress update interval from default"
3294 # test needs a new running copytool
3296 copytool_monitor_setup
3297 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3299 # Just start and stop the copytool to generate events.
3302 # Wait for the copytool to register.
3303 wait_update --verbose $(facet_active_host mds1) \
3304 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3306 error "copytool failed to register with MDT0000"
3310 local REGISTER_EVENT
3311 local UNREGISTER_EVENT
3312 while read event; do
3313 local parsed=$(parse_json_event "$event")
3314 if [ -z "$parsed" ]; then
3315 error "Copytool sent malformed event: $event"
3319 if [ $event_type == "REGISTER" ]; then
3320 REGISTER_EVENT=$event
3321 elif [ $event_type == "UNREGISTER" ]; then
3322 UNREGISTER_EVENT=$event
3324 done < <(echo $"$(get_copytool_event_log)")
3326 if [ -z "$REGISTER_EVENT" ]; then
3327 error "Copytool failed to send register event to FIFO"
3330 if [ -z "$UNREGISTER_EVENT" ]; then
3331 error "Copytool failed to send unregister event to FIFO"
3334 copytool_monitor_cleanup
3335 echo "Register/Unregister events look OK."
3337 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3340 # Bump progress interval for livelier events.
3343 # test needs a new running copytool
3345 copytool_monitor_setup
3346 HSMTOOL_UPDATE_INTERVAL=$interval \
3347 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3350 local f=$DIR/$tdir/$tfile
3352 fid=$(make_custom_file_for_progress $f 39 1000000)
3353 [ $? != 0 ] && skip "not enough free space" && return
3355 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3356 error "could not archive file"
3357 wait_request_state $fid ARCHIVE SUCCEED
3359 local expected_fields="event_time data_fid source_fid"
3360 expected_fields+=" total_bytes current_bytes"
3364 while read event; do
3365 # Make sure we're not getting anything from previous events.
3366 for field in $expected_fields; do
3370 local parsed=$(parse_json_event "$event")
3371 if [ -z "$parsed" ]; then
3372 error "Copytool sent malformed event: $event"
3376 if [ $event_type == "ARCHIVE_START" ]; then
3379 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3382 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3386 # Do some simple checking of the progress update events.
3387 for expected_field in $expected_fields; do
3388 if [ -z ${!expected_field+x} ]; then
3389 error "Missing $expected_field field in event"
3393 if [ $total_bytes -eq 0 ]; then
3394 error "Expected total_bytes to be > 0"
3397 # These should be identical throughout an archive
3399 if [ $source_fid != $data_fid ]; then
3400 error "Expected source_fid to equal data_fid"
3402 done < <(echo $"$(get_copytool_event_log)")
3404 if [ -z "$START_EVENT" ]; then
3405 error "Copytool failed to send archive start event to FIFO"
3408 if [ -z "$FINISH_EVENT" ]; then
3409 error "Copytool failed to send archive finish event to FIFO"
3412 echo "Archive events look OK."
3416 copytool_monitor_cleanup
3418 run_test 71 "Copytool logs JSON archive events to FIFO"
3421 # Bump progress interval for livelier events.
3424 # test needs a new running copytool
3426 copytool_monitor_setup
3427 HSMTOOL_UPDATE_INTERVAL=$interval \
3428 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3429 local test_file=$HSMTOOL_MONITOR_DIR/file
3431 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3433 do_facet $SINGLEAGT "$cmd" ||
3434 error "cannot create $test_file on $SINGLEAGT"
3435 copy2archive $test_file $tdir/$tfile
3438 local f=$DIR/$tdir/$tfile
3439 import_file $tdir/$tfile $f
3440 f=$DIR2/$tdir/$tfile
3441 echo "Verifying released state: "
3442 check_hsm_flags $f "0x0000000d"
3444 local fid=$(path2fid $f)
3446 wait_request_state $fid RESTORE SUCCEED
3448 local expected_fields="event_time data_fid source_fid"
3449 expected_fields+=" total_bytes current_bytes"
3453 while read event; do
3454 # Make sure we're not getting anything from previous events.
3455 for field in $expected_fields; do
3459 local parsed=$(parse_json_event "$event")
3460 if [ -z "$parsed" ]; then
3461 error "Copytool sent malformed event: $event"
3465 if [ $event_type == "RESTORE_START" ]; then
3467 if [ $source_fid != $data_fid ]; then
3468 error "source_fid should == data_fid at start"
3471 elif [ $event_type == "RESTORE_FINISH" ]; then
3473 if [ $source_fid != $data_fid ]; then
3474 error "source_fid should == data_fid at finish"
3477 elif [ $event_type != "RESTORE_RUNNING" ]; then
3481 # Do some simple checking of the progress update events.
3482 for expected_field in $expected_fields; do
3483 if [ -z ${!expected_field+x} ]; then
3484 error "Missing $expected_field field in event"
3488 if [ $total_bytes -eq 0 ]; then
3489 error "Expected total_bytes to be > 0"
3492 # When a restore starts out, the data fid is the same as the
3493 # source fid. After the restore has gotten going, we learn
3494 # the new data fid. Once the restore has finished, the source
3495 # fid is set to the new data fid.
3497 # We test this because some monitoring software may depend on
3498 # this behavior. If it changes, then the consumers of these
3499 # events may need to be modified.
3500 if [ $source_fid == $data_fid ]; then
3501 error "source_fid should != data_fid during restore"
3503 done < <(echo $"$(get_copytool_event_log)")
3505 if [ -z "$START_EVENT" ]; then
3506 error "Copytool failed to send restore start event to FIFO"
3509 if [ -z "$FINISH_EVENT" ]; then
3510 error "Copytool failed to send restore finish event to FIFO"
3513 echo "Restore events look OK."
3517 copytool_monitor_cleanup
3521 run_test 72 "Copytool logs JSON restore events to FIFO"
3524 file_count=51 # Max number of files constrained by LNET message size
3525 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3526 local f=$DIR/$tdir/$tfile
3527 local FILELIST=/tmp/filelist.txt
3531 for i in $(seq 1 $file_count); do
3532 fid=$(copy_file /etc/hosts $f.$i)
3533 echo $f.$i >> $FILELIST
3535 # force copytool to use a local/temp archive dir to ensure best
3536 # performance vs remote/NFS mounts used in auto-tests
3537 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3540 local dai=$(get_hsm_param default_archive_id)
3541 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3543 # to be sure wait_all_done will not be mislead by previous tests
3545 wait_for_grace_delay
3546 $LFS hsm_archive --filelist $FILELIST ||
3547 error "cannot archive a file list"
3549 $LFS hsm_release --filelist $FILELIST ||
3550 error "cannot release a file list"
3551 $LFS hsm_restore --filelist $FILELIST ||
3552 error "cannot restore a file list"
3556 run_test 90 "Archive/restore a file list"
3558 double_verify_reset_hsm_param() {
3560 echo "Testing $HSM_PARAM.$p"
3561 local val=$(get_hsm_param $p)
3563 local val2=$(($val * 2))
3564 set_hsm_param $p $val2
3565 val=$(get_hsm_param $p)
3566 [[ $val == $val2 ]] ||
3567 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3568 echo "Set $p to 0 must failed"
3572 set_hsm_param $p $save
3574 if [[ $rc == 0 ]]; then
3575 error "we must not be able to set $HSM_PARAM.$p to 0"
3580 double_verify_reset_hsm_param loop_period
3581 double_verify_reset_hsm_param grace_delay
3582 double_verify_reset_hsm_param active_request_timeout
3583 double_verify_reset_hsm_param max_requests
3584 double_verify_reset_hsm_param default_archive_id
3586 run_test 100 "Set coordinator /proc tunables"
3593 run_test 102 "Verify coordinator control"
3596 # test needs a running copytool
3603 for i in $(seq 1 20); do
3604 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3606 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3610 echo "Current requests"
3611 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3612 $HSM_PARAM.actions |\
3613 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3615 [[ -z "$res" ]] || error "Some request have not been canceled"
3619 run_test 103 "Purge all requests"
3624 # test needs a running copytool
3628 local f=$DIR/$tdir/$tfile
3630 fid=$(make_custom_file_for_progress $f 39 1000000)
3631 [ $? != 0 ] && skip "not enough free space" && return
3633 # if cdt is on, it can serve too quickly the request
3635 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3636 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3637 $HSM_PARAM.actions |\
3638 grep $fid | cut -f16 -d=")
3641 [[ "$data1" == "$DATAHEX" ]] ||
3642 error "Data field in records is ($data1) and not ($DATAHEX)"
3646 run_test 104 "Copy tool data field"
3653 for i in $(seq -w 1 10); do
3654 cp /etc/passwd $DIR/$tdir/$i
3655 $LFS hsm_archive $DIR/$tdir/$i
3657 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3658 $HSM_PARAM.actions |\
3659 grep WAITING | wc -l")
3662 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3663 $HSM_PARAM.actions |\
3664 grep WAITING | wc -l")
3667 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3668 error "Requests count after shutdown $reqcnt2 != "\
3669 "before shutdown $reqcnt1"
3671 run_test 105 "Restart of coordinator"
3674 # test needs a running copytool
3677 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3679 check_agent_registered $uuid
3681 search_copytools || error "No copytool found"
3684 check_agent_unregistered $uuid
3687 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3688 check_agent_registered $uuid
3692 run_test 106 "Copytool register/unregister"
3695 # test needs a running copytool
3697 # create and archive file
3699 local f1=$DIR/$tdir/$tfile
3700 local fid=$(copy_file /etc/passwd $f1)
3701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3702 wait_request_state $fid ARCHIVE SUCCEED
3703 # shutdown and restart MDS
3705 # check the copytool still gets messages from MDT
3706 local f2=$DIR/$tdir/2
3707 local fid=$(copy_file /etc/passwd $f2)
3708 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3709 # main check of this sanity: this request MUST succeed
3710 wait_request_state $fid ARCHIVE SUCCEED
3713 run_test 107 "Copytool re-register after MDS restart"
3715 policy_set_and_test()
3719 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3720 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3721 [[ "$policy" == "$target" ]] ||
3722 error "Wrong policy after '$change': '$policy' != '$target'"
3726 # to force default policy setting if error
3727 CDT_POLICY_HAD_CHANGED=true
3729 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3730 local default="NonBlockingRestore [NoRetryAction]"
3731 [[ "$policy" == "$default" ]] ||
3732 error "default policy has changed,"\
3733 " '$policy' != '$default' update the test"
3734 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3735 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3736 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3737 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3738 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3739 # useless bacause we know but safer for futur changes to use real value
3740 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3741 echo "Next set_param must failed"
3742 policy_set_and_test "wrong" "$policy"
3745 echo "Back to default policy"
3746 cdt_set_sanity_policy
3748 run_test 109 "Policy display/change"
3751 # test needs a running copytool
3756 copy2archive /etc/passwd $tdir/$tfile
3758 local f=$DIR/$tdir/$tfile
3759 import_file $tdir/$tfile $f
3760 local fid=$(path2fid $f)
3762 cdt_set_non_blocking_restore
3767 wait_request_state $fid RESTORE SUCCEED
3768 cdt_clear_non_blocking_restore
3772 error "md5sum returns $st != 1, "\
3773 "should also perror ENODATA (No data available)"
3777 run_test 110a "Non blocking restore policy (import case)"
3780 # test needs a running copytool
3784 local f=$DIR/$tdir/$tfile
3785 local fid=$(copy_file /etc/passwd $f)
3786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3787 wait_request_state $fid ARCHIVE SUCCEED
3790 cdt_set_non_blocking_restore
3795 wait_request_state $fid RESTORE SUCCEED
3796 cdt_clear_non_blocking_restore
3800 error "md5sum returns $st != 1, "\
3801 "should also perror ENODATA (No data available)"
3805 run_test 110b "Non blocking restore policy (release case)"
3808 # test needs a running copytool
3812 copy2archive /etc/passwd $tdir/$tfile
3814 local f=$DIR/$tdir/$tfile
3816 import_file $tdir/$tfile $f
3817 local fid=$(path2fid $f)
3821 copytool_remove_backend $fid
3824 wait_request_state $fid RESTORE FAILED
3831 [[ $st == 0 ]] || error "Restore does not failed"
3835 run_test 111a "No retry policy (import case), restore will error"\
3836 " (No such file or directory)"
3839 # test needs a running copytool
3843 local f=$DIR/$tdir/$tfile
3844 local fid=$(copy_file /etc/passwd $f)
3846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3847 wait_request_state $fid ARCHIVE SUCCEED
3850 copytool_remove_backend $fid
3853 wait_request_state $fid RESTORE FAILED
3860 [[ $st == 0 ]] || error "Restore does not failed"
3864 run_test 111b "No retry policy (release case), restore will error"\
3865 " (No such file or directory)"
3868 # test needs a running copytool
3872 local f=$DIR/$tdir/$tfile
3873 local fid=$(copy_file /etc/passwd $f)
3875 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3876 local l=$($LFS hsm_action $f)
3878 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3882 wait_request_state $fid ARCHIVE SUCCEED
3885 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3889 run_test 112 "State of recorded request"
3892 # test needs a running copytool
3896 local f=$DIR/$tdir/$tfile
3898 fid=$(make_custom_file_for_progress $f 103 1048576)
3899 [ $? != 0 ] && skip "not enough free space" && return
3901 # test with cdt on is made in test_221
3903 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3904 # wait archive to register at CDT
3905 wait_request_state $fid ARCHIVE WAITING
3908 wait_request_state $fid ARCHIVE CANCELED
3909 wait_request_state $fid CANCEL SUCCEED
3913 run_test 200 "Register/Cancel archive"
3916 # test needs a running copytool
3920 local f=$DIR/$tdir/$tfile
3921 make_archive $tdir/$tfile
3922 import_file $tdir/$tfile $f
3923 local fid=$(path2fid $f)
3925 # test with cdt on is made in test_222
3928 # wait restore to register at CDT
3929 wait_request_state $fid RESTORE WAITING
3932 wait_request_state $fid RESTORE CANCELED
3933 wait_request_state $fid CANCEL SUCCEED
3937 run_test 201 "Register/Cancel restore"
3940 # test needs a running copytool
3944 local f=$DIR/$tdir/$tfile
3946 fid=$(make_custom_file_for_progress $f 39 1000000)
3947 [ $? != 0 ] && skip "not enough free space" && return
3949 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3950 wait_request_state $fid ARCHIVE SUCCEED
3954 # wait remove to register at CDT
3955 wait_request_state $fid REMOVE WAITING
3958 wait_request_state $fid REMOVE CANCELED
3962 run_test 202 "Register/Cancel remove"
3965 # test needs a running copytool
3970 local f=$DIR/$tdir/$tfile
3971 local fid=$(copy_file /etc/passwd $f)
3975 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3976 wait_request_state $fid ARCHIVE SUCCEED
3978 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3982 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3986 run_test 220 "Changelog for archive"
3989 # test needs a running copytool
3994 local f=$DIR/$tdir/$tfile
3995 local fid=$(copy_file /etc/passwd $f)
3999 # block copytool operations to allow for HSM request to be
4000 # submitted and file be unlinked (CDT will find object removed)
4003 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4009 wait_request_state $fid ARCHIVE FAILED
4011 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4016 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4020 run_test 220a "Changelog for failed archive"
4023 # test needs a running copytool
4028 local f=$DIR/$tdir/$tfile
4030 fid=$(make_custom_file_for_progress $f 103 1048576)
4031 [ $? != 0 ] && skip "not enough free space" && return
4035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4036 wait_request_state $fid ARCHIVE STARTED
4038 wait_request_state $fid ARCHIVE CANCELED
4039 wait_request_state $fid CANCEL SUCCEED
4041 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4044 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4048 run_test 221 "Changelog for archive canceled"
4051 # test needs a running copytool
4055 copy2archive /etc/passwd $tdir/$tfile
4057 local f=$DIR/$tdir/$tfile
4058 import_file $tdir/$tfile $f
4059 local fid=$(path2fid $f)
4064 wait_request_state $fid RESTORE SUCCEED
4066 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4069 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4073 run_test 222a "Changelog for explicit restore"
4076 # test needs a running copytool
4080 local f=$DIR/$tdir/$tfile
4081 local fid=$(copy_file /etc/passwd $f)
4084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4085 wait_request_state $fid ARCHIVE SUCCEED
4090 wait_request_state $fid RESTORE SUCCEED
4092 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4095 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4099 run_test 222b "Changelog for implicit restore"
4102 # test needs a running copytool
4106 copy2archive /etc/passwd $tdir/$tfile
4108 local f=$DIR/$tdir/$tfile
4109 import_file $tdir/$tfile $f
4110 local fid=$(path2fid $f)
4114 # block copytool operations to allow for HSM request to be
4115 # submitted and file be unlinked (CDT will find object removed)
4123 wait_request_state $fid RESTORE FAILED
4125 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4129 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4133 run_test 222c "Changelog for failed explicit restore"
4136 # test needs a running copytool
4140 local f=$DIR/$tdir/$tfile
4141 local fid=$(copy_file /etc/passwd $f)
4144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4145 wait_request_state $fid ARCHIVE SUCCEED
4148 copytool_remove_backend $fid
4151 wait_request_state $fid RESTORE FAILED
4153 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4157 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4161 run_test 222d "Changelog for failed implicit restore"
4164 # test needs a running copytool
4169 local f=$DIR/$tdir/$tfile
4170 make_archive $tdir/$tfile
4174 import_file $tdir/$tfile $f
4175 local fid=$(path2fid $f)
4178 wait_request_state $fid RESTORE STARTED
4180 wait_request_state $fid RESTORE CANCELED
4181 wait_request_state $fid CANCEL SUCCEED
4183 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4186 [[ $flags == $target ]] ||
4187 error "Changelog flag is $flags not $target"
4191 run_test 223a "Changelog for restore canceled (import case)"
4194 # test needs a running copytool
4199 local f=$DIR/$tdir/$tfile
4201 fid=$(make_custom_file_for_progress $f 39 1000000)
4202 [ $? != 0 ] && skip "not enough free space" && return
4205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4206 wait_request_state $fid ARCHIVE SUCCEED
4209 wait_request_state $fid RESTORE STARTED
4211 wait_request_state $fid RESTORE CANCELED
4212 wait_request_state $fid CANCEL SUCCEED
4214 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4217 [[ $flags == $target ]] ||
4218 error "Changelog flag is $flags not $target"
4222 run_test 223b "Changelog for restore canceled (release case)"
4225 # test needs a running copytool
4230 local f=$DIR/$tdir/$tfile
4231 local fid=$(copy_file /etc/passwd $f)
4234 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4235 wait_request_state $fid ARCHIVE SUCCEED
4238 wait_request_state $fid REMOVE SUCCEED
4240 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4243 [[ $flags == $target ]] ||
4244 error "Changelog flag is $flags not $target"
4248 run_test 224 "Changelog for remove"
4251 # test needs a running copytool
4256 local f=$DIR/$tdir/$tfile
4257 local fid=$(copy_file /etc/passwd $f)
4260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4261 wait_request_state $fid ARCHIVE SUCCEED
4263 copytool_remove_backend $fid
4265 # block copytool operations to allow for HSM request to be
4266 # submitted and file be unlinked (CDT will find object removed)
4274 wait_request_state $fid REMOVE FAILED
4276 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4280 [[ $flags == $target ]] ||
4281 error "Changelog flag is $flags not $target"
4285 run_test 224a "Changelog for failed remove"
4288 # test needs a running copytool
4291 # test is not usable because remove request is too fast
4292 # so it is always finished before cancel can be done ...
4293 echo "Test disabled"
4298 local f=$DIR/$tdir/$tfile
4300 fid=$(make_custom_file_for_progress $f 39 1000000)
4301 [ $? != 0 ] && skip "not enough free space" && return
4304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4305 wait_request_state $fid ARCHIVE SUCCEED
4307 # if cdt is on, it can serve too quickly the request
4312 wait_request_state $fid REMOVE CANCELED
4313 wait_request_state $fid CANCEL SUCCEED
4315 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4316 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4317 tail -n 1 | awk '{print $5}')
4320 [[ $flags == $target ]] ||
4321 error "Changelog flag is $flags not $target"
4325 run_test 225 "Changelog for remove canceled"
4328 # test needs a running copytool
4333 local f1=$DIR/$tdir/$tfile-1
4334 local f2=$DIR/$tdir/$tfile-2
4335 local f3=$DIR/$tdir/$tfile-3
4336 local fid1=$(copy_file /etc/passwd $f1)
4337 local fid2=$(copy_file /etc/passwd $f2)
4338 copy_file /etc/passwd $f3
4341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4342 wait_request_state $fid1 ARCHIVE SUCCEED
4344 $LFS hsm_archive $f2
4345 wait_request_state $fid2 ARCHIVE SUCCEED
4347 rm $f1 || error "rm $f1 failed"
4349 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4352 [[ $flags == $target ]] ||
4353 error "Changelog flag is $flags not $target"
4355 mv $f3 $f2 || error "mv $f3 $f2 failed"
4357 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4360 [[ $flags == $target ]] ||
4361 error "Changelog flag is $flags not $target"
4365 run_test 226 "changelog for last rm/mv with exiting archive"
4367 check_flags_changes() {
4375 $LFS hsm_set --$hsm_flag $f ||
4376 error "Cannot set $hsm_flag on $f"
4377 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4378 local seen=${#flags[*]}
4380 [[ $seen == $cnt ]] ||
4381 error "set $hsm_flag: Changelog events $seen != $cnt"
4382 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4383 error "set $hsm_flag: Changelog flags are "\
4384 "${flags[$((cnt - 1))]} not $target"
4386 $LFS hsm_clear --$hsm_flag $f ||
4387 error "Cannot clear $hsm_flag on $f"
4388 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4391 [[ $cnt == $seen ]] ||
4392 error "clear $hsm_flag: Changelog events $seen != $cnt"
4394 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4395 error "clear $hsm_flag: Changelog flag is "\
4396 "${flags[$((cnt - 1))]} not $target"
4400 # test needs a running copytool
4407 for i in norelease noarchive exists archived
4409 local f=$DIR/$tdir/$tfile-$i
4410 local fid=$(copy_file /etc/passwd $f)
4411 check_flags_changes $f $fid $i 0 1
4414 f=$DIR/$tdir/$tfile---lost
4415 fid=$(copy_file /etc/passwd $f)
4416 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4417 wait_request_state $fid ARCHIVE SUCCEED
4418 check_flags_changes $f $fid lost 3 1
4422 run_test 227 "changelog when explicit setting of HSM flags"
4425 # test needs a running copytool
4428 local fid=$(make_small_sync $DIR/$tfile)
4429 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4430 wait_request_state $fid ARCHIVE SUCCEED
4432 $LFS hsm_release $DIR/$tfile
4433 check_hsm_flags $DIR/$tfile "0x0000000d"
4435 filefrag $DIR/$tfile | grep " 1 extent found" ||
4436 error "filefrag on released file must return only one extent"
4438 # only newer versions of cp detect sparse files by stat/FIEMAP
4440 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4441 error "copying $DIR/$tfile"
4442 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4444 $LFS hsm_release $DIR/$tfile
4445 check_hsm_flags $DIR/$tfile "0x0000000d"
4447 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4449 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4451 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4452 error "comparing untarred $DIR/$tfile"
4454 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4455 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4458 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4461 # test needs a running copytool
4465 local maxrequest=$(get_hsm_param max_requests)
4466 local rqcnt=$(($maxrequest * 3))
4470 for i in $(seq -w 1 $rqcnt); do
4472 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4474 # we do it in 2 steps, so all requests arrive at the same time
4475 for i in $(seq -w 1 $rqcnt); do
4476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4481 while [[ $cnt != 0 || $wt != 0 ]]; do
4483 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4484 $HSM_PARAM.actions |\
4485 grep STARTED | grep -v CANCEL | wc -l")
4486 [[ $cnt -le $maxrequest ]] ||
4487 error "$cnt > $maxrequest too many started requests"
4488 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4489 $HSM_PARAM.actions |\
4490 grep WAITING | wc -l")
4491 echo "max=$maxrequest started=$cnt waiting=$wt"
4496 run_test 250 "Coordinator max request"
4499 # test needs a running copytool
4503 local f=$DIR/$tdir/$tfile
4505 fid=$(make_custom_file_for_progress $f 103 1048576)
4506 [ $? != 0 ] && skip "not enough free space" && return
4509 # to have a short test
4510 local old_to=$(get_hsm_param active_request_timeout)
4511 set_hsm_param active_request_timeout 4
4512 # to be sure the cdt will wake up frequently so
4513 # it will be able to cancel the "old" request
4514 local old_loop=$(get_hsm_param loop_period)
4515 set_hsm_param loop_period 2
4518 # clear locks to avoid extra delay caused by flush/cancel
4519 # and thus prevent early copytool death to timeout.
4520 cancel_lru_locks osc
4522 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4523 wait_request_state $fid ARCHIVE STARTED
4525 wait_request_state $fid ARCHIVE CANCELED
4527 set_hsm_param active_request_timeout $old_to
4528 set_hsm_param loop_period $old_loop
4532 run_test 251 "Coordinator request timeout"
4535 # the only way to test ondisk conf is to restart MDS ...
4536 echo "Stop coordinator and remove coordinator state at mount"
4539 # clean on disk conf set by default
4540 cdt_clear_mount_state
4541 cdt_check_state stopped
4543 # check cdt still off after umount/remount
4545 cdt_check_state stopped
4547 echo "Set coordinator start at mount, and start coordinator"
4548 cdt_set_mount_state enabled
4551 cdt_check_state enabled
4553 # check cdt still on after umount/remount
4555 cdt_check_state enabled
4557 # we are back to original state (cdt started at mount)
4559 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4562 local ai=$(get_hsm_param default_archive_id)
4563 local new=$((ai + 1))
4565 set_hsm_param default_archive_id $new -P
4567 local res=$(get_hsm_param default_archive_id)
4570 set_hsm_param default_archive_id "" "-P -d"
4572 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4574 run_test 301 "HSM tunnable are persistent"
4577 local ai=$(get_hsm_param default_archive_id)
4578 local new=$((ai + 1))
4583 set_hsm_param default_archive_id $new -P
4586 for mdtno in $(seq 1 $MDSCOUNT); do
4591 cdt_check_state enabled
4593 local res=$(get_hsm_param default_archive_id)
4596 set_hsm_param default_archive_id "" "-P -d"
4598 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4600 run_test 302 "HSM tunnable are persistent when CDT is off"
4603 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4609 local dir_mdt0=$DIR/$tdir/mdt0
4610 local dir_mdt1=$DIR/$tdir/mdt1
4612 # create 1 dir per MDT
4613 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4614 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4616 # create 1 file in each MDT
4617 local fid1=$(make_small $dir_mdt0/$tfile)
4618 local fid2=$(make_small $dir_mdt1/$tfile)
4620 # check that hsm request on mdt0 is sent to the right MDS
4621 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4622 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4623 echo "archive successful on mdt0"
4625 # check that hsm request on mdt1 is sent to the right MDS
4626 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4627 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4628 echo "archive successful on mdt1"
4631 # clean test files and directories
4632 rm -rf $dir_mdt0 $dir_mdt1
4634 run_test 400 "Single request is sent to the right MDT"
4637 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4643 local dir_mdt0=$DIR/$tdir/mdt0
4644 local dir_mdt1=$DIR/$tdir/mdt1
4646 # create 1 dir per MDT
4647 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4648 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4650 # create 1 file in each MDT
4651 local fid1=$(make_small $dir_mdt0/$tfile)
4652 local fid2=$(make_small $dir_mdt1/$tfile)
4654 # check that compound requests are shunt to the rights MDTs
4655 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4656 error "lfs hsm_archive"
4657 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4658 echo "archive successful on mdt0"
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 401 "Compound requests split and sent to their respective MDTs"
4668 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4673 local node=$(facet_active_host $facet)
4675 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4676 awk '{print $4}'); do
4677 echo "$3 $mdc on $node"
4678 do_facet $facet "$LCTL --device $mdc $state" || return 1
4683 # make sure there is no running copytool
4686 # deactivate all mdc on agent1
4687 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4689 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4691 check_agent_unregistered "uuid" # match any agent
4693 # no expected running copytool
4694 search_copytools $agent && error "Copytool start should have failed"
4697 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4699 run_test 402a "Copytool start fails if all MDTs are inactive"
4706 local f=$DIR/$tdir/$tfile
4707 touch $f || error "touch $f failed"
4708 local fid=$(path2fid $f)
4710 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4711 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4712 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4714 # give time for CDT to send request and to keep it for retry
4715 wait_for_loop_period
4717 wait_request_state $fid ARCHIVE WAITING
4719 do_facet $SINGLEAGT lctl set_param fail_loc=0
4721 # request should succeed now
4722 wait_request_state $fid ARCHIVE SUCCEED
4726 run_test 402b "CDT must retry request upon slow start of CT"
4729 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4731 # make sure there is no running copytool
4734 local agent=$(facet_active_host $SINGLEAGT)
4736 # deactivate all mdc for MDT0001
4737 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4740 local uuid=$(get_agent_uuid $agent)
4741 # check the agent is registered on MDT0000, and not on MDT0001
4742 check_agent_registered_by_mdt $uuid 0
4743 check_agent_unregistered_by_mdt $uuid 1
4745 # check running copytool process
4746 search_copytools $agent || error "No running copytools on $agent"
4748 # reactivate all mdc for MDT0001
4749 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4751 # make sure the copytool is now registered to all MDTs
4752 check_agent_registered $uuid
4756 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4759 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4763 # create files on both MDT0000 and MDT0001
4766 local dir_mdt0=$DIR/$tdir/mdt0
4767 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4769 # create 1 file on mdt0
4770 local fid1=$(make_small $dir_mdt0/$tfile)
4772 # deactivate all mdc for MDT0001
4773 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4775 # send an HSM request for files in MDT0000
4776 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4778 # check for completion of files in MDT0000
4779 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4780 echo "archive successful on mdt0"
4782 # reactivate all mdc for MDT0001
4783 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4786 # clean test files and directories
4789 run_test 404 "Inactive MDT does not block requests for active MDTs"
4792 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4798 local striped_dir=$DIR/$tdir/striped_dir
4800 # create striped dir on all of MDTs
4801 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4803 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4804 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4805 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4806 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4808 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4809 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4810 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4811 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4813 # check that compound requests are shunt to the rights MDTs
4814 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4815 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4816 error "lfs hsm_archive"
4818 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4819 echo "archive successful on $fid1"
4820 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4821 echo "archive successful on $fid2"
4822 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4823 echo "archive successful on $fid3"
4824 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4825 echo "archive successful on $fid4"
4827 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4828 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4829 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4830 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4832 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4833 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4834 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4835 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4839 run_test 405 "archive and release under striped directory"
4842 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4844 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4845 skip "need MDS version at least 2.7.64" && return 0
4852 fid=$(make_small $DIR/$tdir/$tfile)
4855 $LFS hsm_archive $DIR/$tdir/$tfile
4856 wait_request_state "$fid" ARCHIVE SUCCEED
4857 $LFS hsm_release $DIR/$tdir/$tfile
4859 # Should migrate $tdir but not $tfile.
4860 $LFS mv -M1 $DIR/$tdir &&
4861 error "migrating HSM an archived file should fail"
4863 $LFS hsm_restore $DIR/$tdir/$tfile
4864 wait_request_state "$fid" RESTORE SUCCEED
4866 $LFS hsm_remove $DIR/$tdir/$tfile
4867 wait_request_state "$fid" REMOVE SUCCEED
4869 cat $DIR/$tdir/$tfile > /dev/null ||
4870 error "cannot read $DIR/$tdir/$tfile"
4872 $LFS mv -M1 $DIR/$tdir ||
4873 error "cannot complete migration after HSM remove"
4875 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4876 if ((mdt_index != 1)); then
4877 error "expected MDT index 1, got $mdt_index"
4880 # Refresh fid after migration.
4881 fid=$(path2fid $DIR/$tdir/$tfile)
4884 $LFS hsm_archive $DIR/$tdir/$tfile
4885 wait_request_state "$fid" ARCHIVE SUCCEED 1
4887 lctl set_param debug=+trace
4888 $LFS hsm_release $DIR/$tdir/$tfile ||
4889 error "cannot release $DIR/$tdir/$tfile"
4891 $LFS hsm_restore $DIR/$tdir/$tfile
4892 wait_request_state "$fid" RESTORE SUCCEED 1
4894 cat $DIR/$tdir/$tfile > /dev/null ||
4895 error "cannot read $DIR/$tdir/$tfile"
4899 run_test 406 "attempting to migrate HSM archived files is safe"
4903 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4904 skip "HSM migrate is not supported" && return
4906 # Stop the existing copytool
4909 test_mkdir -p $DIR/$tdir
4910 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4912 run_test 500 "various LLAPI HSM tests"
4917 check_and_cleanup_lustre