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 MOUNT_2=${MOUNT_2:-"yes"}
30 # script only handles up to 10 MDTs (because of MDT_PREFIX)
31 [ $MDSCOUNT -gt 9 ] &&
32 error "script cannot handle more than 9 MDTs, please fix" && exit
34 check_and_setup_lustre
36 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
37 skip_env "Need MDS version at least 2.4.53" && exit
40 # $RUNAS_ID may get set incorrectly somewhere else
41 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
42 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
48 # if there is no CLIENT1 defined, some tests can be ran on localhost
49 CLIENT1=${CLIENT1:-$HOSTNAME}
50 # if CLIENT2 doesn't exist then use CLIENT1 instead
51 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
53 # Exception is the test which need two separate nodes
54 CLIENT2=${CLIENT2:-$CLIENT1}
57 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
58 # the following associated variables are added:
60 # AGTCOUNT: number of agents
61 # AGTDEV{N}: target HSM mount point (root path of the backend)
62 # agt{N}_HOST: hostname of the agent agt{N}
63 # SINGLEAGT: facet of the single agent
65 # The number of agents is initialized as the number of remote client nodes.
66 # By default, only single copytool is started on a remote client/agent. If there
67 # was no remote client, then the copytool will be started on the local client.
73 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
74 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
76 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
77 if [[ $CLIENTCOUNT -gt 1 ]] &&
78 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
79 skip_env "SHARED_DIRECTORY should be accessible"\
84 # We used to put the HSM archive in $SHARED_DIRECTORY but that
85 # meant NFS issues could hose sanity-hsm sessions. So now we
87 for n in $(seq $AGTCOUNT); do
88 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
89 agent=CLIENT$((n + 1))
90 if [[ -z "${!agent}" ]]; then
91 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
94 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
97 export SINGLEAGT=${SINGLEAGT:-agt1}
99 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
100 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
101 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
102 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
103 export HSMTOOL_TESTDIR
104 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
105 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
108 # The test only support up to 10 MDTs
109 MDT_PREFIX="mdt.$FSNAME-MDT000"
110 HSM_PARAM="${MDT_PREFIX}0.hsm"
112 # archive is purged at copytool setup
113 HSM_ARCHIVE_PURGE=true
115 # Don't allow copytool error upon start/setup
116 HSMTOOL_NOERROR=false
119 # Get the backend root path for the given agent facet.
122 local dev=AGTDEV$(facet_number $facet)
127 # Stop copytool and unregister an existing changelog user.
129 copytool_monitor_cleanup
132 cdt_set_sanity_policy
137 # get MDT device for each mdc
138 for mdtno in $(seq 1 $MDSCOUNT); do
139 local idx=$(($mdtno - 1))
140 MDT[$idx]=$($LCTL get_param -n \
141 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
142 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
147 local agents=${1:-$(facet_active_host $SINGLEAGT)}
148 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
151 search_and_kill_copytool() {
152 local agents=${1:-$(facet_active_host $SINGLEAGT)}
154 echo "Killing existing copytools on $agents"
155 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
158 copytool_monitor_setup() {
159 local facet=${1:-$SINGLEAGT}
160 local agent=$(facet_active_host $facet)
162 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
163 local test_dir=$(do_node $agent "$cmd") ||
164 error "Failed to create tempdir on $agent"
165 export HSMTOOL_MONITOR_DIR=$test_dir
167 # Create the fifo and a monitor (cat dies when copytool dies)
168 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
169 error "failed to create copytool fifo on $agent"
170 cmd="cat $test_dir/fifo > $test_dir/events &"
171 cmd+=" echo \\\$! > $test_dir/monitor_pid"
173 if [[ $PDSH == *Rmrsh* ]]; then
174 # This is required for pdsh -Rmrsh and its handling of remote
176 # Regular ssh and pdsh -Rssh work fine without this
177 # backgrounded subshell nonsense.
178 (do_node $agent "$cmd") &
179 export HSMTOOL_MONITOR_PDSH=$!
181 # Slightly racy, but just making a best-effort to catch obvious
184 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
185 error "Failed to start copytool monitor on $agent"
187 do_node $agent "$cmd"
189 error "Failed to start copytool monitor on $agent"
194 copytool_monitor_cleanup() {
195 local facet=${1:-$SINGLEAGT}
196 local agent=$(facet_active_host $facet)
198 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
199 # Should die when the copytool dies, but just in case.
200 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
201 cmd+=" 2>/dev/null || true"
202 do_node $agent "$cmd"
203 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
204 export HSMTOOL_MONITOR_DIR=
207 # The pdsh should die on its own when the monitor dies. Just
208 # in case, though, try to clean up to avoid any cruft.
209 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
210 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
211 export HSMTOOL_MONITOR_PDSH=
216 local facet=${1:-$SINGLEAGT}
217 # Use MOUNT2 by default if defined
218 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
220 local hsm_root=${4:-$(copytool_device $facet)}
221 local agent=$(facet_active_host $facet)
223 if [[ -z "$arc_id" ]] &&
224 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
225 echo "Only wakeup running copytool $facet on $agent"
229 if $HSM_ARCHIVE_PURGE; then
230 echo "Purging archive on $agent"
231 do_facet $facet "rm -rf $hsm_root/*"
234 echo "Starting copytool $facet on $agent"
235 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
236 # bandwidth is limited to 1MB/s so the copy time is known and
237 # independent of hardware
238 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
239 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
240 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
241 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
242 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
243 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
244 cmd+=" --bandwidth 1 $lustre_mntpnt"
246 # Redirect the standard output and error to a log file which
247 # can be uploaded to Maloo.
248 local prefix=$TESTLOG_PREFIX
249 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
250 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
252 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
253 if [[ $? != 0 ]]; then
254 [[ $HSMTOOL_NOERROR == true ]] ||
255 error "start copytool $facet on $agent failed"
256 echo "start copytool $facet on $agent failed"
262 get_copytool_event_log() {
263 local facet=${1:-$SINGLEAGT}
264 local agent=$(facet_active_host $facet)
266 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
267 error "Can't get event log: No monitor directory!"
269 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
270 error "Could not collect event log from $agent"
275 local agt_facet=$SINGLEAGT
276 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
277 local end_wait=$(( SECONDS + TIMEOUT ))
278 local hsm_root=$(copytool_device $agt_facet)
284 do_nodesv $agt_hosts "pkill -INT -x $HSMTOOL_BASE" || return 0
286 while (( SECONDS < end_wait )); do
288 do_nodesv $agt_hosts "pgrep -x $HSMTOOL_BASE"
289 if [ $? -ne 0 ]; then
290 echo "copytool is stopped on $agt_hosts"
293 echo "copytool still running on $agt_hosts"
296 if do_nodesv $agt_hosts "pgrep -x $HSMTOOL_BASE"; then
297 error "copytool failed to stop in ${TIMEOUT}s"
299 echo "copytool has stopped in " \
300 "$((TIMEOUT - (end_wait - SECONDS)))s"
303 # Clean all CDTs orphans requests from previous tests that
304 # would otherwise need to timeout to clear.
305 for ((i = 0; i < MDSCOUNT; i++)); do
307 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
308 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
310 # Skip already stopping or stopped CDTs.
311 [[ "${state[$i]}" =~ ^stop ]] && continue
313 do_facet $facet "$LCTL set_param $param=shutdown"
316 for ((i = 0; i < MDSCOUNT; i++)); do
317 # Only check and restore CDTs that we stopped in the first loop.
318 [[ "${state[$i]}" =~ ^stop ]] && continue
321 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
323 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
324 error "$facet CDT state is not stopped"
326 # Restore old CDT state.
327 do_facet $facet "$LCTL set_param $param=${state[$i]}"
331 for ((i = 0; i < MDSCOUNT; i++)); do
332 # Only check CDTs that we stopped in the first loop.
333 [[ "${state[$i]}" =~ ^stop ]] && continue
336 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
338 # Check that the old CDT state was restored.
339 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
340 20 || error "$facet CDT state is not '${state[$i]}'"
343 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
344 do_facet $agt_facet "rm -rf $hsm_root/*"
349 local agents=${1:-$(facet_active_host $SINGLEAGT)}
351 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
352 echo "Copytool is suspended on $agents"
355 copytool_remove_backend() {
357 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
358 echo "Remove from backend: $fid = $be"
359 do_facet $SINGLEAGT rm -f $be
363 do_facet $SINGLEAGT \
364 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
365 --import $1 $2 $MOUNT" ||
366 error "import of $1 to $2 failed"
370 local file=$HSM_ARCHIVE/$1
371 do_facet $SINGLEAGT mkdir -p $(dirname $file)
372 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
373 file_creation_failure dd $file $?
377 local file=$HSM_ARCHIVE/$2
378 do_facet $SINGLEAGT mkdir -p $(dirname $file)
379 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
388 if [[ "$value" != "" ]]; then
391 for mdtno in $(seq 1 $MDSCOUNT); do
392 local idx=$(($mdtno - 1))
393 local facet=mds${mdtno}
394 # if $arg include -P option, run 1 set_param per MDT on the MGS
395 # else, run set_param on each MDT
396 [[ $arg = *"-P"* ]] && facet=mgs
397 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
398 [[ $? != 0 ]] && rc=1
408 for mdtno in $(seq 1 $MDSCOUNT); do
409 local idx=$(($mdtno - 1))
410 wait_result mds${mdtno} \
411 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
413 error "$key state is not '$target' on mds${mdtno}"
420 for mdtno in $(seq 1 $MDSCOUNT); do
421 local idx=$(($mdtno - 1))
422 local cl_user=$(do_facet mds${mdtno} $LCTL \
423 --device ${MDT[$idx]} \
424 changelog_register -n)
426 do_facet mds${mdtno} lctl set_param \
427 mdd.${MDT[$idx]}.changelog_mask="+hsm"
428 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
432 changelog_cleanup() {
434 for mdtno in $(seq 1 $MDSCOUNT); do
435 local idx=$(($mdtno - 1))
436 [[ -z ${CL_USERS[$idx]} ]] && continue
437 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
438 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
439 changelog_deregister ${CL_USERS[$idx]}
444 changelog_get_flags() {
449 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
454 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
462 mdts_set_param "$opt -n" "hsm.$param" "$value"
469 mdts_set_param "" hsm_control "$cmd"
470 mdts_check_param hsm_control "$target" 10
473 cdt_set_sanity_policy() {
474 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
477 mdts_set_param "" hsm.policy "+NRA"
478 mdts_set_param "" hsm.policy "-NBR"
479 CDT_POLICY_HAD_CHANGED=
484 mdts_set_param "" hsm.policy "+NRA"
485 CDT_POLICY_HAD_CHANGED=true
488 cdt_clear_no_retry() {
489 mdts_set_param "" hsm.policy "-NRA"
490 CDT_POLICY_HAD_CHANGED=true
493 cdt_set_non_blocking_restore() {
494 mdts_set_param "" hsm.policy "+NBR"
495 CDT_POLICY_HAD_CHANGED=true
498 cdt_clear_non_blocking_restore() {
499 mdts_set_param "" hsm.policy "-NBR"
500 CDT_POLICY_HAD_CHANGED=true
503 cdt_clear_mount_state() {
504 mdts_set_param "-P -d" hsm_control ""
507 cdt_set_mount_state() {
508 mdts_set_param "-P" hsm_control "$1"
509 # set_param -P is asynchronous operation and could race with set_param.
510 # In such case configs could be retrieved and applied at mgc after
511 # set_param -P completion. Sleep here to avoid race with set_param.
512 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
513 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
514 # and 10 seconds to retrieve config from server.
519 mdts_check_param hsm_control "$1" 20
523 set_test_state disabled disabled
527 set_test_state enabled enabled
531 set_test_state shutdown stopped
535 set_test_state purge enabled
541 cdt_set_sanity_policy
545 local client_count=$1
546 if [[ $CLIENTCOUNT -lt $client_count ]]; then
547 skip "Need $client_count or more clients, have $CLIENTCOUNT"
554 $LFS path2fid $1 | tr -d '[]'
555 return ${PIPESTATUS[0]}
563 if [[ $u == "user" ]]; then
564 st=$($RUNAS $LFS hsm_state $f)
567 st=$($LFS hsm_state $f)
570 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
572 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
576 get_hsm_archive_id() {
579 st=$($LFS hsm_state $f)
580 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
582 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
591 local st=$(get_hsm_flags $f)
592 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
595 check_hsm_flags_user() {
599 local st=$(get_hsm_flags $f user)
600 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
603 file_creation_failure() {
608 df $MOUNT $MOUNT2 >&2
609 error "cannot create $f with $cmd, status=$err"
621 if [[ "$3" != 1 ]]; then
625 cp $1 $f || file_creation_failure cp $f $?
627 path2fid $f || error "cannot get fid on $f"
631 local file2=${1/$DIR/$DIR2}
632 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
633 file_creation_failure dd $file2 $?
635 path2fid $1 || error "cannot get fid on $1"
639 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
640 file_creation_failure dd $1 $?
641 path2fid $1 || error "cannot get fid on $1"
644 cleanup_large_files() {
645 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
647 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
650 check_enough_free_space() {
653 local need=$((nb * unit /1024))
654 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
655 (( $need >= $free )) && return 1
659 make_large_for_striping() {
660 local file2=${1/$DIR/$DIR2}
661 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
665 check_enough_free_space 5 $sz
666 [ $? != 0 ] && return $?
668 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
669 file_creation_failure dd $file2 $?
671 path2fid $1 || error "cannot get fid on $1"
674 make_large_for_progress() {
675 local file2=${1/$DIR/$DIR2}
679 check_enough_free_space 39 1000000
680 [ $? != 0 ] && return $?
682 # big file is large enough, so copy time is > 30s
683 # so copytool make 1 progress
684 # size is not a multiple of 1M to avoid stripe
686 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
687 file_creation_failure dd $file2 $?
689 path2fid $1 || error "cannot get fid on $1"
692 make_large_for_progress_aligned() {
693 local file2=${1/$DIR/$DIR2}
697 check_enough_free_space 33 1048576
698 [ $? != 0 ] && return $?
700 # big file is large enough, so copy time is > 30s
701 # so copytool make 1 progress
702 # size is a multiple of 1M to have stripe
704 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
705 file_creation_failure dd $file2 $?
706 path2fid $1 || error "cannot get fid on $1"
709 make_large_for_cancel() {
710 local file2=${1/$DIR/$DIR2}
714 check_enough_free_space 103 1048576
715 [ $? != 0 ] && return $?
717 # Copy timeout is 100s. 105MB => 105s
718 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
719 file_creation_failure dd $file2 $?
720 path2fid $1 || error "cannot get fid on $1"
726 wait_update --verbose $(facet_active_host $facet) "$@"
729 wait_request_state() {
733 # 4th arg (mdt index) is optional
735 local mds=mds$(($mdtidx + 1))
737 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
738 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
740 wait_result $mds "$cmd" $state 200 ||
741 error "request on $fid is not $state on $mds"
744 get_request_state() {
748 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
749 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
752 get_request_count() {
756 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
757 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
764 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
765 [[ -n $fid ]] && cmd+=" | grep '$fid'"
766 cmd+=" | egrep 'WAITING|STARTED'"
768 wait_result $SINGLEMDS "$cmd" "" $timeout ||
769 error "requests did not complete"
772 wait_for_grace_delay() {
773 local val=$(get_hsm_param grace_delay)
780 # python2.6 in EL6 includes an internal json module
781 local json_parser='import json; import fileinput;'
782 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
783 json_parser+='json.loads([line for line in '
784 json_parser+='fileinput.input()][0]).items()])'
786 echo $raw_event | python -c "$json_parser"
789 # populate MDT device array
795 # cleanup from previous bad setup
796 search_and_kill_copytool
798 # for recovery tests, coordinator needs to be started at mount
800 # the lustre conf must be without hsm on (like for sanity.sh)
801 echo "Set HSM on and start"
802 cdt_set_mount_state enabled
803 cdt_check_state enabled
805 echo "Start copytool"
808 echo "Set sanity-hsm HSM policy"
809 cdt_set_sanity_policy
811 # finished requests are quickly removed from list
812 set_hsm_param grace_delay 10
818 local f=$DIR/$tdir/$tfile
822 check_hsm_flags_user $f "0x00000000"
824 $RUNAS $LFS hsm_set --norelease $f ||
825 error "user could not change hsm flags"
826 check_hsm_flags_user $f "0x00000010"
828 $RUNAS $LFS hsm_clear --norelease $f ||
829 error "user could not clear hsm flags"
830 check_hsm_flags_user $f "0x00000000"
832 # User could not change those flags...
833 $RUNAS $LFS hsm_set --exists $f &&
834 error "user should not set this flag"
835 check_hsm_flags_user $f "0x00000000"
838 $LFS hsm_set --exists $f ||
839 error "root could not change hsm flags"
840 check_hsm_flags_user $f "0x00000001"
842 $LFS hsm_clear --exists $f ||
843 error "root could not clear hsm state"
844 check_hsm_flags_user $f "0x00000000"
847 run_test 1 "lfs hsm flags root/non-root access"
851 local f=$DIR/$tdir/$tfile
853 # New files are not dirty
854 check_hsm_flags $f "0x00000000"
856 # For test, we simulate an archived file.
857 $LFS hsm_set --exists $f || error "user could not change hsm flags"
858 check_hsm_flags $f "0x00000001"
860 # chmod do not put the file dirty
861 chmod 600 $f || error "could not chmod test file"
862 check_hsm_flags $f "0x00000001"
864 # chown do not put the file dirty
865 chown $RUNAS_ID $f || error "could not chown test file"
866 check_hsm_flags $f "0x00000001"
868 # truncate put the file dirty
869 $TRUNCATE $f 1 || error "could not truncate test file"
870 check_hsm_flags $f "0x00000003"
872 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
873 check_hsm_flags $f "0x00000001"
875 run_test 2 "Check file dirtyness when doing setattr"
881 # New files are not dirty
883 check_hsm_flags $f "0x00000000"
885 # For test, we simulate an archived file.
886 $LFS hsm_set --exists $f ||
887 error "user could not change hsm flags"
888 check_hsm_flags $f "0x00000001"
890 # Reading a file, does not set dirty
891 cat $f > /dev/null || error "could not read file"
892 check_hsm_flags $f "0x00000001"
894 # Open for write without modifying data, does not set dirty
895 openfile -f O_WRONLY $f || error "could not open test file"
896 check_hsm_flags $f "0x00000001"
898 # Append to a file sets it dirty
899 cp -p /etc/passwd $f.append || error "could not create file"
900 $LFS hsm_set --exists $f.append ||
901 error "user could not change hsm flags"
902 dd if=/etc/passwd of=$f.append bs=1 count=3\
903 conv=notrunc oflag=append status=noxfer ||
904 file_creation_failure dd $f.append $?
905 check_hsm_flags $f.append "0x00000003"
907 # Modify a file sets it dirty
908 cp -p /etc/passwd $f.modify || error "could not create file"
909 $LFS hsm_set --exists $f.modify ||
910 error "user could not change hsm flags"
911 dd if=/dev/zero of=$f.modify bs=1 count=3\
912 conv=notrunc status=noxfer ||
913 file_creation_failure dd $f.modify $?
914 check_hsm_flags $f.modify "0x00000003"
916 # Open O_TRUNC sets dirty
917 cp -p /etc/passwd $f.trunc || error "could not create file"
918 $LFS hsm_set --exists $f.trunc ||
919 error "user could not change hsm flags"
920 cp /etc/group $f.trunc || error "could not override a file"
921 check_hsm_flags $f.trunc "0x00000003"
923 # Mmapped a file sets dirty
924 cp -p /etc/passwd $f.mmap || error "could not create file"
925 $LFS hsm_set --exists $f.mmap ||
926 error "user could not change hsm flags"
927 multiop $f.mmap OSMWUc || error "could not mmap a file"
928 check_hsm_flags $f.mmap "0x00000003"
930 run_test 3 "Check file dirtyness when opening for write"
934 local f=$DIR/$tdir/$tfile
935 local fid=$(make_small $f)
938 local st=$(get_request_state $fid CANCEL)
939 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
941 run_test 4 "Useless cancel must not be registered"
944 # test needs a running copytool
948 local f=$DIR/$tdir/$tfile
949 local fid=$(copy_file /etc/passwd $f)
951 wait_request_state $fid ARCHIVE SUCCEED
953 check_hsm_flags $f "0x00000009"
957 run_test 8 "Test default archive number"
961 local f=$DIR/$tdir/$tfile
962 local fid=$(copy_file /etc/passwd $f)
963 # we do not use the default one to be sure
964 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
966 copytool_setup $SINGLEAGT $MOUNT $new_an
967 $LFS hsm_archive --archive $new_an $f
968 wait_request_state $fid ARCHIVE SUCCEED
970 check_hsm_flags $f "0x00000009"
974 run_test 9 "Use of explicit archive number, with dedicated copytool"
977 needclients 3 || return 0
983 copytool_cleanup $(comma_list $(agts_nodes))
985 # start all of the copytools
986 for n in $(seq $AGTCOUNT); do
990 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
993 for n in $(seq $AGTCOUNT); do
994 file=$DIR/$tdir/$tfile.$n
995 fid=$(make_small $file)
997 $LFS hsm_archive $file || error "could not archive file $file"
998 wait_request_state $fid ARCHIVE SUCCEED
999 check_hsm_flags $file "0x00000009"
1003 copytool_cleanup $(comma_list $(agts_nodes))
1005 run_test 9a "Multiple remote agents"
1008 # test needs a running copytool
1011 mkdir -p $DIR/$tdir/d1
1012 local f=$DIR/$tdir/$tfile
1013 local fid=$(copy_file /etc/hosts $f)
1014 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1015 error "hsm_archive failed"
1016 wait_request_state $fid ARCHIVE SUCCEED
1018 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1019 error "fid $fid not in archive $HSM_ARCHIVE"
1020 echo "Verifying content"
1021 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1022 echo "Verifying hsm state "
1023 check_hsm_flags $f "0x00000009"
1025 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1026 local st=$(get_hsm_archive_id $f)
1027 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1028 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1033 run_test 10a "Archive a file"
1036 # test needs a running copytool
1040 local f=$DIR/$tdir/$tfile
1041 local fid=$(copy_file /etc/hosts $f)
1042 $LFS hsm_archive $f || error "archive request failed"
1043 wait_request_state $fid ARCHIVE SUCCEED
1045 $LFS hsm_archive $f || error "archive of non dirty file failed"
1046 local cnt=$(get_request_count $fid ARCHIVE)
1047 [[ "$cnt" == "1" ]] ||
1048 error "archive of non dirty file must not make a request"
1052 run_test 10b "Archive of non dirty file must work without doing request"
1055 # test needs a running copytool
1059 local f=$DIR/$tdir/$tfile
1060 local fid=$(copy_file /etc/hosts $f)
1061 $LFS hsm_set --noarchive $f
1062 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1066 run_test 10c "Check forbidden archive"
1069 # test needs a running copytool
1073 local f=$DIR/$tdir/$tfile
1074 local fid=$(copy_file /etc/hosts $f)
1075 $LFS hsm_archive $f || error "cannot archive $f"
1076 wait_request_state $fid ARCHIVE SUCCEED
1078 local ar=$(get_hsm_archive_id $f)
1079 local dflt=$(get_hsm_param default_archive_id)
1080 [[ $ar == $dflt ]] ||
1081 error "archived file is not on default archive: $ar != $dflt"
1085 run_test 10d "Archive a file on the default archive id"
1089 copy2archive /etc/hosts $tdir/$tfile
1090 local f=$DIR/$tdir/$tfile
1092 import_file $tdir/$tfile $f
1093 echo -n "Verifying released state: "
1094 check_hsm_flags $f "0x0000000d"
1096 local LSZ=$(stat -c "%s" $f)
1097 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1099 echo "Verifying imported size $LSZ=$ASZ"
1100 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1101 echo -n "Verifying released pattern: "
1102 local PTRN=$($GETSTRIPE -L $f)
1104 [[ $PTRN == 80000001 ]] || error "Is not released"
1105 local fid=$(path2fid $f)
1106 echo "Verifying new fid $fid in archive"
1108 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1109 error "fid $fid not in archive $HSM_ARCHIVE"
1111 run_test 11a "Import a file"
1114 # test needs a running copytool
1118 local f=$DIR/$tdir/$tfile
1119 local fid=$(copy_file /etc/hosts $f)
1120 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1121 error "hsm_archive failed"
1122 wait_request_state $fid ARCHIVE SUCCEED
1124 local FILE_HASH=$(md5sum $f)
1129 echo "$FILE_HASH" | md5sum -c
1131 [[ $? -eq 0 ]] || error "Restored file differs"
1135 run_test 11b "Import a deleted file using its FID"
1138 # test needs a running copytool
1142 copy2archive /etc/hosts $tdir/$tfile
1144 local f=$DIR/$tdir/$tfile
1145 import_file $tdir/$tfile $f
1146 local f2=$DIR2/$tdir/$tfile
1147 echo "Verifying released state: "
1148 check_hsm_flags $f2 "0x0000000d"
1150 local fid=$(path2fid $f2)
1151 $LFS hsm_restore $f2
1152 wait_request_state $fid RESTORE SUCCEED
1154 echo "Verifying file state: "
1155 check_hsm_flags $f2 "0x00000009"
1157 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1159 [[ $? -eq 0 ]] || error "Restored file differs"
1163 run_test 12a "Restore an imported file explicitly"
1166 # test needs a running copytool
1170 copy2archive /etc/hosts $tdir/$tfile
1172 local f=$DIR/$tdir/$tfile
1173 import_file $tdir/$tfile $f
1174 echo "Verifying released state: "
1175 check_hsm_flags $f "0x0000000d"
1177 cat $f > /dev/null || error "File read failed"
1179 echo "Verifying file state after restore: "
1180 check_hsm_flags $f "0x00000009"
1182 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1184 [[ $? -eq 0 ]] || error "Restored file differs"
1188 run_test 12b "Restore an imported file implicitly"
1191 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1193 # test needs a running copytool
1197 local f=$DIR/$tdir/$tfile
1198 $LFS setstripe -c 2 $f
1200 fid=$(make_large_for_striping $f)
1201 [ $? != 0 ] && skip "not enough free space" && return
1203 local FILE_CRC=$(md5sum $f)
1205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1206 wait_request_state $fid ARCHIVE SUCCEED
1207 $LFS hsm_release $f || error "release $f failed"
1209 echo "$FILE_CRC" | md5sum -c
1211 [[ $? -eq 0 ]] || error "Restored file differs"
1215 run_test 12c "Restore a file with stripe of 2"
1218 # test needs a running copytool
1223 local f=$DIR/$tdir/$tfile
1224 local fid=$(copy_file /etc/hosts $f)
1225 $LFS hsm_restore $f || error "restore of non archived file failed"
1226 local cnt=$(get_request_count $fid RESTORE)
1227 [[ "$cnt" == "0" ]] ||
1228 error "restore non archived must not make a request"
1229 $LFS hsm_archive $f ||
1230 error "archive request failed"
1231 wait_request_state $fid ARCHIVE SUCCEED
1232 $LFS hsm_restore $f ||
1233 error "restore of non released file failed"
1234 local cnt=$(get_request_count $fid RESTORE)
1235 [[ "$cnt" == "0" ]] ||
1236 error "restore a non dirty file must not make a request"
1240 run_test 12d "Restore of a non archived, non released file must work"\
1241 " without doing request"
1244 # test needs a running copytool
1247 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_archive $f || error "archive request failed"
1251 wait_request_state $fid ARCHIVE SUCCEED
1254 cat /etc/hosts >> $f
1258 $LFS hsm_restore $f && error "restore a dirty file must fail"
1262 run_test 12e "Check forbidden restore"
1265 # test needs a running copytool
1269 local f=$DIR/$tdir/$tfile
1270 local fid=$(copy_file /etc/hosts $f)
1272 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1273 wait_request_state $fid ARCHIVE SUCCEED
1274 $LFS hsm_release $f || error "release of $f failed"
1276 wait_request_state $fid RESTORE SUCCEED
1278 echo -n "Verifying file state: "
1279 check_hsm_flags $f "0x00000009"
1281 diff -q /etc/hosts $f
1283 [[ $? -eq 0 ]] || error "Restored file differs"
1287 run_test 12f "Restore a released file explicitly"
1290 # test needs a running copytool
1294 local f=$DIR/$tdir/$tfile
1295 local fid=$(copy_file /etc/hosts $f)
1297 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1298 wait_request_state $fid ARCHIVE SUCCEED
1299 $LFS hsm_release $f || error "release of $f failed"
1301 diff -q /etc/hosts $f
1304 # we check we had a restore done
1305 wait_request_state $fid RESTORE SUCCEED
1307 [[ $st -eq 0 ]] || error "Restored file differs"
1311 run_test 12g "Restore a released file implicitly"
1314 needclients 2 || return 0
1316 # test needs a running copytool
1320 local f=$DIR/$tdir/$tfile
1321 local fid=$(copy_file /etc/hosts $f)
1323 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1324 wait_request_state $fid ARCHIVE SUCCEED
1325 $LFS hsm_release $f || error "release of $f failed"
1327 do_node $CLIENT2 diff -q /etc/hosts $f
1330 # we check we had a restore done
1331 wait_request_state $fid RESTORE SUCCEED
1333 [[ $st -eq 0 ]] || error "Restored file differs"
1337 run_test 12h "Restore a released file implicitly from a second node"
1340 # test needs a running copytool
1344 local f=$DIR/$tdir/$tfile
1345 local fid=$(copy_file /etc/passwd $f)
1346 $LFS hsm_archive $f || error "archive of $f failed"
1347 wait_request_state $fid ARCHIVE SUCCEED
1349 $LFS hsm_release $f || error "release of $f failed"
1353 [[ $? -eq 0 ]] || error "Restored file differs"
1357 run_test 12m "Archive/release/implicit restore"
1360 # test needs a running copytool
1364 copy2archive /etc/hosts $tdir/$tfile
1366 local f=$DIR/$tdir/$tfile
1367 import_file $tdir/$tfile $f
1369 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1370 error "Restored file differs"
1372 $LFS hsm_release $f || error "release of $f failed"
1376 run_test 12n "Import/implicit restore/release"
1379 # test needs a running copytool
1383 local f=$DIR/$tdir/$tfile
1384 local fid=$(copy_file /etc/hosts $f)
1386 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1387 wait_request_state $fid ARCHIVE SUCCEED
1388 $LFS hsm_release $f || error "release of $f failed"
1390 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1391 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1393 # set no retry action mode
1396 diff -q /etc/hosts $f
1399 # we check we had a restore failure
1400 wait_request_state $fid RESTORE FAILED
1402 [[ $st -eq 0 ]] && error "Restore must fail"
1404 # remove no retry action mode
1407 # check file is still released
1408 check_hsm_flags $f "0x0000000d"
1410 # retry w/o failure injection
1411 do_facet $SINGLEMDS lctl set_param fail_loc=0
1413 # to be sure previous RESTORE result is gone
1415 wait_for_grace_delay
1417 diff -q /etc/hosts $f
1420 # we check we had a restore done
1421 wait_request_state $fid RESTORE SUCCEED
1423 [[ $st -eq 0 ]] || error "Restored file differs"
1427 run_test 12o "Layout-swap failure during Restore leaves file released"
1430 # test needs a running copytool
1434 local f=$DIR/$tdir/$tfile
1435 local fid=$(copy_file /etc/hosts $f)
1437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1438 wait_request_state $fid ARCHIVE SUCCEED
1439 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1440 $LFS hsm_release $f || error "cannot release $f"
1441 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1442 $LFS hsm_release $f || error "cannot release $f"
1443 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1447 run_test 12p "implicit restore of a file on copytool mount point"
1449 cleanup_test_12q() {
1451 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1452 error "cannot umount $MOUNT3 on $SINGLEAGT"
1456 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1457 skip "need MDS version at least 2.7.58" && return 0
1459 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1460 error "cannot mount $MOUNT3 on $SINGLEAGT"
1462 trap cleanup_test_12q EXIT
1464 # test needs a running copytool
1465 copytool_setup $SINGLEAGT $MOUNT3
1468 local f=$DIR/$tdir/$tfile
1469 local f2=$DIR2/$tdir/$tfile
1470 local fid=$(make_small $f)
1471 local orig_size=$(stat -c "%s" $f)
1473 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1474 wait_request_state $fid ARCHIVE SUCCEED
1476 $LFS hsm_release $f || error "could not release file"
1477 check_hsm_flags $f "0x0000000d"
1479 search_and_kill_copytool
1481 search_copytools && error "Copytool should have stopped"
1483 cat $f > /dev/null &
1485 # wait a bit to allow implicit restore request to be handled.
1486 # if not, next stat would also block on layout-lock.
1489 local size=$(stat -c "%s" $f2)
1490 [ $size -eq $orig_size ] ||
1491 error "$f2: wrong size after archive: $size != $orig_size"
1493 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1497 size=$(stat -c "%s" $f)
1498 [ $size -eq $orig_size ] ||
1499 error "$f: wrong size after restore: $size != $orig_size"
1501 size=$(stat -c "%s" $f2)
1502 [ $size -eq $orig_size ] ||
1503 error "$f2: wrong size after restore: $size != $orig_size"
1507 size=$(stat -c "%s" $f)
1509 error "$f: wrong size after overwrite: $size != 0"
1511 size=$(stat -c "%s" $f2)
1513 error "$f2: wrong size after overwrite: $size != 0"
1516 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1517 error "cannot umount $MOUNT3 on $SINGLEAGT"
1519 run_test 12q "file attributes are refreshed after restore"
1522 # test needs a running copytool
1525 local ARC_SUBDIR="import.orig"
1529 # populate directory to be imported
1530 for d in $(seq 1 10); do
1531 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1532 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1533 for f in $(seq 1 10); do
1534 CURR_FILE="$CURR_DIR/$tfile.$f"
1535 # write file-specific data
1536 do_facet $SINGLEAGT \
1537 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1538 "file=$CURR_FILE > $CURR_FILE"
1542 import_file "$ARC_SUBDIR" $DIR/$tdir
1543 # diff lustre content and origin (triggers file restoration)
1544 # there must be 10x10 identical files, and no difference
1545 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1546 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1547 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1548 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1550 [ $cnt_diff -eq 0 ] ||
1551 error "$cnt_diff imported files differ from read data"
1552 [ $cnt_ok -eq 100 ] ||
1553 error "not enough identical files ($cnt_ok != 100)"
1557 run_test 13 "Recursively import and restore a directory"
1560 # test needs a running copytool
1565 local f=$DIR/$tdir/$tfile
1566 local fid=$(make_small $f)
1567 local sum=$(md5sum $f | awk '{print $1}')
1568 $LFS hsm_archive $f || error "could not archive file"
1569 wait_request_state $fid ARCHIVE SUCCEED
1573 # create released file (simulate llapi_hsm_import call)
1575 local fid2=$(path2fid $f)
1576 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1577 $LFS hsm_release $f || error "could not release file"
1579 # rebind the archive to the newly created file
1580 echo "rebind $fid to $fid2"
1582 do_facet $SINGLEAGT \
1583 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1584 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1586 # restore file and compare md5sum
1587 local sum2=$(md5sum $f | awk '{print $1}')
1589 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1593 run_test 14 "Rebind archived file to a new fid"
1596 # test needs a running copytool
1601 local f=$DIR/$tdir/$tfile
1603 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1607 for i in $(seq 1 $count); do
1608 fids[$i]=$(make_small $f.$i)
1609 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1610 $LFS hsm_archive $f.$i || error "could not archive file"
1612 wait_all_done $(($count*60))
1616 for i in $(seq 1 $count); do
1619 local fid2=$(path2fid $f.$i)
1620 # add the rebind operation to the list
1621 echo ${fids[$i]} $fid2 >> $tmpfile
1623 # set it released (simulate llapi_hsm_import call)
1624 $LFS hsm_set --archived --exists $f.$i ||
1625 error "could not force hsm flags"
1626 $LFS hsm_release $f.$i || error "could not release file"
1628 nl=$(wc -l < $tmpfile)
1629 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1631 echo "rebind list of files"
1632 do_facet $SINGLEAGT \
1633 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1634 --rebind $tmpfile $DIR" || error "could not rebind file list"
1636 # restore files and compare md5sum
1637 for i in $(seq 1 $count); do
1638 local sum2=$(md5sum $f.$i | awk '{print $1}')
1639 [[ $sum2 == ${sums[$i]} ]] ||
1640 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1646 run_test 15 "Rebind a list of files"
1649 # test needs a running copytool
1653 # create a known size file so we can verify transfer speed
1656 dd if=/dev/zero of=$ref bs=1M count=20
1659 local f=$DIR/$tdir/$tfile
1660 local fid=$(copy_file $ref $f)
1662 local start=$(date +%s)
1664 wait_request_state $fid ARCHIVE SUCCEED
1665 local end=$(date +%s)
1666 local duration=$((end - start))
1668 [[ $duration -ge $goal ]] ||
1669 error "Transfer is too fast $duration < $goal"
1673 run_test 16 "Test CT bandwith control option"
1678 local f=$DIR/$tdir/$tfile
1679 touch $f || error "touch $f failed"
1681 # Could not release a non-archived file
1682 $LFS hsm_release $f && error "release should not succeed"
1684 # For following tests, we must test them with HS_ARCHIVED set
1685 $LFS hsm_set --exists --archived $f || error "could not add flag"
1687 # Could not release a file if no-release is set
1688 $LFS hsm_set --norelease $f || error "could not add flag"
1689 $LFS hsm_release $f && error "release should not succeed"
1690 $LFS hsm_clear --norelease $f || error "could not remove flag"
1692 # Could not release a file if lost
1693 $LFS hsm_set --lost $f || error "could not add flag"
1694 $LFS hsm_release $f && error "release should not succeed"
1695 $LFS hsm_clear --lost $f || error "could not remove flag"
1697 # Could not release a file if dirty
1698 $LFS hsm_set --dirty $f || error "could not add flag"
1699 $LFS hsm_release $f && error "release should not succeed"
1700 $LFS hsm_clear --dirty $f || error "could not remove flag"
1702 run_test 20 "Release is not permitted"
1705 # test needs a running copytool
1709 local f=$DIR/$tdir/test_release
1711 # Create a file and check its states
1712 local fid=$(make_small $f)
1713 check_hsm_flags $f "0x00000000"
1715 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1716 # used until file is flushed to disk
1717 if [ $(facet_fstype ost1) == "zfs" ]; then
1718 # this causes an OST_SYNC rpc to be sent
1719 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1720 # clear locks to reread file data
1721 cancel_lru_locks osc
1724 local orig_size=$(stat -c "%s" $f)
1725 local orig_blocks=$(stat -c "%b" $f)
1727 start_full_debug_logging
1729 $LFS hsm_archive $f || error "could not archive file"
1730 wait_request_state $fid ARCHIVE SUCCEED
1732 local blocks=$(stat -c "%b" $f)
1733 [ $blocks -eq $orig_blocks ] ||
1734 error "$f: wrong block number after archive: " \
1735 "$blocks != $orig_blocks"
1736 local size=$(stat -c "%s" $f)
1737 [ $size -eq $orig_size ] ||
1738 error "$f: wrong size after archive: $size != $orig_size"
1740 # Release and check states
1741 $LFS hsm_release $f || error "could not release file"
1742 check_hsm_flags $f "0x0000000d"
1744 blocks=$(stat -c "%b" $f)
1745 [ $blocks -gt 5 ] &&
1746 error "$f: too many blocks after release: $blocks > 5"
1747 size=$(stat -c "%s" $f)
1748 [ $size -ne $orig_size ] &&
1749 error "$f: wrong size after release: $size != $orig_size"
1751 # Check we can release an file without stripe info
1755 check_hsm_flags $f "0x00000000"
1756 $LFS hsm_archive $f || error "could not archive file"
1757 wait_request_state $fid ARCHIVE SUCCEED
1759 # Release and check states
1760 $LFS hsm_release $f || error "could not release file"
1761 check_hsm_flags $f "0x0000000d"
1763 # Release again a file that is already released is OK
1764 $LFS hsm_release $f || fail "second release should succeed"
1765 check_hsm_flags $f "0x0000000d"
1767 stop_full_debug_logging
1771 run_test 21 "Simple release tests"
1774 # test needs a running copytool
1779 local f=$DIR/$tdir/test_release
1780 local swap=$DIR/$tdir/test_swap
1782 # Create a file and check its states
1783 local fid=$(make_small $f)
1784 check_hsm_flags $f "0x00000000"
1786 $LFS hsm_archive $f || error "could not archive file"
1787 wait_request_state $fid ARCHIVE SUCCEED
1789 # Release and check states
1790 $LFS hsm_release $f || error "could not release file"
1791 check_hsm_flags $f "0x0000000d"
1794 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1799 run_test 22 "Could not swap a release file"
1802 # test needs a running copytool
1807 local f=$DIR/$tdir/test_mtime
1809 # Create a file and check its states
1810 local fid=$(make_small $f)
1811 check_hsm_flags $f "0x00000000"
1813 $LFS hsm_archive $f || error "could not archive file"
1814 wait_request_state $fid ARCHIVE SUCCEED
1816 # Set modification time in the past
1817 touch -m -a -d @978261179 $f
1819 # Release and check states
1820 $LFS hsm_release $f || error "could not release file"
1821 check_hsm_flags $f "0x0000000d"
1823 local MTIME=$(stat -c "%Y" $f)
1824 local ATIME=$(stat -c "%X" $f)
1825 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1826 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1830 run_test 23 "Release does not change a/mtime (utime)"
1833 local file=$DIR/$tdir/$tfile
1842 # test needs a running copytool
1847 fid=$(make_small $file)
1849 # Create a file and check its states
1850 check_hsm_flags $file "0x00000000"
1852 # Ensure atime is less than mtime and ctime.
1856 atime0=$(stat -c "%X" $file)
1857 mtime0=$(stat -c "%Y" $file)
1858 ctime0=$(stat -c "%Z" $file)
1860 [ $atime0 -lt $mtime0 ] ||
1861 error "atime $atime0 is not less than mtime $mtime0"
1863 [ $atime0 -lt $ctime0 ] ||
1864 error "atime $atime0 is not less than ctime $ctime0"
1866 # Archive should not change any timestamps.
1867 $LFS hsm_archive $file || error "cannot archive '$file'"
1868 wait_request_state $fid ARCHIVE SUCCEED
1870 atime1=$(stat -c "%X" $file)
1871 mtime1=$(stat -c "%Y" $file)
1872 ctime1=$(stat -c "%Z" $file)
1874 [ $atime0 -eq $atime1 ] ||
1875 error "archive changed atime from $atime0 to $atime1"
1877 [ $mtime0 -eq $mtime1 ] ||
1878 error "archive changed mtime from $mtime0 to $mtime1"
1880 [ $ctime0 -eq $ctime1 ] ||
1881 error "archive changed ctime from $ctime0 to $ctime1"
1883 # Release should not change any timestamps.
1884 $LFS hsm_release $file || error "cannot release '$file'"
1885 check_hsm_flags $file "0x0000000d"
1887 atime1=$(stat -c "%X" $file)
1888 mtime1=$(stat -c "%Y" $file)
1889 ctime1=$(stat -c "%Z" $file)
1891 [ $atime0 -eq $atime1 ] ||
1892 error "release changed atime from $atime0 to $atime1"
1894 [ $mtime0 -eq $mtime1 ] ||
1895 error "release changed mtime from $mtime0 to $mtime1"
1897 [ $ctime0 -eq $ctime1 ] ||
1898 error "release changed ctime from $ctime0 to $ctime1"
1900 # Restore should not change atime or mtime and should not
1902 $LFS hsm_restore $file
1903 wait_request_state $fid RESTORE SUCCEED
1905 atime1=$(stat -c "%X" $file)
1906 mtime1=$(stat -c "%Y" $file)
1907 ctime1=$(stat -c "%Z" $file)
1909 [ $atime0 -eq $atime1 ] ||
1910 error "restore changed atime from $atime0 to $atime1"
1912 [ $mtime0 -eq $mtime1 ] ||
1913 error "restore changed mtime from $mtime0 to $mtime1"
1915 [ $ctime0 -eq $ctime1 ] ||
1916 error "restore changed ctime from $ctime0 to $ctime1"
1920 # Once more, after unmount and mount.
1921 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1922 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1924 atime1=$(stat -c "%X" $file)
1925 mtime1=$(stat -c "%Y" $file)
1926 ctime1=$(stat -c "%Z" $file)
1928 [ $atime0 -eq $atime1 ] ||
1929 error "remount changed atime from $atime0 to $atime1"
1931 [ $mtime0 -eq $mtime1 ] ||
1932 error "remount changed mtime from $mtime0 to $mtime1"
1934 [ $ctime0 -eq $ctime1 ] ||
1935 error "remount changed ctime from $ctime0 to $ctime1"
1937 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1940 local file=$DIR/$tdir/$tfile
1946 # Test needs a running copytool.
1950 # Check that root can do HSM actions on a regular user's file.
1952 fid=$(make_small $file)
1953 sum0=$(md5sum $file)
1955 chown $RUNAS_ID:$RUNAS_GID $file ||
1956 error "cannot chown '$file' to '$RUNAS_ID'"
1958 chmod ugo-w $DIR/$tdir ||
1959 error "cannot chmod '$DIR/$tdir'"
1961 $LFS hsm_archive $file
1962 wait_request_state $fid ARCHIVE SUCCEED
1964 $LFS hsm_release $file
1965 check_hsm_flags $file "0x0000000d"
1967 $LFS hsm_restore $file
1968 wait_request_state $fid RESTORE SUCCEED
1970 # Check that ordinary user can get HSM state.
1971 $RUNAS $LFS hsm_state $file ||
1972 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1974 $LFS hsm_release $file
1975 check_hsm_flags $file "0x0000000d"
1977 # Check that ordinary user can accessed released file.
1978 sum1=$($RUNAS md5sum $file) ||
1979 error "user '$RUNAS_ID' cannot read '$file'"
1981 [ "$sum0" == "$sum1" ] ||
1982 error "md5sum mismatch for '$file'"
1986 run_test 24b "root can archive, release, and restore user files"
1988 cleanup_test_24c() {
1990 set_hsm_param user_request_mask RESTORE
1991 set_hsm_param group_request_mask RESTORE
1992 set_hsm_param other_request_mask RESTORE
1996 local file=$DIR/$tdir/$tfile
1997 local action=archive
2002 # test needs a running copytool
2007 # Save the default masks and check that cleanup_24c will
2008 # restore the request masks correctly.
2009 user_save=$(get_hsm_param user_request_mask)
2010 group_save=$(get_hsm_param group_request_mask)
2011 other_save=$(get_hsm_param other_request_mask)
2013 [ "$user_save" == RESTORE ] ||
2014 error "user_request_mask is '$user_save' expected 'RESTORE'"
2015 [ "$group_save" == RESTORE ] ||
2016 error "group_request_mask is '$group_save' expected 'RESTORE'"
2017 [ "$other_save" == RESTORE ] ||
2018 error "other_request_mask is '$other_save' expected 'RESTORE'"
2020 trap cleanup_test_24c EXIT
2025 chown $RUNAS_ID:nobody $file ||
2026 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2028 set_hsm_param user_request_mask ""
2029 $RUNAS $LFS hsm_$action $file &&
2030 error "$action by user should fail"
2032 set_hsm_param user_request_mask $action
2033 $RUNAS $LFS hsm_$action $file ||
2034 error "$action by user should succeed"
2039 chown nobody:$RUNAS_GID $file ||
2040 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2042 set_hsm_param group_request_mask ""
2043 $RUNAS $LFS hsm_$action $file &&
2044 error "$action by group should fail"
2046 set_hsm_param group_request_mask $action
2047 $RUNAS $LFS hsm_$action $file ||
2048 error "$action by group should succeed"
2053 chown nobody:nobody $file ||
2054 error "cannot chown '$file' to 'nobody:nobody'"
2056 set_hsm_param other_request_mask ""
2057 $RUNAS $LFS hsm_$action $file &&
2058 error "$action by other should fail"
2060 set_hsm_param other_request_mask $action
2061 $RUNAS $LFS hsm_$action $file ||
2062 error "$action by other should succeed"
2067 run_test 24c "check that user,group,other request masks work"
2069 cleanup_test_24d() {
2071 mount -o remount,rw $MOUNT2
2075 local file1=$DIR/$tdir/$tfile
2076 local file2=$DIR2/$tdir/$tfile
2084 fid1=$(make_small $file1)
2086 trap cleanup_test_24d EXIT
2088 mount -o remount,ro $MOUNT2
2090 fid2=$(path2fid $file2)
2091 [ "$fid1" == "$fid2" ] ||
2092 error "FID mismatch '$fid1' != '$fid2'"
2094 $LFS hsm_archive $file2 &&
2095 error "archive should fail on read-only mount"
2096 check_hsm_flags $file1 "0x00000000"
2098 $LFS hsm_archive $file1
2099 wait_request_state $fid1 ARCHIVE SUCCEED
2101 $LFS hsm_release $file1
2102 $LFS hsm_restore $file2
2103 wait_request_state $fid1 RESTORE SUCCEED
2105 $LFS hsm_release $file1 || error "cannot release '$file1'"
2106 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2108 $LFS hsm_release $file2 &&
2109 error "release should fail on read-only mount"
2114 run_test 24d "check that read-only mounts are respected"
2121 local f=$DIR/$tdir/$tfile
2124 fid=$(make_small $f) || error "cannot create $f"
2125 $LFS hsm_archive $f || error "cannot archive $f"
2126 wait_request_state $fid ARCHIVE SUCCEED
2127 $LFS hsm_release $f || error "cannot release $f"
2128 while ! $LFS hsm_state $f | grep released; do
2132 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2136 run_test 24e "tar succeeds on HSM released files" # LU-6213
2140 # test needs a running copytool
2143 mkdir -p $DIR/$tdir/d1
2144 local f=$DIR/$tdir/$tfile
2145 local fid=$(copy_file /etc/hosts $f)
2148 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2149 error "hsm_archive failed"
2150 wait_request_state $fid ARCHIVE SUCCEED
2151 $LFS hsm_release $f || error "cannot release $f"
2152 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2155 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2156 error "Can not recover the tar contents"
2158 echo "Sum0 = $sum0, sum1 = $sum1"
2159 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2163 run_test 24f "root can archive, release, and restore tar files"
2166 # test needs a running copytool
2170 copy2archive /etc/hosts $tdir/$tfile
2172 local f=$DIR/$tdir/$tfile
2174 import_file $tdir/$tfile $f
2176 $LFS hsm_set --lost $f
2181 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2185 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2186 " (Operation not permitted)"
2189 # test needs a running copytool
2194 local f=$DIR/$tdir/$tfile
2195 local fid=$(copy_file /etc/passwd $f)
2197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2198 wait_request_state $fid ARCHIVE SUCCEED
2201 $LFS hsm_set --lost $f
2205 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2209 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2210 " (Operation not permitted)"
2213 # test needs a running copytool
2217 local f=$DIR/$tdir/$tfile
2219 fid=$(make_large_for_progress $f)
2220 [ $? != 0 ] && skip "not enough free space" && return
2222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2223 wait_request_state $fid ARCHIVE SUCCEED
2226 wait_request_state $fid REMOVE SUCCEED
2228 check_hsm_flags $f "0x00000000"
2232 run_test 26 "Remove the archive of a valid file"
2235 # test needs a running copytool
2239 make_archive $tdir/$tfile
2240 local f=$DIR/$tdir/$tfile
2241 import_file $tdir/$tfile $f
2242 local fid=$(path2fid $f)
2246 [[ $? != 0 ]] || error "Remove of a released file should fail"
2250 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2253 # test needs a running copytool
2257 local f=$DIR/$tdir/$tfile
2259 fid=$(make_large_for_progress $f)
2260 [ $? != 0 ] && skip "not enough free space" && return
2262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2263 wait_request_state $fid ARCHIVE SUCCEED
2268 [[ $? != 0 ]] || error "Remove of a released file should fail"
2272 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2275 # test needs a running copytool
2279 local f=$DIR/$tdir/$tfile
2281 fid=$(make_large_for_progress $f)
2282 [ $? != 0 ] && skip "not enough free space" && return
2284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2285 wait_request_state $fid ARCHIVE SUCCEED
2294 wait_request_state $fid REMOVE SUCCEED
2298 run_test 28 "Concurrent archive/file remove"
2301 # Tests --mntpath and --archive options
2304 copytool_setup $SINGLEAGT $MOUNT $archive_id
2306 # Bad archive number
2307 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2308 grep "Invalid argument" ||
2309 error "unexpected hsm_remove failure (1)"
2311 # mntpath is present but file is given
2312 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2313 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2314 error "unexpected hsm_remove failure (2)"
2318 run_test 29a "Tests --mntpath and --archive options"
2321 # test needs a running copytool
2325 local f=$DIR/$tdir/$tfile
2326 local fid=$(make_small $f)
2328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2329 wait_request_state $fid ARCHIVE SUCCEED
2333 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2334 wait_request_state $fid REMOVE SUCCEED
2338 run_test 29b "Archive/delete/remove by FID from the archive."
2341 # test needs a running copytool
2345 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2346 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2347 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2349 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2350 wait_request_state $fid1 ARCHIVE SUCCEED
2351 wait_request_state $fid2 ARCHIVE SUCCEED
2352 wait_request_state $fid3 ARCHIVE SUCCEED
2354 rm -f $DIR/$tdir/$tfile-[1-3]
2356 echo $fid1 > $DIR/$tdir/list
2357 echo $fid2 >> $DIR/$tdir/list
2358 echo $fid3 >> $DIR/$tdir/list
2360 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2361 --filelist $DIR/$tdir/list
2362 wait_request_state $fid1 REMOVE SUCCEED
2363 wait_request_state $fid2 REMOVE SUCCEED
2364 wait_request_state $fid3 REMOVE SUCCEED
2368 run_test 29c "Archive/delete/remove by FID, using a file list."
2371 # restore at exec cannot work on agent node (because of Linux kernel
2372 # protection of executables)
2373 needclients 2 || return 0
2375 # test needs a running copytool
2379 copy2archive /bin/true $tdir/$tfile
2381 local f=$DIR/$tdir/true
2382 import_file $tdir/$tfile $f
2384 local fid=$(path2fid $f)
2386 # set no retry action mode
2392 # remove no try action mode
2396 [[ $st == 0 ]] || error "Failed to exec a released file"
2400 run_test 30a "Restore at exec (import case)"
2403 # restore at exec cannot work on agent node (because of Linux kernel
2404 # protection of executables)
2405 needclients 2 || return 0
2407 # test needs a running copytool
2411 local f=$DIR/$tdir/true
2412 local fid=$(copy_file /bin/true $f)
2414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2415 wait_request_state $fid ARCHIVE SUCCEED
2418 # set no retry action mode
2424 # remove no try action mode
2428 [[ $st == 0 ]] || error "Failed to exec a released file"
2432 run_test 30b "Restore at exec (release case)"
2435 needclients 2 || return 0
2437 # test needs a running copytool
2441 local f=$DIR/$tdir/SLEEP
2442 local slp_sum1=$(md5sum /bin/sleep)
2443 local fid=$(copy_file /bin/sleep $f)
2445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2446 wait_request_state $fid ARCHIVE SUCCEED
2448 check_hsm_flags $f "0x0000000d"
2449 # set no retry action mode
2451 do_node $CLIENT2 "$f 10" &
2455 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2457 [[ $? == 0 ]] || error "Execution failed during run"
2459 if [[ $? != 0 ]]; then
2460 local slp_sum2=$(md5sum /bin/sleep)
2461 # in case sleep file is modified during the test
2462 [[ $slp_sum1 == $slp_sum2 ]] &&
2463 error "Binary overwritten during exec"
2467 # remove no try action mode
2469 check_hsm_flags $f "0x00000009"
2473 run_test 30c "Update during exec of released file must fail"
2475 restore_and_check_size() {
2478 local s=$(stat -c "%s" $f)
2480 local st=$(get_hsm_flags $f)
2484 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2486 n=$(stat -c "%s" $f)
2487 # we echo in both cases to show stat is not
2489 if [[ $n != $s ]]; then
2490 echo "size seen is $n != $s"
2493 echo "size seen is right: $n == $s"
2495 st=$(get_hsm_flags $f)
2499 if [[ $cpt -lt 10 ]]; then
2502 echo " restore is too long"
2503 wait_request_state $fid RESTORE SUCCEED
2509 # test needs a running copytool
2514 make_archive $tdir/$tfile
2515 local f=$DIR/$tdir/$tfile
2516 import_file $tdir/$tfile $f
2517 local fid=$($LFS path2fid $f)
2518 HSM_ARCHIVE_PURGE=false copytool_setup
2520 restore_and_check_size $f $fid
2523 [[ $err -eq 0 ]] || error "File size changed during restore"
2527 run_test 31a "Import a large file and check size during restore"
2531 # test needs a running copytool
2536 local f=$DIR/$tdir/$tfile
2538 fid=$(make_large_for_progress $f)
2539 [ $? != 0 ] && skip "not enough free space" && return
2541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2542 wait_request_state $fid ARCHIVE SUCCEED
2545 restore_and_check_size $f $fid
2548 [[ $err -eq 0 ]] || error "File size changed during restore"
2552 run_test 31b "Restore a large unaligned file and check size during restore"
2555 # test needs a running copytool
2560 local f=$DIR/$tdir/$tfile
2562 fid=$(make_large_for_progress_aligned $f)
2563 [ $? != 0 ] && skip "not enough free space" && return
2565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2566 wait_request_state $fid ARCHIVE SUCCEED
2569 restore_and_check_size $f $fid
2572 [[ $err -eq 0 ]] || error "File size changed during restore"
2576 run_test 31c "Restore a large aligned file and check size during restore"
2579 # test needs a running copytool
2584 local f=$DIR/$tdir/$tfile
2586 fid=$(make_large_for_progress $f)
2587 [ $? != 0 ] && skip "not enough free space" && return
2589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2590 wait_request_state $fid ARCHIVE SUCCEED
2593 # to be sure wait_all_done will not be mislead by previous tests
2596 wait_for_grace_delay
2597 # Also raise grace_delay significantly so the Canceled
2598 # Restore action will stay enough long avail.
2599 local old_grace=$(get_hsm_param grace_delay)
2600 set_hsm_param grace_delay 100
2602 md5sum $f >/dev/null &
2604 wait_request_state $fid RESTORE STARTED
2609 # Check restore trigger process was killed
2610 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2614 # instead of waiting+checking both Restore and Cancel ops
2615 # sequentially, wait for both to be finished and then check
2617 wait_all_done 100 $fid
2618 local rstate=$(get_request_state $fid RESTORE)
2619 local cstate=$(get_request_state $fid CANCEL)
2621 # restore orig grace_delay.
2622 set_hsm_param grace_delay $old_grace
2624 if [[ "$rstate" == "CANCELED" ]] ; then
2625 [[ "$cstate" == "SUCCEED" ]] ||
2626 error "Restore state is CANCELED and Cancel state " \
2627 "is not SUCCEED but $cstate"
2628 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2629 elif [[ "$rstate" == "SUCCEED" ]] ; then
2630 [[ "$cstate" == "FAILED" ]] ||
2631 error "Restore state is SUCCEED and Cancel state " \
2632 "is not FAILED but $cstate"
2633 echo "Restore state is SUCCEED, Cancel state is FAILED"
2635 error "Restore state is $rstate and Cancel state is $cstate"
2639 error "Cannot kill process waiting for restore ($killed)"
2643 run_test 33 "Kill a restore waiting process"
2646 # test needs a running copytool
2651 local f=$DIR/$tdir/$tfile
2653 fid=$(make_large_for_progress $f)
2654 [ $? != 0 ] && skip "not enough free space" && return
2656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2657 wait_request_state $fid ARCHIVE SUCCEED
2660 md5sum $f >/dev/null &
2662 wait_request_state $fid RESTORE STARTED
2664 rm $f || error "rm $f failed"
2665 # rm must not block during restore
2666 wait_request_state $fid RESTORE STARTED
2668 wait_request_state $fid RESTORE SUCCEED
2669 # check md5sum pgm finished
2670 local there=$(ps -o pid,comm hp $pid >/dev/null)
2671 [[ -z $there ]] || error "Restore initiator does not exit"
2673 local rc=$(wait $pid)
2674 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2678 run_test 34 "Remove file during restore"
2681 # test needs a running copytool
2686 local f=$DIR/$tdir/$tfile
2687 local f1=$DIR/$tdir/$tfile-1
2689 fid=$(make_large_for_progress $f)
2690 [ $? != 0 ] && skip "not enough free space" && return
2692 local fid1=$(copy_file /etc/passwd $f1)
2693 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2694 wait_request_state $fid ARCHIVE SUCCEED
2697 md5sum $f >/dev/null &
2699 wait_request_state $fid RESTORE STARTED
2701 mv $f1 $f || error "mv $f1 $f failed"
2702 # mv must not block during restore
2703 wait_request_state $fid RESTORE STARTED
2705 wait_request_state $fid RESTORE SUCCEED
2706 # check md5sum pgm finished
2707 local there=$(ps -o pid,comm hp $pid >/dev/null)
2708 [[ -z $there ]] || error "Restore initiator does not exit"
2710 local rc=$(wait $pid)
2711 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2714 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2718 run_test 35 "Overwrite file during restore"
2721 # test needs a running copytool
2726 local f=$DIR/$tdir/$tfile
2728 fid=$(make_large_for_progress $f)
2729 [ $? != 0 ] && skip "not enough free space" && return
2731 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2732 wait_request_state $fid ARCHIVE SUCCEED
2735 md5sum $f >/dev/null &
2737 wait_request_state $fid RESTORE STARTED
2740 # rm must not block during restore
2741 wait_request_state $fid RESTORE STARTED
2743 wait_request_state $fid RESTORE SUCCEED
2744 # check md5sum pgm finished
2745 local there=$(ps -o pid,comm hp $pid >/dev/null)
2747 error "Restore initiator does not exit"
2749 local rc=$(wait $pid)
2751 error "Restore initiator failed with $rc"
2755 run_test 36 "Move file during restore"
2758 # LU-5683: check that an archived dirty file can be rearchived.
2760 copytool_setup $SINGLEAGT $MOUNT2
2763 local f=$DIR/$tdir/$tfile
2766 fid=$(make_small $f) || error "cannot create small file"
2768 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2769 wait_request_state $fid ARCHIVE SUCCEED
2770 $LFS hsm_release $f || error "cannot release $f"
2773 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2776 wait_request_state $fid ARCHIVE SUCCEED
2780 run_test 37 "re-archive a dirty file"
2787 for n in $(seq 1 $count); do
2788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2790 echo "$count archive requests submitted"
2794 local stream_count=4
2795 local file_count=100
2797 local f=$DIR/$tdir/$tfile
2802 for i in $(seq 1 $file_count); do
2803 for p in $(seq 1 $stream_count); do
2804 fid=$(copy_file /etc/hosts $f.$p.$i)
2807 # force copytool to use a local/temp archive dir to ensure best
2808 # performance vs remote/NFS mounts used in auto-tests
2809 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2812 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2814 # to be sure wait_all_done will not be mislead by previous tests
2816 wait_for_grace_delay
2818 # start archive streams in background (archive files in parallel)
2819 for p in $(seq 1 $stream_count); do
2820 multi_archive $f.$p $file_count &
2823 echo -n "Wait for all requests being enqueued..."
2829 run_test 40 "Parallel archive requests"
2832 # test needs a running copytool
2836 local f=$DIR/$tdir/$tfile
2837 local fid=$(copy_file /etc/motd $f 1)
2839 $LFS hsm_archive $f || error "could not archive file"
2840 wait_request_state $fid ARCHIVE SUCCEED
2841 check_hsm_flags $f "0x00000009"
2843 multiop_bg_pause $f O_c || error "multiop failed"
2847 client_up || client_up || true
2849 kill -USR1 $MULTIPID
2850 wait $MULTIPID || error "multiop close failed"
2852 check_hsm_flags $f "0x0000000b"
2856 run_test 52 "Opened for write file on an evicted client should be set dirty"
2859 # test needs a running copytool
2863 local f=$DIR/$tdir/$tfile
2864 local fid=$(copy_file /etc/motd $f 1)
2866 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2867 error "could not archive file"
2868 wait_request_state $fid ARCHIVE SUCCEED
2869 check_hsm_flags $f "0x00000009"
2871 multiop_bg_pause $f o_c || error "multiop failed"
2875 client_up || client_up || true
2877 kill -USR1 $MULTIPID
2878 wait $MULTIPID || error "multiop close failed"
2880 check_hsm_flags $f "0x00000009"
2884 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2887 # test needs a running copytool
2891 local f=$DIR/$tdir/$tfile
2892 local fid=$(make_large_for_progress $f)
2894 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2895 error "could not archive file"
2896 wait_request_state $fid ARCHIVE STARTED
2898 check_hsm_flags $f "0x00000001"
2900 # Avoid coordinator resending this request as soon it has failed.
2905 wait_request_state $fid ARCHIVE FAILED
2907 check_hsm_flags $f "0x00000003"
2912 run_test 54 "Write during an archive cancels it"
2915 # test needs a running copytool
2919 local f=$DIR/$tdir/$tfile
2920 local fid=$(make_large_for_progress $f)
2922 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2923 error "could not archive file"
2924 wait_request_state $fid ARCHIVE STARTED
2926 check_hsm_flags $f "0x00000001"
2928 # Avoid coordinator resending this request as soon it has failed.
2931 $TRUNCATE $f 1024 || error "truncate failed"
2933 wait_request_state $fid ARCHIVE FAILED
2935 check_hsm_flags $f "0x00000003"
2940 run_test 55 "Truncate during an archive cancels it"
2943 # test needs a running copytool
2947 local f=$DIR/$tdir/$tfile
2949 fid=$(make_large_for_progress $f)
2950 [ $? != 0 ] && skip "not enough free space" && return
2952 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2953 error "could not archive file"
2954 wait_request_state $fid ARCHIVE STARTED
2956 check_hsm_flags $f "0x00000001"
2958 # Change metadata and sync to be sure we are not changing only
2963 wait_request_state $fid ARCHIVE SUCCEED
2965 check_hsm_flags $f "0x00000009"
2969 run_test 56 "Setattr during an archive is ok"
2972 # Need one client for I/O, one for request
2973 needclients 2 || return 0
2975 # test needs a running copytool
2979 local f=$DIR/$tdir/test_archive_remote
2980 # Create a file on a remote node
2981 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2982 "count=2 conv=fsync"
2985 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2986 error "hsm_archive failed"
2987 local fid=$(path2fid $f)
2988 wait_request_state $fid ARCHIVE SUCCEED
2990 # Release and implicit restore it
2991 do_node $CLIENT2 "$LFS hsm_release $f" ||
2992 error "hsm_release failed"
2993 do_node $CLIENT2 "md5sum $f" ||
2994 error "hsm_restore failed"
2996 wait_request_state $fid RESTORE SUCCEED
3000 run_test 57 "Archive a file with dirty cache on another node"
3002 truncate_released_file() {
3006 local sz=$(stat -c %s $src_file)
3007 local f=$DIR/$tdir/$tfile
3008 local fid=$(copy_file $1 $f)
3012 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3013 error "could not archive file"
3014 wait_request_state $fid ARCHIVE SUCCEED
3016 $LFS hsm_release $f || error "could not release file"
3018 $TRUNCATE $f $trunc_to || error "truncate failed"
3021 local sz1=$(stat -c %s $f)
3022 [[ $sz1 == $trunc_to ]] ||
3023 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3026 check_hsm_flags $f "0x0000000b"
3028 local state=$(get_request_state $fid RESTORE)
3029 [[ "$state" == "SUCCEED" ]] ||
3030 error "truncate $sz does not trig restore, state = $state"
3032 $TRUNCATE $ref $trunc_to
3033 cmp $ref $f || error "file data wrong after truncate"
3039 # test needs a running copytool
3044 local sz=$(stat -c %s /etc/passwd)
3046 echo "truncate up from $sz to $((sz*2))"
3047 truncate_released_file /etc/passwd $((sz*2))
3049 echo "truncate down from $sz to $((sz/2))"
3050 truncate_released_file /etc/passwd $((sz/2))
3052 echo "truncate to 0"
3053 truncate_released_file /etc/passwd 0
3057 run_test 58 "Truncate a released file will trigger restore"
3061 local server_version=$(lustre_version_code $SINGLEMDS)
3062 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3063 skip "Need MDS version at least 2.7.63" && return
3066 $MCREATE $DIR/$tfile || error "mcreate failed"
3067 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3068 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3069 fid=$(path2fid $DIR/$tfile)
3070 wait_request_state $fid ARCHIVE SUCCEED
3071 $LFS hsm_release $DIR/$tfile || error "release failed"
3074 run_test 59 "Release stripeless file with non-zero size"
3077 # This test validates the fix for LU-4512. Ensure that the -u
3078 # option changes the progress reporting interval from the
3079 # default (30 seconds) to the user-specified interval.
3081 local progress_timeout=$((interval * 4))
3083 # test needs a new running copytool
3085 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3088 local f=$DIR/$tdir/$tfile
3090 fid=$(make_large_for_progress $f)
3091 [ $? != 0 ] && skip "not enough free space" && return
3094 local mdt=${MDT_PREFIX}${mdtidx}
3095 local mds=mds$((mdtidx + 1))
3097 # Wait for copytool to register
3098 wait_update_facet $mds \
3099 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3100 uuid 100 || error "coyptool failed to register with $mdt"
3102 local start_at=$(date +%s)
3103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3104 error "could not archive file"
3106 local agent=$(facet_active_host $SINGLEAGT)
3107 local prefix=$TESTLOG_PREFIX
3108 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3109 local copytool_log=$prefix.copytool_log.$agent.log
3112 wait_update $agent \
3113 "grep -o start.copy $copytool_log" "start copy" 100 ||
3114 error "copytool failed to start"
3116 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3117 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3123 echo -n "Expecting a progress update within $progress_timeout seconds... "
3125 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3126 if [ $RESULT -gt 0 ]; then
3127 echo "$RESULT bytes copied in $WAIT seconds."
3129 elif [ $WAIT -ge $progress_timeout ]; then
3130 error "Timed out waiting for progress update!"
3133 WAIT=$((WAIT + sleep))
3137 local finish_at=$(date +%s)
3138 local elapsed=$((finish_at - start_at))
3140 # Ensure that the progress update occurred within the expected window.
3141 if [ $elapsed -lt $interval ]; then
3142 error "Expected progress update after at least $interval seconds"
3148 run_test 60 "Changing progress update interval from default"
3151 # test needs a new running copytool
3153 copytool_monitor_setup
3154 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3156 # Just start and stop the copytool to generate events.
3159 # Wait for the copytool to register.
3160 wait_update --verbose $(facet_active_host mds1) \
3161 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3163 error "copytool failed to register with MDT0000"
3167 local REGISTER_EVENT
3168 local UNREGISTER_EVENT
3169 while read event; do
3170 local parsed=$(parse_json_event "$event")
3171 if [ -z "$parsed" ]; then
3172 error "Copytool sent malformed event: $event"
3176 if [ $event_type == "REGISTER" ]; then
3177 REGISTER_EVENT=$event
3178 elif [ $event_type == "UNREGISTER" ]; then
3179 UNREGISTER_EVENT=$event
3181 done < <(echo $"$(get_copytool_event_log)")
3183 if [ -z "$REGISTER_EVENT" ]; then
3184 error "Copytool failed to send register event to FIFO"
3187 if [ -z "$UNREGISTER_EVENT" ]; then
3188 error "Copytool failed to send unregister event to FIFO"
3191 copytool_monitor_cleanup
3192 echo "Register/Unregister events look OK."
3194 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3197 # Bump progress interval for livelier events.
3200 # test needs a new running copytool
3202 copytool_monitor_setup
3203 HSMTOOL_UPDATE_INTERVAL=$interval \
3204 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3207 local f=$DIR/$tdir/$tfile
3209 fid=$(make_large_for_progress $f)
3210 [ $? != 0 ] && skip "not enough free space" && return
3212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3213 error "could not archive file"
3214 wait_request_state $fid ARCHIVE SUCCEED
3216 local expected_fields="event_time data_fid source_fid"
3217 expected_fields+=" total_bytes current_bytes"
3221 while read event; do
3222 # Make sure we're not getting anything from previous events.
3223 for field in $expected_fields; do
3227 local parsed=$(parse_json_event "$event")
3228 if [ -z "$parsed" ]; then
3229 error "Copytool sent malformed event: $event"
3233 if [ $event_type == "ARCHIVE_START" ]; then
3236 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3239 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3243 # Do some simple checking of the progress update events.
3244 for expected_field in $expected_fields; do
3245 if [ -z ${!expected_field+x} ]; then
3246 error "Missing $expected_field field in event"
3250 if [ $total_bytes -eq 0 ]; then
3251 error "Expected total_bytes to be > 0"
3254 # These should be identical throughout an archive
3256 if [ $source_fid != $data_fid ]; then
3257 error "Expected source_fid to equal data_fid"
3259 done < <(echo $"$(get_copytool_event_log)")
3261 if [ -z "$START_EVENT" ]; then
3262 error "Copytool failed to send archive start event to FIFO"
3265 if [ -z "$FINISH_EVENT" ]; then
3266 error "Copytool failed to send archive finish event to FIFO"
3269 echo "Archive events look OK."
3273 copytool_monitor_cleanup
3275 run_test 71 "Copytool logs JSON archive events to FIFO"
3278 # Bump progress interval for livelier events.
3281 # test needs a new running copytool
3283 copytool_monitor_setup
3284 HSMTOOL_UPDATE_INTERVAL=$interval \
3285 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3286 local test_file=$HSMTOOL_MONITOR_DIR/file
3288 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3290 do_facet $SINGLEAGT "$cmd" ||
3291 error "cannot create $test_file on $SINGLEAGT"
3292 copy2archive $test_file $tdir/$tfile
3295 local f=$DIR/$tdir/$tfile
3296 import_file $tdir/$tfile $f
3297 f=$DIR2/$tdir/$tfile
3298 echo "Verifying released state: "
3299 check_hsm_flags $f "0x0000000d"
3301 local fid=$(path2fid $f)
3303 wait_request_state $fid RESTORE SUCCEED
3305 local expected_fields="event_time data_fid source_fid"
3306 expected_fields+=" total_bytes current_bytes"
3310 while read event; do
3311 # Make sure we're not getting anything from previous events.
3312 for field in $expected_fields; do
3316 local parsed=$(parse_json_event "$event")
3317 if [ -z "$parsed" ]; then
3318 error "Copytool sent malformed event: $event"
3322 if [ $event_type == "RESTORE_START" ]; then
3324 if [ $source_fid != $data_fid ]; then
3325 error "source_fid should == data_fid at start"
3328 elif [ $event_type == "RESTORE_FINISH" ]; then
3330 if [ $source_fid != $data_fid ]; then
3331 error "source_fid should == data_fid at finish"
3334 elif [ $event_type != "RESTORE_RUNNING" ]; then
3338 # Do some simple checking of the progress update events.
3339 for expected_field in $expected_fields; do
3340 if [ -z ${!expected_field+x} ]; then
3341 error "Missing $expected_field field in event"
3345 if [ $total_bytes -eq 0 ]; then
3346 error "Expected total_bytes to be > 0"
3349 # When a restore starts out, the data fid is the same as the
3350 # source fid. After the restore has gotten going, we learn
3351 # the new data fid. Once the restore has finished, the source
3352 # fid is set to the new data fid.
3354 # We test this because some monitoring software may depend on
3355 # this behavior. If it changes, then the consumers of these
3356 # events may need to be modified.
3357 if [ $source_fid == $data_fid ]; then
3358 error "source_fid should != data_fid during restore"
3360 done < <(echo $"$(get_copytool_event_log)")
3362 if [ -z "$START_EVENT" ]; then
3363 error "Copytool failed to send restore start event to FIFO"
3366 if [ -z "$FINISH_EVENT" ]; then
3367 error "Copytool failed to send restore finish event to FIFO"
3370 echo "Restore events look OK."
3374 copytool_monitor_cleanup
3378 run_test 72 "Copytool logs JSON restore events to FIFO"
3381 file_count=51 # Max number of files constrained by LNET message size
3382 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3383 local f=$DIR/$tdir/$tfile
3384 local FILELIST=/tmp/filelist.txt
3388 for i in $(seq 1 $file_count); do
3389 fid=$(copy_file /etc/hosts $f.$i)
3390 echo $f.$i >> $FILELIST
3392 # force copytool to use a local/temp archive dir to ensure best
3393 # performance vs remote/NFS mounts used in auto-tests
3394 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3397 local dai=$(get_hsm_param default_archive_id)
3398 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3400 # to be sure wait_all_done will not be mislead by previous tests
3402 wait_for_grace_delay
3403 $LFS hsm_archive --filelist $FILELIST ||
3404 error "cannot archive a file list"
3406 $LFS hsm_release --filelist $FILELIST ||
3407 error "cannot release a file list"
3408 $LFS hsm_restore --filelist $FILELIST ||
3409 error "cannot restore a file list"
3413 run_test 90 "Archive/restore a file list"
3415 double_verify_reset_hsm_param() {
3417 echo "Testing $HSM_PARAM.$p"
3418 local val=$(get_hsm_param $p)
3420 local val2=$(($val * 2))
3421 set_hsm_param $p $val2
3422 val=$(get_hsm_param $p)
3423 [[ $val == $val2 ]] ||
3424 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3425 echo "Set $p to 0 must failed"
3429 set_hsm_param $p $save
3431 if [[ $rc == 0 ]]; then
3432 error "we must not be able to set $HSM_PARAM.$p to 0"
3437 double_verify_reset_hsm_param loop_period
3438 double_verify_reset_hsm_param grace_delay
3439 double_verify_reset_hsm_param active_request_timeout
3440 double_verify_reset_hsm_param max_requests
3441 double_verify_reset_hsm_param default_archive_id
3443 run_test 100 "Set coordinator /proc tunables"
3450 run_test 102 "Verify coordinator control"
3453 # test needs a running copytool
3460 for i in $(seq 1 20); do
3461 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3467 echo "Current requests"
3468 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3469 $HSM_PARAM.actions |\
3470 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3472 [[ -z "$res" ]] || error "Some request have not been canceled"
3476 run_test 103 "Purge all requests"
3481 # test needs a running copytool
3485 local f=$DIR/$tdir/$tfile
3487 fid=$(make_large_for_progress $f)
3488 [ $? != 0 ] && skip "not enough free space" && return
3490 # if cdt is on, it can serve too quickly the request
3492 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3493 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3494 $HSM_PARAM.actions |\
3495 grep $fid | cut -f16 -d=")
3498 [[ "$data1" == "$DATAHEX" ]] ||
3499 error "Data field in records is ($data1) and not ($DATAHEX)"
3503 run_test 104 "Copy tool data field"
3510 for i in $(seq -w 1 10); do
3511 cp /etc/passwd $DIR/$tdir/$i
3512 $LFS hsm_archive $DIR/$tdir/$i
3514 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3515 $HSM_PARAM.actions |\
3516 grep WAITING | wc -l")
3519 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3520 $HSM_PARAM.actions |\
3521 grep WAITING | wc -l")
3524 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3525 error "Requests count after shutdown $reqcnt2 != "\
3526 "before shutdown $reqcnt1"
3528 run_test 105 "Restart of coordinator"
3530 get_agent_by_uuid_mdt() {
3533 local mds=mds$(($mdtidx + 1))
3534 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3538 check_agent_registered_by_mdt() {
3541 local mds=mds$(($mdtidx + 1))
3542 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3543 if [[ ! -z "$agent" ]]; then
3544 echo "found agent $agent on $mds"
3546 error "uuid $uuid not found in agent list on $mds"
3550 check_agent_unregistered_by_mdt() {
3553 local mds=mds$(($mdtidx + 1))
3554 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3555 if [[ -z "$agent" ]]; then
3556 echo "uuid not found in agent list on $mds"
3558 error "uuid found in agent list on $mds: $agent"
3562 check_agent_registered() {
3565 for mdsno in $(seq 1 $MDSCOUNT); do
3566 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3570 check_agent_unregistered() {
3573 for mdsno in $(seq 1 $MDSCOUNT); do
3574 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3579 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3581 # Lustre mount-point is mandatory and last parameter on
3582 # copytool cmd-line.
3583 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3584 grep -v pgrep | awk '{print $NF}')
3585 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3587 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3591 # test needs a running copytool
3594 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3596 check_agent_registered $uuid
3598 search_copytools || error "No copytool found"
3601 check_agent_unregistered $uuid
3604 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3605 check_agent_registered $uuid
3609 run_test 106 "Copytool register/unregister"
3612 # test needs a running copytool
3614 # create and archive file
3616 local f1=$DIR/$tdir/$tfile
3617 local fid=$(copy_file /etc/passwd $f1)
3618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3619 wait_request_state $fid ARCHIVE SUCCEED
3620 # shutdown and restart MDS
3622 # check the copytool still gets messages from MDT
3623 local f2=$DIR/$tdir/2
3624 local fid=$(copy_file /etc/passwd $f2)
3625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3626 # main check of this sanity: this request MUST succeed
3627 wait_request_state $fid ARCHIVE SUCCEED
3630 run_test 107 "Copytool re-register after MDS restart"
3632 policy_set_and_test()
3636 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3637 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3638 [[ "$policy" == "$target" ]] ||
3639 error "Wrong policy after '$change': '$policy' != '$target'"
3643 # to force default policy setting if error
3644 CDT_POLICY_HAD_CHANGED=true
3646 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3647 local default="NonBlockingRestore [NoRetryAction]"
3648 [[ "$policy" == "$default" ]] ||
3649 error "default policy has changed,"\
3650 " '$policy' != '$default' update the test"
3651 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3652 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3653 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3654 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3655 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3656 # useless bacause we know but safer for futur changes to use real value
3657 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3658 echo "Next set_param must failed"
3659 policy_set_and_test "wrong" "$policy"
3662 echo "Back to default policy"
3663 cdt_set_sanity_policy
3665 run_test 109 "Policy display/change"
3668 # test needs a running copytool
3673 copy2archive /etc/passwd $tdir/$tfile
3675 local f=$DIR/$tdir/$tfile
3676 import_file $tdir/$tfile $f
3677 local fid=$(path2fid $f)
3679 cdt_set_non_blocking_restore
3684 wait_request_state $fid RESTORE SUCCEED
3685 cdt_clear_non_blocking_restore
3689 error "md5sum returns $st != 1, "\
3690 "should also perror ENODATA (No data available)"
3694 run_test 110a "Non blocking restore policy (import case)"
3697 # test needs a running copytool
3701 local f=$DIR/$tdir/$tfile
3702 local fid=$(copy_file /etc/passwd $f)
3703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3704 wait_request_state $fid ARCHIVE SUCCEED
3707 cdt_set_non_blocking_restore
3712 wait_request_state $fid RESTORE SUCCEED
3713 cdt_clear_non_blocking_restore
3717 error "md5sum returns $st != 1, "\
3718 "should also perror ENODATA (No data available)"
3722 run_test 110b "Non blocking restore policy (release case)"
3725 # test needs a running copytool
3729 copy2archive /etc/passwd $tdir/$tfile
3731 local f=$DIR/$tdir/$tfile
3733 import_file $tdir/$tfile $f
3734 local fid=$(path2fid $f)
3738 copytool_remove_backend $fid
3741 wait_request_state $fid RESTORE FAILED
3748 [[ $st == 0 ]] || error "Restore does not failed"
3752 run_test 111a "No retry policy (import case), restore will error"\
3753 " (No such file or directory)"
3756 # test needs a running copytool
3760 local f=$DIR/$tdir/$tfile
3761 local fid=$(copy_file /etc/passwd $f)
3763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3764 wait_request_state $fid ARCHIVE SUCCEED
3767 copytool_remove_backend $fid
3770 wait_request_state $fid RESTORE FAILED
3777 [[ $st == 0 ]] || error "Restore does not failed"
3781 run_test 111b "No retry policy (release case), restore will error"\
3782 " (No such file or directory)"
3785 # test needs a running copytool
3789 local f=$DIR/$tdir/$tfile
3790 local fid=$(copy_file /etc/passwd $f)
3792 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3793 local l=$($LFS hsm_action $f)
3795 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3799 wait_request_state $fid ARCHIVE SUCCEED
3802 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3806 run_test 112 "State of recorded request"
3809 # test needs a running copytool
3813 local f=$DIR/$tdir/$tfile
3815 fid=$(make_large_for_cancel $f)
3816 [ $? != 0 ] && skip "not enough free space" && return
3818 # test with cdt on is made in test_221
3820 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3821 # wait archive to register at CDT
3822 wait_request_state $fid ARCHIVE WAITING
3825 wait_request_state $fid ARCHIVE CANCELED
3826 wait_request_state $fid CANCEL SUCCEED
3830 run_test 200 "Register/Cancel archive"
3833 # test needs a running copytool
3837 local f=$DIR/$tdir/$tfile
3838 make_archive $tdir/$tfile
3839 import_file $tdir/$tfile $f
3840 local fid=$(path2fid $f)
3842 # test with cdt on is made in test_222
3845 # wait restore to register at CDT
3846 wait_request_state $fid RESTORE WAITING
3849 wait_request_state $fid RESTORE CANCELED
3850 wait_request_state $fid CANCEL SUCCEED
3854 run_test 201 "Register/Cancel restore"
3857 # test needs a running copytool
3861 local f=$DIR/$tdir/$tfile
3863 fid=$(make_large_for_progress $f)
3864 [ $? != 0 ] && skip "not enough free space" && return
3866 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3867 wait_request_state $fid ARCHIVE SUCCEED
3871 # wait remove to register at CDT
3872 wait_request_state $fid REMOVE WAITING
3875 wait_request_state $fid REMOVE CANCELED
3879 run_test 202 "Register/Cancel remove"
3882 # test needs a running copytool
3887 local f=$DIR/$tdir/$tfile
3888 local fid=$(copy_file /etc/passwd $f)
3892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3893 wait_request_state $fid ARCHIVE SUCCEED
3895 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3899 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3903 run_test 220 "Changelog for archive"
3906 # test needs a running copytool
3911 local f=$DIR/$tdir/$tfile
3913 fid=$(make_large_for_cancel $f)
3914 [ $? != 0 ] && skip "not enough free space" && return
3918 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3919 wait_request_state $fid ARCHIVE STARTED
3921 wait_request_state $fid ARCHIVE CANCELED
3922 wait_request_state $fid CANCEL SUCCEED
3924 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3927 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3931 run_test 221 "Changelog for archive canceled"
3934 # test needs a running copytool
3938 copy2archive /etc/passwd $tdir/$tfile
3940 local f=$DIR/$tdir/$tfile
3941 import_file $tdir/$tfile $f
3942 local fid=$(path2fid $f)
3947 wait_request_state $fid RESTORE SUCCEED
3949 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3952 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3956 run_test 222a "Changelog for explicit restore"
3959 # test needs a running copytool
3963 local f=$DIR/$tdir/$tfile
3964 local fid=$(copy_file /etc/passwd $f)
3967 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3968 wait_request_state $fid ARCHIVE SUCCEED
3973 wait_request_state $fid RESTORE SUCCEED
3975 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3978 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3982 run_test 222b "Changelog for implicit restore"
3985 # test needs a running copytool
3990 local f=$DIR/$tdir/$tfile
3991 make_archive $tdir/$tfile
3995 import_file $tdir/$tfile $f
3996 local fid=$(path2fid $f)
3999 wait_request_state $fid RESTORE STARTED
4001 wait_request_state $fid RESTORE CANCELED
4002 wait_request_state $fid CANCEL SUCCEED
4004 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4007 [[ $flags == $target ]] ||
4008 error "Changelog flag is $flags not $target"
4012 run_test 223a "Changelog for restore canceled (import case)"
4015 # test needs a running copytool
4020 local f=$DIR/$tdir/$tfile
4022 fid=$(make_large_for_progress $f)
4023 [ $? != 0 ] && skip "not enough free space" && return
4026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4027 wait_request_state $fid ARCHIVE SUCCEED
4030 wait_request_state $fid RESTORE STARTED
4032 wait_request_state $fid RESTORE CANCELED
4033 wait_request_state $fid CANCEL SUCCEED
4035 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4038 [[ $flags == $target ]] ||
4039 error "Changelog flag is $flags not $target"
4043 run_test 223b "Changelog for restore canceled (release case)"
4046 # test needs a running copytool
4051 local f=$DIR/$tdir/$tfile
4052 local fid=$(copy_file /etc/passwd $f)
4055 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4056 wait_request_state $fid ARCHIVE SUCCEED
4059 wait_request_state $fid REMOVE SUCCEED
4061 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4064 [[ $flags == $target ]] ||
4065 error "Changelog flag is $flags not $target"
4069 run_test 224 "Changelog for remove"
4072 # test needs a running copytool
4075 # test is not usable because remove request is too fast
4076 # so it is always finished before cancel can be done ...
4077 echo "Test disabled"
4082 local f=$DIR/$tdir/$tfile
4084 fid=$(make_large_for_progress $f)
4085 [ $? != 0 ] && skip "not enough free space" && return
4088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4089 wait_request_state $fid ARCHIVE SUCCEED
4091 # if cdt is on, it can serve too quickly the request
4096 wait_request_state $fid REMOVE CANCELED
4097 wait_request_state $fid CANCEL SUCCEED
4099 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4100 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4101 tail -n 1 | awk '{print $5}')
4104 [[ $flags == $target ]] ||
4105 error "Changelog flag is $flags not $target"
4109 run_test 225 "Changelog for remove canceled"
4112 # test needs a running copytool
4117 local f1=$DIR/$tdir/$tfile-1
4118 local f2=$DIR/$tdir/$tfile-2
4119 local f3=$DIR/$tdir/$tfile-3
4120 local fid1=$(copy_file /etc/passwd $f1)
4121 local fid2=$(copy_file /etc/passwd $f2)
4122 copy_file /etc/passwd $f3
4125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4126 wait_request_state $fid1 ARCHIVE SUCCEED
4128 $LFS hsm_archive $f2
4129 wait_request_state $fid2 ARCHIVE SUCCEED
4131 rm $f1 || error "rm $f1 failed"
4133 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4136 [[ $flags == $target ]] ||
4137 error "Changelog flag is $flags not $target"
4139 mv $f3 $f2 || error "mv $f3 $f2 failed"
4141 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4144 [[ $flags == $target ]] ||
4145 error "Changelog flag is $flags not $target"
4149 run_test 226 "changelog for last rm/mv with exiting archive"
4151 check_flags_changes() {
4159 $LFS hsm_set --$hsm_flag $f ||
4160 error "Cannot set $hsm_flag on $f"
4161 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4162 local seen=${#flags[*]}
4164 [[ $seen == $cnt ]] ||
4165 error "set $hsm_flag: Changelog events $seen != $cnt"
4166 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4167 error "set $hsm_flag: Changelog flags are "\
4168 "${flags[$((cnt - 1))]} not $target"
4170 $LFS hsm_clear --$hsm_flag $f ||
4171 error "Cannot clear $hsm_flag on $f"
4172 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4175 [[ $cnt == $seen ]] ||
4176 error "clear $hsm_flag: Changelog events $seen != $cnt"
4178 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4179 error "clear $hsm_flag: Changelog flag is "\
4180 "${flags[$((cnt - 1))]} not $target"
4184 # test needs a running copytool
4191 for i in norelease noarchive exists archived
4193 local f=$DIR/$tdir/$tfile-$i
4194 local fid=$(copy_file /etc/passwd $f)
4195 check_flags_changes $f $fid $i 0 1
4198 f=$DIR/$tdir/$tfile---lost
4199 fid=$(copy_file /etc/passwd $f)
4200 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4201 wait_request_state $fid ARCHIVE SUCCEED
4202 check_flags_changes $f $fid lost 3 1
4206 run_test 227 "changelog when explicit setting of HSM flags"
4209 # test needs a running copytool
4212 local fid=$(make_small_sync $DIR/$tfile)
4213 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4214 wait_request_state $fid ARCHIVE SUCCEED
4216 $LFS hsm_release $DIR/$tfile
4217 check_hsm_flags $DIR/$tfile "0x0000000d"
4219 filefrag $DIR/$tfile | grep " 1 extent found" ||
4220 error "filefrag on released file must return only one extent"
4222 # only newer versions of cp detect sparse files by stat/FIEMAP
4224 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4225 error "copying $DIR/$tfile"
4226 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4228 $LFS hsm_release $DIR/$tfile
4229 check_hsm_flags $DIR/$tfile "0x0000000d"
4231 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4233 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4235 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4236 error "comparing untarred $DIR/$tfile"
4238 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4239 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4242 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4245 # test needs a running copytool
4249 local maxrequest=$(get_hsm_param max_requests)
4250 local rqcnt=$(($maxrequest * 3))
4254 for i in $(seq -w 1 $rqcnt); do
4256 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4258 # we do it in 2 steps, so all requests arrive at the same time
4259 for i in $(seq -w 1 $rqcnt); do
4260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4265 while [[ $cnt != 0 || $wt != 0 ]]; do
4267 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4268 $HSM_PARAM.actions |\
4269 grep STARTED | grep -v CANCEL | wc -l")
4270 [[ $cnt -le $maxrequest ]] ||
4271 error "$cnt > $maxrequest too many started requests"
4272 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4273 $HSM_PARAM.actions |\
4274 grep WAITING | wc -l")
4275 echo "max=$maxrequest started=$cnt waiting=$wt"
4280 run_test 250 "Coordinator max request"
4283 # test needs a running copytool
4287 local f=$DIR/$tdir/$tfile
4289 fid=$(make_large_for_cancel $f)
4290 [ $? != 0 ] && skip "not enough free space" && return
4293 # to have a short test
4294 local old_to=$(get_hsm_param active_request_timeout)
4295 set_hsm_param active_request_timeout 4
4296 # to be sure the cdt will wake up frequently so
4297 # it will be able to cancel the "old" request
4298 local old_loop=$(get_hsm_param loop_period)
4299 set_hsm_param loop_period 2
4302 # clear locks to avoid extra delay caused by flush/cancel
4303 # and thus prevent early copytool death to timeout.
4304 cancel_lru_locks osc
4306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4307 wait_request_state $fid ARCHIVE STARTED
4309 wait_request_state $fid ARCHIVE CANCELED
4311 set_hsm_param active_request_timeout $old_to
4312 set_hsm_param loop_period $old_loop
4316 run_test 251 "Coordinator request timeout"
4319 # the only way to test ondisk conf is to restart MDS ...
4320 echo "Stop coordinator and remove coordinator state at mount"
4323 # clean on disk conf set by default
4324 cdt_clear_mount_state
4325 cdt_check_state stopped
4327 # check cdt still off after umount/remount
4329 cdt_check_state stopped
4331 echo "Set coordinator start at mount, and start coordinator"
4332 cdt_set_mount_state enabled
4335 cdt_check_state enabled
4337 # check cdt still on after umount/remount
4339 cdt_check_state enabled
4341 # we are back to original state (cdt started at mount)
4343 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4346 local ai=$(get_hsm_param default_archive_id)
4347 local new=$((ai + 1))
4349 set_hsm_param default_archive_id $new -P
4351 local res=$(get_hsm_param default_archive_id)
4354 set_hsm_param default_archive_id "" "-P -d"
4356 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4358 run_test 301 "HSM tunnable are persistent"
4361 local ai=$(get_hsm_param default_archive_id)
4362 local new=$((ai + 1))
4367 set_hsm_param default_archive_id $new -P
4370 for mdtno in $(seq 1 $MDSCOUNT); do
4375 cdt_check_state enabled
4377 local res=$(get_hsm_param default_archive_id)
4380 set_hsm_param default_archive_id "" "-P -d"
4382 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4384 run_test 302 "HSM tunnable are persistent when CDT is off"
4387 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4393 local dir_mdt0=$DIR/$tdir/mdt0
4394 local dir_mdt1=$DIR/$tdir/mdt1
4396 # create 1 dir per MDT
4397 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4398 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4400 # create 1 file in each MDT
4401 local fid1=$(make_small $dir_mdt0/$tfile)
4402 local fid2=$(make_small $dir_mdt1/$tfile)
4404 # check that hsm request on mdt0 is sent to the right MDS
4405 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4406 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4407 echo "archive successful on mdt0"
4409 # check that hsm request on mdt1 is sent to the right MDS
4410 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4411 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4412 echo "archive successful on mdt1"
4415 # clean test files and directories
4416 rm -rf $dir_mdt0 $dir_mdt1
4418 run_test 400 "Single request is sent to the right MDT"
4421 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4427 local dir_mdt0=$DIR/$tdir/mdt0
4428 local dir_mdt1=$DIR/$tdir/mdt1
4430 # create 1 dir per MDT
4431 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4432 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4434 # create 1 file in each MDT
4435 local fid1=$(make_small $dir_mdt0/$tfile)
4436 local fid2=$(make_small $dir_mdt1/$tfile)
4438 # check that compound requests are shunt to the rights MDTs
4439 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4440 error "lfs hsm_archive"
4441 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4442 echo "archive successful on mdt0"
4443 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4444 echo "archive successful on mdt1"
4447 # clean test files and directories
4448 rm -rf $dir_mdt0 $dir_mdt1
4450 run_test 401 "Compound requests split and sent to their respective MDTs"
4452 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4457 local node=$(facet_active_host $facet)
4459 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4460 awk '{print $4}'); do
4461 echo "$3 $mdc on $node"
4462 do_facet $facet "$LCTL --device $mdc $state" || return 1
4467 # make sure there is no running copytool
4470 # deactivate all mdc on agent1
4471 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4473 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4475 check_agent_unregistered "uuid" # match any agent
4477 # no expected running copytool
4478 search_copytools $agent && error "Copytool start should have failed"
4481 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4483 run_test 402 "Copytool start fails if all MDTs are inactive"
4486 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4488 # make sure there is no running copytool
4491 local agent=$(facet_active_host $SINGLEAGT)
4493 # deactivate all mdc for MDT0001
4494 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4497 local uuid=$(get_agent_uuid $agent)
4498 # check the agent is registered on MDT0000, and not on MDT0001
4499 check_agent_registered_by_mdt $uuid 0
4500 check_agent_unregistered_by_mdt $uuid 1
4502 # check running copytool process
4503 search_copytools $agent || error "No running copytools on $agent"
4505 # reactivate all mdc for MDT0001
4506 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4508 # make sure the copytool is now registered to all MDTs
4509 check_agent_registered $uuid
4513 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4516 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4520 # create files on both MDT0000 and MDT0001
4523 local dir_mdt0=$DIR/$tdir/mdt0
4524 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4526 # create 1 file on mdt0
4527 local fid1=$(make_small $dir_mdt0/$tfile)
4529 # deactivate all mdc for MDT0001
4530 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4532 # send an HSM request for files in MDT0000
4533 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4535 # check for completion of files in MDT0000
4536 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4537 echo "archive successful on mdt0"
4539 # reactivate all mdc for MDT0001
4540 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4543 # clean test files and directories
4546 run_test 404 "Inactive MDT does not block requests for active MDTs"
4549 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4555 local striped_dir=$DIR/$tdir/striped_dir
4557 # create striped dir on all of MDTs
4558 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4560 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4561 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4562 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4563 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4565 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4566 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4567 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4568 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4570 # check that compound requests are shunt to the rights MDTs
4571 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4572 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4573 error "lfs hsm_archive"
4575 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4576 echo "archive successful on $fid1"
4577 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4578 echo "archive successful on $fid2"
4579 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4580 echo "archive successful on $fid3"
4581 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4582 echo "archive successful on $fid4"
4584 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4585 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4586 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4587 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4589 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4590 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4591 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4592 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4596 run_test 405 "archive and release under striped directory"
4600 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4601 skip "HSM migrate is not supported" && return
4603 # Stop the existing copytool
4606 test_mkdir -p $DIR/$tdir
4607 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4609 run_test 500 "various LLAPI HSM tests"
4614 check_and_cleanup_lustre