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 set_hsm_param remove_archive_on_last_unlink 0
2509 wait_request_state $fid2 REMOVE SUCCEED
2511 assert_request_count $fid REMOVE 0 \
2512 "Unexpected archived data remove request for $f"
2513 assert_request_count $fid3 REMOVE 0 \
2514 "Unexpected archived data remove request for $f3"
2516 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2519 # test needs a running copytool
2523 local f=$DIR/$tdir/$tfile
2524 local fid=$(copy_file /etc/passwd $f)
2526 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2527 wait_request_state $fid ARCHIVE SUCCEED
2529 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2530 set_hsm_param remove_archive_on_last_unlink 1
2533 cdt_check_state stopped
2537 set_hsm_param remove_archive_on_last_unlink 0
2539 wait_request_state $fid REMOVE WAITING
2543 # copytool must re-register
2545 wait_copytools || error "copytool failed to stop"
2548 wait_request_state $fid REMOVE SUCCEED
2550 run_test 26b "RAoLU policy when CDT off"
2553 # test needs a running copytool
2557 local f=$DIR/$tdir/$tfile
2558 local fid=$(copy_file /etc/passwd $f)
2560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2561 wait_request_state $fid ARCHIVE SUCCEED
2563 local f2=$DIR/$tdir/${tfile}_2
2564 local fid2=$(copy_file /etc/passwd $f2)
2566 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2567 wait_request_state $fid2 ARCHIVE SUCCEED
2569 # set a long grace_delay vs short loop_period
2570 local orig_loop_period=$(get_hsm_param loop_period)
2571 local orig_grace_delay=$(get_hsm_param grace_delay)
2572 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2573 set_hsm_param loop_period 10
2574 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2575 set_hsm_param grace_delay 100
2577 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2578 set_hsm_param remove_archive_on_last_unlink 1
2580 multiop_bg_pause $f O_c || error "open $f failed"
2586 wait_request_state $fid2 REMOVE SUCCEED
2587 assert_request_count $fid REMOVE 0 \
2588 "Unexpected archived data remove request for $f"
2590 kill -USR1 $pid || error "multiop early exit"
2591 # should reach autotest timeout if multiop fails to trap
2592 # signal, close file, and exit ...
2593 wait $pid || error "wait PID $PID failed"
2595 set_hsm_param remove_archive_on_last_unlink 0
2597 wait_request_state $fid REMOVE SUCCEED
2599 run_test 26c "RAoLU effective when file closed"
2602 # test needs a running copytool
2606 local f=$DIR/$tdir/$tfile
2607 local fid=$(create_small_file $f)
2609 $LFS hsm_archive $f || error "could not archive file"
2610 wait_request_state $fid ARCHIVE SUCCEED
2612 # set a long grace_delay vs short loop_period
2613 local orig_loop_period=$(get_hsm_param loop_period)
2614 local orig_grace_delay=$(get_hsm_param grace_delay)
2615 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2616 set_hsm_param loop_period 10
2617 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2618 set_hsm_param grace_delay 100
2620 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2621 set_hsm_param remove_archive_on_last_unlink 1
2623 multiop_bg_pause $f O_c || error "multiop failed"
2630 set_hsm_param remove_archive_on_last_unlink 0
2632 wait_request_state $fid REMOVE SUCCEED
2634 client_up || client_up || true
2636 kill -USR1 $MULTIPID
2637 wait $MULTIPID || error "multiop close failed"
2639 run_test 26d "RAoLU when Client eviction"
2642 # test needs a running copytool
2645 create_archive_file $tdir/$tfile
2646 local f=$DIR/$tdir/$tfile
2647 import_file $tdir/$tfile $f
2648 local fid=$(path2fid $f)
2652 [[ $? != 0 ]] || error "Remove of a released file should fail"
2656 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2659 # test needs a running copytool
2662 local f=$DIR/$tdir/$tfile
2664 fid=$(make_custom_file_for_progress $f 39 1000000)
2665 [ $? != 0 ] && skip "not enough free space" && return
2667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2668 wait_request_state $fid ARCHIVE SUCCEED
2673 [[ $? != 0 ]] || error "Remove of a released file should fail"
2675 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2678 # test needs a running copytool
2681 local f=$DIR/$tdir/$tfile
2683 fid=$(make_custom_file_for_progress $f 39 1000000)
2684 [ $? != 0 ] && skip "not enough free space" && return
2686 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2687 wait_request_state $fid ARCHIVE SUCCEED
2696 wait_request_state $fid REMOVE SUCCEED
2698 run_test 28 "Concurrent archive/file remove"
2701 # Tests --mntpath and --archive options
2704 copytool setup -m "$MOUNT" -a $archive_id
2706 # Bad archive number
2707 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2708 grep "Invalid argument" ||
2709 error "unexpected hsm_remove failure (1)"
2711 # mntpath is present but file is given
2712 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2713 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2714 error "unexpected hsm_remove failure (2)"
2716 run_test 29a "Tests --mntpath and --archive options"
2719 # test needs a running copytool
2722 local f=$DIR/$tdir/$tfile
2723 local fid=$(create_small_file $f)
2725 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2726 wait_request_state $fid ARCHIVE SUCCEED
2730 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2731 wait_request_state $fid REMOVE SUCCEED
2733 run_test 29b "Archive/delete/remove by FID from the archive."
2736 # test needs a running copytool
2739 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2740 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2741 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2744 wait_request_state $fid1 ARCHIVE SUCCEED
2745 wait_request_state $fid2 ARCHIVE SUCCEED
2746 wait_request_state $fid3 ARCHIVE SUCCEED
2748 rm -f $DIR/$tdir/$tfile-[1-3]
2750 echo $fid1 > $DIR/$tdir/list
2751 echo $fid2 >> $DIR/$tdir/list
2752 echo $fid3 >> $DIR/$tdir/list
2754 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2755 --filelist $DIR/$tdir/list
2756 wait_request_state $fid1 REMOVE SUCCEED
2757 wait_request_state $fid2 REMOVE SUCCEED
2758 wait_request_state $fid3 REMOVE SUCCEED
2760 run_test 29c "Archive/delete/remove by FID, using a file list."
2763 # test needs more than one CT
2764 needclients 3 || return 0
2770 # start all of the copytools
2771 for n in $(seq $AGTCOUNT); do
2772 copytool setup -f agt$n -a $n
2776 file=$DIR/$tdir/$tfile
2777 fid=$(create_small_file $file)
2779 $LFS hsm_archive $file
2780 wait_request_state $fid ARCHIVE SUCCEED
2781 check_hsm_flags $file "0x00000009"
2785 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2786 error "cannot hsm_remove '$fid'"
2788 # give time for CDT to handle remove request and create broadcasted
2791 # remove request has been broadcasted ?
2792 local cnt=$(get_request_count $fid REMOVE)
2793 # broadcasted requests + original
2794 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2795 error "remove not broadcasted to all CTs"
2797 # give time for CDT and CTs to handle broadcasted
2798 wait_for_loop_period
2800 # each agent serves one different archive_id, so broadcasted
2801 # hsm_remove request should only succeed once and fail at all others
2805 for n in $(seq $AGTCOUNT); do
2806 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2807 $HSM_PARAM.actions | awk \
2808 '/'$fid'.*action=REMOVE archive#='$n'/ \
2809 {print \\\$13}' | cut -f2 -d=")
2810 if [[ "$res" == "SUCCEED" ]]; then
2812 elif [[ "$res" == "FAILED" ]]; then
2817 [[ $scnt -eq 1 ]] ||
2818 error "one and only CT should have removed successfully"
2820 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2821 error "all but one CT should have failed to remove"
2823 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2824 "request to be sent once for each registered archive_id"
2827 # restore at exec cannot work on agent node (because of Linux kernel
2828 # protection of executables)
2829 needclients 2 || return 0
2831 # test needs a running copytool
2835 copy2archive /bin/true $tdir/$tfile
2837 local f=$DIR/$tdir/true
2838 import_file $tdir/$tfile $f
2840 local fid=$(path2fid $f)
2842 # set no retry action mode
2848 # remove no try action mode
2852 [[ $st == 0 ]] || error "Failed to exec a released file"
2856 run_test 30a "Restore at exec (import case)"
2859 # restore at exec cannot work on agent node (because of Linux kernel
2860 # protection of executables)
2861 needclients 2 || return 0
2863 # test needs a running copytool
2867 local f=$DIR/$tdir/true
2868 local fid=$(copy_file /bin/true $f)
2870 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2871 wait_request_state $fid ARCHIVE SUCCEED
2875 stack_trap cdt_clear_no_retry EXIT
2876 # set no retry action mode
2884 [[ $st == 0 ]] || error "Failed to exec a released file"
2886 run_test 30b "Restore at exec (release case)"
2889 needclients 2 || return 0
2891 # test needs a running copytool
2895 local f=$DIR/$tdir/SLEEP
2896 local slp_sum1=$(md5sum /bin/sleep)
2897 local fid=$(copy_file /bin/sleep $f)
2899 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2900 wait_request_state $fid ARCHIVE SUCCEED
2902 check_hsm_flags $f "0x0000000d"
2904 stack_trap cdt_clear_no_retry EXIT
2905 # set no retry action mode
2908 do_node $CLIENT2 "$f 10" &
2912 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2914 [[ $? == 0 ]] || error "Execution failed during run"
2916 if [[ $? != 0 ]]; then
2917 local slp_sum2=$(md5sum /bin/sleep)
2918 # in case sleep file is modified during the test
2919 [[ $slp_sum1 == $slp_sum2 ]] &&
2920 error "Binary overwritten during exec"
2923 check_hsm_flags $f "0x00000009"
2925 run_test 30c "Update during exec of released file must fail"
2927 restore_and_check_size() {
2930 local s=$(stat -c "%s" $f)
2932 local st=$(get_hsm_flags $f)
2936 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2938 n=$(stat -c "%s" $f)
2939 # we echo in both cases to show stat is not hang
2940 if [[ $n != $s ]]; then
2941 echo "size seen is $n != $s"
2944 echo "size seen is right: $n == $s"
2948 st=$(get_hsm_flags $f)
2950 if [[ "$st" = "0x00000009" ]]; then
2953 echo " restore is too long"
2954 wait_request_state $fid RESTORE SUCCEED
2960 # test needs a running copytool
2963 create_archive_file $tdir/$tfile
2964 local f=$DIR/$tdir/$tfile
2965 import_file $tdir/$tfile $f
2966 local fid=$($LFS path2fid $f)
2967 HSM_ARCHIVE_PURGE=false copytool_setup
2969 restore_and_check_size $f $fid
2972 [[ $err -eq 0 ]] || error "File size changed during restore"
2976 run_test 31a "Import a large file and check size during restore"
2980 # test needs a running copytool
2983 local f=$DIR/$tdir/$tfile
2985 fid=$(make_custom_file_for_progress $f 39 1000000)
2986 [ $? != 0 ] && skip "not enough free space" && return
2988 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2989 wait_request_state $fid ARCHIVE SUCCEED
2992 restore_and_check_size $f $fid
2995 [[ $err -eq 0 ]] || error "File size changed during restore"
2997 run_test 31b "Restore a large unaligned file and check size during restore"
3000 # test needs a running copytool
3003 local f=$DIR/$tdir/$tfile
3005 fid=$(make_custom_file_for_progress $f 33 1048576)
3006 [ $? != 0 ] && skip "not enough free space" && return
3008 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3009 wait_request_state $fid ARCHIVE SUCCEED
3012 restore_and_check_size $f $fid
3015 [[ $err -eq 0 ]] || error "File size changed during restore"
3017 run_test 31c "Restore a large aligned file and check size during restore"
3020 # test needs a running copytool
3023 local f=$DIR/$tdir/$tfile
3025 fid=$(make_custom_file_for_progress $f 39 1000000)
3026 [ $? != 0 ] && skip "not enough free space" && return
3028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3029 wait_request_state $fid ARCHIVE SUCCEED
3032 # to be sure wait_all_done will not be mislead by previous tests
3035 wait_for_grace_delay
3036 # Also raise grace_delay significantly so the Canceled
3037 # Restore action will stay enough long avail.
3038 local old_grace=$(get_hsm_param grace_delay)
3039 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3040 set_hsm_param grace_delay 100
3042 md5sum $f >/dev/null &
3044 wait_request_state $fid RESTORE STARTED
3049 # Check restore trigger process was killed
3050 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3054 # instead of waiting+checking both Restore and Cancel ops
3055 # sequentially, wait for both to be finished and then check
3057 wait_all_done 100 $fid
3058 local rstate=$(get_request_state $fid RESTORE)
3059 local cstate=$(get_request_state $fid CANCEL)
3061 if [[ "$rstate" == "CANCELED" ]] ; then
3062 [[ "$cstate" == "SUCCEED" ]] ||
3063 error "Restore state is CANCELED and Cancel state " \
3064 "is not SUCCEED but $cstate"
3065 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3066 elif [[ "$rstate" == "SUCCEED" ]] ; then
3067 [[ "$cstate" == "FAILED" ]] ||
3068 error "Restore state is SUCCEED and Cancel state " \
3069 "is not FAILED but $cstate"
3070 echo "Restore state is SUCCEED, Cancel state is FAILED"
3072 error "Restore state is $rstate and Cancel state is $cstate"
3076 error "Cannot kill process waiting for restore ($killed)"
3078 run_test 33 "Kill a restore waiting process"
3081 # test needs a running copytool
3084 local f=$DIR/$tdir/$tfile
3086 fid=$(make_custom_file_for_progress $f 39 1000000)
3087 [ $? != 0 ] && skip "not enough free space" && return
3089 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3090 wait_request_state $fid ARCHIVE SUCCEED
3093 md5sum $f >/dev/null &
3095 wait_request_state $fid RESTORE STARTED
3097 rm $f || error "rm $f failed"
3098 # rm must not block during restore
3099 wait_request_state $fid RESTORE STARTED
3101 wait_request_state $fid RESTORE SUCCEED
3102 # check md5sum pgm finished
3103 local there=$(ps -o pid,comm hp $pid >/dev/null)
3104 [[ -z $there ]] || error "Restore initiator does not exit"
3106 wait $pid || error "Restore initiator failed with $?"
3108 run_test 34 "Remove file during restore"
3111 # test needs a running copytool
3114 local f=$DIR/$tdir/$tfile
3115 local f1=$DIR/$tdir/$tfile-1
3117 fid=$(make_custom_file_for_progress $f 39 1000000)
3118 [ $? != 0 ] && skip "not enough free space" && return
3120 local fid1=$(copy_file /etc/passwd $f1)
3121 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3122 wait_request_state $fid ARCHIVE SUCCEED
3125 md5sum $f >/dev/null &
3127 wait_request_state $fid RESTORE STARTED
3129 mv $f1 $f || error "mv $f1 $f failed"
3130 # mv must not block during restore
3131 wait_request_state $fid RESTORE STARTED
3133 wait_request_state $fid RESTORE SUCCEED
3134 # check md5sum pgm finished
3135 local there=$(ps -o pid,comm hp $pid >/dev/null)
3136 [[ -z $there ]] || error "Restore initiator does not exit"
3138 wait $pid || error "Restore initiator failed with $?"
3141 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3143 run_test 35 "Overwrite file during restore"
3146 # test needs a running copytool
3149 local f=$DIR/$tdir/$tfile
3151 fid=$(make_custom_file_for_progress $f 39 1000000)
3152 [ $? != 0 ] && skip "not enough free space" && return
3154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3155 wait_request_state $fid ARCHIVE SUCCEED
3158 md5sum $f >/dev/null &
3160 wait_request_state $fid RESTORE STARTED
3163 # rm must not block during restore
3164 wait_request_state $fid RESTORE STARTED
3166 wait_request_state $fid RESTORE SUCCEED
3167 # check md5sum pgm finished
3168 local there=$(ps -o pid,comm hp $pid >/dev/null)
3170 error "Restore initiator does not exit"
3172 wait $pid || error "Restore initiator failed with $?"
3174 run_test 36 "Move file during restore"
3177 # LU-5683: check that an archived dirty file can be rearchived.
3180 local f=$DIR/$tdir/$tfile
3183 fid=$(create_small_file $f) || error "cannot create small file"
3185 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3186 wait_request_state $fid ARCHIVE SUCCEED
3187 $LFS hsm_release $f || error "cannot release $f"
3189 # Allow previous archive request to expire from the actions log.
3190 wait_for_grace_delay
3193 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3196 wait_request_state $fid ARCHIVE SUCCEED
3198 run_test 37 "re-archive a dirty file"
3205 for n in $(seq 1 $count); do
3206 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3208 echo "$count archive requests submitted"
3212 local stream_count=4
3213 local file_count=100
3215 local f=$DIR/$tdir/$tfile
3219 local max_requests=$(get_hsm_param max_requests)
3221 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3222 # Increase the number of HSM request that can be performed in
3223 # parallel. With the coordinator running once per second, this
3224 # also limits the number of requests per seconds that can be
3225 # performed, so we pick a decent number. But we also need to keep
3226 # that number low because the copytool has no rate limit and will
3227 # fail some requests if if gets too many at once.
3228 set_hsm_param max_requests 300
3230 for i in $(seq 1 $file_count); do
3231 for p in $(seq 1 $stream_count); do
3232 fid=$(copy_file /etc/hosts $f.$p.$i)
3238 # to be sure wait_all_done will not be mislead by previous tests
3240 wait_for_grace_delay
3242 # start archive streams in background (archive files in parallel)
3243 for p in $(seq 1 $stream_count); do
3244 multi_archive $f.$p $file_count &
3247 echo -n "Wait for all requests being enqueued..."
3252 run_test 40 "Parallel archive requests"
3255 # test needs a running copytool
3259 local f=$DIR/$tdir/$tfile
3260 local fid=$(create_small_file $f)
3262 $LFS hsm_archive $f || error "could not archive file"
3263 wait_request_state $fid ARCHIVE SUCCEED
3264 check_hsm_flags $f "0x00000009"
3266 multiop_bg_pause $f O_c || error "multiop failed"
3270 client_up || client_up || true
3272 kill -USR1 $MULTIPID
3273 wait $MULTIPID || error "multiop close failed"
3275 check_hsm_flags $f "0x0000000b"
3277 run_test 52 "Opened for write file on an evicted client should be set dirty"
3280 # test needs a running copytool
3284 local f=$DIR/$tdir/$tfile
3285 local fid=$(create_small_file $f)
3287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3288 error "could not archive file"
3289 wait_request_state $fid ARCHIVE SUCCEED
3290 check_hsm_flags $f "0x00000009"
3292 multiop_bg_pause $f o_c || error "multiop failed"
3296 client_up || client_up || true
3298 kill -USR1 $MULTIPID
3299 wait $MULTIPID || error "multiop close failed"
3301 check_hsm_flags $f "0x00000009"
3303 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3306 # test needs a running copytool
3309 local f=$DIR/$tdir/$tfile
3310 local fid=$(make_custom_file_for_progress $f 39 1000000)
3312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3313 error "could not archive file"
3314 wait_request_state $fid ARCHIVE STARTED
3316 check_hsm_flags $f "0x00000001"
3318 stack_trap "cdt_clear_no_retry" EXIT
3319 # Avoid coordinator resending this request as soon it has failed.
3324 wait_request_state $fid ARCHIVE FAILED
3326 check_hsm_flags $f "0x00000003"
3328 run_test 54 "Write during an archive cancels it"
3331 # test needs a running copytool
3334 local f=$DIR/$tdir/$tfile
3335 local fid=$(make_custom_file_for_progress $f 39 1000000)
3337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3338 error "could not archive file"
3339 wait_request_state $fid ARCHIVE STARTED
3341 check_hsm_flags $f "0x00000001"
3343 stack_trap "cdt_clear_no_retry" EXIT
3344 # Avoid coordinator resending this request as soon it has failed.
3347 $TRUNCATE $f 1024 || error "truncate failed"
3349 wait_request_state $fid ARCHIVE FAILED
3351 check_hsm_flags $f "0x00000003"
3353 run_test 55 "Truncate during an archive cancels it"
3356 # test needs a running copytool
3359 local f=$DIR/$tdir/$tfile
3361 fid=$(make_custom_file_for_progress $f 39 1000000)
3362 [ $? != 0 ] && skip "not enough free space" && return
3364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3365 error "could not archive file"
3366 wait_request_state $fid ARCHIVE STARTED
3368 check_hsm_flags $f "0x00000001"
3370 # Change metadata and sync to be sure we are not changing only
3375 wait_request_state $fid ARCHIVE SUCCEED
3377 check_hsm_flags $f "0x00000009"
3379 run_test 56 "Setattr during an archive is ok"
3382 # Need one client for I/O, one for request
3383 needclients 2 || return 0
3385 # test needs a running copytool
3389 local f=$DIR/$tdir/test_archive_remote
3390 # Create a file on a remote node
3391 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3392 "count=2 conv=fsync"
3395 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3396 error "hsm_archive failed"
3397 local fid=$(path2fid $f)
3398 wait_request_state $fid ARCHIVE SUCCEED
3400 # Release and implicit restore it
3401 do_node $CLIENT2 "$LFS hsm_release $f" ||
3402 error "hsm_release failed"
3403 do_node $CLIENT2 "md5sum $f" ||
3404 error "hsm_restore failed"
3406 wait_request_state $fid RESTORE SUCCEED
3408 run_test 57 "Archive a file with dirty cache on another node"
3410 truncate_released_file() {
3414 local sz=$(stat -c %s $src_file)
3415 local f=$DIR/$tdir/$tfile
3416 local fid=$(copy_file $1 $f)
3420 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3421 error "could not archive file"
3422 wait_request_state $fid ARCHIVE SUCCEED
3424 $LFS hsm_release $f || error "could not release file"
3426 $TRUNCATE $f $trunc_to || error "truncate failed"
3429 local sz1=$(stat -c %s $f)
3430 [[ $sz1 == $trunc_to ]] ||
3431 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3434 check_hsm_flags $f "0x0000000b"
3436 local state=$(get_request_state $fid RESTORE)
3437 [[ "$state" == "SUCCEED" ]] ||
3438 error "truncate $sz does not trig restore, state = $state"
3440 $TRUNCATE $ref $trunc_to
3441 cmp $ref $f || error "file data wrong after truncate"
3447 # test needs a running copytool
3452 local sz=$(stat -c %s /etc/passwd)
3454 echo "truncate up from $sz to $((sz*2))"
3455 truncate_released_file /etc/passwd $((sz*2))
3457 echo "truncate down from $sz to $((sz/2))"
3458 truncate_released_file /etc/passwd $((sz/2))
3460 echo "truncate to 0"
3461 truncate_released_file /etc/passwd 0
3463 run_test 58 "Truncate a released file will trigger restore"
3467 local server_version=$(lustre_version_code $SINGLEMDS)
3468 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3469 skip "Need MDS version at least 2.7.63" && return
3472 $MCREATE $DIR/$tfile || error "mcreate failed"
3473 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3474 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3475 fid=$(path2fid $DIR/$tfile)
3476 wait_request_state $fid ARCHIVE SUCCEED
3477 $LFS hsm_release $DIR/$tfile || error "release failed"
3479 run_test 59 "Release stripeless file with non-zero size"
3482 # This test validates the fix for LU-4512. Ensure that the -u
3483 # option changes the progress reporting interval from the
3484 # default (30 seconds) to the user-specified interval.
3486 local progress_timeout=$((interval * 4))
3488 copytool setup -b 1 --update-interval $interval
3490 local f=$DIR/$tdir/$tfile
3492 fid=$(make_custom_file_for_progress $f 10)
3493 [ $? != 0 ] && skip "not enough free space" && return
3496 local mdt=${MDT_PREFIX}${mdtidx}
3497 local mds=mds$((mdtidx + 1))
3499 # Wait for copytool to register
3500 wait_update_facet $mds \
3501 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3502 uuid 100 || error "coyptool failed to register with $mdt"
3504 local start_at=$(date +%s)
3505 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3506 error "could not archive file"
3508 local agent=$(facet_active_host $SINGLEAGT)
3509 local logfile=$(copytool_logfile $SINGLEAGT)
3511 wait_update $agent \
3512 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3513 error "copytool failed to start"
3515 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3516 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3522 echo -n "Expecting a progress update within $progress_timeout seconds... "
3524 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3525 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3526 echo "$RESULT bytes copied in $WAIT seconds."
3528 elif [ $WAIT -ge $progress_timeout ]; then
3529 error "Timed out waiting for progress update!"
3532 WAIT=$((WAIT + sleep))
3536 local finish_at=$(date +%s)
3537 local elapsed=$((finish_at - start_at))
3539 # Ensure that the progress update occurred within the expected window.
3540 if [ $elapsed -lt $((interval - 1)) ]; then
3541 error "Expected progress update after at least $interval seconds"
3544 echo "Wait for on going archive hsm action to complete"
3545 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3546 echo "File archiving not completed even after 10 secs"
3548 run_test 60 "Changing progress update interval from default"
3551 # test needs a running copytool
3555 local f=$DIR/$tdir/$tfile
3556 local fid=$(copy_file /etc/passwd $f)
3558 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3561 wait_request_state $fid ARCHIVE FAILED
3563 run_test 61 "Waiting archive of a removed file should fail"
3566 # test needs a new running copytool
3567 stack_trap copytool_monitor_cleanup EXIT
3568 copytool_monitor_setup
3569 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3571 # Wait for the copytool to register.
3572 wait_update --verbose $(facet_active_host mds1) \
3573 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3575 error "copytool failed to register with MDT0000"
3578 wait_copytools || error "Copytools failed to stop"
3580 local REGISTER_EVENT
3581 local UNREGISTER_EVENT
3582 while read event; do
3583 local parsed=$(parse_json_event "$event")
3584 if [ -z "$parsed" ]; then
3585 error "Copytool sent malformed event: $event"
3589 if [ $event_type == "REGISTER" ]; then
3590 REGISTER_EVENT=$event
3591 elif [ $event_type == "UNREGISTER" ]; then
3592 UNREGISTER_EVENT=$event
3594 done < <(echo $"$(get_copytool_event_log)")
3596 if [ -z "$REGISTER_EVENT" ]; then
3597 error "Copytool failed to send register event to FIFO"
3600 if [ -z "$UNREGISTER_EVENT" ]; then
3601 error "Copytool failed to send unregister event to FIFO"
3604 echo "Register/Unregister events look OK."
3606 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3609 # Bump progress interval for livelier events.
3612 # test needs a new running copytool
3613 stack_trap copytool_monitor_cleanup EXIT
3614 copytool_monitor_setup
3615 copytool setup --update-interval $interval --event-fifo \
3616 "$HSMTOOL_MONITOR_DIR/fifo"
3618 stack_trap "cdt_clear_no_retry" EXIT
3619 # Just start and stop the copytool to generate events.
3622 local f=$DIR/$tdir/$tfile
3624 fid=$(make_custom_file_for_progress $f 39 1000000)
3625 [ $? != 0 ] && skip "not enough free space" && return
3627 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3628 error "could not archive file"
3629 wait_request_state $fid ARCHIVE SUCCEED
3631 local expected_fields="event_time data_fid source_fid"
3632 expected_fields+=" total_bytes current_bytes"
3636 while read event; do
3637 # Make sure we're not getting anything from previous events.
3638 for field in $expected_fields; do
3642 local parsed=$(parse_json_event "$event")
3643 if [ -z "$parsed" ]; then
3644 error "Copytool sent malformed event: $event"
3648 if [ $event_type == "ARCHIVE_START" ]; then
3651 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3654 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3658 # Do some simple checking of the progress update events.
3659 for expected_field in $expected_fields; do
3660 if [ -z ${!expected_field+x} ]; then
3661 error "Missing $expected_field field in event"
3665 if [ $total_bytes -eq 0 ]; then
3666 error "Expected total_bytes to be > 0"
3669 # These should be identical throughout an archive
3671 if [ $source_fid != $data_fid ]; then
3672 error "Expected source_fid to equal data_fid"
3674 done < <(echo $"$(get_copytool_event_log)")
3676 if [ -z "$START_EVENT" ]; then
3677 error "Copytool failed to send archive start event to FIFO"
3680 if [ -z "$FINISH_EVENT" ]; then
3681 error "Copytool failed to send archive finish event to FIFO"
3684 echo "Archive events look OK."
3686 run_test 71 "Copytool logs JSON archive events to FIFO"
3689 # Bump progress interval for livelier events.
3692 # test needs a new running copytool
3694 copytool_monitor_setup
3695 HSMTOOL_UPDATE_INTERVAL=$interval \
3696 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3697 local test_file=$HSMTOOL_MONITOR_DIR/file
3699 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3701 do_facet $SINGLEAGT "$cmd" ||
3702 error "cannot create $test_file on $SINGLEAGT"
3703 copy2archive $test_file $tdir/$tfile
3706 local f=$DIR/$tdir/$tfile
3707 import_file $tdir/$tfile $f
3708 f=$DIR2/$tdir/$tfile
3709 echo "Verifying released state: "
3710 check_hsm_flags $f "0x0000000d"
3712 local fid=$(path2fid $f)
3714 wait_request_state $fid RESTORE SUCCEED
3716 local expected_fields="event_time data_fid source_fid"
3717 expected_fields+=" total_bytes current_bytes"
3721 while read event; do
3722 # Make sure we're not getting anything from previous events.
3723 for field in $expected_fields; do
3727 local parsed=$(parse_json_event "$event")
3728 if [ -z "$parsed" ]; then
3729 error "Copytool sent malformed event: $event"
3733 if [ $event_type == "RESTORE_START" ]; then
3735 if [ $source_fid != $data_fid ]; then
3736 error "source_fid should == data_fid at start"
3739 elif [ $event_type == "RESTORE_FINISH" ]; then
3741 if [ $source_fid != $data_fid ]; then
3742 error "source_fid should == data_fid at finish"
3745 elif [ $event_type != "RESTORE_RUNNING" ]; then
3749 # Do some simple checking of the progress update events.
3750 for expected_field in $expected_fields; do
3751 if [ -z ${!expected_field+x} ]; then
3752 error "Missing $expected_field field in event"
3756 if [ $total_bytes -eq 0 ]; then
3757 error "Expected total_bytes to be > 0"
3760 # When a restore starts out, the data fid is the same as the
3761 # source fid. After the restore has gotten going, we learn
3762 # the new data fid. Once the restore has finished, the source
3763 # fid is set to the new data fid.
3765 # We test this because some monitoring software may depend on
3766 # this behavior. If it changes, then the consumers of these
3767 # events may need to be modified.
3768 if [ $source_fid == $data_fid ]; then
3769 error "source_fid should != data_fid during restore"
3771 done < <(echo $"$(get_copytool_event_log)")
3773 if [ -z "$START_EVENT" ]; then
3774 error "Copytool failed to send restore start event to FIFO"
3777 if [ -z "$FINISH_EVENT" ]; then
3778 error "Copytool failed to send restore finish event to FIFO"
3781 echo "Restore events look OK."
3785 copytool_monitor_cleanup
3789 run_test 72 "Copytool logs JSON restore events to FIFO"
3792 file_count=51 # Max number of files constrained by LNET message size
3793 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3794 local f=$DIR/$tdir/$tfile
3795 local FILELIST=/tmp/filelist.txt
3799 for i in $(seq 1 $file_count); do
3800 fid=$(copy_file /etc/hosts $f.$i)
3801 echo $f.$i >> $FILELIST
3805 # to be sure wait_all_done will not be mislead by previous tests
3807 wait_for_grace_delay
3808 $LFS hsm_archive --filelist $FILELIST ||
3809 error "cannot archive a file list"
3811 $LFS hsm_release --filelist $FILELIST ||
3812 error "cannot release a file list"
3813 $LFS hsm_restore --filelist $FILELIST ||
3814 error "cannot restore a file list"
3817 run_test 90 "Archive/restore a file list"
3819 double_verify_reset_hsm_param() {
3821 echo "Testing $HSM_PARAM.$p"
3822 local val=$(get_hsm_param $p)
3824 local val2=$(($val * 2))
3825 set_hsm_param $p $val2
3826 val=$(get_hsm_param $p)
3827 [[ $val == $val2 ]] ||
3828 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3829 echo "Set $p to 0 must failed"
3833 set_hsm_param $p $save
3835 if [[ $rc == 0 ]]; then
3836 error "we must not be able to set $HSM_PARAM.$p to 0"
3841 double_verify_reset_hsm_param loop_period
3842 double_verify_reset_hsm_param grace_delay
3843 double_verify_reset_hsm_param active_request_timeout
3844 double_verify_reset_hsm_param max_requests
3845 double_verify_reset_hsm_param default_archive_id
3847 run_test 100 "Set coordinator /proc tunables"
3854 run_test 102 "Verify coordinator control"
3857 # test needs a running copytool
3864 for i in $(seq 1 20); do
3865 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3867 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3871 echo "Current requests"
3872 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3873 $HSM_PARAM.actions |\
3874 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3876 [[ -z "$res" ]] || error "Some request have not been canceled"
3878 run_test 103 "Purge all requests"
3883 local f=$DIR/$tdir/$tfile
3885 fid=$(make_custom_file_for_progress $f 39 1000000)
3886 [ $? != 0 ] && skip "not enough free space" && return
3888 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3889 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3890 $HSM_PARAM.actions |\
3891 grep $fid | cut -f16 -d=")
3893 [[ "$data1" == "$DATAHEX" ]] ||
3894 error "Data field in records is ($data1) and not ($DATAHEX)"
3899 wait_request_state $fid ARCHIVE SUCCEED
3901 run_test 104 "Copy tool data field"
3904 local max_requests=$(get_hsm_param max_requests)
3908 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3909 set_hsm_param max_requests 300
3912 for i in $(seq -w 1 10); do
3913 cp /etc/passwd $DIR/$tdir/$i
3914 $LFS hsm_archive $DIR/$tdir/$i
3916 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3917 $HSM_PARAM.actions |\
3918 grep WAITING | wc -l")
3922 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3923 $HSM_PARAM.actions |\
3924 grep WAITING | wc -l")
3927 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3928 error "Requests count after shutdown $reqcnt2 != "\
3929 "before shutdown $reqcnt1"
3931 run_test 105 "Restart of coordinator"
3934 # test needs a running copytool
3937 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3939 check_agent_registered $uuid
3941 search_copytools || error "No copytool found"
3944 wait_copytools || error "Copytool failed to stop"
3946 check_agent_unregistered $uuid
3949 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3950 check_agent_registered $uuid
3952 run_test 106 "Copytool register/unregister"
3955 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3957 # test needs a running copytool
3959 # create and archive file
3961 local f1=$DIR/$tdir/$tfile
3962 local fid=$(copy_file /etc/passwd $f1)
3963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3964 wait_request_state $fid ARCHIVE SUCCEED
3965 # shutdown and restart MDS
3967 # check the copytool still gets messages from MDT
3968 local f2=$DIR/$tdir/2
3969 local fid=$(copy_file /etc/passwd $f2)
3970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3971 # main check of this sanity: this request MUST succeed
3972 wait_request_state $fid ARCHIVE SUCCEED
3974 run_test 107 "Copytool re-register after MDS restart"
3976 policy_set_and_test()
3980 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3981 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3982 [[ "$policy" == "$target" ]] ||
3983 error "Wrong policy after '$change': '$policy' != '$target'"
3987 # to force default policy setting if error
3988 CDT_POLICY_HAD_CHANGED=true
3990 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3991 local default="NonBlockingRestore [NoRetryAction]"
3992 [[ "$policy" == "$default" ]] ||
3993 error "default policy has changed,"\
3994 " '$policy' != '$default' update the test"
3995 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3996 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3997 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3998 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3999 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4000 # useless bacause we know but safer for futur changes to use real value
4001 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4002 echo "Next set_param must failed"
4003 policy_set_and_test "wrong" "$policy"
4006 echo "Back to default policy"
4007 cdt_set_sanity_policy
4009 run_test 109 "Policy display/change"
4012 # test needs a running copytool
4017 copy2archive /etc/passwd $tdir/$tfile
4019 local f=$DIR/$tdir/$tfile
4020 import_file $tdir/$tfile $f
4021 local fid=$(path2fid $f)
4023 cdt_set_non_blocking_restore
4028 wait_request_state $fid RESTORE SUCCEED
4029 cdt_clear_non_blocking_restore
4033 error "md5sum returns $st != 1, "\
4034 "should also perror ENODATA (No data available)"
4036 run_test 110a "Non blocking restore policy (import case)"
4039 # test needs a running copytool
4043 local f=$DIR/$tdir/$tfile
4044 local fid=$(copy_file /etc/passwd $f)
4045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4046 wait_request_state $fid ARCHIVE SUCCEED
4049 cdt_set_non_blocking_restore
4054 wait_request_state $fid RESTORE SUCCEED
4055 cdt_clear_non_blocking_restore
4059 error "md5sum returns $st != 1, "\
4060 "should also perror ENODATA (No data available)"
4062 run_test 110b "Non blocking restore policy (release case)"
4065 # test needs a running copytool
4069 copy2archive /etc/passwd $tdir/$tfile
4071 local f=$DIR/$tdir/$tfile
4073 import_file $tdir/$tfile $f
4074 local fid=$(path2fid $f)
4078 copytool_remove_backend $fid
4081 wait_request_state $fid RESTORE FAILED
4088 [[ $st == 0 ]] || error "Restore does not failed"
4092 run_test 111a "No retry policy (import case), restore will error"\
4093 " (No such file or directory)"
4096 # test needs a running copytool
4100 local f=$DIR/$tdir/$tfile
4101 local fid=$(copy_file /etc/passwd $f)
4103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4104 wait_request_state $fid ARCHIVE SUCCEED
4107 copytool_remove_backend $fid
4110 wait_request_state $fid RESTORE FAILED
4117 [[ $st == 0 ]] || error "Restore does not failed"
4121 run_test 111b "No retry policy (release case), restore will error"\
4122 " (No such file or directory)"
4125 # test needs a running copytool
4129 local f=$DIR/$tdir/$tfile
4130 local fid=$(copy_file /etc/passwd $f)
4132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4133 local l=$($LFS hsm_action $f)
4135 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4138 wait_request_state $fid ARCHIVE SUCCEED
4141 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4143 run_test 112 "State of recorded request"
4146 # test needs a running copytool
4149 local f=$DIR/$tdir/$tfile
4151 fid=$(make_custom_file_for_progress $f 103 1048576)
4152 [ $? != 0 ] && skip "not enough free space" && return
4154 # test with cdt on is made in test_221
4156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4157 # wait archive to register at CDT
4158 wait_request_state $fid ARCHIVE WAITING
4161 wait_request_state $fid ARCHIVE CANCELED
4162 wait_request_state $fid CANCEL SUCCEED
4164 run_test 200 "Register/Cancel archive"
4167 # test needs a running copytool
4170 local f=$DIR/$tdir/$tfile
4171 create_archive_file $tdir/$tfile
4172 import_file $tdir/$tfile $f
4173 local fid=$(path2fid $f)
4175 # test with cdt on is made in test_222
4178 # wait restore to register at CDT
4179 wait_request_state $fid RESTORE WAITING
4182 wait_request_state $fid RESTORE CANCELED
4183 wait_request_state $fid CANCEL SUCCEED
4187 run_test 201 "Register/Cancel restore"
4190 # test needs a running copytool
4193 local f=$DIR/$tdir/$tfile
4195 fid=$(make_custom_file_for_progress $f 39 1000000)
4196 [ $? != 0 ] && skip "not enough free space" && return
4198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4199 wait_request_state $fid ARCHIVE SUCCEED
4203 # wait remove to register at CDT
4204 wait_request_state $fid REMOVE WAITING
4207 wait_request_state $fid REMOVE CANCELED
4209 run_test 202 "Register/Cancel remove"
4211 test_220A() { # was test_220
4212 # test needs a running copytool
4217 local f=$DIR/$tdir/$tfile
4218 local fid=$(copy_file /etc/passwd $f)
4222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4223 wait_request_state $fid ARCHIVE SUCCEED
4225 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4229 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4231 run_test 220A "Changelog for archive"
4234 # test needs a running copytool
4239 local f=$DIR/$tdir/$tfile
4240 local fid=$(copy_file /etc/passwd $f)
4244 # block copytool operations to allow for HSM request to be
4245 # submitted and file be unlinked (CDT will find object removed)
4248 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4250 # wait request to reach CT
4251 wait_request_state $fid ARCHIVE STARTED
4257 wait_request_state $fid ARCHIVE FAILED
4259 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4264 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4266 run_test 220a "Changelog for failed archive"
4269 # test needs a running copytool
4272 local f=$DIR/$tdir/$tfile
4274 fid=$(make_custom_file_for_progress $f 103 1048576)
4275 [ $? != 0 ] && skip "not enough free space" && return
4279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4280 wait_request_state $fid ARCHIVE STARTED
4282 wait_request_state $fid ARCHIVE CANCELED
4283 wait_request_state $fid CANCEL SUCCEED
4285 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4288 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4290 run_test 221 "Changelog for archive canceled"
4293 # test needs a running copytool
4297 copy2archive /etc/passwd $tdir/$tfile
4299 local f=$DIR/$tdir/$tfile
4300 import_file $tdir/$tfile $f
4301 local fid=$(path2fid $f)
4306 wait_request_state $fid RESTORE SUCCEED
4308 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4311 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4315 run_test 222a "Changelog for explicit restore"
4318 # test needs a running copytool
4322 local f=$DIR/$tdir/$tfile
4323 local fid=$(copy_file /etc/passwd $f)
4326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4327 wait_request_state $fid ARCHIVE SUCCEED
4332 wait_request_state $fid RESTORE SUCCEED
4334 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4337 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4339 run_test 222b "Changelog for implicit restore"
4342 # test needs a running copytool
4346 copy2archive /etc/passwd $tdir/$tfile
4348 local f=$DIR/$tdir/$tfile
4349 import_file $tdir/$tfile $f
4350 local fid=$(path2fid $f)
4354 # block copytool operations to allow for HSM request to be
4355 # submitted and file be unlinked (CDT will find object removed)
4360 # wait request to reach CT
4361 wait_request_state $fid RESTORE STARTED
4367 wait_request_state $fid RESTORE FAILED
4369 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4373 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4377 run_test 222c "Changelog for failed explicit restore"
4380 # test needs a running copytool
4384 local f=$DIR/$tdir/$tfile
4385 local fid=$(copy_file /etc/passwd $f)
4388 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4389 wait_request_state $fid ARCHIVE SUCCEED
4392 copytool_remove_backend $fid
4395 wait_request_state $fid RESTORE FAILED
4397 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4401 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4405 run_test 222d "Changelog for failed implicit restore"
4408 # test needs a running copytool
4411 local f=$DIR/$tdir/$tfile
4412 create_archive_file $tdir/$tfile
4416 import_file $tdir/$tfile $f
4417 local fid=$(path2fid $f)
4420 wait_request_state $fid RESTORE STARTED
4422 wait_request_state $fid RESTORE CANCELED
4423 wait_request_state $fid CANCEL SUCCEED
4425 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4428 [[ $flags == $target ]] ||
4429 error "Changelog flag is $flags not $target"
4433 run_test 223a "Changelog for restore canceled (import case)"
4436 # test needs a running copytool
4439 local f=$DIR/$tdir/$tfile
4441 fid=$(make_custom_file_for_progress $f 39 1000000)
4442 [ $? != 0 ] && skip "not enough free space" && return
4445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4446 wait_request_state $fid ARCHIVE SUCCEED
4449 wait_request_state $fid RESTORE STARTED
4451 wait_request_state $fid RESTORE CANCELED
4452 wait_request_state $fid CANCEL SUCCEED
4454 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4457 [[ $flags == $target ]] ||
4458 error "Changelog flag is $flags not $target"
4462 run_test 223b "Changelog for restore canceled (release case)"
4464 test_224A() { # was test_224
4465 # test needs a running copytool
4470 local f=$DIR/$tdir/$tfile
4471 local fid=$(copy_file /etc/passwd $f)
4474 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4475 wait_request_state $fid ARCHIVE SUCCEED
4478 wait_request_state $fid REMOVE SUCCEED
4480 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4483 [[ $flags == $target ]] ||
4484 error "Changelog flag is $flags not $target"
4486 run_test 224A "Changelog for remove"
4489 # test needs a running copytool
4494 local f=$DIR/$tdir/$tfile
4495 local fid=$(copy_file /etc/passwd $f)
4498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4499 wait_request_state $fid ARCHIVE SUCCEED
4501 copytool_remove_backend $fid
4503 # block copytool operations to allow for HSM request to be
4504 # submitted and file be unlinked (CDT will find object removed)
4509 # wait for request to reach CT
4510 wait_request_state $fid REMOVE STARTED
4516 wait_request_state $fid REMOVE FAILED
4518 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4522 [[ $flags == $target ]] ||
4523 error "Changelog flag is $flags not $target"
4527 run_test 224a "Changelog for failed remove"
4530 # test needs a running copytool
4533 # test is not usable because remove request is too fast
4534 # so it is always finished before cancel can be done ...
4535 echo "Test disabled"
4539 local f=$DIR/$tdir/$tfile
4541 fid=$(make_custom_file_for_progress $f 39 1000000)
4542 [ $? != 0 ] && skip "not enough free space" && return
4545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4546 wait_request_state $fid ARCHIVE SUCCEED
4548 # if cdt is on, it can serve too quickly the request
4553 wait_request_state $fid REMOVE CANCELED
4554 wait_request_state $fid CANCEL SUCCEED
4556 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4557 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4558 tail -n 1 | awk '{print $5}')
4561 [[ $flags == $target ]] ||
4562 error "Changelog flag is $flags not $target"
4564 run_test 225 "Changelog for remove canceled"
4567 # test needs a running copytool
4572 local f1=$DIR/$tdir/$tfile-1
4573 local f2=$DIR/$tdir/$tfile-2
4574 local f3=$DIR/$tdir/$tfile-3
4575 local fid1=$(copy_file /etc/passwd $f1)
4576 local fid2=$(copy_file /etc/passwd $f2)
4577 copy_file /etc/passwd $f3
4580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4581 wait_request_state $fid1 ARCHIVE SUCCEED
4583 $LFS hsm_archive $f2
4584 wait_request_state $fid2 ARCHIVE SUCCEED
4586 rm $f1 || error "rm $f1 failed"
4588 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4591 [[ $flags == $target ]] ||
4592 error "Changelog flag is $flags not $target"
4594 mv $f3 $f2 || error "mv $f3 $f2 failed"
4596 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4599 [[ $flags == $target ]] ||
4600 error "Changelog flag is $flags not $target"
4602 run_test 226 "changelog for last rm/mv with exiting archive"
4604 check_flags_changes() {
4612 $LFS hsm_set --$hsm_flag $f ||
4613 error "Cannot set $hsm_flag on $f"
4614 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4615 local seen=${#flags[*]}
4617 [[ $seen == $cnt ]] ||
4618 error "set $hsm_flag: Changelog events $seen != $cnt"
4619 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4620 error "set $hsm_flag: Changelog flags are "\
4621 "${flags[$((cnt - 1))]} not $target"
4623 $LFS hsm_clear --$hsm_flag $f ||
4624 error "Cannot clear $hsm_flag on $f"
4625 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4628 [[ $cnt == $seen ]] ||
4629 error "clear $hsm_flag: Changelog events $seen != $cnt"
4631 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4632 error "clear $hsm_flag: Changelog flag is "\
4633 "${flags[$((cnt - 1))]} not $target"
4637 # test needs a running copytool
4644 for i in norelease noarchive exists archived
4646 local f=$DIR/$tdir/$tfile-$i
4647 local fid=$(copy_file /etc/passwd $f)
4648 check_flags_changes $f $fid $i 0 1
4651 f=$DIR/$tdir/$tfile---lost
4652 fid=$(copy_file /etc/passwd $f)
4653 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4654 wait_request_state $fid ARCHIVE SUCCEED
4655 check_flags_changes $f $fid lost 3 1
4657 run_test 227 "changelog when explicit setting of HSM flags"
4660 # test needs a running copytool
4663 local fid=$(create_small_sync_file $DIR/$tfile)
4664 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4665 wait_request_state $fid ARCHIVE SUCCEED
4667 $LFS hsm_release $DIR/$tfile
4668 check_hsm_flags $DIR/$tfile "0x0000000d"
4670 filefrag $DIR/$tfile | grep " 1 extent found" ||
4671 error "filefrag on released file must return only one extent"
4673 # only newer versions of cp detect sparse files by stat/FIEMAP
4675 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4676 error "copying $DIR/$tfile"
4677 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4679 $LFS hsm_release $DIR/$tfile
4680 check_hsm_flags $DIR/$tfile "0x0000000d"
4682 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4684 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4686 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4687 error "comparing untarred $DIR/$tfile"
4689 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4690 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4692 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4695 # test needs a running copytool
4699 local maxrequest=$(get_hsm_param max_requests)
4700 local rqcnt=$(($maxrequest * 3))
4704 for i in $(seq -w 1 $rqcnt); do
4706 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4708 # we do it in 2 steps, so all requests arrive at the same time
4709 for i in $(seq -w 1 $rqcnt); do
4710 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4715 while [[ $cnt != 0 || $wt != 0 ]]; do
4717 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4718 $HSM_PARAM.actions |\
4719 grep STARTED | grep -v CANCEL | wc -l")
4720 [[ $cnt -le $maxrequest ]] ||
4721 error "$cnt > $maxrequest too many started requests"
4722 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4723 $HSM_PARAM.actions |\
4724 grep WAITING | wc -l")
4725 echo "max=$maxrequest started=$cnt waiting=$wt"
4728 run_test 250 "Coordinator max request"
4731 # test needs a running copytool
4734 local f=$DIR/$tdir/$tfile
4736 fid=$(make_custom_file_for_progress $f 103 1048576)
4737 [ $? != 0 ] && skip "not enough free space" && return
4740 # to have a short test
4741 local old_to=$(get_hsm_param active_request_timeout)
4742 set_hsm_param active_request_timeout 4
4743 # to be sure the cdt will wake up frequently so
4744 # it will be able to cancel the "old" request
4745 local old_loop=$(get_hsm_param loop_period)
4746 set_hsm_param loop_period 2
4749 # clear locks to avoid extra delay caused by flush/cancel
4750 # and thus prevent early copytool death to timeout.
4751 cancel_lru_locks osc
4753 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4754 wait_request_state $fid ARCHIVE STARTED
4756 wait_request_state $fid ARCHIVE CANCELED
4758 set_hsm_param active_request_timeout $old_to
4759 set_hsm_param loop_period $old_loop
4761 run_test 251 "Coordinator request timeout"
4765 local f=$DIR/$tdir/$tfile
4766 local fid=$(create_empty_file "$f")
4768 # to have a short test
4769 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4770 set_hsm_param loop_period 1
4775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4776 wait_request_state $fid ARCHIVE STARTED
4779 stack_trap "set_hsm_param active_request_timeout \
4780 $(get_hsm_param active_request_timeout)" EXIT
4781 set_hsm_param active_request_timeout 1
4783 wait_request_state $fid ARCHIVE CANCELED
4786 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4790 # test needs a running copytool
4794 local f=$DIR/$tdir/$tfile
4796 dd if=/dev/zero of=$f bs=1MB count=10
4797 local fid=$(path2fid $f)
4799 $LFS hsm_archive $f || error "could not archive file"
4800 wait_request_state $fid ARCHIVE SUCCEED
4802 # clear locks to discard inode data
4803 cancel_lru_locks osc
4805 #define OBD_FAIL_MDC_MERGE 0x807
4806 $LCTL set_param fail_loc=0x807
4808 #expect error here, instead of release with wrong size
4811 if ((rc == 0)); then
4812 file_size=$(stat -c '%s' $f)
4813 if ((file_size != 10485760)); then
4814 error "Wrong file size after hsm_release"
4817 echo "could not release file"
4820 run_test 253 "Check for wrong file size after release"
4824 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4825 skip "need MDS version at least 2.10.56" && return
4827 # Check that the counters are initialized to 0
4829 for request_type in archive restore remove; do
4830 count="$(get_hsm_param ${request_type}_count)" ||
4831 error "Reading ${request_type}_count failed with $?"
4833 [ "$count" -eq 0 ] ||
4834 error "Expected ${request_type}_count to be " \
4838 run_test 254a "Request counters are initialized to zero"
4842 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4843 skip "need MDS version at least 2.10.56" && return
4845 # The number of request to launch (at least 32)
4846 local request_count=$((RANDOM % 32 + 32))
4847 printf "Will launch %i requests of each type\n" "$request_count"
4849 # Launch a copytool to process requests
4852 # Set hsm.max_requests to allow starting all requests at the same time
4854 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4855 set_hsm_param max_requests "$request_count"
4859 for request_type in archive restore remove; do
4860 printf "Checking %s requests\n" "${request_type}"
4861 # Suspend the copytool to give us time to read the proc files
4864 for ((i = 0; i < $request_count; i++)); do
4865 case $request_type in
4867 create_empty_file "$DIR/$tdir/$tfile-$i" \
4871 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4874 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4877 # Give the coordinator 10 seconds to start every request
4879 while get_hsm_param actions | grep -q WAITING; do
4882 [ $timeout -gt 0 ] ||
4883 error "${request_type^} requests took too " \
4887 count="$(get_hsm_param ${request_type}_count)"
4888 [ "$count" -eq "$request_count" ] ||
4889 error "Expected '$request_count' (!= '$count') " \
4890 "active $request_type requests"
4892 # Let the copytool process the requests
4894 # Give it 10 seconds maximum
4896 while get_hsm_param actions | grep -q STARTED; do
4899 [ $timeout -gt 0 ] ||
4900 error "${request_type^} requests took too " \
4904 count="$(get_hsm_param ${request_type}_count)"
4905 [ "$count" -eq 0 ] ||
4906 error "Expected 0 (!= '$count') " \
4907 "active $request_type requests"
4910 run_test 254b "Request counters are correctly incremented and decremented"
4913 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4915 # the only way to test ondisk conf is to restart MDS ...
4916 echo "Stop coordinator and remove coordinator state at mount"
4919 # clean on disk conf set by default
4920 cdt_clear_mount_state
4921 cdt_check_state stopped
4923 # check cdt still off after umount/remount
4925 cdt_check_state stopped
4927 echo "Set coordinator start at mount, and start coordinator"
4928 cdt_set_mount_state enabled
4931 cdt_check_state enabled
4933 # check cdt still on after umount/remount
4935 cdt_check_state enabled
4937 # we are back to original state (cdt started at mount)
4939 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4942 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4944 local ai=$(get_hsm_param default_archive_id)
4945 local new=$((ai + 1))
4947 set_hsm_param default_archive_id $new -P
4949 local res=$(get_hsm_param default_archive_id)
4952 set_hsm_param default_archive_id "" "-P -d"
4954 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4956 run_test 301 "HSM tunnable are persistent"
4959 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4961 local ai=$(get_hsm_param default_archive_id)
4962 local new=$((ai + 1))
4967 set_hsm_param default_archive_id $new -P
4970 for mdtno in $(seq 1 $MDSCOUNT); do
4975 cdt_check_state enabled
4977 local res=$(get_hsm_param default_archive_id)
4980 set_hsm_param default_archive_id "" "-P -d"
4982 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4984 run_test 302 "HSM tunnable are persistent when CDT is off"
4987 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4993 local dir_mdt0=$DIR/$tdir/mdt0
4994 local dir_mdt1=$DIR/$tdir/mdt1
4996 # create 1 dir per MDT
4997 stack_trap "rm -rf $dir_mdt0"
4998 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4999 stack_trap "rm -rf $dir_mdt1"
5000 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5002 # create 1 file in each MDT
5003 local fid1=$(create_small_file $dir_mdt0/$tfile)
5004 local fid2=$(create_small_file $dir_mdt1/$tfile)
5006 # check that hsm request on mdt0 is sent to the right MDS
5007 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5008 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5009 echo "archive successful on mdt0"
5011 # check that hsm request on mdt1 is sent to the right MDS
5012 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5013 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5014 echo "archive successful on mdt1"
5016 run_test 400 "Single request is sent to the right MDT"
5019 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5025 local dir_mdt0=$DIR/$tdir/mdt0
5026 local dir_mdt1=$DIR/$tdir/mdt1
5028 # create 1 dir per MDT
5029 stack_trap "rm -rf $dir_mdt0" EXIT
5030 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5031 stack_trap "rm -rf $dir_mdt1" EXIT
5032 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5034 # create 1 file in each MDT
5035 local fid1=$(create_small_file $dir_mdt0/$tfile)
5036 local fid2=$(create_small_file $dir_mdt1/$tfile)
5038 # check that compound requests are shunt to the rights MDTs
5039 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5040 error "lfs hsm_archive"
5041 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5042 echo "archive successful on mdt0"
5043 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5044 echo "archive successful on mdt1"
5046 run_test 401 "Compound requests split and sent to their respective MDTs"
5048 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5053 local node=$(facet_active_host $facet)
5055 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5056 awk '{print $4}'); do
5057 echo "$3 $mdc on $node"
5058 do_facet $facet "$LCTL --device $mdc $state" || return 1
5063 # deactivate all mdc on agent1
5064 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5066 copytool setup --no-fail
5068 check_agent_unregistered "uuid" # match any agent
5070 # no expected running copytool
5071 search_copytools $agent && error "Copytool start should have failed"
5074 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5076 run_test 402a "Copytool start fails if all MDTs are inactive"
5083 local f=$DIR/$tdir/$tfile
5084 touch $f || error "touch $f failed"
5085 local fid=$(path2fid $f)
5087 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5088 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5089 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5091 # give time for CDT to send request and to keep it for retry
5092 wait_for_loop_period
5094 wait_request_state $fid ARCHIVE WAITING
5096 do_facet $SINGLEAGT lctl set_param fail_loc=0
5098 # request should succeed now
5099 wait_request_state $fid ARCHIVE SUCCEED
5101 run_test 402b "CDT must retry request upon slow start of CT"
5104 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5106 local agent=$(facet_active_host $SINGLEAGT)
5108 # deactivate all mdc for MDT0001
5109 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5112 local uuid=$(get_agent_uuid $agent)
5113 # check the agent is registered on MDT0000, and not on MDT0001
5114 check_agent_registered_by_mdt $uuid 0
5115 check_agent_unregistered_by_mdt $uuid 1
5117 # check running copytool process
5118 search_copytools $agent || error "No running copytools on $agent"
5120 # reactivate all mdc for MDT0001
5121 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5123 # make sure the copytool is now registered to all MDTs
5124 check_agent_registered $uuid
5126 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5129 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5133 # create files on both MDT0000 and MDT0001
5136 local dir_mdt0=$DIR/$tdir/mdt0
5137 stack_trap "rm -rf $dir_mdt0" EXIT
5138 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5140 # create 1 file on mdt0
5141 local fid1=$(create_small_file $dir_mdt0/$tfile)
5143 # deactivate all mdc for MDT0001
5144 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5146 # send an HSM request for files in MDT0000
5147 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5149 # check for completion of files in MDT0000
5150 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5151 echo "archive successful on mdt0"
5153 # reactivate all mdc for MDT0001
5154 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5156 run_test 404 "Inactive MDT does not block requests for active MDTs"
5159 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5165 local striped_dir=$DIR/$tdir/striped_dir
5167 # create striped dir on all of MDTs
5168 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5170 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5171 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5172 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5173 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5175 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5176 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5177 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5178 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5180 # check that compound requests are shunt to the rights MDTs
5181 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5182 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5183 error "lfs hsm_archive"
5185 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5186 echo "archive successful on $fid1"
5187 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5188 echo "archive successful on $fid2"
5189 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5190 echo "archive successful on $fid3"
5191 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5192 echo "archive successful on $fid4"
5194 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5195 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5196 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5197 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5199 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5200 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5201 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5202 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5204 run_test 405 "archive and release under striped directory"
5207 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5209 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5210 skip "need MDS version at least 2.7.64" && return 0
5215 fid=$(create_small_file $DIR/$tdir/$tfile)
5220 $LFS hsm_archive $DIR/$tdir/$tfile
5221 wait_request_state "$fid" ARCHIVE SUCCEED
5222 $LFS hsm_release $DIR/$tdir/$tfile
5224 # Should migrate $tdir but not $tfile.
5225 $LFS migrate -m1 $DIR/$tdir &&
5226 error "migrating HSM an archived file should fail"
5228 $LFS hsm_restore $DIR/$tdir/$tfile
5229 wait_request_state "$fid" RESTORE SUCCEED
5231 $LFS hsm_remove $DIR/$tdir/$tfile
5232 wait_request_state "$fid" REMOVE SUCCEED
5234 cat $DIR/$tdir/$tfile > /dev/null ||
5235 error "cannot read $DIR/$tdir/$tfile"
5237 $LFS migrate -m1 $DIR/$tdir ||
5238 error "cannot complete migration after HSM remove"
5240 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5241 if ((mdt_index != 1)); then
5242 error "expected MDT index 1, got $mdt_index"
5245 # Refresh fid after migration.
5246 fid=$(path2fid $DIR/$tdir/$tfile)
5249 $LFS hsm_archive $DIR/$tdir/$tfile
5250 wait_request_state "$fid" ARCHIVE SUCCEED 1
5252 lctl set_param debug=+trace
5253 $LFS hsm_release $DIR/$tdir/$tfile ||
5254 error "cannot release $DIR/$tdir/$tfile"
5256 $LFS hsm_restore $DIR/$tdir/$tfile
5257 wait_request_state "$fid" RESTORE SUCCEED 1
5259 cat $DIR/$tdir/$tfile > /dev/null ||
5260 error "cannot read $DIR/$tdir/$tfile"
5262 run_test 406 "attempting to migrate HSM archived files is safe"
5265 needclients 2 || return 0
5266 # test needs a running copytool
5271 local f=$DIR/$tdir/$tfile
5272 local f2=$DIR2/$tdir/$tfile
5274 fid=$(make_custom_file_for_progress $f 39 1000000)
5275 [ $? != 0 ] && skip "not enough free space" && return
5277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5278 wait_request_state $fid ARCHIVE SUCCEED
5281 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5282 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5285 # 1st request holds layout lock while appropriate
5286 # RESTORE record is still not added to llog
5290 # after umount hsm_actions->O/x/x log shouldn't have
5291 # double RESTORE records like below
5292 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5293 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5295 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5298 wait_request_state $fid RESTORE SUCCEED
5300 run_test 407 "Check for double RESTORE records in llog"
5304 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5305 skip "HSM migrate is not supported" && return
5307 test_mkdir -p $DIR/$tdir
5308 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5310 run_test 500 "various LLAPI HSM tests"
5315 check_and_cleanup_lustre