3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
173 local sleep_time=100000 # 0.1 second
175 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
183 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
184 sleep_time=$(bc <<< "$sleep_time * 2")
187 # try to dump Copytool's stack
188 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
189 "echo t >/proc/sysrq-trigger"
191 echo "copytools failed to stop in ${wait_timeout}s"
196 copytool_monitor_setup() {
197 local facet=${1:-$SINGLEAGT}
198 local agent=$(facet_active_host $facet)
200 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
201 local test_dir=$(do_node $agent "$cmd") ||
202 error "Failed to create tempdir on $agent"
203 export HSMTOOL_MONITOR_DIR=$test_dir
205 # Create the fifo and a monitor (cat dies when copytool dies)
206 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
207 error "failed to create copytool fifo on $agent"
208 cmd="cat $test_dir/fifo > $test_dir/events &"
209 cmd+=" echo \\\$! > $test_dir/monitor_pid"
211 if [[ $PDSH == *Rmrsh* ]]; then
212 # This is required for pdsh -Rmrsh and its handling of remote
214 # Regular ssh and pdsh -Rssh work fine without this
215 # backgrounded subshell nonsense.
216 (do_node $agent "$cmd") &
217 export HSMTOOL_MONITOR_PDSH=$!
219 # Slightly racy, but just making a best-effort to catch obvious
222 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
223 error "Failed to start copytool monitor on $agent"
225 do_node $agent "$cmd"
227 error "Failed to start copytool monitor on $agent"
232 copytool_monitor_cleanup() {
233 local facet=${1:-$SINGLEAGT}
234 local agent=$(facet_active_host $facet)
236 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
237 # Should die when the copytool dies, but just in case.
238 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
239 cmd+=" 2>/dev/null || true"
240 do_node $agent "$cmd"
241 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
242 export HSMTOOL_MONITOR_DIR=
245 # The pdsh should die on its own when the monitor dies. Just
246 # in case, though, try to clean up to avoid any cruft.
247 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
248 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
249 export HSMTOOL_MONITOR_PDSH=
254 local facet=${1:-$SINGLEAGT}
255 # Use MOUNT2 by default if defined
256 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
258 local hsm_root=${4:-$(copytool_device $facet)}
260 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
262 local agent=$(facet_active_host $facet)
264 if $HSM_ARCHIVE_PURGE; then
265 echo "Purging archive on $agent"
266 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
269 echo "Starting copytool $facet on $agent"
270 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
271 error "mkdir '$hsm_root/$HSMTMP' failed"
272 # bandwidth is limited to 1MB/s so the copy time is known and
273 # independent of hardware
274 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
275 cmd+=" --hsm-root $hsm_root/$HSMTMP"
276 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
277 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
278 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
279 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
280 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
281 cmd+=" --bandwidth 1 $lustre_mntpnt"
283 # Redirect the standard output and error to a log file which
284 # can be uploaded to Maloo.
285 local prefix=$TESTLOG_PREFIX
286 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
287 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
289 stack_trap cleanup EXIT
290 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
291 if [[ $? != 0 ]]; then
292 [[ $HSMTOOL_NOERROR == true ]] ||
293 error "start copytool $facet on $agent failed"
294 echo "start copytool $facet on $agent failed"
298 get_copytool_event_log() {
299 local facet=${1:-$SINGLEAGT}
300 local agent=$(facet_active_host $facet)
302 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
303 error "Can't get event log: No monitor directory!"
305 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
306 error "Could not collect event log from $agent"
311 local agt_facet=$SINGLEAGT
312 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
313 local hsm_root=$(copytool_device $agt_facet)
315 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
322 kill_copytools $agt_hosts
323 wait_copytools $agt_hosts || error "copytools failed to stop"
325 # Clean all CDTs orphans requests from previous tests that
326 # would otherwise need to timeout to clear.
327 for ((i = 0; i < MDSCOUNT; i++)); do
329 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
330 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
332 # Skip already stopping or stopped CDTs.
333 [[ "${state[$i]}" =~ ^stop ]] && continue
335 do_facet $facet "$LCTL set_param $param=shutdown"
338 for ((i = 0; i < MDSCOUNT; i++)); do
339 # Only check and restore CDTs that we stopped in the first loop.
340 [[ "${state[$i]}" =~ ^stop ]] && continue
343 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
345 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
346 error "$facet CDT state is not stopped"
348 # Restore old CDT state.
349 do_facet $facet "$LCTL set_param $param=${state[$i]}"
352 for ((i = 0; i < MDSCOUNT; i++)); do
353 # Only check CDTs that we stopped in the first loop.
354 [[ "${state[$i]}" =~ ^stop ]] && continue
357 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
359 # Check that the old CDT state was restored.
360 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
361 20 || error "$facet CDT state is not '${state[$i]}'"
364 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
365 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
370 local agents=${1:-$(facet_active_host $SINGLEAGT)}
372 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
373 echo "Copytool is suspended on $agents"
376 copytool_continue() {
377 local agents=${1:-$(facet_active_host $SINGLEAGT)}
379 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
380 echo "Copytool is continued on $agents"
383 copytool_remove_backend() {
385 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
386 echo "Remove from backend: $fid = $be"
387 do_facet $SINGLEAGT rm -f $be
391 do_facet $SINGLEAGT \
392 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
393 --import $1 $2 $MOUNT" ||
394 error "import of $1 to $2 failed"
397 file_creation_failure() {
404 df $MOUNT $MOUNT2 >&2
405 error "Not enough space to create $file with $cmd"
408 error "cannot create $file with $cmd, status=$err"
413 # Creates a file using dd
419 local if=${5:-/dev/zero}
420 local facet=$SINGLEAGT
423 printf -v cmd 'do_facet "%s" dd if="%s" of="%s" count=%s bs=%s' \
424 "$facet" "$if" "$file" "$count" "$bs"
425 [ -n "$conv" ] && cmd+=" conv=$conv"
427 # Create the directory in case it does not exist
428 do_facet "$facet" mkdir -p "$(dirname "$file")"
429 # Delete the file in case it already exist
430 do_facet "$facet" rm -f "$file"
433 # print the FID if the file is not an archive
434 [[ "$file" =~ ^$HSM_ARCHIVE ]] || path2fid "$file" ||
435 error "cannot get fid on '$file'"
438 printf "$cmd failed with $err\n" >&2;
439 # Let the caller decide what to do on error
444 create_empty_file() {
445 create_file "${1/$DIR/$DIR2}" 1M 0 ||
446 file_creation_failure dd "${1/$DIR/$DIR2}" $?
449 create_small_file() {
450 local source_file=/dev/urandom
453 local conv=${2:-fsync}
455 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
456 file_creation_failure dd "${1/$DIR/$DIR2}" $?
459 create_small_sync_file() {
460 create_small_file "$1" sync
463 create_archive_file() {
464 local if=/dev/urandom
467 local facet=$SINGLEAGT
469 # Create the counterpart directory of the archive
470 do_facet "$facet" mkdir -p "$DIR2/$(dirname "$1")"
471 create_file "${HSM_ARCHIVE}/$1" $bs $count "" $if ||
472 file_creation_failure dd "${HSM_ARCHIVE}/$1" $?
476 local file=$HSM_ARCHIVE/$2
477 do_facet $SINGLEAGT mkdir -p $(dirname $file)
478 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
487 if [[ "$value" != "" ]]; then
490 for mdtno in $(seq 1 $MDSCOUNT); do
491 local idx=$(($mdtno - 1))
492 local facet=mds${mdtno}
493 # if $arg include -P option, run 1 set_param per MDT on the MGS
494 # else, run set_param on each MDT
495 [[ $arg = *"-P"* ]] && facet=mgs
496 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
497 [[ $? != 0 ]] && rc=1
507 for mdtno in $(seq 1 $MDSCOUNT); do
508 local idx=$(($mdtno - 1))
509 wait_result mds${mdtno} \
510 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
512 error "$key state is not '$target' on mds${mdtno}"
519 for mdtno in $(seq 1 $MDSCOUNT); do
520 local idx=$(($mdtno - 1))
521 local cl_user=$(do_facet mds${mdtno} $LCTL \
522 --device ${MDT[$idx]} \
523 changelog_register -n)
525 do_facet mds${mdtno} lctl set_param \
526 mdd.${MDT[$idx]}.changelog_mask="+hsm"
527 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
531 changelog_cleanup() {
533 for mdtno in $(seq 1 $MDSCOUNT); do
534 local idx=$(($mdtno - 1))
535 [[ -z ${CL_USERS[$idx]} ]] && continue
536 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
537 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
538 changelog_deregister ${CL_USERS[$idx]}
543 changelog_get_flags() {
548 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
553 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
561 mdts_set_param "$opt -n" "hsm.$param" "$value"
568 mdts_set_param "" hsm_control "$cmd"
569 mdts_check_param hsm_control "$target" 10
572 cdt_set_sanity_policy() {
573 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
576 mdts_set_param "" hsm.policy "+NRA"
577 mdts_set_param "" hsm.policy "-NBR"
578 CDT_POLICY_HAD_CHANGED=
583 mdts_set_param "" hsm.policy "+NRA"
584 CDT_POLICY_HAD_CHANGED=true
587 cdt_clear_no_retry() {
588 mdts_set_param "" hsm.policy "-NRA"
589 CDT_POLICY_HAD_CHANGED=true
592 cdt_set_non_blocking_restore() {
593 mdts_set_param "" hsm.policy "+NBR"
594 CDT_POLICY_HAD_CHANGED=true
597 cdt_clear_non_blocking_restore() {
598 mdts_set_param "" hsm.policy "-NBR"
599 CDT_POLICY_HAD_CHANGED=true
602 cdt_clear_mount_state() {
603 mdts_set_param "-P -d" hsm_control ""
606 cdt_set_mount_state() {
607 mdts_set_param "-P" hsm_control "$1"
608 # set_param -P is asynchronous operation and could race with set_param.
609 # In such case configs could be retrieved and applied at mgc after
610 # set_param -P completion. Sleep here to avoid race with set_param.
611 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
612 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
613 # and 10 seconds to retrieve config from server.
618 mdts_check_param hsm_control "$1" 20
622 set_test_state disabled disabled
626 set_test_state enabled enabled
630 set_test_state shutdown stopped
634 set_test_state purge enabled
640 cdt_set_sanity_policy
644 local client_count=$1
645 if [[ $CLIENTCOUNT -lt $client_count ]]; then
646 skip "Need $client_count or more clients, have $CLIENTCOUNT"
653 $LFS path2fid $1 | tr -d '[]'
654 return ${PIPESTATUS[0]}
662 if [[ $u == "user" ]]; then
663 st=$($RUNAS $LFS hsm_state $f)
666 st=$($LFS hsm_state $f)
669 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
671 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
675 get_hsm_archive_id() {
678 st=$($LFS hsm_state $f)
679 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
681 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
689 local st=$(get_hsm_flags $f)
690 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
693 check_hsm_flags_user() {
697 local st=$(get_hsm_flags $f user)
698 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
710 if [[ "$3" != 1 ]]; then
714 cp $1 $f || file_creation_failure cp $f $?
716 path2fid $f || error "cannot get fid on $f"
719 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
721 # Note that this might lead to surprising behaviours such as deleting an
722 # important file for the currently running test
723 delete_large_files() {
724 printf "Deleting large files...\n" >&2
725 find $MOUNT -size +10M -delete
726 wait_delete_completed
729 make_custom_file_for_progress() {
730 local count=${2:-"39"}
731 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
734 [[ $count -gt 0 ]] || error "Invalid file size"
735 [[ $bs -gt 0 ]] || error "Invalid stripe size"
737 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
738 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
739 echo "It might be due to a lack of space in the filesystem" >&2
740 delete_large_files >&2
741 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
742 file_creation_failure dd "${1/$DIR/$DIR2}" $?
749 wait_update --verbose $(facet_active_host $facet) "$@"
752 wait_request_state() {
756 # 4th arg (mdt index) is optional
758 local mds=mds$(($mdtidx + 1))
760 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
761 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
763 wait_result $mds "$cmd" $state 200 ||
764 error "request on $fid is not $state on $mds"
767 get_request_state() {
771 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
772 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
775 get_request_count() {
779 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
780 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
783 # Ensure the number of HSM request for a given FID is correct
784 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
785 assert_request_count() {
786 local request_count=$(get_request_count $1 $2)
787 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
789 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
796 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
797 [[ -n $fid ]] && cmd+=" | grep '$fid'"
798 cmd+=" | egrep 'WAITING|STARTED'"
800 wait_result $SINGLEMDS "$cmd" "" $timeout ||
801 error "requests did not complete"
804 wait_for_grace_delay() {
805 local val=$(get_hsm_param grace_delay)
809 wait_for_loop_period() {
810 local val=$(get_hsm_param loop_period)
817 # python2.6 in EL6 includes an internal json module
818 local json_parser='import json; import fileinput;'
819 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
820 json_parser+='json.loads([line for line in '
821 json_parser+='fileinput.input()][0]).items()])'
823 echo $raw_event | python -c "$json_parser"
826 get_agent_by_uuid_mdt() {
829 local mds=mds$(($mdtidx + 1))
830 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
834 check_agent_registered_by_mdt() {
837 local mds=mds$(($mdtidx + 1))
838 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
839 if [[ ! -z "$agent" ]]; then
840 echo "found agent $agent on $mds"
842 error "uuid $uuid not found in agent list on $mds"
846 check_agent_unregistered_by_mdt() {
849 local mds=mds$(($mdtidx + 1))
850 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
851 if [[ -z "$agent" ]]; then
852 echo "uuid not found in agent list on $mds"
854 error "uuid found in agent list on $mds: $agent"
858 check_agent_registered() {
861 for mdsno in $(seq 1 $MDSCOUNT); do
862 check_agent_registered_by_mdt $uuid $((mdsno - 1))
866 check_agent_unregistered() {
869 for mdsno in $(seq 1 $MDSCOUNT); do
870 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
875 local agent=${1:-$(facet_active_host $SINGLEAGT)}
877 # Lustre mount-point is mandatory and last parameter on
879 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
881 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
883 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
889 # populate MDT device array
892 # cleanup from previous bad setup
895 # for recovery tests, coordinator needs to be started at mount
897 # the lustre conf must be without hsm on (like for sanity.sh)
898 echo "Set HSM on and start"
899 cdt_set_mount_state enabled
900 cdt_check_state enabled
902 echo "Set sanity-hsm HSM policy"
903 cdt_set_sanity_policy
905 # finished requests are quickly removed from list
906 set_hsm_param grace_delay 10
912 local f=$DIR/$tdir/$tfile
916 check_hsm_flags_user $f "0x00000000"
918 $RUNAS $LFS hsm_set --norelease $f ||
919 error "user could not change hsm flags"
920 check_hsm_flags_user $f "0x00000010"
922 $RUNAS $LFS hsm_clear --norelease $f ||
923 error "user could not clear hsm flags"
924 check_hsm_flags_user $f "0x00000000"
926 # User could not change those flags...
927 $RUNAS $LFS hsm_set --exists $f &&
928 error "user should not set this flag"
929 check_hsm_flags_user $f "0x00000000"
932 $LFS hsm_set --exists $f ||
933 error "root could not change hsm flags"
934 check_hsm_flags_user $f "0x00000001"
936 $LFS hsm_clear --exists $f ||
937 error "root could not clear hsm state"
938 check_hsm_flags_user $f "0x00000000"
941 run_test 1 "lfs hsm flags root/non-root access"
944 local f=$DIR/$tdir/$tfile
945 local fid=$(create_small_file $f)
949 $LFS hsm_archive $f || error "could not archive file"
950 wait_request_state $fid ARCHIVE SUCCEED
952 # Release and check states
953 $LFS hsm_release $f || error "could not release file"
954 echo -n "Verifying released state: "
955 check_hsm_flags $f "0x0000000d"
957 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
961 run_test 1a "mmap & cat a HSM released file"
965 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
966 error "failed to set default stripe"
967 local f=$DIR/$tdir/$tfile
970 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
971 error "failed to create file"
972 local fid=$(path2fid $f)
977 $LFS hsm_archive $f || error "could not archive file"
978 wait_request_state $fid ARCHIVE SUCCEED
981 $LFS hsm_release $f || error "could not release file"
982 echo "verify released state: "
983 check_hsm_flags $f "0x0000000d" && echo "pass"
986 $LFS hsm_restore $f || error "could not restore file"
987 wait_request_state $fid RESTORE SUCCEED
988 echo "verify restored state: "
989 check_hsm_flags $f "0x00000009" && echo "pass"
993 run_test 1b "Archive, Release & Restore composite file"
999 local f=$DIR/$tdir/$tfile
1002 # Test whether we can set the maximum archive number.
1003 local LOCAL_HSM_ARCHIVE_NUMBER=32
1004 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1005 error "root could not change hsm flags"
1006 check_hsm_flags_user $f "0x00000001"
1007 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1008 local st=$(get_hsm_archive_id $f)
1009 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1010 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1012 # Test whether setting archive number 0 results in no change.
1013 $LFS hsm_set --exists --archive-id 0 $f ||
1014 error "root could not change hsm flags"
1015 check_hsm_flags_user $f "0x00000001"
1016 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1017 st=$(get_hsm_archive_id $f)
1018 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1019 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1021 # Test whether setting archive number > 32 results in error.
1022 $LFS hsm_set --exists --archive-id 33 $f &&
1023 error "archive number is larger than 32"
1024 check_hsm_flags_user $f "0x00000001"
1026 # Test whether setting archive number 16 and archived flag.
1027 LOCAL_HSM_ARCHIVE_NUMBER=16
1028 $LFS hsm_set --exists --archived \
1029 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1030 error "root could not change hsm flags"
1031 check_hsm_flags_user $f "0x00000009"
1032 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1033 st=$(get_hsm_archive_id $f)
1034 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1035 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1037 run_test 1c "Check setting archive-id in lfs hsm_set"
1040 local f=$DIR/$tdir/$tfile
1042 create_empty_file "$f"
1043 # New files are not dirty
1044 check_hsm_flags $f "0x00000000"
1046 # For test, we simulate an archived file.
1047 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1048 check_hsm_flags $f "0x00000001"
1050 # chmod do not put the file dirty
1051 chmod 600 $f || error "could not chmod test file"
1052 check_hsm_flags $f "0x00000001"
1054 # chown do not put the file dirty
1055 chown $RUNAS_ID $f || error "could not chown test file"
1056 check_hsm_flags $f "0x00000001"
1058 # truncate put the file dirty
1059 $TRUNCATE $f 1 || error "could not truncate test file"
1060 check_hsm_flags $f "0x00000003"
1062 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1063 check_hsm_flags $f "0x00000001"
1065 run_test 2 "Check file dirtyness when doing setattr"
1071 # New files are not dirty
1072 cp -p /etc/passwd $f
1073 check_hsm_flags $f "0x00000000"
1075 # For test, we simulate an archived file.
1076 $LFS hsm_set --exists $f ||
1077 error "user could not change hsm flags"
1078 check_hsm_flags $f "0x00000001"
1080 # Reading a file, does not set dirty
1081 cat $f > /dev/null || error "could not read file"
1082 check_hsm_flags $f "0x00000001"
1084 # Open for write without modifying data, does not set dirty
1085 openfile -f O_WRONLY $f || error "could not open test file"
1086 check_hsm_flags $f "0x00000001"
1088 # Append to a file sets it dirty
1089 cp -p /etc/passwd $f.append || error "could not create file"
1090 $LFS hsm_set --exists $f.append ||
1091 error "user could not change hsm flags"
1092 dd if=/etc/passwd of=$f.append bs=1 count=3\
1093 conv=notrunc oflag=append status=noxfer ||
1094 file_creation_failure dd $f.append $?
1095 check_hsm_flags $f.append "0x00000003"
1097 # Modify a file sets it dirty
1098 cp -p /etc/passwd $f.modify || error "could not create file"
1099 $LFS hsm_set --exists $f.modify ||
1100 error "user could not change hsm flags"
1101 dd if=/dev/zero of=$f.modify bs=1 count=3\
1102 conv=notrunc status=noxfer ||
1103 file_creation_failure dd $f.modify $?
1104 check_hsm_flags $f.modify "0x00000003"
1106 # Open O_TRUNC sets dirty
1107 cp -p /etc/passwd $f.trunc || error "could not create file"
1108 $LFS hsm_set --exists $f.trunc ||
1109 error "user could not change hsm flags"
1110 cp /etc/group $f.trunc || error "could not override a file"
1111 check_hsm_flags $f.trunc "0x00000003"
1113 # Mmapped a file sets dirty
1114 cp -p /etc/passwd $f.mmap || error "could not create file"
1115 $LFS hsm_set --exists $f.mmap ||
1116 error "user could not change hsm flags"
1117 multiop $f.mmap OSMWUc || error "could not mmap a file"
1118 check_hsm_flags $f.mmap "0x00000003"
1120 run_test 3 "Check file dirtyness when opening for write"
1123 local f=$DIR/$tdir/$tfile
1124 local fid=$(create_small_file $f)
1127 local st=$(get_request_state $fid CANCEL)
1128 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1130 run_test 4 "Useless cancel must not be registered"
1133 # test needs a running copytool
1137 local f=$DIR/$tdir/$tfile
1138 local fid=$(copy_file /etc/passwd $f)
1140 wait_request_state $fid ARCHIVE SUCCEED
1142 check_hsm_flags $f "0x00000009"
1146 run_test 8 "Test default archive number"
1149 # we do not use the default one to be sure
1150 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1152 copytool_setup $SINGLEAGT $MOUNT $new_an
1154 # give time for CT to register with MDTs
1155 sleep $(($MDSCOUNT*2))
1156 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1157 check_agent_registered $uuid
1160 local f=$DIR/$tdir/$tfile
1161 local fid=$(copy_file /etc/passwd $f)
1162 $LFS hsm_archive --archive $new_an $f
1163 wait_request_state $fid ARCHIVE SUCCEED
1165 check_hsm_flags $f "0x00000009"
1169 run_test 9 "Use of explicit archive number, with dedicated copytool"
1172 needclients 3 || return 0
1178 copytool_cleanup $(comma_list $(agts_nodes))
1180 # start all of the copytools
1181 for n in $(seq $AGTCOUNT); do
1182 copytool_setup agt$n
1185 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1187 for n in $(seq $AGTCOUNT); do
1188 file=$DIR/$tdir/$tfile.$n
1189 fid=$(create_small_file $file)
1191 $LFS hsm_archive $file || error "could not archive file $file"
1192 wait_request_state $fid ARCHIVE SUCCEED
1193 check_hsm_flags $file "0x00000009"
1197 copytool_cleanup $(comma_list $(agts_nodes))
1199 run_test 9a "Multiple remote agents"
1202 # test needs a running copytool
1205 mkdir -p $DIR/$tdir/d1
1206 local f=$DIR/$tdir/$tfile
1207 local fid=$(copy_file /etc/hosts $f)
1208 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1209 error "hsm_archive failed"
1210 wait_request_state $fid ARCHIVE SUCCEED
1212 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1213 error "fid $fid not in archive $HSM_ARCHIVE"
1214 echo "Verifying content"
1215 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1216 echo "Verifying hsm state "
1217 check_hsm_flags $f "0x00000009"
1219 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1220 local st=$(get_hsm_archive_id $f)
1221 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1222 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1227 run_test 10a "Archive a file"
1230 # test needs a running copytool
1234 local f=$DIR/$tdir/$tfile
1235 local fid=$(copy_file /etc/hosts $f)
1236 $LFS hsm_archive $f || error "archive request failed"
1237 wait_request_state $fid ARCHIVE SUCCEED
1239 $LFS hsm_archive $f || error "archive of non dirty file failed"
1240 local cnt=$(get_request_count $fid ARCHIVE)
1241 [[ "$cnt" == "1" ]] ||
1242 error "archive of non dirty file must not make a request"
1246 run_test 10b "Archive of non dirty file must work without doing request"
1249 # test needs a running copytool
1253 local f=$DIR/$tdir/$tfile
1254 local fid=$(copy_file /etc/hosts $f)
1255 $LFS hsm_set --noarchive $f
1256 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1260 run_test 10c "Check forbidden archive"
1263 # test needs a running copytool
1267 local f=$DIR/$tdir/$tfile
1268 local fid=$(copy_file /etc/hosts $f)
1269 $LFS hsm_archive $f || error "cannot archive $f"
1270 wait_request_state $fid ARCHIVE SUCCEED
1272 local ar=$(get_hsm_archive_id $f)
1273 local dflt=$(get_hsm_param default_archive_id)
1274 [[ $ar == $dflt ]] ||
1275 error "archived file is not on default archive: $ar != $dflt"
1279 run_test 10d "Archive a file on the default archive id"
1283 copy2archive /etc/hosts $tdir/$tfile
1284 local f=$DIR/$tdir/$tfile
1286 import_file $tdir/$tfile $f
1287 echo -n "Verifying released state: "
1288 check_hsm_flags $f "0x0000000d"
1290 local LSZ=$(stat -c "%s" $f)
1291 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1293 echo "Verifying imported size $LSZ=$ASZ"
1294 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1295 echo -n "Verifying released pattern: "
1296 local PTRN=$($GETSTRIPE -L $f)
1298 [[ $PTRN == 80000001 ]] || error "Is not released"
1299 local fid=$(path2fid $f)
1300 echo "Verifying new fid $fid in archive"
1302 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1303 error "fid $fid not in archive $HSM_ARCHIVE"
1305 run_test 11a "Import a file"
1308 # test needs a running copytool
1312 local f=$DIR/$tdir/$tfile
1313 local fid=$(copy_file /etc/hosts $f)
1314 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1315 error "hsm_archive failed"
1316 wait_request_state $fid ARCHIVE SUCCEED
1318 local FILE_HASH=$(md5sum $f)
1323 echo "$FILE_HASH" | md5sum -c
1325 [[ $? -eq 0 ]] || error "Restored file differs"
1329 run_test 11b "Import a deleted file using its FID"
1332 # test needs a running copytool
1336 copy2archive /etc/hosts $tdir/$tfile
1338 local f=$DIR/$tdir/$tfile
1339 import_file $tdir/$tfile $f
1340 local f2=$DIR2/$tdir/$tfile
1341 echo "Verifying released state: "
1342 check_hsm_flags $f2 "0x0000000d"
1344 local fid=$(path2fid $f2)
1345 $LFS hsm_restore $f2
1346 wait_request_state $fid RESTORE SUCCEED
1348 echo "Verifying file state: "
1349 check_hsm_flags $f2 "0x00000009"
1351 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1353 [[ $? -eq 0 ]] || error "Restored file differs"
1357 run_test 12a "Restore an imported file explicitly"
1360 # test needs a running copytool
1364 copy2archive /etc/hosts $tdir/$tfile
1366 local f=$DIR/$tdir/$tfile
1367 import_file $tdir/$tfile $f
1368 echo "Verifying released state: "
1369 check_hsm_flags $f "0x0000000d"
1371 cat $f > /dev/null || error "File read failed"
1373 echo "Verifying file state after restore: "
1374 check_hsm_flags $f "0x00000009"
1376 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1378 [[ $? -eq 0 ]] || error "Restored file differs"
1382 run_test 12b "Restore an imported file implicitly"
1385 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1387 # test needs a running copytool
1390 local f=$DIR/$tdir/$tfile
1392 $LFS setstripe -c 2 "$f"
1394 fid=$(make_custom_file_for_progress $f 5)
1395 [ $? != 0 ] && skip "not enough free space" && return
1397 local FILE_CRC=$(md5sum $f)
1399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1400 wait_request_state $fid ARCHIVE SUCCEED
1401 $LFS hsm_release $f || error "release $f failed"
1403 echo "$FILE_CRC" | md5sum -c
1405 [[ $? -eq 0 ]] || error "Restored file differs"
1409 run_test 12c "Restore a file with stripe of 2"
1412 # test needs a running copytool
1417 local f=$DIR/$tdir/$tfile
1418 local fid=$(copy_file /etc/hosts $f)
1419 $LFS hsm_restore $f || error "restore of non archived file failed"
1420 local cnt=$(get_request_count $fid RESTORE)
1421 [[ "$cnt" == "0" ]] ||
1422 error "restore non archived must not make a request"
1423 $LFS hsm_archive $f ||
1424 error "archive request failed"
1425 wait_request_state $fid ARCHIVE SUCCEED
1426 $LFS hsm_restore $f ||
1427 error "restore of non released file failed"
1428 local cnt=$(get_request_count $fid RESTORE)
1429 [[ "$cnt" == "0" ]] ||
1430 error "restore a non dirty file must not make a request"
1434 run_test 12d "Restore of a non archived, non released file must work"\
1435 " without doing request"
1438 # test needs a running copytool
1441 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1442 local f=$DIR/$tdir/$tfile
1443 local fid=$(copy_file /etc/hosts $f)
1444 $LFS hsm_archive $f || error "archive request failed"
1445 wait_request_state $fid ARCHIVE SUCCEED
1448 cat /etc/hosts >> $f
1452 $LFS hsm_restore $f && error "restore a dirty file must fail"
1456 run_test 12e "Check forbidden restore"
1459 # test needs a running copytool
1463 local f=$DIR/$tdir/$tfile
1464 local fid=$(copy_file /etc/hosts $f)
1466 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1467 wait_request_state $fid ARCHIVE SUCCEED
1468 $LFS hsm_release $f || error "release of $f failed"
1470 wait_request_state $fid RESTORE SUCCEED
1472 echo -n "Verifying file state: "
1473 check_hsm_flags $f "0x00000009"
1475 diff -q /etc/hosts $f
1477 [[ $? -eq 0 ]] || error "Restored file differs"
1481 run_test 12f "Restore a released file explicitly"
1484 # test needs a running copytool
1488 local f=$DIR/$tdir/$tfile
1489 local fid=$(copy_file /etc/hosts $f)
1491 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1492 wait_request_state $fid ARCHIVE SUCCEED
1493 $LFS hsm_release $f || error "release of $f failed"
1495 diff -q /etc/hosts $f
1498 # we check we had a restore done
1499 wait_request_state $fid RESTORE SUCCEED
1501 [[ $st -eq 0 ]] || error "Restored file differs"
1505 run_test 12g "Restore a released file implicitly"
1508 needclients 2 || return 0
1510 # test needs a running copytool
1514 local f=$DIR/$tdir/$tfile
1515 local fid=$(copy_file /etc/hosts $f)
1517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1518 wait_request_state $fid ARCHIVE SUCCEED
1519 $LFS hsm_release $f || error "release of $f failed"
1521 do_node $CLIENT2 diff -q /etc/hosts $f
1524 # we check we had a restore done
1525 wait_request_state $fid RESTORE SUCCEED
1527 [[ $st -eq 0 ]] || error "Restored file differs"
1531 run_test 12h "Restore a released file implicitly from a second node"
1534 # test needs a running copytool
1538 local f=$DIR/$tdir/$tfile
1539 local fid=$(copy_file /etc/passwd $f)
1540 $LFS hsm_archive $f || error "archive of $f failed"
1541 wait_request_state $fid ARCHIVE SUCCEED
1543 $LFS hsm_release $f || error "release of $f failed"
1547 [[ $? -eq 0 ]] || error "Restored file differs"
1551 run_test 12m "Archive/release/implicit restore"
1554 # test needs a running copytool
1558 copy2archive /etc/hosts $tdir/$tfile
1560 local f=$DIR/$tdir/$tfile
1561 import_file $tdir/$tfile $f
1563 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1564 error "Restored file differs"
1566 $LFS hsm_release $f || error "release of $f failed"
1570 run_test 12n "Import/implicit restore/release"
1573 # test needs a running copytool
1577 local f=$DIR/$tdir/$tfile
1578 local fid=$(copy_file /etc/hosts $f)
1580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1581 wait_request_state $fid ARCHIVE SUCCEED
1582 $LFS hsm_release $f || error "release of $f failed"
1584 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1585 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1587 # set no retry action mode
1590 diff -q /etc/hosts $f
1593 # we check we had a restore failure
1594 wait_request_state $fid RESTORE FAILED
1596 [[ $st -eq 0 ]] && error "Restore must fail"
1598 # remove no retry action mode
1601 # check file is still released
1602 check_hsm_flags $f "0x0000000d"
1604 # retry w/o failure injection
1605 do_facet $SINGLEMDS lctl set_param fail_loc=0
1607 # to be sure previous RESTORE result is gone
1609 wait_for_grace_delay
1611 diff -q /etc/hosts $f
1614 # we check we had a restore done
1615 wait_request_state $fid RESTORE SUCCEED
1617 [[ $st -eq 0 ]] || error "Restored file differs"
1621 run_test 12o "Layout-swap failure during Restore leaves file released"
1624 # test needs a running copytool
1628 local f=$DIR/$tdir/$tfile
1629 local fid=$(copy_file /etc/hosts $f)
1631 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1632 wait_request_state $fid ARCHIVE SUCCEED
1633 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1634 $LFS hsm_release $f || error "cannot release $f"
1635 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1636 $LFS hsm_release $f || error "cannot release $f"
1637 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1641 run_test 12p "implicit restore of a file on copytool mount point"
1643 cleanup_test_12q() {
1645 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1646 error "cannot umount $MOUNT3 on $SINGLEAGT"
1650 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1651 skip "need MDS version at least 2.7.58" && return 0
1653 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1654 error "cannot mount $MOUNT3 on $SINGLEAGT"
1656 trap cleanup_test_12q EXIT
1658 # test needs a running copytool
1659 copytool_setup $SINGLEAGT $MOUNT3
1661 local f=$DIR/$tdir/$tfile
1662 local f2=$DIR2/$tdir/$tfile
1663 local fid=$(create_small_file $f)
1664 local orig_size=$(stat -c "%s" $f)
1666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1667 wait_request_state $fid ARCHIVE SUCCEED
1669 $LFS hsm_release $f || error "could not release file"
1670 check_hsm_flags $f "0x0000000d"
1673 wait_copytools || error "copytool failed to stop"
1675 cat $f > /dev/null &
1677 # wait a bit to allow implicit restore request to be handled.
1678 # if not, next stat would also block on layout-lock.
1681 local size=$(stat -c "%s" $f2)
1682 [ $size -eq $orig_size ] ||
1683 error "$f2: wrong size after archive: $size != $orig_size"
1685 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1689 size=$(stat -c "%s" $f)
1690 [ $size -eq $orig_size ] ||
1691 error "$f: wrong size after restore: $size != $orig_size"
1693 size=$(stat -c "%s" $f2)
1694 [ $size -eq $orig_size ] ||
1695 error "$f2: wrong size after restore: $size != $orig_size"
1699 size=$(stat -c "%s" $f)
1701 error "$f: wrong size after overwrite: $size != 0"
1703 size=$(stat -c "%s" $f2)
1705 error "$f2: wrong size after overwrite: $size != 0"
1708 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1709 error "cannot umount $MOUNT3 on $SINGLEAGT"
1711 run_test 12q "file attributes are refreshed after restore"
1714 # test needs a running copytool
1717 local ARC_SUBDIR="import.orig"
1721 # populate directory to be imported
1722 for d in $(seq 1 10); do
1723 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1724 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1725 for f in $(seq 1 10); do
1726 CURR_FILE="$CURR_DIR/$tfile.$f"
1727 # write file-specific data
1728 do_facet $SINGLEAGT \
1729 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1730 "file=$CURR_FILE > $CURR_FILE"
1734 import_file "$ARC_SUBDIR" $DIR/$tdir
1735 # diff lustre content and origin (triggers file restoration)
1736 # there must be 10x10 identical files, and no difference
1737 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1738 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1739 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1740 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1742 [ $cnt_diff -eq 0 ] ||
1743 error "$cnt_diff imported files differ from read data"
1744 [ $cnt_ok -eq 100 ] ||
1745 error "not enough identical files ($cnt_ok != 100)"
1749 run_test 13 "Recursively import and restore a directory"
1752 # test needs a running copytool
1756 local f=$DIR/$tdir/$tfile
1757 local fid=$(create_small_file $f)
1758 local sum=$(md5sum $f | awk '{print $1}')
1759 $LFS hsm_archive $f || error "could not archive file"
1760 wait_request_state $fid ARCHIVE SUCCEED
1762 # create released file (simulate llapi_hsm_import call)
1763 local fid2=$(create_empty_file "$f")
1764 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1765 $LFS hsm_release $f || error "could not release file"
1767 # rebind the archive to the newly created file
1768 echo "rebind $fid to $fid2"
1770 do_facet $SINGLEAGT \
1771 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1772 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1774 # restore file and compare md5sum
1775 local sum2=$(md5sum $f | awk '{print $1}')
1777 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1781 run_test 14 "Rebind archived file to a new fid"
1784 # test needs a running copytool
1788 local f=$DIR/$tdir/$tfile
1790 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1794 for i in $(seq 1 $count); do
1795 fids[$i]=$(create_small_file $f.$i)
1796 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1797 $LFS hsm_archive $f.$i || error "could not archive file"
1799 wait_all_done $(($count*60))
1803 for i in $(seq 1 $count); do
1804 local fid2=$(create_empty_file "${f}.${i}")
1805 # add the rebind operation to the list
1806 echo ${fids[$i]} $fid2 >> $tmpfile
1808 # set it released (simulate llapi_hsm_import call)
1809 $LFS hsm_set --archived --exists $f.$i ||
1810 error "could not force hsm flags"
1811 $LFS hsm_release $f.$i || error "could not release file"
1813 nl=$(wc -l < $tmpfile)
1814 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1816 echo "rebind list of files"
1817 do_facet $SINGLEAGT \
1818 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1819 --rebind $tmpfile $DIR" || error "could not rebind file list"
1821 # restore files and compare md5sum
1822 for i in $(seq 1 $count); do
1823 local sum2=$(md5sum $f.$i | awk '{print $1}')
1824 [[ $sum2 == ${sums[$i]} ]] ||
1825 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1831 run_test 15 "Rebind a list of files"
1834 # test needs a running copytool
1838 # create a known size file so we can verify transfer speed
1841 dd if=/dev/zero of=$ref bs=1M count=20
1844 local f=$DIR/$tdir/$tfile
1845 local fid=$(copy_file $ref $f)
1847 local start=$(date +%s)
1849 wait_request_state $fid ARCHIVE SUCCEED
1850 local end=$(date +%s)
1851 # Add 1 to account for rounding errors between start and end (LU-8155)
1852 local duration=$((end - start + 1))
1854 [[ $duration -ge $((goal - 1)) ]] ||
1855 error "Transfer is too fast $duration < $goal"
1859 run_test 16 "Test CT bandwith control option"
1862 local f=$DIR/$tdir/$tfile
1863 create_empty_file "$f"
1865 # Could not release a non-archived file
1866 $LFS hsm_release $f && error "release should not succeed"
1868 # For following tests, we must test them with HS_ARCHIVED set
1869 $LFS hsm_set --exists --archived $f || error "could not add flag"
1871 # Could not release a file if no-release is set
1872 $LFS hsm_set --norelease $f || error "could not add flag"
1873 $LFS hsm_release $f && error "release should not succeed"
1874 $LFS hsm_clear --norelease $f || error "could not remove flag"
1876 # Could not release a file if lost
1877 $LFS hsm_set --lost $f || error "could not add flag"
1878 $LFS hsm_release $f && error "release should not succeed"
1879 $LFS hsm_clear --lost $f || error "could not remove flag"
1881 # Could not release a file if dirty
1882 $LFS hsm_set --dirty $f || error "could not add flag"
1883 $LFS hsm_release $f && error "release should not succeed"
1884 $LFS hsm_clear --dirty $f || error "could not remove flag"
1886 run_test 20 "Release is not permitted"
1889 # test needs a running copytool
1892 local f=$DIR/$tdir/test_release
1894 # Create a file and check its states
1895 local fid=$(create_small_file $f)
1896 check_hsm_flags $f "0x00000000"
1898 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1899 # used until file is flushed to disk
1900 if [ $(facet_fstype ost1) == "zfs" ]; then
1901 # this causes an OST_SYNC rpc to be sent
1902 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1903 # clear locks to reread file data
1904 cancel_lru_locks osc
1907 local orig_size=$(stat -c "%s" $f)
1908 local orig_blocks=$(stat -c "%b" $f)
1910 start_full_debug_logging
1912 $LFS hsm_archive $f || error "could not archive file"
1913 wait_request_state $fid ARCHIVE SUCCEED
1915 local blocks=$(stat -c "%b" $f)
1916 [ $blocks -eq $orig_blocks ] ||
1917 error "$f: wrong block number after archive: " \
1918 "$blocks != $orig_blocks"
1919 local size=$(stat -c "%s" $f)
1920 [ $size -eq $orig_size ] ||
1921 error "$f: wrong size after archive: $size != $orig_size"
1923 # Release and check states
1924 $LFS hsm_release $f || error "could not release file"
1925 check_hsm_flags $f "0x0000000d"
1927 blocks=$(stat -c "%b" $f)
1928 [ $blocks -gt 5 ] &&
1929 error "$f: too many blocks after release: $blocks > 5"
1930 size=$(stat -c "%s" $f)
1931 [ $size -ne $orig_size ] &&
1932 error "$f: wrong size after release: $size != $orig_size"
1934 # Check we can release an file without stripe info
1938 check_hsm_flags $f "0x00000000"
1939 $LFS hsm_archive $f || error "could not archive file"
1940 wait_request_state $fid ARCHIVE SUCCEED
1942 # Release and check states
1943 $LFS hsm_release $f || error "could not release file"
1944 check_hsm_flags $f "0x0000000d"
1946 # Release again a file that is already released is OK
1947 $LFS hsm_release $f || fail "second release should succeed"
1948 check_hsm_flags $f "0x0000000d"
1950 stop_full_debug_logging
1954 run_test 21 "Simple release tests"
1957 # test needs a running copytool
1960 local f=$DIR/$tdir/test_release
1961 local swap=$DIR/$tdir/test_swap
1963 # Create a file and check its states
1964 local fid=$(create_small_file $f)
1965 check_hsm_flags $f "0x00000000"
1967 $LFS hsm_archive $f || error "could not archive file"
1968 wait_request_state $fid ARCHIVE SUCCEED
1970 # Release and check states
1971 $LFS hsm_release $f || error "could not release file"
1972 check_hsm_flags $f "0x0000000d"
1974 create_small_file $swap
1975 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1980 run_test 22 "Could not swap a release file"
1983 # test needs a running copytool
1986 local f=$DIR/$tdir/test_mtime
1988 # Create a file and check its states
1989 local fid=$(create_small_file $f)
1990 check_hsm_flags $f "0x00000000"
1992 $LFS hsm_archive $f || error "could not archive file"
1993 wait_request_state $fid ARCHIVE SUCCEED
1995 # Set modification time in the past
1996 touch -m -a -d @978261179 $f
1998 # Release and check states
1999 $LFS hsm_release $f || error "could not release file"
2000 check_hsm_flags $f "0x0000000d"
2002 local MTIME=$(stat -c "%Y" $f)
2003 local ATIME=$(stat -c "%X" $f)
2004 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
2005 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
2009 run_test 23 "Release does not change a/mtime (utime)"
2012 local file=$DIR/$tdir/$tfile
2021 # test needs a running copytool
2024 fid=$(create_small_file $file)
2026 # Create a file and check its states
2027 check_hsm_flags $file "0x00000000"
2029 # Ensure atime is less than mtime and ctime.
2033 atime0=$(stat -c "%X" $file)
2034 mtime0=$(stat -c "%Y" $file)
2035 ctime0=$(stat -c "%Z" $file)
2037 [ $atime0 -lt $mtime0 ] ||
2038 error "atime $atime0 is not less than mtime $mtime0"
2040 [ $atime0 -lt $ctime0 ] ||
2041 error "atime $atime0 is not less than ctime $ctime0"
2043 # Archive should not change any timestamps.
2044 $LFS hsm_archive $file || error "cannot archive '$file'"
2045 wait_request_state $fid ARCHIVE SUCCEED
2047 atime1=$(stat -c "%X" $file)
2048 mtime1=$(stat -c "%Y" $file)
2049 ctime1=$(stat -c "%Z" $file)
2051 [ $atime0 -eq $atime1 ] ||
2052 error "archive changed atime from $atime0 to $atime1"
2054 [ $mtime0 -eq $mtime1 ] ||
2055 error "archive changed mtime from $mtime0 to $mtime1"
2057 [ $ctime0 -eq $ctime1 ] ||
2058 error "archive changed ctime from $ctime0 to $ctime1"
2060 # Release should not change any timestamps.
2061 $LFS hsm_release $file || error "cannot release '$file'"
2062 check_hsm_flags $file "0x0000000d"
2064 atime1=$(stat -c "%X" $file)
2065 mtime1=$(stat -c "%Y" $file)
2066 ctime1=$(stat -c "%Z" $file)
2068 [ $atime0 -eq $atime1 ] ||
2069 error "release changed atime from $atime0 to $atime1"
2071 [ $mtime0 -eq $mtime1 ] ||
2072 error "release changed mtime from $mtime0 to $mtime1"
2074 [ $ctime0 -eq $ctime1 ] ||
2075 error "release changed ctime from $ctime0 to $ctime1"
2077 # Restore should not change any timestamps.
2078 $LFS hsm_restore $file
2079 wait_request_state $fid RESTORE SUCCEED
2081 atime1=$(stat -c "%X" $file)
2082 mtime1=$(stat -c "%Y" $file)
2083 ctime1=$(stat -c "%Z" $file)
2085 [ $atime0 -eq $atime1 ] ||
2086 error "restore changed atime from $atime0 to $atime1"
2088 [ $mtime0 -eq $mtime1 ] ||
2089 error "restore changed mtime from $mtime0 to $mtime1"
2091 [ $ctime0 -eq $ctime1 ] ||
2092 error "restore changed ctime from $ctime0 to $ctime1"
2096 # Once more, after unmount and mount.
2097 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2098 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2100 atime1=$(stat -c "%X" $file)
2101 mtime1=$(stat -c "%Y" $file)
2102 ctime1=$(stat -c "%Z" $file)
2104 [ $atime0 -eq $atime1 ] ||
2105 error "remount changed atime from $atime0 to $atime1"
2107 [ $mtime0 -eq $mtime1 ] ||
2108 error "remount changed mtime from $mtime0 to $mtime1"
2110 [ $ctime0 -eq $ctime1 ] ||
2111 error "remount changed ctime from $ctime0 to $ctime1"
2113 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2116 local file=$DIR/$tdir/$tfile
2122 # Test needs a running copytool.
2125 # Check that root can do HSM actions on a regular user's file.
2126 fid=$(create_small_file $file)
2127 sum0=$(md5sum $file)
2129 chown $RUNAS_ID:$RUNAS_GID $file ||
2130 error "cannot chown '$file' to '$RUNAS_ID'"
2132 chmod ugo-w $DIR/$tdir ||
2133 error "cannot chmod '$DIR/$tdir'"
2135 $LFS hsm_archive $file
2136 wait_request_state $fid ARCHIVE SUCCEED
2138 $LFS hsm_release $file
2139 check_hsm_flags $file "0x0000000d"
2141 $LFS hsm_restore $file
2142 wait_request_state $fid RESTORE SUCCEED
2144 # Check that ordinary user can get HSM state.
2145 $RUNAS $LFS hsm_state $file ||
2146 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2148 $LFS hsm_release $file
2149 check_hsm_flags $file "0x0000000d"
2151 # Check that ordinary user can accessed released file.
2152 sum1=$($RUNAS md5sum $file) ||
2153 error "user '$RUNAS_ID' cannot read '$file'"
2155 [ "$sum0" == "$sum1" ] ||
2156 error "md5sum mismatch for '$file'"
2160 run_test 24b "root can archive, release, and restore user files"
2162 cleanup_test_24c() {
2164 set_hsm_param user_request_mask RESTORE
2165 set_hsm_param group_request_mask RESTORE
2166 set_hsm_param other_request_mask RESTORE
2170 local file=$DIR/$tdir/$tfile
2171 local action=archive
2176 # test needs a running copytool
2181 # Save the default masks and check that cleanup_24c will
2182 # restore the request masks correctly.
2183 user_save=$(get_hsm_param user_request_mask)
2184 group_save=$(get_hsm_param group_request_mask)
2185 other_save=$(get_hsm_param other_request_mask)
2187 [ "$user_save" == RESTORE ] ||
2188 error "user_request_mask is '$user_save' expected 'RESTORE'"
2189 [ "$group_save" == RESTORE ] ||
2190 error "group_request_mask is '$group_save' expected 'RESTORE'"
2191 [ "$other_save" == RESTORE ] ||
2192 error "other_request_mask is '$other_save' expected 'RESTORE'"
2194 trap cleanup_test_24c EXIT
2197 create_small_file $file
2198 chown $RUNAS_ID:nobody $file ||
2199 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2201 $RUNAS $LFS hsm_$action $file &&
2202 error "$action by user should fail"
2204 set_hsm_param user_request_mask $action
2205 $RUNAS $LFS hsm_$action $file ||
2206 error "$action by user should succeed"
2209 create_small_file $file
2210 chown nobody:$RUNAS_GID $file ||
2211 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2213 $RUNAS $LFS hsm_$action $file &&
2214 error "$action by group should fail"
2216 set_hsm_param group_request_mask $action
2217 $RUNAS $LFS hsm_$action $file ||
2218 error "$action by group should succeed"
2221 create_small_file $file
2222 chown nobody:nobody $file ||
2223 error "cannot chown '$file' to 'nobody:nobody'"
2225 $RUNAS $LFS hsm_$action $file &&
2226 error "$action by other should fail"
2228 set_hsm_param other_request_mask $action
2229 $RUNAS $LFS hsm_$action $file ||
2230 error "$action by other should succeed"
2235 run_test 24c "check that user,group,other request masks work"
2237 cleanup_test_24d() {
2238 mount -o remount,rw $MOUNT2
2239 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2243 local file1=$DIR/$tdir/$tfile
2244 local file2=$DIR2/$tdir/$tfile
2248 fid1=$(create_small_file $file1)
2251 $LFS getstripe $file1
2253 trap cleanup_test_24d EXIT
2254 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2255 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2256 copytool_setup $SINGLEAGT "$MOUNT3" ||
2257 error "unable to setup a copytool for the test"
2259 mount -o remount,ro $MOUNT2
2261 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2263 fid2=$(path2fid $file2)
2264 [ "$fid1" == "$fid2" ] ||
2265 error "FID mismatch '$fid1' != '$fid2'"
2267 $LFS hsm_archive $file2 &&
2268 error "archive should fail on read-only mount"
2269 check_hsm_flags $file1 "0x00000000"
2271 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2272 wait_request_state $fid1 ARCHIVE SUCCEED
2274 $LFS hsm_release $file1
2275 $LFS hsm_restore $file2
2276 wait_request_state $fid1 RESTORE SUCCEED
2278 $LFS hsm_release $file1 || error "cannot release '$file1'"
2279 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2281 $LFS hsm_release $file2 &&
2282 error "release should fail on read-only mount"
2286 run_test 24d "check that read-only mounts are respected"
2291 local f=$DIR/$tdir/$tfile
2294 fid=$(create_small_file $f) || error "cannot create $f"
2295 $LFS hsm_archive $f || error "cannot archive $f"
2296 wait_request_state $fid ARCHIVE SUCCEED
2297 $LFS hsm_release $f || error "cannot release $f"
2298 while ! $LFS hsm_state $f | grep released; do
2302 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2306 run_test 24e "tar succeeds on HSM released files" # LU-6213
2310 # test needs a running copytool
2313 mkdir -p $DIR/$tdir/d1
2314 local f=$DIR/$tdir/$tfile
2315 local fid=$(copy_file /etc/hosts $f)
2318 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2319 error "hsm_archive failed"
2320 wait_request_state $fid ARCHIVE SUCCEED
2321 $LFS hsm_release $f || error "cannot release $f"
2322 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2325 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2326 error "Can not recover the tar contents"
2328 echo "Sum0 = $sum0, sum1 = $sum1"
2329 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2333 run_test 24f "root can archive, release, and restore tar files"
2336 # test needs a running copytool
2340 copy2archive /etc/hosts $tdir/$tfile
2342 local f=$DIR/$tdir/$tfile
2344 import_file $tdir/$tfile $f
2346 $LFS hsm_set --lost $f
2351 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2355 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2356 " (Operation not permitted)"
2359 # test needs a running copytool
2364 local f=$DIR/$tdir/$tfile
2365 local fid=$(copy_file /etc/passwd $f)
2367 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2368 wait_request_state $fid ARCHIVE SUCCEED
2371 $LFS hsm_set --lost $f
2375 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2379 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2380 " (Operation not permitted)"
2383 # test needs a running copytool
2386 local f=$DIR/$tdir/$tfile
2388 fid=$(make_custom_file_for_progress $f 39 1000000)
2389 [ $? != 0 ] && skip "not enough free space" && return
2391 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2392 wait_request_state $fid ARCHIVE SUCCEED
2395 wait_request_state $fid REMOVE SUCCEED
2397 check_hsm_flags $f "0x00000000"
2401 run_test 26 "Remove the archive of a valid file"
2403 cleanup_test_26a() {
2405 set_hsm_param remove_archive_on_last_unlink 0
2406 set_hsm_param loop_period $orig_loop_period
2407 set_hsm_param grace_delay $orig_grace_delay
2412 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2413 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2415 # test needs a running copytool
2419 local f=$DIR/$tdir/$tfile
2420 local fid=$(copy_file /etc/passwd $f)
2422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2423 wait_request_state $fid ARCHIVE SUCCEED
2425 local f2=$DIR/$tdir/${tfile}_2
2426 local fid2=$(copy_file /etc/passwd $f2)
2428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2429 wait_request_state $fid2 ARCHIVE SUCCEED
2431 local f3=$DIR/$tdir/${tfile}_3
2432 local fid3=$(copy_file /etc/passwd $f3)
2434 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2435 wait_request_state $fid3 ARCHIVE SUCCEED
2437 trap cleanup_test_26a EXIT
2439 # set a long grace_delay vs short loop_period
2440 local orig_loop_period=$(get_hsm_param loop_period)
2441 local orig_grace_delay=$(get_hsm_param grace_delay)
2442 set_hsm_param loop_period 10
2443 set_hsm_param grace_delay 100
2447 set_hsm_param remove_archive_on_last_unlink 1
2449 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2454 set_hsm_param remove_archive_on_last_unlink 0
2456 wait_request_state $fid2 REMOVE SUCCEED
2458 assert_request_count $fid REMOVE 0 \
2459 "Unexpected archived data remove request for $f"
2460 assert_request_count $fid3 REMOVE 0 \
2461 "Unexpected archived data remove request for $f3"
2465 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2467 cleanup_test_26b() {
2469 set_hsm_param remove_archive_on_last_unlink 0
2475 # test needs a running copytool
2479 local f=$DIR/$tdir/$tfile
2480 local fid=$(copy_file /etc/passwd $f)
2482 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2483 wait_request_state $fid ARCHIVE SUCCEED
2485 trap cleanup_test_26b EXIT
2487 set_hsm_param remove_archive_on_last_unlink 1
2490 cdt_check_state stopped
2494 set_hsm_param remove_archive_on_last_unlink 0
2496 wait_request_state $fid REMOVE WAITING
2499 # copytool must re-register
2501 wait_copytools || error "copytool failed to stop"
2502 HSM_ARCHIVE_PURGE=false copytool_setup
2504 wait_request_state $fid REMOVE SUCCEED
2508 run_test 26b "RAoLU policy when CDT off"
2510 cleanup_test_26c() {
2512 set_hsm_param remove_archive_on_last_unlink 0
2513 set_hsm_param loop_period $orig_loop_period
2514 set_hsm_param grace_delay $orig_grace_delay
2520 # test needs a running copytool
2524 local f=$DIR/$tdir/$tfile
2525 local fid=$(copy_file /etc/passwd $f)
2527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2528 wait_request_state $fid ARCHIVE SUCCEED
2530 local f2=$DIR/$tdir/${tfile}_2
2531 local fid2=$(copy_file /etc/passwd $f2)
2533 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2534 wait_request_state $fid2 ARCHIVE SUCCEED
2536 trap cleanup_test_26c EXIT
2538 # set a long grace_delay vs short loop_period
2539 local orig_loop_period=$(get_hsm_param loop_period)
2540 local orig_grace_delay=$(get_hsm_param grace_delay)
2541 set_hsm_param loop_period 10
2542 set_hsm_param grace_delay 100
2544 set_hsm_param remove_archive_on_last_unlink 1
2546 multiop_bg_pause $f O_c || error "open $f failed"
2552 wait_request_state $fid2 REMOVE SUCCEED
2553 assert_request_count $fid REMOVE 0 \
2554 "Unexpected archived data remove request for $f"
2556 kill -USR1 $pid || error "multiop early exit"
2557 # should reach autotest timeout if multiop fails to trap
2558 # signal, close file, and exit ...
2561 set_hsm_param remove_archive_on_last_unlink 0
2563 wait_request_state $fid REMOVE SUCCEED
2567 run_test 26c "RAoLU effective when file closed"
2569 cleanup_test_26d() {
2571 set_hsm_param remove_archive_on_last_unlink 0
2572 set_hsm_param loop_period $orig_loop_period
2573 set_hsm_param grace_delay $orig_grace_delay
2579 # test needs a running copytool
2583 local f=$DIR/$tdir/$tfile
2584 local fid=$(copy_file /etc/motd $f 1)
2586 $LFS hsm_archive $f || error "could not archive file"
2587 wait_request_state $fid ARCHIVE SUCCEED
2589 trap cleanup_test_26d EXIT
2591 # set a long grace_delay vs short loop_period
2592 local orig_loop_period=$(get_hsm_param loop_period)
2593 local orig_grace_delay=$(get_hsm_param grace_delay)
2594 set_hsm_param loop_period 10
2595 set_hsm_param grace_delay 100
2597 set_hsm_param remove_archive_on_last_unlink 1
2599 multiop_bg_pause $f O_c || error "multiop failed"
2606 set_hsm_param remove_archive_on_last_unlink 0
2608 wait_request_state $fid REMOVE SUCCEED
2610 client_up || client_up || true
2612 kill -USR1 $MULTIPID
2613 wait $MULTIPID || error "multiop close failed"
2617 run_test 26d "RAoLU when Client eviction"
2620 # test needs a running copytool
2623 create_archive_file $tdir/$tfile
2624 local f=$DIR/$tdir/$tfile
2625 import_file $tdir/$tfile $f
2626 local fid=$(path2fid $f)
2630 [[ $? != 0 ]] || error "Remove of a released file should fail"
2634 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2637 # test needs a running copytool
2640 local f=$DIR/$tdir/$tfile
2642 fid=$(make_custom_file_for_progress $f 39 1000000)
2643 [ $? != 0 ] && skip "not enough free space" && return
2645 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2646 wait_request_state $fid ARCHIVE SUCCEED
2651 [[ $? != 0 ]] || error "Remove of a released file should fail"
2655 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2658 # test needs a running copytool
2661 local f=$DIR/$tdir/$tfile
2663 fid=$(make_custom_file_for_progress $f 39 1000000)
2664 [ $? != 0 ] && skip "not enough free space" && return
2666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2667 wait_request_state $fid ARCHIVE SUCCEED
2676 wait_request_state $fid REMOVE SUCCEED
2680 run_test 28 "Concurrent archive/file remove"
2683 # Tests --mntpath and --archive options
2686 copytool_setup $SINGLEAGT $MOUNT $archive_id
2688 # Bad archive number
2689 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2690 grep "Invalid argument" ||
2691 error "unexpected hsm_remove failure (1)"
2693 # mntpath is present but file is given
2694 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2695 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2696 error "unexpected hsm_remove failure (2)"
2700 run_test 29a "Tests --mntpath and --archive options"
2703 # test needs a running copytool
2706 local f=$DIR/$tdir/$tfile
2707 local fid=$(create_small_file $f)
2709 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2710 wait_request_state $fid ARCHIVE SUCCEED
2714 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2715 wait_request_state $fid REMOVE SUCCEED
2719 run_test 29b "Archive/delete/remove by FID from the archive."
2722 # test needs a running copytool
2725 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2726 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2727 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2729 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2730 wait_request_state $fid1 ARCHIVE SUCCEED
2731 wait_request_state $fid2 ARCHIVE SUCCEED
2732 wait_request_state $fid3 ARCHIVE SUCCEED
2734 rm -f $DIR/$tdir/$tfile-[1-3]
2736 echo $fid1 > $DIR/$tdir/list
2737 echo $fid2 >> $DIR/$tdir/list
2738 echo $fid3 >> $DIR/$tdir/list
2740 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2741 --filelist $DIR/$tdir/list
2742 wait_request_state $fid1 REMOVE SUCCEED
2743 wait_request_state $fid2 REMOVE SUCCEED
2744 wait_request_state $fid3 REMOVE SUCCEED
2748 run_test 29c "Archive/delete/remove by FID, using a file list."
2751 # test needs more than one CT
2752 needclients 3 || return 0
2758 copytool_cleanup $(comma_list $(agts_nodes))
2760 # start all of the copytools
2761 for n in $(seq $AGTCOUNT); do
2762 copytool_setup agt$n $MOUNT2 $n
2765 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2767 file=$DIR/$tdir/$tfile
2768 fid=$(create_small_file $file)
2770 $LFS hsm_archive $file
2771 wait_request_state $fid ARCHIVE SUCCEED
2772 check_hsm_flags $file "0x00000009"
2776 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2777 error "cannot hsm_remove '$fid'"
2779 # give time for CDT to handle remove request and create broadcasted
2782 # remove request has been broadcasted ?
2783 local cnt=$(get_request_count $fid REMOVE)
2784 # broadcasted requests + original
2785 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2786 error "remove not broadcasted to all CTs"
2788 # give time for CDT and CTs to handle broadcasted
2789 wait_for_loop_period
2791 # each agent serves one different archive_id, so broadcasted
2792 # hsm_remove request should only succeed once and fail at all others
2796 for n in $(seq $AGTCOUNT); do
2797 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2798 $HSM_PARAM.actions | awk \
2799 '/'$fid'.*action=REMOVE archive#='$n'/ \
2800 {print \\\$13}' | cut -f2 -d=")
2801 if [[ "$res" == "SUCCEED" ]]; then
2803 elif [[ "$res" == "FAILED" ]]; then
2808 [[ $scnt -ne 1 ]] &&
2809 error "one and only CT should have removed successfully"
2811 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2812 error "all but one CT should have failed to remove"
2815 copytool_cleanup $(comma_list $(agts_nodes))
2818 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2819 "request to be sent once for each registered archive_id"
2822 # restore at exec cannot work on agent node (because of Linux kernel
2823 # protection of executables)
2824 needclients 2 || return 0
2826 # test needs a running copytool
2830 copy2archive /bin/true $tdir/$tfile
2832 local f=$DIR/$tdir/true
2833 import_file $tdir/$tfile $f
2835 local fid=$(path2fid $f)
2837 # set no retry action mode
2843 # remove no try action mode
2847 [[ $st == 0 ]] || error "Failed to exec a released file"
2851 run_test 30a "Restore at exec (import case)"
2854 # restore at exec cannot work on agent node (because of Linux kernel
2855 # protection of executables)
2856 needclients 2 || return 0
2858 # test needs a running copytool
2862 local f=$DIR/$tdir/true
2863 local fid=$(copy_file /bin/true $f)
2865 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2866 wait_request_state $fid ARCHIVE SUCCEED
2869 # set no retry action mode
2875 # remove no try action mode
2879 [[ $st == 0 ]] || error "Failed to exec a released file"
2883 run_test 30b "Restore at exec (release case)"
2886 needclients 2 || return 0
2888 # test needs a running copytool
2892 local f=$DIR/$tdir/SLEEP
2893 local slp_sum1=$(md5sum /bin/sleep)
2894 local fid=$(copy_file /bin/sleep $f)
2896 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2897 wait_request_state $fid ARCHIVE SUCCEED
2899 check_hsm_flags $f "0x0000000d"
2900 # set no retry action mode
2902 do_node $CLIENT2 "$f 10" &
2906 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2908 [[ $? == 0 ]] || error "Execution failed during run"
2910 if [[ $? != 0 ]]; then
2911 local slp_sum2=$(md5sum /bin/sleep)
2912 # in case sleep file is modified during the test
2913 [[ $slp_sum1 == $slp_sum2 ]] &&
2914 error "Binary overwritten during exec"
2918 # remove no try action mode
2920 check_hsm_flags $f "0x00000009"
2924 run_test 30c "Update during exec of released file must fail"
2926 restore_and_check_size() {
2929 local s=$(stat -c "%s" $f)
2931 local st=$(get_hsm_flags $f)
2935 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2937 n=$(stat -c "%s" $f)
2938 # we echo in both cases to show stat is not hang
2939 if [[ $n != $s ]]; then
2940 echo "size seen is $n != $s"
2943 echo "size seen is right: $n == $s"
2947 st=$(get_hsm_flags $f)
2949 if [[ "$st" = "0x00000009" ]]; then
2952 echo " restore is too long"
2953 wait_request_state $fid RESTORE SUCCEED
2959 # test needs a running copytool
2962 create_archive_file $tdir/$tfile
2963 local f=$DIR/$tdir/$tfile
2964 import_file $tdir/$tfile $f
2965 local fid=$($LFS path2fid $f)
2966 HSM_ARCHIVE_PURGE=false copytool_setup
2968 restore_and_check_size $f $fid
2971 [[ $err -eq 0 ]] || error "File size changed during restore"
2975 run_test 31a "Import a large file and check size during restore"
2979 # test needs a running copytool
2982 local f=$DIR/$tdir/$tfile
2984 fid=$(make_custom_file_for_progress $f 39 1000000)
2985 [ $? != 0 ] && skip "not enough free space" && return
2987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2988 wait_request_state $fid ARCHIVE SUCCEED
2991 restore_and_check_size $f $fid
2994 [[ $err -eq 0 ]] || error "File size changed during restore"
2998 run_test 31b "Restore a large unaligned file and check size during restore"
3001 # test needs a running copytool
3004 local f=$DIR/$tdir/$tfile
3006 fid=$(make_custom_file_for_progress $f 33 1048576)
3007 [ $? != 0 ] && skip "not enough free space" && return
3009 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3010 wait_request_state $fid ARCHIVE SUCCEED
3013 restore_and_check_size $f $fid
3016 [[ $err -eq 0 ]] || error "File size changed during restore"
3020 run_test 31c "Restore a large aligned file and check size during restore"
3023 # test needs a running copytool
3026 local f=$DIR/$tdir/$tfile
3028 fid=$(make_custom_file_for_progress $f 39 1000000)
3029 [ $? != 0 ] && skip "not enough free space" && return
3031 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3032 wait_request_state $fid ARCHIVE SUCCEED
3035 # to be sure wait_all_done will not be mislead by previous tests
3038 wait_for_grace_delay
3039 # Also raise grace_delay significantly so the Canceled
3040 # Restore action will stay enough long avail.
3041 local old_grace=$(get_hsm_param grace_delay)
3042 set_hsm_param grace_delay 100
3044 md5sum $f >/dev/null &
3046 wait_request_state $fid RESTORE STARTED
3051 # Check restore trigger process was killed
3052 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3056 # instead of waiting+checking both Restore and Cancel ops
3057 # sequentially, wait for both to be finished and then check
3059 wait_all_done 100 $fid
3060 local rstate=$(get_request_state $fid RESTORE)
3061 local cstate=$(get_request_state $fid CANCEL)
3063 # restore orig grace_delay.
3064 set_hsm_param grace_delay $old_grace
3066 if [[ "$rstate" == "CANCELED" ]] ; then
3067 [[ "$cstate" == "SUCCEED" ]] ||
3068 error "Restore state is CANCELED and Cancel state " \
3069 "is not SUCCEED but $cstate"
3070 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3071 elif [[ "$rstate" == "SUCCEED" ]] ; then
3072 [[ "$cstate" == "FAILED" ]] ||
3073 error "Restore state is SUCCEED and Cancel state " \
3074 "is not FAILED but $cstate"
3075 echo "Restore state is SUCCEED, Cancel state is FAILED"
3077 error "Restore state is $rstate and Cancel state is $cstate"
3081 error "Cannot kill process waiting for restore ($killed)"
3085 run_test 33 "Kill a restore waiting process"
3088 # test needs a running copytool
3091 local f=$DIR/$tdir/$tfile
3093 fid=$(make_custom_file_for_progress $f 39 1000000)
3094 [ $? != 0 ] && skip "not enough free space" && return
3096 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3097 wait_request_state $fid ARCHIVE SUCCEED
3100 md5sum $f >/dev/null &
3102 wait_request_state $fid RESTORE STARTED
3104 rm $f || error "rm $f failed"
3105 # rm must not block during restore
3106 wait_request_state $fid RESTORE STARTED
3108 wait_request_state $fid RESTORE SUCCEED
3109 # check md5sum pgm finished
3110 local there=$(ps -o pid,comm hp $pid >/dev/null)
3111 [[ -z $there ]] || error "Restore initiator does not exit"
3113 wait $pid || error "Restore initiator failed with $?"
3117 run_test 34 "Remove file during restore"
3120 # test needs a running copytool
3123 local f=$DIR/$tdir/$tfile
3124 local f1=$DIR/$tdir/$tfile-1
3126 fid=$(make_custom_file_for_progress $f 39 1000000)
3127 [ $? != 0 ] && skip "not enough free space" && return
3129 local fid1=$(copy_file /etc/passwd $f1)
3130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3131 wait_request_state $fid ARCHIVE SUCCEED
3134 md5sum $f >/dev/null &
3136 wait_request_state $fid RESTORE STARTED
3138 mv $f1 $f || error "mv $f1 $f failed"
3139 # mv must not block during restore
3140 wait_request_state $fid RESTORE STARTED
3142 wait_request_state $fid RESTORE SUCCEED
3143 # check md5sum pgm finished
3144 local there=$(ps -o pid,comm hp $pid >/dev/null)
3145 [[ -z $there ]] || error "Restore initiator does not exit"
3147 wait $pid || error "Restore initiator failed with $?"
3150 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3154 run_test 35 "Overwrite file during restore"
3157 # test needs a running copytool
3160 local f=$DIR/$tdir/$tfile
3162 fid=$(make_custom_file_for_progress $f 39 1000000)
3163 [ $? != 0 ] && skip "not enough free space" && return
3165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3166 wait_request_state $fid ARCHIVE SUCCEED
3169 md5sum $f >/dev/null &
3171 wait_request_state $fid RESTORE STARTED
3174 # rm must not block during restore
3175 wait_request_state $fid RESTORE STARTED
3177 wait_request_state $fid RESTORE SUCCEED
3178 # check md5sum pgm finished
3179 local there=$(ps -o pid,comm hp $pid >/dev/null)
3181 error "Restore initiator does not exit"
3183 wait $pid || error "Restore initiator failed with $?"
3187 run_test 36 "Move file during restore"
3190 # LU-5683: check that an archived dirty file can be rearchived.
3192 copytool_setup $SINGLEAGT $MOUNT2
3194 local f=$DIR/$tdir/$tfile
3197 fid=$(create_small_file $f) || error "cannot create small file"
3199 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3200 wait_request_state $fid ARCHIVE SUCCEED
3201 $LFS hsm_release $f || error "cannot release $f"
3203 # Allow previous archive request to expire from the actions log.
3204 wait_for_grace_delay
3207 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3210 wait_request_state $fid ARCHIVE SUCCEED
3214 run_test 37 "re-archive a dirty file"
3221 for n in $(seq 1 $count); do
3222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3224 echo "$count archive requests submitted"
3229 set_hsm_param max_requests $max_requests
3234 local stream_count=4
3235 local file_count=100
3237 local f=$DIR/$tdir/$tfile
3241 local max_requests=$(get_hsm_param max_requests)
3243 # Increase the number of HSM request that can be performed in
3244 # parallel. With the coordinator running once per second, this
3245 # also limits the number of requests per seconds that can be
3246 # performed, so we pick a decent number. But we also need to keep
3247 # that number low because the copytool has no rate limit and will
3248 # fail some requests if if gets too many at once.
3249 set_hsm_param max_requests 300
3251 trap cleanup_test_40 EXIT
3253 for i in $(seq 1 $file_count); do
3254 for p in $(seq 1 $stream_count); do
3255 fid=$(copy_file /etc/hosts $f.$p.$i)
3258 # force copytool to use a local/temp archive dir to ensure best
3259 # performance vs remote/NFS mounts used in auto-tests
3260 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3263 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3265 # to be sure wait_all_done will not be mislead by previous tests
3267 wait_for_grace_delay
3269 # start archive streams in background (archive files in parallel)
3270 for p in $(seq 1 $stream_count); do
3271 multi_archive $f.$p $file_count &
3274 echo -n "Wait for all requests being enqueued..."
3281 run_test 40 "Parallel archive requests"
3284 # test needs a running copytool
3288 local f=$DIR/$tdir/$tfile
3289 local fid=$(copy_file /etc/motd $f 1)
3291 $LFS hsm_archive $f || error "could not archive file"
3292 wait_request_state $fid ARCHIVE SUCCEED
3293 check_hsm_flags $f "0x00000009"
3295 multiop_bg_pause $f O_c || error "multiop failed"
3299 client_up || client_up || true
3301 kill -USR1 $MULTIPID
3302 wait $MULTIPID || error "multiop close failed"
3304 check_hsm_flags $f "0x0000000b"
3308 run_test 52 "Opened for write file on an evicted client should be set dirty"
3311 # test needs a running copytool
3315 local f=$DIR/$tdir/$tfile
3316 local fid=$(copy_file /etc/motd $f 1)
3318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3319 error "could not archive file"
3320 wait_request_state $fid ARCHIVE SUCCEED
3321 check_hsm_flags $f "0x00000009"
3323 multiop_bg_pause $f o_c || error "multiop failed"
3327 client_up || client_up || true
3329 kill -USR1 $MULTIPID
3330 wait $MULTIPID || error "multiop close failed"
3332 check_hsm_flags $f "0x00000009"
3336 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3339 # test needs a running copytool
3342 local f=$DIR/$tdir/$tfile
3343 local fid=$(make_custom_file_for_progress $f 39 1000000)
3345 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3346 error "could not archive file"
3347 wait_request_state $fid ARCHIVE STARTED
3349 check_hsm_flags $f "0x00000001"
3351 # Avoid coordinator resending this request as soon it has failed.
3356 wait_request_state $fid ARCHIVE FAILED
3358 check_hsm_flags $f "0x00000003"
3363 run_test 54 "Write during an archive cancels it"
3366 # test needs a running copytool
3369 local f=$DIR/$tdir/$tfile
3370 local fid=$(make_custom_file_for_progress $f 39 1000000)
3372 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3373 error "could not archive file"
3374 wait_request_state $fid ARCHIVE STARTED
3376 check_hsm_flags $f "0x00000001"
3378 # Avoid coordinator resending this request as soon it has failed.
3381 $TRUNCATE $f 1024 || error "truncate failed"
3383 wait_request_state $fid ARCHIVE FAILED
3385 check_hsm_flags $f "0x00000003"
3390 run_test 55 "Truncate during an archive cancels it"
3393 # test needs a running copytool
3396 local f=$DIR/$tdir/$tfile
3398 fid=$(make_custom_file_for_progress $f 39 1000000)
3399 [ $? != 0 ] && skip "not enough free space" && return
3401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3402 error "could not archive file"
3403 wait_request_state $fid ARCHIVE STARTED
3405 check_hsm_flags $f "0x00000001"
3407 # Change metadata and sync to be sure we are not changing only
3412 wait_request_state $fid ARCHIVE SUCCEED
3414 check_hsm_flags $f "0x00000009"
3418 run_test 56 "Setattr during an archive is ok"
3421 # Need one client for I/O, one for request
3422 needclients 2 || return 0
3424 # test needs a running copytool
3428 local f=$DIR/$tdir/test_archive_remote
3429 # Create a file on a remote node
3430 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3431 "count=2 conv=fsync"
3434 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3435 error "hsm_archive failed"
3436 local fid=$(path2fid $f)
3437 wait_request_state $fid ARCHIVE SUCCEED
3439 # Release and implicit restore it
3440 do_node $CLIENT2 "$LFS hsm_release $f" ||
3441 error "hsm_release failed"
3442 do_node $CLIENT2 "md5sum $f" ||
3443 error "hsm_restore failed"
3445 wait_request_state $fid RESTORE SUCCEED
3449 run_test 57 "Archive a file with dirty cache on another node"
3451 truncate_released_file() {
3455 local sz=$(stat -c %s $src_file)
3456 local f=$DIR/$tdir/$tfile
3457 local fid=$(copy_file $1 $f)
3461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3462 error "could not archive file"
3463 wait_request_state $fid ARCHIVE SUCCEED
3465 $LFS hsm_release $f || error "could not release file"
3467 $TRUNCATE $f $trunc_to || error "truncate failed"
3470 local sz1=$(stat -c %s $f)
3471 [[ $sz1 == $trunc_to ]] ||
3472 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3475 check_hsm_flags $f "0x0000000b"
3477 local state=$(get_request_state $fid RESTORE)
3478 [[ "$state" == "SUCCEED" ]] ||
3479 error "truncate $sz does not trig restore, state = $state"
3481 $TRUNCATE $ref $trunc_to
3482 cmp $ref $f || error "file data wrong after truncate"
3488 # test needs a running copytool
3493 local sz=$(stat -c %s /etc/passwd)
3495 echo "truncate up from $sz to $((sz*2))"
3496 truncate_released_file /etc/passwd $((sz*2))
3498 echo "truncate down from $sz to $((sz/2))"
3499 truncate_released_file /etc/passwd $((sz/2))
3501 echo "truncate to 0"
3502 truncate_released_file /etc/passwd 0
3506 run_test 58 "Truncate a released file will trigger restore"
3510 local server_version=$(lustre_version_code $SINGLEMDS)
3511 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3512 skip "Need MDS version at least 2.7.63" && return
3515 $MCREATE $DIR/$tfile || error "mcreate failed"
3516 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3517 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3518 fid=$(path2fid $DIR/$tfile)
3519 wait_request_state $fid ARCHIVE SUCCEED
3520 $LFS hsm_release $DIR/$tfile || error "release failed"
3523 run_test 59 "Release stripeless file with non-zero size"
3526 # This test validates the fix for LU-4512. Ensure that the -u
3527 # option changes the progress reporting interval from the
3528 # default (30 seconds) to the user-specified interval.
3530 local progress_timeout=$((interval * 4))
3532 # test needs a new running copytool
3534 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3536 local f=$DIR/$tdir/$tfile
3538 fid=$(make_custom_file_for_progress $f 10)
3539 [ $? != 0 ] && skip "not enough free space" && return
3542 local mdt=${MDT_PREFIX}${mdtidx}
3543 local mds=mds$((mdtidx + 1))
3545 # Wait for copytool to register
3546 wait_update_facet $mds \
3547 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3548 uuid 100 || error "coyptool failed to register with $mdt"
3550 local start_at=$(date +%s)
3551 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3552 error "could not archive file"
3554 local agent=$(facet_active_host $SINGLEAGT)
3555 local prefix=$TESTLOG_PREFIX
3556 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3557 local copytool_log=$prefix.copytool_log.$agent.log
3560 wait_update $agent \
3561 "grep -o start.copy $copytool_log" "start copy" 100 ||
3562 error "copytool failed to start"
3564 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3565 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3571 echo -n "Expecting a progress update within $progress_timeout seconds... "
3573 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3574 if [ $RESULT -gt 0 ]; then
3575 echo "$RESULT bytes copied in $WAIT seconds."
3577 elif [ $WAIT -ge $progress_timeout ]; then
3578 error "Timed out waiting for progress update!"
3581 WAIT=$((WAIT + sleep))
3585 local finish_at=$(date +%s)
3586 local elapsed=$((finish_at - start_at))
3588 # Ensure that the progress update occurred within the expected window.
3589 if [ $elapsed -lt $((interval - 1)) ]; then
3590 error "Expected progress update after at least $interval seconds"
3593 echo "Wait for on going archive hsm action to complete"
3594 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3595 echo "File archiving not completed even after 10 secs"
3600 run_test 60 "Changing progress update interval from default"
3603 # test needs a running copytool
3607 local f=$DIR/$tdir/$tfile
3608 local fid=$(copy_file /etc/passwd $f)
3610 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3613 wait_request_state $fid ARCHIVE FAILED
3617 run_test 61 "Waiting archive of a removed file should fail"
3620 # test needs a new running copytool
3622 copytool_monitor_setup
3623 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3625 # Just start and stop the copytool to generate events.
3628 # Wait for the copytool to register.
3629 wait_update --verbose $(facet_active_host mds1) \
3630 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3632 error "copytool failed to register with MDT0000"
3636 local REGISTER_EVENT
3637 local UNREGISTER_EVENT
3638 while read event; do
3639 local parsed=$(parse_json_event "$event")
3640 if [ -z "$parsed" ]; then
3641 error "Copytool sent malformed event: $event"
3645 if [ $event_type == "REGISTER" ]; then
3646 REGISTER_EVENT=$event
3647 elif [ $event_type == "UNREGISTER" ]; then
3648 UNREGISTER_EVENT=$event
3650 done < <(echo $"$(get_copytool_event_log)")
3652 if [ -z "$REGISTER_EVENT" ]; then
3653 error "Copytool failed to send register event to FIFO"
3656 if [ -z "$UNREGISTER_EVENT" ]; then
3657 error "Copytool failed to send unregister event to FIFO"
3660 copytool_monitor_cleanup
3661 echo "Register/Unregister events look OK."
3663 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3666 # Bump progress interval for livelier events.
3669 # test needs a new running copytool
3671 copytool_monitor_setup
3672 HSMTOOL_UPDATE_INTERVAL=$interval \
3673 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3675 local f=$DIR/$tdir/$tfile
3677 fid=$(make_custom_file_for_progress $f 39 1000000)
3678 [ $? != 0 ] && skip "not enough free space" && return
3680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3681 error "could not archive file"
3682 wait_request_state $fid ARCHIVE SUCCEED
3684 local expected_fields="event_time data_fid source_fid"
3685 expected_fields+=" total_bytes current_bytes"
3689 while read event; do
3690 # Make sure we're not getting anything from previous events.
3691 for field in $expected_fields; do
3695 local parsed=$(parse_json_event "$event")
3696 if [ -z "$parsed" ]; then
3697 error "Copytool sent malformed event: $event"
3701 if [ $event_type == "ARCHIVE_START" ]; then
3704 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3707 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3711 # Do some simple checking of the progress update events.
3712 for expected_field in $expected_fields; do
3713 if [ -z ${!expected_field+x} ]; then
3714 error "Missing $expected_field field in event"
3718 if [ $total_bytes -eq 0 ]; then
3719 error "Expected total_bytes to be > 0"
3722 # These should be identical throughout an archive
3724 if [ $source_fid != $data_fid ]; then
3725 error "Expected source_fid to equal data_fid"
3727 done < <(echo $"$(get_copytool_event_log)")
3729 if [ -z "$START_EVENT" ]; then
3730 error "Copytool failed to send archive start event to FIFO"
3733 if [ -z "$FINISH_EVENT" ]; then
3734 error "Copytool failed to send archive finish event to FIFO"
3737 echo "Archive events look OK."
3741 copytool_monitor_cleanup
3743 run_test 71 "Copytool logs JSON archive events to FIFO"
3746 # Bump progress interval for livelier events.
3749 # test needs a new running copytool
3751 copytool_monitor_setup
3752 HSMTOOL_UPDATE_INTERVAL=$interval \
3753 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3754 local test_file=$HSMTOOL_MONITOR_DIR/file
3756 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3758 do_facet $SINGLEAGT "$cmd" ||
3759 error "cannot create $test_file on $SINGLEAGT"
3760 copy2archive $test_file $tdir/$tfile
3763 local f=$DIR/$tdir/$tfile
3764 import_file $tdir/$tfile $f
3765 f=$DIR2/$tdir/$tfile
3766 echo "Verifying released state: "
3767 check_hsm_flags $f "0x0000000d"
3769 local fid=$(path2fid $f)
3771 wait_request_state $fid RESTORE SUCCEED
3773 local expected_fields="event_time data_fid source_fid"
3774 expected_fields+=" total_bytes current_bytes"
3778 while read event; do
3779 # Make sure we're not getting anything from previous events.
3780 for field in $expected_fields; do
3784 local parsed=$(parse_json_event "$event")
3785 if [ -z "$parsed" ]; then
3786 error "Copytool sent malformed event: $event"
3790 if [ $event_type == "RESTORE_START" ]; then
3792 if [ $source_fid != $data_fid ]; then
3793 error "source_fid should == data_fid at start"
3796 elif [ $event_type == "RESTORE_FINISH" ]; then
3798 if [ $source_fid != $data_fid ]; then
3799 error "source_fid should == data_fid at finish"
3802 elif [ $event_type != "RESTORE_RUNNING" ]; then
3806 # Do some simple checking of the progress update events.
3807 for expected_field in $expected_fields; do
3808 if [ -z ${!expected_field+x} ]; then
3809 error "Missing $expected_field field in event"
3813 if [ $total_bytes -eq 0 ]; then
3814 error "Expected total_bytes to be > 0"
3817 # When a restore starts out, the data fid is the same as the
3818 # source fid. After the restore has gotten going, we learn
3819 # the new data fid. Once the restore has finished, the source
3820 # fid is set to the new data fid.
3822 # We test this because some monitoring software may depend on
3823 # this behavior. If it changes, then the consumers of these
3824 # events may need to be modified.
3825 if [ $source_fid == $data_fid ]; then
3826 error "source_fid should != data_fid during restore"
3828 done < <(echo $"$(get_copytool_event_log)")
3830 if [ -z "$START_EVENT" ]; then
3831 error "Copytool failed to send restore start event to FIFO"
3834 if [ -z "$FINISH_EVENT" ]; then
3835 error "Copytool failed to send restore finish event to FIFO"
3838 echo "Restore events look OK."
3842 copytool_monitor_cleanup
3846 run_test 72 "Copytool logs JSON restore events to FIFO"
3849 file_count=51 # Max number of files constrained by LNET message size
3850 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3851 local f=$DIR/$tdir/$tfile
3852 local FILELIST=/tmp/filelist.txt
3856 for i in $(seq 1 $file_count); do
3857 fid=$(copy_file /etc/hosts $f.$i)
3858 echo $f.$i >> $FILELIST
3860 # force copytool to use a local/temp archive dir to ensure best
3861 # performance vs remote/NFS mounts used in auto-tests
3862 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3865 local dai=$(get_hsm_param default_archive_id)
3866 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3868 # to be sure wait_all_done will not be mislead by previous tests
3870 wait_for_grace_delay
3871 $LFS hsm_archive --filelist $FILELIST ||
3872 error "cannot archive a file list"
3874 $LFS hsm_release --filelist $FILELIST ||
3875 error "cannot release a file list"
3876 $LFS hsm_restore --filelist $FILELIST ||
3877 error "cannot restore a file list"
3881 run_test 90 "Archive/restore a file list"
3883 double_verify_reset_hsm_param() {
3885 echo "Testing $HSM_PARAM.$p"
3886 local val=$(get_hsm_param $p)
3888 local val2=$(($val * 2))
3889 set_hsm_param $p $val2
3890 val=$(get_hsm_param $p)
3891 [[ $val == $val2 ]] ||
3892 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3893 echo "Set $p to 0 must failed"
3897 set_hsm_param $p $save
3899 if [[ $rc == 0 ]]; then
3900 error "we must not be able to set $HSM_PARAM.$p to 0"
3905 double_verify_reset_hsm_param loop_period
3906 double_verify_reset_hsm_param grace_delay
3907 double_verify_reset_hsm_param active_request_timeout
3908 double_verify_reset_hsm_param max_requests
3909 double_verify_reset_hsm_param default_archive_id
3911 run_test 100 "Set coordinator /proc tunables"
3918 run_test 102 "Verify coordinator control"
3921 # test needs a running copytool
3928 for i in $(seq 1 20); do
3929 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3931 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3935 echo "Current requests"
3936 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3937 $HSM_PARAM.actions |\
3938 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3940 [[ -z "$res" ]] || error "Some request have not been canceled"
3944 run_test 103 "Purge all requests"
3950 local f=$DIR/$tdir/$tfile
3952 fid=$(make_custom_file_for_progress $f 39 1000000)
3953 [ $? != 0 ] && skip "not enough free space" && return
3955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3956 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3957 $HSM_PARAM.actions |\
3958 grep $fid | cut -f16 -d=")
3960 [[ "$data1" == "$DATAHEX" ]] ||
3961 error "Data field in records is ($data1) and not ($DATAHEX)"
3966 wait_request_state $fid ARCHIVE SUCCEED
3970 run_test 104 "Copy tool data field"
3972 cleanup_test_105() {
3974 set_hsm_param max_requests $max_requests
3979 local max_requests=$(get_hsm_param max_requests)
3983 set_hsm_param max_requests 300
3985 trap cleanup_test_105 EXIT
3988 for i in $(seq -w 1 10); do
3989 cp /etc/passwd $DIR/$tdir/$i
3990 $LFS hsm_archive $DIR/$tdir/$i
3992 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3993 $HSM_PARAM.actions |\
3994 grep WAITING | wc -l")
3998 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3999 $HSM_PARAM.actions |\
4000 grep WAITING | wc -l")
4003 [[ "$reqcnt1" == "$reqcnt2" ]] ||
4004 error "Requests count after shutdown $reqcnt2 != "\
4005 "before shutdown $reqcnt1"
4009 run_test 105 "Restart of coordinator"
4012 # test needs a running copytool
4015 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4017 check_agent_registered $uuid
4019 search_copytools || error "No copytool found"
4022 check_agent_unregistered $uuid
4025 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4026 check_agent_registered $uuid
4030 run_test 106 "Copytool register/unregister"
4033 # test needs a running copytool
4035 # create and archive file
4037 local f1=$DIR/$tdir/$tfile
4038 local fid=$(copy_file /etc/passwd $f1)
4039 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4040 wait_request_state $fid ARCHIVE SUCCEED
4041 # shutdown and restart MDS
4043 # check the copytool still gets messages from MDT
4044 local f2=$DIR/$tdir/2
4045 local fid=$(copy_file /etc/passwd $f2)
4046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
4047 # main check of this sanity: this request MUST succeed
4048 wait_request_state $fid ARCHIVE SUCCEED
4051 run_test 107 "Copytool re-register after MDS restart"
4053 policy_set_and_test()
4057 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
4058 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4059 [[ "$policy" == "$target" ]] ||
4060 error "Wrong policy after '$change': '$policy' != '$target'"
4064 # to force default policy setting if error
4065 CDT_POLICY_HAD_CHANGED=true
4067 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4068 local default="NonBlockingRestore [NoRetryAction]"
4069 [[ "$policy" == "$default" ]] ||
4070 error "default policy has changed,"\
4071 " '$policy' != '$default' update the test"
4072 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
4073 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
4074 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
4075 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
4076 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4077 # useless bacause we know but safer for futur changes to use real value
4078 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4079 echo "Next set_param must failed"
4080 policy_set_and_test "wrong" "$policy"
4083 echo "Back to default policy"
4084 cdt_set_sanity_policy
4086 run_test 109 "Policy display/change"
4089 # test needs a running copytool
4094 copy2archive /etc/passwd $tdir/$tfile
4096 local f=$DIR/$tdir/$tfile
4097 import_file $tdir/$tfile $f
4098 local fid=$(path2fid $f)
4100 cdt_set_non_blocking_restore
4105 wait_request_state $fid RESTORE SUCCEED
4106 cdt_clear_non_blocking_restore
4110 error "md5sum returns $st != 1, "\
4111 "should also perror ENODATA (No data available)"
4115 run_test 110a "Non blocking restore policy (import case)"
4118 # test needs a running copytool
4122 local f=$DIR/$tdir/$tfile
4123 local fid=$(copy_file /etc/passwd $f)
4124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4125 wait_request_state $fid ARCHIVE SUCCEED
4128 cdt_set_non_blocking_restore
4133 wait_request_state $fid RESTORE SUCCEED
4134 cdt_clear_non_blocking_restore
4138 error "md5sum returns $st != 1, "\
4139 "should also perror ENODATA (No data available)"
4143 run_test 110b "Non blocking restore policy (release case)"
4146 # test needs a running copytool
4150 copy2archive /etc/passwd $tdir/$tfile
4152 local f=$DIR/$tdir/$tfile
4154 import_file $tdir/$tfile $f
4155 local fid=$(path2fid $f)
4159 copytool_remove_backend $fid
4162 wait_request_state $fid RESTORE FAILED
4169 [[ $st == 0 ]] || error "Restore does not failed"
4173 run_test 111a "No retry policy (import case), restore will error"\
4174 " (No such file or directory)"
4177 # test needs a running copytool
4181 local f=$DIR/$tdir/$tfile
4182 local fid=$(copy_file /etc/passwd $f)
4184 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4185 wait_request_state $fid ARCHIVE SUCCEED
4188 copytool_remove_backend $fid
4191 wait_request_state $fid RESTORE FAILED
4198 [[ $st == 0 ]] || error "Restore does not failed"
4202 run_test 111b "No retry policy (release case), restore will error"\
4203 " (No such file or directory)"
4206 # test needs a running copytool
4210 local f=$DIR/$tdir/$tfile
4211 local fid=$(copy_file /etc/passwd $f)
4213 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4214 local l=$($LFS hsm_action $f)
4216 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4220 wait_request_state $fid ARCHIVE SUCCEED
4223 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4227 run_test 112 "State of recorded request"
4230 # test needs a running copytool
4233 local f=$DIR/$tdir/$tfile
4235 fid=$(make_custom_file_for_progress $f 103 1048576)
4236 [ $? != 0 ] && skip "not enough free space" && return
4238 # test with cdt on is made in test_221
4240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4241 # wait archive to register at CDT
4242 wait_request_state $fid ARCHIVE WAITING
4245 wait_request_state $fid ARCHIVE CANCELED
4246 wait_request_state $fid CANCEL SUCCEED
4250 run_test 200 "Register/Cancel archive"
4253 # test needs a running copytool
4256 local f=$DIR/$tdir/$tfile
4257 create_archive_file $tdir/$tfile
4258 import_file $tdir/$tfile $f
4259 local fid=$(path2fid $f)
4261 # test with cdt on is made in test_222
4264 # wait restore to register at CDT
4265 wait_request_state $fid RESTORE WAITING
4268 wait_request_state $fid RESTORE CANCELED
4269 wait_request_state $fid CANCEL SUCCEED
4273 run_test 201 "Register/Cancel restore"
4276 # test needs a running copytool
4279 local f=$DIR/$tdir/$tfile
4281 fid=$(make_custom_file_for_progress $f 39 1000000)
4282 [ $? != 0 ] && skip "not enough free space" && return
4284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4285 wait_request_state $fid ARCHIVE SUCCEED
4289 # wait remove to register at CDT
4290 wait_request_state $fid REMOVE WAITING
4293 wait_request_state $fid REMOVE CANCELED
4297 run_test 202 "Register/Cancel remove"
4300 # test needs a running copytool
4305 local f=$DIR/$tdir/$tfile
4306 local fid=$(copy_file /etc/passwd $f)
4310 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4311 wait_request_state $fid ARCHIVE SUCCEED
4313 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4317 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4321 run_test 220 "Changelog for archive"
4324 # test needs a running copytool
4329 local f=$DIR/$tdir/$tfile
4330 local fid=$(copy_file /etc/passwd $f)
4334 # block copytool operations to allow for HSM request to be
4335 # submitted and file be unlinked (CDT will find object removed)
4338 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4340 # wait request to reach CT
4341 wait_request_state $fid ARCHIVE STARTED
4347 wait_request_state $fid ARCHIVE FAILED
4349 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4354 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4358 run_test 220a "Changelog for failed archive"
4361 # test needs a running copytool
4364 local f=$DIR/$tdir/$tfile
4366 fid=$(make_custom_file_for_progress $f 103 1048576)
4367 [ $? != 0 ] && skip "not enough free space" && return
4371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4372 wait_request_state $fid ARCHIVE STARTED
4374 wait_request_state $fid ARCHIVE CANCELED
4375 wait_request_state $fid CANCEL SUCCEED
4377 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4380 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4384 run_test 221 "Changelog for archive canceled"
4387 # test needs a running copytool
4391 copy2archive /etc/passwd $tdir/$tfile
4393 local f=$DIR/$tdir/$tfile
4394 import_file $tdir/$tfile $f
4395 local fid=$(path2fid $f)
4400 wait_request_state $fid RESTORE SUCCEED
4402 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4405 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4409 run_test 222a "Changelog for explicit restore"
4412 # test needs a running copytool
4416 local f=$DIR/$tdir/$tfile
4417 local fid=$(copy_file /etc/passwd $f)
4420 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4421 wait_request_state $fid ARCHIVE SUCCEED
4426 wait_request_state $fid RESTORE SUCCEED
4428 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4431 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4435 run_test 222b "Changelog for implicit restore"
4438 # test needs a running copytool
4442 copy2archive /etc/passwd $tdir/$tfile
4444 local f=$DIR/$tdir/$tfile
4445 import_file $tdir/$tfile $f
4446 local fid=$(path2fid $f)
4450 # block copytool operations to allow for HSM request to be
4451 # submitted and file be unlinked (CDT will find object removed)
4456 # wait request to reach CT
4457 wait_request_state $fid RESTORE STARTED
4463 wait_request_state $fid RESTORE FAILED
4465 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4469 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4473 run_test 222c "Changelog for failed explicit restore"
4476 # test needs a running copytool
4480 local f=$DIR/$tdir/$tfile
4481 local fid=$(copy_file /etc/passwd $f)
4484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4485 wait_request_state $fid ARCHIVE SUCCEED
4488 copytool_remove_backend $fid
4491 wait_request_state $fid RESTORE FAILED
4493 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4497 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4501 run_test 222d "Changelog for failed implicit restore"
4504 # test needs a running copytool
4507 local f=$DIR/$tdir/$tfile
4508 create_archive_file $tdir/$tfile
4512 import_file $tdir/$tfile $f
4513 local fid=$(path2fid $f)
4516 wait_request_state $fid RESTORE STARTED
4518 wait_request_state $fid RESTORE CANCELED
4519 wait_request_state $fid CANCEL SUCCEED
4521 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4524 [[ $flags == $target ]] ||
4525 error "Changelog flag is $flags not $target"
4529 run_test 223a "Changelog for restore canceled (import case)"
4532 # test needs a running copytool
4535 local f=$DIR/$tdir/$tfile
4537 fid=$(make_custom_file_for_progress $f 39 1000000)
4538 [ $? != 0 ] && skip "not enough free space" && return
4541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4542 wait_request_state $fid ARCHIVE SUCCEED
4545 wait_request_state $fid RESTORE STARTED
4547 wait_request_state $fid RESTORE CANCELED
4548 wait_request_state $fid CANCEL SUCCEED
4550 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4553 [[ $flags == $target ]] ||
4554 error "Changelog flag is $flags not $target"
4558 run_test 223b "Changelog for restore canceled (release case)"
4561 # test needs a running copytool
4566 local f=$DIR/$tdir/$tfile
4567 local fid=$(copy_file /etc/passwd $f)
4570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4571 wait_request_state $fid ARCHIVE SUCCEED
4574 wait_request_state $fid REMOVE SUCCEED
4576 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4579 [[ $flags == $target ]] ||
4580 error "Changelog flag is $flags not $target"
4584 run_test 224 "Changelog for remove"
4587 # test needs a running copytool
4592 local f=$DIR/$tdir/$tfile
4593 local fid=$(copy_file /etc/passwd $f)
4596 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4597 wait_request_state $fid ARCHIVE SUCCEED
4599 copytool_remove_backend $fid
4601 # block copytool operations to allow for HSM request to be
4602 # submitted and file be unlinked (CDT will find object removed)
4607 # wait for request to reach CT
4608 wait_request_state $fid REMOVE STARTED
4614 wait_request_state $fid REMOVE FAILED
4616 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4620 [[ $flags == $target ]] ||
4621 error "Changelog flag is $flags not $target"
4625 run_test 224a "Changelog for failed remove"
4628 # test needs a running copytool
4631 # test is not usable because remove request is too fast
4632 # so it is always finished before cancel can be done ...
4633 echo "Test disabled"
4637 local f=$DIR/$tdir/$tfile
4639 fid=$(make_custom_file_for_progress $f 39 1000000)
4640 [ $? != 0 ] && skip "not enough free space" && return
4643 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4644 wait_request_state $fid ARCHIVE SUCCEED
4646 # if cdt is on, it can serve too quickly the request
4651 wait_request_state $fid REMOVE CANCELED
4652 wait_request_state $fid CANCEL SUCCEED
4654 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4655 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4656 tail -n 1 | awk '{print $5}')
4659 [[ $flags == $target ]] ||
4660 error "Changelog flag is $flags not $target"
4664 run_test 225 "Changelog for remove canceled"
4667 # test needs a running copytool
4672 local f1=$DIR/$tdir/$tfile-1
4673 local f2=$DIR/$tdir/$tfile-2
4674 local f3=$DIR/$tdir/$tfile-3
4675 local fid1=$(copy_file /etc/passwd $f1)
4676 local fid2=$(copy_file /etc/passwd $f2)
4677 copy_file /etc/passwd $f3
4680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4681 wait_request_state $fid1 ARCHIVE SUCCEED
4683 $LFS hsm_archive $f2
4684 wait_request_state $fid2 ARCHIVE SUCCEED
4686 rm $f1 || error "rm $f1 failed"
4688 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4691 [[ $flags == $target ]] ||
4692 error "Changelog flag is $flags not $target"
4694 mv $f3 $f2 || error "mv $f3 $f2 failed"
4696 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4699 [[ $flags == $target ]] ||
4700 error "Changelog flag is $flags not $target"
4704 run_test 226 "changelog for last rm/mv with exiting archive"
4706 check_flags_changes() {
4714 $LFS hsm_set --$hsm_flag $f ||
4715 error "Cannot set $hsm_flag on $f"
4716 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4717 local seen=${#flags[*]}
4719 [[ $seen == $cnt ]] ||
4720 error "set $hsm_flag: Changelog events $seen != $cnt"
4721 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4722 error "set $hsm_flag: Changelog flags are "\
4723 "${flags[$((cnt - 1))]} not $target"
4725 $LFS hsm_clear --$hsm_flag $f ||
4726 error "Cannot clear $hsm_flag on $f"
4727 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4730 [[ $cnt == $seen ]] ||
4731 error "clear $hsm_flag: Changelog events $seen != $cnt"
4733 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4734 error "clear $hsm_flag: Changelog flag is "\
4735 "${flags[$((cnt - 1))]} not $target"
4739 # test needs a running copytool
4746 for i in norelease noarchive exists archived
4748 local f=$DIR/$tdir/$tfile-$i
4749 local fid=$(copy_file /etc/passwd $f)
4750 check_flags_changes $f $fid $i 0 1
4753 f=$DIR/$tdir/$tfile---lost
4754 fid=$(copy_file /etc/passwd $f)
4755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4756 wait_request_state $fid ARCHIVE SUCCEED
4757 check_flags_changes $f $fid lost 3 1
4761 run_test 227 "changelog when explicit setting of HSM flags"
4764 # test needs a running copytool
4767 local fid=$(create_small_sync_file $DIR/$tfile)
4768 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4769 wait_request_state $fid ARCHIVE SUCCEED
4771 $LFS hsm_release $DIR/$tfile
4772 check_hsm_flags $DIR/$tfile "0x0000000d"
4774 filefrag $DIR/$tfile | grep " 1 extent found" ||
4775 error "filefrag on released file must return only one extent"
4777 # only newer versions of cp detect sparse files by stat/FIEMAP
4779 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4780 error "copying $DIR/$tfile"
4781 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4783 $LFS hsm_release $DIR/$tfile
4784 check_hsm_flags $DIR/$tfile "0x0000000d"
4786 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4788 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4790 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4791 error "comparing untarred $DIR/$tfile"
4793 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4794 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4797 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4800 # test needs a running copytool
4804 local maxrequest=$(get_hsm_param max_requests)
4805 local rqcnt=$(($maxrequest * 3))
4809 for i in $(seq -w 1 $rqcnt); do
4811 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4813 # we do it in 2 steps, so all requests arrive at the same time
4814 for i in $(seq -w 1 $rqcnt); do
4815 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4820 while [[ $cnt != 0 || $wt != 0 ]]; do
4822 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4823 $HSM_PARAM.actions |\
4824 grep STARTED | grep -v CANCEL | wc -l")
4825 [[ $cnt -le $maxrequest ]] ||
4826 error "$cnt > $maxrequest too many started requests"
4827 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4828 $HSM_PARAM.actions |\
4829 grep WAITING | wc -l")
4830 echo "max=$maxrequest started=$cnt waiting=$wt"
4835 run_test 250 "Coordinator max request"
4838 # test needs a running copytool
4841 local f=$DIR/$tdir/$tfile
4843 fid=$(make_custom_file_for_progress $f 103 1048576)
4844 [ $? != 0 ] && skip "not enough free space" && return
4847 # to have a short test
4848 local old_to=$(get_hsm_param active_request_timeout)
4849 set_hsm_param active_request_timeout 4
4850 # to be sure the cdt will wake up frequently so
4851 # it will be able to cancel the "old" request
4852 local old_loop=$(get_hsm_param loop_period)
4853 set_hsm_param loop_period 2
4856 # clear locks to avoid extra delay caused by flush/cancel
4857 # and thus prevent early copytool death to timeout.
4858 cancel_lru_locks osc
4860 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4861 wait_request_state $fid ARCHIVE STARTED
4863 wait_request_state $fid ARCHIVE CANCELED
4865 set_hsm_param active_request_timeout $old_to
4866 set_hsm_param loop_period $old_loop
4870 run_test 251 "Coordinator request timeout"
4873 # test needs a running copytool
4877 local f=$DIR/$tdir/$tfile
4878 local fid=$(make_custom_file_for_progress $f 103 1048576)
4881 # to have a short test
4882 local old_to=$(get_hsm_param active_request_timeout)
4883 set_hsm_param active_request_timeout 20
4884 # to be sure the cdt will wake up frequently so
4885 # it will be able to cancel the "old" request
4886 local old_loop=$(get_hsm_param loop_period)
4887 set_hsm_param loop_period 2
4890 # clear locks to avoid extra delay caused by flush/cancel
4891 # and thus prevent early copytool death to timeout.
4892 cancel_lru_locks osc
4894 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4895 wait_request_state $fid ARCHIVE STARTED
4898 # wait but less than active_request_timeout+grace_delay
4900 wait_request_state $fid ARCHIVE CANCELED
4902 set_hsm_param active_request_timeout $old_to
4903 set_hsm_param loop_period $old_loop
4907 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4911 # test needs a running copytool
4915 local f=$DIR/$tdir/$tfile
4917 dd if=/dev/zero of=$f bs=1MB count=10
4918 local fid=$(path2fid $f)
4920 $LFS hsm_archive $f || error "could not archive file"
4921 wait_request_state $fid ARCHIVE SUCCEED
4923 # clear locks to discard inode data
4924 cancel_lru_locks osc
4926 #define OBD_FAIL_MDC_MERGE 0x807
4927 $LCTL set_param fail_loc=0x807
4929 #expect error here, instead of release with wrong size
4932 if ((rc == 0)); then
4933 file_size=$(stat -c '%s' $f)
4934 if ((file_size != 10485760)); then
4935 error "Wrong file size after hsm_release"
4938 echo "could not release file"
4942 run_test 253 "Check for wrong file size after release"
4945 # the only way to test ondisk conf is to restart MDS ...
4946 echo "Stop coordinator and remove coordinator state at mount"
4949 # clean on disk conf set by default
4950 cdt_clear_mount_state
4951 cdt_check_state stopped
4953 # check cdt still off after umount/remount
4955 cdt_check_state stopped
4957 echo "Set coordinator start at mount, and start coordinator"
4958 cdt_set_mount_state enabled
4961 cdt_check_state enabled
4963 # check cdt still on after umount/remount
4965 cdt_check_state enabled
4967 # we are back to original state (cdt started at mount)
4969 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4972 local ai=$(get_hsm_param default_archive_id)
4973 local new=$((ai + 1))
4975 set_hsm_param default_archive_id $new -P
4977 local res=$(get_hsm_param default_archive_id)
4980 set_hsm_param default_archive_id "" "-P -d"
4982 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4984 run_test 301 "HSM tunnable are persistent"
4987 local ai=$(get_hsm_param default_archive_id)
4988 local new=$((ai + 1))
4993 set_hsm_param default_archive_id $new -P
4996 for mdtno in $(seq 1 $MDSCOUNT); do
5001 cdt_check_state enabled
5003 local res=$(get_hsm_param default_archive_id)
5006 set_hsm_param default_archive_id "" "-P -d"
5008 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5010 run_test 302 "HSM tunnable are persistent when CDT is off"
5013 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5019 local dir_mdt0=$DIR/$tdir/mdt0
5020 local dir_mdt1=$DIR/$tdir/mdt1
5022 # create 1 dir per MDT
5023 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5024 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5026 # create 1 file in each MDT
5027 local fid1=$(create_small_file $dir_mdt0/$tfile)
5028 local fid2=$(create_small_file $dir_mdt1/$tfile)
5030 # check that hsm request on mdt0 is sent to the right MDS
5031 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5032 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5033 echo "archive successful on mdt0"
5035 # check that hsm request on mdt1 is sent to the right MDS
5036 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5037 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5038 echo "archive successful on mdt1"
5041 # clean test files and directories
5042 rm -rf $dir_mdt0 $dir_mdt1
5044 run_test 400 "Single request is sent to the right MDT"
5047 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5053 local dir_mdt0=$DIR/$tdir/mdt0
5054 local dir_mdt1=$DIR/$tdir/mdt1
5056 # create 1 dir per MDT
5057 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5058 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5060 # create 1 file in each MDT
5061 local fid1=$(create_small_file $dir_mdt0/$tfile)
5062 local fid2=$(create_small_file $dir_mdt1/$tfile)
5064 # check that compound requests are shunt to the rights MDTs
5065 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5066 error "lfs hsm_archive"
5067 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5068 echo "archive successful on mdt0"
5069 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5070 echo "archive successful on mdt1"
5073 # clean test files and directories
5074 rm -rf $dir_mdt0 $dir_mdt1
5076 run_test 401 "Compound requests split and sent to their respective MDTs"
5078 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5083 local node=$(facet_active_host $facet)
5085 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5086 awk '{print $4}'); do
5087 echo "$3 $mdc on $node"
5088 do_facet $facet "$LCTL --device $mdc $state" || return 1
5093 # make sure there is no running copytool
5096 # deactivate all mdc on agent1
5097 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5099 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
5101 check_agent_unregistered "uuid" # match any agent
5103 # no expected running copytool
5104 search_copytools $agent && error "Copytool start should have failed"
5107 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5109 run_test 402a "Copytool start fails if all MDTs are inactive"
5116 local f=$DIR/$tdir/$tfile
5117 touch $f || error "touch $f failed"
5118 local fid=$(path2fid $f)
5120 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5121 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5122 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5124 # give time for CDT to send request and to keep it for retry
5125 wait_for_loop_period
5127 wait_request_state $fid ARCHIVE WAITING
5129 do_facet $SINGLEAGT lctl set_param fail_loc=0
5131 # request should succeed now
5132 wait_request_state $fid ARCHIVE SUCCEED
5136 run_test 402b "CDT must retry request upon slow start of CT"
5139 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5141 # make sure there is no running copytool
5144 local agent=$(facet_active_host $SINGLEAGT)
5146 # deactivate all mdc for MDT0001
5147 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5150 local uuid=$(get_agent_uuid $agent)
5151 # check the agent is registered on MDT0000, and not on MDT0001
5152 check_agent_registered_by_mdt $uuid 0
5153 check_agent_unregistered_by_mdt $uuid 1
5155 # check running copytool process
5156 search_copytools $agent || error "No running copytools on $agent"
5158 # reactivate all mdc for MDT0001
5159 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5161 # make sure the copytool is now registered to all MDTs
5162 check_agent_registered $uuid
5166 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5169 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5173 # create files on both MDT0000 and MDT0001
5176 local dir_mdt0=$DIR/$tdir/mdt0
5177 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5179 # create 1 file on mdt0
5180 local fid1=$(create_small_file $dir_mdt0/$tfile)
5182 # deactivate all mdc for MDT0001
5183 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5185 # send an HSM request for files in MDT0000
5186 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5188 # check for completion of files in MDT0000
5189 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5190 echo "archive successful on mdt0"
5192 # reactivate all mdc for MDT0001
5193 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5196 # clean test files and directories
5199 run_test 404 "Inactive MDT does not block requests for active MDTs"
5202 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5208 local striped_dir=$DIR/$tdir/striped_dir
5210 # create striped dir on all of MDTs
5211 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5213 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5214 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5215 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5216 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5218 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5219 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5220 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5221 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5223 # check that compound requests are shunt to the rights MDTs
5224 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5225 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5226 error "lfs hsm_archive"
5228 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5229 echo "archive successful on $fid1"
5230 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5231 echo "archive successful on $fid2"
5232 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5233 echo "archive successful on $fid3"
5234 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5235 echo "archive successful on $fid4"
5237 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5238 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5239 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5240 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5242 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5243 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5244 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5245 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5249 run_test 405 "archive and release under striped directory"
5252 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5254 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5255 skip "need MDS version at least 2.7.64" && return 0
5261 fid=$(create_small_file $DIR/$tdir/$tfile)
5264 $LFS hsm_archive $DIR/$tdir/$tfile
5265 wait_request_state "$fid" ARCHIVE SUCCEED
5266 $LFS hsm_release $DIR/$tdir/$tfile
5268 # Should migrate $tdir but not $tfile.
5269 $LFS mv -M1 $DIR/$tdir &&
5270 error "migrating HSM an archived file should fail"
5272 $LFS hsm_restore $DIR/$tdir/$tfile
5273 wait_request_state "$fid" RESTORE SUCCEED
5275 $LFS hsm_remove $DIR/$tdir/$tfile
5276 wait_request_state "$fid" REMOVE SUCCEED
5278 cat $DIR/$tdir/$tfile > /dev/null ||
5279 error "cannot read $DIR/$tdir/$tfile"
5281 $LFS mv -M1 $DIR/$tdir ||
5282 error "cannot complete migration after HSM remove"
5284 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5285 if ((mdt_index != 1)); then
5286 error "expected MDT index 1, got $mdt_index"
5289 # Refresh fid after migration.
5290 fid=$(path2fid $DIR/$tdir/$tfile)
5293 $LFS hsm_archive $DIR/$tdir/$tfile
5294 wait_request_state "$fid" ARCHIVE SUCCEED 1
5296 lctl set_param debug=+trace
5297 $LFS hsm_release $DIR/$tdir/$tfile ||
5298 error "cannot release $DIR/$tdir/$tfile"
5300 $LFS hsm_restore $DIR/$tdir/$tfile
5301 wait_request_state "$fid" RESTORE SUCCEED 1
5303 cat $DIR/$tdir/$tfile > /dev/null ||
5304 error "cannot read $DIR/$tdir/$tfile"
5308 run_test 406 "attempting to migrate HSM archived files is safe"
5311 needclients 2 || return 0
5312 # test needs a running copytool
5317 local f=$DIR/$tdir/$tfile
5318 local f2=$DIR2/$tdir/$tfile
5320 fid=$(make_custom_file_for_progress $f 39 1000000)
5321 [ $? != 0 ] && skip "not enough free space" && return
5323 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5324 wait_request_state $fid ARCHIVE SUCCEED
5327 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5328 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5331 # 1st request holds layout lock while appropriate
5332 # RESTORE record is still not added to llog
5336 # after umount hsm_actions->O/x/x log shouldn't have
5337 # double RESTORE records like below
5338 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5339 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5341 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5344 wait_request_state $fid RESTORE SUCCEED
5347 run_test 407 "Check for double RESTORE records in llog"
5351 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5352 skip "HSM migrate is not supported" && return
5354 # Stop the existing copytool
5357 test_mkdir -p $DIR/$tdir
5358 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5360 run_test 500 "various LLAPI HSM tests"
5365 check_and_cleanup_lustre