3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
46 if getent group nobody; then
48 elif getent group nogroup; then
51 error "No generic nobody group"
56 # if there is no CLIENT1 defined, some tests can be ran on localhost
57 CLIENT1=${CLIENT1:-$HOSTNAME}
58 # if CLIENT2 doesn't exist then use CLIENT1 instead
59 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # Exception is the test which need two separate nodes
62 CLIENT2=${CLIENT2:-$CLIENT1}
65 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
66 # the following associated variables are added:
68 # AGTCOUNT: number of agents
69 # AGTDEV{N}: target HSM mount point (root path of the backend)
70 # agt{N}_HOST: hostname of the agent agt{N}
71 # SINGLEAGT: facet of the single agent
73 # The number of agents is initialized as the number of remote client nodes.
74 # By default, only single copytool is started on a remote client/agent. If there
75 # was no remote client, then the copytool will be started on the local client.
81 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
82 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
84 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
85 if [[ $CLIENTCOUNT -gt 1 ]] &&
86 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
87 skip_env "SHARED_DIRECTORY should be accessible"\
92 # We used to put the HSM archive in $SHARED_DIRECTORY but that
93 # meant NFS issues could hose sanity-hsm sessions. So now we
95 for n in $(seq $AGTCOUNT); do
96 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
97 agent=CLIENT$((n + 1))
98 if [[ -z "${!agent}" ]]; then
99 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
102 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
105 export SINGLEAGT=${SINGLEAGT:-agt1}
107 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
108 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
109 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
110 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
111 export HSMTOOL_TESTDIR
112 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
113 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
114 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
115 # deleting everything in filesystem, independent of any copytool.
116 export HSMTMP=${HSMTMP:-"shsm"}
118 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
120 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
121 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
125 # The test only support up to 10 MDTs
126 MDT_PREFIX="mdt.$FSNAME-MDT000"
127 HSM_PARAM="${MDT_PREFIX}0.hsm"
129 # archive is purged at copytool setup
130 HSM_ARCHIVE_PURGE=true
132 # Don't allow copytool error upon start/setup
133 HSMTOOL_NOERROR=false
136 # Get the backend root path for the given agent facet.
139 local dev=AGTDEV$(facet_number $facet)
144 # Stop copytool and unregister an existing changelog user.
146 copytool_monitor_cleanup
149 cdt_set_sanity_policy
154 # get MDT device for each mdc
155 for mdtno in $(seq 1 $MDSCOUNT); do
156 local idx=$(($mdtno - 1))
157 MDT[$idx]=$($LCTL get_param -n \
158 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
159 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
164 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
165 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
171 echo "Killing existing copytools on $hosts"
172 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
176 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
177 local wait_timeout=200
178 local wait_start=$SECONDS
179 local wait_end=$((wait_start + wait_timeout))
180 local sleep_time=100000 # 0.1 second
182 while ((SECONDS < wait_end)); do
183 if ! search_copytools $hosts; then
184 echo "copytools stopped in $((SECONDS - wait_start))s"
188 echo "copytools still running on $hosts"
190 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
191 sleep_time=$(bc <<< "$sleep_time * 2")
194 # try to dump Copytool's stack
195 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
196 "echo t >/proc/sysrq-trigger"
198 echo "copytools failed to stop in ${wait_timeout}s"
203 copytool_monitor_setup() {
204 local facet=${1:-$SINGLEAGT}
205 local agent=$(facet_active_host $facet)
207 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
208 local test_dir=$(do_node $agent "$cmd") ||
209 error "Failed to create tempdir on $agent"
210 export HSMTOOL_MONITOR_DIR=$test_dir
212 # Create the fifo and a monitor (cat dies when copytool dies)
213 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
214 error "failed to create copytool fifo on $agent"
215 cmd="cat $test_dir/fifo > $test_dir/events &"
216 cmd+=" echo \\\$! > $test_dir/monitor_pid"
218 if [[ $PDSH == *Rmrsh* ]]; then
219 # This is required for pdsh -Rmrsh and its handling of remote
221 # Regular ssh and pdsh -Rssh work fine without this
222 # backgrounded subshell nonsense.
223 (do_node $agent "$cmd") &
224 export HSMTOOL_MONITOR_PDSH=$!
226 # Slightly racy, but just making a best-effort to catch obvious
229 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
230 error "Failed to start copytool monitor on $agent"
232 do_node $agent "$cmd"
234 error "Failed to start copytool monitor on $agent"
239 copytool_monitor_cleanup() {
240 local facet=${1:-$SINGLEAGT}
241 local agent=$(facet_active_host $facet)
243 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
244 # Should die when the copytool dies, but just in case.
245 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
246 cmd+=" 2>/dev/null || true"
247 do_node $agent "$cmd"
248 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
249 export HSMTOOL_MONITOR_DIR=
252 # The pdsh should die on its own when the monitor dies. Just
253 # in case, though, try to clean up to avoid any cruft.
254 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
255 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
256 export HSMTOOL_MONITOR_PDSH=
262 local host="$(facet_host "$1")"
263 local prefix=$TESTLOG_PREFIX
264 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
266 printf "${prefix}.copytool${archive_id}_log.${host}.log"
271 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
272 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
273 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
274 [ ${#misc_options[@]} -gt 0 ] &&
275 cmd+=" $(IFS=" " echo "$@")"
276 cmd+=" \"$mountpoint\""
278 echo "Starting copytool $facet on $(facet_host $facet)"
279 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
280 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
284 local facet="${1:-$SINGLEAGT}"
286 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
295 local fail_on_error=true
296 local -a misc_options
297 while [ $# -gt 0 ]; do
305 local mountpoint="$1"
309 local archive_id="$1"
313 local bandwidth="$1" # in MB/s
316 local fail_on_error=false
319 # Uncommon(/copytool dependent) option
326 # Use default values if needed
327 local facet=${facet:-$SINGLEAGT}
328 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
329 local hsm_root="$(hsm_root "$facet")"
331 stack_trap "do_facet $facet \"rm -rf \\\"$hsm_root\\\"\"" EXIT
332 do_facet $facet "mkdir -p \"$hsm_root\"" ||
333 error "mkdir \"$hsm_root\" failed"
337 local copytool=lhsmtool
341 __${copytool}_${action} "${misc_options[@]}"
342 if [ $? -ne 0 ]; then
347 local host="$(facet_host $facet)"
348 error_msg="Failed to start copytool $facet on '$host'"
352 $fail_on_error && error "$error_msg" || echo "$error_msg"
357 local facet=${1:-$SINGLEAGT}
358 # Use MOUNT2 by default if defined
359 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
361 local hsm_root=${4:-$(copytool_device $facet)}
363 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
365 local agent=$(facet_active_host $facet)
367 if $HSM_ARCHIVE_PURGE; then
368 echo "Purging archive on $agent"
369 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
372 echo "Starting copytool $facet on $agent"
373 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
374 error "mkdir '$hsm_root/$HSMTMP' failed"
375 # bandwidth is limited to 1MB/s so the copy time is known and
376 # independent of hardware
377 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
378 cmd+=" --hsm-root $hsm_root/$HSMTMP"
379 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
380 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
381 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
382 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
383 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
384 cmd+=" --bandwidth 1 $lustre_mntpnt"
386 # Redirect the standard output and error to a log file which
387 # can be uploaded to Maloo.
388 local prefix=$TESTLOG_PREFIX
389 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
390 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
392 stack_trap cleanup EXIT
393 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
394 if [[ $? != 0 ]]; then
395 [[ $HSMTOOL_NOERROR == true ]] ||
396 error "start copytool $facet on $agent failed"
397 echo "start copytool $facet on $agent failed"
401 get_copytool_event_log() {
402 local facet=${1:-$SINGLEAGT}
403 local agent=$(facet_active_host $facet)
405 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
406 error "Can't get event log: No monitor directory!"
408 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
409 error "Could not collect event log from $agent"
414 local agt_facet=$SINGLEAGT
415 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
416 local hsm_root=$(copytool_device $agt_facet)
418 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
425 kill_copytools $agt_hosts
426 wait_copytools $agt_hosts || error "copytools failed to stop"
428 # Clean all CDTs orphans requests from previous tests that
429 # would otherwise need to timeout to clear.
430 for ((i = 0; i < MDSCOUNT; i++)); do
432 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
433 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
435 # Skip already stopping or stopped CDTs.
436 [[ "${state[$i]}" =~ ^stop ]] && continue
438 do_facet $facet "$LCTL set_param $param=shutdown"
441 for ((i = 0; i < MDSCOUNT; i++)); do
442 # Only check and restore CDTs that we stopped in the first loop.
443 [[ "${state[$i]}" =~ ^stop ]] && continue
446 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
448 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
449 error "$facet CDT state is not stopped"
451 # Restore old CDT state.
452 do_facet $facet "$LCTL set_param $param=${state[$i]}"
455 for ((i = 0; i < MDSCOUNT; i++)); do
456 # Only check CDTs that we stopped in the first loop.
457 [[ "${state[$i]}" =~ ^stop ]] && continue
460 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
462 # Check that the old CDT state was restored.
463 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
464 20 || error "$facet CDT state is not '${state[$i]}'"
467 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
468 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
473 local agents=${1:-$(facet_active_host $SINGLEAGT)}
475 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
476 echo "Copytool is suspended on $agents"
479 copytool_continue() {
480 local agents=${1:-$(facet_active_host $SINGLEAGT)}
482 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
483 echo "Copytool is continued on $agents"
486 copytool_remove_backend() {
488 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
489 echo "Remove from backend: $fid = $be"
490 do_facet $SINGLEAGT rm -f $be
494 mkdir -p "$(dirname "$2")" ||
495 error "cannot create directory '$(dirname "$2")'"
497 do_facet $SINGLEAGT \
498 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
499 --import $1 $2 $MOUNT" ||
500 error "import of $1 to $2 failed"
503 file_creation_failure() {
510 df $MOUNT $MOUNT2 >&2
511 error "Not enough space to create $file with $cmd"
514 error "cannot create $file with $cmd, status=$err"
519 # Creates a file using dd
525 local source=${5:-/dev/zero}
529 if [ -n "$conv" ]; then
533 # Create the directory in case it does not exist
534 mkdir -p "$(dirname "$file")"
535 # Delete the file in case it already exist
538 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
539 path2fid "$file" || error "cannot get FID of '$file'"
542 echo "cannot create file '$file'" >&2;
543 # Let the caller decide what to do on error
548 create_empty_file() {
549 create_file "${1/$DIR/$DIR2}" 1M 0 ||
550 file_creation_failure dd "${1/$DIR/$DIR2}" $?
553 create_small_file() {
554 local source_file=/dev/urandom
557 local conv=${2:-fsync}
559 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
560 file_creation_failure dd "${1/$DIR/$DIR2}" $?
563 create_small_sync_file() {
564 create_small_file "$1" sync
567 create_archive_file() {
568 local file="$HSM_ARCHIVE/$1"
570 local source=/dev/urandom
572 # Create the counterpart directory of the archive
573 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
574 error "cannot create archive directory '$(dirname "$file")'"
576 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
577 error "cannot create archive file '$file'"
581 local file=$HSM_ARCHIVE/$2
582 do_facet $SINGLEAGT mkdir -p $(dirname $file)
583 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
592 if [[ "$value" != "" ]]; then
595 for mdtno in $(seq 1 $MDSCOUNT); do
596 local idx=$(($mdtno - 1))
597 local facet=mds${mdtno}
598 # if $arg include -P option, run 1 set_param per MDT on the MGS
599 # else, run set_param on each MDT
600 [[ $arg = *"-P"* ]] && facet=mgs
601 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
602 [[ $? != 0 ]] && rc=1
612 for mdtno in $(seq 1 $MDSCOUNT); do
613 local idx=$(($mdtno - 1))
614 wait_result mds${mdtno} \
615 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
617 error "$key state is not '$target' on mds${mdtno}"
624 for mdtno in $(seq 1 $MDSCOUNT); do
625 local idx=$(($mdtno - 1))
626 local cl_user=$(do_facet mds${mdtno} $LCTL \
627 --device ${MDT[$idx]} \
628 changelog_register -n)
630 do_facet mds${mdtno} lctl set_param \
631 mdd.${MDT[$idx]}.changelog_mask="+hsm"
632 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
636 changelog_cleanup() {
638 for mdtno in $(seq 1 $MDSCOUNT); do
639 local idx=$(($mdtno - 1))
640 [[ -z ${CL_USERS[$idx]} ]] && continue
641 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
642 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
643 changelog_deregister ${CL_USERS[$idx]}
648 changelog_get_flags() {
653 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
658 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
666 mdts_set_param "$opt -n" "hsm.$param" "$value"
673 mdts_set_param "" hsm_control "$cmd"
674 mdts_check_param hsm_control "$target" 10
677 cdt_set_sanity_policy() {
678 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
681 mdts_set_param "" hsm.policy "+NRA"
682 mdts_set_param "" hsm.policy "-NBR"
683 CDT_POLICY_HAD_CHANGED=
688 mdts_set_param "" hsm.policy "+NRA"
689 CDT_POLICY_HAD_CHANGED=true
692 cdt_clear_no_retry() {
693 mdts_set_param "" hsm.policy "-NRA"
694 CDT_POLICY_HAD_CHANGED=true
697 cdt_set_non_blocking_restore() {
698 mdts_set_param "" hsm.policy "+NBR"
699 CDT_POLICY_HAD_CHANGED=true
702 cdt_clear_non_blocking_restore() {
703 mdts_set_param "" hsm.policy "-NBR"
704 CDT_POLICY_HAD_CHANGED=true
707 cdt_clear_mount_state() {
708 mdts_set_param "-P -d" hsm_control ""
711 cdt_set_mount_state() {
712 mdts_set_param "-P" hsm_control "$1"
713 # set_param -P is asynchronous operation and could race with set_param.
714 # In such case configs could be retrieved and applied at mgc after
715 # set_param -P completion. Sleep here to avoid race with set_param.
716 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
717 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
718 # and 10 seconds to retrieve config from server.
723 mdts_check_param hsm_control "$1" 20
727 set_test_state disabled disabled
731 set_test_state enabled enabled
735 set_test_state shutdown stopped
739 set_test_state purge enabled
745 cdt_set_sanity_policy
749 local client_count=$1
750 if [[ $CLIENTCOUNT -lt $client_count ]]; then
751 skip "Need $client_count or more clients, have $CLIENTCOUNT"
758 $LFS path2fid $1 | tr -d '[]'
759 return ${PIPESTATUS[0]}
767 if [[ $u == "user" ]]; then
768 st=$($RUNAS $LFS hsm_state $f)
771 st=$($LFS hsm_state $f)
774 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
776 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
780 get_hsm_archive_id() {
783 st=$($LFS hsm_state $f)
784 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
786 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
794 local st=$(get_hsm_flags $f)
795 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
798 check_hsm_flags_user() {
802 local st=$(get_hsm_flags $f user)
803 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
815 if [[ "$3" != 1 ]]; then
819 cp $1 $f || file_creation_failure cp $f $?
821 path2fid $f || error "cannot get fid on $f"
824 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
826 # Note that this might lead to surprising behaviours such as deleting an
827 # important file for the currently running test
828 delete_large_files() {
829 printf "Deleting large files...\n" >&2
830 find $MOUNT -size +10M -delete
831 wait_delete_completed
834 make_custom_file_for_progress() {
835 local count=${2:-"39"}
836 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
839 [[ $count -gt 0 ]] || error "Invalid file size"
840 [[ $bs -gt 0 ]] || error "Invalid stripe size"
842 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
843 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
844 echo "It might be due to a lack of space in the filesystem" >&2
845 delete_large_files >&2
846 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
847 file_creation_failure dd "${1/$DIR/$DIR2}" $?
854 wait_update --verbose $(facet_active_host $facet) "$@"
857 wait_request_state() {
861 # 4th arg (mdt index) is optional
863 local mds=mds$(($mdtidx + 1))
865 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
866 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
868 wait_result $mds "$cmd" $state 200 ||
869 error "request on $fid is not $state on $mds"
872 get_request_state() {
876 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
877 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
880 get_request_count() {
884 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
885 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
888 # Ensure the number of HSM request for a given FID is correct
889 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
890 assert_request_count() {
891 local request_count=$(get_request_count $1 $2)
892 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
894 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
901 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
902 [[ -n $fid ]] && cmd+=" | grep '$fid'"
903 cmd+=" | egrep 'WAITING|STARTED'"
905 wait_result $SINGLEMDS "$cmd" "" $timeout ||
906 error "requests did not complete"
909 wait_for_grace_delay() {
910 local val=$(get_hsm_param grace_delay)
914 wait_for_loop_period() {
915 local val=$(get_hsm_param loop_period)
922 # python2.6 in EL6 includes an internal json module
923 local json_parser='import json; import fileinput;'
924 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
925 json_parser+='json.loads([line for line in '
926 json_parser+='fileinput.input()][0]).items()])'
928 echo $raw_event | python -c "$json_parser"
931 get_agent_by_uuid_mdt() {
934 local mds=mds$(($mdtidx + 1))
935 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
939 check_agent_registered_by_mdt() {
942 local mds=mds$(($mdtidx + 1))
943 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
944 if [[ ! -z "$agent" ]]; then
945 echo "found agent $agent on $mds"
947 error "uuid $uuid not found in agent list on $mds"
951 check_agent_unregistered_by_mdt() {
954 local mds=mds$(($mdtidx + 1))
955 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
956 if [[ -z "$agent" ]]; then
957 echo "uuid not found in agent list on $mds"
959 error "uuid found in agent list on $mds: $agent"
963 check_agent_registered() {
966 for mdsno in $(seq 1 $MDSCOUNT); do
967 check_agent_registered_by_mdt $uuid $((mdsno - 1))
971 check_agent_unregistered() {
974 for mdsno in $(seq 1 $MDSCOUNT); do
975 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
980 local agent=${1:-$(facet_active_host $SINGLEAGT)}
982 # Lustre mount-point is mandatory and last parameter on
984 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
986 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
988 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
994 # populate MDT device array
997 # cleanup from previous bad setup
1000 # for recovery tests, coordinator needs to be started at mount
1002 # the lustre conf must be without hsm on (like for sanity.sh)
1003 echo "Set HSM on and start"
1004 cdt_set_mount_state enabled
1005 cdt_check_state enabled
1007 echo "Set sanity-hsm HSM policy"
1008 cdt_set_sanity_policy
1010 # finished requests are quickly removed from list
1011 set_hsm_param grace_delay 10
1015 chmod 777 $DIR/$tdir
1017 local f=$DIR/$tdir/$tfile
1021 check_hsm_flags_user $f "0x00000000"
1023 $RUNAS $LFS hsm_set --norelease $f ||
1024 error "user could not change hsm flags"
1025 check_hsm_flags_user $f "0x00000010"
1027 $RUNAS $LFS hsm_clear --norelease $f ||
1028 error "user could not clear hsm flags"
1029 check_hsm_flags_user $f "0x00000000"
1031 # User could not change those flags...
1032 $RUNAS $LFS hsm_set --exists $f &&
1033 error "user should not set this flag"
1034 check_hsm_flags_user $f "0x00000000"
1037 $LFS hsm_set --exists $f ||
1038 error "root could not change hsm flags"
1039 check_hsm_flags_user $f "0x00000001"
1041 $LFS hsm_clear --exists $f ||
1042 error "root could not clear hsm state"
1043 check_hsm_flags_user $f "0x00000000"
1046 run_test 1 "lfs hsm flags root/non-root access"
1049 local f=$DIR/$tdir/$tfile
1050 local fid=$(create_small_file $f)
1054 $LFS hsm_archive $f || error "could not archive file"
1055 wait_request_state $fid ARCHIVE SUCCEED
1057 # Release and check states
1058 $LFS hsm_release $f || error "could not release file"
1059 echo -n "Verifying released state: "
1060 check_hsm_flags $f "0x0000000d"
1062 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
1064 run_test 1a "mmap & cat a HSM released file"
1068 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
1069 error "failed to set default stripe"
1070 local f=$DIR/$tdir/$tfile
1073 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1074 error "failed to create file"
1075 local fid=$(path2fid $f)
1080 $LFS hsm_archive $f || error "could not archive file"
1081 wait_request_state $fid ARCHIVE SUCCEED
1084 $LFS hsm_release $f || error "could not release file"
1085 echo "verify released state: "
1086 check_hsm_flags $f "0x0000000d" && echo "pass"
1089 $LFS hsm_restore $f || error "could not restore file"
1090 wait_request_state $fid RESTORE SUCCEED
1091 echo "verify restored state: "
1092 check_hsm_flags $f "0x00000009" && echo "pass"
1094 run_test 1b "Archive, Release & Restore composite file"
1098 chmod 777 $DIR/$tdir
1100 local f=$DIR/$tdir/$tfile
1103 # Test whether we can set the maximum archive number.
1104 local LOCAL_HSM_ARCHIVE_NUMBER=32
1105 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1106 error "root could not change hsm flags"
1107 check_hsm_flags_user $f "0x00000001"
1108 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1109 local st=$(get_hsm_archive_id $f)
1110 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1111 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1113 # Test whether setting archive number 0 results in no change.
1114 $LFS hsm_set --exists --archive-id 0 $f ||
1115 error "root could not change hsm flags"
1116 check_hsm_flags_user $f "0x00000001"
1117 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1118 st=$(get_hsm_archive_id $f)
1119 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1120 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1122 # Test whether setting archive number > 32 results in error.
1123 $LFS hsm_set --exists --archive-id 33 $f &&
1124 error "archive number is larger than 32"
1125 check_hsm_flags_user $f "0x00000001"
1127 # Test whether setting archive number 16 and archived flag.
1128 LOCAL_HSM_ARCHIVE_NUMBER=16
1129 $LFS hsm_set --exists --archived \
1130 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1131 error "root could not change hsm flags"
1132 check_hsm_flags_user $f "0x00000009"
1133 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1134 st=$(get_hsm_archive_id $f)
1135 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1136 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1138 run_test 1c "Check setting archive-id in lfs hsm_set"
1141 local f=$DIR/$tdir/$tfile
1143 create_empty_file "$f"
1144 # New files are not dirty
1145 check_hsm_flags $f "0x00000000"
1147 # For test, we simulate an archived file.
1148 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1149 check_hsm_flags $f "0x00000001"
1151 # chmod do not put the file dirty
1152 chmod 600 $f || error "could not chmod test file"
1153 check_hsm_flags $f "0x00000001"
1155 # chown do not put the file dirty
1156 chown $RUNAS_ID $f || error "could not chown test file"
1157 check_hsm_flags $f "0x00000001"
1159 # truncate put the file dirty
1160 $TRUNCATE $f 1 || error "could not truncate test file"
1161 check_hsm_flags $f "0x00000003"
1163 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1164 check_hsm_flags $f "0x00000001"
1166 run_test 2 "Check file dirtyness when doing setattr"
1172 # New files are not dirty
1173 cp -p /etc/passwd $f
1174 check_hsm_flags $f "0x00000000"
1176 # For test, we simulate an archived file.
1177 $LFS hsm_set --exists $f ||
1178 error "user could not change hsm flags"
1179 check_hsm_flags $f "0x00000001"
1181 # Reading a file, does not set dirty
1182 cat $f > /dev/null || error "could not read file"
1183 check_hsm_flags $f "0x00000001"
1185 # Open for write without modifying data, does not set dirty
1186 openfile -f O_WRONLY $f || error "could not open test file"
1187 check_hsm_flags $f "0x00000001"
1189 # Append to a file sets it dirty
1190 cp -p /etc/passwd $f.append || error "could not create file"
1191 $LFS hsm_set --exists $f.append ||
1192 error "user could not change hsm flags"
1193 dd if=/etc/passwd of=$f.append bs=1 count=3\
1194 conv=notrunc oflag=append status=noxfer ||
1195 file_creation_failure dd $f.append $?
1196 check_hsm_flags $f.append "0x00000003"
1198 # Modify a file sets it dirty
1199 cp -p /etc/passwd $f.modify || error "could not create file"
1200 $LFS hsm_set --exists $f.modify ||
1201 error "user could not change hsm flags"
1202 dd if=/dev/zero of=$f.modify bs=1 count=3\
1203 conv=notrunc status=noxfer ||
1204 file_creation_failure dd $f.modify $?
1205 check_hsm_flags $f.modify "0x00000003"
1207 # Open O_TRUNC sets dirty
1208 cp -p /etc/passwd $f.trunc || error "could not create file"
1209 $LFS hsm_set --exists $f.trunc ||
1210 error "user could not change hsm flags"
1211 cp /etc/group $f.trunc || error "could not override a file"
1212 check_hsm_flags $f.trunc "0x00000003"
1214 # Mmapped a file sets dirty
1215 cp -p /etc/passwd $f.mmap || error "could not create file"
1216 $LFS hsm_set --exists $f.mmap ||
1217 error "user could not change hsm flags"
1218 multiop $f.mmap OSMWUc || error "could not mmap a file"
1219 check_hsm_flags $f.mmap "0x00000003"
1221 run_test 3 "Check file dirtyness when opening for write"
1224 local f=$DIR/$tdir/$tfile
1225 local fid=$(create_small_file $f)
1228 local st=$(get_request_state $fid CANCEL)
1229 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1231 run_test 4 "Useless cancel must not be registered"
1234 # test needs a running copytool
1238 local f=$DIR/$tdir/$tfile
1239 local fid=$(copy_file /etc/passwd $f)
1241 wait_request_state $fid ARCHIVE SUCCEED
1243 check_hsm_flags $f "0x00000009"
1245 run_test 8 "Test default archive number"
1248 # we do not use the default one to be sure
1249 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1250 copytool setup --archive-id $archive_id
1252 # give time for CT to register with MDTs
1253 sleep $(($MDSCOUNT*2))
1254 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1255 check_agent_registered $uuid
1258 local f=$DIR/$tdir/$tfile
1259 local fid=$(copy_file /etc/passwd $f)
1260 $LFS hsm_archive --archive $archive_id $f
1261 wait_request_state $fid ARCHIVE SUCCEED
1263 check_hsm_flags $f "0x00000009"
1265 run_test 9 "Use of explicit archive number, with dedicated copytool"
1268 needclients 3 || return 0
1274 # start all of the copytools
1275 for n in $(seq $AGTCOUNT); do
1276 copytool setup --facet agt$n
1280 for n in $(seq $AGTCOUNT); do
1281 file=$DIR/$tdir/$tfile.$n
1282 fid=$(create_small_file $file)
1284 $LFS hsm_archive $file || error "could not archive file $file"
1285 wait_request_state $fid ARCHIVE SUCCEED
1286 check_hsm_flags $file "0x00000009"
1289 run_test 9a "Multiple remote agents"
1292 # test needs a running copytool
1295 mkdir -p $DIR/$tdir/d1
1296 local f=$DIR/$tdir/$tfile
1297 local fid=$(copy_file /etc/hosts $f)
1298 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1299 error "hsm_archive failed"
1300 wait_request_state $fid ARCHIVE SUCCEED
1302 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1303 error "fid $fid not in archive $HSM_ARCHIVE"
1304 echo "Verifying content"
1305 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1306 echo "Verifying hsm state "
1307 check_hsm_flags $f "0x00000009"
1309 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1310 local st=$(get_hsm_archive_id $f)
1311 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1312 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1316 run_test 10a "Archive a file"
1319 # test needs a running copytool
1323 local f=$DIR/$tdir/$tfile
1324 local fid=$(copy_file /etc/hosts $f)
1325 $LFS hsm_archive $f || error "archive request failed"
1326 wait_request_state $fid ARCHIVE SUCCEED
1328 $LFS hsm_archive $f || error "archive of non dirty file failed"
1329 local cnt=$(get_request_count $fid ARCHIVE)
1330 [[ "$cnt" == "1" ]] ||
1331 error "archive of non dirty file must not make a request"
1333 run_test 10b "Archive of non dirty file must work without doing request"
1336 # test needs a running copytool
1340 local f=$DIR/$tdir/$tfile
1341 local fid=$(copy_file /etc/hosts $f)
1342 $LFS hsm_set --noarchive $f
1343 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1346 run_test 10c "Check forbidden archive"
1349 # test needs a running copytool
1353 local f=$DIR/$tdir/$tfile
1354 local fid=$(copy_file /etc/hosts $f)
1355 $LFS hsm_archive $f || error "cannot archive $f"
1356 wait_request_state $fid ARCHIVE SUCCEED
1358 local ar=$(get_hsm_archive_id $f)
1359 local dflt=$(get_hsm_param default_archive_id)
1360 [[ $ar == $dflt ]] ||
1361 error "archived file is not on default archive: $ar != $dflt"
1363 run_test 10d "Archive a file on the default archive id"
1367 copy2archive /etc/hosts $tdir/$tfile
1368 local f=$DIR/$tdir/$tfile
1370 import_file $tdir/$tfile $f
1371 echo -n "Verifying released state: "
1372 check_hsm_flags $f "0x0000000d"
1374 local LSZ=$(stat -c "%s" $f)
1375 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1377 echo "Verifying imported size $LSZ=$ASZ"
1378 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1379 echo -n "Verifying released pattern: "
1380 local PTRN=$($GETSTRIPE -L $f)
1382 [[ $PTRN == released ]] || error "Is not released"
1383 local fid=$(path2fid $f)
1384 echo "Verifying new fid $fid in archive"
1386 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1387 error "fid $fid not in archive $HSM_ARCHIVE"
1389 run_test 11a "Import a file"
1392 # test needs a running copytool
1396 local f=$DIR/$tdir/$tfile
1397 local fid=$(copy_file /etc/hosts $f)
1398 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1399 error "hsm_archive failed"
1400 wait_request_state $fid ARCHIVE SUCCEED
1402 local FILE_HASH=$(md5sum $f)
1407 echo "$FILE_HASH" | md5sum -c
1409 [[ $? -eq 0 ]] || error "Restored file differs"
1413 run_test 11b "Import a deleted file using its FID"
1416 # test needs a running copytool
1420 copy2archive /etc/hosts $tdir/$tfile
1422 local f=$DIR/$tdir/$tfile
1423 import_file $tdir/$tfile $f
1424 local f2=$DIR2/$tdir/$tfile
1425 echo "Verifying released state: "
1426 check_hsm_flags $f2 "0x0000000d"
1428 local fid=$(path2fid $f2)
1429 $LFS hsm_restore $f2
1430 wait_request_state $fid RESTORE SUCCEED
1432 echo "Verifying file state: "
1433 check_hsm_flags $f2 "0x00000009"
1435 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1437 [[ $? -eq 0 ]] || error "Restored file differs"
1441 run_test 12a "Restore an imported file explicitly"
1444 # test needs a running copytool
1448 copy2archive /etc/hosts $tdir/$tfile
1450 local f=$DIR/$tdir/$tfile
1451 import_file $tdir/$tfile $f
1452 echo "Verifying released state: "
1453 check_hsm_flags $f "0x0000000d"
1455 cat $f > /dev/null || error "File read failed"
1457 echo "Verifying file state after restore: "
1458 check_hsm_flags $f "0x00000009"
1460 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1462 [[ $? -eq 0 ]] || error "Restored file differs"
1466 run_test 12b "Restore an imported file implicitly"
1469 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1471 # test needs a running copytool
1474 local f=$DIR/$tdir/$tfile
1476 $LFS setstripe -c 2 "$f"
1478 fid=$(make_custom_file_for_progress $f 5)
1479 [ $? != 0 ] && skip "not enough free space" && return
1481 local FILE_CRC=$(md5sum $f)
1483 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1484 wait_request_state $fid ARCHIVE SUCCEED
1485 $LFS hsm_release $f || error "release $f failed"
1487 echo "$FILE_CRC" | md5sum -c
1489 [[ $? -eq 0 ]] || error "Restored file differs"
1491 run_test 12c "Restore a file with stripe of 2"
1494 # test needs a running copytool
1499 local f=$DIR/$tdir/$tfile
1500 local fid=$(copy_file /etc/hosts $f)
1501 $LFS hsm_restore $f || error "restore of non archived file failed"
1502 local cnt=$(get_request_count $fid RESTORE)
1503 [[ "$cnt" == "0" ]] ||
1504 error "restore non archived must not make a request"
1505 $LFS hsm_archive $f ||
1506 error "archive request failed"
1507 wait_request_state $fid ARCHIVE SUCCEED
1508 $LFS hsm_restore $f ||
1509 error "restore of non released file failed"
1510 local cnt=$(get_request_count $fid RESTORE)
1511 [[ "$cnt" == "0" ]] ||
1512 error "restore a non dirty file must not make a request"
1514 run_test 12d "Restore of a non archived, non released file must work"\
1515 " without doing request"
1518 # test needs a running copytool
1521 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1522 local f=$DIR/$tdir/$tfile
1523 local fid=$(copy_file /etc/hosts $f)
1524 $LFS hsm_archive $f || error "archive request failed"
1525 wait_request_state $fid ARCHIVE SUCCEED
1528 cat /etc/hosts >> $f
1532 $LFS hsm_restore $f && error "restore a dirty file must fail"
1535 run_test 12e "Check forbidden restore"
1538 # test needs a running copytool
1542 local f=$DIR/$tdir/$tfile
1543 local fid=$(copy_file /etc/hosts $f)
1545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1546 wait_request_state $fid ARCHIVE SUCCEED
1547 $LFS hsm_release $f || error "release of $f failed"
1549 wait_request_state $fid RESTORE SUCCEED
1551 echo -n "Verifying file state: "
1552 check_hsm_flags $f "0x00000009"
1554 diff -q /etc/hosts $f
1556 [[ $? -eq 0 ]] || error "Restored file differs"
1558 run_test 12f "Restore a released file explicitly"
1561 # test needs a running copytool
1565 local f=$DIR/$tdir/$tfile
1566 local fid=$(copy_file /etc/hosts $f)
1568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1569 wait_request_state $fid ARCHIVE SUCCEED
1570 $LFS hsm_release $f || error "release of $f failed"
1572 diff -q /etc/hosts $f
1575 # we check we had a restore done
1576 wait_request_state $fid RESTORE SUCCEED
1578 [[ $st -eq 0 ]] || error "Restored file differs"
1580 run_test 12g "Restore a released file implicitly"
1583 needclients 2 || return 0
1585 # test needs a running copytool
1589 local f=$DIR/$tdir/$tfile
1590 local fid=$(copy_file /etc/hosts $f)
1592 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1593 wait_request_state $fid ARCHIVE SUCCEED
1594 $LFS hsm_release $f || error "release of $f failed"
1596 do_node $CLIENT2 diff -q /etc/hosts $f
1599 # we check we had a restore done
1600 wait_request_state $fid RESTORE SUCCEED
1602 [[ $st -eq 0 ]] || error "Restored file differs"
1604 run_test 12h "Restore a released file implicitly from a second node"
1607 # test needs a running copytool
1611 local f=$DIR/$tdir/$tfile
1612 local fid=$(copy_file /etc/passwd $f)
1613 $LFS hsm_archive $f || error "archive of $f failed"
1614 wait_request_state $fid ARCHIVE SUCCEED
1616 $LFS hsm_release $f || error "release of $f failed"
1620 [[ $? -eq 0 ]] || error "Restored file differs"
1622 run_test 12m "Archive/release/implicit restore"
1625 # test needs a running copytool
1629 copy2archive /etc/hosts $tdir/$tfile
1631 local f=$DIR/$tdir/$tfile
1632 import_file $tdir/$tfile $f
1634 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1635 error "Restored file differs"
1637 $LFS hsm_release $f || error "release of $f failed"
1641 run_test 12n "Import/implicit restore/release"
1644 # test needs a running copytool
1648 local f=$DIR/$tdir/$tfile
1649 local fid=$(copy_file /etc/hosts $f)
1651 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1652 wait_request_state $fid ARCHIVE SUCCEED
1653 $LFS hsm_release $f || error "release of $f failed"
1655 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1656 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1658 # set no retry action mode
1661 diff -q /etc/hosts $f
1664 # we check we had a restore failure
1665 wait_request_state $fid RESTORE FAILED
1667 [[ $st -eq 0 ]] && error "Restore must fail"
1669 # remove no retry action mode
1672 # check file is still released
1673 check_hsm_flags $f "0x0000000d"
1675 # retry w/o failure injection
1676 do_facet $SINGLEMDS lctl set_param fail_loc=0
1678 # to be sure previous RESTORE result is gone
1680 wait_for_grace_delay
1682 diff -q /etc/hosts $f
1685 # we check we had a restore done
1686 wait_request_state $fid RESTORE SUCCEED
1688 [[ $st -eq 0 ]] || error "Restored file differs"
1690 run_test 12o "Layout-swap failure during Restore leaves file released"
1693 # test needs a running copytool
1697 local f=$DIR/$tdir/$tfile
1698 local fid=$(copy_file /etc/hosts $f)
1700 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1701 wait_request_state $fid ARCHIVE SUCCEED
1702 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1703 $LFS hsm_release $f || error "cannot release $f"
1704 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1705 $LFS hsm_release $f || error "cannot release $f"
1706 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1708 run_test 12p "implicit restore of a file on copytool mount point"
1710 cleanup_test_12q() {
1711 error "cannot umount $MOUNT3 on $SINGLEAGT"
1715 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1716 skip "need MDS version at least 2.7.58" && return 0
1718 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1719 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1720 error "cannot mount $MOUNT3 on $SINGLEAGT"
1722 # test needs a running copytool
1723 copytool setup -m "$MOUNT3"
1725 local f=$DIR/$tdir/$tfile
1726 local f2=$DIR2/$tdir/$tfile
1727 local fid=$(create_small_file $f)
1728 local orig_size=$(stat -c "%s" $f)
1730 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1731 wait_request_state $fid ARCHIVE SUCCEED
1733 $LFS hsm_release $f || error "could not release file"
1734 check_hsm_flags $f "0x0000000d"
1737 wait_copytools || error "copytool failed to stop"
1739 cat $f > /dev/null &
1741 # wait a bit to allow implicit restore request to be handled.
1742 # if not, next stat would also block on layout-lock.
1745 local size=$(stat -c "%s" $f2)
1746 [ $size -eq $orig_size ] ||
1747 error "$f2: wrong size after archive: $size != $orig_size"
1749 copytool setup -m "$MOUNT3"
1753 size=$(stat -c "%s" $f)
1754 [ $size -eq $orig_size ] ||
1755 error "$f: wrong size after restore: $size != $orig_size"
1757 size=$(stat -c "%s" $f2)
1758 [ $size -eq $orig_size ] ||
1759 error "$f2: wrong size after restore: $size != $orig_size"
1763 size=$(stat -c "%s" $f)
1765 error "$f: wrong size after overwrite: $size != 0"
1767 size=$(stat -c "%s" $f2)
1769 error "$f2: wrong size after overwrite: $size != 0"
1771 run_test 12q "file attributes are refreshed after restore"
1774 # test needs a running copytool
1777 local ARC_SUBDIR="import.orig"
1781 # populate directory to be imported
1782 for d in $(seq 1 10); do
1783 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1784 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1785 for f in $(seq 1 10); do
1786 CURR_FILE="$CURR_DIR/$tfile.$f"
1787 # write file-specific data
1788 do_facet $SINGLEAGT \
1789 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1790 "file=$CURR_FILE > $CURR_FILE"
1794 import_file "$ARC_SUBDIR" $DIR/$tdir
1795 # diff lustre content and origin (triggers file restoration)
1796 # there must be 10x10 identical files, and no difference
1797 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1798 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1799 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1800 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1802 [ $cnt_diff -eq 0 ] ||
1803 error "$cnt_diff imported files differ from read data"
1804 [ $cnt_ok -eq 100 ] ||
1805 error "not enough identical files ($cnt_ok != 100)"
1809 run_test 13 "Recursively import and restore a directory"
1812 # test needs a running copytool
1816 local f=$DIR/$tdir/$tfile
1817 local fid=$(create_small_file $f)
1818 local sum=$(md5sum $f | awk '{print $1}')
1819 $LFS hsm_archive $f || error "could not archive file"
1820 wait_request_state $fid ARCHIVE SUCCEED
1822 # create released file (simulate llapi_hsm_import call)
1823 local fid2=$(create_empty_file "$f")
1824 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1825 $LFS hsm_release $f || error "could not release file"
1827 # rebind the archive to the newly created file
1828 echo "rebind $fid to $fid2"
1830 do_facet $SINGLEAGT \
1831 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1832 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1834 # restore file and compare md5sum
1835 local sum2=$(md5sum $f | awk '{print $1}')
1837 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1841 run_test 14 "Rebind archived file to a new fid"
1844 # test needs a running copytool
1848 local f=$DIR/$tdir/$tfile
1850 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1854 for i in $(seq 1 $count); do
1855 fids[$i]=$(create_small_file $f.$i)
1856 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1857 $LFS hsm_archive $f.$i || error "could not archive file"
1859 wait_all_done $(($count*60))
1863 for i in $(seq 1 $count); do
1864 local fid2=$(create_empty_file "${f}.${i}")
1865 # add the rebind operation to the list
1866 echo ${fids[$i]} $fid2 >> $tmpfile
1868 # set it released (simulate llapi_hsm_import call)
1869 $LFS hsm_set --archived --exists $f.$i ||
1870 error "could not force hsm flags"
1871 $LFS hsm_release $f.$i || error "could not release file"
1873 nl=$(wc -l < $tmpfile)
1874 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1876 echo "rebind list of files"
1877 do_facet $SINGLEAGT \
1878 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1879 --rebind $tmpfile $DIR" || error "could not rebind file list"
1881 # restore files and compare md5sum
1882 for i in $(seq 1 $count); do
1883 local sum2=$(md5sum $f.$i | awk '{print $1}')
1884 [[ $sum2 == ${sums[$i]} ]] ||
1885 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1891 run_test 15 "Rebind a list of files"
1894 # test needs a running copytool
1898 # create a known size file so we can verify transfer speed
1901 dd if=/dev/zero of=$ref bs=1M count=20
1904 local f=$DIR/$tdir/$tfile
1905 local fid=$(copy_file $ref $f)
1907 local start=$(date +%s)
1909 wait_request_state $fid ARCHIVE SUCCEED
1910 local end=$(date +%s)
1911 # Add 1 to account for rounding errors between start and end (LU-8155)
1912 local duration=$((end - start + 1))
1914 [[ $duration -ge $((goal - 1)) ]] ||
1915 error "Transfer is too fast $duration < $goal"
1917 run_test 16 "Test CT bandwith control option"
1920 local f=$DIR/$tdir/$tfile
1921 create_empty_file "$f"
1923 # Could not release a non-archived file
1924 $LFS hsm_release $f && error "release should not succeed"
1926 # For following tests, we must test them with HS_ARCHIVED set
1927 $LFS hsm_set --exists --archived $f || error "could not add flag"
1929 # Could not release a file if no-release is set
1930 $LFS hsm_set --norelease $f || error "could not add flag"
1931 $LFS hsm_release $f && error "release should not succeed"
1932 $LFS hsm_clear --norelease $f || error "could not remove flag"
1934 # Could not release a file if lost
1935 $LFS hsm_set --lost $f || error "could not add flag"
1936 $LFS hsm_release $f && error "release should not succeed"
1937 $LFS hsm_clear --lost $f || error "could not remove flag"
1939 # Could not release a file if dirty
1940 $LFS hsm_set --dirty $f || error "could not add flag"
1941 $LFS hsm_release $f && error "release should not succeed"
1942 $LFS hsm_clear --dirty $f || error "could not remove flag"
1944 run_test 20 "Release is not permitted"
1947 # test needs a running copytool
1950 local f=$DIR/$tdir/test_release
1952 # Create a file and check its states
1953 local fid=$(create_small_file $f)
1954 check_hsm_flags $f "0x00000000"
1956 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1957 # used until file is flushed to disk
1958 if [ $(facet_fstype ost1) == "zfs" ]; then
1959 # this causes an OST_SYNC rpc to be sent
1960 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1961 # clear locks to reread file data
1962 cancel_lru_locks osc
1965 local orig_size=$(stat -c "%s" $f)
1966 local orig_blocks=$(stat -c "%b" $f)
1968 start_full_debug_logging
1970 $LFS hsm_archive $f || error "could not archive file"
1971 wait_request_state $fid ARCHIVE SUCCEED
1973 local blocks=$(stat -c "%b" $f)
1974 [ $blocks -eq $orig_blocks ] ||
1975 error "$f: wrong block number after archive: " \
1976 "$blocks != $orig_blocks"
1977 local size=$(stat -c "%s" $f)
1978 [ $size -eq $orig_size ] ||
1979 error "$f: wrong size after archive: $size != $orig_size"
1981 # Release and check states
1982 $LFS hsm_release $f || error "could not release file"
1983 check_hsm_flags $f "0x0000000d"
1985 blocks=$(stat -c "%b" $f)
1986 [ $blocks -gt 5 ] &&
1987 error "$f: too many blocks after release: $blocks > 5"
1988 size=$(stat -c "%s" $f)
1989 [ $size -ne $orig_size ] &&
1990 error "$f: wrong size after release: $size != $orig_size"
1992 # Check we can release an file without stripe info
1996 check_hsm_flags $f "0x00000000"
1997 $LFS hsm_archive $f || error "could not archive file"
1998 wait_request_state $fid ARCHIVE SUCCEED
2000 # Release and check states
2001 $LFS hsm_release $f || error "could not release file"
2002 check_hsm_flags $f "0x0000000d"
2004 # Release again a file that is already released is OK
2005 $LFS hsm_release $f || fail "second release should succeed"
2006 check_hsm_flags $f "0x0000000d"
2008 stop_full_debug_logging
2010 run_test 21 "Simple release tests"
2013 # test needs a running copytool
2016 local f=$DIR/$tdir/test_release
2017 local swap=$DIR/$tdir/test_swap
2019 # Create a file and check its states
2020 local fid=$(create_small_file $f)
2021 check_hsm_flags $f "0x00000000"
2023 $LFS hsm_archive $f || error "could not archive file"
2024 wait_request_state $fid ARCHIVE SUCCEED
2026 # Release and check states
2027 $LFS hsm_release $f || error "could not release file"
2028 check_hsm_flags $f "0x0000000d"
2030 create_small_file $swap
2031 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2035 run_test 22 "Could not swap a release file"
2038 # test needs a running copytool
2041 local f=$DIR/$tdir/test_mtime
2043 # Create a file and check its states
2044 local fid=$(create_small_file $f)
2045 check_hsm_flags $f "0x00000000"
2047 $LFS hsm_archive $f || error "could not archive file"
2048 wait_request_state $fid ARCHIVE SUCCEED
2050 # Set modification time in the past
2051 touch -m -a -d @978261179 $f
2053 # Release and check states
2054 $LFS hsm_release $f || error "could not release file"
2055 check_hsm_flags $f "0x0000000d"
2057 local MTIME=$(stat -c "%Y" $f)
2058 local ATIME=$(stat -c "%X" $f)
2059 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2060 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2062 run_test 23 "Release does not change a/mtime (utime)"
2065 local file=$DIR/$tdir/$tfile
2074 # test needs a running copytool
2077 fid=$(create_small_file $file)
2079 # Create a file and check its states
2080 check_hsm_flags $file "0x00000000"
2082 # Ensure atime is less than mtime and ctime.
2086 atime0=$(stat -c "%X" $file)
2087 mtime0=$(stat -c "%Y" $file)
2088 ctime0=$(stat -c "%Z" $file)
2090 [ $atime0 -lt $mtime0 ] ||
2091 error "atime $atime0 is not less than mtime $mtime0"
2093 [ $atime0 -lt $ctime0 ] ||
2094 error "atime $atime0 is not less than ctime $ctime0"
2096 # Archive should not change any timestamps.
2097 $LFS hsm_archive $file || error "cannot archive '$file'"
2098 wait_request_state $fid ARCHIVE SUCCEED
2100 atime1=$(stat -c "%X" $file)
2101 mtime1=$(stat -c "%Y" $file)
2102 ctime1=$(stat -c "%Z" $file)
2104 [ $atime0 -eq $atime1 ] ||
2105 error "archive changed atime from $atime0 to $atime1"
2107 [ $mtime0 -eq $mtime1 ] ||
2108 error "archive changed mtime from $mtime0 to $mtime1"
2110 [ $ctime0 -eq $ctime1 ] ||
2111 error "archive changed ctime from $ctime0 to $ctime1"
2113 # Release should not change any timestamps.
2114 $LFS hsm_release $file || error "cannot release '$file'"
2115 check_hsm_flags $file "0x0000000d"
2117 atime1=$(stat -c "%X" $file)
2118 mtime1=$(stat -c "%Y" $file)
2119 ctime1=$(stat -c "%Z" $file)
2121 [ $atime0 -eq $atime1 ] ||
2122 error "release changed atime from $atime0 to $atime1"
2124 [ $mtime0 -eq $mtime1 ] ||
2125 error "release changed mtime from $mtime0 to $mtime1"
2127 [ $ctime0 -eq $ctime1 ] ||
2128 error "release changed ctime from $ctime0 to $ctime1"
2130 # Restore should not change any timestamps.
2131 $LFS hsm_restore $file
2132 wait_request_state $fid RESTORE SUCCEED
2134 atime1=$(stat -c "%X" $file)
2135 mtime1=$(stat -c "%Y" $file)
2136 ctime1=$(stat -c "%Z" $file)
2138 [ $atime0 -eq $atime1 ] ||
2139 error "restore changed atime from $atime0 to $atime1"
2141 [ $mtime0 -eq $mtime1 ] ||
2142 error "restore changed mtime from $mtime0 to $mtime1"
2144 [ $ctime0 -eq $ctime1 ] ||
2145 error "restore changed ctime from $ctime0 to $ctime1"
2148 wait_copytools || error "Copytools failed to stop"
2150 # Once more, after unmount and mount.
2151 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2152 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2154 atime1=$(stat -c "%X" $file)
2155 mtime1=$(stat -c "%Y" $file)
2156 ctime1=$(stat -c "%Z" $file)
2158 [ $atime0 -eq $atime1 ] ||
2159 error "remount changed atime from $atime0 to $atime1"
2161 [ $mtime0 -eq $mtime1 ] ||
2162 error "remount changed mtime from $mtime0 to $mtime1"
2164 [ $ctime0 -eq $ctime1 ] ||
2165 error "remount changed ctime from $ctime0 to $ctime1"
2167 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2170 local file=$DIR/$tdir/$tfile
2176 # Test needs a running copytool.
2179 # Check that root can do HSM actions on a regular user's file.
2180 fid=$(create_small_file $file)
2181 sum0=$(md5sum $file)
2183 chown $RUNAS_ID:$RUNAS_GID $file ||
2184 error "cannot chown '$file' to '$RUNAS_ID'"
2186 chmod ugo-w $DIR/$tdir ||
2187 error "cannot chmod '$DIR/$tdir'"
2189 $LFS hsm_archive $file
2190 wait_request_state $fid ARCHIVE SUCCEED
2192 $LFS hsm_release $file
2193 check_hsm_flags $file "0x0000000d"
2195 $LFS hsm_restore $file
2196 wait_request_state $fid RESTORE SUCCEED
2198 # Check that ordinary user can get HSM state.
2199 $RUNAS $LFS hsm_state $file ||
2200 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2202 $LFS hsm_release $file
2203 check_hsm_flags $file "0x0000000d"
2205 # Check that ordinary user can accessed released file.
2206 sum1=$($RUNAS md5sum $file) ||
2207 error "user '$RUNAS_ID' cannot read '$file'"
2209 [ "$sum0" == "$sum1" ] ||
2210 error "md5sum mismatch for '$file'"
2212 run_test 24b "root can archive, release, and restore user files"
2215 local file=$DIR/$tdir/$tfile
2216 local action=archive
2221 # test needs a running copytool
2226 # Save the default masks and check that cleanup_24c will
2227 # restore the request masks correctly.
2228 user_save=$(get_hsm_param user_request_mask)
2229 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2230 group_save=$(get_hsm_param group_request_mask)
2231 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2232 other_save=$(get_hsm_param other_request_mask)
2233 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2235 [ "$user_save" == RESTORE ] ||
2236 error "user_request_mask is '$user_save' expected 'RESTORE'"
2237 [ "$group_save" == RESTORE ] ||
2238 error "group_request_mask is '$group_save' expected 'RESTORE'"
2239 [ "$other_save" == RESTORE ] ||
2240 error "other_request_mask is '$other_save' expected 'RESTORE'"
2243 create_small_file $file
2244 chown $RUNAS_ID:$GROUP $file ||
2245 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2247 $RUNAS $LFS hsm_$action $file &&
2248 error "$action by user should fail"
2250 set_hsm_param user_request_mask $action
2251 $RUNAS $LFS hsm_$action $file ||
2252 error "$action by user should succeed"
2255 create_small_file $file
2256 chown nobody:$RUNAS_GID $file ||
2257 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2259 $RUNAS $LFS hsm_$action $file &&
2260 error "$action by group should fail"
2262 set_hsm_param group_request_mask $action
2263 $RUNAS $LFS hsm_$action $file ||
2264 error "$action by group should succeed"
2267 create_small_file $file
2268 chown nobody:$GROUP $file ||
2269 error "cannot chown '$file' to 'nobody:$GROUP'"
2271 $RUNAS $LFS hsm_$action $file &&
2272 error "$action by other should fail"
2274 set_hsm_param other_request_mask $action
2275 $RUNAS $LFS hsm_$action $file ||
2276 error "$action by other should succeed"
2278 run_test 24c "check that user,group,other request masks work"
2281 local file1=$DIR/$tdir/$tfile
2282 local file2=$DIR2/$tdir/$tfile
2286 fid1=$(create_small_file $file1)
2289 $LFS getstripe $file1
2291 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2292 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2293 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2295 copytool setup -m "$MOUNT3"
2297 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2298 mount -o remount,ro $MOUNT2
2300 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2302 fid2=$(path2fid $file2)
2303 [ "$fid1" == "$fid2" ] ||
2304 error "FID mismatch '$fid1' != '$fid2'"
2306 $LFS hsm_archive $file2 &&
2307 error "archive should fail on read-only mount"
2308 check_hsm_flags $file1 "0x00000000"
2310 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2311 wait_request_state $fid1 ARCHIVE SUCCEED
2313 $LFS hsm_release $file1
2314 $LFS hsm_restore $file2
2315 wait_request_state $fid1 RESTORE SUCCEED
2317 $LFS hsm_release $file1 || error "cannot release '$file1'"
2318 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2320 $LFS hsm_release $file2 &&
2321 error "release should fail on read-only mount"
2325 run_test 24d "check that read-only mounts are respected"
2330 local f=$DIR/$tdir/$tfile
2333 fid=$(create_small_file $f) || error "cannot create $f"
2334 $LFS hsm_archive $f || error "cannot archive $f"
2335 wait_request_state $fid ARCHIVE SUCCEED
2336 $LFS hsm_release $f || error "cannot release $f"
2337 while ! $LFS hsm_state $f | grep released; do
2341 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2343 run_test 24e "tar succeeds on HSM released files" # LU-6213
2346 # test needs a running copytool
2349 mkdir -p $DIR/$tdir/d1
2350 local f=$DIR/$tdir/$tfile
2351 local fid=$(copy_file /etc/hosts $f)
2354 $LFS hsm_archive $f ||
2355 error "hsm_archive failed"
2356 wait_request_state $fid ARCHIVE SUCCEED
2357 $LFS hsm_release $f || error "cannot release $f"
2358 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2361 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2362 error "Can not recover the tar contents"
2364 echo "Sum0 = $sum0, sum1 = $sum1"
2365 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2367 run_test 24f "root can archive, release, and restore tar files"
2370 # test needs a running copytool
2374 copy2archive /etc/hosts $tdir/$tfile
2376 local f=$DIR/$tdir/$tfile
2378 import_file $tdir/$tfile $f
2380 $LFS hsm_set --lost $f
2385 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2389 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2390 " (Operation not permitted)"
2393 # test needs a running copytool
2398 local f=$DIR/$tdir/$tfile
2399 local fid=$(copy_file /etc/passwd $f)
2401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2402 wait_request_state $fid ARCHIVE SUCCEED
2405 $LFS hsm_set --lost $f
2409 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2411 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2412 " (Operation not permitted)"
2415 # test needs a running copytool
2418 local f=$DIR/$tdir/$tfile
2420 fid=$(make_custom_file_for_progress $f 39 1000000)
2421 [ $? != 0 ] && skip "not enough free space" && return
2423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2424 wait_request_state $fid ARCHIVE SUCCEED
2427 wait_request_state $fid REMOVE SUCCEED
2429 check_hsm_flags $f "0x00000000"
2431 run_test 26 "Remove the archive of a valid file"
2434 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2435 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2437 # test needs a running copytool
2441 local f=$DIR/$tdir/$tfile
2442 local fid=$(copy_file /etc/passwd $f)
2444 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2445 wait_request_state $fid ARCHIVE SUCCEED
2447 local f2=$DIR/$tdir/${tfile}_2
2448 local fid2=$(copy_file /etc/passwd $f2)
2450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2451 wait_request_state $fid2 ARCHIVE SUCCEED
2453 local f3=$DIR/$tdir/${tfile}_3
2454 local fid3=$(copy_file /etc/passwd $f3)
2456 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2457 wait_request_state $fid3 ARCHIVE SUCCEED
2459 # set a long grace_delay vs short loop_period
2460 local orig_loop_period=$(get_hsm_param loop_period)
2461 local orig_grace_delay=$(get_hsm_param grace_delay)
2462 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2463 set_hsm_param loop_period 10
2464 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2465 set_hsm_param grace_delay 100
2469 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2470 set_hsm_param remove_archive_on_last_unlink 1
2472 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2477 set_hsm_param remove_archive_on_last_unlink 0
2479 wait_request_state $fid2 REMOVE SUCCEED
2481 assert_request_count $fid REMOVE 0 \
2482 "Unexpected archived data remove request for $f"
2483 assert_request_count $fid3 REMOVE 0 \
2484 "Unexpected archived data remove request for $f3"
2486 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2489 # test needs a running copytool
2493 local f=$DIR/$tdir/$tfile
2494 local fid=$(copy_file /etc/passwd $f)
2496 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2497 wait_request_state $fid ARCHIVE SUCCEED
2499 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2500 set_hsm_param remove_archive_on_last_unlink 1
2503 cdt_check_state stopped
2507 set_hsm_param remove_archive_on_last_unlink 0
2509 wait_request_state $fid REMOVE WAITING
2513 # copytool must re-register
2515 wait_copytools || error "copytool failed to stop"
2518 wait_request_state $fid REMOVE SUCCEED
2520 run_test 26b "RAoLU policy when CDT off"
2523 # test needs a running copytool
2527 local f=$DIR/$tdir/$tfile
2528 local fid=$(copy_file /etc/passwd $f)
2530 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2531 wait_request_state $fid ARCHIVE SUCCEED
2533 local f2=$DIR/$tdir/${tfile}_2
2534 local fid2=$(copy_file /etc/passwd $f2)
2536 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2537 wait_request_state $fid2 ARCHIVE SUCCEED
2539 # set a long grace_delay vs short loop_period
2540 local orig_loop_period=$(get_hsm_param loop_period)
2541 local orig_grace_delay=$(get_hsm_param grace_delay)
2542 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2543 set_hsm_param loop_period 10
2544 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2545 set_hsm_param grace_delay 100
2547 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2548 set_hsm_param remove_archive_on_last_unlink 1
2550 multiop_bg_pause $f O_c || error "open $f failed"
2556 wait_request_state $fid2 REMOVE SUCCEED
2557 assert_request_count $fid REMOVE 0 \
2558 "Unexpected archived data remove request for $f"
2560 kill -USR1 $pid || error "multiop early exit"
2561 # should reach autotest timeout if multiop fails to trap
2562 # signal, close file, and exit ...
2563 wait $pid || error "wait PID $PID failed"
2565 set_hsm_param remove_archive_on_last_unlink 0
2567 wait_request_state $fid REMOVE SUCCEED
2569 run_test 26c "RAoLU effective when file closed"
2572 # test needs a running copytool
2576 local f=$DIR/$tdir/$tfile
2577 local fid=$(create_small_file $f)
2579 $LFS hsm_archive $f || error "could not archive file"
2580 wait_request_state $fid ARCHIVE SUCCEED
2582 # set a long grace_delay vs short loop_period
2583 local orig_loop_period=$(get_hsm_param loop_period)
2584 local orig_grace_delay=$(get_hsm_param grace_delay)
2585 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2586 set_hsm_param loop_period 10
2587 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2588 set_hsm_param grace_delay 100
2590 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2591 set_hsm_param remove_archive_on_last_unlink 1
2593 multiop_bg_pause $f O_c || error "multiop failed"
2600 set_hsm_param remove_archive_on_last_unlink 0
2602 wait_request_state $fid REMOVE SUCCEED
2604 client_up || client_up || true
2606 kill -USR1 $MULTIPID
2607 wait $MULTIPID || error "multiop close failed"
2609 run_test 26d "RAoLU when Client eviction"
2612 # test needs a running copytool
2615 create_archive_file $tdir/$tfile
2616 local f=$DIR/$tdir/$tfile
2617 import_file $tdir/$tfile $f
2618 local fid=$(path2fid $f)
2622 [[ $? != 0 ]] || error "Remove of a released file should fail"
2626 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2629 # test needs a running copytool
2632 local f=$DIR/$tdir/$tfile
2634 fid=$(make_custom_file_for_progress $f 39 1000000)
2635 [ $? != 0 ] && skip "not enough free space" && return
2637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2638 wait_request_state $fid ARCHIVE SUCCEED
2643 [[ $? != 0 ]] || error "Remove of a released file should fail"
2645 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2648 # test needs a running copytool
2651 local f=$DIR/$tdir/$tfile
2653 fid=$(make_custom_file_for_progress $f 39 1000000)
2654 [ $? != 0 ] && skip "not enough free space" && return
2656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2657 wait_request_state $fid ARCHIVE SUCCEED
2666 wait_request_state $fid REMOVE SUCCEED
2668 run_test 28 "Concurrent archive/file remove"
2671 # Tests --mntpath and --archive options
2674 copytool setup -m "$MOUNT" -a $archive_id
2676 # Bad archive number
2677 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2678 grep "Invalid argument" ||
2679 error "unexpected hsm_remove failure (1)"
2681 # mntpath is present but file is given
2682 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2683 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2684 error "unexpected hsm_remove failure (2)"
2686 run_test 29a "Tests --mntpath and --archive options"
2689 # test needs a running copytool
2692 local f=$DIR/$tdir/$tfile
2693 local fid=$(create_small_file $f)
2695 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2696 wait_request_state $fid ARCHIVE SUCCEED
2700 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2701 wait_request_state $fid REMOVE SUCCEED
2703 run_test 29b "Archive/delete/remove by FID from the archive."
2706 # test needs a running copytool
2709 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2710 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2711 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2714 wait_request_state $fid1 ARCHIVE SUCCEED
2715 wait_request_state $fid2 ARCHIVE SUCCEED
2716 wait_request_state $fid3 ARCHIVE SUCCEED
2718 rm -f $DIR/$tdir/$tfile-[1-3]
2720 echo $fid1 > $DIR/$tdir/list
2721 echo $fid2 >> $DIR/$tdir/list
2722 echo $fid3 >> $DIR/$tdir/list
2724 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2725 --filelist $DIR/$tdir/list
2726 wait_request_state $fid1 REMOVE SUCCEED
2727 wait_request_state $fid2 REMOVE SUCCEED
2728 wait_request_state $fid3 REMOVE SUCCEED
2730 run_test 29c "Archive/delete/remove by FID, using a file list."
2733 # test needs more than one CT
2734 needclients 3 || return 0
2740 # start all of the copytools
2741 for n in $(seq $AGTCOUNT); do
2742 copytool setup -f agt$n -a $n
2746 file=$DIR/$tdir/$tfile
2747 fid=$(create_small_file $file)
2749 $LFS hsm_archive $file
2750 wait_request_state $fid ARCHIVE SUCCEED
2751 check_hsm_flags $file "0x00000009"
2755 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2756 error "cannot hsm_remove '$fid'"
2758 # give time for CDT to handle remove request and create broadcasted
2761 # remove request has been broadcasted ?
2762 local cnt=$(get_request_count $fid REMOVE)
2763 # broadcasted requests + original
2764 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2765 error "remove not broadcasted to all CTs"
2767 # give time for CDT and CTs to handle broadcasted
2768 wait_for_loop_period
2770 # each agent serves one different archive_id, so broadcasted
2771 # hsm_remove request should only succeed once and fail at all others
2775 for n in $(seq $AGTCOUNT); do
2776 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2777 $HSM_PARAM.actions | awk \
2778 '/'$fid'.*action=REMOVE archive#='$n'/ \
2779 {print \\\$13}' | cut -f2 -d=")
2780 if [[ "$res" == "SUCCEED" ]]; then
2782 elif [[ "$res" == "FAILED" ]]; then
2787 [[ $scnt -eq 1 ]] ||
2788 error "one and only CT should have removed successfully"
2790 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2791 error "all but one CT should have failed to remove"
2793 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2794 "request to be sent once for each registered archive_id"
2797 # restore at exec cannot work on agent node (because of Linux kernel
2798 # protection of executables)
2799 needclients 2 || return 0
2801 # test needs a running copytool
2805 copy2archive /bin/true $tdir/$tfile
2807 local f=$DIR/$tdir/true
2808 import_file $tdir/$tfile $f
2810 local fid=$(path2fid $f)
2812 # set no retry action mode
2818 # remove no try action mode
2822 [[ $st == 0 ]] || error "Failed to exec a released file"
2826 run_test 30a "Restore at exec (import case)"
2829 # restore at exec cannot work on agent node (because of Linux kernel
2830 # protection of executables)
2831 needclients 2 || return 0
2833 # test needs a running copytool
2837 local f=$DIR/$tdir/true
2838 local fid=$(copy_file /bin/true $f)
2840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2841 wait_request_state $fid ARCHIVE SUCCEED
2845 stack_trap cdt_clear_no_retry EXIT
2846 # set no retry action mode
2854 [[ $st == 0 ]] || error "Failed to exec a released file"
2856 run_test 30b "Restore at exec (release case)"
2859 needclients 2 || return 0
2861 # test needs a running copytool
2865 local f=$DIR/$tdir/SLEEP
2866 local slp_sum1=$(md5sum /bin/sleep)
2867 local fid=$(copy_file /bin/sleep $f)
2869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2870 wait_request_state $fid ARCHIVE SUCCEED
2872 check_hsm_flags $f "0x0000000d"
2874 stack_trap cdt_clear_no_retry EXIT
2875 # set no retry action mode
2878 do_node $CLIENT2 "$f 10" &
2882 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2884 [[ $? == 0 ]] || error "Execution failed during run"
2886 if [[ $? != 0 ]]; then
2887 local slp_sum2=$(md5sum /bin/sleep)
2888 # in case sleep file is modified during the test
2889 [[ $slp_sum1 == $slp_sum2 ]] &&
2890 error "Binary overwritten during exec"
2893 check_hsm_flags $f "0x00000009"
2895 run_test 30c "Update during exec of released file must fail"
2897 restore_and_check_size() {
2900 local s=$(stat -c "%s" $f)
2902 local st=$(get_hsm_flags $f)
2906 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2908 n=$(stat -c "%s" $f)
2909 # we echo in both cases to show stat is not hang
2910 if [[ $n != $s ]]; then
2911 echo "size seen is $n != $s"
2914 echo "size seen is right: $n == $s"
2918 st=$(get_hsm_flags $f)
2920 if [[ "$st" = "0x00000009" ]]; then
2923 echo " restore is too long"
2924 wait_request_state $fid RESTORE SUCCEED
2930 # test needs a running copytool
2933 create_archive_file $tdir/$tfile
2934 local f=$DIR/$tdir/$tfile
2935 import_file $tdir/$tfile $f
2936 local fid=$($LFS path2fid $f)
2937 HSM_ARCHIVE_PURGE=false copytool_setup
2939 restore_and_check_size $f $fid
2942 [[ $err -eq 0 ]] || error "File size changed during restore"
2946 run_test 31a "Import a large file and check size during restore"
2950 # test needs a running copytool
2953 local f=$DIR/$tdir/$tfile
2955 fid=$(make_custom_file_for_progress $f 39 1000000)
2956 [ $? != 0 ] && skip "not enough free space" && return
2958 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2959 wait_request_state $fid ARCHIVE SUCCEED
2962 restore_and_check_size $f $fid
2965 [[ $err -eq 0 ]] || error "File size changed during restore"
2967 run_test 31b "Restore a large unaligned file and check size during restore"
2970 # test needs a running copytool
2973 local f=$DIR/$tdir/$tfile
2975 fid=$(make_custom_file_for_progress $f 33 1048576)
2976 [ $? != 0 ] && skip "not enough free space" && return
2978 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2979 wait_request_state $fid ARCHIVE SUCCEED
2982 restore_and_check_size $f $fid
2985 [[ $err -eq 0 ]] || error "File size changed during restore"
2987 run_test 31c "Restore a large aligned file and check size during restore"
2990 # test needs a running copytool
2993 local f=$DIR/$tdir/$tfile
2995 fid=$(make_custom_file_for_progress $f 39 1000000)
2996 [ $? != 0 ] && skip "not enough free space" && return
2998 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2999 wait_request_state $fid ARCHIVE SUCCEED
3002 # to be sure wait_all_done will not be mislead by previous tests
3005 wait_for_grace_delay
3006 # Also raise grace_delay significantly so the Canceled
3007 # Restore action will stay enough long avail.
3008 local old_grace=$(get_hsm_param grace_delay)
3009 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3010 set_hsm_param grace_delay 100
3012 md5sum $f >/dev/null &
3014 wait_request_state $fid RESTORE STARTED
3019 # Check restore trigger process was killed
3020 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3024 # instead of waiting+checking both Restore and Cancel ops
3025 # sequentially, wait for both to be finished and then check
3027 wait_all_done 100 $fid
3028 local rstate=$(get_request_state $fid RESTORE)
3029 local cstate=$(get_request_state $fid CANCEL)
3031 if [[ "$rstate" == "CANCELED" ]] ; then
3032 [[ "$cstate" == "SUCCEED" ]] ||
3033 error "Restore state is CANCELED and Cancel state " \
3034 "is not SUCCEED but $cstate"
3035 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3036 elif [[ "$rstate" == "SUCCEED" ]] ; then
3037 [[ "$cstate" == "FAILED" ]] ||
3038 error "Restore state is SUCCEED and Cancel state " \
3039 "is not FAILED but $cstate"
3040 echo "Restore state is SUCCEED, Cancel state is FAILED"
3042 error "Restore state is $rstate and Cancel state is $cstate"
3046 error "Cannot kill process waiting for restore ($killed)"
3048 run_test 33 "Kill a restore waiting process"
3051 # test needs a running copytool
3054 local f=$DIR/$tdir/$tfile
3056 fid=$(make_custom_file_for_progress $f 39 1000000)
3057 [ $? != 0 ] && skip "not enough free space" && return
3059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3060 wait_request_state $fid ARCHIVE SUCCEED
3063 md5sum $f >/dev/null &
3065 wait_request_state $fid RESTORE STARTED
3067 rm $f || error "rm $f failed"
3068 # rm must not block during restore
3069 wait_request_state $fid RESTORE STARTED
3071 wait_request_state $fid RESTORE SUCCEED
3072 # check md5sum pgm finished
3073 local there=$(ps -o pid,comm hp $pid >/dev/null)
3074 [[ -z $there ]] || error "Restore initiator does not exit"
3076 wait $pid || error "Restore initiator failed with $?"
3078 run_test 34 "Remove file during restore"
3081 # test needs a running copytool
3084 local f=$DIR/$tdir/$tfile
3085 local f1=$DIR/$tdir/$tfile-1
3087 fid=$(make_custom_file_for_progress $f 39 1000000)
3088 [ $? != 0 ] && skip "not enough free space" && return
3090 local fid1=$(copy_file /etc/passwd $f1)
3091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3092 wait_request_state $fid ARCHIVE SUCCEED
3095 md5sum $f >/dev/null &
3097 wait_request_state $fid RESTORE STARTED
3099 mv $f1 $f || error "mv $f1 $f failed"
3100 # mv must not block during restore
3101 wait_request_state $fid RESTORE STARTED
3103 wait_request_state $fid RESTORE SUCCEED
3104 # check md5sum pgm finished
3105 local there=$(ps -o pid,comm hp $pid >/dev/null)
3106 [[ -z $there ]] || error "Restore initiator does not exit"
3108 wait $pid || error "Restore initiator failed with $?"
3111 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3113 run_test 35 "Overwrite file during restore"
3116 # test needs a running copytool
3119 local f=$DIR/$tdir/$tfile
3121 fid=$(make_custom_file_for_progress $f 39 1000000)
3122 [ $? != 0 ] && skip "not enough free space" && return
3124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3125 wait_request_state $fid ARCHIVE SUCCEED
3128 md5sum $f >/dev/null &
3130 wait_request_state $fid RESTORE STARTED
3133 # rm must not block during restore
3134 wait_request_state $fid RESTORE STARTED
3136 wait_request_state $fid RESTORE SUCCEED
3137 # check md5sum pgm finished
3138 local there=$(ps -o pid,comm hp $pid >/dev/null)
3140 error "Restore initiator does not exit"
3142 wait $pid || error "Restore initiator failed with $?"
3144 run_test 36 "Move file during restore"
3147 # LU-5683: check that an archived dirty file can be rearchived.
3150 local f=$DIR/$tdir/$tfile
3153 fid=$(create_small_file $f) || error "cannot create small file"
3155 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3156 wait_request_state $fid ARCHIVE SUCCEED
3157 $LFS hsm_release $f || error "cannot release $f"
3159 # Allow previous archive request to expire from the actions log.
3160 wait_for_grace_delay
3163 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3166 wait_request_state $fid ARCHIVE SUCCEED
3168 run_test 37 "re-archive a dirty file"
3175 for n in $(seq 1 $count); do
3176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3178 echo "$count archive requests submitted"
3182 local stream_count=4
3183 local file_count=100
3185 local f=$DIR/$tdir/$tfile
3189 local max_requests=$(get_hsm_param max_requests)
3191 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3192 # Increase the number of HSM request that can be performed in
3193 # parallel. With the coordinator running once per second, this
3194 # also limits the number of requests per seconds that can be
3195 # performed, so we pick a decent number. But we also need to keep
3196 # that number low because the copytool has no rate limit and will
3197 # fail some requests if if gets too many at once.
3198 set_hsm_param max_requests 300
3200 for i in $(seq 1 $file_count); do
3201 for p in $(seq 1 $stream_count); do
3202 fid=$(copy_file /etc/hosts $f.$p.$i)
3208 # to be sure wait_all_done will not be mislead by previous tests
3210 wait_for_grace_delay
3212 # start archive streams in background (archive files in parallel)
3213 for p in $(seq 1 $stream_count); do
3214 multi_archive $f.$p $file_count &
3217 echo -n "Wait for all requests being enqueued..."
3222 run_test 40 "Parallel archive requests"
3225 # test needs a running copytool
3229 local f=$DIR/$tdir/$tfile
3230 local fid=$(create_small_file $f)
3232 $LFS hsm_archive $f || error "could not archive file"
3233 wait_request_state $fid ARCHIVE SUCCEED
3234 check_hsm_flags $f "0x00000009"
3236 multiop_bg_pause $f O_c || error "multiop failed"
3240 client_up || client_up || true
3242 kill -USR1 $MULTIPID
3243 wait $MULTIPID || error "multiop close failed"
3245 check_hsm_flags $f "0x0000000b"
3247 run_test 52 "Opened for write file on an evicted client should be set dirty"
3250 # test needs a running copytool
3254 local f=$DIR/$tdir/$tfile
3255 local fid=$(create_small_file $f)
3257 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3258 error "could not archive file"
3259 wait_request_state $fid ARCHIVE SUCCEED
3260 check_hsm_flags $f "0x00000009"
3262 multiop_bg_pause $f o_c || error "multiop failed"
3266 client_up || client_up || true
3268 kill -USR1 $MULTIPID
3269 wait $MULTIPID || error "multiop close failed"
3271 check_hsm_flags $f "0x00000009"
3273 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3276 # test needs a running copytool
3279 local f=$DIR/$tdir/$tfile
3280 local fid=$(make_custom_file_for_progress $f 39 1000000)
3282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3283 error "could not archive file"
3284 wait_request_state $fid ARCHIVE STARTED
3286 check_hsm_flags $f "0x00000001"
3288 stack_trap "cdt_clear_no_retry" EXIT
3289 # Avoid coordinator resending this request as soon it has failed.
3294 wait_request_state $fid ARCHIVE FAILED
3296 check_hsm_flags $f "0x00000003"
3298 run_test 54 "Write during an archive cancels it"
3301 # test needs a running copytool
3304 local f=$DIR/$tdir/$tfile
3305 local fid=$(make_custom_file_for_progress $f 39 1000000)
3307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3308 error "could not archive file"
3309 wait_request_state $fid ARCHIVE STARTED
3311 check_hsm_flags $f "0x00000001"
3313 stack_trap "cdt_clear_no_retry" EXIT
3314 # Avoid coordinator resending this request as soon it has failed.
3317 $TRUNCATE $f 1024 || error "truncate failed"
3319 wait_request_state $fid ARCHIVE FAILED
3321 check_hsm_flags $f "0x00000003"
3323 run_test 55 "Truncate during an archive cancels it"
3326 # test needs a running copytool
3329 local f=$DIR/$tdir/$tfile
3331 fid=$(make_custom_file_for_progress $f 39 1000000)
3332 [ $? != 0 ] && skip "not enough free space" && return
3334 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3335 error "could not archive file"
3336 wait_request_state $fid ARCHIVE STARTED
3338 check_hsm_flags $f "0x00000001"
3340 # Change metadata and sync to be sure we are not changing only
3345 wait_request_state $fid ARCHIVE SUCCEED
3347 check_hsm_flags $f "0x00000009"
3349 run_test 56 "Setattr during an archive is ok"
3352 # Need one client for I/O, one for request
3353 needclients 2 || return 0
3355 # test needs a running copytool
3359 local f=$DIR/$tdir/test_archive_remote
3360 # Create a file on a remote node
3361 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3362 "count=2 conv=fsync"
3365 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3366 error "hsm_archive failed"
3367 local fid=$(path2fid $f)
3368 wait_request_state $fid ARCHIVE SUCCEED
3370 # Release and implicit restore it
3371 do_node $CLIENT2 "$LFS hsm_release $f" ||
3372 error "hsm_release failed"
3373 do_node $CLIENT2 "md5sum $f" ||
3374 error "hsm_restore failed"
3376 wait_request_state $fid RESTORE SUCCEED
3378 run_test 57 "Archive a file with dirty cache on another node"
3380 truncate_released_file() {
3384 local sz=$(stat -c %s $src_file)
3385 local f=$DIR/$tdir/$tfile
3386 local fid=$(copy_file $1 $f)
3390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3391 error "could not archive file"
3392 wait_request_state $fid ARCHIVE SUCCEED
3394 $LFS hsm_release $f || error "could not release file"
3396 $TRUNCATE $f $trunc_to || error "truncate failed"
3399 local sz1=$(stat -c %s $f)
3400 [[ $sz1 == $trunc_to ]] ||
3401 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3404 check_hsm_flags $f "0x0000000b"
3406 local state=$(get_request_state $fid RESTORE)
3407 [[ "$state" == "SUCCEED" ]] ||
3408 error "truncate $sz does not trig restore, state = $state"
3410 $TRUNCATE $ref $trunc_to
3411 cmp $ref $f || error "file data wrong after truncate"
3417 # test needs a running copytool
3422 local sz=$(stat -c %s /etc/passwd)
3424 echo "truncate up from $sz to $((sz*2))"
3425 truncate_released_file /etc/passwd $((sz*2))
3427 echo "truncate down from $sz to $((sz/2))"
3428 truncate_released_file /etc/passwd $((sz/2))
3430 echo "truncate to 0"
3431 truncate_released_file /etc/passwd 0
3433 run_test 58 "Truncate a released file will trigger restore"
3437 local server_version=$(lustre_version_code $SINGLEMDS)
3438 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3439 skip "Need MDS version at least 2.7.63" && return
3442 $MCREATE $DIR/$tfile || error "mcreate failed"
3443 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3444 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3445 fid=$(path2fid $DIR/$tfile)
3446 wait_request_state $fid ARCHIVE SUCCEED
3447 $LFS hsm_release $DIR/$tfile || error "release failed"
3449 run_test 59 "Release stripeless file with non-zero size"
3452 # This test validates the fix for LU-4512. Ensure that the -u
3453 # option changes the progress reporting interval from the
3454 # default (30 seconds) to the user-specified interval.
3456 local progress_timeout=$((interval * 4))
3458 copytool setup -b 1 --update-interval $interval
3460 local f=$DIR/$tdir/$tfile
3462 fid=$(make_custom_file_for_progress $f 10)
3463 [ $? != 0 ] && skip "not enough free space" && return
3466 local mdt=${MDT_PREFIX}${mdtidx}
3467 local mds=mds$((mdtidx + 1))
3469 # Wait for copytool to register
3470 wait_update_facet $mds \
3471 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3472 uuid 100 || error "coyptool failed to register with $mdt"
3474 local start_at=$(date +%s)
3475 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3476 error "could not archive file"
3478 local agent=$(facet_active_host $SINGLEAGT)
3479 local logfile=$(copytool_logfile $SINGLEAGT)
3481 wait_update $agent \
3482 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3483 error "copytool failed to start"
3485 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3486 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3492 echo -n "Expecting a progress update within $progress_timeout seconds... "
3494 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3495 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3496 echo "$RESULT bytes copied in $WAIT seconds."
3498 elif [ $WAIT -ge $progress_timeout ]; then
3499 error "Timed out waiting for progress update!"
3502 WAIT=$((WAIT + sleep))
3506 local finish_at=$(date +%s)
3507 local elapsed=$((finish_at - start_at))
3509 # Ensure that the progress update occurred within the expected window.
3510 if [ $elapsed -lt $((interval - 1)) ]; then
3511 error "Expected progress update after at least $interval seconds"
3514 echo "Wait for on going archive hsm action to complete"
3515 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3516 echo "File archiving not completed even after 10 secs"
3518 run_test 60 "Changing progress update interval from default"
3521 # test needs a running copytool
3525 local f=$DIR/$tdir/$tfile
3526 local fid=$(copy_file /etc/passwd $f)
3528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3531 wait_request_state $fid ARCHIVE FAILED
3533 run_test 61 "Waiting archive of a removed file should fail"
3536 # test needs a new running copytool
3537 stack_trap copytool_monitor_cleanup EXIT
3538 copytool_monitor_setup
3539 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3541 # Wait for the copytool to register.
3542 wait_update --verbose $(facet_active_host mds1) \
3543 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3545 error "copytool failed to register with MDT0000"
3548 wait_copytools || error "Copytools failed to stop"
3550 local REGISTER_EVENT
3551 local UNREGISTER_EVENT
3552 while read event; do
3553 local parsed=$(parse_json_event "$event")
3554 if [ -z "$parsed" ]; then
3555 error "Copytool sent malformed event: $event"
3559 if [ $event_type == "REGISTER" ]; then
3560 REGISTER_EVENT=$event
3561 elif [ $event_type == "UNREGISTER" ]; then
3562 UNREGISTER_EVENT=$event
3564 done < <(echo $"$(get_copytool_event_log)")
3566 if [ -z "$REGISTER_EVENT" ]; then
3567 error "Copytool failed to send register event to FIFO"
3570 if [ -z "$UNREGISTER_EVENT" ]; then
3571 error "Copytool failed to send unregister event to FIFO"
3574 echo "Register/Unregister events look OK."
3576 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3579 # Bump progress interval for livelier events.
3582 # test needs a new running copytool
3583 stack_trap copytool_monitor_cleanup EXIT
3584 copytool_monitor_setup
3585 copytool setup --update-interval $interval --event-fifo \
3586 "$HSMTOOL_MONITOR_DIR/fifo"
3588 stack_trap "cdt_clear_no_retry" EXIT
3589 # Just start and stop the copytool to generate events.
3592 local f=$DIR/$tdir/$tfile
3594 fid=$(make_custom_file_for_progress $f 39 1000000)
3595 [ $? != 0 ] && skip "not enough free space" && return
3597 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3598 error "could not archive file"
3599 wait_request_state $fid ARCHIVE SUCCEED
3601 local expected_fields="event_time data_fid source_fid"
3602 expected_fields+=" total_bytes current_bytes"
3606 while read event; do
3607 # Make sure we're not getting anything from previous events.
3608 for field in $expected_fields; do
3612 local parsed=$(parse_json_event "$event")
3613 if [ -z "$parsed" ]; then
3614 error "Copytool sent malformed event: $event"
3618 if [ $event_type == "ARCHIVE_START" ]; then
3621 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3624 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3628 # Do some simple checking of the progress update events.
3629 for expected_field in $expected_fields; do
3630 if [ -z ${!expected_field+x} ]; then
3631 error "Missing $expected_field field in event"
3635 if [ $total_bytes -eq 0 ]; then
3636 error "Expected total_bytes to be > 0"
3639 # These should be identical throughout an archive
3641 if [ $source_fid != $data_fid ]; then
3642 error "Expected source_fid to equal data_fid"
3644 done < <(echo $"$(get_copytool_event_log)")
3646 if [ -z "$START_EVENT" ]; then
3647 error "Copytool failed to send archive start event to FIFO"
3650 if [ -z "$FINISH_EVENT" ]; then
3651 error "Copytool failed to send archive finish event to FIFO"
3654 echo "Archive events look OK."
3656 run_test 71 "Copytool logs JSON archive events to FIFO"
3659 # Bump progress interval for livelier events.
3662 # test needs a new running copytool
3664 copytool_monitor_setup
3665 HSMTOOL_UPDATE_INTERVAL=$interval \
3666 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3667 local test_file=$HSMTOOL_MONITOR_DIR/file
3669 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3671 do_facet $SINGLEAGT "$cmd" ||
3672 error "cannot create $test_file on $SINGLEAGT"
3673 copy2archive $test_file $tdir/$tfile
3676 local f=$DIR/$tdir/$tfile
3677 import_file $tdir/$tfile $f
3678 f=$DIR2/$tdir/$tfile
3679 echo "Verifying released state: "
3680 check_hsm_flags $f "0x0000000d"
3682 local fid=$(path2fid $f)
3684 wait_request_state $fid RESTORE SUCCEED
3686 local expected_fields="event_time data_fid source_fid"
3687 expected_fields+=" total_bytes current_bytes"
3691 while read event; do
3692 # Make sure we're not getting anything from previous events.
3693 for field in $expected_fields; do
3697 local parsed=$(parse_json_event "$event")
3698 if [ -z "$parsed" ]; then
3699 error "Copytool sent malformed event: $event"
3703 if [ $event_type == "RESTORE_START" ]; then
3705 if [ $source_fid != $data_fid ]; then
3706 error "source_fid should == data_fid at start"
3709 elif [ $event_type == "RESTORE_FINISH" ]; then
3711 if [ $source_fid != $data_fid ]; then
3712 error "source_fid should == data_fid at finish"
3715 elif [ $event_type != "RESTORE_RUNNING" ]; then
3719 # Do some simple checking of the progress update events.
3720 for expected_field in $expected_fields; do
3721 if [ -z ${!expected_field+x} ]; then
3722 error "Missing $expected_field field in event"
3726 if [ $total_bytes -eq 0 ]; then
3727 error "Expected total_bytes to be > 0"
3730 # When a restore starts out, the data fid is the same as the
3731 # source fid. After the restore has gotten going, we learn
3732 # the new data fid. Once the restore has finished, the source
3733 # fid is set to the new data fid.
3735 # We test this because some monitoring software may depend on
3736 # this behavior. If it changes, then the consumers of these
3737 # events may need to be modified.
3738 if [ $source_fid == $data_fid ]; then
3739 error "source_fid should != data_fid during restore"
3741 done < <(echo $"$(get_copytool_event_log)")
3743 if [ -z "$START_EVENT" ]; then
3744 error "Copytool failed to send restore start event to FIFO"
3747 if [ -z "$FINISH_EVENT" ]; then
3748 error "Copytool failed to send restore finish event to FIFO"
3751 echo "Restore events look OK."
3755 copytool_monitor_cleanup
3759 run_test 72 "Copytool logs JSON restore events to FIFO"
3762 file_count=51 # Max number of files constrained by LNET message size
3763 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3764 local f=$DIR/$tdir/$tfile
3765 local FILELIST=/tmp/filelist.txt
3769 for i in $(seq 1 $file_count); do
3770 fid=$(copy_file /etc/hosts $f.$i)
3771 echo $f.$i >> $FILELIST
3775 # to be sure wait_all_done will not be mislead by previous tests
3777 wait_for_grace_delay
3778 $LFS hsm_archive --filelist $FILELIST ||
3779 error "cannot archive a file list"
3781 $LFS hsm_release --filelist $FILELIST ||
3782 error "cannot release a file list"
3783 $LFS hsm_restore --filelist $FILELIST ||
3784 error "cannot restore a file list"
3787 run_test 90 "Archive/restore a file list"
3789 double_verify_reset_hsm_param() {
3791 echo "Testing $HSM_PARAM.$p"
3792 local val=$(get_hsm_param $p)
3794 local val2=$(($val * 2))
3795 set_hsm_param $p $val2
3796 val=$(get_hsm_param $p)
3797 [[ $val == $val2 ]] ||
3798 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3799 echo "Set $p to 0 must failed"
3803 set_hsm_param $p $save
3805 if [[ $rc == 0 ]]; then
3806 error "we must not be able to set $HSM_PARAM.$p to 0"
3811 double_verify_reset_hsm_param loop_period
3812 double_verify_reset_hsm_param grace_delay
3813 double_verify_reset_hsm_param active_request_timeout
3814 double_verify_reset_hsm_param max_requests
3815 double_verify_reset_hsm_param default_archive_id
3817 run_test 100 "Set coordinator /proc tunables"
3824 run_test 102 "Verify coordinator control"
3827 # test needs a running copytool
3834 for i in $(seq 1 20); do
3835 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3837 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3841 echo "Current requests"
3842 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3843 $HSM_PARAM.actions |\
3844 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3846 [[ -z "$res" ]] || error "Some request have not been canceled"
3848 run_test 103 "Purge all requests"
3853 local f=$DIR/$tdir/$tfile
3855 fid=$(make_custom_file_for_progress $f 39 1000000)
3856 [ $? != 0 ] && skip "not enough free space" && return
3858 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3859 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3860 $HSM_PARAM.actions |\
3861 grep $fid | cut -f16 -d=")
3863 [[ "$data1" == "$DATAHEX" ]] ||
3864 error "Data field in records is ($data1) and not ($DATAHEX)"
3869 wait_request_state $fid ARCHIVE SUCCEED
3871 run_test 104 "Copy tool data field"
3874 local max_requests=$(get_hsm_param max_requests)
3878 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3879 set_hsm_param max_requests 300
3882 for i in $(seq -w 1 10); do
3883 cp /etc/passwd $DIR/$tdir/$i
3884 $LFS hsm_archive $DIR/$tdir/$i
3886 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3887 $HSM_PARAM.actions |\
3888 grep WAITING | wc -l")
3892 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3893 $HSM_PARAM.actions |\
3894 grep WAITING | wc -l")
3897 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3898 error "Requests count after shutdown $reqcnt2 != "\
3899 "before shutdown $reqcnt1"
3901 run_test 105 "Restart of coordinator"
3904 # test needs a running copytool
3907 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3909 check_agent_registered $uuid
3911 search_copytools || error "No copytool found"
3914 wait_copytools || error "Copytool failed to stop"
3916 check_agent_unregistered $uuid
3919 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3920 check_agent_registered $uuid
3922 run_test 106 "Copytool register/unregister"
3925 # test needs a running copytool
3927 # create and archive file
3929 local f1=$DIR/$tdir/$tfile
3930 local fid=$(copy_file /etc/passwd $f1)
3931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3932 wait_request_state $fid ARCHIVE SUCCEED
3933 # shutdown and restart MDS
3935 # check the copytool still gets messages from MDT
3936 local f2=$DIR/$tdir/2
3937 local fid=$(copy_file /etc/passwd $f2)
3938 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3939 # main check of this sanity: this request MUST succeed
3940 wait_request_state $fid ARCHIVE SUCCEED
3942 run_test 107 "Copytool re-register after MDS restart"
3944 policy_set_and_test()
3948 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3949 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3950 [[ "$policy" == "$target" ]] ||
3951 error "Wrong policy after '$change': '$policy' != '$target'"
3955 # to force default policy setting if error
3956 CDT_POLICY_HAD_CHANGED=true
3958 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3959 local default="NonBlockingRestore [NoRetryAction]"
3960 [[ "$policy" == "$default" ]] ||
3961 error "default policy has changed,"\
3962 " '$policy' != '$default' update the test"
3963 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3964 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3965 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3966 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3967 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3968 # useless bacause we know but safer for futur changes to use real value
3969 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3970 echo "Next set_param must failed"
3971 policy_set_and_test "wrong" "$policy"
3974 echo "Back to default policy"
3975 cdt_set_sanity_policy
3977 run_test 109 "Policy display/change"
3980 # test needs a running copytool
3985 copy2archive /etc/passwd $tdir/$tfile
3987 local f=$DIR/$tdir/$tfile
3988 import_file $tdir/$tfile $f
3989 local fid=$(path2fid $f)
3991 cdt_set_non_blocking_restore
3996 wait_request_state $fid RESTORE SUCCEED
3997 cdt_clear_non_blocking_restore
4001 error "md5sum returns $st != 1, "\
4002 "should also perror ENODATA (No data available)"
4004 run_test 110a "Non blocking restore policy (import case)"
4007 # test needs a running copytool
4011 local f=$DIR/$tdir/$tfile
4012 local fid=$(copy_file /etc/passwd $f)
4013 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4014 wait_request_state $fid ARCHIVE SUCCEED
4017 cdt_set_non_blocking_restore
4022 wait_request_state $fid RESTORE SUCCEED
4023 cdt_clear_non_blocking_restore
4027 error "md5sum returns $st != 1, "\
4028 "should also perror ENODATA (No data available)"
4030 run_test 110b "Non blocking restore policy (release case)"
4033 # test needs a running copytool
4037 copy2archive /etc/passwd $tdir/$tfile
4039 local f=$DIR/$tdir/$tfile
4041 import_file $tdir/$tfile $f
4042 local fid=$(path2fid $f)
4046 copytool_remove_backend $fid
4049 wait_request_state $fid RESTORE FAILED
4056 [[ $st == 0 ]] || error "Restore does not failed"
4060 run_test 111a "No retry policy (import case), restore will error"\
4061 " (No such file or directory)"
4064 # test needs a running copytool
4068 local f=$DIR/$tdir/$tfile
4069 local fid=$(copy_file /etc/passwd $f)
4071 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4072 wait_request_state $fid ARCHIVE SUCCEED
4075 copytool_remove_backend $fid
4078 wait_request_state $fid RESTORE FAILED
4085 [[ $st == 0 ]] || error "Restore does not failed"
4089 run_test 111b "No retry policy (release case), restore will error"\
4090 " (No such file or directory)"
4093 # test needs a running copytool
4097 local f=$DIR/$tdir/$tfile
4098 local fid=$(copy_file /etc/passwd $f)
4100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4101 local l=$($LFS hsm_action $f)
4103 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4106 wait_request_state $fid ARCHIVE SUCCEED
4109 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4111 run_test 112 "State of recorded request"
4114 # test needs a running copytool
4117 local f=$DIR/$tdir/$tfile
4119 fid=$(make_custom_file_for_progress $f 103 1048576)
4120 [ $? != 0 ] && skip "not enough free space" && return
4122 # test with cdt on is made in test_221
4124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4125 # wait archive to register at CDT
4126 wait_request_state $fid ARCHIVE WAITING
4129 wait_request_state $fid ARCHIVE CANCELED
4130 wait_request_state $fid CANCEL SUCCEED
4132 run_test 200 "Register/Cancel archive"
4135 # test needs a running copytool
4138 local f=$DIR/$tdir/$tfile
4139 create_archive_file $tdir/$tfile
4140 import_file $tdir/$tfile $f
4141 local fid=$(path2fid $f)
4143 # test with cdt on is made in test_222
4146 # wait restore to register at CDT
4147 wait_request_state $fid RESTORE WAITING
4150 wait_request_state $fid RESTORE CANCELED
4151 wait_request_state $fid CANCEL SUCCEED
4155 run_test 201 "Register/Cancel restore"
4158 # test needs a running copytool
4161 local f=$DIR/$tdir/$tfile
4163 fid=$(make_custom_file_for_progress $f 39 1000000)
4164 [ $? != 0 ] && skip "not enough free space" && return
4166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4167 wait_request_state $fid ARCHIVE SUCCEED
4171 # wait remove to register at CDT
4172 wait_request_state $fid REMOVE WAITING
4175 wait_request_state $fid REMOVE CANCELED
4177 run_test 202 "Register/Cancel remove"
4180 # test needs a running copytool
4185 local f=$DIR/$tdir/$tfile
4186 local fid=$(copy_file /etc/passwd $f)
4190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4191 wait_request_state $fid ARCHIVE SUCCEED
4193 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4197 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4199 run_test 220 "Changelog for archive"
4202 # test needs a running copytool
4207 local f=$DIR/$tdir/$tfile
4208 local fid=$(copy_file /etc/passwd $f)
4212 # block copytool operations to allow for HSM request to be
4213 # submitted and file be unlinked (CDT will find object removed)
4216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4218 # wait request to reach CT
4219 wait_request_state $fid ARCHIVE STARTED
4225 wait_request_state $fid ARCHIVE FAILED
4227 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4232 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4234 run_test 220a "Changelog for failed archive"
4237 # test needs a running copytool
4240 local f=$DIR/$tdir/$tfile
4242 fid=$(make_custom_file_for_progress $f 103 1048576)
4243 [ $? != 0 ] && skip "not enough free space" && return
4247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4248 wait_request_state $fid ARCHIVE STARTED
4250 wait_request_state $fid ARCHIVE CANCELED
4251 wait_request_state $fid CANCEL SUCCEED
4253 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4256 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4258 run_test 221 "Changelog for archive canceled"
4261 # test needs a running copytool
4265 copy2archive /etc/passwd $tdir/$tfile
4267 local f=$DIR/$tdir/$tfile
4268 import_file $tdir/$tfile $f
4269 local fid=$(path2fid $f)
4274 wait_request_state $fid RESTORE SUCCEED
4276 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4279 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4283 run_test 222a "Changelog for explicit restore"
4286 # test needs a running copytool
4290 local f=$DIR/$tdir/$tfile
4291 local fid=$(copy_file /etc/passwd $f)
4294 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4295 wait_request_state $fid ARCHIVE SUCCEED
4300 wait_request_state $fid RESTORE SUCCEED
4302 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4305 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4307 run_test 222b "Changelog for implicit restore"
4310 # test needs a running copytool
4314 copy2archive /etc/passwd $tdir/$tfile
4316 local f=$DIR/$tdir/$tfile
4317 import_file $tdir/$tfile $f
4318 local fid=$(path2fid $f)
4322 # block copytool operations to allow for HSM request to be
4323 # submitted and file be unlinked (CDT will find object removed)
4328 # wait request to reach CT
4329 wait_request_state $fid RESTORE STARTED
4335 wait_request_state $fid RESTORE FAILED
4337 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4341 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4345 run_test 222c "Changelog for failed explicit restore"
4348 # test needs a running copytool
4352 local f=$DIR/$tdir/$tfile
4353 local fid=$(copy_file /etc/passwd $f)
4356 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4357 wait_request_state $fid ARCHIVE SUCCEED
4360 copytool_remove_backend $fid
4363 wait_request_state $fid RESTORE FAILED
4365 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4369 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4373 run_test 222d "Changelog for failed implicit restore"
4376 # test needs a running copytool
4379 local f=$DIR/$tdir/$tfile
4380 create_archive_file $tdir/$tfile
4384 import_file $tdir/$tfile $f
4385 local fid=$(path2fid $f)
4388 wait_request_state $fid RESTORE STARTED
4390 wait_request_state $fid RESTORE CANCELED
4391 wait_request_state $fid CANCEL SUCCEED
4393 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4396 [[ $flags == $target ]] ||
4397 error "Changelog flag is $flags not $target"
4401 run_test 223a "Changelog for restore canceled (import case)"
4404 # test needs a running copytool
4407 local f=$DIR/$tdir/$tfile
4409 fid=$(make_custom_file_for_progress $f 39 1000000)
4410 [ $? != 0 ] && skip "not enough free space" && return
4413 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4414 wait_request_state $fid ARCHIVE SUCCEED
4417 wait_request_state $fid RESTORE STARTED
4419 wait_request_state $fid RESTORE CANCELED
4420 wait_request_state $fid CANCEL SUCCEED
4422 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4425 [[ $flags == $target ]] ||
4426 error "Changelog flag is $flags not $target"
4430 run_test 223b "Changelog for restore canceled (release case)"
4433 # test needs a running copytool
4438 local f=$DIR/$tdir/$tfile
4439 local fid=$(copy_file /etc/passwd $f)
4442 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4443 wait_request_state $fid ARCHIVE SUCCEED
4446 wait_request_state $fid REMOVE SUCCEED
4448 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4451 [[ $flags == $target ]] ||
4452 error "Changelog flag is $flags not $target"
4454 run_test 224 "Changelog for remove"
4457 # test needs a running copytool
4462 local f=$DIR/$tdir/$tfile
4463 local fid=$(copy_file /etc/passwd $f)
4466 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4467 wait_request_state $fid ARCHIVE SUCCEED
4469 copytool_remove_backend $fid
4471 # block copytool operations to allow for HSM request to be
4472 # submitted and file be unlinked (CDT will find object removed)
4477 # wait for request to reach CT
4478 wait_request_state $fid REMOVE STARTED
4484 wait_request_state $fid REMOVE FAILED
4486 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4490 [[ $flags == $target ]] ||
4491 error "Changelog flag is $flags not $target"
4495 run_test 224a "Changelog for failed remove"
4498 # test needs a running copytool
4501 # test is not usable because remove request is too fast
4502 # so it is always finished before cancel can be done ...
4503 echo "Test disabled"
4507 local f=$DIR/$tdir/$tfile
4509 fid=$(make_custom_file_for_progress $f 39 1000000)
4510 [ $? != 0 ] && skip "not enough free space" && return
4513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4514 wait_request_state $fid ARCHIVE SUCCEED
4516 # if cdt is on, it can serve too quickly the request
4521 wait_request_state $fid REMOVE CANCELED
4522 wait_request_state $fid CANCEL SUCCEED
4524 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4525 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4526 tail -n 1 | awk '{print $5}')
4529 [[ $flags == $target ]] ||
4530 error "Changelog flag is $flags not $target"
4532 run_test 225 "Changelog for remove canceled"
4535 # test needs a running copytool
4540 local f1=$DIR/$tdir/$tfile-1
4541 local f2=$DIR/$tdir/$tfile-2
4542 local f3=$DIR/$tdir/$tfile-3
4543 local fid1=$(copy_file /etc/passwd $f1)
4544 local fid2=$(copy_file /etc/passwd $f2)
4545 copy_file /etc/passwd $f3
4548 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4549 wait_request_state $fid1 ARCHIVE SUCCEED
4551 $LFS hsm_archive $f2
4552 wait_request_state $fid2 ARCHIVE SUCCEED
4554 rm $f1 || error "rm $f1 failed"
4556 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4559 [[ $flags == $target ]] ||
4560 error "Changelog flag is $flags not $target"
4562 mv $f3 $f2 || error "mv $f3 $f2 failed"
4564 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4567 [[ $flags == $target ]] ||
4568 error "Changelog flag is $flags not $target"
4570 run_test 226 "changelog for last rm/mv with exiting archive"
4572 check_flags_changes() {
4580 $LFS hsm_set --$hsm_flag $f ||
4581 error "Cannot set $hsm_flag on $f"
4582 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4583 local seen=${#flags[*]}
4585 [[ $seen == $cnt ]] ||
4586 error "set $hsm_flag: Changelog events $seen != $cnt"
4587 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4588 error "set $hsm_flag: Changelog flags are "\
4589 "${flags[$((cnt - 1))]} not $target"
4591 $LFS hsm_clear --$hsm_flag $f ||
4592 error "Cannot clear $hsm_flag on $f"
4593 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4596 [[ $cnt == $seen ]] ||
4597 error "clear $hsm_flag: Changelog events $seen != $cnt"
4599 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4600 error "clear $hsm_flag: Changelog flag is "\
4601 "${flags[$((cnt - 1))]} not $target"
4605 # test needs a running copytool
4612 for i in norelease noarchive exists archived
4614 local f=$DIR/$tdir/$tfile-$i
4615 local fid=$(copy_file /etc/passwd $f)
4616 check_flags_changes $f $fid $i 0 1
4619 f=$DIR/$tdir/$tfile---lost
4620 fid=$(copy_file /etc/passwd $f)
4621 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4622 wait_request_state $fid ARCHIVE SUCCEED
4623 check_flags_changes $f $fid lost 3 1
4625 run_test 227 "changelog when explicit setting of HSM flags"
4628 # test needs a running copytool
4631 local fid=$(create_small_sync_file $DIR/$tfile)
4632 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4633 wait_request_state $fid ARCHIVE SUCCEED
4635 $LFS hsm_release $DIR/$tfile
4636 check_hsm_flags $DIR/$tfile "0x0000000d"
4638 filefrag $DIR/$tfile | grep " 1 extent found" ||
4639 error "filefrag on released file must return only one extent"
4641 # only newer versions of cp detect sparse files by stat/FIEMAP
4643 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4644 error "copying $DIR/$tfile"
4645 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4647 $LFS hsm_release $DIR/$tfile
4648 check_hsm_flags $DIR/$tfile "0x0000000d"
4650 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4652 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4654 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4655 error "comparing untarred $DIR/$tfile"
4657 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4658 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4660 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4663 # test needs a running copytool
4667 local maxrequest=$(get_hsm_param max_requests)
4668 local rqcnt=$(($maxrequest * 3))
4672 for i in $(seq -w 1 $rqcnt); do
4674 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4676 # we do it in 2 steps, so all requests arrive at the same time
4677 for i in $(seq -w 1 $rqcnt); do
4678 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4683 while [[ $cnt != 0 || $wt != 0 ]]; do
4685 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4686 $HSM_PARAM.actions |\
4687 grep STARTED | grep -v CANCEL | wc -l")
4688 [[ $cnt -le $maxrequest ]] ||
4689 error "$cnt > $maxrequest too many started requests"
4690 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4691 $HSM_PARAM.actions |\
4692 grep WAITING | wc -l")
4693 echo "max=$maxrequest started=$cnt waiting=$wt"
4696 run_test 250 "Coordinator max request"
4699 # test needs a running copytool
4702 local f=$DIR/$tdir/$tfile
4704 fid=$(make_custom_file_for_progress $f 103 1048576)
4705 [ $? != 0 ] && skip "not enough free space" && return
4708 # to have a short test
4709 local old_to=$(get_hsm_param active_request_timeout)
4710 set_hsm_param active_request_timeout 4
4711 # to be sure the cdt will wake up frequently so
4712 # it will be able to cancel the "old" request
4713 local old_loop=$(get_hsm_param loop_period)
4714 set_hsm_param loop_period 2
4717 # clear locks to avoid extra delay caused by flush/cancel
4718 # and thus prevent early copytool death to timeout.
4719 cancel_lru_locks osc
4721 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4722 wait_request_state $fid ARCHIVE STARTED
4724 wait_request_state $fid ARCHIVE CANCELED
4726 set_hsm_param active_request_timeout $old_to
4727 set_hsm_param loop_period $old_loop
4729 run_test 251 "Coordinator request timeout"
4733 local f=$DIR/$tdir/$tfile
4734 local fid=$(create_empty_file "$f")
4736 # to have a short test
4737 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4738 set_hsm_param loop_period 1
4743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4744 wait_request_state $fid ARCHIVE STARTED
4747 stack_trap "set_hsm_param active_request_timeout \
4748 $(get_hsm_param active_request_timeout)" EXIT
4749 set_hsm_param active_request_timeout 1
4751 wait_request_state $fid ARCHIVE CANCELED
4754 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4758 # test needs a running copytool
4762 local f=$DIR/$tdir/$tfile
4764 dd if=/dev/zero of=$f bs=1MB count=10
4765 local fid=$(path2fid $f)
4767 $LFS hsm_archive $f || error "could not archive file"
4768 wait_request_state $fid ARCHIVE SUCCEED
4770 # clear locks to discard inode data
4771 cancel_lru_locks osc
4773 #define OBD_FAIL_MDC_MERGE 0x807
4774 $LCTL set_param fail_loc=0x807
4776 #expect error here, instead of release with wrong size
4779 if ((rc == 0)); then
4780 file_size=$(stat -c '%s' $f)
4781 if ((file_size != 10485760)); then
4782 error "Wrong file size after hsm_release"
4785 echo "could not release file"
4788 run_test 253 "Check for wrong file size after release"
4792 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4793 skip "need MDS version at least 2.10.56" && return
4795 # Check that the counters are initialized to 0
4797 for request_type in archive restore remove; do
4798 count="$(get_hsm_param ${request_type}_count)" ||
4799 error "Reading ${request_type}_count failed with $?"
4801 [ "$count" -eq 0 ] ||
4802 error "Expected ${request_type}_count to be " \
4806 run_test 254a "Request counters are initialized to zero"
4810 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4811 skip "need MDS version at least 2.10.56" && return
4813 # The number of request to launch (at least 32)
4814 local request_count=$((RANDOM % 32 + 32))
4815 printf "Will launch %i requests of each type\n" "$request_count"
4817 # Launch a copytool to process requests
4820 # Set hsm.max_requests to allow starting all requests at the same time
4822 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4823 set_hsm_param max_requests "$request_count"
4827 for request_type in archive restore remove; do
4828 printf "Checking %s requests\n" "${request_type}"
4829 # Suspend the copytool to give us time to read the proc files
4832 for ((i = 0; i < $request_count; i++)); do
4833 case $request_type in
4835 create_empty_file "$DIR/$tdir/$tfile-$i" \
4839 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4842 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4845 # Give the coordinator 10 seconds to start every request
4847 while get_hsm_param actions | grep -q WAITING; do
4850 [ $timeout -gt 0 ] ||
4851 error "${request_type^} requests took too " \
4855 count="$(get_hsm_param ${request_type}_count)"
4856 [ "$count" -eq "$request_count" ] ||
4857 error "Expected '$request_count' (!= '$count') " \
4858 "active $request_type requests"
4860 # Let the copytool process the requests
4862 # Give it 10 seconds maximum
4864 while get_hsm_param actions | grep -q STARTED; do
4867 [ $timeout -gt 0 ] ||
4868 error "${request_type^} requests took too " \
4872 count="$(get_hsm_param ${request_type}_count)"
4873 [ "$count" -eq 0 ] ||
4874 error "Expected 0 (!= '$count') " \
4875 "active $request_type requests"
4878 run_test 254b "Request counters are correctly incremented and decremented"
4881 # the only way to test ondisk conf is to restart MDS ...
4882 echo "Stop coordinator and remove coordinator state at mount"
4885 # clean on disk conf set by default
4886 cdt_clear_mount_state
4887 cdt_check_state stopped
4889 # check cdt still off after umount/remount
4891 cdt_check_state stopped
4893 echo "Set coordinator start at mount, and start coordinator"
4894 cdt_set_mount_state enabled
4897 cdt_check_state enabled
4899 # check cdt still on after umount/remount
4901 cdt_check_state enabled
4903 # we are back to original state (cdt started at mount)
4905 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4908 local ai=$(get_hsm_param default_archive_id)
4909 local new=$((ai + 1))
4911 set_hsm_param default_archive_id $new -P
4913 local res=$(get_hsm_param default_archive_id)
4916 set_hsm_param default_archive_id "" "-P -d"
4918 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4920 run_test 301 "HSM tunnable are persistent"
4923 local ai=$(get_hsm_param default_archive_id)
4924 local new=$((ai + 1))
4929 set_hsm_param default_archive_id $new -P
4932 for mdtno in $(seq 1 $MDSCOUNT); do
4937 cdt_check_state enabled
4939 local res=$(get_hsm_param default_archive_id)
4942 set_hsm_param default_archive_id "" "-P -d"
4944 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4946 run_test 302 "HSM tunnable are persistent when CDT is off"
4949 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4955 local dir_mdt0=$DIR/$tdir/mdt0
4956 local dir_mdt1=$DIR/$tdir/mdt1
4958 # create 1 dir per MDT
4959 stack_trap "rm -rf $dir_mdt0"
4960 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4961 stack_trap "rm -rf $dir_mdt1"
4962 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4964 # create 1 file in each MDT
4965 local fid1=$(create_small_file $dir_mdt0/$tfile)
4966 local fid2=$(create_small_file $dir_mdt1/$tfile)
4968 # check that hsm request on mdt0 is sent to the right MDS
4969 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4970 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4971 echo "archive successful on mdt0"
4973 # check that hsm request on mdt1 is sent to the right MDS
4974 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4975 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4976 echo "archive successful on mdt1"
4978 run_test 400 "Single request is sent to the right MDT"
4981 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4987 local dir_mdt0=$DIR/$tdir/mdt0
4988 local dir_mdt1=$DIR/$tdir/mdt1
4990 # create 1 dir per MDT
4991 stack_trap "rm -rf $dir_mdt0" EXIT
4992 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4993 stack_trap "rm -rf $dir_mdt1" EXIT
4994 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4996 # create 1 file in each MDT
4997 local fid1=$(create_small_file $dir_mdt0/$tfile)
4998 local fid2=$(create_small_file $dir_mdt1/$tfile)
5000 # check that compound requests are shunt to the rights MDTs
5001 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5002 error "lfs hsm_archive"
5003 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5004 echo "archive successful on mdt0"
5005 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5006 echo "archive successful on mdt1"
5008 run_test 401 "Compound requests split and sent to their respective MDTs"
5010 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5015 local node=$(facet_active_host $facet)
5017 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5018 awk '{print $4}'); do
5019 echo "$3 $mdc on $node"
5020 do_facet $facet "$LCTL --device $mdc $state" || return 1
5025 # deactivate all mdc on agent1
5026 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5028 copytool setup --no-fail
5030 check_agent_unregistered "uuid" # match any agent
5032 # no expected running copytool
5033 search_copytools $agent && error "Copytool start should have failed"
5036 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5038 run_test 402a "Copytool start fails if all MDTs are inactive"
5045 local f=$DIR/$tdir/$tfile
5046 touch $f || error "touch $f failed"
5047 local fid=$(path2fid $f)
5049 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5050 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5053 # give time for CDT to send request and to keep it for retry
5054 wait_for_loop_period
5056 wait_request_state $fid ARCHIVE WAITING
5058 do_facet $SINGLEAGT lctl set_param fail_loc=0
5060 # request should succeed now
5061 wait_request_state $fid ARCHIVE SUCCEED
5063 run_test 402b "CDT must retry request upon slow start of CT"
5066 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5068 local agent=$(facet_active_host $SINGLEAGT)
5070 # deactivate all mdc for MDT0001
5071 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5074 local uuid=$(get_agent_uuid $agent)
5075 # check the agent is registered on MDT0000, and not on MDT0001
5076 check_agent_registered_by_mdt $uuid 0
5077 check_agent_unregistered_by_mdt $uuid 1
5079 # check running copytool process
5080 search_copytools $agent || error "No running copytools on $agent"
5082 # reactivate all mdc for MDT0001
5083 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5085 # make sure the copytool is now registered to all MDTs
5086 check_agent_registered $uuid
5088 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5091 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5095 # create files on both MDT0000 and MDT0001
5098 local dir_mdt0=$DIR/$tdir/mdt0
5099 stack_trap "rm -rf $dir_mdt0" EXIT
5100 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5102 # create 1 file on mdt0
5103 local fid1=$(create_small_file $dir_mdt0/$tfile)
5105 # deactivate all mdc for MDT0001
5106 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5108 # send an HSM request for files in MDT0000
5109 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5111 # check for completion of files in MDT0000
5112 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5113 echo "archive successful on mdt0"
5115 # reactivate all mdc for MDT0001
5116 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5118 run_test 404 "Inactive MDT does not block requests for active MDTs"
5121 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5127 local striped_dir=$DIR/$tdir/striped_dir
5129 # create striped dir on all of MDTs
5130 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5132 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5133 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5134 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5135 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5137 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5138 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5139 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5140 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5142 # check that compound requests are shunt to the rights MDTs
5143 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5144 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5145 error "lfs hsm_archive"
5147 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5148 echo "archive successful on $fid1"
5149 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5150 echo "archive successful on $fid2"
5151 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5152 echo "archive successful on $fid3"
5153 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5154 echo "archive successful on $fid4"
5156 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5157 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5158 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5159 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5161 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5162 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5163 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5164 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5166 run_test 405 "archive and release under striped directory"
5169 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5171 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5172 skip "need MDS version at least 2.7.64" && return 0
5177 fid=$(create_small_file $DIR/$tdir/$tfile)
5182 $LFS hsm_archive $DIR/$tdir/$tfile
5183 wait_request_state "$fid" ARCHIVE SUCCEED
5184 $LFS hsm_release $DIR/$tdir/$tfile
5186 # Should migrate $tdir but not $tfile.
5187 $LFS migrate -m1 $DIR/$tdir &&
5188 error "migrating HSM an archived file should fail"
5190 $LFS hsm_restore $DIR/$tdir/$tfile
5191 wait_request_state "$fid" RESTORE SUCCEED
5193 $LFS hsm_remove $DIR/$tdir/$tfile
5194 wait_request_state "$fid" REMOVE SUCCEED
5196 cat $DIR/$tdir/$tfile > /dev/null ||
5197 error "cannot read $DIR/$tdir/$tfile"
5199 $LFS migrate -m1 $DIR/$tdir ||
5200 error "cannot complete migration after HSM remove"
5202 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5203 if ((mdt_index != 1)); then
5204 error "expected MDT index 1, got $mdt_index"
5207 # Refresh fid after migration.
5208 fid=$(path2fid $DIR/$tdir/$tfile)
5211 $LFS hsm_archive $DIR/$tdir/$tfile
5212 wait_request_state "$fid" ARCHIVE SUCCEED 1
5214 lctl set_param debug=+trace
5215 $LFS hsm_release $DIR/$tdir/$tfile ||
5216 error "cannot release $DIR/$tdir/$tfile"
5218 $LFS hsm_restore $DIR/$tdir/$tfile
5219 wait_request_state "$fid" RESTORE SUCCEED 1
5221 cat $DIR/$tdir/$tfile > /dev/null ||
5222 error "cannot read $DIR/$tdir/$tfile"
5224 run_test 406 "attempting to migrate HSM archived files is safe"
5227 needclients 2 || return 0
5228 # test needs a running copytool
5233 local f=$DIR/$tdir/$tfile
5234 local f2=$DIR2/$tdir/$tfile
5236 fid=$(make_custom_file_for_progress $f 39 1000000)
5237 [ $? != 0 ] && skip "not enough free space" && return
5239 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5240 wait_request_state $fid ARCHIVE SUCCEED
5243 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5244 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5247 # 1st request holds layout lock while appropriate
5248 # RESTORE record is still not added to llog
5252 # after umount hsm_actions->O/x/x log shouldn't have
5253 # double RESTORE records like below
5254 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5255 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5257 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5260 wait_request_state $fid RESTORE SUCCEED
5262 run_test 407 "Check for double RESTORE records in llog"
5266 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5267 skip "HSM migrate is not supported" && return
5269 test_mkdir -p $DIR/$tdir
5270 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5272 run_test 500 "various LLAPI HSM tests"
5277 check_and_cleanup_lustre