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 echo "copytools failed to stop in ${wait_timeout}s"
180 copytool_monitor_setup() {
181 local facet=${1:-$SINGLEAGT}
182 local agent=$(facet_active_host $facet)
184 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
185 local test_dir=$(do_node $agent "$cmd") ||
186 error "Failed to create tempdir on $agent"
187 export HSMTOOL_MONITOR_DIR=$test_dir
189 # Create the fifo and a monitor (cat dies when copytool dies)
190 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
191 error "failed to create copytool fifo on $agent"
192 cmd="cat $test_dir/fifo > $test_dir/events &"
193 cmd+=" echo \\\$! > $test_dir/monitor_pid"
195 if [[ $PDSH == *Rmrsh* ]]; then
196 # This is required for pdsh -Rmrsh and its handling of remote
198 # Regular ssh and pdsh -Rssh work fine without this
199 # backgrounded subshell nonsense.
200 (do_node $agent "$cmd") &
201 export HSMTOOL_MONITOR_PDSH=$!
203 # Slightly racy, but just making a best-effort to catch obvious
206 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
207 error "Failed to start copytool monitor on $agent"
209 do_node $agent "$cmd"
211 error "Failed to start copytool monitor on $agent"
216 copytool_monitor_cleanup() {
217 local facet=${1:-$SINGLEAGT}
218 local agent=$(facet_active_host $facet)
220 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
221 # Should die when the copytool dies, but just in case.
222 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
223 cmd+=" 2>/dev/null || true"
224 do_node $agent "$cmd"
225 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
226 export HSMTOOL_MONITOR_DIR=
229 # The pdsh should die on its own when the monitor dies. Just
230 # in case, though, try to clean up to avoid any cruft.
231 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
232 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
233 export HSMTOOL_MONITOR_PDSH=
238 local facet=${1:-$SINGLEAGT}
239 # Use MOUNT2 by default if defined
240 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
242 local hsm_root=${4:-$(copytool_device $facet)}
243 local agent=$(facet_active_host $facet)
245 if [[ -z "$arc_id" ]] &&
246 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
247 echo "Only wakeup running copytool $facet on $agent"
251 if $HSM_ARCHIVE_PURGE; then
252 echo "Purging archive on $agent"
253 do_facet $facet "rm -rf $hsm_root/*"
256 echo "Starting copytool $facet on $agent"
257 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
258 # bandwidth is limited to 1MB/s so the copy time is known and
259 # independent of hardware
260 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
261 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
262 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
263 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
264 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
265 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
266 cmd+=" --bandwidth 1 $lustre_mntpnt"
268 # Redirect the standard output and error to a log file which
269 # can be uploaded to Maloo.
270 local prefix=$TESTLOG_PREFIX
271 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
272 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
274 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
275 if [[ $? != 0 ]]; then
276 [[ $HSMTOOL_NOERROR == true ]] ||
277 error "start copytool $facet on $agent failed"
278 echo "start copytool $facet on $agent failed"
284 get_copytool_event_log() {
285 local facet=${1:-$SINGLEAGT}
286 local agent=$(facet_active_host $facet)
288 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
289 error "Can't get event log: No monitor directory!"
291 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
292 error "Could not collect event log from $agent"
297 local agt_facet=$SINGLEAGT
298 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
299 local hsm_root=$(copytool_device $agt_facet)
305 kill_copytools $agt_hosts
306 wait_copytools $agt_hosts || error "copytools failed to stop"
308 # Clean all CDTs orphans requests from previous tests that
309 # would otherwise need to timeout to clear.
310 for ((i = 0; i < MDSCOUNT; i++)); do
312 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
313 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
315 # Skip already stopping or stopped CDTs.
316 [[ "${state[$i]}" =~ ^stop ]] && continue
318 do_facet $facet "$LCTL set_param $param=shutdown"
321 for ((i = 0; i < MDSCOUNT; i++)); do
322 # Only check and restore CDTs that we stopped in the first loop.
323 [[ "${state[$i]}" =~ ^stop ]] && continue
326 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
328 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
329 error "$facet CDT state is not stopped"
331 # Restore old CDT state.
332 do_facet $facet "$LCTL set_param $param=${state[$i]}"
335 for ((i = 0; i < MDSCOUNT; i++)); do
336 # Only check CDTs that we stopped in the first loop.
337 [[ "${state[$i]}" =~ ^stop ]] && continue
340 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
342 # Check that the old CDT state was restored.
343 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
344 20 || error "$facet CDT state is not '${state[$i]}'"
347 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
348 do_facet $agt_facet "rm -rf $hsm_root/*"
353 local agents=${1:-$(facet_active_host $SINGLEAGT)}
355 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
356 echo "Copytool is suspended on $agents"
359 copytool_remove_backend() {
361 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
362 echo "Remove from backend: $fid = $be"
363 do_facet $SINGLEAGT rm -f $be
367 do_facet $SINGLEAGT \
368 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
369 --import $1 $2 $MOUNT" ||
370 error "import of $1 to $2 failed"
374 local file=$HSM_ARCHIVE/$1
375 do_facet $SINGLEAGT mkdir -p $(dirname $file)
376 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
377 file_creation_failure dd $file $?
381 local file=$HSM_ARCHIVE/$2
382 do_facet $SINGLEAGT mkdir -p $(dirname $file)
383 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
392 if [[ "$value" != "" ]]; then
395 for mdtno in $(seq 1 $MDSCOUNT); do
396 local idx=$(($mdtno - 1))
397 local facet=mds${mdtno}
398 # if $arg include -P option, run 1 set_param per MDT on the MGS
399 # else, run set_param on each MDT
400 [[ $arg = *"-P"* ]] && facet=mgs
401 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
402 [[ $? != 0 ]] && rc=1
412 for mdtno in $(seq 1 $MDSCOUNT); do
413 local idx=$(($mdtno - 1))
414 wait_result mds${mdtno} \
415 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
417 error "$key state is not '$target' on mds${mdtno}"
424 for mdtno in $(seq 1 $MDSCOUNT); do
425 local idx=$(($mdtno - 1))
426 local cl_user=$(do_facet mds${mdtno} $LCTL \
427 --device ${MDT[$idx]} \
428 changelog_register -n)
430 do_facet mds${mdtno} lctl set_param \
431 mdd.${MDT[$idx]}.changelog_mask="+hsm"
432 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
436 changelog_cleanup() {
438 for mdtno in $(seq 1 $MDSCOUNT); do
439 local idx=$(($mdtno - 1))
440 [[ -z ${CL_USERS[$idx]} ]] && continue
441 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
442 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
443 changelog_deregister ${CL_USERS[$idx]}
448 changelog_get_flags() {
453 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
458 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
466 mdts_set_param "$opt -n" "hsm.$param" "$value"
473 mdts_set_param "" hsm_control "$cmd"
474 mdts_check_param hsm_control "$target" 10
477 cdt_set_sanity_policy() {
478 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
481 mdts_set_param "" hsm.policy "+NRA"
482 mdts_set_param "" hsm.policy "-NBR"
483 CDT_POLICY_HAD_CHANGED=
488 mdts_set_param "" hsm.policy "+NRA"
489 CDT_POLICY_HAD_CHANGED=true
492 cdt_clear_no_retry() {
493 mdts_set_param "" hsm.policy "-NRA"
494 CDT_POLICY_HAD_CHANGED=true
497 cdt_set_non_blocking_restore() {
498 mdts_set_param "" hsm.policy "+NBR"
499 CDT_POLICY_HAD_CHANGED=true
502 cdt_clear_non_blocking_restore() {
503 mdts_set_param "" hsm.policy "-NBR"
504 CDT_POLICY_HAD_CHANGED=true
507 cdt_clear_mount_state() {
508 mdts_set_param "-P -d" hsm_control ""
511 cdt_set_mount_state() {
512 mdts_set_param "-P" hsm_control "$1"
513 # set_param -P is asynchronous operation and could race with set_param.
514 # In such case configs could be retrieved and applied at mgc after
515 # set_param -P completion. Sleep here to avoid race with set_param.
516 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
517 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
518 # and 10 seconds to retrieve config from server.
523 mdts_check_param hsm_control "$1" 20
527 set_test_state disabled disabled
531 set_test_state enabled enabled
535 set_test_state shutdown stopped
539 set_test_state purge enabled
545 cdt_set_sanity_policy
549 local client_count=$1
550 if [[ $CLIENTCOUNT -lt $client_count ]]; then
551 skip "Need $client_count or more clients, have $CLIENTCOUNT"
558 $LFS path2fid $1 | tr -d '[]'
559 return ${PIPESTATUS[0]}
567 if [[ $u == "user" ]]; then
568 st=$($RUNAS $LFS hsm_state $f)
571 st=$($LFS hsm_state $f)
574 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
576 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
580 get_hsm_archive_id() {
583 st=$($LFS hsm_state $f)
584 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
586 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
595 local st=$(get_hsm_flags $f)
596 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
599 check_hsm_flags_user() {
603 local st=$(get_hsm_flags $f user)
604 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
607 file_creation_failure() {
612 df $MOUNT $MOUNT2 >&2
613 error "cannot create $f with $cmd, status=$err"
625 if [[ "$3" != 1 ]]; then
629 cp $1 $f || file_creation_failure cp $f $?
631 path2fid $f || error "cannot get fid on $f"
635 local file2=${1/$DIR/$DIR2}
636 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
637 file_creation_failure dd $file2 $?
639 path2fid $1 || error "cannot get fid on $1"
643 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
644 file_creation_failure dd $1 $?
645 path2fid $1 || error "cannot get fid on $1"
648 cleanup_large_files() {
649 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
651 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
654 check_enough_free_space() {
657 local need=$((nb * unit /1024))
658 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
659 (( $need >= $free )) && return 1
663 make_large_for_striping() {
664 local file2=${1/$DIR/$DIR2}
665 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
669 check_enough_free_space 5 $sz
670 [ $? != 0 ] && return $?
672 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
673 file_creation_failure dd $file2 $?
675 path2fid $1 || error "cannot get fid on $1"
678 make_large_for_progress() {
679 local file2=${1/$DIR/$DIR2}
683 check_enough_free_space 39 1000000
684 [ $? != 0 ] && return $?
686 # big file is large enough, so copy time is > 30s
687 # so copytool make 1 progress
688 # size is not a multiple of 1M to avoid stripe
690 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
691 file_creation_failure dd $file2 $?
693 path2fid $1 || error "cannot get fid on $1"
696 make_large_for_progress_aligned() {
697 local file2=${1/$DIR/$DIR2}
701 check_enough_free_space 33 1048576
702 [ $? != 0 ] && return $?
704 # big file is large enough, so copy time is > 30s
705 # so copytool make 1 progress
706 # size is a multiple of 1M to have stripe
708 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
709 file_creation_failure dd $file2 $?
710 path2fid $1 || error "cannot get fid on $1"
713 make_large_for_cancel() {
714 local file2=${1/$DIR/$DIR2}
718 check_enough_free_space 103 1048576
719 [ $? != 0 ] && return $?
721 # Copy timeout is 100s. 105MB => 105s
722 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
723 file_creation_failure dd $file2 $?
724 path2fid $1 || error "cannot get fid on $1"
730 wait_update --verbose $(facet_active_host $facet) "$@"
733 wait_request_state() {
737 # 4th arg (mdt index) is optional
739 local mds=mds$(($mdtidx + 1))
741 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
742 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
744 wait_result $mds "$cmd" $state 200 ||
745 error "request on $fid is not $state on $mds"
748 get_request_state() {
752 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
753 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
756 get_request_count() {
760 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
761 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
768 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
769 [[ -n $fid ]] && cmd+=" | grep '$fid'"
770 cmd+=" | egrep 'WAITING|STARTED'"
772 wait_result $SINGLEMDS "$cmd" "" $timeout ||
773 error "requests did not complete"
776 wait_for_grace_delay() {
777 local val=$(get_hsm_param grace_delay)
784 # python2.6 in EL6 includes an internal json module
785 local json_parser='import json; import fileinput;'
786 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
787 json_parser+='json.loads([line for line in '
788 json_parser+='fileinput.input()][0]).items()])'
790 echo $raw_event | python -c "$json_parser"
793 # populate MDT device array
799 # cleanup from previous bad setup
802 # for recovery tests, coordinator needs to be started at mount
804 # the lustre conf must be without hsm on (like for sanity.sh)
805 echo "Set HSM on and start"
806 cdt_set_mount_state enabled
807 cdt_check_state enabled
809 echo "Start copytool"
812 echo "Set sanity-hsm HSM policy"
813 cdt_set_sanity_policy
815 # finished requests are quickly removed from list
816 set_hsm_param grace_delay 10
822 local f=$DIR/$tdir/$tfile
826 check_hsm_flags_user $f "0x00000000"
828 $RUNAS $LFS hsm_set --norelease $f ||
829 error "user could not change hsm flags"
830 check_hsm_flags_user $f "0x00000010"
832 $RUNAS $LFS hsm_clear --norelease $f ||
833 error "user could not clear hsm flags"
834 check_hsm_flags_user $f "0x00000000"
836 # User could not change those flags...
837 $RUNAS $LFS hsm_set --exists $f &&
838 error "user should not set this flag"
839 check_hsm_flags_user $f "0x00000000"
842 $LFS hsm_set --exists $f ||
843 error "root could not change hsm flags"
844 check_hsm_flags_user $f "0x00000001"
846 $LFS hsm_clear --exists $f ||
847 error "root could not clear hsm state"
848 check_hsm_flags_user $f "0x00000000"
851 run_test 1 "lfs hsm flags root/non-root access"
855 local f=$DIR/$tdir/$tfile
856 local fid=$(make_small $f)
858 $LFS hsm_archive $f || error "could not archive file"
859 wait_request_state $fid ARCHIVE SUCCEED
861 # Release and check states
862 $LFS hsm_release $f || error "could not release file"
863 echo -n "Verifying released state: "
864 check_hsm_flags $f "0x0000000d"
866 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
868 run_test 1a "mmap & cat a HSM released file"
872 local f=$DIR/$tdir/$tfile
874 # New files are not dirty
875 check_hsm_flags $f "0x00000000"
877 # For test, we simulate an archived file.
878 $LFS hsm_set --exists $f || error "user could not change hsm flags"
879 check_hsm_flags $f "0x00000001"
881 # chmod do not put the file dirty
882 chmod 600 $f || error "could not chmod test file"
883 check_hsm_flags $f "0x00000001"
885 # chown do not put the file dirty
886 chown $RUNAS_ID $f || error "could not chown test file"
887 check_hsm_flags $f "0x00000001"
889 # truncate put the file dirty
890 $TRUNCATE $f 1 || error "could not truncate test file"
891 check_hsm_flags $f "0x00000003"
893 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
894 check_hsm_flags $f "0x00000001"
896 run_test 2 "Check file dirtyness when doing setattr"
902 # New files are not dirty
904 check_hsm_flags $f "0x00000000"
906 # For test, we simulate an archived file.
907 $LFS hsm_set --exists $f ||
908 error "user could not change hsm flags"
909 check_hsm_flags $f "0x00000001"
911 # Reading a file, does not set dirty
912 cat $f > /dev/null || error "could not read file"
913 check_hsm_flags $f "0x00000001"
915 # Open for write without modifying data, does not set dirty
916 openfile -f O_WRONLY $f || error "could not open test file"
917 check_hsm_flags $f "0x00000001"
919 # Append to a file sets it dirty
920 cp -p /etc/passwd $f.append || error "could not create file"
921 $LFS hsm_set --exists $f.append ||
922 error "user could not change hsm flags"
923 dd if=/etc/passwd of=$f.append bs=1 count=3\
924 conv=notrunc oflag=append status=noxfer ||
925 file_creation_failure dd $f.append $?
926 check_hsm_flags $f.append "0x00000003"
928 # Modify a file sets it dirty
929 cp -p /etc/passwd $f.modify || error "could not create file"
930 $LFS hsm_set --exists $f.modify ||
931 error "user could not change hsm flags"
932 dd if=/dev/zero of=$f.modify bs=1 count=3\
933 conv=notrunc status=noxfer ||
934 file_creation_failure dd $f.modify $?
935 check_hsm_flags $f.modify "0x00000003"
937 # Open O_TRUNC sets dirty
938 cp -p /etc/passwd $f.trunc || error "could not create file"
939 $LFS hsm_set --exists $f.trunc ||
940 error "user could not change hsm flags"
941 cp /etc/group $f.trunc || error "could not override a file"
942 check_hsm_flags $f.trunc "0x00000003"
944 # Mmapped a file sets dirty
945 cp -p /etc/passwd $f.mmap || error "could not create file"
946 $LFS hsm_set --exists $f.mmap ||
947 error "user could not change hsm flags"
948 multiop $f.mmap OSMWUc || error "could not mmap a file"
949 check_hsm_flags $f.mmap "0x00000003"
951 run_test 3 "Check file dirtyness when opening for write"
955 local f=$DIR/$tdir/$tfile
956 local fid=$(make_small $f)
959 local st=$(get_request_state $fid CANCEL)
960 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
962 run_test 4 "Useless cancel must not be registered"
965 # test needs a running copytool
969 local f=$DIR/$tdir/$tfile
970 local fid=$(copy_file /etc/passwd $f)
972 wait_request_state $fid ARCHIVE SUCCEED
974 check_hsm_flags $f "0x00000009"
978 run_test 8 "Test default archive number"
982 local f=$DIR/$tdir/$tfile
983 local fid=$(copy_file /etc/passwd $f)
984 # we do not use the default one to be sure
985 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
987 copytool_setup $SINGLEAGT $MOUNT $new_an
988 $LFS hsm_archive --archive $new_an $f
989 wait_request_state $fid ARCHIVE SUCCEED
991 check_hsm_flags $f "0x00000009"
995 run_test 9 "Use of explicit archive number, with dedicated copytool"
998 needclients 3 || return 0
1004 copytool_cleanup $(comma_list $(agts_nodes))
1006 # start all of the copytools
1007 for n in $(seq $AGTCOUNT); do
1008 copytool_setup agt$n
1011 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1014 for n in $(seq $AGTCOUNT); do
1015 file=$DIR/$tdir/$tfile.$n
1016 fid=$(make_small $file)
1018 $LFS hsm_archive $file || error "could not archive file $file"
1019 wait_request_state $fid ARCHIVE SUCCEED
1020 check_hsm_flags $file "0x00000009"
1024 copytool_cleanup $(comma_list $(agts_nodes))
1026 run_test 9a "Multiple remote agents"
1029 # test needs a running copytool
1032 mkdir -p $DIR/$tdir/d1
1033 local f=$DIR/$tdir/$tfile
1034 local fid=$(copy_file /etc/hosts $f)
1035 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1036 error "hsm_archive failed"
1037 wait_request_state $fid ARCHIVE SUCCEED
1039 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1040 error "fid $fid not in archive $HSM_ARCHIVE"
1041 echo "Verifying content"
1042 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1043 echo "Verifying hsm state "
1044 check_hsm_flags $f "0x00000009"
1046 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1047 local st=$(get_hsm_archive_id $f)
1048 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1049 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1054 run_test 10a "Archive a file"
1057 # test needs a running copytool
1061 local f=$DIR/$tdir/$tfile
1062 local fid=$(copy_file /etc/hosts $f)
1063 $LFS hsm_archive $f || error "archive request failed"
1064 wait_request_state $fid ARCHIVE SUCCEED
1066 $LFS hsm_archive $f || error "archive of non dirty file failed"
1067 local cnt=$(get_request_count $fid ARCHIVE)
1068 [[ "$cnt" == "1" ]] ||
1069 error "archive of non dirty file must not make a request"
1073 run_test 10b "Archive of non dirty file must work without doing request"
1076 # test needs a running copytool
1080 local f=$DIR/$tdir/$tfile
1081 local fid=$(copy_file /etc/hosts $f)
1082 $LFS hsm_set --noarchive $f
1083 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1087 run_test 10c "Check forbidden archive"
1090 # test needs a running copytool
1094 local f=$DIR/$tdir/$tfile
1095 local fid=$(copy_file /etc/hosts $f)
1096 $LFS hsm_archive $f || error "cannot archive $f"
1097 wait_request_state $fid ARCHIVE SUCCEED
1099 local ar=$(get_hsm_archive_id $f)
1100 local dflt=$(get_hsm_param default_archive_id)
1101 [[ $ar == $dflt ]] ||
1102 error "archived file is not on default archive: $ar != $dflt"
1106 run_test 10d "Archive a file on the default archive id"
1110 copy2archive /etc/hosts $tdir/$tfile
1111 local f=$DIR/$tdir/$tfile
1113 import_file $tdir/$tfile $f
1114 echo -n "Verifying released state: "
1115 check_hsm_flags $f "0x0000000d"
1117 local LSZ=$(stat -c "%s" $f)
1118 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1120 echo "Verifying imported size $LSZ=$ASZ"
1121 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1122 echo -n "Verifying released pattern: "
1123 local PTRN=$($GETSTRIPE -L $f)
1125 [[ $PTRN == 80000001 ]] || error "Is not released"
1126 local fid=$(path2fid $f)
1127 echo "Verifying new fid $fid in archive"
1129 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1130 error "fid $fid not in archive $HSM_ARCHIVE"
1132 run_test 11a "Import a file"
1135 # test needs a running copytool
1139 local f=$DIR/$tdir/$tfile
1140 local fid=$(copy_file /etc/hosts $f)
1141 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1142 error "hsm_archive failed"
1143 wait_request_state $fid ARCHIVE SUCCEED
1145 local FILE_HASH=$(md5sum $f)
1150 echo "$FILE_HASH" | md5sum -c
1152 [[ $? -eq 0 ]] || error "Restored file differs"
1156 run_test 11b "Import a deleted file using its FID"
1159 # test needs a running copytool
1163 copy2archive /etc/hosts $tdir/$tfile
1165 local f=$DIR/$tdir/$tfile
1166 import_file $tdir/$tfile $f
1167 local f2=$DIR2/$tdir/$tfile
1168 echo "Verifying released state: "
1169 check_hsm_flags $f2 "0x0000000d"
1171 local fid=$(path2fid $f2)
1172 $LFS hsm_restore $f2
1173 wait_request_state $fid RESTORE SUCCEED
1175 echo "Verifying file state: "
1176 check_hsm_flags $f2 "0x00000009"
1178 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1180 [[ $? -eq 0 ]] || error "Restored file differs"
1184 run_test 12a "Restore an imported file explicitly"
1187 # test needs a running copytool
1191 copy2archive /etc/hosts $tdir/$tfile
1193 local f=$DIR/$tdir/$tfile
1194 import_file $tdir/$tfile $f
1195 echo "Verifying released state: "
1196 check_hsm_flags $f "0x0000000d"
1198 cat $f > /dev/null || error "File read failed"
1200 echo "Verifying file state after restore: "
1201 check_hsm_flags $f "0x00000009"
1203 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1205 [[ $? -eq 0 ]] || error "Restored file differs"
1209 run_test 12b "Restore an imported file implicitly"
1212 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1214 # test needs a running copytool
1218 local f=$DIR/$tdir/$tfile
1219 $LFS setstripe -c 2 $f
1221 fid=$(make_large_for_striping $f)
1222 [ $? != 0 ] && skip "not enough free space" && return
1224 local FILE_CRC=$(md5sum $f)
1226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1227 wait_request_state $fid ARCHIVE SUCCEED
1228 $LFS hsm_release $f || error "release $f failed"
1230 echo "$FILE_CRC" | md5sum -c
1232 [[ $? -eq 0 ]] || error "Restored file differs"
1236 run_test 12c "Restore a file with stripe of 2"
1239 # test needs a running copytool
1244 local f=$DIR/$tdir/$tfile
1245 local fid=$(copy_file /etc/hosts $f)
1246 $LFS hsm_restore $f || error "restore of non archived file failed"
1247 local cnt=$(get_request_count $fid RESTORE)
1248 [[ "$cnt" == "0" ]] ||
1249 error "restore non archived must not make a request"
1250 $LFS hsm_archive $f ||
1251 error "archive request failed"
1252 wait_request_state $fid ARCHIVE SUCCEED
1253 $LFS hsm_restore $f ||
1254 error "restore of non released file failed"
1255 local cnt=$(get_request_count $fid RESTORE)
1256 [[ "$cnt" == "0" ]] ||
1257 error "restore a non dirty file must not make a request"
1261 run_test 12d "Restore of a non archived, non released file must work"\
1262 " without doing request"
1265 # test needs a running copytool
1268 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1269 local f=$DIR/$tdir/$tfile
1270 local fid=$(copy_file /etc/hosts $f)
1271 $LFS hsm_archive $f || error "archive request failed"
1272 wait_request_state $fid ARCHIVE SUCCEED
1275 cat /etc/hosts >> $f
1279 $LFS hsm_restore $f && error "restore a dirty file must fail"
1283 run_test 12e "Check forbidden restore"
1286 # test needs a running copytool
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/hosts $f)
1293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1294 wait_request_state $fid ARCHIVE SUCCEED
1295 $LFS hsm_release $f || error "release of $f failed"
1297 wait_request_state $fid RESTORE SUCCEED
1299 echo -n "Verifying file state: "
1300 check_hsm_flags $f "0x00000009"
1302 diff -q /etc/hosts $f
1304 [[ $? -eq 0 ]] || error "Restored file differs"
1308 run_test 12f "Restore a released file explicitly"
1311 # test needs a running copytool
1315 local f=$DIR/$tdir/$tfile
1316 local fid=$(copy_file /etc/hosts $f)
1318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1319 wait_request_state $fid ARCHIVE SUCCEED
1320 $LFS hsm_release $f || error "release of $f failed"
1322 diff -q /etc/hosts $f
1325 # we check we had a restore done
1326 wait_request_state $fid RESTORE SUCCEED
1328 [[ $st -eq 0 ]] || error "Restored file differs"
1332 run_test 12g "Restore a released file implicitly"
1335 needclients 2 || return 0
1337 # test needs a running copytool
1341 local f=$DIR/$tdir/$tfile
1342 local fid=$(copy_file /etc/hosts $f)
1344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1345 wait_request_state $fid ARCHIVE SUCCEED
1346 $LFS hsm_release $f || error "release of $f failed"
1348 do_node $CLIENT2 diff -q /etc/hosts $f
1351 # we check we had a restore done
1352 wait_request_state $fid RESTORE SUCCEED
1354 [[ $st -eq 0 ]] || error "Restored file differs"
1358 run_test 12h "Restore a released file implicitly from a second node"
1361 # test needs a running copytool
1365 local f=$DIR/$tdir/$tfile
1366 local fid=$(copy_file /etc/passwd $f)
1367 $LFS hsm_archive $f || error "archive of $f failed"
1368 wait_request_state $fid ARCHIVE SUCCEED
1370 $LFS hsm_release $f || error "release of $f failed"
1374 [[ $? -eq 0 ]] || error "Restored file differs"
1378 run_test 12m "Archive/release/implicit restore"
1381 # test needs a running copytool
1385 copy2archive /etc/hosts $tdir/$tfile
1387 local f=$DIR/$tdir/$tfile
1388 import_file $tdir/$tfile $f
1390 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1391 error "Restored file differs"
1393 $LFS hsm_release $f || error "release of $f failed"
1397 run_test 12n "Import/implicit restore/release"
1400 # test needs a running copytool
1404 local f=$DIR/$tdir/$tfile
1405 local fid=$(copy_file /etc/hosts $f)
1407 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1408 wait_request_state $fid ARCHIVE SUCCEED
1409 $LFS hsm_release $f || error "release of $f failed"
1411 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1412 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1414 # set no retry action mode
1417 diff -q /etc/hosts $f
1420 # we check we had a restore failure
1421 wait_request_state $fid RESTORE FAILED
1423 [[ $st -eq 0 ]] && error "Restore must fail"
1425 # remove no retry action mode
1428 # check file is still released
1429 check_hsm_flags $f "0x0000000d"
1431 # retry w/o failure injection
1432 do_facet $SINGLEMDS lctl set_param fail_loc=0
1434 # to be sure previous RESTORE result is gone
1436 wait_for_grace_delay
1438 diff -q /etc/hosts $f
1441 # we check we had a restore done
1442 wait_request_state $fid RESTORE SUCCEED
1444 [[ $st -eq 0 ]] || error "Restored file differs"
1448 run_test 12o "Layout-swap failure during Restore leaves file released"
1451 # test needs a running copytool
1455 local f=$DIR/$tdir/$tfile
1456 local fid=$(copy_file /etc/hosts $f)
1458 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1459 wait_request_state $fid ARCHIVE SUCCEED
1460 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1461 $LFS hsm_release $f || error "cannot release $f"
1462 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1463 $LFS hsm_release $f || error "cannot release $f"
1464 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1468 run_test 12p "implicit restore of a file on copytool mount point"
1470 cleanup_test_12q() {
1472 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1473 error "cannot umount $MOUNT3 on $SINGLEAGT"
1477 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1478 skip "need MDS version at least 2.7.58" && return 0
1480 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1481 error "cannot mount $MOUNT3 on $SINGLEAGT"
1483 trap cleanup_test_12q EXIT
1485 # test needs a running copytool
1486 copytool_setup $SINGLEAGT $MOUNT3
1489 local f=$DIR/$tdir/$tfile
1490 local f2=$DIR2/$tdir/$tfile
1491 local fid=$(make_small $f)
1492 local orig_size=$(stat -c "%s" $f)
1494 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1495 wait_request_state $fid ARCHIVE SUCCEED
1497 $LFS hsm_release $f || error "could not release file"
1498 check_hsm_flags $f "0x0000000d"
1501 wait_copytools || error "copytool failed to stop"
1503 cat $f > /dev/null &
1505 # wait a bit to allow implicit restore request to be handled.
1506 # if not, next stat would also block on layout-lock.
1509 local size=$(stat -c "%s" $f2)
1510 [ $size -eq $orig_size ] ||
1511 error "$f2: wrong size after archive: $size != $orig_size"
1513 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1517 size=$(stat -c "%s" $f)
1518 [ $size -eq $orig_size ] ||
1519 error "$f: wrong size after restore: $size != $orig_size"
1521 size=$(stat -c "%s" $f2)
1522 [ $size -eq $orig_size ] ||
1523 error "$f2: wrong size after restore: $size != $orig_size"
1527 size=$(stat -c "%s" $f)
1529 error "$f: wrong size after overwrite: $size != 0"
1531 size=$(stat -c "%s" $f2)
1533 error "$f2: wrong size after overwrite: $size != 0"
1536 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1537 error "cannot umount $MOUNT3 on $SINGLEAGT"
1539 run_test 12q "file attributes are refreshed after restore"
1542 # test needs a running copytool
1545 local ARC_SUBDIR="import.orig"
1549 # populate directory to be imported
1550 for d in $(seq 1 10); do
1551 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1552 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1553 for f in $(seq 1 10); do
1554 CURR_FILE="$CURR_DIR/$tfile.$f"
1555 # write file-specific data
1556 do_facet $SINGLEAGT \
1557 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1558 "file=$CURR_FILE > $CURR_FILE"
1562 import_file "$ARC_SUBDIR" $DIR/$tdir
1563 # diff lustre content and origin (triggers file restoration)
1564 # there must be 10x10 identical files, and no difference
1565 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1566 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1567 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1568 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1570 [ $cnt_diff -eq 0 ] ||
1571 error "$cnt_diff imported files differ from read data"
1572 [ $cnt_ok -eq 100 ] ||
1573 error "not enough identical files ($cnt_ok != 100)"
1577 run_test 13 "Recursively import and restore a directory"
1580 # test needs a running copytool
1585 local f=$DIR/$tdir/$tfile
1586 local fid=$(make_small $f)
1587 local sum=$(md5sum $f | awk '{print $1}')
1588 $LFS hsm_archive $f || error "could not archive file"
1589 wait_request_state $fid ARCHIVE SUCCEED
1593 # create released file (simulate llapi_hsm_import call)
1595 local fid2=$(path2fid $f)
1596 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1597 $LFS hsm_release $f || error "could not release file"
1599 # rebind the archive to the newly created file
1600 echo "rebind $fid to $fid2"
1602 do_facet $SINGLEAGT \
1603 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1604 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1606 # restore file and compare md5sum
1607 local sum2=$(md5sum $f | awk '{print $1}')
1609 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1613 run_test 14 "Rebind archived file to a new fid"
1616 # test needs a running copytool
1621 local f=$DIR/$tdir/$tfile
1623 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1627 for i in $(seq 1 $count); do
1628 fids[$i]=$(make_small $f.$i)
1629 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1630 $LFS hsm_archive $f.$i || error "could not archive file"
1632 wait_all_done $(($count*60))
1636 for i in $(seq 1 $count); do
1639 local fid2=$(path2fid $f.$i)
1640 # add the rebind operation to the list
1641 echo ${fids[$i]} $fid2 >> $tmpfile
1643 # set it released (simulate llapi_hsm_import call)
1644 $LFS hsm_set --archived --exists $f.$i ||
1645 error "could not force hsm flags"
1646 $LFS hsm_release $f.$i || error "could not release file"
1648 nl=$(wc -l < $tmpfile)
1649 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1651 echo "rebind list of files"
1652 do_facet $SINGLEAGT \
1653 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1654 --rebind $tmpfile $DIR" || error "could not rebind file list"
1656 # restore files and compare md5sum
1657 for i in $(seq 1 $count); do
1658 local sum2=$(md5sum $f.$i | awk '{print $1}')
1659 [[ $sum2 == ${sums[$i]} ]] ||
1660 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1666 run_test 15 "Rebind a list of files"
1669 # test needs a running copytool
1673 # create a known size file so we can verify transfer speed
1676 dd if=/dev/zero of=$ref bs=1M count=20
1679 local f=$DIR/$tdir/$tfile
1680 local fid=$(copy_file $ref $f)
1682 local start=$(date +%s)
1684 wait_request_state $fid ARCHIVE SUCCEED
1685 local end=$(date +%s)
1686 local duration=$((end - start))
1688 [[ $duration -ge $goal ]] ||
1689 error "Transfer is too fast $duration < $goal"
1693 run_test 16 "Test CT bandwith control option"
1698 local f=$DIR/$tdir/$tfile
1699 touch $f || error "touch $f failed"
1701 # Could not release a non-archived file
1702 $LFS hsm_release $f && error "release should not succeed"
1704 # For following tests, we must test them with HS_ARCHIVED set
1705 $LFS hsm_set --exists --archived $f || error "could not add flag"
1707 # Could not release a file if no-release is set
1708 $LFS hsm_set --norelease $f || error "could not add flag"
1709 $LFS hsm_release $f && error "release should not succeed"
1710 $LFS hsm_clear --norelease $f || error "could not remove flag"
1712 # Could not release a file if lost
1713 $LFS hsm_set --lost $f || error "could not add flag"
1714 $LFS hsm_release $f && error "release should not succeed"
1715 $LFS hsm_clear --lost $f || error "could not remove flag"
1717 # Could not release a file if dirty
1718 $LFS hsm_set --dirty $f || error "could not add flag"
1719 $LFS hsm_release $f && error "release should not succeed"
1720 $LFS hsm_clear --dirty $f || error "could not remove flag"
1722 run_test 20 "Release is not permitted"
1725 # test needs a running copytool
1729 local f=$DIR/$tdir/test_release
1731 # Create a file and check its states
1732 local fid=$(make_small $f)
1733 check_hsm_flags $f "0x00000000"
1735 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1736 # used until file is flushed to disk
1737 if [ $(facet_fstype ost1) == "zfs" ]; then
1738 # this causes an OST_SYNC rpc to be sent
1739 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1740 # clear locks to reread file data
1741 cancel_lru_locks osc
1744 local orig_size=$(stat -c "%s" $f)
1745 local orig_blocks=$(stat -c "%b" $f)
1747 start_full_debug_logging
1749 $LFS hsm_archive $f || error "could not archive file"
1750 wait_request_state $fid ARCHIVE SUCCEED
1752 local blocks=$(stat -c "%b" $f)
1753 [ $blocks -eq $orig_blocks ] ||
1754 error "$f: wrong block number after archive: " \
1755 "$blocks != $orig_blocks"
1756 local size=$(stat -c "%s" $f)
1757 [ $size -eq $orig_size ] ||
1758 error "$f: wrong size after archive: $size != $orig_size"
1760 # Release and check states
1761 $LFS hsm_release $f || error "could not release file"
1762 check_hsm_flags $f "0x0000000d"
1764 blocks=$(stat -c "%b" $f)
1765 [ $blocks -gt 5 ] &&
1766 error "$f: too many blocks after release: $blocks > 5"
1767 size=$(stat -c "%s" $f)
1768 [ $size -ne $orig_size ] &&
1769 error "$f: wrong size after release: $size != $orig_size"
1771 # Check we can release an file without stripe info
1775 check_hsm_flags $f "0x00000000"
1776 $LFS hsm_archive $f || error "could not archive file"
1777 wait_request_state $fid ARCHIVE SUCCEED
1779 # Release and check states
1780 $LFS hsm_release $f || error "could not release file"
1781 check_hsm_flags $f "0x0000000d"
1783 # Release again a file that is already released is OK
1784 $LFS hsm_release $f || fail "second release should succeed"
1785 check_hsm_flags $f "0x0000000d"
1787 stop_full_debug_logging
1791 run_test 21 "Simple release tests"
1794 # test needs a running copytool
1799 local f=$DIR/$tdir/test_release
1800 local swap=$DIR/$tdir/test_swap
1802 # Create a file and check its states
1803 local fid=$(make_small $f)
1804 check_hsm_flags $f "0x00000000"
1806 $LFS hsm_archive $f || error "could not archive file"
1807 wait_request_state $fid ARCHIVE SUCCEED
1809 # Release and check states
1810 $LFS hsm_release $f || error "could not release file"
1811 check_hsm_flags $f "0x0000000d"
1814 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1819 run_test 22 "Could not swap a release file"
1822 # test needs a running copytool
1827 local f=$DIR/$tdir/test_mtime
1829 # Create a file and check its states
1830 local fid=$(make_small $f)
1831 check_hsm_flags $f "0x00000000"
1833 $LFS hsm_archive $f || error "could not archive file"
1834 wait_request_state $fid ARCHIVE SUCCEED
1836 # Set modification time in the past
1837 touch -m -a -d @978261179 $f
1839 # Release and check states
1840 $LFS hsm_release $f || error "could not release file"
1841 check_hsm_flags $f "0x0000000d"
1843 local MTIME=$(stat -c "%Y" $f)
1844 local ATIME=$(stat -c "%X" $f)
1845 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1846 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1850 run_test 23 "Release does not change a/mtime (utime)"
1853 local file=$DIR/$tdir/$tfile
1862 # test needs a running copytool
1867 fid=$(make_small $file)
1869 # Create a file and check its states
1870 check_hsm_flags $file "0x00000000"
1872 # Ensure atime is less than mtime and ctime.
1876 atime0=$(stat -c "%X" $file)
1877 mtime0=$(stat -c "%Y" $file)
1878 ctime0=$(stat -c "%Z" $file)
1880 [ $atime0 -lt $mtime0 ] ||
1881 error "atime $atime0 is not less than mtime $mtime0"
1883 [ $atime0 -lt $ctime0 ] ||
1884 error "atime $atime0 is not less than ctime $ctime0"
1886 # Archive should not change any timestamps.
1887 $LFS hsm_archive $file || error "cannot archive '$file'"
1888 wait_request_state $fid ARCHIVE SUCCEED
1890 atime1=$(stat -c "%X" $file)
1891 mtime1=$(stat -c "%Y" $file)
1892 ctime1=$(stat -c "%Z" $file)
1894 [ $atime0 -eq $atime1 ] ||
1895 error "archive changed atime from $atime0 to $atime1"
1897 [ $mtime0 -eq $mtime1 ] ||
1898 error "archive changed mtime from $mtime0 to $mtime1"
1900 [ $ctime0 -eq $ctime1 ] ||
1901 error "archive changed ctime from $ctime0 to $ctime1"
1903 # Release should not change any timestamps.
1904 $LFS hsm_release $file || error "cannot release '$file'"
1905 check_hsm_flags $file "0x0000000d"
1907 atime1=$(stat -c "%X" $file)
1908 mtime1=$(stat -c "%Y" $file)
1909 ctime1=$(stat -c "%Z" $file)
1911 [ $atime0 -eq $atime1 ] ||
1912 error "release changed atime from $atime0 to $atime1"
1914 [ $mtime0 -eq $mtime1 ] ||
1915 error "release changed mtime from $mtime0 to $mtime1"
1917 [ $ctime0 -eq $ctime1 ] ||
1918 error "release changed ctime from $ctime0 to $ctime1"
1920 # Restore should not change atime or mtime and should not
1922 $LFS hsm_restore $file
1923 wait_request_state $fid RESTORE SUCCEED
1925 atime1=$(stat -c "%X" $file)
1926 mtime1=$(stat -c "%Y" $file)
1927 ctime1=$(stat -c "%Z" $file)
1929 [ $atime0 -eq $atime1 ] ||
1930 error "restore changed atime from $atime0 to $atime1"
1932 [ $mtime0 -eq $mtime1 ] ||
1933 error "restore changed mtime from $mtime0 to $mtime1"
1935 [ $ctime0 -eq $ctime1 ] ||
1936 error "restore changed ctime from $ctime0 to $ctime1"
1940 # Once more, after unmount and mount.
1941 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1942 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1944 atime1=$(stat -c "%X" $file)
1945 mtime1=$(stat -c "%Y" $file)
1946 ctime1=$(stat -c "%Z" $file)
1948 [ $atime0 -eq $atime1 ] ||
1949 error "remount changed atime from $atime0 to $atime1"
1951 [ $mtime0 -eq $mtime1 ] ||
1952 error "remount changed mtime from $mtime0 to $mtime1"
1954 [ $ctime0 -eq $ctime1 ] ||
1955 error "remount changed ctime from $ctime0 to $ctime1"
1957 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1960 local file=$DIR/$tdir/$tfile
1966 # Test needs a running copytool.
1970 # Check that root can do HSM actions on a regular user's file.
1972 fid=$(make_small $file)
1973 sum0=$(md5sum $file)
1975 chown $RUNAS_ID:$RUNAS_GID $file ||
1976 error "cannot chown '$file' to '$RUNAS_ID'"
1978 chmod ugo-w $DIR/$tdir ||
1979 error "cannot chmod '$DIR/$tdir'"
1981 $LFS hsm_archive $file
1982 wait_request_state $fid ARCHIVE SUCCEED
1984 $LFS hsm_release $file
1985 check_hsm_flags $file "0x0000000d"
1987 $LFS hsm_restore $file
1988 wait_request_state $fid RESTORE SUCCEED
1990 # Check that ordinary user can get HSM state.
1991 $RUNAS $LFS hsm_state $file ||
1992 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1994 $LFS hsm_release $file
1995 check_hsm_flags $file "0x0000000d"
1997 # Check that ordinary user can accessed released file.
1998 sum1=$($RUNAS md5sum $file) ||
1999 error "user '$RUNAS_ID' cannot read '$file'"
2001 [ "$sum0" == "$sum1" ] ||
2002 error "md5sum mismatch for '$file'"
2006 run_test 24b "root can archive, release, and restore user files"
2008 cleanup_test_24c() {
2010 set_hsm_param user_request_mask RESTORE
2011 set_hsm_param group_request_mask RESTORE
2012 set_hsm_param other_request_mask RESTORE
2016 local file=$DIR/$tdir/$tfile
2017 local action=archive
2022 # test needs a running copytool
2027 # Save the default masks and check that cleanup_24c will
2028 # restore the request masks correctly.
2029 user_save=$(get_hsm_param user_request_mask)
2030 group_save=$(get_hsm_param group_request_mask)
2031 other_save=$(get_hsm_param other_request_mask)
2033 [ "$user_save" == RESTORE ] ||
2034 error "user_request_mask is '$user_save' expected 'RESTORE'"
2035 [ "$group_save" == RESTORE ] ||
2036 error "group_request_mask is '$group_save' expected 'RESTORE'"
2037 [ "$other_save" == RESTORE ] ||
2038 error "other_request_mask is '$other_save' expected 'RESTORE'"
2040 trap cleanup_test_24c EXIT
2045 chown $RUNAS_ID:nobody $file ||
2046 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2048 set_hsm_param user_request_mask ""
2049 $RUNAS $LFS hsm_$action $file &&
2050 error "$action by user should fail"
2052 set_hsm_param user_request_mask $action
2053 $RUNAS $LFS hsm_$action $file ||
2054 error "$action by user should succeed"
2059 chown nobody:$RUNAS_GID $file ||
2060 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2062 set_hsm_param group_request_mask ""
2063 $RUNAS $LFS hsm_$action $file &&
2064 error "$action by group should fail"
2066 set_hsm_param group_request_mask $action
2067 $RUNAS $LFS hsm_$action $file ||
2068 error "$action by group should succeed"
2073 chown nobody:nobody $file ||
2074 error "cannot chown '$file' to 'nobody:nobody'"
2076 set_hsm_param other_request_mask ""
2077 $RUNAS $LFS hsm_$action $file &&
2078 error "$action by other should fail"
2080 set_hsm_param other_request_mask $action
2081 $RUNAS $LFS hsm_$action $file ||
2082 error "$action by other should succeed"
2087 run_test 24c "check that user,group,other request masks work"
2089 cleanup_test_24d() {
2091 mount -o remount,rw $MOUNT2
2095 local file1=$DIR/$tdir/$tfile
2096 local file2=$DIR2/$tdir/$tfile
2104 fid1=$(make_small $file1)
2106 trap cleanup_test_24d EXIT
2108 mount -o remount,ro $MOUNT2
2110 fid2=$(path2fid $file2)
2111 [ "$fid1" == "$fid2" ] ||
2112 error "FID mismatch '$fid1' != '$fid2'"
2114 $LFS hsm_archive $file2 &&
2115 error "archive should fail on read-only mount"
2116 check_hsm_flags $file1 "0x00000000"
2118 $LFS hsm_archive $file1
2119 wait_request_state $fid1 ARCHIVE SUCCEED
2121 $LFS hsm_release $file1
2122 $LFS hsm_restore $file2
2123 wait_request_state $fid1 RESTORE SUCCEED
2125 $LFS hsm_release $file1 || error "cannot release '$file1'"
2126 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2128 $LFS hsm_release $file2 &&
2129 error "release should fail on read-only mount"
2134 run_test 24d "check that read-only mounts are respected"
2141 local f=$DIR/$tdir/$tfile
2144 fid=$(make_small $f) || error "cannot create $f"
2145 $LFS hsm_archive $f || error "cannot archive $f"
2146 wait_request_state $fid ARCHIVE SUCCEED
2147 $LFS hsm_release $f || error "cannot release $f"
2148 while ! $LFS hsm_state $f | grep released; do
2152 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2156 run_test 24e "tar succeeds on HSM released files" # LU-6213
2160 # test needs a running copytool
2163 mkdir -p $DIR/$tdir/d1
2164 local f=$DIR/$tdir/$tfile
2165 local fid=$(copy_file /etc/hosts $f)
2168 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2169 error "hsm_archive failed"
2170 wait_request_state $fid ARCHIVE SUCCEED
2171 $LFS hsm_release $f || error "cannot release $f"
2172 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2175 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2176 error "Can not recover the tar contents"
2178 echo "Sum0 = $sum0, sum1 = $sum1"
2179 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2183 run_test 24f "root can archive, release, and restore tar files"
2186 # test needs a running copytool
2190 copy2archive /etc/hosts $tdir/$tfile
2192 local f=$DIR/$tdir/$tfile
2194 import_file $tdir/$tfile $f
2196 $LFS hsm_set --lost $f
2201 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2205 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2206 " (Operation not permitted)"
2209 # test needs a running copytool
2214 local f=$DIR/$tdir/$tfile
2215 local fid=$(copy_file /etc/passwd $f)
2217 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2218 wait_request_state $fid ARCHIVE SUCCEED
2221 $LFS hsm_set --lost $f
2225 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2229 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2230 " (Operation not permitted)"
2233 # test needs a running copytool
2237 local f=$DIR/$tdir/$tfile
2239 fid=$(make_large_for_progress $f)
2240 [ $? != 0 ] && skip "not enough free space" && return
2242 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2243 wait_request_state $fid ARCHIVE SUCCEED
2246 wait_request_state $fid REMOVE SUCCEED
2248 check_hsm_flags $f "0x00000000"
2252 run_test 26 "Remove the archive of a valid file"
2255 # test needs a running copytool
2259 make_archive $tdir/$tfile
2260 local f=$DIR/$tdir/$tfile
2261 import_file $tdir/$tfile $f
2262 local fid=$(path2fid $f)
2266 [[ $? != 0 ]] || error "Remove of a released file should fail"
2270 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2273 # test needs a running copytool
2277 local f=$DIR/$tdir/$tfile
2279 fid=$(make_large_for_progress $f)
2280 [ $? != 0 ] && skip "not enough free space" && return
2282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2283 wait_request_state $fid ARCHIVE SUCCEED
2288 [[ $? != 0 ]] || error "Remove of a released file should fail"
2292 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2295 # test needs a running copytool
2299 local f=$DIR/$tdir/$tfile
2301 fid=$(make_large_for_progress $f)
2302 [ $? != 0 ] && skip "not enough free space" && return
2304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2305 wait_request_state $fid ARCHIVE SUCCEED
2314 wait_request_state $fid REMOVE SUCCEED
2318 run_test 28 "Concurrent archive/file remove"
2321 # Tests --mntpath and --archive options
2324 copytool_setup $SINGLEAGT $MOUNT $archive_id
2326 # Bad archive number
2327 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2328 grep "Invalid argument" ||
2329 error "unexpected hsm_remove failure (1)"
2331 # mntpath is present but file is given
2332 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2333 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2334 error "unexpected hsm_remove failure (2)"
2338 run_test 29a "Tests --mntpath and --archive options"
2341 # test needs a running copytool
2345 local f=$DIR/$tdir/$tfile
2346 local fid=$(make_small $f)
2348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2349 wait_request_state $fid ARCHIVE SUCCEED
2353 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2354 wait_request_state $fid REMOVE SUCCEED
2358 run_test 29b "Archive/delete/remove by FID from the archive."
2361 # test needs a running copytool
2365 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2366 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2367 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2370 wait_request_state $fid1 ARCHIVE SUCCEED
2371 wait_request_state $fid2 ARCHIVE SUCCEED
2372 wait_request_state $fid3 ARCHIVE SUCCEED
2374 rm -f $DIR/$tdir/$tfile-[1-3]
2376 echo $fid1 > $DIR/$tdir/list
2377 echo $fid2 >> $DIR/$tdir/list
2378 echo $fid3 >> $DIR/$tdir/list
2380 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2381 --filelist $DIR/$tdir/list
2382 wait_request_state $fid1 REMOVE SUCCEED
2383 wait_request_state $fid2 REMOVE SUCCEED
2384 wait_request_state $fid3 REMOVE SUCCEED
2388 run_test 29c "Archive/delete/remove by FID, using a file list."
2391 # restore at exec cannot work on agent node (because of Linux kernel
2392 # protection of executables)
2393 needclients 2 || return 0
2395 # test needs a running copytool
2399 copy2archive /bin/true $tdir/$tfile
2401 local f=$DIR/$tdir/true
2402 import_file $tdir/$tfile $f
2404 local fid=$(path2fid $f)
2406 # set no retry action mode
2412 # remove no try action mode
2416 [[ $st == 0 ]] || error "Failed to exec a released file"
2420 run_test 30a "Restore at exec (import case)"
2423 # restore at exec cannot work on agent node (because of Linux kernel
2424 # protection of executables)
2425 needclients 2 || return 0
2427 # test needs a running copytool
2431 local f=$DIR/$tdir/true
2432 local fid=$(copy_file /bin/true $f)
2434 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2435 wait_request_state $fid ARCHIVE SUCCEED
2438 # set no retry action mode
2444 # remove no try action mode
2448 [[ $st == 0 ]] || error "Failed to exec a released file"
2452 run_test 30b "Restore at exec (release case)"
2455 needclients 2 || return 0
2457 # test needs a running copytool
2461 local f=$DIR/$tdir/SLEEP
2462 local slp_sum1=$(md5sum /bin/sleep)
2463 local fid=$(copy_file /bin/sleep $f)
2465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2466 wait_request_state $fid ARCHIVE SUCCEED
2468 check_hsm_flags $f "0x0000000d"
2469 # set no retry action mode
2471 do_node $CLIENT2 "$f 10" &
2475 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2477 [[ $? == 0 ]] || error "Execution failed during run"
2479 if [[ $? != 0 ]]; then
2480 local slp_sum2=$(md5sum /bin/sleep)
2481 # in case sleep file is modified during the test
2482 [[ $slp_sum1 == $slp_sum2 ]] &&
2483 error "Binary overwritten during exec"
2487 # remove no try action mode
2489 check_hsm_flags $f "0x00000009"
2493 run_test 30c "Update during exec of released file must fail"
2495 restore_and_check_size() {
2498 local s=$(stat -c "%s" $f)
2500 local st=$(get_hsm_flags $f)
2504 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2506 n=$(stat -c "%s" $f)
2507 # we echo in both cases to show stat is not
2509 if [[ $n != $s ]]; then
2510 echo "size seen is $n != $s"
2513 echo "size seen is right: $n == $s"
2515 st=$(get_hsm_flags $f)
2519 if [[ $cpt -lt 10 ]]; then
2522 echo " restore is too long"
2523 wait_request_state $fid RESTORE SUCCEED
2529 # test needs a running copytool
2534 make_archive $tdir/$tfile
2535 local f=$DIR/$tdir/$tfile
2536 import_file $tdir/$tfile $f
2537 local fid=$($LFS path2fid $f)
2538 HSM_ARCHIVE_PURGE=false copytool_setup
2540 restore_and_check_size $f $fid
2543 [[ $err -eq 0 ]] || error "File size changed during restore"
2547 run_test 31a "Import a large file and check size during restore"
2551 # test needs a running copytool
2556 local f=$DIR/$tdir/$tfile
2558 fid=$(make_large_for_progress $f)
2559 [ $? != 0 ] && skip "not enough free space" && return
2561 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2562 wait_request_state $fid ARCHIVE SUCCEED
2565 restore_and_check_size $f $fid
2568 [[ $err -eq 0 ]] || error "File size changed during restore"
2572 run_test 31b "Restore a large unaligned file and check size during restore"
2575 # test needs a running copytool
2580 local f=$DIR/$tdir/$tfile
2582 fid=$(make_large_for_progress_aligned $f)
2583 [ $? != 0 ] && skip "not enough free space" && return
2585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2586 wait_request_state $fid ARCHIVE SUCCEED
2589 restore_and_check_size $f $fid
2592 [[ $err -eq 0 ]] || error "File size changed during restore"
2596 run_test 31c "Restore a large aligned file and check size during restore"
2599 # test needs a running copytool
2604 local f=$DIR/$tdir/$tfile
2606 fid=$(make_large_for_progress $f)
2607 [ $? != 0 ] && skip "not enough free space" && return
2609 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2610 wait_request_state $fid ARCHIVE SUCCEED
2613 # to be sure wait_all_done will not be mislead by previous tests
2616 wait_for_grace_delay
2617 # Also raise grace_delay significantly so the Canceled
2618 # Restore action will stay enough long avail.
2619 local old_grace=$(get_hsm_param grace_delay)
2620 set_hsm_param grace_delay 100
2622 md5sum $f >/dev/null &
2624 wait_request_state $fid RESTORE STARTED
2629 # Check restore trigger process was killed
2630 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2634 # instead of waiting+checking both Restore and Cancel ops
2635 # sequentially, wait for both to be finished and then check
2637 wait_all_done 100 $fid
2638 local rstate=$(get_request_state $fid RESTORE)
2639 local cstate=$(get_request_state $fid CANCEL)
2641 # restore orig grace_delay.
2642 set_hsm_param grace_delay $old_grace
2644 if [[ "$rstate" == "CANCELED" ]] ; then
2645 [[ "$cstate" == "SUCCEED" ]] ||
2646 error "Restore state is CANCELED and Cancel state " \
2647 "is not SUCCEED but $cstate"
2648 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2649 elif [[ "$rstate" == "SUCCEED" ]] ; then
2650 [[ "$cstate" == "FAILED" ]] ||
2651 error "Restore state is SUCCEED and Cancel state " \
2652 "is not FAILED but $cstate"
2653 echo "Restore state is SUCCEED, Cancel state is FAILED"
2655 error "Restore state is $rstate and Cancel state is $cstate"
2659 error "Cannot kill process waiting for restore ($killed)"
2663 run_test 33 "Kill a restore waiting process"
2666 # test needs a running copytool
2671 local f=$DIR/$tdir/$tfile
2673 fid=$(make_large_for_progress $f)
2674 [ $? != 0 ] && skip "not enough free space" && return
2676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2677 wait_request_state $fid ARCHIVE SUCCEED
2680 md5sum $f >/dev/null &
2682 wait_request_state $fid RESTORE STARTED
2684 rm $f || error "rm $f failed"
2685 # rm must not block during restore
2686 wait_request_state $fid RESTORE STARTED
2688 wait_request_state $fid RESTORE SUCCEED
2689 # check md5sum pgm finished
2690 local there=$(ps -o pid,comm hp $pid >/dev/null)
2691 [[ -z $there ]] || error "Restore initiator does not exit"
2693 local rc=$(wait $pid)
2694 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2698 run_test 34 "Remove file during restore"
2701 # test needs a running copytool
2706 local f=$DIR/$tdir/$tfile
2707 local f1=$DIR/$tdir/$tfile-1
2709 fid=$(make_large_for_progress $f)
2710 [ $? != 0 ] && skip "not enough free space" && return
2712 local fid1=$(copy_file /etc/passwd $f1)
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 wait_request_state $fid ARCHIVE SUCCEED
2717 md5sum $f >/dev/null &
2719 wait_request_state $fid RESTORE STARTED
2721 mv $f1 $f || error "mv $f1 $f failed"
2722 # mv must not block during restore
2723 wait_request_state $fid RESTORE STARTED
2725 wait_request_state $fid RESTORE SUCCEED
2726 # check md5sum pgm finished
2727 local there=$(ps -o pid,comm hp $pid >/dev/null)
2728 [[ -z $there ]] || error "Restore initiator does not exit"
2730 local rc=$(wait $pid)
2731 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2734 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2738 run_test 35 "Overwrite file during restore"
2741 # test needs a running copytool
2746 local f=$DIR/$tdir/$tfile
2748 fid=$(make_large_for_progress $f)
2749 [ $? != 0 ] && skip "not enough free space" && return
2751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2752 wait_request_state $fid ARCHIVE SUCCEED
2755 md5sum $f >/dev/null &
2757 wait_request_state $fid RESTORE STARTED
2760 # rm must not block during restore
2761 wait_request_state $fid RESTORE STARTED
2763 wait_request_state $fid RESTORE SUCCEED
2764 # check md5sum pgm finished
2765 local there=$(ps -o pid,comm hp $pid >/dev/null)
2767 error "Restore initiator does not exit"
2769 local rc=$(wait $pid)
2771 error "Restore initiator failed with $rc"
2775 run_test 36 "Move file during restore"
2778 # LU-5683: check that an archived dirty file can be rearchived.
2780 copytool_setup $SINGLEAGT $MOUNT2
2783 local f=$DIR/$tdir/$tfile
2786 fid=$(make_small $f) || error "cannot create small file"
2788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2789 wait_request_state $fid ARCHIVE SUCCEED
2790 $LFS hsm_release $f || error "cannot release $f"
2793 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2795 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2796 wait_request_state $fid ARCHIVE SUCCEED
2800 run_test 37 "re-archive a dirty file"
2807 for n in $(seq 1 $count); do
2808 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2810 echo "$count archive requests submitted"
2814 local stream_count=4
2815 local file_count=100
2817 local f=$DIR/$tdir/$tfile
2822 for i in $(seq 1 $file_count); do
2823 for p in $(seq 1 $stream_count); do
2824 fid=$(copy_file /etc/hosts $f.$p.$i)
2827 # force copytool to use a local/temp archive dir to ensure best
2828 # performance vs remote/NFS mounts used in auto-tests
2829 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2832 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2834 # to be sure wait_all_done will not be mislead by previous tests
2836 wait_for_grace_delay
2838 # start archive streams in background (archive files in parallel)
2839 for p in $(seq 1 $stream_count); do
2840 multi_archive $f.$p $file_count &
2843 echo -n "Wait for all requests being enqueued..."
2849 run_test 40 "Parallel archive requests"
2852 # test needs a running copytool
2856 local f=$DIR/$tdir/$tfile
2857 local fid=$(copy_file /etc/motd $f 1)
2859 $LFS hsm_archive $f || error "could not archive file"
2860 wait_request_state $fid ARCHIVE SUCCEED
2861 check_hsm_flags $f "0x00000009"
2863 multiop_bg_pause $f O_c || error "multiop failed"
2867 client_up || client_up || true
2869 kill -USR1 $MULTIPID
2870 wait $MULTIPID || error "multiop close failed"
2872 check_hsm_flags $f "0x0000000b"
2876 run_test 52 "Opened for write file on an evicted client should be set dirty"
2879 # test needs a running copytool
2883 local f=$DIR/$tdir/$tfile
2884 local fid=$(copy_file /etc/motd $f 1)
2886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2887 error "could not archive file"
2888 wait_request_state $fid ARCHIVE SUCCEED
2889 check_hsm_flags $f "0x00000009"
2891 multiop_bg_pause $f o_c || error "multiop failed"
2895 client_up || client_up || true
2897 kill -USR1 $MULTIPID
2898 wait $MULTIPID || error "multiop close failed"
2900 check_hsm_flags $f "0x00000009"
2904 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2907 # test needs a running copytool
2911 local f=$DIR/$tdir/$tfile
2912 local fid=$(make_large_for_progress $f)
2914 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2915 error "could not archive file"
2916 wait_request_state $fid ARCHIVE STARTED
2918 check_hsm_flags $f "0x00000001"
2920 # Avoid coordinator resending this request as soon it has failed.
2925 wait_request_state $fid ARCHIVE FAILED
2927 check_hsm_flags $f "0x00000003"
2932 run_test 54 "Write during an archive cancels it"
2935 # test needs a running copytool
2939 local f=$DIR/$tdir/$tfile
2940 local fid=$(make_large_for_progress $f)
2942 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2943 error "could not archive file"
2944 wait_request_state $fid ARCHIVE STARTED
2946 check_hsm_flags $f "0x00000001"
2948 # Avoid coordinator resending this request as soon it has failed.
2951 $TRUNCATE $f 1024 || error "truncate failed"
2953 wait_request_state $fid ARCHIVE FAILED
2955 check_hsm_flags $f "0x00000003"
2960 run_test 55 "Truncate during an archive cancels it"
2963 # test needs a running copytool
2967 local f=$DIR/$tdir/$tfile
2969 fid=$(make_large_for_progress $f)
2970 [ $? != 0 ] && skip "not enough free space" && return
2972 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2973 error "could not archive file"
2974 wait_request_state $fid ARCHIVE STARTED
2976 check_hsm_flags $f "0x00000001"
2978 # Change metadata and sync to be sure we are not changing only
2983 wait_request_state $fid ARCHIVE SUCCEED
2985 check_hsm_flags $f "0x00000009"
2989 run_test 56 "Setattr during an archive is ok"
2992 # Need one client for I/O, one for request
2993 needclients 2 || return 0
2995 # test needs a running copytool
2999 local f=$DIR/$tdir/test_archive_remote
3000 # Create a file on a remote node
3001 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3002 "count=2 conv=fsync"
3005 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3006 error "hsm_archive failed"
3007 local fid=$(path2fid $f)
3008 wait_request_state $fid ARCHIVE SUCCEED
3010 # Release and implicit restore it
3011 do_node $CLIENT2 "$LFS hsm_release $f" ||
3012 error "hsm_release failed"
3013 do_node $CLIENT2 "md5sum $f" ||
3014 error "hsm_restore failed"
3016 wait_request_state $fid RESTORE SUCCEED
3020 run_test 57 "Archive a file with dirty cache on another node"
3022 truncate_released_file() {
3026 local sz=$(stat -c %s $src_file)
3027 local f=$DIR/$tdir/$tfile
3028 local fid=$(copy_file $1 $f)
3032 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3033 error "could not archive file"
3034 wait_request_state $fid ARCHIVE SUCCEED
3036 $LFS hsm_release $f || error "could not release file"
3038 $TRUNCATE $f $trunc_to || error "truncate failed"
3041 local sz1=$(stat -c %s $f)
3042 [[ $sz1 == $trunc_to ]] ||
3043 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3046 check_hsm_flags $f "0x0000000b"
3048 local state=$(get_request_state $fid RESTORE)
3049 [[ "$state" == "SUCCEED" ]] ||
3050 error "truncate $sz does not trig restore, state = $state"
3052 $TRUNCATE $ref $trunc_to
3053 cmp $ref $f || error "file data wrong after truncate"
3059 # test needs a running copytool
3064 local sz=$(stat -c %s /etc/passwd)
3066 echo "truncate up from $sz to $((sz*2))"
3067 truncate_released_file /etc/passwd $((sz*2))
3069 echo "truncate down from $sz to $((sz/2))"
3070 truncate_released_file /etc/passwd $((sz/2))
3072 echo "truncate to 0"
3073 truncate_released_file /etc/passwd 0
3077 run_test 58 "Truncate a released file will trigger restore"
3081 local server_version=$(lustre_version_code $SINGLEMDS)
3082 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3083 skip "Need MDS version at least 2.7.63" && return
3086 $MCREATE $DIR/$tfile || error "mcreate failed"
3087 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3088 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3089 fid=$(path2fid $DIR/$tfile)
3090 wait_request_state $fid ARCHIVE SUCCEED
3091 $LFS hsm_release $DIR/$tfile || error "release failed"
3094 run_test 59 "Release stripeless file with non-zero size"
3097 # This test validates the fix for LU-4512. Ensure that the -u
3098 # option changes the progress reporting interval from the
3099 # default (30 seconds) to the user-specified interval.
3101 local progress_timeout=$((interval * 4))
3103 # test needs a new running copytool
3105 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3108 local f=$DIR/$tdir/$tfile
3110 fid=$(make_large_for_progress $f)
3111 [ $? != 0 ] && skip "not enough free space" && return
3114 local mdt=${MDT_PREFIX}${mdtidx}
3115 local mds=mds$((mdtidx + 1))
3117 # Wait for copytool to register
3118 wait_update_facet $mds \
3119 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3120 uuid 100 || error "coyptool failed to register with $mdt"
3122 local start_at=$(date +%s)
3123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3124 error "could not archive file"
3126 local agent=$(facet_active_host $SINGLEAGT)
3127 local prefix=$TESTLOG_PREFIX
3128 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3129 local copytool_log=$prefix.copytool_log.$agent.log
3132 wait_update $agent \
3133 "grep -o start.copy $copytool_log" "start copy" 100 ||
3134 error "copytool failed to start"
3136 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3137 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3143 echo -n "Expecting a progress update within $progress_timeout seconds... "
3145 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3146 if [ $RESULT -gt 0 ]; then
3147 echo "$RESULT bytes copied in $WAIT seconds."
3149 elif [ $WAIT -ge $progress_timeout ]; then
3150 error "Timed out waiting for progress update!"
3153 WAIT=$((WAIT + sleep))
3157 local finish_at=$(date +%s)
3158 local elapsed=$((finish_at - start_at))
3160 # Ensure that the progress update occurred within the expected window.
3161 if [ $elapsed -lt $interval ]; then
3162 error "Expected progress update after at least $interval seconds"
3168 run_test 60 "Changing progress update interval from default"
3171 # test needs a new running copytool
3173 copytool_monitor_setup
3174 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3176 # Just start and stop the copytool to generate events.
3179 # Wait for the copytool to register.
3180 wait_update --verbose $(facet_active_host mds1) \
3181 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3183 error "copytool failed to register with MDT0000"
3187 local REGISTER_EVENT
3188 local UNREGISTER_EVENT
3189 while read event; do
3190 local parsed=$(parse_json_event "$event")
3191 if [ -z "$parsed" ]; then
3192 error "Copytool sent malformed event: $event"
3196 if [ $event_type == "REGISTER" ]; then
3197 REGISTER_EVENT=$event
3198 elif [ $event_type == "UNREGISTER" ]; then
3199 UNREGISTER_EVENT=$event
3201 done < <(echo $"$(get_copytool_event_log)")
3203 if [ -z "$REGISTER_EVENT" ]; then
3204 error "Copytool failed to send register event to FIFO"
3207 if [ -z "$UNREGISTER_EVENT" ]; then
3208 error "Copytool failed to send unregister event to FIFO"
3211 copytool_monitor_cleanup
3212 echo "Register/Unregister events look OK."
3214 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3217 # Bump progress interval for livelier events.
3220 # test needs a new running copytool
3222 copytool_monitor_setup
3223 HSMTOOL_UPDATE_INTERVAL=$interval \
3224 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3227 local f=$DIR/$tdir/$tfile
3229 fid=$(make_large_for_progress $f)
3230 [ $? != 0 ] && skip "not enough free space" && return
3232 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3233 error "could not archive file"
3234 wait_request_state $fid ARCHIVE SUCCEED
3236 local expected_fields="event_time data_fid source_fid"
3237 expected_fields+=" total_bytes current_bytes"
3241 while read event; do
3242 # Make sure we're not getting anything from previous events.
3243 for field in $expected_fields; do
3247 local parsed=$(parse_json_event "$event")
3248 if [ -z "$parsed" ]; then
3249 error "Copytool sent malformed event: $event"
3253 if [ $event_type == "ARCHIVE_START" ]; then
3256 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3259 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3263 # Do some simple checking of the progress update events.
3264 for expected_field in $expected_fields; do
3265 if [ -z ${!expected_field+x} ]; then
3266 error "Missing $expected_field field in event"
3270 if [ $total_bytes -eq 0 ]; then
3271 error "Expected total_bytes to be > 0"
3274 # These should be identical throughout an archive
3276 if [ $source_fid != $data_fid ]; then
3277 error "Expected source_fid to equal data_fid"
3279 done < <(echo $"$(get_copytool_event_log)")
3281 if [ -z "$START_EVENT" ]; then
3282 error "Copytool failed to send archive start event to FIFO"
3285 if [ -z "$FINISH_EVENT" ]; then
3286 error "Copytool failed to send archive finish event to FIFO"
3289 echo "Archive events look OK."
3293 copytool_monitor_cleanup
3295 run_test 71 "Copytool logs JSON archive events to FIFO"
3298 # Bump progress interval for livelier events.
3301 # test needs a new running copytool
3303 copytool_monitor_setup
3304 HSMTOOL_UPDATE_INTERVAL=$interval \
3305 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3306 local test_file=$HSMTOOL_MONITOR_DIR/file
3308 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3310 do_facet $SINGLEAGT "$cmd" ||
3311 error "cannot create $test_file on $SINGLEAGT"
3312 copy2archive $test_file $tdir/$tfile
3315 local f=$DIR/$tdir/$tfile
3316 import_file $tdir/$tfile $f
3317 f=$DIR2/$tdir/$tfile
3318 echo "Verifying released state: "
3319 check_hsm_flags $f "0x0000000d"
3321 local fid=$(path2fid $f)
3323 wait_request_state $fid RESTORE SUCCEED
3325 local expected_fields="event_time data_fid source_fid"
3326 expected_fields+=" total_bytes current_bytes"
3330 while read event; do
3331 # Make sure we're not getting anything from previous events.
3332 for field in $expected_fields; do
3336 local parsed=$(parse_json_event "$event")
3337 if [ -z "$parsed" ]; then
3338 error "Copytool sent malformed event: $event"
3342 if [ $event_type == "RESTORE_START" ]; then
3344 if [ $source_fid != $data_fid ]; then
3345 error "source_fid should == data_fid at start"
3348 elif [ $event_type == "RESTORE_FINISH" ]; then
3350 if [ $source_fid != $data_fid ]; then
3351 error "source_fid should == data_fid at finish"
3354 elif [ $event_type != "RESTORE_RUNNING" ]; then
3358 # Do some simple checking of the progress update events.
3359 for expected_field in $expected_fields; do
3360 if [ -z ${!expected_field+x} ]; then
3361 error "Missing $expected_field field in event"
3365 if [ $total_bytes -eq 0 ]; then
3366 error "Expected total_bytes to be > 0"
3369 # When a restore starts out, the data fid is the same as the
3370 # source fid. After the restore has gotten going, we learn
3371 # the new data fid. Once the restore has finished, the source
3372 # fid is set to the new data fid.
3374 # We test this because some monitoring software may depend on
3375 # this behavior. If it changes, then the consumers of these
3376 # events may need to be modified.
3377 if [ $source_fid == $data_fid ]; then
3378 error "source_fid should != data_fid during restore"
3380 done < <(echo $"$(get_copytool_event_log)")
3382 if [ -z "$START_EVENT" ]; then
3383 error "Copytool failed to send restore start event to FIFO"
3386 if [ -z "$FINISH_EVENT" ]; then
3387 error "Copytool failed to send restore finish event to FIFO"
3390 echo "Restore events look OK."
3394 copytool_monitor_cleanup
3398 run_test 72 "Copytool logs JSON restore events to FIFO"
3401 file_count=51 # Max number of files constrained by LNET message size
3402 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3403 local f=$DIR/$tdir/$tfile
3404 local FILELIST=/tmp/filelist.txt
3408 for i in $(seq 1 $file_count); do
3409 fid=$(copy_file /etc/hosts $f.$i)
3410 echo $f.$i >> $FILELIST
3412 # force copytool to use a local/temp archive dir to ensure best
3413 # performance vs remote/NFS mounts used in auto-tests
3414 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3417 local dai=$(get_hsm_param default_archive_id)
3418 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3420 # to be sure wait_all_done will not be mislead by previous tests
3422 wait_for_grace_delay
3423 $LFS hsm_archive --filelist $FILELIST ||
3424 error "cannot archive a file list"
3426 $LFS hsm_release --filelist $FILELIST ||
3427 error "cannot release a file list"
3428 $LFS hsm_restore --filelist $FILELIST ||
3429 error "cannot restore a file list"
3433 run_test 90 "Archive/restore a file list"
3435 double_verify_reset_hsm_param() {
3437 echo "Testing $HSM_PARAM.$p"
3438 local val=$(get_hsm_param $p)
3440 local val2=$(($val * 2))
3441 set_hsm_param $p $val2
3442 val=$(get_hsm_param $p)
3443 [[ $val == $val2 ]] ||
3444 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3445 echo "Set $p to 0 must failed"
3449 set_hsm_param $p $save
3451 if [[ $rc == 0 ]]; then
3452 error "we must not be able to set $HSM_PARAM.$p to 0"
3457 double_verify_reset_hsm_param loop_period
3458 double_verify_reset_hsm_param grace_delay
3459 double_verify_reset_hsm_param active_request_timeout
3460 double_verify_reset_hsm_param max_requests
3461 double_verify_reset_hsm_param default_archive_id
3463 run_test 100 "Set coordinator /proc tunables"
3470 run_test 102 "Verify coordinator control"
3473 # test needs a running copytool
3480 for i in $(seq 1 20); do
3481 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3483 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3487 echo "Current requests"
3488 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3489 $HSM_PARAM.actions |\
3490 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3492 [[ -z "$res" ]] || error "Some request have not been canceled"
3496 run_test 103 "Purge all requests"
3501 # test needs a running copytool
3505 local f=$DIR/$tdir/$tfile
3507 fid=$(make_large_for_progress $f)
3508 [ $? != 0 ] && skip "not enough free space" && return
3510 # if cdt is on, it can serve too quickly the request
3512 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3513 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3514 $HSM_PARAM.actions |\
3515 grep $fid | cut -f16 -d=")
3518 [[ "$data1" == "$DATAHEX" ]] ||
3519 error "Data field in records is ($data1) and not ($DATAHEX)"
3523 run_test 104 "Copy tool data field"
3530 for i in $(seq -w 1 10); do
3531 cp /etc/passwd $DIR/$tdir/$i
3532 $LFS hsm_archive $DIR/$tdir/$i
3534 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3535 $HSM_PARAM.actions |\
3536 grep WAITING | wc -l")
3539 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3540 $HSM_PARAM.actions |\
3541 grep WAITING | wc -l")
3544 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3545 error "Requests count after shutdown $reqcnt2 != "\
3546 "before shutdown $reqcnt1"
3548 run_test 105 "Restart of coordinator"
3550 get_agent_by_uuid_mdt() {
3553 local mds=mds$(($mdtidx + 1))
3554 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3558 check_agent_registered_by_mdt() {
3561 local mds=mds$(($mdtidx + 1))
3562 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3563 if [[ ! -z "$agent" ]]; then
3564 echo "found agent $agent on $mds"
3566 error "uuid $uuid not found in agent list on $mds"
3570 check_agent_unregistered_by_mdt() {
3573 local mds=mds$(($mdtidx + 1))
3574 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3575 if [[ -z "$agent" ]]; then
3576 echo "uuid not found in agent list on $mds"
3578 error "uuid found in agent list on $mds: $agent"
3582 check_agent_registered() {
3585 for mdsno in $(seq 1 $MDSCOUNT); do
3586 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3590 check_agent_unregistered() {
3593 for mdsno in $(seq 1 $MDSCOUNT); do
3594 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3599 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3601 # Lustre mount-point is mandatory and last parameter on
3602 # copytool cmd-line.
3603 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3604 grep -v pgrep | awk '{print $NF}')
3605 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3607 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3611 # test needs a running copytool
3614 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3616 check_agent_registered $uuid
3618 search_copytools || error "No copytool found"
3621 check_agent_unregistered $uuid
3624 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3625 check_agent_registered $uuid
3629 run_test 106 "Copytool register/unregister"
3632 # test needs a running copytool
3634 # create and archive file
3636 local f1=$DIR/$tdir/$tfile
3637 local fid=$(copy_file /etc/passwd $f1)
3638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3639 wait_request_state $fid ARCHIVE SUCCEED
3640 # shutdown and restart MDS
3642 # check the copytool still gets messages from MDT
3643 local f2=$DIR/$tdir/2
3644 local fid=$(copy_file /etc/passwd $f2)
3645 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3646 # main check of this sanity: this request MUST succeed
3647 wait_request_state $fid ARCHIVE SUCCEED
3650 run_test 107 "Copytool re-register after MDS restart"
3652 policy_set_and_test()
3656 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3657 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3658 [[ "$policy" == "$target" ]] ||
3659 error "Wrong policy after '$change': '$policy' != '$target'"
3663 # to force default policy setting if error
3664 CDT_POLICY_HAD_CHANGED=true
3666 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3667 local default="NonBlockingRestore [NoRetryAction]"
3668 [[ "$policy" == "$default" ]] ||
3669 error "default policy has changed,"\
3670 " '$policy' != '$default' update the test"
3671 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3672 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3673 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3674 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3675 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3676 # useless bacause we know but safer for futur changes to use real value
3677 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3678 echo "Next set_param must failed"
3679 policy_set_and_test "wrong" "$policy"
3682 echo "Back to default policy"
3683 cdt_set_sanity_policy
3685 run_test 109 "Policy display/change"
3688 # test needs a running copytool
3693 copy2archive /etc/passwd $tdir/$tfile
3695 local f=$DIR/$tdir/$tfile
3696 import_file $tdir/$tfile $f
3697 local fid=$(path2fid $f)
3699 cdt_set_non_blocking_restore
3704 wait_request_state $fid RESTORE SUCCEED
3705 cdt_clear_non_blocking_restore
3709 error "md5sum returns $st != 1, "\
3710 "should also perror ENODATA (No data available)"
3714 run_test 110a "Non blocking restore policy (import case)"
3717 # test needs a running copytool
3721 local f=$DIR/$tdir/$tfile
3722 local fid=$(copy_file /etc/passwd $f)
3723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3724 wait_request_state $fid ARCHIVE SUCCEED
3727 cdt_set_non_blocking_restore
3732 wait_request_state $fid RESTORE SUCCEED
3733 cdt_clear_non_blocking_restore
3737 error "md5sum returns $st != 1, "\
3738 "should also perror ENODATA (No data available)"
3742 run_test 110b "Non blocking restore policy (release case)"
3745 # test needs a running copytool
3749 copy2archive /etc/passwd $tdir/$tfile
3751 local f=$DIR/$tdir/$tfile
3753 import_file $tdir/$tfile $f
3754 local fid=$(path2fid $f)
3758 copytool_remove_backend $fid
3761 wait_request_state $fid RESTORE FAILED
3768 [[ $st == 0 ]] || error "Restore does not failed"
3772 run_test 111a "No retry policy (import case), restore will error"\
3773 " (No such file or directory)"
3776 # test needs a running copytool
3780 local f=$DIR/$tdir/$tfile
3781 local fid=$(copy_file /etc/passwd $f)
3783 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3784 wait_request_state $fid ARCHIVE SUCCEED
3787 copytool_remove_backend $fid
3790 wait_request_state $fid RESTORE FAILED
3797 [[ $st == 0 ]] || error "Restore does not failed"
3801 run_test 111b "No retry policy (release case), restore will error"\
3802 " (No such file or directory)"
3805 # test needs a running copytool
3809 local f=$DIR/$tdir/$tfile
3810 local fid=$(copy_file /etc/passwd $f)
3812 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3813 local l=$($LFS hsm_action $f)
3815 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3819 wait_request_state $fid ARCHIVE SUCCEED
3822 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3826 run_test 112 "State of recorded request"
3829 # test needs a running copytool
3833 local f=$DIR/$tdir/$tfile
3835 fid=$(make_large_for_cancel $f)
3836 [ $? != 0 ] && skip "not enough free space" && return
3838 # test with cdt on is made in test_221
3840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3841 # wait archive to register at CDT
3842 wait_request_state $fid ARCHIVE WAITING
3845 wait_request_state $fid ARCHIVE CANCELED
3846 wait_request_state $fid CANCEL SUCCEED
3850 run_test 200 "Register/Cancel archive"
3853 # test needs a running copytool
3857 local f=$DIR/$tdir/$tfile
3858 make_archive $tdir/$tfile
3859 import_file $tdir/$tfile $f
3860 local fid=$(path2fid $f)
3862 # test with cdt on is made in test_222
3865 # wait restore to register at CDT
3866 wait_request_state $fid RESTORE WAITING
3869 wait_request_state $fid RESTORE CANCELED
3870 wait_request_state $fid CANCEL SUCCEED
3874 run_test 201 "Register/Cancel restore"
3877 # test needs a running copytool
3881 local f=$DIR/$tdir/$tfile
3883 fid=$(make_large_for_progress $f)
3884 [ $? != 0 ] && skip "not enough free space" && return
3886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3887 wait_request_state $fid ARCHIVE SUCCEED
3891 # wait remove to register at CDT
3892 wait_request_state $fid REMOVE WAITING
3895 wait_request_state $fid REMOVE CANCELED
3899 run_test 202 "Register/Cancel remove"
3902 # test needs a running copytool
3907 local f=$DIR/$tdir/$tfile
3908 local fid=$(copy_file /etc/passwd $f)
3912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3913 wait_request_state $fid ARCHIVE SUCCEED
3915 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3919 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3923 run_test 220 "Changelog for archive"
3926 # test needs a running copytool
3931 local f=$DIR/$tdir/$tfile
3933 fid=$(make_large_for_cancel $f)
3934 [ $? != 0 ] && skip "not enough free space" && return
3938 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3939 wait_request_state $fid ARCHIVE STARTED
3941 wait_request_state $fid ARCHIVE CANCELED
3942 wait_request_state $fid CANCEL SUCCEED
3944 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3947 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3951 run_test 221 "Changelog for archive canceled"
3954 # test needs a running copytool
3958 copy2archive /etc/passwd $tdir/$tfile
3960 local f=$DIR/$tdir/$tfile
3961 import_file $tdir/$tfile $f
3962 local fid=$(path2fid $f)
3967 wait_request_state $fid RESTORE SUCCEED
3969 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3972 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3976 run_test 222a "Changelog for explicit restore"
3979 # test needs a running copytool
3983 local f=$DIR/$tdir/$tfile
3984 local fid=$(copy_file /etc/passwd $f)
3987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3988 wait_request_state $fid ARCHIVE SUCCEED
3993 wait_request_state $fid RESTORE SUCCEED
3995 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3998 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4002 run_test 222b "Changelog for implicit restore"
4005 # test needs a running copytool
4010 local f=$DIR/$tdir/$tfile
4011 make_archive $tdir/$tfile
4015 import_file $tdir/$tfile $f
4016 local fid=$(path2fid $f)
4019 wait_request_state $fid RESTORE STARTED
4021 wait_request_state $fid RESTORE CANCELED
4022 wait_request_state $fid CANCEL SUCCEED
4024 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4027 [[ $flags == $target ]] ||
4028 error "Changelog flag is $flags not $target"
4032 run_test 223a "Changelog for restore canceled (import case)"
4035 # test needs a running copytool
4040 local f=$DIR/$tdir/$tfile
4042 fid=$(make_large_for_progress $f)
4043 [ $? != 0 ] && skip "not enough free space" && return
4046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4047 wait_request_state $fid ARCHIVE SUCCEED
4050 wait_request_state $fid RESTORE STARTED
4052 wait_request_state $fid RESTORE CANCELED
4053 wait_request_state $fid CANCEL SUCCEED
4055 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4058 [[ $flags == $target ]] ||
4059 error "Changelog flag is $flags not $target"
4063 run_test 223b "Changelog for restore canceled (release case)"
4066 # test needs a running copytool
4071 local f=$DIR/$tdir/$tfile
4072 local fid=$(copy_file /etc/passwd $f)
4075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4076 wait_request_state $fid ARCHIVE SUCCEED
4079 wait_request_state $fid REMOVE SUCCEED
4081 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4084 [[ $flags == $target ]] ||
4085 error "Changelog flag is $flags not $target"
4089 run_test 224 "Changelog for remove"
4092 # test needs a running copytool
4095 # test is not usable because remove request is too fast
4096 # so it is always finished before cancel can be done ...
4097 echo "Test disabled"
4102 local f=$DIR/$tdir/$tfile
4104 fid=$(make_large_for_progress $f)
4105 [ $? != 0 ] && skip "not enough free space" && return
4108 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4109 wait_request_state $fid ARCHIVE SUCCEED
4111 # if cdt is on, it can serve too quickly the request
4116 wait_request_state $fid REMOVE CANCELED
4117 wait_request_state $fid CANCEL SUCCEED
4119 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4120 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4121 tail -n 1 | awk '{print $5}')
4124 [[ $flags == $target ]] ||
4125 error "Changelog flag is $flags not $target"
4129 run_test 225 "Changelog for remove canceled"
4132 # test needs a running copytool
4137 local f1=$DIR/$tdir/$tfile-1
4138 local f2=$DIR/$tdir/$tfile-2
4139 local f3=$DIR/$tdir/$tfile-3
4140 local fid1=$(copy_file /etc/passwd $f1)
4141 local fid2=$(copy_file /etc/passwd $f2)
4142 copy_file /etc/passwd $f3
4145 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4146 wait_request_state $fid1 ARCHIVE SUCCEED
4148 $LFS hsm_archive $f2
4149 wait_request_state $fid2 ARCHIVE SUCCEED
4151 rm $f1 || error "rm $f1 failed"
4153 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4156 [[ $flags == $target ]] ||
4157 error "Changelog flag is $flags not $target"
4159 mv $f3 $f2 || error "mv $f3 $f2 failed"
4161 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4164 [[ $flags == $target ]] ||
4165 error "Changelog flag is $flags not $target"
4169 run_test 226 "changelog for last rm/mv with exiting archive"
4171 check_flags_changes() {
4179 $LFS hsm_set --$hsm_flag $f ||
4180 error "Cannot set $hsm_flag on $f"
4181 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4182 local seen=${#flags[*]}
4184 [[ $seen == $cnt ]] ||
4185 error "set $hsm_flag: Changelog events $seen != $cnt"
4186 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4187 error "set $hsm_flag: Changelog flags are "\
4188 "${flags[$((cnt - 1))]} not $target"
4190 $LFS hsm_clear --$hsm_flag $f ||
4191 error "Cannot clear $hsm_flag on $f"
4192 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4195 [[ $cnt == $seen ]] ||
4196 error "clear $hsm_flag: Changelog events $seen != $cnt"
4198 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4199 error "clear $hsm_flag: Changelog flag is "\
4200 "${flags[$((cnt - 1))]} not $target"
4204 # test needs a running copytool
4211 for i in norelease noarchive exists archived
4213 local f=$DIR/$tdir/$tfile-$i
4214 local fid=$(copy_file /etc/passwd $f)
4215 check_flags_changes $f $fid $i 0 1
4218 f=$DIR/$tdir/$tfile---lost
4219 fid=$(copy_file /etc/passwd $f)
4220 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4221 wait_request_state $fid ARCHIVE SUCCEED
4222 check_flags_changes $f $fid lost 3 1
4226 run_test 227 "changelog when explicit setting of HSM flags"
4229 # test needs a running copytool
4232 local fid=$(make_small_sync $DIR/$tfile)
4233 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4234 wait_request_state $fid ARCHIVE SUCCEED
4236 $LFS hsm_release $DIR/$tfile
4237 check_hsm_flags $DIR/$tfile "0x0000000d"
4239 filefrag $DIR/$tfile | grep " 1 extent found" ||
4240 error "filefrag on released file must return only one extent"
4242 # only newer versions of cp detect sparse files by stat/FIEMAP
4244 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4245 error "copying $DIR/$tfile"
4246 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4248 $LFS hsm_release $DIR/$tfile
4249 check_hsm_flags $DIR/$tfile "0x0000000d"
4251 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4253 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4255 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4256 error "comparing untarred $DIR/$tfile"
4258 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4259 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4262 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4265 # test needs a running copytool
4269 local maxrequest=$(get_hsm_param max_requests)
4270 local rqcnt=$(($maxrequest * 3))
4274 for i in $(seq -w 1 $rqcnt); do
4276 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4278 # we do it in 2 steps, so all requests arrive at the same time
4279 for i in $(seq -w 1 $rqcnt); do
4280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4285 while [[ $cnt != 0 || $wt != 0 ]]; do
4287 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4288 $HSM_PARAM.actions |\
4289 grep STARTED | grep -v CANCEL | wc -l")
4290 [[ $cnt -le $maxrequest ]] ||
4291 error "$cnt > $maxrequest too many started requests"
4292 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4293 $HSM_PARAM.actions |\
4294 grep WAITING | wc -l")
4295 echo "max=$maxrequest started=$cnt waiting=$wt"
4300 run_test 250 "Coordinator max request"
4303 # test needs a running copytool
4307 local f=$DIR/$tdir/$tfile
4309 fid=$(make_large_for_cancel $f)
4310 [ $? != 0 ] && skip "not enough free space" && return
4313 # to have a short test
4314 local old_to=$(get_hsm_param active_request_timeout)
4315 set_hsm_param active_request_timeout 4
4316 # to be sure the cdt will wake up frequently so
4317 # it will be able to cancel the "old" request
4318 local old_loop=$(get_hsm_param loop_period)
4319 set_hsm_param loop_period 2
4322 # clear locks to avoid extra delay caused by flush/cancel
4323 # and thus prevent early copytool death to timeout.
4324 cancel_lru_locks osc
4326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4327 wait_request_state $fid ARCHIVE STARTED
4329 wait_request_state $fid ARCHIVE CANCELED
4331 set_hsm_param active_request_timeout $old_to
4332 set_hsm_param loop_period $old_loop
4336 run_test 251 "Coordinator request timeout"
4339 # the only way to test ondisk conf is to restart MDS ...
4340 echo "Stop coordinator and remove coordinator state at mount"
4343 # clean on disk conf set by default
4344 cdt_clear_mount_state
4345 cdt_check_state stopped
4347 # check cdt still off after umount/remount
4349 cdt_check_state stopped
4351 echo "Set coordinator start at mount, and start coordinator"
4352 cdt_set_mount_state enabled
4355 cdt_check_state enabled
4357 # check cdt still on after umount/remount
4359 cdt_check_state enabled
4361 # we are back to original state (cdt started at mount)
4363 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4366 local ai=$(get_hsm_param default_archive_id)
4367 local new=$((ai + 1))
4369 set_hsm_param default_archive_id $new -P
4371 local res=$(get_hsm_param default_archive_id)
4374 set_hsm_param default_archive_id "" "-P -d"
4376 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4378 run_test 301 "HSM tunnable are persistent"
4381 local ai=$(get_hsm_param default_archive_id)
4382 local new=$((ai + 1))
4387 set_hsm_param default_archive_id $new -P
4390 for mdtno in $(seq 1 $MDSCOUNT); do
4395 cdt_check_state enabled
4397 local res=$(get_hsm_param default_archive_id)
4400 set_hsm_param default_archive_id "" "-P -d"
4402 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4404 run_test 302 "HSM tunnable are persistent when CDT is off"
4407 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4413 local dir_mdt0=$DIR/$tdir/mdt0
4414 local dir_mdt1=$DIR/$tdir/mdt1
4416 # create 1 dir per MDT
4417 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4418 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4420 # create 1 file in each MDT
4421 local fid1=$(make_small $dir_mdt0/$tfile)
4422 local fid2=$(make_small $dir_mdt1/$tfile)
4424 # check that hsm request on mdt0 is sent to the right MDS
4425 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4426 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4427 echo "archive successful on mdt0"
4429 # check that hsm request on mdt1 is sent to the right MDS
4430 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4431 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4432 echo "archive successful on mdt1"
4435 # clean test files and directories
4436 rm -rf $dir_mdt0 $dir_mdt1
4438 run_test 400 "Single request is sent to the right MDT"
4441 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4447 local dir_mdt0=$DIR/$tdir/mdt0
4448 local dir_mdt1=$DIR/$tdir/mdt1
4450 # create 1 dir per MDT
4451 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4452 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4454 # create 1 file in each MDT
4455 local fid1=$(make_small $dir_mdt0/$tfile)
4456 local fid2=$(make_small $dir_mdt1/$tfile)
4458 # check that compound requests are shunt to the rights MDTs
4459 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4460 error "lfs hsm_archive"
4461 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4462 echo "archive successful on mdt0"
4463 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4464 echo "archive successful on mdt1"
4467 # clean test files and directories
4468 rm -rf $dir_mdt0 $dir_mdt1
4470 run_test 401 "Compound requests split and sent to their respective MDTs"
4472 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4477 local node=$(facet_active_host $facet)
4479 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4480 awk '{print $4}'); do
4481 echo "$3 $mdc on $node"
4482 do_facet $facet "$LCTL --device $mdc $state" || return 1
4487 # make sure there is no running copytool
4490 # deactivate all mdc on agent1
4491 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4493 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4495 check_agent_unregistered "uuid" # match any agent
4497 # no expected running copytool
4498 search_copytools $agent && error "Copytool start should have failed"
4501 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4503 run_test 402 "Copytool start fails if all MDTs are inactive"
4506 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4508 # make sure there is no running copytool
4511 local agent=$(facet_active_host $SINGLEAGT)
4513 # deactivate all mdc for MDT0001
4514 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4517 local uuid=$(get_agent_uuid $agent)
4518 # check the agent is registered on MDT0000, and not on MDT0001
4519 check_agent_registered_by_mdt $uuid 0
4520 check_agent_unregistered_by_mdt $uuid 1
4522 # check running copytool process
4523 search_copytools $agent || error "No running copytools on $agent"
4525 # reactivate all mdc for MDT0001
4526 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4528 # make sure the copytool is now registered to all MDTs
4529 check_agent_registered $uuid
4533 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4536 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4540 # create files on both MDT0000 and MDT0001
4543 local dir_mdt0=$DIR/$tdir/mdt0
4544 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4546 # create 1 file on mdt0
4547 local fid1=$(make_small $dir_mdt0/$tfile)
4549 # deactivate all mdc for MDT0001
4550 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4552 # send an HSM request for files in MDT0000
4553 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4555 # check for completion of files in MDT0000
4556 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4557 echo "archive successful on mdt0"
4559 # reactivate all mdc for MDT0001
4560 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4563 # clean test files and directories
4566 run_test 404 "Inactive MDT does not block requests for active MDTs"
4569 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4575 local striped_dir=$DIR/$tdir/striped_dir
4577 # create striped dir on all of MDTs
4578 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4580 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4581 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4582 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4583 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4585 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4586 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4587 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4588 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4590 # check that compound requests are shunt to the rights MDTs
4591 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4592 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4593 error "lfs hsm_archive"
4595 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4596 echo "archive successful on $fid1"
4597 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4598 echo "archive successful on $fid2"
4599 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4600 echo "archive successful on $fid3"
4601 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4602 echo "archive successful on $fid4"
4604 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4605 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4606 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4607 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4609 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4610 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4611 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4612 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4616 run_test 405 "archive and release under striped directory"
4620 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4621 skip "HSM migrate is not supported" && return
4623 # Stop the existing copytool
4626 test_mkdir -p $DIR/$tdir
4627 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4629 run_test 500 "various LLAPI HSM tests"
4634 check_and_cleanup_lustre