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 agents=${1:-$(facet_active_host $SINGLEAGT)}
149 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
152 search_and_kill_copytool() {
153 local agents=${1:-$(facet_active_host $SINGLEAGT)}
155 echo "Killing existing copytools on $agents"
156 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
159 copytool_monitor_setup() {
160 local facet=${1:-$SINGLEAGT}
161 local agent=$(facet_active_host $facet)
163 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
164 local test_dir=$(do_node $agent "$cmd") ||
165 error "Failed to create tempdir on $agent"
166 export HSMTOOL_MONITOR_DIR=$test_dir
168 # Create the fifo and a monitor (cat dies when copytool dies)
169 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
170 error "failed to create copytool fifo on $agent"
171 cmd="cat $test_dir/fifo > $test_dir/events &"
172 cmd+=" echo \\\$! > $test_dir/monitor_pid"
174 if [[ $PDSH == *Rmrsh* ]]; then
175 # This is required for pdsh -Rmrsh and its handling of remote
177 # Regular ssh and pdsh -Rssh work fine without this
178 # backgrounded subshell nonsense.
179 (do_node $agent "$cmd") &
180 export HSMTOOL_MONITOR_PDSH=$!
182 # Slightly racy, but just making a best-effort to catch obvious
185 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
186 error "Failed to start copytool monitor on $agent"
188 do_node $agent "$cmd"
190 error "Failed to start copytool monitor on $agent"
195 copytool_monitor_cleanup() {
196 local facet=${1:-$SINGLEAGT}
197 local agent=$(facet_active_host $facet)
199 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
200 # Should die when the copytool dies, but just in case.
201 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
202 cmd+=" 2>/dev/null || true"
203 do_node $agent "$cmd"
204 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
205 export HSMTOOL_MONITOR_DIR=
208 # The pdsh should die on its own when the monitor dies. Just
209 # in case, though, try to clean up to avoid any cruft.
210 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
211 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
212 export HSMTOOL_MONITOR_PDSH=
217 local facet=${1:-$SINGLEAGT}
218 # Use MOUNT2 by default if defined
219 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
221 local hsm_root=${4:-$(copytool_device $facet)}
222 local agent=$(facet_active_host $facet)
224 if [[ -z "$arc_id" ]] &&
225 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
226 echo "Only wakeup running copytool $facet on $agent"
230 if $HSM_ARCHIVE_PURGE; then
231 echo "Purging archive on $agent"
232 do_facet $facet "rm -rf $hsm_root/*"
235 echo "Starting copytool $facet on $agent"
236 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
237 # bandwidth is limited to 1MB/s so the copy time is known and
238 # independent of hardware
239 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
240 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
241 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
242 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
243 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
244 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
245 cmd+=" --bandwidth 1 $lustre_mntpnt"
247 # Redirect the standard output and error to a log file which
248 # can be uploaded to Maloo.
249 local prefix=$TESTLOG_PREFIX
250 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
251 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
253 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
254 if [[ $? != 0 ]]; then
255 [[ $HSMTOOL_NOERROR == true ]] ||
256 error "start copytool $facet on $agent failed"
257 echo "start copytool $facet on $agent failed"
263 get_copytool_event_log() {
264 local facet=${1:-$SINGLEAGT}
265 local agent=$(facet_active_host $facet)
267 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
268 error "Can't get event log: No monitor directory!"
270 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
271 error "Could not collect event log from $agent"
276 local agt_facet=$SINGLEAGT
277 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
278 local end_wait=$(( SECONDS + TIMEOUT ))
279 local hsm_root=$(copytool_device $agt_facet)
285 do_nodesv $agt_hosts "pkill -INT -x $HSMTOOL_BASE" || return 0
287 while (( SECONDS < end_wait )); do
289 do_nodesv $agt_hosts "pgrep -x $HSMTOOL_BASE"
290 if [ $? -ne 0 ]; then
291 echo "copytool is stopped on $agt_hosts"
294 echo "copytool still running on $agt_hosts"
297 if do_nodesv $agt_hosts "pgrep -x $HSMTOOL_BASE"; then
298 error "copytool failed to stop in ${TIMEOUT}s"
300 echo "copytool has stopped in " \
301 "$((TIMEOUT - (end_wait - SECONDS)))s"
304 # Clean all CDTs orphans requests from previous tests that
305 # would otherwise need to timeout to clear.
306 for ((i = 0; i < MDSCOUNT; i++)); do
308 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
309 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
311 # Skip already stopping or stopped CDTs.
312 [[ "${state[$i]}" =~ ^stop ]] && continue
314 do_facet $facet "$LCTL set_param $param=shutdown"
317 for ((i = 0; i < MDSCOUNT; i++)); do
318 # Only check and restore CDTs that we stopped in the first loop.
319 [[ "${state[$i]}" =~ ^stop ]] && continue
322 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
324 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
325 error "$facet CDT state is not stopped"
327 # Restore old CDT state.
328 do_facet $facet "$LCTL set_param $param=${state[$i]}"
332 for ((i = 0; i < MDSCOUNT; i++)); do
333 # Only check CDTs that we stopped in the first loop.
334 [[ "${state[$i]}" =~ ^stop ]] && continue
337 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
339 # Check that the old CDT state was restored.
340 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
341 20 || error "$facet CDT state is not '${state[$i]}'"
344 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
345 do_facet $agt_facet "rm -rf $hsm_root/*"
350 local agents=${1:-$(facet_active_host $SINGLEAGT)}
352 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
353 echo "Copytool is suspended on $agents"
356 copytool_remove_backend() {
358 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
359 echo "Remove from backend: $fid = $be"
360 do_facet $SINGLEAGT rm -f $be
364 do_facet $SINGLEAGT \
365 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
366 --import $1 $2 $MOUNT" ||
367 error "import of $1 to $2 failed"
371 local file=$HSM_ARCHIVE/$1
372 do_facet $SINGLEAGT mkdir -p $(dirname $file)
373 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
374 file_creation_failure dd $file $?
378 local file=$HSM_ARCHIVE/$2
379 do_facet $SINGLEAGT mkdir -p $(dirname $file)
380 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
389 if [[ "$value" != "" ]]; then
392 for mdtno in $(seq 1 $MDSCOUNT); do
393 local idx=$(($mdtno - 1))
394 local facet=mds${mdtno}
395 # if $arg include -P option, run 1 set_param per MDT on the MGS
396 # else, run set_param on each MDT
397 [[ $arg = *"-P"* ]] && facet=mgs
398 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
399 [[ $? != 0 ]] && rc=1
409 for mdtno in $(seq 1 $MDSCOUNT); do
410 local idx=$(($mdtno - 1))
411 wait_result mds${mdtno} \
412 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
414 error "$key state is not '$target' on mds${mdtno}"
421 for mdtno in $(seq 1 $MDSCOUNT); do
422 local idx=$(($mdtno - 1))
423 local cl_user=$(do_facet mds${mdtno} $LCTL \
424 --device ${MDT[$idx]} \
425 changelog_register -n)
427 do_facet mds${mdtno} lctl set_param \
428 mdd.${MDT[$idx]}.changelog_mask="+hsm"
429 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
433 changelog_cleanup() {
435 for mdtno in $(seq 1 $MDSCOUNT); do
436 local idx=$(($mdtno - 1))
437 [[ -z ${CL_USERS[$idx]} ]] && continue
438 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
439 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
440 changelog_deregister ${CL_USERS[$idx]}
445 changelog_get_flags() {
450 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
455 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
463 mdts_set_param "$opt -n" "hsm.$param" "$value"
470 mdts_set_param "" hsm_control "$cmd"
471 mdts_check_param hsm_control "$target" 10
474 cdt_set_sanity_policy() {
475 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
478 mdts_set_param "" hsm.policy "+NRA"
479 mdts_set_param "" hsm.policy "-NBR"
480 CDT_POLICY_HAD_CHANGED=
485 mdts_set_param "" hsm.policy "+NRA"
486 CDT_POLICY_HAD_CHANGED=true
489 cdt_clear_no_retry() {
490 mdts_set_param "" hsm.policy "-NRA"
491 CDT_POLICY_HAD_CHANGED=true
494 cdt_set_non_blocking_restore() {
495 mdts_set_param "" hsm.policy "+NBR"
496 CDT_POLICY_HAD_CHANGED=true
499 cdt_clear_non_blocking_restore() {
500 mdts_set_param "" hsm.policy "-NBR"
501 CDT_POLICY_HAD_CHANGED=true
504 cdt_clear_mount_state() {
505 mdts_set_param "-P -d" hsm_control ""
508 cdt_set_mount_state() {
509 mdts_set_param "-P" hsm_control "$1"
510 # set_param -P is asynchronous operation and could race with set_param.
511 # In such case configs could be retrieved and applied at mgc after
512 # set_param -P completion. Sleep here to avoid race with set_param.
513 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
514 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
515 # and 10 seconds to retrieve config from server.
520 mdts_check_param hsm_control "$1" 20
524 set_test_state disabled disabled
528 set_test_state enabled enabled
532 set_test_state shutdown stopped
536 set_test_state purge enabled
542 cdt_set_sanity_policy
546 local client_count=$1
547 if [[ $CLIENTCOUNT -lt $client_count ]]; then
548 skip "Need $client_count or more clients, have $CLIENTCOUNT"
555 $LFS path2fid $1 | tr -d '[]'
556 return ${PIPESTATUS[0]}
564 if [[ $u == "user" ]]; then
565 st=$($RUNAS $LFS hsm_state $f)
568 st=$($LFS hsm_state $f)
571 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
573 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
577 get_hsm_archive_id() {
580 st=$($LFS hsm_state $f)
581 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
583 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
592 local st=$(get_hsm_flags $f)
593 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
596 check_hsm_flags_user() {
600 local st=$(get_hsm_flags $f user)
601 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
604 file_creation_failure() {
609 df $MOUNT $MOUNT2 >&2
610 error "cannot create $f with $cmd, status=$err"
622 if [[ "$3" != 1 ]]; then
626 cp $1 $f || file_creation_failure cp $f $?
628 path2fid $f || error "cannot get fid on $f"
632 local file2=${1/$DIR/$DIR2}
633 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
634 file_creation_failure dd $file2 $?
636 path2fid $1 || error "cannot get fid on $1"
640 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
641 file_creation_failure dd $1 $?
642 path2fid $1 || error "cannot get fid on $1"
645 cleanup_large_files() {
646 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
648 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
651 check_enough_free_space() {
654 local need=$((nb * unit /1024))
655 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
656 (( $need >= $free )) && return 1
660 make_large_for_striping() {
661 local file2=${1/$DIR/$DIR2}
662 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
666 check_enough_free_space 5 $sz
667 [ $? != 0 ] && return $?
669 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
670 file_creation_failure dd $file2 $?
672 path2fid $1 || error "cannot get fid on $1"
675 make_large_for_progress() {
676 local file2=${1/$DIR/$DIR2}
680 check_enough_free_space 39 1000000
681 [ $? != 0 ] && return $?
683 # big file is large enough, so copy time is > 30s
684 # so copytool make 1 progress
685 # size is not a multiple of 1M to avoid stripe
687 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
688 file_creation_failure dd $file2 $?
690 path2fid $1 || error "cannot get fid on $1"
693 make_large_for_progress_aligned() {
694 local file2=${1/$DIR/$DIR2}
698 check_enough_free_space 33 1048576
699 [ $? != 0 ] && return $?
701 # big file is large enough, so copy time is > 30s
702 # so copytool make 1 progress
703 # size is a multiple of 1M to have stripe
705 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
706 file_creation_failure dd $file2 $?
707 path2fid $1 || error "cannot get fid on $1"
710 make_large_for_cancel() {
711 local file2=${1/$DIR/$DIR2}
715 check_enough_free_space 103 1048576
716 [ $? != 0 ] && return $?
718 # Copy timeout is 100s. 105MB => 105s
719 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
720 file_creation_failure dd $file2 $?
721 path2fid $1 || error "cannot get fid on $1"
727 wait_update --verbose $(facet_active_host $facet) "$@"
730 wait_request_state() {
734 # 4th arg (mdt index) is optional
736 local mds=mds$(($mdtidx + 1))
738 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
739 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
741 wait_result $mds "$cmd" $state 200 ||
742 error "request on $fid is not $state on $mds"
745 get_request_state() {
749 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
750 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
753 get_request_count() {
757 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
758 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
765 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
766 [[ -n $fid ]] && cmd+=" | grep '$fid'"
767 cmd+=" | egrep 'WAITING|STARTED'"
769 wait_result $SINGLEMDS "$cmd" "" $timeout ||
770 error "requests did not complete"
773 wait_for_grace_delay() {
774 local val=$(get_hsm_param grace_delay)
781 # python2.6 in EL6 includes an internal json module
782 local json_parser='import json; import fileinput;'
783 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
784 json_parser+='json.loads([line for line in '
785 json_parser+='fileinput.input()][0]).items()])'
787 echo $raw_event | python -c "$json_parser"
790 # populate MDT device array
796 # cleanup from previous bad setup
797 search_and_kill_copytool
799 # for recovery tests, coordinator needs to be started at mount
801 # the lustre conf must be without hsm on (like for sanity.sh)
802 echo "Set HSM on and start"
803 cdt_set_mount_state enabled
804 cdt_check_state enabled
806 echo "Start copytool"
809 echo "Set sanity-hsm HSM policy"
810 cdt_set_sanity_policy
812 # finished requests are quickly removed from list
813 set_hsm_param grace_delay 10
819 local f=$DIR/$tdir/$tfile
823 check_hsm_flags_user $f "0x00000000"
825 $RUNAS $LFS hsm_set --norelease $f ||
826 error "user could not change hsm flags"
827 check_hsm_flags_user $f "0x00000010"
829 $RUNAS $LFS hsm_clear --norelease $f ||
830 error "user could not clear hsm flags"
831 check_hsm_flags_user $f "0x00000000"
833 # User could not change those flags...
834 $RUNAS $LFS hsm_set --exists $f &&
835 error "user should not set this flag"
836 check_hsm_flags_user $f "0x00000000"
839 $LFS hsm_set --exists $f ||
840 error "root could not change hsm flags"
841 check_hsm_flags_user $f "0x00000001"
843 $LFS hsm_clear --exists $f ||
844 error "root could not clear hsm state"
845 check_hsm_flags_user $f "0x00000000"
848 run_test 1 "lfs hsm flags root/non-root access"
852 local f=$DIR/$tdir/$tfile
853 local fid=$(make_small $f)
855 $LFS hsm_archive $f || error "could not archive file"
856 wait_request_state $fid ARCHIVE SUCCEED
858 # Release and check states
859 $LFS hsm_release $f || error "could not release file"
860 echo -n "Verifying released state: "
861 check_hsm_flags $f "0x0000000d"
863 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
865 run_test 1a "mmap & cat a HSM released file"
869 local f=$DIR/$tdir/$tfile
871 # New files are not dirty
872 check_hsm_flags $f "0x00000000"
874 # For test, we simulate an archived file.
875 $LFS hsm_set --exists $f || error "user could not change hsm flags"
876 check_hsm_flags $f "0x00000001"
878 # chmod do not put the file dirty
879 chmod 600 $f || error "could not chmod test file"
880 check_hsm_flags $f "0x00000001"
882 # chown do not put the file dirty
883 chown $RUNAS_ID $f || error "could not chown test file"
884 check_hsm_flags $f "0x00000001"
886 # truncate put the file dirty
887 $TRUNCATE $f 1 || error "could not truncate test file"
888 check_hsm_flags $f "0x00000003"
890 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
891 check_hsm_flags $f "0x00000001"
893 run_test 2 "Check file dirtyness when doing setattr"
899 # New files are not dirty
901 check_hsm_flags $f "0x00000000"
903 # For test, we simulate an archived file.
904 $LFS hsm_set --exists $f ||
905 error "user could not change hsm flags"
906 check_hsm_flags $f "0x00000001"
908 # Reading a file, does not set dirty
909 cat $f > /dev/null || error "could not read file"
910 check_hsm_flags $f "0x00000001"
912 # Open for write without modifying data, does not set dirty
913 openfile -f O_WRONLY $f || error "could not open test file"
914 check_hsm_flags $f "0x00000001"
916 # Append to a file sets it dirty
917 cp -p /etc/passwd $f.append || error "could not create file"
918 $LFS hsm_set --exists $f.append ||
919 error "user could not change hsm flags"
920 dd if=/etc/passwd of=$f.append bs=1 count=3\
921 conv=notrunc oflag=append status=noxfer ||
922 file_creation_failure dd $f.append $?
923 check_hsm_flags $f.append "0x00000003"
925 # Modify a file sets it dirty
926 cp -p /etc/passwd $f.modify || error "could not create file"
927 $LFS hsm_set --exists $f.modify ||
928 error "user could not change hsm flags"
929 dd if=/dev/zero of=$f.modify bs=1 count=3\
930 conv=notrunc status=noxfer ||
931 file_creation_failure dd $f.modify $?
932 check_hsm_flags $f.modify "0x00000003"
934 # Open O_TRUNC sets dirty
935 cp -p /etc/passwd $f.trunc || error "could not create file"
936 $LFS hsm_set --exists $f.trunc ||
937 error "user could not change hsm flags"
938 cp /etc/group $f.trunc || error "could not override a file"
939 check_hsm_flags $f.trunc "0x00000003"
941 # Mmapped a file sets dirty
942 cp -p /etc/passwd $f.mmap || error "could not create file"
943 $LFS hsm_set --exists $f.mmap ||
944 error "user could not change hsm flags"
945 multiop $f.mmap OSMWUc || error "could not mmap a file"
946 check_hsm_flags $f.mmap "0x00000003"
948 run_test 3 "Check file dirtyness when opening for write"
952 local f=$DIR/$tdir/$tfile
953 local fid=$(make_small $f)
956 local st=$(get_request_state $fid CANCEL)
957 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
959 run_test 4 "Useless cancel must not be registered"
962 # test needs a running copytool
966 local f=$DIR/$tdir/$tfile
967 local fid=$(copy_file /etc/passwd $f)
969 wait_request_state $fid ARCHIVE SUCCEED
971 check_hsm_flags $f "0x00000009"
975 run_test 8 "Test default archive number"
979 local f=$DIR/$tdir/$tfile
980 local fid=$(copy_file /etc/passwd $f)
981 # we do not use the default one to be sure
982 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
984 copytool_setup $SINGLEAGT $MOUNT $new_an
985 $LFS hsm_archive --archive $new_an $f
986 wait_request_state $fid ARCHIVE SUCCEED
988 check_hsm_flags $f "0x00000009"
992 run_test 9 "Use of explicit archive number, with dedicated copytool"
995 needclients 3 || return 0
1001 copytool_cleanup $(comma_list $(agts_nodes))
1003 # start all of the copytools
1004 for n in $(seq $AGTCOUNT); do
1005 copytool_setup agt$n
1008 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1011 for n in $(seq $AGTCOUNT); do
1012 file=$DIR/$tdir/$tfile.$n
1013 fid=$(make_small $file)
1015 $LFS hsm_archive $file || error "could not archive file $file"
1016 wait_request_state $fid ARCHIVE SUCCEED
1017 check_hsm_flags $file "0x00000009"
1021 copytool_cleanup $(comma_list $(agts_nodes))
1023 run_test 9a "Multiple remote agents"
1026 # test needs a running copytool
1029 mkdir -p $DIR/$tdir/d1
1030 local f=$DIR/$tdir/$tfile
1031 local fid=$(copy_file /etc/hosts $f)
1032 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1033 error "hsm_archive failed"
1034 wait_request_state $fid ARCHIVE SUCCEED
1036 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1037 error "fid $fid not in archive $HSM_ARCHIVE"
1038 echo "Verifying content"
1039 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1040 echo "Verifying hsm state "
1041 check_hsm_flags $f "0x00000009"
1043 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1044 local st=$(get_hsm_archive_id $f)
1045 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1046 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1051 run_test 10a "Archive a file"
1054 # test needs a running copytool
1058 local f=$DIR/$tdir/$tfile
1059 local fid=$(copy_file /etc/hosts $f)
1060 $LFS hsm_archive $f || error "archive request failed"
1061 wait_request_state $fid ARCHIVE SUCCEED
1063 $LFS hsm_archive $f || error "archive of non dirty file failed"
1064 local cnt=$(get_request_count $fid ARCHIVE)
1065 [[ "$cnt" == "1" ]] ||
1066 error "archive of non dirty file must not make a request"
1070 run_test 10b "Archive of non dirty file must work without doing request"
1073 # test needs a running copytool
1077 local f=$DIR/$tdir/$tfile
1078 local fid=$(copy_file /etc/hosts $f)
1079 $LFS hsm_set --noarchive $f
1080 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1084 run_test 10c "Check forbidden archive"
1087 # test needs a running copytool
1091 local f=$DIR/$tdir/$tfile
1092 local fid=$(copy_file /etc/hosts $f)
1093 $LFS hsm_archive $f || error "cannot archive $f"
1094 wait_request_state $fid ARCHIVE SUCCEED
1096 local ar=$(get_hsm_archive_id $f)
1097 local dflt=$(get_hsm_param default_archive_id)
1098 [[ $ar == $dflt ]] ||
1099 error "archived file is not on default archive: $ar != $dflt"
1103 run_test 10d "Archive a file on the default archive id"
1107 copy2archive /etc/hosts $tdir/$tfile
1108 local f=$DIR/$tdir/$tfile
1110 import_file $tdir/$tfile $f
1111 echo -n "Verifying released state: "
1112 check_hsm_flags $f "0x0000000d"
1114 local LSZ=$(stat -c "%s" $f)
1115 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1117 echo "Verifying imported size $LSZ=$ASZ"
1118 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1119 echo -n "Verifying released pattern: "
1120 local PTRN=$($GETSTRIPE -L $f)
1122 [[ $PTRN == 80000001 ]] || error "Is not released"
1123 local fid=$(path2fid $f)
1124 echo "Verifying new fid $fid in archive"
1126 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1127 error "fid $fid not in archive $HSM_ARCHIVE"
1129 run_test 11a "Import a file"
1132 # test needs a running copytool
1136 local f=$DIR/$tdir/$tfile
1137 local fid=$(copy_file /etc/hosts $f)
1138 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1139 error "hsm_archive failed"
1140 wait_request_state $fid ARCHIVE SUCCEED
1142 local FILE_HASH=$(md5sum $f)
1147 echo "$FILE_HASH" | md5sum -c
1149 [[ $? -eq 0 ]] || error "Restored file differs"
1153 run_test 11b "Import a deleted file using its FID"
1156 # test needs a running copytool
1160 copy2archive /etc/hosts $tdir/$tfile
1162 local f=$DIR/$tdir/$tfile
1163 import_file $tdir/$tfile $f
1164 local f2=$DIR2/$tdir/$tfile
1165 echo "Verifying released state: "
1166 check_hsm_flags $f2 "0x0000000d"
1168 local fid=$(path2fid $f2)
1169 $LFS hsm_restore $f2
1170 wait_request_state $fid RESTORE SUCCEED
1172 echo "Verifying file state: "
1173 check_hsm_flags $f2 "0x00000009"
1175 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1177 [[ $? -eq 0 ]] || error "Restored file differs"
1181 run_test 12a "Restore an imported file explicitly"
1184 # test needs a running copytool
1188 copy2archive /etc/hosts $tdir/$tfile
1190 local f=$DIR/$tdir/$tfile
1191 import_file $tdir/$tfile $f
1192 echo "Verifying released state: "
1193 check_hsm_flags $f "0x0000000d"
1195 cat $f > /dev/null || error "File read failed"
1197 echo "Verifying file state after restore: "
1198 check_hsm_flags $f "0x00000009"
1200 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1202 [[ $? -eq 0 ]] || error "Restored file differs"
1206 run_test 12b "Restore an imported file implicitly"
1209 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1211 # test needs a running copytool
1215 local f=$DIR/$tdir/$tfile
1216 $LFS setstripe -c 2 $f
1218 fid=$(make_large_for_striping $f)
1219 [ $? != 0 ] && skip "not enough free space" && return
1221 local FILE_CRC=$(md5sum $f)
1223 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1224 wait_request_state $fid ARCHIVE SUCCEED
1225 $LFS hsm_release $f || error "release $f failed"
1227 echo "$FILE_CRC" | md5sum -c
1229 [[ $? -eq 0 ]] || error "Restored file differs"
1233 run_test 12c "Restore a file with stripe of 2"
1236 # test needs a running copytool
1241 local f=$DIR/$tdir/$tfile
1242 local fid=$(copy_file /etc/hosts $f)
1243 $LFS hsm_restore $f || error "restore of non archived file failed"
1244 local cnt=$(get_request_count $fid RESTORE)
1245 [[ "$cnt" == "0" ]] ||
1246 error "restore non archived must not make a request"
1247 $LFS hsm_archive $f ||
1248 error "archive request failed"
1249 wait_request_state $fid ARCHIVE SUCCEED
1250 $LFS hsm_restore $f ||
1251 error "restore of non released file failed"
1252 local cnt=$(get_request_count $fid RESTORE)
1253 [[ "$cnt" == "0" ]] ||
1254 error "restore a non dirty file must not make a request"
1258 run_test 12d "Restore of a non archived, non released file must work"\
1259 " without doing request"
1262 # test needs a running copytool
1265 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1266 local f=$DIR/$tdir/$tfile
1267 local fid=$(copy_file /etc/hosts $f)
1268 $LFS hsm_archive $f || error "archive request failed"
1269 wait_request_state $fid ARCHIVE SUCCEED
1272 cat /etc/hosts >> $f
1276 $LFS hsm_restore $f && error "restore a dirty file must fail"
1280 run_test 12e "Check forbidden restore"
1283 # test needs a running copytool
1287 local f=$DIR/$tdir/$tfile
1288 local fid=$(copy_file /etc/hosts $f)
1290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1291 wait_request_state $fid ARCHIVE SUCCEED
1292 $LFS hsm_release $f || error "release of $f failed"
1294 wait_request_state $fid RESTORE SUCCEED
1296 echo -n "Verifying file state: "
1297 check_hsm_flags $f "0x00000009"
1299 diff -q /etc/hosts $f
1301 [[ $? -eq 0 ]] || error "Restored file differs"
1305 run_test 12f "Restore a released file explicitly"
1308 # test needs a running copytool
1312 local f=$DIR/$tdir/$tfile
1313 local fid=$(copy_file /etc/hosts $f)
1315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1316 wait_request_state $fid ARCHIVE SUCCEED
1317 $LFS hsm_release $f || error "release of $f failed"
1319 diff -q /etc/hosts $f
1322 # we check we had a restore done
1323 wait_request_state $fid RESTORE SUCCEED
1325 [[ $st -eq 0 ]] || error "Restored file differs"
1329 run_test 12g "Restore a released file implicitly"
1332 needclients 2 || return 0
1334 # test needs a running copytool
1338 local f=$DIR/$tdir/$tfile
1339 local fid=$(copy_file /etc/hosts $f)
1341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1342 wait_request_state $fid ARCHIVE SUCCEED
1343 $LFS hsm_release $f || error "release of $f failed"
1345 do_node $CLIENT2 diff -q /etc/hosts $f
1348 # we check we had a restore done
1349 wait_request_state $fid RESTORE SUCCEED
1351 [[ $st -eq 0 ]] || error "Restored file differs"
1355 run_test 12h "Restore a released file implicitly from a second node"
1358 # test needs a running copytool
1362 local f=$DIR/$tdir/$tfile
1363 local fid=$(copy_file /etc/passwd $f)
1364 $LFS hsm_archive $f || error "archive of $f failed"
1365 wait_request_state $fid ARCHIVE SUCCEED
1367 $LFS hsm_release $f || error "release of $f failed"
1371 [[ $? -eq 0 ]] || error "Restored file differs"
1375 run_test 12m "Archive/release/implicit restore"
1378 # test needs a running copytool
1382 copy2archive /etc/hosts $tdir/$tfile
1384 local f=$DIR/$tdir/$tfile
1385 import_file $tdir/$tfile $f
1387 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1388 error "Restored file differs"
1390 $LFS hsm_release $f || error "release of $f failed"
1394 run_test 12n "Import/implicit restore/release"
1397 # test needs a running copytool
1401 local f=$DIR/$tdir/$tfile
1402 local fid=$(copy_file /etc/hosts $f)
1404 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1405 wait_request_state $fid ARCHIVE SUCCEED
1406 $LFS hsm_release $f || error "release of $f failed"
1408 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1409 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1411 # set no retry action mode
1414 diff -q /etc/hosts $f
1417 # we check we had a restore failure
1418 wait_request_state $fid RESTORE FAILED
1420 [[ $st -eq 0 ]] && error "Restore must fail"
1422 # remove no retry action mode
1425 # check file is still released
1426 check_hsm_flags $f "0x0000000d"
1428 # retry w/o failure injection
1429 do_facet $SINGLEMDS lctl set_param fail_loc=0
1431 # to be sure previous RESTORE result is gone
1433 wait_for_grace_delay
1435 diff -q /etc/hosts $f
1438 # we check we had a restore done
1439 wait_request_state $fid RESTORE SUCCEED
1441 [[ $st -eq 0 ]] || error "Restored file differs"
1445 run_test 12o "Layout-swap failure during Restore leaves file released"
1448 # test needs a running copytool
1452 local f=$DIR/$tdir/$tfile
1453 local fid=$(copy_file /etc/hosts $f)
1455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1456 wait_request_state $fid ARCHIVE SUCCEED
1457 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1458 $LFS hsm_release $f || error "cannot release $f"
1459 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1460 $LFS hsm_release $f || error "cannot release $f"
1461 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1465 run_test 12p "implicit restore of a file on copytool mount point"
1467 cleanup_test_12q() {
1469 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1470 error "cannot umount $MOUNT3 on $SINGLEAGT"
1474 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1475 skip "need MDS version at least 2.7.58" && return 0
1477 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1478 error "cannot mount $MOUNT3 on $SINGLEAGT"
1480 trap cleanup_test_12q EXIT
1482 # test needs a running copytool
1483 copytool_setup $SINGLEAGT $MOUNT3
1486 local f=$DIR/$tdir/$tfile
1487 local f2=$DIR2/$tdir/$tfile
1488 local fid=$(make_small $f)
1489 local orig_size=$(stat -c "%s" $f)
1491 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1492 wait_request_state $fid ARCHIVE SUCCEED
1494 $LFS hsm_release $f || error "could not release file"
1495 check_hsm_flags $f "0x0000000d"
1497 search_and_kill_copytool
1499 search_copytools && error "Copytool should have stopped"
1501 cat $f > /dev/null &
1503 # wait a bit to allow implicit restore request to be handled.
1504 # if not, next stat would also block on layout-lock.
1507 local size=$(stat -c "%s" $f2)
1508 [ $size -eq $orig_size ] ||
1509 error "$f2: wrong size after archive: $size != $orig_size"
1511 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1515 size=$(stat -c "%s" $f)
1516 [ $size -eq $orig_size ] ||
1517 error "$f: wrong size after restore: $size != $orig_size"
1519 size=$(stat -c "%s" $f2)
1520 [ $size -eq $orig_size ] ||
1521 error "$f2: wrong size after restore: $size != $orig_size"
1525 size=$(stat -c "%s" $f)
1527 error "$f: wrong size after overwrite: $size != 0"
1529 size=$(stat -c "%s" $f2)
1531 error "$f2: wrong size after overwrite: $size != 0"
1534 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1535 error "cannot umount $MOUNT3 on $SINGLEAGT"
1537 run_test 12q "file attributes are refreshed after restore"
1540 # test needs a running copytool
1543 local ARC_SUBDIR="import.orig"
1547 # populate directory to be imported
1548 for d in $(seq 1 10); do
1549 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1550 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1551 for f in $(seq 1 10); do
1552 CURR_FILE="$CURR_DIR/$tfile.$f"
1553 # write file-specific data
1554 do_facet $SINGLEAGT \
1555 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1556 "file=$CURR_FILE > $CURR_FILE"
1560 import_file "$ARC_SUBDIR" $DIR/$tdir
1561 # diff lustre content and origin (triggers file restoration)
1562 # there must be 10x10 identical files, and no difference
1563 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1564 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1565 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1566 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1568 [ $cnt_diff -eq 0 ] ||
1569 error "$cnt_diff imported files differ from read data"
1570 [ $cnt_ok -eq 100 ] ||
1571 error "not enough identical files ($cnt_ok != 100)"
1575 run_test 13 "Recursively import and restore a directory"
1578 # test needs a running copytool
1583 local f=$DIR/$tdir/$tfile
1584 local fid=$(make_small $f)
1585 local sum=$(md5sum $f | awk '{print $1}')
1586 $LFS hsm_archive $f || error "could not archive file"
1587 wait_request_state $fid ARCHIVE SUCCEED
1591 # create released file (simulate llapi_hsm_import call)
1593 local fid2=$(path2fid $f)
1594 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1595 $LFS hsm_release $f || error "could not release file"
1597 # rebind the archive to the newly created file
1598 echo "rebind $fid to $fid2"
1600 do_facet $SINGLEAGT \
1601 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1602 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1604 # restore file and compare md5sum
1605 local sum2=$(md5sum $f | awk '{print $1}')
1607 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1611 run_test 14 "Rebind archived file to a new fid"
1614 # test needs a running copytool
1619 local f=$DIR/$tdir/$tfile
1621 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1625 for i in $(seq 1 $count); do
1626 fids[$i]=$(make_small $f.$i)
1627 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1628 $LFS hsm_archive $f.$i || error "could not archive file"
1630 wait_all_done $(($count*60))
1634 for i in $(seq 1 $count); do
1637 local fid2=$(path2fid $f.$i)
1638 # add the rebind operation to the list
1639 echo ${fids[$i]} $fid2 >> $tmpfile
1641 # set it released (simulate llapi_hsm_import call)
1642 $LFS hsm_set --archived --exists $f.$i ||
1643 error "could not force hsm flags"
1644 $LFS hsm_release $f.$i || error "could not release file"
1646 nl=$(wc -l < $tmpfile)
1647 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1649 echo "rebind list of files"
1650 do_facet $SINGLEAGT \
1651 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1652 --rebind $tmpfile $DIR" || error "could not rebind file list"
1654 # restore files and compare md5sum
1655 for i in $(seq 1 $count); do
1656 local sum2=$(md5sum $f.$i | awk '{print $1}')
1657 [[ $sum2 == ${sums[$i]} ]] ||
1658 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1664 run_test 15 "Rebind a list of files"
1667 # test needs a running copytool
1671 # create a known size file so we can verify transfer speed
1674 dd if=/dev/zero of=$ref bs=1M count=20
1677 local f=$DIR/$tdir/$tfile
1678 local fid=$(copy_file $ref $f)
1680 local start=$(date +%s)
1682 wait_request_state $fid ARCHIVE SUCCEED
1683 local end=$(date +%s)
1684 local duration=$((end - start))
1686 [[ $duration -ge $goal ]] ||
1687 error "Transfer is too fast $duration < $goal"
1691 run_test 16 "Test CT bandwith control option"
1696 local f=$DIR/$tdir/$tfile
1697 touch $f || error "touch $f failed"
1699 # Could not release a non-archived file
1700 $LFS hsm_release $f && error "release should not succeed"
1702 # For following tests, we must test them with HS_ARCHIVED set
1703 $LFS hsm_set --exists --archived $f || error "could not add flag"
1705 # Could not release a file if no-release is set
1706 $LFS hsm_set --norelease $f || error "could not add flag"
1707 $LFS hsm_release $f && error "release should not succeed"
1708 $LFS hsm_clear --norelease $f || error "could not remove flag"
1710 # Could not release a file if lost
1711 $LFS hsm_set --lost $f || error "could not add flag"
1712 $LFS hsm_release $f && error "release should not succeed"
1713 $LFS hsm_clear --lost $f || error "could not remove flag"
1715 # Could not release a file if dirty
1716 $LFS hsm_set --dirty $f || error "could not add flag"
1717 $LFS hsm_release $f && error "release should not succeed"
1718 $LFS hsm_clear --dirty $f || error "could not remove flag"
1720 run_test 20 "Release is not permitted"
1723 # test needs a running copytool
1727 local f=$DIR/$tdir/test_release
1729 # Create a file and check its states
1730 local fid=$(make_small $f)
1731 check_hsm_flags $f "0x00000000"
1733 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1734 # used until file is flushed to disk
1735 if [ $(facet_fstype ost1) == "zfs" ]; then
1736 # this causes an OST_SYNC rpc to be sent
1737 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1738 # clear locks to reread file data
1739 cancel_lru_locks osc
1742 local orig_size=$(stat -c "%s" $f)
1743 local orig_blocks=$(stat -c "%b" $f)
1745 start_full_debug_logging
1747 $LFS hsm_archive $f || error "could not archive file"
1748 wait_request_state $fid ARCHIVE SUCCEED
1750 local blocks=$(stat -c "%b" $f)
1751 [ $blocks -eq $orig_blocks ] ||
1752 error "$f: wrong block number after archive: " \
1753 "$blocks != $orig_blocks"
1754 local size=$(stat -c "%s" $f)
1755 [ $size -eq $orig_size ] ||
1756 error "$f: wrong size after archive: $size != $orig_size"
1758 # Release and check states
1759 $LFS hsm_release $f || error "could not release file"
1760 check_hsm_flags $f "0x0000000d"
1762 blocks=$(stat -c "%b" $f)
1763 [ $blocks -gt 5 ] &&
1764 error "$f: too many blocks after release: $blocks > 5"
1765 size=$(stat -c "%s" $f)
1766 [ $size -ne $orig_size ] &&
1767 error "$f: wrong size after release: $size != $orig_size"
1769 # Check we can release an file without stripe info
1773 check_hsm_flags $f "0x00000000"
1774 $LFS hsm_archive $f || error "could not archive file"
1775 wait_request_state $fid ARCHIVE SUCCEED
1777 # Release and check states
1778 $LFS hsm_release $f || error "could not release file"
1779 check_hsm_flags $f "0x0000000d"
1781 # Release again a file that is already released is OK
1782 $LFS hsm_release $f || fail "second release should succeed"
1783 check_hsm_flags $f "0x0000000d"
1785 stop_full_debug_logging
1789 run_test 21 "Simple release tests"
1792 # test needs a running copytool
1797 local f=$DIR/$tdir/test_release
1798 local swap=$DIR/$tdir/test_swap
1800 # Create a file and check its states
1801 local fid=$(make_small $f)
1802 check_hsm_flags $f "0x00000000"
1804 $LFS hsm_archive $f || error "could not archive file"
1805 wait_request_state $fid ARCHIVE SUCCEED
1807 # Release and check states
1808 $LFS hsm_release $f || error "could not release file"
1809 check_hsm_flags $f "0x0000000d"
1812 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1817 run_test 22 "Could not swap a release file"
1820 # test needs a running copytool
1825 local f=$DIR/$tdir/test_mtime
1827 # Create a file and check its states
1828 local fid=$(make_small $f)
1829 check_hsm_flags $f "0x00000000"
1831 $LFS hsm_archive $f || error "could not archive file"
1832 wait_request_state $fid ARCHIVE SUCCEED
1834 # Set modification time in the past
1835 touch -m -a -d @978261179 $f
1837 # Release and check states
1838 $LFS hsm_release $f || error "could not release file"
1839 check_hsm_flags $f "0x0000000d"
1841 local MTIME=$(stat -c "%Y" $f)
1842 local ATIME=$(stat -c "%X" $f)
1843 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1844 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1848 run_test 23 "Release does not change a/mtime (utime)"
1851 local file=$DIR/$tdir/$tfile
1860 # test needs a running copytool
1865 fid=$(make_small $file)
1867 # Create a file and check its states
1868 check_hsm_flags $file "0x00000000"
1870 # Ensure atime is less than mtime and ctime.
1874 atime0=$(stat -c "%X" $file)
1875 mtime0=$(stat -c "%Y" $file)
1876 ctime0=$(stat -c "%Z" $file)
1878 [ $atime0 -lt $mtime0 ] ||
1879 error "atime $atime0 is not less than mtime $mtime0"
1881 [ $atime0 -lt $ctime0 ] ||
1882 error "atime $atime0 is not less than ctime $ctime0"
1884 # Archive should not change any timestamps.
1885 $LFS hsm_archive $file || error "cannot archive '$file'"
1886 wait_request_state $fid ARCHIVE SUCCEED
1888 atime1=$(stat -c "%X" $file)
1889 mtime1=$(stat -c "%Y" $file)
1890 ctime1=$(stat -c "%Z" $file)
1892 [ $atime0 -eq $atime1 ] ||
1893 error "archive changed atime from $atime0 to $atime1"
1895 [ $mtime0 -eq $mtime1 ] ||
1896 error "archive changed mtime from $mtime0 to $mtime1"
1898 [ $ctime0 -eq $ctime1 ] ||
1899 error "archive changed ctime from $ctime0 to $ctime1"
1901 # Release should not change any timestamps.
1902 $LFS hsm_release $file || error "cannot release '$file'"
1903 check_hsm_flags $file "0x0000000d"
1905 atime1=$(stat -c "%X" $file)
1906 mtime1=$(stat -c "%Y" $file)
1907 ctime1=$(stat -c "%Z" $file)
1909 [ $atime0 -eq $atime1 ] ||
1910 error "release changed atime from $atime0 to $atime1"
1912 [ $mtime0 -eq $mtime1 ] ||
1913 error "release changed mtime from $mtime0 to $mtime1"
1915 [ $ctime0 -eq $ctime1 ] ||
1916 error "release changed ctime from $ctime0 to $ctime1"
1918 # Restore should not change atime or mtime and should not
1920 $LFS hsm_restore $file
1921 wait_request_state $fid RESTORE SUCCEED
1923 atime1=$(stat -c "%X" $file)
1924 mtime1=$(stat -c "%Y" $file)
1925 ctime1=$(stat -c "%Z" $file)
1927 [ $atime0 -eq $atime1 ] ||
1928 error "restore changed atime from $atime0 to $atime1"
1930 [ $mtime0 -eq $mtime1 ] ||
1931 error "restore changed mtime from $mtime0 to $mtime1"
1933 [ $ctime0 -eq $ctime1 ] ||
1934 error "restore changed ctime from $ctime0 to $ctime1"
1938 # Once more, after unmount and mount.
1939 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1940 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1942 atime1=$(stat -c "%X" $file)
1943 mtime1=$(stat -c "%Y" $file)
1944 ctime1=$(stat -c "%Z" $file)
1946 [ $atime0 -eq $atime1 ] ||
1947 error "remount changed atime from $atime0 to $atime1"
1949 [ $mtime0 -eq $mtime1 ] ||
1950 error "remount changed mtime from $mtime0 to $mtime1"
1952 [ $ctime0 -eq $ctime1 ] ||
1953 error "remount changed ctime from $ctime0 to $ctime1"
1955 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1958 local file=$DIR/$tdir/$tfile
1964 # Test needs a running copytool.
1968 # Check that root can do HSM actions on a regular user's file.
1970 fid=$(make_small $file)
1971 sum0=$(md5sum $file)
1973 chown $RUNAS_ID:$RUNAS_GID $file ||
1974 error "cannot chown '$file' to '$RUNAS_ID'"
1976 chmod ugo-w $DIR/$tdir ||
1977 error "cannot chmod '$DIR/$tdir'"
1979 $LFS hsm_archive $file
1980 wait_request_state $fid ARCHIVE SUCCEED
1982 $LFS hsm_release $file
1983 check_hsm_flags $file "0x0000000d"
1985 $LFS hsm_restore $file
1986 wait_request_state $fid RESTORE SUCCEED
1988 # Check that ordinary user can get HSM state.
1989 $RUNAS $LFS hsm_state $file ||
1990 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1992 $LFS hsm_release $file
1993 check_hsm_flags $file "0x0000000d"
1995 # Check that ordinary user can accessed released file.
1996 sum1=$($RUNAS md5sum $file) ||
1997 error "user '$RUNAS_ID' cannot read '$file'"
1999 [ "$sum0" == "$sum1" ] ||
2000 error "md5sum mismatch for '$file'"
2004 run_test 24b "root can archive, release, and restore user files"
2006 cleanup_test_24c() {
2008 set_hsm_param user_request_mask RESTORE
2009 set_hsm_param group_request_mask RESTORE
2010 set_hsm_param other_request_mask RESTORE
2014 local file=$DIR/$tdir/$tfile
2015 local action=archive
2020 # test needs a running copytool
2025 # Save the default masks and check that cleanup_24c will
2026 # restore the request masks correctly.
2027 user_save=$(get_hsm_param user_request_mask)
2028 group_save=$(get_hsm_param group_request_mask)
2029 other_save=$(get_hsm_param other_request_mask)
2031 [ "$user_save" == RESTORE ] ||
2032 error "user_request_mask is '$user_save' expected 'RESTORE'"
2033 [ "$group_save" == RESTORE ] ||
2034 error "group_request_mask is '$group_save' expected 'RESTORE'"
2035 [ "$other_save" == RESTORE ] ||
2036 error "other_request_mask is '$other_save' expected 'RESTORE'"
2038 trap cleanup_test_24c EXIT
2043 chown $RUNAS_ID:nobody $file ||
2044 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2046 set_hsm_param user_request_mask ""
2047 $RUNAS $LFS hsm_$action $file &&
2048 error "$action by user should fail"
2050 set_hsm_param user_request_mask $action
2051 $RUNAS $LFS hsm_$action $file ||
2052 error "$action by user should succeed"
2057 chown nobody:$RUNAS_GID $file ||
2058 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2060 set_hsm_param group_request_mask ""
2061 $RUNAS $LFS hsm_$action $file &&
2062 error "$action by group should fail"
2064 set_hsm_param group_request_mask $action
2065 $RUNAS $LFS hsm_$action $file ||
2066 error "$action by group should succeed"
2071 chown nobody:nobody $file ||
2072 error "cannot chown '$file' to 'nobody:nobody'"
2074 set_hsm_param other_request_mask ""
2075 $RUNAS $LFS hsm_$action $file &&
2076 error "$action by other should fail"
2078 set_hsm_param other_request_mask $action
2079 $RUNAS $LFS hsm_$action $file ||
2080 error "$action by other should succeed"
2085 run_test 24c "check that user,group,other request masks work"
2087 cleanup_test_24d() {
2089 mount -o remount,rw $MOUNT2
2093 local file1=$DIR/$tdir/$tfile
2094 local file2=$DIR2/$tdir/$tfile
2102 fid1=$(make_small $file1)
2104 trap cleanup_test_24d EXIT
2106 mount -o remount,ro $MOUNT2
2108 fid2=$(path2fid $file2)
2109 [ "$fid1" == "$fid2" ] ||
2110 error "FID mismatch '$fid1' != '$fid2'"
2112 $LFS hsm_archive $file2 &&
2113 error "archive should fail on read-only mount"
2114 check_hsm_flags $file1 "0x00000000"
2116 $LFS hsm_archive $file1
2117 wait_request_state $fid1 ARCHIVE SUCCEED
2119 $LFS hsm_release $file1
2120 $LFS hsm_restore $file2
2121 wait_request_state $fid1 RESTORE SUCCEED
2123 $LFS hsm_release $file1 || error "cannot release '$file1'"
2124 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2126 $LFS hsm_release $file2 &&
2127 error "release should fail on read-only mount"
2132 run_test 24d "check that read-only mounts are respected"
2139 local f=$DIR/$tdir/$tfile
2142 fid=$(make_small $f) || error "cannot create $f"
2143 $LFS hsm_archive $f || error "cannot archive $f"
2144 wait_request_state $fid ARCHIVE SUCCEED
2145 $LFS hsm_release $f || error "cannot release $f"
2146 while ! $LFS hsm_state $f | grep released; do
2150 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2154 run_test 24e "tar succeeds on HSM released files" # LU-6213
2158 # test needs a running copytool
2161 mkdir -p $DIR/$tdir/d1
2162 local f=$DIR/$tdir/$tfile
2163 local fid=$(copy_file /etc/hosts $f)
2166 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2167 error "hsm_archive failed"
2168 wait_request_state $fid ARCHIVE SUCCEED
2169 $LFS hsm_release $f || error "cannot release $f"
2170 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2173 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2174 error "Can not recover the tar contents"
2176 echo "Sum0 = $sum0, sum1 = $sum1"
2177 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2181 run_test 24f "root can archive, release, and restore tar files"
2184 # test needs a running copytool
2188 copy2archive /etc/hosts $tdir/$tfile
2190 local f=$DIR/$tdir/$tfile
2192 import_file $tdir/$tfile $f
2194 $LFS hsm_set --lost $f
2199 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2203 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2204 " (Operation not permitted)"
2207 # test needs a running copytool
2212 local f=$DIR/$tdir/$tfile
2213 local fid=$(copy_file /etc/passwd $f)
2215 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2216 wait_request_state $fid ARCHIVE SUCCEED
2219 $LFS hsm_set --lost $f
2223 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2227 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2228 " (Operation not permitted)"
2231 # test needs a running copytool
2235 local f=$DIR/$tdir/$tfile
2237 fid=$(make_large_for_progress $f)
2238 [ $? != 0 ] && skip "not enough free space" && return
2240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2241 wait_request_state $fid ARCHIVE SUCCEED
2244 wait_request_state $fid REMOVE SUCCEED
2246 check_hsm_flags $f "0x00000000"
2250 run_test 26 "Remove the archive of a valid file"
2253 # test needs a running copytool
2257 make_archive $tdir/$tfile
2258 local f=$DIR/$tdir/$tfile
2259 import_file $tdir/$tfile $f
2260 local fid=$(path2fid $f)
2264 [[ $? != 0 ]] || error "Remove of a released file should fail"
2268 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2271 # test needs a running copytool
2275 local f=$DIR/$tdir/$tfile
2277 fid=$(make_large_for_progress $f)
2278 [ $? != 0 ] && skip "not enough free space" && return
2280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2281 wait_request_state $fid ARCHIVE SUCCEED
2286 [[ $? != 0 ]] || error "Remove of a released file should fail"
2290 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2293 # test needs a running copytool
2297 local f=$DIR/$tdir/$tfile
2299 fid=$(make_large_for_progress $f)
2300 [ $? != 0 ] && skip "not enough free space" && return
2302 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2303 wait_request_state $fid ARCHIVE SUCCEED
2312 wait_request_state $fid REMOVE SUCCEED
2316 run_test 28 "Concurrent archive/file remove"
2319 # Tests --mntpath and --archive options
2322 copytool_setup $SINGLEAGT $MOUNT $archive_id
2324 # Bad archive number
2325 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2326 grep "Invalid argument" ||
2327 error "unexpected hsm_remove failure (1)"
2329 # mntpath is present but file is given
2330 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2331 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2332 error "unexpected hsm_remove failure (2)"
2336 run_test 29a "Tests --mntpath and --archive options"
2339 # test needs a running copytool
2343 local f=$DIR/$tdir/$tfile
2344 local fid=$(make_small $f)
2346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2347 wait_request_state $fid ARCHIVE SUCCEED
2351 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2352 wait_request_state $fid REMOVE SUCCEED
2356 run_test 29b "Archive/delete/remove by FID from the archive."
2359 # test needs a running copytool
2363 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2364 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2365 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2367 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2368 wait_request_state $fid1 ARCHIVE SUCCEED
2369 wait_request_state $fid2 ARCHIVE SUCCEED
2370 wait_request_state $fid3 ARCHIVE SUCCEED
2372 rm -f $DIR/$tdir/$tfile-[1-3]
2374 echo $fid1 > $DIR/$tdir/list
2375 echo $fid2 >> $DIR/$tdir/list
2376 echo $fid3 >> $DIR/$tdir/list
2378 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2379 --filelist $DIR/$tdir/list
2380 wait_request_state $fid1 REMOVE SUCCEED
2381 wait_request_state $fid2 REMOVE SUCCEED
2382 wait_request_state $fid3 REMOVE SUCCEED
2386 run_test 29c "Archive/delete/remove by FID, using a file list."
2389 # restore at exec cannot work on agent node (because of Linux kernel
2390 # protection of executables)
2391 needclients 2 || return 0
2393 # test needs a running copytool
2397 copy2archive /bin/true $tdir/$tfile
2399 local f=$DIR/$tdir/true
2400 import_file $tdir/$tfile $f
2402 local fid=$(path2fid $f)
2404 # set no retry action mode
2410 # remove no try action mode
2414 [[ $st == 0 ]] || error "Failed to exec a released file"
2418 run_test 30a "Restore at exec (import case)"
2421 # restore at exec cannot work on agent node (because of Linux kernel
2422 # protection of executables)
2423 needclients 2 || return 0
2425 # test needs a running copytool
2429 local f=$DIR/$tdir/true
2430 local fid=$(copy_file /bin/true $f)
2432 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2433 wait_request_state $fid ARCHIVE SUCCEED
2436 # set no retry action mode
2442 # remove no try action mode
2446 [[ $st == 0 ]] || error "Failed to exec a released file"
2450 run_test 30b "Restore at exec (release case)"
2453 needclients 2 || return 0
2455 # test needs a running copytool
2459 local f=$DIR/$tdir/SLEEP
2460 local slp_sum1=$(md5sum /bin/sleep)
2461 local fid=$(copy_file /bin/sleep $f)
2463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2464 wait_request_state $fid ARCHIVE SUCCEED
2466 check_hsm_flags $f "0x0000000d"
2467 # set no retry action mode
2469 do_node $CLIENT2 "$f 10" &
2473 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2475 [[ $? == 0 ]] || error "Execution failed during run"
2477 if [[ $? != 0 ]]; then
2478 local slp_sum2=$(md5sum /bin/sleep)
2479 # in case sleep file is modified during the test
2480 [[ $slp_sum1 == $slp_sum2 ]] &&
2481 error "Binary overwritten during exec"
2485 # remove no try action mode
2487 check_hsm_flags $f "0x00000009"
2491 run_test 30c "Update during exec of released file must fail"
2493 restore_and_check_size() {
2496 local s=$(stat -c "%s" $f)
2498 local st=$(get_hsm_flags $f)
2502 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2504 n=$(stat -c "%s" $f)
2505 # we echo in both cases to show stat is not
2507 if [[ $n != $s ]]; then
2508 echo "size seen is $n != $s"
2511 echo "size seen is right: $n == $s"
2513 st=$(get_hsm_flags $f)
2517 if [[ $cpt -lt 10 ]]; then
2520 echo " restore is too long"
2521 wait_request_state $fid RESTORE SUCCEED
2527 # test needs a running copytool
2532 make_archive $tdir/$tfile
2533 local f=$DIR/$tdir/$tfile
2534 import_file $tdir/$tfile $f
2535 local fid=$($LFS path2fid $f)
2536 HSM_ARCHIVE_PURGE=false copytool_setup
2538 restore_and_check_size $f $fid
2541 [[ $err -eq 0 ]] || error "File size changed during restore"
2545 run_test 31a "Import a large file and check size during restore"
2549 # test needs a running copytool
2554 local f=$DIR/$tdir/$tfile
2556 fid=$(make_large_for_progress $f)
2557 [ $? != 0 ] && skip "not enough free space" && return
2559 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2560 wait_request_state $fid ARCHIVE SUCCEED
2563 restore_and_check_size $f $fid
2566 [[ $err -eq 0 ]] || error "File size changed during restore"
2570 run_test 31b "Restore a large unaligned file and check size during restore"
2573 # test needs a running copytool
2578 local f=$DIR/$tdir/$tfile
2580 fid=$(make_large_for_progress_aligned $f)
2581 [ $? != 0 ] && skip "not enough free space" && return
2583 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2584 wait_request_state $fid ARCHIVE SUCCEED
2587 restore_and_check_size $f $fid
2590 [[ $err -eq 0 ]] || error "File size changed during restore"
2594 run_test 31c "Restore a large aligned file and check size during restore"
2597 # test needs a running copytool
2602 local f=$DIR/$tdir/$tfile
2604 fid=$(make_large_for_progress $f)
2605 [ $? != 0 ] && skip "not enough free space" && return
2607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2608 wait_request_state $fid ARCHIVE SUCCEED
2611 # to be sure wait_all_done will not be mislead by previous tests
2614 wait_for_grace_delay
2615 # Also raise grace_delay significantly so the Canceled
2616 # Restore action will stay enough long avail.
2617 local old_grace=$(get_hsm_param grace_delay)
2618 set_hsm_param grace_delay 100
2620 md5sum $f >/dev/null &
2622 wait_request_state $fid RESTORE STARTED
2627 # Check restore trigger process was killed
2628 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2632 # instead of waiting+checking both Restore and Cancel ops
2633 # sequentially, wait for both to be finished and then check
2635 wait_all_done 100 $fid
2636 local rstate=$(get_request_state $fid RESTORE)
2637 local cstate=$(get_request_state $fid CANCEL)
2639 # restore orig grace_delay.
2640 set_hsm_param grace_delay $old_grace
2642 if [[ "$rstate" == "CANCELED" ]] ; then
2643 [[ "$cstate" == "SUCCEED" ]] ||
2644 error "Restore state is CANCELED and Cancel state " \
2645 "is not SUCCEED but $cstate"
2646 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2647 elif [[ "$rstate" == "SUCCEED" ]] ; then
2648 [[ "$cstate" == "FAILED" ]] ||
2649 error "Restore state is SUCCEED and Cancel state " \
2650 "is not FAILED but $cstate"
2651 echo "Restore state is SUCCEED, Cancel state is FAILED"
2653 error "Restore state is $rstate and Cancel state is $cstate"
2657 error "Cannot kill process waiting for restore ($killed)"
2661 run_test 33 "Kill a restore waiting process"
2664 # test needs a running copytool
2669 local f=$DIR/$tdir/$tfile
2671 fid=$(make_large_for_progress $f)
2672 [ $? != 0 ] && skip "not enough free space" && return
2674 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2675 wait_request_state $fid ARCHIVE SUCCEED
2678 md5sum $f >/dev/null &
2680 wait_request_state $fid RESTORE STARTED
2682 rm $f || error "rm $f failed"
2683 # rm must not block during restore
2684 wait_request_state $fid RESTORE STARTED
2686 wait_request_state $fid RESTORE SUCCEED
2687 # check md5sum pgm finished
2688 local there=$(ps -o pid,comm hp $pid >/dev/null)
2689 [[ -z $there ]] || error "Restore initiator does not exit"
2691 local rc=$(wait $pid)
2692 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2696 run_test 34 "Remove file during restore"
2699 # test needs a running copytool
2704 local f=$DIR/$tdir/$tfile
2705 local f1=$DIR/$tdir/$tfile-1
2707 fid=$(make_large_for_progress $f)
2708 [ $? != 0 ] && skip "not enough free space" && return
2710 local fid1=$(copy_file /etc/passwd $f1)
2711 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2712 wait_request_state $fid ARCHIVE SUCCEED
2715 md5sum $f >/dev/null &
2717 wait_request_state $fid RESTORE STARTED
2719 mv $f1 $f || error "mv $f1 $f failed"
2720 # mv must not block during restore
2721 wait_request_state $fid RESTORE STARTED
2723 wait_request_state $fid RESTORE SUCCEED
2724 # check md5sum pgm finished
2725 local there=$(ps -o pid,comm hp $pid >/dev/null)
2726 [[ -z $there ]] || error "Restore initiator does not exit"
2728 local rc=$(wait $pid)
2729 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2732 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2736 run_test 35 "Overwrite file during restore"
2739 # test needs a running copytool
2744 local f=$DIR/$tdir/$tfile
2746 fid=$(make_large_for_progress $f)
2747 [ $? != 0 ] && skip "not enough free space" && return
2749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2750 wait_request_state $fid ARCHIVE SUCCEED
2753 md5sum $f >/dev/null &
2755 wait_request_state $fid RESTORE STARTED
2758 # rm must not block during restore
2759 wait_request_state $fid RESTORE STARTED
2761 wait_request_state $fid RESTORE SUCCEED
2762 # check md5sum pgm finished
2763 local there=$(ps -o pid,comm hp $pid >/dev/null)
2765 error "Restore initiator does not exit"
2767 local rc=$(wait $pid)
2769 error "Restore initiator failed with $rc"
2773 run_test 36 "Move file during restore"
2776 # LU-5683: check that an archived dirty file can be rearchived.
2778 copytool_setup $SINGLEAGT $MOUNT2
2781 local f=$DIR/$tdir/$tfile
2784 fid=$(make_small $f) || error "cannot create small file"
2786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2787 wait_request_state $fid ARCHIVE SUCCEED
2788 $LFS hsm_release $f || error "cannot release $f"
2791 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2793 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2794 wait_request_state $fid ARCHIVE SUCCEED
2798 run_test 37 "re-archive a dirty file"
2805 for n in $(seq 1 $count); do
2806 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2808 echo "$count archive requests submitted"
2812 local stream_count=4
2813 local file_count=100
2815 local f=$DIR/$tdir/$tfile
2820 for i in $(seq 1 $file_count); do
2821 for p in $(seq 1 $stream_count); do
2822 fid=$(copy_file /etc/hosts $f.$p.$i)
2825 # force copytool to use a local/temp archive dir to ensure best
2826 # performance vs remote/NFS mounts used in auto-tests
2827 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2830 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2832 # to be sure wait_all_done will not be mislead by previous tests
2834 wait_for_grace_delay
2836 # start archive streams in background (archive files in parallel)
2837 for p in $(seq 1 $stream_count); do
2838 multi_archive $f.$p $file_count &
2841 echo -n "Wait for all requests being enqueued..."
2847 run_test 40 "Parallel archive requests"
2850 # test needs a running copytool
2854 local f=$DIR/$tdir/$tfile
2855 local fid=$(copy_file /etc/motd $f 1)
2857 $LFS hsm_archive $f || error "could not archive file"
2858 wait_request_state $fid ARCHIVE SUCCEED
2859 check_hsm_flags $f "0x00000009"
2861 multiop_bg_pause $f O_c || error "multiop failed"
2865 client_up || client_up || true
2867 kill -USR1 $MULTIPID
2868 wait $MULTIPID || error "multiop close failed"
2870 check_hsm_flags $f "0x0000000b"
2874 run_test 52 "Opened for write file on an evicted client should be set dirty"
2877 # test needs a running copytool
2881 local f=$DIR/$tdir/$tfile
2882 local fid=$(copy_file /etc/motd $f 1)
2884 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2885 error "could not archive file"
2886 wait_request_state $fid ARCHIVE SUCCEED
2887 check_hsm_flags $f "0x00000009"
2889 multiop_bg_pause $f o_c || error "multiop failed"
2893 client_up || client_up || true
2895 kill -USR1 $MULTIPID
2896 wait $MULTIPID || error "multiop close failed"
2898 check_hsm_flags $f "0x00000009"
2902 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2905 # test needs a running copytool
2909 local f=$DIR/$tdir/$tfile
2910 local fid=$(make_large_for_progress $f)
2912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2913 error "could not archive file"
2914 wait_request_state $fid ARCHIVE STARTED
2916 check_hsm_flags $f "0x00000001"
2918 # Avoid coordinator resending this request as soon it has failed.
2923 wait_request_state $fid ARCHIVE FAILED
2925 check_hsm_flags $f "0x00000003"
2930 run_test 54 "Write during an archive cancels it"
2933 # test needs a running copytool
2937 local f=$DIR/$tdir/$tfile
2938 local fid=$(make_large_for_progress $f)
2940 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2941 error "could not archive file"
2942 wait_request_state $fid ARCHIVE STARTED
2944 check_hsm_flags $f "0x00000001"
2946 # Avoid coordinator resending this request as soon it has failed.
2949 $TRUNCATE $f 1024 || error "truncate failed"
2951 wait_request_state $fid ARCHIVE FAILED
2953 check_hsm_flags $f "0x00000003"
2958 run_test 55 "Truncate during an archive cancels it"
2961 # test needs a running copytool
2965 local f=$DIR/$tdir/$tfile
2967 fid=$(make_large_for_progress $f)
2968 [ $? != 0 ] && skip "not enough free space" && return
2970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2971 error "could not archive file"
2972 wait_request_state $fid ARCHIVE STARTED
2974 check_hsm_flags $f "0x00000001"
2976 # Change metadata and sync to be sure we are not changing only
2981 wait_request_state $fid ARCHIVE SUCCEED
2983 check_hsm_flags $f "0x00000009"
2987 run_test 56 "Setattr during an archive is ok"
2990 # Need one client for I/O, one for request
2991 needclients 2 || return 0
2993 # test needs a running copytool
2997 local f=$DIR/$tdir/test_archive_remote
2998 # Create a file on a remote node
2999 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3000 "count=2 conv=fsync"
3003 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3004 error "hsm_archive failed"
3005 local fid=$(path2fid $f)
3006 wait_request_state $fid ARCHIVE SUCCEED
3008 # Release and implicit restore it
3009 do_node $CLIENT2 "$LFS hsm_release $f" ||
3010 error "hsm_release failed"
3011 do_node $CLIENT2 "md5sum $f" ||
3012 error "hsm_restore failed"
3014 wait_request_state $fid RESTORE SUCCEED
3018 run_test 57 "Archive a file with dirty cache on another node"
3020 truncate_released_file() {
3024 local sz=$(stat -c %s $src_file)
3025 local f=$DIR/$tdir/$tfile
3026 local fid=$(copy_file $1 $f)
3030 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3031 error "could not archive file"
3032 wait_request_state $fid ARCHIVE SUCCEED
3034 $LFS hsm_release $f || error "could not release file"
3036 $TRUNCATE $f $trunc_to || error "truncate failed"
3039 local sz1=$(stat -c %s $f)
3040 [[ $sz1 == $trunc_to ]] ||
3041 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3044 check_hsm_flags $f "0x0000000b"
3046 local state=$(get_request_state $fid RESTORE)
3047 [[ "$state" == "SUCCEED" ]] ||
3048 error "truncate $sz does not trig restore, state = $state"
3050 $TRUNCATE $ref $trunc_to
3051 cmp $ref $f || error "file data wrong after truncate"
3057 # test needs a running copytool
3062 local sz=$(stat -c %s /etc/passwd)
3064 echo "truncate up from $sz to $((sz*2))"
3065 truncate_released_file /etc/passwd $((sz*2))
3067 echo "truncate down from $sz to $((sz/2))"
3068 truncate_released_file /etc/passwd $((sz/2))
3070 echo "truncate to 0"
3071 truncate_released_file /etc/passwd 0
3075 run_test 58 "Truncate a released file will trigger restore"
3079 local server_version=$(lustre_version_code $SINGLEMDS)
3080 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3081 skip "Need MDS version at least 2.7.63" && return
3084 $MCREATE $DIR/$tfile || error "mcreate failed"
3085 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3086 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3087 fid=$(path2fid $DIR/$tfile)
3088 wait_request_state $fid ARCHIVE SUCCEED
3089 $LFS hsm_release $DIR/$tfile || error "release failed"
3092 run_test 59 "Release stripeless file with non-zero size"
3095 # This test validates the fix for LU-4512. Ensure that the -u
3096 # option changes the progress reporting interval from the
3097 # default (30 seconds) to the user-specified interval.
3099 local progress_timeout=$((interval * 4))
3101 # test needs a new running copytool
3103 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3106 local f=$DIR/$tdir/$tfile
3108 fid=$(make_large_for_progress $f)
3109 [ $? != 0 ] && skip "not enough free space" && return
3112 local mdt=${MDT_PREFIX}${mdtidx}
3113 local mds=mds$((mdtidx + 1))
3115 # Wait for copytool to register
3116 wait_update_facet $mds \
3117 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3118 uuid 100 || error "coyptool failed to register with $mdt"
3120 local start_at=$(date +%s)
3121 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3122 error "could not archive file"
3124 local agent=$(facet_active_host $SINGLEAGT)
3125 local prefix=$TESTLOG_PREFIX
3126 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3127 local copytool_log=$prefix.copytool_log.$agent.log
3130 wait_update $agent \
3131 "grep -o start.copy $copytool_log" "start copy" 100 ||
3132 error "copytool failed to start"
3134 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3135 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3141 echo -n "Expecting a progress update within $progress_timeout seconds... "
3143 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3144 if [ $RESULT -gt 0 ]; then
3145 echo "$RESULT bytes copied in $WAIT seconds."
3147 elif [ $WAIT -ge $progress_timeout ]; then
3148 error "Timed out waiting for progress update!"
3151 WAIT=$((WAIT + sleep))
3155 local finish_at=$(date +%s)
3156 local elapsed=$((finish_at - start_at))
3158 # Ensure that the progress update occurred within the expected window.
3159 if [ $elapsed -lt $interval ]; then
3160 error "Expected progress update after at least $interval seconds"
3166 run_test 60 "Changing progress update interval from default"
3169 # test needs a new running copytool
3171 copytool_monitor_setup
3172 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3174 # Just start and stop the copytool to generate events.
3177 # Wait for the copytool to register.
3178 wait_update --verbose $(facet_active_host mds1) \
3179 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3181 error "copytool failed to register with MDT0000"
3185 local REGISTER_EVENT
3186 local UNREGISTER_EVENT
3187 while read event; do
3188 local parsed=$(parse_json_event "$event")
3189 if [ -z "$parsed" ]; then
3190 error "Copytool sent malformed event: $event"
3194 if [ $event_type == "REGISTER" ]; then
3195 REGISTER_EVENT=$event
3196 elif [ $event_type == "UNREGISTER" ]; then
3197 UNREGISTER_EVENT=$event
3199 done < <(echo $"$(get_copytool_event_log)")
3201 if [ -z "$REGISTER_EVENT" ]; then
3202 error "Copytool failed to send register event to FIFO"
3205 if [ -z "$UNREGISTER_EVENT" ]; then
3206 error "Copytool failed to send unregister event to FIFO"
3209 copytool_monitor_cleanup
3210 echo "Register/Unregister events look OK."
3212 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3215 # Bump progress interval for livelier events.
3218 # test needs a new running copytool
3220 copytool_monitor_setup
3221 HSMTOOL_UPDATE_INTERVAL=$interval \
3222 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3225 local f=$DIR/$tdir/$tfile
3227 fid=$(make_large_for_progress $f)
3228 [ $? != 0 ] && skip "not enough free space" && return
3230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3231 error "could not archive file"
3232 wait_request_state $fid ARCHIVE SUCCEED
3234 local expected_fields="event_time data_fid source_fid"
3235 expected_fields+=" total_bytes current_bytes"
3239 while read event; do
3240 # Make sure we're not getting anything from previous events.
3241 for field in $expected_fields; do
3245 local parsed=$(parse_json_event "$event")
3246 if [ -z "$parsed" ]; then
3247 error "Copytool sent malformed event: $event"
3251 if [ $event_type == "ARCHIVE_START" ]; then
3254 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3257 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3261 # Do some simple checking of the progress update events.
3262 for expected_field in $expected_fields; do
3263 if [ -z ${!expected_field+x} ]; then
3264 error "Missing $expected_field field in event"
3268 if [ $total_bytes -eq 0 ]; then
3269 error "Expected total_bytes to be > 0"
3272 # These should be identical throughout an archive
3274 if [ $source_fid != $data_fid ]; then
3275 error "Expected source_fid to equal data_fid"
3277 done < <(echo $"$(get_copytool_event_log)")
3279 if [ -z "$START_EVENT" ]; then
3280 error "Copytool failed to send archive start event to FIFO"
3283 if [ -z "$FINISH_EVENT" ]; then
3284 error "Copytool failed to send archive finish event to FIFO"
3287 echo "Archive events look OK."
3291 copytool_monitor_cleanup
3293 run_test 71 "Copytool logs JSON archive events to FIFO"
3296 # Bump progress interval for livelier events.
3299 # test needs a new running copytool
3301 copytool_monitor_setup
3302 HSMTOOL_UPDATE_INTERVAL=$interval \
3303 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3304 local test_file=$HSMTOOL_MONITOR_DIR/file
3306 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3308 do_facet $SINGLEAGT "$cmd" ||
3309 error "cannot create $test_file on $SINGLEAGT"
3310 copy2archive $test_file $tdir/$tfile
3313 local f=$DIR/$tdir/$tfile
3314 import_file $tdir/$tfile $f
3315 f=$DIR2/$tdir/$tfile
3316 echo "Verifying released state: "
3317 check_hsm_flags $f "0x0000000d"
3319 local fid=$(path2fid $f)
3321 wait_request_state $fid RESTORE SUCCEED
3323 local expected_fields="event_time data_fid source_fid"
3324 expected_fields+=" total_bytes current_bytes"
3328 while read event; do
3329 # Make sure we're not getting anything from previous events.
3330 for field in $expected_fields; do
3334 local parsed=$(parse_json_event "$event")
3335 if [ -z "$parsed" ]; then
3336 error "Copytool sent malformed event: $event"
3340 if [ $event_type == "RESTORE_START" ]; then
3342 if [ $source_fid != $data_fid ]; then
3343 error "source_fid should == data_fid at start"
3346 elif [ $event_type == "RESTORE_FINISH" ]; then
3348 if [ $source_fid != $data_fid ]; then
3349 error "source_fid should == data_fid at finish"
3352 elif [ $event_type != "RESTORE_RUNNING" ]; then
3356 # Do some simple checking of the progress update events.
3357 for expected_field in $expected_fields; do
3358 if [ -z ${!expected_field+x} ]; then
3359 error "Missing $expected_field field in event"
3363 if [ $total_bytes -eq 0 ]; then
3364 error "Expected total_bytes to be > 0"
3367 # When a restore starts out, the data fid is the same as the
3368 # source fid. After the restore has gotten going, we learn
3369 # the new data fid. Once the restore has finished, the source
3370 # fid is set to the new data fid.
3372 # We test this because some monitoring software may depend on
3373 # this behavior. If it changes, then the consumers of these
3374 # events may need to be modified.
3375 if [ $source_fid == $data_fid ]; then
3376 error "source_fid should != data_fid during restore"
3378 done < <(echo $"$(get_copytool_event_log)")
3380 if [ -z "$START_EVENT" ]; then
3381 error "Copytool failed to send restore start event to FIFO"
3384 if [ -z "$FINISH_EVENT" ]; then
3385 error "Copytool failed to send restore finish event to FIFO"
3388 echo "Restore events look OK."
3392 copytool_monitor_cleanup
3396 run_test 72 "Copytool logs JSON restore events to FIFO"
3399 file_count=51 # Max number of files constrained by LNET message size
3400 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3401 local f=$DIR/$tdir/$tfile
3402 local FILELIST=/tmp/filelist.txt
3406 for i in $(seq 1 $file_count); do
3407 fid=$(copy_file /etc/hosts $f.$i)
3408 echo $f.$i >> $FILELIST
3410 # force copytool to use a local/temp archive dir to ensure best
3411 # performance vs remote/NFS mounts used in auto-tests
3412 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3415 local dai=$(get_hsm_param default_archive_id)
3416 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3418 # to be sure wait_all_done will not be mislead by previous tests
3420 wait_for_grace_delay
3421 $LFS hsm_archive --filelist $FILELIST ||
3422 error "cannot archive a file list"
3424 $LFS hsm_release --filelist $FILELIST ||
3425 error "cannot release a file list"
3426 $LFS hsm_restore --filelist $FILELIST ||
3427 error "cannot restore a file list"
3431 run_test 90 "Archive/restore a file list"
3433 double_verify_reset_hsm_param() {
3435 echo "Testing $HSM_PARAM.$p"
3436 local val=$(get_hsm_param $p)
3438 local val2=$(($val * 2))
3439 set_hsm_param $p $val2
3440 val=$(get_hsm_param $p)
3441 [[ $val == $val2 ]] ||
3442 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3443 echo "Set $p to 0 must failed"
3447 set_hsm_param $p $save
3449 if [[ $rc == 0 ]]; then
3450 error "we must not be able to set $HSM_PARAM.$p to 0"
3455 double_verify_reset_hsm_param loop_period
3456 double_verify_reset_hsm_param grace_delay
3457 double_verify_reset_hsm_param active_request_timeout
3458 double_verify_reset_hsm_param max_requests
3459 double_verify_reset_hsm_param default_archive_id
3461 run_test 100 "Set coordinator /proc tunables"
3468 run_test 102 "Verify coordinator control"
3471 # test needs a running copytool
3478 for i in $(seq 1 20); do
3479 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3481 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3485 echo "Current requests"
3486 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3487 $HSM_PARAM.actions |\
3488 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3490 [[ -z "$res" ]] || error "Some request have not been canceled"
3494 run_test 103 "Purge all requests"
3499 # test needs a running copytool
3503 local f=$DIR/$tdir/$tfile
3505 fid=$(make_large_for_progress $f)
3506 [ $? != 0 ] && skip "not enough free space" && return
3508 # if cdt is on, it can serve too quickly the request
3510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3511 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3512 $HSM_PARAM.actions |\
3513 grep $fid | cut -f16 -d=")
3516 [[ "$data1" == "$DATAHEX" ]] ||
3517 error "Data field in records is ($data1) and not ($DATAHEX)"
3521 run_test 104 "Copy tool data field"
3528 for i in $(seq -w 1 10); do
3529 cp /etc/passwd $DIR/$tdir/$i
3530 $LFS hsm_archive $DIR/$tdir/$i
3532 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3533 $HSM_PARAM.actions |\
3534 grep WAITING | wc -l")
3537 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3538 $HSM_PARAM.actions |\
3539 grep WAITING | wc -l")
3542 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3543 error "Requests count after shutdown $reqcnt2 != "\
3544 "before shutdown $reqcnt1"
3546 run_test 105 "Restart of coordinator"
3548 get_agent_by_uuid_mdt() {
3551 local mds=mds$(($mdtidx + 1))
3552 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3556 check_agent_registered_by_mdt() {
3559 local mds=mds$(($mdtidx + 1))
3560 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3561 if [[ ! -z "$agent" ]]; then
3562 echo "found agent $agent on $mds"
3564 error "uuid $uuid not found in agent list on $mds"
3568 check_agent_unregistered_by_mdt() {
3571 local mds=mds$(($mdtidx + 1))
3572 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3573 if [[ -z "$agent" ]]; then
3574 echo "uuid not found in agent list on $mds"
3576 error "uuid found in agent list on $mds: $agent"
3580 check_agent_registered() {
3583 for mdsno in $(seq 1 $MDSCOUNT); do
3584 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3588 check_agent_unregistered() {
3591 for mdsno in $(seq 1 $MDSCOUNT); do
3592 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3597 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3599 # Lustre mount-point is mandatory and last parameter on
3600 # copytool cmd-line.
3601 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3602 grep -v pgrep | awk '{print $NF}')
3603 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3605 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3609 # test needs a running copytool
3612 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3614 check_agent_registered $uuid
3616 search_copytools || error "No copytool found"
3619 check_agent_unregistered $uuid
3622 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3623 check_agent_registered $uuid
3627 run_test 106 "Copytool register/unregister"
3630 # test needs a running copytool
3632 # create and archive file
3634 local f1=$DIR/$tdir/$tfile
3635 local fid=$(copy_file /etc/passwd $f1)
3636 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3637 wait_request_state $fid ARCHIVE SUCCEED
3638 # shutdown and restart MDS
3640 # check the copytool still gets messages from MDT
3641 local f2=$DIR/$tdir/2
3642 local fid=$(copy_file /etc/passwd $f2)
3643 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3644 # main check of this sanity: this request MUST succeed
3645 wait_request_state $fid ARCHIVE SUCCEED
3648 run_test 107 "Copytool re-register after MDS restart"
3650 policy_set_and_test()
3654 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3655 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3656 [[ "$policy" == "$target" ]] ||
3657 error "Wrong policy after '$change': '$policy' != '$target'"
3661 # to force default policy setting if error
3662 CDT_POLICY_HAD_CHANGED=true
3664 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3665 local default="NonBlockingRestore [NoRetryAction]"
3666 [[ "$policy" == "$default" ]] ||
3667 error "default policy has changed,"\
3668 " '$policy' != '$default' update the test"
3669 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3670 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3671 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3672 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3673 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3674 # useless bacause we know but safer for futur changes to use real value
3675 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3676 echo "Next set_param must failed"
3677 policy_set_and_test "wrong" "$policy"
3680 echo "Back to default policy"
3681 cdt_set_sanity_policy
3683 run_test 109 "Policy display/change"
3686 # test needs a running copytool
3691 copy2archive /etc/passwd $tdir/$tfile
3693 local f=$DIR/$tdir/$tfile
3694 import_file $tdir/$tfile $f
3695 local fid=$(path2fid $f)
3697 cdt_set_non_blocking_restore
3702 wait_request_state $fid RESTORE SUCCEED
3703 cdt_clear_non_blocking_restore
3707 error "md5sum returns $st != 1, "\
3708 "should also perror ENODATA (No data available)"
3712 run_test 110a "Non blocking restore policy (import case)"
3715 # test needs a running copytool
3719 local f=$DIR/$tdir/$tfile
3720 local fid=$(copy_file /etc/passwd $f)
3721 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3722 wait_request_state $fid ARCHIVE SUCCEED
3725 cdt_set_non_blocking_restore
3730 wait_request_state $fid RESTORE SUCCEED
3731 cdt_clear_non_blocking_restore
3735 error "md5sum returns $st != 1, "\
3736 "should also perror ENODATA (No data available)"
3740 run_test 110b "Non blocking restore policy (release case)"
3743 # test needs a running copytool
3747 copy2archive /etc/passwd $tdir/$tfile
3749 local f=$DIR/$tdir/$tfile
3751 import_file $tdir/$tfile $f
3752 local fid=$(path2fid $f)
3756 copytool_remove_backend $fid
3759 wait_request_state $fid RESTORE FAILED
3766 [[ $st == 0 ]] || error "Restore does not failed"
3770 run_test 111a "No retry policy (import case), restore will error"\
3771 " (No such file or directory)"
3774 # test needs a running copytool
3778 local f=$DIR/$tdir/$tfile
3779 local fid=$(copy_file /etc/passwd $f)
3781 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3782 wait_request_state $fid ARCHIVE SUCCEED
3785 copytool_remove_backend $fid
3788 wait_request_state $fid RESTORE FAILED
3795 [[ $st == 0 ]] || error "Restore does not failed"
3799 run_test 111b "No retry policy (release case), restore will error"\
3800 " (No such file or directory)"
3803 # test needs a running copytool
3807 local f=$DIR/$tdir/$tfile
3808 local fid=$(copy_file /etc/passwd $f)
3810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3811 local l=$($LFS hsm_action $f)
3813 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3817 wait_request_state $fid ARCHIVE SUCCEED
3820 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3824 run_test 112 "State of recorded request"
3827 # test needs a running copytool
3831 local f=$DIR/$tdir/$tfile
3833 fid=$(make_large_for_cancel $f)
3834 [ $? != 0 ] && skip "not enough free space" && return
3836 # test with cdt on is made in test_221
3838 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3839 # wait archive to register at CDT
3840 wait_request_state $fid ARCHIVE WAITING
3843 wait_request_state $fid ARCHIVE CANCELED
3844 wait_request_state $fid CANCEL SUCCEED
3848 run_test 200 "Register/Cancel archive"
3851 # test needs a running copytool
3855 local f=$DIR/$tdir/$tfile
3856 make_archive $tdir/$tfile
3857 import_file $tdir/$tfile $f
3858 local fid=$(path2fid $f)
3860 # test with cdt on is made in test_222
3863 # wait restore to register at CDT
3864 wait_request_state $fid RESTORE WAITING
3867 wait_request_state $fid RESTORE CANCELED
3868 wait_request_state $fid CANCEL SUCCEED
3872 run_test 201 "Register/Cancel restore"
3875 # test needs a running copytool
3879 local f=$DIR/$tdir/$tfile
3881 fid=$(make_large_for_progress $f)
3882 [ $? != 0 ] && skip "not enough free space" && return
3884 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3885 wait_request_state $fid ARCHIVE SUCCEED
3889 # wait remove to register at CDT
3890 wait_request_state $fid REMOVE WAITING
3893 wait_request_state $fid REMOVE CANCELED
3897 run_test 202 "Register/Cancel remove"
3900 # test needs a running copytool
3905 local f=$DIR/$tdir/$tfile
3906 local fid=$(copy_file /etc/passwd $f)
3910 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3911 wait_request_state $fid ARCHIVE SUCCEED
3913 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3917 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3921 run_test 220 "Changelog for archive"
3924 # test needs a running copytool
3929 local f=$DIR/$tdir/$tfile
3931 fid=$(make_large_for_cancel $f)
3932 [ $? != 0 ] && skip "not enough free space" && return
3936 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3937 wait_request_state $fid ARCHIVE STARTED
3939 wait_request_state $fid ARCHIVE CANCELED
3940 wait_request_state $fid CANCEL SUCCEED
3942 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3945 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3949 run_test 221 "Changelog for archive canceled"
3952 # test needs a running copytool
3956 copy2archive /etc/passwd $tdir/$tfile
3958 local f=$DIR/$tdir/$tfile
3959 import_file $tdir/$tfile $f
3960 local fid=$(path2fid $f)
3965 wait_request_state $fid RESTORE SUCCEED
3967 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3970 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3974 run_test 222a "Changelog for explicit restore"
3977 # test needs a running copytool
3981 local f=$DIR/$tdir/$tfile
3982 local fid=$(copy_file /etc/passwd $f)
3985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3986 wait_request_state $fid ARCHIVE SUCCEED
3991 wait_request_state $fid RESTORE SUCCEED
3993 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3996 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4000 run_test 222b "Changelog for implicit restore"
4003 # test needs a running copytool
4008 local f=$DIR/$tdir/$tfile
4009 make_archive $tdir/$tfile
4013 import_file $tdir/$tfile $f
4014 local fid=$(path2fid $f)
4017 wait_request_state $fid RESTORE STARTED
4019 wait_request_state $fid RESTORE CANCELED
4020 wait_request_state $fid CANCEL SUCCEED
4022 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4025 [[ $flags == $target ]] ||
4026 error "Changelog flag is $flags not $target"
4030 run_test 223a "Changelog for restore canceled (import case)"
4033 # test needs a running copytool
4038 local f=$DIR/$tdir/$tfile
4040 fid=$(make_large_for_progress $f)
4041 [ $? != 0 ] && skip "not enough free space" && return
4044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4045 wait_request_state $fid ARCHIVE SUCCEED
4048 wait_request_state $fid RESTORE STARTED
4050 wait_request_state $fid RESTORE CANCELED
4051 wait_request_state $fid CANCEL SUCCEED
4053 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4056 [[ $flags == $target ]] ||
4057 error "Changelog flag is $flags not $target"
4061 run_test 223b "Changelog for restore canceled (release case)"
4064 # test needs a running copytool
4069 local f=$DIR/$tdir/$tfile
4070 local fid=$(copy_file /etc/passwd $f)
4073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4074 wait_request_state $fid ARCHIVE SUCCEED
4077 wait_request_state $fid REMOVE SUCCEED
4079 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4082 [[ $flags == $target ]] ||
4083 error "Changelog flag is $flags not $target"
4087 run_test 224 "Changelog for remove"
4090 # test needs a running copytool
4093 # test is not usable because remove request is too fast
4094 # so it is always finished before cancel can be done ...
4095 echo "Test disabled"
4100 local f=$DIR/$tdir/$tfile
4102 fid=$(make_large_for_progress $f)
4103 [ $? != 0 ] && skip "not enough free space" && return
4106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4107 wait_request_state $fid ARCHIVE SUCCEED
4109 # if cdt is on, it can serve too quickly the request
4114 wait_request_state $fid REMOVE CANCELED
4115 wait_request_state $fid CANCEL SUCCEED
4117 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4118 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4119 tail -n 1 | awk '{print $5}')
4122 [[ $flags == $target ]] ||
4123 error "Changelog flag is $flags not $target"
4127 run_test 225 "Changelog for remove canceled"
4130 # test needs a running copytool
4135 local f1=$DIR/$tdir/$tfile-1
4136 local f2=$DIR/$tdir/$tfile-2
4137 local f3=$DIR/$tdir/$tfile-3
4138 local fid1=$(copy_file /etc/passwd $f1)
4139 local fid2=$(copy_file /etc/passwd $f2)
4140 copy_file /etc/passwd $f3
4143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4144 wait_request_state $fid1 ARCHIVE SUCCEED
4146 $LFS hsm_archive $f2
4147 wait_request_state $fid2 ARCHIVE SUCCEED
4149 rm $f1 || error "rm $f1 failed"
4151 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4154 [[ $flags == $target ]] ||
4155 error "Changelog flag is $flags not $target"
4157 mv $f3 $f2 || error "mv $f3 $f2 failed"
4159 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4162 [[ $flags == $target ]] ||
4163 error "Changelog flag is $flags not $target"
4167 run_test 226 "changelog for last rm/mv with exiting archive"
4169 check_flags_changes() {
4177 $LFS hsm_set --$hsm_flag $f ||
4178 error "Cannot set $hsm_flag on $f"
4179 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4180 local seen=${#flags[*]}
4182 [[ $seen == $cnt ]] ||
4183 error "set $hsm_flag: Changelog events $seen != $cnt"
4184 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4185 error "set $hsm_flag: Changelog flags are "\
4186 "${flags[$((cnt - 1))]} not $target"
4188 $LFS hsm_clear --$hsm_flag $f ||
4189 error "Cannot clear $hsm_flag on $f"
4190 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4193 [[ $cnt == $seen ]] ||
4194 error "clear $hsm_flag: Changelog events $seen != $cnt"
4196 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4197 error "clear $hsm_flag: Changelog flag is "\
4198 "${flags[$((cnt - 1))]} not $target"
4202 # test needs a running copytool
4209 for i in norelease noarchive exists archived
4211 local f=$DIR/$tdir/$tfile-$i
4212 local fid=$(copy_file /etc/passwd $f)
4213 check_flags_changes $f $fid $i 0 1
4216 f=$DIR/$tdir/$tfile---lost
4217 fid=$(copy_file /etc/passwd $f)
4218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4219 wait_request_state $fid ARCHIVE SUCCEED
4220 check_flags_changes $f $fid lost 3 1
4224 run_test 227 "changelog when explicit setting of HSM flags"
4227 # test needs a running copytool
4230 local fid=$(make_small_sync $DIR/$tfile)
4231 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4232 wait_request_state $fid ARCHIVE SUCCEED
4234 $LFS hsm_release $DIR/$tfile
4235 check_hsm_flags $DIR/$tfile "0x0000000d"
4237 filefrag $DIR/$tfile | grep " 1 extent found" ||
4238 error "filefrag on released file must return only one extent"
4240 # only newer versions of cp detect sparse files by stat/FIEMAP
4242 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4243 error "copying $DIR/$tfile"
4244 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4246 $LFS hsm_release $DIR/$tfile
4247 check_hsm_flags $DIR/$tfile "0x0000000d"
4249 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4251 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4253 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4254 error "comparing untarred $DIR/$tfile"
4256 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4257 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4260 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4263 # test needs a running copytool
4267 local maxrequest=$(get_hsm_param max_requests)
4268 local rqcnt=$(($maxrequest * 3))
4272 for i in $(seq -w 1 $rqcnt); do
4274 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4276 # we do it in 2 steps, so all requests arrive at the same time
4277 for i in $(seq -w 1 $rqcnt); do
4278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4283 while [[ $cnt != 0 || $wt != 0 ]]; do
4285 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4286 $HSM_PARAM.actions |\
4287 grep STARTED | grep -v CANCEL | wc -l")
4288 [[ $cnt -le $maxrequest ]] ||
4289 error "$cnt > $maxrequest too many started requests"
4290 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4291 $HSM_PARAM.actions |\
4292 grep WAITING | wc -l")
4293 echo "max=$maxrequest started=$cnt waiting=$wt"
4298 run_test 250 "Coordinator max request"
4301 # test needs a running copytool
4305 local f=$DIR/$tdir/$tfile
4307 fid=$(make_large_for_cancel $f)
4308 [ $? != 0 ] && skip "not enough free space" && return
4311 # to have a short test
4312 local old_to=$(get_hsm_param active_request_timeout)
4313 set_hsm_param active_request_timeout 4
4314 # to be sure the cdt will wake up frequently so
4315 # it will be able to cancel the "old" request
4316 local old_loop=$(get_hsm_param loop_period)
4317 set_hsm_param loop_period 2
4320 # clear locks to avoid extra delay caused by flush/cancel
4321 # and thus prevent early copytool death to timeout.
4322 cancel_lru_locks osc
4324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4325 wait_request_state $fid ARCHIVE STARTED
4327 wait_request_state $fid ARCHIVE CANCELED
4329 set_hsm_param active_request_timeout $old_to
4330 set_hsm_param loop_period $old_loop
4334 run_test 251 "Coordinator request timeout"
4337 # the only way to test ondisk conf is to restart MDS ...
4338 echo "Stop coordinator and remove coordinator state at mount"
4341 # clean on disk conf set by default
4342 cdt_clear_mount_state
4343 cdt_check_state stopped
4345 # check cdt still off after umount/remount
4347 cdt_check_state stopped
4349 echo "Set coordinator start at mount, and start coordinator"
4350 cdt_set_mount_state enabled
4353 cdt_check_state enabled
4355 # check cdt still on after umount/remount
4357 cdt_check_state enabled
4359 # we are back to original state (cdt started at mount)
4361 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4364 local ai=$(get_hsm_param default_archive_id)
4365 local new=$((ai + 1))
4367 set_hsm_param default_archive_id $new -P
4369 local res=$(get_hsm_param default_archive_id)
4372 set_hsm_param default_archive_id "" "-P -d"
4374 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4376 run_test 301 "HSM tunnable are persistent"
4379 local ai=$(get_hsm_param default_archive_id)
4380 local new=$((ai + 1))
4385 set_hsm_param default_archive_id $new -P
4388 for mdtno in $(seq 1 $MDSCOUNT); do
4393 cdt_check_state enabled
4395 local res=$(get_hsm_param default_archive_id)
4398 set_hsm_param default_archive_id "" "-P -d"
4400 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4402 run_test 302 "HSM tunnable are persistent when CDT is off"
4405 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4411 local dir_mdt0=$DIR/$tdir/mdt0
4412 local dir_mdt1=$DIR/$tdir/mdt1
4414 # create 1 dir per MDT
4415 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4416 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4418 # create 1 file in each MDT
4419 local fid1=$(make_small $dir_mdt0/$tfile)
4420 local fid2=$(make_small $dir_mdt1/$tfile)
4422 # check that hsm request on mdt0 is sent to the right MDS
4423 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4424 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4425 echo "archive successful on mdt0"
4427 # check that hsm request on mdt1 is sent to the right MDS
4428 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4429 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4430 echo "archive successful on mdt1"
4433 # clean test files and directories
4434 rm -rf $dir_mdt0 $dir_mdt1
4436 run_test 400 "Single request is sent to the right MDT"
4439 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4445 local dir_mdt0=$DIR/$tdir/mdt0
4446 local dir_mdt1=$DIR/$tdir/mdt1
4448 # create 1 dir per MDT
4449 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4450 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4452 # create 1 file in each MDT
4453 local fid1=$(make_small $dir_mdt0/$tfile)
4454 local fid2=$(make_small $dir_mdt1/$tfile)
4456 # check that compound requests are shunt to the rights MDTs
4457 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4458 error "lfs hsm_archive"
4459 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4460 echo "archive successful on mdt0"
4461 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4462 echo "archive successful on mdt1"
4465 # clean test files and directories
4466 rm -rf $dir_mdt0 $dir_mdt1
4468 run_test 401 "Compound requests split and sent to their respective MDTs"
4470 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4475 local node=$(facet_active_host $facet)
4477 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4478 awk '{print $4}'); do
4479 echo "$3 $mdc on $node"
4480 do_facet $facet "$LCTL --device $mdc $state" || return 1
4485 # make sure there is no running copytool
4488 # deactivate all mdc on agent1
4489 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4491 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4493 check_agent_unregistered "uuid" # match any agent
4495 # no expected running copytool
4496 search_copytools $agent && error "Copytool start should have failed"
4499 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4501 run_test 402 "Copytool start fails if all MDTs are inactive"
4504 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4506 # make sure there is no running copytool
4509 local agent=$(facet_active_host $SINGLEAGT)
4511 # deactivate all mdc for MDT0001
4512 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4515 local uuid=$(get_agent_uuid $agent)
4516 # check the agent is registered on MDT0000, and not on MDT0001
4517 check_agent_registered_by_mdt $uuid 0
4518 check_agent_unregistered_by_mdt $uuid 1
4520 # check running copytool process
4521 search_copytools $agent || error "No running copytools on $agent"
4523 # reactivate all mdc for MDT0001
4524 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4526 # make sure the copytool is now registered to all MDTs
4527 check_agent_registered $uuid
4531 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4534 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4538 # create files on both MDT0000 and MDT0001
4541 local dir_mdt0=$DIR/$tdir/mdt0
4542 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4544 # create 1 file on mdt0
4545 local fid1=$(make_small $dir_mdt0/$tfile)
4547 # deactivate all mdc for MDT0001
4548 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4550 # send an HSM request for files in MDT0000
4551 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4553 # check for completion of files in MDT0000
4554 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4555 echo "archive successful on mdt0"
4557 # reactivate all mdc for MDT0001
4558 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4561 # clean test files and directories
4564 run_test 404 "Inactive MDT does not block requests for active MDTs"
4567 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4573 local striped_dir=$DIR/$tdir/striped_dir
4575 # create striped dir on all of MDTs
4576 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4578 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4579 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4580 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4581 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4583 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4584 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4585 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4586 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4588 # check that compound requests are shunt to the rights MDTs
4589 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4590 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4591 error "lfs hsm_archive"
4593 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4594 echo "archive successful on $fid1"
4595 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4596 echo "archive successful on $fid2"
4597 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4598 echo "archive successful on $fid3"
4599 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4600 echo "archive successful on $fid4"
4602 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4603 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4604 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4605 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4607 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4608 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4609 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4610 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4614 run_test 405 "archive and release under striped directory"
4618 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4619 skip "HSM migrate is not supported" && return
4621 # Stop the existing copytool
4624 test_mkdir -p $DIR/$tdir
4625 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4627 run_test 500 "various LLAPI HSM tests"
4632 check_and_cleanup_lustre