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 CLIENT_NIDS=( $($LCTL list_nids all) )
979 test_1A() { # was test_1
983 local f=$DIR/$tdir/$tfile
987 check_hsm_flags_user $f "0x00000000"
989 $RUNAS $LFS hsm_set --norelease $f ||
990 error "user could not change hsm flags"
991 check_hsm_flags_user $f "0x00000010"
993 $RUNAS $LFS hsm_clear --norelease $f ||
994 error "user could not clear hsm flags"
995 check_hsm_flags_user $f "0x00000000"
997 # User could not change those flags...
998 $RUNAS $LFS hsm_set --exists $f &&
999 error "user should not set this flag"
1000 check_hsm_flags_user $f "0x00000000"
1003 $LFS hsm_set --exists $f ||
1004 error "root could not change hsm flags"
1005 check_hsm_flags_user $f "0x00000001"
1007 $LFS hsm_clear --exists $f ||
1008 error "root could not clear hsm state"
1009 check_hsm_flags_user $f "0x00000000"
1012 run_test 1A "lfs hsm flags root/non-root access"
1015 local f=$DIR/$tdir/$tfile
1016 local fid=$(create_small_file $f)
1020 $LFS hsm_archive $f || error "could not archive file"
1021 wait_request_state $fid ARCHIVE SUCCEED
1023 # Release and check states
1024 $LFS hsm_release $f || error "could not release file"
1025 echo -n "Verifying released state: "
1026 check_hsm_flags $f "0x0000000d"
1028 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
1030 run_test 1a "mmap & cat a HSM released file"
1034 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
1035 error "failed to set default stripe"
1036 local f=$DIR/$tdir/$tfile
1039 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1040 error "failed to create file"
1041 local fid=$(path2fid $f)
1046 $LFS hsm_archive $f || error "could not archive file"
1047 wait_request_state $fid ARCHIVE SUCCEED
1050 $LFS hsm_release $f || error "could not release file"
1051 echo "verify released state: "
1052 check_hsm_flags $f "0x0000000d" && echo "pass"
1055 $LFS hsm_restore $f || error "could not restore file"
1056 wait_request_state $fid RESTORE SUCCEED
1057 echo "verify restored state: "
1058 check_hsm_flags $f "0x00000009" && echo "pass"
1060 run_test 1b "Archive, Release and Restore composite file"
1064 chmod 777 $DIR/$tdir
1066 local f=$DIR/$tdir/$tfile
1069 # Test whether we can set the maximum archive number.
1070 local LOCAL_HSM_ARCHIVE_NUMBER=32
1071 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1072 error "root could not change hsm flags"
1073 check_hsm_flags_user $f "0x00000001"
1074 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1075 local st=$(get_hsm_archive_id $f)
1076 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1077 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1079 # Test whether setting archive number 0 results in no change.
1080 $LFS hsm_set --exists --archive-id 0 $f ||
1081 error "root could not change hsm flags"
1082 check_hsm_flags_user $f "0x00000001"
1083 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1084 st=$(get_hsm_archive_id $f)
1085 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1086 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1088 # Test whether setting archive number > 32 results in error.
1089 $LFS hsm_set --exists --archive-id 33 $f &&
1090 error "archive number is larger than 32"
1091 check_hsm_flags_user $f "0x00000001"
1093 # Test whether setting archive number 16 and archived flag.
1094 LOCAL_HSM_ARCHIVE_NUMBER=16
1095 $LFS hsm_set --exists --archived \
1096 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1097 error "root could not change hsm flags"
1098 check_hsm_flags_user $f "0x00000009"
1099 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1100 st=$(get_hsm_archive_id $f)
1101 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1102 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1104 run_test 1c "Check setting archive-id in lfs hsm_set"
1108 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1109 error "failed to set default stripe"
1110 local f=$DIR/$tdir/$tfile
1113 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1114 error "failed to create file"
1115 local fid=$(path2fid $f)
1120 $LFS hsm_archive $f || error "could not archive file"
1121 wait_request_state $fid ARCHIVE SUCCEED
1124 $LFS hsm_release $f || error "could not release file"
1125 echo "verify released state: "
1126 check_hsm_flags $f "0x0000000d" && echo "pass"
1129 $LFS hsm_restore $f || error "could not restore file"
1130 wait_request_state $fid RESTORE SUCCEED
1131 echo "verify restored state: "
1132 check_hsm_flags $f "0x00000009" && echo "pass"
1134 run_test 1d "Archive, Release and Restore DoM file"
1137 local f=$DIR/$tdir/$tfile
1139 create_empty_file "$f"
1140 # New files are not dirty
1141 check_hsm_flags $f "0x00000000"
1143 # For test, we simulate an archived file.
1144 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1145 check_hsm_flags $f "0x00000001"
1147 # chmod do not put the file dirty
1148 chmod 600 $f || error "could not chmod test file"
1149 check_hsm_flags $f "0x00000001"
1151 # chown do not put the file dirty
1152 chown $RUNAS_ID $f || error "could not chown test file"
1153 check_hsm_flags $f "0x00000001"
1155 # truncate put the file dirty
1156 $TRUNCATE $f 1 || error "could not truncate test file"
1157 check_hsm_flags $f "0x00000003"
1159 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1160 check_hsm_flags $f "0x00000001"
1162 run_test 2 "Check file dirtyness when doing setattr"
1168 # New files are not dirty
1169 cp -p /etc/passwd $f
1170 check_hsm_flags $f "0x00000000"
1172 # For test, we simulate an archived file.
1173 $LFS hsm_set --exists $f ||
1174 error "user could not change hsm flags"
1175 check_hsm_flags $f "0x00000001"
1177 # Reading a file, does not set dirty
1178 cat $f > /dev/null || error "could not read file"
1179 check_hsm_flags $f "0x00000001"
1181 # Open for write without modifying data, does not set dirty
1182 openfile -f O_WRONLY $f || error "could not open test file"
1183 check_hsm_flags $f "0x00000001"
1185 # Append to a file sets it dirty
1186 cp -p /etc/passwd $f.append || error "could not create file"
1187 $LFS hsm_set --exists $f.append ||
1188 error "user could not change hsm flags"
1189 dd if=/etc/passwd of=$f.append bs=1 count=3\
1190 conv=notrunc oflag=append status=noxfer ||
1191 file_creation_failure dd $f.append $?
1192 check_hsm_flags $f.append "0x00000003"
1194 # Modify a file sets it dirty
1195 cp -p /etc/passwd $f.modify || error "could not create file"
1196 $LFS hsm_set --exists $f.modify ||
1197 error "user could not change hsm flags"
1198 dd if=/dev/zero of=$f.modify bs=1 count=3\
1199 conv=notrunc status=noxfer ||
1200 file_creation_failure dd $f.modify $?
1201 check_hsm_flags $f.modify "0x00000003"
1203 # Open O_TRUNC sets dirty
1204 cp -p /etc/passwd $f.trunc || error "could not create file"
1205 $LFS hsm_set --exists $f.trunc ||
1206 error "user could not change hsm flags"
1207 cp /etc/group $f.trunc || error "could not override a file"
1208 check_hsm_flags $f.trunc "0x00000003"
1210 # Mmapped a file sets dirty
1211 cp -p /etc/passwd $f.mmap || error "could not create file"
1212 $LFS hsm_set --exists $f.mmap ||
1213 error "user could not change hsm flags"
1214 multiop $f.mmap OSMWUc || error "could not mmap a file"
1215 check_hsm_flags $f.mmap "0x00000003"
1217 run_test 3 "Check file dirtyness when opening for write"
1220 local f=$DIR/$tdir/$tfile
1221 local fid=$(create_small_file $f)
1224 local st=$(get_request_state $fid CANCEL)
1225 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1227 run_test 4 "Useless cancel must not be registered"
1230 # test needs a running copytool
1234 local f=$DIR/$tdir/$tfile
1235 local fid=$(copy_file /etc/passwd $f)
1237 wait_request_state $fid ARCHIVE SUCCEED
1239 check_hsm_flags $f "0x00000009"
1241 run_test 8 "Test default archive number"
1243 test_9A() { # was test_9
1244 # we do not use the default one to be sure
1245 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1246 copytool setup --archive-id $archive_id
1248 # give time for CT to register with MDTs
1249 sleep $(($MDSCOUNT*2))
1250 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1251 check_agent_registered $uuid
1254 local f=$DIR/$tdir/$tfile
1255 local fid=$(copy_file /etc/passwd $f)
1256 $LFS hsm_archive --archive $archive_id $f
1257 wait_request_state $fid ARCHIVE SUCCEED
1259 check_hsm_flags $f "0x00000009"
1261 run_test 9A "Use of explicit archive number, with dedicated copytool"
1264 needclients 3 || return 0
1270 # start all of the copytools
1271 for n in $(seq $AGTCOUNT); do
1272 copytool setup --facet agt$n
1276 for n in $(seq $AGTCOUNT); do
1277 file=$DIR/$tdir/$tfile.$n
1278 fid=$(create_small_file $file)
1280 $LFS hsm_archive $file || error "could not archive file $file"
1281 wait_request_state $fid ARCHIVE SUCCEED
1282 check_hsm_flags $file "0x00000009"
1285 run_test 9a "Multiple remote agents"
1288 # test needs a running copytool
1291 mkdir -p $DIR/$tdir/d1
1292 local f=$DIR/$tdir/$tfile
1293 local fid=$(copy_file /etc/hosts $f)
1294 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1295 error "hsm_archive failed"
1296 wait_request_state $fid ARCHIVE SUCCEED
1298 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1299 error "fid $fid not in archive $HSM_ARCHIVE"
1300 echo "Verifying content"
1301 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1302 echo "Verifying hsm state "
1303 check_hsm_flags $f "0x00000009"
1305 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1306 local st=$(get_hsm_archive_id $f)
1307 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1308 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1312 run_test 10a "Archive a file"
1315 # test needs a running copytool
1319 local f=$DIR/$tdir/$tfile
1320 local fid=$(copy_file /etc/hosts $f)
1321 $LFS hsm_archive $f || error "archive request failed"
1322 wait_request_state $fid ARCHIVE SUCCEED
1324 $LFS hsm_archive $f || error "archive of non dirty file failed"
1325 local cnt=$(get_request_count $fid ARCHIVE)
1326 [[ "$cnt" == "1" ]] ||
1327 error "archive of non dirty file must not make a request"
1329 run_test 10b "Archive of non dirty file must work without doing request"
1332 # test needs a running copytool
1336 local f=$DIR/$tdir/$tfile
1337 local fid=$(copy_file /etc/hosts $f)
1338 $LFS hsm_set --noarchive $f
1339 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1342 run_test 10c "Check forbidden archive"
1345 # test needs a running copytool
1349 local f=$DIR/$tdir/$tfile
1350 local fid=$(copy_file /etc/hosts $f)
1351 $LFS hsm_archive $f || error "cannot archive $f"
1352 wait_request_state $fid ARCHIVE SUCCEED
1354 local ar=$(get_hsm_archive_id $f)
1355 local dflt=$(get_hsm_param default_archive_id)
1356 [[ $ar == $dflt ]] ||
1357 error "archived file is not on default archive: $ar != $dflt"
1359 run_test 10d "Archive a file on the default archive id"
1363 copy2archive /etc/hosts $tdir/$tfile
1364 local f=$DIR/$tdir/$tfile
1366 import_file $tdir/$tfile $f
1367 echo -n "Verifying released state: "
1368 check_hsm_flags $f "0x0000000d"
1370 local LSZ=$(stat -c "%s" $f)
1371 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1373 echo "Verifying imported size $LSZ=$ASZ"
1374 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1375 echo -n "Verifying released pattern: "
1376 local PTRN=$($GETSTRIPE -L $f)
1378 [[ $PTRN == released ]] || error "Is not released"
1379 local fid=$(path2fid $f)
1380 echo "Verifying new fid $fid in archive"
1382 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1383 error "fid $fid not in archive $HSM_ARCHIVE"
1385 run_test 11a "Import a file"
1388 # test needs a running copytool
1392 local f=$DIR/$tdir/$tfile
1393 local fid=$(copy_file /etc/hosts $f)
1394 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1395 error "hsm_archive failed"
1396 wait_request_state $fid ARCHIVE SUCCEED
1398 local FILE_HASH=$(md5sum $f)
1403 echo "$FILE_HASH" | md5sum -c
1405 [[ $? -eq 0 ]] || error "Restored file differs"
1409 run_test 11b "Import a deleted file using its FID"
1412 # test needs a running copytool
1416 copy2archive /etc/hosts $tdir/$tfile
1418 local f=$DIR/$tdir/$tfile
1419 import_file $tdir/$tfile $f
1420 local f2=$DIR2/$tdir/$tfile
1421 echo "Verifying released state: "
1422 check_hsm_flags $f2 "0x0000000d"
1424 local fid=$(path2fid $f2)
1425 $LFS hsm_restore $f2
1426 wait_request_state $fid RESTORE SUCCEED
1428 echo "Verifying file state: "
1429 check_hsm_flags $f2 "0x00000009"
1431 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1433 [[ $? -eq 0 ]] || error "Restored file differs"
1437 run_test 12a "Restore an imported file explicitly"
1440 # test needs a running copytool
1444 copy2archive /etc/hosts $tdir/$tfile
1446 local f=$DIR/$tdir/$tfile
1447 import_file $tdir/$tfile $f
1448 echo "Verifying released state: "
1449 check_hsm_flags $f "0x0000000d"
1451 cat $f > /dev/null || error "File read failed"
1453 echo "Verifying file state after restore: "
1454 check_hsm_flags $f "0x00000009"
1456 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1458 [[ $? -eq 0 ]] || error "Restored file differs"
1462 run_test 12b "Restore an imported file implicitly"
1465 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1467 # test needs a running copytool
1470 local f=$DIR/$tdir/$tfile
1472 $LFS setstripe -c 2 "$f"
1474 fid=$(make_custom_file_for_progress $f 5)
1475 [ $? != 0 ] && skip "not enough free space" && return
1477 local FILE_CRC=$(md5sum $f)
1479 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1480 wait_request_state $fid ARCHIVE SUCCEED
1481 $LFS hsm_release $f || error "release $f failed"
1483 echo "$FILE_CRC" | md5sum -c
1485 [[ $? -eq 0 ]] || error "Restored file differs"
1487 run_test 12c "Restore a file with stripe of 2"
1490 # test needs a running copytool
1495 local f=$DIR/$tdir/$tfile
1496 local fid=$(copy_file /etc/hosts $f)
1497 $LFS hsm_restore $f || error "restore of non archived file failed"
1498 local cnt=$(get_request_count $fid RESTORE)
1499 [[ "$cnt" == "0" ]] ||
1500 error "restore non archived must not make a request"
1501 $LFS hsm_archive $f ||
1502 error "archive request failed"
1503 wait_request_state $fid ARCHIVE SUCCEED
1504 $LFS hsm_restore $f ||
1505 error "restore of non released file failed"
1506 local cnt=$(get_request_count $fid RESTORE)
1507 [[ "$cnt" == "0" ]] ||
1508 error "restore a non dirty file must not make a request"
1510 run_test 12d "Restore of a non archived, non released file must work"\
1511 " without doing request"
1514 # test needs a running copytool
1517 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1518 local f=$DIR/$tdir/$tfile
1519 local fid=$(copy_file /etc/hosts $f)
1520 $LFS hsm_archive $f || error "archive request failed"
1521 wait_request_state $fid ARCHIVE SUCCEED
1524 cat /etc/hosts >> $f
1528 $LFS hsm_restore $f && error "restore a dirty file must fail"
1531 run_test 12e "Check forbidden restore"
1534 # test needs a running copytool
1538 local f=$DIR/$tdir/$tfile
1539 local fid=$(copy_file /etc/hosts $f)
1541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1542 wait_request_state $fid ARCHIVE SUCCEED
1543 $LFS hsm_release $f || error "release of $f failed"
1545 wait_request_state $fid RESTORE SUCCEED
1547 echo -n "Verifying file state: "
1548 check_hsm_flags $f "0x00000009"
1550 diff -q /etc/hosts $f
1552 [[ $? -eq 0 ]] || error "Restored file differs"
1554 run_test 12f "Restore a released file explicitly"
1557 # test needs a running copytool
1561 local f=$DIR/$tdir/$tfile
1562 local fid=$(copy_file /etc/hosts $f)
1564 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1565 wait_request_state $fid ARCHIVE SUCCEED
1566 $LFS hsm_release $f || error "release of $f failed"
1568 diff -q /etc/hosts $f
1571 # we check we had a restore done
1572 wait_request_state $fid RESTORE SUCCEED
1574 [[ $st -eq 0 ]] || error "Restored file differs"
1576 run_test 12g "Restore a released file implicitly"
1579 needclients 2 || return 0
1581 # test needs a running copytool
1585 local f=$DIR/$tdir/$tfile
1586 local fid=$(copy_file /etc/hosts $f)
1588 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1589 wait_request_state $fid ARCHIVE SUCCEED
1590 $LFS hsm_release $f || error "release of $f failed"
1592 do_node $CLIENT2 diff -q /etc/hosts $f
1595 # we check we had a restore done
1596 wait_request_state $fid RESTORE SUCCEED
1598 [[ $st -eq 0 ]] || error "Restored file differs"
1600 run_test 12h "Restore a released file implicitly from a second node"
1603 # test needs a running copytool
1607 local f=$DIR/$tdir/$tfile
1608 local fid=$(copy_file /etc/passwd $f)
1609 $LFS hsm_archive $f || error "archive of $f failed"
1610 wait_request_state $fid ARCHIVE SUCCEED
1612 $LFS hsm_release $f || error "release of $f failed"
1616 [[ $? -eq 0 ]] || error "Restored file differs"
1618 run_test 12m "Archive/release/implicit restore"
1621 # test needs a running copytool
1625 copy2archive /etc/hosts $tdir/$tfile
1627 local f=$DIR/$tdir/$tfile
1628 import_file $tdir/$tfile $f
1630 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1631 error "Restored file differs"
1633 $LFS hsm_release $f || error "release of $f failed"
1637 run_test 12n "Import/implicit restore/release"
1640 # test needs a running copytool
1644 local f=$DIR/$tdir/$tfile
1645 local fid=$(copy_file /etc/hosts $f)
1647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1648 wait_request_state $fid ARCHIVE SUCCEED
1649 $LFS hsm_release $f || error "release of $f failed"
1651 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1652 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1654 # set no retry action mode
1657 diff -q /etc/hosts $f
1660 # we check we had a restore failure
1661 wait_request_state $fid RESTORE FAILED
1663 [[ $st -eq 0 ]] && error "Restore must fail"
1665 # remove no retry action mode
1668 # check file is still released
1669 check_hsm_flags $f "0x0000000d"
1671 # retry w/o failure injection
1672 do_facet $SINGLEMDS lctl set_param fail_loc=0
1674 # to be sure previous RESTORE result is gone
1676 wait_for_grace_delay
1678 diff -q /etc/hosts $f
1681 # we check we had a restore done
1682 wait_request_state $fid RESTORE SUCCEED
1684 [[ $st -eq 0 ]] || error "Restored file differs"
1686 run_test 12o "Layout-swap failure during Restore leaves file released"
1689 # test needs a running copytool
1693 local f=$DIR/$tdir/$tfile
1694 local fid=$(copy_file /etc/hosts $f)
1696 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1697 wait_request_state $fid ARCHIVE SUCCEED
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"
1701 $LFS hsm_release $f || error "cannot release $f"
1702 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1704 run_test 12p "implicit restore of a file on copytool mount point"
1706 cleanup_test_12q() {
1707 error "cannot umount $MOUNT3 on $SINGLEAGT"
1711 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1712 skip "need MDS version at least 2.7.58" && return 0
1714 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1715 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1716 error "cannot mount $MOUNT3 on $SINGLEAGT"
1718 # test needs a running copytool
1719 copytool setup -m "$MOUNT3"
1721 local f=$DIR/$tdir/$tfile
1722 local f2=$DIR2/$tdir/$tfile
1723 local fid=$(create_small_file $f)
1724 local orig_size=$(stat -c "%s" $f)
1726 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1727 wait_request_state $fid ARCHIVE SUCCEED
1729 $LFS hsm_release $f || error "could not release file"
1730 check_hsm_flags $f "0x0000000d"
1733 wait_copytools || error "copytool failed to stop"
1735 cat $f > /dev/null &
1737 # wait a bit to allow implicit restore request to be handled.
1738 # if not, next stat would also block on layout-lock.
1741 local size=$(stat -c "%s" $f2)
1742 [ $size -eq $orig_size ] ||
1743 error "$f2: wrong size after archive: $size != $orig_size"
1745 copytool setup -m "$MOUNT3"
1749 size=$(stat -c "%s" $f)
1750 [ $size -eq $orig_size ] ||
1751 error "$f: wrong size after restore: $size != $orig_size"
1753 size=$(stat -c "%s" $f2)
1754 [ $size -eq $orig_size ] ||
1755 error "$f2: wrong size after restore: $size != $orig_size"
1759 size=$(stat -c "%s" $f)
1761 error "$f: wrong size after overwrite: $size != 0"
1763 size=$(stat -c "%s" $f2)
1765 error "$f2: wrong size after overwrite: $size != 0"
1767 run_test 12q "file attributes are refreshed after restore"
1770 # test needs a running copytool
1773 local ARC_SUBDIR="import.orig"
1777 # populate directory to be imported
1778 for d in $(seq 1 10); do
1779 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1780 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1781 for f in $(seq 1 10); do
1782 CURR_FILE="$CURR_DIR/$tfile.$f"
1783 # write file-specific data
1784 do_facet $SINGLEAGT \
1785 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1786 "file=$CURR_FILE > $CURR_FILE"
1790 import_file "$ARC_SUBDIR" $DIR/$tdir
1791 # diff lustre content and origin (triggers file restoration)
1792 # there must be 10x10 identical files, and no difference
1793 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1794 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1795 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1796 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1798 [ $cnt_diff -eq 0 ] ||
1799 error "$cnt_diff imported files differ from read data"
1800 [ $cnt_ok -eq 100 ] ||
1801 error "not enough identical files ($cnt_ok != 100)"
1805 run_test 13 "Recursively import and restore a directory"
1808 # test needs a running copytool
1812 local f=$DIR/$tdir/$tfile
1813 local fid=$(create_small_file $f)
1814 local sum=$(md5sum $f | awk '{print $1}')
1815 $LFS hsm_archive $f || error "could not archive file"
1816 wait_request_state $fid ARCHIVE SUCCEED
1818 # create released file (simulate llapi_hsm_import call)
1819 local fid2=$(create_empty_file "$f")
1820 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1821 $LFS hsm_release $f || error "could not release file"
1823 # rebind the archive to the newly created file
1824 echo "rebind $fid to $fid2"
1826 do_facet $SINGLEAGT \
1827 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1828 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1830 # restore file and compare md5sum
1831 local sum2=$(md5sum $f | awk '{print $1}')
1833 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1837 run_test 14 "Rebind archived file to a new fid"
1840 # test needs a running copytool
1844 local f=$DIR/$tdir/$tfile
1846 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1850 for i in $(seq 1 $count); do
1851 fids[$i]=$(create_small_file $f.$i)
1852 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1853 $LFS hsm_archive $f.$i || error "could not archive file"
1855 wait_all_done $(($count*60))
1859 for i in $(seq 1 $count); do
1860 local fid2=$(create_empty_file "${f}.${i}")
1861 # add the rebind operation to the list
1862 echo ${fids[$i]} $fid2 >> $tmpfile
1864 # set it released (simulate llapi_hsm_import call)
1865 $LFS hsm_set --archived --exists $f.$i ||
1866 error "could not force hsm flags"
1867 $LFS hsm_release $f.$i || error "could not release file"
1869 nl=$(wc -l < $tmpfile)
1870 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1872 echo "rebind list of files"
1873 do_facet $SINGLEAGT \
1874 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1875 --rebind $tmpfile $DIR" || error "could not rebind file list"
1877 # restore files and compare md5sum
1878 for i in $(seq 1 $count); do
1879 local sum2=$(md5sum $f.$i | awk '{print $1}')
1880 [[ $sum2 == ${sums[$i]} ]] ||
1881 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1887 run_test 15 "Rebind a list of files"
1890 # test needs a running copytool
1894 # create a known size file so we can verify transfer speed
1897 dd if=/dev/zero of=$ref bs=1M count=20
1900 local f=$DIR/$tdir/$tfile
1901 local fid=$(copy_file $ref $f)
1903 local start=$(date +%s)
1905 wait_request_state $fid ARCHIVE SUCCEED
1906 local end=$(date +%s)
1907 # Add 1 to account for rounding errors between start and end (LU-8155)
1908 local duration=$((end - start + 1))
1910 [[ $duration -ge $((goal - 1)) ]] ||
1911 error "Transfer is too fast $duration < $goal"
1913 run_test 16 "Test CT bandwith control option"
1916 local f=$DIR/$tdir/$tfile
1917 create_empty_file "$f"
1919 # Could not release a non-archived file
1920 $LFS hsm_release $f && error "release should not succeed"
1922 # For following tests, we must test them with HS_ARCHIVED set
1923 $LFS hsm_set --exists --archived $f || error "could not add flag"
1925 # Could not release a file if no-release is set
1926 $LFS hsm_set --norelease $f || error "could not add flag"
1927 $LFS hsm_release $f && error "release should not succeed"
1928 $LFS hsm_clear --norelease $f || error "could not remove flag"
1930 # Could not release a file if lost
1931 $LFS hsm_set --lost $f || error "could not add flag"
1932 $LFS hsm_release $f && error "release should not succeed"
1933 $LFS hsm_clear --lost $f || error "could not remove flag"
1935 # Could not release a file if dirty
1936 $LFS hsm_set --dirty $f || error "could not add flag"
1937 $LFS hsm_release $f && error "release should not succeed"
1938 $LFS hsm_clear --dirty $f || error "could not remove flag"
1940 run_test 20 "Release is not permitted"
1943 # test needs a running copytool
1946 local f=$DIR/$tdir/test_release
1948 # Create a file and check its states
1949 local fid=$(create_small_file $f)
1950 check_hsm_flags $f "0x00000000"
1952 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1953 # used until file is flushed to disk
1954 if [ $(facet_fstype ost1) == "zfs" ]; then
1955 # this causes an OST_SYNC rpc to be sent
1956 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1957 # clear locks to reread file data
1958 cancel_lru_locks osc
1961 local orig_size=$(stat -c "%s" $f)
1962 local orig_blocks=$(stat -c "%b" $f)
1964 start_full_debug_logging
1966 $LFS hsm_archive $f || error "could not archive file"
1967 wait_request_state $fid ARCHIVE SUCCEED
1969 local blocks=$(stat -c "%b" $f)
1970 [ $blocks -eq $orig_blocks ] ||
1971 error "$f: wrong block number after archive: " \
1972 "$blocks != $orig_blocks"
1973 local size=$(stat -c "%s" $f)
1974 [ $size -eq $orig_size ] ||
1975 error "$f: wrong size after archive: $size != $orig_size"
1977 # Release and check states
1978 $LFS hsm_release $f || error "could not release file"
1979 check_hsm_flags $f "0x0000000d"
1981 blocks=$(stat -c "%b" $f)
1982 [ $blocks -gt 5 ] &&
1983 error "$f: too many blocks after release: $blocks > 5"
1984 size=$(stat -c "%s" $f)
1985 [ $size -ne $orig_size ] &&
1986 error "$f: wrong size after release: $size != $orig_size"
1988 # Check we can release an file without stripe info
1992 check_hsm_flags $f "0x00000000"
1993 $LFS hsm_archive $f || error "could not archive file"
1994 wait_request_state $fid ARCHIVE SUCCEED
1996 # Release and check states
1997 $LFS hsm_release $f || error "could not release file"
1998 check_hsm_flags $f "0x0000000d"
2000 # Release again a file that is already released is OK
2001 $LFS hsm_release $f || fail "second release should succeed"
2002 check_hsm_flags $f "0x0000000d"
2004 stop_full_debug_logging
2006 run_test 21 "Simple release tests"
2009 # test needs a running copytool
2012 local f=$DIR/$tdir/test_release
2013 local swap=$DIR/$tdir/test_swap
2015 # Create a file and check its states
2016 local fid=$(create_small_file $f)
2017 check_hsm_flags $f "0x00000000"
2019 $LFS hsm_archive $f || error "could not archive file"
2020 wait_request_state $fid ARCHIVE SUCCEED
2022 # Release and check states
2023 $LFS hsm_release $f || error "could not release file"
2024 check_hsm_flags $f "0x0000000d"
2026 create_small_file $swap
2027 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2031 run_test 22 "Could not swap a release file"
2034 # test needs a running copytool
2037 local f=$DIR/$tdir/test_mtime
2039 # Create a file and check its states
2040 local fid=$(create_small_file $f)
2041 check_hsm_flags $f "0x00000000"
2043 $LFS hsm_archive $f || error "could not archive file"
2044 wait_request_state $fid ARCHIVE SUCCEED
2046 # Set modification time in the past
2047 touch -m -a -d @978261179 $f
2049 # Release and check states
2050 $LFS hsm_release $f || error "could not release file"
2051 check_hsm_flags $f "0x0000000d"
2053 local MTIME=$(stat -c "%Y" $f)
2054 local ATIME=$(stat -c "%X" $f)
2055 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2056 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2058 run_test 23 "Release does not change a/mtime (utime)"
2061 local file=$DIR/$tdir/$tfile
2070 # test needs a running copytool
2073 fid=$(create_small_file $file)
2075 # Create a file and check its states
2076 check_hsm_flags $file "0x00000000"
2078 # Ensure atime is less than mtime and ctime.
2082 atime0=$(stat -c "%X" $file)
2083 mtime0=$(stat -c "%Y" $file)
2084 ctime0=$(stat -c "%Z" $file)
2086 [ $atime0 -lt $mtime0 ] ||
2087 error "atime $atime0 is not less than mtime $mtime0"
2089 [ $atime0 -lt $ctime0 ] ||
2090 error "atime $atime0 is not less than ctime $ctime0"
2092 # Archive should not change any timestamps.
2093 $LFS hsm_archive $file || error "cannot archive '$file'"
2094 wait_request_state $fid ARCHIVE SUCCEED
2096 atime1=$(stat -c "%X" $file)
2097 mtime1=$(stat -c "%Y" $file)
2098 ctime1=$(stat -c "%Z" $file)
2100 [ $atime0 -eq $atime1 ] ||
2101 error "archive changed atime from $atime0 to $atime1"
2103 [ $mtime0 -eq $mtime1 ] ||
2104 error "archive changed mtime from $mtime0 to $mtime1"
2106 [ $ctime0 -eq $ctime1 ] ||
2107 error "archive changed ctime from $ctime0 to $ctime1"
2109 # Release should not change any timestamps.
2110 $LFS hsm_release $file || error "cannot release '$file'"
2111 check_hsm_flags $file "0x0000000d"
2113 atime1=$(stat -c "%X" $file)
2114 mtime1=$(stat -c "%Y" $file)
2115 ctime1=$(stat -c "%Z" $file)
2117 [ $atime0 -eq $atime1 ] ||
2118 error "release changed atime from $atime0 to $atime1"
2120 [ $mtime0 -eq $mtime1 ] ||
2121 error "release changed mtime from $mtime0 to $mtime1"
2123 [ $ctime0 -eq $ctime1 ] ||
2124 error "release changed ctime from $ctime0 to $ctime1"
2126 # Restore should not change any timestamps.
2127 $LFS hsm_restore $file
2128 wait_request_state $fid RESTORE SUCCEED
2130 atime1=$(stat -c "%X" $file)
2131 mtime1=$(stat -c "%Y" $file)
2132 ctime1=$(stat -c "%Z" $file)
2134 [ $atime0 -eq $atime1 ] ||
2135 error "restore changed atime from $atime0 to $atime1"
2137 [ $mtime0 -eq $mtime1 ] ||
2138 error "restore changed mtime from $mtime0 to $mtime1"
2140 [ $ctime0 -eq $ctime1 ] ||
2141 error "restore changed ctime from $ctime0 to $ctime1"
2144 wait_copytools || error "Copytools failed to stop"
2146 # Once more, after unmount and mount.
2147 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2148 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2150 atime1=$(stat -c "%X" $file)
2151 mtime1=$(stat -c "%Y" $file)
2152 ctime1=$(stat -c "%Z" $file)
2154 [ $atime0 -eq $atime1 ] ||
2155 error "remount changed atime from $atime0 to $atime1"
2157 [ $mtime0 -eq $mtime1 ] ||
2158 error "remount changed mtime from $mtime0 to $mtime1"
2160 [ $ctime0 -eq $ctime1 ] ||
2161 error "remount changed ctime from $ctime0 to $ctime1"
2163 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2166 local file=$DIR/$tdir/$tfile
2172 # Test needs a running copytool.
2175 # Check that root can do HSM actions on a regular user's file.
2176 fid=$(create_small_file $file)
2177 sum0=$(md5sum $file)
2179 chown $RUNAS_ID:$RUNAS_GID $file ||
2180 error "cannot chown '$file' to '$RUNAS_ID'"
2182 chmod ugo-w $DIR/$tdir ||
2183 error "cannot chmod '$DIR/$tdir'"
2185 $LFS hsm_archive $file
2186 wait_request_state $fid ARCHIVE SUCCEED
2188 $LFS hsm_release $file
2189 check_hsm_flags $file "0x0000000d"
2191 $LFS hsm_restore $file
2192 wait_request_state $fid RESTORE SUCCEED
2194 # Check that ordinary user can get HSM state.
2195 $RUNAS $LFS hsm_state $file ||
2196 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2198 $LFS hsm_release $file
2199 check_hsm_flags $file "0x0000000d"
2201 # Check that ordinary user can accessed released file.
2202 sum1=$($RUNAS md5sum $file) ||
2203 error "user '$RUNAS_ID' cannot read '$file'"
2205 [ "$sum0" == "$sum1" ] ||
2206 error "md5sum mismatch for '$file'"
2208 run_test 24b "root can archive, release, and restore user files"
2211 local file=$DIR/$tdir/$tfile
2212 local action=archive
2217 # test needs a running copytool
2222 # Save the default masks and check that cleanup_24c will
2223 # restore the request masks correctly.
2224 user_save=$(get_hsm_param user_request_mask)
2225 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2226 group_save=$(get_hsm_param group_request_mask)
2227 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2228 other_save=$(get_hsm_param other_request_mask)
2229 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2231 [ "$user_save" == RESTORE ] ||
2232 error "user_request_mask is '$user_save' expected 'RESTORE'"
2233 [ "$group_save" == RESTORE ] ||
2234 error "group_request_mask is '$group_save' expected 'RESTORE'"
2235 [ "$other_save" == RESTORE ] ||
2236 error "other_request_mask is '$other_save' expected 'RESTORE'"
2239 create_small_file $file
2240 chown $RUNAS_ID:$GROUP $file ||
2241 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2243 $RUNAS $LFS hsm_$action $file &&
2244 error "$action by user should fail"
2246 set_hsm_param user_request_mask $action
2247 $RUNAS $LFS hsm_$action $file ||
2248 error "$action by user should succeed"
2251 create_small_file $file
2252 chown nobody:$RUNAS_GID $file ||
2253 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2255 $RUNAS $LFS hsm_$action $file &&
2256 error "$action by group should fail"
2258 set_hsm_param group_request_mask $action
2259 $RUNAS $LFS hsm_$action $file ||
2260 error "$action by group should succeed"
2263 create_small_file $file
2264 chown nobody:$GROUP $file ||
2265 error "cannot chown '$file' to 'nobody:$GROUP'"
2267 $RUNAS $LFS hsm_$action $file &&
2268 error "$action by other should fail"
2270 set_hsm_param other_request_mask $action
2271 $RUNAS $LFS hsm_$action $file ||
2272 error "$action by other should succeed"
2274 run_test 24c "check that user,group,other request masks work"
2277 local file1=$DIR/$tdir/$tfile
2278 local file2=$DIR2/$tdir/$tfile
2282 fid1=$(create_small_file $file1)
2285 $LFS getstripe $file1
2287 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2288 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2289 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2291 copytool setup -m "$MOUNT3"
2293 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2294 mount -o remount,ro $MOUNT2
2296 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2298 fid2=$(path2fid $file2)
2299 [ "$fid1" == "$fid2" ] ||
2300 error "FID mismatch '$fid1' != '$fid2'"
2302 $LFS hsm_archive $file2 &&
2303 error "archive should fail on read-only mount"
2304 check_hsm_flags $file1 "0x00000000"
2306 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2307 wait_request_state $fid1 ARCHIVE SUCCEED
2309 $LFS hsm_release $file1
2310 $LFS hsm_restore $file2
2311 wait_request_state $fid1 RESTORE SUCCEED
2313 $LFS hsm_release $file1 || error "cannot release '$file1'"
2314 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2316 $LFS hsm_release $file2 &&
2317 error "release should fail on read-only mount"
2321 run_test 24d "check that read-only mounts are respected"
2326 local f=$DIR/$tdir/$tfile
2329 fid=$(create_small_file $f) || error "cannot create $f"
2330 $LFS hsm_archive $f || error "cannot archive $f"
2331 wait_request_state $fid ARCHIVE SUCCEED
2332 $LFS hsm_release $f || error "cannot release $f"
2333 while ! $LFS hsm_state $f | grep released; do
2337 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2339 run_test 24e "tar succeeds on HSM released files" # LU-6213
2342 # test needs a running copytool
2345 mkdir -p $DIR/$tdir/d1
2346 local f=$DIR/$tdir/$tfile
2347 local fid=$(copy_file /etc/hosts $f)
2350 $LFS hsm_archive $f ||
2351 error "hsm_archive failed"
2352 wait_request_state $fid ARCHIVE SUCCEED
2353 $LFS hsm_release $f || error "cannot release $f"
2354 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2357 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2358 error "Can not recover the tar contents"
2360 echo "Sum0 = $sum0, sum1 = $sum1"
2361 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2363 run_test 24f "root can archive, release, and restore tar files"
2366 # test needs a running copytool
2370 copy2archive /etc/hosts $tdir/$tfile
2372 local f=$DIR/$tdir/$tfile
2374 import_file $tdir/$tfile $f
2376 $LFS hsm_set --lost $f
2381 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2385 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2386 " (Operation not permitted)"
2389 # test needs a running copytool
2394 local f=$DIR/$tdir/$tfile
2395 local fid=$(copy_file /etc/passwd $f)
2397 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2398 wait_request_state $fid ARCHIVE SUCCEED
2401 $LFS hsm_set --lost $f
2405 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2407 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2408 " (Operation not permitted)"
2410 test_26A() { # was test_26
2411 # test needs a running copytool
2414 local f=$DIR/$tdir/$tfile
2416 fid=$(make_custom_file_for_progress $f 39 1000000)
2417 [ $? != 0 ] && skip "not enough free space" && return
2419 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2420 wait_request_state $fid ARCHIVE SUCCEED
2423 wait_request_state $fid REMOVE SUCCEED
2425 check_hsm_flags $f "0x00000000"
2427 run_test 26A "Remove the archive of a valid file"
2430 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2431 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2433 # test needs a running copytool
2437 local f=$DIR/$tdir/$tfile
2438 local fid=$(copy_file /etc/passwd $f)
2440 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2441 wait_request_state $fid ARCHIVE SUCCEED
2443 local f2=$DIR/$tdir/${tfile}_2
2444 local fid2=$(copy_file /etc/passwd $f2)
2446 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2447 wait_request_state $fid2 ARCHIVE SUCCEED
2449 local f3=$DIR/$tdir/${tfile}_3
2450 local fid3=$(copy_file /etc/passwd $f3)
2452 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2453 wait_request_state $fid3 ARCHIVE SUCCEED
2455 # set a long grace_delay vs short loop_period
2456 local orig_loop_period=$(get_hsm_param loop_period)
2457 local orig_grace_delay=$(get_hsm_param grace_delay)
2458 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2459 set_hsm_param loop_period 10
2460 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2461 set_hsm_param grace_delay 100
2465 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2466 set_hsm_param remove_archive_on_last_unlink 1
2468 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2473 wait_request_state $fid2 REMOVE SUCCEED
2475 assert_request_count $fid REMOVE 0 \
2476 "Unexpected archived data remove request for $f"
2477 assert_request_count $fid3 REMOVE 0 \
2478 "Unexpected archived data remove request for $f3"
2480 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2483 # test needs a running copytool
2487 local f=$DIR/$tdir/$tfile
2488 local fid=$(copy_file /etc/passwd $f)
2490 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2491 wait_request_state $fid ARCHIVE SUCCEED
2493 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2494 set_hsm_param remove_archive_on_last_unlink 1
2497 cdt_check_state stopped
2501 wait_request_state $fid REMOVE WAITING
2505 # copytool must re-register
2507 wait_copytools || error "copytool failed to stop"
2510 wait_request_state $fid REMOVE SUCCEED
2512 run_test 26b "RAoLU policy when CDT off"
2515 # test needs a running copytool
2519 local f=$DIR/$tdir/$tfile
2520 local fid=$(copy_file /etc/passwd $f)
2522 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2523 wait_request_state $fid ARCHIVE SUCCEED
2525 local f2=$DIR/$tdir/${tfile}_2
2526 local fid2=$(copy_file /etc/passwd $f2)
2528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2529 wait_request_state $fid2 ARCHIVE SUCCEED
2531 # set a long grace_delay vs short loop_period
2532 local orig_loop_period=$(get_hsm_param loop_period)
2533 local orig_grace_delay=$(get_hsm_param grace_delay)
2534 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2535 set_hsm_param loop_period 10
2536 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2537 set_hsm_param grace_delay 100
2539 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2540 set_hsm_param remove_archive_on_last_unlink 1
2542 multiop_bg_pause $f O_c || error "open $f failed"
2548 wait_request_state $fid2 REMOVE SUCCEED
2549 assert_request_count $fid REMOVE 0 \
2550 "Unexpected archived data remove request for $f"
2552 kill -USR1 $pid || error "multiop early exit"
2553 # should reach autotest timeout if multiop fails to trap
2554 # signal, close file, and exit ...
2555 wait $pid || error "wait PID $PID failed"
2557 wait_request_state $fid REMOVE SUCCEED
2559 run_test 26c "RAoLU effective when file closed"
2562 # test needs a running copytool
2566 local f=$DIR/$tdir/$tfile
2567 local fid=$(create_small_file $f)
2569 $LFS hsm_archive $f || error "could not archive file"
2570 wait_request_state $fid ARCHIVE SUCCEED
2572 # set a long grace_delay vs short loop_period
2573 local orig_loop_period=$(get_hsm_param loop_period)
2574 local orig_grace_delay=$(get_hsm_param grace_delay)
2575 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2576 set_hsm_param loop_period 10
2577 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2578 set_hsm_param grace_delay 100
2580 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2581 set_hsm_param remove_archive_on_last_unlink 1
2583 multiop_bg_pause $f O_c || error "multiop failed"
2590 wait_request_state $fid REMOVE SUCCEED
2592 client_up || client_up || true
2594 kill -USR1 $MULTIPID
2595 wait $MULTIPID || error "multiop close failed"
2597 run_test 26d "RAoLU when Client eviction"
2600 # test needs a running copytool
2603 create_archive_file $tdir/$tfile
2604 local f=$DIR/$tdir/$tfile
2605 import_file $tdir/$tfile $f
2606 local fid=$(path2fid $f)
2610 [[ $? != 0 ]] || error "Remove of a released file should fail"
2614 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2617 # test needs a running copytool
2620 local f=$DIR/$tdir/$tfile
2622 fid=$(make_custom_file_for_progress $f 39 1000000)
2623 [ $? != 0 ] && skip "not enough free space" && return
2625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2626 wait_request_state $fid ARCHIVE SUCCEED
2631 [[ $? != 0 ]] || error "Remove of a released file should fail"
2633 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2636 # test needs a running copytool
2639 local f=$DIR/$tdir/$tfile
2641 fid=$(make_custom_file_for_progress $f 39 1000000)
2642 [ $? != 0 ] && skip "not enough free space" && return
2644 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2645 wait_request_state $fid ARCHIVE SUCCEED
2654 wait_request_state $fid REMOVE SUCCEED
2656 run_test 28 "Concurrent archive/file remove"
2659 # Tests --mntpath and --archive options
2662 copytool setup -m "$MOUNT" -a $archive_id
2664 # Bad archive number
2665 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2666 grep "Invalid argument" ||
2667 error "unexpected hsm_remove failure (1)"
2669 # mntpath is present but file is given
2670 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2671 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2672 error "unexpected hsm_remove failure (2)"
2674 run_test 29a "Tests --mntpath and --archive options"
2677 # test needs a running copytool
2680 local f=$DIR/$tdir/$tfile
2681 local fid=$(create_small_file $f)
2683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2684 wait_request_state $fid ARCHIVE SUCCEED
2688 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2689 wait_request_state $fid REMOVE SUCCEED
2691 run_test 29b "Archive/delete/remove by FID from the archive."
2694 # test needs a running copytool
2697 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2698 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2699 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2702 wait_request_state $fid1 ARCHIVE SUCCEED
2703 wait_request_state $fid2 ARCHIVE SUCCEED
2704 wait_request_state $fid3 ARCHIVE SUCCEED
2706 rm -f $DIR/$tdir/$tfile-[1-3]
2708 echo $fid1 > $DIR/$tdir/list
2709 echo $fid2 >> $DIR/$tdir/list
2710 echo $fid3 >> $DIR/$tdir/list
2712 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2713 --filelist $DIR/$tdir/list
2714 wait_request_state $fid1 REMOVE SUCCEED
2715 wait_request_state $fid2 REMOVE SUCCEED
2716 wait_request_state $fid3 REMOVE SUCCEED
2718 run_test 29c "Archive/delete/remove by FID, using a file list."
2721 # test needs more than one CT
2722 needclients 3 || return 0
2728 # start all of the copytools
2729 for n in $(seq $AGTCOUNT); do
2730 copytool setup -f agt$n -a $n
2734 file=$DIR/$tdir/$tfile
2735 fid=$(create_small_file $file)
2737 $LFS hsm_archive $file
2738 wait_request_state $fid ARCHIVE SUCCEED
2739 check_hsm_flags $file "0x00000009"
2743 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2744 error "cannot hsm_remove '$fid'"
2746 # give time for CDT to handle remove request and create broadcasted
2749 # remove request has been broadcasted ?
2750 local cnt=$(get_request_count $fid REMOVE)
2751 # broadcasted requests + original
2752 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2753 error "remove not broadcasted to all CTs"
2755 # give time for CDT and CTs to handle broadcasted
2756 wait_for_loop_period
2758 # each agent serves one different archive_id, so broadcasted
2759 # hsm_remove request should only succeed once and fail at all others
2763 for n in $(seq $AGTCOUNT); do
2764 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2765 $HSM_PARAM.actions | awk \
2766 '/'$fid'.*action=REMOVE archive#='$n'/ \
2767 {print \\\$13}' | cut -f2 -d=")
2768 if [[ "$res" == "SUCCEED" ]]; then
2770 elif [[ "$res" == "FAILED" ]]; then
2775 [[ $scnt -eq 1 ]] ||
2776 error "one and only CT should have removed successfully"
2778 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2779 error "all but one CT should have failed to remove"
2781 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2782 "request to be sent once for each registered archive_id"
2785 # restore at exec cannot work on agent node (because of Linux kernel
2786 # protection of executables)
2787 needclients 2 || return 0
2789 # test needs a running copytool
2793 copy2archive /bin/true $tdir/$tfile
2795 local f=$DIR/$tdir/true
2796 import_file $tdir/$tfile $f
2798 local fid=$(path2fid $f)
2800 # set no retry action mode
2806 # remove no try action mode
2810 [[ $st == 0 ]] || error "Failed to exec a released file"
2814 run_test 30a "Restore at exec (import case)"
2817 # restore at exec cannot work on agent node (because of Linux kernel
2818 # protection of executables)
2819 needclients 2 || return 0
2821 # test needs a running copytool
2825 local f=$DIR/$tdir/true
2826 local fid=$(copy_file /bin/true $f)
2828 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2829 wait_request_state $fid ARCHIVE SUCCEED
2833 stack_trap cdt_clear_no_retry EXIT
2834 # set no retry action mode
2842 [[ $st == 0 ]] || error "Failed to exec a released file"
2844 run_test 30b "Restore at exec (release case)"
2847 needclients 2 || return 0
2849 # test needs a running copytool
2853 local f=$DIR/$tdir/SLEEP
2854 local slp_sum1=$(md5sum /bin/sleep)
2855 local fid=$(copy_file /bin/sleep $f)
2857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2858 wait_request_state $fid ARCHIVE SUCCEED
2860 check_hsm_flags $f "0x0000000d"
2862 stack_trap cdt_clear_no_retry EXIT
2863 # set no retry action mode
2866 do_node $CLIENT2 "$f 10" &
2870 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2872 [[ $? == 0 ]] || error "Execution failed during run"
2874 if [[ $? != 0 ]]; then
2875 local slp_sum2=$(md5sum /bin/sleep)
2876 # in case sleep file is modified during the test
2877 [[ $slp_sum1 == $slp_sum2 ]] &&
2878 error "Binary overwritten during exec"
2881 check_hsm_flags $f "0x00000009"
2883 run_test 30c "Update during exec of released file must fail"
2885 restore_and_check_size() {
2888 local s=$(stat -c "%s" $f)
2890 local st=$(get_hsm_flags $f)
2894 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2896 n=$(stat -c "%s" $f)
2897 # we echo in both cases to show stat is not hang
2898 if [[ $n != $s ]]; then
2899 echo "size seen is $n != $s"
2902 echo "size seen is right: $n == $s"
2906 st=$(get_hsm_flags $f)
2908 if [[ "$st" = "0x00000009" ]]; then
2911 echo " restore is too long"
2912 wait_request_state $fid RESTORE SUCCEED
2918 # test needs a running copytool
2921 create_archive_file $tdir/$tfile
2922 local f=$DIR/$tdir/$tfile
2923 import_file $tdir/$tfile $f
2924 local fid=$($LFS path2fid $f)
2925 HSM_ARCHIVE_PURGE=false copytool_setup
2927 restore_and_check_size $f $fid
2930 [[ $err -eq 0 ]] || error "File size changed during restore"
2934 run_test 31a "Import a large file and check size during restore"
2938 # test needs a running copytool
2941 local f=$DIR/$tdir/$tfile
2943 fid=$(make_custom_file_for_progress $f 39 1000000)
2944 [ $? != 0 ] && skip "not enough free space" && return
2946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2947 wait_request_state $fid ARCHIVE SUCCEED
2950 restore_and_check_size $f $fid
2953 [[ $err -eq 0 ]] || error "File size changed during restore"
2955 run_test 31b "Restore a large unaligned file and check size during restore"
2958 # test needs a running copytool
2961 local f=$DIR/$tdir/$tfile
2963 fid=$(make_custom_file_for_progress $f 33 1048576)
2964 [ $? != 0 ] && skip "not enough free space" && return
2966 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2967 wait_request_state $fid ARCHIVE SUCCEED
2970 restore_and_check_size $f $fid
2973 [[ $err -eq 0 ]] || error "File size changed during restore"
2975 run_test 31c "Restore a large aligned file and check size during restore"
2978 # test needs a running copytool
2981 local f=$DIR/$tdir/$tfile
2983 fid=$(make_custom_file_for_progress $f 39 1000000)
2984 [ $? != 0 ] && skip "not enough free space" && return
2986 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2987 wait_request_state $fid ARCHIVE SUCCEED
2990 # to be sure wait_all_done will not be mislead by previous tests
2993 wait_for_grace_delay
2994 # Also raise grace_delay significantly so the Canceled
2995 # Restore action will stay enough long avail.
2996 local old_grace=$(get_hsm_param grace_delay)
2997 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
2998 set_hsm_param grace_delay 100
3000 md5sum $f >/dev/null &
3002 wait_request_state $fid RESTORE STARTED
3007 # Check restore trigger process was killed
3008 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3012 # instead of waiting+checking both Restore and Cancel ops
3013 # sequentially, wait for both to be finished and then check
3015 wait_all_done 100 $fid
3016 local rstate=$(get_request_state $fid RESTORE)
3017 local cstate=$(get_request_state $fid CANCEL)
3019 if [[ "$rstate" == "CANCELED" ]] ; then
3020 [[ "$cstate" == "SUCCEED" ]] ||
3021 error "Restore state is CANCELED and Cancel state " \
3022 "is not SUCCEED but $cstate"
3023 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3024 elif [[ "$rstate" == "SUCCEED" ]] ; then
3025 [[ "$cstate" == "FAILED" ]] ||
3026 error "Restore state is SUCCEED and Cancel state " \
3027 "is not FAILED but $cstate"
3028 echo "Restore state is SUCCEED, Cancel state is FAILED"
3030 error "Restore state is $rstate and Cancel state is $cstate"
3034 error "Cannot kill process waiting for restore ($killed)"
3036 run_test 33 "Kill a restore waiting process"
3039 # test needs a running copytool
3042 local f=$DIR/$tdir/$tfile
3044 fid=$(make_custom_file_for_progress $f 39 1000000)
3045 [ $? != 0 ] && skip "not enough free space" && return
3047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3048 wait_request_state $fid ARCHIVE SUCCEED
3051 md5sum $f >/dev/null &
3053 wait_request_state $fid RESTORE STARTED
3055 rm $f || error "rm $f failed"
3056 # rm must not block during restore
3057 wait_request_state $fid RESTORE STARTED
3059 wait_request_state $fid RESTORE SUCCEED
3060 # check md5sum pgm finished
3061 local there=$(ps -o pid,comm hp $pid >/dev/null)
3062 [[ -z $there ]] || error "Restore initiator does not exit"
3064 wait $pid || error "Restore initiator failed with $?"
3066 run_test 34 "Remove file during restore"
3069 # test needs a running copytool
3072 local f=$DIR/$tdir/$tfile
3073 local f1=$DIR/$tdir/$tfile-1
3075 fid=$(make_custom_file_for_progress $f 39 1000000)
3076 [ $? != 0 ] && skip "not enough free space" && return
3078 local fid1=$(copy_file /etc/passwd $f1)
3079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3080 wait_request_state $fid ARCHIVE SUCCEED
3083 md5sum $f >/dev/null &
3085 wait_request_state $fid RESTORE STARTED
3087 mv $f1 $f || error "mv $f1 $f failed"
3088 # mv must not block during restore
3089 wait_request_state $fid RESTORE STARTED
3091 wait_request_state $fid RESTORE SUCCEED
3092 # check md5sum pgm finished
3093 local there=$(ps -o pid,comm hp $pid >/dev/null)
3094 [[ -z $there ]] || error "Restore initiator does not exit"
3096 wait $pid || error "Restore initiator failed with $?"
3099 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3101 run_test 35 "Overwrite file during restore"
3104 # test needs a running copytool
3107 local f=$DIR/$tdir/$tfile
3109 fid=$(make_custom_file_for_progress $f 39 1000000)
3110 [ $? != 0 ] && skip "not enough free space" && return
3112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3113 wait_request_state $fid ARCHIVE SUCCEED
3116 md5sum $f >/dev/null &
3118 wait_request_state $fid RESTORE STARTED
3121 # rm must not block during restore
3122 wait_request_state $fid RESTORE STARTED
3124 wait_request_state $fid RESTORE SUCCEED
3125 # check md5sum pgm finished
3126 local there=$(ps -o pid,comm hp $pid >/dev/null)
3128 error "Restore initiator does not exit"
3130 wait $pid || error "Restore initiator failed with $?"
3132 run_test 36 "Move file during restore"
3135 # LU-5683: check that an archived dirty file can be rearchived.
3138 local f=$DIR/$tdir/$tfile
3141 fid=$(create_small_file $f) || error "cannot create small file"
3143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3144 wait_request_state $fid ARCHIVE SUCCEED
3145 $LFS hsm_release $f || error "cannot release $f"
3147 # Allow previous archive request to expire from the actions log.
3148 wait_for_grace_delay
3151 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3153 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3154 wait_request_state $fid ARCHIVE SUCCEED
3156 run_test 37 "re-archive a dirty file"
3163 for n in $(seq 1 $count); do
3164 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3166 echo "$count archive requests submitted"
3170 local stream_count=4
3171 local file_count=100
3173 local f=$DIR/$tdir/$tfile
3177 local max_requests=$(get_hsm_param max_requests)
3179 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3180 # Increase the number of HSM request that can be performed in
3181 # parallel. With the coordinator running once per second, this
3182 # also limits the number of requests per seconds that can be
3183 # performed, so we pick a decent number. But we also need to keep
3184 # that number low because the copytool has no rate limit and will
3185 # fail some requests if if gets too many at once.
3186 set_hsm_param max_requests 300
3188 for i in $(seq 1 $file_count); do
3189 for p in $(seq 1 $stream_count); do
3190 fid=$(copy_file /etc/hosts $f.$p.$i)
3196 # to be sure wait_all_done will not be mislead by previous tests
3198 wait_for_grace_delay
3200 # start archive streams in background (archive files in parallel)
3201 for p in $(seq 1 $stream_count); do
3202 multi_archive $f.$p $file_count &
3205 echo -n "Wait for all requests being enqueued..."
3210 run_test 40 "Parallel archive requests"
3213 # test needs a running copytool
3217 local f=$DIR/$tdir/$tfile
3218 local fid=$(create_small_file $f)
3220 $LFS hsm_archive $f || error "could not archive file"
3221 wait_request_state $fid ARCHIVE SUCCEED
3222 check_hsm_flags $f "0x00000009"
3224 multiop_bg_pause $f O_c || error "multiop failed"
3228 client_up || client_up || true
3230 kill -USR1 $MULTIPID
3231 wait $MULTIPID || error "multiop close failed"
3233 check_hsm_flags $f "0x0000000b"
3235 run_test 52 "Opened for write file on an evicted client should be set dirty"
3238 # test needs a running copytool
3242 local f=$DIR/$tdir/$tfile
3243 local fid=$(create_small_file $f)
3245 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3246 error "could not archive file"
3247 wait_request_state $fid ARCHIVE SUCCEED
3248 check_hsm_flags $f "0x00000009"
3250 multiop_bg_pause $f o_c || error "multiop failed"
3254 client_up || client_up || true
3256 kill -USR1 $MULTIPID
3257 wait $MULTIPID || error "multiop close failed"
3259 check_hsm_flags $f "0x00000009"
3261 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3264 # test needs a running copytool
3267 local f=$DIR/$tdir/$tfile
3268 local fid=$(make_custom_file_for_progress $f 39 1000000)
3270 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3271 error "could not archive file"
3272 wait_request_state $fid ARCHIVE STARTED
3274 check_hsm_flags $f "0x00000001"
3276 stack_trap "cdt_clear_no_retry" EXIT
3277 # Avoid coordinator resending this request as soon it has failed.
3282 wait_request_state $fid ARCHIVE FAILED
3284 check_hsm_flags $f "0x00000003"
3286 run_test 54 "Write during an archive cancels it"
3289 # test needs a running copytool
3292 local f=$DIR/$tdir/$tfile
3293 local fid=$(make_custom_file_for_progress $f 39 1000000)
3295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3296 error "could not archive file"
3297 wait_request_state $fid ARCHIVE STARTED
3299 check_hsm_flags $f "0x00000001"
3301 stack_trap "cdt_clear_no_retry" EXIT
3302 # Avoid coordinator resending this request as soon it has failed.
3305 $TRUNCATE $f 1024 || error "truncate failed"
3307 wait_request_state $fid ARCHIVE FAILED
3309 check_hsm_flags $f "0x00000003"
3311 run_test 55 "Truncate during an archive cancels it"
3314 # test needs a running copytool
3317 local f=$DIR/$tdir/$tfile
3319 fid=$(make_custom_file_for_progress $f 39 1000000)
3320 [ $? != 0 ] && skip "not enough free space" && return
3322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3323 error "could not archive file"
3324 wait_request_state $fid ARCHIVE STARTED
3326 check_hsm_flags $f "0x00000001"
3328 # Change metadata and sync to be sure we are not changing only
3333 wait_request_state $fid ARCHIVE SUCCEED
3335 check_hsm_flags $f "0x00000009"
3337 run_test 56 "Setattr during an archive is ok"
3340 # Need one client for I/O, one for request
3341 needclients 2 || return 0
3343 # test needs a running copytool
3347 local f=$DIR/$tdir/test_archive_remote
3348 # Create a file on a remote node
3349 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3350 "count=2 conv=fsync"
3353 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3354 error "hsm_archive failed"
3355 local fid=$(path2fid $f)
3356 wait_request_state $fid ARCHIVE SUCCEED
3358 # Release and implicit restore it
3359 do_node $CLIENT2 "$LFS hsm_release $f" ||
3360 error "hsm_release failed"
3361 do_node $CLIENT2 "md5sum $f" ||
3362 error "hsm_restore failed"
3364 wait_request_state $fid RESTORE SUCCEED
3366 run_test 57 "Archive a file with dirty cache on another node"
3368 truncate_released_file() {
3372 local sz=$(stat -c %s $src_file)
3373 local f=$DIR/$tdir/$tfile
3374 local fid=$(copy_file $1 $f)
3378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3379 error "could not archive file"
3380 wait_request_state $fid ARCHIVE SUCCEED
3382 $LFS hsm_release $f || error "could not release file"
3384 $TRUNCATE $f $trunc_to || error "truncate failed"
3387 local sz1=$(stat -c %s $f)
3388 [[ $sz1 == $trunc_to ]] ||
3389 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3392 check_hsm_flags $f "0x0000000b"
3394 local state=$(get_request_state $fid RESTORE)
3395 [[ "$state" == "SUCCEED" ]] ||
3396 error "truncate $sz does not trig restore, state = $state"
3398 $TRUNCATE $ref $trunc_to
3399 cmp $ref $f || error "file data wrong after truncate"
3405 # test needs a running copytool
3410 local sz=$(stat -c %s /etc/passwd)
3412 echo "truncate up from $sz to $((sz*2))"
3413 truncate_released_file /etc/passwd $((sz*2))
3415 echo "truncate down from $sz to $((sz/2))"
3416 truncate_released_file /etc/passwd $((sz/2))
3418 echo "truncate to 0"
3419 truncate_released_file /etc/passwd 0
3421 run_test 58 "Truncate a released file will trigger restore"
3425 local server_version=$(lustre_version_code $SINGLEMDS)
3426 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3427 skip "Need MDS version at least 2.7.63" && return
3430 $MCREATE $DIR/$tfile || error "mcreate failed"
3431 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3432 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3433 fid=$(path2fid $DIR/$tfile)
3434 wait_request_state $fid ARCHIVE SUCCEED
3435 $LFS hsm_release $DIR/$tfile || error "release failed"
3437 run_test 59 "Release stripeless file with non-zero size"
3440 # This test validates the fix for LU-4512. Ensure that the -u
3441 # option changes the progress reporting interval from the
3442 # default (30 seconds) to the user-specified interval.
3444 local progress_timeout=$((interval * 4))
3446 copytool setup -b 1 --update-interval $interval
3448 local f=$DIR/$tdir/$tfile
3450 fid=$(make_custom_file_for_progress $f 10)
3451 [ $? != 0 ] && skip "not enough free space" && return
3454 local mdt=${MDT_PREFIX}${mdtidx}
3455 local mds=mds$((mdtidx + 1))
3457 # Wait for copytool to register
3458 wait_update_facet $mds \
3459 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3460 uuid 100 || error "coyptool failed to register with $mdt"
3462 local start_at=$(date +%s)
3463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3464 error "could not archive file"
3466 local agent=$(facet_active_host $SINGLEAGT)
3467 local logfile=$(copytool_logfile $SINGLEAGT)
3469 wait_update $agent \
3470 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3471 error "copytool failed to start"
3473 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3474 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3480 echo -n "Expecting a progress update within $progress_timeout seconds... "
3482 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3483 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3484 echo "$RESULT bytes copied in $WAIT seconds."
3486 elif [ $WAIT -ge $progress_timeout ]; then
3487 error "Timed out waiting for progress update!"
3490 WAIT=$((WAIT + sleep))
3494 local finish_at=$(date +%s)
3495 local elapsed=$((finish_at - start_at))
3497 # Ensure that the progress update occurred within the expected window.
3498 if [ $elapsed -lt $((interval - 1)) ]; then
3499 error "Expected progress update after at least $interval seconds"
3502 echo "Wait for on going archive hsm action to complete"
3503 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3504 echo "File archiving not completed even after 10 secs"
3506 run_test 60 "Changing progress update interval from default"
3509 # test needs a running copytool
3513 local f=$DIR/$tdir/$tfile
3514 local fid=$(copy_file /etc/passwd $f)
3516 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3519 wait_request_state $fid ARCHIVE FAILED
3521 run_test 61 "Waiting archive of a removed file should fail"
3524 # test needs a new running copytool
3525 stack_trap copytool_monitor_cleanup EXIT
3526 copytool_monitor_setup
3527 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3529 # Wait for the copytool to register.
3530 wait_update --verbose $(facet_active_host mds1) \
3531 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3533 error "copytool failed to register with MDT0000"
3536 wait_copytools || error "Copytools failed to stop"
3538 local REGISTER_EVENT
3539 local UNREGISTER_EVENT
3540 while read event; do
3541 local parsed=$(parse_json_event "$event")
3542 if [ -z "$parsed" ]; then
3543 error "Copytool sent malformed event: $event"
3547 if [ $event_type == "REGISTER" ]; then
3548 REGISTER_EVENT=$event
3549 elif [ $event_type == "UNREGISTER" ]; then
3550 UNREGISTER_EVENT=$event
3552 done < <(echo $"$(get_copytool_event_log)")
3554 if [ -z "$REGISTER_EVENT" ]; then
3555 error "Copytool failed to send register event to FIFO"
3558 if [ -z "$UNREGISTER_EVENT" ]; then
3559 error "Copytool failed to send unregister event to FIFO"
3562 echo "Register/Unregister events look OK."
3564 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3567 # Bump progress interval for livelier events.
3570 # test needs a new running copytool
3571 stack_trap copytool_monitor_cleanup EXIT
3572 copytool_monitor_setup
3573 copytool setup --update-interval $interval --event-fifo \
3574 "$HSMTOOL_MONITOR_DIR/fifo"
3576 stack_trap "cdt_clear_no_retry" EXIT
3577 # Just start and stop the copytool to generate events.
3580 local f=$DIR/$tdir/$tfile
3582 fid=$(make_custom_file_for_progress $f 39 1000000)
3583 [ $? != 0 ] && skip "not enough free space" && return
3585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3586 error "could not archive file"
3587 wait_request_state $fid ARCHIVE SUCCEED
3589 local expected_fields="event_time data_fid source_fid"
3590 expected_fields+=" total_bytes current_bytes"
3594 while read event; do
3595 # Make sure we're not getting anything from previous events.
3596 for field in $expected_fields; do
3600 local parsed=$(parse_json_event "$event")
3601 if [ -z "$parsed" ]; then
3602 error "Copytool sent malformed event: $event"
3606 if [ $event_type == "ARCHIVE_START" ]; then
3609 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3612 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3616 # Do some simple checking of the progress update events.
3617 for expected_field in $expected_fields; do
3618 if [ -z ${!expected_field+x} ]; then
3619 error "Missing $expected_field field in event"
3623 if [ $total_bytes -eq 0 ]; then
3624 error "Expected total_bytes to be > 0"
3627 # These should be identical throughout an archive
3629 if [ $source_fid != $data_fid ]; then
3630 error "Expected source_fid to equal data_fid"
3632 done < <(echo $"$(get_copytool_event_log)")
3634 if [ -z "$START_EVENT" ]; then
3635 error "Copytool failed to send archive start event to FIFO"
3638 if [ -z "$FINISH_EVENT" ]; then
3639 error "Copytool failed to send archive finish event to FIFO"
3642 echo "Archive events look OK."
3644 run_test 71 "Copytool logs JSON archive events to FIFO"
3647 # Bump progress interval for livelier events.
3650 # test needs a new running copytool
3652 copytool_monitor_setup
3653 HSMTOOL_UPDATE_INTERVAL=$interval \
3654 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3655 local test_file=$HSMTOOL_MONITOR_DIR/file
3657 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3659 do_facet $SINGLEAGT "$cmd" ||
3660 error "cannot create $test_file on $SINGLEAGT"
3661 copy2archive $test_file $tdir/$tfile
3664 local f=$DIR/$tdir/$tfile
3665 import_file $tdir/$tfile $f
3666 f=$DIR2/$tdir/$tfile
3667 echo "Verifying released state: "
3668 check_hsm_flags $f "0x0000000d"
3670 local fid=$(path2fid $f)
3672 wait_request_state $fid RESTORE SUCCEED
3674 local expected_fields="event_time data_fid source_fid"
3675 expected_fields+=" total_bytes current_bytes"
3679 while read event; do
3680 # Make sure we're not getting anything from previous events.
3681 for field in $expected_fields; do
3685 local parsed=$(parse_json_event "$event")
3686 if [ -z "$parsed" ]; then
3687 error "Copytool sent malformed event: $event"
3691 if [ $event_type == "RESTORE_START" ]; then
3693 if [ $source_fid != $data_fid ]; then
3694 error "source_fid should == data_fid at start"
3697 elif [ $event_type == "RESTORE_FINISH" ]; then
3699 if [ $source_fid != $data_fid ]; then
3700 error "source_fid should == data_fid at finish"
3703 elif [ $event_type != "RESTORE_RUNNING" ]; then
3707 # Do some simple checking of the progress update events.
3708 for expected_field in $expected_fields; do
3709 if [ -z ${!expected_field+x} ]; then
3710 error "Missing $expected_field field in event"
3714 if [ $total_bytes -eq 0 ]; then
3715 error "Expected total_bytes to be > 0"
3718 # When a restore starts out, the data fid is the same as the
3719 # source fid. After the restore has gotten going, we learn
3720 # the new data fid. Once the restore has finished, the source
3721 # fid is set to the new data fid.
3723 # We test this because some monitoring software may depend on
3724 # this behavior. If it changes, then the consumers of these
3725 # events may need to be modified.
3726 if [ $source_fid == $data_fid ]; then
3727 error "source_fid should != data_fid during restore"
3729 done < <(echo $"$(get_copytool_event_log)")
3731 if [ -z "$START_EVENT" ]; then
3732 error "Copytool failed to send restore start event to FIFO"
3735 if [ -z "$FINISH_EVENT" ]; then
3736 error "Copytool failed to send restore finish event to FIFO"
3739 echo "Restore events look OK."
3743 copytool_monitor_cleanup
3747 run_test 72 "Copytool logs JSON restore events to FIFO"
3750 file_count=51 # Max number of files constrained by LNET message size
3751 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3752 local f=$DIR/$tdir/$tfile
3753 local FILELIST=/tmp/filelist.txt
3757 for i in $(seq 1 $file_count); do
3758 fid=$(copy_file /etc/hosts $f.$i)
3759 echo $f.$i >> $FILELIST
3763 # to be sure wait_all_done will not be mislead by previous tests
3765 wait_for_grace_delay
3766 $LFS hsm_archive --filelist $FILELIST ||
3767 error "cannot archive a file list"
3769 $LFS hsm_release --filelist $FILELIST ||
3770 error "cannot release a file list"
3771 $LFS hsm_restore --filelist $FILELIST ||
3772 error "cannot restore a file list"
3775 run_test 90 "Archive/restore a file list"
3777 double_verify_reset_hsm_param() {
3779 echo "Testing $HSM_PARAM.$p"
3780 local val=$(get_hsm_param $p)
3782 local val2=$(($val * 2))
3783 set_hsm_param $p $val2
3784 val=$(get_hsm_param $p)
3785 [[ $val == $val2 ]] ||
3786 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3787 echo "Set $p to 0 must failed"
3791 set_hsm_param $p $save
3793 if [[ $rc == 0 ]]; then
3794 error "we must not be able to set $HSM_PARAM.$p to 0"
3799 double_verify_reset_hsm_param loop_period
3800 double_verify_reset_hsm_param grace_delay
3801 double_verify_reset_hsm_param active_request_timeout
3802 double_verify_reset_hsm_param max_requests
3803 double_verify_reset_hsm_param default_archive_id
3805 run_test 100 "Set coordinator /proc tunables"
3812 run_test 102 "Verify coordinator control"
3815 # test needs a running copytool
3822 for i in $(seq 1 20); do
3823 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3829 echo "Current requests"
3830 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3831 $HSM_PARAM.actions |\
3832 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3834 [[ -z "$res" ]] || error "Some request have not been canceled"
3836 run_test 103 "Purge all requests"
3841 local f=$DIR/$tdir/$tfile
3843 fid=$(make_custom_file_for_progress $f 39 1000000)
3844 [ $? != 0 ] && skip "not enough free space" && return
3846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3847 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3848 $HSM_PARAM.actions |\
3849 grep $fid | cut -f16 -d=")
3851 [[ "$data1" == "$DATAHEX" ]] ||
3852 error "Data field in records is ($data1) and not ($DATAHEX)"
3857 wait_request_state $fid ARCHIVE SUCCEED
3859 run_test 104 "Copy tool data field"
3862 local max_requests=$(get_hsm_param max_requests)
3866 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3867 set_hsm_param max_requests 300
3870 for i in $(seq -w 1 10); do
3871 cp /etc/passwd $DIR/$tdir/$i
3872 $LFS hsm_archive $DIR/$tdir/$i
3874 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3875 $HSM_PARAM.actions |\
3876 grep WAITING | wc -l")
3880 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3881 $HSM_PARAM.actions |\
3882 grep WAITING | wc -l")
3885 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3886 error "Requests count after shutdown $reqcnt2 != "\
3887 "before shutdown $reqcnt1"
3889 run_test 105 "Restart of coordinator"
3892 # test needs a running copytool
3895 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3897 check_agent_registered $uuid
3899 search_copytools || error "No copytool found"
3902 wait_copytools || error "Copytool failed to stop"
3904 check_agent_unregistered $uuid
3907 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3908 check_agent_registered $uuid
3910 run_test 106 "Copytool register/unregister"
3913 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3915 # test needs a running copytool
3917 # create and archive file
3919 local f1=$DIR/$tdir/$tfile
3920 local fid=$(copy_file /etc/passwd $f1)
3921 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3922 wait_request_state $fid ARCHIVE SUCCEED
3923 # shutdown and restart MDS
3925 # check the copytool still gets messages from MDT
3926 local f2=$DIR/$tdir/2
3927 local fid=$(copy_file /etc/passwd $f2)
3928 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3929 # main check of this sanity: this request MUST succeed
3930 wait_request_state $fid ARCHIVE SUCCEED
3932 run_test 107 "Copytool re-register after MDS restart"
3934 policy_set_and_test()
3938 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3939 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3940 [[ "$policy" == "$target" ]] ||
3941 error "Wrong policy after '$change': '$policy' != '$target'"
3945 # to force default policy setting if error
3946 CDT_POLICY_HAD_CHANGED=true
3948 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3949 local default="NonBlockingRestore [NoRetryAction]"
3950 [[ "$policy" == "$default" ]] ||
3951 error "default policy has changed,"\
3952 " '$policy' != '$default' update the test"
3953 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3954 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3955 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3956 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3957 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3958 # useless bacause we know but safer for futur changes to use real value
3959 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3960 echo "Next set_param must failed"
3961 policy_set_and_test "wrong" "$policy"
3964 echo "Back to default policy"
3965 cdt_set_sanity_policy
3967 run_test 109 "Policy display/change"
3970 # test needs a running copytool
3975 copy2archive /etc/passwd $tdir/$tfile
3977 local f=$DIR/$tdir/$tfile
3978 import_file $tdir/$tfile $f
3979 local fid=$(path2fid $f)
3981 cdt_set_non_blocking_restore
3986 wait_request_state $fid RESTORE SUCCEED
3987 cdt_clear_non_blocking_restore
3991 error "md5sum returns $st != 1, "\
3992 "should also perror ENODATA (No data available)"
3994 run_test 110a "Non blocking restore policy (import case)"
3997 # test needs a running copytool
4001 local f=$DIR/$tdir/$tfile
4002 local fid=$(copy_file /etc/passwd $f)
4003 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4004 wait_request_state $fid ARCHIVE SUCCEED
4007 cdt_set_non_blocking_restore
4012 wait_request_state $fid RESTORE SUCCEED
4013 cdt_clear_non_blocking_restore
4017 error "md5sum returns $st != 1, "\
4018 "should also perror ENODATA (No data available)"
4020 run_test 110b "Non blocking restore policy (release case)"
4023 # test needs a running copytool
4027 copy2archive /etc/passwd $tdir/$tfile
4029 local f=$DIR/$tdir/$tfile
4031 import_file $tdir/$tfile $f
4032 local fid=$(path2fid $f)
4036 copytool_remove_backend $fid
4039 wait_request_state $fid RESTORE FAILED
4046 [[ $st == 0 ]] || error "Restore does not failed"
4050 run_test 111a "No retry policy (import case), restore will error"\
4051 " (No such file or directory)"
4054 # test needs a running copytool
4058 local f=$DIR/$tdir/$tfile
4059 local fid=$(copy_file /etc/passwd $f)
4061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4062 wait_request_state $fid ARCHIVE SUCCEED
4065 copytool_remove_backend $fid
4068 wait_request_state $fid RESTORE FAILED
4075 [[ $st == 0 ]] || error "Restore does not failed"
4079 run_test 111b "No retry policy (release case), restore will error"\
4080 " (No such file or directory)"
4083 # test needs a running copytool
4087 local f=$DIR/$tdir/$tfile
4088 local fid=$(copy_file /etc/passwd $f)
4090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4091 local l=$($LFS hsm_action $f)
4093 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4096 wait_request_state $fid ARCHIVE SUCCEED
4099 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4101 run_test 112 "State of recorded request"
4104 # test needs a running copytool
4107 local f=$DIR/$tdir/$tfile
4109 fid=$(make_custom_file_for_progress $f 103 1048576)
4110 [ $? != 0 ] && skip "not enough free space" && return
4112 # test with cdt on is made in test_221
4114 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4115 # wait archive to register at CDT
4116 wait_request_state $fid ARCHIVE WAITING
4119 wait_request_state $fid ARCHIVE CANCELED
4120 wait_request_state $fid CANCEL SUCCEED
4122 run_test 200 "Register/Cancel archive"
4125 # test needs a running copytool
4128 local f=$DIR/$tdir/$tfile
4129 create_archive_file $tdir/$tfile
4130 import_file $tdir/$tfile $f
4131 local fid=$(path2fid $f)
4133 # test with cdt on is made in test_222
4136 # wait restore to register at CDT
4137 wait_request_state $fid RESTORE WAITING
4140 wait_request_state $fid RESTORE CANCELED
4141 wait_request_state $fid CANCEL SUCCEED
4145 run_test 201 "Register/Cancel restore"
4148 # test needs a running copytool
4151 local f=$DIR/$tdir/$tfile
4153 fid=$(make_custom_file_for_progress $f 39 1000000)
4154 [ $? != 0 ] && skip "not enough free space" && return
4156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4157 wait_request_state $fid ARCHIVE SUCCEED
4161 # wait remove to register at CDT
4162 wait_request_state $fid REMOVE WAITING
4165 wait_request_state $fid REMOVE CANCELED
4167 run_test 202 "Register/Cancel remove"
4169 test_220A() { # was test_220
4170 # test needs a running copytool
4175 local f=$DIR/$tdir/$tfile
4176 local fid=$(copy_file /etc/passwd $f)
4180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4181 wait_request_state $fid ARCHIVE SUCCEED
4183 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4184 error "The expected changelog was not emitted"
4186 run_test 220A "Changelog for archive"
4189 # test needs a running copytool
4194 local f=$DIR/$tdir/$tfile
4195 local fid=$(copy_file /etc/passwd $f)
4199 # block copytool operations to allow for HSM request to be
4200 # submitted and file be unlinked (CDT will find object removed)
4203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4205 # wait request to reach CT
4206 wait_request_state $fid ARCHIVE STARTED
4212 wait_request_state $fid ARCHIVE FAILED
4215 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4216 error "The expected changelog was not emitted"
4218 run_test 220a "Changelog for failed archive"
4221 # test needs a running copytool
4224 local f=$DIR/$tdir/$tfile
4226 fid=$(make_custom_file_for_progress $f 103 1048576)
4227 [ $? != 0 ] && skip "not enough free space" && return
4231 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4232 wait_request_state $fid ARCHIVE STARTED
4234 wait_request_state $fid ARCHIVE CANCELED
4235 wait_request_state $fid CANCEL SUCCEED
4237 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4238 error "The expected changelog was not emitted"
4240 run_test 221 "Changelog for archive canceled"
4243 # test needs a running copytool
4247 copy2archive /etc/passwd $tdir/$tfile
4249 local f=$DIR/$tdir/$tfile
4250 import_file $tdir/$tfile $f
4251 local fid=$(path2fid $f)
4256 wait_request_state $fid RESTORE SUCCEED
4258 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4259 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"
4317 run_test 222c "Changelog for failed explicit restore"
4320 # test needs a running copytool
4324 local f=$DIR/$tdir/$tfile
4325 local fid=$(copy_file /etc/passwd $f)
4328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4329 wait_request_state $fid ARCHIVE SUCCEED
4332 copytool_remove_backend $fid
4335 wait_request_state $fid RESTORE FAILED
4338 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4339 error "The expected changelog was not emitted"
4341 run_test 222d "Changelog for failed implicit restore"
4344 # test needs a running copytool
4347 local f=$DIR/$tdir/$tfile
4348 create_archive_file $tdir/$tfile
4352 import_file $tdir/$tfile $f
4353 local fid=$(path2fid $f)
4356 wait_request_state $fid RESTORE STARTED
4358 wait_request_state $fid RESTORE CANCELED
4359 wait_request_state $fid CANCEL SUCCEED
4361 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4362 error "The expected changelog was not emitted"
4364 run_test 223a "Changelog for restore canceled (import case)"
4367 # test needs a running copytool
4370 local f=$DIR/$tdir/$tfile
4372 fid=$(make_custom_file_for_progress $f 39 1000000)
4373 [ $? != 0 ] && skip "not enough free space" && return
4376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4377 wait_request_state $fid ARCHIVE SUCCEED
4380 wait_request_state $fid RESTORE STARTED
4382 wait_request_state $fid RESTORE CANCELED
4383 wait_request_state $fid CANCEL SUCCEED
4385 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4386 error "The expected changelog was not emitted"
4388 run_test 223b "Changelog for restore canceled (release case)"
4390 test_224A() { # was test_224
4391 # test needs a running copytool
4396 local f=$DIR/$tdir/$tfile
4397 local fid=$(copy_file /etc/passwd $f)
4400 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4401 wait_request_state $fid ARCHIVE SUCCEED
4404 wait_request_state $fid REMOVE SUCCEED
4406 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4407 error "The expected changelog was not emitted"
4409 run_test 224A "Changelog for remove"
4412 # test needs a running copytool
4417 local f=$DIR/$tdir/$tfile
4418 local fid=$(copy_file /etc/passwd $f)
4421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4422 wait_request_state $fid ARCHIVE SUCCEED
4424 copytool_remove_backend $fid
4426 # block copytool operations to allow for HSM request to be
4427 # submitted and file be unlinked (CDT will find object removed)
4432 # wait for request to reach CT
4433 wait_request_state $fid REMOVE STARTED
4439 wait_request_state $fid REMOVE FAILED
4441 # HE_REMOVE|ENOENT=0x202
4442 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4443 error "The expected changelog was not emitted"
4445 run_test 224a "Changelog for failed remove"
4448 # test needs a running copytool
4451 # test is not usable because remove request is too fast
4452 # so it is always finished before cancel can be done ...
4453 echo "Test disabled"
4457 local f=$DIR/$tdir/$tfile
4459 fid=$(make_custom_file_for_progress $f 39 1000000)
4460 [ $? != 0 ] && skip "not enough free space" && return
4463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4464 wait_request_state $fid ARCHIVE SUCCEED
4466 # if cdt is on, it can serve too quickly the request
4471 wait_request_state $fid REMOVE CANCELED
4472 wait_request_state $fid CANCEL SUCCEED
4474 changelog_find -type HSM -target-fid $fid -flags 0x27d
4475 error "The expected changelog was not emitted"
4477 run_test 225 "Changelog for remove canceled"
4480 # test needs a running copytool
4485 local f1=$DIR/$tdir/$tfile-1
4486 local f2=$DIR/$tdir/$tfile-2
4487 local f3=$DIR/$tdir/$tfile-3
4488 local fid1=$(copy_file /etc/passwd $f1)
4489 local fid2=$(copy_file /etc/passwd $f2)
4490 copy_file /etc/passwd $f3
4493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4494 wait_request_state $fid1 ARCHIVE SUCCEED
4496 $LFS hsm_archive $f2
4497 wait_request_state $fid2 ARCHIVE SUCCEED
4499 rm $f1 || error "rm $f1 failed"
4502 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4503 error "The expected changelog was not emitted"
4505 mv $f3 $f2 || error "mv $f3 $f2 failed"
4507 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4508 error "The expected changelog was not emitted"
4510 run_test 226 "changelog for last rm/mv with exiting archive"
4512 # This is just a utility function to clarify what test_227 does
4517 "$LFS" "$action" --$flag "$file" ||
4518 error "Cannot ${action#hsm_} $flag on '$file'"
4520 # Only one changelog should be produced
4521 local entries="$(changelog_find -type HSM -target-fid $fid)"
4522 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4523 error "lfs $action --$flag '$file' produced more than one" \
4526 # Parse the last changelog record
4527 local entry="$(tail -n 1 <<< "$entries")"
4528 eval local -A changelog=$(changelog2array $entry)
4530 # Also check the flags match what is expected
4531 [[ ${changelog[flags]} == $target ]] ||
4532 error "Changelog flag is '${changelog[flags]}', not $target"
4536 local file="$DIR/$tdir/$tfile"
4537 local fid=$(create_empty_file "$file")
4542 for flag in norelease noarchive exists archived lost; do
4543 if [ "$flag" == lost ]; then
4544 # The flag "lost" only works on an archived file
4545 "$LFS" hsm_set --archived "$file"
4549 action="hsm_set" __test_227
4550 action="hsm_clear" __test_227
4553 run_test 227 "changelog when explicit setting of HSM flags"
4556 # test needs a running copytool
4559 local fid=$(create_small_sync_file $DIR/$tfile)
4560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4561 wait_request_state $fid ARCHIVE SUCCEED
4563 $LFS hsm_release $DIR/$tfile
4564 check_hsm_flags $DIR/$tfile "0x0000000d"
4566 filefrag $DIR/$tfile | grep " 1 extent found" ||
4567 error "filefrag on released file must return only one extent"
4569 # only newer versions of cp detect sparse files by stat/FIEMAP
4571 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4572 error "copying $DIR/$tfile"
4573 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4575 $LFS hsm_release $DIR/$tfile
4576 check_hsm_flags $DIR/$tfile "0x0000000d"
4578 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4580 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4582 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4583 error "comparing untarred $DIR/$tfile"
4585 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4586 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4588 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4591 # test needs a running copytool
4595 local maxrequest=$(get_hsm_param max_requests)
4596 local rqcnt=$(($maxrequest * 3))
4600 for i in $(seq -w 1 $rqcnt); do
4602 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4604 # we do it in 2 steps, so all requests arrive at the same time
4605 for i in $(seq -w 1 $rqcnt); do
4606 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4611 while [[ $cnt != 0 || $wt != 0 ]]; do
4613 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4614 $HSM_PARAM.actions |\
4615 grep STARTED | grep -v CANCEL | wc -l")
4616 [[ $cnt -le $maxrequest ]] ||
4617 error "$cnt > $maxrequest too many started requests"
4618 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4619 $HSM_PARAM.actions |\
4620 grep WAITING | wc -l")
4621 echo "max=$maxrequest started=$cnt waiting=$wt"
4624 run_test 250 "Coordinator max request"
4627 # test needs a running copytool
4630 local f=$DIR/$tdir/$tfile
4632 fid=$(make_custom_file_for_progress $f 103 1048576)
4633 [ $? != 0 ] && skip "not enough free space" && return
4636 # to have a short test
4637 local old_to=$(get_hsm_param active_request_timeout)
4638 set_hsm_param active_request_timeout 4
4639 # to be sure the cdt will wake up frequently so
4640 # it will be able to cancel the "old" request
4641 local old_loop=$(get_hsm_param loop_period)
4642 set_hsm_param loop_period 2
4645 # clear locks to avoid extra delay caused by flush/cancel
4646 # and thus prevent early copytool death to timeout.
4647 cancel_lru_locks osc
4649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4650 wait_request_state $fid ARCHIVE STARTED
4652 wait_request_state $fid ARCHIVE CANCELED
4654 set_hsm_param active_request_timeout $old_to
4655 set_hsm_param loop_period $old_loop
4657 run_test 251 "Coordinator request timeout"
4661 local f=$DIR/$tdir/$tfile
4662 local fid=$(create_empty_file "$f")
4664 # to have a short test
4665 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4666 set_hsm_param loop_period 1
4671 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4672 wait_request_state $fid ARCHIVE STARTED
4675 stack_trap "set_hsm_param active_request_timeout \
4676 $(get_hsm_param active_request_timeout)" EXIT
4677 set_hsm_param active_request_timeout 1
4679 wait_request_state $fid ARCHIVE CANCELED
4682 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4686 # test needs a running copytool
4690 local f=$DIR/$tdir/$tfile
4692 dd if=/dev/zero of=$f bs=1MB count=10
4693 local fid=$(path2fid $f)
4695 $LFS hsm_archive $f || error "could not archive file"
4696 wait_request_state $fid ARCHIVE SUCCEED
4698 # clear locks to discard inode data
4699 cancel_lru_locks osc
4701 #define OBD_FAIL_MDC_MERGE 0x807
4702 $LCTL set_param fail_loc=0x807
4704 #expect error here, instead of release with wrong size
4707 if ((rc == 0)); then
4708 file_size=$(stat -c '%s' $f)
4709 if ((file_size != 10485760)); then
4710 error "Wrong file size after hsm_release"
4713 echo "could not release file"
4716 run_test 253 "Check for wrong file size after release"
4720 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4721 skip "need MDS version at least 2.10.56" && return
4723 # Check that the counters are initialized to 0
4725 for request_type in archive restore remove; do
4726 count="$(get_hsm_param ${request_type}_count)" ||
4727 error "Reading ${request_type}_count failed with $?"
4729 [ "$count" -eq 0 ] ||
4730 error "Expected ${request_type}_count to be " \
4734 run_test 254a "Request counters are initialized to zero"
4738 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4739 skip "need MDS version at least 2.10.56" && return
4741 # The number of request to launch (at least 32)
4742 local request_count=$((RANDOM % 32 + 32))
4743 printf "Will launch %i requests of each type\n" "$request_count"
4745 # Launch a copytool to process requests
4748 # Set hsm.max_requests to allow starting all requests at the same time
4750 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4751 set_hsm_param max_requests "$request_count"
4755 for request_type in archive restore remove; do
4756 printf "Checking %s requests\n" "${request_type}"
4757 # Suspend the copytool to give us time to read the proc files
4760 for ((i = 0; i < $request_count; i++)); do
4761 case $request_type in
4763 create_empty_file "$DIR/$tdir/$tfile-$i" \
4767 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4770 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4773 # Give the coordinator 10 seconds to start every request
4775 while get_hsm_param actions | grep -q WAITING; do
4778 [ $timeout -gt 0 ] ||
4779 error "${request_type^} requests took too " \
4783 count="$(get_hsm_param ${request_type}_count)"
4784 [ "$count" -eq "$request_count" ] ||
4785 error "Expected '$request_count' (!= '$count') " \
4786 "active $request_type requests"
4788 # Let the copytool process the requests
4790 # Give it 10 seconds maximum
4792 while get_hsm_param actions | grep -q STARTED; do
4795 [ $timeout -gt 0 ] ||
4796 error "${request_type^} requests took too " \
4800 count="$(get_hsm_param ${request_type}_count)"
4801 [ "$count" -eq 0 ] ||
4802 error "Expected 0 (!= '$count') " \
4803 "active $request_type requests"
4806 run_test 254b "Request counters are correctly incremented and decremented"
4809 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4811 # the only way to test ondisk conf is to restart MDS ...
4812 echo "Stop coordinator and remove coordinator state at mount"
4815 # clean on disk conf set by default
4816 cdt_clear_mount_state
4817 cdt_check_state stopped
4819 # check cdt still off after umount/remount
4821 cdt_check_state stopped
4823 echo "Set coordinator start at mount, and start coordinator"
4824 cdt_set_mount_state enabled
4827 cdt_check_state enabled
4829 # check cdt still on after umount/remount
4831 cdt_check_state enabled
4833 # we are back to original state (cdt started at mount)
4835 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4838 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4840 local ai=$(get_hsm_param default_archive_id)
4841 local new=$((ai + 1))
4843 set_hsm_param default_archive_id $new -P
4845 local res=$(get_hsm_param default_archive_id)
4848 set_hsm_param default_archive_id "" "-P -d"
4850 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4852 run_test 301 "HSM tunnable are persistent"
4855 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4857 local ai=$(get_hsm_param default_archive_id)
4858 local new=$((ai + 1))
4863 set_hsm_param default_archive_id $new -P
4866 for mdtno in $(seq 1 $MDSCOUNT); do
4871 cdt_check_state enabled
4873 local res=$(get_hsm_param default_archive_id)
4876 set_hsm_param default_archive_id "" "-P -d"
4878 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4880 run_test 302 "HSM tunnable are persistent when CDT is off"
4883 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4889 local dir_mdt0=$DIR/$tdir/mdt0
4890 local dir_mdt1=$DIR/$tdir/mdt1
4892 # create 1 dir per MDT
4893 stack_trap "rm -rf $dir_mdt0"
4894 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4895 stack_trap "rm -rf $dir_mdt1"
4896 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4898 # create 1 file in each MDT
4899 local fid1=$(create_small_file $dir_mdt0/$tfile)
4900 local fid2=$(create_small_file $dir_mdt1/$tfile)
4902 # check that hsm request on mdt0 is sent to the right MDS
4903 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4904 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4905 echo "archive successful on mdt0"
4907 # check that hsm request on mdt1 is sent to the right MDS
4908 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4909 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4910 echo "archive successful on mdt1"
4912 run_test 400 "Single request is sent to the right MDT"
4915 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4921 local dir_mdt0=$DIR/$tdir/mdt0
4922 local dir_mdt1=$DIR/$tdir/mdt1
4924 # create 1 dir per MDT
4925 stack_trap "rm -rf $dir_mdt0" EXIT
4926 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4927 stack_trap "rm -rf $dir_mdt1" EXIT
4928 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4930 # create 1 file in each MDT
4931 local fid1=$(create_small_file $dir_mdt0/$tfile)
4932 local fid2=$(create_small_file $dir_mdt1/$tfile)
4934 # check that compound requests are shunt to the rights MDTs
4935 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4936 error "lfs hsm_archive"
4937 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4938 echo "archive successful on mdt0"
4939 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4940 echo "archive successful on mdt1"
4942 run_test 401 "Compound requests split and sent to their respective MDTs"
4944 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4949 local node=$(facet_active_host $facet)
4951 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4952 awk '{print $4}'); do
4953 echo "$3 $mdc on $node"
4954 do_facet $facet "$LCTL --device $mdc $state" || return 1
4959 # deactivate all mdc on agent1
4960 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4962 copytool setup --no-fail
4964 check_agent_unregistered "uuid" # match any agent
4966 # no expected running copytool
4967 search_copytools $agent && error "Copytool start should have failed"
4970 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4972 run_test 402a "Copytool start fails if all MDTs are inactive"
4979 local f=$DIR/$tdir/$tfile
4980 touch $f || error "touch $f failed"
4981 local fid=$(path2fid $f)
4983 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4984 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4987 # give time for CDT to send request and to keep it for retry
4988 wait_for_loop_period
4990 wait_request_state $fid ARCHIVE WAITING
4992 do_facet $SINGLEAGT lctl set_param fail_loc=0
4994 # request should succeed now
4995 wait_request_state $fid ARCHIVE SUCCEED
4997 run_test 402b "CDT must retry request upon slow start of CT"
5000 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5002 local agent=$(facet_active_host $SINGLEAGT)
5004 # deactivate all mdc for MDT0001
5005 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5008 local uuid=$(get_agent_uuid $agent)
5009 # check the agent is registered on MDT0000, and not on MDT0001
5010 check_agent_registered_by_mdt $uuid 0
5011 check_agent_unregistered_by_mdt $uuid 1
5013 # check running copytool process
5014 search_copytools $agent || error "No running copytools on $agent"
5016 # reactivate all mdc for MDT0001
5017 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5019 # make sure the copytool is now registered to all MDTs
5020 check_agent_registered $uuid
5022 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5025 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5029 # create files on both MDT0000 and MDT0001
5032 local dir_mdt0=$DIR/$tdir/mdt0
5033 stack_trap "rm -rf $dir_mdt0" EXIT
5034 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5036 # create 1 file on mdt0
5037 local fid1=$(create_small_file $dir_mdt0/$tfile)
5039 # deactivate all mdc for MDT0001
5040 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5042 # send an HSM request for files in MDT0000
5043 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5045 # check for completion of files in MDT0000
5046 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5047 echo "archive successful on mdt0"
5049 # reactivate all mdc for MDT0001
5050 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5052 run_test 404 "Inactive MDT does not block requests for active MDTs"
5055 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5061 local striped_dir=$DIR/$tdir/striped_dir
5063 # create striped dir on all of MDTs
5064 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5066 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5067 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5068 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5069 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5071 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5072 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5073 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5074 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5076 # check that compound requests are shunt to the rights MDTs
5077 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5078 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5079 error "lfs hsm_archive"
5081 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5082 echo "archive successful on $fid1"
5083 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5084 echo "archive successful on $fid2"
5085 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5086 echo "archive successful on $fid3"
5087 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5088 echo "archive successful on $fid4"
5090 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5091 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5092 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5093 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5095 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5096 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5097 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5098 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5100 run_test 405 "archive and release under striped directory"
5103 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5105 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5106 skip "need MDS version at least 2.7.64" && return 0
5111 fid=$(create_small_file $DIR/$tdir/$tfile)
5116 $LFS hsm_archive $DIR/$tdir/$tfile
5117 wait_request_state "$fid" ARCHIVE SUCCEED
5118 $LFS hsm_release $DIR/$tdir/$tfile
5120 # Should migrate $tdir but not $tfile.
5121 $LFS migrate -m1 $DIR/$tdir &&
5122 error "migrating HSM an archived file should fail"
5124 $LFS hsm_restore $DIR/$tdir/$tfile
5125 wait_request_state "$fid" RESTORE SUCCEED
5127 $LFS hsm_remove $DIR/$tdir/$tfile
5128 wait_request_state "$fid" REMOVE SUCCEED
5130 cat $DIR/$tdir/$tfile > /dev/null ||
5131 error "cannot read $DIR/$tdir/$tfile"
5133 $LFS migrate -m1 $DIR/$tdir ||
5134 error "cannot complete migration after HSM remove"
5136 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5137 if ((mdt_index != 1)); then
5138 error "expected MDT index 1, got $mdt_index"
5141 # Refresh fid after migration.
5142 fid=$(path2fid $DIR/$tdir/$tfile)
5145 $LFS hsm_archive $DIR/$tdir/$tfile
5146 wait_request_state "$fid" ARCHIVE SUCCEED 1
5148 lctl set_param debug=+trace
5149 $LFS hsm_release $DIR/$tdir/$tfile ||
5150 error "cannot release $DIR/$tdir/$tfile"
5152 $LFS hsm_restore $DIR/$tdir/$tfile
5153 wait_request_state "$fid" RESTORE SUCCEED 1
5155 cat $DIR/$tdir/$tfile > /dev/null ||
5156 error "cannot read $DIR/$tdir/$tfile"
5158 run_test 406 "attempting to migrate HSM archived files is safe"
5161 needclients 2 || return 0
5162 # test needs a running copytool
5167 local f=$DIR/$tdir/$tfile
5168 local f2=$DIR2/$tdir/$tfile
5170 fid=$(make_custom_file_for_progress $f 39 1000000)
5171 [ $? != 0 ] && skip "not enough free space" && return
5173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5174 wait_request_state $fid ARCHIVE SUCCEED
5177 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5178 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5181 # 1st request holds layout lock while appropriate
5182 # RESTORE record is still not added to llog
5186 # after umount hsm_actions->O/x/x log shouldn't have
5187 # double RESTORE records like below
5188 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5189 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5191 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5194 wait_request_state $fid RESTORE SUCCEED
5196 run_test 407 "Check for double RESTORE records in llog"
5200 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5201 skip "HSM migrate is not supported" && return
5203 test_mkdir -p $DIR/$tdir
5204 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5206 run_test 500 "various LLAPI HSM tests"
5209 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5210 skip "need MDS version at least 2.10.58" && return 0
5214 local f=$DIR/$tdir/$tfile
5217 # set changelog_mask to ALL
5218 changelog_chmask "ALL"
5220 chmod 777 $DIR/$tdir
5221 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5222 local fid=$(path2fid $f)
5225 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5226 -gid "$RUNAS_GID") ||
5227 error "No matching CREAT entry"
5229 # Parse the changelog
5230 eval local -A changelog=$(changelog2array $entry)
5231 local nid="${changelog[nid]}"
5234 echo "Got NID '$nid'"
5235 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5236 error "nid '$nid' does not match any client NID:" \
5239 run_test 600 "Changelog fields 'u=' and 'nid='"
5242 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5243 skip "need MDS version at least 2.10.58" && return 0
5247 local f=$DIR/$tdir/$tfile
5250 # set changelog_mask to ALL
5251 changelog_chmask "ALL"
5253 touch $f || error "touch $f failed"
5254 local fid=$(path2fid $f)
5257 cat $f || error "cat $f failed"
5259 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5260 error "No matching OPEN entry"
5262 run_test 601 "OPEN Changelog entry"
5265 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5266 skip "need MDS version at least 2.10.58" && return 0
5270 local f=$DIR/$tdir/$tfile
5273 # set changelog_mask to ALL
5274 changelog_chmask "ALL"
5276 touch $f || error "touch $f failed"
5277 local fid=$(path2fid $f)
5280 cat $f || error "cat $f failed"
5282 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5286 echo f > $f || error "write $f failed"
5289 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5291 # remove OPEN from changelog_mask
5292 changelog_chmask "-OPEN"
5296 cat $f || error "cat $f failed"
5299 changelog_find -type CLOSE -target-fid $fid &&
5300 error "There should be no CLOSE entry"
5304 echo f > $f || error "write $f failed"
5307 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5309 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5312 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5313 skip "need MDS version at least 2.10.58" && return 0
5317 local f=$DIR/$tdir/$tfile
5320 # set changelog_mask to ALL
5321 changelog_chmask "ALL"
5323 touch $f || error "touch $f failed"
5324 local fid=$(path2fid $f)
5326 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5329 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5331 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5332 error "No matching GXATR entry"
5334 run_test 603 "GETXATTR Changelog entry"
5337 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5338 skip "need MDS version at least 2.10.58" && return 0
5342 local f=$DIR/$tdir/$tfile
5343 local f2=$DIR2/$tdir/$tfile
5344 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5346 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5347 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5348 do_facet mds1 lctl set_param "$procname=20"
5352 # set changelog_mask to ALL
5353 changelog_chmask "ALL"
5355 touch $f || error "touch $f failed"
5356 local fid=$(path2fid $f)
5362 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5366 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5367 -gid "$RUNAS_GID" -mode "r--") ||
5368 error "No matching NOPEN entry"
5370 # Parse the changelog
5371 eval local -A changelog=$(changelog2array $entry)
5372 local nid="${changelog[nid]}"
5375 echo "Got NID '$nid'"
5376 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5377 error "nid '$nid' does not match any client NID:" \
5382 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5385 changelog_find -type NOPEN -target-fid $fid &&
5386 error "There should be no NOPEN entry"
5388 # Sleep for `changelog_deniednext` seconds
5393 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5396 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5397 -gid "$RUNAS_GID" -mode "r--") ||
5398 error "No matching NOPEN entry"
5400 # Parse the changelog
5401 eval local -A changelog=$(changelog2array $entry)
5402 local nid="${changelog[nid]}"
5405 echo "Got NID '$nid'"
5406 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5407 error "nid '$nid' does not match any client NID:" \
5410 run_test 604 "NOPEN Changelog entry"
5413 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5414 skip "need MDS version at least 2.10.58" && return 0
5418 local f=$DIR/$tdir/$tfile
5419 local f2=$DIR2/$tdir/$tfile
5422 # set changelog_mask to ALL
5423 changelog_chmask "ALL"
5425 touch $f || error "touch $f failed"
5426 local fid=$(path2fid $f)
5430 exec 3<> $f || error "open $f failed"
5434 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5438 exec 4<> $f || error "open $f failed"
5441 changelog_find -type OPEN -target-fid $fid &&
5442 error "There should be no OPEN entry"
5444 exec 4>&- || error "close $f failed"
5447 changelog_find -type CLOSE -target-fid $fid &&
5448 error "There should be no CLOSE entry"
5452 # access in rw, so different access mode should generate entries
5453 cat $f || error "cat $f failed"
5456 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5458 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5462 # same access as first one, should not generate new entries
5463 exec 4<> $f || error "open $f failed"
5466 changelog_find -type OPEN -target-fid $fid &&
5467 error "There should be no OPEN entry"
5469 exec 4>&- || error "close $f failed"
5472 changelog_find -type CLOSE -target-fid $fid &&
5473 error "There should be no CLOSE entry"
5477 # access by different user should generate new entries
5478 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5481 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5483 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5487 exec 3>&- || error "close $f failed"
5490 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5492 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5495 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5496 skip "need MDS version at least 2.10.58" && return 0
5498 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5499 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5500 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5501 skip_env "missing llog_reader" && return
5502 local fstype=$(facet_fstype mds1)
5506 local f=$DIR/$tdir/$tfile
5509 # set changelog_mask to ALL
5510 changelog_chmask "ALL"
5512 chmod 777 $DIR/$tdir
5513 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5514 local fid=$(path2fid $f)
5515 rm $f || error "rm $f failed"
5517 local mntpt=$(facet_mntpt mds1)
5521 #remount mds1 as ldiskfs or zfs type
5522 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5523 stop mds1 || error "stop mds1 failed"
5524 mount_fstype mds1 || error "remount mds1 failed"
5526 for ((i = 0; i < 1; i++)); do
5527 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5528 local cat_file=$(do_facet mds1 $llog_reader \
5529 $mntpt/changelog_catalog | awk \
5530 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5531 [ -n "$cat_file" ] || error "no catalog file"
5533 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5534 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5535 [ -n "$entry" ] || error "no CREAT entry"
5538 local uidgid=$(echo $entry |
5539 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5540 [ -n "$uidgid" ] || error "uidgid is empty"
5541 echo "Got UID/GID $uidgid"
5542 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5543 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5544 local nid=$(echo $entry |
5545 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5546 [ -n "$nid" ] || error "nid is empty"
5548 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5549 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5551 run_test 606 "llog_reader groks changelog fields"
5556 check_and_cleanup_lustre