3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
174 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
184 # try to dump Copytool's stack
185 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
186 "echo t >/proc/sysrq-trigger"
188 echo "copytools failed to stop in ${wait_timeout}s"
193 copytool_monitor_setup() {
194 local facet=${1:-$SINGLEAGT}
195 local agent=$(facet_active_host $facet)
197 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
198 local test_dir=$(do_node $agent "$cmd") ||
199 error "Failed to create tempdir on $agent"
200 export HSMTOOL_MONITOR_DIR=$test_dir
202 # Create the fifo and a monitor (cat dies when copytool dies)
203 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
204 error "failed to create copytool fifo on $agent"
205 cmd="cat $test_dir/fifo > $test_dir/events &"
206 cmd+=" echo \\\$! > $test_dir/monitor_pid"
208 if [[ $PDSH == *Rmrsh* ]]; then
209 # This is required for pdsh -Rmrsh and its handling of remote
211 # Regular ssh and pdsh -Rssh work fine without this
212 # backgrounded subshell nonsense.
213 (do_node $agent "$cmd") &
214 export HSMTOOL_MONITOR_PDSH=$!
216 # Slightly racy, but just making a best-effort to catch obvious
219 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
220 error "Failed to start copytool monitor on $agent"
222 do_node $agent "$cmd"
224 error "Failed to start copytool monitor on $agent"
229 copytool_monitor_cleanup() {
230 local facet=${1:-$SINGLEAGT}
231 local agent=$(facet_active_host $facet)
233 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
234 # Should die when the copytool dies, but just in case.
235 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
236 cmd+=" 2>/dev/null || true"
237 do_node $agent "$cmd"
238 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
239 export HSMTOOL_MONITOR_DIR=
242 # The pdsh should die on its own when the monitor dies. Just
243 # in case, though, try to clean up to avoid any cruft.
244 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
245 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
246 export HSMTOOL_MONITOR_PDSH=
251 local facet=${1:-$SINGLEAGT}
252 # Use MOUNT2 by default if defined
253 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
255 local hsm_root=${4:-$(copytool_device $facet)}
257 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
259 local agent=$(facet_active_host $facet)
261 if [[ -z "$arc_id" ]] &&
262 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
263 echo "Only wakeup running copytool $facet on $agent"
267 if $HSM_ARCHIVE_PURGE; then
268 echo "Purging archive on $agent"
269 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
272 echo "Starting copytool $facet on $agent"
273 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
274 error "mkdir '$hsm_root/$HSMTMP' failed"
275 # bandwidth is limited to 1MB/s so the copy time is known and
276 # independent of hardware
277 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
278 cmd+=" --hsm-root $hsm_root/$HSMTMP"
279 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
280 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
281 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
282 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
283 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
284 cmd+=" --bandwidth 1 $lustre_mntpnt"
286 # Redirect the standard output and error to a log file which
287 # can be uploaded to Maloo.
288 local prefix=$TESTLOG_PREFIX
289 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
290 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
292 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
293 if [[ $? != 0 ]]; then
294 [[ $HSMTOOL_NOERROR == true ]] ||
295 error "start copytool $facet on $agent failed"
296 echo "start copytool $facet on $agent failed"
302 get_copytool_event_log() {
303 local facet=${1:-$SINGLEAGT}
304 local agent=$(facet_active_host $facet)
306 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
307 error "Can't get event log: No monitor directory!"
309 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
310 error "Could not collect event log from $agent"
315 local agt_facet=$SINGLEAGT
316 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
317 local hsm_root=$(copytool_device $agt_facet)
319 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
326 kill_copytools $agt_hosts
327 wait_copytools $agt_hosts || error "copytools failed to stop"
329 # Clean all CDTs orphans requests from previous tests that
330 # would otherwise need to timeout to clear.
331 for ((i = 0; i < MDSCOUNT; i++)); do
333 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
334 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
336 # Skip already stopping or stopped CDTs.
337 [[ "${state[$i]}" =~ ^stop ]] && continue
339 do_facet $facet "$LCTL set_param $param=shutdown"
342 for ((i = 0; i < MDSCOUNT; i++)); do
343 # Only check and restore CDTs that we stopped in the first loop.
344 [[ "${state[$i]}" =~ ^stop ]] && continue
347 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
349 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
350 error "$facet CDT state is not stopped"
352 # Restore old CDT state.
353 do_facet $facet "$LCTL set_param $param=${state[$i]}"
356 for ((i = 0; i < MDSCOUNT; i++)); do
357 # Only check CDTs that we stopped in the first loop.
358 [[ "${state[$i]}" =~ ^stop ]] && continue
361 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
363 # Check that the old CDT state was restored.
364 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
365 20 || error "$facet CDT state is not '${state[$i]}'"
368 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
369 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
374 local agents=${1:-$(facet_active_host $SINGLEAGT)}
376 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
377 echo "Copytool is suspended on $agents"
380 copytool_remove_backend() {
382 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
383 echo "Remove from backend: $fid = $be"
384 do_facet $SINGLEAGT rm -f $be
388 do_facet $SINGLEAGT \
389 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
390 --import $1 $2 $MOUNT" ||
391 error "import of $1 to $2 failed"
395 local file=$HSM_ARCHIVE/$1
396 do_facet $SINGLEAGT mkdir -p $(dirname $file)
397 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
398 file_creation_failure dd $file $?
402 local file=$HSM_ARCHIVE/$2
403 do_facet $SINGLEAGT mkdir -p $(dirname $file)
404 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
413 if [[ "$value" != "" ]]; then
416 for mdtno in $(seq 1 $MDSCOUNT); do
417 local idx=$(($mdtno - 1))
418 local facet=mds${mdtno}
419 # if $arg include -P option, run 1 set_param per MDT on the MGS
420 # else, run set_param on each MDT
421 [[ $arg = *"-P"* ]] && facet=mgs
422 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
423 [[ $? != 0 ]] && rc=1
433 for mdtno in $(seq 1 $MDSCOUNT); do
434 local idx=$(($mdtno - 1))
435 wait_result mds${mdtno} \
436 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
438 error "$key state is not '$target' on mds${mdtno}"
445 for mdtno in $(seq 1 $MDSCOUNT); do
446 local idx=$(($mdtno - 1))
447 local cl_user=$(do_facet mds${mdtno} $LCTL \
448 --device ${MDT[$idx]} \
449 changelog_register -n)
451 do_facet mds${mdtno} lctl set_param \
452 mdd.${MDT[$idx]}.changelog_mask="+hsm"
453 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
457 changelog_cleanup() {
459 for mdtno in $(seq 1 $MDSCOUNT); do
460 local idx=$(($mdtno - 1))
461 [[ -z ${CL_USERS[$idx]} ]] && continue
462 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
463 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
464 changelog_deregister ${CL_USERS[$idx]}
469 changelog_get_flags() {
474 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
479 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
487 mdts_set_param "$opt -n" "hsm.$param" "$value"
494 mdts_set_param "" hsm_control "$cmd"
495 mdts_check_param hsm_control "$target" 10
498 cdt_set_sanity_policy() {
499 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
502 mdts_set_param "" hsm.policy "+NRA"
503 mdts_set_param "" hsm.policy "-NBR"
504 CDT_POLICY_HAD_CHANGED=
509 mdts_set_param "" hsm.policy "+NRA"
510 CDT_POLICY_HAD_CHANGED=true
513 cdt_clear_no_retry() {
514 mdts_set_param "" hsm.policy "-NRA"
515 CDT_POLICY_HAD_CHANGED=true
518 cdt_set_non_blocking_restore() {
519 mdts_set_param "" hsm.policy "+NBR"
520 CDT_POLICY_HAD_CHANGED=true
523 cdt_clear_non_blocking_restore() {
524 mdts_set_param "" hsm.policy "-NBR"
525 CDT_POLICY_HAD_CHANGED=true
528 cdt_clear_mount_state() {
529 mdts_set_param "-P -d" hsm_control ""
532 cdt_set_mount_state() {
533 mdts_set_param "-P" hsm_control "$1"
534 # set_param -P is asynchronous operation and could race with set_param.
535 # In such case configs could be retrieved and applied at mgc after
536 # set_param -P completion. Sleep here to avoid race with set_param.
537 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
538 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
539 # and 10 seconds to retrieve config from server.
544 mdts_check_param hsm_control "$1" 20
548 set_test_state disabled disabled
552 set_test_state enabled enabled
556 set_test_state shutdown stopped
560 set_test_state purge enabled
566 cdt_set_sanity_policy
570 local client_count=$1
571 if [[ $CLIENTCOUNT -lt $client_count ]]; then
572 skip "Need $client_count or more clients, have $CLIENTCOUNT"
579 $LFS path2fid $1 | tr -d '[]'
580 return ${PIPESTATUS[0]}
588 if [[ $u == "user" ]]; then
589 st=$($RUNAS $LFS hsm_state $f)
592 st=$($LFS hsm_state $f)
595 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
597 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
601 get_hsm_archive_id() {
604 st=$($LFS hsm_state $f)
605 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
607 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
616 local st=$(get_hsm_flags $f)
617 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
620 check_hsm_flags_user() {
624 local st=$(get_hsm_flags $f user)
625 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
628 file_creation_failure() {
633 df $MOUNT $MOUNT2 >&2
634 error "cannot create $f with $cmd, status=$err"
646 if [[ "$3" != 1 ]]; then
650 cp $1 $f || file_creation_failure cp $f $?
652 path2fid $f || error "cannot get fid on $f"
656 local file2=${1/$DIR/$DIR2}
657 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
658 file_creation_failure dd $file2 $?
660 path2fid $1 || error "cannot get fid on $1"
664 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
665 file_creation_failure dd $1 $?
666 path2fid $1 || error "cannot get fid on $1"
669 cleanup_large_files() {
670 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
672 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
675 check_enough_free_space() {
678 local need=$((nb * unit /1024))
679 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
680 (( $need >= $free )) && return 1
684 make_custom_file_for_progress() {
685 local file2=${1/$DIR/$DIR2}
686 local fsize=${2:-"39"}
687 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
690 [[ $fsize -gt 0 ]] || error "Invalid file size"
691 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
694 check_enough_free_space $fsize $blksz
695 [ $? != 0 ] && 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 "Start copytool"
851 echo "Set sanity-hsm HSM policy"
852 cdt_set_sanity_policy
854 # finished requests are quickly removed from list
855 set_hsm_param grace_delay 10
861 local f=$DIR/$tdir/$tfile
865 check_hsm_flags_user $f "0x00000000"
867 $RUNAS $LFS hsm_set --norelease $f ||
868 error "user could not change hsm flags"
869 check_hsm_flags_user $f "0x00000010"
871 $RUNAS $LFS hsm_clear --norelease $f ||
872 error "user could not clear hsm flags"
873 check_hsm_flags_user $f "0x00000000"
875 # User could not change those flags...
876 $RUNAS $LFS hsm_set --exists $f &&
877 error "user should not set this flag"
878 check_hsm_flags_user $f "0x00000000"
881 $LFS hsm_set --exists $f ||
882 error "root could not change hsm flags"
883 check_hsm_flags_user $f "0x00000001"
885 $LFS hsm_clear --exists $f ||
886 error "root could not clear hsm state"
887 check_hsm_flags_user $f "0x00000000"
890 run_test 1 "lfs hsm flags root/non-root access"
894 local f=$DIR/$tdir/$tfile
895 local fid=$(make_small $f)
897 $LFS hsm_archive $f || error "could not archive file"
898 wait_request_state $fid ARCHIVE SUCCEED
900 # Release and check states
901 $LFS hsm_release $f || error "could not release file"
902 echo -n "Verifying released state: "
903 check_hsm_flags $f "0x0000000d"
905 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
907 run_test 1a "mmap & cat a HSM released file"
911 local f=$DIR/$tdir/$tfile
913 # New files are not dirty
914 check_hsm_flags $f "0x00000000"
916 # For test, we simulate an archived file.
917 $LFS hsm_set --exists $f || error "user could not change hsm flags"
918 check_hsm_flags $f "0x00000001"
920 # chmod do not put the file dirty
921 chmod 600 $f || error "could not chmod test file"
922 check_hsm_flags $f "0x00000001"
924 # chown do not put the file dirty
925 chown $RUNAS_ID $f || error "could not chown test file"
926 check_hsm_flags $f "0x00000001"
928 # truncate put the file dirty
929 $TRUNCATE $f 1 || error "could not truncate test file"
930 check_hsm_flags $f "0x00000003"
932 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
933 check_hsm_flags $f "0x00000001"
935 run_test 2 "Check file dirtyness when doing setattr"
941 # New files are not dirty
943 check_hsm_flags $f "0x00000000"
945 # For test, we simulate an archived file.
946 $LFS hsm_set --exists $f ||
947 error "user could not change hsm flags"
948 check_hsm_flags $f "0x00000001"
950 # Reading a file, does not set dirty
951 cat $f > /dev/null || error "could not read file"
952 check_hsm_flags $f "0x00000001"
954 # Open for write without modifying data, does not set dirty
955 openfile -f O_WRONLY $f || error "could not open test file"
956 check_hsm_flags $f "0x00000001"
958 # Append to a file sets it dirty
959 cp -p /etc/passwd $f.append || error "could not create file"
960 $LFS hsm_set --exists $f.append ||
961 error "user could not change hsm flags"
962 dd if=/etc/passwd of=$f.append bs=1 count=3\
963 conv=notrunc oflag=append status=noxfer ||
964 file_creation_failure dd $f.append $?
965 check_hsm_flags $f.append "0x00000003"
967 # Modify a file sets it dirty
968 cp -p /etc/passwd $f.modify || error "could not create file"
969 $LFS hsm_set --exists $f.modify ||
970 error "user could not change hsm flags"
971 dd if=/dev/zero of=$f.modify bs=1 count=3\
972 conv=notrunc status=noxfer ||
973 file_creation_failure dd $f.modify $?
974 check_hsm_flags $f.modify "0x00000003"
976 # Open O_TRUNC sets dirty
977 cp -p /etc/passwd $f.trunc || error "could not create file"
978 $LFS hsm_set --exists $f.trunc ||
979 error "user could not change hsm flags"
980 cp /etc/group $f.trunc || error "could not override a file"
981 check_hsm_flags $f.trunc "0x00000003"
983 # Mmapped a file sets dirty
984 cp -p /etc/passwd $f.mmap || error "could not create file"
985 $LFS hsm_set --exists $f.mmap ||
986 error "user could not change hsm flags"
987 multiop $f.mmap OSMWUc || error "could not mmap a file"
988 check_hsm_flags $f.mmap "0x00000003"
990 run_test 3 "Check file dirtyness when opening for write"
994 local f=$DIR/$tdir/$tfile
995 local fid=$(make_small $f)
998 local st=$(get_request_state $fid CANCEL)
999 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1001 run_test 4 "Useless cancel must not be registered"
1004 # test needs a running copytool
1008 local f=$DIR/$tdir/$tfile
1009 local fid=$(copy_file /etc/passwd $f)
1011 wait_request_state $fid ARCHIVE SUCCEED
1013 check_hsm_flags $f "0x00000009"
1017 run_test 8 "Test default archive number"
1020 # we do not use the default one to be sure
1021 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1023 copytool_setup $SINGLEAGT $MOUNT $new_an
1025 # give time for CT to register with MDTs
1026 sleep $(($MDSCOUNT*2))
1027 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1028 check_agent_registered $uuid
1031 local f=$DIR/$tdir/$tfile
1032 local fid=$(copy_file /etc/passwd $f)
1033 $LFS hsm_archive --archive $new_an $f
1034 wait_request_state $fid ARCHIVE SUCCEED
1036 check_hsm_flags $f "0x00000009"
1040 run_test 9 "Use of explicit archive number, with dedicated copytool"
1043 needclients 3 || return 0
1049 copytool_cleanup $(comma_list $(agts_nodes))
1051 # start all of the copytools
1052 for n in $(seq $AGTCOUNT); do
1053 copytool_setup agt$n
1056 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1059 for n in $(seq $AGTCOUNT); do
1060 file=$DIR/$tdir/$tfile.$n
1061 fid=$(make_small $file)
1063 $LFS hsm_archive $file || error "could not archive file $file"
1064 wait_request_state $fid ARCHIVE SUCCEED
1065 check_hsm_flags $file "0x00000009"
1069 copytool_cleanup $(comma_list $(agts_nodes))
1071 run_test 9a "Multiple remote agents"
1074 # test needs a running copytool
1077 mkdir -p $DIR/$tdir/d1
1078 local f=$DIR/$tdir/$tfile
1079 local fid=$(copy_file /etc/hosts $f)
1080 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1081 error "hsm_archive failed"
1082 wait_request_state $fid ARCHIVE SUCCEED
1084 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1085 error "fid $fid not in archive $HSM_ARCHIVE"
1086 echo "Verifying content"
1087 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1088 echo "Verifying hsm state "
1089 check_hsm_flags $f "0x00000009"
1091 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1092 local st=$(get_hsm_archive_id $f)
1093 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1094 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1099 run_test 10a "Archive a file"
1102 # test needs a running copytool
1106 local f=$DIR/$tdir/$tfile
1107 local fid=$(copy_file /etc/hosts $f)
1108 $LFS hsm_archive $f || error "archive request failed"
1109 wait_request_state $fid ARCHIVE SUCCEED
1111 $LFS hsm_archive $f || error "archive of non dirty file failed"
1112 local cnt=$(get_request_count $fid ARCHIVE)
1113 [[ "$cnt" == "1" ]] ||
1114 error "archive of non dirty file must not make a request"
1118 run_test 10b "Archive of non dirty file must work without doing request"
1121 # test needs a running copytool
1125 local f=$DIR/$tdir/$tfile
1126 local fid=$(copy_file /etc/hosts $f)
1127 $LFS hsm_set --noarchive $f
1128 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1132 run_test 10c "Check forbidden archive"
1135 # test needs a running copytool
1139 local f=$DIR/$tdir/$tfile
1140 local fid=$(copy_file /etc/hosts $f)
1141 $LFS hsm_archive $f || error "cannot archive $f"
1142 wait_request_state $fid ARCHIVE SUCCEED
1144 local ar=$(get_hsm_archive_id $f)
1145 local dflt=$(get_hsm_param default_archive_id)
1146 [[ $ar == $dflt ]] ||
1147 error "archived file is not on default archive: $ar != $dflt"
1151 run_test 10d "Archive a file on the default archive id"
1155 copy2archive /etc/hosts $tdir/$tfile
1156 local f=$DIR/$tdir/$tfile
1158 import_file $tdir/$tfile $f
1159 echo -n "Verifying released state: "
1160 check_hsm_flags $f "0x0000000d"
1162 local LSZ=$(stat -c "%s" $f)
1163 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1165 echo "Verifying imported size $LSZ=$ASZ"
1166 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1167 echo -n "Verifying released pattern: "
1168 local PTRN=$($GETSTRIPE -L $f)
1170 [[ $PTRN == 80000001 ]] || error "Is not released"
1171 local fid=$(path2fid $f)
1172 echo "Verifying new fid $fid in archive"
1174 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1175 error "fid $fid not in archive $HSM_ARCHIVE"
1177 run_test 11a "Import a file"
1180 # test needs a running copytool
1184 local f=$DIR/$tdir/$tfile
1185 local fid=$(copy_file /etc/hosts $f)
1186 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1187 error "hsm_archive failed"
1188 wait_request_state $fid ARCHIVE SUCCEED
1190 local FILE_HASH=$(md5sum $f)
1195 echo "$FILE_HASH" | md5sum -c
1197 [[ $? -eq 0 ]] || error "Restored file differs"
1201 run_test 11b "Import a deleted file using its FID"
1204 # test needs a running copytool
1208 copy2archive /etc/hosts $tdir/$tfile
1210 local f=$DIR/$tdir/$tfile
1211 import_file $tdir/$tfile $f
1212 local f2=$DIR2/$tdir/$tfile
1213 echo "Verifying released state: "
1214 check_hsm_flags $f2 "0x0000000d"
1216 local fid=$(path2fid $f2)
1217 $LFS hsm_restore $f2
1218 wait_request_state $fid RESTORE SUCCEED
1220 echo "Verifying file state: "
1221 check_hsm_flags $f2 "0x00000009"
1223 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1225 [[ $? -eq 0 ]] || error "Restored file differs"
1229 run_test 12a "Restore an imported file explicitly"
1232 # test needs a running copytool
1236 copy2archive /etc/hosts $tdir/$tfile
1238 local f=$DIR/$tdir/$tfile
1239 import_file $tdir/$tfile $f
1240 echo "Verifying released state: "
1241 check_hsm_flags $f "0x0000000d"
1243 cat $f > /dev/null || error "File read failed"
1245 echo "Verifying file state after restore: "
1246 check_hsm_flags $f "0x00000009"
1248 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1250 [[ $? -eq 0 ]] || error "Restored file differs"
1254 run_test 12b "Restore an imported file implicitly"
1257 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1259 # test needs a running copytool
1263 local f=$DIR/$tdir/$tfile
1264 $LFS setstripe -c 2 $f
1266 fid=$(make_custom_file_for_progress $f 5)
1267 [ $? != 0 ] && skip "not enough free space" && return
1269 local FILE_CRC=$(md5sum $f)
1271 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1272 wait_request_state $fid ARCHIVE SUCCEED
1273 $LFS hsm_release $f || error "release $f failed"
1275 echo "$FILE_CRC" | md5sum -c
1277 [[ $? -eq 0 ]] || error "Restored file differs"
1281 run_test 12c "Restore a file with stripe of 2"
1284 # test needs a running copytool
1289 local f=$DIR/$tdir/$tfile
1290 local fid=$(copy_file /etc/hosts $f)
1291 $LFS hsm_restore $f || error "restore of non archived file failed"
1292 local cnt=$(get_request_count $fid RESTORE)
1293 [[ "$cnt" == "0" ]] ||
1294 error "restore non archived must not make a request"
1295 $LFS hsm_archive $f ||
1296 error "archive request failed"
1297 wait_request_state $fid ARCHIVE SUCCEED
1298 $LFS hsm_restore $f ||
1299 error "restore of non released file failed"
1300 local cnt=$(get_request_count $fid RESTORE)
1301 [[ "$cnt" == "0" ]] ||
1302 error "restore a non dirty file must not make a request"
1306 run_test 12d "Restore of a non archived, non released file must work"\
1307 " without doing request"
1310 # test needs a running copytool
1313 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1314 local f=$DIR/$tdir/$tfile
1315 local fid=$(copy_file /etc/hosts $f)
1316 $LFS hsm_archive $f || error "archive request failed"
1317 wait_request_state $fid ARCHIVE SUCCEED
1320 cat /etc/hosts >> $f
1324 $LFS hsm_restore $f && error "restore a dirty file must fail"
1328 run_test 12e "Check forbidden restore"
1331 # test needs a running copytool
1335 local f=$DIR/$tdir/$tfile
1336 local fid=$(copy_file /etc/hosts $f)
1338 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1339 wait_request_state $fid ARCHIVE SUCCEED
1340 $LFS hsm_release $f || error "release of $f failed"
1342 wait_request_state $fid RESTORE SUCCEED
1344 echo -n "Verifying file state: "
1345 check_hsm_flags $f "0x00000009"
1347 diff -q /etc/hosts $f
1349 [[ $? -eq 0 ]] || error "Restored file differs"
1353 run_test 12f "Restore a released file explicitly"
1356 # test needs a running copytool
1360 local f=$DIR/$tdir/$tfile
1361 local fid=$(copy_file /etc/hosts $f)
1363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1364 wait_request_state $fid ARCHIVE SUCCEED
1365 $LFS hsm_release $f || error "release of $f failed"
1367 diff -q /etc/hosts $f
1370 # we check we had a restore done
1371 wait_request_state $fid RESTORE SUCCEED
1373 [[ $st -eq 0 ]] || error "Restored file differs"
1377 run_test 12g "Restore a released file implicitly"
1380 needclients 2 || return 0
1382 # test needs a running copytool
1386 local f=$DIR/$tdir/$tfile
1387 local fid=$(copy_file /etc/hosts $f)
1389 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1390 wait_request_state $fid ARCHIVE SUCCEED
1391 $LFS hsm_release $f || error "release of $f failed"
1393 do_node $CLIENT2 diff -q /etc/hosts $f
1396 # we check we had a restore done
1397 wait_request_state $fid RESTORE SUCCEED
1399 [[ $st -eq 0 ]] || error "Restored file differs"
1403 run_test 12h "Restore a released file implicitly from a second node"
1406 # test needs a running copytool
1410 local f=$DIR/$tdir/$tfile
1411 local fid=$(copy_file /etc/passwd $f)
1412 $LFS hsm_archive $f || error "archive of $f failed"
1413 wait_request_state $fid ARCHIVE SUCCEED
1415 $LFS hsm_release $f || error "release of $f failed"
1419 [[ $? -eq 0 ]] || error "Restored file differs"
1423 run_test 12m "Archive/release/implicit restore"
1426 # test needs a running copytool
1430 copy2archive /etc/hosts $tdir/$tfile
1432 local f=$DIR/$tdir/$tfile
1433 import_file $tdir/$tfile $f
1435 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1436 error "Restored file differs"
1438 $LFS hsm_release $f || error "release of $f failed"
1442 run_test 12n "Import/implicit restore/release"
1445 # test needs a running copytool
1449 local f=$DIR/$tdir/$tfile
1450 local fid=$(copy_file /etc/hosts $f)
1452 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1453 wait_request_state $fid ARCHIVE SUCCEED
1454 $LFS hsm_release $f || error "release of $f failed"
1456 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1457 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1459 # set no retry action mode
1462 diff -q /etc/hosts $f
1465 # we check we had a restore failure
1466 wait_request_state $fid RESTORE FAILED
1468 [[ $st -eq 0 ]] && error "Restore must fail"
1470 # remove no retry action mode
1473 # check file is still released
1474 check_hsm_flags $f "0x0000000d"
1476 # retry w/o failure injection
1477 do_facet $SINGLEMDS lctl set_param fail_loc=0
1479 # to be sure previous RESTORE result is gone
1481 wait_for_grace_delay
1483 diff -q /etc/hosts $f
1486 # we check we had a restore done
1487 wait_request_state $fid RESTORE SUCCEED
1489 [[ $st -eq 0 ]] || error "Restored file differs"
1493 run_test 12o "Layout-swap failure during Restore leaves file released"
1496 # test needs a running copytool
1500 local f=$DIR/$tdir/$tfile
1501 local fid=$(copy_file /etc/hosts $f)
1503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1504 wait_request_state $fid ARCHIVE SUCCEED
1505 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1506 $LFS hsm_release $f || error "cannot release $f"
1507 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1508 $LFS hsm_release $f || error "cannot release $f"
1509 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1513 run_test 12p "implicit restore of a file on copytool mount point"
1515 cleanup_test_12q() {
1517 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1518 error "cannot umount $MOUNT3 on $SINGLEAGT"
1522 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1523 skip "need MDS version at least 2.7.58" && return 0
1525 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1526 error "cannot mount $MOUNT3 on $SINGLEAGT"
1528 trap cleanup_test_12q EXIT
1530 # test needs a running copytool
1531 copytool_setup $SINGLEAGT $MOUNT3
1534 local f=$DIR/$tdir/$tfile
1535 local f2=$DIR2/$tdir/$tfile
1536 local fid=$(make_small $f)
1537 local orig_size=$(stat -c "%s" $f)
1539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1540 wait_request_state $fid ARCHIVE SUCCEED
1542 $LFS hsm_release $f || error "could not release file"
1543 check_hsm_flags $f "0x0000000d"
1546 wait_copytools || error "copytool failed to stop"
1548 cat $f > /dev/null &
1550 # wait a bit to allow implicit restore request to be handled.
1551 # if not, next stat would also block on layout-lock.
1554 local size=$(stat -c "%s" $f2)
1555 [ $size -eq $orig_size ] ||
1556 error "$f2: wrong size after archive: $size != $orig_size"
1558 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1562 size=$(stat -c "%s" $f)
1563 [ $size -eq $orig_size ] ||
1564 error "$f: wrong size after restore: $size != $orig_size"
1566 size=$(stat -c "%s" $f2)
1567 [ $size -eq $orig_size ] ||
1568 error "$f2: wrong size after restore: $size != $orig_size"
1572 size=$(stat -c "%s" $f)
1574 error "$f: wrong size after overwrite: $size != 0"
1576 size=$(stat -c "%s" $f2)
1578 error "$f2: wrong size after overwrite: $size != 0"
1581 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1582 error "cannot umount $MOUNT3 on $SINGLEAGT"
1584 run_test 12q "file attributes are refreshed after restore"
1587 # test needs a running copytool
1590 local ARC_SUBDIR="import.orig"
1594 # populate directory to be imported
1595 for d in $(seq 1 10); do
1596 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1597 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1598 for f in $(seq 1 10); do
1599 CURR_FILE="$CURR_DIR/$tfile.$f"
1600 # write file-specific data
1601 do_facet $SINGLEAGT \
1602 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1603 "file=$CURR_FILE > $CURR_FILE"
1607 import_file "$ARC_SUBDIR" $DIR/$tdir
1608 # diff lustre content and origin (triggers file restoration)
1609 # there must be 10x10 identical files, and no difference
1610 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1611 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1612 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1613 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1615 [ $cnt_diff -eq 0 ] ||
1616 error "$cnt_diff imported files differ from read data"
1617 [ $cnt_ok -eq 100 ] ||
1618 error "not enough identical files ($cnt_ok != 100)"
1622 run_test 13 "Recursively import and restore a directory"
1625 # test needs a running copytool
1630 local f=$DIR/$tdir/$tfile
1631 local fid=$(make_small $f)
1632 local sum=$(md5sum $f | awk '{print $1}')
1633 $LFS hsm_archive $f || error "could not archive file"
1634 wait_request_state $fid ARCHIVE SUCCEED
1638 # create released file (simulate llapi_hsm_import call)
1640 local fid2=$(path2fid $f)
1641 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1642 $LFS hsm_release $f || error "could not release file"
1644 # rebind the archive to the newly created file
1645 echo "rebind $fid to $fid2"
1647 do_facet $SINGLEAGT \
1648 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1649 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1651 # restore file and compare md5sum
1652 local sum2=$(md5sum $f | awk '{print $1}')
1654 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1658 run_test 14 "Rebind archived file to a new fid"
1661 # test needs a running copytool
1666 local f=$DIR/$tdir/$tfile
1668 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1672 for i in $(seq 1 $count); do
1673 fids[$i]=$(make_small $f.$i)
1674 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1675 $LFS hsm_archive $f.$i || error "could not archive file"
1677 wait_all_done $(($count*60))
1681 for i in $(seq 1 $count); do
1684 local fid2=$(path2fid $f.$i)
1685 # add the rebind operation to the list
1686 echo ${fids[$i]} $fid2 >> $tmpfile
1688 # set it released (simulate llapi_hsm_import call)
1689 $LFS hsm_set --archived --exists $f.$i ||
1690 error "could not force hsm flags"
1691 $LFS hsm_release $f.$i || error "could not release file"
1693 nl=$(wc -l < $tmpfile)
1694 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1696 echo "rebind list of files"
1697 do_facet $SINGLEAGT \
1698 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1699 --rebind $tmpfile $DIR" || error "could not rebind file list"
1701 # restore files and compare md5sum
1702 for i in $(seq 1 $count); do
1703 local sum2=$(md5sum $f.$i | awk '{print $1}')
1704 [[ $sum2 == ${sums[$i]} ]] ||
1705 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1711 run_test 15 "Rebind a list of files"
1714 # test needs a running copytool
1718 # create a known size file so we can verify transfer speed
1721 dd if=/dev/zero of=$ref bs=1M count=20
1724 local f=$DIR/$tdir/$tfile
1725 local fid=$(copy_file $ref $f)
1727 local start=$(date +%s)
1729 wait_request_state $fid ARCHIVE SUCCEED
1730 local end=$(date +%s)
1731 # Add 1 to account for rounding errors between start and end (LU-8155)
1732 local duration=$((end - start + 1))
1734 [[ $duration -ge $goal ]] ||
1735 error "Transfer is too fast $duration < $goal"
1739 run_test 16 "Test CT bandwith control option"
1744 local f=$DIR/$tdir/$tfile
1745 touch $f || error "touch $f failed"
1747 # Could not release a non-archived file
1748 $LFS hsm_release $f && error "release should not succeed"
1750 # For following tests, we must test them with HS_ARCHIVED set
1751 $LFS hsm_set --exists --archived $f || error "could not add flag"
1753 # Could not release a file if no-release is set
1754 $LFS hsm_set --norelease $f || error "could not add flag"
1755 $LFS hsm_release $f && error "release should not succeed"
1756 $LFS hsm_clear --norelease $f || error "could not remove flag"
1758 # Could not release a file if lost
1759 $LFS hsm_set --lost $f || error "could not add flag"
1760 $LFS hsm_release $f && error "release should not succeed"
1761 $LFS hsm_clear --lost $f || error "could not remove flag"
1763 # Could not release a file if dirty
1764 $LFS hsm_set --dirty $f || error "could not add flag"
1765 $LFS hsm_release $f && error "release should not succeed"
1766 $LFS hsm_clear --dirty $f || error "could not remove flag"
1768 run_test 20 "Release is not permitted"
1771 # test needs a running copytool
1775 local f=$DIR/$tdir/test_release
1777 # Create a file and check its states
1778 local fid=$(make_small $f)
1779 check_hsm_flags $f "0x00000000"
1781 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1782 # used until file is flushed to disk
1783 if [ $(facet_fstype ost1) == "zfs" ]; then
1784 # this causes an OST_SYNC rpc to be sent
1785 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1786 # clear locks to reread file data
1787 cancel_lru_locks osc
1790 local orig_size=$(stat -c "%s" $f)
1791 local orig_blocks=$(stat -c "%b" $f)
1793 start_full_debug_logging
1795 $LFS hsm_archive $f || error "could not archive file"
1796 wait_request_state $fid ARCHIVE SUCCEED
1798 local blocks=$(stat -c "%b" $f)
1799 [ $blocks -eq $orig_blocks ] ||
1800 error "$f: wrong block number after archive: " \
1801 "$blocks != $orig_blocks"
1802 local size=$(stat -c "%s" $f)
1803 [ $size -eq $orig_size ] ||
1804 error "$f: wrong size after archive: $size != $orig_size"
1806 # Release and check states
1807 $LFS hsm_release $f || error "could not release file"
1808 check_hsm_flags $f "0x0000000d"
1810 blocks=$(stat -c "%b" $f)
1811 [ $blocks -gt 5 ] &&
1812 error "$f: too many blocks after release: $blocks > 5"
1813 size=$(stat -c "%s" $f)
1814 [ $size -ne $orig_size ] &&
1815 error "$f: wrong size after release: $size != $orig_size"
1817 # Check we can release an file without stripe info
1821 check_hsm_flags $f "0x00000000"
1822 $LFS hsm_archive $f || error "could not archive file"
1823 wait_request_state $fid ARCHIVE SUCCEED
1825 # Release and check states
1826 $LFS hsm_release $f || error "could not release file"
1827 check_hsm_flags $f "0x0000000d"
1829 # Release again a file that is already released is OK
1830 $LFS hsm_release $f || fail "second release should succeed"
1831 check_hsm_flags $f "0x0000000d"
1833 stop_full_debug_logging
1837 run_test 21 "Simple release tests"
1840 # test needs a running copytool
1845 local f=$DIR/$tdir/test_release
1846 local swap=$DIR/$tdir/test_swap
1848 # Create a file and check its states
1849 local fid=$(make_small $f)
1850 check_hsm_flags $f "0x00000000"
1852 $LFS hsm_archive $f || error "could not archive file"
1853 wait_request_state $fid ARCHIVE SUCCEED
1855 # Release and check states
1856 $LFS hsm_release $f || error "could not release file"
1857 check_hsm_flags $f "0x0000000d"
1860 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1865 run_test 22 "Could not swap a release file"
1868 # test needs a running copytool
1873 local f=$DIR/$tdir/test_mtime
1875 # Create a file and check its states
1876 local fid=$(make_small $f)
1877 check_hsm_flags $f "0x00000000"
1879 $LFS hsm_archive $f || error "could not archive file"
1880 wait_request_state $fid ARCHIVE SUCCEED
1882 # Set modification time in the past
1883 touch -m -a -d @978261179 $f
1885 # Release and check states
1886 $LFS hsm_release $f || error "could not release file"
1887 check_hsm_flags $f "0x0000000d"
1889 local MTIME=$(stat -c "%Y" $f)
1890 local ATIME=$(stat -c "%X" $f)
1891 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1892 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1896 run_test 23 "Release does not change a/mtime (utime)"
1899 local file=$DIR/$tdir/$tfile
1908 # test needs a running copytool
1913 fid=$(make_small $file)
1915 # Create a file and check its states
1916 check_hsm_flags $file "0x00000000"
1918 # Ensure atime is less than mtime and ctime.
1922 atime0=$(stat -c "%X" $file)
1923 mtime0=$(stat -c "%Y" $file)
1924 ctime0=$(stat -c "%Z" $file)
1926 [ $atime0 -lt $mtime0 ] ||
1927 error "atime $atime0 is not less than mtime $mtime0"
1929 [ $atime0 -lt $ctime0 ] ||
1930 error "atime $atime0 is not less than ctime $ctime0"
1932 # Archive should not change any timestamps.
1933 $LFS hsm_archive $file || error "cannot archive '$file'"
1934 wait_request_state $fid ARCHIVE SUCCEED
1936 atime1=$(stat -c "%X" $file)
1937 mtime1=$(stat -c "%Y" $file)
1938 ctime1=$(stat -c "%Z" $file)
1940 [ $atime0 -eq $atime1 ] ||
1941 error "archive changed atime from $atime0 to $atime1"
1943 [ $mtime0 -eq $mtime1 ] ||
1944 error "archive changed mtime from $mtime0 to $mtime1"
1946 [ $ctime0 -eq $ctime1 ] ||
1947 error "archive changed ctime from $ctime0 to $ctime1"
1949 # Release should not change any timestamps.
1950 $LFS hsm_release $file || error "cannot release '$file'"
1951 check_hsm_flags $file "0x0000000d"
1953 atime1=$(stat -c "%X" $file)
1954 mtime1=$(stat -c "%Y" $file)
1955 ctime1=$(stat -c "%Z" $file)
1957 [ $atime0 -eq $atime1 ] ||
1958 error "release changed atime from $atime0 to $atime1"
1960 [ $mtime0 -eq $mtime1 ] ||
1961 error "release changed mtime from $mtime0 to $mtime1"
1963 [ $ctime0 -eq $ctime1 ] ||
1964 error "release changed ctime from $ctime0 to $ctime1"
1966 # Restore should not change any timestamps.
1967 $LFS hsm_restore $file
1968 wait_request_state $fid RESTORE SUCCEED
1970 atime1=$(stat -c "%X" $file)
1971 mtime1=$(stat -c "%Y" $file)
1972 ctime1=$(stat -c "%Z" $file)
1974 [ $atime0 -eq $atime1 ] ||
1975 error "restore changed atime from $atime0 to $atime1"
1977 [ $mtime0 -eq $mtime1 ] ||
1978 error "restore changed mtime from $mtime0 to $mtime1"
1980 [ $ctime0 -eq $ctime1 ] ||
1981 error "restore changed ctime from $ctime0 to $ctime1"
1985 # Once more, after unmount and mount.
1986 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1987 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1989 atime1=$(stat -c "%X" $file)
1990 mtime1=$(stat -c "%Y" $file)
1991 ctime1=$(stat -c "%Z" $file)
1993 [ $atime0 -eq $atime1 ] ||
1994 error "remount changed atime from $atime0 to $atime1"
1996 [ $mtime0 -eq $mtime1 ] ||
1997 error "remount changed mtime from $mtime0 to $mtime1"
1999 [ $ctime0 -eq $ctime1 ] ||
2000 error "remount changed ctime from $ctime0 to $ctime1"
2002 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2005 local file=$DIR/$tdir/$tfile
2011 # Test needs a running copytool.
2015 # Check that root can do HSM actions on a regular user's file.
2017 fid=$(make_small $file)
2018 sum0=$(md5sum $file)
2020 chown $RUNAS_ID:$RUNAS_GID $file ||
2021 error "cannot chown '$file' to '$RUNAS_ID'"
2023 chmod ugo-w $DIR/$tdir ||
2024 error "cannot chmod '$DIR/$tdir'"
2026 $LFS hsm_archive $file
2027 wait_request_state $fid ARCHIVE SUCCEED
2029 $LFS hsm_release $file
2030 check_hsm_flags $file "0x0000000d"
2032 $LFS hsm_restore $file
2033 wait_request_state $fid RESTORE SUCCEED
2035 # Check that ordinary user can get HSM state.
2036 $RUNAS $LFS hsm_state $file ||
2037 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2039 $LFS hsm_release $file
2040 check_hsm_flags $file "0x0000000d"
2042 # Check that ordinary user can accessed released file.
2043 sum1=$($RUNAS md5sum $file) ||
2044 error "user '$RUNAS_ID' cannot read '$file'"
2046 [ "$sum0" == "$sum1" ] ||
2047 error "md5sum mismatch for '$file'"
2051 run_test 24b "root can archive, release, and restore user files"
2053 cleanup_test_24c() {
2055 set_hsm_param user_request_mask RESTORE
2056 set_hsm_param group_request_mask RESTORE
2057 set_hsm_param other_request_mask RESTORE
2061 local file=$DIR/$tdir/$tfile
2062 local action=archive
2067 # test needs a running copytool
2072 # Save the default masks and check that cleanup_24c will
2073 # restore the request masks correctly.
2074 user_save=$(get_hsm_param user_request_mask)
2075 group_save=$(get_hsm_param group_request_mask)
2076 other_save=$(get_hsm_param other_request_mask)
2078 [ "$user_save" == RESTORE ] ||
2079 error "user_request_mask is '$user_save' expected 'RESTORE'"
2080 [ "$group_save" == RESTORE ] ||
2081 error "group_request_mask is '$group_save' expected 'RESTORE'"
2082 [ "$other_save" == RESTORE ] ||
2083 error "other_request_mask is '$other_save' expected 'RESTORE'"
2085 trap cleanup_test_24c EXIT
2090 chown $RUNAS_ID:nobody $file ||
2091 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2093 $RUNAS $LFS hsm_$action $file &&
2094 error "$action by user should fail"
2096 set_hsm_param user_request_mask $action
2097 $RUNAS $LFS hsm_$action $file ||
2098 error "$action by user should succeed"
2103 chown nobody:$RUNAS_GID $file ||
2104 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2106 $RUNAS $LFS hsm_$action $file &&
2107 error "$action by group should fail"
2109 set_hsm_param group_request_mask $action
2110 $RUNAS $LFS hsm_$action $file ||
2111 error "$action by group should succeed"
2116 chown nobody:nobody $file ||
2117 error "cannot chown '$file' to 'nobody:nobody'"
2119 $RUNAS $LFS hsm_$action $file &&
2120 error "$action by other should fail"
2122 set_hsm_param other_request_mask $action
2123 $RUNAS $LFS hsm_$action $file ||
2124 error "$action by other should succeed"
2129 run_test 24c "check that user,group,other request masks work"
2131 cleanup_test_24d() {
2133 mount -o remount,rw $MOUNT2
2137 local file1=$DIR/$tdir/$tfile
2138 local file2=$DIR2/$tdir/$tfile
2146 fid1=$(make_small $file1)
2148 trap cleanup_test_24d EXIT
2150 mount -o remount,ro $MOUNT2
2152 fid2=$(path2fid $file2)
2153 [ "$fid1" == "$fid2" ] ||
2154 error "FID mismatch '$fid1' != '$fid2'"
2156 $LFS hsm_archive $file2 &&
2157 error "archive should fail on read-only mount"
2158 check_hsm_flags $file1 "0x00000000"
2160 $LFS hsm_archive $file1
2161 wait_request_state $fid1 ARCHIVE SUCCEED
2163 $LFS hsm_release $file1
2164 $LFS hsm_restore $file2
2165 wait_request_state $fid1 RESTORE SUCCEED
2167 $LFS hsm_release $file1 || error "cannot release '$file1'"
2168 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2170 $LFS hsm_release $file2 &&
2171 error "release should fail on read-only mount"
2176 run_test 24d "check that read-only mounts are respected"
2183 local f=$DIR/$tdir/$tfile
2186 fid=$(make_small $f) || error "cannot create $f"
2187 $LFS hsm_archive $f || error "cannot archive $f"
2188 wait_request_state $fid ARCHIVE SUCCEED
2189 $LFS hsm_release $f || error "cannot release $f"
2190 while ! $LFS hsm_state $f | grep released; do
2194 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2198 run_test 24e "tar succeeds on HSM released files" # LU-6213
2202 # test needs a running copytool
2205 mkdir -p $DIR/$tdir/d1
2206 local f=$DIR/$tdir/$tfile
2207 local fid=$(copy_file /etc/hosts $f)
2210 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2211 error "hsm_archive failed"
2212 wait_request_state $fid ARCHIVE SUCCEED
2213 $LFS hsm_release $f || error "cannot release $f"
2214 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2217 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2218 error "Can not recover the tar contents"
2220 echo "Sum0 = $sum0, sum1 = $sum1"
2221 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2225 run_test 24f "root can archive, release, and restore tar files"
2228 # test needs a running copytool
2232 copy2archive /etc/hosts $tdir/$tfile
2234 local f=$DIR/$tdir/$tfile
2236 import_file $tdir/$tfile $f
2238 $LFS hsm_set --lost $f
2243 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2247 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2248 " (Operation not permitted)"
2251 # test needs a running copytool
2256 local f=$DIR/$tdir/$tfile
2257 local fid=$(copy_file /etc/passwd $f)
2259 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2260 wait_request_state $fid ARCHIVE SUCCEED
2263 $LFS hsm_set --lost $f
2267 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2271 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2272 " (Operation not permitted)"
2275 # test needs a running copytool
2279 local f=$DIR/$tdir/$tfile
2281 fid=$(make_custom_file_for_progress $f 39 1000000)
2282 [ $? != 0 ] && skip "not enough free space" && return
2284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2285 wait_request_state $fid ARCHIVE SUCCEED
2288 wait_request_state $fid REMOVE SUCCEED
2290 check_hsm_flags $f "0x00000000"
2294 run_test 26 "Remove the archive of a valid file"
2297 # test needs a running copytool
2301 make_archive $tdir/$tfile
2302 local f=$DIR/$tdir/$tfile
2303 import_file $tdir/$tfile $f
2304 local fid=$(path2fid $f)
2308 [[ $? != 0 ]] || error "Remove of a released file should fail"
2312 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2315 # test needs a running copytool
2319 local f=$DIR/$tdir/$tfile
2321 fid=$(make_custom_file_for_progress $f 39 1000000)
2322 [ $? != 0 ] && skip "not enough free space" && return
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2325 wait_request_state $fid ARCHIVE SUCCEED
2330 [[ $? != 0 ]] || error "Remove of a released file should fail"
2334 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2337 # test needs a running copytool
2341 local f=$DIR/$tdir/$tfile
2343 fid=$(make_custom_file_for_progress $f 39 1000000)
2344 [ $? != 0 ] && skip "not enough free space" && return
2346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2347 wait_request_state $fid ARCHIVE SUCCEED
2356 wait_request_state $fid REMOVE SUCCEED
2360 run_test 28 "Concurrent archive/file remove"
2363 # Tests --mntpath and --archive options
2366 copytool_setup $SINGLEAGT $MOUNT $archive_id
2368 # Bad archive number
2369 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2370 grep "Invalid argument" ||
2371 error "unexpected hsm_remove failure (1)"
2373 # mntpath is present but file is given
2374 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2375 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2376 error "unexpected hsm_remove failure (2)"
2380 run_test 29a "Tests --mntpath and --archive options"
2383 # test needs a running copytool
2387 local f=$DIR/$tdir/$tfile
2388 local fid=$(make_small $f)
2390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2391 wait_request_state $fid ARCHIVE SUCCEED
2395 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2396 wait_request_state $fid REMOVE SUCCEED
2400 run_test 29b "Archive/delete/remove by FID from the archive."
2403 # test needs a running copytool
2407 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2408 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2409 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2411 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2412 wait_request_state $fid1 ARCHIVE SUCCEED
2413 wait_request_state $fid2 ARCHIVE SUCCEED
2414 wait_request_state $fid3 ARCHIVE SUCCEED
2416 rm -f $DIR/$tdir/$tfile-[1-3]
2418 echo $fid1 > $DIR/$tdir/list
2419 echo $fid2 >> $DIR/$tdir/list
2420 echo $fid3 >> $DIR/$tdir/list
2422 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2423 --filelist $DIR/$tdir/list
2424 wait_request_state $fid1 REMOVE SUCCEED
2425 wait_request_state $fid2 REMOVE SUCCEED
2426 wait_request_state $fid3 REMOVE SUCCEED
2430 run_test 29c "Archive/delete/remove by FID, using a file list."
2433 # test needs more than one CT
2434 needclients 3 || return 0
2440 copytool_cleanup $(comma_list $(agts_nodes))
2442 # start all of the copytools
2443 for n in $(seq $AGTCOUNT); do
2444 copytool_setup agt$n $MOUNT2 $n
2447 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2450 file=$DIR/$tdir/$tfile
2451 fid=$(make_small $file)
2453 $LFS hsm_archive $file
2454 wait_request_state $fid ARCHIVE SUCCEED
2455 check_hsm_flags $file "0x00000009"
2459 $LFS hsm_remove -a 0 $fid
2461 # give time for CDT to handle remove request and create broadcasted
2464 # remove request has been broadcasted ?
2465 local cnt=$(get_request_count $fid REMOVE)
2466 # broadcasted requests + original
2467 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2468 error "remove not broadcasted to all CTs"
2470 # give time for CDT and CTs to handle broadcasted
2471 wait_for_loop_period
2473 # each agent serves one different archive_id, so broadcasted
2474 # hsm_remove request should only succeed once and fail at all others
2478 for n in $(seq $AGTCOUNT); do
2479 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2480 $HSM_PARAM.actions | awk \
2481 '/'$fid'.*action=REMOVE archive#='$n'/ \
2482 {print \\\$13}' | cut -f2 -d=")
2483 if [[ "$res" == "SUCCEED" ]]; then
2485 elif [[ "$res" == "FAILED" ]]; then
2490 [[ $scnt -ne 1 ]] &&
2491 error "one and only CT should have removed successfully"
2493 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2494 error "all but one CT should have failed to remove"
2497 copytool_cleanup $(comma_list $(agts_nodes))
2500 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2501 "request to be sent once for each registered archive_id"
2504 # restore at exec cannot work on agent node (because of Linux kernel
2505 # protection of executables)
2506 needclients 2 || return 0
2508 # test needs a running copytool
2512 copy2archive /bin/true $tdir/$tfile
2514 local f=$DIR/$tdir/true
2515 import_file $tdir/$tfile $f
2517 local fid=$(path2fid $f)
2519 # set no retry action mode
2525 # remove no try action mode
2529 [[ $st == 0 ]] || error "Failed to exec a released file"
2533 run_test 30a "Restore at exec (import case)"
2536 # restore at exec cannot work on agent node (because of Linux kernel
2537 # protection of executables)
2538 needclients 2 || return 0
2540 # test needs a running copytool
2544 local f=$DIR/$tdir/true
2545 local fid=$(copy_file /bin/true $f)
2547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2548 wait_request_state $fid ARCHIVE SUCCEED
2551 # set no retry action mode
2557 # remove no try action mode
2561 [[ $st == 0 ]] || error "Failed to exec a released file"
2565 run_test 30b "Restore at exec (release case)"
2568 needclients 2 || return 0
2570 # test needs a running copytool
2574 local f=$DIR/$tdir/SLEEP
2575 local slp_sum1=$(md5sum /bin/sleep)
2576 local fid=$(copy_file /bin/sleep $f)
2578 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2579 wait_request_state $fid ARCHIVE SUCCEED
2581 check_hsm_flags $f "0x0000000d"
2582 # set no retry action mode
2584 do_node $CLIENT2 "$f 10" &
2588 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2590 [[ $? == 0 ]] || error "Execution failed during run"
2592 if [[ $? != 0 ]]; then
2593 local slp_sum2=$(md5sum /bin/sleep)
2594 # in case sleep file is modified during the test
2595 [[ $slp_sum1 == $slp_sum2 ]] &&
2596 error "Binary overwritten during exec"
2600 # remove no try action mode
2602 check_hsm_flags $f "0x00000009"
2606 run_test 30c "Update during exec of released file must fail"
2608 restore_and_check_size() {
2611 local s=$(stat -c "%s" $f)
2613 local st=$(get_hsm_flags $f)
2617 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2619 n=$(stat -c "%s" $f)
2620 # we echo in both cases to show stat is not
2622 if [[ $n != $s ]]; then
2623 echo "size seen is $n != $s"
2626 echo "size seen is right: $n == $s"
2628 st=$(get_hsm_flags $f)
2632 if [[ $cpt -lt 10 ]]; then
2635 echo " restore is too long"
2636 wait_request_state $fid RESTORE SUCCEED
2642 # test needs a running copytool
2647 make_archive $tdir/$tfile
2648 local f=$DIR/$tdir/$tfile
2649 import_file $tdir/$tfile $f
2650 local fid=$($LFS path2fid $f)
2651 HSM_ARCHIVE_PURGE=false copytool_setup
2653 restore_and_check_size $f $fid
2656 [[ $err -eq 0 ]] || error "File size changed during restore"
2660 run_test 31a "Import a large file and check size during restore"
2664 # test needs a running copytool
2669 local f=$DIR/$tdir/$tfile
2671 fid=$(make_custom_file_for_progress $f 39 1000000)
2672 [ $? != 0 ] && skip "not enough free space" && return
2674 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2675 wait_request_state $fid ARCHIVE SUCCEED
2678 restore_and_check_size $f $fid
2681 [[ $err -eq 0 ]] || error "File size changed during restore"
2685 run_test 31b "Restore a large unaligned file and check size during restore"
2688 # test needs a running copytool
2693 local f=$DIR/$tdir/$tfile
2695 fid=$(make_custom_file_for_progress $f 33 1048576)
2696 [ $? != 0 ] && skip "not enough free space" && return
2698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2699 wait_request_state $fid ARCHIVE SUCCEED
2702 restore_and_check_size $f $fid
2705 [[ $err -eq 0 ]] || error "File size changed during restore"
2709 run_test 31c "Restore a large aligned file and check size during restore"
2712 # test needs a running copytool
2717 local f=$DIR/$tdir/$tfile
2719 fid=$(make_custom_file_for_progress $f 39 1000000)
2720 [ $? != 0 ] && skip "not enough free space" && return
2722 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2723 wait_request_state $fid ARCHIVE SUCCEED
2726 # to be sure wait_all_done will not be mislead by previous tests
2729 wait_for_grace_delay
2730 # Also raise grace_delay significantly so the Canceled
2731 # Restore action will stay enough long avail.
2732 local old_grace=$(get_hsm_param grace_delay)
2733 set_hsm_param grace_delay 100
2735 md5sum $f >/dev/null &
2737 wait_request_state $fid RESTORE STARTED
2742 # Check restore trigger process was killed
2743 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2747 # instead of waiting+checking both Restore and Cancel ops
2748 # sequentially, wait for both to be finished and then check
2750 wait_all_done 100 $fid
2751 local rstate=$(get_request_state $fid RESTORE)
2752 local cstate=$(get_request_state $fid CANCEL)
2754 # restore orig grace_delay.
2755 set_hsm_param grace_delay $old_grace
2757 if [[ "$rstate" == "CANCELED" ]] ; then
2758 [[ "$cstate" == "SUCCEED" ]] ||
2759 error "Restore state is CANCELED and Cancel state " \
2760 "is not SUCCEED but $cstate"
2761 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2762 elif [[ "$rstate" == "SUCCEED" ]] ; then
2763 [[ "$cstate" == "FAILED" ]] ||
2764 error "Restore state is SUCCEED and Cancel state " \
2765 "is not FAILED but $cstate"
2766 echo "Restore state is SUCCEED, Cancel state is FAILED"
2768 error "Restore state is $rstate and Cancel state is $cstate"
2772 error "Cannot kill process waiting for restore ($killed)"
2776 run_test 33 "Kill a restore waiting process"
2779 # test needs a running copytool
2784 local f=$DIR/$tdir/$tfile
2786 fid=$(make_custom_file_for_progress $f 39 1000000)
2787 [ $? != 0 ] && skip "not enough free space" && return
2789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2790 wait_request_state $fid ARCHIVE SUCCEED
2793 md5sum $f >/dev/null &
2795 wait_request_state $fid RESTORE STARTED
2797 rm $f || error "rm $f failed"
2798 # rm must not block during restore
2799 wait_request_state $fid RESTORE STARTED
2801 wait_request_state $fid RESTORE SUCCEED
2802 # check md5sum pgm finished
2803 local there=$(ps -o pid,comm hp $pid >/dev/null)
2804 [[ -z $there ]] || error "Restore initiator does not exit"
2806 local rc=$(wait $pid)
2807 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2811 run_test 34 "Remove file during restore"
2814 # test needs a running copytool
2819 local f=$DIR/$tdir/$tfile
2820 local f1=$DIR/$tdir/$tfile-1
2822 fid=$(make_custom_file_for_progress $f 39 1000000)
2823 [ $? != 0 ] && skip "not enough free space" && return
2825 local fid1=$(copy_file /etc/passwd $f1)
2826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2827 wait_request_state $fid ARCHIVE SUCCEED
2830 md5sum $f >/dev/null &
2832 wait_request_state $fid RESTORE STARTED
2834 mv $f1 $f || error "mv $f1 $f failed"
2835 # mv must not block during restore
2836 wait_request_state $fid RESTORE STARTED
2838 wait_request_state $fid RESTORE SUCCEED
2839 # check md5sum pgm finished
2840 local there=$(ps -o pid,comm hp $pid >/dev/null)
2841 [[ -z $there ]] || error "Restore initiator does not exit"
2843 local rc=$(wait $pid)
2844 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2847 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2851 run_test 35 "Overwrite file during restore"
2854 # test needs a running copytool
2859 local f=$DIR/$tdir/$tfile
2861 fid=$(make_custom_file_for_progress $f 39 1000000)
2862 [ $? != 0 ] && skip "not enough free space" && return
2864 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2865 wait_request_state $fid ARCHIVE SUCCEED
2868 md5sum $f >/dev/null &
2870 wait_request_state $fid RESTORE STARTED
2873 # rm must not block during restore
2874 wait_request_state $fid RESTORE STARTED
2876 wait_request_state $fid RESTORE SUCCEED
2877 # check md5sum pgm finished
2878 local there=$(ps -o pid,comm hp $pid >/dev/null)
2880 error "Restore initiator does not exit"
2882 local rc=$(wait $pid)
2884 error "Restore initiator failed with $rc"
2888 run_test 36 "Move file during restore"
2891 # LU-5683: check that an archived dirty file can be rearchived.
2893 copytool_setup $SINGLEAGT $MOUNT2
2896 local f=$DIR/$tdir/$tfile
2899 fid=$(make_small $f) || error "cannot create small file"
2901 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2902 wait_request_state $fid ARCHIVE SUCCEED
2903 $LFS hsm_release $f || error "cannot release $f"
2906 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2908 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2909 wait_request_state $fid ARCHIVE SUCCEED
2913 run_test 37 "re-archive a dirty file"
2920 for n in $(seq 1 $count); do
2921 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2923 echo "$count archive requests submitted"
2927 local stream_count=4
2928 local file_count=100
2930 local f=$DIR/$tdir/$tfile
2935 for i in $(seq 1 $file_count); do
2936 for p in $(seq 1 $stream_count); do
2937 fid=$(copy_file /etc/hosts $f.$p.$i)
2940 # force copytool to use a local/temp archive dir to ensure best
2941 # performance vs remote/NFS mounts used in auto-tests
2942 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2945 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2947 # to be sure wait_all_done will not be mislead by previous tests
2949 wait_for_grace_delay
2951 # start archive streams in background (archive files in parallel)
2952 for p in $(seq 1 $stream_count); do
2953 multi_archive $f.$p $file_count &
2956 echo -n "Wait for all requests being enqueued..."
2962 run_test 40 "Parallel archive requests"
2965 # test needs a running copytool
2969 local f=$DIR/$tdir/$tfile
2970 local fid=$(copy_file /etc/motd $f 1)
2972 $LFS hsm_archive $f || error "could not archive file"
2973 wait_request_state $fid ARCHIVE SUCCEED
2974 check_hsm_flags $f "0x00000009"
2976 multiop_bg_pause $f O_c || error "multiop failed"
2980 client_up || client_up || true
2982 kill -USR1 $MULTIPID
2983 wait $MULTIPID || error "multiop close failed"
2985 check_hsm_flags $f "0x0000000b"
2989 run_test 52 "Opened for write file on an evicted client should be set dirty"
2992 # test needs a running copytool
2996 local f=$DIR/$tdir/$tfile
2997 local fid=$(copy_file /etc/motd $f 1)
2999 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3000 error "could not archive file"
3001 wait_request_state $fid ARCHIVE SUCCEED
3002 check_hsm_flags $f "0x00000009"
3004 multiop_bg_pause $f o_c || error "multiop failed"
3008 client_up || client_up || true
3010 kill -USR1 $MULTIPID
3011 wait $MULTIPID || error "multiop close failed"
3013 check_hsm_flags $f "0x00000009"
3017 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3020 # test needs a running copytool
3024 local f=$DIR/$tdir/$tfile
3025 local fid=$(make_custom_file_for_progress $f 39 1000000)
3027 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3028 error "could not archive file"
3029 wait_request_state $fid ARCHIVE STARTED
3031 check_hsm_flags $f "0x00000001"
3033 # Avoid coordinator resending this request as soon it has failed.
3038 wait_request_state $fid ARCHIVE FAILED
3040 check_hsm_flags $f "0x00000003"
3045 run_test 54 "Write during an archive cancels it"
3048 # test needs a running copytool
3052 local f=$DIR/$tdir/$tfile
3053 local fid=$(make_custom_file_for_progress $f 39 1000000)
3055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3056 error "could not archive file"
3057 wait_request_state $fid ARCHIVE STARTED
3059 check_hsm_flags $f "0x00000001"
3061 # Avoid coordinator resending this request as soon it has failed.
3064 $TRUNCATE $f 1024 || error "truncate failed"
3066 wait_request_state $fid ARCHIVE FAILED
3068 check_hsm_flags $f "0x00000003"
3073 run_test 55 "Truncate during an archive cancels it"
3076 # test needs a running copytool
3080 local f=$DIR/$tdir/$tfile
3082 fid=$(make_custom_file_for_progress $f 39 1000000)
3083 [ $? != 0 ] && skip "not enough free space" && return
3085 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3086 error "could not archive file"
3087 wait_request_state $fid ARCHIVE STARTED
3089 check_hsm_flags $f "0x00000001"
3091 # Change metadata and sync to be sure we are not changing only
3096 wait_request_state $fid ARCHIVE SUCCEED
3098 check_hsm_flags $f "0x00000009"
3102 run_test 56 "Setattr during an archive is ok"
3105 # Need one client for I/O, one for request
3106 needclients 2 || return 0
3108 # test needs a running copytool
3112 local f=$DIR/$tdir/test_archive_remote
3113 # Create a file on a remote node
3114 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3115 "count=2 conv=fsync"
3118 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3119 error "hsm_archive failed"
3120 local fid=$(path2fid $f)
3121 wait_request_state $fid ARCHIVE SUCCEED
3123 # Release and implicit restore it
3124 do_node $CLIENT2 "$LFS hsm_release $f" ||
3125 error "hsm_release failed"
3126 do_node $CLIENT2 "md5sum $f" ||
3127 error "hsm_restore failed"
3129 wait_request_state $fid RESTORE SUCCEED
3133 run_test 57 "Archive a file with dirty cache on another node"
3135 truncate_released_file() {
3139 local sz=$(stat -c %s $src_file)
3140 local f=$DIR/$tdir/$tfile
3141 local fid=$(copy_file $1 $f)
3145 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3146 error "could not archive file"
3147 wait_request_state $fid ARCHIVE SUCCEED
3149 $LFS hsm_release $f || error "could not release file"
3151 $TRUNCATE $f $trunc_to || error "truncate failed"
3154 local sz1=$(stat -c %s $f)
3155 [[ $sz1 == $trunc_to ]] ||
3156 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3159 check_hsm_flags $f "0x0000000b"
3161 local state=$(get_request_state $fid RESTORE)
3162 [[ "$state" == "SUCCEED" ]] ||
3163 error "truncate $sz does not trig restore, state = $state"
3165 $TRUNCATE $ref $trunc_to
3166 cmp $ref $f || error "file data wrong after truncate"
3172 # test needs a running copytool
3177 local sz=$(stat -c %s /etc/passwd)
3179 echo "truncate up from $sz to $((sz*2))"
3180 truncate_released_file /etc/passwd $((sz*2))
3182 echo "truncate down from $sz to $((sz/2))"
3183 truncate_released_file /etc/passwd $((sz/2))
3185 echo "truncate to 0"
3186 truncate_released_file /etc/passwd 0
3190 run_test 58 "Truncate a released file will trigger restore"
3194 local server_version=$(lustre_version_code $SINGLEMDS)
3195 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3196 skip "Need MDS version at least 2.7.63" && return
3199 $MCREATE $DIR/$tfile || error "mcreate failed"
3200 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3201 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3202 fid=$(path2fid $DIR/$tfile)
3203 wait_request_state $fid ARCHIVE SUCCEED
3204 $LFS hsm_release $DIR/$tfile || error "release failed"
3207 run_test 59 "Release stripeless file with non-zero size"
3210 # This test validates the fix for LU-4512. Ensure that the -u
3211 # option changes the progress reporting interval from the
3212 # default (30 seconds) to the user-specified interval.
3214 local progress_timeout=$((interval * 4))
3216 # test needs a new running copytool
3218 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3221 local f=$DIR/$tdir/$tfile
3223 fid=$(make_custom_file_for_progress $f 10)
3224 [ $? != 0 ] && skip "not enough free space" && return
3227 local mdt=${MDT_PREFIX}${mdtidx}
3228 local mds=mds$((mdtidx + 1))
3230 # Wait for copytool to register
3231 wait_update_facet $mds \
3232 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3233 uuid 100 || error "coyptool failed to register with $mdt"
3235 local start_at=$(date +%s)
3236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3237 error "could not archive file"
3239 local agent=$(facet_active_host $SINGLEAGT)
3240 local prefix=$TESTLOG_PREFIX
3241 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3242 local copytool_log=$prefix.copytool_log.$agent.log
3245 wait_update $agent \
3246 "grep -o start.copy $copytool_log" "start copy" 100 ||
3247 error "copytool failed to start"
3249 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3250 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3256 echo -n "Expecting a progress update within $progress_timeout seconds... "
3258 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3259 if [ $RESULT -gt 0 ]; then
3260 echo "$RESULT bytes copied in $WAIT seconds."
3262 elif [ $WAIT -ge $progress_timeout ]; then
3263 error "Timed out waiting for progress update!"
3266 WAIT=$((WAIT + sleep))
3270 local finish_at=$(date +%s)
3271 local elapsed=$((finish_at - start_at))
3273 # Ensure that the progress update occurred within the expected window.
3274 if [ $elapsed -lt $((interval - 1)) ]; then
3275 error "Expected progress update after at least $interval seconds"
3278 echo "Wait for on going archive hsm action to complete"
3279 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3280 echo "File archiving not completed even after 10 secs"
3285 run_test 60 "Changing progress update interval from default"
3288 # test needs a new running copytool
3290 copytool_monitor_setup
3291 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3293 # Just start and stop the copytool to generate events.
3296 # Wait for the copytool to register.
3297 wait_update --verbose $(facet_active_host mds1) \
3298 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3300 error "copytool failed to register with MDT0000"
3304 local REGISTER_EVENT
3305 local UNREGISTER_EVENT
3306 while read event; do
3307 local parsed=$(parse_json_event "$event")
3308 if [ -z "$parsed" ]; then
3309 error "Copytool sent malformed event: $event"
3313 if [ $event_type == "REGISTER" ]; then
3314 REGISTER_EVENT=$event
3315 elif [ $event_type == "UNREGISTER" ]; then
3316 UNREGISTER_EVENT=$event
3318 done < <(echo $"$(get_copytool_event_log)")
3320 if [ -z "$REGISTER_EVENT" ]; then
3321 error "Copytool failed to send register event to FIFO"
3324 if [ -z "$UNREGISTER_EVENT" ]; then
3325 error "Copytool failed to send unregister event to FIFO"
3328 copytool_monitor_cleanup
3329 echo "Register/Unregister events look OK."
3331 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3334 # Bump progress interval for livelier events.
3337 # test needs a new running copytool
3339 copytool_monitor_setup
3340 HSMTOOL_UPDATE_INTERVAL=$interval \
3341 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3344 local f=$DIR/$tdir/$tfile
3346 fid=$(make_custom_file_for_progress $f 39 1000000)
3347 [ $? != 0 ] && skip "not enough free space" && return
3349 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3350 error "could not archive file"
3351 wait_request_state $fid ARCHIVE SUCCEED
3353 local expected_fields="event_time data_fid source_fid"
3354 expected_fields+=" total_bytes current_bytes"
3358 while read event; do
3359 # Make sure we're not getting anything from previous events.
3360 for field in $expected_fields; do
3364 local parsed=$(parse_json_event "$event")
3365 if [ -z "$parsed" ]; then
3366 error "Copytool sent malformed event: $event"
3370 if [ $event_type == "ARCHIVE_START" ]; then
3373 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3376 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3380 # Do some simple checking of the progress update events.
3381 for expected_field in $expected_fields; do
3382 if [ -z ${!expected_field+x} ]; then
3383 error "Missing $expected_field field in event"
3387 if [ $total_bytes -eq 0 ]; then
3388 error "Expected total_bytes to be > 0"
3391 # These should be identical throughout an archive
3393 if [ $source_fid != $data_fid ]; then
3394 error "Expected source_fid to equal data_fid"
3396 done < <(echo $"$(get_copytool_event_log)")
3398 if [ -z "$START_EVENT" ]; then
3399 error "Copytool failed to send archive start event to FIFO"
3402 if [ -z "$FINISH_EVENT" ]; then
3403 error "Copytool failed to send archive finish event to FIFO"
3406 echo "Archive events look OK."
3410 copytool_monitor_cleanup
3412 run_test 71 "Copytool logs JSON archive events to FIFO"
3415 # Bump progress interval for livelier events.
3418 # test needs a new running copytool
3420 copytool_monitor_setup
3421 HSMTOOL_UPDATE_INTERVAL=$interval \
3422 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3423 local test_file=$HSMTOOL_MONITOR_DIR/file
3425 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3427 do_facet $SINGLEAGT "$cmd" ||
3428 error "cannot create $test_file on $SINGLEAGT"
3429 copy2archive $test_file $tdir/$tfile
3432 local f=$DIR/$tdir/$tfile
3433 import_file $tdir/$tfile $f
3434 f=$DIR2/$tdir/$tfile
3435 echo "Verifying released state: "
3436 check_hsm_flags $f "0x0000000d"
3438 local fid=$(path2fid $f)
3440 wait_request_state $fid RESTORE SUCCEED
3442 local expected_fields="event_time data_fid source_fid"
3443 expected_fields+=" total_bytes current_bytes"
3447 while read event; do
3448 # Make sure we're not getting anything from previous events.
3449 for field in $expected_fields; do
3453 local parsed=$(parse_json_event "$event")
3454 if [ -z "$parsed" ]; then
3455 error "Copytool sent malformed event: $event"
3459 if [ $event_type == "RESTORE_START" ]; then
3461 if [ $source_fid != $data_fid ]; then
3462 error "source_fid should == data_fid at start"
3465 elif [ $event_type == "RESTORE_FINISH" ]; then
3467 if [ $source_fid != $data_fid ]; then
3468 error "source_fid should == data_fid at finish"
3471 elif [ $event_type != "RESTORE_RUNNING" ]; then
3475 # Do some simple checking of the progress update events.
3476 for expected_field in $expected_fields; do
3477 if [ -z ${!expected_field+x} ]; then
3478 error "Missing $expected_field field in event"
3482 if [ $total_bytes -eq 0 ]; then
3483 error "Expected total_bytes to be > 0"
3486 # When a restore starts out, the data fid is the same as the
3487 # source fid. After the restore has gotten going, we learn
3488 # the new data fid. Once the restore has finished, the source
3489 # fid is set to the new data fid.
3491 # We test this because some monitoring software may depend on
3492 # this behavior. If it changes, then the consumers of these
3493 # events may need to be modified.
3494 if [ $source_fid == $data_fid ]; then
3495 error "source_fid should != data_fid during restore"
3497 done < <(echo $"$(get_copytool_event_log)")
3499 if [ -z "$START_EVENT" ]; then
3500 error "Copytool failed to send restore start event to FIFO"
3503 if [ -z "$FINISH_EVENT" ]; then
3504 error "Copytool failed to send restore finish event to FIFO"
3507 echo "Restore events look OK."
3511 copytool_monitor_cleanup
3515 run_test 72 "Copytool logs JSON restore events to FIFO"
3518 file_count=51 # Max number of files constrained by LNET message size
3519 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3520 local f=$DIR/$tdir/$tfile
3521 local FILELIST=/tmp/filelist.txt
3525 for i in $(seq 1 $file_count); do
3526 fid=$(copy_file /etc/hosts $f.$i)
3527 echo $f.$i >> $FILELIST
3529 # force copytool to use a local/temp archive dir to ensure best
3530 # performance vs remote/NFS mounts used in auto-tests
3531 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3534 local dai=$(get_hsm_param default_archive_id)
3535 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3537 # to be sure wait_all_done will not be mislead by previous tests
3539 wait_for_grace_delay
3540 $LFS hsm_archive --filelist $FILELIST ||
3541 error "cannot archive a file list"
3543 $LFS hsm_release --filelist $FILELIST ||
3544 error "cannot release a file list"
3545 $LFS hsm_restore --filelist $FILELIST ||
3546 error "cannot restore a file list"
3550 run_test 90 "Archive/restore a file list"
3552 double_verify_reset_hsm_param() {
3554 echo "Testing $HSM_PARAM.$p"
3555 local val=$(get_hsm_param $p)
3557 local val2=$(($val * 2))
3558 set_hsm_param $p $val2
3559 val=$(get_hsm_param $p)
3560 [[ $val == $val2 ]] ||
3561 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3562 echo "Set $p to 0 must failed"
3566 set_hsm_param $p $save
3568 if [[ $rc == 0 ]]; then
3569 error "we must not be able to set $HSM_PARAM.$p to 0"
3574 double_verify_reset_hsm_param loop_period
3575 double_verify_reset_hsm_param grace_delay
3576 double_verify_reset_hsm_param active_request_timeout
3577 double_verify_reset_hsm_param max_requests
3578 double_verify_reset_hsm_param default_archive_id
3580 run_test 100 "Set coordinator /proc tunables"
3587 run_test 102 "Verify coordinator control"
3590 # test needs a running copytool
3597 for i in $(seq 1 20); do
3598 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3600 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3604 echo "Current requests"
3605 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3606 $HSM_PARAM.actions |\
3607 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3609 [[ -z "$res" ]] || error "Some request have not been canceled"
3613 run_test 103 "Purge all requests"
3618 # test needs a running copytool
3622 local f=$DIR/$tdir/$tfile
3624 fid=$(make_custom_file_for_progress $f 39 1000000)
3625 [ $? != 0 ] && skip "not enough free space" && return
3627 # if cdt is on, it can serve too quickly the request
3629 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3630 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3631 $HSM_PARAM.actions |\
3632 grep $fid | cut -f16 -d=")
3635 [[ "$data1" == "$DATAHEX" ]] ||
3636 error "Data field in records is ($data1) and not ($DATAHEX)"
3640 run_test 104 "Copy tool data field"
3647 for i in $(seq -w 1 10); do
3648 cp /etc/passwd $DIR/$tdir/$i
3649 $LFS hsm_archive $DIR/$tdir/$i
3651 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3652 $HSM_PARAM.actions |\
3653 grep WAITING | wc -l")
3656 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3657 $HSM_PARAM.actions |\
3658 grep WAITING | wc -l")
3661 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3662 error "Requests count after shutdown $reqcnt2 != "\
3663 "before shutdown $reqcnt1"
3665 run_test 105 "Restart of coordinator"
3668 # test needs a running copytool
3671 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3673 check_agent_registered $uuid
3675 search_copytools || error "No copytool found"
3678 check_agent_unregistered $uuid
3681 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3682 check_agent_registered $uuid
3686 run_test 106 "Copytool register/unregister"
3689 # test needs a running copytool
3691 # create and archive file
3693 local f1=$DIR/$tdir/$tfile
3694 local fid=$(copy_file /etc/passwd $f1)
3695 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3696 wait_request_state $fid ARCHIVE SUCCEED
3697 # shutdown and restart MDS
3699 # check the copytool still gets messages from MDT
3700 local f2=$DIR/$tdir/2
3701 local fid=$(copy_file /etc/passwd $f2)
3702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3703 # main check of this sanity: this request MUST succeed
3704 wait_request_state $fid ARCHIVE SUCCEED
3707 run_test 107 "Copytool re-register after MDS restart"
3709 policy_set_and_test()
3713 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3714 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3715 [[ "$policy" == "$target" ]] ||
3716 error "Wrong policy after '$change': '$policy' != '$target'"
3720 # to force default policy setting if error
3721 CDT_POLICY_HAD_CHANGED=true
3723 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3724 local default="NonBlockingRestore [NoRetryAction]"
3725 [[ "$policy" == "$default" ]] ||
3726 error "default policy has changed,"\
3727 " '$policy' != '$default' update the test"
3728 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3729 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3730 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3731 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3732 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3733 # useless bacause we know but safer for futur changes to use real value
3734 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3735 echo "Next set_param must failed"
3736 policy_set_and_test "wrong" "$policy"
3739 echo "Back to default policy"
3740 cdt_set_sanity_policy
3742 run_test 109 "Policy display/change"
3745 # test needs a running copytool
3750 copy2archive /etc/passwd $tdir/$tfile
3752 local f=$DIR/$tdir/$tfile
3753 import_file $tdir/$tfile $f
3754 local fid=$(path2fid $f)
3756 cdt_set_non_blocking_restore
3761 wait_request_state $fid RESTORE SUCCEED
3762 cdt_clear_non_blocking_restore
3766 error "md5sum returns $st != 1, "\
3767 "should also perror ENODATA (No data available)"
3771 run_test 110a "Non blocking restore policy (import case)"
3774 # test needs a running copytool
3778 local f=$DIR/$tdir/$tfile
3779 local fid=$(copy_file /etc/passwd $f)
3780 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3781 wait_request_state $fid ARCHIVE SUCCEED
3784 cdt_set_non_blocking_restore
3789 wait_request_state $fid RESTORE SUCCEED
3790 cdt_clear_non_blocking_restore
3794 error "md5sum returns $st != 1, "\
3795 "should also perror ENODATA (No data available)"
3799 run_test 110b "Non blocking restore policy (release case)"
3802 # test needs a running copytool
3806 copy2archive /etc/passwd $tdir/$tfile
3808 local f=$DIR/$tdir/$tfile
3810 import_file $tdir/$tfile $f
3811 local fid=$(path2fid $f)
3815 copytool_remove_backend $fid
3818 wait_request_state $fid RESTORE FAILED
3825 [[ $st == 0 ]] || error "Restore does not failed"
3829 run_test 111a "No retry policy (import case), restore will error"\
3830 " (No such file or directory)"
3833 # test needs a running copytool
3837 local f=$DIR/$tdir/$tfile
3838 local fid=$(copy_file /etc/passwd $f)
3840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3841 wait_request_state $fid ARCHIVE SUCCEED
3844 copytool_remove_backend $fid
3847 wait_request_state $fid RESTORE FAILED
3854 [[ $st == 0 ]] || error "Restore does not failed"
3858 run_test 111b "No retry policy (release case), restore will error"\
3859 " (No such file or directory)"
3862 # test needs a running copytool
3866 local f=$DIR/$tdir/$tfile
3867 local fid=$(copy_file /etc/passwd $f)
3869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3870 local l=$($LFS hsm_action $f)
3872 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3876 wait_request_state $fid ARCHIVE SUCCEED
3879 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3883 run_test 112 "State of recorded request"
3886 # test needs a running copytool
3890 local f=$DIR/$tdir/$tfile
3892 fid=$(make_custom_file_for_progress $f 103 1048576)
3893 [ $? != 0 ] && skip "not enough free space" && return
3895 # test with cdt on is made in test_221
3897 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3898 # wait archive to register at CDT
3899 wait_request_state $fid ARCHIVE WAITING
3902 wait_request_state $fid ARCHIVE CANCELED
3903 wait_request_state $fid CANCEL SUCCEED
3907 run_test 200 "Register/Cancel archive"
3910 # test needs a running copytool
3914 local f=$DIR/$tdir/$tfile
3915 make_archive $tdir/$tfile
3916 import_file $tdir/$tfile $f
3917 local fid=$(path2fid $f)
3919 # test with cdt on is made in test_222
3922 # wait restore to register at CDT
3923 wait_request_state $fid RESTORE WAITING
3926 wait_request_state $fid RESTORE CANCELED
3927 wait_request_state $fid CANCEL SUCCEED
3931 run_test 201 "Register/Cancel restore"
3934 # test needs a running copytool
3938 local f=$DIR/$tdir/$tfile
3940 fid=$(make_custom_file_for_progress $f 39 1000000)
3941 [ $? != 0 ] && skip "not enough free space" && return
3943 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3944 wait_request_state $fid ARCHIVE SUCCEED
3948 # wait remove to register at CDT
3949 wait_request_state $fid REMOVE WAITING
3952 wait_request_state $fid REMOVE CANCELED
3956 run_test 202 "Register/Cancel remove"
3959 # test needs a running copytool
3964 local f=$DIR/$tdir/$tfile
3965 local fid=$(copy_file /etc/passwd $f)
3969 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3970 wait_request_state $fid ARCHIVE SUCCEED
3972 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3976 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3980 run_test 220 "Changelog for archive"
3983 # test needs a running copytool
3988 local f=$DIR/$tdir/$tfile
3990 fid=$(make_custom_file_for_progress $f 103 1048576)
3991 [ $? != 0 ] && skip "not enough free space" && return
3995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3996 wait_request_state $fid ARCHIVE STARTED
3998 wait_request_state $fid ARCHIVE CANCELED
3999 wait_request_state $fid CANCEL SUCCEED
4001 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4004 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4008 run_test 221 "Changelog for archive canceled"
4011 # test needs a running copytool
4015 copy2archive /etc/passwd $tdir/$tfile
4017 local f=$DIR/$tdir/$tfile
4018 import_file $tdir/$tfile $f
4019 local fid=$(path2fid $f)
4024 wait_request_state $fid RESTORE SUCCEED
4026 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4029 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4033 run_test 222a "Changelog for explicit restore"
4036 # test needs a running copytool
4040 local f=$DIR/$tdir/$tfile
4041 local fid=$(copy_file /etc/passwd $f)
4044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4045 wait_request_state $fid ARCHIVE SUCCEED
4050 wait_request_state $fid RESTORE SUCCEED
4052 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4055 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4059 run_test 222b "Changelog for implicit restore"
4062 # test needs a running copytool
4067 local f=$DIR/$tdir/$tfile
4068 make_archive $tdir/$tfile
4072 import_file $tdir/$tfile $f
4073 local fid=$(path2fid $f)
4076 wait_request_state $fid RESTORE STARTED
4078 wait_request_state $fid RESTORE CANCELED
4079 wait_request_state $fid CANCEL SUCCEED
4081 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4084 [[ $flags == $target ]] ||
4085 error "Changelog flag is $flags not $target"
4089 run_test 223a "Changelog for restore canceled (import case)"
4092 # test needs a running copytool
4097 local f=$DIR/$tdir/$tfile
4099 fid=$(make_custom_file_for_progress $f 39 1000000)
4100 [ $? != 0 ] && skip "not enough free space" && return
4103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4104 wait_request_state $fid ARCHIVE SUCCEED
4107 wait_request_state $fid RESTORE STARTED
4109 wait_request_state $fid RESTORE CANCELED
4110 wait_request_state $fid CANCEL SUCCEED
4112 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4115 [[ $flags == $target ]] ||
4116 error "Changelog flag is $flags not $target"
4120 run_test 223b "Changelog for restore canceled (release case)"
4123 # test needs a running copytool
4128 local f=$DIR/$tdir/$tfile
4129 local fid=$(copy_file /etc/passwd $f)
4132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4133 wait_request_state $fid ARCHIVE SUCCEED
4136 wait_request_state $fid REMOVE SUCCEED
4138 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4141 [[ $flags == $target ]] ||
4142 error "Changelog flag is $flags not $target"
4146 run_test 224 "Changelog for remove"
4149 # test needs a running copytool
4152 # test is not usable because remove request is too fast
4153 # so it is always finished before cancel can be done ...
4154 echo "Test disabled"
4159 local f=$DIR/$tdir/$tfile
4161 fid=$(make_custom_file_for_progress $f 39 1000000)
4162 [ $? != 0 ] && skip "not enough free space" && return
4165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4166 wait_request_state $fid ARCHIVE SUCCEED
4168 # if cdt is on, it can serve too quickly the request
4173 wait_request_state $fid REMOVE CANCELED
4174 wait_request_state $fid CANCEL SUCCEED
4176 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4177 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4178 tail -n 1 | awk '{print $5}')
4181 [[ $flags == $target ]] ||
4182 error "Changelog flag is $flags not $target"
4186 run_test 225 "Changelog for remove canceled"
4189 # test needs a running copytool
4194 local f1=$DIR/$tdir/$tfile-1
4195 local f2=$DIR/$tdir/$tfile-2
4196 local f3=$DIR/$tdir/$tfile-3
4197 local fid1=$(copy_file /etc/passwd $f1)
4198 local fid2=$(copy_file /etc/passwd $f2)
4199 copy_file /etc/passwd $f3
4202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4203 wait_request_state $fid1 ARCHIVE SUCCEED
4205 $LFS hsm_archive $f2
4206 wait_request_state $fid2 ARCHIVE SUCCEED
4208 rm $f1 || error "rm $f1 failed"
4210 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4213 [[ $flags == $target ]] ||
4214 error "Changelog flag is $flags not $target"
4216 mv $f3 $f2 || error "mv $f3 $f2 failed"
4218 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4221 [[ $flags == $target ]] ||
4222 error "Changelog flag is $flags not $target"
4226 run_test 226 "changelog for last rm/mv with exiting archive"
4228 check_flags_changes() {
4236 $LFS hsm_set --$hsm_flag $f ||
4237 error "Cannot set $hsm_flag on $f"
4238 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4239 local seen=${#flags[*]}
4241 [[ $seen == $cnt ]] ||
4242 error "set $hsm_flag: Changelog events $seen != $cnt"
4243 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4244 error "set $hsm_flag: Changelog flags are "\
4245 "${flags[$((cnt - 1))]} not $target"
4247 $LFS hsm_clear --$hsm_flag $f ||
4248 error "Cannot clear $hsm_flag on $f"
4249 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4252 [[ $cnt == $seen ]] ||
4253 error "clear $hsm_flag: Changelog events $seen != $cnt"
4255 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4256 error "clear $hsm_flag: Changelog flag is "\
4257 "${flags[$((cnt - 1))]} not $target"
4261 # test needs a running copytool
4268 for i in norelease noarchive exists archived
4270 local f=$DIR/$tdir/$tfile-$i
4271 local fid=$(copy_file /etc/passwd $f)
4272 check_flags_changes $f $fid $i 0 1
4275 f=$DIR/$tdir/$tfile---lost
4276 fid=$(copy_file /etc/passwd $f)
4277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4278 wait_request_state $fid ARCHIVE SUCCEED
4279 check_flags_changes $f $fid lost 3 1
4283 run_test 227 "changelog when explicit setting of HSM flags"
4286 # test needs a running copytool
4289 local fid=$(make_small_sync $DIR/$tfile)
4290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4291 wait_request_state $fid ARCHIVE SUCCEED
4293 $LFS hsm_release $DIR/$tfile
4294 check_hsm_flags $DIR/$tfile "0x0000000d"
4296 filefrag $DIR/$tfile | grep " 1 extent found" ||
4297 error "filefrag on released file must return only one extent"
4299 # only newer versions of cp detect sparse files by stat/FIEMAP
4301 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4302 error "copying $DIR/$tfile"
4303 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4305 $LFS hsm_release $DIR/$tfile
4306 check_hsm_flags $DIR/$tfile "0x0000000d"
4308 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4310 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4312 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4313 error "comparing untarred $DIR/$tfile"
4315 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4316 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4319 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4322 # test needs a running copytool
4326 local maxrequest=$(get_hsm_param max_requests)
4327 local rqcnt=$(($maxrequest * 3))
4331 for i in $(seq -w 1 $rqcnt); do
4333 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4335 # we do it in 2 steps, so all requests arrive at the same time
4336 for i in $(seq -w 1 $rqcnt); do
4337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4342 while [[ $cnt != 0 || $wt != 0 ]]; do
4344 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4345 $HSM_PARAM.actions |\
4346 grep STARTED | grep -v CANCEL | wc -l")
4347 [[ $cnt -le $maxrequest ]] ||
4348 error "$cnt > $maxrequest too many started requests"
4349 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4350 $HSM_PARAM.actions |\
4351 grep WAITING | wc -l")
4352 echo "max=$maxrequest started=$cnt waiting=$wt"
4357 run_test 250 "Coordinator max request"
4360 # test needs a running copytool
4364 local f=$DIR/$tdir/$tfile
4366 fid=$(make_custom_file_for_progress $f 103 1048576)
4367 [ $? != 0 ] && skip "not enough free space" && return
4370 # to have a short test
4371 local old_to=$(get_hsm_param active_request_timeout)
4372 set_hsm_param active_request_timeout 4
4373 # to be sure the cdt will wake up frequently so
4374 # it will be able to cancel the "old" request
4375 local old_loop=$(get_hsm_param loop_period)
4376 set_hsm_param loop_period 2
4379 # clear locks to avoid extra delay caused by flush/cancel
4380 # and thus prevent early copytool death to timeout.
4381 cancel_lru_locks osc
4383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4384 wait_request_state $fid ARCHIVE STARTED
4386 wait_request_state $fid ARCHIVE CANCELED
4388 set_hsm_param active_request_timeout $old_to
4389 set_hsm_param loop_period $old_loop
4393 run_test 251 "Coordinator request timeout"
4396 # the only way to test ondisk conf is to restart MDS ...
4397 echo "Stop coordinator and remove coordinator state at mount"
4400 # clean on disk conf set by default
4401 cdt_clear_mount_state
4402 cdt_check_state stopped
4404 # check cdt still off after umount/remount
4406 cdt_check_state stopped
4408 echo "Set coordinator start at mount, and start coordinator"
4409 cdt_set_mount_state enabled
4412 cdt_check_state enabled
4414 # check cdt still on after umount/remount
4416 cdt_check_state enabled
4418 # we are back to original state (cdt started at mount)
4420 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4423 local ai=$(get_hsm_param default_archive_id)
4424 local new=$((ai + 1))
4426 set_hsm_param default_archive_id $new -P
4428 local res=$(get_hsm_param default_archive_id)
4431 set_hsm_param default_archive_id "" "-P -d"
4433 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4435 run_test 301 "HSM tunnable are persistent"
4438 local ai=$(get_hsm_param default_archive_id)
4439 local new=$((ai + 1))
4444 set_hsm_param default_archive_id $new -P
4447 for mdtno in $(seq 1 $MDSCOUNT); do
4452 cdt_check_state enabled
4454 local res=$(get_hsm_param default_archive_id)
4457 set_hsm_param default_archive_id "" "-P -d"
4459 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4461 run_test 302 "HSM tunnable are persistent when CDT is off"
4464 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4470 local dir_mdt0=$DIR/$tdir/mdt0
4471 local dir_mdt1=$DIR/$tdir/mdt1
4473 # create 1 dir per MDT
4474 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4475 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4477 # create 1 file in each MDT
4478 local fid1=$(make_small $dir_mdt0/$tfile)
4479 local fid2=$(make_small $dir_mdt1/$tfile)
4481 # check that hsm request on mdt0 is sent to the right MDS
4482 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4483 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4484 echo "archive successful on mdt0"
4486 # check that hsm request on mdt1 is sent to the right MDS
4487 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4488 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4489 echo "archive successful on mdt1"
4492 # clean test files and directories
4493 rm -rf $dir_mdt0 $dir_mdt1
4495 run_test 400 "Single request is sent to the right MDT"
4498 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4504 local dir_mdt0=$DIR/$tdir/mdt0
4505 local dir_mdt1=$DIR/$tdir/mdt1
4507 # create 1 dir per MDT
4508 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4509 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4511 # create 1 file in each MDT
4512 local fid1=$(make_small $dir_mdt0/$tfile)
4513 local fid2=$(make_small $dir_mdt1/$tfile)
4515 # check that compound requests are shunt to the rights MDTs
4516 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4517 error "lfs hsm_archive"
4518 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4519 echo "archive successful on mdt0"
4520 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4521 echo "archive successful on mdt1"
4524 # clean test files and directories
4525 rm -rf $dir_mdt0 $dir_mdt1
4527 run_test 401 "Compound requests split and sent to their respective MDTs"
4529 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4534 local node=$(facet_active_host $facet)
4536 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4537 awk '{print $4}'); do
4538 echo "$3 $mdc on $node"
4539 do_facet $facet "$LCTL --device $mdc $state" || return 1
4544 # make sure there is no running copytool
4547 # deactivate all mdc on agent1
4548 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4550 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4552 check_agent_unregistered "uuid" # match any agent
4554 # no expected running copytool
4555 search_copytools $agent && error "Copytool start should have failed"
4558 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4560 run_test 402 "Copytool start fails if all MDTs are inactive"
4563 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4565 # make sure there is no running copytool
4568 local agent=$(facet_active_host $SINGLEAGT)
4570 # deactivate all mdc for MDT0001
4571 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4574 local uuid=$(get_agent_uuid $agent)
4575 # check the agent is registered on MDT0000, and not on MDT0001
4576 check_agent_registered_by_mdt $uuid 0
4577 check_agent_unregistered_by_mdt $uuid 1
4579 # check running copytool process
4580 search_copytools $agent || error "No running copytools on $agent"
4582 # reactivate all mdc for MDT0001
4583 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4585 # make sure the copytool is now registered to all MDTs
4586 check_agent_registered $uuid
4590 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4593 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4597 # create files on both MDT0000 and MDT0001
4600 local dir_mdt0=$DIR/$tdir/mdt0
4601 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4603 # create 1 file on mdt0
4604 local fid1=$(make_small $dir_mdt0/$tfile)
4606 # deactivate all mdc for MDT0001
4607 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4609 # send an HSM request for files in MDT0000
4610 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4612 # check for completion of files in MDT0000
4613 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4614 echo "archive successful on mdt0"
4616 # reactivate all mdc for MDT0001
4617 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4620 # clean test files and directories
4623 run_test 404 "Inactive MDT does not block requests for active MDTs"
4626 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4632 local striped_dir=$DIR/$tdir/striped_dir
4634 # create striped dir on all of MDTs
4635 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4637 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4638 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4639 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4640 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4642 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4643 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4644 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4645 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4647 # check that compound requests are shunt to the rights MDTs
4648 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4649 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4650 error "lfs hsm_archive"
4652 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4653 echo "archive successful on $fid1"
4654 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4655 echo "archive successful on $fid2"
4656 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4657 echo "archive successful on $fid3"
4658 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4659 echo "archive successful on $fid4"
4661 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4662 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4663 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4664 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4666 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4667 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4668 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4669 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4673 run_test 405 "archive and release under striped directory"
4676 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4678 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4679 skip "need MDS version at least 2.7.64" && return 0
4686 fid=$(make_small $DIR/$tdir/$tfile)
4689 $LFS hsm_archive $DIR/$tdir/$tfile
4690 wait_request_state "$fid" ARCHIVE SUCCEED
4691 $LFS hsm_release $DIR/$tdir/$tfile
4693 # Should migrate $tdir but not $tfile.
4694 $LFS mv -M1 $DIR/$tdir &&
4695 error "migrating HSM an archived file should fail"
4697 $LFS hsm_restore $DIR/$tdir/$tfile
4698 wait_request_state "$fid" RESTORE SUCCEED
4700 $LFS hsm_remove $DIR/$tdir/$tfile
4701 wait_request_state "$fid" REMOVE SUCCEED
4703 cat $DIR/$tdir/$tfile > /dev/null ||
4704 error "cannot read $DIR/$tdir/$tfile"
4706 $LFS mv -M1 $DIR/$tdir ||
4707 error "cannot complete migration after HSM remove"
4709 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4710 if ((mdt_index != 1)); then
4711 error "expected MDT index 1, got $mdt_index"
4714 # Refresh fid after migration.
4715 fid=$(path2fid $DIR/$tdir/$tfile)
4718 $LFS hsm_archive $DIR/$tdir/$tfile
4719 wait_request_state "$fid" ARCHIVE SUCCEED 1
4721 lctl set_param debug=+trace
4722 $LFS hsm_release $DIR/$tdir/$tfile ||
4723 error "cannot release $DIR/$tdir/$tfile"
4725 $LFS hsm_restore $DIR/$tdir/$tfile
4726 wait_request_state "$fid" RESTORE SUCCEED 1
4728 cat $DIR/$tdir/$tfile > /dev/null ||
4729 error "cannot read $DIR/$tdir/$tfile"
4733 run_test 406 "attempting to migrate HSM archived files is safe"
4737 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4738 skip "HSM migrate is not supported" && return
4740 # Stop the existing copytool
4743 test_mkdir -p $DIR/$tdir
4744 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4746 run_test 500 "various LLAPI HSM tests"
4751 check_and_cleanup_lustre