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
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 1 "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 & 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"
1143 local f=$DIR/$tdir/$tfile
1145 create_empty_file "$f"
1146 # New files are not dirty
1147 check_hsm_flags $f "0x00000000"
1149 # For test, we simulate an archived file.
1150 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1151 check_hsm_flags $f "0x00000001"
1153 # chmod do not put the file dirty
1154 chmod 600 $f || error "could not chmod test file"
1155 check_hsm_flags $f "0x00000001"
1157 # chown do not put the file dirty
1158 chown $RUNAS_ID $f || error "could not chown test file"
1159 check_hsm_flags $f "0x00000001"
1161 # truncate put the file dirty
1162 $TRUNCATE $f 1 || error "could not truncate test file"
1163 check_hsm_flags $f "0x00000003"
1165 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1166 check_hsm_flags $f "0x00000001"
1168 run_test 2 "Check file dirtyness when doing setattr"
1174 # New files are not dirty
1175 cp -p /etc/passwd $f
1176 check_hsm_flags $f "0x00000000"
1178 # For test, we simulate an archived file.
1179 $LFS hsm_set --exists $f ||
1180 error "user could not change hsm flags"
1181 check_hsm_flags $f "0x00000001"
1183 # Reading a file, does not set dirty
1184 cat $f > /dev/null || error "could not read file"
1185 check_hsm_flags $f "0x00000001"
1187 # Open for write without modifying data, does not set dirty
1188 openfile -f O_WRONLY $f || error "could not open test file"
1189 check_hsm_flags $f "0x00000001"
1191 # Append to a file sets it dirty
1192 cp -p /etc/passwd $f.append || error "could not create file"
1193 $LFS hsm_set --exists $f.append ||
1194 error "user could not change hsm flags"
1195 dd if=/etc/passwd of=$f.append bs=1 count=3\
1196 conv=notrunc oflag=append status=noxfer ||
1197 file_creation_failure dd $f.append $?
1198 check_hsm_flags $f.append "0x00000003"
1200 # Modify a file sets it dirty
1201 cp -p /etc/passwd $f.modify || error "could not create file"
1202 $LFS hsm_set --exists $f.modify ||
1203 error "user could not change hsm flags"
1204 dd if=/dev/zero of=$f.modify bs=1 count=3\
1205 conv=notrunc status=noxfer ||
1206 file_creation_failure dd $f.modify $?
1207 check_hsm_flags $f.modify "0x00000003"
1209 # Open O_TRUNC sets dirty
1210 cp -p /etc/passwd $f.trunc || error "could not create file"
1211 $LFS hsm_set --exists $f.trunc ||
1212 error "user could not change hsm flags"
1213 cp /etc/group $f.trunc || error "could not override a file"
1214 check_hsm_flags $f.trunc "0x00000003"
1216 # Mmapped a file sets dirty
1217 cp -p /etc/passwd $f.mmap || error "could not create file"
1218 $LFS hsm_set --exists $f.mmap ||
1219 error "user could not change hsm flags"
1220 multiop $f.mmap OSMWUc || error "could not mmap a file"
1221 check_hsm_flags $f.mmap "0x00000003"
1223 run_test 3 "Check file dirtyness when opening for write"
1226 local f=$DIR/$tdir/$tfile
1227 local fid=$(create_small_file $f)
1230 local st=$(get_request_state $fid CANCEL)
1231 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1233 run_test 4 "Useless cancel must not be registered"
1236 # test needs a running copytool
1240 local f=$DIR/$tdir/$tfile
1241 local fid=$(copy_file /etc/passwd $f)
1243 wait_request_state $fid ARCHIVE SUCCEED
1245 check_hsm_flags $f "0x00000009"
1247 run_test 8 "Test default archive number"
1250 # we do not use the default one to be sure
1251 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1252 copytool setup --archive-id $archive_id
1254 # give time for CT to register with MDTs
1255 sleep $(($MDSCOUNT*2))
1256 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1257 check_agent_registered $uuid
1260 local f=$DIR/$tdir/$tfile
1261 local fid=$(copy_file /etc/passwd $f)
1262 $LFS hsm_archive --archive $archive_id $f
1263 wait_request_state $fid ARCHIVE SUCCEED
1265 check_hsm_flags $f "0x00000009"
1267 run_test 9 "Use of explicit archive number, with dedicated copytool"
1270 needclients 3 || return 0
1276 # start all of the copytools
1277 for n in $(seq $AGTCOUNT); do
1278 copytool setup --facet agt$n
1282 for n in $(seq $AGTCOUNT); do
1283 file=$DIR/$tdir/$tfile.$n
1284 fid=$(create_small_file $file)
1286 $LFS hsm_archive $file || error "could not archive file $file"
1287 wait_request_state $fid ARCHIVE SUCCEED
1288 check_hsm_flags $file "0x00000009"
1291 run_test 9a "Multiple remote agents"
1294 # test needs a running copytool
1297 mkdir -p $DIR/$tdir/d1
1298 local f=$DIR/$tdir/$tfile
1299 local fid=$(copy_file /etc/hosts $f)
1300 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1301 error "hsm_archive failed"
1302 wait_request_state $fid ARCHIVE SUCCEED
1304 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1305 error "fid $fid not in archive $HSM_ARCHIVE"
1306 echo "Verifying content"
1307 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1308 echo "Verifying hsm state "
1309 check_hsm_flags $f "0x00000009"
1311 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1312 local st=$(get_hsm_archive_id $f)
1313 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1314 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1318 run_test 10a "Archive a file"
1321 # test needs a running copytool
1325 local f=$DIR/$tdir/$tfile
1326 local fid=$(copy_file /etc/hosts $f)
1327 $LFS hsm_archive $f || error "archive request failed"
1328 wait_request_state $fid ARCHIVE SUCCEED
1330 $LFS hsm_archive $f || error "archive of non dirty file failed"
1331 local cnt=$(get_request_count $fid ARCHIVE)
1332 [[ "$cnt" == "1" ]] ||
1333 error "archive of non dirty file must not make a request"
1335 run_test 10b "Archive of non dirty file must work without doing request"
1338 # test needs a running copytool
1342 local f=$DIR/$tdir/$tfile
1343 local fid=$(copy_file /etc/hosts $f)
1344 $LFS hsm_set --noarchive $f
1345 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1348 run_test 10c "Check forbidden archive"
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 "cannot archive $f"
1358 wait_request_state $fid ARCHIVE SUCCEED
1360 local ar=$(get_hsm_archive_id $f)
1361 local dflt=$(get_hsm_param default_archive_id)
1362 [[ $ar == $dflt ]] ||
1363 error "archived file is not on default archive: $ar != $dflt"
1365 run_test 10d "Archive a file on the default archive id"
1369 copy2archive /etc/hosts $tdir/$tfile
1370 local f=$DIR/$tdir/$tfile
1372 import_file $tdir/$tfile $f
1373 echo -n "Verifying released state: "
1374 check_hsm_flags $f "0x0000000d"
1376 local LSZ=$(stat -c "%s" $f)
1377 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1379 echo "Verifying imported size $LSZ=$ASZ"
1380 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1381 echo -n "Verifying released pattern: "
1382 local PTRN=$($GETSTRIPE -L $f)
1384 [[ $PTRN == released ]] || error "Is not released"
1385 local fid=$(path2fid $f)
1386 echo "Verifying new fid $fid in archive"
1388 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1389 error "fid $fid not in archive $HSM_ARCHIVE"
1391 run_test 11a "Import a file"
1394 # test needs a running copytool
1398 local f=$DIR/$tdir/$tfile
1399 local fid=$(copy_file /etc/hosts $f)
1400 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1401 error "hsm_archive failed"
1402 wait_request_state $fid ARCHIVE SUCCEED
1404 local FILE_HASH=$(md5sum $f)
1409 echo "$FILE_HASH" | md5sum -c
1411 [[ $? -eq 0 ]] || error "Restored file differs"
1415 run_test 11b "Import a deleted file using its FID"
1418 # test needs a running copytool
1422 copy2archive /etc/hosts $tdir/$tfile
1424 local f=$DIR/$tdir/$tfile
1425 import_file $tdir/$tfile $f
1426 local f2=$DIR2/$tdir/$tfile
1427 echo "Verifying released state: "
1428 check_hsm_flags $f2 "0x0000000d"
1430 local fid=$(path2fid $f2)
1431 $LFS hsm_restore $f2
1432 wait_request_state $fid RESTORE SUCCEED
1434 echo "Verifying file state: "
1435 check_hsm_flags $f2 "0x00000009"
1437 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1439 [[ $? -eq 0 ]] || error "Restored file differs"
1443 run_test 12a "Restore an imported file explicitly"
1446 # test needs a running copytool
1450 copy2archive /etc/hosts $tdir/$tfile
1452 local f=$DIR/$tdir/$tfile
1453 import_file $tdir/$tfile $f
1454 echo "Verifying released state: "
1455 check_hsm_flags $f "0x0000000d"
1457 cat $f > /dev/null || error "File read failed"
1459 echo "Verifying file state after restore: "
1460 check_hsm_flags $f "0x00000009"
1462 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1464 [[ $? -eq 0 ]] || error "Restored file differs"
1468 run_test 12b "Restore an imported file implicitly"
1471 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1473 # test needs a running copytool
1476 local f=$DIR/$tdir/$tfile
1478 $LFS setstripe -c 2 "$f"
1480 fid=$(make_custom_file_for_progress $f 5)
1481 [ $? != 0 ] && skip "not enough free space" && return
1483 local FILE_CRC=$(md5sum $f)
1485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1486 wait_request_state $fid ARCHIVE SUCCEED
1487 $LFS hsm_release $f || error "release $f failed"
1489 echo "$FILE_CRC" | md5sum -c
1491 [[ $? -eq 0 ]] || error "Restored file differs"
1493 run_test 12c "Restore a file with stripe of 2"
1496 # test needs a running copytool
1501 local f=$DIR/$tdir/$tfile
1502 local fid=$(copy_file /etc/hosts $f)
1503 $LFS hsm_restore $f || error "restore of non archived file failed"
1504 local cnt=$(get_request_count $fid RESTORE)
1505 [[ "$cnt" == "0" ]] ||
1506 error "restore non archived must not make a request"
1507 $LFS hsm_archive $f ||
1508 error "archive request failed"
1509 wait_request_state $fid ARCHIVE SUCCEED
1510 $LFS hsm_restore $f ||
1511 error "restore of non released file failed"
1512 local cnt=$(get_request_count $fid RESTORE)
1513 [[ "$cnt" == "0" ]] ||
1514 error "restore a non dirty file must not make a request"
1516 run_test 12d "Restore of a non archived, non released file must work"\
1517 " without doing request"
1520 # test needs a running copytool
1523 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1524 local f=$DIR/$tdir/$tfile
1525 local fid=$(copy_file /etc/hosts $f)
1526 $LFS hsm_archive $f || error "archive request failed"
1527 wait_request_state $fid ARCHIVE SUCCEED
1530 cat /etc/hosts >> $f
1534 $LFS hsm_restore $f && error "restore a dirty file must fail"
1537 run_test 12e "Check forbidden restore"
1540 # test needs a running copytool
1544 local f=$DIR/$tdir/$tfile
1545 local fid=$(copy_file /etc/hosts $f)
1547 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1548 wait_request_state $fid ARCHIVE SUCCEED
1549 $LFS hsm_release $f || error "release of $f failed"
1551 wait_request_state $fid RESTORE SUCCEED
1553 echo -n "Verifying file state: "
1554 check_hsm_flags $f "0x00000009"
1556 diff -q /etc/hosts $f
1558 [[ $? -eq 0 ]] || error "Restored file differs"
1560 run_test 12f "Restore a released file explicitly"
1563 # test needs a running copytool
1567 local f=$DIR/$tdir/$tfile
1568 local fid=$(copy_file /etc/hosts $f)
1570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1571 wait_request_state $fid ARCHIVE SUCCEED
1572 $LFS hsm_release $f || error "release of $f failed"
1574 diff -q /etc/hosts $f
1577 # we check we had a restore done
1578 wait_request_state $fid RESTORE SUCCEED
1580 [[ $st -eq 0 ]] || error "Restored file differs"
1582 run_test 12g "Restore a released file implicitly"
1585 needclients 2 || return 0
1587 # test needs a running copytool
1591 local f=$DIR/$tdir/$tfile
1592 local fid=$(copy_file /etc/hosts $f)
1594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1595 wait_request_state $fid ARCHIVE SUCCEED
1596 $LFS hsm_release $f || error "release of $f failed"
1598 do_node $CLIENT2 diff -q /etc/hosts $f
1601 # we check we had a restore done
1602 wait_request_state $fid RESTORE SUCCEED
1604 [[ $st -eq 0 ]] || error "Restored file differs"
1606 run_test 12h "Restore a released file implicitly from a second node"
1609 # test needs a running copytool
1613 local f=$DIR/$tdir/$tfile
1614 local fid=$(copy_file /etc/passwd $f)
1615 $LFS hsm_archive $f || error "archive of $f failed"
1616 wait_request_state $fid ARCHIVE SUCCEED
1618 $LFS hsm_release $f || error "release of $f failed"
1622 [[ $? -eq 0 ]] || error "Restored file differs"
1624 run_test 12m "Archive/release/implicit restore"
1627 # test needs a running copytool
1631 copy2archive /etc/hosts $tdir/$tfile
1633 local f=$DIR/$tdir/$tfile
1634 import_file $tdir/$tfile $f
1636 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1637 error "Restored file differs"
1639 $LFS hsm_release $f || error "release of $f failed"
1643 run_test 12n "Import/implicit restore/release"
1646 # test needs a running copytool
1650 local f=$DIR/$tdir/$tfile
1651 local fid=$(copy_file /etc/hosts $f)
1653 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1654 wait_request_state $fid ARCHIVE SUCCEED
1655 $LFS hsm_release $f || error "release of $f failed"
1657 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1658 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1660 # set no retry action mode
1663 diff -q /etc/hosts $f
1666 # we check we had a restore failure
1667 wait_request_state $fid RESTORE FAILED
1669 [[ $st -eq 0 ]] && error "Restore must fail"
1671 # remove no retry action mode
1674 # check file is still released
1675 check_hsm_flags $f "0x0000000d"
1677 # retry w/o failure injection
1678 do_facet $SINGLEMDS lctl set_param fail_loc=0
1680 # to be sure previous RESTORE result is gone
1682 wait_for_grace_delay
1684 diff -q /etc/hosts $f
1687 # we check we had a restore done
1688 wait_request_state $fid RESTORE SUCCEED
1690 [[ $st -eq 0 ]] || error "Restored file differs"
1692 run_test 12o "Layout-swap failure during Restore leaves file released"
1695 # test needs a running copytool
1699 local f=$DIR/$tdir/$tfile
1700 local fid=$(copy_file /etc/hosts $f)
1702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1703 wait_request_state $fid ARCHIVE SUCCEED
1704 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1705 $LFS hsm_release $f || error "cannot release $f"
1706 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1707 $LFS hsm_release $f || error "cannot release $f"
1708 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1710 run_test 12p "implicit restore of a file on copytool mount point"
1712 cleanup_test_12q() {
1713 error "cannot umount $MOUNT3 on $SINGLEAGT"
1717 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1718 skip "need MDS version at least 2.7.58" && return 0
1720 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1721 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1722 error "cannot mount $MOUNT3 on $SINGLEAGT"
1724 # test needs a running copytool
1725 copytool setup -m "$MOUNT3"
1727 local f=$DIR/$tdir/$tfile
1728 local f2=$DIR2/$tdir/$tfile
1729 local fid=$(create_small_file $f)
1730 local orig_size=$(stat -c "%s" $f)
1732 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1733 wait_request_state $fid ARCHIVE SUCCEED
1735 $LFS hsm_release $f || error "could not release file"
1736 check_hsm_flags $f "0x0000000d"
1739 wait_copytools || error "copytool failed to stop"
1741 cat $f > /dev/null &
1743 # wait a bit to allow implicit restore request to be handled.
1744 # if not, next stat would also block on layout-lock.
1747 local size=$(stat -c "%s" $f2)
1748 [ $size -eq $orig_size ] ||
1749 error "$f2: wrong size after archive: $size != $orig_size"
1751 copytool setup -m "$MOUNT3"
1755 size=$(stat -c "%s" $f)
1756 [ $size -eq $orig_size ] ||
1757 error "$f: wrong size after restore: $size != $orig_size"
1759 size=$(stat -c "%s" $f2)
1760 [ $size -eq $orig_size ] ||
1761 error "$f2: wrong size after restore: $size != $orig_size"
1765 size=$(stat -c "%s" $f)
1767 error "$f: wrong size after overwrite: $size != 0"
1769 size=$(stat -c "%s" $f2)
1771 error "$f2: wrong size after overwrite: $size != 0"
1773 run_test 12q "file attributes are refreshed after restore"
1776 # test needs a running copytool
1779 local ARC_SUBDIR="import.orig"
1783 # populate directory to be imported
1784 for d in $(seq 1 10); do
1785 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1786 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1787 for f in $(seq 1 10); do
1788 CURR_FILE="$CURR_DIR/$tfile.$f"
1789 # write file-specific data
1790 do_facet $SINGLEAGT \
1791 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1792 "file=$CURR_FILE > $CURR_FILE"
1796 import_file "$ARC_SUBDIR" $DIR/$tdir
1797 # diff lustre content and origin (triggers file restoration)
1798 # there must be 10x10 identical files, and no difference
1799 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1800 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1801 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1802 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1804 [ $cnt_diff -eq 0 ] ||
1805 error "$cnt_diff imported files differ from read data"
1806 [ $cnt_ok -eq 100 ] ||
1807 error "not enough identical files ($cnt_ok != 100)"
1811 run_test 13 "Recursively import and restore a directory"
1814 # test needs a running copytool
1818 local f=$DIR/$tdir/$tfile
1819 local fid=$(create_small_file $f)
1820 local sum=$(md5sum $f | awk '{print $1}')
1821 $LFS hsm_archive $f || error "could not archive file"
1822 wait_request_state $fid ARCHIVE SUCCEED
1824 # create released file (simulate llapi_hsm_import call)
1825 local fid2=$(create_empty_file "$f")
1826 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1827 $LFS hsm_release $f || error "could not release file"
1829 # rebind the archive to the newly created file
1830 echo "rebind $fid to $fid2"
1832 do_facet $SINGLEAGT \
1833 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1834 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1836 # restore file and compare md5sum
1837 local sum2=$(md5sum $f | awk '{print $1}')
1839 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1843 run_test 14 "Rebind archived file to a new fid"
1846 # test needs a running copytool
1850 local f=$DIR/$tdir/$tfile
1852 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1856 for i in $(seq 1 $count); do
1857 fids[$i]=$(create_small_file $f.$i)
1858 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1859 $LFS hsm_archive $f.$i || error "could not archive file"
1861 wait_all_done $(($count*60))
1865 for i in $(seq 1 $count); do
1866 local fid2=$(create_empty_file "${f}.${i}")
1867 # add the rebind operation to the list
1868 echo ${fids[$i]} $fid2 >> $tmpfile
1870 # set it released (simulate llapi_hsm_import call)
1871 $LFS hsm_set --archived --exists $f.$i ||
1872 error "could not force hsm flags"
1873 $LFS hsm_release $f.$i || error "could not release file"
1875 nl=$(wc -l < $tmpfile)
1876 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1878 echo "rebind list of files"
1879 do_facet $SINGLEAGT \
1880 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1881 --rebind $tmpfile $DIR" || error "could not rebind file list"
1883 # restore files and compare md5sum
1884 for i in $(seq 1 $count); do
1885 local sum2=$(md5sum $f.$i | awk '{print $1}')
1886 [[ $sum2 == ${sums[$i]} ]] ||
1887 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1893 run_test 15 "Rebind a list of files"
1896 # test needs a running copytool
1900 # create a known size file so we can verify transfer speed
1903 dd if=/dev/zero of=$ref bs=1M count=20
1906 local f=$DIR/$tdir/$tfile
1907 local fid=$(copy_file $ref $f)
1909 local start=$(date +%s)
1911 wait_request_state $fid ARCHIVE SUCCEED
1912 local end=$(date +%s)
1913 # Add 1 to account for rounding errors between start and end (LU-8155)
1914 local duration=$((end - start + 1))
1916 [[ $duration -ge $((goal - 1)) ]] ||
1917 error "Transfer is too fast $duration < $goal"
1919 run_test 16 "Test CT bandwith control option"
1922 local f=$DIR/$tdir/$tfile
1923 create_empty_file "$f"
1925 # Could not release a non-archived file
1926 $LFS hsm_release $f && error "release should not succeed"
1928 # For following tests, we must test them with HS_ARCHIVED set
1929 $LFS hsm_set --exists --archived $f || error "could not add flag"
1931 # Could not release a file if no-release is set
1932 $LFS hsm_set --norelease $f || error "could not add flag"
1933 $LFS hsm_release $f && error "release should not succeed"
1934 $LFS hsm_clear --norelease $f || error "could not remove flag"
1936 # Could not release a file if lost
1937 $LFS hsm_set --lost $f || error "could not add flag"
1938 $LFS hsm_release $f && error "release should not succeed"
1939 $LFS hsm_clear --lost $f || error "could not remove flag"
1941 # Could not release a file if dirty
1942 $LFS hsm_set --dirty $f || error "could not add flag"
1943 $LFS hsm_release $f && error "release should not succeed"
1944 $LFS hsm_clear --dirty $f || error "could not remove flag"
1946 run_test 20 "Release is not permitted"
1949 # test needs a running copytool
1952 local f=$DIR/$tdir/test_release
1954 # Create a file and check its states
1955 local fid=$(create_small_file $f)
1956 check_hsm_flags $f "0x00000000"
1958 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1959 # used until file is flushed to disk
1960 if [ $(facet_fstype ost1) == "zfs" ]; then
1961 # this causes an OST_SYNC rpc to be sent
1962 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1963 # clear locks to reread file data
1964 cancel_lru_locks osc
1967 local orig_size=$(stat -c "%s" $f)
1968 local orig_blocks=$(stat -c "%b" $f)
1970 start_full_debug_logging
1972 $LFS hsm_archive $f || error "could not archive file"
1973 wait_request_state $fid ARCHIVE SUCCEED
1975 local blocks=$(stat -c "%b" $f)
1976 [ $blocks -eq $orig_blocks ] ||
1977 error "$f: wrong block number after archive: " \
1978 "$blocks != $orig_blocks"
1979 local size=$(stat -c "%s" $f)
1980 [ $size -eq $orig_size ] ||
1981 error "$f: wrong size after archive: $size != $orig_size"
1983 # Release and check states
1984 $LFS hsm_release $f || error "could not release file"
1985 check_hsm_flags $f "0x0000000d"
1987 blocks=$(stat -c "%b" $f)
1988 [ $blocks -gt 5 ] &&
1989 error "$f: too many blocks after release: $blocks > 5"
1990 size=$(stat -c "%s" $f)
1991 [ $size -ne $orig_size ] &&
1992 error "$f: wrong size after release: $size != $orig_size"
1994 # Check we can release an file without stripe info
1998 check_hsm_flags $f "0x00000000"
1999 $LFS hsm_archive $f || error "could not archive file"
2000 wait_request_state $fid ARCHIVE SUCCEED
2002 # Release and check states
2003 $LFS hsm_release $f || error "could not release file"
2004 check_hsm_flags $f "0x0000000d"
2006 # Release again a file that is already released is OK
2007 $LFS hsm_release $f || fail "second release should succeed"
2008 check_hsm_flags $f "0x0000000d"
2010 stop_full_debug_logging
2012 run_test 21 "Simple release tests"
2015 # test needs a running copytool
2018 local f=$DIR/$tdir/test_release
2019 local swap=$DIR/$tdir/test_swap
2021 # Create a file and check its states
2022 local fid=$(create_small_file $f)
2023 check_hsm_flags $f "0x00000000"
2025 $LFS hsm_archive $f || error "could not archive file"
2026 wait_request_state $fid ARCHIVE SUCCEED
2028 # Release and check states
2029 $LFS hsm_release $f || error "could not release file"
2030 check_hsm_flags $f "0x0000000d"
2032 create_small_file $swap
2033 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
2037 run_test 22 "Could not swap a release file"
2040 # test needs a running copytool
2043 local f=$DIR/$tdir/test_mtime
2045 # Create a file and check its states
2046 local fid=$(create_small_file $f)
2047 check_hsm_flags $f "0x00000000"
2049 $LFS hsm_archive $f || error "could not archive file"
2050 wait_request_state $fid ARCHIVE SUCCEED
2052 # Set modification time in the past
2053 touch -m -a -d @978261179 $f
2055 # Release and check states
2056 $LFS hsm_release $f || error "could not release file"
2057 check_hsm_flags $f "0x0000000d"
2059 local MTIME=$(stat -c "%Y" $f)
2060 local ATIME=$(stat -c "%X" $f)
2061 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2062 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2064 run_test 23 "Release does not change a/mtime (utime)"
2067 local file=$DIR/$tdir/$tfile
2076 # test needs a running copytool
2079 fid=$(create_small_file $file)
2081 # Create a file and check its states
2082 check_hsm_flags $file "0x00000000"
2084 # Ensure atime is less than mtime and ctime.
2088 atime0=$(stat -c "%X" $file)
2089 mtime0=$(stat -c "%Y" $file)
2090 ctime0=$(stat -c "%Z" $file)
2092 [ $atime0 -lt $mtime0 ] ||
2093 error "atime $atime0 is not less than mtime $mtime0"
2095 [ $atime0 -lt $ctime0 ] ||
2096 error "atime $atime0 is not less than ctime $ctime0"
2098 # Archive should not change any timestamps.
2099 $LFS hsm_archive $file || error "cannot archive '$file'"
2100 wait_request_state $fid ARCHIVE SUCCEED
2102 atime1=$(stat -c "%X" $file)
2103 mtime1=$(stat -c "%Y" $file)
2104 ctime1=$(stat -c "%Z" $file)
2106 [ $atime0 -eq $atime1 ] ||
2107 error "archive changed atime from $atime0 to $atime1"
2109 [ $mtime0 -eq $mtime1 ] ||
2110 error "archive changed mtime from $mtime0 to $mtime1"
2112 [ $ctime0 -eq $ctime1 ] ||
2113 error "archive changed ctime from $ctime0 to $ctime1"
2115 # Release should not change any timestamps.
2116 $LFS hsm_release $file || error "cannot release '$file'"
2117 check_hsm_flags $file "0x0000000d"
2119 atime1=$(stat -c "%X" $file)
2120 mtime1=$(stat -c "%Y" $file)
2121 ctime1=$(stat -c "%Z" $file)
2123 [ $atime0 -eq $atime1 ] ||
2124 error "release changed atime from $atime0 to $atime1"
2126 [ $mtime0 -eq $mtime1 ] ||
2127 error "release changed mtime from $mtime0 to $mtime1"
2129 [ $ctime0 -eq $ctime1 ] ||
2130 error "release changed ctime from $ctime0 to $ctime1"
2132 # Restore should not change any timestamps.
2133 $LFS hsm_restore $file
2134 wait_request_state $fid RESTORE SUCCEED
2136 atime1=$(stat -c "%X" $file)
2137 mtime1=$(stat -c "%Y" $file)
2138 ctime1=$(stat -c "%Z" $file)
2140 [ $atime0 -eq $atime1 ] ||
2141 error "restore changed atime from $atime0 to $atime1"
2143 [ $mtime0 -eq $mtime1 ] ||
2144 error "restore changed mtime from $mtime0 to $mtime1"
2146 [ $ctime0 -eq $ctime1 ] ||
2147 error "restore changed ctime from $ctime0 to $ctime1"
2150 wait_copytools || error "Copytools failed to stop"
2152 # Once more, after unmount and mount.
2153 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2154 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2156 atime1=$(stat -c "%X" $file)
2157 mtime1=$(stat -c "%Y" $file)
2158 ctime1=$(stat -c "%Z" $file)
2160 [ $atime0 -eq $atime1 ] ||
2161 error "remount changed atime from $atime0 to $atime1"
2163 [ $mtime0 -eq $mtime1 ] ||
2164 error "remount changed mtime from $mtime0 to $mtime1"
2166 [ $ctime0 -eq $ctime1 ] ||
2167 error "remount changed ctime from $ctime0 to $ctime1"
2169 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2172 local file=$DIR/$tdir/$tfile
2178 # Test needs a running copytool.
2181 # Check that root can do HSM actions on a regular user's file.
2182 fid=$(create_small_file $file)
2183 sum0=$(md5sum $file)
2185 chown $RUNAS_ID:$RUNAS_GID $file ||
2186 error "cannot chown '$file' to '$RUNAS_ID'"
2188 chmod ugo-w $DIR/$tdir ||
2189 error "cannot chmod '$DIR/$tdir'"
2191 $LFS hsm_archive $file
2192 wait_request_state $fid ARCHIVE SUCCEED
2194 $LFS hsm_release $file
2195 check_hsm_flags $file "0x0000000d"
2197 $LFS hsm_restore $file
2198 wait_request_state $fid RESTORE SUCCEED
2200 # Check that ordinary user can get HSM state.
2201 $RUNAS $LFS hsm_state $file ||
2202 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2204 $LFS hsm_release $file
2205 check_hsm_flags $file "0x0000000d"
2207 # Check that ordinary user can accessed released file.
2208 sum1=$($RUNAS md5sum $file) ||
2209 error "user '$RUNAS_ID' cannot read '$file'"
2211 [ "$sum0" == "$sum1" ] ||
2212 error "md5sum mismatch for '$file'"
2214 run_test 24b "root can archive, release, and restore user files"
2217 local file=$DIR/$tdir/$tfile
2218 local action=archive
2223 # test needs a running copytool
2228 # Save the default masks and check that cleanup_24c will
2229 # restore the request masks correctly.
2230 user_save=$(get_hsm_param user_request_mask)
2231 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2232 group_save=$(get_hsm_param group_request_mask)
2233 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2234 other_save=$(get_hsm_param other_request_mask)
2235 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2237 [ "$user_save" == RESTORE ] ||
2238 error "user_request_mask is '$user_save' expected 'RESTORE'"
2239 [ "$group_save" == RESTORE ] ||
2240 error "group_request_mask is '$group_save' expected 'RESTORE'"
2241 [ "$other_save" == RESTORE ] ||
2242 error "other_request_mask is '$other_save' expected 'RESTORE'"
2245 create_small_file $file
2246 chown $RUNAS_ID:$GROUP $file ||
2247 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2249 $RUNAS $LFS hsm_$action $file &&
2250 error "$action by user should fail"
2252 set_hsm_param user_request_mask $action
2253 $RUNAS $LFS hsm_$action $file ||
2254 error "$action by user should succeed"
2257 create_small_file $file
2258 chown nobody:$RUNAS_GID $file ||
2259 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2261 $RUNAS $LFS hsm_$action $file &&
2262 error "$action by group should fail"
2264 set_hsm_param group_request_mask $action
2265 $RUNAS $LFS hsm_$action $file ||
2266 error "$action by group should succeed"
2269 create_small_file $file
2270 chown nobody:$GROUP $file ||
2271 error "cannot chown '$file' to 'nobody:$GROUP'"
2273 $RUNAS $LFS hsm_$action $file &&
2274 error "$action by other should fail"
2276 set_hsm_param other_request_mask $action
2277 $RUNAS $LFS hsm_$action $file ||
2278 error "$action by other should succeed"
2280 run_test 24c "check that user,group,other request masks work"
2283 local file1=$DIR/$tdir/$tfile
2284 local file2=$DIR2/$tdir/$tfile
2288 fid1=$(create_small_file $file1)
2291 $LFS getstripe $file1
2293 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2294 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2295 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2297 copytool setup -m "$MOUNT3"
2299 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2300 mount -o remount,ro $MOUNT2
2302 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2304 fid2=$(path2fid $file2)
2305 [ "$fid1" == "$fid2" ] ||
2306 error "FID mismatch '$fid1' != '$fid2'"
2308 $LFS hsm_archive $file2 &&
2309 error "archive should fail on read-only mount"
2310 check_hsm_flags $file1 "0x00000000"
2312 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2313 wait_request_state $fid1 ARCHIVE SUCCEED
2315 $LFS hsm_release $file1
2316 $LFS hsm_restore $file2
2317 wait_request_state $fid1 RESTORE SUCCEED
2319 $LFS hsm_release $file1 || error "cannot release '$file1'"
2320 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2322 $LFS hsm_release $file2 &&
2323 error "release should fail on read-only mount"
2327 run_test 24d "check that read-only mounts are respected"
2332 local f=$DIR/$tdir/$tfile
2335 fid=$(create_small_file $f) || error "cannot create $f"
2336 $LFS hsm_archive $f || error "cannot archive $f"
2337 wait_request_state $fid ARCHIVE SUCCEED
2338 $LFS hsm_release $f || error "cannot release $f"
2339 while ! $LFS hsm_state $f | grep released; do
2343 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2345 run_test 24e "tar succeeds on HSM released files" # LU-6213
2348 # test needs a running copytool
2351 mkdir -p $DIR/$tdir/d1
2352 local f=$DIR/$tdir/$tfile
2353 local fid=$(copy_file /etc/hosts $f)
2356 $LFS hsm_archive $f ||
2357 error "hsm_archive failed"
2358 wait_request_state $fid ARCHIVE SUCCEED
2359 $LFS hsm_release $f || error "cannot release $f"
2360 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2363 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2364 error "Can not recover the tar contents"
2366 echo "Sum0 = $sum0, sum1 = $sum1"
2367 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2369 run_test 24f "root can archive, release, and restore tar files"
2372 # test needs a running copytool
2376 copy2archive /etc/hosts $tdir/$tfile
2378 local f=$DIR/$tdir/$tfile
2380 import_file $tdir/$tfile $f
2382 $LFS hsm_set --lost $f
2387 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2391 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2392 " (Operation not permitted)"
2395 # test needs a running copytool
2400 local f=$DIR/$tdir/$tfile
2401 local fid=$(copy_file /etc/passwd $f)
2403 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2404 wait_request_state $fid ARCHIVE SUCCEED
2407 $LFS hsm_set --lost $f
2411 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2413 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2414 " (Operation not permitted)"
2417 # test needs a running copytool
2420 local f=$DIR/$tdir/$tfile
2422 fid=$(make_custom_file_for_progress $f 39 1000000)
2423 [ $? != 0 ] && skip "not enough free space" && return
2425 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2426 wait_request_state $fid ARCHIVE SUCCEED
2429 wait_request_state $fid REMOVE SUCCEED
2431 check_hsm_flags $f "0x00000000"
2433 run_test 26 "Remove the archive of a valid file"
2436 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2437 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2439 # test needs a running copytool
2443 local f=$DIR/$tdir/$tfile
2444 local fid=$(copy_file /etc/passwd $f)
2446 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2447 wait_request_state $fid ARCHIVE SUCCEED
2449 local f2=$DIR/$tdir/${tfile}_2
2450 local fid2=$(copy_file /etc/passwd $f2)
2452 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2453 wait_request_state $fid2 ARCHIVE SUCCEED
2455 local f3=$DIR/$tdir/${tfile}_3
2456 local fid3=$(copy_file /etc/passwd $f3)
2458 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2459 wait_request_state $fid3 ARCHIVE SUCCEED
2461 # set a long grace_delay vs short loop_period
2462 local orig_loop_period=$(get_hsm_param loop_period)
2463 local orig_grace_delay=$(get_hsm_param grace_delay)
2464 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2465 set_hsm_param loop_period 10
2466 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2467 set_hsm_param grace_delay 100
2471 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2472 set_hsm_param remove_archive_on_last_unlink 1
2474 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2479 set_hsm_param remove_archive_on_last_unlink 0
2481 wait_request_state $fid2 REMOVE SUCCEED
2483 assert_request_count $fid REMOVE 0 \
2484 "Unexpected archived data remove request for $f"
2485 assert_request_count $fid3 REMOVE 0 \
2486 "Unexpected archived data remove request for $f3"
2488 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2491 # test needs a running copytool
2495 local f=$DIR/$tdir/$tfile
2496 local fid=$(copy_file /etc/passwd $f)
2498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2499 wait_request_state $fid ARCHIVE SUCCEED
2501 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2502 set_hsm_param remove_archive_on_last_unlink 1
2505 cdt_check_state stopped
2509 set_hsm_param remove_archive_on_last_unlink 0
2511 wait_request_state $fid REMOVE WAITING
2515 # copytool must re-register
2517 wait_copytools || error "copytool failed to stop"
2520 wait_request_state $fid REMOVE SUCCEED
2522 run_test 26b "RAoLU policy when CDT off"
2525 # test needs a running copytool
2529 local f=$DIR/$tdir/$tfile
2530 local fid=$(copy_file /etc/passwd $f)
2532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2533 wait_request_state $fid ARCHIVE SUCCEED
2535 local f2=$DIR/$tdir/${tfile}_2
2536 local fid2=$(copy_file /etc/passwd $f2)
2538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2539 wait_request_state $fid2 ARCHIVE SUCCEED
2541 # set a long grace_delay vs short loop_period
2542 local orig_loop_period=$(get_hsm_param loop_period)
2543 local orig_grace_delay=$(get_hsm_param grace_delay)
2544 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2545 set_hsm_param loop_period 10
2546 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2547 set_hsm_param grace_delay 100
2549 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2550 set_hsm_param remove_archive_on_last_unlink 1
2552 multiop_bg_pause $f O_c || error "open $f failed"
2558 wait_request_state $fid2 REMOVE SUCCEED
2559 assert_request_count $fid REMOVE 0 \
2560 "Unexpected archived data remove request for $f"
2562 kill -USR1 $pid || error "multiop early exit"
2563 # should reach autotest timeout if multiop fails to trap
2564 # signal, close file, and exit ...
2565 wait $pid || error "wait PID $PID failed"
2567 set_hsm_param remove_archive_on_last_unlink 0
2569 wait_request_state $fid REMOVE SUCCEED
2571 run_test 26c "RAoLU effective when file closed"
2574 # test needs a running copytool
2578 local f=$DIR/$tdir/$tfile
2579 local fid=$(create_small_file $f)
2581 $LFS hsm_archive $f || error "could not archive file"
2582 wait_request_state $fid ARCHIVE SUCCEED
2584 # set a long grace_delay vs short loop_period
2585 local orig_loop_period=$(get_hsm_param loop_period)
2586 local orig_grace_delay=$(get_hsm_param grace_delay)
2587 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2588 set_hsm_param loop_period 10
2589 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2590 set_hsm_param grace_delay 100
2592 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2593 set_hsm_param remove_archive_on_last_unlink 1
2595 multiop_bg_pause $f O_c || error "multiop failed"
2602 set_hsm_param remove_archive_on_last_unlink 0
2604 wait_request_state $fid REMOVE SUCCEED
2606 client_up || client_up || true
2608 kill -USR1 $MULTIPID
2609 wait $MULTIPID || error "multiop close failed"
2611 run_test 26d "RAoLU when Client eviction"
2614 # test needs a running copytool
2617 create_archive_file $tdir/$tfile
2618 local f=$DIR/$tdir/$tfile
2619 import_file $tdir/$tfile $f
2620 local fid=$(path2fid $f)
2624 [[ $? != 0 ]] || error "Remove of a released file should fail"
2628 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2631 # test needs a running copytool
2634 local f=$DIR/$tdir/$tfile
2636 fid=$(make_custom_file_for_progress $f 39 1000000)
2637 [ $? != 0 ] && skip "not enough free space" && return
2639 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2640 wait_request_state $fid ARCHIVE SUCCEED
2645 [[ $? != 0 ]] || error "Remove of a released file should fail"
2647 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2650 # test needs a running copytool
2653 local f=$DIR/$tdir/$tfile
2655 fid=$(make_custom_file_for_progress $f 39 1000000)
2656 [ $? != 0 ] && skip "not enough free space" && return
2658 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2659 wait_request_state $fid ARCHIVE SUCCEED
2668 wait_request_state $fid REMOVE SUCCEED
2670 run_test 28 "Concurrent archive/file remove"
2673 # Tests --mntpath and --archive options
2676 copytool setup -m "$MOUNT" -a $archive_id
2678 # Bad archive number
2679 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2680 grep "Invalid argument" ||
2681 error "unexpected hsm_remove failure (1)"
2683 # mntpath is present but file is given
2684 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2685 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2686 error "unexpected hsm_remove failure (2)"
2688 run_test 29a "Tests --mntpath and --archive options"
2691 # test needs a running copytool
2694 local f=$DIR/$tdir/$tfile
2695 local fid=$(create_small_file $f)
2697 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2698 wait_request_state $fid ARCHIVE SUCCEED
2702 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2703 wait_request_state $fid REMOVE SUCCEED
2705 run_test 29b "Archive/delete/remove by FID from the archive."
2708 # test needs a running copytool
2711 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2712 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2713 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2715 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2716 wait_request_state $fid1 ARCHIVE SUCCEED
2717 wait_request_state $fid2 ARCHIVE SUCCEED
2718 wait_request_state $fid3 ARCHIVE SUCCEED
2720 rm -f $DIR/$tdir/$tfile-[1-3]
2722 echo $fid1 > $DIR/$tdir/list
2723 echo $fid2 >> $DIR/$tdir/list
2724 echo $fid3 >> $DIR/$tdir/list
2726 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2727 --filelist $DIR/$tdir/list
2728 wait_request_state $fid1 REMOVE SUCCEED
2729 wait_request_state $fid2 REMOVE SUCCEED
2730 wait_request_state $fid3 REMOVE SUCCEED
2732 run_test 29c "Archive/delete/remove by FID, using a file list."
2735 # test needs more than one CT
2736 needclients 3 || return 0
2742 # start all of the copytools
2743 for n in $(seq $AGTCOUNT); do
2744 copytool setup -f agt$n -a $n
2748 file=$DIR/$tdir/$tfile
2749 fid=$(create_small_file $file)
2751 $LFS hsm_archive $file
2752 wait_request_state $fid ARCHIVE SUCCEED
2753 check_hsm_flags $file "0x00000009"
2757 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2758 error "cannot hsm_remove '$fid'"
2760 # give time for CDT to handle remove request and create broadcasted
2763 # remove request has been broadcasted ?
2764 local cnt=$(get_request_count $fid REMOVE)
2765 # broadcasted requests + original
2766 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2767 error "remove not broadcasted to all CTs"
2769 # give time for CDT and CTs to handle broadcasted
2770 wait_for_loop_period
2772 # each agent serves one different archive_id, so broadcasted
2773 # hsm_remove request should only succeed once and fail at all others
2777 for n in $(seq $AGTCOUNT); do
2778 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2779 $HSM_PARAM.actions | awk \
2780 '/'$fid'.*action=REMOVE archive#='$n'/ \
2781 {print \\\$13}' | cut -f2 -d=")
2782 if [[ "$res" == "SUCCEED" ]]; then
2784 elif [[ "$res" == "FAILED" ]]; then
2789 [[ $scnt -eq 1 ]] ||
2790 error "one and only CT should have removed successfully"
2792 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2793 error "all but one CT should have failed to remove"
2795 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2796 "request to be sent once for each registered archive_id"
2799 # restore at exec cannot work on agent node (because of Linux kernel
2800 # protection of executables)
2801 needclients 2 || return 0
2803 # test needs a running copytool
2807 copy2archive /bin/true $tdir/$tfile
2809 local f=$DIR/$tdir/true
2810 import_file $tdir/$tfile $f
2812 local fid=$(path2fid $f)
2814 # set no retry action mode
2820 # remove no try action mode
2824 [[ $st == 0 ]] || error "Failed to exec a released file"
2828 run_test 30a "Restore at exec (import case)"
2831 # restore at exec cannot work on agent node (because of Linux kernel
2832 # protection of executables)
2833 needclients 2 || return 0
2835 # test needs a running copytool
2839 local f=$DIR/$tdir/true
2840 local fid=$(copy_file /bin/true $f)
2842 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2843 wait_request_state $fid ARCHIVE SUCCEED
2847 stack_trap cdt_clear_no_retry EXIT
2848 # set no retry action mode
2856 [[ $st == 0 ]] || error "Failed to exec a released file"
2858 run_test 30b "Restore at exec (release case)"
2861 needclients 2 || return 0
2863 # test needs a running copytool
2867 local f=$DIR/$tdir/SLEEP
2868 local slp_sum1=$(md5sum /bin/sleep)
2869 local fid=$(copy_file /bin/sleep $f)
2871 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2872 wait_request_state $fid ARCHIVE SUCCEED
2874 check_hsm_flags $f "0x0000000d"
2876 stack_trap cdt_clear_no_retry EXIT
2877 # set no retry action mode
2880 do_node $CLIENT2 "$f 10" &
2884 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2886 [[ $? == 0 ]] || error "Execution failed during run"
2888 if [[ $? != 0 ]]; then
2889 local slp_sum2=$(md5sum /bin/sleep)
2890 # in case sleep file is modified during the test
2891 [[ $slp_sum1 == $slp_sum2 ]] &&
2892 error "Binary overwritten during exec"
2895 check_hsm_flags $f "0x00000009"
2897 run_test 30c "Update during exec of released file must fail"
2899 restore_and_check_size() {
2902 local s=$(stat -c "%s" $f)
2904 local st=$(get_hsm_flags $f)
2908 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2910 n=$(stat -c "%s" $f)
2911 # we echo in both cases to show stat is not hang
2912 if [[ $n != $s ]]; then
2913 echo "size seen is $n != $s"
2916 echo "size seen is right: $n == $s"
2920 st=$(get_hsm_flags $f)
2922 if [[ "$st" = "0x00000009" ]]; then
2925 echo " restore is too long"
2926 wait_request_state $fid RESTORE SUCCEED
2932 # test needs a running copytool
2935 create_archive_file $tdir/$tfile
2936 local f=$DIR/$tdir/$tfile
2937 import_file $tdir/$tfile $f
2938 local fid=$($LFS path2fid $f)
2939 HSM_ARCHIVE_PURGE=false copytool_setup
2941 restore_and_check_size $f $fid
2944 [[ $err -eq 0 ]] || error "File size changed during restore"
2948 run_test 31a "Import a large file and check size during restore"
2952 # test needs a running copytool
2955 local f=$DIR/$tdir/$tfile
2957 fid=$(make_custom_file_for_progress $f 39 1000000)
2958 [ $? != 0 ] && skip "not enough free space" && return
2960 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2961 wait_request_state $fid ARCHIVE SUCCEED
2964 restore_and_check_size $f $fid
2967 [[ $err -eq 0 ]] || error "File size changed during restore"
2969 run_test 31b "Restore a large unaligned file and check size during restore"
2972 # test needs a running copytool
2975 local f=$DIR/$tdir/$tfile
2977 fid=$(make_custom_file_for_progress $f 33 1048576)
2978 [ $? != 0 ] && skip "not enough free space" && return
2980 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2981 wait_request_state $fid ARCHIVE SUCCEED
2984 restore_and_check_size $f $fid
2987 [[ $err -eq 0 ]] || error "File size changed during restore"
2989 run_test 31c "Restore a large aligned file and check size during restore"
2992 # test needs a running copytool
2995 local f=$DIR/$tdir/$tfile
2997 fid=$(make_custom_file_for_progress $f 39 1000000)
2998 [ $? != 0 ] && skip "not enough free space" && return
3000 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3001 wait_request_state $fid ARCHIVE SUCCEED
3004 # to be sure wait_all_done will not be mislead by previous tests
3007 wait_for_grace_delay
3008 # Also raise grace_delay significantly so the Canceled
3009 # Restore action will stay enough long avail.
3010 local old_grace=$(get_hsm_param grace_delay)
3011 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
3012 set_hsm_param grace_delay 100
3014 md5sum $f >/dev/null &
3016 wait_request_state $fid RESTORE STARTED
3021 # Check restore trigger process was killed
3022 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3026 # instead of waiting+checking both Restore and Cancel ops
3027 # sequentially, wait for both to be finished and then check
3029 wait_all_done 100 $fid
3030 local rstate=$(get_request_state $fid RESTORE)
3031 local cstate=$(get_request_state $fid CANCEL)
3033 if [[ "$rstate" == "CANCELED" ]] ; then
3034 [[ "$cstate" == "SUCCEED" ]] ||
3035 error "Restore state is CANCELED and Cancel state " \
3036 "is not SUCCEED but $cstate"
3037 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3038 elif [[ "$rstate" == "SUCCEED" ]] ; then
3039 [[ "$cstate" == "FAILED" ]] ||
3040 error "Restore state is SUCCEED and Cancel state " \
3041 "is not FAILED but $cstate"
3042 echo "Restore state is SUCCEED, Cancel state is FAILED"
3044 error "Restore state is $rstate and Cancel state is $cstate"
3048 error "Cannot kill process waiting for restore ($killed)"
3050 run_test 33 "Kill a restore waiting process"
3053 # test needs a running copytool
3056 local f=$DIR/$tdir/$tfile
3058 fid=$(make_custom_file_for_progress $f 39 1000000)
3059 [ $? != 0 ] && skip "not enough free space" && return
3061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3062 wait_request_state $fid ARCHIVE SUCCEED
3065 md5sum $f >/dev/null &
3067 wait_request_state $fid RESTORE STARTED
3069 rm $f || error "rm $f failed"
3070 # rm must not block during restore
3071 wait_request_state $fid RESTORE STARTED
3073 wait_request_state $fid RESTORE SUCCEED
3074 # check md5sum pgm finished
3075 local there=$(ps -o pid,comm hp $pid >/dev/null)
3076 [[ -z $there ]] || error "Restore initiator does not exit"
3078 wait $pid || error "Restore initiator failed with $?"
3080 run_test 34 "Remove file during restore"
3083 # test needs a running copytool
3086 local f=$DIR/$tdir/$tfile
3087 local f1=$DIR/$tdir/$tfile-1
3089 fid=$(make_custom_file_for_progress $f 39 1000000)
3090 [ $? != 0 ] && skip "not enough free space" && return
3092 local fid1=$(copy_file /etc/passwd $f1)
3093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3094 wait_request_state $fid ARCHIVE SUCCEED
3097 md5sum $f >/dev/null &
3099 wait_request_state $fid RESTORE STARTED
3101 mv $f1 $f || error "mv $f1 $f failed"
3102 # mv must not block during restore
3103 wait_request_state $fid RESTORE STARTED
3105 wait_request_state $fid RESTORE SUCCEED
3106 # check md5sum pgm finished
3107 local there=$(ps -o pid,comm hp $pid >/dev/null)
3108 [[ -z $there ]] || error "Restore initiator does not exit"
3110 wait $pid || error "Restore initiator failed with $?"
3113 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3115 run_test 35 "Overwrite file during restore"
3118 # test needs a running copytool
3121 local f=$DIR/$tdir/$tfile
3123 fid=$(make_custom_file_for_progress $f 39 1000000)
3124 [ $? != 0 ] && skip "not enough free space" && return
3126 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3127 wait_request_state $fid ARCHIVE SUCCEED
3130 md5sum $f >/dev/null &
3132 wait_request_state $fid RESTORE STARTED
3135 # rm must not block during restore
3136 wait_request_state $fid RESTORE STARTED
3138 wait_request_state $fid RESTORE SUCCEED
3139 # check md5sum pgm finished
3140 local there=$(ps -o pid,comm hp $pid >/dev/null)
3142 error "Restore initiator does not exit"
3144 wait $pid || error "Restore initiator failed with $?"
3146 run_test 36 "Move file during restore"
3149 # LU-5683: check that an archived dirty file can be rearchived.
3152 local f=$DIR/$tdir/$tfile
3155 fid=$(create_small_file $f) || error "cannot create small file"
3157 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3158 wait_request_state $fid ARCHIVE SUCCEED
3159 $LFS hsm_release $f || error "cannot release $f"
3161 # Allow previous archive request to expire from the actions log.
3162 wait_for_grace_delay
3165 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3168 wait_request_state $fid ARCHIVE SUCCEED
3170 run_test 37 "re-archive a dirty file"
3177 for n in $(seq 1 $count); do
3178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3180 echo "$count archive requests submitted"
3184 local stream_count=4
3185 local file_count=100
3187 local f=$DIR/$tdir/$tfile
3191 local max_requests=$(get_hsm_param max_requests)
3193 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3194 # Increase the number of HSM request that can be performed in
3195 # parallel. With the coordinator running once per second, this
3196 # also limits the number of requests per seconds that can be
3197 # performed, so we pick a decent number. But we also need to keep
3198 # that number low because the copytool has no rate limit and will
3199 # fail some requests if if gets too many at once.
3200 set_hsm_param max_requests 300
3202 for i in $(seq 1 $file_count); do
3203 for p in $(seq 1 $stream_count); do
3204 fid=$(copy_file /etc/hosts $f.$p.$i)
3210 # to be sure wait_all_done will not be mislead by previous tests
3212 wait_for_grace_delay
3214 # start archive streams in background (archive files in parallel)
3215 for p in $(seq 1 $stream_count); do
3216 multi_archive $f.$p $file_count &
3219 echo -n "Wait for all requests being enqueued..."
3224 run_test 40 "Parallel archive requests"
3227 # test needs a running copytool
3231 local f=$DIR/$tdir/$tfile
3232 local fid=$(create_small_file $f)
3234 $LFS hsm_archive $f || error "could not archive file"
3235 wait_request_state $fid ARCHIVE SUCCEED
3236 check_hsm_flags $f "0x00000009"
3238 multiop_bg_pause $f O_c || error "multiop failed"
3242 client_up || client_up || true
3244 kill -USR1 $MULTIPID
3245 wait $MULTIPID || error "multiop close failed"
3247 check_hsm_flags $f "0x0000000b"
3249 run_test 52 "Opened for write file on an evicted client should be set dirty"
3252 # test needs a running copytool
3256 local f=$DIR/$tdir/$tfile
3257 local fid=$(create_small_file $f)
3259 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3260 error "could not archive file"
3261 wait_request_state $fid ARCHIVE SUCCEED
3262 check_hsm_flags $f "0x00000009"
3264 multiop_bg_pause $f o_c || error "multiop failed"
3268 client_up || client_up || true
3270 kill -USR1 $MULTIPID
3271 wait $MULTIPID || error "multiop close failed"
3273 check_hsm_flags $f "0x00000009"
3275 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3278 # test needs a running copytool
3281 local f=$DIR/$tdir/$tfile
3282 local fid=$(make_custom_file_for_progress $f 39 1000000)
3284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3285 error "could not archive file"
3286 wait_request_state $fid ARCHIVE STARTED
3288 check_hsm_flags $f "0x00000001"
3290 stack_trap "cdt_clear_no_retry" EXIT
3291 # Avoid coordinator resending this request as soon it has failed.
3296 wait_request_state $fid ARCHIVE FAILED
3298 check_hsm_flags $f "0x00000003"
3300 run_test 54 "Write during an archive cancels it"
3303 # test needs a running copytool
3306 local f=$DIR/$tdir/$tfile
3307 local fid=$(make_custom_file_for_progress $f 39 1000000)
3309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3310 error "could not archive file"
3311 wait_request_state $fid ARCHIVE STARTED
3313 check_hsm_flags $f "0x00000001"
3315 stack_trap "cdt_clear_no_retry" EXIT
3316 # Avoid coordinator resending this request as soon it has failed.
3319 $TRUNCATE $f 1024 || error "truncate failed"
3321 wait_request_state $fid ARCHIVE FAILED
3323 check_hsm_flags $f "0x00000003"
3325 run_test 55 "Truncate during an archive cancels it"
3328 # test needs a running copytool
3331 local f=$DIR/$tdir/$tfile
3333 fid=$(make_custom_file_for_progress $f 39 1000000)
3334 [ $? != 0 ] && skip "not enough free space" && return
3336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3337 error "could not archive file"
3338 wait_request_state $fid ARCHIVE STARTED
3340 check_hsm_flags $f "0x00000001"
3342 # Change metadata and sync to be sure we are not changing only
3347 wait_request_state $fid ARCHIVE SUCCEED
3349 check_hsm_flags $f "0x00000009"
3351 run_test 56 "Setattr during an archive is ok"
3354 # Need one client for I/O, one for request
3355 needclients 2 || return 0
3357 # test needs a running copytool
3361 local f=$DIR/$tdir/test_archive_remote
3362 # Create a file on a remote node
3363 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3364 "count=2 conv=fsync"
3367 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3368 error "hsm_archive failed"
3369 local fid=$(path2fid $f)
3370 wait_request_state $fid ARCHIVE SUCCEED
3372 # Release and implicit restore it
3373 do_node $CLIENT2 "$LFS hsm_release $f" ||
3374 error "hsm_release failed"
3375 do_node $CLIENT2 "md5sum $f" ||
3376 error "hsm_restore failed"
3378 wait_request_state $fid RESTORE SUCCEED
3380 run_test 57 "Archive a file with dirty cache on another node"
3382 truncate_released_file() {
3386 local sz=$(stat -c %s $src_file)
3387 local f=$DIR/$tdir/$tfile
3388 local fid=$(copy_file $1 $f)
3392 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3393 error "could not archive file"
3394 wait_request_state $fid ARCHIVE SUCCEED
3396 $LFS hsm_release $f || error "could not release file"
3398 $TRUNCATE $f $trunc_to || error "truncate failed"
3401 local sz1=$(stat -c %s $f)
3402 [[ $sz1 == $trunc_to ]] ||
3403 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3406 check_hsm_flags $f "0x0000000b"
3408 local state=$(get_request_state $fid RESTORE)
3409 [[ "$state" == "SUCCEED" ]] ||
3410 error "truncate $sz does not trig restore, state = $state"
3412 $TRUNCATE $ref $trunc_to
3413 cmp $ref $f || error "file data wrong after truncate"
3419 # test needs a running copytool
3424 local sz=$(stat -c %s /etc/passwd)
3426 echo "truncate up from $sz to $((sz*2))"
3427 truncate_released_file /etc/passwd $((sz*2))
3429 echo "truncate down from $sz to $((sz/2))"
3430 truncate_released_file /etc/passwd $((sz/2))
3432 echo "truncate to 0"
3433 truncate_released_file /etc/passwd 0
3435 run_test 58 "Truncate a released file will trigger restore"
3439 local server_version=$(lustre_version_code $SINGLEMDS)
3440 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3441 skip "Need MDS version at least 2.7.63" && return
3444 $MCREATE $DIR/$tfile || error "mcreate failed"
3445 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3446 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3447 fid=$(path2fid $DIR/$tfile)
3448 wait_request_state $fid ARCHIVE SUCCEED
3449 $LFS hsm_release $DIR/$tfile || error "release failed"
3451 run_test 59 "Release stripeless file with non-zero size"
3454 # This test validates the fix for LU-4512. Ensure that the -u
3455 # option changes the progress reporting interval from the
3456 # default (30 seconds) to the user-specified interval.
3458 local progress_timeout=$((interval * 4))
3460 copytool setup -b 1 --update-interval $interval
3462 local f=$DIR/$tdir/$tfile
3464 fid=$(make_custom_file_for_progress $f 10)
3465 [ $? != 0 ] && skip "not enough free space" && return
3468 local mdt=${MDT_PREFIX}${mdtidx}
3469 local mds=mds$((mdtidx + 1))
3471 # Wait for copytool to register
3472 wait_update_facet $mds \
3473 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3474 uuid 100 || error "coyptool failed to register with $mdt"
3476 local start_at=$(date +%s)
3477 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3478 error "could not archive file"
3480 local agent=$(facet_active_host $SINGLEAGT)
3481 local logfile=$(copytool_logfile $SINGLEAGT)
3483 wait_update $agent \
3484 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3485 error "copytool failed to start"
3487 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3488 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3494 echo -n "Expecting a progress update within $progress_timeout seconds... "
3496 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3497 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3498 echo "$RESULT bytes copied in $WAIT seconds."
3500 elif [ $WAIT -ge $progress_timeout ]; then
3501 error "Timed out waiting for progress update!"
3504 WAIT=$((WAIT + sleep))
3508 local finish_at=$(date +%s)
3509 local elapsed=$((finish_at - start_at))
3511 # Ensure that the progress update occurred within the expected window.
3512 if [ $elapsed -lt $((interval - 1)) ]; then
3513 error "Expected progress update after at least $interval seconds"
3516 echo "Wait for on going archive hsm action to complete"
3517 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3518 echo "File archiving not completed even after 10 secs"
3520 run_test 60 "Changing progress update interval from default"
3523 # test needs a running copytool
3527 local f=$DIR/$tdir/$tfile
3528 local fid=$(copy_file /etc/passwd $f)
3530 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3533 wait_request_state $fid ARCHIVE FAILED
3535 run_test 61 "Waiting archive of a removed file should fail"
3538 # test needs a new running copytool
3539 stack_trap copytool_monitor_cleanup EXIT
3540 copytool_monitor_setup
3541 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3543 # Wait for the copytool to register.
3544 wait_update --verbose $(facet_active_host mds1) \
3545 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3547 error "copytool failed to register with MDT0000"
3550 wait_copytools || error "Copytools failed to stop"
3552 local REGISTER_EVENT
3553 local UNREGISTER_EVENT
3554 while read event; do
3555 local parsed=$(parse_json_event "$event")
3556 if [ -z "$parsed" ]; then
3557 error "Copytool sent malformed event: $event"
3561 if [ $event_type == "REGISTER" ]; then
3562 REGISTER_EVENT=$event
3563 elif [ $event_type == "UNREGISTER" ]; then
3564 UNREGISTER_EVENT=$event
3566 done < <(echo $"$(get_copytool_event_log)")
3568 if [ -z "$REGISTER_EVENT" ]; then
3569 error "Copytool failed to send register event to FIFO"
3572 if [ -z "$UNREGISTER_EVENT" ]; then
3573 error "Copytool failed to send unregister event to FIFO"
3576 echo "Register/Unregister events look OK."
3578 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3581 # Bump progress interval for livelier events.
3584 # test needs a new running copytool
3585 stack_trap copytool_monitor_cleanup EXIT
3586 copytool_monitor_setup
3587 copytool setup --update-interval $interval --event-fifo \
3588 "$HSMTOOL_MONITOR_DIR/fifo"
3590 stack_trap "cdt_clear_no_retry" EXIT
3591 # Just start and stop the copytool to generate events.
3594 local f=$DIR/$tdir/$tfile
3596 fid=$(make_custom_file_for_progress $f 39 1000000)
3597 [ $? != 0 ] && skip "not enough free space" && return
3599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3600 error "could not archive file"
3601 wait_request_state $fid ARCHIVE SUCCEED
3603 local expected_fields="event_time data_fid source_fid"
3604 expected_fields+=" total_bytes current_bytes"
3608 while read event; do
3609 # Make sure we're not getting anything from previous events.
3610 for field in $expected_fields; do
3614 local parsed=$(parse_json_event "$event")
3615 if [ -z "$parsed" ]; then
3616 error "Copytool sent malformed event: $event"
3620 if [ $event_type == "ARCHIVE_START" ]; then
3623 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3626 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3630 # Do some simple checking of the progress update events.
3631 for expected_field in $expected_fields; do
3632 if [ -z ${!expected_field+x} ]; then
3633 error "Missing $expected_field field in event"
3637 if [ $total_bytes -eq 0 ]; then
3638 error "Expected total_bytes to be > 0"
3641 # These should be identical throughout an archive
3643 if [ $source_fid != $data_fid ]; then
3644 error "Expected source_fid to equal data_fid"
3646 done < <(echo $"$(get_copytool_event_log)")
3648 if [ -z "$START_EVENT" ]; then
3649 error "Copytool failed to send archive start event to FIFO"
3652 if [ -z "$FINISH_EVENT" ]; then
3653 error "Copytool failed to send archive finish event to FIFO"
3656 echo "Archive events look OK."
3658 run_test 71 "Copytool logs JSON archive events to FIFO"
3661 # Bump progress interval for livelier events.
3664 # test needs a new running copytool
3666 copytool_monitor_setup
3667 HSMTOOL_UPDATE_INTERVAL=$interval \
3668 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3669 local test_file=$HSMTOOL_MONITOR_DIR/file
3671 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3673 do_facet $SINGLEAGT "$cmd" ||
3674 error "cannot create $test_file on $SINGLEAGT"
3675 copy2archive $test_file $tdir/$tfile
3678 local f=$DIR/$tdir/$tfile
3679 import_file $tdir/$tfile $f
3680 f=$DIR2/$tdir/$tfile
3681 echo "Verifying released state: "
3682 check_hsm_flags $f "0x0000000d"
3684 local fid=$(path2fid $f)
3686 wait_request_state $fid RESTORE SUCCEED
3688 local expected_fields="event_time data_fid source_fid"
3689 expected_fields+=" total_bytes current_bytes"
3693 while read event; do
3694 # Make sure we're not getting anything from previous events.
3695 for field in $expected_fields; do
3699 local parsed=$(parse_json_event "$event")
3700 if [ -z "$parsed" ]; then
3701 error "Copytool sent malformed event: $event"
3705 if [ $event_type == "RESTORE_START" ]; then
3707 if [ $source_fid != $data_fid ]; then
3708 error "source_fid should == data_fid at start"
3711 elif [ $event_type == "RESTORE_FINISH" ]; then
3713 if [ $source_fid != $data_fid ]; then
3714 error "source_fid should == data_fid at finish"
3717 elif [ $event_type != "RESTORE_RUNNING" ]; then
3721 # Do some simple checking of the progress update events.
3722 for expected_field in $expected_fields; do
3723 if [ -z ${!expected_field+x} ]; then
3724 error "Missing $expected_field field in event"
3728 if [ $total_bytes -eq 0 ]; then
3729 error "Expected total_bytes to be > 0"
3732 # When a restore starts out, the data fid is the same as the
3733 # source fid. After the restore has gotten going, we learn
3734 # the new data fid. Once the restore has finished, the source
3735 # fid is set to the new data fid.
3737 # We test this because some monitoring software may depend on
3738 # this behavior. If it changes, then the consumers of these
3739 # events may need to be modified.
3740 if [ $source_fid == $data_fid ]; then
3741 error "source_fid should != data_fid during restore"
3743 done < <(echo $"$(get_copytool_event_log)")
3745 if [ -z "$START_EVENT" ]; then
3746 error "Copytool failed to send restore start event to FIFO"
3749 if [ -z "$FINISH_EVENT" ]; then
3750 error "Copytool failed to send restore finish event to FIFO"
3753 echo "Restore events look OK."
3757 copytool_monitor_cleanup
3761 run_test 72 "Copytool logs JSON restore events to FIFO"
3764 file_count=51 # Max number of files constrained by LNET message size
3765 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3766 local f=$DIR/$tdir/$tfile
3767 local FILELIST=/tmp/filelist.txt
3771 for i in $(seq 1 $file_count); do
3772 fid=$(copy_file /etc/hosts $f.$i)
3773 echo $f.$i >> $FILELIST
3777 # to be sure wait_all_done will not be mislead by previous tests
3779 wait_for_grace_delay
3780 $LFS hsm_archive --filelist $FILELIST ||
3781 error "cannot archive a file list"
3783 $LFS hsm_release --filelist $FILELIST ||
3784 error "cannot release a file list"
3785 $LFS hsm_restore --filelist $FILELIST ||
3786 error "cannot restore a file list"
3789 run_test 90 "Archive/restore a file list"
3791 double_verify_reset_hsm_param() {
3793 echo "Testing $HSM_PARAM.$p"
3794 local val=$(get_hsm_param $p)
3796 local val2=$(($val * 2))
3797 set_hsm_param $p $val2
3798 val=$(get_hsm_param $p)
3799 [[ $val == $val2 ]] ||
3800 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3801 echo "Set $p to 0 must failed"
3805 set_hsm_param $p $save
3807 if [[ $rc == 0 ]]; then
3808 error "we must not be able to set $HSM_PARAM.$p to 0"
3813 double_verify_reset_hsm_param loop_period
3814 double_verify_reset_hsm_param grace_delay
3815 double_verify_reset_hsm_param active_request_timeout
3816 double_verify_reset_hsm_param max_requests
3817 double_verify_reset_hsm_param default_archive_id
3819 run_test 100 "Set coordinator /proc tunables"
3826 run_test 102 "Verify coordinator control"
3829 # test needs a running copytool
3836 for i in $(seq 1 20); do
3837 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3843 echo "Current requests"
3844 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3845 $HSM_PARAM.actions |\
3846 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3848 [[ -z "$res" ]] || error "Some request have not been canceled"
3850 run_test 103 "Purge all requests"
3855 local f=$DIR/$tdir/$tfile
3857 fid=$(make_custom_file_for_progress $f 39 1000000)
3858 [ $? != 0 ] && skip "not enough free space" && return
3860 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3861 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3862 $HSM_PARAM.actions |\
3863 grep $fid | cut -f16 -d=")
3865 [[ "$data1" == "$DATAHEX" ]] ||
3866 error "Data field in records is ($data1) and not ($DATAHEX)"
3871 wait_request_state $fid ARCHIVE SUCCEED
3873 run_test 104 "Copy tool data field"
3876 local max_requests=$(get_hsm_param max_requests)
3880 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3881 set_hsm_param max_requests 300
3884 for i in $(seq -w 1 10); do
3885 cp /etc/passwd $DIR/$tdir/$i
3886 $LFS hsm_archive $DIR/$tdir/$i
3888 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3889 $HSM_PARAM.actions |\
3890 grep WAITING | wc -l")
3894 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3895 $HSM_PARAM.actions |\
3896 grep WAITING | wc -l")
3899 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3900 error "Requests count after shutdown $reqcnt2 != "\
3901 "before shutdown $reqcnt1"
3903 run_test 105 "Restart of coordinator"
3906 # test needs a running copytool
3909 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3911 check_agent_registered $uuid
3913 search_copytools || error "No copytool found"
3916 wait_copytools || error "Copytool failed to stop"
3918 check_agent_unregistered $uuid
3921 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3922 check_agent_registered $uuid
3924 run_test 106 "Copytool register/unregister"
3927 # test needs a running copytool
3929 # create and archive file
3931 local f1=$DIR/$tdir/$tfile
3932 local fid=$(copy_file /etc/passwd $f1)
3933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3934 wait_request_state $fid ARCHIVE SUCCEED
3935 # shutdown and restart MDS
3937 # check the copytool still gets messages from MDT
3938 local f2=$DIR/$tdir/2
3939 local fid=$(copy_file /etc/passwd $f2)
3940 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3941 # main check of this sanity: this request MUST succeed
3942 wait_request_state $fid ARCHIVE SUCCEED
3944 run_test 107 "Copytool re-register after MDS restart"
3946 policy_set_and_test()
3950 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3951 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3952 [[ "$policy" == "$target" ]] ||
3953 error "Wrong policy after '$change': '$policy' != '$target'"
3957 # to force default policy setting if error
3958 CDT_POLICY_HAD_CHANGED=true
3960 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3961 local default="NonBlockingRestore [NoRetryAction]"
3962 [[ "$policy" == "$default" ]] ||
3963 error "default policy has changed,"\
3964 " '$policy' != '$default' update the test"
3965 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3966 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3967 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3968 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3969 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3970 # useless bacause we know but safer for futur changes to use real value
3971 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3972 echo "Next set_param must failed"
3973 policy_set_and_test "wrong" "$policy"
3976 echo "Back to default policy"
3977 cdt_set_sanity_policy
3979 run_test 109 "Policy display/change"
3982 # test needs a running copytool
3987 copy2archive /etc/passwd $tdir/$tfile
3989 local f=$DIR/$tdir/$tfile
3990 import_file $tdir/$tfile $f
3991 local fid=$(path2fid $f)
3993 cdt_set_non_blocking_restore
3998 wait_request_state $fid RESTORE SUCCEED
3999 cdt_clear_non_blocking_restore
4003 error "md5sum returns $st != 1, "\
4004 "should also perror ENODATA (No data available)"
4006 run_test 110a "Non blocking restore policy (import case)"
4009 # test needs a running copytool
4013 local f=$DIR/$tdir/$tfile
4014 local fid=$(copy_file /etc/passwd $f)
4015 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4016 wait_request_state $fid ARCHIVE SUCCEED
4019 cdt_set_non_blocking_restore
4024 wait_request_state $fid RESTORE SUCCEED
4025 cdt_clear_non_blocking_restore
4029 error "md5sum returns $st != 1, "\
4030 "should also perror ENODATA (No data available)"
4032 run_test 110b "Non blocking restore policy (release case)"
4035 # test needs a running copytool
4039 copy2archive /etc/passwd $tdir/$tfile
4041 local f=$DIR/$tdir/$tfile
4043 import_file $tdir/$tfile $f
4044 local fid=$(path2fid $f)
4048 copytool_remove_backend $fid
4051 wait_request_state $fid RESTORE FAILED
4058 [[ $st == 0 ]] || error "Restore does not failed"
4062 run_test 111a "No retry policy (import case), restore will error"\
4063 " (No such file or directory)"
4066 # test needs a running copytool
4070 local f=$DIR/$tdir/$tfile
4071 local fid=$(copy_file /etc/passwd $f)
4073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4074 wait_request_state $fid ARCHIVE SUCCEED
4077 copytool_remove_backend $fid
4080 wait_request_state $fid RESTORE FAILED
4087 [[ $st == 0 ]] || error "Restore does not failed"
4091 run_test 111b "No retry policy (release case), restore will error"\
4092 " (No such file or directory)"
4095 # test needs a running copytool
4099 local f=$DIR/$tdir/$tfile
4100 local fid=$(copy_file /etc/passwd $f)
4102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4103 local l=$($LFS hsm_action $f)
4105 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4108 wait_request_state $fid ARCHIVE SUCCEED
4111 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4113 run_test 112 "State of recorded request"
4116 # test needs a running copytool
4119 local f=$DIR/$tdir/$tfile
4121 fid=$(make_custom_file_for_progress $f 103 1048576)
4122 [ $? != 0 ] && skip "not enough free space" && return
4124 # test with cdt on is made in test_221
4126 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4127 # wait archive to register at CDT
4128 wait_request_state $fid ARCHIVE WAITING
4131 wait_request_state $fid ARCHIVE CANCELED
4132 wait_request_state $fid CANCEL SUCCEED
4134 run_test 200 "Register/Cancel archive"
4137 # test needs a running copytool
4140 local f=$DIR/$tdir/$tfile
4141 create_archive_file $tdir/$tfile
4142 import_file $tdir/$tfile $f
4143 local fid=$(path2fid $f)
4145 # test with cdt on is made in test_222
4148 # wait restore to register at CDT
4149 wait_request_state $fid RESTORE WAITING
4152 wait_request_state $fid RESTORE CANCELED
4153 wait_request_state $fid CANCEL SUCCEED
4157 run_test 201 "Register/Cancel restore"
4160 # test needs a running copytool
4163 local f=$DIR/$tdir/$tfile
4165 fid=$(make_custom_file_for_progress $f 39 1000000)
4166 [ $? != 0 ] && skip "not enough free space" && return
4168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4169 wait_request_state $fid ARCHIVE SUCCEED
4173 # wait remove to register at CDT
4174 wait_request_state $fid REMOVE WAITING
4177 wait_request_state $fid REMOVE CANCELED
4179 run_test 202 "Register/Cancel remove"
4182 # test needs a running copytool
4187 local f=$DIR/$tdir/$tfile
4188 local fid=$(copy_file /etc/passwd $f)
4192 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4193 wait_request_state $fid ARCHIVE SUCCEED
4195 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4199 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4201 run_test 220 "Changelog for archive"
4204 # test needs a running copytool
4209 local f=$DIR/$tdir/$tfile
4210 local fid=$(copy_file /etc/passwd $f)
4214 # block copytool operations to allow for HSM request to be
4215 # submitted and file be unlinked (CDT will find object removed)
4218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4220 # wait request to reach CT
4221 wait_request_state $fid ARCHIVE STARTED
4227 wait_request_state $fid ARCHIVE FAILED
4229 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4234 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4236 run_test 220a "Changelog for failed archive"
4239 # test needs a running copytool
4242 local f=$DIR/$tdir/$tfile
4244 fid=$(make_custom_file_for_progress $f 103 1048576)
4245 [ $? != 0 ] && skip "not enough free space" && return
4249 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4250 wait_request_state $fid ARCHIVE STARTED
4252 wait_request_state $fid ARCHIVE CANCELED
4253 wait_request_state $fid CANCEL SUCCEED
4255 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4258 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4260 run_test 221 "Changelog for archive canceled"
4263 # test needs a running copytool
4267 copy2archive /etc/passwd $tdir/$tfile
4269 local f=$DIR/$tdir/$tfile
4270 import_file $tdir/$tfile $f
4271 local fid=$(path2fid $f)
4276 wait_request_state $fid RESTORE SUCCEED
4278 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4281 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4285 run_test 222a "Changelog for explicit restore"
4288 # test needs a running copytool
4292 local f=$DIR/$tdir/$tfile
4293 local fid=$(copy_file /etc/passwd $f)
4296 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4297 wait_request_state $fid ARCHIVE SUCCEED
4302 wait_request_state $fid RESTORE SUCCEED
4304 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4307 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4309 run_test 222b "Changelog for implicit restore"
4312 # test needs a running copytool
4316 copy2archive /etc/passwd $tdir/$tfile
4318 local f=$DIR/$tdir/$tfile
4319 import_file $tdir/$tfile $f
4320 local fid=$(path2fid $f)
4324 # block copytool operations to allow for HSM request to be
4325 # submitted and file be unlinked (CDT will find object removed)
4330 # wait request to reach CT
4331 wait_request_state $fid RESTORE STARTED
4337 wait_request_state $fid RESTORE FAILED
4339 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4343 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4347 run_test 222c "Changelog for failed explicit restore"
4350 # test needs a running copytool
4354 local f=$DIR/$tdir/$tfile
4355 local fid=$(copy_file /etc/passwd $f)
4358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4359 wait_request_state $fid ARCHIVE SUCCEED
4362 copytool_remove_backend $fid
4365 wait_request_state $fid RESTORE FAILED
4367 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4371 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4375 run_test 222d "Changelog for failed implicit restore"
4378 # test needs a running copytool
4381 local f=$DIR/$tdir/$tfile
4382 create_archive_file $tdir/$tfile
4386 import_file $tdir/$tfile $f
4387 local fid=$(path2fid $f)
4390 wait_request_state $fid RESTORE STARTED
4392 wait_request_state $fid RESTORE CANCELED
4393 wait_request_state $fid CANCEL SUCCEED
4395 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4398 [[ $flags == $target ]] ||
4399 error "Changelog flag is $flags not $target"
4403 run_test 223a "Changelog for restore canceled (import case)"
4406 # test needs a running copytool
4409 local f=$DIR/$tdir/$tfile
4411 fid=$(make_custom_file_for_progress $f 39 1000000)
4412 [ $? != 0 ] && skip "not enough free space" && return
4415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4416 wait_request_state $fid ARCHIVE SUCCEED
4419 wait_request_state $fid RESTORE STARTED
4421 wait_request_state $fid RESTORE CANCELED
4422 wait_request_state $fid CANCEL SUCCEED
4424 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4427 [[ $flags == $target ]] ||
4428 error "Changelog flag is $flags not $target"
4432 run_test 223b "Changelog for restore canceled (release case)"
4435 # test needs a running copytool
4440 local f=$DIR/$tdir/$tfile
4441 local fid=$(copy_file /etc/passwd $f)
4444 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4445 wait_request_state $fid ARCHIVE SUCCEED
4448 wait_request_state $fid REMOVE SUCCEED
4450 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4453 [[ $flags == $target ]] ||
4454 error "Changelog flag is $flags not $target"
4456 run_test 224 "Changelog for remove"
4459 # test needs a running copytool
4464 local f=$DIR/$tdir/$tfile
4465 local fid=$(copy_file /etc/passwd $f)
4468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4469 wait_request_state $fid ARCHIVE SUCCEED
4471 copytool_remove_backend $fid
4473 # block copytool operations to allow for HSM request to be
4474 # submitted and file be unlinked (CDT will find object removed)
4479 # wait for request to reach CT
4480 wait_request_state $fid REMOVE STARTED
4486 wait_request_state $fid REMOVE FAILED
4488 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4492 [[ $flags == $target ]] ||
4493 error "Changelog flag is $flags not $target"
4497 run_test 224a "Changelog for failed remove"
4500 # test needs a running copytool
4503 # test is not usable because remove request is too fast
4504 # so it is always finished before cancel can be done ...
4505 echo "Test disabled"
4509 local f=$DIR/$tdir/$tfile
4511 fid=$(make_custom_file_for_progress $f 39 1000000)
4512 [ $? != 0 ] && skip "not enough free space" && return
4515 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4516 wait_request_state $fid ARCHIVE SUCCEED
4518 # if cdt is on, it can serve too quickly the request
4523 wait_request_state $fid REMOVE CANCELED
4524 wait_request_state $fid CANCEL SUCCEED
4526 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4527 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4528 tail -n 1 | awk '{print $5}')
4531 [[ $flags == $target ]] ||
4532 error "Changelog flag is $flags not $target"
4534 run_test 225 "Changelog for remove canceled"
4537 # test needs a running copytool
4542 local f1=$DIR/$tdir/$tfile-1
4543 local f2=$DIR/$tdir/$tfile-2
4544 local f3=$DIR/$tdir/$tfile-3
4545 local fid1=$(copy_file /etc/passwd $f1)
4546 local fid2=$(copy_file /etc/passwd $f2)
4547 copy_file /etc/passwd $f3
4550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4551 wait_request_state $fid1 ARCHIVE SUCCEED
4553 $LFS hsm_archive $f2
4554 wait_request_state $fid2 ARCHIVE SUCCEED
4556 rm $f1 || error "rm $f1 failed"
4558 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4561 [[ $flags == $target ]] ||
4562 error "Changelog flag is $flags not $target"
4564 mv $f3 $f2 || error "mv $f3 $f2 failed"
4566 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4569 [[ $flags == $target ]] ||
4570 error "Changelog flag is $flags not $target"
4572 run_test 226 "changelog for last rm/mv with exiting archive"
4574 check_flags_changes() {
4582 $LFS hsm_set --$hsm_flag $f ||
4583 error "Cannot set $hsm_flag on $f"
4584 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4585 local seen=${#flags[*]}
4587 [[ $seen == $cnt ]] ||
4588 error "set $hsm_flag: Changelog events $seen != $cnt"
4589 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4590 error "set $hsm_flag: Changelog flags are "\
4591 "${flags[$((cnt - 1))]} not $target"
4593 $LFS hsm_clear --$hsm_flag $f ||
4594 error "Cannot clear $hsm_flag on $f"
4595 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4598 [[ $cnt == $seen ]] ||
4599 error "clear $hsm_flag: Changelog events $seen != $cnt"
4601 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4602 error "clear $hsm_flag: Changelog flag is "\
4603 "${flags[$((cnt - 1))]} not $target"
4607 # test needs a running copytool
4614 for i in norelease noarchive exists archived
4616 local f=$DIR/$tdir/$tfile-$i
4617 local fid=$(copy_file /etc/passwd $f)
4618 check_flags_changes $f $fid $i 0 1
4621 f=$DIR/$tdir/$tfile---lost
4622 fid=$(copy_file /etc/passwd $f)
4623 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4624 wait_request_state $fid ARCHIVE SUCCEED
4625 check_flags_changes $f $fid lost 3 1
4627 run_test 227 "changelog when explicit setting of HSM flags"
4630 # test needs a running copytool
4633 local fid=$(create_small_sync_file $DIR/$tfile)
4634 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4635 wait_request_state $fid ARCHIVE SUCCEED
4637 $LFS hsm_release $DIR/$tfile
4638 check_hsm_flags $DIR/$tfile "0x0000000d"
4640 filefrag $DIR/$tfile | grep " 1 extent found" ||
4641 error "filefrag on released file must return only one extent"
4643 # only newer versions of cp detect sparse files by stat/FIEMAP
4645 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4646 error "copying $DIR/$tfile"
4647 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4649 $LFS hsm_release $DIR/$tfile
4650 check_hsm_flags $DIR/$tfile "0x0000000d"
4652 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4654 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4656 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4657 error "comparing untarred $DIR/$tfile"
4659 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4660 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4662 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4665 # test needs a running copytool
4669 local maxrequest=$(get_hsm_param max_requests)
4670 local rqcnt=$(($maxrequest * 3))
4674 for i in $(seq -w 1 $rqcnt); do
4676 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4678 # we do it in 2 steps, so all requests arrive at the same time
4679 for i in $(seq -w 1 $rqcnt); do
4680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4685 while [[ $cnt != 0 || $wt != 0 ]]; do
4687 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4688 $HSM_PARAM.actions |\
4689 grep STARTED | grep -v CANCEL | wc -l")
4690 [[ $cnt -le $maxrequest ]] ||
4691 error "$cnt > $maxrequest too many started requests"
4692 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4693 $HSM_PARAM.actions |\
4694 grep WAITING | wc -l")
4695 echo "max=$maxrequest started=$cnt waiting=$wt"
4698 run_test 250 "Coordinator max request"
4701 # test needs a running copytool
4704 local f=$DIR/$tdir/$tfile
4706 fid=$(make_custom_file_for_progress $f 103 1048576)
4707 [ $? != 0 ] && skip "not enough free space" && return
4710 # to have a short test
4711 local old_to=$(get_hsm_param active_request_timeout)
4712 set_hsm_param active_request_timeout 4
4713 # to be sure the cdt will wake up frequently so
4714 # it will be able to cancel the "old" request
4715 local old_loop=$(get_hsm_param loop_period)
4716 set_hsm_param loop_period 2
4719 # clear locks to avoid extra delay caused by flush/cancel
4720 # and thus prevent early copytool death to timeout.
4721 cancel_lru_locks osc
4723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4724 wait_request_state $fid ARCHIVE STARTED
4726 wait_request_state $fid ARCHIVE CANCELED
4728 set_hsm_param active_request_timeout $old_to
4729 set_hsm_param loop_period $old_loop
4731 run_test 251 "Coordinator request timeout"
4735 local f=$DIR/$tdir/$tfile
4736 local fid=$(create_empty_file "$f")
4738 # to have a short test
4739 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4740 set_hsm_param loop_period 1
4745 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4746 wait_request_state $fid ARCHIVE STARTED
4749 stack_trap "set_hsm_param active_request_timeout \
4750 $(get_hsm_param active_request_timeout)" EXIT
4751 set_hsm_param active_request_timeout 1
4753 wait_request_state $fid ARCHIVE CANCELED
4756 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4760 # test needs a running copytool
4764 local f=$DIR/$tdir/$tfile
4766 dd if=/dev/zero of=$f bs=1MB count=10
4767 local fid=$(path2fid $f)
4769 $LFS hsm_archive $f || error "could not archive file"
4770 wait_request_state $fid ARCHIVE SUCCEED
4772 # clear locks to discard inode data
4773 cancel_lru_locks osc
4775 #define OBD_FAIL_MDC_MERGE 0x807
4776 $LCTL set_param fail_loc=0x807
4778 #expect error here, instead of release with wrong size
4781 if ((rc == 0)); then
4782 file_size=$(stat -c '%s' $f)
4783 if ((file_size != 10485760)); then
4784 error "Wrong file size after hsm_release"
4787 echo "could not release file"
4790 run_test 253 "Check for wrong file size after release"
4794 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4795 skip "need MDS version at least 2.10.56" && return
4797 # Check that the counters are initialized to 0
4799 for request_type in archive restore remove; do
4800 count="$(get_hsm_param ${request_type}_count)" ||
4801 error "Reading ${request_type}_count failed with $?"
4803 [ "$count" -eq 0 ] ||
4804 error "Expected ${request_type}_count to be " \
4808 run_test 254a "Request counters are initialized to zero"
4812 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4813 skip "need MDS version at least 2.10.56" && return
4815 # The number of request to launch (at least 32)
4816 local request_count=$((RANDOM % 32 + 32))
4817 printf "Will launch %i requests of each type\n" "$request_count"
4819 # Launch a copytool to process requests
4822 # Set hsm.max_requests to allow starting all requests at the same time
4824 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4825 set_hsm_param max_requests "$request_count"
4829 for request_type in archive restore remove; do
4830 printf "Checking %s requests\n" "${request_type}"
4831 # Suspend the copytool to give us time to read the proc files
4834 for ((i = 0; i < $request_count; i++)); do
4835 case $request_type in
4837 create_empty_file "$DIR/$tdir/$tfile-$i" \
4841 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4844 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4847 # Give the coordinator 10 seconds to start every request
4849 while get_hsm_param actions | grep -q WAITING; do
4852 [ $timeout -gt 0 ] ||
4853 error "${request_type^} requests took too " \
4857 count="$(get_hsm_param ${request_type}_count)"
4858 [ "$count" -eq "$request_count" ] ||
4859 error "Expected '$request_count' (!= '$count') " \
4860 "active $request_type requests"
4862 # Let the copytool process the requests
4864 # Give it 10 seconds maximum
4866 while get_hsm_param actions | grep -q STARTED; do
4869 [ $timeout -gt 0 ] ||
4870 error "${request_type^} requests took too " \
4874 count="$(get_hsm_param ${request_type}_count)"
4875 [ "$count" -eq 0 ] ||
4876 error "Expected 0 (!= '$count') " \
4877 "active $request_type requests"
4880 run_test 254b "Request counters are correctly incremented and decremented"
4883 # the only way to test ondisk conf is to restart MDS ...
4884 echo "Stop coordinator and remove coordinator state at mount"
4887 # clean on disk conf set by default
4888 cdt_clear_mount_state
4889 cdt_check_state stopped
4891 # check cdt still off after umount/remount
4893 cdt_check_state stopped
4895 echo "Set coordinator start at mount, and start coordinator"
4896 cdt_set_mount_state enabled
4899 cdt_check_state enabled
4901 # check cdt still on after umount/remount
4903 cdt_check_state enabled
4905 # we are back to original state (cdt started at mount)
4907 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4910 local ai=$(get_hsm_param default_archive_id)
4911 local new=$((ai + 1))
4913 set_hsm_param default_archive_id $new -P
4915 local res=$(get_hsm_param default_archive_id)
4918 set_hsm_param default_archive_id "" "-P -d"
4920 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4922 run_test 301 "HSM tunnable are persistent"
4925 local ai=$(get_hsm_param default_archive_id)
4926 local new=$((ai + 1))
4931 set_hsm_param default_archive_id $new -P
4934 for mdtno in $(seq 1 $MDSCOUNT); do
4939 cdt_check_state enabled
4941 local res=$(get_hsm_param default_archive_id)
4944 set_hsm_param default_archive_id "" "-P -d"
4946 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4948 run_test 302 "HSM tunnable are persistent when CDT is off"
4951 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4957 local dir_mdt0=$DIR/$tdir/mdt0
4958 local dir_mdt1=$DIR/$tdir/mdt1
4960 # create 1 dir per MDT
4961 stack_trap "rm -rf $dir_mdt0"
4962 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4963 stack_trap "rm -rf $dir_mdt1"
4964 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4966 # create 1 file in each MDT
4967 local fid1=$(create_small_file $dir_mdt0/$tfile)
4968 local fid2=$(create_small_file $dir_mdt1/$tfile)
4970 # check that hsm request on mdt0 is sent to the right MDS
4971 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4972 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4973 echo "archive successful on mdt0"
4975 # check that hsm request on mdt1 is sent to the right MDS
4976 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4977 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4978 echo "archive successful on mdt1"
4980 run_test 400 "Single request is sent to the right MDT"
4983 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4989 local dir_mdt0=$DIR/$tdir/mdt0
4990 local dir_mdt1=$DIR/$tdir/mdt1
4992 # create 1 dir per MDT
4993 stack_trap "rm -rf $dir_mdt0" EXIT
4994 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4995 stack_trap "rm -rf $dir_mdt1" EXIT
4996 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4998 # create 1 file in each MDT
4999 local fid1=$(create_small_file $dir_mdt0/$tfile)
5000 local fid2=$(create_small_file $dir_mdt1/$tfile)
5002 # check that compound requests are shunt to the rights MDTs
5003 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5004 error "lfs hsm_archive"
5005 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5006 echo "archive successful on mdt0"
5007 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5008 echo "archive successful on mdt1"
5010 run_test 401 "Compound requests split and sent to their respective MDTs"
5012 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5017 local node=$(facet_active_host $facet)
5019 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5020 awk '{print $4}'); do
5021 echo "$3 $mdc on $node"
5022 do_facet $facet "$LCTL --device $mdc $state" || return 1
5027 # deactivate all mdc on agent1
5028 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5030 copytool setup --no-fail
5032 check_agent_unregistered "uuid" # match any agent
5034 # no expected running copytool
5035 search_copytools $agent && error "Copytool start should have failed"
5038 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5040 run_test 402a "Copytool start fails if all MDTs are inactive"
5047 local f=$DIR/$tdir/$tfile
5048 touch $f || error "touch $f failed"
5049 local fid=$(path2fid $f)
5051 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5052 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5055 # give time for CDT to send request and to keep it for retry
5056 wait_for_loop_period
5058 wait_request_state $fid ARCHIVE WAITING
5060 do_facet $SINGLEAGT lctl set_param fail_loc=0
5062 # request should succeed now
5063 wait_request_state $fid ARCHIVE SUCCEED
5065 run_test 402b "CDT must retry request upon slow start of CT"
5068 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5070 local agent=$(facet_active_host $SINGLEAGT)
5072 # deactivate all mdc for MDT0001
5073 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5076 local uuid=$(get_agent_uuid $agent)
5077 # check the agent is registered on MDT0000, and not on MDT0001
5078 check_agent_registered_by_mdt $uuid 0
5079 check_agent_unregistered_by_mdt $uuid 1
5081 # check running copytool process
5082 search_copytools $agent || error "No running copytools on $agent"
5084 # reactivate all mdc for MDT0001
5085 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5087 # make sure the copytool is now registered to all MDTs
5088 check_agent_registered $uuid
5090 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5093 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5097 # create files on both MDT0000 and MDT0001
5100 local dir_mdt0=$DIR/$tdir/mdt0
5101 stack_trap "rm -rf $dir_mdt0" EXIT
5102 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5104 # create 1 file on mdt0
5105 local fid1=$(create_small_file $dir_mdt0/$tfile)
5107 # deactivate all mdc for MDT0001
5108 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5110 # send an HSM request for files in MDT0000
5111 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5113 # check for completion of files in MDT0000
5114 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5115 echo "archive successful on mdt0"
5117 # reactivate all mdc for MDT0001
5118 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5120 run_test 404 "Inactive MDT does not block requests for active MDTs"
5123 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5129 local striped_dir=$DIR/$tdir/striped_dir
5131 # create striped dir on all of MDTs
5132 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5134 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5135 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5136 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5137 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5139 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5140 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5141 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5142 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5144 # check that compound requests are shunt to the rights MDTs
5145 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5146 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5147 error "lfs hsm_archive"
5149 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5150 echo "archive successful on $fid1"
5151 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5152 echo "archive successful on $fid2"
5153 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5154 echo "archive successful on $fid3"
5155 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5156 echo "archive successful on $fid4"
5158 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5159 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5160 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5161 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5163 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5164 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5165 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5166 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5168 run_test 405 "archive and release under striped directory"
5171 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5173 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5174 skip "need MDS version at least 2.7.64" && return 0
5179 fid=$(create_small_file $DIR/$tdir/$tfile)
5184 $LFS hsm_archive $DIR/$tdir/$tfile
5185 wait_request_state "$fid" ARCHIVE SUCCEED
5186 $LFS hsm_release $DIR/$tdir/$tfile
5188 # Should migrate $tdir but not $tfile.
5189 $LFS migrate -m1 $DIR/$tdir &&
5190 error "migrating HSM an archived file should fail"
5192 $LFS hsm_restore $DIR/$tdir/$tfile
5193 wait_request_state "$fid" RESTORE SUCCEED
5195 $LFS hsm_remove $DIR/$tdir/$tfile
5196 wait_request_state "$fid" REMOVE SUCCEED
5198 cat $DIR/$tdir/$tfile > /dev/null ||
5199 error "cannot read $DIR/$tdir/$tfile"
5201 $LFS migrate -m1 $DIR/$tdir ||
5202 error "cannot complete migration after HSM remove"
5204 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5205 if ((mdt_index != 1)); then
5206 error "expected MDT index 1, got $mdt_index"
5209 # Refresh fid after migration.
5210 fid=$(path2fid $DIR/$tdir/$tfile)
5213 $LFS hsm_archive $DIR/$tdir/$tfile
5214 wait_request_state "$fid" ARCHIVE SUCCEED 1
5216 lctl set_param debug=+trace
5217 $LFS hsm_release $DIR/$tdir/$tfile ||
5218 error "cannot release $DIR/$tdir/$tfile"
5220 $LFS hsm_restore $DIR/$tdir/$tfile
5221 wait_request_state "$fid" RESTORE SUCCEED 1
5223 cat $DIR/$tdir/$tfile > /dev/null ||
5224 error "cannot read $DIR/$tdir/$tfile"
5226 run_test 406 "attempting to migrate HSM archived files is safe"
5229 needclients 2 || return 0
5230 # test needs a running copytool
5235 local f=$DIR/$tdir/$tfile
5236 local f2=$DIR2/$tdir/$tfile
5238 fid=$(make_custom_file_for_progress $f 39 1000000)
5239 [ $? != 0 ] && skip "not enough free space" && return
5241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5242 wait_request_state $fid ARCHIVE SUCCEED
5245 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5246 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5249 # 1st request holds layout lock while appropriate
5250 # RESTORE record is still not added to llog
5254 # after umount hsm_actions->O/x/x log shouldn't have
5255 # double RESTORE records like below
5256 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5257 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5259 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5262 wait_request_state $fid RESTORE SUCCEED
5264 run_test 407 "Check for double RESTORE records in llog"
5268 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5269 skip "HSM migrate is not supported" && return
5271 test_mkdir -p $DIR/$tdir
5272 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5274 run_test 500 "various LLAPI HSM tests"
5279 check_and_cleanup_lustre