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
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
173 local sleep_time=100000 # 0.1 second
175 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
183 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
184 sleep_time=$(bc <<< "$sleep_time * 2")
187 # try to dump Copytool's stack
188 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
189 "echo t >/proc/sysrq-trigger"
191 echo "copytools failed to stop in ${wait_timeout}s"
196 copytool_monitor_setup() {
197 local facet=${1:-$SINGLEAGT}
198 local agent=$(facet_active_host $facet)
200 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
201 local test_dir=$(do_node $agent "$cmd") ||
202 error "Failed to create tempdir on $agent"
203 export HSMTOOL_MONITOR_DIR=$test_dir
205 # Create the fifo and a monitor (cat dies when copytool dies)
206 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
207 error "failed to create copytool fifo on $agent"
208 cmd="cat $test_dir/fifo > $test_dir/events &"
209 cmd+=" echo \\\$! > $test_dir/monitor_pid"
211 if [[ $PDSH == *Rmrsh* ]]; then
212 # This is required for pdsh -Rmrsh and its handling of remote
214 # Regular ssh and pdsh -Rssh work fine without this
215 # backgrounded subshell nonsense.
216 (do_node $agent "$cmd") &
217 export HSMTOOL_MONITOR_PDSH=$!
219 # Slightly racy, but just making a best-effort to catch obvious
222 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
223 error "Failed to start copytool monitor on $agent"
225 do_node $agent "$cmd"
227 error "Failed to start copytool monitor on $agent"
232 copytool_monitor_cleanup() {
233 local facet=${1:-$SINGLEAGT}
234 local agent=$(facet_active_host $facet)
236 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
237 # Should die when the copytool dies, but just in case.
238 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
239 cmd+=" 2>/dev/null || true"
240 do_node $agent "$cmd"
241 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
242 export HSMTOOL_MONITOR_DIR=
245 # The pdsh should die on its own when the monitor dies. Just
246 # in case, though, try to clean up to avoid any cruft.
247 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
248 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
249 export HSMTOOL_MONITOR_PDSH=
255 local host="$(facet_host "$1")"
256 local prefix=$TESTLOG_PREFIX
257 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
259 printf "${prefix}.copytool${archive_id}_log.${host}.log"
264 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
265 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
266 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
267 [ ${#misc_options[@]} -gt 0 ] &&
268 cmd+=" $(IFS=" " echo "$@")"
269 cmd+=" \"$mountpoint\""
271 echo "Starting copytool $facet on $(facet_host $facet)"
272 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
273 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
277 local facet="${1:-$SINGLEAGT}"
279 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
288 local fail_on_error=true
289 local -a misc_options
290 while [ $# -gt 0 ]; do
298 local mountpoint="$1"
302 local archive_id="$1"
306 local bandwidth="$1" # in MB/s
309 local fail_on_error=false
312 # Uncommon(/copytool dependent) option
319 # Use default values if needed
320 local facet=${facet:-$SINGLEAGT}
321 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
322 local hsm_root="$(hsm_root "$facet")"
324 stack_trap "do_facet $facet \"rm -rf \\\"$hsm_root\\\"\"" EXIT
325 do_facet $facet "mkdir -p \"$hsm_root\"" ||
326 error "mkdir \"$hsm_root\" failed"
330 local copytool=lhsmtool
334 __${copytool}_${action} "${misc_options[@]}"
335 if [ $? -ne 0 ]; then
340 local host="$(facet_host $facet)"
341 error_msg="Failed to start copytool $facet on '$host'"
345 $fail_on_error && error "$error_msg" || echo "$error_msg"
350 local facet=${1:-$SINGLEAGT}
351 # Use MOUNT2 by default if defined
352 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
354 local hsm_root=${4:-$(copytool_device $facet)}
356 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
358 local agent=$(facet_active_host $facet)
360 if $HSM_ARCHIVE_PURGE; then
361 echo "Purging archive on $agent"
362 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
365 echo "Starting copytool $facet on $agent"
366 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
367 error "mkdir '$hsm_root/$HSMTMP' failed"
368 # bandwidth is limited to 1MB/s so the copy time is known and
369 # independent of hardware
370 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
371 cmd+=" --hsm-root $hsm_root/$HSMTMP"
372 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
373 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
374 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
375 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
376 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
377 cmd+=" --bandwidth 1 $lustre_mntpnt"
379 # Redirect the standard output and error to a log file which
380 # can be uploaded to Maloo.
381 local prefix=$TESTLOG_PREFIX
382 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
383 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
385 stack_trap cleanup EXIT
386 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
387 if [[ $? != 0 ]]; then
388 [[ $HSMTOOL_NOERROR == true ]] ||
389 error "start copytool $facet on $agent failed"
390 echo "start copytool $facet on $agent failed"
394 get_copytool_event_log() {
395 local facet=${1:-$SINGLEAGT}
396 local agent=$(facet_active_host $facet)
398 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
399 error "Can't get event log: No monitor directory!"
401 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
402 error "Could not collect event log from $agent"
407 local agt_facet=$SINGLEAGT
408 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
409 local hsm_root=$(copytool_device $agt_facet)
411 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
418 kill_copytools $agt_hosts
419 wait_copytools $agt_hosts || error "copytools failed to stop"
421 # Clean all CDTs orphans requests from previous tests that
422 # would otherwise need to timeout to clear.
423 for ((i = 0; i < MDSCOUNT; i++)); do
425 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
426 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
428 # Skip already stopping or stopped CDTs.
429 [[ "${state[$i]}" =~ ^stop ]] && continue
431 do_facet $facet "$LCTL set_param $param=shutdown"
434 for ((i = 0; i < MDSCOUNT; i++)); do
435 # Only check and restore CDTs that we stopped in the first loop.
436 [[ "${state[$i]}" =~ ^stop ]] && continue
439 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
441 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
442 error "$facet CDT state is not stopped"
444 # Restore old CDT state.
445 do_facet $facet "$LCTL set_param $param=${state[$i]}"
448 for ((i = 0; i < MDSCOUNT; i++)); do
449 # Only check CDTs that we stopped in the first loop.
450 [[ "${state[$i]}" =~ ^stop ]] && continue
453 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
455 # Check that the old CDT state was restored.
456 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
457 20 || error "$facet CDT state is not '${state[$i]}'"
460 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
461 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
466 local agents=${1:-$(facet_active_host $SINGLEAGT)}
468 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
469 echo "Copytool is suspended on $agents"
472 copytool_continue() {
473 local agents=${1:-$(facet_active_host $SINGLEAGT)}
475 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
476 echo "Copytool is continued on $agents"
479 copytool_remove_backend() {
481 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
482 echo "Remove from backend: $fid = $be"
483 do_facet $SINGLEAGT rm -f $be
487 mkdir -p "$(dirname "$2")" ||
488 error "cannot create directory '$(dirname "$2")'"
490 do_facet $SINGLEAGT \
491 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
492 --import $1 $2 $MOUNT" ||
493 error "import of $1 to $2 failed"
496 file_creation_failure() {
503 df $MOUNT $MOUNT2 >&2
504 error "Not enough space to create $file with $cmd"
507 error "cannot create $file with $cmd, status=$err"
512 # Creates a file using dd
518 local source=${5:-/dev/zero}
522 if [ -n "$conv" ]; then
526 # Create the directory in case it does not exist
527 mkdir -p "$(dirname "$file")"
528 # Delete the file in case it already exist
531 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
532 path2fid "$file" || error "cannot get FID of '$file'"
535 echo "cannot create file '$file'" >&2;
536 # Let the caller decide what to do on error
541 create_empty_file() {
542 create_file "${1/$DIR/$DIR2}" 1M 0 ||
543 file_creation_failure dd "${1/$DIR/$DIR2}" $?
546 create_small_file() {
547 local source_file=/dev/urandom
550 local conv=${2:-fsync}
552 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
553 file_creation_failure dd "${1/$DIR/$DIR2}" $?
556 create_small_sync_file() {
557 create_small_file "$1" sync
560 create_archive_file() {
561 local file="$HSM_ARCHIVE/$1"
563 local source=/dev/urandom
565 # Create the counterpart directory of the archive
566 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
567 error "cannot create archive directory '$(dirname "$file")'"
569 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
570 error "cannot create archive file '$file'"
574 local file=$HSM_ARCHIVE/$2
575 do_facet $SINGLEAGT mkdir -p $(dirname $file)
576 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
585 if [[ "$value" != "" ]]; then
588 for mdtno in $(seq 1 $MDSCOUNT); do
589 local idx=$(($mdtno - 1))
590 local facet=mds${mdtno}
591 # if $arg include -P option, run 1 set_param per MDT on the MGS
592 # else, run set_param on each MDT
593 [[ $arg = *"-P"* ]] && facet=mgs
594 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
595 [[ $? != 0 ]] && rc=1
605 for mdtno in $(seq 1 $MDSCOUNT); do
606 local idx=$(($mdtno - 1))
607 wait_result mds${mdtno} \
608 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
610 error "$key state is not '$target' on mds${mdtno}"
617 for mdtno in $(seq 1 $MDSCOUNT); do
618 local idx=$(($mdtno - 1))
619 local cl_user=$(do_facet mds${mdtno} $LCTL \
620 --device ${MDT[$idx]} \
621 changelog_register -n)
623 do_facet mds${mdtno} lctl set_param \
624 mdd.${MDT[$idx]}.changelog_mask="+hsm"
625 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
629 changelog_cleanup() {
631 for mdtno in $(seq 1 $MDSCOUNT); do
632 local idx=$(($mdtno - 1))
633 [[ -z ${CL_USERS[$idx]} ]] && continue
634 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
635 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
636 changelog_deregister ${CL_USERS[$idx]}
641 changelog_get_flags() {
646 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
651 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
659 mdts_set_param "$opt -n" "hsm.$param" "$value"
666 mdts_set_param "" hsm_control "$cmd"
667 mdts_check_param hsm_control "$target" 10
670 cdt_set_sanity_policy() {
671 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
674 mdts_set_param "" hsm.policy "+NRA"
675 mdts_set_param "" hsm.policy "-NBR"
676 CDT_POLICY_HAD_CHANGED=
681 mdts_set_param "" hsm.policy "+NRA"
682 CDT_POLICY_HAD_CHANGED=true
685 cdt_clear_no_retry() {
686 mdts_set_param "" hsm.policy "-NRA"
687 CDT_POLICY_HAD_CHANGED=true
690 cdt_set_non_blocking_restore() {
691 mdts_set_param "" hsm.policy "+NBR"
692 CDT_POLICY_HAD_CHANGED=true
695 cdt_clear_non_blocking_restore() {
696 mdts_set_param "" hsm.policy "-NBR"
697 CDT_POLICY_HAD_CHANGED=true
700 cdt_clear_mount_state() {
701 mdts_set_param "-P -d" hsm_control ""
704 cdt_set_mount_state() {
705 mdts_set_param "-P" hsm_control "$1"
706 # set_param -P is asynchronous operation and could race with set_param.
707 # In such case configs could be retrieved and applied at mgc after
708 # set_param -P completion. Sleep here to avoid race with set_param.
709 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
710 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
711 # and 10 seconds to retrieve config from server.
716 mdts_check_param hsm_control "$1" 20
720 set_test_state disabled disabled
724 set_test_state enabled enabled
728 set_test_state shutdown stopped
732 set_test_state purge enabled
738 cdt_set_sanity_policy
742 local client_count=$1
743 if [[ $CLIENTCOUNT -lt $client_count ]]; then
744 skip "Need $client_count or more clients, have $CLIENTCOUNT"
751 $LFS path2fid $1 | tr -d '[]'
752 return ${PIPESTATUS[0]}
760 if [[ $u == "user" ]]; then
761 st=$($RUNAS $LFS hsm_state $f)
764 st=$($LFS hsm_state $f)
767 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
769 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
773 get_hsm_archive_id() {
776 st=$($LFS hsm_state $f)
777 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
779 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
787 local st=$(get_hsm_flags $f)
788 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
791 check_hsm_flags_user() {
795 local st=$(get_hsm_flags $f user)
796 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
808 if [[ "$3" != 1 ]]; then
812 cp $1 $f || file_creation_failure cp $f $?
814 path2fid $f || error "cannot get fid on $f"
817 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
819 # Note that this might lead to surprising behaviours such as deleting an
820 # important file for the currently running test
821 delete_large_files() {
822 printf "Deleting large files...\n" >&2
823 find $MOUNT -size +10M -delete
824 wait_delete_completed
827 make_custom_file_for_progress() {
828 local count=${2:-"39"}
829 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
832 [[ $count -gt 0 ]] || error "Invalid file size"
833 [[ $bs -gt 0 ]] || error "Invalid stripe size"
835 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
836 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
837 echo "It might be due to a lack of space in the filesystem" >&2
838 delete_large_files >&2
839 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
840 file_creation_failure dd "${1/$DIR/$DIR2}" $?
847 wait_update --verbose $(facet_active_host $facet) "$@"
850 wait_request_state() {
854 # 4th arg (mdt index) is optional
856 local mds=mds$(($mdtidx + 1))
858 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
859 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
861 wait_result $mds "$cmd" $state 200 ||
862 error "request on $fid is not $state on $mds"
865 get_request_state() {
869 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
870 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
873 get_request_count() {
877 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
878 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
881 # Ensure the number of HSM request for a given FID is correct
882 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
883 assert_request_count() {
884 local request_count=$(get_request_count $1 $2)
885 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
887 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
894 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
895 [[ -n $fid ]] && cmd+=" | grep '$fid'"
896 cmd+=" | egrep 'WAITING|STARTED'"
898 wait_result $SINGLEMDS "$cmd" "" $timeout ||
899 error "requests did not complete"
902 wait_for_grace_delay() {
903 local val=$(get_hsm_param grace_delay)
907 wait_for_loop_period() {
908 local val=$(get_hsm_param loop_period)
915 # python2.6 in EL6 includes an internal json module
916 local json_parser='import json; import fileinput;'
917 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
918 json_parser+='json.loads([line for line in '
919 json_parser+='fileinput.input()][0]).items()])'
921 echo $raw_event | python -c "$json_parser"
924 get_agent_by_uuid_mdt() {
927 local mds=mds$(($mdtidx + 1))
928 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
932 check_agent_registered_by_mdt() {
935 local mds=mds$(($mdtidx + 1))
936 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
937 if [[ ! -z "$agent" ]]; then
938 echo "found agent $agent on $mds"
940 error "uuid $uuid not found in agent list on $mds"
944 check_agent_unregistered_by_mdt() {
947 local mds=mds$(($mdtidx + 1))
948 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
949 if [[ -z "$agent" ]]; then
950 echo "uuid not found in agent list on $mds"
952 error "uuid found in agent list on $mds: $agent"
956 check_agent_registered() {
959 for mdsno in $(seq 1 $MDSCOUNT); do
960 check_agent_registered_by_mdt $uuid $((mdsno - 1))
964 check_agent_unregistered() {
967 for mdsno in $(seq 1 $MDSCOUNT); do
968 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
973 local agent=${1:-$(facet_active_host $SINGLEAGT)}
975 # Lustre mount-point is mandatory and last parameter on
977 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
979 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
981 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
987 # populate MDT device array
990 # cleanup from previous bad setup
993 # for recovery tests, coordinator needs to be started at mount
995 # the lustre conf must be without hsm on (like for sanity.sh)
996 echo "Set HSM on and start"
997 cdt_set_mount_state enabled
998 cdt_check_state enabled
1000 echo "Set sanity-hsm HSM policy"
1001 cdt_set_sanity_policy
1003 # finished requests are quickly removed from list
1004 set_hsm_param grace_delay 10
1008 chmod 777 $DIR/$tdir
1010 local f=$DIR/$tdir/$tfile
1014 check_hsm_flags_user $f "0x00000000"
1016 $RUNAS $LFS hsm_set --norelease $f ||
1017 error "user could not change hsm flags"
1018 check_hsm_flags_user $f "0x00000010"
1020 $RUNAS $LFS hsm_clear --norelease $f ||
1021 error "user could not clear hsm flags"
1022 check_hsm_flags_user $f "0x00000000"
1024 # User could not change those flags...
1025 $RUNAS $LFS hsm_set --exists $f &&
1026 error "user should not set this flag"
1027 check_hsm_flags_user $f "0x00000000"
1030 $LFS hsm_set --exists $f ||
1031 error "root could not change hsm flags"
1032 check_hsm_flags_user $f "0x00000001"
1034 $LFS hsm_clear --exists $f ||
1035 error "root could not clear hsm state"
1036 check_hsm_flags_user $f "0x00000000"
1039 run_test 1 "lfs hsm flags root/non-root access"
1042 local f=$DIR/$tdir/$tfile
1043 local fid=$(create_small_file $f)
1047 $LFS hsm_archive $f || error "could not archive file"
1048 wait_request_state $fid ARCHIVE SUCCEED
1050 # Release and check states
1051 $LFS hsm_release $f || error "could not release file"
1052 echo -n "Verifying released state: "
1053 check_hsm_flags $f "0x0000000d"
1055 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
1057 run_test 1a "mmap & cat a HSM released file"
1061 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
1062 error "failed to set default stripe"
1063 local f=$DIR/$tdir/$tfile
1066 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1067 error "failed to create file"
1068 local fid=$(path2fid $f)
1073 $LFS hsm_archive $f || error "could not archive file"
1074 wait_request_state $fid ARCHIVE SUCCEED
1077 $LFS hsm_release $f || error "could not release file"
1078 echo "verify released state: "
1079 check_hsm_flags $f "0x0000000d" && echo "pass"
1082 $LFS hsm_restore $f || error "could not restore file"
1083 wait_request_state $fid RESTORE SUCCEED
1084 echo "verify restored state: "
1085 check_hsm_flags $f "0x00000009" && echo "pass"
1087 run_test 1b "Archive, Release & Restore composite file"
1091 chmod 777 $DIR/$tdir
1093 local f=$DIR/$tdir/$tfile
1096 # Test whether we can set the maximum archive number.
1097 local LOCAL_HSM_ARCHIVE_NUMBER=32
1098 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1099 error "root could not change hsm flags"
1100 check_hsm_flags_user $f "0x00000001"
1101 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1102 local st=$(get_hsm_archive_id $f)
1103 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1104 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1106 # Test whether setting archive number 0 results in no change.
1107 $LFS hsm_set --exists --archive-id 0 $f ||
1108 error "root could not change hsm flags"
1109 check_hsm_flags_user $f "0x00000001"
1110 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1111 st=$(get_hsm_archive_id $f)
1112 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1113 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1115 # Test whether setting archive number > 32 results in error.
1116 $LFS hsm_set --exists --archive-id 33 $f &&
1117 error "archive number is larger than 32"
1118 check_hsm_flags_user $f "0x00000001"
1120 # Test whether setting archive number 16 and archived flag.
1121 LOCAL_HSM_ARCHIVE_NUMBER=16
1122 $LFS hsm_set --exists --archived \
1123 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1124 error "root could not change hsm flags"
1125 check_hsm_flags_user $f "0x00000009"
1126 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1127 st=$(get_hsm_archive_id $f)
1128 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1129 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1131 run_test 1c "Check setting archive-id in lfs hsm_set"
1134 local f=$DIR/$tdir/$tfile
1136 create_empty_file "$f"
1137 # New files are not dirty
1138 check_hsm_flags $f "0x00000000"
1140 # For test, we simulate an archived file.
1141 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1142 check_hsm_flags $f "0x00000001"
1144 # chmod do not put the file dirty
1145 chmod 600 $f || error "could not chmod test file"
1146 check_hsm_flags $f "0x00000001"
1148 # chown do not put the file dirty
1149 chown $RUNAS_ID $f || error "could not chown test file"
1150 check_hsm_flags $f "0x00000001"
1152 # truncate put the file dirty
1153 $TRUNCATE $f 1 || error "could not truncate test file"
1154 check_hsm_flags $f "0x00000003"
1156 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1157 check_hsm_flags $f "0x00000001"
1159 run_test 2 "Check file dirtyness when doing setattr"
1165 # New files are not dirty
1166 cp -p /etc/passwd $f
1167 check_hsm_flags $f "0x00000000"
1169 # For test, we simulate an archived file.
1170 $LFS hsm_set --exists $f ||
1171 error "user could not change hsm flags"
1172 check_hsm_flags $f "0x00000001"
1174 # Reading a file, does not set dirty
1175 cat $f > /dev/null || error "could not read file"
1176 check_hsm_flags $f "0x00000001"
1178 # Open for write without modifying data, does not set dirty
1179 openfile -f O_WRONLY $f || error "could not open test file"
1180 check_hsm_flags $f "0x00000001"
1182 # Append to a file sets it dirty
1183 cp -p /etc/passwd $f.append || error "could not create file"
1184 $LFS hsm_set --exists $f.append ||
1185 error "user could not change hsm flags"
1186 dd if=/etc/passwd of=$f.append bs=1 count=3\
1187 conv=notrunc oflag=append status=noxfer ||
1188 file_creation_failure dd $f.append $?
1189 check_hsm_flags $f.append "0x00000003"
1191 # Modify a file sets it dirty
1192 cp -p /etc/passwd $f.modify || error "could not create file"
1193 $LFS hsm_set --exists $f.modify ||
1194 error "user could not change hsm flags"
1195 dd if=/dev/zero of=$f.modify bs=1 count=3\
1196 conv=notrunc status=noxfer ||
1197 file_creation_failure dd $f.modify $?
1198 check_hsm_flags $f.modify "0x00000003"
1200 # Open O_TRUNC sets dirty
1201 cp -p /etc/passwd $f.trunc || error "could not create file"
1202 $LFS hsm_set --exists $f.trunc ||
1203 error "user could not change hsm flags"
1204 cp /etc/group $f.trunc || error "could not override a file"
1205 check_hsm_flags $f.trunc "0x00000003"
1207 # Mmapped a file sets dirty
1208 cp -p /etc/passwd $f.mmap || error "could not create file"
1209 $LFS hsm_set --exists $f.mmap ||
1210 error "user could not change hsm flags"
1211 multiop $f.mmap OSMWUc || error "could not mmap a file"
1212 check_hsm_flags $f.mmap "0x00000003"
1214 run_test 3 "Check file dirtyness when opening for write"
1217 local f=$DIR/$tdir/$tfile
1218 local fid=$(create_small_file $f)
1221 local st=$(get_request_state $fid CANCEL)
1222 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1224 run_test 4 "Useless cancel must not be registered"
1227 # test needs a running copytool
1231 local f=$DIR/$tdir/$tfile
1232 local fid=$(copy_file /etc/passwd $f)
1234 wait_request_state $fid ARCHIVE SUCCEED
1236 check_hsm_flags $f "0x00000009"
1238 run_test 8 "Test default archive number"
1241 # we do not use the default one to be sure
1242 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1243 copytool setup --archive-id $archive_id
1245 # give time for CT to register with MDTs
1246 sleep $(($MDSCOUNT*2))
1247 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1248 check_agent_registered $uuid
1251 local f=$DIR/$tdir/$tfile
1252 local fid=$(copy_file /etc/passwd $f)
1253 $LFS hsm_archive --archive $archive_id $f
1254 wait_request_state $fid ARCHIVE SUCCEED
1256 check_hsm_flags $f "0x00000009"
1258 run_test 9 "Use of explicit archive number, with dedicated copytool"
1261 needclients 3 || return 0
1267 # start all of the copytools
1268 for n in $(seq $AGTCOUNT); do
1269 copytool setup --facet agt$n
1273 for n in $(seq $AGTCOUNT); do
1274 file=$DIR/$tdir/$tfile.$n
1275 fid=$(create_small_file $file)
1277 $LFS hsm_archive $file || error "could not archive file $file"
1278 wait_request_state $fid ARCHIVE SUCCEED
1279 check_hsm_flags $file "0x00000009"
1282 run_test 9a "Multiple remote agents"
1285 # test needs a running copytool
1288 mkdir -p $DIR/$tdir/d1
1289 local f=$DIR/$tdir/$tfile
1290 local fid=$(copy_file /etc/hosts $f)
1291 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1292 error "hsm_archive failed"
1293 wait_request_state $fid ARCHIVE SUCCEED
1295 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1296 error "fid $fid not in archive $HSM_ARCHIVE"
1297 echo "Verifying content"
1298 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1299 echo "Verifying hsm state "
1300 check_hsm_flags $f "0x00000009"
1302 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1303 local st=$(get_hsm_archive_id $f)
1304 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1305 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1309 run_test 10a "Archive a file"
1312 # test needs a running copytool
1316 local f=$DIR/$tdir/$tfile
1317 local fid=$(copy_file /etc/hosts $f)
1318 $LFS hsm_archive $f || error "archive request failed"
1319 wait_request_state $fid ARCHIVE SUCCEED
1321 $LFS hsm_archive $f || error "archive of non dirty file failed"
1322 local cnt=$(get_request_count $fid ARCHIVE)
1323 [[ "$cnt" == "1" ]] ||
1324 error "archive of non dirty file must not make a request"
1326 run_test 10b "Archive of non dirty file must work without doing request"
1329 # test needs a running copytool
1333 local f=$DIR/$tdir/$tfile
1334 local fid=$(copy_file /etc/hosts $f)
1335 $LFS hsm_set --noarchive $f
1336 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1339 run_test 10c "Check forbidden archive"
1342 # test needs a running copytool
1346 local f=$DIR/$tdir/$tfile
1347 local fid=$(copy_file /etc/hosts $f)
1348 $LFS hsm_archive $f || error "cannot archive $f"
1349 wait_request_state $fid ARCHIVE SUCCEED
1351 local ar=$(get_hsm_archive_id $f)
1352 local dflt=$(get_hsm_param default_archive_id)
1353 [[ $ar == $dflt ]] ||
1354 error "archived file is not on default archive: $ar != $dflt"
1356 run_test 10d "Archive a file on the default archive id"
1360 copy2archive /etc/hosts $tdir/$tfile
1361 local f=$DIR/$tdir/$tfile
1363 import_file $tdir/$tfile $f
1364 echo -n "Verifying released state: "
1365 check_hsm_flags $f "0x0000000d"
1367 local LSZ=$(stat -c "%s" $f)
1368 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1370 echo "Verifying imported size $LSZ=$ASZ"
1371 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1372 echo -n "Verifying released pattern: "
1373 local PTRN=$($GETSTRIPE -L $f)
1375 [[ $PTRN == released ]] || error "Is not released"
1376 local fid=$(path2fid $f)
1377 echo "Verifying new fid $fid in archive"
1379 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1380 error "fid $fid not in archive $HSM_ARCHIVE"
1382 run_test 11a "Import a file"
1385 # test needs a running copytool
1389 local f=$DIR/$tdir/$tfile
1390 local fid=$(copy_file /etc/hosts $f)
1391 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1392 error "hsm_archive failed"
1393 wait_request_state $fid ARCHIVE SUCCEED
1395 local FILE_HASH=$(md5sum $f)
1400 echo "$FILE_HASH" | md5sum -c
1402 [[ $? -eq 0 ]] || error "Restored file differs"
1406 run_test 11b "Import a deleted file using its FID"
1409 # test needs a running copytool
1413 copy2archive /etc/hosts $tdir/$tfile
1415 local f=$DIR/$tdir/$tfile
1416 import_file $tdir/$tfile $f
1417 local f2=$DIR2/$tdir/$tfile
1418 echo "Verifying released state: "
1419 check_hsm_flags $f2 "0x0000000d"
1421 local fid=$(path2fid $f2)
1422 $LFS hsm_restore $f2
1423 wait_request_state $fid RESTORE SUCCEED
1425 echo "Verifying file state: "
1426 check_hsm_flags $f2 "0x00000009"
1428 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1430 [[ $? -eq 0 ]] || error "Restored file differs"
1434 run_test 12a "Restore an imported file explicitly"
1437 # test needs a running copytool
1441 copy2archive /etc/hosts $tdir/$tfile
1443 local f=$DIR/$tdir/$tfile
1444 import_file $tdir/$tfile $f
1445 echo "Verifying released state: "
1446 check_hsm_flags $f "0x0000000d"
1448 cat $f > /dev/null || error "File read failed"
1450 echo "Verifying file state after restore: "
1451 check_hsm_flags $f "0x00000009"
1453 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1455 [[ $? -eq 0 ]] || error "Restored file differs"
1459 run_test 12b "Restore an imported file implicitly"
1462 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1464 # test needs a running copytool
1467 local f=$DIR/$tdir/$tfile
1469 $LFS setstripe -c 2 "$f"
1471 fid=$(make_custom_file_for_progress $f 5)
1472 [ $? != 0 ] && skip "not enough free space" && return
1474 local FILE_CRC=$(md5sum $f)
1476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1477 wait_request_state $fid ARCHIVE SUCCEED
1478 $LFS hsm_release $f || error "release $f failed"
1480 echo "$FILE_CRC" | md5sum -c
1482 [[ $? -eq 0 ]] || error "Restored file differs"
1484 run_test 12c "Restore a file with stripe of 2"
1487 # test needs a running copytool
1492 local f=$DIR/$tdir/$tfile
1493 local fid=$(copy_file /etc/hosts $f)
1494 $LFS hsm_restore $f || error "restore of non archived file failed"
1495 local cnt=$(get_request_count $fid RESTORE)
1496 [[ "$cnt" == "0" ]] ||
1497 error "restore non archived must not make a request"
1498 $LFS hsm_archive $f ||
1499 error "archive request failed"
1500 wait_request_state $fid ARCHIVE SUCCEED
1501 $LFS hsm_restore $f ||
1502 error "restore of non released file failed"
1503 local cnt=$(get_request_count $fid RESTORE)
1504 [[ "$cnt" == "0" ]] ||
1505 error "restore a non dirty file must not make a request"
1507 run_test 12d "Restore of a non archived, non released file must work"\
1508 " without doing request"
1511 # test needs a running copytool
1514 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1515 local f=$DIR/$tdir/$tfile
1516 local fid=$(copy_file /etc/hosts $f)
1517 $LFS hsm_archive $f || error "archive request failed"
1518 wait_request_state $fid ARCHIVE SUCCEED
1521 cat /etc/hosts >> $f
1525 $LFS hsm_restore $f && error "restore a dirty file must fail"
1528 run_test 12e "Check forbidden restore"
1531 # test needs a running copytool
1535 local f=$DIR/$tdir/$tfile
1536 local fid=$(copy_file /etc/hosts $f)
1538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1539 wait_request_state $fid ARCHIVE SUCCEED
1540 $LFS hsm_release $f || error "release of $f failed"
1542 wait_request_state $fid RESTORE SUCCEED
1544 echo -n "Verifying file state: "
1545 check_hsm_flags $f "0x00000009"
1547 diff -q /etc/hosts $f
1549 [[ $? -eq 0 ]] || error "Restored file differs"
1551 run_test 12f "Restore a released file explicitly"
1554 # test needs a running copytool
1558 local f=$DIR/$tdir/$tfile
1559 local fid=$(copy_file /etc/hosts $f)
1561 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1562 wait_request_state $fid ARCHIVE SUCCEED
1563 $LFS hsm_release $f || error "release of $f failed"
1565 diff -q /etc/hosts $f
1568 # we check we had a restore done
1569 wait_request_state $fid RESTORE SUCCEED
1571 [[ $st -eq 0 ]] || error "Restored file differs"
1573 run_test 12g "Restore a released file implicitly"
1576 needclients 2 || return 0
1578 # test needs a running copytool
1582 local f=$DIR/$tdir/$tfile
1583 local fid=$(copy_file /etc/hosts $f)
1585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1586 wait_request_state $fid ARCHIVE SUCCEED
1587 $LFS hsm_release $f || error "release of $f failed"
1589 do_node $CLIENT2 diff -q /etc/hosts $f
1592 # we check we had a restore done
1593 wait_request_state $fid RESTORE SUCCEED
1595 [[ $st -eq 0 ]] || error "Restored file differs"
1597 run_test 12h "Restore a released file implicitly from a second node"
1600 # test needs a running copytool
1604 local f=$DIR/$tdir/$tfile
1605 local fid=$(copy_file /etc/passwd $f)
1606 $LFS hsm_archive $f || error "archive of $f failed"
1607 wait_request_state $fid ARCHIVE SUCCEED
1609 $LFS hsm_release $f || error "release of $f failed"
1613 [[ $? -eq 0 ]] || error "Restored file differs"
1615 run_test 12m "Archive/release/implicit restore"
1618 # test needs a running copytool
1622 copy2archive /etc/hosts $tdir/$tfile
1624 local f=$DIR/$tdir/$tfile
1625 import_file $tdir/$tfile $f
1627 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1628 error "Restored file differs"
1630 $LFS hsm_release $f || error "release of $f failed"
1634 run_test 12n "Import/implicit restore/release"
1637 # test needs a running copytool
1641 local f=$DIR/$tdir/$tfile
1642 local fid=$(copy_file /etc/hosts $f)
1644 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1645 wait_request_state $fid ARCHIVE SUCCEED
1646 $LFS hsm_release $f || error "release of $f failed"
1648 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1649 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1651 # set no retry action mode
1654 diff -q /etc/hosts $f
1657 # we check we had a restore failure
1658 wait_request_state $fid RESTORE FAILED
1660 [[ $st -eq 0 ]] && error "Restore must fail"
1662 # remove no retry action mode
1665 # check file is still released
1666 check_hsm_flags $f "0x0000000d"
1668 # retry w/o failure injection
1669 do_facet $SINGLEMDS lctl set_param fail_loc=0
1671 # to be sure previous RESTORE result is gone
1673 wait_for_grace_delay
1675 diff -q /etc/hosts $f
1678 # we check we had a restore done
1679 wait_request_state $fid RESTORE SUCCEED
1681 [[ $st -eq 0 ]] || error "Restored file differs"
1683 run_test 12o "Layout-swap failure during Restore leaves file released"
1686 # test needs a running copytool
1690 local f=$DIR/$tdir/$tfile
1691 local fid=$(copy_file /etc/hosts $f)
1693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1694 wait_request_state $fid ARCHIVE SUCCEED
1695 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1696 $LFS hsm_release $f || error "cannot release $f"
1697 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1698 $LFS hsm_release $f || error "cannot release $f"
1699 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1701 run_test 12p "implicit restore of a file on copytool mount point"
1703 cleanup_test_12q() {
1704 error "cannot umount $MOUNT3 on $SINGLEAGT"
1708 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1709 skip "need MDS version at least 2.7.58" && return 0
1711 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1712 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1713 error "cannot mount $MOUNT3 on $SINGLEAGT"
1715 # test needs a running copytool
1716 copytool setup -m "$MOUNT3"
1718 local f=$DIR/$tdir/$tfile
1719 local f2=$DIR2/$tdir/$tfile
1720 local fid=$(create_small_file $f)
1721 local orig_size=$(stat -c "%s" $f)
1723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1724 wait_request_state $fid ARCHIVE SUCCEED
1726 $LFS hsm_release $f || error "could not release file"
1727 check_hsm_flags $f "0x0000000d"
1730 wait_copytools || error "copytool failed to stop"
1732 cat $f > /dev/null &
1734 # wait a bit to allow implicit restore request to be handled.
1735 # if not, next stat would also block on layout-lock.
1738 local size=$(stat -c "%s" $f2)
1739 [ $size -eq $orig_size ] ||
1740 error "$f2: wrong size after archive: $size != $orig_size"
1742 copytool setup -m "$MOUNT3"
1746 size=$(stat -c "%s" $f)
1747 [ $size -eq $orig_size ] ||
1748 error "$f: wrong size after restore: $size != $orig_size"
1750 size=$(stat -c "%s" $f2)
1751 [ $size -eq $orig_size ] ||
1752 error "$f2: wrong size after restore: $size != $orig_size"
1756 size=$(stat -c "%s" $f)
1758 error "$f: wrong size after overwrite: $size != 0"
1760 size=$(stat -c "%s" $f2)
1762 error "$f2: wrong size after overwrite: $size != 0"
1764 run_test 12q "file attributes are refreshed after restore"
1767 # test needs a running copytool
1770 local ARC_SUBDIR="import.orig"
1774 # populate directory to be imported
1775 for d in $(seq 1 10); do
1776 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1777 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1778 for f in $(seq 1 10); do
1779 CURR_FILE="$CURR_DIR/$tfile.$f"
1780 # write file-specific data
1781 do_facet $SINGLEAGT \
1782 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1783 "file=$CURR_FILE > $CURR_FILE"
1787 import_file "$ARC_SUBDIR" $DIR/$tdir
1788 # diff lustre content and origin (triggers file restoration)
1789 # there must be 10x10 identical files, and no difference
1790 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1791 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1792 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1793 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1795 [ $cnt_diff -eq 0 ] ||
1796 error "$cnt_diff imported files differ from read data"
1797 [ $cnt_ok -eq 100 ] ||
1798 error "not enough identical files ($cnt_ok != 100)"
1802 run_test 13 "Recursively import and restore a directory"
1805 # test needs a running copytool
1809 local f=$DIR/$tdir/$tfile
1810 local fid=$(create_small_file $f)
1811 local sum=$(md5sum $f | awk '{print $1}')
1812 $LFS hsm_archive $f || error "could not archive file"
1813 wait_request_state $fid ARCHIVE SUCCEED
1815 # create released file (simulate llapi_hsm_import call)
1816 local fid2=$(create_empty_file "$f")
1817 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1818 $LFS hsm_release $f || error "could not release file"
1820 # rebind the archive to the newly created file
1821 echo "rebind $fid to $fid2"
1823 do_facet $SINGLEAGT \
1824 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1825 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1827 # restore file and compare md5sum
1828 local sum2=$(md5sum $f | awk '{print $1}')
1830 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1834 run_test 14 "Rebind archived file to a new fid"
1837 # test needs a running copytool
1841 local f=$DIR/$tdir/$tfile
1843 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1847 for i in $(seq 1 $count); do
1848 fids[$i]=$(create_small_file $f.$i)
1849 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1850 $LFS hsm_archive $f.$i || error "could not archive file"
1852 wait_all_done $(($count*60))
1856 for i in $(seq 1 $count); do
1857 local fid2=$(create_empty_file "${f}.${i}")
1858 # add the rebind operation to the list
1859 echo ${fids[$i]} $fid2 >> $tmpfile
1861 # set it released (simulate llapi_hsm_import call)
1862 $LFS hsm_set --archived --exists $f.$i ||
1863 error "could not force hsm flags"
1864 $LFS hsm_release $f.$i || error "could not release file"
1866 nl=$(wc -l < $tmpfile)
1867 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1869 echo "rebind list of files"
1870 do_facet $SINGLEAGT \
1871 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1872 --rebind $tmpfile $DIR" || error "could not rebind file list"
1874 # restore files and compare md5sum
1875 for i in $(seq 1 $count); do
1876 local sum2=$(md5sum $f.$i | awk '{print $1}')
1877 [[ $sum2 == ${sums[$i]} ]] ||
1878 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1884 run_test 15 "Rebind a list of files"
1887 # test needs a running copytool
1891 # create a known size file so we can verify transfer speed
1894 dd if=/dev/zero of=$ref bs=1M count=20
1897 local f=$DIR/$tdir/$tfile
1898 local fid=$(copy_file $ref $f)
1900 local start=$(date +%s)
1902 wait_request_state $fid ARCHIVE SUCCEED
1903 local end=$(date +%s)
1904 # Add 1 to account for rounding errors between start and end (LU-8155)
1905 local duration=$((end - start + 1))
1907 [[ $duration -ge $((goal - 1)) ]] ||
1908 error "Transfer is too fast $duration < $goal"
1910 run_test 16 "Test CT bandwith control option"
1913 local f=$DIR/$tdir/$tfile
1914 create_empty_file "$f"
1916 # Could not release a non-archived file
1917 $LFS hsm_release $f && error "release should not succeed"
1919 # For following tests, we must test them with HS_ARCHIVED set
1920 $LFS hsm_set --exists --archived $f || error "could not add flag"
1922 # Could not release a file if no-release is set
1923 $LFS hsm_set --norelease $f || error "could not add flag"
1924 $LFS hsm_release $f && error "release should not succeed"
1925 $LFS hsm_clear --norelease $f || error "could not remove flag"
1927 # Could not release a file if lost
1928 $LFS hsm_set --lost $f || error "could not add flag"
1929 $LFS hsm_release $f && error "release should not succeed"
1930 $LFS hsm_clear --lost $f || error "could not remove flag"
1932 # Could not release a file if dirty
1933 $LFS hsm_set --dirty $f || error "could not add flag"
1934 $LFS hsm_release $f && error "release should not succeed"
1935 $LFS hsm_clear --dirty $f || error "could not remove flag"
1937 run_test 20 "Release is not permitted"
1940 # test needs a running copytool
1943 local f=$DIR/$tdir/test_release
1945 # Create a file and check its states
1946 local fid=$(create_small_file $f)
1947 check_hsm_flags $f "0x00000000"
1949 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1950 # used until file is flushed to disk
1951 if [ $(facet_fstype ost1) == "zfs" ]; then
1952 # this causes an OST_SYNC rpc to be sent
1953 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1954 # clear locks to reread file data
1955 cancel_lru_locks osc
1958 local orig_size=$(stat -c "%s" $f)
1959 local orig_blocks=$(stat -c "%b" $f)
1961 start_full_debug_logging
1963 $LFS hsm_archive $f || error "could not archive file"
1964 wait_request_state $fid ARCHIVE SUCCEED
1966 local blocks=$(stat -c "%b" $f)
1967 [ $blocks -eq $orig_blocks ] ||
1968 error "$f: wrong block number after archive: " \
1969 "$blocks != $orig_blocks"
1970 local size=$(stat -c "%s" $f)
1971 [ $size -eq $orig_size ] ||
1972 error "$f: wrong size after archive: $size != $orig_size"
1974 # Release and check states
1975 $LFS hsm_release $f || error "could not release file"
1976 check_hsm_flags $f "0x0000000d"
1978 blocks=$(stat -c "%b" $f)
1979 [ $blocks -gt 5 ] &&
1980 error "$f: too many blocks after release: $blocks > 5"
1981 size=$(stat -c "%s" $f)
1982 [ $size -ne $orig_size ] &&
1983 error "$f: wrong size after release: $size != $orig_size"
1985 # Check we can release an file without stripe info
1989 check_hsm_flags $f "0x00000000"
1990 $LFS hsm_archive $f || error "could not archive file"
1991 wait_request_state $fid ARCHIVE SUCCEED
1993 # Release and check states
1994 $LFS hsm_release $f || error "could not release file"
1995 check_hsm_flags $f "0x0000000d"
1997 # Release again a file that is already released is OK
1998 $LFS hsm_release $f || fail "second release should succeed"
1999 check_hsm_flags $f "0x0000000d"
2001 stop_full_debug_logging
2003 run_test 21 "Simple release tests"
2006 # test needs a running copytool
2009 local f=$DIR/$tdir/test_release
2010 local swap=$DIR/$tdir/test_swap
2012 # Create a file and check its states
2013 local fid=$(create_small_file $f)
2014 check_hsm_flags $f "0x00000000"
2016 $LFS hsm_archive $f || error "could not archive file"
2017 wait_request_state $fid ARCHIVE SUCCEED
2019 # Release and check states
2020 $LFS hsm_release $f || error "could not release file"
2021 check_hsm_flags $f "0x0000000d"
2023 create_small_file $swap
2024 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2028 run_test 22 "Could not swap a release file"
2031 # test needs a running copytool
2034 local f=$DIR/$tdir/test_mtime
2036 # Create a file and check its states
2037 local fid=$(create_small_file $f)
2038 check_hsm_flags $f "0x00000000"
2040 $LFS hsm_archive $f || error "could not archive file"
2041 wait_request_state $fid ARCHIVE SUCCEED
2043 # Set modification time in the past
2044 touch -m -a -d @978261179 $f
2046 # Release and check states
2047 $LFS hsm_release $f || error "could not release file"
2048 check_hsm_flags $f "0x0000000d"
2050 local MTIME=$(stat -c "%Y" $f)
2051 local ATIME=$(stat -c "%X" $f)
2052 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2053 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2055 run_test 23 "Release does not change a/mtime (utime)"
2058 local file=$DIR/$tdir/$tfile
2067 # test needs a running copytool
2070 fid=$(create_small_file $file)
2072 # Create a file and check its states
2073 check_hsm_flags $file "0x00000000"
2075 # Ensure atime is less than mtime and ctime.
2079 atime0=$(stat -c "%X" $file)
2080 mtime0=$(stat -c "%Y" $file)
2081 ctime0=$(stat -c "%Z" $file)
2083 [ $atime0 -lt $mtime0 ] ||
2084 error "atime $atime0 is not less than mtime $mtime0"
2086 [ $atime0 -lt $ctime0 ] ||
2087 error "atime $atime0 is not less than ctime $ctime0"
2089 # Archive should not change any timestamps.
2090 $LFS hsm_archive $file || error "cannot archive '$file'"
2091 wait_request_state $fid ARCHIVE SUCCEED
2093 atime1=$(stat -c "%X" $file)
2094 mtime1=$(stat -c "%Y" $file)
2095 ctime1=$(stat -c "%Z" $file)
2097 [ $atime0 -eq $atime1 ] ||
2098 error "archive changed atime from $atime0 to $atime1"
2100 [ $mtime0 -eq $mtime1 ] ||
2101 error "archive changed mtime from $mtime0 to $mtime1"
2103 [ $ctime0 -eq $ctime1 ] ||
2104 error "archive changed ctime from $ctime0 to $ctime1"
2106 # Release should not change any timestamps.
2107 $LFS hsm_release $file || error "cannot release '$file'"
2108 check_hsm_flags $file "0x0000000d"
2110 atime1=$(stat -c "%X" $file)
2111 mtime1=$(stat -c "%Y" $file)
2112 ctime1=$(stat -c "%Z" $file)
2114 [ $atime0 -eq $atime1 ] ||
2115 error "release changed atime from $atime0 to $atime1"
2117 [ $mtime0 -eq $mtime1 ] ||
2118 error "release changed mtime from $mtime0 to $mtime1"
2120 [ $ctime0 -eq $ctime1 ] ||
2121 error "release changed ctime from $ctime0 to $ctime1"
2123 # Restore should not change any timestamps.
2124 $LFS hsm_restore $file
2125 wait_request_state $fid RESTORE SUCCEED
2127 atime1=$(stat -c "%X" $file)
2128 mtime1=$(stat -c "%Y" $file)
2129 ctime1=$(stat -c "%Z" $file)
2131 [ $atime0 -eq $atime1 ] ||
2132 error "restore changed atime from $atime0 to $atime1"
2134 [ $mtime0 -eq $mtime1 ] ||
2135 error "restore changed mtime from $mtime0 to $mtime1"
2137 [ $ctime0 -eq $ctime1 ] ||
2138 error "restore changed ctime from $ctime0 to $ctime1"
2141 wait_copytools || error "Copytools failed to stop"
2143 # Once more, after unmount and mount.
2144 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2145 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2147 atime1=$(stat -c "%X" $file)
2148 mtime1=$(stat -c "%Y" $file)
2149 ctime1=$(stat -c "%Z" $file)
2151 [ $atime0 -eq $atime1 ] ||
2152 error "remount changed atime from $atime0 to $atime1"
2154 [ $mtime0 -eq $mtime1 ] ||
2155 error "remount changed mtime from $mtime0 to $mtime1"
2157 [ $ctime0 -eq $ctime1 ] ||
2158 error "remount changed ctime from $ctime0 to $ctime1"
2160 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2163 local file=$DIR/$tdir/$tfile
2169 # Test needs a running copytool.
2172 # Check that root can do HSM actions on a regular user's file.
2173 fid=$(create_small_file $file)
2174 sum0=$(md5sum $file)
2176 chown $RUNAS_ID:$RUNAS_GID $file ||
2177 error "cannot chown '$file' to '$RUNAS_ID'"
2179 chmod ugo-w $DIR/$tdir ||
2180 error "cannot chmod '$DIR/$tdir'"
2182 $LFS hsm_archive $file
2183 wait_request_state $fid ARCHIVE SUCCEED
2185 $LFS hsm_release $file
2186 check_hsm_flags $file "0x0000000d"
2188 $LFS hsm_restore $file
2189 wait_request_state $fid RESTORE SUCCEED
2191 # Check that ordinary user can get HSM state.
2192 $RUNAS $LFS hsm_state $file ||
2193 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2195 $LFS hsm_release $file
2196 check_hsm_flags $file "0x0000000d"
2198 # Check that ordinary user can accessed released file.
2199 sum1=$($RUNAS md5sum $file) ||
2200 error "user '$RUNAS_ID' cannot read '$file'"
2202 [ "$sum0" == "$sum1" ] ||
2203 error "md5sum mismatch for '$file'"
2205 run_test 24b "root can archive, release, and restore user files"
2208 local file=$DIR/$tdir/$tfile
2209 local action=archive
2214 # test needs a running copytool
2219 # Save the default masks and check that cleanup_24c will
2220 # restore the request masks correctly.
2221 user_save=$(get_hsm_param user_request_mask)
2222 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2223 group_save=$(get_hsm_param group_request_mask)
2224 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2225 other_save=$(get_hsm_param other_request_mask)
2226 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2228 [ "$user_save" == RESTORE ] ||
2229 error "user_request_mask is '$user_save' expected 'RESTORE'"
2230 [ "$group_save" == RESTORE ] ||
2231 error "group_request_mask is '$group_save' expected 'RESTORE'"
2232 [ "$other_save" == RESTORE ] ||
2233 error "other_request_mask is '$other_save' expected 'RESTORE'"
2236 create_small_file $file
2237 chown $RUNAS_ID:nobody $file ||
2238 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2240 $RUNAS $LFS hsm_$action $file &&
2241 error "$action by user should fail"
2243 set_hsm_param user_request_mask $action
2244 $RUNAS $LFS hsm_$action $file ||
2245 error "$action by user should succeed"
2248 create_small_file $file
2249 chown nobody:$RUNAS_GID $file ||
2250 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2252 $RUNAS $LFS hsm_$action $file &&
2253 error "$action by group should fail"
2255 set_hsm_param group_request_mask $action
2256 $RUNAS $LFS hsm_$action $file ||
2257 error "$action by group should succeed"
2260 create_small_file $file
2261 chown nobody:nobody $file ||
2262 error "cannot chown '$file' to 'nobody:nobody'"
2264 $RUNAS $LFS hsm_$action $file &&
2265 error "$action by other should fail"
2267 set_hsm_param other_request_mask $action
2268 $RUNAS $LFS hsm_$action $file ||
2269 error "$action by other should succeed"
2271 run_test 24c "check that user,group,other request masks work"
2274 local file1=$DIR/$tdir/$tfile
2275 local file2=$DIR2/$tdir/$tfile
2279 fid1=$(create_small_file $file1)
2282 $LFS getstripe $file1
2284 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2285 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2286 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2288 copytool setup -m "$MOUNT3"
2290 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2291 mount -o remount,ro $MOUNT2
2293 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2295 fid2=$(path2fid $file2)
2296 [ "$fid1" == "$fid2" ] ||
2297 error "FID mismatch '$fid1' != '$fid2'"
2299 $LFS hsm_archive $file2 &&
2300 error "archive should fail on read-only mount"
2301 check_hsm_flags $file1 "0x00000000"
2303 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2304 wait_request_state $fid1 ARCHIVE SUCCEED
2306 $LFS hsm_release $file1
2307 $LFS hsm_restore $file2
2308 wait_request_state $fid1 RESTORE SUCCEED
2310 $LFS hsm_release $file1 || error "cannot release '$file1'"
2311 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2313 $LFS hsm_release $file2 &&
2314 error "release should fail on read-only mount"
2318 run_test 24d "check that read-only mounts are respected"
2323 local f=$DIR/$tdir/$tfile
2326 fid=$(create_small_file $f) || error "cannot create $f"
2327 $LFS hsm_archive $f || error "cannot archive $f"
2328 wait_request_state $fid ARCHIVE SUCCEED
2329 $LFS hsm_release $f || error "cannot release $f"
2330 while ! $LFS hsm_state $f | grep released; do
2334 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2336 run_test 24e "tar succeeds on HSM released files" # LU-6213
2339 # test needs a running copytool
2342 mkdir -p $DIR/$tdir/d1
2343 local f=$DIR/$tdir/$tfile
2344 local fid=$(copy_file /etc/hosts $f)
2347 $LFS hsm_archive $f ||
2348 error "hsm_archive failed"
2349 wait_request_state $fid ARCHIVE SUCCEED
2350 $LFS hsm_release $f || error "cannot release $f"
2351 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2354 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2355 error "Can not recover the tar contents"
2357 echo "Sum0 = $sum0, sum1 = $sum1"
2358 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2360 run_test 24f "root can archive, release, and restore tar files"
2363 # test needs a running copytool
2367 copy2archive /etc/hosts $tdir/$tfile
2369 local f=$DIR/$tdir/$tfile
2371 import_file $tdir/$tfile $f
2373 $LFS hsm_set --lost $f
2378 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2382 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2383 " (Operation not permitted)"
2386 # test needs a running copytool
2391 local f=$DIR/$tdir/$tfile
2392 local fid=$(copy_file /etc/passwd $f)
2394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2395 wait_request_state $fid ARCHIVE SUCCEED
2398 $LFS hsm_set --lost $f
2402 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2404 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2405 " (Operation not permitted)"
2408 # test needs a running copytool
2411 local f=$DIR/$tdir/$tfile
2413 fid=$(make_custom_file_for_progress $f 39 1000000)
2414 [ $? != 0 ] && skip "not enough free space" && return
2416 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2417 wait_request_state $fid ARCHIVE SUCCEED
2420 wait_request_state $fid REMOVE SUCCEED
2422 check_hsm_flags $f "0x00000000"
2424 run_test 26 "Remove the archive of a valid file"
2427 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2428 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2430 # test needs a running copytool
2434 local f=$DIR/$tdir/$tfile
2435 local fid=$(copy_file /etc/passwd $f)
2437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2438 wait_request_state $fid ARCHIVE SUCCEED
2440 local f2=$DIR/$tdir/${tfile}_2
2441 local fid2=$(copy_file /etc/passwd $f2)
2443 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2444 wait_request_state $fid2 ARCHIVE SUCCEED
2446 local f3=$DIR/$tdir/${tfile}_3
2447 local fid3=$(copy_file /etc/passwd $f3)
2449 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2450 wait_request_state $fid3 ARCHIVE SUCCEED
2452 # set a long grace_delay vs short loop_period
2453 local orig_loop_period=$(get_hsm_param loop_period)
2454 local orig_grace_delay=$(get_hsm_param grace_delay)
2455 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2456 set_hsm_param loop_period 10
2457 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2458 set_hsm_param grace_delay 100
2462 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2463 set_hsm_param remove_archive_on_last_unlink 1
2465 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2470 set_hsm_param remove_archive_on_last_unlink 0
2472 wait_request_state $fid2 REMOVE SUCCEED
2474 assert_request_count $fid REMOVE 0 \
2475 "Unexpected archived data remove request for $f"
2476 assert_request_count $fid3 REMOVE 0 \
2477 "Unexpected archived data remove request for $f3"
2479 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2482 # test needs a running copytool
2486 local f=$DIR/$tdir/$tfile
2487 local fid=$(copy_file /etc/passwd $f)
2489 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2490 wait_request_state $fid ARCHIVE SUCCEED
2492 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2493 set_hsm_param remove_archive_on_last_unlink 1
2496 cdt_check_state stopped
2500 set_hsm_param remove_archive_on_last_unlink 0
2502 wait_request_state $fid REMOVE WAITING
2506 # copytool must re-register
2508 wait_copytools || error "copytool failed to stop"
2511 wait_request_state $fid REMOVE SUCCEED
2513 run_test 26b "RAoLU policy when CDT off"
2516 # test needs a running copytool
2520 local f=$DIR/$tdir/$tfile
2521 local fid=$(copy_file /etc/passwd $f)
2523 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2524 wait_request_state $fid ARCHIVE SUCCEED
2526 local f2=$DIR/$tdir/${tfile}_2
2527 local fid2=$(copy_file /etc/passwd $f2)
2529 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2530 wait_request_state $fid2 ARCHIVE SUCCEED
2532 # set a long grace_delay vs short loop_period
2533 local orig_loop_period=$(get_hsm_param loop_period)
2534 local orig_grace_delay=$(get_hsm_param grace_delay)
2535 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2536 set_hsm_param loop_period 10
2537 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2538 set_hsm_param grace_delay 100
2540 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2541 set_hsm_param remove_archive_on_last_unlink 1
2543 multiop_bg_pause $f O_c || error "open $f failed"
2549 wait_request_state $fid2 REMOVE SUCCEED
2550 assert_request_count $fid REMOVE 0 \
2551 "Unexpected archived data remove request for $f"
2553 kill -USR1 $pid || error "multiop early exit"
2554 # should reach autotest timeout if multiop fails to trap
2555 # signal, close file, and exit ...
2558 set_hsm_param remove_archive_on_last_unlink 0
2560 wait_request_state $fid REMOVE SUCCEED
2562 run_test 26c "RAoLU effective when file closed"
2565 # test needs a running copytool
2569 local f=$DIR/$tdir/$tfile
2570 local fid=$(copy_file /etc/motd $f 1)
2572 $LFS hsm_archive $f || error "could not archive file"
2573 wait_request_state $fid ARCHIVE SUCCEED
2575 # set a long grace_delay vs short loop_period
2576 local orig_loop_period=$(get_hsm_param loop_period)
2577 local orig_grace_delay=$(get_hsm_param grace_delay)
2578 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2579 set_hsm_param loop_period 10
2580 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2581 set_hsm_param grace_delay 100
2583 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2584 set_hsm_param remove_archive_on_last_unlink 1
2586 multiop_bg_pause $f O_c || error "multiop failed"
2593 set_hsm_param remove_archive_on_last_unlink 0
2595 wait_request_state $fid REMOVE SUCCEED
2597 client_up || client_up || true
2599 kill -USR1 $MULTIPID
2600 wait $MULTIPID || error "multiop close failed"
2602 run_test 26d "RAoLU when Client eviction"
2605 # test needs a running copytool
2608 create_archive_file $tdir/$tfile
2609 local f=$DIR/$tdir/$tfile
2610 import_file $tdir/$tfile $f
2611 local fid=$(path2fid $f)
2615 [[ $? != 0 ]] || error "Remove of a released file should fail"
2619 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2622 # test needs a running copytool
2625 local f=$DIR/$tdir/$tfile
2627 fid=$(make_custom_file_for_progress $f 39 1000000)
2628 [ $? != 0 ] && skip "not enough free space" && return
2630 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2631 wait_request_state $fid ARCHIVE SUCCEED
2636 [[ $? != 0 ]] || error "Remove of a released file should fail"
2638 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2641 # test needs a running copytool
2644 local f=$DIR/$tdir/$tfile
2646 fid=$(make_custom_file_for_progress $f 39 1000000)
2647 [ $? != 0 ] && skip "not enough free space" && return
2649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2650 wait_request_state $fid ARCHIVE SUCCEED
2659 wait_request_state $fid REMOVE SUCCEED
2661 run_test 28 "Concurrent archive/file remove"
2664 # Tests --mntpath and --archive options
2667 copytool setup -m "$MOUNT" -a $archive_id
2669 # Bad archive number
2670 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2671 grep "Invalid argument" ||
2672 error "unexpected hsm_remove failure (1)"
2674 # mntpath is present but file is given
2675 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2676 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2677 error "unexpected hsm_remove failure (2)"
2679 run_test 29a "Tests --mntpath and --archive options"
2682 # test needs a running copytool
2685 local f=$DIR/$tdir/$tfile
2686 local fid=$(create_small_file $f)
2688 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2689 wait_request_state $fid ARCHIVE SUCCEED
2693 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2694 wait_request_state $fid REMOVE SUCCEED
2696 run_test 29b "Archive/delete/remove by FID from the archive."
2699 # test needs a running copytool
2702 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2703 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2704 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2706 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2707 wait_request_state $fid1 ARCHIVE SUCCEED
2708 wait_request_state $fid2 ARCHIVE SUCCEED
2709 wait_request_state $fid3 ARCHIVE SUCCEED
2711 rm -f $DIR/$tdir/$tfile-[1-3]
2713 echo $fid1 > $DIR/$tdir/list
2714 echo $fid2 >> $DIR/$tdir/list
2715 echo $fid3 >> $DIR/$tdir/list
2717 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2718 --filelist $DIR/$tdir/list
2719 wait_request_state $fid1 REMOVE SUCCEED
2720 wait_request_state $fid2 REMOVE SUCCEED
2721 wait_request_state $fid3 REMOVE SUCCEED
2723 run_test 29c "Archive/delete/remove by FID, using a file list."
2726 # test needs more than one CT
2727 needclients 3 || return 0
2733 # start all of the copytools
2734 for n in $(seq $AGTCOUNT); do
2735 copytool setup -f agt$n -a $n
2739 file=$DIR/$tdir/$tfile
2740 fid=$(create_small_file $file)
2742 $LFS hsm_archive $file
2743 wait_request_state $fid ARCHIVE SUCCEED
2744 check_hsm_flags $file "0x00000009"
2748 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2749 error "cannot hsm_remove '$fid'"
2751 # give time for CDT to handle remove request and create broadcasted
2754 # remove request has been broadcasted ?
2755 local cnt=$(get_request_count $fid REMOVE)
2756 # broadcasted requests + original
2757 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2758 error "remove not broadcasted to all CTs"
2760 # give time for CDT and CTs to handle broadcasted
2761 wait_for_loop_period
2763 # each agent serves one different archive_id, so broadcasted
2764 # hsm_remove request should only succeed once and fail at all others
2768 for n in $(seq $AGTCOUNT); do
2769 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2770 $HSM_PARAM.actions | awk \
2771 '/'$fid'.*action=REMOVE archive#='$n'/ \
2772 {print \\\$13}' | cut -f2 -d=")
2773 if [[ "$res" == "SUCCEED" ]]; then
2775 elif [[ "$res" == "FAILED" ]]; then
2780 [[ $scnt -eq 1 ]] ||
2781 error "one and only CT should have removed successfully"
2783 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2784 error "all but one CT should have failed to remove"
2786 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2787 "request to be sent once for each registered archive_id"
2790 # restore at exec cannot work on agent node (because of Linux kernel
2791 # protection of executables)
2792 needclients 2 || return 0
2794 # test needs a running copytool
2798 copy2archive /bin/true $tdir/$tfile
2800 local f=$DIR/$tdir/true
2801 import_file $tdir/$tfile $f
2803 local fid=$(path2fid $f)
2805 # set no retry action mode
2811 # remove no try action mode
2815 [[ $st == 0 ]] || error "Failed to exec a released file"
2819 run_test 30a "Restore at exec (import case)"
2822 # restore at exec cannot work on agent node (because of Linux kernel
2823 # protection of executables)
2824 needclients 2 || return 0
2826 # test needs a running copytool
2830 local f=$DIR/$tdir/true
2831 local fid=$(copy_file /bin/true $f)
2833 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2834 wait_request_state $fid ARCHIVE SUCCEED
2838 stack_trap cdt_clear_no_retry EXIT
2839 # set no retry action mode
2847 [[ $st == 0 ]] || error "Failed to exec a released file"
2849 run_test 30b "Restore at exec (release case)"
2852 needclients 2 || return 0
2854 # test needs a running copytool
2858 local f=$DIR/$tdir/SLEEP
2859 local slp_sum1=$(md5sum /bin/sleep)
2860 local fid=$(copy_file /bin/sleep $f)
2862 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2863 wait_request_state $fid ARCHIVE SUCCEED
2865 check_hsm_flags $f "0x0000000d"
2867 stack_trap cdt_clear_no_retry EXIT
2868 # set no retry action mode
2871 do_node $CLIENT2 "$f 10" &
2875 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2877 [[ $? == 0 ]] || error "Execution failed during run"
2879 if [[ $? != 0 ]]; then
2880 local slp_sum2=$(md5sum /bin/sleep)
2881 # in case sleep file is modified during the test
2882 [[ $slp_sum1 == $slp_sum2 ]] &&
2883 error "Binary overwritten during exec"
2886 check_hsm_flags $f "0x00000009"
2888 run_test 30c "Update during exec of released file must fail"
2890 restore_and_check_size() {
2893 local s=$(stat -c "%s" $f)
2895 local st=$(get_hsm_flags $f)
2899 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2901 n=$(stat -c "%s" $f)
2902 # we echo in both cases to show stat is not hang
2903 if [[ $n != $s ]]; then
2904 echo "size seen is $n != $s"
2907 echo "size seen is right: $n == $s"
2911 st=$(get_hsm_flags $f)
2913 if [[ "$st" = "0x00000009" ]]; then
2916 echo " restore is too long"
2917 wait_request_state $fid RESTORE SUCCEED
2923 # test needs a running copytool
2926 create_archive_file $tdir/$tfile
2927 local f=$DIR/$tdir/$tfile
2928 import_file $tdir/$tfile $f
2929 local fid=$($LFS path2fid $f)
2930 HSM_ARCHIVE_PURGE=false copytool_setup
2932 restore_and_check_size $f $fid
2935 [[ $err -eq 0 ]] || error "File size changed during restore"
2939 run_test 31a "Import a large file and check size during restore"
2943 # test needs a running copytool
2946 local f=$DIR/$tdir/$tfile
2948 fid=$(make_custom_file_for_progress $f 39 1000000)
2949 [ $? != 0 ] && skip "not enough free space" && return
2951 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2952 wait_request_state $fid ARCHIVE SUCCEED
2955 restore_and_check_size $f $fid
2958 [[ $err -eq 0 ]] || error "File size changed during restore"
2960 run_test 31b "Restore a large unaligned file and check size during restore"
2963 # test needs a running copytool
2966 local f=$DIR/$tdir/$tfile
2968 fid=$(make_custom_file_for_progress $f 33 1048576)
2969 [ $? != 0 ] && skip "not enough free space" && return
2971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2972 wait_request_state $fid ARCHIVE SUCCEED
2975 restore_and_check_size $f $fid
2978 [[ $err -eq 0 ]] || error "File size changed during restore"
2980 run_test 31c "Restore a large aligned file and check size during restore"
2983 # test needs a running copytool
2986 local f=$DIR/$tdir/$tfile
2988 fid=$(make_custom_file_for_progress $f 39 1000000)
2989 [ $? != 0 ] && skip "not enough free space" && return
2991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2992 wait_request_state $fid ARCHIVE SUCCEED
2995 # to be sure wait_all_done will not be mislead by previous tests
2998 wait_for_grace_delay
2999 # Also raise grace_delay significantly so the Canceled
3000 # Restore action will stay enough long avail.
3001 local old_grace=$(get_hsm_param grace_delay)
3002 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3003 set_hsm_param grace_delay 100
3005 md5sum $f >/dev/null &
3007 wait_request_state $fid RESTORE STARTED
3012 # Check restore trigger process was killed
3013 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3017 # instead of waiting+checking both Restore and Cancel ops
3018 # sequentially, wait for both to be finished and then check
3020 wait_all_done 100 $fid
3021 local rstate=$(get_request_state $fid RESTORE)
3022 local cstate=$(get_request_state $fid CANCEL)
3024 if [[ "$rstate" == "CANCELED" ]] ; then
3025 [[ "$cstate" == "SUCCEED" ]] ||
3026 error "Restore state is CANCELED and Cancel state " \
3027 "is not SUCCEED but $cstate"
3028 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3029 elif [[ "$rstate" == "SUCCEED" ]] ; then
3030 [[ "$cstate" == "FAILED" ]] ||
3031 error "Restore state is SUCCEED and Cancel state " \
3032 "is not FAILED but $cstate"
3033 echo "Restore state is SUCCEED, Cancel state is FAILED"
3035 error "Restore state is $rstate and Cancel state is $cstate"
3039 error "Cannot kill process waiting for restore ($killed)"
3041 run_test 33 "Kill a restore waiting process"
3044 # test needs a running copytool
3047 local f=$DIR/$tdir/$tfile
3049 fid=$(make_custom_file_for_progress $f 39 1000000)
3050 [ $? != 0 ] && skip "not enough free space" && return
3052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3053 wait_request_state $fid ARCHIVE SUCCEED
3056 md5sum $f >/dev/null &
3058 wait_request_state $fid RESTORE STARTED
3060 rm $f || error "rm $f failed"
3061 # rm must not block during restore
3062 wait_request_state $fid RESTORE STARTED
3064 wait_request_state $fid RESTORE SUCCEED
3065 # check md5sum pgm finished
3066 local there=$(ps -o pid,comm hp $pid >/dev/null)
3067 [[ -z $there ]] || error "Restore initiator does not exit"
3069 wait $pid || error "Restore initiator failed with $?"
3071 run_test 34 "Remove file during restore"
3074 # test needs a running copytool
3077 local f=$DIR/$tdir/$tfile
3078 local f1=$DIR/$tdir/$tfile-1
3080 fid=$(make_custom_file_for_progress $f 39 1000000)
3081 [ $? != 0 ] && skip "not enough free space" && return
3083 local fid1=$(copy_file /etc/passwd $f1)
3084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3085 wait_request_state $fid ARCHIVE SUCCEED
3088 md5sum $f >/dev/null &
3090 wait_request_state $fid RESTORE STARTED
3092 mv $f1 $f || error "mv $f1 $f failed"
3093 # mv must not block during restore
3094 wait_request_state $fid RESTORE STARTED
3096 wait_request_state $fid RESTORE SUCCEED
3097 # check md5sum pgm finished
3098 local there=$(ps -o pid,comm hp $pid >/dev/null)
3099 [[ -z $there ]] || error "Restore initiator does not exit"
3101 wait $pid || error "Restore initiator failed with $?"
3104 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3106 run_test 35 "Overwrite file during restore"
3109 # test needs a running copytool
3112 local f=$DIR/$tdir/$tfile
3114 fid=$(make_custom_file_for_progress $f 39 1000000)
3115 [ $? != 0 ] && skip "not enough free space" && return
3117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3118 wait_request_state $fid ARCHIVE SUCCEED
3121 md5sum $f >/dev/null &
3123 wait_request_state $fid RESTORE STARTED
3126 # rm must not block during restore
3127 wait_request_state $fid RESTORE STARTED
3129 wait_request_state $fid RESTORE SUCCEED
3130 # check md5sum pgm finished
3131 local there=$(ps -o pid,comm hp $pid >/dev/null)
3133 error "Restore initiator does not exit"
3135 wait $pid || error "Restore initiator failed with $?"
3137 run_test 36 "Move file during restore"
3140 # LU-5683: check that an archived dirty file can be rearchived.
3143 local f=$DIR/$tdir/$tfile
3146 fid=$(create_small_file $f) || error "cannot create small file"
3148 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3149 wait_request_state $fid ARCHIVE SUCCEED
3150 $LFS hsm_release $f || error "cannot release $f"
3152 # Allow previous archive request to expire from the actions log.
3153 wait_for_grace_delay
3156 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3158 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3159 wait_request_state $fid ARCHIVE SUCCEED
3161 run_test 37 "re-archive a dirty file"
3168 for n in $(seq 1 $count); do
3169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3171 echo "$count archive requests submitted"
3175 local stream_count=4
3176 local file_count=100
3178 local f=$DIR/$tdir/$tfile
3182 local max_requests=$(get_hsm_param max_requests)
3184 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3185 # Increase the number of HSM request that can be performed in
3186 # parallel. With the coordinator running once per second, this
3187 # also limits the number of requests per seconds that can be
3188 # performed, so we pick a decent number. But we also need to keep
3189 # that number low because the copytool has no rate limit and will
3190 # fail some requests if if gets too many at once.
3191 set_hsm_param max_requests 300
3193 for i in $(seq 1 $file_count); do
3194 for p in $(seq 1 $stream_count); do
3195 fid=$(copy_file /etc/hosts $f.$p.$i)
3201 # to be sure wait_all_done will not be mislead by previous tests
3203 wait_for_grace_delay
3205 # start archive streams in background (archive files in parallel)
3206 for p in $(seq 1 $stream_count); do
3207 multi_archive $f.$p $file_count &
3210 echo -n "Wait for all requests being enqueued..."
3215 run_test 40 "Parallel archive requests"
3218 # test needs a running copytool
3222 local f=$DIR/$tdir/$tfile
3223 local fid=$(copy_file /etc/motd $f 1)
3225 $LFS hsm_archive $f || error "could not archive file"
3226 wait_request_state $fid ARCHIVE SUCCEED
3227 check_hsm_flags $f "0x00000009"
3229 multiop_bg_pause $f O_c || error "multiop failed"
3233 client_up || client_up || true
3235 kill -USR1 $MULTIPID
3236 wait $MULTIPID || error "multiop close failed"
3238 check_hsm_flags $f "0x0000000b"
3240 run_test 52 "Opened for write file on an evicted client should be set dirty"
3243 # test needs a running copytool
3247 local f=$DIR/$tdir/$tfile
3248 local fid=$(copy_file /etc/motd $f 1)
3250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3251 error "could not archive file"
3252 wait_request_state $fid ARCHIVE SUCCEED
3253 check_hsm_flags $f "0x00000009"
3255 multiop_bg_pause $f o_c || error "multiop failed"
3259 client_up || client_up || true
3261 kill -USR1 $MULTIPID
3262 wait $MULTIPID || error "multiop close failed"
3264 check_hsm_flags $f "0x00000009"
3266 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3269 # test needs a running copytool
3272 local f=$DIR/$tdir/$tfile
3273 local fid=$(make_custom_file_for_progress $f 39 1000000)
3275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3276 error "could not archive file"
3277 wait_request_state $fid ARCHIVE STARTED
3279 check_hsm_flags $f "0x00000001"
3281 stack_trap "cdt_clear_no_retry" EXIT
3282 # Avoid coordinator resending this request as soon it has failed.
3287 wait_request_state $fid ARCHIVE FAILED
3289 check_hsm_flags $f "0x00000003"
3291 run_test 54 "Write during an archive cancels it"
3294 # test needs a running copytool
3297 local f=$DIR/$tdir/$tfile
3298 local fid=$(make_custom_file_for_progress $f 39 1000000)
3300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3301 error "could not archive file"
3302 wait_request_state $fid ARCHIVE STARTED
3304 check_hsm_flags $f "0x00000001"
3306 stack_trap "cdt_clear_no_retry" EXIT
3307 # Avoid coordinator resending this request as soon it has failed.
3310 $TRUNCATE $f 1024 || error "truncate failed"
3312 wait_request_state $fid ARCHIVE FAILED
3314 check_hsm_flags $f "0x00000003"
3316 run_test 55 "Truncate during an archive cancels it"
3319 # test needs a running copytool
3322 local f=$DIR/$tdir/$tfile
3324 fid=$(make_custom_file_for_progress $f 39 1000000)
3325 [ $? != 0 ] && skip "not enough free space" && return
3327 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3328 error "could not archive file"
3329 wait_request_state $fid ARCHIVE STARTED
3331 check_hsm_flags $f "0x00000001"
3333 # Change metadata and sync to be sure we are not changing only
3338 wait_request_state $fid ARCHIVE SUCCEED
3340 check_hsm_flags $f "0x00000009"
3342 run_test 56 "Setattr during an archive is ok"
3345 # Need one client for I/O, one for request
3346 needclients 2 || return 0
3348 # test needs a running copytool
3352 local f=$DIR/$tdir/test_archive_remote
3353 # Create a file on a remote node
3354 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3355 "count=2 conv=fsync"
3358 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3359 error "hsm_archive failed"
3360 local fid=$(path2fid $f)
3361 wait_request_state $fid ARCHIVE SUCCEED
3363 # Release and implicit restore it
3364 do_node $CLIENT2 "$LFS hsm_release $f" ||
3365 error "hsm_release failed"
3366 do_node $CLIENT2 "md5sum $f" ||
3367 error "hsm_restore failed"
3369 wait_request_state $fid RESTORE SUCCEED
3371 run_test 57 "Archive a file with dirty cache on another node"
3373 truncate_released_file() {
3377 local sz=$(stat -c %s $src_file)
3378 local f=$DIR/$tdir/$tfile
3379 local fid=$(copy_file $1 $f)
3383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3384 error "could not archive file"
3385 wait_request_state $fid ARCHIVE SUCCEED
3387 $LFS hsm_release $f || error "could not release file"
3389 $TRUNCATE $f $trunc_to || error "truncate failed"
3392 local sz1=$(stat -c %s $f)
3393 [[ $sz1 == $trunc_to ]] ||
3394 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3397 check_hsm_flags $f "0x0000000b"
3399 local state=$(get_request_state $fid RESTORE)
3400 [[ "$state" == "SUCCEED" ]] ||
3401 error "truncate $sz does not trig restore, state = $state"
3403 $TRUNCATE $ref $trunc_to
3404 cmp $ref $f || error "file data wrong after truncate"
3410 # test needs a running copytool
3415 local sz=$(stat -c %s /etc/passwd)
3417 echo "truncate up from $sz to $((sz*2))"
3418 truncate_released_file /etc/passwd $((sz*2))
3420 echo "truncate down from $sz to $((sz/2))"
3421 truncate_released_file /etc/passwd $((sz/2))
3423 echo "truncate to 0"
3424 truncate_released_file /etc/passwd 0
3426 run_test 58 "Truncate a released file will trigger restore"
3430 local server_version=$(lustre_version_code $SINGLEMDS)
3431 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3432 skip "Need MDS version at least 2.7.63" && return
3435 $MCREATE $DIR/$tfile || error "mcreate failed"
3436 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3437 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3438 fid=$(path2fid $DIR/$tfile)
3439 wait_request_state $fid ARCHIVE SUCCEED
3440 $LFS hsm_release $DIR/$tfile || error "release failed"
3442 run_test 59 "Release stripeless file with non-zero size"
3445 # This test validates the fix for LU-4512. Ensure that the -u
3446 # option changes the progress reporting interval from the
3447 # default (30 seconds) to the user-specified interval.
3449 local progress_timeout=$((interval * 4))
3451 copytool setup -b 1 --update-interval $interval
3453 local f=$DIR/$tdir/$tfile
3455 fid=$(make_custom_file_for_progress $f 10)
3456 [ $? != 0 ] && skip "not enough free space" && return
3459 local mdt=${MDT_PREFIX}${mdtidx}
3460 local mds=mds$((mdtidx + 1))
3462 # Wait for copytool to register
3463 wait_update_facet $mds \
3464 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3465 uuid 100 || error "coyptool failed to register with $mdt"
3467 local start_at=$(date +%s)
3468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3469 error "could not archive file"
3471 local agent=$(facet_active_host $SINGLEAGT)
3472 local logfile=$(copytool_logfile $SINGLEAGT)
3474 wait_update $agent \
3475 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3476 error "copytool failed to start"
3478 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3479 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3485 echo -n "Expecting a progress update within $progress_timeout seconds... "
3487 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3488 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3489 echo "$RESULT bytes copied in $WAIT seconds."
3491 elif [ $WAIT -ge $progress_timeout ]; then
3492 error "Timed out waiting for progress update!"
3495 WAIT=$((WAIT + sleep))
3499 local finish_at=$(date +%s)
3500 local elapsed=$((finish_at - start_at))
3502 # Ensure that the progress update occurred within the expected window.
3503 if [ $elapsed -lt $((interval - 1)) ]; then
3504 error "Expected progress update after at least $interval seconds"
3507 echo "Wait for on going archive hsm action to complete"
3508 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3509 echo "File archiving not completed even after 10 secs"
3511 run_test 60 "Changing progress update interval from default"
3514 # test needs a running copytool
3518 local f=$DIR/$tdir/$tfile
3519 local fid=$(copy_file /etc/passwd $f)
3521 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3524 wait_request_state $fid ARCHIVE FAILED
3526 run_test 61 "Waiting archive of a removed file should fail"
3529 # test needs a new running copytool
3530 stack_trap copytool_monitor_cleanup EXIT
3531 copytool_monitor_setup
3532 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3534 # Wait for the copytool to register.
3535 wait_update --verbose $(facet_active_host mds1) \
3536 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3538 error "copytool failed to register with MDT0000"
3541 wait_copytools || error "Copytools failed to stop"
3543 local REGISTER_EVENT
3544 local UNREGISTER_EVENT
3545 while read event; do
3546 local parsed=$(parse_json_event "$event")
3547 if [ -z "$parsed" ]; then
3548 error "Copytool sent malformed event: $event"
3552 if [ $event_type == "REGISTER" ]; then
3553 REGISTER_EVENT=$event
3554 elif [ $event_type == "UNREGISTER" ]; then
3555 UNREGISTER_EVENT=$event
3557 done < <(echo $"$(get_copytool_event_log)")
3559 if [ -z "$REGISTER_EVENT" ]; then
3560 error "Copytool failed to send register event to FIFO"
3563 if [ -z "$UNREGISTER_EVENT" ]; then
3564 error "Copytool failed to send unregister event to FIFO"
3567 echo "Register/Unregister events look OK."
3569 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3572 # Bump progress interval for livelier events.
3575 # test needs a new running copytool
3576 stack_trap copytool_monitor_cleanup EXIT
3577 copytool_monitor_setup
3578 copytool setup --update-interval $interval --event-fifo \
3579 "$HSMTOOL_MONITOR_DIR/fifo"
3581 stack_trap "cdt_clear_no_retry" EXIT
3582 # Just start and stop the copytool to generate events.
3585 local f=$DIR/$tdir/$tfile
3587 fid=$(make_custom_file_for_progress $f 39 1000000)
3588 [ $? != 0 ] && skip "not enough free space" && return
3590 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3591 error "could not archive file"
3592 wait_request_state $fid ARCHIVE SUCCEED
3594 local expected_fields="event_time data_fid source_fid"
3595 expected_fields+=" total_bytes current_bytes"
3599 while read event; do
3600 # Make sure we're not getting anything from previous events.
3601 for field in $expected_fields; do
3605 local parsed=$(parse_json_event "$event")
3606 if [ -z "$parsed" ]; then
3607 error "Copytool sent malformed event: $event"
3611 if [ $event_type == "ARCHIVE_START" ]; then
3614 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3617 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3621 # Do some simple checking of the progress update events.
3622 for expected_field in $expected_fields; do
3623 if [ -z ${!expected_field+x} ]; then
3624 error "Missing $expected_field field in event"
3628 if [ $total_bytes -eq 0 ]; then
3629 error "Expected total_bytes to be > 0"
3632 # These should be identical throughout an archive
3634 if [ $source_fid != $data_fid ]; then
3635 error "Expected source_fid to equal data_fid"
3637 done < <(echo $"$(get_copytool_event_log)")
3639 if [ -z "$START_EVENT" ]; then
3640 error "Copytool failed to send archive start event to FIFO"
3643 if [ -z "$FINISH_EVENT" ]; then
3644 error "Copytool failed to send archive finish event to FIFO"
3647 echo "Archive events look OK."
3649 run_test 71 "Copytool logs JSON archive events to FIFO"
3652 # Bump progress interval for livelier events.
3655 # test needs a new running copytool
3657 copytool_monitor_setup
3658 HSMTOOL_UPDATE_INTERVAL=$interval \
3659 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3660 local test_file=$HSMTOOL_MONITOR_DIR/file
3662 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3664 do_facet $SINGLEAGT "$cmd" ||
3665 error "cannot create $test_file on $SINGLEAGT"
3666 copy2archive $test_file $tdir/$tfile
3669 local f=$DIR/$tdir/$tfile
3670 import_file $tdir/$tfile $f
3671 f=$DIR2/$tdir/$tfile
3672 echo "Verifying released state: "
3673 check_hsm_flags $f "0x0000000d"
3675 local fid=$(path2fid $f)
3677 wait_request_state $fid RESTORE SUCCEED
3679 local expected_fields="event_time data_fid source_fid"
3680 expected_fields+=" total_bytes current_bytes"
3684 while read event; do
3685 # Make sure we're not getting anything from previous events.
3686 for field in $expected_fields; do
3690 local parsed=$(parse_json_event "$event")
3691 if [ -z "$parsed" ]; then
3692 error "Copytool sent malformed event: $event"
3696 if [ $event_type == "RESTORE_START" ]; then
3698 if [ $source_fid != $data_fid ]; then
3699 error "source_fid should == data_fid at start"
3702 elif [ $event_type == "RESTORE_FINISH" ]; then
3704 if [ $source_fid != $data_fid ]; then
3705 error "source_fid should == data_fid at finish"
3708 elif [ $event_type != "RESTORE_RUNNING" ]; then
3712 # Do some simple checking of the progress update events.
3713 for expected_field in $expected_fields; do
3714 if [ -z ${!expected_field+x} ]; then
3715 error "Missing $expected_field field in event"
3719 if [ $total_bytes -eq 0 ]; then
3720 error "Expected total_bytes to be > 0"
3723 # When a restore starts out, the data fid is the same as the
3724 # source fid. After the restore has gotten going, we learn
3725 # the new data fid. Once the restore has finished, the source
3726 # fid is set to the new data fid.
3728 # We test this because some monitoring software may depend on
3729 # this behavior. If it changes, then the consumers of these
3730 # events may need to be modified.
3731 if [ $source_fid == $data_fid ]; then
3732 error "source_fid should != data_fid during restore"
3734 done < <(echo $"$(get_copytool_event_log)")
3736 if [ -z "$START_EVENT" ]; then
3737 error "Copytool failed to send restore start event to FIFO"
3740 if [ -z "$FINISH_EVENT" ]; then
3741 error "Copytool failed to send restore finish event to FIFO"
3744 echo "Restore events look OK."
3748 copytool_monitor_cleanup
3752 run_test 72 "Copytool logs JSON restore events to FIFO"
3755 file_count=51 # Max number of files constrained by LNET message size
3756 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3757 local f=$DIR/$tdir/$tfile
3758 local FILELIST=/tmp/filelist.txt
3762 for i in $(seq 1 $file_count); do
3763 fid=$(copy_file /etc/hosts $f.$i)
3764 echo $f.$i >> $FILELIST
3768 # to be sure wait_all_done will not be mislead by previous tests
3770 wait_for_grace_delay
3771 $LFS hsm_archive --filelist $FILELIST ||
3772 error "cannot archive a file list"
3774 $LFS hsm_release --filelist $FILELIST ||
3775 error "cannot release a file list"
3776 $LFS hsm_restore --filelist $FILELIST ||
3777 error "cannot restore a file list"
3780 run_test 90 "Archive/restore a file list"
3782 double_verify_reset_hsm_param() {
3784 echo "Testing $HSM_PARAM.$p"
3785 local val=$(get_hsm_param $p)
3787 local val2=$(($val * 2))
3788 set_hsm_param $p $val2
3789 val=$(get_hsm_param $p)
3790 [[ $val == $val2 ]] ||
3791 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3792 echo "Set $p to 0 must failed"
3796 set_hsm_param $p $save
3798 if [[ $rc == 0 ]]; then
3799 error "we must not be able to set $HSM_PARAM.$p to 0"
3804 double_verify_reset_hsm_param loop_period
3805 double_verify_reset_hsm_param grace_delay
3806 double_verify_reset_hsm_param active_request_timeout
3807 double_verify_reset_hsm_param max_requests
3808 double_verify_reset_hsm_param default_archive_id
3810 run_test 100 "Set coordinator /proc tunables"
3817 run_test 102 "Verify coordinator control"
3820 # test needs a running copytool
3827 for i in $(seq 1 20); do
3828 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3830 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3834 echo "Current requests"
3835 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3836 $HSM_PARAM.actions |\
3837 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3839 [[ -z "$res" ]] || error "Some request have not been canceled"
3841 run_test 103 "Purge all requests"
3846 local f=$DIR/$tdir/$tfile
3848 fid=$(make_custom_file_for_progress $f 39 1000000)
3849 [ $? != 0 ] && skip "not enough free space" && return
3851 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3852 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3853 $HSM_PARAM.actions |\
3854 grep $fid | cut -f16 -d=")
3856 [[ "$data1" == "$DATAHEX" ]] ||
3857 error "Data field in records is ($data1) and not ($DATAHEX)"
3862 wait_request_state $fid ARCHIVE SUCCEED
3864 run_test 104 "Copy tool data field"
3867 local max_requests=$(get_hsm_param max_requests)
3871 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3872 set_hsm_param max_requests 300
3875 for i in $(seq -w 1 10); do
3876 cp /etc/passwd $DIR/$tdir/$i
3877 $LFS hsm_archive $DIR/$tdir/$i
3879 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3880 $HSM_PARAM.actions |\
3881 grep WAITING | wc -l")
3885 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3886 $HSM_PARAM.actions |\
3887 grep WAITING | wc -l")
3890 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3891 error "Requests count after shutdown $reqcnt2 != "\
3892 "before shutdown $reqcnt1"
3894 run_test 105 "Restart of coordinator"
3897 # test needs a running copytool
3900 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3902 check_agent_registered $uuid
3904 search_copytools || error "No copytool found"
3907 wait_copytools || error "Copytool failed to stop"
3909 check_agent_unregistered $uuid
3912 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3913 check_agent_registered $uuid
3915 run_test 106 "Copytool register/unregister"
3918 # test needs a running copytool
3920 # create and archive file
3922 local f1=$DIR/$tdir/$tfile
3923 local fid=$(copy_file /etc/passwd $f1)
3924 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3925 wait_request_state $fid ARCHIVE SUCCEED
3926 # shutdown and restart MDS
3928 # check the copytool still gets messages from MDT
3929 local f2=$DIR/$tdir/2
3930 local fid=$(copy_file /etc/passwd $f2)
3931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3932 # main check of this sanity: this request MUST succeed
3933 wait_request_state $fid ARCHIVE SUCCEED
3935 run_test 107 "Copytool re-register after MDS restart"
3937 policy_set_and_test()
3941 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3942 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3943 [[ "$policy" == "$target" ]] ||
3944 error "Wrong policy after '$change': '$policy' != '$target'"
3948 # to force default policy setting if error
3949 CDT_POLICY_HAD_CHANGED=true
3951 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3952 local default="NonBlockingRestore [NoRetryAction]"
3953 [[ "$policy" == "$default" ]] ||
3954 error "default policy has changed,"\
3955 " '$policy' != '$default' update the test"
3956 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3957 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3958 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3959 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3960 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3961 # useless bacause we know but safer for futur changes to use real value
3962 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3963 echo "Next set_param must failed"
3964 policy_set_and_test "wrong" "$policy"
3967 echo "Back to default policy"
3968 cdt_set_sanity_policy
3970 run_test 109 "Policy display/change"
3973 # test needs a running copytool
3978 copy2archive /etc/passwd $tdir/$tfile
3980 local f=$DIR/$tdir/$tfile
3981 import_file $tdir/$tfile $f
3982 local fid=$(path2fid $f)
3984 cdt_set_non_blocking_restore
3989 wait_request_state $fid RESTORE SUCCEED
3990 cdt_clear_non_blocking_restore
3994 error "md5sum returns $st != 1, "\
3995 "should also perror ENODATA (No data available)"
3997 run_test 110a "Non blocking restore policy (import case)"
4000 # test needs a running copytool
4004 local f=$DIR/$tdir/$tfile
4005 local fid=$(copy_file /etc/passwd $f)
4006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4007 wait_request_state $fid ARCHIVE SUCCEED
4010 cdt_set_non_blocking_restore
4015 wait_request_state $fid RESTORE SUCCEED
4016 cdt_clear_non_blocking_restore
4020 error "md5sum returns $st != 1, "\
4021 "should also perror ENODATA (No data available)"
4023 run_test 110b "Non blocking restore policy (release case)"
4026 # test needs a running copytool
4030 copy2archive /etc/passwd $tdir/$tfile
4032 local f=$DIR/$tdir/$tfile
4034 import_file $tdir/$tfile $f
4035 local fid=$(path2fid $f)
4039 copytool_remove_backend $fid
4042 wait_request_state $fid RESTORE FAILED
4049 [[ $st == 0 ]] || error "Restore does not failed"
4053 run_test 111a "No retry policy (import case), restore will error"\
4054 " (No such file or directory)"
4057 # test needs a running copytool
4061 local f=$DIR/$tdir/$tfile
4062 local fid=$(copy_file /etc/passwd $f)
4064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4065 wait_request_state $fid ARCHIVE SUCCEED
4068 copytool_remove_backend $fid
4071 wait_request_state $fid RESTORE FAILED
4078 [[ $st == 0 ]] || error "Restore does not failed"
4082 run_test 111b "No retry policy (release case), restore will error"\
4083 " (No such file or directory)"
4086 # test needs a running copytool
4090 local f=$DIR/$tdir/$tfile
4091 local fid=$(copy_file /etc/passwd $f)
4093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4094 local l=$($LFS hsm_action $f)
4096 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4099 wait_request_state $fid ARCHIVE SUCCEED
4102 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4104 run_test 112 "State of recorded request"
4107 # test needs a running copytool
4110 local f=$DIR/$tdir/$tfile
4112 fid=$(make_custom_file_for_progress $f 103 1048576)
4113 [ $? != 0 ] && skip "not enough free space" && return
4115 # test with cdt on is made in test_221
4117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4118 # wait archive to register at CDT
4119 wait_request_state $fid ARCHIVE WAITING
4122 wait_request_state $fid ARCHIVE CANCELED
4123 wait_request_state $fid CANCEL SUCCEED
4125 run_test 200 "Register/Cancel archive"
4128 # test needs a running copytool
4131 local f=$DIR/$tdir/$tfile
4132 create_archive_file $tdir/$tfile
4133 import_file $tdir/$tfile $f
4134 local fid=$(path2fid $f)
4136 # test with cdt on is made in test_222
4139 # wait restore to register at CDT
4140 wait_request_state $fid RESTORE WAITING
4143 wait_request_state $fid RESTORE CANCELED
4144 wait_request_state $fid CANCEL SUCCEED
4148 run_test 201 "Register/Cancel restore"
4151 # test needs a running copytool
4154 local f=$DIR/$tdir/$tfile
4156 fid=$(make_custom_file_for_progress $f 39 1000000)
4157 [ $? != 0 ] && skip "not enough free space" && return
4159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4160 wait_request_state $fid ARCHIVE SUCCEED
4164 # wait remove to register at CDT
4165 wait_request_state $fid REMOVE WAITING
4168 wait_request_state $fid REMOVE CANCELED
4170 run_test 202 "Register/Cancel remove"
4173 # test needs a running copytool
4178 local f=$DIR/$tdir/$tfile
4179 local fid=$(copy_file /etc/passwd $f)
4183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4184 wait_request_state $fid ARCHIVE SUCCEED
4186 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4190 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4192 run_test 220 "Changelog for archive"
4195 # test needs a running copytool
4200 local f=$DIR/$tdir/$tfile
4201 local fid=$(copy_file /etc/passwd $f)
4205 # block copytool operations to allow for HSM request to be
4206 # submitted and file be unlinked (CDT will find object removed)
4209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4211 # wait request to reach CT
4212 wait_request_state $fid ARCHIVE STARTED
4218 wait_request_state $fid ARCHIVE FAILED
4220 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4225 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4227 run_test 220a "Changelog for failed archive"
4230 # test needs a running copytool
4233 local f=$DIR/$tdir/$tfile
4235 fid=$(make_custom_file_for_progress $f 103 1048576)
4236 [ $? != 0 ] && skip "not enough free space" && return
4240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4241 wait_request_state $fid ARCHIVE STARTED
4243 wait_request_state $fid ARCHIVE CANCELED
4244 wait_request_state $fid CANCEL SUCCEED
4246 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4249 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4251 run_test 221 "Changelog for archive canceled"
4254 # test needs a running copytool
4258 copy2archive /etc/passwd $tdir/$tfile
4260 local f=$DIR/$tdir/$tfile
4261 import_file $tdir/$tfile $f
4262 local fid=$(path2fid $f)
4267 wait_request_state $fid RESTORE SUCCEED
4269 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4272 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4276 run_test 222a "Changelog for explicit restore"
4279 # test needs a running copytool
4283 local f=$DIR/$tdir/$tfile
4284 local fid=$(copy_file /etc/passwd $f)
4287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4288 wait_request_state $fid ARCHIVE SUCCEED
4293 wait_request_state $fid RESTORE SUCCEED
4295 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4298 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4300 run_test 222b "Changelog for implicit restore"
4303 # test needs a running copytool
4307 copy2archive /etc/passwd $tdir/$tfile
4309 local f=$DIR/$tdir/$tfile
4310 import_file $tdir/$tfile $f
4311 local fid=$(path2fid $f)
4315 # block copytool operations to allow for HSM request to be
4316 # submitted and file be unlinked (CDT will find object removed)
4321 # wait request to reach CT
4322 wait_request_state $fid RESTORE STARTED
4328 wait_request_state $fid RESTORE FAILED
4330 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4334 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4338 run_test 222c "Changelog for failed explicit restore"
4341 # test needs a running copytool
4345 local f=$DIR/$tdir/$tfile
4346 local fid=$(copy_file /etc/passwd $f)
4349 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4350 wait_request_state $fid ARCHIVE SUCCEED
4353 copytool_remove_backend $fid
4356 wait_request_state $fid RESTORE FAILED
4358 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4362 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4366 run_test 222d "Changelog for failed implicit restore"
4369 # test needs a running copytool
4372 local f=$DIR/$tdir/$tfile
4373 create_archive_file $tdir/$tfile
4377 import_file $tdir/$tfile $f
4378 local fid=$(path2fid $f)
4381 wait_request_state $fid RESTORE STARTED
4383 wait_request_state $fid RESTORE CANCELED
4384 wait_request_state $fid CANCEL SUCCEED
4386 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4389 [[ $flags == $target ]] ||
4390 error "Changelog flag is $flags not $target"
4394 run_test 223a "Changelog for restore canceled (import case)"
4397 # test needs a running copytool
4400 local f=$DIR/$tdir/$tfile
4402 fid=$(make_custom_file_for_progress $f 39 1000000)
4403 [ $? != 0 ] && skip "not enough free space" && return
4406 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4407 wait_request_state $fid ARCHIVE SUCCEED
4410 wait_request_state $fid RESTORE STARTED
4412 wait_request_state $fid RESTORE CANCELED
4413 wait_request_state $fid CANCEL SUCCEED
4415 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4418 [[ $flags == $target ]] ||
4419 error "Changelog flag is $flags not $target"
4423 run_test 223b "Changelog for restore canceled (release case)"
4426 # test needs a running copytool
4431 local f=$DIR/$tdir/$tfile
4432 local fid=$(copy_file /etc/passwd $f)
4435 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4436 wait_request_state $fid ARCHIVE SUCCEED
4439 wait_request_state $fid REMOVE SUCCEED
4441 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4444 [[ $flags == $target ]] ||
4445 error "Changelog flag is $flags not $target"
4447 run_test 224 "Changelog for remove"
4450 # test needs a running copytool
4455 local f=$DIR/$tdir/$tfile
4456 local fid=$(copy_file /etc/passwd $f)
4459 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4460 wait_request_state $fid ARCHIVE SUCCEED
4462 copytool_remove_backend $fid
4464 # block copytool operations to allow for HSM request to be
4465 # submitted and file be unlinked (CDT will find object removed)
4470 # wait for request to reach CT
4471 wait_request_state $fid REMOVE STARTED
4477 wait_request_state $fid REMOVE FAILED
4479 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4483 [[ $flags == $target ]] ||
4484 error "Changelog flag is $flags not $target"
4488 run_test 224a "Changelog for failed remove"
4491 # test needs a running copytool
4494 # test is not usable because remove request is too fast
4495 # so it is always finished before cancel can be done ...
4496 echo "Test disabled"
4500 local f=$DIR/$tdir/$tfile
4502 fid=$(make_custom_file_for_progress $f 39 1000000)
4503 [ $? != 0 ] && skip "not enough free space" && return
4506 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4507 wait_request_state $fid ARCHIVE SUCCEED
4509 # if cdt is on, it can serve too quickly the request
4514 wait_request_state $fid REMOVE CANCELED
4515 wait_request_state $fid CANCEL SUCCEED
4517 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4518 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4519 tail -n 1 | awk '{print $5}')
4522 [[ $flags == $target ]] ||
4523 error "Changelog flag is $flags not $target"
4525 run_test 225 "Changelog for remove canceled"
4528 # test needs a running copytool
4533 local f1=$DIR/$tdir/$tfile-1
4534 local f2=$DIR/$tdir/$tfile-2
4535 local f3=$DIR/$tdir/$tfile-3
4536 local fid1=$(copy_file /etc/passwd $f1)
4537 local fid2=$(copy_file /etc/passwd $f2)
4538 copy_file /etc/passwd $f3
4541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4542 wait_request_state $fid1 ARCHIVE SUCCEED
4544 $LFS hsm_archive $f2
4545 wait_request_state $fid2 ARCHIVE SUCCEED
4547 rm $f1 || error "rm $f1 failed"
4549 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4552 [[ $flags == $target ]] ||
4553 error "Changelog flag is $flags not $target"
4555 mv $f3 $f2 || error "mv $f3 $f2 failed"
4557 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4560 [[ $flags == $target ]] ||
4561 error "Changelog flag is $flags not $target"
4563 run_test 226 "changelog for last rm/mv with exiting archive"
4565 check_flags_changes() {
4573 $LFS hsm_set --$hsm_flag $f ||
4574 error "Cannot set $hsm_flag on $f"
4575 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4576 local seen=${#flags[*]}
4578 [[ $seen == $cnt ]] ||
4579 error "set $hsm_flag: Changelog events $seen != $cnt"
4580 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4581 error "set $hsm_flag: Changelog flags are "\
4582 "${flags[$((cnt - 1))]} not $target"
4584 $LFS hsm_clear --$hsm_flag $f ||
4585 error "Cannot clear $hsm_flag on $f"
4586 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4589 [[ $cnt == $seen ]] ||
4590 error "clear $hsm_flag: Changelog events $seen != $cnt"
4592 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4593 error "clear $hsm_flag: Changelog flag is "\
4594 "${flags[$((cnt - 1))]} not $target"
4598 # test needs a running copytool
4605 for i in norelease noarchive exists archived
4607 local f=$DIR/$tdir/$tfile-$i
4608 local fid=$(copy_file /etc/passwd $f)
4609 check_flags_changes $f $fid $i 0 1
4612 f=$DIR/$tdir/$tfile---lost
4613 fid=$(copy_file /etc/passwd $f)
4614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4615 wait_request_state $fid ARCHIVE SUCCEED
4616 check_flags_changes $f $fid lost 3 1
4618 run_test 227 "changelog when explicit setting of HSM flags"
4621 # test needs a running copytool
4624 local fid=$(create_small_sync_file $DIR/$tfile)
4625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4626 wait_request_state $fid ARCHIVE SUCCEED
4628 $LFS hsm_release $DIR/$tfile
4629 check_hsm_flags $DIR/$tfile "0x0000000d"
4631 filefrag $DIR/$tfile | grep " 1 extent found" ||
4632 error "filefrag on released file must return only one extent"
4634 # only newer versions of cp detect sparse files by stat/FIEMAP
4636 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4637 error "copying $DIR/$tfile"
4638 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4640 $LFS hsm_release $DIR/$tfile
4641 check_hsm_flags $DIR/$tfile "0x0000000d"
4643 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4645 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4647 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4648 error "comparing untarred $DIR/$tfile"
4650 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4651 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4653 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4656 # test needs a running copytool
4660 local maxrequest=$(get_hsm_param max_requests)
4661 local rqcnt=$(($maxrequest * 3))
4665 for i in $(seq -w 1 $rqcnt); do
4667 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4669 # we do it in 2 steps, so all requests arrive at the same time
4670 for i in $(seq -w 1 $rqcnt); do
4671 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4676 while [[ $cnt != 0 || $wt != 0 ]]; do
4678 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4679 $HSM_PARAM.actions |\
4680 grep STARTED | grep -v CANCEL | wc -l")
4681 [[ $cnt -le $maxrequest ]] ||
4682 error "$cnt > $maxrequest too many started requests"
4683 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4684 $HSM_PARAM.actions |\
4685 grep WAITING | wc -l")
4686 echo "max=$maxrequest started=$cnt waiting=$wt"
4689 run_test 250 "Coordinator max request"
4692 # test needs a running copytool
4695 local f=$DIR/$tdir/$tfile
4697 fid=$(make_custom_file_for_progress $f 103 1048576)
4698 [ $? != 0 ] && skip "not enough free space" && return
4701 # to have a short test
4702 local old_to=$(get_hsm_param active_request_timeout)
4703 set_hsm_param active_request_timeout 4
4704 # to be sure the cdt will wake up frequently so
4705 # it will be able to cancel the "old" request
4706 local old_loop=$(get_hsm_param loop_period)
4707 set_hsm_param loop_period 2
4710 # clear locks to avoid extra delay caused by flush/cancel
4711 # and thus prevent early copytool death to timeout.
4712 cancel_lru_locks osc
4714 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4715 wait_request_state $fid ARCHIVE STARTED
4717 wait_request_state $fid ARCHIVE CANCELED
4719 set_hsm_param active_request_timeout $old_to
4720 set_hsm_param loop_period $old_loop
4722 run_test 251 "Coordinator request timeout"
4725 # test needs a running copytool
4729 local f=$DIR/$tdir/$tfile
4730 local fid=$(make_custom_file_for_progress $f 103 1048576)
4733 # to have a short test
4734 local old_timeout=$(get_hsm_param active_request_timeout)
4735 stack_trap "set_hsm_param active_request_timeout $old_timeout" EXIT
4736 set_hsm_param active_request_timeout 20
4737 # to be sure the cdt will wake up frequently so
4738 # it will be able to cancel the "old" request
4739 local old_loop_period=$(get_hsm_param loop_period)
4740 stack_trap "set_hsm_param loop_period $old_loop_period" EXIT
4741 set_hsm_param loop_period 2
4744 # clear locks to avoid extra delay caused by flush/cancel
4745 # and thus prevent early copytool death to timeout.
4746 cancel_lru_locks osc
4748 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4749 wait_request_state $fid ARCHIVE STARTED
4752 # wait but less than active_request_timeout+grace_delay
4754 wait_request_state $fid ARCHIVE CANCELED
4756 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4760 # test needs a running copytool
4764 local f=$DIR/$tdir/$tfile
4766 dd if=/dev/zero of=$f bs=1MB count=10
4767 local fid=$(path2fid $f)
4769 $LFS hsm_archive $f || error "could not archive file"
4770 wait_request_state $fid ARCHIVE SUCCEED
4772 # clear locks to discard inode data
4773 cancel_lru_locks osc
4775 #define OBD_FAIL_MDC_MERGE 0x807
4776 $LCTL set_param fail_loc=0x807
4778 #expect error here, instead of release with wrong size
4781 if ((rc == 0)); then
4782 file_size=$(stat -c '%s' $f)
4783 if ((file_size != 10485760)); then
4784 error "Wrong file size after hsm_release"
4787 echo "could not release file"
4790 run_test 253 "Check for wrong file size after release"
4794 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4795 skip "need MDS version at least 2.10.56" && return
4797 # Check that the counters are initialized to 0
4799 for request_type in archive restore remove; do
4800 count="$(get_hsm_param ${request_type}_count)" ||
4801 error "Reading ${request_type}_count failed with $?"
4803 [ "$count" -eq 0 ] ||
4804 error "Expected ${request_type}_count to be " \
4808 run_test 254a "Request counters are initialized to zero"
4812 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4813 skip "need MDS version at least 2.10.56" && return
4815 # The number of request to launch (at least 32)
4816 local request_count=$((RANDOM % 32 + 32))
4817 printf "Will launch %i requests of each type\n" "$request_count"
4819 # Launch a copytool to process requests
4822 # Set hsm.max_requests to allow starting all requests at the same time
4824 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4825 set_hsm_param max_requests "$request_count"
4829 for request_type in archive restore remove; do
4830 printf "Checking %s requests\n" "${request_type}"
4831 # Suspend the copytool to give us time to read the proc files
4834 for ((i = 0; i < $request_count; i++)); do
4835 case $request_type in
4837 create_empty_file "$DIR/$tdir/$tfile-$i" \
4841 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4844 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4847 # Give the coordinator 10 seconds to start every request
4849 while get_hsm_param actions | grep -q WAITING; do
4852 [ $timeout -gt 0 ] ||
4853 error "${request_type^} requests took too " \
4857 count="$(get_hsm_param ${request_type}_count)"
4858 [ "$count" -eq "$request_count" ] ||
4859 error "Expected '$request_count' (!= '$count') " \
4860 "active $request_type requests"
4862 # Let the copytool process the requests
4864 # Give it 10 seconds maximum
4866 while get_hsm_param actions | grep -q STARTED; do
4869 [ $timeout -gt 0 ] ||
4870 error "${request_type^} requests took too " \
4874 count="$(get_hsm_param ${request_type}_count)"
4875 [ "$count" -eq 0 ] ||
4876 error "Expected 0 (!= '$count') " \
4877 "active $request_type requests"
4880 run_test 254b "Request counters are correctly incremented and decremented"
4883 # the only way to test ondisk conf is to restart MDS ...
4884 echo "Stop coordinator and remove coordinator state at mount"
4887 # clean on disk conf set by default
4888 cdt_clear_mount_state
4889 cdt_check_state stopped
4891 # check cdt still off after umount/remount
4893 cdt_check_state stopped
4895 echo "Set coordinator start at mount, and start coordinator"
4896 cdt_set_mount_state enabled
4899 cdt_check_state enabled
4901 # check cdt still on after umount/remount
4903 cdt_check_state enabled
4905 # we are back to original state (cdt started at mount)
4907 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4910 local ai=$(get_hsm_param default_archive_id)
4911 local new=$((ai + 1))
4913 set_hsm_param default_archive_id $new -P
4915 local res=$(get_hsm_param default_archive_id)
4918 set_hsm_param default_archive_id "" "-P -d"
4920 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4922 run_test 301 "HSM tunnable are persistent"
4925 local ai=$(get_hsm_param default_archive_id)
4926 local new=$((ai + 1))
4931 set_hsm_param default_archive_id $new -P
4934 for mdtno in $(seq 1 $MDSCOUNT); do
4939 cdt_check_state enabled
4941 local res=$(get_hsm_param default_archive_id)
4944 set_hsm_param default_archive_id "" "-P -d"
4946 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4948 run_test 302 "HSM tunnable are persistent when CDT is off"
4951 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4957 local dir_mdt0=$DIR/$tdir/mdt0
4958 local dir_mdt1=$DIR/$tdir/mdt1
4960 # create 1 dir per MDT
4961 stack_trap "rm -rf $dir_mdt0"
4962 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4963 stack_trap "rm -rf $dir_mdt1"
4964 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4966 # create 1 file in each MDT
4967 local fid1=$(create_small_file $dir_mdt0/$tfile)
4968 local fid2=$(create_small_file $dir_mdt1/$tfile)
4970 # check that hsm request on mdt0 is sent to the right MDS
4971 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4972 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4973 echo "archive successful on mdt0"
4975 # check that hsm request on mdt1 is sent to the right MDS
4976 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4977 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4978 echo "archive successful on mdt1"
4980 run_test 400 "Single request is sent to the right MDT"
4983 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4989 local dir_mdt0=$DIR/$tdir/mdt0
4990 local dir_mdt1=$DIR/$tdir/mdt1
4992 # create 1 dir per MDT
4993 stack_trap "rm -rf $dir_mdt0" EXIT
4994 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4995 stack_trap "rm -rf $dir_mdt1" EXIT
4996 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4998 # create 1 file in each MDT
4999 local fid1=$(create_small_file $dir_mdt0/$tfile)
5000 local fid2=$(create_small_file $dir_mdt1/$tfile)
5002 # check that compound requests are shunt to the rights MDTs
5003 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5004 error "lfs hsm_archive"
5005 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5006 echo "archive successful on mdt0"
5007 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5008 echo "archive successful on mdt1"
5010 run_test 401 "Compound requests split and sent to their respective MDTs"
5012 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5017 local node=$(facet_active_host $facet)
5019 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5020 awk '{print $4}'); do
5021 echo "$3 $mdc on $node"
5022 do_facet $facet "$LCTL --device $mdc $state" || return 1
5027 # deactivate all mdc on agent1
5028 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5030 copytool setup --no-fail
5032 check_agent_unregistered "uuid" # match any agent
5034 # no expected running copytool
5035 search_copytools $agent && error "Copytool start should have failed"
5038 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5040 run_test 402a "Copytool start fails if all MDTs are inactive"
5047 local f=$DIR/$tdir/$tfile
5048 touch $f || error "touch $f failed"
5049 local fid=$(path2fid $f)
5051 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5052 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5055 # give time for CDT to send request and to keep it for retry
5056 wait_for_loop_period
5058 wait_request_state $fid ARCHIVE WAITING
5060 do_facet $SINGLEAGT lctl set_param fail_loc=0
5062 # request should succeed now
5063 wait_request_state $fid ARCHIVE SUCCEED
5065 run_test 402b "CDT must retry request upon slow start of CT"
5068 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5070 local agent=$(facet_active_host $SINGLEAGT)
5072 # deactivate all mdc for MDT0001
5073 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5076 local uuid=$(get_agent_uuid $agent)
5077 # check the agent is registered on MDT0000, and not on MDT0001
5078 check_agent_registered_by_mdt $uuid 0
5079 check_agent_unregistered_by_mdt $uuid 1
5081 # check running copytool process
5082 search_copytools $agent || error "No running copytools on $agent"
5084 # reactivate all mdc for MDT0001
5085 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5087 # make sure the copytool is now registered to all MDTs
5088 check_agent_registered $uuid
5090 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5093 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5097 # create files on both MDT0000 and MDT0001
5100 local dir_mdt0=$DIR/$tdir/mdt0
5101 stack_trap "rm -rf $dir_mdt0" EXIT
5102 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5104 # create 1 file on mdt0
5105 local fid1=$(create_small_file $dir_mdt0/$tfile)
5107 # deactivate all mdc for MDT0001
5108 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5110 # send an HSM request for files in MDT0000
5111 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5113 # check for completion of files in MDT0000
5114 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5115 echo "archive successful on mdt0"
5117 # reactivate all mdc for MDT0001
5118 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5120 run_test 404 "Inactive MDT does not block requests for active MDTs"
5123 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5129 local striped_dir=$DIR/$tdir/striped_dir
5131 # create striped dir on all of MDTs
5132 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5134 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5135 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5136 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5137 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5139 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5140 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5141 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5142 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5144 # check that compound requests are shunt to the rights MDTs
5145 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5146 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5147 error "lfs hsm_archive"
5149 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5150 echo "archive successful on $fid1"
5151 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5152 echo "archive successful on $fid2"
5153 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5154 echo "archive successful on $fid3"
5155 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5156 echo "archive successful on $fid4"
5158 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5159 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5160 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5161 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5163 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5164 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5165 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5166 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5168 run_test 405 "archive and release under striped directory"
5171 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5173 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5174 skip "need MDS version at least 2.7.64" && return 0
5179 fid=$(create_small_file $DIR/$tdir/$tfile)
5184 $LFS hsm_archive $DIR/$tdir/$tfile
5185 wait_request_state "$fid" ARCHIVE SUCCEED
5186 $LFS hsm_release $DIR/$tdir/$tfile
5188 # Should migrate $tdir but not $tfile.
5189 $LFS mv -M1 $DIR/$tdir &&
5190 error "migrating HSM an archived file should fail"
5192 $LFS hsm_restore $DIR/$tdir/$tfile
5193 wait_request_state "$fid" RESTORE SUCCEED
5195 $LFS hsm_remove $DIR/$tdir/$tfile
5196 wait_request_state "$fid" REMOVE SUCCEED
5198 cat $DIR/$tdir/$tfile > /dev/null ||
5199 error "cannot read $DIR/$tdir/$tfile"
5201 $LFS mv -M1 $DIR/$tdir ||
5202 error "cannot complete migration after HSM remove"
5204 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5205 if ((mdt_index != 1)); then
5206 error "expected MDT index 1, got $mdt_index"
5209 # Refresh fid after migration.
5210 fid=$(path2fid $DIR/$tdir/$tfile)
5213 $LFS hsm_archive $DIR/$tdir/$tfile
5214 wait_request_state "$fid" ARCHIVE SUCCEED 1
5216 lctl set_param debug=+trace
5217 $LFS hsm_release $DIR/$tdir/$tfile ||
5218 error "cannot release $DIR/$tdir/$tfile"
5220 $LFS hsm_restore $DIR/$tdir/$tfile
5221 wait_request_state "$fid" RESTORE SUCCEED 1
5223 cat $DIR/$tdir/$tfile > /dev/null ||
5224 error "cannot read $DIR/$tdir/$tfile"
5226 run_test 406 "attempting to migrate HSM archived files is safe"
5229 needclients 2 || return 0
5230 # test needs a running copytool
5235 local f=$DIR/$tdir/$tfile
5236 local f2=$DIR2/$tdir/$tfile
5238 fid=$(make_custom_file_for_progress $f 39 1000000)
5239 [ $? != 0 ] && skip "not enough free space" && return
5241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5242 wait_request_state $fid ARCHIVE SUCCEED
5245 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5246 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5249 # 1st request holds layout lock while appropriate
5250 # RESTORE record is still not added to llog
5254 # after umount hsm_actions->O/x/x log shouldn't have
5255 # double RESTORE records like below
5256 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5257 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5259 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5262 wait_request_state $fid RESTORE SUCCEED
5264 run_test 407 "Check for double RESTORE records in llog"
5268 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5269 skip "HSM migrate is not supported" && return
5271 test_mkdir -p $DIR/$tdir
5272 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5274 run_test 500 "various LLAPI HSM tests"
5279 check_and_cleanup_lustre