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)
629 _CL_USERS+=($cl_user)
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
1013 test_1A() { # was test_1
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 1A "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 -S 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 and 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"
1142 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1143 error "failed to set default stripe"
1144 local f=$DIR/$tdir/$tfile
1147 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1148 error "failed to create file"
1149 local fid=$(path2fid $f)
1154 $LFS hsm_archive $f || error "could not archive file"
1155 wait_request_state $fid ARCHIVE SUCCEED
1158 $LFS hsm_release $f || error "could not release file"
1159 echo "verify released state: "
1160 check_hsm_flags $f "0x0000000d" && echo "pass"
1163 $LFS hsm_restore $f || error "could not restore file"
1164 wait_request_state $fid RESTORE SUCCEED
1165 echo "verify restored state: "
1166 check_hsm_flags $f "0x00000009" && echo "pass"
1168 run_test 1d "Archive, Release and Restore DoM file"
1171 local f=$DIR/$tdir/$tfile
1173 create_empty_file "$f"
1174 # New files are not dirty
1175 check_hsm_flags $f "0x00000000"
1177 # For test, we simulate an archived file.
1178 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1179 check_hsm_flags $f "0x00000001"
1181 # chmod do not put the file dirty
1182 chmod 600 $f || error "could not chmod test file"
1183 check_hsm_flags $f "0x00000001"
1185 # chown do not put the file dirty
1186 chown $RUNAS_ID $f || error "could not chown test file"
1187 check_hsm_flags $f "0x00000001"
1189 # truncate put the file dirty
1190 $TRUNCATE $f 1 || error "could not truncate test file"
1191 check_hsm_flags $f "0x00000003"
1193 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1194 check_hsm_flags $f "0x00000001"
1196 run_test 2 "Check file dirtyness when doing setattr"
1202 # New files are not dirty
1203 cp -p /etc/passwd $f
1204 check_hsm_flags $f "0x00000000"
1206 # For test, we simulate an archived file.
1207 $LFS hsm_set --exists $f ||
1208 error "user could not change hsm flags"
1209 check_hsm_flags $f "0x00000001"
1211 # Reading a file, does not set dirty
1212 cat $f > /dev/null || error "could not read file"
1213 check_hsm_flags $f "0x00000001"
1215 # Open for write without modifying data, does not set dirty
1216 openfile -f O_WRONLY $f || error "could not open test file"
1217 check_hsm_flags $f "0x00000001"
1219 # Append to a file sets it dirty
1220 cp -p /etc/passwd $f.append || error "could not create file"
1221 $LFS hsm_set --exists $f.append ||
1222 error "user could not change hsm flags"
1223 dd if=/etc/passwd of=$f.append bs=1 count=3\
1224 conv=notrunc oflag=append status=noxfer ||
1225 file_creation_failure dd $f.append $?
1226 check_hsm_flags $f.append "0x00000003"
1228 # Modify a file sets it dirty
1229 cp -p /etc/passwd $f.modify || error "could not create file"
1230 $LFS hsm_set --exists $f.modify ||
1231 error "user could not change hsm flags"
1232 dd if=/dev/zero of=$f.modify bs=1 count=3\
1233 conv=notrunc status=noxfer ||
1234 file_creation_failure dd $f.modify $?
1235 check_hsm_flags $f.modify "0x00000003"
1237 # Open O_TRUNC sets dirty
1238 cp -p /etc/passwd $f.trunc || error "could not create file"
1239 $LFS hsm_set --exists $f.trunc ||
1240 error "user could not change hsm flags"
1241 cp /etc/group $f.trunc || error "could not override a file"
1242 check_hsm_flags $f.trunc "0x00000003"
1244 # Mmapped a file sets dirty
1245 cp -p /etc/passwd $f.mmap || error "could not create file"
1246 $LFS hsm_set --exists $f.mmap ||
1247 error "user could not change hsm flags"
1248 multiop $f.mmap OSMWUc || error "could not mmap a file"
1249 check_hsm_flags $f.mmap "0x00000003"
1251 run_test 3 "Check file dirtyness when opening for write"
1254 local f=$DIR/$tdir/$tfile
1255 local fid=$(create_small_file $f)
1258 local st=$(get_request_state $fid CANCEL)
1259 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1261 run_test 4 "Useless cancel must not be registered"
1264 # test needs a running copytool
1268 local f=$DIR/$tdir/$tfile
1269 local fid=$(copy_file /etc/passwd $f)
1271 wait_request_state $fid ARCHIVE SUCCEED
1273 check_hsm_flags $f "0x00000009"
1275 run_test 8 "Test default archive number"
1277 test_9A() { # was test_9
1278 # we do not use the default one to be sure
1279 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1280 copytool setup --archive-id $archive_id
1282 # give time for CT to register with MDTs
1283 sleep $(($MDSCOUNT*2))
1284 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1285 check_agent_registered $uuid
1288 local f=$DIR/$tdir/$tfile
1289 local fid=$(copy_file /etc/passwd $f)
1290 $LFS hsm_archive --archive $archive_id $f
1291 wait_request_state $fid ARCHIVE SUCCEED
1293 check_hsm_flags $f "0x00000009"
1295 run_test 9A "Use of explicit archive number, with dedicated copytool"
1298 needclients 3 || return 0
1304 # start all of the copytools
1305 for n in $(seq $AGTCOUNT); do
1306 copytool setup --facet agt$n
1310 for n in $(seq $AGTCOUNT); do
1311 file=$DIR/$tdir/$tfile.$n
1312 fid=$(create_small_file $file)
1314 $LFS hsm_archive $file || error "could not archive file $file"
1315 wait_request_state $fid ARCHIVE SUCCEED
1316 check_hsm_flags $file "0x00000009"
1319 run_test 9a "Multiple remote agents"
1322 # test needs a running copytool
1325 mkdir -p $DIR/$tdir/d1
1326 local f=$DIR/$tdir/$tfile
1327 local fid=$(copy_file /etc/hosts $f)
1328 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1329 error "hsm_archive failed"
1330 wait_request_state $fid ARCHIVE SUCCEED
1332 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1333 error "fid $fid not in archive $HSM_ARCHIVE"
1334 echo "Verifying content"
1335 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1336 echo "Verifying hsm state "
1337 check_hsm_flags $f "0x00000009"
1339 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1340 local st=$(get_hsm_archive_id $f)
1341 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1342 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1346 run_test 10a "Archive a file"
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 "archive request failed"
1356 wait_request_state $fid ARCHIVE SUCCEED
1358 $LFS hsm_archive $f || error "archive of non dirty file failed"
1359 local cnt=$(get_request_count $fid ARCHIVE)
1360 [[ "$cnt" == "1" ]] ||
1361 error "archive of non dirty file must not make a request"
1363 run_test 10b "Archive of non dirty file must work without doing request"
1366 # test needs a running copytool
1370 local f=$DIR/$tdir/$tfile
1371 local fid=$(copy_file /etc/hosts $f)
1372 $LFS hsm_set --noarchive $f
1373 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1376 run_test 10c "Check forbidden archive"
1379 # test needs a running copytool
1383 local f=$DIR/$tdir/$tfile
1384 local fid=$(copy_file /etc/hosts $f)
1385 $LFS hsm_archive $f || error "cannot archive $f"
1386 wait_request_state $fid ARCHIVE SUCCEED
1388 local ar=$(get_hsm_archive_id $f)
1389 local dflt=$(get_hsm_param default_archive_id)
1390 [[ $ar == $dflt ]] ||
1391 error "archived file is not on default archive: $ar != $dflt"
1393 run_test 10d "Archive a file on the default archive id"
1397 copy2archive /etc/hosts $tdir/$tfile
1398 local f=$DIR/$tdir/$tfile
1400 import_file $tdir/$tfile $f
1401 echo -n "Verifying released state: "
1402 check_hsm_flags $f "0x0000000d"
1404 local LSZ=$(stat -c "%s" $f)
1405 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1407 echo "Verifying imported size $LSZ=$ASZ"
1408 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1409 echo -n "Verifying released pattern: "
1410 local PTRN=$($GETSTRIPE -L $f)
1412 [[ $PTRN == released ]] || error "Is not released"
1413 local fid=$(path2fid $f)
1414 echo "Verifying new fid $fid in archive"
1416 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1417 error "fid $fid not in archive $HSM_ARCHIVE"
1419 run_test 11a "Import a file"
1422 # test needs a running copytool
1426 local f=$DIR/$tdir/$tfile
1427 local fid=$(copy_file /etc/hosts $f)
1428 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1429 error "hsm_archive failed"
1430 wait_request_state $fid ARCHIVE SUCCEED
1432 local FILE_HASH=$(md5sum $f)
1437 echo "$FILE_HASH" | md5sum -c
1439 [[ $? -eq 0 ]] || error "Restored file differs"
1443 run_test 11b "Import a deleted file using its FID"
1446 # test needs a running copytool
1450 copy2archive /etc/hosts $tdir/$tfile
1452 local f=$DIR/$tdir/$tfile
1453 import_file $tdir/$tfile $f
1454 local f2=$DIR2/$tdir/$tfile
1455 echo "Verifying released state: "
1456 check_hsm_flags $f2 "0x0000000d"
1458 local fid=$(path2fid $f2)
1459 $LFS hsm_restore $f2
1460 wait_request_state $fid RESTORE SUCCEED
1462 echo "Verifying file state: "
1463 check_hsm_flags $f2 "0x00000009"
1465 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1467 [[ $? -eq 0 ]] || error "Restored file differs"
1471 run_test 12a "Restore an imported file explicitly"
1474 # test needs a running copytool
1478 copy2archive /etc/hosts $tdir/$tfile
1480 local f=$DIR/$tdir/$tfile
1481 import_file $tdir/$tfile $f
1482 echo "Verifying released state: "
1483 check_hsm_flags $f "0x0000000d"
1485 cat $f > /dev/null || error "File read failed"
1487 echo "Verifying file state after restore: "
1488 check_hsm_flags $f "0x00000009"
1490 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1492 [[ $? -eq 0 ]] || error "Restored file differs"
1496 run_test 12b "Restore an imported file implicitly"
1499 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1501 # test needs a running copytool
1504 local f=$DIR/$tdir/$tfile
1506 $LFS setstripe -c 2 "$f"
1508 fid=$(make_custom_file_for_progress $f 5)
1509 [ $? != 0 ] && skip "not enough free space" && return
1511 local FILE_CRC=$(md5sum $f)
1513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1514 wait_request_state $fid ARCHIVE SUCCEED
1515 $LFS hsm_release $f || error "release $f failed"
1517 echo "$FILE_CRC" | md5sum -c
1519 [[ $? -eq 0 ]] || error "Restored file differs"
1521 run_test 12c "Restore a file with stripe of 2"
1524 # test needs a running copytool
1529 local f=$DIR/$tdir/$tfile
1530 local fid=$(copy_file /etc/hosts $f)
1531 $LFS hsm_restore $f || error "restore of non archived file failed"
1532 local cnt=$(get_request_count $fid RESTORE)
1533 [[ "$cnt" == "0" ]] ||
1534 error "restore non archived must not make a request"
1535 $LFS hsm_archive $f ||
1536 error "archive request failed"
1537 wait_request_state $fid ARCHIVE SUCCEED
1538 $LFS hsm_restore $f ||
1539 error "restore of non released file failed"
1540 local cnt=$(get_request_count $fid RESTORE)
1541 [[ "$cnt" == "0" ]] ||
1542 error "restore a non dirty file must not make a request"
1544 run_test 12d "Restore of a non archived, non released file must work"\
1545 " without doing request"
1548 # test needs a running copytool
1551 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1552 local f=$DIR/$tdir/$tfile
1553 local fid=$(copy_file /etc/hosts $f)
1554 $LFS hsm_archive $f || error "archive request failed"
1555 wait_request_state $fid ARCHIVE SUCCEED
1558 cat /etc/hosts >> $f
1562 $LFS hsm_restore $f && error "restore a dirty file must fail"
1565 run_test 12e "Check forbidden restore"
1568 # test needs a running copytool
1572 local f=$DIR/$tdir/$tfile
1573 local fid=$(copy_file /etc/hosts $f)
1575 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1576 wait_request_state $fid ARCHIVE SUCCEED
1577 $LFS hsm_release $f || error "release of $f failed"
1579 wait_request_state $fid RESTORE SUCCEED
1581 echo -n "Verifying file state: "
1582 check_hsm_flags $f "0x00000009"
1584 diff -q /etc/hosts $f
1586 [[ $? -eq 0 ]] || error "Restored file differs"
1588 run_test 12f "Restore a released file explicitly"
1591 # test needs a running copytool
1595 local f=$DIR/$tdir/$tfile
1596 local fid=$(copy_file /etc/hosts $f)
1598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1599 wait_request_state $fid ARCHIVE SUCCEED
1600 $LFS hsm_release $f || error "release of $f failed"
1602 diff -q /etc/hosts $f
1605 # we check we had a restore done
1606 wait_request_state $fid RESTORE SUCCEED
1608 [[ $st -eq 0 ]] || error "Restored file differs"
1610 run_test 12g "Restore a released file implicitly"
1613 needclients 2 || return 0
1615 # test needs a running copytool
1619 local f=$DIR/$tdir/$tfile
1620 local fid=$(copy_file /etc/hosts $f)
1622 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1623 wait_request_state $fid ARCHIVE SUCCEED
1624 $LFS hsm_release $f || error "release of $f failed"
1626 do_node $CLIENT2 diff -q /etc/hosts $f
1629 # we check we had a restore done
1630 wait_request_state $fid RESTORE SUCCEED
1632 [[ $st -eq 0 ]] || error "Restored file differs"
1634 run_test 12h "Restore a released file implicitly from a second node"
1637 # test needs a running copytool
1641 local f=$DIR/$tdir/$tfile
1642 local fid=$(copy_file /etc/passwd $f)
1643 $LFS hsm_archive $f || error "archive of $f failed"
1644 wait_request_state $fid ARCHIVE SUCCEED
1646 $LFS hsm_release $f || error "release of $f failed"
1650 [[ $? -eq 0 ]] || error "Restored file differs"
1652 run_test 12m "Archive/release/implicit restore"
1655 # test needs a running copytool
1659 copy2archive /etc/hosts $tdir/$tfile
1661 local f=$DIR/$tdir/$tfile
1662 import_file $tdir/$tfile $f
1664 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1665 error "Restored file differs"
1667 $LFS hsm_release $f || error "release of $f failed"
1671 run_test 12n "Import/implicit restore/release"
1674 # test needs a running copytool
1678 local f=$DIR/$tdir/$tfile
1679 local fid=$(copy_file /etc/hosts $f)
1681 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1682 wait_request_state $fid ARCHIVE SUCCEED
1683 $LFS hsm_release $f || error "release of $f failed"
1685 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1686 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1688 # set no retry action mode
1691 diff -q /etc/hosts $f
1694 # we check we had a restore failure
1695 wait_request_state $fid RESTORE FAILED
1697 [[ $st -eq 0 ]] && error "Restore must fail"
1699 # remove no retry action mode
1702 # check file is still released
1703 check_hsm_flags $f "0x0000000d"
1705 # retry w/o failure injection
1706 do_facet $SINGLEMDS lctl set_param fail_loc=0
1708 # to be sure previous RESTORE result is gone
1710 wait_for_grace_delay
1712 diff -q /etc/hosts $f
1715 # we check we had a restore done
1716 wait_request_state $fid RESTORE SUCCEED
1718 [[ $st -eq 0 ]] || error "Restored file differs"
1720 run_test 12o "Layout-swap failure during Restore leaves file released"
1723 # test needs a running copytool
1727 local f=$DIR/$tdir/$tfile
1728 local fid=$(copy_file /etc/hosts $f)
1730 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1731 wait_request_state $fid ARCHIVE SUCCEED
1732 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1733 $LFS hsm_release $f || error "cannot release $f"
1734 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1735 $LFS hsm_release $f || error "cannot release $f"
1736 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1738 run_test 12p "implicit restore of a file on copytool mount point"
1740 cleanup_test_12q() {
1741 error "cannot umount $MOUNT3 on $SINGLEAGT"
1745 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1746 skip "need MDS version at least 2.7.58" && return 0
1748 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1749 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1750 error "cannot mount $MOUNT3 on $SINGLEAGT"
1752 # test needs a running copytool
1753 copytool setup -m "$MOUNT3"
1755 local f=$DIR/$tdir/$tfile
1756 local f2=$DIR2/$tdir/$tfile
1757 local fid=$(create_small_file $f)
1758 local orig_size=$(stat -c "%s" $f)
1760 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1761 wait_request_state $fid ARCHIVE SUCCEED
1763 $LFS hsm_release $f || error "could not release file"
1764 check_hsm_flags $f "0x0000000d"
1767 wait_copytools || error "copytool failed to stop"
1769 cat $f > /dev/null &
1771 # wait a bit to allow implicit restore request to be handled.
1772 # if not, next stat would also block on layout-lock.
1775 local size=$(stat -c "%s" $f2)
1776 [ $size -eq $orig_size ] ||
1777 error "$f2: wrong size after archive: $size != $orig_size"
1779 copytool setup -m "$MOUNT3"
1783 size=$(stat -c "%s" $f)
1784 [ $size -eq $orig_size ] ||
1785 error "$f: wrong size after restore: $size != $orig_size"
1787 size=$(stat -c "%s" $f2)
1788 [ $size -eq $orig_size ] ||
1789 error "$f2: wrong size after restore: $size != $orig_size"
1793 size=$(stat -c "%s" $f)
1795 error "$f: wrong size after overwrite: $size != 0"
1797 size=$(stat -c "%s" $f2)
1799 error "$f2: wrong size after overwrite: $size != 0"
1801 run_test 12q "file attributes are refreshed after restore"
1804 # test needs a running copytool
1807 local ARC_SUBDIR="import.orig"
1811 # populate directory to be imported
1812 for d in $(seq 1 10); do
1813 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1814 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1815 for f in $(seq 1 10); do
1816 CURR_FILE="$CURR_DIR/$tfile.$f"
1817 # write file-specific data
1818 do_facet $SINGLEAGT \
1819 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1820 "file=$CURR_FILE > $CURR_FILE"
1824 import_file "$ARC_SUBDIR" $DIR/$tdir
1825 # diff lustre content and origin (triggers file restoration)
1826 # there must be 10x10 identical files, and no difference
1827 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1828 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1829 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1830 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1832 [ $cnt_diff -eq 0 ] ||
1833 error "$cnt_diff imported files differ from read data"
1834 [ $cnt_ok -eq 100 ] ||
1835 error "not enough identical files ($cnt_ok != 100)"
1839 run_test 13 "Recursively import and restore a directory"
1842 # test needs a running copytool
1846 local f=$DIR/$tdir/$tfile
1847 local fid=$(create_small_file $f)
1848 local sum=$(md5sum $f | awk '{print $1}')
1849 $LFS hsm_archive $f || error "could not archive file"
1850 wait_request_state $fid ARCHIVE SUCCEED
1852 # create released file (simulate llapi_hsm_import call)
1853 local fid2=$(create_empty_file "$f")
1854 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1855 $LFS hsm_release $f || error "could not release file"
1857 # rebind the archive to the newly created file
1858 echo "rebind $fid to $fid2"
1860 do_facet $SINGLEAGT \
1861 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1862 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1864 # restore file and compare md5sum
1865 local sum2=$(md5sum $f | awk '{print $1}')
1867 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1871 run_test 14 "Rebind archived file to a new fid"
1874 # test needs a running copytool
1878 local f=$DIR/$tdir/$tfile
1880 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1884 for i in $(seq 1 $count); do
1885 fids[$i]=$(create_small_file $f.$i)
1886 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1887 $LFS hsm_archive $f.$i || error "could not archive file"
1889 wait_all_done $(($count*60))
1893 for i in $(seq 1 $count); do
1894 local fid2=$(create_empty_file "${f}.${i}")
1895 # add the rebind operation to the list
1896 echo ${fids[$i]} $fid2 >> $tmpfile
1898 # set it released (simulate llapi_hsm_import call)
1899 $LFS hsm_set --archived --exists $f.$i ||
1900 error "could not force hsm flags"
1901 $LFS hsm_release $f.$i || error "could not release file"
1903 nl=$(wc -l < $tmpfile)
1904 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1906 echo "rebind list of files"
1907 do_facet $SINGLEAGT \
1908 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1909 --rebind $tmpfile $DIR" || error "could not rebind file list"
1911 # restore files and compare md5sum
1912 for i in $(seq 1 $count); do
1913 local sum2=$(md5sum $f.$i | awk '{print $1}')
1914 [[ $sum2 == ${sums[$i]} ]] ||
1915 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1921 run_test 15 "Rebind a list of files"
1924 # test needs a running copytool
1928 # create a known size file so we can verify transfer speed
1931 dd if=/dev/zero of=$ref bs=1M count=20
1934 local f=$DIR/$tdir/$tfile
1935 local fid=$(copy_file $ref $f)
1937 local start=$(date +%s)
1939 wait_request_state $fid ARCHIVE SUCCEED
1940 local end=$(date +%s)
1941 # Add 1 to account for rounding errors between start and end (LU-8155)
1942 local duration=$((end - start + 1))
1944 [[ $duration -ge $((goal - 1)) ]] ||
1945 error "Transfer is too fast $duration < $goal"
1947 run_test 16 "Test CT bandwith control option"
1950 local f=$DIR/$tdir/$tfile
1951 create_empty_file "$f"
1953 # Could not release a non-archived file
1954 $LFS hsm_release $f && error "release should not succeed"
1956 # For following tests, we must test them with HS_ARCHIVED set
1957 $LFS hsm_set --exists --archived $f || error "could not add flag"
1959 # Could not release a file if no-release is set
1960 $LFS hsm_set --norelease $f || error "could not add flag"
1961 $LFS hsm_release $f && error "release should not succeed"
1962 $LFS hsm_clear --norelease $f || error "could not remove flag"
1964 # Could not release a file if lost
1965 $LFS hsm_set --lost $f || error "could not add flag"
1966 $LFS hsm_release $f && error "release should not succeed"
1967 $LFS hsm_clear --lost $f || error "could not remove flag"
1969 # Could not release a file if dirty
1970 $LFS hsm_set --dirty $f || error "could not add flag"
1971 $LFS hsm_release $f && error "release should not succeed"
1972 $LFS hsm_clear --dirty $f || error "could not remove flag"
1974 run_test 20 "Release is not permitted"
1977 # test needs a running copytool
1980 local f=$DIR/$tdir/test_release
1982 # Create a file and check its states
1983 local fid=$(create_small_file $f)
1984 check_hsm_flags $f "0x00000000"
1986 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1987 # used until file is flushed to disk
1988 if [ $(facet_fstype ost1) == "zfs" ]; then
1989 # this causes an OST_SYNC rpc to be sent
1990 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1991 # clear locks to reread file data
1992 cancel_lru_locks osc
1995 local orig_size=$(stat -c "%s" $f)
1996 local orig_blocks=$(stat -c "%b" $f)
1998 start_full_debug_logging
2000 $LFS hsm_archive $f || error "could not archive file"
2001 wait_request_state $fid ARCHIVE SUCCEED
2003 local blocks=$(stat -c "%b" $f)
2004 [ $blocks -eq $orig_blocks ] ||
2005 error "$f: wrong block number after archive: " \
2006 "$blocks != $orig_blocks"
2007 local size=$(stat -c "%s" $f)
2008 [ $size -eq $orig_size ] ||
2009 error "$f: wrong size after archive: $size != $orig_size"
2011 # Release and check states
2012 $LFS hsm_release $f || error "could not release file"
2013 check_hsm_flags $f "0x0000000d"
2015 blocks=$(stat -c "%b" $f)
2016 [ $blocks -gt 5 ] &&
2017 error "$f: too many blocks after release: $blocks > 5"
2018 size=$(stat -c "%s" $f)
2019 [ $size -ne $orig_size ] &&
2020 error "$f: wrong size after release: $size != $orig_size"
2022 # Check we can release an file without stripe info
2026 check_hsm_flags $f "0x00000000"
2027 $LFS hsm_archive $f || error "could not archive file"
2028 wait_request_state $fid ARCHIVE SUCCEED
2030 # Release and check states
2031 $LFS hsm_release $f || error "could not release file"
2032 check_hsm_flags $f "0x0000000d"
2034 # Release again a file that is already released is OK
2035 $LFS hsm_release $f || fail "second release should succeed"
2036 check_hsm_flags $f "0x0000000d"
2038 stop_full_debug_logging
2040 run_test 21 "Simple release tests"
2043 # test needs a running copytool
2046 local f=$DIR/$tdir/test_release
2047 local swap=$DIR/$tdir/test_swap
2049 # Create a file and check its states
2050 local fid=$(create_small_file $f)
2051 check_hsm_flags $f "0x00000000"
2053 $LFS hsm_archive $f || error "could not archive file"
2054 wait_request_state $fid ARCHIVE SUCCEED
2056 # Release and check states
2057 $LFS hsm_release $f || error "could not release file"
2058 check_hsm_flags $f "0x0000000d"
2060 create_small_file $swap
2061 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2065 run_test 22 "Could not swap a release file"
2068 # test needs a running copytool
2071 local f=$DIR/$tdir/test_mtime
2073 # Create a file and check its states
2074 local fid=$(create_small_file $f)
2075 check_hsm_flags $f "0x00000000"
2077 $LFS hsm_archive $f || error "could not archive file"
2078 wait_request_state $fid ARCHIVE SUCCEED
2080 # Set modification time in the past
2081 touch -m -a -d @978261179 $f
2083 # Release and check states
2084 $LFS hsm_release $f || error "could not release file"
2085 check_hsm_flags $f "0x0000000d"
2087 local MTIME=$(stat -c "%Y" $f)
2088 local ATIME=$(stat -c "%X" $f)
2089 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2090 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2092 run_test 23 "Release does not change a/mtime (utime)"
2095 local file=$DIR/$tdir/$tfile
2104 # test needs a running copytool
2107 fid=$(create_small_file $file)
2109 # Create a file and check its states
2110 check_hsm_flags $file "0x00000000"
2112 # Ensure atime is less than mtime and ctime.
2116 atime0=$(stat -c "%X" $file)
2117 mtime0=$(stat -c "%Y" $file)
2118 ctime0=$(stat -c "%Z" $file)
2120 [ $atime0 -lt $mtime0 ] ||
2121 error "atime $atime0 is not less than mtime $mtime0"
2123 [ $atime0 -lt $ctime0 ] ||
2124 error "atime $atime0 is not less than ctime $ctime0"
2126 # Archive should not change any timestamps.
2127 $LFS hsm_archive $file || error "cannot archive '$file'"
2128 wait_request_state $fid ARCHIVE SUCCEED
2130 atime1=$(stat -c "%X" $file)
2131 mtime1=$(stat -c "%Y" $file)
2132 ctime1=$(stat -c "%Z" $file)
2134 [ $atime0 -eq $atime1 ] ||
2135 error "archive changed atime from $atime0 to $atime1"
2137 [ $mtime0 -eq $mtime1 ] ||
2138 error "archive changed mtime from $mtime0 to $mtime1"
2140 [ $ctime0 -eq $ctime1 ] ||
2141 error "archive changed ctime from $ctime0 to $ctime1"
2143 # Release should not change any timestamps.
2144 $LFS hsm_release $file || error "cannot release '$file'"
2145 check_hsm_flags $file "0x0000000d"
2147 atime1=$(stat -c "%X" $file)
2148 mtime1=$(stat -c "%Y" $file)
2149 ctime1=$(stat -c "%Z" $file)
2151 [ $atime0 -eq $atime1 ] ||
2152 error "release changed atime from $atime0 to $atime1"
2154 [ $mtime0 -eq $mtime1 ] ||
2155 error "release changed mtime from $mtime0 to $mtime1"
2157 [ $ctime0 -eq $ctime1 ] ||
2158 error "release changed ctime from $ctime0 to $ctime1"
2160 # Restore should not change any timestamps.
2161 $LFS hsm_restore $file
2162 wait_request_state $fid RESTORE SUCCEED
2164 atime1=$(stat -c "%X" $file)
2165 mtime1=$(stat -c "%Y" $file)
2166 ctime1=$(stat -c "%Z" $file)
2168 [ $atime0 -eq $atime1 ] ||
2169 error "restore changed atime from $atime0 to $atime1"
2171 [ $mtime0 -eq $mtime1 ] ||
2172 error "restore changed mtime from $mtime0 to $mtime1"
2174 [ $ctime0 -eq $ctime1 ] ||
2175 error "restore changed ctime from $ctime0 to $ctime1"
2178 wait_copytools || error "Copytools failed to stop"
2180 # Once more, after unmount and mount.
2181 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2182 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2184 atime1=$(stat -c "%X" $file)
2185 mtime1=$(stat -c "%Y" $file)
2186 ctime1=$(stat -c "%Z" $file)
2188 [ $atime0 -eq $atime1 ] ||
2189 error "remount changed atime from $atime0 to $atime1"
2191 [ $mtime0 -eq $mtime1 ] ||
2192 error "remount changed mtime from $mtime0 to $mtime1"
2194 [ $ctime0 -eq $ctime1 ] ||
2195 error "remount changed ctime from $ctime0 to $ctime1"
2197 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2200 local file=$DIR/$tdir/$tfile
2206 # Test needs a running copytool.
2209 # Check that root can do HSM actions on a regular user's file.
2210 fid=$(create_small_file $file)
2211 sum0=$(md5sum $file)
2213 chown $RUNAS_ID:$RUNAS_GID $file ||
2214 error "cannot chown '$file' to '$RUNAS_ID'"
2216 chmod ugo-w $DIR/$tdir ||
2217 error "cannot chmod '$DIR/$tdir'"
2219 $LFS hsm_archive $file
2220 wait_request_state $fid ARCHIVE SUCCEED
2222 $LFS hsm_release $file
2223 check_hsm_flags $file "0x0000000d"
2225 $LFS hsm_restore $file
2226 wait_request_state $fid RESTORE SUCCEED
2228 # Check that ordinary user can get HSM state.
2229 $RUNAS $LFS hsm_state $file ||
2230 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2232 $LFS hsm_release $file
2233 check_hsm_flags $file "0x0000000d"
2235 # Check that ordinary user can accessed released file.
2236 sum1=$($RUNAS md5sum $file) ||
2237 error "user '$RUNAS_ID' cannot read '$file'"
2239 [ "$sum0" == "$sum1" ] ||
2240 error "md5sum mismatch for '$file'"
2242 run_test 24b "root can archive, release, and restore user files"
2245 local file=$DIR/$tdir/$tfile
2246 local action=archive
2251 # test needs a running copytool
2256 # Save the default masks and check that cleanup_24c will
2257 # restore the request masks correctly.
2258 user_save=$(get_hsm_param user_request_mask)
2259 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2260 group_save=$(get_hsm_param group_request_mask)
2261 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2262 other_save=$(get_hsm_param other_request_mask)
2263 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2265 [ "$user_save" == RESTORE ] ||
2266 error "user_request_mask is '$user_save' expected 'RESTORE'"
2267 [ "$group_save" == RESTORE ] ||
2268 error "group_request_mask is '$group_save' expected 'RESTORE'"
2269 [ "$other_save" == RESTORE ] ||
2270 error "other_request_mask is '$other_save' expected 'RESTORE'"
2273 create_small_file $file
2274 chown $RUNAS_ID:$GROUP $file ||
2275 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2277 $RUNAS $LFS hsm_$action $file &&
2278 error "$action by user should fail"
2280 set_hsm_param user_request_mask $action
2281 $RUNAS $LFS hsm_$action $file ||
2282 error "$action by user should succeed"
2285 create_small_file $file
2286 chown nobody:$RUNAS_GID $file ||
2287 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2289 $RUNAS $LFS hsm_$action $file &&
2290 error "$action by group should fail"
2292 set_hsm_param group_request_mask $action
2293 $RUNAS $LFS hsm_$action $file ||
2294 error "$action by group should succeed"
2297 create_small_file $file
2298 chown nobody:$GROUP $file ||
2299 error "cannot chown '$file' to 'nobody:$GROUP'"
2301 $RUNAS $LFS hsm_$action $file &&
2302 error "$action by other should fail"
2304 set_hsm_param other_request_mask $action
2305 $RUNAS $LFS hsm_$action $file ||
2306 error "$action by other should succeed"
2308 run_test 24c "check that user,group,other request masks work"
2311 local file1=$DIR/$tdir/$tfile
2312 local file2=$DIR2/$tdir/$tfile
2316 fid1=$(create_small_file $file1)
2319 $LFS getstripe $file1
2321 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2322 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2323 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2325 copytool setup -m "$MOUNT3"
2327 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2328 mount -o remount,ro $MOUNT2
2330 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2332 fid2=$(path2fid $file2)
2333 [ "$fid1" == "$fid2" ] ||
2334 error "FID mismatch '$fid1' != '$fid2'"
2336 $LFS hsm_archive $file2 &&
2337 error "archive should fail on read-only mount"
2338 check_hsm_flags $file1 "0x00000000"
2340 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2341 wait_request_state $fid1 ARCHIVE SUCCEED
2343 $LFS hsm_release $file1
2344 $LFS hsm_restore $file2
2345 wait_request_state $fid1 RESTORE SUCCEED
2347 $LFS hsm_release $file1 || error "cannot release '$file1'"
2348 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2350 $LFS hsm_release $file2 &&
2351 error "release should fail on read-only mount"
2355 run_test 24d "check that read-only mounts are respected"
2360 local f=$DIR/$tdir/$tfile
2363 fid=$(create_small_file $f) || error "cannot create $f"
2364 $LFS hsm_archive $f || error "cannot archive $f"
2365 wait_request_state $fid ARCHIVE SUCCEED
2366 $LFS hsm_release $f || error "cannot release $f"
2367 while ! $LFS hsm_state $f | grep released; do
2371 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2373 run_test 24e "tar succeeds on HSM released files" # LU-6213
2376 # test needs a running copytool
2379 mkdir -p $DIR/$tdir/d1
2380 local f=$DIR/$tdir/$tfile
2381 local fid=$(copy_file /etc/hosts $f)
2384 $LFS hsm_archive $f ||
2385 error "hsm_archive failed"
2386 wait_request_state $fid ARCHIVE SUCCEED
2387 $LFS hsm_release $f || error "cannot release $f"
2388 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2391 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2392 error "Can not recover the tar contents"
2394 echo "Sum0 = $sum0, sum1 = $sum1"
2395 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2397 run_test 24f "root can archive, release, and restore tar files"
2400 # test needs a running copytool
2404 copy2archive /etc/hosts $tdir/$tfile
2406 local f=$DIR/$tdir/$tfile
2408 import_file $tdir/$tfile $f
2410 $LFS hsm_set --lost $f
2415 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2419 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2420 " (Operation not permitted)"
2423 # test needs a running copytool
2428 local f=$DIR/$tdir/$tfile
2429 local fid=$(copy_file /etc/passwd $f)
2431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2432 wait_request_state $fid ARCHIVE SUCCEED
2435 $LFS hsm_set --lost $f
2439 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2441 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2442 " (Operation not permitted)"
2444 test_26A() { # was test_26
2445 # test needs a running copytool
2448 local f=$DIR/$tdir/$tfile
2450 fid=$(make_custom_file_for_progress $f 39 1000000)
2451 [ $? != 0 ] && skip "not enough free space" && return
2453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2454 wait_request_state $fid ARCHIVE SUCCEED
2457 wait_request_state $fid REMOVE SUCCEED
2459 check_hsm_flags $f "0x00000000"
2461 run_test 26A "Remove the archive of a valid file"
2464 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2465 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2467 # test needs a running copytool
2471 local f=$DIR/$tdir/$tfile
2472 local fid=$(copy_file /etc/passwd $f)
2474 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2475 wait_request_state $fid ARCHIVE SUCCEED
2477 local f2=$DIR/$tdir/${tfile}_2
2478 local fid2=$(copy_file /etc/passwd $f2)
2480 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2481 wait_request_state $fid2 ARCHIVE SUCCEED
2483 local f3=$DIR/$tdir/${tfile}_3
2484 local fid3=$(copy_file /etc/passwd $f3)
2486 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2487 wait_request_state $fid3 ARCHIVE SUCCEED
2489 # set a long grace_delay vs short loop_period
2490 local orig_loop_period=$(get_hsm_param loop_period)
2491 local orig_grace_delay=$(get_hsm_param grace_delay)
2492 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2493 set_hsm_param loop_period 10
2494 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2495 set_hsm_param grace_delay 100
2499 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2500 set_hsm_param remove_archive_on_last_unlink 1
2502 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2507 wait_request_state $fid2 REMOVE SUCCEED
2509 assert_request_count $fid REMOVE 0 \
2510 "Unexpected archived data remove request for $f"
2511 assert_request_count $fid3 REMOVE 0 \
2512 "Unexpected archived data remove request for $f3"
2514 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2517 # test needs a running copytool
2521 local f=$DIR/$tdir/$tfile
2522 local fid=$(copy_file /etc/passwd $f)
2524 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2525 wait_request_state $fid ARCHIVE SUCCEED
2527 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2528 set_hsm_param remove_archive_on_last_unlink 1
2531 cdt_check_state stopped
2535 wait_request_state $fid REMOVE WAITING
2539 # copytool must re-register
2541 wait_copytools || error "copytool failed to stop"
2544 wait_request_state $fid REMOVE SUCCEED
2546 run_test 26b "RAoLU policy when CDT off"
2549 # test needs a running copytool
2553 local f=$DIR/$tdir/$tfile
2554 local fid=$(copy_file /etc/passwd $f)
2556 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2557 wait_request_state $fid ARCHIVE SUCCEED
2559 local f2=$DIR/$tdir/${tfile}_2
2560 local fid2=$(copy_file /etc/passwd $f2)
2562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2563 wait_request_state $fid2 ARCHIVE SUCCEED
2565 # set a long grace_delay vs short loop_period
2566 local orig_loop_period=$(get_hsm_param loop_period)
2567 local orig_grace_delay=$(get_hsm_param grace_delay)
2568 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2569 set_hsm_param loop_period 10
2570 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2571 set_hsm_param grace_delay 100
2573 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2574 set_hsm_param remove_archive_on_last_unlink 1
2576 multiop_bg_pause $f O_c || error "open $f failed"
2582 wait_request_state $fid2 REMOVE SUCCEED
2583 assert_request_count $fid REMOVE 0 \
2584 "Unexpected archived data remove request for $f"
2586 kill -USR1 $pid || error "multiop early exit"
2587 # should reach autotest timeout if multiop fails to trap
2588 # signal, close file, and exit ...
2589 wait $pid || error "wait PID $PID failed"
2591 wait_request_state $fid REMOVE SUCCEED
2593 run_test 26c "RAoLU effective when file closed"
2596 # test needs a running copytool
2600 local f=$DIR/$tdir/$tfile
2601 local fid=$(create_small_file $f)
2603 $LFS hsm_archive $f || error "could not archive file"
2604 wait_request_state $fid ARCHIVE SUCCEED
2606 # set a long grace_delay vs short loop_period
2607 local orig_loop_period=$(get_hsm_param loop_period)
2608 local orig_grace_delay=$(get_hsm_param grace_delay)
2609 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2610 set_hsm_param loop_period 10
2611 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2612 set_hsm_param grace_delay 100
2614 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2615 set_hsm_param remove_archive_on_last_unlink 1
2617 multiop_bg_pause $f O_c || error "multiop failed"
2624 wait_request_state $fid REMOVE SUCCEED
2626 client_up || client_up || true
2628 kill -USR1 $MULTIPID
2629 wait $MULTIPID || error "multiop close failed"
2631 run_test 26d "RAoLU when Client eviction"
2634 # test needs a running copytool
2637 create_archive_file $tdir/$tfile
2638 local f=$DIR/$tdir/$tfile
2639 import_file $tdir/$tfile $f
2640 local fid=$(path2fid $f)
2644 [[ $? != 0 ]] || error "Remove of a released file should fail"
2648 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2651 # test needs a running copytool
2654 local f=$DIR/$tdir/$tfile
2656 fid=$(make_custom_file_for_progress $f 39 1000000)
2657 [ $? != 0 ] && skip "not enough free space" && return
2659 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2660 wait_request_state $fid ARCHIVE SUCCEED
2665 [[ $? != 0 ]] || error "Remove of a released file should fail"
2667 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2670 # test needs a running copytool
2673 local f=$DIR/$tdir/$tfile
2675 fid=$(make_custom_file_for_progress $f 39 1000000)
2676 [ $? != 0 ] && skip "not enough free space" && return
2678 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2679 wait_request_state $fid ARCHIVE SUCCEED
2688 wait_request_state $fid REMOVE SUCCEED
2690 run_test 28 "Concurrent archive/file remove"
2693 # Tests --mntpath and --archive options
2696 copytool setup -m "$MOUNT" -a $archive_id
2698 # Bad archive number
2699 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2700 grep "Invalid argument" ||
2701 error "unexpected hsm_remove failure (1)"
2703 # mntpath is present but file is given
2704 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2705 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2706 error "unexpected hsm_remove failure (2)"
2708 run_test 29a "Tests --mntpath and --archive options"
2711 # test needs a running copytool
2714 local f=$DIR/$tdir/$tfile
2715 local fid=$(create_small_file $f)
2717 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2718 wait_request_state $fid ARCHIVE SUCCEED
2722 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2723 wait_request_state $fid REMOVE SUCCEED
2725 run_test 29b "Archive/delete/remove by FID from the archive."
2728 # test needs a running copytool
2731 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2732 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2733 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2735 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2736 wait_request_state $fid1 ARCHIVE SUCCEED
2737 wait_request_state $fid2 ARCHIVE SUCCEED
2738 wait_request_state $fid3 ARCHIVE SUCCEED
2740 rm -f $DIR/$tdir/$tfile-[1-3]
2742 echo $fid1 > $DIR/$tdir/list
2743 echo $fid2 >> $DIR/$tdir/list
2744 echo $fid3 >> $DIR/$tdir/list
2746 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2747 --filelist $DIR/$tdir/list
2748 wait_request_state $fid1 REMOVE SUCCEED
2749 wait_request_state $fid2 REMOVE SUCCEED
2750 wait_request_state $fid3 REMOVE SUCCEED
2752 run_test 29c "Archive/delete/remove by FID, using a file list."
2755 # test needs more than one CT
2756 needclients 3 || return 0
2762 # start all of the copytools
2763 for n in $(seq $AGTCOUNT); do
2764 copytool setup -f agt$n -a $n
2768 file=$DIR/$tdir/$tfile
2769 fid=$(create_small_file $file)
2771 $LFS hsm_archive $file
2772 wait_request_state $fid ARCHIVE SUCCEED
2773 check_hsm_flags $file "0x00000009"
2777 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2778 error "cannot hsm_remove '$fid'"
2780 # give time for CDT to handle remove request and create broadcasted
2783 # remove request has been broadcasted ?
2784 local cnt=$(get_request_count $fid REMOVE)
2785 # broadcasted requests + original
2786 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2787 error "remove not broadcasted to all CTs"
2789 # give time for CDT and CTs to handle broadcasted
2790 wait_for_loop_period
2792 # each agent serves one different archive_id, so broadcasted
2793 # hsm_remove request should only succeed once and fail at all others
2797 for n in $(seq $AGTCOUNT); do
2798 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2799 $HSM_PARAM.actions | awk \
2800 '/'$fid'.*action=REMOVE archive#='$n'/ \
2801 {print \\\$13}' | cut -f2 -d=")
2802 if [[ "$res" == "SUCCEED" ]]; then
2804 elif [[ "$res" == "FAILED" ]]; then
2809 [[ $scnt -eq 1 ]] ||
2810 error "one and only CT should have removed successfully"
2812 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2813 error "all but one CT should have failed to remove"
2815 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2816 "request to be sent once for each registered archive_id"
2819 # restore at exec cannot work on agent node (because of Linux kernel
2820 # protection of executables)
2821 needclients 2 || return 0
2823 # test needs a running copytool
2827 copy2archive /bin/true $tdir/$tfile
2829 local f=$DIR/$tdir/true
2830 import_file $tdir/$tfile $f
2832 local fid=$(path2fid $f)
2834 # set no retry action mode
2840 # remove no try action mode
2844 [[ $st == 0 ]] || error "Failed to exec a released file"
2848 run_test 30a "Restore at exec (import case)"
2851 # restore at exec cannot work on agent node (because of Linux kernel
2852 # protection of executables)
2853 needclients 2 || return 0
2855 # test needs a running copytool
2859 local f=$DIR/$tdir/true
2860 local fid=$(copy_file /bin/true $f)
2862 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2863 wait_request_state $fid ARCHIVE SUCCEED
2867 stack_trap cdt_clear_no_retry EXIT
2868 # set no retry action mode
2876 [[ $st == 0 ]] || error "Failed to exec a released file"
2878 run_test 30b "Restore at exec (release case)"
2881 needclients 2 || return 0
2883 # test needs a running copytool
2887 local f=$DIR/$tdir/SLEEP
2888 local slp_sum1=$(md5sum /bin/sleep)
2889 local fid=$(copy_file /bin/sleep $f)
2891 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2892 wait_request_state $fid ARCHIVE SUCCEED
2894 check_hsm_flags $f "0x0000000d"
2896 stack_trap cdt_clear_no_retry EXIT
2897 # set no retry action mode
2900 do_node $CLIENT2 "$f 10" &
2904 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2906 [[ $? == 0 ]] || error "Execution failed during run"
2908 if [[ $? != 0 ]]; then
2909 local slp_sum2=$(md5sum /bin/sleep)
2910 # in case sleep file is modified during the test
2911 [[ $slp_sum1 == $slp_sum2 ]] &&
2912 error "Binary overwritten during exec"
2915 check_hsm_flags $f "0x00000009"
2917 run_test 30c "Update during exec of released file must fail"
2919 restore_and_check_size() {
2922 local s=$(stat -c "%s" $f)
2924 local st=$(get_hsm_flags $f)
2928 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2930 n=$(stat -c "%s" $f)
2931 # we echo in both cases to show stat is not hang
2932 if [[ $n != $s ]]; then
2933 echo "size seen is $n != $s"
2936 echo "size seen is right: $n == $s"
2940 st=$(get_hsm_flags $f)
2942 if [[ "$st" = "0x00000009" ]]; then
2945 echo " restore is too long"
2946 wait_request_state $fid RESTORE SUCCEED
2952 # test needs a running copytool
2955 create_archive_file $tdir/$tfile
2956 local f=$DIR/$tdir/$tfile
2957 import_file $tdir/$tfile $f
2958 local fid=$($LFS path2fid $f)
2959 HSM_ARCHIVE_PURGE=false copytool_setup
2961 restore_and_check_size $f $fid
2964 [[ $err -eq 0 ]] || error "File size changed during restore"
2968 run_test 31a "Import a large file and check size during restore"
2972 # test needs a running copytool
2975 local f=$DIR/$tdir/$tfile
2977 fid=$(make_custom_file_for_progress $f 39 1000000)
2978 [ $? != 0 ] && skip "not enough free space" && return
2980 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2981 wait_request_state $fid ARCHIVE SUCCEED
2984 restore_and_check_size $f $fid
2987 [[ $err -eq 0 ]] || error "File size changed during restore"
2989 run_test 31b "Restore a large unaligned file and check size during restore"
2992 # test needs a running copytool
2995 local f=$DIR/$tdir/$tfile
2997 fid=$(make_custom_file_for_progress $f 33 1048576)
2998 [ $? != 0 ] && skip "not enough free space" && return
3000 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3001 wait_request_state $fid ARCHIVE SUCCEED
3004 restore_and_check_size $f $fid
3007 [[ $err -eq 0 ]] || error "File size changed during restore"
3009 run_test 31c "Restore a large aligned file and check size during restore"
3012 # test needs a running copytool
3015 local f=$DIR/$tdir/$tfile
3017 fid=$(make_custom_file_for_progress $f 39 1000000)
3018 [ $? != 0 ] && skip "not enough free space" && return
3020 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3021 wait_request_state $fid ARCHIVE SUCCEED
3024 # to be sure wait_all_done will not be mislead by previous tests
3027 wait_for_grace_delay
3028 # Also raise grace_delay significantly so the Canceled
3029 # Restore action will stay enough long avail.
3030 local old_grace=$(get_hsm_param grace_delay)
3031 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3032 set_hsm_param grace_delay 100
3034 md5sum $f >/dev/null &
3036 wait_request_state $fid RESTORE STARTED
3041 # Check restore trigger process was killed
3042 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3046 # instead of waiting+checking both Restore and Cancel ops
3047 # sequentially, wait for both to be finished and then check
3049 wait_all_done 100 $fid
3050 local rstate=$(get_request_state $fid RESTORE)
3051 local cstate=$(get_request_state $fid CANCEL)
3053 if [[ "$rstate" == "CANCELED" ]] ; then
3054 [[ "$cstate" == "SUCCEED" ]] ||
3055 error "Restore state is CANCELED and Cancel state " \
3056 "is not SUCCEED but $cstate"
3057 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3058 elif [[ "$rstate" == "SUCCEED" ]] ; then
3059 [[ "$cstate" == "FAILED" ]] ||
3060 error "Restore state is SUCCEED and Cancel state " \
3061 "is not FAILED but $cstate"
3062 echo "Restore state is SUCCEED, Cancel state is FAILED"
3064 error "Restore state is $rstate and Cancel state is $cstate"
3068 error "Cannot kill process waiting for restore ($killed)"
3070 run_test 33 "Kill a restore waiting process"
3073 # test needs a running copytool
3076 local f=$DIR/$tdir/$tfile
3078 fid=$(make_custom_file_for_progress $f 39 1000000)
3079 [ $? != 0 ] && skip "not enough free space" && return
3081 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3082 wait_request_state $fid ARCHIVE SUCCEED
3085 md5sum $f >/dev/null &
3087 wait_request_state $fid RESTORE STARTED
3089 rm $f || error "rm $f failed"
3090 # rm must not block during restore
3091 wait_request_state $fid RESTORE STARTED
3093 wait_request_state $fid RESTORE SUCCEED
3094 # check md5sum pgm finished
3095 local there=$(ps -o pid,comm hp $pid >/dev/null)
3096 [[ -z $there ]] || error "Restore initiator does not exit"
3098 wait $pid || error "Restore initiator failed with $?"
3100 run_test 34 "Remove file during restore"
3103 # test needs a running copytool
3106 local f=$DIR/$tdir/$tfile
3107 local f1=$DIR/$tdir/$tfile-1
3109 fid=$(make_custom_file_for_progress $f 39 1000000)
3110 [ $? != 0 ] && skip "not enough free space" && return
3112 local fid1=$(copy_file /etc/passwd $f1)
3113 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3114 wait_request_state $fid ARCHIVE SUCCEED
3117 md5sum $f >/dev/null &
3119 wait_request_state $fid RESTORE STARTED
3121 mv $f1 $f || error "mv $f1 $f failed"
3122 # mv must not block during restore
3123 wait_request_state $fid RESTORE STARTED
3125 wait_request_state $fid RESTORE SUCCEED
3126 # check md5sum pgm finished
3127 local there=$(ps -o pid,comm hp $pid >/dev/null)
3128 [[ -z $there ]] || error "Restore initiator does not exit"
3130 wait $pid || error "Restore initiator failed with $?"
3133 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3135 run_test 35 "Overwrite file during restore"
3138 # test needs a running copytool
3141 local f=$DIR/$tdir/$tfile
3143 fid=$(make_custom_file_for_progress $f 39 1000000)
3144 [ $? != 0 ] && skip "not enough free space" && return
3146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3147 wait_request_state $fid ARCHIVE SUCCEED
3150 md5sum $f >/dev/null &
3152 wait_request_state $fid RESTORE STARTED
3155 # rm must not block during restore
3156 wait_request_state $fid RESTORE STARTED
3158 wait_request_state $fid RESTORE SUCCEED
3159 # check md5sum pgm finished
3160 local there=$(ps -o pid,comm hp $pid >/dev/null)
3162 error "Restore initiator does not exit"
3164 wait $pid || error "Restore initiator failed with $?"
3166 run_test 36 "Move file during restore"
3169 # LU-5683: check that an archived dirty file can be rearchived.
3172 local f=$DIR/$tdir/$tfile
3175 fid=$(create_small_file $f) || error "cannot create small file"
3177 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3178 wait_request_state $fid ARCHIVE SUCCEED
3179 $LFS hsm_release $f || error "cannot release $f"
3181 # Allow previous archive request to expire from the actions log.
3182 wait_for_grace_delay
3185 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3187 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3188 wait_request_state $fid ARCHIVE SUCCEED
3190 run_test 37 "re-archive a dirty file"
3197 for n in $(seq 1 $count); do
3198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3200 echo "$count archive requests submitted"
3204 local stream_count=4
3205 local file_count=100
3207 local f=$DIR/$tdir/$tfile
3211 local max_requests=$(get_hsm_param max_requests)
3213 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3214 # Increase the number of HSM request that can be performed in
3215 # parallel. With the coordinator running once per second, this
3216 # also limits the number of requests per seconds that can be
3217 # performed, so we pick a decent number. But we also need to keep
3218 # that number low because the copytool has no rate limit and will
3219 # fail some requests if if gets too many at once.
3220 set_hsm_param max_requests 300
3222 for i in $(seq 1 $file_count); do
3223 for p in $(seq 1 $stream_count); do
3224 fid=$(copy_file /etc/hosts $f.$p.$i)
3230 # to be sure wait_all_done will not be mislead by previous tests
3232 wait_for_grace_delay
3234 # start archive streams in background (archive files in parallel)
3235 for p in $(seq 1 $stream_count); do
3236 multi_archive $f.$p $file_count &
3239 echo -n "Wait for all requests being enqueued..."
3244 run_test 40 "Parallel archive requests"
3247 # test needs a running copytool
3251 local f=$DIR/$tdir/$tfile
3252 local fid=$(create_small_file $f)
3254 $LFS hsm_archive $f || error "could not archive file"
3255 wait_request_state $fid ARCHIVE SUCCEED
3256 check_hsm_flags $f "0x00000009"
3258 multiop_bg_pause $f O_c || error "multiop failed"
3262 client_up || client_up || true
3264 kill -USR1 $MULTIPID
3265 wait $MULTIPID || error "multiop close failed"
3267 check_hsm_flags $f "0x0000000b"
3269 run_test 52 "Opened for write file on an evicted client should be set dirty"
3272 # test needs a running copytool
3276 local f=$DIR/$tdir/$tfile
3277 local fid=$(create_small_file $f)
3279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3280 error "could not archive file"
3281 wait_request_state $fid ARCHIVE SUCCEED
3282 check_hsm_flags $f "0x00000009"
3284 multiop_bg_pause $f o_c || error "multiop failed"
3288 client_up || client_up || true
3290 kill -USR1 $MULTIPID
3291 wait $MULTIPID || error "multiop close failed"
3293 check_hsm_flags $f "0x00000009"
3295 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3298 # test needs a running copytool
3301 local f=$DIR/$tdir/$tfile
3302 local fid=$(make_custom_file_for_progress $f 39 1000000)
3304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3305 error "could not archive file"
3306 wait_request_state $fid ARCHIVE STARTED
3308 check_hsm_flags $f "0x00000001"
3310 stack_trap "cdt_clear_no_retry" EXIT
3311 # Avoid coordinator resending this request as soon it has failed.
3316 wait_request_state $fid ARCHIVE FAILED
3318 check_hsm_flags $f "0x00000003"
3320 run_test 54 "Write during an archive cancels it"
3323 # test needs a running copytool
3326 local f=$DIR/$tdir/$tfile
3327 local fid=$(make_custom_file_for_progress $f 39 1000000)
3329 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3330 error "could not archive file"
3331 wait_request_state $fid ARCHIVE STARTED
3333 check_hsm_flags $f "0x00000001"
3335 stack_trap "cdt_clear_no_retry" EXIT
3336 # Avoid coordinator resending this request as soon it has failed.
3339 $TRUNCATE $f 1024 || error "truncate failed"
3341 wait_request_state $fid ARCHIVE FAILED
3343 check_hsm_flags $f "0x00000003"
3345 run_test 55 "Truncate during an archive cancels it"
3348 # test needs a running copytool
3351 local f=$DIR/$tdir/$tfile
3353 fid=$(make_custom_file_for_progress $f 39 1000000)
3354 [ $? != 0 ] && skip "not enough free space" && return
3356 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3357 error "could not archive file"
3358 wait_request_state $fid ARCHIVE STARTED
3360 check_hsm_flags $f "0x00000001"
3362 # Change metadata and sync to be sure we are not changing only
3367 wait_request_state $fid ARCHIVE SUCCEED
3369 check_hsm_flags $f "0x00000009"
3371 run_test 56 "Setattr during an archive is ok"
3374 # Need one client for I/O, one for request
3375 needclients 2 || return 0
3377 # test needs a running copytool
3381 local f=$DIR/$tdir/test_archive_remote
3382 # Create a file on a remote node
3383 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3384 "count=2 conv=fsync"
3387 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3388 error "hsm_archive failed"
3389 local fid=$(path2fid $f)
3390 wait_request_state $fid ARCHIVE SUCCEED
3392 # Release and implicit restore it
3393 do_node $CLIENT2 "$LFS hsm_release $f" ||
3394 error "hsm_release failed"
3395 do_node $CLIENT2 "md5sum $f" ||
3396 error "hsm_restore failed"
3398 wait_request_state $fid RESTORE SUCCEED
3400 run_test 57 "Archive a file with dirty cache on another node"
3402 truncate_released_file() {
3406 local sz=$(stat -c %s $src_file)
3407 local f=$DIR/$tdir/$tfile
3408 local fid=$(copy_file $1 $f)
3412 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3413 error "could not archive file"
3414 wait_request_state $fid ARCHIVE SUCCEED
3416 $LFS hsm_release $f || error "could not release file"
3418 $TRUNCATE $f $trunc_to || error "truncate failed"
3421 local sz1=$(stat -c %s $f)
3422 [[ $sz1 == $trunc_to ]] ||
3423 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3426 check_hsm_flags $f "0x0000000b"
3428 local state=$(get_request_state $fid RESTORE)
3429 [[ "$state" == "SUCCEED" ]] ||
3430 error "truncate $sz does not trig restore, state = $state"
3432 $TRUNCATE $ref $trunc_to
3433 cmp $ref $f || error "file data wrong after truncate"
3439 # test needs a running copytool
3444 local sz=$(stat -c %s /etc/passwd)
3446 echo "truncate up from $sz to $((sz*2))"
3447 truncate_released_file /etc/passwd $((sz*2))
3449 echo "truncate down from $sz to $((sz/2))"
3450 truncate_released_file /etc/passwd $((sz/2))
3452 echo "truncate to 0"
3453 truncate_released_file /etc/passwd 0
3455 run_test 58 "Truncate a released file will trigger restore"
3459 local server_version=$(lustre_version_code $SINGLEMDS)
3460 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3461 skip "Need MDS version at least 2.7.63" && return
3464 $MCREATE $DIR/$tfile || error "mcreate failed"
3465 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3466 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3467 fid=$(path2fid $DIR/$tfile)
3468 wait_request_state $fid ARCHIVE SUCCEED
3469 $LFS hsm_release $DIR/$tfile || error "release failed"
3471 run_test 59 "Release stripeless file with non-zero size"
3474 # This test validates the fix for LU-4512. Ensure that the -u
3475 # option changes the progress reporting interval from the
3476 # default (30 seconds) to the user-specified interval.
3478 local progress_timeout=$((interval * 4))
3480 copytool setup -b 1 --update-interval $interval
3482 local f=$DIR/$tdir/$tfile
3484 fid=$(make_custom_file_for_progress $f 10)
3485 [ $? != 0 ] && skip "not enough free space" && return
3488 local mdt=${MDT_PREFIX}${mdtidx}
3489 local mds=mds$((mdtidx + 1))
3491 # Wait for copytool to register
3492 wait_update_facet $mds \
3493 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3494 uuid 100 || error "coyptool failed to register with $mdt"
3496 local start_at=$(date +%s)
3497 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3498 error "could not archive file"
3500 local agent=$(facet_active_host $SINGLEAGT)
3501 local logfile=$(copytool_logfile $SINGLEAGT)
3503 wait_update $agent \
3504 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3505 error "copytool failed to start"
3507 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3508 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3514 echo -n "Expecting a progress update within $progress_timeout seconds... "
3516 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3517 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3518 echo "$RESULT bytes copied in $WAIT seconds."
3520 elif [ $WAIT -ge $progress_timeout ]; then
3521 error "Timed out waiting for progress update!"
3524 WAIT=$((WAIT + sleep))
3528 local finish_at=$(date +%s)
3529 local elapsed=$((finish_at - start_at))
3531 # Ensure that the progress update occurred within the expected window.
3532 if [ $elapsed -lt $((interval - 1)) ]; then
3533 error "Expected progress update after at least $interval seconds"
3536 echo "Wait for on going archive hsm action to complete"
3537 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3538 echo "File archiving not completed even after 10 secs"
3540 run_test 60 "Changing progress update interval from default"
3543 # test needs a running copytool
3547 local f=$DIR/$tdir/$tfile
3548 local fid=$(copy_file /etc/passwd $f)
3550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3553 wait_request_state $fid ARCHIVE FAILED
3555 run_test 61 "Waiting archive of a removed file should fail"
3558 # test needs a new running copytool
3559 stack_trap copytool_monitor_cleanup EXIT
3560 copytool_monitor_setup
3561 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3563 # Wait for the copytool to register.
3564 wait_update --verbose $(facet_active_host mds1) \
3565 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3567 error "copytool failed to register with MDT0000"
3570 wait_copytools || error "Copytools failed to stop"
3572 local REGISTER_EVENT
3573 local UNREGISTER_EVENT
3574 while read event; do
3575 local parsed=$(parse_json_event "$event")
3576 if [ -z "$parsed" ]; then
3577 error "Copytool sent malformed event: $event"
3581 if [ $event_type == "REGISTER" ]; then
3582 REGISTER_EVENT=$event
3583 elif [ $event_type == "UNREGISTER" ]; then
3584 UNREGISTER_EVENT=$event
3586 done < <(echo $"$(get_copytool_event_log)")
3588 if [ -z "$REGISTER_EVENT" ]; then
3589 error "Copytool failed to send register event to FIFO"
3592 if [ -z "$UNREGISTER_EVENT" ]; then
3593 error "Copytool failed to send unregister event to FIFO"
3596 echo "Register/Unregister events look OK."
3598 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3601 # Bump progress interval for livelier events.
3604 # test needs a new running copytool
3605 stack_trap copytool_monitor_cleanup EXIT
3606 copytool_monitor_setup
3607 copytool setup --update-interval $interval --event-fifo \
3608 "$HSMTOOL_MONITOR_DIR/fifo"
3610 stack_trap "cdt_clear_no_retry" EXIT
3611 # Just start and stop the copytool to generate events.
3614 local f=$DIR/$tdir/$tfile
3616 fid=$(make_custom_file_for_progress $f 39 1000000)
3617 [ $? != 0 ] && skip "not enough free space" && return
3619 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3620 error "could not archive file"
3621 wait_request_state $fid ARCHIVE SUCCEED
3623 local expected_fields="event_time data_fid source_fid"
3624 expected_fields+=" total_bytes current_bytes"
3628 while read event; do
3629 # Make sure we're not getting anything from previous events.
3630 for field in $expected_fields; do
3634 local parsed=$(parse_json_event "$event")
3635 if [ -z "$parsed" ]; then
3636 error "Copytool sent malformed event: $event"
3640 if [ $event_type == "ARCHIVE_START" ]; then
3643 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3646 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3650 # Do some simple checking of the progress update events.
3651 for expected_field in $expected_fields; do
3652 if [ -z ${!expected_field+x} ]; then
3653 error "Missing $expected_field field in event"
3657 if [ $total_bytes -eq 0 ]; then
3658 error "Expected total_bytes to be > 0"
3661 # These should be identical throughout an archive
3663 if [ $source_fid != $data_fid ]; then
3664 error "Expected source_fid to equal data_fid"
3666 done < <(echo $"$(get_copytool_event_log)")
3668 if [ -z "$START_EVENT" ]; then
3669 error "Copytool failed to send archive start event to FIFO"
3672 if [ -z "$FINISH_EVENT" ]; then
3673 error "Copytool failed to send archive finish event to FIFO"
3676 echo "Archive events look OK."
3678 run_test 71 "Copytool logs JSON archive events to FIFO"
3681 # Bump progress interval for livelier events.
3684 # test needs a new running copytool
3686 copytool_monitor_setup
3687 HSMTOOL_UPDATE_INTERVAL=$interval \
3688 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3689 local test_file=$HSMTOOL_MONITOR_DIR/file
3691 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3693 do_facet $SINGLEAGT "$cmd" ||
3694 error "cannot create $test_file on $SINGLEAGT"
3695 copy2archive $test_file $tdir/$tfile
3698 local f=$DIR/$tdir/$tfile
3699 import_file $tdir/$tfile $f
3700 f=$DIR2/$tdir/$tfile
3701 echo "Verifying released state: "
3702 check_hsm_flags $f "0x0000000d"
3704 local fid=$(path2fid $f)
3706 wait_request_state $fid RESTORE SUCCEED
3708 local expected_fields="event_time data_fid source_fid"
3709 expected_fields+=" total_bytes current_bytes"
3713 while read event; do
3714 # Make sure we're not getting anything from previous events.
3715 for field in $expected_fields; do
3719 local parsed=$(parse_json_event "$event")
3720 if [ -z "$parsed" ]; then
3721 error "Copytool sent malformed event: $event"
3725 if [ $event_type == "RESTORE_START" ]; then
3727 if [ $source_fid != $data_fid ]; then
3728 error "source_fid should == data_fid at start"
3731 elif [ $event_type == "RESTORE_FINISH" ]; then
3733 if [ $source_fid != $data_fid ]; then
3734 error "source_fid should == data_fid at finish"
3737 elif [ $event_type != "RESTORE_RUNNING" ]; then
3741 # Do some simple checking of the progress update events.
3742 for expected_field in $expected_fields; do
3743 if [ -z ${!expected_field+x} ]; then
3744 error "Missing $expected_field field in event"
3748 if [ $total_bytes -eq 0 ]; then
3749 error "Expected total_bytes to be > 0"
3752 # When a restore starts out, the data fid is the same as the
3753 # source fid. After the restore has gotten going, we learn
3754 # the new data fid. Once the restore has finished, the source
3755 # fid is set to the new data fid.
3757 # We test this because some monitoring software may depend on
3758 # this behavior. If it changes, then the consumers of these
3759 # events may need to be modified.
3760 if [ $source_fid == $data_fid ]; then
3761 error "source_fid should != data_fid during restore"
3763 done < <(echo $"$(get_copytool_event_log)")
3765 if [ -z "$START_EVENT" ]; then
3766 error "Copytool failed to send restore start event to FIFO"
3769 if [ -z "$FINISH_EVENT" ]; then
3770 error "Copytool failed to send restore finish event to FIFO"
3773 echo "Restore events look OK."
3777 copytool_monitor_cleanup
3781 run_test 72 "Copytool logs JSON restore events to FIFO"
3784 file_count=51 # Max number of files constrained by LNET message size
3785 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3786 local f=$DIR/$tdir/$tfile
3787 local FILELIST=/tmp/filelist.txt
3791 for i in $(seq 1 $file_count); do
3792 fid=$(copy_file /etc/hosts $f.$i)
3793 echo $f.$i >> $FILELIST
3797 # to be sure wait_all_done will not be mislead by previous tests
3799 wait_for_grace_delay
3800 $LFS hsm_archive --filelist $FILELIST ||
3801 error "cannot archive a file list"
3803 $LFS hsm_release --filelist $FILELIST ||
3804 error "cannot release a file list"
3805 $LFS hsm_restore --filelist $FILELIST ||
3806 error "cannot restore a file list"
3809 run_test 90 "Archive/restore a file list"
3811 double_verify_reset_hsm_param() {
3813 echo "Testing $HSM_PARAM.$p"
3814 local val=$(get_hsm_param $p)
3816 local val2=$(($val * 2))
3817 set_hsm_param $p $val2
3818 val=$(get_hsm_param $p)
3819 [[ $val == $val2 ]] ||
3820 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3821 echo "Set $p to 0 must failed"
3825 set_hsm_param $p $save
3827 if [[ $rc == 0 ]]; then
3828 error "we must not be able to set $HSM_PARAM.$p to 0"
3833 double_verify_reset_hsm_param loop_period
3834 double_verify_reset_hsm_param grace_delay
3835 double_verify_reset_hsm_param active_request_timeout
3836 double_verify_reset_hsm_param max_requests
3837 double_verify_reset_hsm_param default_archive_id
3839 run_test 100 "Set coordinator /proc tunables"
3846 run_test 102 "Verify coordinator control"
3849 # test needs a running copytool
3856 for i in $(seq 1 20); do
3857 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3859 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3863 echo "Current requests"
3864 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3865 $HSM_PARAM.actions |\
3866 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3868 [[ -z "$res" ]] || error "Some request have not been canceled"
3870 run_test 103 "Purge all requests"
3875 local f=$DIR/$tdir/$tfile
3877 fid=$(make_custom_file_for_progress $f 39 1000000)
3878 [ $? != 0 ] && skip "not enough free space" && return
3880 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3881 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3882 $HSM_PARAM.actions |\
3883 grep $fid | cut -f16 -d=")
3885 [[ "$data1" == "$DATAHEX" ]] ||
3886 error "Data field in records is ($data1) and not ($DATAHEX)"
3891 wait_request_state $fid ARCHIVE SUCCEED
3893 run_test 104 "Copy tool data field"
3896 local max_requests=$(get_hsm_param max_requests)
3900 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3901 set_hsm_param max_requests 300
3904 for i in $(seq -w 1 10); do
3905 cp /etc/passwd $DIR/$tdir/$i
3906 $LFS hsm_archive $DIR/$tdir/$i
3908 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3909 $HSM_PARAM.actions |\
3910 grep WAITING | wc -l")
3914 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3915 $HSM_PARAM.actions |\
3916 grep WAITING | wc -l")
3919 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3920 error "Requests count after shutdown $reqcnt2 != "\
3921 "before shutdown $reqcnt1"
3923 run_test 105 "Restart of coordinator"
3926 # test needs a running copytool
3929 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3931 check_agent_registered $uuid
3933 search_copytools || error "No copytool found"
3936 wait_copytools || error "Copytool failed to stop"
3938 check_agent_unregistered $uuid
3941 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3942 check_agent_registered $uuid
3944 run_test 106 "Copytool register/unregister"
3947 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3949 # test needs a running copytool
3951 # create and archive file
3953 local f1=$DIR/$tdir/$tfile
3954 local fid=$(copy_file /etc/passwd $f1)
3955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3956 wait_request_state $fid ARCHIVE SUCCEED
3957 # shutdown and restart MDS
3959 # check the copytool still gets messages from MDT
3960 local f2=$DIR/$tdir/2
3961 local fid=$(copy_file /etc/passwd $f2)
3962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3963 # main check of this sanity: this request MUST succeed
3964 wait_request_state $fid ARCHIVE SUCCEED
3966 run_test 107 "Copytool re-register after MDS restart"
3968 policy_set_and_test()
3972 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3973 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3974 [[ "$policy" == "$target" ]] ||
3975 error "Wrong policy after '$change': '$policy' != '$target'"
3979 # to force default policy setting if error
3980 CDT_POLICY_HAD_CHANGED=true
3982 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3983 local default="NonBlockingRestore [NoRetryAction]"
3984 [[ "$policy" == "$default" ]] ||
3985 error "default policy has changed,"\
3986 " '$policy' != '$default' update the test"
3987 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3988 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3989 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3990 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3991 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3992 # useless bacause we know but safer for futur changes to use real value
3993 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3994 echo "Next set_param must failed"
3995 policy_set_and_test "wrong" "$policy"
3998 echo "Back to default policy"
3999 cdt_set_sanity_policy
4001 run_test 109 "Policy display/change"
4004 # test needs a running copytool
4009 copy2archive /etc/passwd $tdir/$tfile
4011 local f=$DIR/$tdir/$tfile
4012 import_file $tdir/$tfile $f
4013 local fid=$(path2fid $f)
4015 cdt_set_non_blocking_restore
4020 wait_request_state $fid RESTORE SUCCEED
4021 cdt_clear_non_blocking_restore
4025 error "md5sum returns $st != 1, "\
4026 "should also perror ENODATA (No data available)"
4028 run_test 110a "Non blocking restore policy (import case)"
4031 # test needs a running copytool
4035 local f=$DIR/$tdir/$tfile
4036 local fid=$(copy_file /etc/passwd $f)
4037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4038 wait_request_state $fid ARCHIVE SUCCEED
4041 cdt_set_non_blocking_restore
4046 wait_request_state $fid RESTORE SUCCEED
4047 cdt_clear_non_blocking_restore
4051 error "md5sum returns $st != 1, "\
4052 "should also perror ENODATA (No data available)"
4054 run_test 110b "Non blocking restore policy (release case)"
4057 # test needs a running copytool
4061 copy2archive /etc/passwd $tdir/$tfile
4063 local f=$DIR/$tdir/$tfile
4065 import_file $tdir/$tfile $f
4066 local fid=$(path2fid $f)
4070 copytool_remove_backend $fid
4073 wait_request_state $fid RESTORE FAILED
4080 [[ $st == 0 ]] || error "Restore does not failed"
4084 run_test 111a "No retry policy (import case), restore will error"\
4085 " (No such file or directory)"
4088 # test needs a running copytool
4092 local f=$DIR/$tdir/$tfile
4093 local fid=$(copy_file /etc/passwd $f)
4095 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4096 wait_request_state $fid ARCHIVE SUCCEED
4099 copytool_remove_backend $fid
4102 wait_request_state $fid RESTORE FAILED
4109 [[ $st == 0 ]] || error "Restore does not failed"
4113 run_test 111b "No retry policy (release case), restore will error"\
4114 " (No such file or directory)"
4117 # test needs a running copytool
4121 local f=$DIR/$tdir/$tfile
4122 local fid=$(copy_file /etc/passwd $f)
4124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4125 local l=$($LFS hsm_action $f)
4127 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4130 wait_request_state $fid ARCHIVE SUCCEED
4133 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4135 run_test 112 "State of recorded request"
4138 # test needs a running copytool
4141 local f=$DIR/$tdir/$tfile
4143 fid=$(make_custom_file_for_progress $f 103 1048576)
4144 [ $? != 0 ] && skip "not enough free space" && return
4146 # test with cdt on is made in test_221
4148 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4149 # wait archive to register at CDT
4150 wait_request_state $fid ARCHIVE WAITING
4153 wait_request_state $fid ARCHIVE CANCELED
4154 wait_request_state $fid CANCEL SUCCEED
4156 run_test 200 "Register/Cancel archive"
4159 # test needs a running copytool
4162 local f=$DIR/$tdir/$tfile
4163 create_archive_file $tdir/$tfile
4164 import_file $tdir/$tfile $f
4165 local fid=$(path2fid $f)
4167 # test with cdt on is made in test_222
4170 # wait restore to register at CDT
4171 wait_request_state $fid RESTORE WAITING
4174 wait_request_state $fid RESTORE CANCELED
4175 wait_request_state $fid CANCEL SUCCEED
4179 run_test 201 "Register/Cancel restore"
4182 # test needs a running copytool
4185 local f=$DIR/$tdir/$tfile
4187 fid=$(make_custom_file_for_progress $f 39 1000000)
4188 [ $? != 0 ] && skip "not enough free space" && return
4190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4191 wait_request_state $fid ARCHIVE SUCCEED
4195 # wait remove to register at CDT
4196 wait_request_state $fid REMOVE WAITING
4199 wait_request_state $fid REMOVE CANCELED
4201 run_test 202 "Register/Cancel remove"
4203 test_220A() { # was test_220
4204 # test needs a running copytool
4209 local f=$DIR/$tdir/$tfile
4210 local fid=$(copy_file /etc/passwd $f)
4214 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4215 wait_request_state $fid ARCHIVE SUCCEED
4217 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4221 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4223 run_test 220A "Changelog for archive"
4226 # test needs a running copytool
4231 local f=$DIR/$tdir/$tfile
4232 local fid=$(copy_file /etc/passwd $f)
4236 # block copytool operations to allow for HSM request to be
4237 # submitted and file be unlinked (CDT will find object removed)
4240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4242 # wait request to reach CT
4243 wait_request_state $fid ARCHIVE STARTED
4249 wait_request_state $fid ARCHIVE FAILED
4251 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4256 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4258 run_test 220a "Changelog for failed archive"
4261 # test needs a running copytool
4264 local f=$DIR/$tdir/$tfile
4266 fid=$(make_custom_file_for_progress $f 103 1048576)
4267 [ $? != 0 ] && skip "not enough free space" && return
4271 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4272 wait_request_state $fid ARCHIVE STARTED
4274 wait_request_state $fid ARCHIVE CANCELED
4275 wait_request_state $fid CANCEL SUCCEED
4277 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4280 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4282 run_test 221 "Changelog for archive canceled"
4285 # test needs a running copytool
4289 copy2archive /etc/passwd $tdir/$tfile
4291 local f=$DIR/$tdir/$tfile
4292 import_file $tdir/$tfile $f
4293 local fid=$(path2fid $f)
4298 wait_request_state $fid RESTORE SUCCEED
4300 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4303 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4307 run_test 222a "Changelog for explicit restore"
4310 # test needs a running copytool
4314 local f=$DIR/$tdir/$tfile
4315 local fid=$(copy_file /etc/passwd $f)
4318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4319 wait_request_state $fid ARCHIVE SUCCEED
4324 wait_request_state $fid RESTORE SUCCEED
4326 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4329 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4331 run_test 222b "Changelog for implicit restore"
4334 # test needs a running copytool
4338 copy2archive /etc/passwd $tdir/$tfile
4340 local f=$DIR/$tdir/$tfile
4341 import_file $tdir/$tfile $f
4342 local fid=$(path2fid $f)
4346 # block copytool operations to allow for HSM request to be
4347 # submitted and file be unlinked (CDT will find object removed)
4352 # wait request to reach CT
4353 wait_request_state $fid RESTORE STARTED
4359 wait_request_state $fid RESTORE FAILED
4361 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4365 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4369 run_test 222c "Changelog for failed explicit restore"
4372 # test needs a running copytool
4376 local f=$DIR/$tdir/$tfile
4377 local fid=$(copy_file /etc/passwd $f)
4380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4381 wait_request_state $fid ARCHIVE SUCCEED
4384 copytool_remove_backend $fid
4387 wait_request_state $fid RESTORE FAILED
4389 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4393 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4397 run_test 222d "Changelog for failed implicit restore"
4400 # test needs a running copytool
4403 local f=$DIR/$tdir/$tfile
4404 create_archive_file $tdir/$tfile
4408 import_file $tdir/$tfile $f
4409 local fid=$(path2fid $f)
4412 wait_request_state $fid RESTORE STARTED
4414 wait_request_state $fid RESTORE CANCELED
4415 wait_request_state $fid CANCEL SUCCEED
4417 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4420 [[ $flags == $target ]] ||
4421 error "Changelog flag is $flags not $target"
4425 run_test 223a "Changelog for restore canceled (import case)"
4428 # test needs a running copytool
4431 local f=$DIR/$tdir/$tfile
4433 fid=$(make_custom_file_for_progress $f 39 1000000)
4434 [ $? != 0 ] && skip "not enough free space" && return
4437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4438 wait_request_state $fid ARCHIVE SUCCEED
4441 wait_request_state $fid RESTORE STARTED
4443 wait_request_state $fid RESTORE CANCELED
4444 wait_request_state $fid CANCEL SUCCEED
4446 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4449 [[ $flags == $target ]] ||
4450 error "Changelog flag is $flags not $target"
4454 run_test 223b "Changelog for restore canceled (release case)"
4456 test_224A() { # was test_224
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
4470 wait_request_state $fid REMOVE SUCCEED
4472 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4475 [[ $flags == $target ]] ||
4476 error "Changelog flag is $flags not $target"
4478 run_test 224A "Changelog for remove"
4481 # test needs a running copytool
4486 local f=$DIR/$tdir/$tfile
4487 local fid=$(copy_file /etc/passwd $f)
4490 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4491 wait_request_state $fid ARCHIVE SUCCEED
4493 copytool_remove_backend $fid
4495 # block copytool operations to allow for HSM request to be
4496 # submitted and file be unlinked (CDT will find object removed)
4501 # wait for request to reach CT
4502 wait_request_state $fid REMOVE STARTED
4508 wait_request_state $fid REMOVE FAILED
4510 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4514 [[ $flags == $target ]] ||
4515 error "Changelog flag is $flags not $target"
4519 run_test 224a "Changelog for failed remove"
4522 # test needs a running copytool
4525 # test is not usable because remove request is too fast
4526 # so it is always finished before cancel can be done ...
4527 echo "Test disabled"
4531 local f=$DIR/$tdir/$tfile
4533 fid=$(make_custom_file_for_progress $f 39 1000000)
4534 [ $? != 0 ] && skip "not enough free space" && return
4537 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4538 wait_request_state $fid ARCHIVE SUCCEED
4540 # if cdt is on, it can serve too quickly the request
4545 wait_request_state $fid REMOVE CANCELED
4546 wait_request_state $fid CANCEL SUCCEED
4548 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4549 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4550 tail -n 1 | awk '{print $5}')
4553 [[ $flags == $target ]] ||
4554 error "Changelog flag is $flags not $target"
4556 run_test 225 "Changelog for remove canceled"
4559 # test needs a running copytool
4564 local f1=$DIR/$tdir/$tfile-1
4565 local f2=$DIR/$tdir/$tfile-2
4566 local f3=$DIR/$tdir/$tfile-3
4567 local fid1=$(copy_file /etc/passwd $f1)
4568 local fid2=$(copy_file /etc/passwd $f2)
4569 copy_file /etc/passwd $f3
4572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4573 wait_request_state $fid1 ARCHIVE SUCCEED
4575 $LFS hsm_archive $f2
4576 wait_request_state $fid2 ARCHIVE SUCCEED
4578 rm $f1 || error "rm $f1 failed"
4580 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4583 [[ $flags == $target ]] ||
4584 error "Changelog flag is $flags not $target"
4586 mv $f3 $f2 || error "mv $f3 $f2 failed"
4588 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4591 [[ $flags == $target ]] ||
4592 error "Changelog flag is $flags not $target"
4594 run_test 226 "changelog for last rm/mv with exiting archive"
4596 check_flags_changes() {
4604 $LFS hsm_set --$hsm_flag $f ||
4605 error "Cannot set $hsm_flag on $f"
4606 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4607 local seen=${#flags[*]}
4609 [[ $seen == $cnt ]] ||
4610 error "set $hsm_flag: Changelog events $seen != $cnt"
4611 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4612 error "set $hsm_flag: Changelog flags are "\
4613 "${flags[$((cnt - 1))]} not $target"
4615 $LFS hsm_clear --$hsm_flag $f ||
4616 error "Cannot clear $hsm_flag on $f"
4617 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4620 [[ $cnt == $seen ]] ||
4621 error "clear $hsm_flag: Changelog events $seen != $cnt"
4623 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4624 error "clear $hsm_flag: Changelog flag is "\
4625 "${flags[$((cnt - 1))]} not $target"
4629 # test needs a running copytool
4636 for i in norelease noarchive exists archived
4638 local f=$DIR/$tdir/$tfile-$i
4639 local fid=$(copy_file /etc/passwd $f)
4640 check_flags_changes $f $fid $i 0 1
4643 f=$DIR/$tdir/$tfile---lost
4644 fid=$(copy_file /etc/passwd $f)
4645 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4646 wait_request_state $fid ARCHIVE SUCCEED
4647 check_flags_changes $f $fid lost 3 1
4649 run_test 227 "changelog when explicit setting of HSM flags"
4652 # test needs a running copytool
4655 local fid=$(create_small_sync_file $DIR/$tfile)
4656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4657 wait_request_state $fid ARCHIVE SUCCEED
4659 $LFS hsm_release $DIR/$tfile
4660 check_hsm_flags $DIR/$tfile "0x0000000d"
4662 filefrag $DIR/$tfile | grep " 1 extent found" ||
4663 error "filefrag on released file must return only one extent"
4665 # only newer versions of cp detect sparse files by stat/FIEMAP
4667 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4668 error "copying $DIR/$tfile"
4669 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4671 $LFS hsm_release $DIR/$tfile
4672 check_hsm_flags $DIR/$tfile "0x0000000d"
4674 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4676 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4678 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4679 error "comparing untarred $DIR/$tfile"
4681 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4682 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4684 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4687 # test needs a running copytool
4691 local maxrequest=$(get_hsm_param max_requests)
4692 local rqcnt=$(($maxrequest * 3))
4696 for i in $(seq -w 1 $rqcnt); do
4698 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4700 # we do it in 2 steps, so all requests arrive at the same time
4701 for i in $(seq -w 1 $rqcnt); do
4702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4707 while [[ $cnt != 0 || $wt != 0 ]]; do
4709 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4710 $HSM_PARAM.actions |\
4711 grep STARTED | grep -v CANCEL | wc -l")
4712 [[ $cnt -le $maxrequest ]] ||
4713 error "$cnt > $maxrequest too many started requests"
4714 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4715 $HSM_PARAM.actions |\
4716 grep WAITING | wc -l")
4717 echo "max=$maxrequest started=$cnt waiting=$wt"
4720 run_test 250 "Coordinator max request"
4723 # test needs a running copytool
4726 local f=$DIR/$tdir/$tfile
4728 fid=$(make_custom_file_for_progress $f 103 1048576)
4729 [ $? != 0 ] && skip "not enough free space" && return
4732 # to have a short test
4733 local old_to=$(get_hsm_param active_request_timeout)
4734 set_hsm_param active_request_timeout 4
4735 # to be sure the cdt will wake up frequently so
4736 # it will be able to cancel the "old" request
4737 local old_loop=$(get_hsm_param loop_period)
4738 set_hsm_param loop_period 2
4741 # clear locks to avoid extra delay caused by flush/cancel
4742 # and thus prevent early copytool death to timeout.
4743 cancel_lru_locks osc
4745 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4746 wait_request_state $fid ARCHIVE STARTED
4748 wait_request_state $fid ARCHIVE CANCELED
4750 set_hsm_param active_request_timeout $old_to
4751 set_hsm_param loop_period $old_loop
4753 run_test 251 "Coordinator request timeout"
4757 local f=$DIR/$tdir/$tfile
4758 local fid=$(create_empty_file "$f")
4760 # to have a short test
4761 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4762 set_hsm_param loop_period 1
4767 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4768 wait_request_state $fid ARCHIVE STARTED
4771 stack_trap "set_hsm_param active_request_timeout \
4772 $(get_hsm_param active_request_timeout)" EXIT
4773 set_hsm_param active_request_timeout 1
4775 wait_request_state $fid ARCHIVE CANCELED
4778 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4782 # test needs a running copytool
4786 local f=$DIR/$tdir/$tfile
4788 dd if=/dev/zero of=$f bs=1MB count=10
4789 local fid=$(path2fid $f)
4791 $LFS hsm_archive $f || error "could not archive file"
4792 wait_request_state $fid ARCHIVE SUCCEED
4794 # clear locks to discard inode data
4795 cancel_lru_locks osc
4797 #define OBD_FAIL_MDC_MERGE 0x807
4798 $LCTL set_param fail_loc=0x807
4800 #expect error here, instead of release with wrong size
4803 if ((rc == 0)); then
4804 file_size=$(stat -c '%s' $f)
4805 if ((file_size != 10485760)); then
4806 error "Wrong file size after hsm_release"
4809 echo "could not release file"
4812 run_test 253 "Check for wrong file size after release"
4816 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4817 skip "need MDS version at least 2.10.56" && return
4819 # Check that the counters are initialized to 0
4821 for request_type in archive restore remove; do
4822 count="$(get_hsm_param ${request_type}_count)" ||
4823 error "Reading ${request_type}_count failed with $?"
4825 [ "$count" -eq 0 ] ||
4826 error "Expected ${request_type}_count to be " \
4830 run_test 254a "Request counters are initialized to zero"
4834 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4835 skip "need MDS version at least 2.10.56" && return
4837 # The number of request to launch (at least 32)
4838 local request_count=$((RANDOM % 32 + 32))
4839 printf "Will launch %i requests of each type\n" "$request_count"
4841 # Launch a copytool to process requests
4844 # Set hsm.max_requests to allow starting all requests at the same time
4846 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4847 set_hsm_param max_requests "$request_count"
4851 for request_type in archive restore remove; do
4852 printf "Checking %s requests\n" "${request_type}"
4853 # Suspend the copytool to give us time to read the proc files
4856 for ((i = 0; i < $request_count; i++)); do
4857 case $request_type in
4859 create_empty_file "$DIR/$tdir/$tfile-$i" \
4863 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4866 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4869 # Give the coordinator 10 seconds to start every request
4871 while get_hsm_param actions | grep -q WAITING; do
4874 [ $timeout -gt 0 ] ||
4875 error "${request_type^} requests took too " \
4879 count="$(get_hsm_param ${request_type}_count)"
4880 [ "$count" -eq "$request_count" ] ||
4881 error "Expected '$request_count' (!= '$count') " \
4882 "active $request_type requests"
4884 # Let the copytool process the requests
4886 # Give it 10 seconds maximum
4888 while get_hsm_param actions | grep -q STARTED; do
4891 [ $timeout -gt 0 ] ||
4892 error "${request_type^} requests took too " \
4896 count="$(get_hsm_param ${request_type}_count)"
4897 [ "$count" -eq 0 ] ||
4898 error "Expected 0 (!= '$count') " \
4899 "active $request_type requests"
4902 run_test 254b "Request counters are correctly incremented and decremented"
4905 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4907 # the only way to test ondisk conf is to restart MDS ...
4908 echo "Stop coordinator and remove coordinator state at mount"
4911 # clean on disk conf set by default
4912 cdt_clear_mount_state
4913 cdt_check_state stopped
4915 # check cdt still off after umount/remount
4917 cdt_check_state stopped
4919 echo "Set coordinator start at mount, and start coordinator"
4920 cdt_set_mount_state enabled
4923 cdt_check_state enabled
4925 # check cdt still on after umount/remount
4927 cdt_check_state enabled
4929 # we are back to original state (cdt started at mount)
4931 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4934 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4936 local ai=$(get_hsm_param default_archive_id)
4937 local new=$((ai + 1))
4939 set_hsm_param default_archive_id $new -P
4941 local res=$(get_hsm_param default_archive_id)
4944 set_hsm_param default_archive_id "" "-P -d"
4946 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4948 run_test 301 "HSM tunnable are persistent"
4951 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4953 local ai=$(get_hsm_param default_archive_id)
4954 local new=$((ai + 1))
4959 set_hsm_param default_archive_id $new -P
4962 for mdtno in $(seq 1 $MDSCOUNT); do
4967 cdt_check_state enabled
4969 local res=$(get_hsm_param default_archive_id)
4972 set_hsm_param default_archive_id "" "-P -d"
4974 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4976 run_test 302 "HSM tunnable are persistent when CDT is off"
4979 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4985 local dir_mdt0=$DIR/$tdir/mdt0
4986 local dir_mdt1=$DIR/$tdir/mdt1
4988 # create 1 dir per MDT
4989 stack_trap "rm -rf $dir_mdt0"
4990 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4991 stack_trap "rm -rf $dir_mdt1"
4992 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4994 # create 1 file in each MDT
4995 local fid1=$(create_small_file $dir_mdt0/$tfile)
4996 local fid2=$(create_small_file $dir_mdt1/$tfile)
4998 # check that hsm request on mdt0 is sent to the right MDS
4999 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5000 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5001 echo "archive successful on mdt0"
5003 # check that hsm request on mdt1 is sent to the right MDS
5004 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5005 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5006 echo "archive successful on mdt1"
5008 run_test 400 "Single request is sent to the right MDT"
5011 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5017 local dir_mdt0=$DIR/$tdir/mdt0
5018 local dir_mdt1=$DIR/$tdir/mdt1
5020 # create 1 dir per MDT
5021 stack_trap "rm -rf $dir_mdt0" EXIT
5022 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5023 stack_trap "rm -rf $dir_mdt1" EXIT
5024 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5026 # create 1 file in each MDT
5027 local fid1=$(create_small_file $dir_mdt0/$tfile)
5028 local fid2=$(create_small_file $dir_mdt1/$tfile)
5030 # check that compound requests are shunt to the rights MDTs
5031 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5032 error "lfs hsm_archive"
5033 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5034 echo "archive successful on mdt0"
5035 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5036 echo "archive successful on mdt1"
5038 run_test 401 "Compound requests split and sent to their respective MDTs"
5040 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5045 local node=$(facet_active_host $facet)
5047 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5048 awk '{print $4}'); do
5049 echo "$3 $mdc on $node"
5050 do_facet $facet "$LCTL --device $mdc $state" || return 1
5055 # deactivate all mdc on agent1
5056 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5058 copytool setup --no-fail
5060 check_agent_unregistered "uuid" # match any agent
5062 # no expected running copytool
5063 search_copytools $agent && error "Copytool start should have failed"
5066 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5068 run_test 402a "Copytool start fails if all MDTs are inactive"
5075 local f=$DIR/$tdir/$tfile
5076 touch $f || error "touch $f failed"
5077 local fid=$(path2fid $f)
5079 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5080 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5081 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5083 # give time for CDT to send request and to keep it for retry
5084 wait_for_loop_period
5086 wait_request_state $fid ARCHIVE WAITING
5088 do_facet $SINGLEAGT lctl set_param fail_loc=0
5090 # request should succeed now
5091 wait_request_state $fid ARCHIVE SUCCEED
5093 run_test 402b "CDT must retry request upon slow start of CT"
5096 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5098 local agent=$(facet_active_host $SINGLEAGT)
5100 # deactivate all mdc for MDT0001
5101 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5104 local uuid=$(get_agent_uuid $agent)
5105 # check the agent is registered on MDT0000, and not on MDT0001
5106 check_agent_registered_by_mdt $uuid 0
5107 check_agent_unregistered_by_mdt $uuid 1
5109 # check running copytool process
5110 search_copytools $agent || error "No running copytools on $agent"
5112 # reactivate all mdc for MDT0001
5113 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5115 # make sure the copytool is now registered to all MDTs
5116 check_agent_registered $uuid
5118 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5121 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5125 # create files on both MDT0000 and MDT0001
5128 local dir_mdt0=$DIR/$tdir/mdt0
5129 stack_trap "rm -rf $dir_mdt0" EXIT
5130 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5132 # create 1 file on mdt0
5133 local fid1=$(create_small_file $dir_mdt0/$tfile)
5135 # deactivate all mdc for MDT0001
5136 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5138 # send an HSM request for files in MDT0000
5139 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5141 # check for completion of files in MDT0000
5142 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5143 echo "archive successful on mdt0"
5145 # reactivate all mdc for MDT0001
5146 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5148 run_test 404 "Inactive MDT does not block requests for active MDTs"
5151 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5157 local striped_dir=$DIR/$tdir/striped_dir
5159 # create striped dir on all of MDTs
5160 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5162 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5163 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5164 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5165 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5167 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5168 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5169 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5170 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5172 # check that compound requests are shunt to the rights MDTs
5173 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5174 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5175 error "lfs hsm_archive"
5177 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5178 echo "archive successful on $fid1"
5179 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5180 echo "archive successful on $fid2"
5181 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5182 echo "archive successful on $fid3"
5183 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5184 echo "archive successful on $fid4"
5186 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5187 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5188 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5189 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5191 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5192 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5193 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5194 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5196 run_test 405 "archive and release under striped directory"
5199 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5201 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5202 skip "need MDS version at least 2.7.64" && return 0
5207 fid=$(create_small_file $DIR/$tdir/$tfile)
5212 $LFS hsm_archive $DIR/$tdir/$tfile
5213 wait_request_state "$fid" ARCHIVE SUCCEED
5214 $LFS hsm_release $DIR/$tdir/$tfile
5216 # Should migrate $tdir but not $tfile.
5217 $LFS migrate -m1 $DIR/$tdir &&
5218 error "migrating HSM an archived file should fail"
5220 $LFS hsm_restore $DIR/$tdir/$tfile
5221 wait_request_state "$fid" RESTORE SUCCEED
5223 $LFS hsm_remove $DIR/$tdir/$tfile
5224 wait_request_state "$fid" REMOVE SUCCEED
5226 cat $DIR/$tdir/$tfile > /dev/null ||
5227 error "cannot read $DIR/$tdir/$tfile"
5229 $LFS migrate -m1 $DIR/$tdir ||
5230 error "cannot complete migration after HSM remove"
5232 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5233 if ((mdt_index != 1)); then
5234 error "expected MDT index 1, got $mdt_index"
5237 # Refresh fid after migration.
5238 fid=$(path2fid $DIR/$tdir/$tfile)
5241 $LFS hsm_archive $DIR/$tdir/$tfile
5242 wait_request_state "$fid" ARCHIVE SUCCEED 1
5244 lctl set_param debug=+trace
5245 $LFS hsm_release $DIR/$tdir/$tfile ||
5246 error "cannot release $DIR/$tdir/$tfile"
5248 $LFS hsm_restore $DIR/$tdir/$tfile
5249 wait_request_state "$fid" RESTORE SUCCEED 1
5251 cat $DIR/$tdir/$tfile > /dev/null ||
5252 error "cannot read $DIR/$tdir/$tfile"
5254 run_test 406 "attempting to migrate HSM archived files is safe"
5257 needclients 2 || return 0
5258 # test needs a running copytool
5263 local f=$DIR/$tdir/$tfile
5264 local f2=$DIR2/$tdir/$tfile
5266 fid=$(make_custom_file_for_progress $f 39 1000000)
5267 [ $? != 0 ] && skip "not enough free space" && return
5269 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5270 wait_request_state $fid ARCHIVE SUCCEED
5273 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5274 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5277 # 1st request holds layout lock while appropriate
5278 # RESTORE record is still not added to llog
5282 # after umount hsm_actions->O/x/x log shouldn't have
5283 # double RESTORE records like below
5284 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5285 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5287 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5290 wait_request_state $fid RESTORE SUCCEED
5292 run_test 407 "Check for double RESTORE records in llog"
5296 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5297 skip "HSM migrate is not supported" && return
5299 test_mkdir -p $DIR/$tdir
5300 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5302 run_test 500 "various LLAPI HSM tests"
5307 check_and_cleanup_lustre