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
148 cdt_set_sanity_policy
153 # get MDT device for each mdc
154 for mdtno in $(seq 1 $MDSCOUNT); do
155 local idx=$(($mdtno - 1))
156 MDT[$idx]=$($LCTL get_param -n \
157 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
158 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
163 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
168 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 echo "Killing existing copytools on $hosts"
171 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
175 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
176 local wait_timeout=200
177 local wait_start=$SECONDS
178 local wait_end=$((wait_start + wait_timeout))
179 local sleep_time=100000 # 0.1 second
181 while ((SECONDS < wait_end)); do
182 if ! search_copytools $hosts; then
183 echo "copytools stopped in $((SECONDS - wait_start))s"
187 echo "copytools still running on $hosts"
189 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
190 sleep_time=$(bc <<< "$sleep_time * 2")
193 # try to dump Copytool's stack
194 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
195 "echo t >/proc/sysrq-trigger"
197 echo "copytools failed to stop in ${wait_timeout}s"
202 copytool_monitor_setup() {
203 local facet=${1:-$SINGLEAGT}
204 local agent=$(facet_active_host $facet)
206 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
207 local test_dir=$(do_node $agent "$cmd") ||
208 error "Failed to create tempdir on $agent"
209 export HSMTOOL_MONITOR_DIR=$test_dir
211 # Create the fifo and a monitor (cat dies when copytool dies)
212 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
213 error "failed to create copytool fifo on $agent"
214 cmd="cat $test_dir/fifo > $test_dir/events &"
215 cmd+=" echo \\\$! > $test_dir/monitor_pid"
217 if [[ $PDSH == *Rmrsh* ]]; then
218 # This is required for pdsh -Rmrsh and its handling of remote
220 # Regular ssh and pdsh -Rssh work fine without this
221 # backgrounded subshell nonsense.
222 (do_node $agent "$cmd") &
223 export HSMTOOL_MONITOR_PDSH=$!
225 # Slightly racy, but just making a best-effort to catch obvious
228 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
229 error "Failed to start copytool monitor on $agent"
231 do_node $agent "$cmd"
233 error "Failed to start copytool monitor on $agent"
238 copytool_monitor_cleanup() {
239 local facet=${1:-$SINGLEAGT}
240 local agent=$(facet_active_host $facet)
242 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
243 # Should die when the copytool dies, but just in case.
244 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
245 cmd+=" 2>/dev/null || true"
246 do_node $agent "$cmd"
247 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
248 export HSMTOOL_MONITOR_DIR=
251 # The pdsh should die on its own when the monitor dies. Just
252 # in case, though, try to clean up to avoid any cruft.
253 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
254 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
255 export HSMTOOL_MONITOR_PDSH=
261 local host="$(facet_host "$1")"
262 local prefix=$TESTLOG_PREFIX
263 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
265 printf "${prefix}.copytool${archive_id}_log.${host}.log"
270 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
271 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
272 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
273 [ ${#misc_options[@]} -gt 0 ] &&
274 cmd+=" $(IFS=" " echo "$@")"
275 cmd+=" \"$mountpoint\""
277 echo "Starting copytool $facet on $(facet_host $facet)"
278 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
279 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
283 local facet="${1:-$SINGLEAGT}"
285 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
294 local fail_on_error=true
295 local -a misc_options
296 while [ $# -gt 0 ]; do
304 local mountpoint="$1"
308 local archive_id="$1"
312 local bandwidth="$1" # in MB/s
315 local fail_on_error=false
318 # Uncommon(/copytool dependent) option
325 # Use default values if needed
326 local facet=${facet:-$SINGLEAGT}
327 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
328 local hsm_root="$(hsm_root "$facet")"
330 stack_trap "do_facet $facet \"rm -rf \\\"$hsm_root\\\"\"" EXIT
331 do_facet $facet "mkdir -p \"$hsm_root\"" ||
332 error "mkdir \"$hsm_root\" failed"
336 local copytool=lhsmtool
340 __${copytool}_${action} "${misc_options[@]}"
341 if [ $? -ne 0 ]; then
346 local host="$(facet_host $facet)"
347 error_msg="Failed to start copytool $facet on '$host'"
351 $fail_on_error && error "$error_msg" || echo "$error_msg"
356 local facet=${1:-$SINGLEAGT}
357 # Use MOUNT2 by default if defined
358 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
360 local hsm_root=${4:-$(copytool_device $facet)}
362 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
364 local agent=$(facet_active_host $facet)
366 if $HSM_ARCHIVE_PURGE; then
367 echo "Purging archive on $agent"
368 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
371 echo "Starting copytool $facet on $agent"
372 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
373 error "mkdir '$hsm_root/$HSMTMP' failed"
374 # bandwidth is limited to 1MB/s so the copy time is known and
375 # independent of hardware
376 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
377 cmd+=" --hsm-root $hsm_root/$HSMTMP"
378 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
379 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
380 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
381 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
382 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
383 cmd+=" --bandwidth 1 $lustre_mntpnt"
385 # Redirect the standard output and error to a log file which
386 # can be uploaded to Maloo.
387 local prefix=$TESTLOG_PREFIX
388 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
389 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
391 stack_trap cleanup EXIT
392 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
393 if [[ $? != 0 ]]; then
394 [[ $HSMTOOL_NOERROR == true ]] ||
395 error "start copytool $facet on $agent failed"
396 echo "start copytool $facet on $agent failed"
400 get_copytool_event_log() {
401 local facet=${1:-$SINGLEAGT}
402 local agent=$(facet_active_host $facet)
404 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
405 error "Can't get event log: No monitor directory!"
407 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
408 error "Could not collect event log from $agent"
413 local agt_facet=$SINGLEAGT
414 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
415 local hsm_root=$(copytool_device $agt_facet)
417 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
424 kill_copytools $agt_hosts
425 wait_copytools $agt_hosts || error "copytools failed to stop"
427 # Clean all CDTs orphans requests from previous tests that
428 # would otherwise need to timeout to clear.
429 for ((i = 0; i < MDSCOUNT; i++)); do
431 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
432 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
434 # Skip already stopping or stopped CDTs.
435 [[ "${state[$i]}" =~ ^stop ]] && continue
437 do_facet $facet "$LCTL set_param $param=shutdown"
440 for ((i = 0; i < MDSCOUNT; i++)); do
441 # Only check and restore CDTs that we stopped in the first loop.
442 [[ "${state[$i]}" =~ ^stop ]] && continue
445 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
447 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
448 error "$facet CDT state is not stopped"
450 # Restore old CDT state.
451 do_facet $facet "$LCTL set_param $param=${state[$i]}"
454 for ((i = 0; i < MDSCOUNT; i++)); do
455 # Only check CDTs that we stopped in the first loop.
456 [[ "${state[$i]}" =~ ^stop ]] && continue
459 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
461 # Check that the old CDT state was restored.
462 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
463 20 || error "$facet CDT state is not '${state[$i]}'"
466 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
467 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
472 local agents=${1:-$(facet_active_host $SINGLEAGT)}
474 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
475 echo "Copytool is suspended on $agents"
478 copytool_continue() {
479 local agents=${1:-$(facet_active_host $SINGLEAGT)}
481 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
482 echo "Copytool is continued on $agents"
485 copytool_remove_backend() {
487 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
488 echo "Remove from backend: $fid = $be"
489 do_facet $SINGLEAGT rm -f $be
493 mkdir -p "$(dirname "$2")" ||
494 error "cannot create directory '$(dirname "$2")'"
496 do_facet $SINGLEAGT \
497 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
498 --import $1 $2 $MOUNT" ||
499 error "import of $1 to $2 failed"
502 file_creation_failure() {
509 df $MOUNT $MOUNT2 >&2
510 error "Not enough space to create $file with $cmd"
513 error "cannot create $file with $cmd, status=$err"
518 # Creates a file using dd
524 local source=${5:-/dev/zero}
528 if [ -n "$conv" ]; then
532 # Create the directory in case it does not exist
533 mkdir -p "$(dirname "$file")"
534 # Delete the file in case it already exist
537 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
538 path2fid "$file" || error "cannot get FID of '$file'"
541 echo "cannot create file '$file'" >&2;
542 # Let the caller decide what to do on error
547 create_empty_file() {
548 create_file "${1/$DIR/$DIR2}" 1M 0 ||
549 file_creation_failure dd "${1/$DIR/$DIR2}" $?
552 create_small_file() {
553 local source_file=/dev/urandom
556 local conv=${2:-fsync}
558 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
559 file_creation_failure dd "${1/$DIR/$DIR2}" $?
562 create_small_sync_file() {
563 create_small_file "$1" sync
566 create_archive_file() {
567 local file="$HSM_ARCHIVE/$1"
569 local source=/dev/urandom
571 # Create the counterpart directory of the archive
572 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
573 error "cannot create archive directory '$(dirname "$file")'"
575 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
576 error "cannot create archive file '$file'"
580 local file=$HSM_ARCHIVE/$2
581 do_facet $SINGLEAGT mkdir -p $(dirname $file)
582 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
591 if [[ "$value" != "" ]]; then
594 for mdtno in $(seq 1 $MDSCOUNT); do
595 local idx=$(($mdtno - 1))
596 local facet=mds${mdtno}
597 # if $arg include -P option, run 1 set_param per MDT on the MGS
598 # else, run set_param on each MDT
599 [[ $arg = *"-P"* ]] && facet=mgs
600 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
601 [[ $? != 0 ]] && rc=1
611 for mdtno in $(seq 1 $MDSCOUNT); do
612 local idx=$(($mdtno - 1))
613 wait_result mds${mdtno} \
614 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
616 error "$key state is not '$target' on mds${mdtno}"
622 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
630 mdts_set_param "$opt -n" "hsm.$param" "$value"
637 mdts_set_param "" hsm_control "$cmd"
638 mdts_check_param hsm_control "$target" 10
641 cdt_set_sanity_policy() {
642 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
645 mdts_set_param "" hsm.policy "+NRA"
646 mdts_set_param "" hsm.policy "-NBR"
647 CDT_POLICY_HAD_CHANGED=
652 mdts_set_param "" hsm.policy "+NRA"
653 CDT_POLICY_HAD_CHANGED=true
656 cdt_clear_no_retry() {
657 mdts_set_param "" hsm.policy "-NRA"
658 CDT_POLICY_HAD_CHANGED=true
661 cdt_set_non_blocking_restore() {
662 mdts_set_param "" hsm.policy "+NBR"
663 CDT_POLICY_HAD_CHANGED=true
666 cdt_clear_non_blocking_restore() {
667 mdts_set_param "" hsm.policy "-NBR"
668 CDT_POLICY_HAD_CHANGED=true
671 cdt_clear_mount_state() {
672 mdts_set_param "-P -d" hsm_control ""
675 cdt_set_mount_state() {
676 mdts_set_param "-P" hsm_control "$1"
677 # set_param -P is asynchronous operation and could race with set_param.
678 # In such case configs could be retrieved and applied at mgc after
679 # set_param -P completion. Sleep here to avoid race with set_param.
680 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
681 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
682 # and 10 seconds to retrieve config from server.
687 mdts_check_param hsm_control "$1" 20
691 set_test_state disabled disabled
695 set_test_state enabled enabled
699 set_test_state shutdown stopped
703 set_test_state purge enabled
709 cdt_set_sanity_policy
713 local client_count=$1
714 if [[ $CLIENTCOUNT -lt $client_count ]]; then
715 skip "Need $client_count or more clients, have $CLIENTCOUNT"
722 $LFS path2fid $1 | tr -d '[]'
723 return ${PIPESTATUS[0]}
731 if [[ $u == "user" ]]; then
732 st=$($RUNAS $LFS hsm_state $f)
735 st=$($LFS hsm_state $f)
738 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
740 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
744 get_hsm_archive_id() {
747 st=$($LFS hsm_state $f)
748 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
750 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
758 local st=$(get_hsm_flags $f)
759 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
762 check_hsm_flags_user() {
766 local st=$(get_hsm_flags $f user)
767 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
779 if [[ "$3" != 1 ]]; then
783 cp $1 $f || file_creation_failure cp $f $?
785 path2fid $f || error "cannot get fid on $f"
788 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
790 # Note that this might lead to surprising behaviours such as deleting an
791 # important file for the currently running test
792 delete_large_files() {
793 printf "Deleting large files...\n" >&2
794 find $MOUNT -size +10M -delete
795 wait_delete_completed
798 make_custom_file_for_progress() {
799 local count=${2:-"39"}
800 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
803 [[ $count -gt 0 ]] || error "Invalid file size"
804 [[ $bs -gt 0 ]] || error "Invalid stripe size"
806 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
807 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
808 echo "It might be due to a lack of space in the filesystem" >&2
809 delete_large_files >&2
810 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
811 file_creation_failure dd "${1/$DIR/$DIR2}" $?
818 wait_update --verbose $(facet_active_host $facet) "$@"
821 wait_request_state() {
825 # 4th arg (mdt index) is optional
827 local mds=mds$(($mdtidx + 1))
829 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
830 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
832 wait_result $mds "$cmd" $state 200 ||
833 error "request on $fid is not $state on $mds"
836 get_request_state() {
840 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
841 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
844 get_request_count() {
848 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
849 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
852 # Ensure the number of HSM request for a given FID is correct
853 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
854 assert_request_count() {
855 local request_count=$(get_request_count $1 $2)
856 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
858 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
865 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
866 [[ -n $fid ]] && cmd+=" | grep '$fid'"
867 cmd+=" | egrep 'WAITING|STARTED'"
869 wait_result $SINGLEMDS "$cmd" "" $timeout ||
870 error "requests did not complete"
873 wait_for_grace_delay() {
874 local val=$(get_hsm_param grace_delay)
878 wait_for_loop_period() {
879 local val=$(get_hsm_param loop_period)
886 # python2.6 in EL6 includes an internal json module
887 local json_parser='import json; import fileinput;'
888 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
889 json_parser+='json.loads([line for line in '
890 json_parser+='fileinput.input()][0]).items()])'
892 echo $raw_event | python -c "$json_parser"
895 get_agent_by_uuid_mdt() {
898 local mds=mds$(($mdtidx + 1))
899 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
903 check_agent_registered_by_mdt() {
906 local mds=mds$(($mdtidx + 1))
907 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
908 if [[ ! -z "$agent" ]]; then
909 echo "found agent $agent on $mds"
911 error "uuid $uuid not found in agent list on $mds"
915 check_agent_unregistered_by_mdt() {
918 local mds=mds$(($mdtidx + 1))
919 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
920 if [[ -z "$agent" ]]; then
921 echo "uuid not found in agent list on $mds"
923 error "uuid found in agent list on $mds: $agent"
927 check_agent_registered() {
930 for mdsno in $(seq 1 $MDSCOUNT); do
931 check_agent_registered_by_mdt $uuid $((mdsno - 1))
935 check_agent_unregistered() {
938 for mdsno in $(seq 1 $MDSCOUNT); do
939 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
944 local agent=${1:-$(facet_active_host $SINGLEAGT)}
946 # Lustre mount-point is mandatory and last parameter on
948 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
950 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
952 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
958 # populate MDT device array
961 # cleanup from previous bad setup
964 # for recovery tests, coordinator needs to be started at mount
966 # the lustre conf must be without hsm on (like for sanity.sh)
967 echo "Set HSM on and start"
968 cdt_set_mount_state enabled
969 cdt_check_state enabled
971 echo "Set sanity-hsm HSM policy"
972 cdt_set_sanity_policy
974 # finished requests are quickly removed from list
975 set_hsm_param grace_delay 10
977 test_1A() { # was test_1
981 local f=$DIR/$tdir/$tfile
985 check_hsm_flags_user $f "0x00000000"
987 $RUNAS $LFS hsm_set --norelease $f ||
988 error "user could not change hsm flags"
989 check_hsm_flags_user $f "0x00000010"
991 $RUNAS $LFS hsm_clear --norelease $f ||
992 error "user could not clear hsm flags"
993 check_hsm_flags_user $f "0x00000000"
995 # User could not change those flags...
996 $RUNAS $LFS hsm_set --exists $f &&
997 error "user should not set this flag"
998 check_hsm_flags_user $f "0x00000000"
1001 $LFS hsm_set --exists $f ||
1002 error "root could not change hsm flags"
1003 check_hsm_flags_user $f "0x00000001"
1005 $LFS hsm_clear --exists $f ||
1006 error "root could not clear hsm state"
1007 check_hsm_flags_user $f "0x00000000"
1010 run_test 1A "lfs hsm flags root/non-root access"
1013 local f=$DIR/$tdir/$tfile
1014 local fid=$(create_small_file $f)
1018 $LFS hsm_archive $f || error "could not archive file"
1019 wait_request_state $fid ARCHIVE SUCCEED
1021 # Release and check states
1022 $LFS hsm_release $f || error "could not release file"
1023 echo -n "Verifying released state: "
1024 check_hsm_flags $f "0x0000000d"
1026 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
1028 run_test 1a "mmap & cat a HSM released file"
1032 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
1033 error "failed to set default stripe"
1034 local f=$DIR/$tdir/$tfile
1037 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1038 error "failed to create file"
1039 local fid=$(path2fid $f)
1044 $LFS hsm_archive $f || error "could not archive file"
1045 wait_request_state $fid ARCHIVE SUCCEED
1048 $LFS hsm_release $f || error "could not release file"
1049 echo "verify released state: "
1050 check_hsm_flags $f "0x0000000d" && echo "pass"
1053 $LFS hsm_restore $f || error "could not restore file"
1054 wait_request_state $fid RESTORE SUCCEED
1055 echo "verify restored state: "
1056 check_hsm_flags $f "0x00000009" && echo "pass"
1058 run_test 1b "Archive, Release and Restore composite file"
1062 chmod 777 $DIR/$tdir
1064 local f=$DIR/$tdir/$tfile
1067 # Test whether we can set the maximum archive number.
1068 local LOCAL_HSM_ARCHIVE_NUMBER=32
1069 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1070 error "root could not change hsm flags"
1071 check_hsm_flags_user $f "0x00000001"
1072 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1073 local st=$(get_hsm_archive_id $f)
1074 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1075 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1077 # Test whether setting archive number 0 results in no change.
1078 $LFS hsm_set --exists --archive-id 0 $f ||
1079 error "root could not change hsm flags"
1080 check_hsm_flags_user $f "0x00000001"
1081 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1082 st=$(get_hsm_archive_id $f)
1083 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1084 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1086 # Test whether setting archive number > 32 results in error.
1087 $LFS hsm_set --exists --archive-id 33 $f &&
1088 error "archive number is larger than 32"
1089 check_hsm_flags_user $f "0x00000001"
1091 # Test whether setting archive number 16 and archived flag.
1092 LOCAL_HSM_ARCHIVE_NUMBER=16
1093 $LFS hsm_set --exists --archived \
1094 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1095 error "root could not change hsm flags"
1096 check_hsm_flags_user $f "0x00000009"
1097 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1098 st=$(get_hsm_archive_id $f)
1099 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1100 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1102 run_test 1c "Check setting archive-id in lfs hsm_set"
1106 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1107 error "failed to set default stripe"
1108 local f=$DIR/$tdir/$tfile
1111 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1112 error "failed to create file"
1113 local fid=$(path2fid $f)
1118 $LFS hsm_archive $f || error "could not archive file"
1119 wait_request_state $fid ARCHIVE SUCCEED
1122 $LFS hsm_release $f || error "could not release file"
1123 echo "verify released state: "
1124 check_hsm_flags $f "0x0000000d" && echo "pass"
1127 $LFS hsm_restore $f || error "could not restore file"
1128 wait_request_state $fid RESTORE SUCCEED
1129 echo "verify restored state: "
1130 check_hsm_flags $f "0x00000009" && echo "pass"
1132 run_test 1d "Archive, Release and Restore DoM file"
1135 local f=$DIR/$tdir/$tfile
1137 create_empty_file "$f"
1138 # New files are not dirty
1139 check_hsm_flags $f "0x00000000"
1141 # For test, we simulate an archived file.
1142 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1143 check_hsm_flags $f "0x00000001"
1145 # chmod do not put the file dirty
1146 chmod 600 $f || error "could not chmod test file"
1147 check_hsm_flags $f "0x00000001"
1149 # chown do not put the file dirty
1150 chown $RUNAS_ID $f || error "could not chown test file"
1151 check_hsm_flags $f "0x00000001"
1153 # truncate put the file dirty
1154 $TRUNCATE $f 1 || error "could not truncate test file"
1155 check_hsm_flags $f "0x00000003"
1157 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1158 check_hsm_flags $f "0x00000001"
1160 run_test 2 "Check file dirtyness when doing setattr"
1166 # New files are not dirty
1167 cp -p /etc/passwd $f
1168 check_hsm_flags $f "0x00000000"
1170 # For test, we simulate an archived file.
1171 $LFS hsm_set --exists $f ||
1172 error "user could not change hsm flags"
1173 check_hsm_flags $f "0x00000001"
1175 # Reading a file, does not set dirty
1176 cat $f > /dev/null || error "could not read file"
1177 check_hsm_flags $f "0x00000001"
1179 # Open for write without modifying data, does not set dirty
1180 openfile -f O_WRONLY $f || error "could not open test file"
1181 check_hsm_flags $f "0x00000001"
1183 # Append to a file sets it dirty
1184 cp -p /etc/passwd $f.append || error "could not create file"
1185 $LFS hsm_set --exists $f.append ||
1186 error "user could not change hsm flags"
1187 dd if=/etc/passwd of=$f.append bs=1 count=3\
1188 conv=notrunc oflag=append status=noxfer ||
1189 file_creation_failure dd $f.append $?
1190 check_hsm_flags $f.append "0x00000003"
1192 # Modify a file sets it dirty
1193 cp -p /etc/passwd $f.modify || error "could not create file"
1194 $LFS hsm_set --exists $f.modify ||
1195 error "user could not change hsm flags"
1196 dd if=/dev/zero of=$f.modify bs=1 count=3\
1197 conv=notrunc status=noxfer ||
1198 file_creation_failure dd $f.modify $?
1199 check_hsm_flags $f.modify "0x00000003"
1201 # Open O_TRUNC sets dirty
1202 cp -p /etc/passwd $f.trunc || error "could not create file"
1203 $LFS hsm_set --exists $f.trunc ||
1204 error "user could not change hsm flags"
1205 cp /etc/group $f.trunc || error "could not override a file"
1206 check_hsm_flags $f.trunc "0x00000003"
1208 # Mmapped a file sets dirty
1209 cp -p /etc/passwd $f.mmap || error "could not create file"
1210 $LFS hsm_set --exists $f.mmap ||
1211 error "user could not change hsm flags"
1212 multiop $f.mmap OSMWUc || error "could not mmap a file"
1213 check_hsm_flags $f.mmap "0x00000003"
1215 run_test 3 "Check file dirtyness when opening for write"
1218 local f=$DIR/$tdir/$tfile
1219 local fid=$(create_small_file $f)
1222 local st=$(get_request_state $fid CANCEL)
1223 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1225 run_test 4 "Useless cancel must not be registered"
1228 # test needs a running copytool
1232 local f=$DIR/$tdir/$tfile
1233 local fid=$(copy_file /etc/passwd $f)
1235 wait_request_state $fid ARCHIVE SUCCEED
1237 check_hsm_flags $f "0x00000009"
1239 run_test 8 "Test default archive number"
1241 test_9A() { # was test_9
1242 # we do not use the default one to be sure
1243 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1244 copytool setup --archive-id $archive_id
1246 # give time for CT to register with MDTs
1247 sleep $(($MDSCOUNT*2))
1248 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1249 check_agent_registered $uuid
1252 local f=$DIR/$tdir/$tfile
1253 local fid=$(copy_file /etc/passwd $f)
1254 $LFS hsm_archive --archive $archive_id $f
1255 wait_request_state $fid ARCHIVE SUCCEED
1257 check_hsm_flags $f "0x00000009"
1259 run_test 9A "Use of explicit archive number, with dedicated copytool"
1262 needclients 3 || return 0
1268 # start all of the copytools
1269 for n in $(seq $AGTCOUNT); do
1270 copytool setup --facet agt$n
1274 for n in $(seq $AGTCOUNT); do
1275 file=$DIR/$tdir/$tfile.$n
1276 fid=$(create_small_file $file)
1278 $LFS hsm_archive $file || error "could not archive file $file"
1279 wait_request_state $fid ARCHIVE SUCCEED
1280 check_hsm_flags $file "0x00000009"
1283 run_test 9a "Multiple remote agents"
1286 # test needs a running copytool
1289 mkdir -p $DIR/$tdir/d1
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/hosts $f)
1292 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1293 error "hsm_archive failed"
1294 wait_request_state $fid ARCHIVE SUCCEED
1296 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1297 error "fid $fid not in archive $HSM_ARCHIVE"
1298 echo "Verifying content"
1299 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1300 echo "Verifying hsm state "
1301 check_hsm_flags $f "0x00000009"
1303 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1304 local st=$(get_hsm_archive_id $f)
1305 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1306 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1310 run_test 10a "Archive a file"
1313 # test needs a running copytool
1317 local f=$DIR/$tdir/$tfile
1318 local fid=$(copy_file /etc/hosts $f)
1319 $LFS hsm_archive $f || error "archive request failed"
1320 wait_request_state $fid ARCHIVE SUCCEED
1322 $LFS hsm_archive $f || error "archive of non dirty file failed"
1323 local cnt=$(get_request_count $fid ARCHIVE)
1324 [[ "$cnt" == "1" ]] ||
1325 error "archive of non dirty file must not make a request"
1327 run_test 10b "Archive of non dirty file must work without doing request"
1330 # test needs a running copytool
1334 local f=$DIR/$tdir/$tfile
1335 local fid=$(copy_file /etc/hosts $f)
1336 $LFS hsm_set --noarchive $f
1337 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1340 run_test 10c "Check forbidden archive"
1343 # test needs a running copytool
1347 local f=$DIR/$tdir/$tfile
1348 local fid=$(copy_file /etc/hosts $f)
1349 $LFS hsm_archive $f || error "cannot archive $f"
1350 wait_request_state $fid ARCHIVE SUCCEED
1352 local ar=$(get_hsm_archive_id $f)
1353 local dflt=$(get_hsm_param default_archive_id)
1354 [[ $ar == $dflt ]] ||
1355 error "archived file is not on default archive: $ar != $dflt"
1357 run_test 10d "Archive a file on the default archive id"
1361 copy2archive /etc/hosts $tdir/$tfile
1362 local f=$DIR/$tdir/$tfile
1364 import_file $tdir/$tfile $f
1365 echo -n "Verifying released state: "
1366 check_hsm_flags $f "0x0000000d"
1368 local LSZ=$(stat -c "%s" $f)
1369 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1371 echo "Verifying imported size $LSZ=$ASZ"
1372 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1373 echo -n "Verifying released pattern: "
1374 local PTRN=$($GETSTRIPE -L $f)
1376 [[ $PTRN == released ]] || error "Is not released"
1377 local fid=$(path2fid $f)
1378 echo "Verifying new fid $fid in archive"
1380 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1381 error "fid $fid not in archive $HSM_ARCHIVE"
1383 run_test 11a "Import a file"
1386 # test needs a running copytool
1390 local f=$DIR/$tdir/$tfile
1391 local fid=$(copy_file /etc/hosts $f)
1392 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1393 error "hsm_archive failed"
1394 wait_request_state $fid ARCHIVE SUCCEED
1396 local FILE_HASH=$(md5sum $f)
1401 echo "$FILE_HASH" | md5sum -c
1403 [[ $? -eq 0 ]] || error "Restored file differs"
1407 run_test 11b "Import a deleted file using its FID"
1410 # test needs a running copytool
1414 copy2archive /etc/hosts $tdir/$tfile
1416 local f=$DIR/$tdir/$tfile
1417 import_file $tdir/$tfile $f
1418 local f2=$DIR2/$tdir/$tfile
1419 echo "Verifying released state: "
1420 check_hsm_flags $f2 "0x0000000d"
1422 local fid=$(path2fid $f2)
1423 $LFS hsm_restore $f2
1424 wait_request_state $fid RESTORE SUCCEED
1426 echo "Verifying file state: "
1427 check_hsm_flags $f2 "0x00000009"
1429 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1431 [[ $? -eq 0 ]] || error "Restored file differs"
1435 run_test 12a "Restore an imported file explicitly"
1438 # test needs a running copytool
1442 copy2archive /etc/hosts $tdir/$tfile
1444 local f=$DIR/$tdir/$tfile
1445 import_file $tdir/$tfile $f
1446 echo "Verifying released state: "
1447 check_hsm_flags $f "0x0000000d"
1449 cat $f > /dev/null || error "File read failed"
1451 echo "Verifying file state after restore: "
1452 check_hsm_flags $f "0x00000009"
1454 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1456 [[ $? -eq 0 ]] || error "Restored file differs"
1460 run_test 12b "Restore an imported file implicitly"
1463 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1465 # test needs a running copytool
1468 local f=$DIR/$tdir/$tfile
1470 $LFS setstripe -c 2 "$f"
1472 fid=$(make_custom_file_for_progress $f 5)
1473 [ $? != 0 ] && skip "not enough free space" && return
1475 local FILE_CRC=$(md5sum $f)
1477 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1478 wait_request_state $fid ARCHIVE SUCCEED
1479 $LFS hsm_release $f || error "release $f failed"
1481 echo "$FILE_CRC" | md5sum -c
1483 [[ $? -eq 0 ]] || error "Restored file differs"
1485 run_test 12c "Restore a file with stripe of 2"
1488 # test needs a running copytool
1493 local f=$DIR/$tdir/$tfile
1494 local fid=$(copy_file /etc/hosts $f)
1495 $LFS hsm_restore $f || error "restore of non archived file failed"
1496 local cnt=$(get_request_count $fid RESTORE)
1497 [[ "$cnt" == "0" ]] ||
1498 error "restore non archived must not make a request"
1499 $LFS hsm_archive $f ||
1500 error "archive request failed"
1501 wait_request_state $fid ARCHIVE SUCCEED
1502 $LFS hsm_restore $f ||
1503 error "restore of non released file failed"
1504 local cnt=$(get_request_count $fid RESTORE)
1505 [[ "$cnt" == "0" ]] ||
1506 error "restore a non dirty file must not make a request"
1508 run_test 12d "Restore of a non archived, non released file must work"\
1509 " without doing request"
1512 # test needs a running copytool
1515 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1516 local f=$DIR/$tdir/$tfile
1517 local fid=$(copy_file /etc/hosts $f)
1518 $LFS hsm_archive $f || error "archive request failed"
1519 wait_request_state $fid ARCHIVE SUCCEED
1522 cat /etc/hosts >> $f
1526 $LFS hsm_restore $f && error "restore a dirty file must fail"
1529 run_test 12e "Check forbidden restore"
1532 # test needs a running copytool
1536 local f=$DIR/$tdir/$tfile
1537 local fid=$(copy_file /etc/hosts $f)
1539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1540 wait_request_state $fid ARCHIVE SUCCEED
1541 $LFS hsm_release $f || error "release of $f failed"
1543 wait_request_state $fid RESTORE SUCCEED
1545 echo -n "Verifying file state: "
1546 check_hsm_flags $f "0x00000009"
1548 diff -q /etc/hosts $f
1550 [[ $? -eq 0 ]] || error "Restored file differs"
1552 run_test 12f "Restore a released file explicitly"
1555 # test needs a running copytool
1559 local f=$DIR/$tdir/$tfile
1560 local fid=$(copy_file /etc/hosts $f)
1562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1563 wait_request_state $fid ARCHIVE SUCCEED
1564 $LFS hsm_release $f || error "release of $f failed"
1566 diff -q /etc/hosts $f
1569 # we check we had a restore done
1570 wait_request_state $fid RESTORE SUCCEED
1572 [[ $st -eq 0 ]] || error "Restored file differs"
1574 run_test 12g "Restore a released file implicitly"
1577 needclients 2 || return 0
1579 # test needs a running copytool
1583 local f=$DIR/$tdir/$tfile
1584 local fid=$(copy_file /etc/hosts $f)
1586 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1587 wait_request_state $fid ARCHIVE SUCCEED
1588 $LFS hsm_release $f || error "release of $f failed"
1590 do_node $CLIENT2 diff -q /etc/hosts $f
1593 # we check we had a restore done
1594 wait_request_state $fid RESTORE SUCCEED
1596 [[ $st -eq 0 ]] || error "Restored file differs"
1598 run_test 12h "Restore a released file implicitly from a second node"
1601 # test needs a running copytool
1605 local f=$DIR/$tdir/$tfile
1606 local fid=$(copy_file /etc/passwd $f)
1607 $LFS hsm_archive $f || error "archive of $f failed"
1608 wait_request_state $fid ARCHIVE SUCCEED
1610 $LFS hsm_release $f || error "release of $f failed"
1614 [[ $? -eq 0 ]] || error "Restored file differs"
1616 run_test 12m "Archive/release/implicit restore"
1619 # test needs a running copytool
1623 copy2archive /etc/hosts $tdir/$tfile
1625 local f=$DIR/$tdir/$tfile
1626 import_file $tdir/$tfile $f
1628 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1629 error "Restored file differs"
1631 $LFS hsm_release $f || error "release of $f failed"
1635 run_test 12n "Import/implicit restore/release"
1638 # test needs a running copytool
1642 local f=$DIR/$tdir/$tfile
1643 local fid=$(copy_file /etc/hosts $f)
1645 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1646 wait_request_state $fid ARCHIVE SUCCEED
1647 $LFS hsm_release $f || error "release of $f failed"
1649 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1650 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1652 # set no retry action mode
1655 diff -q /etc/hosts $f
1658 # we check we had a restore failure
1659 wait_request_state $fid RESTORE FAILED
1661 [[ $st -eq 0 ]] && error "Restore must fail"
1663 # remove no retry action mode
1666 # check file is still released
1667 check_hsm_flags $f "0x0000000d"
1669 # retry w/o failure injection
1670 do_facet $SINGLEMDS lctl set_param fail_loc=0
1672 # to be sure previous RESTORE result is gone
1674 wait_for_grace_delay
1676 diff -q /etc/hosts $f
1679 # we check we had a restore done
1680 wait_request_state $fid RESTORE SUCCEED
1682 [[ $st -eq 0 ]] || error "Restored file differs"
1684 run_test 12o "Layout-swap failure during Restore leaves file released"
1687 # test needs a running copytool
1691 local f=$DIR/$tdir/$tfile
1692 local fid=$(copy_file /etc/hosts $f)
1694 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1695 wait_request_state $fid ARCHIVE SUCCEED
1696 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1697 $LFS hsm_release $f || error "cannot release $f"
1698 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1699 $LFS hsm_release $f || error "cannot release $f"
1700 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1702 run_test 12p "implicit restore of a file on copytool mount point"
1704 cleanup_test_12q() {
1705 error "cannot umount $MOUNT3 on $SINGLEAGT"
1709 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1710 skip "need MDS version at least 2.7.58" && return 0
1712 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1713 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1714 error "cannot mount $MOUNT3 on $SINGLEAGT"
1716 # test needs a running copytool
1717 copytool setup -m "$MOUNT3"
1719 local f=$DIR/$tdir/$tfile
1720 local f2=$DIR2/$tdir/$tfile
1721 local fid=$(create_small_file $f)
1722 local orig_size=$(stat -c "%s" $f)
1724 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1725 wait_request_state $fid ARCHIVE SUCCEED
1727 $LFS hsm_release $f || error "could not release file"
1728 check_hsm_flags $f "0x0000000d"
1731 wait_copytools || error "copytool failed to stop"
1733 cat $f > /dev/null &
1735 # wait a bit to allow implicit restore request to be handled.
1736 # if not, next stat would also block on layout-lock.
1739 local size=$(stat -c "%s" $f2)
1740 [ $size -eq $orig_size ] ||
1741 error "$f2: wrong size after archive: $size != $orig_size"
1743 copytool setup -m "$MOUNT3"
1747 size=$(stat -c "%s" $f)
1748 [ $size -eq $orig_size ] ||
1749 error "$f: wrong size after restore: $size != $orig_size"
1751 size=$(stat -c "%s" $f2)
1752 [ $size -eq $orig_size ] ||
1753 error "$f2: wrong size after restore: $size != $orig_size"
1757 size=$(stat -c "%s" $f)
1759 error "$f: wrong size after overwrite: $size != 0"
1761 size=$(stat -c "%s" $f2)
1763 error "$f2: wrong size after overwrite: $size != 0"
1765 run_test 12q "file attributes are refreshed after restore"
1768 # test needs a running copytool
1771 local ARC_SUBDIR="import.orig"
1775 # populate directory to be imported
1776 for d in $(seq 1 10); do
1777 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1778 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1779 for f in $(seq 1 10); do
1780 CURR_FILE="$CURR_DIR/$tfile.$f"
1781 # write file-specific data
1782 do_facet $SINGLEAGT \
1783 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1784 "file=$CURR_FILE > $CURR_FILE"
1788 import_file "$ARC_SUBDIR" $DIR/$tdir
1789 # diff lustre content and origin (triggers file restoration)
1790 # there must be 10x10 identical files, and no difference
1791 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1792 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1793 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1794 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1796 [ $cnt_diff -eq 0 ] ||
1797 error "$cnt_diff imported files differ from read data"
1798 [ $cnt_ok -eq 100 ] ||
1799 error "not enough identical files ($cnt_ok != 100)"
1803 run_test 13 "Recursively import and restore a directory"
1806 # test needs a running copytool
1810 local f=$DIR/$tdir/$tfile
1811 local fid=$(create_small_file $f)
1812 local sum=$(md5sum $f | awk '{print $1}')
1813 $LFS hsm_archive $f || error "could not archive file"
1814 wait_request_state $fid ARCHIVE SUCCEED
1816 # create released file (simulate llapi_hsm_import call)
1817 local fid2=$(create_empty_file "$f")
1818 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1819 $LFS hsm_release $f || error "could not release file"
1821 # rebind the archive to the newly created file
1822 echo "rebind $fid to $fid2"
1824 do_facet $SINGLEAGT \
1825 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1826 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1828 # restore file and compare md5sum
1829 local sum2=$(md5sum $f | awk '{print $1}')
1831 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1835 run_test 14 "Rebind archived file to a new fid"
1838 # test needs a running copytool
1842 local f=$DIR/$tdir/$tfile
1844 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1848 for i in $(seq 1 $count); do
1849 fids[$i]=$(create_small_file $f.$i)
1850 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1851 $LFS hsm_archive $f.$i || error "could not archive file"
1853 wait_all_done $(($count*60))
1857 for i in $(seq 1 $count); do
1858 local fid2=$(create_empty_file "${f}.${i}")
1859 # add the rebind operation to the list
1860 echo ${fids[$i]} $fid2 >> $tmpfile
1862 # set it released (simulate llapi_hsm_import call)
1863 $LFS hsm_set --archived --exists $f.$i ||
1864 error "could not force hsm flags"
1865 $LFS hsm_release $f.$i || error "could not release file"
1867 nl=$(wc -l < $tmpfile)
1868 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1870 echo "rebind list of files"
1871 do_facet $SINGLEAGT \
1872 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1873 --rebind $tmpfile $DIR" || error "could not rebind file list"
1875 # restore files and compare md5sum
1876 for i in $(seq 1 $count); do
1877 local sum2=$(md5sum $f.$i | awk '{print $1}')
1878 [[ $sum2 == ${sums[$i]} ]] ||
1879 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1885 run_test 15 "Rebind a list of files"
1888 # test needs a running copytool
1892 # create a known size file so we can verify transfer speed
1895 dd if=/dev/zero of=$ref bs=1M count=20
1898 local f=$DIR/$tdir/$tfile
1899 local fid=$(copy_file $ref $f)
1901 local start=$(date +%s)
1903 wait_request_state $fid ARCHIVE SUCCEED
1904 local end=$(date +%s)
1905 # Add 1 to account for rounding errors between start and end (LU-8155)
1906 local duration=$((end - start + 1))
1908 [[ $duration -ge $((goal - 1)) ]] ||
1909 error "Transfer is too fast $duration < $goal"
1911 run_test 16 "Test CT bandwith control option"
1914 local f=$DIR/$tdir/$tfile
1915 create_empty_file "$f"
1917 # Could not release a non-archived file
1918 $LFS hsm_release $f && error "release should not succeed"
1920 # For following tests, we must test them with HS_ARCHIVED set
1921 $LFS hsm_set --exists --archived $f || error "could not add flag"
1923 # Could not release a file if no-release is set
1924 $LFS hsm_set --norelease $f || error "could not add flag"
1925 $LFS hsm_release $f && error "release should not succeed"
1926 $LFS hsm_clear --norelease $f || error "could not remove flag"
1928 # Could not release a file if lost
1929 $LFS hsm_set --lost $f || error "could not add flag"
1930 $LFS hsm_release $f && error "release should not succeed"
1931 $LFS hsm_clear --lost $f || error "could not remove flag"
1933 # Could not release a file if dirty
1934 $LFS hsm_set --dirty $f || error "could not add flag"
1935 $LFS hsm_release $f && error "release should not succeed"
1936 $LFS hsm_clear --dirty $f || error "could not remove flag"
1938 run_test 20 "Release is not permitted"
1941 # test needs a running copytool
1944 local f=$DIR/$tdir/test_release
1946 # Create a file and check its states
1947 local fid=$(create_small_file $f)
1948 check_hsm_flags $f "0x00000000"
1950 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1951 # used until file is flushed to disk
1952 if [ $(facet_fstype ost1) == "zfs" ]; then
1953 # this causes an OST_SYNC rpc to be sent
1954 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1955 # clear locks to reread file data
1956 cancel_lru_locks osc
1959 local orig_size=$(stat -c "%s" $f)
1960 local orig_blocks=$(stat -c "%b" $f)
1962 start_full_debug_logging
1964 $LFS hsm_archive $f || error "could not archive file"
1965 wait_request_state $fid ARCHIVE SUCCEED
1967 local blocks=$(stat -c "%b" $f)
1968 [ $blocks -eq $orig_blocks ] ||
1969 error "$f: wrong block number after archive: " \
1970 "$blocks != $orig_blocks"
1971 local size=$(stat -c "%s" $f)
1972 [ $size -eq $orig_size ] ||
1973 error "$f: wrong size after archive: $size != $orig_size"
1975 # Release and check states
1976 $LFS hsm_release $f || error "could not release file"
1977 check_hsm_flags $f "0x0000000d"
1979 blocks=$(stat -c "%b" $f)
1980 [ $blocks -gt 5 ] &&
1981 error "$f: too many blocks after release: $blocks > 5"
1982 size=$(stat -c "%s" $f)
1983 [ $size -ne $orig_size ] &&
1984 error "$f: wrong size after release: $size != $orig_size"
1986 # Check we can release an file without stripe info
1990 check_hsm_flags $f "0x00000000"
1991 $LFS hsm_archive $f || error "could not archive file"
1992 wait_request_state $fid ARCHIVE SUCCEED
1994 # Release and check states
1995 $LFS hsm_release $f || error "could not release file"
1996 check_hsm_flags $f "0x0000000d"
1998 # Release again a file that is already released is OK
1999 $LFS hsm_release $f || fail "second release should succeed"
2000 check_hsm_flags $f "0x0000000d"
2002 stop_full_debug_logging
2004 run_test 21 "Simple release tests"
2007 # test needs a running copytool
2010 local f=$DIR/$tdir/test_release
2011 local swap=$DIR/$tdir/test_swap
2013 # Create a file and check its states
2014 local fid=$(create_small_file $f)
2015 check_hsm_flags $f "0x00000000"
2017 $LFS hsm_archive $f || error "could not archive file"
2018 wait_request_state $fid ARCHIVE SUCCEED
2020 # Release and check states
2021 $LFS hsm_release $f || error "could not release file"
2022 check_hsm_flags $f "0x0000000d"
2024 create_small_file $swap
2025 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2029 run_test 22 "Could not swap a release file"
2032 # test needs a running copytool
2035 local f=$DIR/$tdir/test_mtime
2037 # Create a file and check its states
2038 local fid=$(create_small_file $f)
2039 check_hsm_flags $f "0x00000000"
2041 $LFS hsm_archive $f || error "could not archive file"
2042 wait_request_state $fid ARCHIVE SUCCEED
2044 # Set modification time in the past
2045 touch -m -a -d @978261179 $f
2047 # Release and check states
2048 $LFS hsm_release $f || error "could not release file"
2049 check_hsm_flags $f "0x0000000d"
2051 local MTIME=$(stat -c "%Y" $f)
2052 local ATIME=$(stat -c "%X" $f)
2053 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2054 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2056 run_test 23 "Release does not change a/mtime (utime)"
2059 local file=$DIR/$tdir/$tfile
2068 # test needs a running copytool
2071 fid=$(create_small_file $file)
2073 # Create a file and check its states
2074 check_hsm_flags $file "0x00000000"
2076 # Ensure atime is less than mtime and ctime.
2080 atime0=$(stat -c "%X" $file)
2081 mtime0=$(stat -c "%Y" $file)
2082 ctime0=$(stat -c "%Z" $file)
2084 [ $atime0 -lt $mtime0 ] ||
2085 error "atime $atime0 is not less than mtime $mtime0"
2087 [ $atime0 -lt $ctime0 ] ||
2088 error "atime $atime0 is not less than ctime $ctime0"
2090 # Archive should not change any timestamps.
2091 $LFS hsm_archive $file || error "cannot archive '$file'"
2092 wait_request_state $fid ARCHIVE SUCCEED
2094 atime1=$(stat -c "%X" $file)
2095 mtime1=$(stat -c "%Y" $file)
2096 ctime1=$(stat -c "%Z" $file)
2098 [ $atime0 -eq $atime1 ] ||
2099 error "archive changed atime from $atime0 to $atime1"
2101 [ $mtime0 -eq $mtime1 ] ||
2102 error "archive changed mtime from $mtime0 to $mtime1"
2104 [ $ctime0 -eq $ctime1 ] ||
2105 error "archive changed ctime from $ctime0 to $ctime1"
2107 # Release should not change any timestamps.
2108 $LFS hsm_release $file || error "cannot release '$file'"
2109 check_hsm_flags $file "0x0000000d"
2111 atime1=$(stat -c "%X" $file)
2112 mtime1=$(stat -c "%Y" $file)
2113 ctime1=$(stat -c "%Z" $file)
2115 [ $atime0 -eq $atime1 ] ||
2116 error "release changed atime from $atime0 to $atime1"
2118 [ $mtime0 -eq $mtime1 ] ||
2119 error "release changed mtime from $mtime0 to $mtime1"
2121 [ $ctime0 -eq $ctime1 ] ||
2122 error "release changed ctime from $ctime0 to $ctime1"
2124 # Restore should not change any timestamps.
2125 $LFS hsm_restore $file
2126 wait_request_state $fid RESTORE SUCCEED
2128 atime1=$(stat -c "%X" $file)
2129 mtime1=$(stat -c "%Y" $file)
2130 ctime1=$(stat -c "%Z" $file)
2132 [ $atime0 -eq $atime1 ] ||
2133 error "restore changed atime from $atime0 to $atime1"
2135 [ $mtime0 -eq $mtime1 ] ||
2136 error "restore changed mtime from $mtime0 to $mtime1"
2138 [ $ctime0 -eq $ctime1 ] ||
2139 error "restore changed ctime from $ctime0 to $ctime1"
2142 wait_copytools || error "Copytools failed to stop"
2144 # Once more, after unmount and mount.
2145 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2146 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2148 atime1=$(stat -c "%X" $file)
2149 mtime1=$(stat -c "%Y" $file)
2150 ctime1=$(stat -c "%Z" $file)
2152 [ $atime0 -eq $atime1 ] ||
2153 error "remount changed atime from $atime0 to $atime1"
2155 [ $mtime0 -eq $mtime1 ] ||
2156 error "remount changed mtime from $mtime0 to $mtime1"
2158 [ $ctime0 -eq $ctime1 ] ||
2159 error "remount changed ctime from $ctime0 to $ctime1"
2161 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2164 local file=$DIR/$tdir/$tfile
2170 # Test needs a running copytool.
2173 # Check that root can do HSM actions on a regular user's file.
2174 fid=$(create_small_file $file)
2175 sum0=$(md5sum $file)
2177 chown $RUNAS_ID:$RUNAS_GID $file ||
2178 error "cannot chown '$file' to '$RUNAS_ID'"
2180 chmod ugo-w $DIR/$tdir ||
2181 error "cannot chmod '$DIR/$tdir'"
2183 $LFS hsm_archive $file
2184 wait_request_state $fid ARCHIVE SUCCEED
2186 $LFS hsm_release $file
2187 check_hsm_flags $file "0x0000000d"
2189 $LFS hsm_restore $file
2190 wait_request_state $fid RESTORE SUCCEED
2192 # Check that ordinary user can get HSM state.
2193 $RUNAS $LFS hsm_state $file ||
2194 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2196 $LFS hsm_release $file
2197 check_hsm_flags $file "0x0000000d"
2199 # Check that ordinary user can accessed released file.
2200 sum1=$($RUNAS md5sum $file) ||
2201 error "user '$RUNAS_ID' cannot read '$file'"
2203 [ "$sum0" == "$sum1" ] ||
2204 error "md5sum mismatch for '$file'"
2206 run_test 24b "root can archive, release, and restore user files"
2209 local file=$DIR/$tdir/$tfile
2210 local action=archive
2215 # test needs a running copytool
2220 # Save the default masks and check that cleanup_24c will
2221 # restore the request masks correctly.
2222 user_save=$(get_hsm_param user_request_mask)
2223 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2224 group_save=$(get_hsm_param group_request_mask)
2225 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2226 other_save=$(get_hsm_param other_request_mask)
2227 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2229 [ "$user_save" == RESTORE ] ||
2230 error "user_request_mask is '$user_save' expected 'RESTORE'"
2231 [ "$group_save" == RESTORE ] ||
2232 error "group_request_mask is '$group_save' expected 'RESTORE'"
2233 [ "$other_save" == RESTORE ] ||
2234 error "other_request_mask is '$other_save' expected 'RESTORE'"
2237 create_small_file $file
2238 chown $RUNAS_ID:$GROUP $file ||
2239 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2241 $RUNAS $LFS hsm_$action $file &&
2242 error "$action by user should fail"
2244 set_hsm_param user_request_mask $action
2245 $RUNAS $LFS hsm_$action $file ||
2246 error "$action by user should succeed"
2249 create_small_file $file
2250 chown nobody:$RUNAS_GID $file ||
2251 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2253 $RUNAS $LFS hsm_$action $file &&
2254 error "$action by group should fail"
2256 set_hsm_param group_request_mask $action
2257 $RUNAS $LFS hsm_$action $file ||
2258 error "$action by group should succeed"
2261 create_small_file $file
2262 chown nobody:$GROUP $file ||
2263 error "cannot chown '$file' to 'nobody:$GROUP'"
2265 $RUNAS $LFS hsm_$action $file &&
2266 error "$action by other should fail"
2268 set_hsm_param other_request_mask $action
2269 $RUNAS $LFS hsm_$action $file ||
2270 error "$action by other should succeed"
2272 run_test 24c "check that user,group,other request masks work"
2275 local file1=$DIR/$tdir/$tfile
2276 local file2=$DIR2/$tdir/$tfile
2280 fid1=$(create_small_file $file1)
2283 $LFS getstripe $file1
2285 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2286 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2287 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2289 copytool setup -m "$MOUNT3"
2291 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2292 mount -o remount,ro $MOUNT2
2294 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2296 fid2=$(path2fid $file2)
2297 [ "$fid1" == "$fid2" ] ||
2298 error "FID mismatch '$fid1' != '$fid2'"
2300 $LFS hsm_archive $file2 &&
2301 error "archive should fail on read-only mount"
2302 check_hsm_flags $file1 "0x00000000"
2304 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2305 wait_request_state $fid1 ARCHIVE SUCCEED
2307 $LFS hsm_release $file1
2308 $LFS hsm_restore $file2
2309 wait_request_state $fid1 RESTORE SUCCEED
2311 $LFS hsm_release $file1 || error "cannot release '$file1'"
2312 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2314 $LFS hsm_release $file2 &&
2315 error "release should fail on read-only mount"
2319 run_test 24d "check that read-only mounts are respected"
2324 local f=$DIR/$tdir/$tfile
2327 fid=$(create_small_file $f) || error "cannot create $f"
2328 $LFS hsm_archive $f || error "cannot archive $f"
2329 wait_request_state $fid ARCHIVE SUCCEED
2330 $LFS hsm_release $f || error "cannot release $f"
2331 while ! $LFS hsm_state $f | grep released; do
2335 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2337 run_test 24e "tar succeeds on HSM released files" # LU-6213
2340 # test needs a running copytool
2343 mkdir -p $DIR/$tdir/d1
2344 local f=$DIR/$tdir/$tfile
2345 local fid=$(copy_file /etc/hosts $f)
2348 $LFS hsm_archive $f ||
2349 error "hsm_archive failed"
2350 wait_request_state $fid ARCHIVE SUCCEED
2351 $LFS hsm_release $f || error "cannot release $f"
2352 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2355 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2356 error "Can not recover the tar contents"
2358 echo "Sum0 = $sum0, sum1 = $sum1"
2359 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2361 run_test 24f "root can archive, release, and restore tar files"
2364 # test needs a running copytool
2368 copy2archive /etc/hosts $tdir/$tfile
2370 local f=$DIR/$tdir/$tfile
2372 import_file $tdir/$tfile $f
2374 $LFS hsm_set --lost $f
2379 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2383 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2384 " (Operation not permitted)"
2387 # test needs a running copytool
2392 local f=$DIR/$tdir/$tfile
2393 local fid=$(copy_file /etc/passwd $f)
2395 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2396 wait_request_state $fid ARCHIVE SUCCEED
2399 $LFS hsm_set --lost $f
2403 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2405 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2406 " (Operation not permitted)"
2408 test_26A() { # was test_26
2409 # test needs a running copytool
2412 local f=$DIR/$tdir/$tfile
2414 fid=$(make_custom_file_for_progress $f 39 1000000)
2415 [ $? != 0 ] && skip "not enough free space" && return
2417 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2418 wait_request_state $fid ARCHIVE SUCCEED
2421 wait_request_state $fid REMOVE SUCCEED
2423 check_hsm_flags $f "0x00000000"
2425 run_test 26A "Remove the archive of a valid file"
2428 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2429 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2431 # test needs a running copytool
2435 local f=$DIR/$tdir/$tfile
2436 local fid=$(copy_file /etc/passwd $f)
2438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2439 wait_request_state $fid ARCHIVE SUCCEED
2441 local f2=$DIR/$tdir/${tfile}_2
2442 local fid2=$(copy_file /etc/passwd $f2)
2444 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2445 wait_request_state $fid2 ARCHIVE SUCCEED
2447 local f3=$DIR/$tdir/${tfile}_3
2448 local fid3=$(copy_file /etc/passwd $f3)
2450 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2451 wait_request_state $fid3 ARCHIVE SUCCEED
2453 # set a long grace_delay vs short loop_period
2454 local orig_loop_period=$(get_hsm_param loop_period)
2455 local orig_grace_delay=$(get_hsm_param grace_delay)
2456 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2457 set_hsm_param loop_period 10
2458 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2459 set_hsm_param grace_delay 100
2463 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2464 set_hsm_param remove_archive_on_last_unlink 1
2466 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2471 wait_request_state $fid2 REMOVE SUCCEED
2473 assert_request_count $fid REMOVE 0 \
2474 "Unexpected archived data remove request for $f"
2475 assert_request_count $fid3 REMOVE 0 \
2476 "Unexpected archived data remove request for $f3"
2478 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2481 # test needs a running copytool
2485 local f=$DIR/$tdir/$tfile
2486 local fid=$(copy_file /etc/passwd $f)
2488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2489 wait_request_state $fid ARCHIVE SUCCEED
2491 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2492 set_hsm_param remove_archive_on_last_unlink 1
2495 cdt_check_state stopped
2499 wait_request_state $fid REMOVE WAITING
2503 # copytool must re-register
2505 wait_copytools || error "copytool failed to stop"
2508 wait_request_state $fid REMOVE SUCCEED
2510 run_test 26b "RAoLU policy when CDT off"
2513 # test needs a running copytool
2517 local f=$DIR/$tdir/$tfile
2518 local fid=$(copy_file /etc/passwd $f)
2520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2521 wait_request_state $fid ARCHIVE SUCCEED
2523 local f2=$DIR/$tdir/${tfile}_2
2524 local fid2=$(copy_file /etc/passwd $f2)
2526 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2527 wait_request_state $fid2 ARCHIVE SUCCEED
2529 # set a long grace_delay vs short loop_period
2530 local orig_loop_period=$(get_hsm_param loop_period)
2531 local orig_grace_delay=$(get_hsm_param grace_delay)
2532 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2533 set_hsm_param loop_period 10
2534 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2535 set_hsm_param grace_delay 100
2537 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2538 set_hsm_param remove_archive_on_last_unlink 1
2540 multiop_bg_pause $f O_c || error "open $f failed"
2546 wait_request_state $fid2 REMOVE SUCCEED
2547 assert_request_count $fid REMOVE 0 \
2548 "Unexpected archived data remove request for $f"
2550 kill -USR1 $pid || error "multiop early exit"
2551 # should reach autotest timeout if multiop fails to trap
2552 # signal, close file, and exit ...
2553 wait $pid || error "wait PID $PID failed"
2555 wait_request_state $fid REMOVE SUCCEED
2557 run_test 26c "RAoLU effective when file closed"
2560 # test needs a running copytool
2564 local f=$DIR/$tdir/$tfile
2565 local fid=$(create_small_file $f)
2567 $LFS hsm_archive $f || error "could not archive file"
2568 wait_request_state $fid ARCHIVE SUCCEED
2570 # set a long grace_delay vs short loop_period
2571 local orig_loop_period=$(get_hsm_param loop_period)
2572 local orig_grace_delay=$(get_hsm_param grace_delay)
2573 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2574 set_hsm_param loop_period 10
2575 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2576 set_hsm_param grace_delay 100
2578 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2579 set_hsm_param remove_archive_on_last_unlink 1
2581 multiop_bg_pause $f O_c || error "multiop failed"
2588 wait_request_state $fid REMOVE SUCCEED
2590 client_up || client_up || true
2592 kill -USR1 $MULTIPID
2593 wait $MULTIPID || error "multiop close failed"
2595 run_test 26d "RAoLU when Client eviction"
2598 # test needs a running copytool
2601 create_archive_file $tdir/$tfile
2602 local f=$DIR/$tdir/$tfile
2603 import_file $tdir/$tfile $f
2604 local fid=$(path2fid $f)
2608 [[ $? != 0 ]] || error "Remove of a released file should fail"
2612 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2615 # test needs a running copytool
2618 local f=$DIR/$tdir/$tfile
2620 fid=$(make_custom_file_for_progress $f 39 1000000)
2621 [ $? != 0 ] && skip "not enough free space" && return
2623 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2624 wait_request_state $fid ARCHIVE SUCCEED
2629 [[ $? != 0 ]] || error "Remove of a released file should fail"
2631 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2634 # test needs a running copytool
2637 local f=$DIR/$tdir/$tfile
2639 fid=$(make_custom_file_for_progress $f 39 1000000)
2640 [ $? != 0 ] && skip "not enough free space" && return
2642 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2643 wait_request_state $fid ARCHIVE SUCCEED
2652 wait_request_state $fid REMOVE SUCCEED
2654 run_test 28 "Concurrent archive/file remove"
2657 # Tests --mntpath and --archive options
2660 copytool setup -m "$MOUNT" -a $archive_id
2662 # Bad archive number
2663 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2664 grep "Invalid argument" ||
2665 error "unexpected hsm_remove failure (1)"
2667 # mntpath is present but file is given
2668 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2669 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2670 error "unexpected hsm_remove failure (2)"
2672 run_test 29a "Tests --mntpath and --archive options"
2675 # test needs a running copytool
2678 local f=$DIR/$tdir/$tfile
2679 local fid=$(create_small_file $f)
2681 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2682 wait_request_state $fid ARCHIVE SUCCEED
2686 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2687 wait_request_state $fid REMOVE SUCCEED
2689 run_test 29b "Archive/delete/remove by FID from the archive."
2692 # test needs a running copytool
2695 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2696 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2697 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2699 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2700 wait_request_state $fid1 ARCHIVE SUCCEED
2701 wait_request_state $fid2 ARCHIVE SUCCEED
2702 wait_request_state $fid3 ARCHIVE SUCCEED
2704 rm -f $DIR/$tdir/$tfile-[1-3]
2706 echo $fid1 > $DIR/$tdir/list
2707 echo $fid2 >> $DIR/$tdir/list
2708 echo $fid3 >> $DIR/$tdir/list
2710 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2711 --filelist $DIR/$tdir/list
2712 wait_request_state $fid1 REMOVE SUCCEED
2713 wait_request_state $fid2 REMOVE SUCCEED
2714 wait_request_state $fid3 REMOVE SUCCEED
2716 run_test 29c "Archive/delete/remove by FID, using a file list."
2719 # test needs more than one CT
2720 needclients 3 || return 0
2726 # start all of the copytools
2727 for n in $(seq $AGTCOUNT); do
2728 copytool setup -f agt$n -a $n
2732 file=$DIR/$tdir/$tfile
2733 fid=$(create_small_file $file)
2735 $LFS hsm_archive $file
2736 wait_request_state $fid ARCHIVE SUCCEED
2737 check_hsm_flags $file "0x00000009"
2741 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2742 error "cannot hsm_remove '$fid'"
2744 # give time for CDT to handle remove request and create broadcasted
2747 # remove request has been broadcasted ?
2748 local cnt=$(get_request_count $fid REMOVE)
2749 # broadcasted requests + original
2750 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2751 error "remove not broadcasted to all CTs"
2753 # give time for CDT and CTs to handle broadcasted
2754 wait_for_loop_period
2756 # each agent serves one different archive_id, so broadcasted
2757 # hsm_remove request should only succeed once and fail at all others
2761 for n in $(seq $AGTCOUNT); do
2762 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2763 $HSM_PARAM.actions | awk \
2764 '/'$fid'.*action=REMOVE archive#='$n'/ \
2765 {print \\\$13}' | cut -f2 -d=")
2766 if [[ "$res" == "SUCCEED" ]]; then
2768 elif [[ "$res" == "FAILED" ]]; then
2773 [[ $scnt -eq 1 ]] ||
2774 error "one and only CT should have removed successfully"
2776 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2777 error "all but one CT should have failed to remove"
2779 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2780 "request to be sent once for each registered archive_id"
2783 # restore at exec cannot work on agent node (because of Linux kernel
2784 # protection of executables)
2785 needclients 2 || return 0
2787 # test needs a running copytool
2791 copy2archive /bin/true $tdir/$tfile
2793 local f=$DIR/$tdir/true
2794 import_file $tdir/$tfile $f
2796 local fid=$(path2fid $f)
2798 # set no retry action mode
2804 # remove no try action mode
2808 [[ $st == 0 ]] || error "Failed to exec a released file"
2812 run_test 30a "Restore at exec (import case)"
2815 # restore at exec cannot work on agent node (because of Linux kernel
2816 # protection of executables)
2817 needclients 2 || return 0
2819 # test needs a running copytool
2823 local f=$DIR/$tdir/true
2824 local fid=$(copy_file /bin/true $f)
2826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2827 wait_request_state $fid ARCHIVE SUCCEED
2831 stack_trap cdt_clear_no_retry EXIT
2832 # set no retry action mode
2840 [[ $st == 0 ]] || error "Failed to exec a released file"
2842 run_test 30b "Restore at exec (release case)"
2845 needclients 2 || return 0
2847 # test needs a running copytool
2851 local f=$DIR/$tdir/SLEEP
2852 local slp_sum1=$(md5sum /bin/sleep)
2853 local fid=$(copy_file /bin/sleep $f)
2855 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2856 wait_request_state $fid ARCHIVE SUCCEED
2858 check_hsm_flags $f "0x0000000d"
2860 stack_trap cdt_clear_no_retry EXIT
2861 # set no retry action mode
2864 do_node $CLIENT2 "$f 10" &
2868 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2870 [[ $? == 0 ]] || error "Execution failed during run"
2872 if [[ $? != 0 ]]; then
2873 local slp_sum2=$(md5sum /bin/sleep)
2874 # in case sleep file is modified during the test
2875 [[ $slp_sum1 == $slp_sum2 ]] &&
2876 error "Binary overwritten during exec"
2879 check_hsm_flags $f "0x00000009"
2881 run_test 30c "Update during exec of released file must fail"
2883 restore_and_check_size() {
2886 local s=$(stat -c "%s" $f)
2888 local st=$(get_hsm_flags $f)
2892 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2894 n=$(stat -c "%s" $f)
2895 # we echo in both cases to show stat is not hang
2896 if [[ $n != $s ]]; then
2897 echo "size seen is $n != $s"
2900 echo "size seen is right: $n == $s"
2904 st=$(get_hsm_flags $f)
2906 if [[ "$st" = "0x00000009" ]]; then
2909 echo " restore is too long"
2910 wait_request_state $fid RESTORE SUCCEED
2916 # test needs a running copytool
2919 create_archive_file $tdir/$tfile
2920 local f=$DIR/$tdir/$tfile
2921 import_file $tdir/$tfile $f
2922 local fid=$($LFS path2fid $f)
2923 HSM_ARCHIVE_PURGE=false copytool_setup
2925 restore_and_check_size $f $fid
2928 [[ $err -eq 0 ]] || error "File size changed during restore"
2932 run_test 31a "Import a large file and check size during restore"
2936 # test needs a running copytool
2939 local f=$DIR/$tdir/$tfile
2941 fid=$(make_custom_file_for_progress $f 39 1000000)
2942 [ $? != 0 ] && skip "not enough free space" && return
2944 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2945 wait_request_state $fid ARCHIVE SUCCEED
2948 restore_and_check_size $f $fid
2951 [[ $err -eq 0 ]] || error "File size changed during restore"
2953 run_test 31b "Restore a large unaligned file and check size during restore"
2956 # test needs a running copytool
2959 local f=$DIR/$tdir/$tfile
2961 fid=$(make_custom_file_for_progress $f 33 1048576)
2962 [ $? != 0 ] && skip "not enough free space" && return
2964 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2965 wait_request_state $fid ARCHIVE SUCCEED
2968 restore_and_check_size $f $fid
2971 [[ $err -eq 0 ]] || error "File size changed during restore"
2973 run_test 31c "Restore a large aligned file and check size during restore"
2976 # test needs a running copytool
2979 local f=$DIR/$tdir/$tfile
2981 fid=$(make_custom_file_for_progress $f 39 1000000)
2982 [ $? != 0 ] && skip "not enough free space" && return
2984 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2985 wait_request_state $fid ARCHIVE SUCCEED
2988 # to be sure wait_all_done will not be mislead by previous tests
2991 wait_for_grace_delay
2992 # Also raise grace_delay significantly so the Canceled
2993 # Restore action will stay enough long avail.
2994 local old_grace=$(get_hsm_param grace_delay)
2995 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
2996 set_hsm_param grace_delay 100
2998 md5sum $f >/dev/null &
3000 wait_request_state $fid RESTORE STARTED
3005 # Check restore trigger process was killed
3006 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3010 # instead of waiting+checking both Restore and Cancel ops
3011 # sequentially, wait for both to be finished and then check
3013 wait_all_done 100 $fid
3014 local rstate=$(get_request_state $fid RESTORE)
3015 local cstate=$(get_request_state $fid CANCEL)
3017 if [[ "$rstate" == "CANCELED" ]] ; then
3018 [[ "$cstate" == "SUCCEED" ]] ||
3019 error "Restore state is CANCELED and Cancel state " \
3020 "is not SUCCEED but $cstate"
3021 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3022 elif [[ "$rstate" == "SUCCEED" ]] ; then
3023 [[ "$cstate" == "FAILED" ]] ||
3024 error "Restore state is SUCCEED and Cancel state " \
3025 "is not FAILED but $cstate"
3026 echo "Restore state is SUCCEED, Cancel state is FAILED"
3028 error "Restore state is $rstate and Cancel state is $cstate"
3032 error "Cannot kill process waiting for restore ($killed)"
3034 run_test 33 "Kill a restore waiting process"
3037 # test needs a running copytool
3040 local f=$DIR/$tdir/$tfile
3042 fid=$(make_custom_file_for_progress $f 39 1000000)
3043 [ $? != 0 ] && skip "not enough free space" && return
3045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3046 wait_request_state $fid ARCHIVE SUCCEED
3049 md5sum $f >/dev/null &
3051 wait_request_state $fid RESTORE STARTED
3053 rm $f || error "rm $f failed"
3054 # rm must not block during restore
3055 wait_request_state $fid RESTORE STARTED
3057 wait_request_state $fid RESTORE SUCCEED
3058 # check md5sum pgm finished
3059 local there=$(ps -o pid,comm hp $pid >/dev/null)
3060 [[ -z $there ]] || error "Restore initiator does not exit"
3062 wait $pid || error "Restore initiator failed with $?"
3064 run_test 34 "Remove file during restore"
3067 # test needs a running copytool
3070 local f=$DIR/$tdir/$tfile
3071 local f1=$DIR/$tdir/$tfile-1
3073 fid=$(make_custom_file_for_progress $f 39 1000000)
3074 [ $? != 0 ] && skip "not enough free space" && return
3076 local fid1=$(copy_file /etc/passwd $f1)
3077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3078 wait_request_state $fid ARCHIVE SUCCEED
3081 md5sum $f >/dev/null &
3083 wait_request_state $fid RESTORE STARTED
3085 mv $f1 $f || error "mv $f1 $f failed"
3086 # mv must not block during restore
3087 wait_request_state $fid RESTORE STARTED
3089 wait_request_state $fid RESTORE SUCCEED
3090 # check md5sum pgm finished
3091 local there=$(ps -o pid,comm hp $pid >/dev/null)
3092 [[ -z $there ]] || error "Restore initiator does not exit"
3094 wait $pid || error "Restore initiator failed with $?"
3097 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3099 run_test 35 "Overwrite file during restore"
3102 # test needs a running copytool
3105 local f=$DIR/$tdir/$tfile
3107 fid=$(make_custom_file_for_progress $f 39 1000000)
3108 [ $? != 0 ] && skip "not enough free space" && return
3110 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3111 wait_request_state $fid ARCHIVE SUCCEED
3114 md5sum $f >/dev/null &
3116 wait_request_state $fid RESTORE STARTED
3119 # rm must not block during restore
3120 wait_request_state $fid RESTORE STARTED
3122 wait_request_state $fid RESTORE SUCCEED
3123 # check md5sum pgm finished
3124 local there=$(ps -o pid,comm hp $pid >/dev/null)
3126 error "Restore initiator does not exit"
3128 wait $pid || error "Restore initiator failed with $?"
3130 run_test 36 "Move file during restore"
3133 # LU-5683: check that an archived dirty file can be rearchived.
3136 local f=$DIR/$tdir/$tfile
3139 fid=$(create_small_file $f) || error "cannot create small file"
3141 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3142 wait_request_state $fid ARCHIVE SUCCEED
3143 $LFS hsm_release $f || error "cannot release $f"
3145 # Allow previous archive request to expire from the actions log.
3146 wait_for_grace_delay
3149 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3152 wait_request_state $fid ARCHIVE SUCCEED
3154 run_test 37 "re-archive a dirty file"
3161 for n in $(seq 1 $count); do
3162 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3164 echo "$count archive requests submitted"
3168 local stream_count=4
3169 local file_count=100
3171 local f=$DIR/$tdir/$tfile
3175 local max_requests=$(get_hsm_param max_requests)
3177 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3178 # Increase the number of HSM request that can be performed in
3179 # parallel. With the coordinator running once per second, this
3180 # also limits the number of requests per seconds that can be
3181 # performed, so we pick a decent number. But we also need to keep
3182 # that number low because the copytool has no rate limit and will
3183 # fail some requests if if gets too many at once.
3184 set_hsm_param max_requests 300
3186 for i in $(seq 1 $file_count); do
3187 for p in $(seq 1 $stream_count); do
3188 fid=$(copy_file /etc/hosts $f.$p.$i)
3194 # to be sure wait_all_done will not be mislead by previous tests
3196 wait_for_grace_delay
3198 # start archive streams in background (archive files in parallel)
3199 for p in $(seq 1 $stream_count); do
3200 multi_archive $f.$p $file_count &
3203 echo -n "Wait for all requests being enqueued..."
3208 run_test 40 "Parallel archive requests"
3211 # test needs a running copytool
3215 local f=$DIR/$tdir/$tfile
3216 local fid=$(create_small_file $f)
3218 $LFS hsm_archive $f || error "could not archive file"
3219 wait_request_state $fid ARCHIVE SUCCEED
3220 check_hsm_flags $f "0x00000009"
3222 multiop_bg_pause $f O_c || error "multiop failed"
3226 client_up || client_up || true
3228 kill -USR1 $MULTIPID
3229 wait $MULTIPID || error "multiop close failed"
3231 check_hsm_flags $f "0x0000000b"
3233 run_test 52 "Opened for write file on an evicted client should be set dirty"
3236 # test needs a running copytool
3240 local f=$DIR/$tdir/$tfile
3241 local fid=$(create_small_file $f)
3243 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3244 error "could not archive file"
3245 wait_request_state $fid ARCHIVE SUCCEED
3246 check_hsm_flags $f "0x00000009"
3248 multiop_bg_pause $f o_c || error "multiop failed"
3252 client_up || client_up || true
3254 kill -USR1 $MULTIPID
3255 wait $MULTIPID || error "multiop close failed"
3257 check_hsm_flags $f "0x00000009"
3259 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3262 # test needs a running copytool
3265 local f=$DIR/$tdir/$tfile
3266 local fid=$(make_custom_file_for_progress $f 39 1000000)
3268 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3269 error "could not archive file"
3270 wait_request_state $fid ARCHIVE STARTED
3272 check_hsm_flags $f "0x00000001"
3274 stack_trap "cdt_clear_no_retry" EXIT
3275 # Avoid coordinator resending this request as soon it has failed.
3280 wait_request_state $fid ARCHIVE FAILED
3282 check_hsm_flags $f "0x00000003"
3284 run_test 54 "Write during an archive cancels it"
3287 # test needs a running copytool
3290 local f=$DIR/$tdir/$tfile
3291 local fid=$(make_custom_file_for_progress $f 39 1000000)
3293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3294 error "could not archive file"
3295 wait_request_state $fid ARCHIVE STARTED
3297 check_hsm_flags $f "0x00000001"
3299 stack_trap "cdt_clear_no_retry" EXIT
3300 # Avoid coordinator resending this request as soon it has failed.
3303 $TRUNCATE $f 1024 || error "truncate failed"
3305 wait_request_state $fid ARCHIVE FAILED
3307 check_hsm_flags $f "0x00000003"
3309 run_test 55 "Truncate during an archive cancels it"
3312 # test needs a running copytool
3315 local f=$DIR/$tdir/$tfile
3317 fid=$(make_custom_file_for_progress $f 39 1000000)
3318 [ $? != 0 ] && skip "not enough free space" && return
3320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3321 error "could not archive file"
3322 wait_request_state $fid ARCHIVE STARTED
3324 check_hsm_flags $f "0x00000001"
3326 # Change metadata and sync to be sure we are not changing only
3331 wait_request_state $fid ARCHIVE SUCCEED
3333 check_hsm_flags $f "0x00000009"
3335 run_test 56 "Setattr during an archive is ok"
3338 # Need one client for I/O, one for request
3339 needclients 2 || return 0
3341 # test needs a running copytool
3345 local f=$DIR/$tdir/test_archive_remote
3346 # Create a file on a remote node
3347 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3348 "count=2 conv=fsync"
3351 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3352 error "hsm_archive failed"
3353 local fid=$(path2fid $f)
3354 wait_request_state $fid ARCHIVE SUCCEED
3356 # Release and implicit restore it
3357 do_node $CLIENT2 "$LFS hsm_release $f" ||
3358 error "hsm_release failed"
3359 do_node $CLIENT2 "md5sum $f" ||
3360 error "hsm_restore failed"
3362 wait_request_state $fid RESTORE SUCCEED
3364 run_test 57 "Archive a file with dirty cache on another node"
3366 truncate_released_file() {
3370 local sz=$(stat -c %s $src_file)
3371 local f=$DIR/$tdir/$tfile
3372 local fid=$(copy_file $1 $f)
3376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3377 error "could not archive file"
3378 wait_request_state $fid ARCHIVE SUCCEED
3380 $LFS hsm_release $f || error "could not release file"
3382 $TRUNCATE $f $trunc_to || error "truncate failed"
3385 local sz1=$(stat -c %s $f)
3386 [[ $sz1 == $trunc_to ]] ||
3387 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3390 check_hsm_flags $f "0x0000000b"
3392 local state=$(get_request_state $fid RESTORE)
3393 [[ "$state" == "SUCCEED" ]] ||
3394 error "truncate $sz does not trig restore, state = $state"
3396 $TRUNCATE $ref $trunc_to
3397 cmp $ref $f || error "file data wrong after truncate"
3403 # test needs a running copytool
3408 local sz=$(stat -c %s /etc/passwd)
3410 echo "truncate up from $sz to $((sz*2))"
3411 truncate_released_file /etc/passwd $((sz*2))
3413 echo "truncate down from $sz to $((sz/2))"
3414 truncate_released_file /etc/passwd $((sz/2))
3416 echo "truncate to 0"
3417 truncate_released_file /etc/passwd 0
3419 run_test 58 "Truncate a released file will trigger restore"
3423 local server_version=$(lustre_version_code $SINGLEMDS)
3424 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3425 skip "Need MDS version at least 2.7.63" && return
3428 $MCREATE $DIR/$tfile || error "mcreate failed"
3429 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3430 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3431 fid=$(path2fid $DIR/$tfile)
3432 wait_request_state $fid ARCHIVE SUCCEED
3433 $LFS hsm_release $DIR/$tfile || error "release failed"
3435 run_test 59 "Release stripeless file with non-zero size"
3438 # This test validates the fix for LU-4512. Ensure that the -u
3439 # option changes the progress reporting interval from the
3440 # default (30 seconds) to the user-specified interval.
3442 local progress_timeout=$((interval * 4))
3444 copytool setup -b 1 --update-interval $interval
3446 local f=$DIR/$tdir/$tfile
3448 fid=$(make_custom_file_for_progress $f 10)
3449 [ $? != 0 ] && skip "not enough free space" && return
3452 local mdt=${MDT_PREFIX}${mdtidx}
3453 local mds=mds$((mdtidx + 1))
3455 # Wait for copytool to register
3456 wait_update_facet $mds \
3457 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3458 uuid 100 || error "coyptool failed to register with $mdt"
3460 local start_at=$(date +%s)
3461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3462 error "could not archive file"
3464 local agent=$(facet_active_host $SINGLEAGT)
3465 local logfile=$(copytool_logfile $SINGLEAGT)
3467 wait_update $agent \
3468 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3469 error "copytool failed to start"
3471 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3472 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3478 echo -n "Expecting a progress update within $progress_timeout seconds... "
3480 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3481 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3482 echo "$RESULT bytes copied in $WAIT seconds."
3484 elif [ $WAIT -ge $progress_timeout ]; then
3485 error "Timed out waiting for progress update!"
3488 WAIT=$((WAIT + sleep))
3492 local finish_at=$(date +%s)
3493 local elapsed=$((finish_at - start_at))
3495 # Ensure that the progress update occurred within the expected window.
3496 if [ $elapsed -lt $((interval - 1)) ]; then
3497 error "Expected progress update after at least $interval seconds"
3500 echo "Wait for on going archive hsm action to complete"
3501 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3502 echo "File archiving not completed even after 10 secs"
3504 run_test 60 "Changing progress update interval from default"
3507 # test needs a running copytool
3511 local f=$DIR/$tdir/$tfile
3512 local fid=$(copy_file /etc/passwd $f)
3514 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3517 wait_request_state $fid ARCHIVE FAILED
3519 run_test 61 "Waiting archive of a removed file should fail"
3522 # test needs a new running copytool
3523 stack_trap copytool_monitor_cleanup EXIT
3524 copytool_monitor_setup
3525 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3527 # Wait for the copytool to register.
3528 wait_update --verbose $(facet_active_host mds1) \
3529 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3531 error "copytool failed to register with MDT0000"
3534 wait_copytools || error "Copytools failed to stop"
3536 local REGISTER_EVENT
3537 local UNREGISTER_EVENT
3538 while read event; do
3539 local parsed=$(parse_json_event "$event")
3540 if [ -z "$parsed" ]; then
3541 error "Copytool sent malformed event: $event"
3545 if [ $event_type == "REGISTER" ]; then
3546 REGISTER_EVENT=$event
3547 elif [ $event_type == "UNREGISTER" ]; then
3548 UNREGISTER_EVENT=$event
3550 done < <(echo $"$(get_copytool_event_log)")
3552 if [ -z "$REGISTER_EVENT" ]; then
3553 error "Copytool failed to send register event to FIFO"
3556 if [ -z "$UNREGISTER_EVENT" ]; then
3557 error "Copytool failed to send unregister event to FIFO"
3560 echo "Register/Unregister events look OK."
3562 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3565 # Bump progress interval for livelier events.
3568 # test needs a new running copytool
3569 stack_trap copytool_monitor_cleanup EXIT
3570 copytool_monitor_setup
3571 copytool setup --update-interval $interval --event-fifo \
3572 "$HSMTOOL_MONITOR_DIR/fifo"
3574 stack_trap "cdt_clear_no_retry" EXIT
3575 # Just start and stop the copytool to generate events.
3578 local f=$DIR/$tdir/$tfile
3580 fid=$(make_custom_file_for_progress $f 39 1000000)
3581 [ $? != 0 ] && skip "not enough free space" && return
3583 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3584 error "could not archive file"
3585 wait_request_state $fid ARCHIVE SUCCEED
3587 local expected_fields="event_time data_fid source_fid"
3588 expected_fields+=" total_bytes current_bytes"
3592 while read event; do
3593 # Make sure we're not getting anything from previous events.
3594 for field in $expected_fields; do
3598 local parsed=$(parse_json_event "$event")
3599 if [ -z "$parsed" ]; then
3600 error "Copytool sent malformed event: $event"
3604 if [ $event_type == "ARCHIVE_START" ]; then
3607 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3610 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3614 # Do some simple checking of the progress update events.
3615 for expected_field in $expected_fields; do
3616 if [ -z ${!expected_field+x} ]; then
3617 error "Missing $expected_field field in event"
3621 if [ $total_bytes -eq 0 ]; then
3622 error "Expected total_bytes to be > 0"
3625 # These should be identical throughout an archive
3627 if [ $source_fid != $data_fid ]; then
3628 error "Expected source_fid to equal data_fid"
3630 done < <(echo $"$(get_copytool_event_log)")
3632 if [ -z "$START_EVENT" ]; then
3633 error "Copytool failed to send archive start event to FIFO"
3636 if [ -z "$FINISH_EVENT" ]; then
3637 error "Copytool failed to send archive finish event to FIFO"
3640 echo "Archive events look OK."
3642 run_test 71 "Copytool logs JSON archive events to FIFO"
3645 # Bump progress interval for livelier events.
3648 # test needs a new running copytool
3650 copytool_monitor_setup
3651 HSMTOOL_UPDATE_INTERVAL=$interval \
3652 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3653 local test_file=$HSMTOOL_MONITOR_DIR/file
3655 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3657 do_facet $SINGLEAGT "$cmd" ||
3658 error "cannot create $test_file on $SINGLEAGT"
3659 copy2archive $test_file $tdir/$tfile
3662 local f=$DIR/$tdir/$tfile
3663 import_file $tdir/$tfile $f
3664 f=$DIR2/$tdir/$tfile
3665 echo "Verifying released state: "
3666 check_hsm_flags $f "0x0000000d"
3668 local fid=$(path2fid $f)
3670 wait_request_state $fid RESTORE SUCCEED
3672 local expected_fields="event_time data_fid source_fid"
3673 expected_fields+=" total_bytes current_bytes"
3677 while read event; do
3678 # Make sure we're not getting anything from previous events.
3679 for field in $expected_fields; do
3683 local parsed=$(parse_json_event "$event")
3684 if [ -z "$parsed" ]; then
3685 error "Copytool sent malformed event: $event"
3689 if [ $event_type == "RESTORE_START" ]; then
3691 if [ $source_fid != $data_fid ]; then
3692 error "source_fid should == data_fid at start"
3695 elif [ $event_type == "RESTORE_FINISH" ]; then
3697 if [ $source_fid != $data_fid ]; then
3698 error "source_fid should == data_fid at finish"
3701 elif [ $event_type != "RESTORE_RUNNING" ]; then
3705 # Do some simple checking of the progress update events.
3706 for expected_field in $expected_fields; do
3707 if [ -z ${!expected_field+x} ]; then
3708 error "Missing $expected_field field in event"
3712 if [ $total_bytes -eq 0 ]; then
3713 error "Expected total_bytes to be > 0"
3716 # When a restore starts out, the data fid is the same as the
3717 # source fid. After the restore has gotten going, we learn
3718 # the new data fid. Once the restore has finished, the source
3719 # fid is set to the new data fid.
3721 # We test this because some monitoring software may depend on
3722 # this behavior. If it changes, then the consumers of these
3723 # events may need to be modified.
3724 if [ $source_fid == $data_fid ]; then
3725 error "source_fid should != data_fid during restore"
3727 done < <(echo $"$(get_copytool_event_log)")
3729 if [ -z "$START_EVENT" ]; then
3730 error "Copytool failed to send restore start event to FIFO"
3733 if [ -z "$FINISH_EVENT" ]; then
3734 error "Copytool failed to send restore finish event to FIFO"
3737 echo "Restore events look OK."
3741 copytool_monitor_cleanup
3745 run_test 72 "Copytool logs JSON restore events to FIFO"
3748 file_count=51 # Max number of files constrained by LNET message size
3749 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3750 local f=$DIR/$tdir/$tfile
3751 local FILELIST=/tmp/filelist.txt
3755 for i in $(seq 1 $file_count); do
3756 fid=$(copy_file /etc/hosts $f.$i)
3757 echo $f.$i >> $FILELIST
3761 # to be sure wait_all_done will not be mislead by previous tests
3763 wait_for_grace_delay
3764 $LFS hsm_archive --filelist $FILELIST ||
3765 error "cannot archive a file list"
3767 $LFS hsm_release --filelist $FILELIST ||
3768 error "cannot release a file list"
3769 $LFS hsm_restore --filelist $FILELIST ||
3770 error "cannot restore a file list"
3773 run_test 90 "Archive/restore a file list"
3775 double_verify_reset_hsm_param() {
3777 echo "Testing $HSM_PARAM.$p"
3778 local val=$(get_hsm_param $p)
3780 local val2=$(($val * 2))
3781 set_hsm_param $p $val2
3782 val=$(get_hsm_param $p)
3783 [[ $val == $val2 ]] ||
3784 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3785 echo "Set $p to 0 must failed"
3789 set_hsm_param $p $save
3791 if [[ $rc == 0 ]]; then
3792 error "we must not be able to set $HSM_PARAM.$p to 0"
3797 double_verify_reset_hsm_param loop_period
3798 double_verify_reset_hsm_param grace_delay
3799 double_verify_reset_hsm_param active_request_timeout
3800 double_verify_reset_hsm_param max_requests
3801 double_verify_reset_hsm_param default_archive_id
3803 run_test 100 "Set coordinator /proc tunables"
3810 run_test 102 "Verify coordinator control"
3813 # test needs a running copytool
3820 for i in $(seq 1 20); do
3821 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3823 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3827 echo "Current requests"
3828 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3829 $HSM_PARAM.actions |\
3830 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3832 [[ -z "$res" ]] || error "Some request have not been canceled"
3834 run_test 103 "Purge all requests"
3839 local f=$DIR/$tdir/$tfile
3841 fid=$(make_custom_file_for_progress $f 39 1000000)
3842 [ $? != 0 ] && skip "not enough free space" && return
3844 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3845 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3846 $HSM_PARAM.actions |\
3847 grep $fid | cut -f16 -d=")
3849 [[ "$data1" == "$DATAHEX" ]] ||
3850 error "Data field in records is ($data1) and not ($DATAHEX)"
3855 wait_request_state $fid ARCHIVE SUCCEED
3857 run_test 104 "Copy tool data field"
3860 local max_requests=$(get_hsm_param max_requests)
3864 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3865 set_hsm_param max_requests 300
3868 for i in $(seq -w 1 10); do
3869 cp /etc/passwd $DIR/$tdir/$i
3870 $LFS hsm_archive $DIR/$tdir/$i
3872 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3873 $HSM_PARAM.actions |\
3874 grep WAITING | wc -l")
3878 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3879 $HSM_PARAM.actions |\
3880 grep WAITING | wc -l")
3883 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3884 error "Requests count after shutdown $reqcnt2 != "\
3885 "before shutdown $reqcnt1"
3887 run_test 105 "Restart of coordinator"
3890 # test needs a running copytool
3893 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3895 check_agent_registered $uuid
3897 search_copytools || error "No copytool found"
3900 wait_copytools || error "Copytool failed to stop"
3902 check_agent_unregistered $uuid
3905 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3906 check_agent_registered $uuid
3908 run_test 106 "Copytool register/unregister"
3911 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3913 # test needs a running copytool
3915 # create and archive file
3917 local f1=$DIR/$tdir/$tfile
3918 local fid=$(copy_file /etc/passwd $f1)
3919 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3920 wait_request_state $fid ARCHIVE SUCCEED
3921 # shutdown and restart MDS
3923 # check the copytool still gets messages from MDT
3924 local f2=$DIR/$tdir/2
3925 local fid=$(copy_file /etc/passwd $f2)
3926 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3927 # main check of this sanity: this request MUST succeed
3928 wait_request_state $fid ARCHIVE SUCCEED
3930 run_test 107 "Copytool re-register after MDS restart"
3932 policy_set_and_test()
3936 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3937 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3938 [[ "$policy" == "$target" ]] ||
3939 error "Wrong policy after '$change': '$policy' != '$target'"
3943 # to force default policy setting if error
3944 CDT_POLICY_HAD_CHANGED=true
3946 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3947 local default="NonBlockingRestore [NoRetryAction]"
3948 [[ "$policy" == "$default" ]] ||
3949 error "default policy has changed,"\
3950 " '$policy' != '$default' update the test"
3951 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3952 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3953 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3954 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3955 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3956 # useless bacause we know but safer for futur changes to use real value
3957 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3958 echo "Next set_param must failed"
3959 policy_set_and_test "wrong" "$policy"
3962 echo "Back to default policy"
3963 cdt_set_sanity_policy
3965 run_test 109 "Policy display/change"
3968 # test needs a running copytool
3973 copy2archive /etc/passwd $tdir/$tfile
3975 local f=$DIR/$tdir/$tfile
3976 import_file $tdir/$tfile $f
3977 local fid=$(path2fid $f)
3979 cdt_set_non_blocking_restore
3984 wait_request_state $fid RESTORE SUCCEED
3985 cdt_clear_non_blocking_restore
3989 error "md5sum returns $st != 1, "\
3990 "should also perror ENODATA (No data available)"
3992 run_test 110a "Non blocking restore policy (import case)"
3995 # test needs a running copytool
3999 local f=$DIR/$tdir/$tfile
4000 local fid=$(copy_file /etc/passwd $f)
4001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4002 wait_request_state $fid ARCHIVE SUCCEED
4005 cdt_set_non_blocking_restore
4010 wait_request_state $fid RESTORE SUCCEED
4011 cdt_clear_non_blocking_restore
4015 error "md5sum returns $st != 1, "\
4016 "should also perror ENODATA (No data available)"
4018 run_test 110b "Non blocking restore policy (release case)"
4021 # test needs a running copytool
4025 copy2archive /etc/passwd $tdir/$tfile
4027 local f=$DIR/$tdir/$tfile
4029 import_file $tdir/$tfile $f
4030 local fid=$(path2fid $f)
4034 copytool_remove_backend $fid
4037 wait_request_state $fid RESTORE FAILED
4044 [[ $st == 0 ]] || error "Restore does not failed"
4048 run_test 111a "No retry policy (import case), restore will error"\
4049 " (No such file or directory)"
4052 # test needs a running copytool
4056 local f=$DIR/$tdir/$tfile
4057 local fid=$(copy_file /etc/passwd $f)
4059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4060 wait_request_state $fid ARCHIVE SUCCEED
4063 copytool_remove_backend $fid
4066 wait_request_state $fid RESTORE FAILED
4073 [[ $st == 0 ]] || error "Restore does not failed"
4077 run_test 111b "No retry policy (release case), restore will error"\
4078 " (No such file or directory)"
4081 # test needs a running copytool
4085 local f=$DIR/$tdir/$tfile
4086 local fid=$(copy_file /etc/passwd $f)
4088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4089 local l=$($LFS hsm_action $f)
4091 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4094 wait_request_state $fid ARCHIVE SUCCEED
4097 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4099 run_test 112 "State of recorded request"
4102 # test needs a running copytool
4105 local f=$DIR/$tdir/$tfile
4107 fid=$(make_custom_file_for_progress $f 103 1048576)
4108 [ $? != 0 ] && skip "not enough free space" && return
4110 # test with cdt on is made in test_221
4112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4113 # wait archive to register at CDT
4114 wait_request_state $fid ARCHIVE WAITING
4117 wait_request_state $fid ARCHIVE CANCELED
4118 wait_request_state $fid CANCEL SUCCEED
4120 run_test 200 "Register/Cancel archive"
4123 # test needs a running copytool
4126 local f=$DIR/$tdir/$tfile
4127 create_archive_file $tdir/$tfile
4128 import_file $tdir/$tfile $f
4129 local fid=$(path2fid $f)
4131 # test with cdt on is made in test_222
4134 # wait restore to register at CDT
4135 wait_request_state $fid RESTORE WAITING
4138 wait_request_state $fid RESTORE CANCELED
4139 wait_request_state $fid CANCEL SUCCEED
4143 run_test 201 "Register/Cancel restore"
4146 # test needs a running copytool
4149 local f=$DIR/$tdir/$tfile
4151 fid=$(make_custom_file_for_progress $f 39 1000000)
4152 [ $? != 0 ] && skip "not enough free space" && return
4154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4155 wait_request_state $fid ARCHIVE SUCCEED
4159 # wait remove to register at CDT
4160 wait_request_state $fid REMOVE WAITING
4163 wait_request_state $fid REMOVE CANCELED
4165 run_test 202 "Register/Cancel remove"
4167 test_220A() { # was test_220
4168 # test needs a running copytool
4173 local f=$DIR/$tdir/$tfile
4174 local fid=$(copy_file /etc/passwd $f)
4178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4179 wait_request_state $fid ARCHIVE SUCCEED
4181 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4182 error "The expected changelog was not emitted"
4184 run_test 220A "Changelog for archive"
4187 # test needs a running copytool
4192 local f=$DIR/$tdir/$tfile
4193 local fid=$(copy_file /etc/passwd $f)
4197 # block copytool operations to allow for HSM request to be
4198 # submitted and file be unlinked (CDT will find object removed)
4201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4203 # wait request to reach CT
4204 wait_request_state $fid ARCHIVE STARTED
4210 wait_request_state $fid ARCHIVE FAILED
4213 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4214 error "The expected changelog was not emitted"
4216 run_test 220a "Changelog for failed archive"
4219 # test needs a running copytool
4222 local f=$DIR/$tdir/$tfile
4224 fid=$(make_custom_file_for_progress $f 103 1048576)
4225 [ $? != 0 ] && skip "not enough free space" && return
4229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4230 wait_request_state $fid ARCHIVE STARTED
4232 wait_request_state $fid ARCHIVE CANCELED
4233 wait_request_state $fid CANCEL SUCCEED
4235 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4236 error "The expected changelog was not emitted"
4238 run_test 221 "Changelog for archive canceled"
4241 # test needs a running copytool
4245 copy2archive /etc/passwd $tdir/$tfile
4247 local f=$DIR/$tdir/$tfile
4248 import_file $tdir/$tfile $f
4249 local fid=$(path2fid $f)
4254 wait_request_state $fid RESTORE SUCCEED
4256 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4257 error "The expected changelog was not emitted"
4261 run_test 222a "Changelog for explicit restore"
4264 # test needs a running copytool
4268 local f=$DIR/$tdir/$tfile
4269 local fid=$(copy_file /etc/passwd $f)
4272 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4273 wait_request_state $fid ARCHIVE SUCCEED
4278 wait_request_state $fid RESTORE SUCCEED
4280 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4281 error "The expected changelog was not emitted"
4283 run_test 222b "Changelog for implicit restore"
4286 # test needs a running copytool
4290 copy2archive /etc/passwd $tdir/$tfile
4292 local f=$DIR/$tdir/$tfile
4293 import_file $tdir/$tfile $f
4294 local fid=$(path2fid $f)
4298 # block copytool operations to allow for HSM request to be
4299 # submitted and file be unlinked (CDT will find object removed)
4304 # wait request to reach CT
4305 wait_request_state $fid RESTORE STARTED
4311 wait_request_state $fid RESTORE FAILED
4314 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4315 error "The expected changelog was not emitted"
4319 run_test 222c "Changelog for failed explicit restore"
4322 # test needs a running copytool
4326 local f=$DIR/$tdir/$tfile
4327 local fid=$(copy_file /etc/passwd $f)
4330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4331 wait_request_state $fid ARCHIVE SUCCEED
4334 copytool_remove_backend $fid
4337 wait_request_state $fid RESTORE FAILED
4340 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4341 error "The expected changelog was not emitted"
4345 run_test 222d "Changelog for failed implicit restore"
4348 # test needs a running copytool
4351 local f=$DIR/$tdir/$tfile
4352 create_archive_file $tdir/$tfile
4356 import_file $tdir/$tfile $f
4357 local fid=$(path2fid $f)
4360 wait_request_state $fid RESTORE STARTED
4362 wait_request_state $fid RESTORE CANCELED
4363 wait_request_state $fid CANCEL SUCCEED
4365 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4366 error "The expected changelog was not emitted"
4370 run_test 223a "Changelog for restore canceled (import case)"
4373 # test needs a running copytool
4376 local f=$DIR/$tdir/$tfile
4378 fid=$(make_custom_file_for_progress $f 39 1000000)
4379 [ $? != 0 ] && skip "not enough free space" && return
4382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4383 wait_request_state $fid ARCHIVE SUCCEED
4386 wait_request_state $fid RESTORE STARTED
4388 wait_request_state $fid RESTORE CANCELED
4389 wait_request_state $fid CANCEL SUCCEED
4391 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4392 error "The expected changelog was not emitted"
4396 run_test 223b "Changelog for restore canceled (release case)"
4398 test_224A() { # was test_224
4399 # test needs a running copytool
4404 local f=$DIR/$tdir/$tfile
4405 local fid=$(copy_file /etc/passwd $f)
4408 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4409 wait_request_state $fid ARCHIVE SUCCEED
4412 wait_request_state $fid REMOVE SUCCEED
4414 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4415 error "The expected changelog was not emitted"
4417 run_test 224A "Changelog for remove"
4420 # test needs a running copytool
4425 local f=$DIR/$tdir/$tfile
4426 local fid=$(copy_file /etc/passwd $f)
4429 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4430 wait_request_state $fid ARCHIVE SUCCEED
4432 copytool_remove_backend $fid
4434 # block copytool operations to allow for HSM request to be
4435 # submitted and file be unlinked (CDT will find object removed)
4440 # wait for request to reach CT
4441 wait_request_state $fid REMOVE STARTED
4447 wait_request_state $fid REMOVE FAILED
4449 # HE_REMOVE|ENOENT=0x202
4450 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4451 error "The expected changelog was not emitted"
4455 run_test 224a "Changelog for failed remove"
4458 # test needs a running copytool
4461 # test is not usable because remove request is too fast
4462 # so it is always finished before cancel can be done ...
4463 echo "Test disabled"
4467 local f=$DIR/$tdir/$tfile
4469 fid=$(make_custom_file_for_progress $f 39 1000000)
4470 [ $? != 0 ] && skip "not enough free space" && return
4473 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4474 wait_request_state $fid ARCHIVE SUCCEED
4476 # if cdt is on, it can serve too quickly the request
4481 wait_request_state $fid REMOVE CANCELED
4482 wait_request_state $fid CANCEL SUCCEED
4484 changelog_find -type HSM -target-fid $fid -flags 0x27d
4485 error "The expected changelog was not emitted"
4487 run_test 225 "Changelog for remove canceled"
4490 # test needs a running copytool
4495 local f1=$DIR/$tdir/$tfile-1
4496 local f2=$DIR/$tdir/$tfile-2
4497 local f3=$DIR/$tdir/$tfile-3
4498 local fid1=$(copy_file /etc/passwd $f1)
4499 local fid2=$(copy_file /etc/passwd $f2)
4500 copy_file /etc/passwd $f3
4503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4504 wait_request_state $fid1 ARCHIVE SUCCEED
4506 $LFS hsm_archive $f2
4507 wait_request_state $fid2 ARCHIVE SUCCEED
4509 rm $f1 || error "rm $f1 failed"
4512 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4513 error "The expected changelog was not emitted"
4515 mv $f3 $f2 || error "mv $f3 $f2 failed"
4517 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4518 error "The expected changelog was not emitted"
4520 run_test 226 "changelog for last rm/mv with exiting archive"
4522 # This is just a utility function to clarify what test_227 does
4527 "$LFS" "$action" --$flag "$file" ||
4528 error "Cannot ${action#hsm_} $flag on '$file'"
4530 # Only one changelog should be produced
4531 local entries="$(changelog_find -type HSM -target-fid $fid)"
4532 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4533 error "lfs $action --$flag '$file' produced more than one" \
4536 # Parse the last changelog record
4537 local entry="$(tail -n 1 <<< "$entries")"
4538 eval local -A changelog=$(changelog2array $entry)
4540 # Also check the flags match what is expected
4541 [[ ${changelog[flags]} == $target ]] ||
4542 error "Changelog flag is '${changelog[flags]}', not $target"
4546 local file="$DIR/$tdir/$tfile"
4547 local fid=$(create_empty_file "$file")
4552 for flag in norelease noarchive exists archived lost; do
4553 if [ "$flag" == lost ]; then
4554 # The flag "lost" only works on an archived file
4555 "$LFS" hsm_set --archived "$file"
4559 action="hsm_set" __test_227
4560 action="hsm_clear" __test_227
4563 run_test 227 "changelog when explicit setting of HSM flags"
4566 # test needs a running copytool
4569 local fid=$(create_small_sync_file $DIR/$tfile)
4570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4571 wait_request_state $fid ARCHIVE SUCCEED
4573 $LFS hsm_release $DIR/$tfile
4574 check_hsm_flags $DIR/$tfile "0x0000000d"
4576 filefrag $DIR/$tfile | grep " 1 extent found" ||
4577 error "filefrag on released file must return only one extent"
4579 # only newer versions of cp detect sparse files by stat/FIEMAP
4581 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4582 error "copying $DIR/$tfile"
4583 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4585 $LFS hsm_release $DIR/$tfile
4586 check_hsm_flags $DIR/$tfile "0x0000000d"
4588 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4590 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4592 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4593 error "comparing untarred $DIR/$tfile"
4595 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4596 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4598 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4601 # test needs a running copytool
4605 local maxrequest=$(get_hsm_param max_requests)
4606 local rqcnt=$(($maxrequest * 3))
4610 for i in $(seq -w 1 $rqcnt); do
4612 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4614 # we do it in 2 steps, so all requests arrive at the same time
4615 for i in $(seq -w 1 $rqcnt); do
4616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4621 while [[ $cnt != 0 || $wt != 0 ]]; do
4623 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4624 $HSM_PARAM.actions |\
4625 grep STARTED | grep -v CANCEL | wc -l")
4626 [[ $cnt -le $maxrequest ]] ||
4627 error "$cnt > $maxrequest too many started requests"
4628 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4629 $HSM_PARAM.actions |\
4630 grep WAITING | wc -l")
4631 echo "max=$maxrequest started=$cnt waiting=$wt"
4634 run_test 250 "Coordinator max request"
4637 # test needs a running copytool
4640 local f=$DIR/$tdir/$tfile
4642 fid=$(make_custom_file_for_progress $f 103 1048576)
4643 [ $? != 0 ] && skip "not enough free space" && return
4646 # to have a short test
4647 local old_to=$(get_hsm_param active_request_timeout)
4648 set_hsm_param active_request_timeout 4
4649 # to be sure the cdt will wake up frequently so
4650 # it will be able to cancel the "old" request
4651 local old_loop=$(get_hsm_param loop_period)
4652 set_hsm_param loop_period 2
4655 # clear locks to avoid extra delay caused by flush/cancel
4656 # and thus prevent early copytool death to timeout.
4657 cancel_lru_locks osc
4659 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4660 wait_request_state $fid ARCHIVE STARTED
4662 wait_request_state $fid ARCHIVE CANCELED
4664 set_hsm_param active_request_timeout $old_to
4665 set_hsm_param loop_period $old_loop
4667 run_test 251 "Coordinator request timeout"
4671 local f=$DIR/$tdir/$tfile
4672 local fid=$(create_empty_file "$f")
4674 # to have a short test
4675 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4676 set_hsm_param loop_period 1
4681 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4682 wait_request_state $fid ARCHIVE STARTED
4685 stack_trap "set_hsm_param active_request_timeout \
4686 $(get_hsm_param active_request_timeout)" EXIT
4687 set_hsm_param active_request_timeout 1
4689 wait_request_state $fid ARCHIVE CANCELED
4692 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4696 # test needs a running copytool
4700 local f=$DIR/$tdir/$tfile
4702 dd if=/dev/zero of=$f bs=1MB count=10
4703 local fid=$(path2fid $f)
4705 $LFS hsm_archive $f || error "could not archive file"
4706 wait_request_state $fid ARCHIVE SUCCEED
4708 # clear locks to discard inode data
4709 cancel_lru_locks osc
4711 #define OBD_FAIL_MDC_MERGE 0x807
4712 $LCTL set_param fail_loc=0x807
4714 #expect error here, instead of release with wrong size
4717 if ((rc == 0)); then
4718 file_size=$(stat -c '%s' $f)
4719 if ((file_size != 10485760)); then
4720 error "Wrong file size after hsm_release"
4723 echo "could not release file"
4726 run_test 253 "Check for wrong file size after release"
4730 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4731 skip "need MDS version at least 2.10.56" && return
4733 # Check that the counters are initialized to 0
4735 for request_type in archive restore remove; do
4736 count="$(get_hsm_param ${request_type}_count)" ||
4737 error "Reading ${request_type}_count failed with $?"
4739 [ "$count" -eq 0 ] ||
4740 error "Expected ${request_type}_count to be " \
4744 run_test 254a "Request counters are initialized to zero"
4748 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4749 skip "need MDS version at least 2.10.56" && return
4751 # The number of request to launch (at least 32)
4752 local request_count=$((RANDOM % 32 + 32))
4753 printf "Will launch %i requests of each type\n" "$request_count"
4755 # Launch a copytool to process requests
4758 # Set hsm.max_requests to allow starting all requests at the same time
4760 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4761 set_hsm_param max_requests "$request_count"
4765 for request_type in archive restore remove; do
4766 printf "Checking %s requests\n" "${request_type}"
4767 # Suspend the copytool to give us time to read the proc files
4770 for ((i = 0; i < $request_count; i++)); do
4771 case $request_type in
4773 create_empty_file "$DIR/$tdir/$tfile-$i" \
4777 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4780 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4783 # Give the coordinator 10 seconds to start every request
4785 while get_hsm_param actions | grep -q WAITING; do
4788 [ $timeout -gt 0 ] ||
4789 error "${request_type^} requests took too " \
4793 count="$(get_hsm_param ${request_type}_count)"
4794 [ "$count" -eq "$request_count" ] ||
4795 error "Expected '$request_count' (!= '$count') " \
4796 "active $request_type requests"
4798 # Let the copytool process the requests
4800 # Give it 10 seconds maximum
4802 while get_hsm_param actions | grep -q STARTED; do
4805 [ $timeout -gt 0 ] ||
4806 error "${request_type^} requests took too " \
4810 count="$(get_hsm_param ${request_type}_count)"
4811 [ "$count" -eq 0 ] ||
4812 error "Expected 0 (!= '$count') " \
4813 "active $request_type requests"
4816 run_test 254b "Request counters are correctly incremented and decremented"
4819 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4821 # the only way to test ondisk conf is to restart MDS ...
4822 echo "Stop coordinator and remove coordinator state at mount"
4825 # clean on disk conf set by default
4826 cdt_clear_mount_state
4827 cdt_check_state stopped
4829 # check cdt still off after umount/remount
4831 cdt_check_state stopped
4833 echo "Set coordinator start at mount, and start coordinator"
4834 cdt_set_mount_state enabled
4837 cdt_check_state enabled
4839 # check cdt still on after umount/remount
4841 cdt_check_state enabled
4843 # we are back to original state (cdt started at mount)
4845 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4848 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4850 local ai=$(get_hsm_param default_archive_id)
4851 local new=$((ai + 1))
4853 set_hsm_param default_archive_id $new -P
4855 local res=$(get_hsm_param default_archive_id)
4858 set_hsm_param default_archive_id "" "-P -d"
4860 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4862 run_test 301 "HSM tunnable are persistent"
4865 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4867 local ai=$(get_hsm_param default_archive_id)
4868 local new=$((ai + 1))
4873 set_hsm_param default_archive_id $new -P
4876 for mdtno in $(seq 1 $MDSCOUNT); do
4881 cdt_check_state enabled
4883 local res=$(get_hsm_param default_archive_id)
4886 set_hsm_param default_archive_id "" "-P -d"
4888 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4890 run_test 302 "HSM tunnable are persistent when CDT is off"
4893 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4899 local dir_mdt0=$DIR/$tdir/mdt0
4900 local dir_mdt1=$DIR/$tdir/mdt1
4902 # create 1 dir per MDT
4903 stack_trap "rm -rf $dir_mdt0"
4904 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4905 stack_trap "rm -rf $dir_mdt1"
4906 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4908 # create 1 file in each MDT
4909 local fid1=$(create_small_file $dir_mdt0/$tfile)
4910 local fid2=$(create_small_file $dir_mdt1/$tfile)
4912 # check that hsm request on mdt0 is sent to the right MDS
4913 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4914 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4915 echo "archive successful on mdt0"
4917 # check that hsm request on mdt1 is sent to the right MDS
4918 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4919 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4920 echo "archive successful on mdt1"
4922 run_test 400 "Single request is sent to the right MDT"
4925 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4931 local dir_mdt0=$DIR/$tdir/mdt0
4932 local dir_mdt1=$DIR/$tdir/mdt1
4934 # create 1 dir per MDT
4935 stack_trap "rm -rf $dir_mdt0" EXIT
4936 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4937 stack_trap "rm -rf $dir_mdt1" EXIT
4938 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4940 # create 1 file in each MDT
4941 local fid1=$(create_small_file $dir_mdt0/$tfile)
4942 local fid2=$(create_small_file $dir_mdt1/$tfile)
4944 # check that compound requests are shunt to the rights MDTs
4945 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4946 error "lfs hsm_archive"
4947 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4948 echo "archive successful on mdt0"
4949 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4950 echo "archive successful on mdt1"
4952 run_test 401 "Compound requests split and sent to their respective MDTs"
4954 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4959 local node=$(facet_active_host $facet)
4961 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4962 awk '{print $4}'); do
4963 echo "$3 $mdc on $node"
4964 do_facet $facet "$LCTL --device $mdc $state" || return 1
4969 # deactivate all mdc on agent1
4970 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4972 copytool setup --no-fail
4974 check_agent_unregistered "uuid" # match any agent
4976 # no expected running copytool
4977 search_copytools $agent && error "Copytool start should have failed"
4980 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4982 run_test 402a "Copytool start fails if all MDTs are inactive"
4989 local f=$DIR/$tdir/$tfile
4990 touch $f || error "touch $f failed"
4991 local fid=$(path2fid $f)
4993 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4994 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4997 # give time for CDT to send request and to keep it for retry
4998 wait_for_loop_period
5000 wait_request_state $fid ARCHIVE WAITING
5002 do_facet $SINGLEAGT lctl set_param fail_loc=0
5004 # request should succeed now
5005 wait_request_state $fid ARCHIVE SUCCEED
5007 run_test 402b "CDT must retry request upon slow start of CT"
5010 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5012 local agent=$(facet_active_host $SINGLEAGT)
5014 # deactivate all mdc for MDT0001
5015 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5018 local uuid=$(get_agent_uuid $agent)
5019 # check the agent is registered on MDT0000, and not on MDT0001
5020 check_agent_registered_by_mdt $uuid 0
5021 check_agent_unregistered_by_mdt $uuid 1
5023 # check running copytool process
5024 search_copytools $agent || error "No running copytools on $agent"
5026 # reactivate all mdc for MDT0001
5027 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5029 # make sure the copytool is now registered to all MDTs
5030 check_agent_registered $uuid
5032 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5035 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5039 # create files on both MDT0000 and MDT0001
5042 local dir_mdt0=$DIR/$tdir/mdt0
5043 stack_trap "rm -rf $dir_mdt0" EXIT
5044 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5046 # create 1 file on mdt0
5047 local fid1=$(create_small_file $dir_mdt0/$tfile)
5049 # deactivate all mdc for MDT0001
5050 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5052 # send an HSM request for files in MDT0000
5053 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5055 # check for completion of files in MDT0000
5056 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5057 echo "archive successful on mdt0"
5059 # reactivate all mdc for MDT0001
5060 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5062 run_test 404 "Inactive MDT does not block requests for active MDTs"
5065 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5071 local striped_dir=$DIR/$tdir/striped_dir
5073 # create striped dir on all of MDTs
5074 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5076 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5077 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5078 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5079 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5081 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5082 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5083 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5084 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5086 # check that compound requests are shunt to the rights MDTs
5087 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5088 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5089 error "lfs hsm_archive"
5091 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5092 echo "archive successful on $fid1"
5093 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5094 echo "archive successful on $fid2"
5095 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5096 echo "archive successful on $fid3"
5097 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5098 echo "archive successful on $fid4"
5100 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5101 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5102 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5103 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5105 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5106 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5107 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5108 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5110 run_test 405 "archive and release under striped directory"
5113 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5115 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5116 skip "need MDS version at least 2.7.64" && return 0
5121 fid=$(create_small_file $DIR/$tdir/$tfile)
5126 $LFS hsm_archive $DIR/$tdir/$tfile
5127 wait_request_state "$fid" ARCHIVE SUCCEED
5128 $LFS hsm_release $DIR/$tdir/$tfile
5130 # Should migrate $tdir but not $tfile.
5131 $LFS migrate -m1 $DIR/$tdir &&
5132 error "migrating HSM an archived file should fail"
5134 $LFS hsm_restore $DIR/$tdir/$tfile
5135 wait_request_state "$fid" RESTORE SUCCEED
5137 $LFS hsm_remove $DIR/$tdir/$tfile
5138 wait_request_state "$fid" REMOVE SUCCEED
5140 cat $DIR/$tdir/$tfile > /dev/null ||
5141 error "cannot read $DIR/$tdir/$tfile"
5143 $LFS migrate -m1 $DIR/$tdir ||
5144 error "cannot complete migration after HSM remove"
5146 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5147 if ((mdt_index != 1)); then
5148 error "expected MDT index 1, got $mdt_index"
5151 # Refresh fid after migration.
5152 fid=$(path2fid $DIR/$tdir/$tfile)
5155 $LFS hsm_archive $DIR/$tdir/$tfile
5156 wait_request_state "$fid" ARCHIVE SUCCEED 1
5158 lctl set_param debug=+trace
5159 $LFS hsm_release $DIR/$tdir/$tfile ||
5160 error "cannot release $DIR/$tdir/$tfile"
5162 $LFS hsm_restore $DIR/$tdir/$tfile
5163 wait_request_state "$fid" RESTORE SUCCEED 1
5165 cat $DIR/$tdir/$tfile > /dev/null ||
5166 error "cannot read $DIR/$tdir/$tfile"
5168 run_test 406 "attempting to migrate HSM archived files is safe"
5171 needclients 2 || return 0
5172 # test needs a running copytool
5177 local f=$DIR/$tdir/$tfile
5178 local f2=$DIR2/$tdir/$tfile
5180 fid=$(make_custom_file_for_progress $f 39 1000000)
5181 [ $? != 0 ] && skip "not enough free space" && return
5183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5184 wait_request_state $fid ARCHIVE SUCCEED
5187 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5188 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5191 # 1st request holds layout lock while appropriate
5192 # RESTORE record is still not added to llog
5196 # after umount hsm_actions->O/x/x log shouldn't have
5197 # double RESTORE records like below
5198 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5199 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5201 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5204 wait_request_state $fid RESTORE SUCCEED
5206 run_test 407 "Check for double RESTORE records in llog"
5210 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5211 skip "HSM migrate is not supported" && return
5213 test_mkdir -p $DIR/$tdir
5214 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5216 run_test 500 "various LLAPI HSM tests"
5221 check_and_cleanup_lustre