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: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
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_ARCHIVE=$(copytool_device $SINGLEAGT)
109 # The test only support up to 10 MDTs
110 MDT_PREFIX="mdt.$FSNAME-MDT000"
111 HSM_PARAM="${MDT_PREFIX}0.hsm"
113 # archive is purged at copytool setup
114 HSM_ARCHIVE_PURGE=true
116 # Don't allow copytool error upon start/setup
117 HSMTOOL_NOERROR=false
120 # Get the backend root path for the given agent facet.
123 local dev=AGTDEV$(facet_number $facet)
128 # Stop copytool and unregister an existing changelog user.
130 copytool_monitor_cleanup
133 cdt_set_sanity_policy
138 # get MDT device for each mdc
139 for mdtno in $(seq 1 $MDSCOUNT); do
140 local idx=$(($mdtno - 1))
141 MDT[$idx]=$($LCTL get_param -n \
142 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
143 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
148 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
149 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
153 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
155 echo "Killing existing copytools on $hosts"
156 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
160 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
161 local wait_timeout=200
162 local wait_start=$SECONDS
163 local wait_end=$((wait_start + wait_timeout))
165 while ((SECONDS < wait_end)); do
167 if ! search_copytools $hosts; then
168 echo "copytools stopped in $((SECONDS - wait_start))s"
172 echo "copytools still running on $hosts"
175 # try to dump Copytool's stack
176 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
177 "echo t >/proc/sysrq-trigger"
179 echo "copytools failed to stop in ${wait_timeout}s"
184 copytool_monitor_setup() {
185 local facet=${1:-$SINGLEAGT}
186 local agent=$(facet_active_host $facet)
188 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
189 local test_dir=$(do_node $agent "$cmd") ||
190 error "Failed to create tempdir on $agent"
191 export HSMTOOL_MONITOR_DIR=$test_dir
193 # Create the fifo and a monitor (cat dies when copytool dies)
194 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
195 error "failed to create copytool fifo on $agent"
196 cmd="cat $test_dir/fifo > $test_dir/events &"
197 cmd+=" echo \\\$! > $test_dir/monitor_pid"
199 if [[ $PDSH == *Rmrsh* ]]; then
200 # This is required for pdsh -Rmrsh and its handling of remote
202 # Regular ssh and pdsh -Rssh work fine without this
203 # backgrounded subshell nonsense.
204 (do_node $agent "$cmd") &
205 export HSMTOOL_MONITOR_PDSH=$!
207 # Slightly racy, but just making a best-effort to catch obvious
210 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
211 error "Failed to start copytool monitor on $agent"
213 do_node $agent "$cmd"
215 error "Failed to start copytool monitor on $agent"
220 copytool_monitor_cleanup() {
221 local facet=${1:-$SINGLEAGT}
222 local agent=$(facet_active_host $facet)
224 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
225 # Should die when the copytool dies, but just in case.
226 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
227 cmd+=" 2>/dev/null || true"
228 do_node $agent "$cmd"
229 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
230 export HSMTOOL_MONITOR_DIR=
233 # The pdsh should die on its own when the monitor dies. Just
234 # in case, though, try to clean up to avoid any cruft.
235 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
236 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
237 export HSMTOOL_MONITOR_PDSH=
242 local facet=${1:-$SINGLEAGT}
243 # Use MOUNT2 by default if defined
244 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
246 local hsm_root=${4:-$(copytool_device $facet)}
247 local agent=$(facet_active_host $facet)
249 if [[ -z "$arc_id" ]] &&
250 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
251 echo "Only wakeup running copytool $facet on $agent"
255 if $HSM_ARCHIVE_PURGE; then
256 echo "Purging archive on $agent"
257 do_facet $facet "rm -rf $hsm_root/*"
260 echo "Starting copytool $facet on $agent"
261 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
262 # bandwidth is limited to 1MB/s so the copy time is known and
263 # independent of hardware
264 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
265 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
266 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
267 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
268 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
269 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
270 cmd+=" --bandwidth 1 $lustre_mntpnt"
272 # Redirect the standard output and error to a log file which
273 # can be uploaded to Maloo.
274 local prefix=$TESTLOG_PREFIX
275 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
276 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
278 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
279 if [[ $? != 0 ]]; then
280 [[ $HSMTOOL_NOERROR == true ]] ||
281 error "start copytool $facet on $agent failed"
282 echo "start copytool $facet on $agent failed"
288 get_copytool_event_log() {
289 local facet=${1:-$SINGLEAGT}
290 local agent=$(facet_active_host $facet)
292 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
293 error "Can't get event log: No monitor directory!"
295 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
296 error "Could not collect event log from $agent"
301 local agt_facet=$SINGLEAGT
302 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
303 local hsm_root=$(copytool_device $agt_facet)
309 kill_copytools $agt_hosts
310 wait_copytools $agt_hosts || error "copytools failed to stop"
312 # Clean all CDTs orphans requests from previous tests that
313 # would otherwise need to timeout to clear.
314 for ((i = 0; i < MDSCOUNT; i++)); do
316 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
317 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
319 # Skip already stopping or stopped CDTs.
320 [[ "${state[$i]}" =~ ^stop ]] && continue
322 do_facet $facet "$LCTL set_param $param=shutdown"
325 for ((i = 0; i < MDSCOUNT; i++)); do
326 # Only check and restore CDTs that we stopped in the first loop.
327 [[ "${state[$i]}" =~ ^stop ]] && continue
330 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
332 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
333 error "$facet CDT state is not stopped"
335 # Restore old CDT state.
336 do_facet $facet "$LCTL set_param $param=${state[$i]}"
339 for ((i = 0; i < MDSCOUNT; i++)); do
340 # Only check CDTs that we stopped in the first loop.
341 [[ "${state[$i]}" =~ ^stop ]] && continue
344 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
346 # Check that the old CDT state was restored.
347 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
348 20 || error "$facet CDT state is not '${state[$i]}'"
351 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
352 do_facet $agt_facet "rm -rf $hsm_root/*"
357 local agents=${1:-$(facet_active_host $SINGLEAGT)}
359 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
360 echo "Copytool is suspended on $agents"
363 copytool_remove_backend() {
365 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
366 echo "Remove from backend: $fid = $be"
367 do_facet $SINGLEAGT rm -f $be
371 do_facet $SINGLEAGT \
372 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
373 --import $1 $2 $MOUNT" ||
374 error "import of $1 to $2 failed"
378 local file=$HSM_ARCHIVE/$1
379 do_facet $SINGLEAGT mkdir -p $(dirname $file)
380 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
381 file_creation_failure dd $file $?
385 local file=$HSM_ARCHIVE/$2
386 do_facet $SINGLEAGT mkdir -p $(dirname $file)
387 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
396 if [[ "$value" != "" ]]; then
399 for mdtno in $(seq 1 $MDSCOUNT); do
400 local idx=$(($mdtno - 1))
401 local facet=mds${mdtno}
402 # if $arg include -P option, run 1 set_param per MDT on the MGS
403 # else, run set_param on each MDT
404 [[ $arg = *"-P"* ]] && facet=mgs
405 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
406 [[ $? != 0 ]] && rc=1
416 for mdtno in $(seq 1 $MDSCOUNT); do
417 local idx=$(($mdtno - 1))
418 wait_result mds${mdtno} \
419 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
421 error "$key state is not '$target' on mds${mdtno}"
428 for mdtno in $(seq 1 $MDSCOUNT); do
429 local idx=$(($mdtno - 1))
430 local cl_user=$(do_facet mds${mdtno} $LCTL \
431 --device ${MDT[$idx]} \
432 changelog_register -n)
434 do_facet mds${mdtno} lctl set_param \
435 mdd.${MDT[$idx]}.changelog_mask="+hsm"
436 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
440 changelog_cleanup() {
442 for mdtno in $(seq 1 $MDSCOUNT); do
443 local idx=$(($mdtno - 1))
444 [[ -z ${CL_USERS[$idx]} ]] && continue
445 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
446 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
447 changelog_deregister ${CL_USERS[$idx]}
452 changelog_get_flags() {
457 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
462 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
470 mdts_set_param "$opt -n" "hsm.$param" "$value"
477 mdts_set_param "" hsm_control "$cmd"
478 mdts_check_param hsm_control "$target" 10
481 cdt_set_sanity_policy() {
482 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
485 mdts_set_param "" hsm.policy "+NRA"
486 mdts_set_param "" hsm.policy "-NBR"
487 CDT_POLICY_HAD_CHANGED=
492 mdts_set_param "" hsm.policy "+NRA"
493 CDT_POLICY_HAD_CHANGED=true
496 cdt_clear_no_retry() {
497 mdts_set_param "" hsm.policy "-NRA"
498 CDT_POLICY_HAD_CHANGED=true
501 cdt_set_non_blocking_restore() {
502 mdts_set_param "" hsm.policy "+NBR"
503 CDT_POLICY_HAD_CHANGED=true
506 cdt_clear_non_blocking_restore() {
507 mdts_set_param "" hsm.policy "-NBR"
508 CDT_POLICY_HAD_CHANGED=true
511 cdt_clear_mount_state() {
512 mdts_set_param "-P -d" hsm_control ""
515 cdt_set_mount_state() {
516 mdts_set_param "-P" hsm_control "$1"
517 # set_param -P is asynchronous operation and could race with set_param.
518 # In such case configs could be retrieved and applied at mgc after
519 # set_param -P completion. Sleep here to avoid race with set_param.
520 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
521 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
522 # and 10 seconds to retrieve config from server.
527 mdts_check_param hsm_control "$1" 20
531 set_test_state disabled disabled
535 set_test_state enabled enabled
539 set_test_state shutdown stopped
543 set_test_state purge enabled
549 cdt_set_sanity_policy
553 local client_count=$1
554 if [[ $CLIENTCOUNT -lt $client_count ]]; then
555 skip "Need $client_count or more clients, have $CLIENTCOUNT"
562 $LFS path2fid $1 | tr -d '[]'
563 return ${PIPESTATUS[0]}
571 if [[ $u == "user" ]]; then
572 st=$($RUNAS $LFS hsm_state $f)
575 st=$($LFS hsm_state $f)
578 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
580 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
584 get_hsm_archive_id() {
587 st=$($LFS hsm_state $f)
588 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
590 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
599 local st=$(get_hsm_flags $f)
600 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
603 check_hsm_flags_user() {
607 local st=$(get_hsm_flags $f user)
608 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
611 file_creation_failure() {
616 df $MOUNT $MOUNT2 >&2
617 error "cannot create $f with $cmd, status=$err"
629 if [[ "$3" != 1 ]]; then
633 cp $1 $f || file_creation_failure cp $f $?
635 path2fid $f || error "cannot get fid on $f"
639 local file2=${1/$DIR/$DIR2}
640 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
641 file_creation_failure dd $file2 $?
643 path2fid $1 || error "cannot get fid on $1"
647 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
648 file_creation_failure dd $1 $?
649 path2fid $1 || error "cannot get fid on $1"
652 cleanup_large_files() {
653 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
655 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
658 check_enough_free_space() {
661 local need=$((nb * unit /1024))
662 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
663 (( $need >= $free )) && return 1
667 make_large_for_striping() {
668 local file2=${1/$DIR/$DIR2}
669 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
673 check_enough_free_space 5 $sz
674 [ $? != 0 ] && return $?
676 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
677 file_creation_failure dd $file2 $?
679 path2fid $1 || error "cannot get fid on $1"
682 make_large_for_progress() {
683 local file2=${1/$DIR/$DIR2}
687 check_enough_free_space 39 1000000
688 [ $? != 0 ] && return $?
690 # big file is large enough, so copy time is > 30s
691 # so copytool make 1 progress
692 # size is not a multiple of 1M to avoid stripe
694 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
695 file_creation_failure dd $file2 $?
697 path2fid $1 || error "cannot get fid on $1"
700 make_large_for_progress_aligned() {
701 local file2=${1/$DIR/$DIR2}
705 check_enough_free_space 33 1048576
706 [ $? != 0 ] && return $?
708 # big file is large enough, so copy time is > 30s
709 # so copytool make 1 progress
710 # size is a multiple of 1M to have stripe
712 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
713 file_creation_failure dd $file2 $?
714 path2fid $1 || error "cannot get fid on $1"
717 make_large_for_cancel() {
718 local file2=${1/$DIR/$DIR2}
722 check_enough_free_space 103 1048576
723 [ $? != 0 ] && return $?
725 # Copy timeout is 100s. 105MB => 105s
726 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
727 file_creation_failure dd $file2 $?
728 path2fid $1 || error "cannot get fid on $1"
734 wait_update --verbose $(facet_active_host $facet) "$@"
737 wait_request_state() {
741 # 4th arg (mdt index) is optional
743 local mds=mds$(($mdtidx + 1))
745 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
746 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
748 wait_result $mds "$cmd" $state 200 ||
749 error "request on $fid is not $state on $mds"
752 get_request_state() {
756 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
757 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
760 get_request_count() {
764 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
765 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
772 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
773 [[ -n $fid ]] && cmd+=" | grep '$fid'"
774 cmd+=" | egrep 'WAITING|STARTED'"
776 wait_result $SINGLEMDS "$cmd" "" $timeout ||
777 error "requests did not complete"
780 wait_for_grace_delay() {
781 local val=$(get_hsm_param grace_delay)
788 # python2.6 in EL6 includes an internal json module
789 local json_parser='import json; import fileinput;'
790 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
791 json_parser+='json.loads([line for line in '
792 json_parser+='fileinput.input()][0]).items()])'
794 echo $raw_event | python -c "$json_parser"
797 # populate MDT device array
803 # cleanup from previous bad setup
806 # for recovery tests, coordinator needs to be started at mount
808 # the lustre conf must be without hsm on (like for sanity.sh)
809 echo "Set HSM on and start"
810 cdt_set_mount_state enabled
811 cdt_check_state enabled
813 echo "Start copytool"
816 echo "Set sanity-hsm HSM policy"
817 cdt_set_sanity_policy
819 # finished requests are quickly removed from list
820 set_hsm_param grace_delay 10
826 local f=$DIR/$tdir/$tfile
830 check_hsm_flags_user $f "0x00000000"
832 $RUNAS $LFS hsm_set --norelease $f ||
833 error "user could not change hsm flags"
834 check_hsm_flags_user $f "0x00000010"
836 $RUNAS $LFS hsm_clear --norelease $f ||
837 error "user could not clear hsm flags"
838 check_hsm_flags_user $f "0x00000000"
840 # User could not change those flags...
841 $RUNAS $LFS hsm_set --exists $f &&
842 error "user should not set this flag"
843 check_hsm_flags_user $f "0x00000000"
846 $LFS hsm_set --exists $f ||
847 error "root could not change hsm flags"
848 check_hsm_flags_user $f "0x00000001"
850 $LFS hsm_clear --exists $f ||
851 error "root could not clear hsm state"
852 check_hsm_flags_user $f "0x00000000"
855 run_test 1 "lfs hsm flags root/non-root access"
859 local f=$DIR/$tdir/$tfile
860 local fid=$(make_small $f)
862 $LFS hsm_archive $f || error "could not archive file"
863 wait_request_state $fid ARCHIVE SUCCEED
865 # Release and check states
866 $LFS hsm_release $f || error "could not release file"
867 echo -n "Verifying released state: "
868 check_hsm_flags $f "0x0000000d"
870 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
872 run_test 1a "mmap & cat a HSM released file"
876 local f=$DIR/$tdir/$tfile
878 # New files are not dirty
879 check_hsm_flags $f "0x00000000"
881 # For test, we simulate an archived file.
882 $LFS hsm_set --exists $f || error "user could not change hsm flags"
883 check_hsm_flags $f "0x00000001"
885 # chmod do not put the file dirty
886 chmod 600 $f || error "could not chmod test file"
887 check_hsm_flags $f "0x00000001"
889 # chown do not put the file dirty
890 chown $RUNAS_ID $f || error "could not chown test file"
891 check_hsm_flags $f "0x00000001"
893 # truncate put the file dirty
894 $TRUNCATE $f 1 || error "could not truncate test file"
895 check_hsm_flags $f "0x00000003"
897 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
898 check_hsm_flags $f "0x00000001"
900 run_test 2 "Check file dirtyness when doing setattr"
906 # New files are not dirty
908 check_hsm_flags $f "0x00000000"
910 # For test, we simulate an archived file.
911 $LFS hsm_set --exists $f ||
912 error "user could not change hsm flags"
913 check_hsm_flags $f "0x00000001"
915 # Reading a file, does not set dirty
916 cat $f > /dev/null || error "could not read file"
917 check_hsm_flags $f "0x00000001"
919 # Open for write without modifying data, does not set dirty
920 openfile -f O_WRONLY $f || error "could not open test file"
921 check_hsm_flags $f "0x00000001"
923 # Append to a file sets it dirty
924 cp -p /etc/passwd $f.append || error "could not create file"
925 $LFS hsm_set --exists $f.append ||
926 error "user could not change hsm flags"
927 dd if=/etc/passwd of=$f.append bs=1 count=3\
928 conv=notrunc oflag=append status=noxfer ||
929 file_creation_failure dd $f.append $?
930 check_hsm_flags $f.append "0x00000003"
932 # Modify a file sets it dirty
933 cp -p /etc/passwd $f.modify || error "could not create file"
934 $LFS hsm_set --exists $f.modify ||
935 error "user could not change hsm flags"
936 dd if=/dev/zero of=$f.modify bs=1 count=3\
937 conv=notrunc status=noxfer ||
938 file_creation_failure dd $f.modify $?
939 check_hsm_flags $f.modify "0x00000003"
941 # Open O_TRUNC sets dirty
942 cp -p /etc/passwd $f.trunc || error "could not create file"
943 $LFS hsm_set --exists $f.trunc ||
944 error "user could not change hsm flags"
945 cp /etc/group $f.trunc || error "could not override a file"
946 check_hsm_flags $f.trunc "0x00000003"
948 # Mmapped a file sets dirty
949 cp -p /etc/passwd $f.mmap || error "could not create file"
950 $LFS hsm_set --exists $f.mmap ||
951 error "user could not change hsm flags"
952 multiop $f.mmap OSMWUc || error "could not mmap a file"
953 check_hsm_flags $f.mmap "0x00000003"
955 run_test 3 "Check file dirtyness when opening for write"
959 local f=$DIR/$tdir/$tfile
960 local fid=$(make_small $f)
963 local st=$(get_request_state $fid CANCEL)
964 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
966 run_test 4 "Useless cancel must not be registered"
969 # test needs a running copytool
973 local f=$DIR/$tdir/$tfile
974 local fid=$(copy_file /etc/passwd $f)
976 wait_request_state $fid ARCHIVE SUCCEED
978 check_hsm_flags $f "0x00000009"
982 run_test 8 "Test default archive number"
986 local f=$DIR/$tdir/$tfile
987 local fid=$(copy_file /etc/passwd $f)
988 # we do not use the default one to be sure
989 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
991 copytool_setup $SINGLEAGT $MOUNT $new_an
992 $LFS hsm_archive --archive $new_an $f
993 wait_request_state $fid ARCHIVE SUCCEED
995 check_hsm_flags $f "0x00000009"
999 run_test 9 "Use of explicit archive number, with dedicated copytool"
1002 needclients 3 || return 0
1008 copytool_cleanup $(comma_list $(agts_nodes))
1010 # start all of the copytools
1011 for n in $(seq $AGTCOUNT); do
1012 copytool_setup agt$n
1015 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1018 for n in $(seq $AGTCOUNT); do
1019 file=$DIR/$tdir/$tfile.$n
1020 fid=$(make_small $file)
1022 $LFS hsm_archive $file || error "could not archive file $file"
1023 wait_request_state $fid ARCHIVE SUCCEED
1024 check_hsm_flags $file "0x00000009"
1028 copytool_cleanup $(comma_list $(agts_nodes))
1030 run_test 9a "Multiple remote agents"
1033 # test needs a running copytool
1036 mkdir -p $DIR/$tdir/d1
1037 local f=$DIR/$tdir/$tfile
1038 local fid=$(copy_file /etc/hosts $f)
1039 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1040 error "hsm_archive failed"
1041 wait_request_state $fid ARCHIVE SUCCEED
1043 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1044 error "fid $fid not in archive $HSM_ARCHIVE"
1045 echo "Verifying content"
1046 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1047 echo "Verifying hsm state "
1048 check_hsm_flags $f "0x00000009"
1050 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1051 local st=$(get_hsm_archive_id $f)
1052 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1053 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1058 run_test 10a "Archive a file"
1061 # test needs a running copytool
1065 local f=$DIR/$tdir/$tfile
1066 local fid=$(copy_file /etc/hosts $f)
1067 $LFS hsm_archive $f || error "archive request failed"
1068 wait_request_state $fid ARCHIVE SUCCEED
1070 $LFS hsm_archive $f || error "archive of non dirty file failed"
1071 local cnt=$(get_request_count $fid ARCHIVE)
1072 [[ "$cnt" == "1" ]] ||
1073 error "archive of non dirty file must not make a request"
1077 run_test 10b "Archive of non dirty file must work without doing request"
1080 # test needs a running copytool
1084 local f=$DIR/$tdir/$tfile
1085 local fid=$(copy_file /etc/hosts $f)
1086 $LFS hsm_set --noarchive $f
1087 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1091 run_test 10c "Check forbidden archive"
1094 # test needs a running copytool
1098 local f=$DIR/$tdir/$tfile
1099 local fid=$(copy_file /etc/hosts $f)
1100 $LFS hsm_archive $f || error "cannot archive $f"
1101 wait_request_state $fid ARCHIVE SUCCEED
1103 local ar=$(get_hsm_archive_id $f)
1104 local dflt=$(get_hsm_param default_archive_id)
1105 [[ $ar == $dflt ]] ||
1106 error "archived file is not on default archive: $ar != $dflt"
1110 run_test 10d "Archive a file on the default archive id"
1114 copy2archive /etc/hosts $tdir/$tfile
1115 local f=$DIR/$tdir/$tfile
1117 import_file $tdir/$tfile $f
1118 echo -n "Verifying released state: "
1119 check_hsm_flags $f "0x0000000d"
1121 local LSZ=$(stat -c "%s" $f)
1122 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1124 echo "Verifying imported size $LSZ=$ASZ"
1125 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1126 echo -n "Verifying released pattern: "
1127 local PTRN=$($GETSTRIPE -L $f)
1129 [[ $PTRN == 80000001 ]] || error "Is not released"
1130 local fid=$(path2fid $f)
1131 echo "Verifying new fid $fid in archive"
1133 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1134 error "fid $fid not in archive $HSM_ARCHIVE"
1136 run_test 11a "Import a file"
1139 # test needs a running copytool
1143 local f=$DIR/$tdir/$tfile
1144 local fid=$(copy_file /etc/hosts $f)
1145 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1146 error "hsm_archive failed"
1147 wait_request_state $fid ARCHIVE SUCCEED
1149 local FILE_HASH=$(md5sum $f)
1154 echo "$FILE_HASH" | md5sum -c
1156 [[ $? -eq 0 ]] || error "Restored file differs"
1160 run_test 11b "Import a deleted file using its FID"
1163 # test needs a running copytool
1167 copy2archive /etc/hosts $tdir/$tfile
1169 local f=$DIR/$tdir/$tfile
1170 import_file $tdir/$tfile $f
1171 local f2=$DIR2/$tdir/$tfile
1172 echo "Verifying released state: "
1173 check_hsm_flags $f2 "0x0000000d"
1175 local fid=$(path2fid $f2)
1176 $LFS hsm_restore $f2
1177 wait_request_state $fid RESTORE SUCCEED
1179 echo "Verifying file state: "
1180 check_hsm_flags $f2 "0x00000009"
1182 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1184 [[ $? -eq 0 ]] || error "Restored file differs"
1188 run_test 12a "Restore an imported file explicitly"
1191 # test needs a running copytool
1195 copy2archive /etc/hosts $tdir/$tfile
1197 local f=$DIR/$tdir/$tfile
1198 import_file $tdir/$tfile $f
1199 echo "Verifying released state: "
1200 check_hsm_flags $f "0x0000000d"
1202 cat $f > /dev/null || error "File read failed"
1204 echo "Verifying file state after restore: "
1205 check_hsm_flags $f "0x00000009"
1207 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1209 [[ $? -eq 0 ]] || error "Restored file differs"
1213 run_test 12b "Restore an imported file implicitly"
1216 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1218 # test needs a running copytool
1222 local f=$DIR/$tdir/$tfile
1223 $LFS setstripe -c 2 $f
1225 fid=$(make_large_for_striping $f)
1226 [ $? != 0 ] && skip "not enough free space" && return
1228 local FILE_CRC=$(md5sum $f)
1230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1231 wait_request_state $fid ARCHIVE SUCCEED
1232 $LFS hsm_release $f || error "release $f failed"
1234 echo "$FILE_CRC" | md5sum -c
1236 [[ $? -eq 0 ]] || error "Restored file differs"
1240 run_test 12c "Restore a file with stripe of 2"
1243 # test needs a running copytool
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_restore $f || error "restore of non archived file failed"
1251 local cnt=$(get_request_count $fid RESTORE)
1252 [[ "$cnt" == "0" ]] ||
1253 error "restore non archived must not make a request"
1254 $LFS hsm_archive $f ||
1255 error "archive request failed"
1256 wait_request_state $fid ARCHIVE SUCCEED
1257 $LFS hsm_restore $f ||
1258 error "restore of non released file failed"
1259 local cnt=$(get_request_count $fid RESTORE)
1260 [[ "$cnt" == "0" ]] ||
1261 error "restore a non dirty file must not make a request"
1265 run_test 12d "Restore of a non archived, non released file must work"\
1266 " without doing request"
1269 # test needs a running copytool
1272 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1273 local f=$DIR/$tdir/$tfile
1274 local fid=$(copy_file /etc/hosts $f)
1275 $LFS hsm_archive $f || error "archive request failed"
1276 wait_request_state $fid ARCHIVE SUCCEED
1279 cat /etc/hosts >> $f
1283 $LFS hsm_restore $f && error "restore a dirty file must fail"
1287 run_test 12e "Check forbidden restore"
1290 # test needs a running copytool
1294 local f=$DIR/$tdir/$tfile
1295 local fid=$(copy_file /etc/hosts $f)
1297 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1298 wait_request_state $fid ARCHIVE SUCCEED
1299 $LFS hsm_release $f || error "release of $f failed"
1301 wait_request_state $fid RESTORE SUCCEED
1303 echo -n "Verifying file state: "
1304 check_hsm_flags $f "0x00000009"
1306 diff -q /etc/hosts $f
1308 [[ $? -eq 0 ]] || error "Restored file differs"
1312 run_test 12f "Restore a released file explicitly"
1315 # test needs a running copytool
1319 local f=$DIR/$tdir/$tfile
1320 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1323 wait_request_state $fid ARCHIVE SUCCEED
1324 $LFS hsm_release $f || error "release of $f failed"
1326 diff -q /etc/hosts $f
1329 # we check we had a restore done
1330 wait_request_state $fid RESTORE SUCCEED
1332 [[ $st -eq 0 ]] || error "Restored file differs"
1336 run_test 12g "Restore a released file implicitly"
1339 needclients 2 || return 0
1341 # test needs a running copytool
1345 local f=$DIR/$tdir/$tfile
1346 local fid=$(copy_file /etc/hosts $f)
1348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1349 wait_request_state $fid ARCHIVE SUCCEED
1350 $LFS hsm_release $f || error "release of $f failed"
1352 do_node $CLIENT2 diff -q /etc/hosts $f
1355 # we check we had a restore done
1356 wait_request_state $fid RESTORE SUCCEED
1358 [[ $st -eq 0 ]] || error "Restored file differs"
1362 run_test 12h "Restore a released file implicitly from a second node"
1365 # test needs a running copytool
1369 local f=$DIR/$tdir/$tfile
1370 local fid=$(copy_file /etc/passwd $f)
1371 $LFS hsm_archive $f || error "archive of $f failed"
1372 wait_request_state $fid ARCHIVE SUCCEED
1374 $LFS hsm_release $f || error "release of $f failed"
1378 [[ $? -eq 0 ]] || error "Restored file differs"
1382 run_test 12m "Archive/release/implicit restore"
1385 # test needs a running copytool
1389 copy2archive /etc/hosts $tdir/$tfile
1391 local f=$DIR/$tdir/$tfile
1392 import_file $tdir/$tfile $f
1394 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1395 error "Restored file differs"
1397 $LFS hsm_release $f || error "release of $f failed"
1401 run_test 12n "Import/implicit restore/release"
1404 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(copy_file /etc/hosts $f)
1411 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1412 wait_request_state $fid ARCHIVE SUCCEED
1413 $LFS hsm_release $f || error "release of $f failed"
1415 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1416 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1418 # set no retry action mode
1421 diff -q /etc/hosts $f
1424 # we check we had a restore failure
1425 wait_request_state $fid RESTORE FAILED
1427 [[ $st -eq 0 ]] && error "Restore must fail"
1429 # remove no retry action mode
1432 # check file is still released
1433 check_hsm_flags $f "0x0000000d"
1435 # retry w/o failure injection
1436 do_facet $SINGLEMDS lctl set_param fail_loc=0
1438 # to be sure previous RESTORE result is gone
1440 wait_for_grace_delay
1442 diff -q /etc/hosts $f
1445 # we check we had a restore done
1446 wait_request_state $fid RESTORE SUCCEED
1448 [[ $st -eq 0 ]] || error "Restored file differs"
1452 run_test 12o "Layout-swap failure during Restore leaves file released"
1455 # test needs a running copytool
1459 local f=$DIR/$tdir/$tfile
1460 local fid=$(copy_file /etc/hosts $f)
1462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1463 wait_request_state $fid ARCHIVE SUCCEED
1464 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1465 $LFS hsm_release $f || error "cannot release $f"
1466 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1467 $LFS hsm_release $f || error "cannot release $f"
1468 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1472 run_test 12p "implicit restore of a file on copytool mount point"
1474 cleanup_test_12q() {
1476 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1477 error "cannot umount $MOUNT3 on $SINGLEAGT"
1481 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1482 skip "need MDS version at least 2.7.58" && return 0
1484 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1485 error "cannot mount $MOUNT3 on $SINGLEAGT"
1487 trap cleanup_test_12q EXIT
1489 # test needs a running copytool
1490 copytool_setup $SINGLEAGT $MOUNT3
1493 local f=$DIR/$tdir/$tfile
1494 local f2=$DIR2/$tdir/$tfile
1495 local fid=$(make_small $f)
1496 local orig_size=$(stat -c "%s" $f)
1498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1499 wait_request_state $fid ARCHIVE SUCCEED
1501 $LFS hsm_release $f || error "could not release file"
1502 check_hsm_flags $f "0x0000000d"
1505 wait_copytools || error "copytool failed to stop"
1507 cat $f > /dev/null &
1509 # wait a bit to allow implicit restore request to be handled.
1510 # if not, next stat would also block on layout-lock.
1513 local size=$(stat -c "%s" $f2)
1514 [ $size -eq $orig_size ] ||
1515 error "$f2: wrong size after archive: $size != $orig_size"
1517 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1521 size=$(stat -c "%s" $f)
1522 [ $size -eq $orig_size ] ||
1523 error "$f: wrong size after restore: $size != $orig_size"
1525 size=$(stat -c "%s" $f2)
1526 [ $size -eq $orig_size ] ||
1527 error "$f2: wrong size after restore: $size != $orig_size"
1531 size=$(stat -c "%s" $f)
1533 error "$f: wrong size after overwrite: $size != 0"
1535 size=$(stat -c "%s" $f2)
1537 error "$f2: wrong size after overwrite: $size != 0"
1540 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1541 error "cannot umount $MOUNT3 on $SINGLEAGT"
1543 run_test 12q "file attributes are refreshed after restore"
1546 # test needs a running copytool
1549 local ARC_SUBDIR="import.orig"
1553 # populate directory to be imported
1554 for d in $(seq 1 10); do
1555 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1556 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1557 for f in $(seq 1 10); do
1558 CURR_FILE="$CURR_DIR/$tfile.$f"
1559 # write file-specific data
1560 do_facet $SINGLEAGT \
1561 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1562 "file=$CURR_FILE > $CURR_FILE"
1566 import_file "$ARC_SUBDIR" $DIR/$tdir
1567 # diff lustre content and origin (triggers file restoration)
1568 # there must be 10x10 identical files, and no difference
1569 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1570 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1571 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1572 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1574 [ $cnt_diff -eq 0 ] ||
1575 error "$cnt_diff imported files differ from read data"
1576 [ $cnt_ok -eq 100 ] ||
1577 error "not enough identical files ($cnt_ok != 100)"
1581 run_test 13 "Recursively import and restore a directory"
1584 # test needs a running copytool
1589 local f=$DIR/$tdir/$tfile
1590 local fid=$(make_small $f)
1591 local sum=$(md5sum $f | awk '{print $1}')
1592 $LFS hsm_archive $f || error "could not archive file"
1593 wait_request_state $fid ARCHIVE SUCCEED
1597 # create released file (simulate llapi_hsm_import call)
1599 local fid2=$(path2fid $f)
1600 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1601 $LFS hsm_release $f || error "could not release file"
1603 # rebind the archive to the newly created file
1604 echo "rebind $fid to $fid2"
1606 do_facet $SINGLEAGT \
1607 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1608 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1610 # restore file and compare md5sum
1611 local sum2=$(md5sum $f | awk '{print $1}')
1613 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1617 run_test 14 "Rebind archived file to a new fid"
1620 # test needs a running copytool
1625 local f=$DIR/$tdir/$tfile
1627 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1631 for i in $(seq 1 $count); do
1632 fids[$i]=$(make_small $f.$i)
1633 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1634 $LFS hsm_archive $f.$i || error "could not archive file"
1636 wait_all_done $(($count*60))
1640 for i in $(seq 1 $count); do
1643 local fid2=$(path2fid $f.$i)
1644 # add the rebind operation to the list
1645 echo ${fids[$i]} $fid2 >> $tmpfile
1647 # set it released (simulate llapi_hsm_import call)
1648 $LFS hsm_set --archived --exists $f.$i ||
1649 error "could not force hsm flags"
1650 $LFS hsm_release $f.$i || error "could not release file"
1652 nl=$(wc -l < $tmpfile)
1653 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1655 echo "rebind list of files"
1656 do_facet $SINGLEAGT \
1657 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1658 --rebind $tmpfile $DIR" || error "could not rebind file list"
1660 # restore files and compare md5sum
1661 for i in $(seq 1 $count); do
1662 local sum2=$(md5sum $f.$i | awk '{print $1}')
1663 [[ $sum2 == ${sums[$i]} ]] ||
1664 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1670 run_test 15 "Rebind a list of files"
1673 # test needs a running copytool
1677 # create a known size file so we can verify transfer speed
1680 dd if=/dev/zero of=$ref bs=1M count=20
1683 local f=$DIR/$tdir/$tfile
1684 local fid=$(copy_file $ref $f)
1686 local start=$(date +%s)
1688 wait_request_state $fid ARCHIVE SUCCEED
1689 local end=$(date +%s)
1690 local duration=$((end - start))
1692 [[ $duration -ge $goal ]] ||
1693 error "Transfer is too fast $duration < $goal"
1697 run_test 16 "Test CT bandwith control option"
1702 local f=$DIR/$tdir/$tfile
1703 touch $f || error "touch $f failed"
1705 # Could not release a non-archived file
1706 $LFS hsm_release $f && error "release should not succeed"
1708 # For following tests, we must test them with HS_ARCHIVED set
1709 $LFS hsm_set --exists --archived $f || error "could not add flag"
1711 # Could not release a file if no-release is set
1712 $LFS hsm_set --norelease $f || error "could not add flag"
1713 $LFS hsm_release $f && error "release should not succeed"
1714 $LFS hsm_clear --norelease $f || error "could not remove flag"
1716 # Could not release a file if lost
1717 $LFS hsm_set --lost $f || error "could not add flag"
1718 $LFS hsm_release $f && error "release should not succeed"
1719 $LFS hsm_clear --lost $f || error "could not remove flag"
1721 # Could not release a file if dirty
1722 $LFS hsm_set --dirty $f || error "could not add flag"
1723 $LFS hsm_release $f && error "release should not succeed"
1724 $LFS hsm_clear --dirty $f || error "could not remove flag"
1726 run_test 20 "Release is not permitted"
1729 # test needs a running copytool
1733 local f=$DIR/$tdir/test_release
1735 # Create a file and check its states
1736 local fid=$(make_small $f)
1737 check_hsm_flags $f "0x00000000"
1739 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1740 # used until file is flushed to disk
1741 if [ $(facet_fstype ost1) == "zfs" ]; then
1742 # this causes an OST_SYNC rpc to be sent
1743 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1744 # clear locks to reread file data
1745 cancel_lru_locks osc
1748 local orig_size=$(stat -c "%s" $f)
1749 local orig_blocks=$(stat -c "%b" $f)
1751 start_full_debug_logging
1753 $LFS hsm_archive $f || error "could not archive file"
1754 wait_request_state $fid ARCHIVE SUCCEED
1756 local blocks=$(stat -c "%b" $f)
1757 [ $blocks -eq $orig_blocks ] ||
1758 error "$f: wrong block number after archive: " \
1759 "$blocks != $orig_blocks"
1760 local size=$(stat -c "%s" $f)
1761 [ $size -eq $orig_size ] ||
1762 error "$f: wrong size after archive: $size != $orig_size"
1764 # Release and check states
1765 $LFS hsm_release $f || error "could not release file"
1766 check_hsm_flags $f "0x0000000d"
1768 blocks=$(stat -c "%b" $f)
1769 [ $blocks -gt 5 ] &&
1770 error "$f: too many blocks after release: $blocks > 5"
1771 size=$(stat -c "%s" $f)
1772 [ $size -ne $orig_size ] &&
1773 error "$f: wrong size after release: $size != $orig_size"
1775 # Check we can release an file without stripe info
1779 check_hsm_flags $f "0x00000000"
1780 $LFS hsm_archive $f || error "could not archive file"
1781 wait_request_state $fid ARCHIVE SUCCEED
1783 # Release and check states
1784 $LFS hsm_release $f || error "could not release file"
1785 check_hsm_flags $f "0x0000000d"
1787 # Release again a file that is already released is OK
1788 $LFS hsm_release $f || fail "second release should succeed"
1789 check_hsm_flags $f "0x0000000d"
1791 stop_full_debug_logging
1795 run_test 21 "Simple release tests"
1798 # test needs a running copytool
1803 local f=$DIR/$tdir/test_release
1804 local swap=$DIR/$tdir/test_swap
1806 # Create a file and check its states
1807 local fid=$(make_small $f)
1808 check_hsm_flags $f "0x00000000"
1810 $LFS hsm_archive $f || error "could not archive file"
1811 wait_request_state $fid ARCHIVE SUCCEED
1813 # Release and check states
1814 $LFS hsm_release $f || error "could not release file"
1815 check_hsm_flags $f "0x0000000d"
1818 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1823 run_test 22 "Could not swap a release file"
1826 # test needs a running copytool
1831 local f=$DIR/$tdir/test_mtime
1833 # Create a file and check its states
1834 local fid=$(make_small $f)
1835 check_hsm_flags $f "0x00000000"
1837 $LFS hsm_archive $f || error "could not archive file"
1838 wait_request_state $fid ARCHIVE SUCCEED
1840 # Set modification time in the past
1841 touch -m -a -d @978261179 $f
1843 # Release and check states
1844 $LFS hsm_release $f || error "could not release file"
1845 check_hsm_flags $f "0x0000000d"
1847 local MTIME=$(stat -c "%Y" $f)
1848 local ATIME=$(stat -c "%X" $f)
1849 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1850 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1854 run_test 23 "Release does not change a/mtime (utime)"
1857 local file=$DIR/$tdir/$tfile
1866 # test needs a running copytool
1871 fid=$(make_small $file)
1873 # Create a file and check its states
1874 check_hsm_flags $file "0x00000000"
1876 # Ensure atime is less than mtime and ctime.
1880 atime0=$(stat -c "%X" $file)
1881 mtime0=$(stat -c "%Y" $file)
1882 ctime0=$(stat -c "%Z" $file)
1884 [ $atime0 -lt $mtime0 ] ||
1885 error "atime $atime0 is not less than mtime $mtime0"
1887 [ $atime0 -lt $ctime0 ] ||
1888 error "atime $atime0 is not less than ctime $ctime0"
1890 # Archive should not change any timestamps.
1891 $LFS hsm_archive $file || error "cannot archive '$file'"
1892 wait_request_state $fid ARCHIVE SUCCEED
1894 atime1=$(stat -c "%X" $file)
1895 mtime1=$(stat -c "%Y" $file)
1896 ctime1=$(stat -c "%Z" $file)
1898 [ $atime0 -eq $atime1 ] ||
1899 error "archive changed atime from $atime0 to $atime1"
1901 [ $mtime0 -eq $mtime1 ] ||
1902 error "archive changed mtime from $mtime0 to $mtime1"
1904 [ $ctime0 -eq $ctime1 ] ||
1905 error "archive changed ctime from $ctime0 to $ctime1"
1907 # Release should not change any timestamps.
1908 $LFS hsm_release $file || error "cannot release '$file'"
1909 check_hsm_flags $file "0x0000000d"
1911 atime1=$(stat -c "%X" $file)
1912 mtime1=$(stat -c "%Y" $file)
1913 ctime1=$(stat -c "%Z" $file)
1915 [ $atime0 -eq $atime1 ] ||
1916 error "release changed atime from $atime0 to $atime1"
1918 [ $mtime0 -eq $mtime1 ] ||
1919 error "release changed mtime from $mtime0 to $mtime1"
1921 [ $ctime0 -eq $ctime1 ] ||
1922 error "release changed ctime from $ctime0 to $ctime1"
1924 # Restore should not change atime or mtime and should not
1926 $LFS hsm_restore $file
1927 wait_request_state $fid RESTORE SUCCEED
1929 atime1=$(stat -c "%X" $file)
1930 mtime1=$(stat -c "%Y" $file)
1931 ctime1=$(stat -c "%Z" $file)
1933 [ $atime0 -eq $atime1 ] ||
1934 error "restore changed atime from $atime0 to $atime1"
1936 [ $mtime0 -eq $mtime1 ] ||
1937 error "restore changed mtime from $mtime0 to $mtime1"
1939 [ $ctime0 -eq $ctime1 ] ||
1940 error "restore changed ctime from $ctime0 to $ctime1"
1944 # Once more, after unmount and mount.
1945 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1946 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1948 atime1=$(stat -c "%X" $file)
1949 mtime1=$(stat -c "%Y" $file)
1950 ctime1=$(stat -c "%Z" $file)
1952 [ $atime0 -eq $atime1 ] ||
1953 error "remount changed atime from $atime0 to $atime1"
1955 [ $mtime0 -eq $mtime1 ] ||
1956 error "remount changed mtime from $mtime0 to $mtime1"
1958 [ $ctime0 -eq $ctime1 ] ||
1959 error "remount changed ctime from $ctime0 to $ctime1"
1961 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1964 local file=$DIR/$tdir/$tfile
1970 # Test needs a running copytool.
1974 # Check that root can do HSM actions on a regular user's file.
1976 fid=$(make_small $file)
1977 sum0=$(md5sum $file)
1979 chown $RUNAS_ID:$RUNAS_GID $file ||
1980 error "cannot chown '$file' to '$RUNAS_ID'"
1982 chmod ugo-w $DIR/$tdir ||
1983 error "cannot chmod '$DIR/$tdir'"
1985 $LFS hsm_archive $file
1986 wait_request_state $fid ARCHIVE SUCCEED
1988 $LFS hsm_release $file
1989 check_hsm_flags $file "0x0000000d"
1991 $LFS hsm_restore $file
1992 wait_request_state $fid RESTORE SUCCEED
1994 # Check that ordinary user can get HSM state.
1995 $RUNAS $LFS hsm_state $file ||
1996 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1998 $LFS hsm_release $file
1999 check_hsm_flags $file "0x0000000d"
2001 # Check that ordinary user can accessed released file.
2002 sum1=$($RUNAS md5sum $file) ||
2003 error "user '$RUNAS_ID' cannot read '$file'"
2005 [ "$sum0" == "$sum1" ] ||
2006 error "md5sum mismatch for '$file'"
2010 run_test 24b "root can archive, release, and restore user files"
2012 cleanup_test_24c() {
2014 set_hsm_param user_request_mask RESTORE
2015 set_hsm_param group_request_mask RESTORE
2016 set_hsm_param other_request_mask RESTORE
2020 local file=$DIR/$tdir/$tfile
2021 local action=archive
2026 # test needs a running copytool
2031 # Save the default masks and check that cleanup_24c will
2032 # restore the request masks correctly.
2033 user_save=$(get_hsm_param user_request_mask)
2034 group_save=$(get_hsm_param group_request_mask)
2035 other_save=$(get_hsm_param other_request_mask)
2037 [ "$user_save" == RESTORE ] ||
2038 error "user_request_mask is '$user_save' expected 'RESTORE'"
2039 [ "$group_save" == RESTORE ] ||
2040 error "group_request_mask is '$group_save' expected 'RESTORE'"
2041 [ "$other_save" == RESTORE ] ||
2042 error "other_request_mask is '$other_save' expected 'RESTORE'"
2044 trap cleanup_test_24c EXIT
2049 chown $RUNAS_ID:nobody $file ||
2050 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2052 set_hsm_param user_request_mask ""
2053 $RUNAS $LFS hsm_$action $file &&
2054 error "$action by user should fail"
2056 set_hsm_param user_request_mask $action
2057 $RUNAS $LFS hsm_$action $file ||
2058 error "$action by user should succeed"
2063 chown nobody:$RUNAS_GID $file ||
2064 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2066 set_hsm_param group_request_mask ""
2067 $RUNAS $LFS hsm_$action $file &&
2068 error "$action by group should fail"
2070 set_hsm_param group_request_mask $action
2071 $RUNAS $LFS hsm_$action $file ||
2072 error "$action by group should succeed"
2077 chown nobody:nobody $file ||
2078 error "cannot chown '$file' to 'nobody:nobody'"
2080 set_hsm_param other_request_mask ""
2081 $RUNAS $LFS hsm_$action $file &&
2082 error "$action by other should fail"
2084 set_hsm_param other_request_mask $action
2085 $RUNAS $LFS hsm_$action $file ||
2086 error "$action by other should succeed"
2091 run_test 24c "check that user,group,other request masks work"
2093 cleanup_test_24d() {
2095 mount -o remount,rw $MOUNT2
2099 local file1=$DIR/$tdir/$tfile
2100 local file2=$DIR2/$tdir/$tfile
2108 fid1=$(make_small $file1)
2110 trap cleanup_test_24d EXIT
2112 mount -o remount,ro $MOUNT2
2114 fid2=$(path2fid $file2)
2115 [ "$fid1" == "$fid2" ] ||
2116 error "FID mismatch '$fid1' != '$fid2'"
2118 $LFS hsm_archive $file2 &&
2119 error "archive should fail on read-only mount"
2120 check_hsm_flags $file1 "0x00000000"
2122 $LFS hsm_archive $file1
2123 wait_request_state $fid1 ARCHIVE SUCCEED
2125 $LFS hsm_release $file1
2126 $LFS hsm_restore $file2
2127 wait_request_state $fid1 RESTORE SUCCEED
2129 $LFS hsm_release $file1 || error "cannot release '$file1'"
2130 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2132 $LFS hsm_release $file2 &&
2133 error "release should fail on read-only mount"
2138 run_test 24d "check that read-only mounts are respected"
2145 local f=$DIR/$tdir/$tfile
2148 fid=$(make_small $f) || error "cannot create $f"
2149 $LFS hsm_archive $f || error "cannot archive $f"
2150 wait_request_state $fid ARCHIVE SUCCEED
2151 $LFS hsm_release $f || error "cannot release $f"
2152 while ! $LFS hsm_state $f | grep released; do
2156 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2160 run_test 24e "tar succeeds on HSM released files" # LU-6213
2164 # test needs a running copytool
2167 mkdir -p $DIR/$tdir/d1
2168 local f=$DIR/$tdir/$tfile
2169 local fid=$(copy_file /etc/hosts $f)
2172 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2173 error "hsm_archive failed"
2174 wait_request_state $fid ARCHIVE SUCCEED
2175 $LFS hsm_release $f || error "cannot release $f"
2176 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2179 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2180 error "Can not recover the tar contents"
2182 echo "Sum0 = $sum0, sum1 = $sum1"
2183 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2187 run_test 24f "root can archive, release, and restore tar files"
2190 # test needs a running copytool
2194 copy2archive /etc/hosts $tdir/$tfile
2196 local f=$DIR/$tdir/$tfile
2198 import_file $tdir/$tfile $f
2200 $LFS hsm_set --lost $f
2205 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2209 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2210 " (Operation not permitted)"
2213 # test needs a running copytool
2218 local f=$DIR/$tdir/$tfile
2219 local fid=$(copy_file /etc/passwd $f)
2221 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2222 wait_request_state $fid ARCHIVE SUCCEED
2225 $LFS hsm_set --lost $f
2229 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2233 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2234 " (Operation not permitted)"
2237 # test needs a running copytool
2241 local f=$DIR/$tdir/$tfile
2243 fid=$(make_large_for_progress $f)
2244 [ $? != 0 ] && skip "not enough free space" && return
2246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2247 wait_request_state $fid ARCHIVE SUCCEED
2250 wait_request_state $fid REMOVE SUCCEED
2252 check_hsm_flags $f "0x00000000"
2256 run_test 26 "Remove the archive of a valid file"
2259 # test needs a running copytool
2263 make_archive $tdir/$tfile
2264 local f=$DIR/$tdir/$tfile
2265 import_file $tdir/$tfile $f
2266 local fid=$(path2fid $f)
2270 [[ $? != 0 ]] || error "Remove of a released file should fail"
2274 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2277 # test needs a running copytool
2281 local f=$DIR/$tdir/$tfile
2283 fid=$(make_large_for_progress $f)
2284 [ $? != 0 ] && skip "not enough free space" && return
2286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2287 wait_request_state $fid ARCHIVE SUCCEED
2292 [[ $? != 0 ]] || error "Remove of a released file should fail"
2296 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2299 # test needs a running copytool
2303 local f=$DIR/$tdir/$tfile
2305 fid=$(make_large_for_progress $f)
2306 [ $? != 0 ] && skip "not enough free space" && return
2308 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2309 wait_request_state $fid ARCHIVE SUCCEED
2318 wait_request_state $fid REMOVE SUCCEED
2322 run_test 28 "Concurrent archive/file remove"
2325 # Tests --mntpath and --archive options
2328 copytool_setup $SINGLEAGT $MOUNT $archive_id
2330 # Bad archive number
2331 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2332 grep "Invalid argument" ||
2333 error "unexpected hsm_remove failure (1)"
2335 # mntpath is present but file is given
2336 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2337 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2338 error "unexpected hsm_remove failure (2)"
2342 run_test 29a "Tests --mntpath and --archive options"
2345 # test needs a running copytool
2349 local f=$DIR/$tdir/$tfile
2350 local fid=$(make_small $f)
2352 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2353 wait_request_state $fid ARCHIVE SUCCEED
2357 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2358 wait_request_state $fid REMOVE SUCCEED
2362 run_test 29b "Archive/delete/remove by FID from the archive."
2365 # test needs a running copytool
2369 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2370 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2371 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2373 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2374 wait_request_state $fid1 ARCHIVE SUCCEED
2375 wait_request_state $fid2 ARCHIVE SUCCEED
2376 wait_request_state $fid3 ARCHIVE SUCCEED
2378 rm -f $DIR/$tdir/$tfile-[1-3]
2380 echo $fid1 > $DIR/$tdir/list
2381 echo $fid2 >> $DIR/$tdir/list
2382 echo $fid3 >> $DIR/$tdir/list
2384 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2385 --filelist $DIR/$tdir/list
2386 wait_request_state $fid1 REMOVE SUCCEED
2387 wait_request_state $fid2 REMOVE SUCCEED
2388 wait_request_state $fid3 REMOVE SUCCEED
2392 run_test 29c "Archive/delete/remove by FID, using a file list."
2395 # restore at exec cannot work on agent node (because of Linux kernel
2396 # protection of executables)
2397 needclients 2 || return 0
2399 # test needs a running copytool
2403 copy2archive /bin/true $tdir/$tfile
2405 local f=$DIR/$tdir/true
2406 import_file $tdir/$tfile $f
2408 local fid=$(path2fid $f)
2410 # set no retry action mode
2416 # remove no try action mode
2420 [[ $st == 0 ]] || error "Failed to exec a released file"
2424 run_test 30a "Restore at exec (import case)"
2427 # restore at exec cannot work on agent node (because of Linux kernel
2428 # protection of executables)
2429 needclients 2 || return 0
2431 # test needs a running copytool
2435 local f=$DIR/$tdir/true
2436 local fid=$(copy_file /bin/true $f)
2438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2439 wait_request_state $fid ARCHIVE SUCCEED
2442 # set no retry action mode
2448 # remove no try action mode
2452 [[ $st == 0 ]] || error "Failed to exec a released file"
2456 run_test 30b "Restore at exec (release case)"
2459 needclients 2 || return 0
2461 # test needs a running copytool
2465 local f=$DIR/$tdir/SLEEP
2466 local slp_sum1=$(md5sum /bin/sleep)
2467 local fid=$(copy_file /bin/sleep $f)
2469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2470 wait_request_state $fid ARCHIVE SUCCEED
2472 check_hsm_flags $f "0x0000000d"
2473 # set no retry action mode
2475 do_node $CLIENT2 "$f 10" &
2479 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2481 [[ $? == 0 ]] || error "Execution failed during run"
2483 if [[ $? != 0 ]]; then
2484 local slp_sum2=$(md5sum /bin/sleep)
2485 # in case sleep file is modified during the test
2486 [[ $slp_sum1 == $slp_sum2 ]] &&
2487 error "Binary overwritten during exec"
2491 # remove no try action mode
2493 check_hsm_flags $f "0x00000009"
2497 run_test 30c "Update during exec of released file must fail"
2499 restore_and_check_size() {
2502 local s=$(stat -c "%s" $f)
2504 local st=$(get_hsm_flags $f)
2508 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2510 n=$(stat -c "%s" $f)
2511 # we echo in both cases to show stat is not
2513 if [[ $n != $s ]]; then
2514 echo "size seen is $n != $s"
2517 echo "size seen is right: $n == $s"
2519 st=$(get_hsm_flags $f)
2523 if [[ $cpt -lt 10 ]]; then
2526 echo " restore is too long"
2527 wait_request_state $fid RESTORE SUCCEED
2533 # test needs a running copytool
2538 make_archive $tdir/$tfile
2539 local f=$DIR/$tdir/$tfile
2540 import_file $tdir/$tfile $f
2541 local fid=$($LFS path2fid $f)
2542 HSM_ARCHIVE_PURGE=false copytool_setup
2544 restore_and_check_size $f $fid
2547 [[ $err -eq 0 ]] || error "File size changed during restore"
2551 run_test 31a "Import a large file and check size during restore"
2555 # test needs a running copytool
2560 local f=$DIR/$tdir/$tfile
2562 fid=$(make_large_for_progress $f)
2563 [ $? != 0 ] && skip "not enough free space" && return
2565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2566 wait_request_state $fid ARCHIVE SUCCEED
2569 restore_and_check_size $f $fid
2572 [[ $err -eq 0 ]] || error "File size changed during restore"
2576 run_test 31b "Restore a large unaligned file and check size during restore"
2579 # test needs a running copytool
2584 local f=$DIR/$tdir/$tfile
2586 fid=$(make_large_for_progress_aligned $f)
2587 [ $? != 0 ] && skip "not enough free space" && return
2589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2590 wait_request_state $fid ARCHIVE SUCCEED
2593 restore_and_check_size $f $fid
2596 [[ $err -eq 0 ]] || error "File size changed during restore"
2600 run_test 31c "Restore a large aligned file and check size during restore"
2603 # test needs a running copytool
2608 local f=$DIR/$tdir/$tfile
2610 fid=$(make_large_for_progress $f)
2611 [ $? != 0 ] && skip "not enough free space" && return
2613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2614 wait_request_state $fid ARCHIVE SUCCEED
2617 # to be sure wait_all_done will not be mislead by previous tests
2620 wait_for_grace_delay
2621 # Also raise grace_delay significantly so the Canceled
2622 # Restore action will stay enough long avail.
2623 local old_grace=$(get_hsm_param grace_delay)
2624 set_hsm_param grace_delay 100
2626 md5sum $f >/dev/null &
2628 wait_request_state $fid RESTORE STARTED
2633 # Check restore trigger process was killed
2634 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2638 # instead of waiting+checking both Restore and Cancel ops
2639 # sequentially, wait for both to be finished and then check
2641 wait_all_done 100 $fid
2642 local rstate=$(get_request_state $fid RESTORE)
2643 local cstate=$(get_request_state $fid CANCEL)
2645 # restore orig grace_delay.
2646 set_hsm_param grace_delay $old_grace
2648 if [[ "$rstate" == "CANCELED" ]] ; then
2649 [[ "$cstate" == "SUCCEED" ]] ||
2650 error "Restore state is CANCELED and Cancel state " \
2651 "is not SUCCEED but $cstate"
2652 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2653 elif [[ "$rstate" == "SUCCEED" ]] ; then
2654 [[ "$cstate" == "FAILED" ]] ||
2655 error "Restore state is SUCCEED and Cancel state " \
2656 "is not FAILED but $cstate"
2657 echo "Restore state is SUCCEED, Cancel state is FAILED"
2659 error "Restore state is $rstate and Cancel state is $cstate"
2663 error "Cannot kill process waiting for restore ($killed)"
2667 run_test 33 "Kill a restore waiting process"
2670 # test needs a running copytool
2675 local f=$DIR/$tdir/$tfile
2677 fid=$(make_large_for_progress $f)
2678 [ $? != 0 ] && skip "not enough free space" && return
2680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2681 wait_request_state $fid ARCHIVE SUCCEED
2684 md5sum $f >/dev/null &
2686 wait_request_state $fid RESTORE STARTED
2688 rm $f || error "rm $f failed"
2689 # rm must not block during restore
2690 wait_request_state $fid RESTORE STARTED
2692 wait_request_state $fid RESTORE SUCCEED
2693 # check md5sum pgm finished
2694 local there=$(ps -o pid,comm hp $pid >/dev/null)
2695 [[ -z $there ]] || error "Restore initiator does not exit"
2697 local rc=$(wait $pid)
2698 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2702 run_test 34 "Remove file during restore"
2705 # test needs a running copytool
2710 local f=$DIR/$tdir/$tfile
2711 local f1=$DIR/$tdir/$tfile-1
2713 fid=$(make_large_for_progress $f)
2714 [ $? != 0 ] && skip "not enough free space" && return
2716 local fid1=$(copy_file /etc/passwd $f1)
2717 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2718 wait_request_state $fid ARCHIVE SUCCEED
2721 md5sum $f >/dev/null &
2723 wait_request_state $fid RESTORE STARTED
2725 mv $f1 $f || error "mv $f1 $f failed"
2726 # mv must not block during restore
2727 wait_request_state $fid RESTORE STARTED
2729 wait_request_state $fid RESTORE SUCCEED
2730 # check md5sum pgm finished
2731 local there=$(ps -o pid,comm hp $pid >/dev/null)
2732 [[ -z $there ]] || error "Restore initiator does not exit"
2734 local rc=$(wait $pid)
2735 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2738 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2742 run_test 35 "Overwrite file during restore"
2745 # test needs a running copytool
2750 local f=$DIR/$tdir/$tfile
2752 fid=$(make_large_for_progress $f)
2753 [ $? != 0 ] && skip "not enough free space" && return
2755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2756 wait_request_state $fid ARCHIVE SUCCEED
2759 md5sum $f >/dev/null &
2761 wait_request_state $fid RESTORE STARTED
2764 # rm must not block during restore
2765 wait_request_state $fid RESTORE STARTED
2767 wait_request_state $fid RESTORE SUCCEED
2768 # check md5sum pgm finished
2769 local there=$(ps -o pid,comm hp $pid >/dev/null)
2771 error "Restore initiator does not exit"
2773 local rc=$(wait $pid)
2775 error "Restore initiator failed with $rc"
2779 run_test 36 "Move file during restore"
2782 # LU-5683: check that an archived dirty file can be rearchived.
2784 copytool_setup $SINGLEAGT $MOUNT2
2787 local f=$DIR/$tdir/$tfile
2790 fid=$(make_small $f) || error "cannot create small file"
2792 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2793 wait_request_state $fid ARCHIVE SUCCEED
2794 $LFS hsm_release $f || error "cannot release $f"
2797 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2799 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2800 wait_request_state $fid ARCHIVE SUCCEED
2804 run_test 37 "re-archive a dirty file"
2811 for n in $(seq 1 $count); do
2812 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2814 echo "$count archive requests submitted"
2818 local stream_count=4
2819 local file_count=100
2821 local f=$DIR/$tdir/$tfile
2826 for i in $(seq 1 $file_count); do
2827 for p in $(seq 1 $stream_count); do
2828 fid=$(copy_file /etc/hosts $f.$p.$i)
2831 # force copytool to use a local/temp archive dir to ensure best
2832 # performance vs remote/NFS mounts used in auto-tests
2833 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2836 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2838 # to be sure wait_all_done will not be mislead by previous tests
2840 wait_for_grace_delay
2842 # start archive streams in background (archive files in parallel)
2843 for p in $(seq 1 $stream_count); do
2844 multi_archive $f.$p $file_count &
2847 echo -n "Wait for all requests being enqueued..."
2853 run_test 40 "Parallel archive requests"
2856 # test needs a running copytool
2860 local f=$DIR/$tdir/$tfile
2861 local fid=$(copy_file /etc/motd $f 1)
2863 $LFS hsm_archive $f || error "could not archive file"
2864 wait_request_state $fid ARCHIVE SUCCEED
2865 check_hsm_flags $f "0x00000009"
2867 multiop_bg_pause $f O_c || error "multiop failed"
2871 client_up || client_up || true
2873 kill -USR1 $MULTIPID
2874 wait $MULTIPID || error "multiop close failed"
2876 check_hsm_flags $f "0x0000000b"
2880 run_test 52 "Opened for write file on an evicted client should be set dirty"
2883 # test needs a running copytool
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(copy_file /etc/motd $f 1)
2890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2891 error "could not archive file"
2892 wait_request_state $fid ARCHIVE SUCCEED
2893 check_hsm_flags $f "0x00000009"
2895 multiop_bg_pause $f o_c || error "multiop failed"
2899 client_up || client_up || true
2901 kill -USR1 $MULTIPID
2902 wait $MULTIPID || error "multiop close failed"
2904 check_hsm_flags $f "0x00000009"
2908 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2911 # test needs a running copytool
2915 local f=$DIR/$tdir/$tfile
2916 local fid=$(make_large_for_progress $f)
2918 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2919 error "could not archive file"
2920 wait_request_state $fid ARCHIVE STARTED
2922 check_hsm_flags $f "0x00000001"
2924 # Avoid coordinator resending this request as soon it has failed.
2929 wait_request_state $fid ARCHIVE FAILED
2931 check_hsm_flags $f "0x00000003"
2936 run_test 54 "Write during an archive cancels it"
2939 # test needs a running copytool
2943 local f=$DIR/$tdir/$tfile
2944 local fid=$(make_large_for_progress $f)
2946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2947 error "could not archive file"
2948 wait_request_state $fid ARCHIVE STARTED
2950 check_hsm_flags $f "0x00000001"
2952 # Avoid coordinator resending this request as soon it has failed.
2955 $TRUNCATE $f 1024 || error "truncate failed"
2957 wait_request_state $fid ARCHIVE FAILED
2959 check_hsm_flags $f "0x00000003"
2964 run_test 55 "Truncate during an archive cancels it"
2967 # test needs a running copytool
2971 local f=$DIR/$tdir/$tfile
2973 fid=$(make_large_for_progress $f)
2974 [ $? != 0 ] && skip "not enough free space" && return
2976 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2977 error "could not archive file"
2978 wait_request_state $fid ARCHIVE STARTED
2980 check_hsm_flags $f "0x00000001"
2982 # Change metadata and sync to be sure we are not changing only
2987 wait_request_state $fid ARCHIVE SUCCEED
2989 check_hsm_flags $f "0x00000009"
2993 run_test 56 "Setattr during an archive is ok"
2996 # Need one client for I/O, one for request
2997 needclients 2 || return 0
2999 # test needs a running copytool
3003 local f=$DIR/$tdir/test_archive_remote
3004 # Create a file on a remote node
3005 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3006 "count=2 conv=fsync"
3009 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3010 error "hsm_archive failed"
3011 local fid=$(path2fid $f)
3012 wait_request_state $fid ARCHIVE SUCCEED
3014 # Release and implicit restore it
3015 do_node $CLIENT2 "$LFS hsm_release $f" ||
3016 error "hsm_release failed"
3017 do_node $CLIENT2 "md5sum $f" ||
3018 error "hsm_restore failed"
3020 wait_request_state $fid RESTORE SUCCEED
3024 run_test 57 "Archive a file with dirty cache on another node"
3026 truncate_released_file() {
3030 local sz=$(stat -c %s $src_file)
3031 local f=$DIR/$tdir/$tfile
3032 local fid=$(copy_file $1 $f)
3036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3037 error "could not archive file"
3038 wait_request_state $fid ARCHIVE SUCCEED
3040 $LFS hsm_release $f || error "could not release file"
3042 $TRUNCATE $f $trunc_to || error "truncate failed"
3045 local sz1=$(stat -c %s $f)
3046 [[ $sz1 == $trunc_to ]] ||
3047 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3050 check_hsm_flags $f "0x0000000b"
3052 local state=$(get_request_state $fid RESTORE)
3053 [[ "$state" == "SUCCEED" ]] ||
3054 error "truncate $sz does not trig restore, state = $state"
3056 $TRUNCATE $ref $trunc_to
3057 cmp $ref $f || error "file data wrong after truncate"
3063 # test needs a running copytool
3068 local sz=$(stat -c %s /etc/passwd)
3070 echo "truncate up from $sz to $((sz*2))"
3071 truncate_released_file /etc/passwd $((sz*2))
3073 echo "truncate down from $sz to $((sz/2))"
3074 truncate_released_file /etc/passwd $((sz/2))
3076 echo "truncate to 0"
3077 truncate_released_file /etc/passwd 0
3081 run_test 58 "Truncate a released file will trigger restore"
3085 local server_version=$(lustre_version_code $SINGLEMDS)
3086 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3087 skip "Need MDS version at least 2.7.63" && return
3090 $MCREATE $DIR/$tfile || error "mcreate failed"
3091 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3092 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3093 fid=$(path2fid $DIR/$tfile)
3094 wait_request_state $fid ARCHIVE SUCCEED
3095 $LFS hsm_release $DIR/$tfile || error "release failed"
3098 run_test 59 "Release stripeless file with non-zero size"
3101 # This test validates the fix for LU-4512. Ensure that the -u
3102 # option changes the progress reporting interval from the
3103 # default (30 seconds) to the user-specified interval.
3105 local progress_timeout=$((interval * 4))
3107 # test needs a new running copytool
3109 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3112 local f=$DIR/$tdir/$tfile
3114 fid=$(make_large_for_progress $f)
3115 [ $? != 0 ] && skip "not enough free space" && return
3118 local mdt=${MDT_PREFIX}${mdtidx}
3119 local mds=mds$((mdtidx + 1))
3121 # Wait for copytool to register
3122 wait_update_facet $mds \
3123 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3124 uuid 100 || error "coyptool failed to register with $mdt"
3126 local start_at=$(date +%s)
3127 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3128 error "could not archive file"
3130 local agent=$(facet_active_host $SINGLEAGT)
3131 local prefix=$TESTLOG_PREFIX
3132 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3133 local copytool_log=$prefix.copytool_log.$agent.log
3136 wait_update $agent \
3137 "grep -o start.copy $copytool_log" "start copy" 100 ||
3138 error "copytool failed to start"
3140 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3141 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3147 echo -n "Expecting a progress update within $progress_timeout seconds... "
3149 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3150 if [ $RESULT -gt 0 ]; then
3151 echo "$RESULT bytes copied in $WAIT seconds."
3153 elif [ $WAIT -ge $progress_timeout ]; then
3154 error "Timed out waiting for progress update!"
3157 WAIT=$((WAIT + sleep))
3161 local finish_at=$(date +%s)
3162 local elapsed=$((finish_at - start_at))
3164 # Ensure that the progress update occurred within the expected window.
3165 if [ $elapsed -lt $interval ]; then
3166 error "Expected progress update after at least $interval seconds"
3172 run_test 60 "Changing progress update interval from default"
3175 # test needs a new running copytool
3177 copytool_monitor_setup
3178 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3180 # Just start and stop the copytool to generate events.
3183 # Wait for the copytool to register.
3184 wait_update --verbose $(facet_active_host mds1) \
3185 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3187 error "copytool failed to register with MDT0000"
3191 local REGISTER_EVENT
3192 local UNREGISTER_EVENT
3193 while read event; do
3194 local parsed=$(parse_json_event "$event")
3195 if [ -z "$parsed" ]; then
3196 error "Copytool sent malformed event: $event"
3200 if [ $event_type == "REGISTER" ]; then
3201 REGISTER_EVENT=$event
3202 elif [ $event_type == "UNREGISTER" ]; then
3203 UNREGISTER_EVENT=$event
3205 done < <(echo $"$(get_copytool_event_log)")
3207 if [ -z "$REGISTER_EVENT" ]; then
3208 error "Copytool failed to send register event to FIFO"
3211 if [ -z "$UNREGISTER_EVENT" ]; then
3212 error "Copytool failed to send unregister event to FIFO"
3215 copytool_monitor_cleanup
3216 echo "Register/Unregister events look OK."
3218 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3221 # Bump progress interval for livelier events.
3224 # test needs a new running copytool
3226 copytool_monitor_setup
3227 HSMTOOL_UPDATE_INTERVAL=$interval \
3228 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3231 local f=$DIR/$tdir/$tfile
3233 fid=$(make_large_for_progress $f)
3234 [ $? != 0 ] && skip "not enough free space" && return
3236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3237 error "could not archive file"
3238 wait_request_state $fid ARCHIVE SUCCEED
3240 local expected_fields="event_time data_fid source_fid"
3241 expected_fields+=" total_bytes current_bytes"
3245 while read event; do
3246 # Make sure we're not getting anything from previous events.
3247 for field in $expected_fields; do
3251 local parsed=$(parse_json_event "$event")
3252 if [ -z "$parsed" ]; then
3253 error "Copytool sent malformed event: $event"
3257 if [ $event_type == "ARCHIVE_START" ]; then
3260 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3263 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3267 # Do some simple checking of the progress update events.
3268 for expected_field in $expected_fields; do
3269 if [ -z ${!expected_field+x} ]; then
3270 error "Missing $expected_field field in event"
3274 if [ $total_bytes -eq 0 ]; then
3275 error "Expected total_bytes to be > 0"
3278 # These should be identical throughout an archive
3280 if [ $source_fid != $data_fid ]; then
3281 error "Expected source_fid to equal data_fid"
3283 done < <(echo $"$(get_copytool_event_log)")
3285 if [ -z "$START_EVENT" ]; then
3286 error "Copytool failed to send archive start event to FIFO"
3289 if [ -z "$FINISH_EVENT" ]; then
3290 error "Copytool failed to send archive finish event to FIFO"
3293 echo "Archive events look OK."
3297 copytool_monitor_cleanup
3299 run_test 71 "Copytool logs JSON archive events to FIFO"
3302 # Bump progress interval for livelier events.
3305 # test needs a new running copytool
3307 copytool_monitor_setup
3308 HSMTOOL_UPDATE_INTERVAL=$interval \
3309 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3310 local test_file=$HSMTOOL_MONITOR_DIR/file
3312 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3314 do_facet $SINGLEAGT "$cmd" ||
3315 error "cannot create $test_file on $SINGLEAGT"
3316 copy2archive $test_file $tdir/$tfile
3319 local f=$DIR/$tdir/$tfile
3320 import_file $tdir/$tfile $f
3321 f=$DIR2/$tdir/$tfile
3322 echo "Verifying released state: "
3323 check_hsm_flags $f "0x0000000d"
3325 local fid=$(path2fid $f)
3327 wait_request_state $fid RESTORE SUCCEED
3329 local expected_fields="event_time data_fid source_fid"
3330 expected_fields+=" total_bytes current_bytes"
3334 while read event; do
3335 # Make sure we're not getting anything from previous events.
3336 for field in $expected_fields; do
3340 local parsed=$(parse_json_event "$event")
3341 if [ -z "$parsed" ]; then
3342 error "Copytool sent malformed event: $event"
3346 if [ $event_type == "RESTORE_START" ]; then
3348 if [ $source_fid != $data_fid ]; then
3349 error "source_fid should == data_fid at start"
3352 elif [ $event_type == "RESTORE_FINISH" ]; then
3354 if [ $source_fid != $data_fid ]; then
3355 error "source_fid should == data_fid at finish"
3358 elif [ $event_type != "RESTORE_RUNNING" ]; then
3362 # Do some simple checking of the progress update events.
3363 for expected_field in $expected_fields; do
3364 if [ -z ${!expected_field+x} ]; then
3365 error "Missing $expected_field field in event"
3369 if [ $total_bytes -eq 0 ]; then
3370 error "Expected total_bytes to be > 0"
3373 # When a restore starts out, the data fid is the same as the
3374 # source fid. After the restore has gotten going, we learn
3375 # the new data fid. Once the restore has finished, the source
3376 # fid is set to the new data fid.
3378 # We test this because some monitoring software may depend on
3379 # this behavior. If it changes, then the consumers of these
3380 # events may need to be modified.
3381 if [ $source_fid == $data_fid ]; then
3382 error "source_fid should != data_fid during restore"
3384 done < <(echo $"$(get_copytool_event_log)")
3386 if [ -z "$START_EVENT" ]; then
3387 error "Copytool failed to send restore start event to FIFO"
3390 if [ -z "$FINISH_EVENT" ]; then
3391 error "Copytool failed to send restore finish event to FIFO"
3394 echo "Restore events look OK."
3398 copytool_monitor_cleanup
3402 run_test 72 "Copytool logs JSON restore events to FIFO"
3405 file_count=51 # Max number of files constrained by LNET message size
3406 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3407 local f=$DIR/$tdir/$tfile
3408 local FILELIST=/tmp/filelist.txt
3412 for i in $(seq 1 $file_count); do
3413 fid=$(copy_file /etc/hosts $f.$i)
3414 echo $f.$i >> $FILELIST
3416 # force copytool to use a local/temp archive dir to ensure best
3417 # performance vs remote/NFS mounts used in auto-tests
3418 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3421 local dai=$(get_hsm_param default_archive_id)
3422 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3424 # to be sure wait_all_done will not be mislead by previous tests
3426 wait_for_grace_delay
3427 $LFS hsm_archive --filelist $FILELIST ||
3428 error "cannot archive a file list"
3430 $LFS hsm_release --filelist $FILELIST ||
3431 error "cannot release a file list"
3432 $LFS hsm_restore --filelist $FILELIST ||
3433 error "cannot restore a file list"
3437 run_test 90 "Archive/restore a file list"
3439 double_verify_reset_hsm_param() {
3441 echo "Testing $HSM_PARAM.$p"
3442 local val=$(get_hsm_param $p)
3444 local val2=$(($val * 2))
3445 set_hsm_param $p $val2
3446 val=$(get_hsm_param $p)
3447 [[ $val == $val2 ]] ||
3448 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3449 echo "Set $p to 0 must failed"
3453 set_hsm_param $p $save
3455 if [[ $rc == 0 ]]; then
3456 error "we must not be able to set $HSM_PARAM.$p to 0"
3461 double_verify_reset_hsm_param loop_period
3462 double_verify_reset_hsm_param grace_delay
3463 double_verify_reset_hsm_param active_request_timeout
3464 double_verify_reset_hsm_param max_requests
3465 double_verify_reset_hsm_param default_archive_id
3467 run_test 100 "Set coordinator /proc tunables"
3474 run_test 102 "Verify coordinator control"
3477 # test needs a running copytool
3484 for i in $(seq 1 20); do
3485 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3487 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3491 echo "Current requests"
3492 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3493 $HSM_PARAM.actions |\
3494 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3496 [[ -z "$res" ]] || error "Some request have not been canceled"
3500 run_test 103 "Purge all requests"
3505 # test needs a running copytool
3509 local f=$DIR/$tdir/$tfile
3511 fid=$(make_large_for_progress $f)
3512 [ $? != 0 ] && skip "not enough free space" && return
3514 # if cdt is on, it can serve too quickly the request
3516 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3517 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3518 $HSM_PARAM.actions |\
3519 grep $fid | cut -f16 -d=")
3522 [[ "$data1" == "$DATAHEX" ]] ||
3523 error "Data field in records is ($data1) and not ($DATAHEX)"
3527 run_test 104 "Copy tool data field"
3534 for i in $(seq -w 1 10); do
3535 cp /etc/passwd $DIR/$tdir/$i
3536 $LFS hsm_archive $DIR/$tdir/$i
3538 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3539 $HSM_PARAM.actions |\
3540 grep WAITING | wc -l")
3543 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3544 $HSM_PARAM.actions |\
3545 grep WAITING | wc -l")
3548 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3549 error "Requests count after shutdown $reqcnt2 != "\
3550 "before shutdown $reqcnt1"
3552 run_test 105 "Restart of coordinator"
3554 get_agent_by_uuid_mdt() {
3557 local mds=mds$(($mdtidx + 1))
3558 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3562 check_agent_registered_by_mdt() {
3565 local mds=mds$(($mdtidx + 1))
3566 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3567 if [[ ! -z "$agent" ]]; then
3568 echo "found agent $agent on $mds"
3570 error "uuid $uuid not found in agent list on $mds"
3574 check_agent_unregistered_by_mdt() {
3577 local mds=mds$(($mdtidx + 1))
3578 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3579 if [[ -z "$agent" ]]; then
3580 echo "uuid not found in agent list on $mds"
3582 error "uuid found in agent list on $mds: $agent"
3586 check_agent_registered() {
3589 for mdsno in $(seq 1 $MDSCOUNT); do
3590 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3594 check_agent_unregistered() {
3597 for mdsno in $(seq 1 $MDSCOUNT); do
3598 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3603 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3605 # Lustre mount-point is mandatory and last parameter on
3606 # copytool cmd-line.
3607 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3608 grep -v pgrep | awk '{print $NF}')
3609 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3611 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3615 # test needs a running copytool
3618 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3620 check_agent_registered $uuid
3622 search_copytools || error "No copytool found"
3625 check_agent_unregistered $uuid
3628 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3629 check_agent_registered $uuid
3633 run_test 106 "Copytool register/unregister"
3636 # test needs a running copytool
3638 # create and archive file
3640 local f1=$DIR/$tdir/$tfile
3641 local fid=$(copy_file /etc/passwd $f1)
3642 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3643 wait_request_state $fid ARCHIVE SUCCEED
3644 # shutdown and restart MDS
3646 # check the copytool still gets messages from MDT
3647 local f2=$DIR/$tdir/2
3648 local fid=$(copy_file /etc/passwd $f2)
3649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3650 # main check of this sanity: this request MUST succeed
3651 wait_request_state $fid ARCHIVE SUCCEED
3654 run_test 107 "Copytool re-register after MDS restart"
3656 policy_set_and_test()
3660 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3661 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3662 [[ "$policy" == "$target" ]] ||
3663 error "Wrong policy after '$change': '$policy' != '$target'"
3667 # to force default policy setting if error
3668 CDT_POLICY_HAD_CHANGED=true
3670 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3671 local default="NonBlockingRestore [NoRetryAction]"
3672 [[ "$policy" == "$default" ]] ||
3673 error "default policy has changed,"\
3674 " '$policy' != '$default' update the test"
3675 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3676 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3677 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3678 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3679 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3680 # useless bacause we know but safer for futur changes to use real value
3681 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3682 echo "Next set_param must failed"
3683 policy_set_and_test "wrong" "$policy"
3686 echo "Back to default policy"
3687 cdt_set_sanity_policy
3689 run_test 109 "Policy display/change"
3692 # test needs a running copytool
3697 copy2archive /etc/passwd $tdir/$tfile
3699 local f=$DIR/$tdir/$tfile
3700 import_file $tdir/$tfile $f
3701 local fid=$(path2fid $f)
3703 cdt_set_non_blocking_restore
3708 wait_request_state $fid RESTORE SUCCEED
3709 cdt_clear_non_blocking_restore
3713 error "md5sum returns $st != 1, "\
3714 "should also perror ENODATA (No data available)"
3718 run_test 110a "Non blocking restore policy (import case)"
3721 # test needs a running copytool
3725 local f=$DIR/$tdir/$tfile
3726 local fid=$(copy_file /etc/passwd $f)
3727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3728 wait_request_state $fid ARCHIVE SUCCEED
3731 cdt_set_non_blocking_restore
3736 wait_request_state $fid RESTORE SUCCEED
3737 cdt_clear_non_blocking_restore
3741 error "md5sum returns $st != 1, "\
3742 "should also perror ENODATA (No data available)"
3746 run_test 110b "Non blocking restore policy (release case)"
3749 # test needs a running copytool
3753 copy2archive /etc/passwd $tdir/$tfile
3755 local f=$DIR/$tdir/$tfile
3757 import_file $tdir/$tfile $f
3758 local fid=$(path2fid $f)
3762 copytool_remove_backend $fid
3765 wait_request_state $fid RESTORE FAILED
3772 [[ $st == 0 ]] || error "Restore does not failed"
3776 run_test 111a "No retry policy (import case), restore will error"\
3777 " (No such file or directory)"
3780 # test needs a running copytool
3784 local f=$DIR/$tdir/$tfile
3785 local fid=$(copy_file /etc/passwd $f)
3787 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3788 wait_request_state $fid ARCHIVE SUCCEED
3791 copytool_remove_backend $fid
3794 wait_request_state $fid RESTORE FAILED
3801 [[ $st == 0 ]] || error "Restore does not failed"
3805 run_test 111b "No retry policy (release case), restore will error"\
3806 " (No such file or directory)"
3809 # test needs a running copytool
3813 local f=$DIR/$tdir/$tfile
3814 local fid=$(copy_file /etc/passwd $f)
3816 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3817 local l=$($LFS hsm_action $f)
3819 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3823 wait_request_state $fid ARCHIVE SUCCEED
3826 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3830 run_test 112 "State of recorded request"
3833 # test needs a running copytool
3837 local f=$DIR/$tdir/$tfile
3839 fid=$(make_large_for_cancel $f)
3840 [ $? != 0 ] && skip "not enough free space" && return
3842 # test with cdt on is made in test_221
3844 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3845 # wait archive to register at CDT
3846 wait_request_state $fid ARCHIVE WAITING
3849 wait_request_state $fid ARCHIVE CANCELED
3850 wait_request_state $fid CANCEL SUCCEED
3854 run_test 200 "Register/Cancel archive"
3857 # test needs a running copytool
3861 local f=$DIR/$tdir/$tfile
3862 make_archive $tdir/$tfile
3863 import_file $tdir/$tfile $f
3864 local fid=$(path2fid $f)
3866 # test with cdt on is made in test_222
3869 # wait restore to register at CDT
3870 wait_request_state $fid RESTORE WAITING
3873 wait_request_state $fid RESTORE CANCELED
3874 wait_request_state $fid CANCEL SUCCEED
3878 run_test 201 "Register/Cancel restore"
3881 # test needs a running copytool
3885 local f=$DIR/$tdir/$tfile
3887 fid=$(make_large_for_progress $f)
3888 [ $? != 0 ] && skip "not enough free space" && return
3890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3891 wait_request_state $fid ARCHIVE SUCCEED
3895 # wait remove to register at CDT
3896 wait_request_state $fid REMOVE WAITING
3899 wait_request_state $fid REMOVE CANCELED
3903 run_test 202 "Register/Cancel remove"
3906 # test needs a running copytool
3911 local f=$DIR/$tdir/$tfile
3912 local fid=$(copy_file /etc/passwd $f)
3916 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3917 wait_request_state $fid ARCHIVE SUCCEED
3919 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3923 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3927 run_test 220 "Changelog for archive"
3930 # test needs a running copytool
3935 local f=$DIR/$tdir/$tfile
3937 fid=$(make_large_for_cancel $f)
3938 [ $? != 0 ] && skip "not enough free space" && return
3942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3943 wait_request_state $fid ARCHIVE STARTED
3945 wait_request_state $fid ARCHIVE CANCELED
3946 wait_request_state $fid CANCEL SUCCEED
3948 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3951 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3955 run_test 221 "Changelog for archive canceled"
3958 # test needs a running copytool
3962 copy2archive /etc/passwd $tdir/$tfile
3964 local f=$DIR/$tdir/$tfile
3965 import_file $tdir/$tfile $f
3966 local fid=$(path2fid $f)
3971 wait_request_state $fid RESTORE SUCCEED
3973 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3976 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3980 run_test 222a "Changelog for explicit restore"
3983 # test needs a running copytool
3987 local f=$DIR/$tdir/$tfile
3988 local fid=$(copy_file /etc/passwd $f)
3991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3992 wait_request_state $fid ARCHIVE SUCCEED
3997 wait_request_state $fid RESTORE SUCCEED
3999 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4002 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4006 run_test 222b "Changelog for implicit restore"
4009 # test needs a running copytool
4014 local f=$DIR/$tdir/$tfile
4015 make_archive $tdir/$tfile
4019 import_file $tdir/$tfile $f
4020 local fid=$(path2fid $f)
4023 wait_request_state $fid RESTORE STARTED
4025 wait_request_state $fid RESTORE CANCELED
4026 wait_request_state $fid CANCEL SUCCEED
4028 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4031 [[ $flags == $target ]] ||
4032 error "Changelog flag is $flags not $target"
4036 run_test 223a "Changelog for restore canceled (import case)"
4039 # test needs a running copytool
4044 local f=$DIR/$tdir/$tfile
4046 fid=$(make_large_for_progress $f)
4047 [ $? != 0 ] && skip "not enough free space" && return
4050 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4051 wait_request_state $fid ARCHIVE SUCCEED
4054 wait_request_state $fid RESTORE STARTED
4056 wait_request_state $fid RESTORE CANCELED
4057 wait_request_state $fid CANCEL SUCCEED
4059 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4062 [[ $flags == $target ]] ||
4063 error "Changelog flag is $flags not $target"
4067 run_test 223b "Changelog for restore canceled (release case)"
4070 # test needs a running copytool
4075 local f=$DIR/$tdir/$tfile
4076 local fid=$(copy_file /etc/passwd $f)
4079 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4080 wait_request_state $fid ARCHIVE SUCCEED
4083 wait_request_state $fid REMOVE SUCCEED
4085 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4088 [[ $flags == $target ]] ||
4089 error "Changelog flag is $flags not $target"
4093 run_test 224 "Changelog for remove"
4096 # test needs a running copytool
4099 # test is not usable because remove request is too fast
4100 # so it is always finished before cancel can be done ...
4101 echo "Test disabled"
4106 local f=$DIR/$tdir/$tfile
4108 fid=$(make_large_for_progress $f)
4109 [ $? != 0 ] && skip "not enough free space" && return
4112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4113 wait_request_state $fid ARCHIVE SUCCEED
4115 # if cdt is on, it can serve too quickly the request
4120 wait_request_state $fid REMOVE CANCELED
4121 wait_request_state $fid CANCEL SUCCEED
4123 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4124 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4125 tail -n 1 | awk '{print $5}')
4128 [[ $flags == $target ]] ||
4129 error "Changelog flag is $flags not $target"
4133 run_test 225 "Changelog for remove canceled"
4136 # test needs a running copytool
4141 local f1=$DIR/$tdir/$tfile-1
4142 local f2=$DIR/$tdir/$tfile-2
4143 local f3=$DIR/$tdir/$tfile-3
4144 local fid1=$(copy_file /etc/passwd $f1)
4145 local fid2=$(copy_file /etc/passwd $f2)
4146 copy_file /etc/passwd $f3
4149 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4150 wait_request_state $fid1 ARCHIVE SUCCEED
4152 $LFS hsm_archive $f2
4153 wait_request_state $fid2 ARCHIVE SUCCEED
4155 rm $f1 || error "rm $f1 failed"
4157 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4160 [[ $flags == $target ]] ||
4161 error "Changelog flag is $flags not $target"
4163 mv $f3 $f2 || error "mv $f3 $f2 failed"
4165 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4168 [[ $flags == $target ]] ||
4169 error "Changelog flag is $flags not $target"
4173 run_test 226 "changelog for last rm/mv with exiting archive"
4175 check_flags_changes() {
4183 $LFS hsm_set --$hsm_flag $f ||
4184 error "Cannot set $hsm_flag on $f"
4185 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4186 local seen=${#flags[*]}
4188 [[ $seen == $cnt ]] ||
4189 error "set $hsm_flag: Changelog events $seen != $cnt"
4190 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4191 error "set $hsm_flag: Changelog flags are "\
4192 "${flags[$((cnt - 1))]} not $target"
4194 $LFS hsm_clear --$hsm_flag $f ||
4195 error "Cannot clear $hsm_flag on $f"
4196 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4199 [[ $cnt == $seen ]] ||
4200 error "clear $hsm_flag: Changelog events $seen != $cnt"
4202 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4203 error "clear $hsm_flag: Changelog flag is "\
4204 "${flags[$((cnt - 1))]} not $target"
4208 # test needs a running copytool
4215 for i in norelease noarchive exists archived
4217 local f=$DIR/$tdir/$tfile-$i
4218 local fid=$(copy_file /etc/passwd $f)
4219 check_flags_changes $f $fid $i 0 1
4222 f=$DIR/$tdir/$tfile---lost
4223 fid=$(copy_file /etc/passwd $f)
4224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4225 wait_request_state $fid ARCHIVE SUCCEED
4226 check_flags_changes $f $fid lost 3 1
4230 run_test 227 "changelog when explicit setting of HSM flags"
4233 # test needs a running copytool
4236 local fid=$(make_small_sync $DIR/$tfile)
4237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4238 wait_request_state $fid ARCHIVE SUCCEED
4240 $LFS hsm_release $DIR/$tfile
4241 check_hsm_flags $DIR/$tfile "0x0000000d"
4243 filefrag $DIR/$tfile | grep " 1 extent found" ||
4244 error "filefrag on released file must return only one extent"
4246 # only newer versions of cp detect sparse files by stat/FIEMAP
4248 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4249 error "copying $DIR/$tfile"
4250 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4252 $LFS hsm_release $DIR/$tfile
4253 check_hsm_flags $DIR/$tfile "0x0000000d"
4255 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4257 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4259 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4260 error "comparing untarred $DIR/$tfile"
4262 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4263 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4266 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4269 # test needs a running copytool
4273 local maxrequest=$(get_hsm_param max_requests)
4274 local rqcnt=$(($maxrequest * 3))
4278 for i in $(seq -w 1 $rqcnt); do
4280 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4282 # we do it in 2 steps, so all requests arrive at the same time
4283 for i in $(seq -w 1 $rqcnt); do
4284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4289 while [[ $cnt != 0 || $wt != 0 ]]; do
4291 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4292 $HSM_PARAM.actions |\
4293 grep STARTED | grep -v CANCEL | wc -l")
4294 [[ $cnt -le $maxrequest ]] ||
4295 error "$cnt > $maxrequest too many started requests"
4296 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4297 $HSM_PARAM.actions |\
4298 grep WAITING | wc -l")
4299 echo "max=$maxrequest started=$cnt waiting=$wt"
4304 run_test 250 "Coordinator max request"
4307 # test needs a running copytool
4311 local f=$DIR/$tdir/$tfile
4313 fid=$(make_large_for_cancel $f)
4314 [ $? != 0 ] && skip "not enough free space" && return
4317 # to have a short test
4318 local old_to=$(get_hsm_param active_request_timeout)
4319 set_hsm_param active_request_timeout 4
4320 # to be sure the cdt will wake up frequently so
4321 # it will be able to cancel the "old" request
4322 local old_loop=$(get_hsm_param loop_period)
4323 set_hsm_param loop_period 2
4326 # clear locks to avoid extra delay caused by flush/cancel
4327 # and thus prevent early copytool death to timeout.
4328 cancel_lru_locks osc
4330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4331 wait_request_state $fid ARCHIVE STARTED
4333 wait_request_state $fid ARCHIVE CANCELED
4335 set_hsm_param active_request_timeout $old_to
4336 set_hsm_param loop_period $old_loop
4340 run_test 251 "Coordinator request timeout"
4343 # the only way to test ondisk conf is to restart MDS ...
4344 echo "Stop coordinator and remove coordinator state at mount"
4347 # clean on disk conf set by default
4348 cdt_clear_mount_state
4349 cdt_check_state stopped
4351 # check cdt still off after umount/remount
4353 cdt_check_state stopped
4355 echo "Set coordinator start at mount, and start coordinator"
4356 cdt_set_mount_state enabled
4359 cdt_check_state enabled
4361 # check cdt still on after umount/remount
4363 cdt_check_state enabled
4365 # we are back to original state (cdt started at mount)
4367 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4370 local ai=$(get_hsm_param default_archive_id)
4371 local new=$((ai + 1))
4373 set_hsm_param default_archive_id $new -P
4375 local res=$(get_hsm_param default_archive_id)
4378 set_hsm_param default_archive_id "" "-P -d"
4380 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4382 run_test 301 "HSM tunnable are persistent"
4385 local ai=$(get_hsm_param default_archive_id)
4386 local new=$((ai + 1))
4391 set_hsm_param default_archive_id $new -P
4394 for mdtno in $(seq 1 $MDSCOUNT); do
4399 cdt_check_state enabled
4401 local res=$(get_hsm_param default_archive_id)
4404 set_hsm_param default_archive_id "" "-P -d"
4406 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4408 run_test 302 "HSM tunnable are persistent when CDT is off"
4411 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4417 local dir_mdt0=$DIR/$tdir/mdt0
4418 local dir_mdt1=$DIR/$tdir/mdt1
4420 # create 1 dir per MDT
4421 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4422 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4424 # create 1 file in each MDT
4425 local fid1=$(make_small $dir_mdt0/$tfile)
4426 local fid2=$(make_small $dir_mdt1/$tfile)
4428 # check that hsm request on mdt0 is sent to the right MDS
4429 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4430 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4431 echo "archive successful on mdt0"
4433 # check that hsm request on mdt1 is sent to the right MDS
4434 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4435 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4436 echo "archive successful on mdt1"
4439 # clean test files and directories
4440 rm -rf $dir_mdt0 $dir_mdt1
4442 run_test 400 "Single request is sent to the right MDT"
4445 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4451 local dir_mdt0=$DIR/$tdir/mdt0
4452 local dir_mdt1=$DIR/$tdir/mdt1
4454 # create 1 dir per MDT
4455 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4456 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4458 # create 1 file in each MDT
4459 local fid1=$(make_small $dir_mdt0/$tfile)
4460 local fid2=$(make_small $dir_mdt1/$tfile)
4462 # check that compound requests are shunt to the rights MDTs
4463 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4464 error "lfs hsm_archive"
4465 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4466 echo "archive successful on mdt0"
4467 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4468 echo "archive successful on mdt1"
4471 # clean test files and directories
4472 rm -rf $dir_mdt0 $dir_mdt1
4474 run_test 401 "Compound requests split and sent to their respective MDTs"
4476 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4481 local node=$(facet_active_host $facet)
4483 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4484 awk '{print $4}'); do
4485 echo "$3 $mdc on $node"
4486 do_facet $facet "$LCTL --device $mdc $state" || return 1
4491 # make sure there is no running copytool
4494 # deactivate all mdc on agent1
4495 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4497 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4499 check_agent_unregistered "uuid" # match any agent
4501 # no expected running copytool
4502 search_copytools $agent && error "Copytool start should have failed"
4505 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4507 run_test 402 "Copytool start fails if all MDTs are inactive"
4510 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4512 # make sure there is no running copytool
4515 local agent=$(facet_active_host $SINGLEAGT)
4517 # deactivate all mdc for MDT0001
4518 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4521 local uuid=$(get_agent_uuid $agent)
4522 # check the agent is registered on MDT0000, and not on MDT0001
4523 check_agent_registered_by_mdt $uuid 0
4524 check_agent_unregistered_by_mdt $uuid 1
4526 # check running copytool process
4527 search_copytools $agent || error "No running copytools on $agent"
4529 # reactivate all mdc for MDT0001
4530 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4532 # make sure the copytool is now registered to all MDTs
4533 check_agent_registered $uuid
4537 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4540 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4544 # create files on both MDT0000 and MDT0001
4547 local dir_mdt0=$DIR/$tdir/mdt0
4548 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4550 # create 1 file on mdt0
4551 local fid1=$(make_small $dir_mdt0/$tfile)
4553 # deactivate all mdc for MDT0001
4554 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4556 # send an HSM request for files in MDT0000
4557 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4559 # check for completion of files in MDT0000
4560 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4561 echo "archive successful on mdt0"
4563 # reactivate all mdc for MDT0001
4564 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4567 # clean test files and directories
4570 run_test 404 "Inactive MDT does not block requests for active MDTs"
4573 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4579 local striped_dir=$DIR/$tdir/striped_dir
4581 # create striped dir on all of MDTs
4582 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4584 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4585 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4586 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4587 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4589 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4590 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4591 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4592 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4594 # check that compound requests are shunt to the rights MDTs
4595 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4596 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4597 error "lfs hsm_archive"
4599 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4600 echo "archive successful on $fid1"
4601 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4602 echo "archive successful on $fid2"
4603 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4604 echo "archive successful on $fid3"
4605 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4606 echo "archive successful on $fid4"
4608 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4609 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4610 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4611 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4613 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4614 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4615 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4616 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4620 run_test 405 "archive and release under striped directory"
4623 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4625 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4626 skip "need MDS version at least 2.7.64" && return 0
4633 fid=$(make_small $DIR/$tdir/$tfile)
4636 $LFS hsm_archive $DIR/$tdir/$tfile
4637 wait_request_state "$fid" ARCHIVE SUCCEED
4638 $LFS hsm_release $DIR/$tdir/$tfile
4640 # Should migrate $tdir but not $tfile.
4641 $LFS mv -M1 $DIR/$tdir &&
4642 error "migrating HSM an archived file should fail"
4644 $LFS hsm_restore $DIR/$tdir/$tfile
4645 wait_request_state "$fid" RESTORE SUCCEED
4647 $LFS hsm_remove $DIR/$tdir/$tfile
4648 wait_request_state "$fid" REMOVE SUCCEED
4650 cat $DIR/$tdir/$tfile > /dev/null ||
4651 error "cannot read $DIR/$tdir/$tfile"
4653 $LFS mv -M1 $DIR/$tdir ||
4654 error "cannot complete migration after HSM remove"
4656 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4657 if ((mdt_index != 1)); then
4658 error "expected MDT index 1, got $mdt_index"
4661 # Refresh fid after migration.
4662 fid=$(path2fid $DIR/$tdir/$tfile)
4665 $LFS hsm_archive $DIR/$tdir/$tfile
4666 wait_request_state "$fid" ARCHIVE SUCCEED 1
4668 lctl set_param debug=+trace
4669 $LFS hsm_release $DIR/$tdir/$tfile ||
4670 error "cannot release $DIR/$tdir/$tfile"
4672 $LFS hsm_restore $DIR/$tdir/$tfile
4673 wait_request_state "$fid" RESTORE SUCCEED 1
4675 cat $DIR/$tdir/$tfile > /dev/null ||
4676 error "cannot read $DIR/$tdir/$tfile"
4680 run_test 406 "attempting to migrate HSM archived files is safe"
4684 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4685 skip "HSM migrate is not supported" && return
4687 # Stop the existing copytool
4690 test_mkdir -p $DIR/$tdir
4691 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4693 run_test 500 "various LLAPI HSM tests"
4698 check_and_cleanup_lustre