3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
46 if getent group nobody; then
48 elif getent group nogroup; then
51 error "No generic nobody group"
56 # if there is no CLIENT1 defined, some tests can be ran on localhost
57 CLIENT1=${CLIENT1:-$HOSTNAME}
58 # if CLIENT2 doesn't exist then use CLIENT1 instead
59 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # Exception is the test which need two separate nodes
62 CLIENT2=${CLIENT2:-$CLIENT1}
65 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
66 # the following associated variables are added:
68 # AGTCOUNT: number of agents
69 # AGTDEV{N}: target HSM mount point (root path of the backend)
70 # agt{N}_HOST: hostname of the agent agt{N}
71 # SINGLEAGT: facet of the single agent
73 # The number of agents is initialized as the number of remote client nodes.
74 # By default, only single copytool is started on a remote client/agent. If there
75 # was no remote client, then the copytool will be started on the local client.
81 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
82 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
84 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
85 if [[ $CLIENTCOUNT -gt 1 ]] &&
86 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
87 skip_env "SHARED_DIRECTORY should be accessible"\
92 # We used to put the HSM archive in $SHARED_DIRECTORY but that
93 # meant NFS issues could hose sanity-hsm sessions. So now we
95 for n in $(seq $AGTCOUNT); do
96 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
97 agent=CLIENT$((n + 1))
98 if [[ -z "${!agent}" ]]; then
99 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
102 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
103 local var=agt${n}_HOST
104 [[ ! -z "${!var}" ]] || error "agt${n}_HOST is empty!"
107 export SINGLEAGT=${SINGLEAGT:-agt1}
109 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
110 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
111 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
112 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
113 export HSMTOOL_TESTDIR
114 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
115 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
116 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
117 # deleting everything in filesystem, independent of any copytool.
118 export HSMTMP=${HSMTMP:-"shsm"}
120 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
122 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
123 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
127 # The test only support up to 10 MDTs
128 MDT_PREFIX="mdt.$FSNAME-MDT000"
129 HSM_PARAM="${MDT_PREFIX}0.hsm"
131 # archive is purged at copytool setup
132 HSM_ARCHIVE_PURGE=true
134 # Don't allow copytool error upon start/setup
135 HSMTOOL_NOERROR=false
138 # Get the backend root path for the given agent facet.
141 local dev=AGTDEV$(facet_number $facet)
146 # Stop copytool and unregister an existing changelog user.
148 copytool_monitor_cleanup
151 cdt_set_sanity_policy
156 # get MDT device for each mdc
157 for mdtno in $(seq 1 $MDSCOUNT); do
158 local idx=$(($mdtno - 1))
159 MDT[$idx]=$($LCTL get_param -n \
160 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
161 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
166 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
167 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
171 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
173 echo "Killing existing copytools on $hosts"
174 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
178 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
179 local wait_timeout=200
180 local wait_start=$SECONDS
181 local wait_end=$((wait_start + wait_timeout))
182 local sleep_time=100000 # 0.1 second
184 while ((SECONDS < wait_end)); do
185 if ! search_copytools $hosts; then
186 echo "copytools stopped in $((SECONDS - wait_start))s"
190 echo "copytools still running on $hosts"
192 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
193 sleep_time=$(bc <<< "$sleep_time * 2")
196 # try to dump Copytool's stack
197 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
198 "echo t >/proc/sysrq-trigger"
200 echo "copytools failed to stop in ${wait_timeout}s"
205 copytool_monitor_setup() {
206 local facet=${1:-$SINGLEAGT}
207 local agent=$(facet_active_host $facet)
209 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
210 local test_dir=$(do_node $agent "$cmd") ||
211 error "Failed to create tempdir on $agent"
212 export HSMTOOL_MONITOR_DIR=$test_dir
214 # Create the fifo and a monitor (cat dies when copytool dies)
215 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
216 error "failed to create copytool fifo on $agent"
217 cmd="cat $test_dir/fifo > $test_dir/events &"
218 cmd+=" echo \\\$! > $test_dir/monitor_pid"
220 if [[ $PDSH == *Rmrsh* ]]; then
221 # This is required for pdsh -Rmrsh and its handling of remote
223 # Regular ssh and pdsh -Rssh work fine without this
224 # backgrounded subshell nonsense.
225 (do_node $agent "$cmd") &
226 export HSMTOOL_MONITOR_PDSH=$!
228 # Slightly racy, but just making a best-effort to catch obvious
231 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
232 error "Failed to start copytool monitor on $agent"
234 do_node $agent "$cmd"
236 error "Failed to start copytool monitor on $agent"
241 copytool_monitor_cleanup() {
242 local facet=${1:-$SINGLEAGT}
243 local agent=$(facet_active_host $facet)
245 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
246 # Should die when the copytool dies, but just in case.
247 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
248 cmd+=" 2>/dev/null || true"
249 do_node $agent "$cmd"
250 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
251 export HSMTOOL_MONITOR_DIR=
254 # The pdsh should die on its own when the monitor dies. Just
255 # in case, though, try to clean up to avoid any cruft.
256 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
257 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
258 export HSMTOOL_MONITOR_PDSH=
264 local host="$(facet_host "$1")"
265 local prefix=$TESTLOG_PREFIX
266 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
268 printf "${prefix}.copytool${archive_id}_log.${host}.log"
273 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
274 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
275 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
276 [ ${#misc_options[@]} -gt 0 ] &&
277 cmd+=" $(IFS=" " echo "$@")"
278 cmd+=" \"$mountpoint\""
280 echo "Starting copytool $facet on $(facet_host $facet)"
281 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
282 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
286 local facet="${1:-$SINGLEAGT}"
288 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
297 local fail_on_error=true
298 local -a misc_options
299 while [ $# -gt 0 ]; do
307 local mountpoint="$1"
311 local archive_id="$1"
315 local bandwidth="$1" # in MB/s
318 local fail_on_error=false
321 # Uncommon(/copytool dependent) option
328 # Use default values if needed
329 local facet=${facet:-$SINGLEAGT}
330 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
331 local hsm_root="$(hsm_root "$facet")"
333 stack_trap "do_facet $facet \"rm -rf \\\"$hsm_root\\\"\"" EXIT
334 do_facet $facet "mkdir -p \"$hsm_root\"" ||
335 error "mkdir \"$hsm_root\" failed"
339 local copytool=lhsmtool
343 __${copytool}_${action} "${misc_options[@]}"
344 if [ $? -ne 0 ]; then
349 local host="$(facet_host $facet)"
350 error_msg="Failed to start copytool $facet on '$host'"
354 $fail_on_error && error "$error_msg" || echo "$error_msg"
359 local facet=${1:-$SINGLEAGT}
360 # Use MOUNT2 by default if defined
361 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
363 local hsm_root=${4:-$(copytool_device $facet)}
365 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
367 local agent=$(facet_active_host $facet)
369 if $HSM_ARCHIVE_PURGE; then
370 echo "Purging archive on $agent"
371 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
374 echo "Starting copytool $facet on $agent"
375 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
376 error "mkdir '$hsm_root/$HSMTMP' failed"
377 # bandwidth is limited to 1MB/s so the copy time is known and
378 # independent of hardware
379 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
380 cmd+=" --hsm-root $hsm_root/$HSMTMP"
381 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
382 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
383 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
384 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
385 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
386 cmd+=" --bandwidth 1 $lustre_mntpnt"
388 # Redirect the standard output and error to a log file which
389 # can be uploaded to Maloo.
390 local prefix=$TESTLOG_PREFIX
391 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
392 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
394 stack_trap cleanup EXIT
395 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
396 if [[ $? != 0 ]]; then
397 [[ $HSMTOOL_NOERROR == true ]] ||
398 error "start copytool $facet on $agent failed"
399 echo "start copytool $facet on $agent failed"
403 get_copytool_event_log() {
404 local facet=${1:-$SINGLEAGT}
405 local agent=$(facet_active_host $facet)
407 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
408 error "Can't get event log: No monitor directory!"
410 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
411 error "Could not collect event log from $agent"
416 local agt_facet=$SINGLEAGT
417 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
418 local hsm_root=$(copytool_device $agt_facet)
420 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
427 kill_copytools $agt_hosts
428 wait_copytools $agt_hosts || error "copytools failed to stop"
430 # Clean all CDTs orphans requests from previous tests that
431 # would otherwise need to timeout to clear.
432 for ((i = 0; i < MDSCOUNT; i++)); do
434 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
435 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
437 # Skip already stopping or stopped CDTs.
438 [[ "${state[$i]}" =~ ^stop ]] && continue
440 do_facet $facet "$LCTL set_param $param=shutdown"
443 for ((i = 0; i < MDSCOUNT; i++)); do
444 # Only check and restore CDTs that we stopped in the first loop.
445 [[ "${state[$i]}" =~ ^stop ]] && continue
448 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
450 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
451 error "$facet CDT state is not stopped"
453 # Restore old CDT state.
454 do_facet $facet "$LCTL set_param $param=${state[$i]}"
457 for ((i = 0; i < MDSCOUNT; i++)); do
458 # Only check CDTs that we stopped in the first loop.
459 [[ "${state[$i]}" =~ ^stop ]] && continue
462 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
464 # Check that the old CDT state was restored.
465 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
466 20 || error "$facet CDT state is not '${state[$i]}'"
469 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
470 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
475 local agents=${1:-$(facet_active_host $SINGLEAGT)}
477 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
478 echo "Copytool is suspended on $agents"
481 copytool_continue() {
482 local agents=${1:-$(facet_active_host $SINGLEAGT)}
484 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
485 echo "Copytool is continued on $agents"
488 copytool_remove_backend() {
490 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
491 echo "Remove from backend: $fid = $be"
492 do_facet $SINGLEAGT rm -f $be
496 mkdir -p "$(dirname "$2")" ||
497 error "cannot create directory '$(dirname "$2")'"
499 do_facet $SINGLEAGT \
500 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
501 --import $1 $2 $MOUNT" ||
502 error "import of $1 to $2 failed"
505 file_creation_failure() {
512 df $MOUNT $MOUNT2 >&2
513 error "Not enough space to create $file with $cmd"
516 error "cannot create $file with $cmd, status=$err"
521 # Creates a file using dd
527 local source=${5:-/dev/zero}
531 if [ -n "$conv" ]; then
535 # Create the directory in case it does not exist
536 mkdir -p "$(dirname "$file")"
537 # Delete the file in case it already exist
540 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
541 path2fid "$file" || error "cannot get FID of '$file'"
544 echo "cannot create file '$file'" >&2;
545 # Let the caller decide what to do on error
550 create_empty_file() {
551 create_file "${1/$DIR/$DIR2}" 1M 0 ||
552 file_creation_failure dd "${1/$DIR/$DIR2}" $?
555 create_small_file() {
556 local source_file=/dev/urandom
559 local conv=${2:-fsync}
561 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
562 file_creation_failure dd "${1/$DIR/$DIR2}" $?
565 create_small_sync_file() {
566 create_small_file "$1" sync
569 create_archive_file() {
570 local file="$HSM_ARCHIVE/$1"
572 local source=/dev/urandom
574 # Create the counterpart directory of the archive
575 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
576 error "cannot create archive directory '$(dirname "$file")'"
578 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
579 error "cannot create archive file '$file'"
583 local file=$HSM_ARCHIVE/$2
584 do_facet $SINGLEAGT mkdir -p $(dirname $file)
585 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
594 if [[ "$value" != "" ]]; then
597 for mdtno in $(seq 1 $MDSCOUNT); do
598 local idx=$(($mdtno - 1))
599 local facet=mds${mdtno}
600 # if $arg include -P option, run 1 set_param per MDT on the MGS
601 # else, run set_param on each MDT
602 [[ $arg = *"-P"* ]] && facet=mgs
603 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
604 [[ $? != 0 ]] && rc=1
614 for mdtno in $(seq 1 $MDSCOUNT); do
615 local idx=$(($mdtno - 1))
616 wait_result mds${mdtno} \
617 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
619 error "$key state is not '$target' on mds${mdtno}"
626 for mdtno in $(seq 1 $MDSCOUNT); do
627 local idx=$(($mdtno - 1))
628 local cl_user=$(do_facet mds${mdtno} $LCTL \
629 --device ${MDT[$idx]} \
630 changelog_register -n)
632 do_facet mds${mdtno} lctl set_param \
633 mdd.${MDT[$idx]}.changelog_mask="+hsm"
634 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
638 changelog_cleanup() {
640 for mdtno in $(seq 1 $MDSCOUNT); do
641 local idx=$(($mdtno - 1))
642 [[ -z ${CL_USERS[$idx]} ]] && continue
643 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
644 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
645 changelog_deregister ${CL_USERS[$idx]}
650 changelog_get_flags() {
655 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
660 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
668 mdts_set_param "$opt -n" "hsm.$param" "$value"
675 mdts_set_param "" hsm_control "$cmd"
676 mdts_check_param hsm_control "$target" 10
679 cdt_set_sanity_policy() {
680 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
683 mdts_set_param "" hsm.policy "+NRA"
684 mdts_set_param "" hsm.policy "-NBR"
685 CDT_POLICY_HAD_CHANGED=
690 mdts_set_param "" hsm.policy "+NRA"
691 CDT_POLICY_HAD_CHANGED=true
694 cdt_clear_no_retry() {
695 mdts_set_param "" hsm.policy "-NRA"
696 CDT_POLICY_HAD_CHANGED=true
699 cdt_set_non_blocking_restore() {
700 mdts_set_param "" hsm.policy "+NBR"
701 CDT_POLICY_HAD_CHANGED=true
704 cdt_clear_non_blocking_restore() {
705 mdts_set_param "" hsm.policy "-NBR"
706 CDT_POLICY_HAD_CHANGED=true
709 cdt_clear_mount_state() {
710 mdts_set_param "-P -d" hsm_control ""
713 cdt_set_mount_state() {
714 mdts_set_param "-P" hsm_control "$1"
715 # set_param -P is asynchronous operation and could race with set_param.
716 # In such case configs could be retrieved and applied at mgc after
717 # set_param -P completion. Sleep here to avoid race with set_param.
718 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
719 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
720 # and 10 seconds to retrieve config from server.
725 mdts_check_param hsm_control "$1" 20
729 set_test_state disabled disabled
733 set_test_state enabled enabled
737 set_test_state shutdown stopped
741 set_test_state purge enabled
747 cdt_set_sanity_policy
751 local client_count=$1
752 if [[ $CLIENTCOUNT -lt $client_count ]]; then
753 skip "Need $client_count or more clients, have $CLIENTCOUNT"
760 $LFS path2fid $1 | tr -d '[]'
761 return ${PIPESTATUS[0]}
769 if [[ $u == "user" ]]; then
770 st=$($RUNAS $LFS hsm_state $f)
773 st=$($LFS hsm_state $f)
776 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
778 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
782 get_hsm_archive_id() {
785 st=$($LFS hsm_state $f)
786 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
788 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
796 local st=$(get_hsm_flags $f)
797 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
800 check_hsm_flags_user() {
804 local st=$(get_hsm_flags $f user)
805 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
817 if [[ "$3" != 1 ]]; then
821 cp $1 $f || file_creation_failure cp $f $?
823 path2fid $f || error "cannot get fid on $f"
826 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
828 # Note that this might lead to surprising behaviours such as deleting an
829 # important file for the currently running test
830 delete_large_files() {
831 printf "Deleting large files...\n" >&2
832 find $MOUNT -size +10M -delete
833 wait_delete_completed
836 make_custom_file_for_progress() {
837 local count=${2:-"39"}
838 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
841 [[ $count -gt 0 ]] || error "Invalid file size"
842 [[ $bs -gt 0 ]] || error "Invalid stripe size"
844 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
845 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
846 echo "It might be due to a lack of space in the filesystem" >&2
847 delete_large_files >&2
848 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
849 file_creation_failure dd "${1/$DIR/$DIR2}" $?
856 wait_update --verbose $(facet_active_host $facet) "$@"
859 wait_request_state() {
863 # 4th arg (mdt index) is optional
865 local mds=mds$(($mdtidx + 1))
867 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
868 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
870 wait_result $mds "$cmd" $state 200 ||
871 error "request on $fid is not $state on $mds"
874 get_request_state() {
878 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
879 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
882 get_request_count() {
886 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
887 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
890 # Ensure the number of HSM request for a given FID is correct
891 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
892 assert_request_count() {
893 local request_count=$(get_request_count $1 $2)
894 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
896 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
903 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
904 [[ -n $fid ]] && cmd+=" | grep '$fid'"
905 cmd+=" | egrep 'WAITING|STARTED'"
907 wait_result $SINGLEMDS "$cmd" "" $timeout ||
908 error "requests did not complete"
911 wait_for_grace_delay() {
912 local val=$(get_hsm_param grace_delay)
916 wait_for_loop_period() {
917 local val=$(get_hsm_param loop_period)
924 # python2.6 in EL6 includes an internal json module
925 local json_parser='import json; import fileinput;'
926 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
927 json_parser+='json.loads([line for line in '
928 json_parser+='fileinput.input()][0]).items()])'
930 echo $raw_event | python -c "$json_parser"
933 get_agent_by_uuid_mdt() {
936 local mds=mds$(($mdtidx + 1))
937 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
941 check_agent_registered_by_mdt() {
944 local mds=mds$(($mdtidx + 1))
945 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
946 if [[ ! -z "$agent" ]]; then
947 echo "found agent $agent on $mds"
949 error "uuid $uuid not found in agent list on $mds"
953 check_agent_unregistered_by_mdt() {
956 local mds=mds$(($mdtidx + 1))
957 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
958 if [[ -z "$agent" ]]; then
959 echo "uuid not found in agent list on $mds"
961 error "uuid found in agent list on $mds: $agent"
965 check_agent_registered() {
968 for mdsno in $(seq 1 $MDSCOUNT); do
969 check_agent_registered_by_mdt $uuid $((mdsno - 1))
973 check_agent_unregistered() {
976 for mdsno in $(seq 1 $MDSCOUNT); do
977 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
982 local agent=${1:-$(facet_active_host $SINGLEAGT)}
984 # Lustre mount-point is mandatory and last parameter on
986 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
988 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
990 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
996 # populate MDT device array
999 # cleanup from previous bad setup
1002 # for recovery tests, coordinator needs to be started at mount
1004 # the lustre conf must be without hsm on (like for sanity.sh)
1005 echo "Set HSM on and start"
1006 cdt_set_mount_state enabled
1007 cdt_check_state enabled
1009 echo "Set sanity-hsm HSM policy"
1010 cdt_set_sanity_policy
1012 # finished requests are quickly removed from list
1013 set_hsm_param grace_delay 10
1015 test_1A() { # was test_1
1017 chmod 777 $DIR/$tdir
1019 local f=$DIR/$tdir/$tfile
1023 check_hsm_flags_user $f "0x00000000"
1025 $RUNAS $LFS hsm_set --norelease $f ||
1026 error "user could not change hsm flags"
1027 check_hsm_flags_user $f "0x00000010"
1029 $RUNAS $LFS hsm_clear --norelease $f ||
1030 error "user could not clear hsm flags"
1031 check_hsm_flags_user $f "0x00000000"
1033 # User could not change those flags...
1034 $RUNAS $LFS hsm_set --exists $f &&
1035 error "user should not set this flag"
1036 check_hsm_flags_user $f "0x00000000"
1039 $LFS hsm_set --exists $f ||
1040 error "root could not change hsm flags"
1041 check_hsm_flags_user $f "0x00000001"
1043 $LFS hsm_clear --exists $f ||
1044 error "root could not clear hsm state"
1045 check_hsm_flags_user $f "0x00000000"
1048 run_test 1A "lfs hsm flags root/non-root access"
1051 local f=$DIR/$tdir/$tfile
1052 local fid=$(create_small_file $f)
1056 $LFS hsm_archive $f || error "could not archive file"
1057 wait_request_state $fid ARCHIVE SUCCEED
1059 # Release and check states
1060 $LFS hsm_release $f || error "could not release file"
1061 echo -n "Verifying released state: "
1062 check_hsm_flags $f "0x0000000d"
1064 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
1066 run_test 1a "mmap & cat a HSM released file"
1070 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
1071 error "failed to set default stripe"
1072 local f=$DIR/$tdir/$tfile
1075 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1076 error "failed to create file"
1077 local fid=$(path2fid $f)
1082 $LFS hsm_archive $f || error "could not archive file"
1083 wait_request_state $fid ARCHIVE SUCCEED
1086 $LFS hsm_release $f || error "could not release file"
1087 echo "verify released state: "
1088 check_hsm_flags $f "0x0000000d" && echo "pass"
1091 $LFS hsm_restore $f || error "could not restore file"
1092 wait_request_state $fid RESTORE SUCCEED
1093 echo "verify restored state: "
1094 check_hsm_flags $f "0x00000009" && echo "pass"
1096 run_test 1b "Archive, Release and Restore composite file"
1100 chmod 777 $DIR/$tdir
1102 local f=$DIR/$tdir/$tfile
1105 # Test whether we can set the maximum archive number.
1106 local LOCAL_HSM_ARCHIVE_NUMBER=32
1107 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1108 error "root could not change hsm flags"
1109 check_hsm_flags_user $f "0x00000001"
1110 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1111 local 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 0 results in no change.
1116 $LFS hsm_set --exists --archive-id 0 $f ||
1117 error "root could not change hsm flags"
1118 check_hsm_flags_user $f "0x00000001"
1119 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1120 st=$(get_hsm_archive_id $f)
1121 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1122 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1124 # Test whether setting archive number > 32 results in error.
1125 $LFS hsm_set --exists --archive-id 33 $f &&
1126 error "archive number is larger than 32"
1127 check_hsm_flags_user $f "0x00000001"
1129 # Test whether setting archive number 16 and archived flag.
1130 LOCAL_HSM_ARCHIVE_NUMBER=16
1131 $LFS hsm_set --exists --archived \
1132 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1133 error "root could not change hsm flags"
1134 check_hsm_flags_user $f "0x00000009"
1135 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1136 st=$(get_hsm_archive_id $f)
1137 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1138 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1140 run_test 1c "Check setting archive-id in lfs hsm_set"
1144 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1145 error "failed to set default stripe"
1146 local f=$DIR/$tdir/$tfile
1149 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1150 error "failed to create file"
1151 local fid=$(path2fid $f)
1156 $LFS hsm_archive $f || error "could not archive file"
1157 wait_request_state $fid ARCHIVE SUCCEED
1160 $LFS hsm_release $f || error "could not release file"
1161 echo "verify released state: "
1162 check_hsm_flags $f "0x0000000d" && echo "pass"
1165 $LFS hsm_restore $f || error "could not restore file"
1166 wait_request_state $fid RESTORE SUCCEED
1167 echo "verify restored state: "
1168 check_hsm_flags $f "0x00000009" && echo "pass"
1170 run_test 1d "Archive, Release and Restore DoM file"
1173 local f=$DIR/$tdir/$tfile
1175 create_empty_file "$f"
1176 # New files are not dirty
1177 check_hsm_flags $f "0x00000000"
1179 # For test, we simulate an archived file.
1180 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1181 check_hsm_flags $f "0x00000001"
1183 # chmod do not put the file dirty
1184 chmod 600 $f || error "could not chmod test file"
1185 check_hsm_flags $f "0x00000001"
1187 # chown do not put the file dirty
1188 chown $RUNAS_ID $f || error "could not chown test file"
1189 check_hsm_flags $f "0x00000001"
1191 # truncate put the file dirty
1192 $TRUNCATE $f 1 || error "could not truncate test file"
1193 check_hsm_flags $f "0x00000003"
1195 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1196 check_hsm_flags $f "0x00000001"
1198 run_test 2 "Check file dirtyness when doing setattr"
1204 # New files are not dirty
1205 cp -p /etc/passwd $f
1206 check_hsm_flags $f "0x00000000"
1208 # For test, we simulate an archived file.
1209 $LFS hsm_set --exists $f ||
1210 error "user could not change hsm flags"
1211 check_hsm_flags $f "0x00000001"
1213 # Reading a file, does not set dirty
1214 cat $f > /dev/null || error "could not read file"
1215 check_hsm_flags $f "0x00000001"
1217 # Open for write without modifying data, does not set dirty
1218 openfile -f O_WRONLY $f || error "could not open test file"
1219 check_hsm_flags $f "0x00000001"
1221 # Append to a file sets it dirty
1222 cp -p /etc/passwd $f.append || error "could not create file"
1223 $LFS hsm_set --exists $f.append ||
1224 error "user could not change hsm flags"
1225 dd if=/etc/passwd of=$f.append bs=1 count=3\
1226 conv=notrunc oflag=append status=noxfer ||
1227 file_creation_failure dd $f.append $?
1228 check_hsm_flags $f.append "0x00000003"
1230 # Modify a file sets it dirty
1231 cp -p /etc/passwd $f.modify || error "could not create file"
1232 $LFS hsm_set --exists $f.modify ||
1233 error "user could not change hsm flags"
1234 dd if=/dev/zero of=$f.modify bs=1 count=3\
1235 conv=notrunc status=noxfer ||
1236 file_creation_failure dd $f.modify $?
1237 check_hsm_flags $f.modify "0x00000003"
1239 # Open O_TRUNC sets dirty
1240 cp -p /etc/passwd $f.trunc || error "could not create file"
1241 $LFS hsm_set --exists $f.trunc ||
1242 error "user could not change hsm flags"
1243 cp /etc/group $f.trunc || error "could not override a file"
1244 check_hsm_flags $f.trunc "0x00000003"
1246 # Mmapped a file sets dirty
1247 cp -p /etc/passwd $f.mmap || error "could not create file"
1248 $LFS hsm_set --exists $f.mmap ||
1249 error "user could not change hsm flags"
1250 multiop $f.mmap OSMWUc || error "could not mmap a file"
1251 check_hsm_flags $f.mmap "0x00000003"
1253 run_test 3 "Check file dirtyness when opening for write"
1256 local f=$DIR/$tdir/$tfile
1257 local fid=$(create_small_file $f)
1260 local st=$(get_request_state $fid CANCEL)
1261 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1263 run_test 4 "Useless cancel must not be registered"
1266 # test needs a running copytool
1270 local f=$DIR/$tdir/$tfile
1271 local fid=$(copy_file /etc/passwd $f)
1273 wait_request_state $fid ARCHIVE SUCCEED
1275 check_hsm_flags $f "0x00000009"
1277 run_test 8 "Test default archive number"
1279 test_9A() { # was test_9
1280 # we do not use the default one to be sure
1281 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1282 copytool setup --archive-id $archive_id
1284 # give time for CT to register with MDTs
1285 sleep $(($MDSCOUNT*2))
1286 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1287 check_agent_registered $uuid
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/passwd $f)
1292 $LFS hsm_archive --archive $archive_id $f
1293 wait_request_state $fid ARCHIVE SUCCEED
1295 check_hsm_flags $f "0x00000009"
1297 run_test 9A "Use of explicit archive number, with dedicated copytool"
1300 needclients 3 || return 0
1306 # start all of the copytools
1307 for n in $(seq $AGTCOUNT); do
1308 copytool setup --facet agt$n
1312 for n in $(seq $AGTCOUNT); do
1313 file=$DIR/$tdir/$tfile.$n
1314 fid=$(create_small_file $file)
1316 $LFS hsm_archive $file || error "could not archive file $file"
1317 wait_request_state $fid ARCHIVE SUCCEED
1318 check_hsm_flags $file "0x00000009"
1321 run_test 9a "Multiple remote agents"
1324 # test needs a running copytool
1327 mkdir -p $DIR/$tdir/d1
1328 local f=$DIR/$tdir/$tfile
1329 local fid=$(copy_file /etc/hosts $f)
1330 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1331 error "hsm_archive failed"
1332 wait_request_state $fid ARCHIVE SUCCEED
1334 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1335 error "fid $fid not in archive $HSM_ARCHIVE"
1336 echo "Verifying content"
1337 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1338 echo "Verifying hsm state "
1339 check_hsm_flags $f "0x00000009"
1341 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1342 local st=$(get_hsm_archive_id $f)
1343 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1344 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1348 run_test 10a "Archive a file"
1351 # test needs a running copytool
1355 local f=$DIR/$tdir/$tfile
1356 local fid=$(copy_file /etc/hosts $f)
1357 $LFS hsm_archive $f || error "archive request failed"
1358 wait_request_state $fid ARCHIVE SUCCEED
1360 $LFS hsm_archive $f || error "archive of non dirty file failed"
1361 local cnt=$(get_request_count $fid ARCHIVE)
1362 [[ "$cnt" == "1" ]] ||
1363 error "archive of non dirty file must not make a request"
1365 run_test 10b "Archive of non dirty file must work without doing request"
1368 # test needs a running copytool
1372 local f=$DIR/$tdir/$tfile
1373 local fid=$(copy_file /etc/hosts $f)
1374 $LFS hsm_set --noarchive $f
1375 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1378 run_test 10c "Check forbidden archive"
1381 # test needs a running copytool
1385 local f=$DIR/$tdir/$tfile
1386 local fid=$(copy_file /etc/hosts $f)
1387 $LFS hsm_archive $f || error "cannot archive $f"
1388 wait_request_state $fid ARCHIVE SUCCEED
1390 local ar=$(get_hsm_archive_id $f)
1391 local dflt=$(get_hsm_param default_archive_id)
1392 [[ $ar == $dflt ]] ||
1393 error "archived file is not on default archive: $ar != $dflt"
1395 run_test 10d "Archive a file on the default archive id"
1399 copy2archive /etc/hosts $tdir/$tfile
1400 local f=$DIR/$tdir/$tfile
1402 import_file $tdir/$tfile $f
1403 echo -n "Verifying released state: "
1404 check_hsm_flags $f "0x0000000d"
1406 local LSZ=$(stat -c "%s" $f)
1407 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1409 echo "Verifying imported size $LSZ=$ASZ"
1410 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1411 echo -n "Verifying released pattern: "
1412 local PTRN=$($GETSTRIPE -L $f)
1414 [[ $PTRN == released ]] || error "Is not released"
1415 local fid=$(path2fid $f)
1416 echo "Verifying new fid $fid in archive"
1418 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1419 error "fid $fid not in archive $HSM_ARCHIVE"
1421 run_test 11a "Import a file"
1424 # test needs a running copytool
1428 local f=$DIR/$tdir/$tfile
1429 local fid=$(copy_file /etc/hosts $f)
1430 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1431 error "hsm_archive failed"
1432 wait_request_state $fid ARCHIVE SUCCEED
1434 local FILE_HASH=$(md5sum $f)
1439 echo "$FILE_HASH" | md5sum -c
1441 [[ $? -eq 0 ]] || error "Restored file differs"
1445 run_test 11b "Import a deleted file using its FID"
1448 # test needs a running copytool
1452 copy2archive /etc/hosts $tdir/$tfile
1454 local f=$DIR/$tdir/$tfile
1455 import_file $tdir/$tfile $f
1456 local f2=$DIR2/$tdir/$tfile
1457 echo "Verifying released state: "
1458 check_hsm_flags $f2 "0x0000000d"
1460 local fid=$(path2fid $f2)
1461 $LFS hsm_restore $f2
1462 wait_request_state $fid RESTORE SUCCEED
1464 echo "Verifying file state: "
1465 check_hsm_flags $f2 "0x00000009"
1467 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1469 [[ $? -eq 0 ]] || error "Restored file differs"
1473 run_test 12a "Restore an imported file explicitly"
1476 # test needs a running copytool
1480 copy2archive /etc/hosts $tdir/$tfile
1482 local f=$DIR/$tdir/$tfile
1483 import_file $tdir/$tfile $f
1484 echo "Verifying released state: "
1485 check_hsm_flags $f "0x0000000d"
1487 cat $f > /dev/null || error "File read failed"
1489 echo "Verifying file state after restore: "
1490 check_hsm_flags $f "0x00000009"
1492 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1494 [[ $? -eq 0 ]] || error "Restored file differs"
1498 run_test 12b "Restore an imported file implicitly"
1501 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1503 # test needs a running copytool
1506 local f=$DIR/$tdir/$tfile
1508 $LFS setstripe -c 2 "$f"
1510 fid=$(make_custom_file_for_progress $f 5)
1511 [ $? != 0 ] && skip "not enough free space" && return
1513 local FILE_CRC=$(md5sum $f)
1515 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1516 wait_request_state $fid ARCHIVE SUCCEED
1517 $LFS hsm_release $f || error "release $f failed"
1519 echo "$FILE_CRC" | md5sum -c
1521 [[ $? -eq 0 ]] || error "Restored file differs"
1523 run_test 12c "Restore a file with stripe of 2"
1526 # test needs a running copytool
1531 local f=$DIR/$tdir/$tfile
1532 local fid=$(copy_file /etc/hosts $f)
1533 $LFS hsm_restore $f || error "restore of non archived file failed"
1534 local cnt=$(get_request_count $fid RESTORE)
1535 [[ "$cnt" == "0" ]] ||
1536 error "restore non archived must not make a request"
1537 $LFS hsm_archive $f ||
1538 error "archive request failed"
1539 wait_request_state $fid ARCHIVE SUCCEED
1540 $LFS hsm_restore $f ||
1541 error "restore of non released file failed"
1542 local cnt=$(get_request_count $fid RESTORE)
1543 [[ "$cnt" == "0" ]] ||
1544 error "restore a non dirty file must not make a request"
1546 run_test 12d "Restore of a non archived, non released file must work"\
1547 " without doing request"
1550 # test needs a running copytool
1553 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1554 local f=$DIR/$tdir/$tfile
1555 local fid=$(copy_file /etc/hosts $f)
1556 $LFS hsm_archive $f || error "archive request failed"
1557 wait_request_state $fid ARCHIVE SUCCEED
1560 cat /etc/hosts >> $f
1564 $LFS hsm_restore $f && error "restore a dirty file must fail"
1567 run_test 12e "Check forbidden restore"
1570 # test needs a running copytool
1574 local f=$DIR/$tdir/$tfile
1575 local fid=$(copy_file /etc/hosts $f)
1577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1578 wait_request_state $fid ARCHIVE SUCCEED
1579 $LFS hsm_release $f || error "release of $f failed"
1581 wait_request_state $fid RESTORE SUCCEED
1583 echo -n "Verifying file state: "
1584 check_hsm_flags $f "0x00000009"
1586 diff -q /etc/hosts $f
1588 [[ $? -eq 0 ]] || error "Restored file differs"
1590 run_test 12f "Restore a released file explicitly"
1593 # test needs a running copytool
1597 local f=$DIR/$tdir/$tfile
1598 local fid=$(copy_file /etc/hosts $f)
1600 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1601 wait_request_state $fid ARCHIVE SUCCEED
1602 $LFS hsm_release $f || error "release of $f failed"
1604 diff -q /etc/hosts $f
1607 # we check we had a restore done
1608 wait_request_state $fid RESTORE SUCCEED
1610 [[ $st -eq 0 ]] || error "Restored file differs"
1612 run_test 12g "Restore a released file implicitly"
1615 needclients 2 || return 0
1617 # test needs a running copytool
1621 local f=$DIR/$tdir/$tfile
1622 local fid=$(copy_file /etc/hosts $f)
1624 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1625 wait_request_state $fid ARCHIVE SUCCEED
1626 $LFS hsm_release $f || error "release of $f failed"
1628 do_node $CLIENT2 diff -q /etc/hosts $f
1631 # we check we had a restore done
1632 wait_request_state $fid RESTORE SUCCEED
1634 [[ $st -eq 0 ]] || error "Restored file differs"
1636 run_test 12h "Restore a released file implicitly from a second node"
1639 # test needs a running copytool
1643 local f=$DIR/$tdir/$tfile
1644 local fid=$(copy_file /etc/passwd $f)
1645 $LFS hsm_archive $f || error "archive of $f failed"
1646 wait_request_state $fid ARCHIVE SUCCEED
1648 $LFS hsm_release $f || error "release of $f failed"
1652 [[ $? -eq 0 ]] || error "Restored file differs"
1654 run_test 12m "Archive/release/implicit restore"
1657 # test needs a running copytool
1661 copy2archive /etc/hosts $tdir/$tfile
1663 local f=$DIR/$tdir/$tfile
1664 import_file $tdir/$tfile $f
1666 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1667 error "Restored file differs"
1669 $LFS hsm_release $f || error "release of $f failed"
1673 run_test 12n "Import/implicit restore/release"
1676 # test needs a running copytool
1680 local f=$DIR/$tdir/$tfile
1681 local fid=$(copy_file /etc/hosts $f)
1683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1684 wait_request_state $fid ARCHIVE SUCCEED
1685 $LFS hsm_release $f || error "release of $f failed"
1687 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1688 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1690 # set no retry action mode
1693 diff -q /etc/hosts $f
1696 # we check we had a restore failure
1697 wait_request_state $fid RESTORE FAILED
1699 [[ $st -eq 0 ]] && error "Restore must fail"
1701 # remove no retry action mode
1704 # check file is still released
1705 check_hsm_flags $f "0x0000000d"
1707 # retry w/o failure injection
1708 do_facet $SINGLEMDS lctl set_param fail_loc=0
1710 # to be sure previous RESTORE result is gone
1712 wait_for_grace_delay
1714 diff -q /etc/hosts $f
1717 # we check we had a restore done
1718 wait_request_state $fid RESTORE SUCCEED
1720 [[ $st -eq 0 ]] || error "Restored file differs"
1722 run_test 12o "Layout-swap failure during Restore leaves file released"
1725 # test needs a running copytool
1729 local f=$DIR/$tdir/$tfile
1730 local fid=$(copy_file /etc/hosts $f)
1732 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1733 wait_request_state $fid ARCHIVE SUCCEED
1734 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1735 $LFS hsm_release $f || error "cannot release $f"
1736 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1737 $LFS hsm_release $f || error "cannot release $f"
1738 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1740 run_test 12p "implicit restore of a file on copytool mount point"
1742 cleanup_test_12q() {
1743 error "cannot umount $MOUNT3 on $SINGLEAGT"
1747 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1748 skip "need MDS version at least 2.7.58" && return 0
1750 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1751 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1752 error "cannot mount $MOUNT3 on $SINGLEAGT"
1754 # test needs a running copytool
1755 copytool setup -m "$MOUNT3"
1757 local f=$DIR/$tdir/$tfile
1758 local f2=$DIR2/$tdir/$tfile
1759 local fid=$(create_small_file $f)
1760 local orig_size=$(stat -c "%s" $f)
1762 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1763 wait_request_state $fid ARCHIVE SUCCEED
1765 $LFS hsm_release $f || error "could not release file"
1766 check_hsm_flags $f "0x0000000d"
1769 wait_copytools || error "copytool failed to stop"
1771 cat $f > /dev/null &
1773 # wait a bit to allow implicit restore request to be handled.
1774 # if not, next stat would also block on layout-lock.
1777 local size=$(stat -c "%s" $f2)
1778 [ $size -eq $orig_size ] ||
1779 error "$f2: wrong size after archive: $size != $orig_size"
1781 copytool setup -m "$MOUNT3"
1785 size=$(stat -c "%s" $f)
1786 [ $size -eq $orig_size ] ||
1787 error "$f: wrong size after restore: $size != $orig_size"
1789 size=$(stat -c "%s" $f2)
1790 [ $size -eq $orig_size ] ||
1791 error "$f2: wrong size after restore: $size != $orig_size"
1795 size=$(stat -c "%s" $f)
1797 error "$f: wrong size after overwrite: $size != 0"
1799 size=$(stat -c "%s" $f2)
1801 error "$f2: wrong size after overwrite: $size != 0"
1803 run_test 12q "file attributes are refreshed after restore"
1806 # test needs a running copytool
1809 local ARC_SUBDIR="import.orig"
1813 # populate directory to be imported
1814 for d in $(seq 1 10); do
1815 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1816 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1817 for f in $(seq 1 10); do
1818 CURR_FILE="$CURR_DIR/$tfile.$f"
1819 # write file-specific data
1820 do_facet $SINGLEAGT \
1821 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1822 "file=$CURR_FILE > $CURR_FILE"
1826 import_file "$ARC_SUBDIR" $DIR/$tdir
1827 # diff lustre content and origin (triggers file restoration)
1828 # there must be 10x10 identical files, and no difference
1829 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1830 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1831 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1832 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1834 [ $cnt_diff -eq 0 ] ||
1835 error "$cnt_diff imported files differ from read data"
1836 [ $cnt_ok -eq 100 ] ||
1837 error "not enough identical files ($cnt_ok != 100)"
1841 run_test 13 "Recursively import and restore a directory"
1844 # test needs a running copytool
1848 local f=$DIR/$tdir/$tfile
1849 local fid=$(create_small_file $f)
1850 local sum=$(md5sum $f | awk '{print $1}')
1851 $LFS hsm_archive $f || error "could not archive file"
1852 wait_request_state $fid ARCHIVE SUCCEED
1854 # create released file (simulate llapi_hsm_import call)
1855 local fid2=$(create_empty_file "$f")
1856 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1857 $LFS hsm_release $f || error "could not release file"
1859 # rebind the archive to the newly created file
1860 echo "rebind $fid to $fid2"
1862 do_facet $SINGLEAGT \
1863 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1864 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1866 # restore file and compare md5sum
1867 local sum2=$(md5sum $f | awk '{print $1}')
1869 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1873 run_test 14 "Rebind archived file to a new fid"
1876 # test needs a running copytool
1880 local f=$DIR/$tdir/$tfile
1882 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1886 for i in $(seq 1 $count); do
1887 fids[$i]=$(create_small_file $f.$i)
1888 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1889 $LFS hsm_archive $f.$i || error "could not archive file"
1891 wait_all_done $(($count*60))
1895 for i in $(seq 1 $count); do
1896 local fid2=$(create_empty_file "${f}.${i}")
1897 # add the rebind operation to the list
1898 echo ${fids[$i]} $fid2 >> $tmpfile
1900 # set it released (simulate llapi_hsm_import call)
1901 $LFS hsm_set --archived --exists $f.$i ||
1902 error "could not force hsm flags"
1903 $LFS hsm_release $f.$i || error "could not release file"
1905 nl=$(wc -l < $tmpfile)
1906 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1908 echo "rebind list of files"
1909 do_facet $SINGLEAGT \
1910 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1911 --rebind $tmpfile $DIR" || error "could not rebind file list"
1913 # restore files and compare md5sum
1914 for i in $(seq 1 $count); do
1915 local sum2=$(md5sum $f.$i | awk '{print $1}')
1916 [[ $sum2 == ${sums[$i]} ]] ||
1917 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1923 run_test 15 "Rebind a list of files"
1926 # test needs a running copytool
1930 # create a known size file so we can verify transfer speed
1933 dd if=/dev/zero of=$ref bs=1M count=20
1936 local f=$DIR/$tdir/$tfile
1937 local fid=$(copy_file $ref $f)
1939 local start=$(date +%s)
1941 wait_request_state $fid ARCHIVE SUCCEED
1942 local end=$(date +%s)
1943 # Add 1 to account for rounding errors between start and end (LU-8155)
1944 local duration=$((end - start + 1))
1946 [[ $duration -ge $((goal - 1)) ]] ||
1947 error "Transfer is too fast $duration < $goal"
1949 run_test 16 "Test CT bandwith control option"
1952 local f=$DIR/$tdir/$tfile
1953 create_empty_file "$f"
1955 # Could not release a non-archived file
1956 $LFS hsm_release $f && error "release should not succeed"
1958 # For following tests, we must test them with HS_ARCHIVED set
1959 $LFS hsm_set --exists --archived $f || error "could not add flag"
1961 # Could not release a file if no-release is set
1962 $LFS hsm_set --norelease $f || error "could not add flag"
1963 $LFS hsm_release $f && error "release should not succeed"
1964 $LFS hsm_clear --norelease $f || error "could not remove flag"
1966 # Could not release a file if lost
1967 $LFS hsm_set --lost $f || error "could not add flag"
1968 $LFS hsm_release $f && error "release should not succeed"
1969 $LFS hsm_clear --lost $f || error "could not remove flag"
1971 # Could not release a file if dirty
1972 $LFS hsm_set --dirty $f || error "could not add flag"
1973 $LFS hsm_release $f && error "release should not succeed"
1974 $LFS hsm_clear --dirty $f || error "could not remove flag"
1976 run_test 20 "Release is not permitted"
1979 # test needs a running copytool
1982 local f=$DIR/$tdir/test_release
1984 # Create a file and check its states
1985 local fid=$(create_small_file $f)
1986 check_hsm_flags $f "0x00000000"
1988 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1989 # used until file is flushed to disk
1990 if [ $(facet_fstype ost1) == "zfs" ]; then
1991 # this causes an OST_SYNC rpc to be sent
1992 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1993 # clear locks to reread file data
1994 cancel_lru_locks osc
1997 local orig_size=$(stat -c "%s" $f)
1998 local orig_blocks=$(stat -c "%b" $f)
2000 start_full_debug_logging
2002 $LFS hsm_archive $f || error "could not archive file"
2003 wait_request_state $fid ARCHIVE SUCCEED
2005 local blocks=$(stat -c "%b" $f)
2006 [ $blocks -eq $orig_blocks ] ||
2007 error "$f: wrong block number after archive: " \
2008 "$blocks != $orig_blocks"
2009 local size=$(stat -c "%s" $f)
2010 [ $size -eq $orig_size ] ||
2011 error "$f: wrong size after archive: $size != $orig_size"
2013 # Release and check states
2014 $LFS hsm_release $f || error "could not release file"
2015 check_hsm_flags $f "0x0000000d"
2017 blocks=$(stat -c "%b" $f)
2018 [ $blocks -gt 5 ] &&
2019 error "$f: too many blocks after release: $blocks > 5"
2020 size=$(stat -c "%s" $f)
2021 [ $size -ne $orig_size ] &&
2022 error "$f: wrong size after release: $size != $orig_size"
2024 # Check we can release an file without stripe info
2028 check_hsm_flags $f "0x00000000"
2029 $LFS hsm_archive $f || error "could not archive file"
2030 wait_request_state $fid ARCHIVE SUCCEED
2032 # Release and check states
2033 $LFS hsm_release $f || error "could not release file"
2034 check_hsm_flags $f "0x0000000d"
2036 # Release again a file that is already released is OK
2037 $LFS hsm_release $f || fail "second release should succeed"
2038 check_hsm_flags $f "0x0000000d"
2040 stop_full_debug_logging
2042 run_test 21 "Simple release tests"
2045 # test needs a running copytool
2048 local f=$DIR/$tdir/test_release
2049 local swap=$DIR/$tdir/test_swap
2051 # Create a file and check its states
2052 local fid=$(create_small_file $f)
2053 check_hsm_flags $f "0x00000000"
2055 $LFS hsm_archive $f || error "could not archive file"
2056 wait_request_state $fid ARCHIVE SUCCEED
2058 # Release and check states
2059 $LFS hsm_release $f || error "could not release file"
2060 check_hsm_flags $f "0x0000000d"
2062 create_small_file $swap
2063 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2067 run_test 22 "Could not swap a release file"
2070 # test needs a running copytool
2073 local f=$DIR/$tdir/test_mtime
2075 # Create a file and check its states
2076 local fid=$(create_small_file $f)
2077 check_hsm_flags $f "0x00000000"
2079 $LFS hsm_archive $f || error "could not archive file"
2080 wait_request_state $fid ARCHIVE SUCCEED
2082 # Set modification time in the past
2083 touch -m -a -d @978261179 $f
2085 # Release and check states
2086 $LFS hsm_release $f || error "could not release file"
2087 check_hsm_flags $f "0x0000000d"
2089 local MTIME=$(stat -c "%Y" $f)
2090 local ATIME=$(stat -c "%X" $f)
2091 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2092 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2094 run_test 23 "Release does not change a/mtime (utime)"
2097 local file=$DIR/$tdir/$tfile
2106 # test needs a running copytool
2109 fid=$(create_small_file $file)
2111 # Create a file and check its states
2112 check_hsm_flags $file "0x00000000"
2114 # Ensure atime is less than mtime and ctime.
2118 atime0=$(stat -c "%X" $file)
2119 mtime0=$(stat -c "%Y" $file)
2120 ctime0=$(stat -c "%Z" $file)
2122 [ $atime0 -lt $mtime0 ] ||
2123 error "atime $atime0 is not less than mtime $mtime0"
2125 [ $atime0 -lt $ctime0 ] ||
2126 error "atime $atime0 is not less than ctime $ctime0"
2128 # Archive should not change any timestamps.
2129 $LFS hsm_archive $file || error "cannot archive '$file'"
2130 wait_request_state $fid ARCHIVE SUCCEED
2132 atime1=$(stat -c "%X" $file)
2133 mtime1=$(stat -c "%Y" $file)
2134 ctime1=$(stat -c "%Z" $file)
2136 [ $atime0 -eq $atime1 ] ||
2137 error "archive changed atime from $atime0 to $atime1"
2139 [ $mtime0 -eq $mtime1 ] ||
2140 error "archive changed mtime from $mtime0 to $mtime1"
2142 [ $ctime0 -eq $ctime1 ] ||
2143 error "archive changed ctime from $ctime0 to $ctime1"
2145 # Release should not change any timestamps.
2146 $LFS hsm_release $file || error "cannot release '$file'"
2147 check_hsm_flags $file "0x0000000d"
2149 atime1=$(stat -c "%X" $file)
2150 mtime1=$(stat -c "%Y" $file)
2151 ctime1=$(stat -c "%Z" $file)
2153 [ $atime0 -eq $atime1 ] ||
2154 error "release changed atime from $atime0 to $atime1"
2156 [ $mtime0 -eq $mtime1 ] ||
2157 error "release changed mtime from $mtime0 to $mtime1"
2159 [ $ctime0 -eq $ctime1 ] ||
2160 error "release changed ctime from $ctime0 to $ctime1"
2162 # Restore should not change any timestamps.
2163 $LFS hsm_restore $file
2164 wait_request_state $fid RESTORE SUCCEED
2166 atime1=$(stat -c "%X" $file)
2167 mtime1=$(stat -c "%Y" $file)
2168 ctime1=$(stat -c "%Z" $file)
2170 [ $atime0 -eq $atime1 ] ||
2171 error "restore changed atime from $atime0 to $atime1"
2173 [ $mtime0 -eq $mtime1 ] ||
2174 error "restore changed mtime from $mtime0 to $mtime1"
2176 [ $ctime0 -eq $ctime1 ] ||
2177 error "restore changed ctime from $ctime0 to $ctime1"
2180 wait_copytools || error "Copytools failed to stop"
2182 # Once more, after unmount and mount.
2183 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2184 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2186 atime1=$(stat -c "%X" $file)
2187 mtime1=$(stat -c "%Y" $file)
2188 ctime1=$(stat -c "%Z" $file)
2190 [ $atime0 -eq $atime1 ] ||
2191 error "remount changed atime from $atime0 to $atime1"
2193 [ $mtime0 -eq $mtime1 ] ||
2194 error "remount changed mtime from $mtime0 to $mtime1"
2196 [ $ctime0 -eq $ctime1 ] ||
2197 error "remount changed ctime from $ctime0 to $ctime1"
2199 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2202 local file=$DIR/$tdir/$tfile
2208 # Test needs a running copytool.
2211 # Check that root can do HSM actions on a regular user's file.
2212 fid=$(create_small_file $file)
2213 sum0=$(md5sum $file)
2215 chown $RUNAS_ID:$RUNAS_GID $file ||
2216 error "cannot chown '$file' to '$RUNAS_ID'"
2218 chmod ugo-w $DIR/$tdir ||
2219 error "cannot chmod '$DIR/$tdir'"
2221 $LFS hsm_archive $file
2222 wait_request_state $fid ARCHIVE SUCCEED
2224 $LFS hsm_release $file
2225 check_hsm_flags $file "0x0000000d"
2227 $LFS hsm_restore $file
2228 wait_request_state $fid RESTORE SUCCEED
2230 # Check that ordinary user can get HSM state.
2231 $RUNAS $LFS hsm_state $file ||
2232 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2234 $LFS hsm_release $file
2235 check_hsm_flags $file "0x0000000d"
2237 # Check that ordinary user can accessed released file.
2238 sum1=$($RUNAS md5sum $file) ||
2239 error "user '$RUNAS_ID' cannot read '$file'"
2241 [ "$sum0" == "$sum1" ] ||
2242 error "md5sum mismatch for '$file'"
2244 run_test 24b "root can archive, release, and restore user files"
2247 local file=$DIR/$tdir/$tfile
2248 local action=archive
2253 # test needs a running copytool
2258 # Save the default masks and check that cleanup_24c will
2259 # restore the request masks correctly.
2260 user_save=$(get_hsm_param user_request_mask)
2261 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2262 group_save=$(get_hsm_param group_request_mask)
2263 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2264 other_save=$(get_hsm_param other_request_mask)
2265 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2267 [ "$user_save" == RESTORE ] ||
2268 error "user_request_mask is '$user_save' expected 'RESTORE'"
2269 [ "$group_save" == RESTORE ] ||
2270 error "group_request_mask is '$group_save' expected 'RESTORE'"
2271 [ "$other_save" == RESTORE ] ||
2272 error "other_request_mask is '$other_save' expected 'RESTORE'"
2275 create_small_file $file
2276 chown $RUNAS_ID:$GROUP $file ||
2277 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2279 $RUNAS $LFS hsm_$action $file &&
2280 error "$action by user should fail"
2282 set_hsm_param user_request_mask $action
2283 $RUNAS $LFS hsm_$action $file ||
2284 error "$action by user should succeed"
2287 create_small_file $file
2288 chown nobody:$RUNAS_GID $file ||
2289 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2291 $RUNAS $LFS hsm_$action $file &&
2292 error "$action by group should fail"
2294 set_hsm_param group_request_mask $action
2295 $RUNAS $LFS hsm_$action $file ||
2296 error "$action by group should succeed"
2299 create_small_file $file
2300 chown nobody:$GROUP $file ||
2301 error "cannot chown '$file' to 'nobody:$GROUP'"
2303 $RUNAS $LFS hsm_$action $file &&
2304 error "$action by other should fail"
2306 set_hsm_param other_request_mask $action
2307 $RUNAS $LFS hsm_$action $file ||
2308 error "$action by other should succeed"
2310 run_test 24c "check that user,group,other request masks work"
2313 local file1=$DIR/$tdir/$tfile
2314 local file2=$DIR2/$tdir/$tfile
2318 fid1=$(create_small_file $file1)
2321 $LFS getstripe $file1
2323 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2324 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2325 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2327 copytool setup -m "$MOUNT3"
2329 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2330 mount -o remount,ro $MOUNT2
2332 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2334 fid2=$(path2fid $file2)
2335 [ "$fid1" == "$fid2" ] ||
2336 error "FID mismatch '$fid1' != '$fid2'"
2338 $LFS hsm_archive $file2 &&
2339 error "archive should fail on read-only mount"
2340 check_hsm_flags $file1 "0x00000000"
2342 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2343 wait_request_state $fid1 ARCHIVE SUCCEED
2345 $LFS hsm_release $file1
2346 $LFS hsm_restore $file2
2347 wait_request_state $fid1 RESTORE SUCCEED
2349 $LFS hsm_release $file1 || error "cannot release '$file1'"
2350 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2352 $LFS hsm_release $file2 &&
2353 error "release should fail on read-only mount"
2357 run_test 24d "check that read-only mounts are respected"
2362 local f=$DIR/$tdir/$tfile
2365 fid=$(create_small_file $f) || error "cannot create $f"
2366 $LFS hsm_archive $f || error "cannot archive $f"
2367 wait_request_state $fid ARCHIVE SUCCEED
2368 $LFS hsm_release $f || error "cannot release $f"
2369 while ! $LFS hsm_state $f | grep released; do
2373 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2375 run_test 24e "tar succeeds on HSM released files" # LU-6213
2378 # test needs a running copytool
2381 mkdir -p $DIR/$tdir/d1
2382 local f=$DIR/$tdir/$tfile
2383 local fid=$(copy_file /etc/hosts $f)
2386 $LFS hsm_archive $f ||
2387 error "hsm_archive failed"
2388 wait_request_state $fid ARCHIVE SUCCEED
2389 $LFS hsm_release $f || error "cannot release $f"
2390 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2393 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2394 error "Can not recover the tar contents"
2396 echo "Sum0 = $sum0, sum1 = $sum1"
2397 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2399 run_test 24f "root can archive, release, and restore tar files"
2402 # test needs a running copytool
2406 copy2archive /etc/hosts $tdir/$tfile
2408 local f=$DIR/$tdir/$tfile
2410 import_file $tdir/$tfile $f
2412 $LFS hsm_set --lost $f
2417 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2421 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2422 " (Operation not permitted)"
2425 # test needs a running copytool
2430 local f=$DIR/$tdir/$tfile
2431 local fid=$(copy_file /etc/passwd $f)
2433 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2434 wait_request_state $fid ARCHIVE SUCCEED
2437 $LFS hsm_set --lost $f
2441 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2443 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2444 " (Operation not permitted)"
2446 test_26A() { # was test_26
2447 # test needs a running copytool
2450 local f=$DIR/$tdir/$tfile
2452 fid=$(make_custom_file_for_progress $f 39 1000000)
2453 [ $? != 0 ] && skip "not enough free space" && return
2455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2456 wait_request_state $fid ARCHIVE SUCCEED
2459 wait_request_state $fid REMOVE SUCCEED
2461 check_hsm_flags $f "0x00000000"
2463 run_test 26A "Remove the archive of a valid file"
2466 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2467 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2469 # test needs a running copytool
2473 local f=$DIR/$tdir/$tfile
2474 local fid=$(copy_file /etc/passwd $f)
2476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2477 wait_request_state $fid ARCHIVE SUCCEED
2479 local f2=$DIR/$tdir/${tfile}_2
2480 local fid2=$(copy_file /etc/passwd $f2)
2482 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2483 wait_request_state $fid2 ARCHIVE SUCCEED
2485 local f3=$DIR/$tdir/${tfile}_3
2486 local fid3=$(copy_file /etc/passwd $f3)
2488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2489 wait_request_state $fid3 ARCHIVE SUCCEED
2491 # set a long grace_delay vs short loop_period
2492 local orig_loop_period=$(get_hsm_param loop_period)
2493 local orig_grace_delay=$(get_hsm_param grace_delay)
2494 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2495 set_hsm_param loop_period 10
2496 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2497 set_hsm_param grace_delay 100
2501 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2502 set_hsm_param remove_archive_on_last_unlink 1
2504 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2509 set_hsm_param remove_archive_on_last_unlink 0
2511 wait_request_state $fid2 REMOVE SUCCEED
2513 assert_request_count $fid REMOVE 0 \
2514 "Unexpected archived data remove request for $f"
2515 assert_request_count $fid3 REMOVE 0 \
2516 "Unexpected archived data remove request for $f3"
2518 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2521 # test needs a running copytool
2525 local f=$DIR/$tdir/$tfile
2526 local fid=$(copy_file /etc/passwd $f)
2528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2529 wait_request_state $fid ARCHIVE SUCCEED
2531 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2532 set_hsm_param remove_archive_on_last_unlink 1
2535 cdt_check_state stopped
2539 set_hsm_param remove_archive_on_last_unlink 0
2541 wait_request_state $fid REMOVE WAITING
2545 # copytool must re-register
2547 wait_copytools || error "copytool failed to stop"
2550 wait_request_state $fid REMOVE SUCCEED
2552 run_test 26b "RAoLU policy when CDT off"
2555 # test needs a running copytool
2559 local f=$DIR/$tdir/$tfile
2560 local fid=$(copy_file /etc/passwd $f)
2562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2563 wait_request_state $fid ARCHIVE SUCCEED
2565 local f2=$DIR/$tdir/${tfile}_2
2566 local fid2=$(copy_file /etc/passwd $f2)
2568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2569 wait_request_state $fid2 ARCHIVE SUCCEED
2571 # set a long grace_delay vs short loop_period
2572 local orig_loop_period=$(get_hsm_param loop_period)
2573 local orig_grace_delay=$(get_hsm_param grace_delay)
2574 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2575 set_hsm_param loop_period 10
2576 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2577 set_hsm_param grace_delay 100
2579 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2580 set_hsm_param remove_archive_on_last_unlink 1
2582 multiop_bg_pause $f O_c || error "open $f failed"
2588 wait_request_state $fid2 REMOVE SUCCEED
2589 assert_request_count $fid REMOVE 0 \
2590 "Unexpected archived data remove request for $f"
2592 kill -USR1 $pid || error "multiop early exit"
2593 # should reach autotest timeout if multiop fails to trap
2594 # signal, close file, and exit ...
2595 wait $pid || error "wait PID $PID failed"
2597 set_hsm_param remove_archive_on_last_unlink 0
2599 wait_request_state $fid REMOVE SUCCEED
2601 run_test 26c "RAoLU effective when file closed"
2604 # test needs a running copytool
2608 local f=$DIR/$tdir/$tfile
2609 local fid=$(create_small_file $f)
2611 $LFS hsm_archive $f || error "could not archive file"
2612 wait_request_state $fid ARCHIVE SUCCEED
2614 # set a long grace_delay vs short loop_period
2615 local orig_loop_period=$(get_hsm_param loop_period)
2616 local orig_grace_delay=$(get_hsm_param grace_delay)
2617 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2618 set_hsm_param loop_period 10
2619 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2620 set_hsm_param grace_delay 100
2622 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2623 set_hsm_param remove_archive_on_last_unlink 1
2625 multiop_bg_pause $f O_c || error "multiop failed"
2632 set_hsm_param remove_archive_on_last_unlink 0
2634 wait_request_state $fid REMOVE SUCCEED
2636 client_up || client_up || true
2638 kill -USR1 $MULTIPID
2639 wait $MULTIPID || error "multiop close failed"
2641 run_test 26d "RAoLU when Client eviction"
2644 # test needs a running copytool
2647 create_archive_file $tdir/$tfile
2648 local f=$DIR/$tdir/$tfile
2649 import_file $tdir/$tfile $f
2650 local fid=$(path2fid $f)
2654 [[ $? != 0 ]] || error "Remove of a released file should fail"
2658 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2661 # test needs a running copytool
2664 local f=$DIR/$tdir/$tfile
2666 fid=$(make_custom_file_for_progress $f 39 1000000)
2667 [ $? != 0 ] && skip "not enough free space" && return
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE SUCCEED
2675 [[ $? != 0 ]] || error "Remove of a released file should fail"
2677 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2680 # test needs a running copytool
2683 local f=$DIR/$tdir/$tfile
2685 fid=$(make_custom_file_for_progress $f 39 1000000)
2686 [ $? != 0 ] && skip "not enough free space" && return
2688 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2689 wait_request_state $fid ARCHIVE SUCCEED
2698 wait_request_state $fid REMOVE SUCCEED
2700 run_test 28 "Concurrent archive/file remove"
2703 # Tests --mntpath and --archive options
2706 copytool setup -m "$MOUNT" -a $archive_id
2708 # Bad archive number
2709 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2710 grep "Invalid argument" ||
2711 error "unexpected hsm_remove failure (1)"
2713 # mntpath is present but file is given
2714 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2715 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2716 error "unexpected hsm_remove failure (2)"
2718 run_test 29a "Tests --mntpath and --archive options"
2721 # test needs a running copytool
2724 local f=$DIR/$tdir/$tfile
2725 local fid=$(create_small_file $f)
2727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2728 wait_request_state $fid ARCHIVE SUCCEED
2732 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2733 wait_request_state $fid REMOVE SUCCEED
2735 run_test 29b "Archive/delete/remove by FID from the archive."
2738 # test needs a running copytool
2741 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2742 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2743 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2745 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2746 wait_request_state $fid1 ARCHIVE SUCCEED
2747 wait_request_state $fid2 ARCHIVE SUCCEED
2748 wait_request_state $fid3 ARCHIVE SUCCEED
2750 rm -f $DIR/$tdir/$tfile-[1-3]
2752 echo $fid1 > $DIR/$tdir/list
2753 echo $fid2 >> $DIR/$tdir/list
2754 echo $fid3 >> $DIR/$tdir/list
2756 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2757 --filelist $DIR/$tdir/list
2758 wait_request_state $fid1 REMOVE SUCCEED
2759 wait_request_state $fid2 REMOVE SUCCEED
2760 wait_request_state $fid3 REMOVE SUCCEED
2762 run_test 29c "Archive/delete/remove by FID, using a file list."
2765 # test needs more than one CT
2766 needclients 3 || return 0
2772 # start all of the copytools
2773 for n in $(seq $AGTCOUNT); do
2774 copytool setup -f agt$n -a $n
2778 file=$DIR/$tdir/$tfile
2779 fid=$(create_small_file $file)
2781 $LFS hsm_archive $file
2782 wait_request_state $fid ARCHIVE SUCCEED
2783 check_hsm_flags $file "0x00000009"
2787 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2788 error "cannot hsm_remove '$fid'"
2790 # give time for CDT to handle remove request and create broadcasted
2793 # remove request has been broadcasted ?
2794 local cnt=$(get_request_count $fid REMOVE)
2795 # broadcasted requests + original
2796 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2797 error "remove not broadcasted to all CTs"
2799 # give time for CDT and CTs to handle broadcasted
2800 wait_for_loop_period
2802 # each agent serves one different archive_id, so broadcasted
2803 # hsm_remove request should only succeed once and fail at all others
2807 for n in $(seq $AGTCOUNT); do
2808 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2809 $HSM_PARAM.actions | awk \
2810 '/'$fid'.*action=REMOVE archive#='$n'/ \
2811 {print \\\$13}' | cut -f2 -d=")
2812 if [[ "$res" == "SUCCEED" ]]; then
2814 elif [[ "$res" == "FAILED" ]]; then
2819 [[ $scnt -eq 1 ]] ||
2820 error "one and only CT should have removed successfully"
2822 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2823 error "all but one CT should have failed to remove"
2825 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2826 "request to be sent once for each registered archive_id"
2829 # restore at exec cannot work on agent node (because of Linux kernel
2830 # protection of executables)
2831 needclients 2 || return 0
2833 # test needs a running copytool
2837 copy2archive /bin/true $tdir/$tfile
2839 local f=$DIR/$tdir/true
2840 import_file $tdir/$tfile $f
2842 local fid=$(path2fid $f)
2844 # set no retry action mode
2850 # remove no try action mode
2854 [[ $st == 0 ]] || error "Failed to exec a released file"
2858 run_test 30a "Restore at exec (import case)"
2861 # restore at exec cannot work on agent node (because of Linux kernel
2862 # protection of executables)
2863 needclients 2 || return 0
2865 # test needs a running copytool
2869 local f=$DIR/$tdir/true
2870 local fid=$(copy_file /bin/true $f)
2872 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2873 wait_request_state $fid ARCHIVE SUCCEED
2877 stack_trap cdt_clear_no_retry EXIT
2878 # set no retry action mode
2886 [[ $st == 0 ]] || error "Failed to exec a released file"
2888 run_test 30b "Restore at exec (release case)"
2891 needclients 2 || return 0
2893 # test needs a running copytool
2897 local f=$DIR/$tdir/SLEEP
2898 local slp_sum1=$(md5sum /bin/sleep)
2899 local fid=$(copy_file /bin/sleep $f)
2901 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2902 wait_request_state $fid ARCHIVE SUCCEED
2904 check_hsm_flags $f "0x0000000d"
2906 stack_trap cdt_clear_no_retry EXIT
2907 # set no retry action mode
2910 do_node $CLIENT2 "$f 10" &
2914 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2916 [[ $? == 0 ]] || error "Execution failed during run"
2918 if [[ $? != 0 ]]; then
2919 local slp_sum2=$(md5sum /bin/sleep)
2920 # in case sleep file is modified during the test
2921 [[ $slp_sum1 == $slp_sum2 ]] &&
2922 error "Binary overwritten during exec"
2925 check_hsm_flags $f "0x00000009"
2927 run_test 30c "Update during exec of released file must fail"
2929 restore_and_check_size() {
2932 local s=$(stat -c "%s" $f)
2934 local st=$(get_hsm_flags $f)
2938 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2940 n=$(stat -c "%s" $f)
2941 # we echo in both cases to show stat is not hang
2942 if [[ $n != $s ]]; then
2943 echo "size seen is $n != $s"
2946 echo "size seen is right: $n == $s"
2950 st=$(get_hsm_flags $f)
2952 if [[ "$st" = "0x00000009" ]]; then
2955 echo " restore is too long"
2956 wait_request_state $fid RESTORE SUCCEED
2962 # test needs a running copytool
2965 create_archive_file $tdir/$tfile
2966 local f=$DIR/$tdir/$tfile
2967 import_file $tdir/$tfile $f
2968 local fid=$($LFS path2fid $f)
2969 HSM_ARCHIVE_PURGE=false copytool_setup
2971 restore_and_check_size $f $fid
2974 [[ $err -eq 0 ]] || error "File size changed during restore"
2978 run_test 31a "Import a large file and check size during restore"
2982 # test needs a running copytool
2985 local f=$DIR/$tdir/$tfile
2987 fid=$(make_custom_file_for_progress $f 39 1000000)
2988 [ $? != 0 ] && skip "not enough free space" && return
2990 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2991 wait_request_state $fid ARCHIVE SUCCEED
2994 restore_and_check_size $f $fid
2997 [[ $err -eq 0 ]] || error "File size changed during restore"
2999 run_test 31b "Restore a large unaligned file and check size during restore"
3002 # test needs a running copytool
3005 local f=$DIR/$tdir/$tfile
3007 fid=$(make_custom_file_for_progress $f 33 1048576)
3008 [ $? != 0 ] && skip "not enough free space" && return
3010 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3011 wait_request_state $fid ARCHIVE SUCCEED
3014 restore_and_check_size $f $fid
3017 [[ $err -eq 0 ]] || error "File size changed during restore"
3019 run_test 31c "Restore a large aligned file and check size during restore"
3022 # test needs a running copytool
3025 local f=$DIR/$tdir/$tfile
3027 fid=$(make_custom_file_for_progress $f 39 1000000)
3028 [ $? != 0 ] && skip "not enough free space" && return
3030 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3031 wait_request_state $fid ARCHIVE SUCCEED
3034 # to be sure wait_all_done will not be mislead by previous tests
3037 wait_for_grace_delay
3038 # Also raise grace_delay significantly so the Canceled
3039 # Restore action will stay enough long avail.
3040 local old_grace=$(get_hsm_param grace_delay)
3041 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3042 set_hsm_param grace_delay 100
3044 md5sum $f >/dev/null &
3046 wait_request_state $fid RESTORE STARTED
3051 # Check restore trigger process was killed
3052 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3056 # instead of waiting+checking both Restore and Cancel ops
3057 # sequentially, wait for both to be finished and then check
3059 wait_all_done 100 $fid
3060 local rstate=$(get_request_state $fid RESTORE)
3061 local cstate=$(get_request_state $fid CANCEL)
3063 if [[ "$rstate" == "CANCELED" ]] ; then
3064 [[ "$cstate" == "SUCCEED" ]] ||
3065 error "Restore state is CANCELED and Cancel state " \
3066 "is not SUCCEED but $cstate"
3067 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3068 elif [[ "$rstate" == "SUCCEED" ]] ; then
3069 [[ "$cstate" == "FAILED" ]] ||
3070 error "Restore state is SUCCEED and Cancel state " \
3071 "is not FAILED but $cstate"
3072 echo "Restore state is SUCCEED, Cancel state is FAILED"
3074 error "Restore state is $rstate and Cancel state is $cstate"
3078 error "Cannot kill process waiting for restore ($killed)"
3080 run_test 33 "Kill a restore waiting process"
3083 # test needs a running copytool
3086 local f=$DIR/$tdir/$tfile
3088 fid=$(make_custom_file_for_progress $f 39 1000000)
3089 [ $? != 0 ] && skip "not enough free space" && return
3091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3092 wait_request_state $fid ARCHIVE SUCCEED
3095 md5sum $f >/dev/null &
3097 wait_request_state $fid RESTORE STARTED
3099 rm $f || error "rm $f failed"
3100 # rm must not block during restore
3101 wait_request_state $fid RESTORE STARTED
3103 wait_request_state $fid RESTORE SUCCEED
3104 # check md5sum pgm finished
3105 local there=$(ps -o pid,comm hp $pid >/dev/null)
3106 [[ -z $there ]] || error "Restore initiator does not exit"
3108 wait $pid || error "Restore initiator failed with $?"
3110 run_test 34 "Remove file during restore"
3113 # test needs a running copytool
3116 local f=$DIR/$tdir/$tfile
3117 local f1=$DIR/$tdir/$tfile-1
3119 fid=$(make_custom_file_for_progress $f 39 1000000)
3120 [ $? != 0 ] && skip "not enough free space" && return
3122 local fid1=$(copy_file /etc/passwd $f1)
3123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3124 wait_request_state $fid ARCHIVE SUCCEED
3127 md5sum $f >/dev/null &
3129 wait_request_state $fid RESTORE STARTED
3131 mv $f1 $f || error "mv $f1 $f failed"
3132 # mv must not block during restore
3133 wait_request_state $fid RESTORE STARTED
3135 wait_request_state $fid RESTORE SUCCEED
3136 # check md5sum pgm finished
3137 local there=$(ps -o pid,comm hp $pid >/dev/null)
3138 [[ -z $there ]] || error "Restore initiator does not exit"
3140 wait $pid || error "Restore initiator failed with $?"
3143 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3145 run_test 35 "Overwrite file during restore"
3148 # test needs a running copytool
3151 local f=$DIR/$tdir/$tfile
3153 fid=$(make_custom_file_for_progress $f 39 1000000)
3154 [ $? != 0 ] && skip "not enough free space" && return
3156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3157 wait_request_state $fid ARCHIVE SUCCEED
3160 md5sum $f >/dev/null &
3162 wait_request_state $fid RESTORE STARTED
3165 # rm must not block during restore
3166 wait_request_state $fid RESTORE STARTED
3168 wait_request_state $fid RESTORE SUCCEED
3169 # check md5sum pgm finished
3170 local there=$(ps -o pid,comm hp $pid >/dev/null)
3172 error "Restore initiator does not exit"
3174 wait $pid || error "Restore initiator failed with $?"
3176 run_test 36 "Move file during restore"
3179 # LU-5683: check that an archived dirty file can be rearchived.
3182 local f=$DIR/$tdir/$tfile
3185 fid=$(create_small_file $f) || error "cannot create small file"
3187 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3188 wait_request_state $fid ARCHIVE SUCCEED
3189 $LFS hsm_release $f || error "cannot release $f"
3191 # Allow previous archive request to expire from the actions log.
3192 wait_for_grace_delay
3195 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3198 wait_request_state $fid ARCHIVE SUCCEED
3200 run_test 37 "re-archive a dirty file"
3207 for n in $(seq 1 $count); do
3208 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3210 echo "$count archive requests submitted"
3214 local stream_count=4
3215 local file_count=100
3217 local f=$DIR/$tdir/$tfile
3221 local max_requests=$(get_hsm_param max_requests)
3223 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3224 # Increase the number of HSM request that can be performed in
3225 # parallel. With the coordinator running once per second, this
3226 # also limits the number of requests per seconds that can be
3227 # performed, so we pick a decent number. But we also need to keep
3228 # that number low because the copytool has no rate limit and will
3229 # fail some requests if if gets too many at once.
3230 set_hsm_param max_requests 300
3232 for i in $(seq 1 $file_count); do
3233 for p in $(seq 1 $stream_count); do
3234 fid=$(copy_file /etc/hosts $f.$p.$i)
3240 # to be sure wait_all_done will not be mislead by previous tests
3242 wait_for_grace_delay
3244 # start archive streams in background (archive files in parallel)
3245 for p in $(seq 1 $stream_count); do
3246 multi_archive $f.$p $file_count &
3249 echo -n "Wait for all requests being enqueued..."
3254 run_test 40 "Parallel archive requests"
3257 # test needs a running copytool
3261 local f=$DIR/$tdir/$tfile
3262 local fid=$(create_small_file $f)
3264 $LFS hsm_archive $f || error "could not archive file"
3265 wait_request_state $fid ARCHIVE SUCCEED
3266 check_hsm_flags $f "0x00000009"
3268 multiop_bg_pause $f O_c || error "multiop failed"
3272 client_up || client_up || true
3274 kill -USR1 $MULTIPID
3275 wait $MULTIPID || error "multiop close failed"
3277 check_hsm_flags $f "0x0000000b"
3279 run_test 52 "Opened for write file on an evicted client should be set dirty"
3282 # test needs a running copytool
3286 local f=$DIR/$tdir/$tfile
3287 local fid=$(create_small_file $f)
3289 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3290 error "could not archive file"
3291 wait_request_state $fid ARCHIVE SUCCEED
3292 check_hsm_flags $f "0x00000009"
3294 multiop_bg_pause $f o_c || error "multiop failed"
3298 client_up || client_up || true
3300 kill -USR1 $MULTIPID
3301 wait $MULTIPID || error "multiop close failed"
3303 check_hsm_flags $f "0x00000009"
3305 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3308 # test needs a running copytool
3311 local f=$DIR/$tdir/$tfile
3312 local fid=$(make_custom_file_for_progress $f 39 1000000)
3314 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3315 error "could not archive file"
3316 wait_request_state $fid ARCHIVE STARTED
3318 check_hsm_flags $f "0x00000001"
3320 stack_trap "cdt_clear_no_retry" EXIT
3321 # Avoid coordinator resending this request as soon it has failed.
3326 wait_request_state $fid ARCHIVE FAILED
3328 check_hsm_flags $f "0x00000003"
3330 run_test 54 "Write during an archive cancels it"
3333 # test needs a running copytool
3336 local f=$DIR/$tdir/$tfile
3337 local fid=$(make_custom_file_for_progress $f 39 1000000)
3339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3340 error "could not archive file"
3341 wait_request_state $fid ARCHIVE STARTED
3343 check_hsm_flags $f "0x00000001"
3345 stack_trap "cdt_clear_no_retry" EXIT
3346 # Avoid coordinator resending this request as soon it has failed.
3349 $TRUNCATE $f 1024 || error "truncate failed"
3351 wait_request_state $fid ARCHIVE FAILED
3353 check_hsm_flags $f "0x00000003"
3355 run_test 55 "Truncate during an archive cancels it"
3358 # test needs a running copytool
3361 local f=$DIR/$tdir/$tfile
3363 fid=$(make_custom_file_for_progress $f 39 1000000)
3364 [ $? != 0 ] && skip "not enough free space" && return
3366 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3367 error "could not archive file"
3368 wait_request_state $fid ARCHIVE STARTED
3370 check_hsm_flags $f "0x00000001"
3372 # Change metadata and sync to be sure we are not changing only
3377 wait_request_state $fid ARCHIVE SUCCEED
3379 check_hsm_flags $f "0x00000009"
3381 run_test 56 "Setattr during an archive is ok"
3384 # Need one client for I/O, one for request
3385 needclients 2 || return 0
3387 # test needs a running copytool
3391 local f=$DIR/$tdir/test_archive_remote
3392 # Create a file on a remote node
3393 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3394 "count=2 conv=fsync"
3397 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3398 error "hsm_archive failed"
3399 local fid=$(path2fid $f)
3400 wait_request_state $fid ARCHIVE SUCCEED
3402 # Release and implicit restore it
3403 do_node $CLIENT2 "$LFS hsm_release $f" ||
3404 error "hsm_release failed"
3405 do_node $CLIENT2 "md5sum $f" ||
3406 error "hsm_restore failed"
3408 wait_request_state $fid RESTORE SUCCEED
3410 run_test 57 "Archive a file with dirty cache on another node"
3412 truncate_released_file() {
3416 local sz=$(stat -c %s $src_file)
3417 local f=$DIR/$tdir/$tfile
3418 local fid=$(copy_file $1 $f)
3422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3423 error "could not archive file"
3424 wait_request_state $fid ARCHIVE SUCCEED
3426 $LFS hsm_release $f || error "could not release file"
3428 $TRUNCATE $f $trunc_to || error "truncate failed"
3431 local sz1=$(stat -c %s $f)
3432 [[ $sz1 == $trunc_to ]] ||
3433 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3436 check_hsm_flags $f "0x0000000b"
3438 local state=$(get_request_state $fid RESTORE)
3439 [[ "$state" == "SUCCEED" ]] ||
3440 error "truncate $sz does not trig restore, state = $state"
3442 $TRUNCATE $ref $trunc_to
3443 cmp $ref $f || error "file data wrong after truncate"
3449 # test needs a running copytool
3454 local sz=$(stat -c %s /etc/passwd)
3456 echo "truncate up from $sz to $((sz*2))"
3457 truncate_released_file /etc/passwd $((sz*2))
3459 echo "truncate down from $sz to $((sz/2))"
3460 truncate_released_file /etc/passwd $((sz/2))
3462 echo "truncate to 0"
3463 truncate_released_file /etc/passwd 0
3465 run_test 58 "Truncate a released file will trigger restore"
3469 local server_version=$(lustre_version_code $SINGLEMDS)
3470 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3471 skip "Need MDS version at least 2.7.63" && return
3474 $MCREATE $DIR/$tfile || error "mcreate failed"
3475 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3476 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3477 fid=$(path2fid $DIR/$tfile)
3478 wait_request_state $fid ARCHIVE SUCCEED
3479 $LFS hsm_release $DIR/$tfile || error "release failed"
3481 run_test 59 "Release stripeless file with non-zero size"
3484 # This test validates the fix for LU-4512. Ensure that the -u
3485 # option changes the progress reporting interval from the
3486 # default (30 seconds) to the user-specified interval.
3488 local progress_timeout=$((interval * 4))
3490 copytool setup -b 1 --update-interval $interval
3492 local f=$DIR/$tdir/$tfile
3494 fid=$(make_custom_file_for_progress $f 10)
3495 [ $? != 0 ] && skip "not enough free space" && return
3498 local mdt=${MDT_PREFIX}${mdtidx}
3499 local mds=mds$((mdtidx + 1))
3501 # Wait for copytool to register
3502 wait_update_facet $mds \
3503 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3504 uuid 100 || error "coyptool failed to register with $mdt"
3506 local start_at=$(date +%s)
3507 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3508 error "could not archive file"
3510 local agent=$(facet_active_host $SINGLEAGT)
3511 local logfile=$(copytool_logfile $SINGLEAGT)
3513 wait_update $agent \
3514 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3515 error "copytool failed to start"
3517 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3518 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3524 echo -n "Expecting a progress update within $progress_timeout seconds... "
3526 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3527 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3528 echo "$RESULT bytes copied in $WAIT seconds."
3530 elif [ $WAIT -ge $progress_timeout ]; then
3531 error "Timed out waiting for progress update!"
3534 WAIT=$((WAIT + sleep))
3538 local finish_at=$(date +%s)
3539 local elapsed=$((finish_at - start_at))
3541 # Ensure that the progress update occurred within the expected window.
3542 if [ $elapsed -lt $((interval - 1)) ]; then
3543 error "Expected progress update after at least $interval seconds"
3546 echo "Wait for on going archive hsm action to complete"
3547 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3548 echo "File archiving not completed even after 10 secs"
3550 run_test 60 "Changing progress update interval from default"
3553 # test needs a running copytool
3557 local f=$DIR/$tdir/$tfile
3558 local fid=$(copy_file /etc/passwd $f)
3560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3563 wait_request_state $fid ARCHIVE FAILED
3565 run_test 61 "Waiting archive of a removed file should fail"
3568 # test needs a new running copytool
3569 stack_trap copytool_monitor_cleanup EXIT
3570 copytool_monitor_setup
3571 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3573 # Wait for the copytool to register.
3574 wait_update --verbose $(facet_active_host mds1) \
3575 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3577 error "copytool failed to register with MDT0000"
3580 wait_copytools || error "Copytools failed to stop"
3582 local REGISTER_EVENT
3583 local UNREGISTER_EVENT
3584 while read event; do
3585 local parsed=$(parse_json_event "$event")
3586 if [ -z "$parsed" ]; then
3587 error "Copytool sent malformed event: $event"
3591 if [ $event_type == "REGISTER" ]; then
3592 REGISTER_EVENT=$event
3593 elif [ $event_type == "UNREGISTER" ]; then
3594 UNREGISTER_EVENT=$event
3596 done < <(echo $"$(get_copytool_event_log)")
3598 if [ -z "$REGISTER_EVENT" ]; then
3599 error "Copytool failed to send register event to FIFO"
3602 if [ -z "$UNREGISTER_EVENT" ]; then
3603 error "Copytool failed to send unregister event to FIFO"
3606 echo "Register/Unregister events look OK."
3608 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3611 # Bump progress interval for livelier events.
3614 # test needs a new running copytool
3615 stack_trap copytool_monitor_cleanup EXIT
3616 copytool_monitor_setup
3617 copytool setup --update-interval $interval --event-fifo \
3618 "$HSMTOOL_MONITOR_DIR/fifo"
3620 stack_trap "cdt_clear_no_retry" EXIT
3621 # Just start and stop the copytool to generate events.
3624 local f=$DIR/$tdir/$tfile
3626 fid=$(make_custom_file_for_progress $f 39 1000000)
3627 [ $? != 0 ] && skip "not enough free space" && return
3629 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3630 error "could not archive file"
3631 wait_request_state $fid ARCHIVE SUCCEED
3633 local expected_fields="event_time data_fid source_fid"
3634 expected_fields+=" total_bytes current_bytes"
3638 while read event; do
3639 # Make sure we're not getting anything from previous events.
3640 for field in $expected_fields; do
3644 local parsed=$(parse_json_event "$event")
3645 if [ -z "$parsed" ]; then
3646 error "Copytool sent malformed event: $event"
3650 if [ $event_type == "ARCHIVE_START" ]; then
3653 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3656 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3660 # Do some simple checking of the progress update events.
3661 for expected_field in $expected_fields; do
3662 if [ -z ${!expected_field+x} ]; then
3663 error "Missing $expected_field field in event"
3667 if [ $total_bytes -eq 0 ]; then
3668 error "Expected total_bytes to be > 0"
3671 # These should be identical throughout an archive
3673 if [ $source_fid != $data_fid ]; then
3674 error "Expected source_fid to equal data_fid"
3676 done < <(echo $"$(get_copytool_event_log)")
3678 if [ -z "$START_EVENT" ]; then
3679 error "Copytool failed to send archive start event to FIFO"
3682 if [ -z "$FINISH_EVENT" ]; then
3683 error "Copytool failed to send archive finish event to FIFO"
3686 echo "Archive events look OK."
3688 run_test 71 "Copytool logs JSON archive events to FIFO"
3691 # Bump progress interval for livelier events.
3694 # test needs a new running copytool
3696 copytool_monitor_setup
3697 HSMTOOL_UPDATE_INTERVAL=$interval \
3698 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3699 local test_file=$HSMTOOL_MONITOR_DIR/file
3701 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3703 do_facet $SINGLEAGT "$cmd" ||
3704 error "cannot create $test_file on $SINGLEAGT"
3705 copy2archive $test_file $tdir/$tfile
3708 local f=$DIR/$tdir/$tfile
3709 import_file $tdir/$tfile $f
3710 f=$DIR2/$tdir/$tfile
3711 echo "Verifying released state: "
3712 check_hsm_flags $f "0x0000000d"
3714 local fid=$(path2fid $f)
3716 wait_request_state $fid RESTORE SUCCEED
3718 local expected_fields="event_time data_fid source_fid"
3719 expected_fields+=" total_bytes current_bytes"
3723 while read event; do
3724 # Make sure we're not getting anything from previous events.
3725 for field in $expected_fields; do
3729 local parsed=$(parse_json_event "$event")
3730 if [ -z "$parsed" ]; then
3731 error "Copytool sent malformed event: $event"
3735 if [ $event_type == "RESTORE_START" ]; then
3737 if [ $source_fid != $data_fid ]; then
3738 error "source_fid should == data_fid at start"
3741 elif [ $event_type == "RESTORE_FINISH" ]; then
3743 if [ $source_fid != $data_fid ]; then
3744 error "source_fid should == data_fid at finish"
3747 elif [ $event_type != "RESTORE_RUNNING" ]; then
3751 # Do some simple checking of the progress update events.
3752 for expected_field in $expected_fields; do
3753 if [ -z ${!expected_field+x} ]; then
3754 error "Missing $expected_field field in event"
3758 if [ $total_bytes -eq 0 ]; then
3759 error "Expected total_bytes to be > 0"
3762 # When a restore starts out, the data fid is the same as the
3763 # source fid. After the restore has gotten going, we learn
3764 # the new data fid. Once the restore has finished, the source
3765 # fid is set to the new data fid.
3767 # We test this because some monitoring software may depend on
3768 # this behavior. If it changes, then the consumers of these
3769 # events may need to be modified.
3770 if [ $source_fid == $data_fid ]; then
3771 error "source_fid should != data_fid during restore"
3773 done < <(echo $"$(get_copytool_event_log)")
3775 if [ -z "$START_EVENT" ]; then
3776 error "Copytool failed to send restore start event to FIFO"
3779 if [ -z "$FINISH_EVENT" ]; then
3780 error "Copytool failed to send restore finish event to FIFO"
3783 echo "Restore events look OK."
3787 copytool_monitor_cleanup
3791 run_test 72 "Copytool logs JSON restore events to FIFO"
3794 file_count=51 # Max number of files constrained by LNET message size
3795 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3796 local f=$DIR/$tdir/$tfile
3797 local FILELIST=/tmp/filelist.txt
3801 for i in $(seq 1 $file_count); do
3802 fid=$(copy_file /etc/hosts $f.$i)
3803 echo $f.$i >> $FILELIST
3807 # to be sure wait_all_done will not be mislead by previous tests
3809 wait_for_grace_delay
3810 $LFS hsm_archive --filelist $FILELIST ||
3811 error "cannot archive a file list"
3813 $LFS hsm_release --filelist $FILELIST ||
3814 error "cannot release a file list"
3815 $LFS hsm_restore --filelist $FILELIST ||
3816 error "cannot restore a file list"
3819 run_test 90 "Archive/restore a file list"
3821 double_verify_reset_hsm_param() {
3823 echo "Testing $HSM_PARAM.$p"
3824 local val=$(get_hsm_param $p)
3826 local val2=$(($val * 2))
3827 set_hsm_param $p $val2
3828 val=$(get_hsm_param $p)
3829 [[ $val == $val2 ]] ||
3830 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3831 echo "Set $p to 0 must failed"
3835 set_hsm_param $p $save
3837 if [[ $rc == 0 ]]; then
3838 error "we must not be able to set $HSM_PARAM.$p to 0"
3843 double_verify_reset_hsm_param loop_period
3844 double_verify_reset_hsm_param grace_delay
3845 double_verify_reset_hsm_param active_request_timeout
3846 double_verify_reset_hsm_param max_requests
3847 double_verify_reset_hsm_param default_archive_id
3849 run_test 100 "Set coordinator /proc tunables"
3856 run_test 102 "Verify coordinator control"
3859 # test needs a running copytool
3866 for i in $(seq 1 20); do
3867 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3873 echo "Current requests"
3874 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3875 $HSM_PARAM.actions |\
3876 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3878 [[ -z "$res" ]] || error "Some request have not been canceled"
3880 run_test 103 "Purge all requests"
3885 local f=$DIR/$tdir/$tfile
3887 fid=$(make_custom_file_for_progress $f 39 1000000)
3888 [ $? != 0 ] && skip "not enough free space" && return
3890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3891 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3892 $HSM_PARAM.actions |\
3893 grep $fid | cut -f16 -d=")
3895 [[ "$data1" == "$DATAHEX" ]] ||
3896 error "Data field in records is ($data1) and not ($DATAHEX)"
3901 wait_request_state $fid ARCHIVE SUCCEED
3903 run_test 104 "Copy tool data field"
3906 local max_requests=$(get_hsm_param max_requests)
3910 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3911 set_hsm_param max_requests 300
3914 for i in $(seq -w 1 10); do
3915 cp /etc/passwd $DIR/$tdir/$i
3916 $LFS hsm_archive $DIR/$tdir/$i
3918 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3919 $HSM_PARAM.actions |\
3920 grep WAITING | wc -l")
3924 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3925 $HSM_PARAM.actions |\
3926 grep WAITING | wc -l")
3929 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3930 error "Requests count after shutdown $reqcnt2 != "\
3931 "before shutdown $reqcnt1"
3933 run_test 105 "Restart of coordinator"
3936 # test needs a running copytool
3939 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3941 check_agent_registered $uuid
3943 search_copytools || error "No copytool found"
3946 wait_copytools || error "Copytool failed to stop"
3948 check_agent_unregistered $uuid
3951 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3952 check_agent_registered $uuid
3954 run_test 106 "Copytool register/unregister"
3957 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
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"
4213 test_220A() { # was test_220
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 220A "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)"
4466 test_224A() { # was test_224
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 224A "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"
4767 local f=$DIR/$tdir/$tfile
4768 local fid=$(create_empty_file "$f")
4770 # to have a short test
4771 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4772 set_hsm_param loop_period 1
4777 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4778 wait_request_state $fid ARCHIVE STARTED
4781 stack_trap "set_hsm_param active_request_timeout \
4782 $(get_hsm_param active_request_timeout)" EXIT
4783 set_hsm_param active_request_timeout 1
4785 wait_request_state $fid ARCHIVE CANCELED
4788 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4792 # test needs a running copytool
4796 local f=$DIR/$tdir/$tfile
4798 dd if=/dev/zero of=$f bs=1MB count=10
4799 local fid=$(path2fid $f)
4801 $LFS hsm_archive $f || error "could not archive file"
4802 wait_request_state $fid ARCHIVE SUCCEED
4804 # clear locks to discard inode data
4805 cancel_lru_locks osc
4807 #define OBD_FAIL_MDC_MERGE 0x807
4808 $LCTL set_param fail_loc=0x807
4810 #expect error here, instead of release with wrong size
4813 if ((rc == 0)); then
4814 file_size=$(stat -c '%s' $f)
4815 if ((file_size != 10485760)); then
4816 error "Wrong file size after hsm_release"
4819 echo "could not release file"
4822 run_test 253 "Check for wrong file size after release"
4826 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4827 skip "need MDS version at least 2.10.56" && return
4829 # Check that the counters are initialized to 0
4831 for request_type in archive restore remove; do
4832 count="$(get_hsm_param ${request_type}_count)" ||
4833 error "Reading ${request_type}_count failed with $?"
4835 [ "$count" -eq 0 ] ||
4836 error "Expected ${request_type}_count to be " \
4840 run_test 254a "Request counters are initialized to zero"
4844 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4845 skip "need MDS version at least 2.10.56" && return
4847 # The number of request to launch (at least 32)
4848 local request_count=$((RANDOM % 32 + 32))
4849 printf "Will launch %i requests of each type\n" "$request_count"
4851 # Launch a copytool to process requests
4854 # Set hsm.max_requests to allow starting all requests at the same time
4856 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4857 set_hsm_param max_requests "$request_count"
4861 for request_type in archive restore remove; do
4862 printf "Checking %s requests\n" "${request_type}"
4863 # Suspend the copytool to give us time to read the proc files
4866 for ((i = 0; i < $request_count; i++)); do
4867 case $request_type in
4869 create_empty_file "$DIR/$tdir/$tfile-$i" \
4873 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4876 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4879 # Give the coordinator 10 seconds to start every request
4881 while get_hsm_param actions | grep -q WAITING; do
4884 [ $timeout -gt 0 ] ||
4885 error "${request_type^} requests took too " \
4889 count="$(get_hsm_param ${request_type}_count)"
4890 [ "$count" -eq "$request_count" ] ||
4891 error "Expected '$request_count' (!= '$count') " \
4892 "active $request_type requests"
4894 # Let the copytool process the requests
4896 # Give it 10 seconds maximum
4898 while get_hsm_param actions | grep -q STARTED; do
4901 [ $timeout -gt 0 ] ||
4902 error "${request_type^} requests took too " \
4906 count="$(get_hsm_param ${request_type}_count)"
4907 [ "$count" -eq 0 ] ||
4908 error "Expected 0 (!= '$count') " \
4909 "active $request_type requests"
4912 run_test 254b "Request counters are correctly incremented and decremented"
4915 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4917 # the only way to test ondisk conf is to restart MDS ...
4918 echo "Stop coordinator and remove coordinator state at mount"
4921 # clean on disk conf set by default
4922 cdt_clear_mount_state
4923 cdt_check_state stopped
4925 # check cdt still off after umount/remount
4927 cdt_check_state stopped
4929 echo "Set coordinator start at mount, and start coordinator"
4930 cdt_set_mount_state enabled
4933 cdt_check_state enabled
4935 # check cdt still on after umount/remount
4937 cdt_check_state enabled
4939 # we are back to original state (cdt started at mount)
4941 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4944 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4946 local ai=$(get_hsm_param default_archive_id)
4947 local new=$((ai + 1))
4949 set_hsm_param default_archive_id $new -P
4951 local res=$(get_hsm_param default_archive_id)
4954 set_hsm_param default_archive_id "" "-P -d"
4956 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4958 run_test 301 "HSM tunnable are persistent"
4961 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4963 local ai=$(get_hsm_param default_archive_id)
4964 local new=$((ai + 1))
4969 set_hsm_param default_archive_id $new -P
4972 for mdtno in $(seq 1 $MDSCOUNT); do
4977 cdt_check_state enabled
4979 local res=$(get_hsm_param default_archive_id)
4982 set_hsm_param default_archive_id "" "-P -d"
4984 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4986 run_test 302 "HSM tunnable are persistent when CDT is off"
4989 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4995 local dir_mdt0=$DIR/$tdir/mdt0
4996 local dir_mdt1=$DIR/$tdir/mdt1
4998 # create 1 dir per MDT
4999 stack_trap "rm -rf $dir_mdt0"
5000 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5001 stack_trap "rm -rf $dir_mdt1"
5002 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5004 # create 1 file in each MDT
5005 local fid1=$(create_small_file $dir_mdt0/$tfile)
5006 local fid2=$(create_small_file $dir_mdt1/$tfile)
5008 # check that hsm request on mdt0 is sent to the right MDS
5009 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5010 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5011 echo "archive successful on mdt0"
5013 # check that hsm request on mdt1 is sent to the right MDS
5014 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5015 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5016 echo "archive successful on mdt1"
5018 run_test 400 "Single request is sent to the right MDT"
5021 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5027 local dir_mdt0=$DIR/$tdir/mdt0
5028 local dir_mdt1=$DIR/$tdir/mdt1
5030 # create 1 dir per MDT
5031 stack_trap "rm -rf $dir_mdt0" EXIT
5032 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5033 stack_trap "rm -rf $dir_mdt1" EXIT
5034 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5036 # create 1 file in each MDT
5037 local fid1=$(create_small_file $dir_mdt0/$tfile)
5038 local fid2=$(create_small_file $dir_mdt1/$tfile)
5040 # check that compound requests are shunt to the rights MDTs
5041 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5042 error "lfs hsm_archive"
5043 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5044 echo "archive successful on mdt0"
5045 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5046 echo "archive successful on mdt1"
5048 run_test 401 "Compound requests split and sent to their respective MDTs"
5050 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5055 local node=$(facet_active_host $facet)
5057 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5058 awk '{print $4}'); do
5059 echo "$3 $mdc on $node"
5060 do_facet $facet "$LCTL --device $mdc $state" || return 1
5065 # deactivate all mdc on agent1
5066 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5068 copytool setup --no-fail
5070 check_agent_unregistered "uuid" # match any agent
5072 # no expected running copytool
5073 search_copytools $agent && error "Copytool start should have failed"
5076 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5078 run_test 402a "Copytool start fails if all MDTs are inactive"
5085 local f=$DIR/$tdir/$tfile
5086 touch $f || error "touch $f failed"
5087 local fid=$(path2fid $f)
5089 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5090 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5091 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5093 # give time for CDT to send request and to keep it for retry
5094 wait_for_loop_period
5096 wait_request_state $fid ARCHIVE WAITING
5098 do_facet $SINGLEAGT lctl set_param fail_loc=0
5100 # request should succeed now
5101 wait_request_state $fid ARCHIVE SUCCEED
5103 run_test 402b "CDT must retry request upon slow start of CT"
5106 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5108 local agent=$(facet_active_host $SINGLEAGT)
5110 # deactivate all mdc for MDT0001
5111 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5114 local uuid=$(get_agent_uuid $agent)
5115 # check the agent is registered on MDT0000, and not on MDT0001
5116 check_agent_registered_by_mdt $uuid 0
5117 check_agent_unregistered_by_mdt $uuid 1
5119 # check running copytool process
5120 search_copytools $agent || error "No running copytools on $agent"
5122 # reactivate all mdc for MDT0001
5123 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5125 # make sure the copytool is now registered to all MDTs
5126 check_agent_registered $uuid
5128 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5131 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5135 # create files on both MDT0000 and MDT0001
5138 local dir_mdt0=$DIR/$tdir/mdt0
5139 stack_trap "rm -rf $dir_mdt0" EXIT
5140 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5142 # create 1 file on mdt0
5143 local fid1=$(create_small_file $dir_mdt0/$tfile)
5145 # deactivate all mdc for MDT0001
5146 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5148 # send an HSM request for files in MDT0000
5149 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5151 # check for completion of files in MDT0000
5152 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5153 echo "archive successful on mdt0"
5155 # reactivate all mdc for MDT0001
5156 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5158 run_test 404 "Inactive MDT does not block requests for active MDTs"
5161 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5167 local striped_dir=$DIR/$tdir/striped_dir
5169 # create striped dir on all of MDTs
5170 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5172 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5173 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5174 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5175 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5177 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5178 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5179 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5180 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5182 # check that compound requests are shunt to the rights MDTs
5183 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5184 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5185 error "lfs hsm_archive"
5187 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5188 echo "archive successful on $fid1"
5189 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5190 echo "archive successful on $fid2"
5191 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5192 echo "archive successful on $fid3"
5193 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5194 echo "archive successful on $fid4"
5196 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5197 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5198 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5199 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5201 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5202 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5203 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5204 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5206 run_test 405 "archive and release under striped directory"
5209 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5211 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5212 skip "need MDS version at least 2.7.64" && return 0
5217 fid=$(create_small_file $DIR/$tdir/$tfile)
5222 $LFS hsm_archive $DIR/$tdir/$tfile
5223 wait_request_state "$fid" ARCHIVE SUCCEED
5224 $LFS hsm_release $DIR/$tdir/$tfile
5226 # Should migrate $tdir but not $tfile.
5227 $LFS migrate -m1 $DIR/$tdir &&
5228 error "migrating HSM an archived file should fail"
5230 $LFS hsm_restore $DIR/$tdir/$tfile
5231 wait_request_state "$fid" RESTORE SUCCEED
5233 $LFS hsm_remove $DIR/$tdir/$tfile
5234 wait_request_state "$fid" REMOVE SUCCEED
5236 cat $DIR/$tdir/$tfile > /dev/null ||
5237 error "cannot read $DIR/$tdir/$tfile"
5239 $LFS migrate -m1 $DIR/$tdir ||
5240 error "cannot complete migration after HSM remove"
5242 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5243 if ((mdt_index != 1)); then
5244 error "expected MDT index 1, got $mdt_index"
5247 # Refresh fid after migration.
5248 fid=$(path2fid $DIR/$tdir/$tfile)
5251 $LFS hsm_archive $DIR/$tdir/$tfile
5252 wait_request_state "$fid" ARCHIVE SUCCEED 1
5254 lctl set_param debug=+trace
5255 $LFS hsm_release $DIR/$tdir/$tfile ||
5256 error "cannot release $DIR/$tdir/$tfile"
5258 $LFS hsm_restore $DIR/$tdir/$tfile
5259 wait_request_state "$fid" RESTORE SUCCEED 1
5261 cat $DIR/$tdir/$tfile > /dev/null ||
5262 error "cannot read $DIR/$tdir/$tfile"
5264 run_test 406 "attempting to migrate HSM archived files is safe"
5267 needclients 2 || return 0
5268 # test needs a running copytool
5273 local f=$DIR/$tdir/$tfile
5274 local f2=$DIR2/$tdir/$tfile
5276 fid=$(make_custom_file_for_progress $f 39 1000000)
5277 [ $? != 0 ] && skip "not enough free space" && return
5279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5280 wait_request_state $fid ARCHIVE SUCCEED
5283 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5284 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5287 # 1st request holds layout lock while appropriate
5288 # RESTORE record is still not added to llog
5292 # after umount hsm_actions->O/x/x log shouldn't have
5293 # double RESTORE records like below
5294 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5295 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5297 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5300 wait_request_state $fid RESTORE SUCCEED
5302 run_test 407 "Check for double RESTORE records in llog"
5306 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5307 skip "HSM migrate is not supported" && return
5309 test_mkdir -p $DIR/$tdir
5310 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5312 run_test 500 "various LLAPI HSM tests"
5317 check_and_cleanup_lustre