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/random 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 local agent=$(facet_active_host $SINGLEAGT)
3534 local f=$DIR/$tdir/$tfile
3536 fid=$(make_custom_file_for_progress $f 20)
3537 [ $? != 0 ] && skip "not enough free space" && return
3539 local file_hash_before_archive=$(md5sum $f)
3541 wait_request_state $fid ARCHIVE SUCCEED
3544 # Run md5sum in the back ground
3546 wait_request_state $fid RESTORE STARTED
3548 # Kill copytool while md5sum is running
3549 kill_copytools $agent
3550 wait_copytools $agent || error "copytools failed to stop"
3552 echo "Copytool is stopped on $agent"
3554 wait_request_state $fid RESTORE CANCELED
3556 HSM_ARCHIVE_PURGE=false copytool_setup
3557 # md5sum triggers hsm_restore action
3558 local file_hash_after_archive=$(md5sum $f)
3559 wait_request_state $fid RESTORE SUCCEED
3561 [ "$file_hash_before_archive" = \
3562 "$file_hash_after_archive" ] ||
3563 error "Restore incomplete"
3567 run_test 62 "Stopping a copytool should cancel its requests"
3570 # test needs a new running copytool
3571 stack_trap copytool_monitor_cleanup EXIT
3572 copytool_monitor_setup
3573 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3575 # Wait for the copytool to register.
3576 wait_update --verbose $(facet_active_host mds1) \
3577 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3579 error "copytool failed to register with MDT0000"
3582 wait_copytools || error "Copytools failed to stop"
3584 local REGISTER_EVENT
3585 local UNREGISTER_EVENT
3586 while read event; do
3587 local parsed=$(parse_json_event "$event")
3588 if [ -z "$parsed" ]; then
3589 error "Copytool sent malformed event: $event"
3593 if [ $event_type == "REGISTER" ]; then
3594 REGISTER_EVENT=$event
3595 elif [ $event_type == "UNREGISTER" ]; then
3596 UNREGISTER_EVENT=$event
3598 done < <(echo $"$(get_copytool_event_log)")
3600 if [ -z "$REGISTER_EVENT" ]; then
3601 error "Copytool failed to send register event to FIFO"
3604 if [ -z "$UNREGISTER_EVENT" ]; then
3605 error "Copytool failed to send unregister event to FIFO"
3608 echo "Register/Unregister events look OK."
3610 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3613 # Bump progress interval for livelier events.
3616 # test needs a new running copytool
3617 stack_trap copytool_monitor_cleanup EXIT
3618 copytool_monitor_setup
3619 copytool setup --update-interval $interval --event-fifo \
3620 "$HSMTOOL_MONITOR_DIR/fifo"
3622 stack_trap "cdt_clear_no_retry" EXIT
3623 # Just start and stop the copytool to generate events.
3626 local f=$DIR/$tdir/$tfile
3628 fid=$(make_custom_file_for_progress $f 39 1000000)
3629 [ $? != 0 ] && skip "not enough free space" && return
3631 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3632 error "could not archive file"
3633 wait_request_state $fid ARCHIVE SUCCEED
3635 local expected_fields="event_time data_fid source_fid"
3636 expected_fields+=" total_bytes current_bytes"
3640 while read event; do
3641 # Make sure we're not getting anything from previous events.
3642 for field in $expected_fields; do
3646 local parsed=$(parse_json_event "$event")
3647 if [ -z "$parsed" ]; then
3648 error "Copytool sent malformed event: $event"
3652 if [ $event_type == "ARCHIVE_START" ]; then
3655 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3658 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3662 # Do some simple checking of the progress update events.
3663 for expected_field in $expected_fields; do
3664 if [ -z ${!expected_field+x} ]; then
3665 error "Missing $expected_field field in event"
3669 if [ $total_bytes -eq 0 ]; then
3670 error "Expected total_bytes to be > 0"
3673 # These should be identical throughout an archive
3675 if [ $source_fid != $data_fid ]; then
3676 error "Expected source_fid to equal data_fid"
3678 done < <(echo $"$(get_copytool_event_log)")
3680 if [ -z "$START_EVENT" ]; then
3681 error "Copytool failed to send archive start event to FIFO"
3684 if [ -z "$FINISH_EVENT" ]; then
3685 error "Copytool failed to send archive finish event to FIFO"
3688 echo "Archive events look OK."
3690 run_test 71 "Copytool logs JSON archive events to FIFO"
3693 # Bump progress interval for livelier events.
3696 # test needs a new running copytool
3698 copytool_monitor_setup
3699 HSMTOOL_UPDATE_INTERVAL=$interval \
3700 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3701 local test_file=$HSMTOOL_MONITOR_DIR/file
3703 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3705 do_facet $SINGLEAGT "$cmd" ||
3706 error "cannot create $test_file on $SINGLEAGT"
3707 copy2archive $test_file $tdir/$tfile
3710 local f=$DIR/$tdir/$tfile
3711 import_file $tdir/$tfile $f
3712 f=$DIR2/$tdir/$tfile
3713 echo "Verifying released state: "
3714 check_hsm_flags $f "0x0000000d"
3716 local fid=$(path2fid $f)
3718 wait_request_state $fid RESTORE SUCCEED
3720 local expected_fields="event_time data_fid source_fid"
3721 expected_fields+=" total_bytes current_bytes"
3725 while read event; do
3726 # Make sure we're not getting anything from previous events.
3727 for field in $expected_fields; do
3731 local parsed=$(parse_json_event "$event")
3732 if [ -z "$parsed" ]; then
3733 error "Copytool sent malformed event: $event"
3737 if [ $event_type == "RESTORE_START" ]; then
3739 if [ $source_fid != $data_fid ]; then
3740 error "source_fid should == data_fid at start"
3743 elif [ $event_type == "RESTORE_FINISH" ]; then
3745 if [ $source_fid != $data_fid ]; then
3746 error "source_fid should == data_fid at finish"
3749 elif [ $event_type != "RESTORE_RUNNING" ]; then
3753 # Do some simple checking of the progress update events.
3754 for expected_field in $expected_fields; do
3755 if [ -z ${!expected_field+x} ]; then
3756 error "Missing $expected_field field in event"
3760 if [ $total_bytes -eq 0 ]; then
3761 error "Expected total_bytes to be > 0"
3764 # When a restore starts out, the data fid is the same as the
3765 # source fid. After the restore has gotten going, we learn
3766 # the new data fid. Once the restore has finished, the source
3767 # fid is set to the new data fid.
3769 # We test this because some monitoring software may depend on
3770 # this behavior. If it changes, then the consumers of these
3771 # events may need to be modified.
3772 if [ $source_fid == $data_fid ]; then
3773 error "source_fid should != data_fid during restore"
3775 done < <(echo $"$(get_copytool_event_log)")
3777 if [ -z "$START_EVENT" ]; then
3778 error "Copytool failed to send restore start event to FIFO"
3781 if [ -z "$FINISH_EVENT" ]; then
3782 error "Copytool failed to send restore finish event to FIFO"
3785 echo "Restore events look OK."
3789 copytool_monitor_cleanup
3793 run_test 72 "Copytool logs JSON restore events to FIFO"
3796 file_count=51 # Max number of files constrained by LNET message size
3797 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3798 local f=$DIR/$tdir/$tfile
3799 local FILELIST=/tmp/filelist.txt
3803 for i in $(seq 1 $file_count); do
3804 fid=$(copy_file /etc/hosts $f.$i)
3805 echo $f.$i >> $FILELIST
3809 # to be sure wait_all_done will not be mislead by previous tests
3811 wait_for_grace_delay
3812 $LFS hsm_archive --filelist $FILELIST ||
3813 error "cannot archive a file list"
3815 $LFS hsm_release --filelist $FILELIST ||
3816 error "cannot release a file list"
3817 $LFS hsm_restore --filelist $FILELIST ||
3818 error "cannot restore a file list"
3821 run_test 90 "Archive/restore a file list"
3823 double_verify_reset_hsm_param() {
3825 echo "Testing $HSM_PARAM.$p"
3826 local val=$(get_hsm_param $p)
3828 local val2=$(($val * 2))
3829 set_hsm_param $p $val2
3830 val=$(get_hsm_param $p)
3831 [[ $val == $val2 ]] ||
3832 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3833 echo "Set $p to 0 must failed"
3837 set_hsm_param $p $save
3839 if [[ $rc == 0 ]]; then
3840 error "we must not be able to set $HSM_PARAM.$p to 0"
3845 double_verify_reset_hsm_param loop_period
3846 double_verify_reset_hsm_param grace_delay
3847 double_verify_reset_hsm_param active_request_timeout
3848 double_verify_reset_hsm_param max_requests
3849 double_verify_reset_hsm_param default_archive_id
3851 run_test 100 "Set coordinator /proc tunables"
3858 run_test 102 "Verify coordinator control"
3861 # test needs a running copytool
3868 for i in $(seq 1 20); do
3869 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3871 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3875 echo "Current requests"
3876 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3877 $HSM_PARAM.actions |\
3878 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3880 [[ -z "$res" ]] || error "Some request have not been canceled"
3882 run_test 103 "Purge all requests"
3887 local f=$DIR/$tdir/$tfile
3889 fid=$(make_custom_file_for_progress $f 39 1000000)
3890 [ $? != 0 ] && skip "not enough free space" && return
3892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3893 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3894 $HSM_PARAM.actions |\
3895 grep $fid | cut -f16 -d=")
3897 [[ "$data1" == "$DATAHEX" ]] ||
3898 error "Data field in records is ($data1) and not ($DATAHEX)"
3903 wait_request_state $fid ARCHIVE SUCCEED
3905 run_test 104 "Copy tool data field"
3908 local max_requests=$(get_hsm_param max_requests)
3912 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3913 set_hsm_param max_requests 300
3916 for i in $(seq -w 1 10); do
3917 cp /etc/passwd $DIR/$tdir/$i
3918 $LFS hsm_archive $DIR/$tdir/$i
3920 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3921 $HSM_PARAM.actions |\
3922 grep WAITING | wc -l")
3926 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3927 $HSM_PARAM.actions |\
3928 grep WAITING | wc -l")
3931 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3932 error "Requests count after shutdown $reqcnt2 != "\
3933 "before shutdown $reqcnt1"
3935 run_test 105 "Restart of coordinator"
3938 # test needs a running copytool
3941 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3943 check_agent_registered $uuid
3945 search_copytools || error "No copytool found"
3948 wait_copytools || error "Copytool failed to stop"
3950 check_agent_unregistered $uuid
3953 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3954 check_agent_registered $uuid
3956 run_test 106 "Copytool register/unregister"
3959 # test needs a running copytool
3961 # create and archive file
3963 local f1=$DIR/$tdir/$tfile
3964 local fid=$(copy_file /etc/passwd $f1)
3965 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3966 wait_request_state $fid ARCHIVE SUCCEED
3967 # shutdown and restart MDS
3969 # check the copytool still gets messages from MDT
3970 local f2=$DIR/$tdir/2
3971 local fid=$(copy_file /etc/passwd $f2)
3972 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3973 # main check of this sanity: this request MUST succeed
3974 wait_request_state $fid ARCHIVE SUCCEED
3976 run_test 107 "Copytool re-register after MDS restart"
3978 policy_set_and_test()
3982 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3983 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3984 [[ "$policy" == "$target" ]] ||
3985 error "Wrong policy after '$change': '$policy' != '$target'"
3989 # to force default policy setting if error
3990 CDT_POLICY_HAD_CHANGED=true
3992 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3993 local default="NonBlockingRestore [NoRetryAction]"
3994 [[ "$policy" == "$default" ]] ||
3995 error "default policy has changed,"\
3996 " '$policy' != '$default' update the test"
3997 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3998 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3999 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
4000 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
4001 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4002 # useless bacause we know but safer for futur changes to use real value
4003 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4004 echo "Next set_param must failed"
4005 policy_set_and_test "wrong" "$policy"
4008 echo "Back to default policy"
4009 cdt_set_sanity_policy
4011 run_test 109 "Policy display/change"
4014 # test needs a running copytool
4019 copy2archive /etc/passwd $tdir/$tfile
4021 local f=$DIR/$tdir/$tfile
4022 import_file $tdir/$tfile $f
4023 local fid=$(path2fid $f)
4025 cdt_set_non_blocking_restore
4030 wait_request_state $fid RESTORE SUCCEED
4031 cdt_clear_non_blocking_restore
4035 error "md5sum returns $st != 1, "\
4036 "should also perror ENODATA (No data available)"
4038 run_test 110a "Non blocking restore policy (import case)"
4041 # test needs a running copytool
4045 local f=$DIR/$tdir/$tfile
4046 local fid=$(copy_file /etc/passwd $f)
4047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4048 wait_request_state $fid ARCHIVE SUCCEED
4051 cdt_set_non_blocking_restore
4056 wait_request_state $fid RESTORE SUCCEED
4057 cdt_clear_non_blocking_restore
4061 error "md5sum returns $st != 1, "\
4062 "should also perror ENODATA (No data available)"
4064 run_test 110b "Non blocking restore policy (release case)"
4067 # test needs a running copytool
4071 copy2archive /etc/passwd $tdir/$tfile
4073 local f=$DIR/$tdir/$tfile
4075 import_file $tdir/$tfile $f
4076 local fid=$(path2fid $f)
4080 copytool_remove_backend $fid
4083 wait_request_state $fid RESTORE FAILED
4090 [[ $st == 0 ]] || error "Restore does not failed"
4094 run_test 111a "No retry policy (import case), restore will error"\
4095 " (No such file or directory)"
4098 # test needs a running copytool
4102 local f=$DIR/$tdir/$tfile
4103 local fid=$(copy_file /etc/passwd $f)
4105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4106 wait_request_state $fid ARCHIVE SUCCEED
4109 copytool_remove_backend $fid
4112 wait_request_state $fid RESTORE FAILED
4119 [[ $st == 0 ]] || error "Restore does not failed"
4123 run_test 111b "No retry policy (release case), restore will error"\
4124 " (No such file or directory)"
4127 # test needs a running copytool
4131 local f=$DIR/$tdir/$tfile
4132 local fid=$(copy_file /etc/passwd $f)
4134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4135 local l=$($LFS hsm_action $f)
4137 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4140 wait_request_state $fid ARCHIVE SUCCEED
4143 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4145 run_test 112 "State of recorded request"
4148 # test needs a running copytool
4151 local f=$DIR/$tdir/$tfile
4153 fid=$(make_custom_file_for_progress $f 103 1048576)
4154 [ $? != 0 ] && skip "not enough free space" && return
4156 # test with cdt on is made in test_221
4158 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4159 # wait archive to register at CDT
4160 wait_request_state $fid ARCHIVE WAITING
4163 wait_request_state $fid ARCHIVE CANCELED
4164 wait_request_state $fid CANCEL SUCCEED
4166 run_test 200 "Register/Cancel archive"
4169 # test needs a running copytool
4172 local f=$DIR/$tdir/$tfile
4173 create_archive_file $tdir/$tfile
4174 import_file $tdir/$tfile $f
4175 local fid=$(path2fid $f)
4177 # test with cdt on is made in test_222
4180 # wait restore to register at CDT
4181 wait_request_state $fid RESTORE WAITING
4184 wait_request_state $fid RESTORE CANCELED
4185 wait_request_state $fid CANCEL SUCCEED
4189 run_test 201 "Register/Cancel restore"
4192 # test needs a running copytool
4195 local f=$DIR/$tdir/$tfile
4197 fid=$(make_custom_file_for_progress $f 39 1000000)
4198 [ $? != 0 ] && skip "not enough free space" && return
4200 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4201 wait_request_state $fid ARCHIVE SUCCEED
4205 # wait remove to register at CDT
4206 wait_request_state $fid REMOVE WAITING
4209 wait_request_state $fid REMOVE CANCELED
4211 run_test 202 "Register/Cancel remove"
4214 # test needs a running copytool
4219 local f=$DIR/$tdir/$tfile
4220 local fid=$(copy_file /etc/passwd $f)
4224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4225 wait_request_state $fid ARCHIVE SUCCEED
4227 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4231 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4233 run_test 220 "Changelog for archive"
4236 # test needs a running copytool
4241 local f=$DIR/$tdir/$tfile
4242 local fid=$(copy_file /etc/passwd $f)
4246 # block copytool operations to allow for HSM request to be
4247 # submitted and file be unlinked (CDT will find object removed)
4250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4252 # wait request to reach CT
4253 wait_request_state $fid ARCHIVE STARTED
4259 wait_request_state $fid ARCHIVE FAILED
4261 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4266 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4268 run_test 220a "Changelog for failed archive"
4271 # test needs a running copytool
4274 local f=$DIR/$tdir/$tfile
4276 fid=$(make_custom_file_for_progress $f 103 1048576)
4277 [ $? != 0 ] && skip "not enough free space" && return
4281 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4282 wait_request_state $fid ARCHIVE STARTED
4284 wait_request_state $fid ARCHIVE CANCELED
4285 wait_request_state $fid CANCEL SUCCEED
4287 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4290 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4292 run_test 221 "Changelog for archive canceled"
4295 # test needs a running copytool
4299 copy2archive /etc/passwd $tdir/$tfile
4301 local f=$DIR/$tdir/$tfile
4302 import_file $tdir/$tfile $f
4303 local fid=$(path2fid $f)
4308 wait_request_state $fid RESTORE SUCCEED
4310 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4313 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4317 run_test 222a "Changelog for explicit restore"
4320 # test needs a running copytool
4324 local f=$DIR/$tdir/$tfile
4325 local fid=$(copy_file /etc/passwd $f)
4328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4329 wait_request_state $fid ARCHIVE SUCCEED
4334 wait_request_state $fid RESTORE SUCCEED
4336 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4339 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4341 run_test 222b "Changelog for implicit restore"
4344 # test needs a running copytool
4348 copy2archive /etc/passwd $tdir/$tfile
4350 local f=$DIR/$tdir/$tfile
4351 import_file $tdir/$tfile $f
4352 local fid=$(path2fid $f)
4356 # block copytool operations to allow for HSM request to be
4357 # submitted and file be unlinked (CDT will find object removed)
4362 # wait request to reach CT
4363 wait_request_state $fid RESTORE STARTED
4369 wait_request_state $fid RESTORE FAILED
4371 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4375 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4379 run_test 222c "Changelog for failed explicit restore"
4382 # test needs a running copytool
4386 local f=$DIR/$tdir/$tfile
4387 local fid=$(copy_file /etc/passwd $f)
4390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4391 wait_request_state $fid ARCHIVE SUCCEED
4394 copytool_remove_backend $fid
4397 wait_request_state $fid RESTORE FAILED
4399 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4403 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4407 run_test 222d "Changelog for failed implicit restore"
4410 # test needs a running copytool
4413 local f=$DIR/$tdir/$tfile
4414 create_archive_file $tdir/$tfile
4418 import_file $tdir/$tfile $f
4419 local fid=$(path2fid $f)
4422 wait_request_state $fid RESTORE STARTED
4424 wait_request_state $fid RESTORE CANCELED
4425 wait_request_state $fid CANCEL SUCCEED
4427 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4430 [[ $flags == $target ]] ||
4431 error "Changelog flag is $flags not $target"
4435 run_test 223a "Changelog for restore canceled (import case)"
4438 # test needs a running copytool
4441 local f=$DIR/$tdir/$tfile
4443 fid=$(make_custom_file_for_progress $f 39 1000000)
4444 [ $? != 0 ] && skip "not enough free space" && return
4447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4448 wait_request_state $fid ARCHIVE SUCCEED
4451 wait_request_state $fid RESTORE STARTED
4453 wait_request_state $fid RESTORE CANCELED
4454 wait_request_state $fid CANCEL SUCCEED
4456 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4459 [[ $flags == $target ]] ||
4460 error "Changelog flag is $flags not $target"
4464 run_test 223b "Changelog for restore canceled (release case)"
4467 # test needs a running copytool
4472 local f=$DIR/$tdir/$tfile
4473 local fid=$(copy_file /etc/passwd $f)
4476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4477 wait_request_state $fid ARCHIVE SUCCEED
4480 wait_request_state $fid REMOVE SUCCEED
4482 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4485 [[ $flags == $target ]] ||
4486 error "Changelog flag is $flags not $target"
4488 run_test 224 "Changelog for remove"
4491 # test needs a running copytool
4496 local f=$DIR/$tdir/$tfile
4497 local fid=$(copy_file /etc/passwd $f)
4500 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4501 wait_request_state $fid ARCHIVE SUCCEED
4503 copytool_remove_backend $fid
4505 # block copytool operations to allow for HSM request to be
4506 # submitted and file be unlinked (CDT will find object removed)
4511 # wait for request to reach CT
4512 wait_request_state $fid REMOVE STARTED
4518 wait_request_state $fid REMOVE FAILED
4520 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4524 [[ $flags == $target ]] ||
4525 error "Changelog flag is $flags not $target"
4529 run_test 224a "Changelog for failed remove"
4532 # test needs a running copytool
4535 # test is not usable because remove request is too fast
4536 # so it is always finished before cancel can be done ...
4537 echo "Test disabled"
4541 local f=$DIR/$tdir/$tfile
4543 fid=$(make_custom_file_for_progress $f 39 1000000)
4544 [ $? != 0 ] && skip "not enough free space" && return
4547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4548 wait_request_state $fid ARCHIVE SUCCEED
4550 # if cdt is on, it can serve too quickly the request
4555 wait_request_state $fid REMOVE CANCELED
4556 wait_request_state $fid CANCEL SUCCEED
4558 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4559 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4560 tail -n 1 | awk '{print $5}')
4563 [[ $flags == $target ]] ||
4564 error "Changelog flag is $flags not $target"
4566 run_test 225 "Changelog for remove canceled"
4569 # test needs a running copytool
4574 local f1=$DIR/$tdir/$tfile-1
4575 local f2=$DIR/$tdir/$tfile-2
4576 local f3=$DIR/$tdir/$tfile-3
4577 local fid1=$(copy_file /etc/passwd $f1)
4578 local fid2=$(copy_file /etc/passwd $f2)
4579 copy_file /etc/passwd $f3
4582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4583 wait_request_state $fid1 ARCHIVE SUCCEED
4585 $LFS hsm_archive $f2
4586 wait_request_state $fid2 ARCHIVE SUCCEED
4588 rm $f1 || error "rm $f1 failed"
4590 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4593 [[ $flags == $target ]] ||
4594 error "Changelog flag is $flags not $target"
4596 mv $f3 $f2 || error "mv $f3 $f2 failed"
4598 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4601 [[ $flags == $target ]] ||
4602 error "Changelog flag is $flags not $target"
4604 run_test 226 "changelog for last rm/mv with exiting archive"
4606 check_flags_changes() {
4614 $LFS hsm_set --$hsm_flag $f ||
4615 error "Cannot set $hsm_flag on $f"
4616 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4617 local seen=${#flags[*]}
4619 [[ $seen == $cnt ]] ||
4620 error "set $hsm_flag: Changelog events $seen != $cnt"
4621 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4622 error "set $hsm_flag: Changelog flags are "\
4623 "${flags[$((cnt - 1))]} not $target"
4625 $LFS hsm_clear --$hsm_flag $f ||
4626 error "Cannot clear $hsm_flag on $f"
4627 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4630 [[ $cnt == $seen ]] ||
4631 error "clear $hsm_flag: Changelog events $seen != $cnt"
4633 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4634 error "clear $hsm_flag: Changelog flag is "\
4635 "${flags[$((cnt - 1))]} not $target"
4639 # test needs a running copytool
4646 for i in norelease noarchive exists archived
4648 local f=$DIR/$tdir/$tfile-$i
4649 local fid=$(copy_file /etc/passwd $f)
4650 check_flags_changes $f $fid $i 0 1
4653 f=$DIR/$tdir/$tfile---lost
4654 fid=$(copy_file /etc/passwd $f)
4655 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4656 wait_request_state $fid ARCHIVE SUCCEED
4657 check_flags_changes $f $fid lost 3 1
4659 run_test 227 "changelog when explicit setting of HSM flags"
4662 # test needs a running copytool
4665 local fid=$(create_small_sync_file $DIR/$tfile)
4666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4667 wait_request_state $fid ARCHIVE SUCCEED
4669 $LFS hsm_release $DIR/$tfile
4670 check_hsm_flags $DIR/$tfile "0x0000000d"
4672 filefrag $DIR/$tfile | grep " 1 extent found" ||
4673 error "filefrag on released file must return only one extent"
4675 # only newer versions of cp detect sparse files by stat/FIEMAP
4677 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4678 error "copying $DIR/$tfile"
4679 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4681 $LFS hsm_release $DIR/$tfile
4682 check_hsm_flags $DIR/$tfile "0x0000000d"
4684 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4686 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4688 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4689 error "comparing untarred $DIR/$tfile"
4691 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4692 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4694 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4697 # test needs a running copytool
4701 local maxrequest=$(get_hsm_param max_requests)
4702 local rqcnt=$(($maxrequest * 3))
4706 for i in $(seq -w 1 $rqcnt); do
4708 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4710 # we do it in 2 steps, so all requests arrive at the same time
4711 for i in $(seq -w 1 $rqcnt); do
4712 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4717 while [[ $cnt != 0 || $wt != 0 ]]; do
4719 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4720 $HSM_PARAM.actions |\
4721 grep STARTED | grep -v CANCEL | wc -l")
4722 [[ $cnt -le $maxrequest ]] ||
4723 error "$cnt > $maxrequest too many started requests"
4724 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4725 $HSM_PARAM.actions |\
4726 grep WAITING | wc -l")
4727 echo "max=$maxrequest started=$cnt waiting=$wt"
4730 run_test 250 "Coordinator max request"
4733 # test needs a running copytool
4736 local f=$DIR/$tdir/$tfile
4738 fid=$(make_custom_file_for_progress $f 103 1048576)
4739 [ $? != 0 ] && skip "not enough free space" && return
4742 # to have a short test
4743 local old_to=$(get_hsm_param active_request_timeout)
4744 set_hsm_param active_request_timeout 4
4745 # to be sure the cdt will wake up frequently so
4746 # it will be able to cancel the "old" request
4747 local old_loop=$(get_hsm_param loop_period)
4748 set_hsm_param loop_period 2
4751 # clear locks to avoid extra delay caused by flush/cancel
4752 # and thus prevent early copytool death to timeout.
4753 cancel_lru_locks osc
4755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4756 wait_request_state $fid ARCHIVE STARTED
4758 wait_request_state $fid ARCHIVE CANCELED
4760 set_hsm_param active_request_timeout $old_to
4761 set_hsm_param loop_period $old_loop
4763 run_test 251 "Coordinator request timeout"
4766 # test needs a running copytool
4770 local f=$DIR/$tdir/$tfile
4771 local fid=$(make_custom_file_for_progress $f 103 1048576)
4774 # to have a short test
4775 local old_timeout=$(get_hsm_param active_request_timeout)
4776 stack_trap "set_hsm_param active_request_timeout $old_timeout" EXIT
4777 set_hsm_param active_request_timeout 20
4778 # to be sure the cdt will wake up frequently so
4779 # it will be able to cancel the "old" request
4780 local old_loop_period=$(get_hsm_param loop_period)
4781 stack_trap "set_hsm_param loop_period $old_loop_period" EXIT
4782 set_hsm_param loop_period 2
4785 # clear locks to avoid extra delay caused by flush/cancel
4786 # and thus prevent early copytool death to timeout.
4787 cancel_lru_locks osc
4789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4790 wait_request_state $fid ARCHIVE STARTED
4793 # wait but less than active_request_timeout+grace_delay
4795 wait_request_state $fid ARCHIVE CANCELED
4797 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4801 # test needs a running copytool
4805 local f=$DIR/$tdir/$tfile
4807 dd if=/dev/zero of=$f bs=1MB count=10
4808 local fid=$(path2fid $f)
4810 $LFS hsm_archive $f || error "could not archive file"
4811 wait_request_state $fid ARCHIVE SUCCEED
4813 # clear locks to discard inode data
4814 cancel_lru_locks osc
4816 #define OBD_FAIL_MDC_MERGE 0x807
4817 $LCTL set_param fail_loc=0x807
4819 #expect error here, instead of release with wrong size
4822 if ((rc == 0)); then
4823 file_size=$(stat -c '%s' $f)
4824 if ((file_size != 10485760)); then
4825 error "Wrong file size after hsm_release"
4828 echo "could not release file"
4831 run_test 253 "Check for wrong file size after release"
4834 # the only way to test ondisk conf is to restart MDS ...
4835 echo "Stop coordinator and remove coordinator state at mount"
4838 # clean on disk conf set by default
4839 cdt_clear_mount_state
4840 cdt_check_state stopped
4842 # check cdt still off after umount/remount
4844 cdt_check_state stopped
4846 echo "Set coordinator start at mount, and start coordinator"
4847 cdt_set_mount_state enabled
4850 cdt_check_state enabled
4852 # check cdt still on after umount/remount
4854 cdt_check_state enabled
4856 # we are back to original state (cdt started at mount)
4858 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4861 local ai=$(get_hsm_param default_archive_id)
4862 local new=$((ai + 1))
4864 set_hsm_param default_archive_id $new -P
4866 local res=$(get_hsm_param default_archive_id)
4869 set_hsm_param default_archive_id "" "-P -d"
4871 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4873 run_test 301 "HSM tunnable are persistent"
4876 local ai=$(get_hsm_param default_archive_id)
4877 local new=$((ai + 1))
4882 set_hsm_param default_archive_id $new -P
4885 for mdtno in $(seq 1 $MDSCOUNT); do
4890 cdt_check_state enabled
4892 local res=$(get_hsm_param default_archive_id)
4895 set_hsm_param default_archive_id "" "-P -d"
4897 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4899 run_test 302 "HSM tunnable are persistent when CDT is off"
4902 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4908 local dir_mdt0=$DIR/$tdir/mdt0
4909 local dir_mdt1=$DIR/$tdir/mdt1
4911 # create 1 dir per MDT
4912 stack_trap "rm -rf $dir_mdt0"
4913 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4914 stack_trap "rm -rf $dir_mdt1"
4915 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4917 # create 1 file in each MDT
4918 local fid1=$(create_small_file $dir_mdt0/$tfile)
4919 local fid2=$(create_small_file $dir_mdt1/$tfile)
4921 # check that hsm request on mdt0 is sent to the right MDS
4922 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4923 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4924 echo "archive successful on mdt0"
4926 # check that hsm request on mdt1 is sent to the right MDS
4927 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4928 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4929 echo "archive successful on mdt1"
4931 run_test 400 "Single request is sent to the right MDT"
4934 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4940 local dir_mdt0=$DIR/$tdir/mdt0
4941 local dir_mdt1=$DIR/$tdir/mdt1
4943 # create 1 dir per MDT
4944 stack_trap "rm -rf $dir_mdt0" EXIT
4945 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4946 stack_trap "rm -rf $dir_mdt1" EXIT
4947 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4949 # create 1 file in each MDT
4950 local fid1=$(create_small_file $dir_mdt0/$tfile)
4951 local fid2=$(create_small_file $dir_mdt1/$tfile)
4953 # check that compound requests are shunt to the rights MDTs
4954 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4955 error "lfs hsm_archive"
4956 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4957 echo "archive successful on mdt0"
4958 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4959 echo "archive successful on mdt1"
4961 run_test 401 "Compound requests split and sent to their respective MDTs"
4963 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4968 local node=$(facet_active_host $facet)
4970 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4971 awk '{print $4}'); do
4972 echo "$3 $mdc on $node"
4973 do_facet $facet "$LCTL --device $mdc $state" || return 1
4978 # deactivate all mdc on agent1
4979 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4981 copytool setup --no-fail
4983 check_agent_unregistered "uuid" # match any agent
4985 # no expected running copytool
4986 search_copytools $agent && error "Copytool start should have failed"
4989 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4991 run_test 402a "Copytool start fails if all MDTs are inactive"
4998 local f=$DIR/$tdir/$tfile
4999 touch $f || error "touch $f failed"
5000 local fid=$(path2fid $f)
5002 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5003 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5004 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5006 # give time for CDT to send request and to keep it for retry
5007 wait_for_loop_period
5009 wait_request_state $fid ARCHIVE WAITING
5011 do_facet $SINGLEAGT lctl set_param fail_loc=0
5013 # request should succeed now
5014 wait_request_state $fid ARCHIVE SUCCEED
5016 run_test 402b "CDT must retry request upon slow start of CT"
5019 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5021 local agent=$(facet_active_host $SINGLEAGT)
5023 # deactivate all mdc for MDT0001
5024 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5027 local uuid=$(get_agent_uuid $agent)
5028 # check the agent is registered on MDT0000, and not on MDT0001
5029 check_agent_registered_by_mdt $uuid 0
5030 check_agent_unregistered_by_mdt $uuid 1
5032 # check running copytool process
5033 search_copytools $agent || error "No running copytools on $agent"
5035 # reactivate all mdc for MDT0001
5036 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5038 # make sure the copytool is now registered to all MDTs
5039 check_agent_registered $uuid
5041 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5044 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5048 # create files on both MDT0000 and MDT0001
5051 local dir_mdt0=$DIR/$tdir/mdt0
5052 stack_trap "rm -rf $dir_mdt0" EXIT
5053 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5055 # create 1 file on mdt0
5056 local fid1=$(create_small_file $dir_mdt0/$tfile)
5058 # deactivate all mdc for MDT0001
5059 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5061 # send an HSM request for files in MDT0000
5062 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5064 # check for completion of files in MDT0000
5065 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5066 echo "archive successful on mdt0"
5068 # reactivate all mdc for MDT0001
5069 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5071 run_test 404 "Inactive MDT does not block requests for active MDTs"
5074 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5080 local striped_dir=$DIR/$tdir/striped_dir
5082 # create striped dir on all of MDTs
5083 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5085 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5086 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5087 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5088 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5090 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5091 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5092 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5093 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5095 # check that compound requests are shunt to the rights MDTs
5096 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5097 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5098 error "lfs hsm_archive"
5100 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5101 echo "archive successful on $fid1"
5102 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5103 echo "archive successful on $fid2"
5104 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5105 echo "archive successful on $fid3"
5106 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5107 echo "archive successful on $fid4"
5109 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5110 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5111 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5112 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5114 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5115 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5116 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5117 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5119 run_test 405 "archive and release under striped directory"
5122 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5124 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5125 skip "need MDS version at least 2.7.64" && return 0
5130 fid=$(create_small_file $DIR/$tdir/$tfile)
5135 $LFS hsm_archive $DIR/$tdir/$tfile
5136 wait_request_state "$fid" ARCHIVE SUCCEED
5137 $LFS hsm_release $DIR/$tdir/$tfile
5139 # Should migrate $tdir but not $tfile.
5140 $LFS mv -M1 $DIR/$tdir &&
5141 error "migrating HSM an archived file should fail"
5143 $LFS hsm_restore $DIR/$tdir/$tfile
5144 wait_request_state "$fid" RESTORE SUCCEED
5146 $LFS hsm_remove $DIR/$tdir/$tfile
5147 wait_request_state "$fid" REMOVE SUCCEED
5149 cat $DIR/$tdir/$tfile > /dev/null ||
5150 error "cannot read $DIR/$tdir/$tfile"
5152 $LFS mv -M1 $DIR/$tdir ||
5153 error "cannot complete migration after HSM remove"
5155 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5156 if ((mdt_index != 1)); then
5157 error "expected MDT index 1, got $mdt_index"
5160 # Refresh fid after migration.
5161 fid=$(path2fid $DIR/$tdir/$tfile)
5164 $LFS hsm_archive $DIR/$tdir/$tfile
5165 wait_request_state "$fid" ARCHIVE SUCCEED 1
5167 lctl set_param debug=+trace
5168 $LFS hsm_release $DIR/$tdir/$tfile ||
5169 error "cannot release $DIR/$tdir/$tfile"
5171 $LFS hsm_restore $DIR/$tdir/$tfile
5172 wait_request_state "$fid" RESTORE SUCCEED 1
5174 cat $DIR/$tdir/$tfile > /dev/null ||
5175 error "cannot read $DIR/$tdir/$tfile"
5177 run_test 406 "attempting to migrate HSM archived files is safe"
5180 needclients 2 || return 0
5181 # test needs a running copytool
5186 local f=$DIR/$tdir/$tfile
5187 local f2=$DIR2/$tdir/$tfile
5189 fid=$(make_custom_file_for_progress $f 39 1000000)
5190 [ $? != 0 ] && skip "not enough free space" && return
5192 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5193 wait_request_state $fid ARCHIVE SUCCEED
5196 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5197 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5200 # 1st request holds layout lock while appropriate
5201 # RESTORE record is still not added to llog
5205 # after umount hsm_actions->O/x/x log shouldn't have
5206 # double RESTORE records like below
5207 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5208 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5210 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5213 wait_request_state $fid RESTORE SUCCEED
5215 run_test 407 "Check for double RESTORE records in llog"
5219 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5220 skip "HSM migrate is not supported" && return
5222 test_mkdir -p $DIR/$tdir
5223 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5225 run_test 500 "various LLAPI HSM tests"
5230 check_and_cleanup_lustre