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 facet=$SINGLEAGT
276 local agents=${1:-$(facet_active_host $facet)}
281 local hsm_root=$(copytool_device $facet)
282 local end_wait=$(( SECONDS + TIMEOUT ))
284 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
286 while (( SECONDS < end_wait )); do
288 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
289 if [ $? -ne 0 ]; then
290 echo "Copytool is stopped on $agents"
293 echo "Copytool still running on $agents"
295 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
296 error "Copytool failed to stop in ${TIMEOUT}s ..."
298 echo "Copytool has stopped in " \
299 "$((TIMEOUT - (end_wait - SECONDS)))s."
302 # clean all CDTs orphans requests from previous tests
303 # that would otherwise need to timeout to clear.
304 for mdtno in $(seq 1 $MDSCOUNT); do
306 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
307 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
309 # skip already stop[ed,ing] CDTs
310 echo $oldstate | grep stop && continue
312 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
313 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
315 error "mds${mdtno} cdt state is not stopped"
316 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
317 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
319 error "mds${mdtno} cdt state is not $oldstate"
321 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
322 do_facet $facet "rm -rf $hsm_root/*"
327 local agents=${1:-$(facet_active_host $SINGLEAGT)}
329 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
330 echo "Copytool is suspended on $agents"
333 copytool_remove_backend() {
335 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
336 echo "Remove from backend: $fid = $be"
337 do_facet $SINGLEAGT rm -f $be
341 do_facet $SINGLEAGT \
342 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
343 --import $1 $2 $MOUNT" ||
344 error "import of $1 to $2 failed"
348 local file=$HSM_ARCHIVE/$1
349 do_facet $SINGLEAGT mkdir -p $(dirname $file)
350 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
351 file_creation_failure dd $file $?
355 local file=$HSM_ARCHIVE/$2
356 do_facet $SINGLEAGT mkdir -p $(dirname $file)
357 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
366 if [[ "$value" != "" ]]; then
369 for mdtno in $(seq 1 $MDSCOUNT); do
370 local idx=$(($mdtno - 1))
371 local facet=mds${mdtno}
372 # if $arg include -P option, run 1 set_param per MDT on the MGS
373 # else, run set_param on each MDT
374 [[ $arg = *"-P"* ]] && facet=mgs
375 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
376 [[ $? != 0 ]] && rc=1
386 for mdtno in $(seq 1 $MDSCOUNT); do
387 local idx=$(($mdtno - 1))
388 wait_result mds${mdtno} \
389 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
391 error "$key state is not '$target' on mds${mdtno}"
398 for mdtno in $(seq 1 $MDSCOUNT); do
399 local idx=$(($mdtno - 1))
400 local cl_user=$(do_facet mds${mdtno} $LCTL \
401 --device ${MDT[$idx]} \
402 changelog_register -n)
404 do_facet mds${mdtno} lctl set_param \
405 mdd.${MDT[$idx]}.changelog_mask="+hsm"
406 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
410 changelog_cleanup() {
412 for mdtno in $(seq 1 $MDSCOUNT); do
413 local idx=$(($mdtno - 1))
414 [[ -z ${CL_USERS[$idx]} ]] && continue
415 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
416 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
417 changelog_deregister ${CL_USERS[$idx]}
422 changelog_get_flags() {
427 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
432 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
440 mdts_set_param "$opt -n" "hsm.$param" "$value"
447 mdts_set_param "" hsm_control "$cmd"
448 mdts_check_param hsm_control "$target" 10
451 cdt_set_sanity_policy() {
452 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
455 mdts_set_param "" hsm.policy "+NRA"
456 mdts_set_param "" hsm.policy "-NBR"
457 CDT_POLICY_HAD_CHANGED=
462 mdts_set_param "" hsm.policy "+NRA"
463 CDT_POLICY_HAD_CHANGED=true
466 cdt_clear_no_retry() {
467 mdts_set_param "" hsm.policy "-NRA"
468 CDT_POLICY_HAD_CHANGED=true
471 cdt_set_non_blocking_restore() {
472 mdts_set_param "" hsm.policy "+NBR"
473 CDT_POLICY_HAD_CHANGED=true
476 cdt_clear_non_blocking_restore() {
477 mdts_set_param "" hsm.policy "-NBR"
478 CDT_POLICY_HAD_CHANGED=true
481 cdt_clear_mount_state() {
482 mdts_set_param "-P -d" hsm_control ""
485 cdt_set_mount_state() {
486 mdts_set_param "-P" hsm_control "$1"
487 # set_param -P is asynchronous operation and could race with set_param.
488 # In such case configs could be retrieved and applied at mgc after
489 # set_param -P completion. Sleep here to avoid race with set_param.
490 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
491 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
492 # and 10 seconds to retrieve config from server.
497 mdts_check_param hsm_control "$1" 20
501 set_test_state disabled disabled
505 set_test_state enabled enabled
509 set_test_state shutdown stopped
513 set_test_state purge enabled
519 cdt_set_sanity_policy
523 local client_count=$1
524 if [[ $CLIENTCOUNT -lt $client_count ]]; then
525 skip "Need $client_count or more clients, have $CLIENTCOUNT"
532 $LFS path2fid $1 | tr -d '[]'
533 return ${PIPESTATUS[0]}
541 if [[ $u == "user" ]]; then
542 st=$($RUNAS $LFS hsm_state $f)
545 st=$($LFS hsm_state $f)
548 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
550 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
554 get_hsm_archive_id() {
557 st=$($LFS hsm_state $f)
558 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
560 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
569 local st=$(get_hsm_flags $f)
570 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
573 check_hsm_flags_user() {
577 local st=$(get_hsm_flags $f user)
578 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
581 file_creation_failure() {
586 df $MOUNT $MOUNT2 >&2
587 error "cannot create $f with $cmd, status=$err"
599 if [[ "$3" != 1 ]]; then
603 cp $1 $f || file_creation_failure cp $f $?
605 path2fid $f || error "cannot get fid on $f"
609 local file2=${1/$DIR/$DIR2}
610 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
611 file_creation_failure dd $file2 $?
613 path2fid $1 || error "cannot get fid on $1"
617 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
618 file_creation_failure dd $1 $?
619 path2fid $1 || error "cannot get fid on $1"
622 cleanup_large_files() {
623 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
625 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
628 check_enough_free_space() {
631 local need=$((nb * unit /1024))
632 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
633 (( $need >= $free )) && return 1
637 make_large_for_striping() {
638 local file2=${1/$DIR/$DIR2}
639 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
643 check_enough_free_space 5 $sz
644 [ $? != 0 ] && return $?
646 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
647 file_creation_failure dd $file2 $?
649 path2fid $1 || error "cannot get fid on $1"
652 make_large_for_progress() {
653 local file2=${1/$DIR/$DIR2}
657 check_enough_free_space 39 1000000
658 [ $? != 0 ] && return $?
660 # big file is large enough, so copy time is > 30s
661 # so copytool make 1 progress
662 # size is not a multiple of 1M to avoid stripe
664 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
665 file_creation_failure dd $file2 $?
667 path2fid $1 || error "cannot get fid on $1"
670 make_large_for_progress_aligned() {
671 local file2=${1/$DIR/$DIR2}
675 check_enough_free_space 33 1048576
676 [ $? != 0 ] && return $?
678 # big file is large enough, so copy time is > 30s
679 # so copytool make 1 progress
680 # size is a multiple of 1M to have stripe
682 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
683 file_creation_failure dd $file2 $?
684 path2fid $1 || error "cannot get fid on $1"
687 make_large_for_cancel() {
688 local file2=${1/$DIR/$DIR2}
692 check_enough_free_space 103 1048576
693 [ $? != 0 ] && return $?
695 # Copy timeout is 100s. 105MB => 105s
696 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
697 file_creation_failure dd $file2 $?
698 path2fid $1 || error "cannot get fid on $1"
704 wait_update --verbose $(facet_active_host $facet) "$@"
707 wait_request_state() {
711 # 4th arg (mdt index) is optional
713 local mds=mds$(($mdtidx + 1))
715 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
716 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
718 wait_result $mds "$cmd" $state 200 ||
719 error "request on $fid is not $state on $mds"
722 get_request_state() {
726 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
727 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
730 get_request_count() {
734 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
735 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
742 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
743 [[ -n $fid ]] && cmd+=" | grep '$fid'"
744 cmd+=" | egrep 'WAITING|STARTED'"
746 wait_result $SINGLEMDS "$cmd" "" $timeout ||
747 error "requests did not complete"
750 wait_for_grace_delay() {
751 local val=$(get_hsm_param grace_delay)
758 # python2.6 in EL6 includes an internal json module
759 local json_parser='import json; import fileinput;'
760 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
761 json_parser+='json.loads([line for line in '
762 json_parser+='fileinput.input()][0]).items()])'
764 echo $raw_event | python -c "$json_parser"
767 # populate MDT device array
773 # cleanup from previous bad setup
774 search_and_kill_copytool
776 # for recovery tests, coordinator needs to be started at mount
778 # the lustre conf must be without hsm on (like for sanity.sh)
779 echo "Set HSM on and start"
780 cdt_set_mount_state enabled
781 cdt_check_state enabled
783 echo "Start copytool"
786 echo "Set sanity-hsm HSM policy"
787 cdt_set_sanity_policy
789 # finished requests are quickly removed from list
790 set_hsm_param grace_delay 10
796 local f=$DIR/$tdir/$tfile
800 check_hsm_flags_user $f "0x00000000"
802 $RUNAS $LFS hsm_set --norelease $f ||
803 error "user could not change hsm flags"
804 check_hsm_flags_user $f "0x00000010"
806 $RUNAS $LFS hsm_clear --norelease $f ||
807 error "user could not clear hsm flags"
808 check_hsm_flags_user $f "0x00000000"
810 # User could not change those flags...
811 $RUNAS $LFS hsm_set --exists $f &&
812 error "user should not set this flag"
813 check_hsm_flags_user $f "0x00000000"
816 $LFS hsm_set --exists $f ||
817 error "root could not change hsm flags"
818 check_hsm_flags_user $f "0x00000001"
820 $LFS hsm_clear --exists $f ||
821 error "root could not clear hsm state"
822 check_hsm_flags_user $f "0x00000000"
825 run_test 1 "lfs hsm flags root/non-root access"
829 local f=$DIR/$tdir/$tfile
831 # New files are not dirty
832 check_hsm_flags $f "0x00000000"
834 # For test, we simulate an archived file.
835 $LFS hsm_set --exists $f || error "user could not change hsm flags"
836 check_hsm_flags $f "0x00000001"
838 # chmod do not put the file dirty
839 chmod 600 $f || error "could not chmod test file"
840 check_hsm_flags $f "0x00000001"
842 # chown do not put the file dirty
843 chown $RUNAS_ID $f || error "could not chown test file"
844 check_hsm_flags $f "0x00000001"
846 # truncate put the file dirty
847 $TRUNCATE $f 1 || error "could not truncate test file"
848 check_hsm_flags $f "0x00000003"
850 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
851 check_hsm_flags $f "0x00000001"
853 run_test 2 "Check file dirtyness when doing setattr"
859 # New files are not dirty
861 check_hsm_flags $f "0x00000000"
863 # For test, we simulate an archived file.
864 $LFS hsm_set --exists $f ||
865 error "user could not change hsm flags"
866 check_hsm_flags $f "0x00000001"
868 # Reading a file, does not set dirty
869 cat $f > /dev/null || error "could not read file"
870 check_hsm_flags $f "0x00000001"
872 # Open for write without modifying data, does not set dirty
873 openfile -f O_WRONLY $f || error "could not open test file"
874 check_hsm_flags $f "0x00000001"
876 # Append to a file sets it dirty
877 cp -p /etc/passwd $f.append || error "could not create file"
878 $LFS hsm_set --exists $f.append ||
879 error "user could not change hsm flags"
880 dd if=/etc/passwd of=$f.append bs=1 count=3\
881 conv=notrunc oflag=append status=noxfer ||
882 file_creation_failure dd $f.append $?
883 check_hsm_flags $f.append "0x00000003"
885 # Modify a file sets it dirty
886 cp -p /etc/passwd $f.modify || error "could not create file"
887 $LFS hsm_set --exists $f.modify ||
888 error "user could not change hsm flags"
889 dd if=/dev/zero of=$f.modify bs=1 count=3\
890 conv=notrunc status=noxfer ||
891 file_creation_failure dd $f.modify $?
892 check_hsm_flags $f.modify "0x00000003"
894 # Open O_TRUNC sets dirty
895 cp -p /etc/passwd $f.trunc || error "could not create file"
896 $LFS hsm_set --exists $f.trunc ||
897 error "user could not change hsm flags"
898 cp /etc/group $f.trunc || error "could not override a file"
899 check_hsm_flags $f.trunc "0x00000003"
901 # Mmapped a file sets dirty
902 cp -p /etc/passwd $f.mmap || error "could not create file"
903 $LFS hsm_set --exists $f.mmap ||
904 error "user could not change hsm flags"
905 multiop $f.mmap OSMWUc || error "could not mmap a file"
906 check_hsm_flags $f.mmap "0x00000003"
908 run_test 3 "Check file dirtyness when opening for write"
912 local f=$DIR/$tdir/$tfile
913 local fid=$(make_small $f)
916 local st=$(get_request_state $fid CANCEL)
917 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
919 run_test 4 "Useless cancel must not be registered"
922 # test needs a running copytool
926 local f=$DIR/$tdir/$tfile
927 local fid=$(copy_file /etc/passwd $f)
929 wait_request_state $fid ARCHIVE SUCCEED
931 check_hsm_flags $f "0x00000009"
935 run_test 8 "Test default archive number"
939 local f=$DIR/$tdir/$tfile
940 local fid=$(copy_file /etc/passwd $f)
941 # we do not use the default one to be sure
942 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
944 copytool_setup $SINGLEAGT $MOUNT $new_an
945 $LFS hsm_archive --archive $new_an $f
946 wait_request_state $fid ARCHIVE SUCCEED
948 check_hsm_flags $f "0x00000009"
952 run_test 9 "Use of explicit archive number, with dedicated copytool"
955 needclients 3 || return 0
961 copytool_cleanup $(comma_list $(agts_nodes))
963 # start all of the copytools
964 for n in $(seq $AGTCOUNT); do
968 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
971 for n in $(seq $AGTCOUNT); do
972 file=$DIR/$tdir/$tfile.$n
973 fid=$(make_small $file)
975 $LFS hsm_archive $file || error "could not archive file $file"
976 wait_request_state $fid ARCHIVE SUCCEED
977 check_hsm_flags $file "0x00000009"
981 copytool_cleanup $(comma_list $(agts_nodes))
983 run_test 9a "Multiple remote agents"
986 # test needs a running copytool
989 mkdir -p $DIR/$tdir/d1
990 local f=$DIR/$tdir/$tfile
991 local fid=$(copy_file /etc/hosts $f)
992 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
993 error "hsm_archive failed"
994 wait_request_state $fid ARCHIVE SUCCEED
996 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
997 error "fid $fid not in archive $HSM_ARCHIVE"
998 echo "Verifying content"
999 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1000 echo "Verifying hsm state "
1001 check_hsm_flags $f "0x00000009"
1003 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1004 local st=$(get_hsm_archive_id $f)
1005 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1006 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1011 run_test 10a "Archive a file"
1014 # test needs a running copytool
1018 local f=$DIR/$tdir/$tfile
1019 local fid=$(copy_file /etc/hosts $f)
1020 $LFS hsm_archive $f || error "archive request failed"
1021 wait_request_state $fid ARCHIVE SUCCEED
1023 $LFS hsm_archive $f || error "archive of non dirty file failed"
1024 local cnt=$(get_request_count $fid ARCHIVE)
1025 [[ "$cnt" == "1" ]] ||
1026 error "archive of non dirty file must not make a request"
1030 run_test 10b "Archive of non dirty file must work without doing request"
1033 # test needs a running copytool
1037 local f=$DIR/$tdir/$tfile
1038 local fid=$(copy_file /etc/hosts $f)
1039 $LFS hsm_set --noarchive $f
1040 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1044 run_test 10c "Check forbidden archive"
1047 # test needs a running copytool
1051 local f=$DIR/$tdir/$tfile
1052 local fid=$(copy_file /etc/hosts $f)
1053 $LFS hsm_archive $f || error "cannot archive $f"
1054 wait_request_state $fid ARCHIVE SUCCEED
1056 local ar=$(get_hsm_archive_id $f)
1057 local dflt=$(get_hsm_param default_archive_id)
1058 [[ $ar == $dflt ]] ||
1059 error "archived file is not on default archive: $ar != $dflt"
1063 run_test 10d "Archive a file on the default archive id"
1067 copy2archive /etc/hosts $tdir/$tfile
1068 local f=$DIR/$tdir/$tfile
1070 import_file $tdir/$tfile $f
1071 echo -n "Verifying released state: "
1072 check_hsm_flags $f "0x0000000d"
1074 local LSZ=$(stat -c "%s" $f)
1075 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1077 echo "Verifying imported size $LSZ=$ASZ"
1078 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1079 echo -n "Verifying released pattern: "
1080 local PTRN=$($GETSTRIPE -L $f)
1082 [[ $PTRN == 80000001 ]] || error "Is not released"
1083 local fid=$(path2fid $f)
1084 echo "Verifying new fid $fid in archive"
1086 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1087 error "fid $fid not in archive $HSM_ARCHIVE"
1089 run_test 11a "Import a file"
1092 # test needs a running copytool
1096 local f=$DIR/$tdir/$tfile
1097 local fid=$(copy_file /etc/hosts $f)
1098 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1099 error "hsm_archive failed"
1100 wait_request_state $fid ARCHIVE SUCCEED
1102 local FILE_HASH=$(md5sum $f)
1107 echo "$FILE_HASH" | md5sum -c
1109 [[ $? -eq 0 ]] || error "Restored file differs"
1113 run_test 11b "Import a deleted file using its FID"
1116 # test needs a running copytool
1120 copy2archive /etc/hosts $tdir/$tfile
1122 local f=$DIR/$tdir/$tfile
1123 import_file $tdir/$tfile $f
1124 local f2=$DIR2/$tdir/$tfile
1125 echo "Verifying released state: "
1126 check_hsm_flags $f2 "0x0000000d"
1128 local fid=$(path2fid $f2)
1129 $LFS hsm_restore $f2
1130 wait_request_state $fid RESTORE SUCCEED
1132 echo "Verifying file state: "
1133 check_hsm_flags $f2 "0x00000009"
1135 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1137 [[ $? -eq 0 ]] || error "Restored file differs"
1141 run_test 12a "Restore an imported file explicitly"
1144 # test needs a running copytool
1148 copy2archive /etc/hosts $tdir/$tfile
1150 local f=$DIR/$tdir/$tfile
1151 import_file $tdir/$tfile $f
1152 echo "Verifying released state: "
1153 check_hsm_flags $f "0x0000000d"
1155 cat $f > /dev/null || error "File read failed"
1157 echo "Verifying file state after restore: "
1158 check_hsm_flags $f "0x00000009"
1160 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1162 [[ $? -eq 0 ]] || error "Restored file differs"
1166 run_test 12b "Restore an imported file implicitly"
1169 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1171 # test needs a running copytool
1175 local f=$DIR/$tdir/$tfile
1176 $LFS setstripe -c 2 $f
1178 fid=$(make_large_for_striping $f)
1179 [ $? != 0 ] && skip "not enough free space" && return
1181 local FILE_CRC=$(md5sum $f)
1183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1184 wait_request_state $fid ARCHIVE SUCCEED
1185 $LFS hsm_release $f || error "release $f failed"
1187 echo "$FILE_CRC" | md5sum -c
1189 [[ $? -eq 0 ]] || error "Restored file differs"
1193 run_test 12c "Restore a file with stripe of 2"
1196 # test needs a running copytool
1201 local f=$DIR/$tdir/$tfile
1202 local fid=$(copy_file /etc/hosts $f)
1203 $LFS hsm_restore $f || error "restore of non archived file failed"
1204 local cnt=$(get_request_count $fid RESTORE)
1205 [[ "$cnt" == "0" ]] ||
1206 error "restore non archived must not make a request"
1207 $LFS hsm_archive $f ||
1208 error "archive request failed"
1209 wait_request_state $fid ARCHIVE SUCCEED
1210 $LFS hsm_restore $f ||
1211 error "restore of non released file failed"
1212 local cnt=$(get_request_count $fid RESTORE)
1213 [[ "$cnt" == "0" ]] ||
1214 error "restore a non dirty file must not make a request"
1218 run_test 12d "Restore of a non archived, non released file must work"\
1219 " without doing request"
1222 # test needs a running copytool
1225 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1226 local f=$DIR/$tdir/$tfile
1227 local fid=$(copy_file /etc/hosts $f)
1228 $LFS hsm_archive $f || error "archive request failed"
1229 wait_request_state $fid ARCHIVE SUCCEED
1232 cat /etc/hosts >> $f
1236 $LFS hsm_restore $f && error "restore a dirty file must fail"
1240 run_test 12e "Check forbidden restore"
1243 # test needs a running copytool
1247 local f=$DIR/$tdir/$tfile
1248 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1251 wait_request_state $fid ARCHIVE SUCCEED
1252 $LFS hsm_release $f || error "release of $f failed"
1254 wait_request_state $fid RESTORE SUCCEED
1256 echo -n "Verifying file state: "
1257 check_hsm_flags $f "0x00000009"
1259 diff -q /etc/hosts $f
1261 [[ $? -eq 0 ]] || error "Restored file differs"
1265 run_test 12f "Restore a released file explicitly"
1268 # test needs a running copytool
1272 local f=$DIR/$tdir/$tfile
1273 local fid=$(copy_file /etc/hosts $f)
1275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1276 wait_request_state $fid ARCHIVE SUCCEED
1277 $LFS hsm_release $f || error "release of $f failed"
1279 diff -q /etc/hosts $f
1282 # we check we had a restore done
1283 wait_request_state $fid RESTORE SUCCEED
1285 [[ $st -eq 0 ]] || error "Restored file differs"
1289 run_test 12g "Restore a released file implicitly"
1292 needclients 2 || return 0
1294 # test needs a running copytool
1298 local f=$DIR/$tdir/$tfile
1299 local fid=$(copy_file /etc/hosts $f)
1301 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1302 wait_request_state $fid ARCHIVE SUCCEED
1303 $LFS hsm_release $f || error "release of $f failed"
1305 do_node $CLIENT2 diff -q /etc/hosts $f
1308 # we check we had a restore done
1309 wait_request_state $fid RESTORE SUCCEED
1311 [[ $st -eq 0 ]] || error "Restored file differs"
1315 run_test 12h "Restore a released file implicitly from a second node"
1318 # test needs a running copytool
1322 local f=$DIR/$tdir/$tfile
1323 local fid=$(copy_file /etc/passwd $f)
1324 $LFS hsm_archive $f || error "archive of $f failed"
1325 wait_request_state $fid ARCHIVE SUCCEED
1327 $LFS hsm_release $f || error "release of $f failed"
1331 [[ $? -eq 0 ]] || error "Restored file differs"
1335 run_test 12m "Archive/release/implicit restore"
1338 # test needs a running copytool
1342 copy2archive /etc/hosts $tdir/$tfile
1344 local f=$DIR/$tdir/$tfile
1345 import_file $tdir/$tfile $f
1347 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1348 error "Restored file differs"
1350 $LFS hsm_release $f || error "release of $f failed"
1354 run_test 12n "Import/implicit restore/release"
1357 # test needs a running copytool
1361 local f=$DIR/$tdir/$tfile
1362 local fid=$(copy_file /etc/hosts $f)
1364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1365 wait_request_state $fid ARCHIVE SUCCEED
1366 $LFS hsm_release $f || error "release of $f failed"
1368 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1369 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1371 # set no retry action mode
1374 diff -q /etc/hosts $f
1377 # we check we had a restore failure
1378 wait_request_state $fid RESTORE FAILED
1380 [[ $st -eq 0 ]] && error "Restore must fail"
1382 # remove no retry action mode
1385 # check file is still released
1386 check_hsm_flags $f "0x0000000d"
1388 # retry w/o failure injection
1389 do_facet $SINGLEMDS lctl set_param fail_loc=0
1391 # to be sure previous RESTORE result is gone
1393 wait_for_grace_delay
1395 diff -q /etc/hosts $f
1398 # we check we had a restore done
1399 wait_request_state $fid RESTORE SUCCEED
1401 [[ $st -eq 0 ]] || error "Restored file differs"
1405 run_test 12o "Layout-swap failure during Restore leaves file released"
1408 # test needs a running copytool
1412 local f=$DIR/$tdir/$tfile
1413 local fid=$(copy_file /etc/hosts $f)
1415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1416 wait_request_state $fid ARCHIVE SUCCEED
1417 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1418 $LFS hsm_release $f || error "cannot release $f"
1419 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1420 $LFS hsm_release $f || error "cannot release $f"
1421 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1425 run_test 12p "implicit restore of a file on copytool mount point"
1427 cleanup_test_12q() {
1429 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1430 error "cannot umount $MOUNT3 on $SINGLEAGT"
1435 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1436 error "cannot mount $MOUNT3 on $SINGLEAGT"
1438 trap cleanup_test_12q EXIT
1440 # test needs a running copytool
1441 copytool_setup $SINGLEAGT $MOUNT3
1444 local f=$DIR/$tdir/$tfile
1445 local f2=$DIR2/$tdir/$tfile
1446 local fid=$(make_small $f)
1447 local orig_size=$(stat -c "%s" $f)
1449 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1450 wait_request_state $fid ARCHIVE SUCCEED
1452 $LFS hsm_release $f || error "could not release file"
1453 check_hsm_flags $f "0x0000000d"
1455 search_and_kill_copytool
1457 search_copytools && error "Copytool should have stopped"
1459 cat $f > /dev/null &
1461 # wait a bit to allow implicit restore request to be handled.
1462 # if not, next stat would also block on layout-lock.
1465 local size=$(stat -c "%s" $f2)
1466 [ $size -eq $orig_size ] ||
1467 error "$f2: wrong size after archive: $size != $orig_size"
1469 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1473 size=$(stat -c "%s" $f)
1474 [ $size -eq $orig_size ] ||
1475 error "$f: wrong size after restore: $size != $orig_size"
1477 size=$(stat -c "%s" $f2)
1478 [ $size -eq $orig_size ] ||
1479 error "$f2: wrong size after restore: $size != $orig_size"
1483 size=$(stat -c "%s" $f)
1485 error "$f: wrong size after overwrite: $size != 0"
1487 size=$(stat -c "%s" $f2)
1489 error "$f2: wrong size after overwrite: $size != 0"
1492 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1493 error "cannot umount $MOUNT3 on $SINGLEAGT"
1495 run_test 12q "file attributes are refreshed after restore"
1498 # test needs a running copytool
1501 local ARC_SUBDIR="import.orig"
1505 # populate directory to be imported
1506 for d in $(seq 1 10); do
1507 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1508 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1509 for f in $(seq 1 10); do
1510 CURR_FILE="$CURR_DIR/$tfile.$f"
1511 # write file-specific data
1512 do_facet $SINGLEAGT \
1513 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1514 "file=$CURR_FILE > $CURR_FILE"
1518 import_file "$ARC_SUBDIR" $DIR/$tdir
1519 # diff lustre content and origin (triggers file restoration)
1520 # there must be 10x10 identical files, and no difference
1521 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1522 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1523 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1524 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1526 [ $cnt_diff -eq 0 ] ||
1527 error "$cnt_diff imported files differ from read data"
1528 [ $cnt_ok -eq 100 ] ||
1529 error "not enough identical files ($cnt_ok != 100)"
1533 run_test 13 "Recursively import and restore a directory"
1536 # test needs a running copytool
1541 local f=$DIR/$tdir/$tfile
1542 local fid=$(make_small $f)
1543 local sum=$(md5sum $f | awk '{print $1}')
1544 $LFS hsm_archive $f || error "could not archive file"
1545 wait_request_state $fid ARCHIVE SUCCEED
1549 # create released file (simulate llapi_hsm_import call)
1551 local fid2=$(path2fid $f)
1552 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1553 $LFS hsm_release $f || error "could not release file"
1555 # rebind the archive to the newly created file
1556 echo "rebind $fid to $fid2"
1558 do_facet $SINGLEAGT \
1559 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1560 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1562 # restore file and compare md5sum
1563 local sum2=$(md5sum $f | awk '{print $1}')
1565 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1569 run_test 14 "Rebind archived file to a new fid"
1572 # test needs a running copytool
1577 local f=$DIR/$tdir/$tfile
1579 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1583 for i in $(seq 1 $count); do
1584 fids[$i]=$(make_small $f.$i)
1585 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1586 $LFS hsm_archive $f.$i || error "could not archive file"
1588 wait_all_done $(($count*60))
1592 for i in $(seq 1 $count); do
1595 local fid2=$(path2fid $f.$i)
1596 # add the rebind operation to the list
1597 echo ${fids[$i]} $fid2 >> $tmpfile
1599 # set it released (simulate llapi_hsm_import call)
1600 $LFS hsm_set --archived --exists $f.$i ||
1601 error "could not force hsm flags"
1602 $LFS hsm_release $f.$i || error "could not release file"
1604 nl=$(wc -l < $tmpfile)
1605 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1607 echo "rebind list of files"
1608 do_facet $SINGLEAGT \
1609 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1610 --rebind $tmpfile $DIR" || error "could not rebind file list"
1612 # restore files and compare md5sum
1613 for i in $(seq 1 $count); do
1614 local sum2=$(md5sum $f.$i | awk '{print $1}')
1615 [[ $sum2 == ${sums[$i]} ]] ||
1616 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1622 run_test 15 "Rebind a list of files"
1625 # test needs a running copytool
1629 # create a known size file so we can verify transfer speed
1632 dd if=/dev/zero of=$ref bs=1M count=20
1635 local f=$DIR/$tdir/$tfile
1636 local fid=$(copy_file $ref $f)
1638 local start=$(date +%s)
1640 wait_request_state $fid ARCHIVE SUCCEED
1641 local end=$(date +%s)
1642 local duration=$((end - start))
1644 [[ $duration -ge $goal ]] ||
1645 error "Transfer is too fast $duration < $goal"
1649 run_test 16 "Test CT bandwith control option"
1654 local f=$DIR/$tdir/$tfile
1655 touch $f || error "touch $f failed"
1657 # Could not release a non-archived file
1658 $LFS hsm_release $f && error "release should not succeed"
1660 # For following tests, we must test them with HS_ARCHIVED set
1661 $LFS hsm_set --exists --archived $f || error "could not add flag"
1663 # Could not release a file if no-release is set
1664 $LFS hsm_set --norelease $f || error "could not add flag"
1665 $LFS hsm_release $f && error "release should not succeed"
1666 $LFS hsm_clear --norelease $f || error "could not remove flag"
1668 # Could not release a file if lost
1669 $LFS hsm_set --lost $f || error "could not add flag"
1670 $LFS hsm_release $f && error "release should not succeed"
1671 $LFS hsm_clear --lost $f || error "could not remove flag"
1673 # Could not release a file if dirty
1674 $LFS hsm_set --dirty $f || error "could not add flag"
1675 $LFS hsm_release $f && error "release should not succeed"
1676 $LFS hsm_clear --dirty $f || error "could not remove flag"
1678 run_test 20 "Release is not permitted"
1681 # test needs a running copytool
1685 local f=$DIR/$tdir/test_release
1687 # Create a file and check its states
1688 local fid=$(make_small $f)
1689 check_hsm_flags $f "0x00000000"
1691 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1692 # used until file is flushed to disk
1693 if [ $(facet_fstype ost1) == "zfs" ]; then
1694 # this causes an OST_SYNC rpc to be sent
1695 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1696 # clear locks to reread file data
1697 cancel_lru_locks osc
1700 local orig_size=$(stat -c "%s" $f)
1701 local orig_blocks=$(stat -c "%b" $f)
1703 start_full_debug_logging
1705 $LFS hsm_archive $f || error "could not archive file"
1706 wait_request_state $fid ARCHIVE SUCCEED
1708 local blocks=$(stat -c "%b" $f)
1709 [ $blocks -eq $orig_blocks ] ||
1710 error "$f: wrong block number after archive: " \
1711 "$blocks != $orig_blocks"
1712 local size=$(stat -c "%s" $f)
1713 [ $size -eq $orig_size ] ||
1714 error "$f: wrong size after archive: $size != $orig_size"
1716 # Release and check states
1717 $LFS hsm_release $f || error "could not release file"
1718 check_hsm_flags $f "0x0000000d"
1720 blocks=$(stat -c "%b" $f)
1721 [ $blocks -gt 5 ] &&
1722 error "$f: too many blocks after release: $blocks > 5"
1723 size=$(stat -c "%s" $f)
1724 [ $size -ne $orig_size ] &&
1725 error "$f: wrong size after release: $size != $orig_size"
1727 # Check we can release an file without stripe info
1731 check_hsm_flags $f "0x00000000"
1732 $LFS hsm_archive $f || error "could not archive file"
1733 wait_request_state $fid ARCHIVE SUCCEED
1735 # Release and check states
1736 $LFS hsm_release $f || error "could not release file"
1737 check_hsm_flags $f "0x0000000d"
1739 # Release again a file that is already released is OK
1740 $LFS hsm_release $f || fail "second release should succeed"
1741 check_hsm_flags $f "0x0000000d"
1743 stop_full_debug_logging
1747 run_test 21 "Simple release tests"
1750 # test needs a running copytool
1755 local f=$DIR/$tdir/test_release
1756 local swap=$DIR/$tdir/test_swap
1758 # Create a file and check its states
1759 local fid=$(make_small $f)
1760 check_hsm_flags $f "0x00000000"
1762 $LFS hsm_archive $f || error "could not archive file"
1763 wait_request_state $fid ARCHIVE SUCCEED
1765 # Release and check states
1766 $LFS hsm_release $f || error "could not release file"
1767 check_hsm_flags $f "0x0000000d"
1770 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1775 run_test 22 "Could not swap a release file"
1778 # test needs a running copytool
1783 local f=$DIR/$tdir/test_mtime
1785 # Create a file and check its states
1786 local fid=$(make_small $f)
1787 check_hsm_flags $f "0x00000000"
1789 $LFS hsm_archive $f || error "could not archive file"
1790 wait_request_state $fid ARCHIVE SUCCEED
1792 # Set modification time in the past
1793 touch -m -a -d @978261179 $f
1795 # Release and check states
1796 $LFS hsm_release $f || error "could not release file"
1797 check_hsm_flags $f "0x0000000d"
1799 local MTIME=$(stat -c "%Y" $f)
1800 local ATIME=$(stat -c "%X" $f)
1801 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1802 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1806 run_test 23 "Release does not change a/mtime (utime)"
1809 local file=$DIR/$tdir/$tfile
1818 # test needs a running copytool
1823 fid=$(make_small $file)
1825 # Create a file and check its states
1826 check_hsm_flags $file "0x00000000"
1828 # Ensure atime is less than mtime and ctime.
1832 atime0=$(stat -c "%X" $file)
1833 mtime0=$(stat -c "%Y" $file)
1834 ctime0=$(stat -c "%Z" $file)
1836 [ $atime0 -lt $mtime0 ] ||
1837 error "atime $atime0 is not less than mtime $mtime0"
1839 [ $atime0 -lt $ctime0 ] ||
1840 error "atime $atime0 is not less than ctime $ctime0"
1842 # Archive should not change any timestamps.
1843 $LFS hsm_archive $file || error "cannot archive '$file'"
1844 wait_request_state $fid ARCHIVE SUCCEED
1846 atime1=$(stat -c "%X" $file)
1847 mtime1=$(stat -c "%Y" $file)
1848 ctime1=$(stat -c "%Z" $file)
1850 [ $atime0 -eq $atime1 ] ||
1851 error "archive changed atime from $atime0 to $atime1"
1853 [ $mtime0 -eq $mtime1 ] ||
1854 error "archive changed mtime from $mtime0 to $mtime1"
1856 [ $ctime0 -eq $ctime1 ] ||
1857 error "archive changed ctime from $ctime0 to $ctime1"
1859 # Release should not change any timestamps.
1860 $LFS hsm_release $file || error "cannot release '$file'"
1861 check_hsm_flags $file "0x0000000d"
1863 atime1=$(stat -c "%X" $file)
1864 mtime1=$(stat -c "%Y" $file)
1865 ctime1=$(stat -c "%Z" $file)
1867 [ $atime0 -eq $atime1 ] ||
1868 error "release changed atime from $atime0 to $atime1"
1870 [ $mtime0 -eq $mtime1 ] ||
1871 error "release changed mtime from $mtime0 to $mtime1"
1873 [ $ctime0 -eq $ctime1 ] ||
1874 error "release changed ctime from $ctime0 to $ctime1"
1876 # Restore should not change atime or mtime and should not
1878 $LFS hsm_restore $file
1879 wait_request_state $fid RESTORE SUCCEED
1881 atime1=$(stat -c "%X" $file)
1882 mtime1=$(stat -c "%Y" $file)
1883 ctime1=$(stat -c "%Z" $file)
1885 [ $atime0 -eq $atime1 ] ||
1886 error "restore changed atime from $atime0 to $atime1"
1888 [ $mtime0 -eq $mtime1 ] ||
1889 error "restore changed mtime from $mtime0 to $mtime1"
1891 [ $ctime0 -eq $ctime1 ] ||
1892 error "restore changed ctime from $ctime0 to $ctime1"
1896 # Once more, after unmount and mount.
1897 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1898 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1900 atime1=$(stat -c "%X" $file)
1901 mtime1=$(stat -c "%Y" $file)
1902 ctime1=$(stat -c "%Z" $file)
1904 [ $atime0 -eq $atime1 ] ||
1905 error "remount changed atime from $atime0 to $atime1"
1907 [ $mtime0 -eq $mtime1 ] ||
1908 error "remount changed mtime from $mtime0 to $mtime1"
1910 [ $ctime0 -eq $ctime1 ] ||
1911 error "remount changed ctime from $ctime0 to $ctime1"
1913 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1916 local file=$DIR/$tdir/$tfile
1922 # Test needs a running copytool.
1926 # Check that root can do HSM actions on a regular user's file.
1928 fid=$(make_small $file)
1929 sum0=$(md5sum $file)
1931 chown $RUNAS_ID:$RUNAS_GID $file ||
1932 error "cannot chown '$file' to '$RUNAS_ID'"
1934 chmod ugo-w $DIR/$tdir ||
1935 error "cannot chmod '$DIR/$tdir'"
1937 $LFS hsm_archive $file
1938 wait_request_state $fid ARCHIVE SUCCEED
1940 $LFS hsm_release $file
1941 check_hsm_flags $file "0x0000000d"
1943 $LFS hsm_restore $file
1944 wait_request_state $fid RESTORE SUCCEED
1946 # Check that ordinary user can get HSM state.
1947 $RUNAS $LFS hsm_state $file ||
1948 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1950 $LFS hsm_release $file
1951 check_hsm_flags $file "0x0000000d"
1953 # Check that ordinary user can accessed released file.
1954 sum1=$($RUNAS md5sum $file) ||
1955 error "user '$RUNAS_ID' cannot read '$file'"
1957 [ "$sum0" == "$sum1" ] ||
1958 error "md5sum mismatch for '$file'"
1962 run_test 24b "root can archive, release, and restore user files"
1964 cleanup_test_24c() {
1966 set_hsm_param user_request_mask RESTORE
1967 set_hsm_param group_request_mask RESTORE
1968 set_hsm_param other_request_mask RESTORE
1972 local file=$DIR/$tdir/$tfile
1973 local action=archive
1978 # test needs a running copytool
1983 # Save the default masks and check that cleanup_24c will
1984 # restore the request masks correctly.
1985 user_save=$(get_hsm_param user_request_mask)
1986 group_save=$(get_hsm_param group_request_mask)
1987 other_save=$(get_hsm_param other_request_mask)
1989 [ "$user_save" == RESTORE ] ||
1990 error "user_request_mask is '$user_save' expected 'RESTORE'"
1991 [ "$group_save" == RESTORE ] ||
1992 error "group_request_mask is '$group_save' expected 'RESTORE'"
1993 [ "$other_save" == RESTORE ] ||
1994 error "other_request_mask is '$other_save' expected 'RESTORE'"
1996 trap cleanup_test_24c EXIT
2001 chown $RUNAS_ID:nobody $file ||
2002 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2004 set_hsm_param user_request_mask ""
2005 $RUNAS $LFS hsm_$action $file &&
2006 error "$action by user should fail"
2008 set_hsm_param user_request_mask $action
2009 $RUNAS $LFS hsm_$action $file ||
2010 error "$action by user should succeed"
2015 chown nobody:$RUNAS_GID $file ||
2016 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2018 set_hsm_param group_request_mask ""
2019 $RUNAS $LFS hsm_$action $file &&
2020 error "$action by group should fail"
2022 set_hsm_param group_request_mask $action
2023 $RUNAS $LFS hsm_$action $file ||
2024 error "$action by group should succeed"
2029 chown nobody:nobody $file ||
2030 error "cannot chown '$file' to 'nobody:nobody'"
2032 set_hsm_param other_request_mask ""
2033 $RUNAS $LFS hsm_$action $file &&
2034 error "$action by other should fail"
2036 set_hsm_param other_request_mask $action
2037 $RUNAS $LFS hsm_$action $file ||
2038 error "$action by other should succeed"
2043 run_test 24c "check that user,group,other request masks work"
2045 cleanup_test_24d() {
2047 mount -o remount,rw $MOUNT2
2051 local file1=$DIR/$tdir/$tfile
2052 local file2=$DIR2/$tdir/$tfile
2060 fid1=$(make_small $file1)
2062 trap cleanup_test_24d EXIT
2064 mount -o remount,ro $MOUNT2
2066 fid2=$(path2fid $file2)
2067 [ "$fid1" == "$fid2" ] ||
2068 error "FID mismatch '$fid1' != '$fid2'"
2070 $LFS hsm_archive $file2 &&
2071 error "archive should fail on read-only mount"
2072 check_hsm_flags $file1 "0x00000000"
2074 $LFS hsm_archive $file1
2075 wait_request_state $fid1 ARCHIVE SUCCEED
2077 $LFS hsm_release $file1
2078 $LFS hsm_restore $file2
2079 wait_request_state $fid1 RESTORE SUCCEED
2081 $LFS hsm_release $file1 || error "cannot release '$file1'"
2082 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2084 $LFS hsm_release $file2 &&
2085 error "release should fail on read-only mount"
2090 run_test 24d "check that read-only mounts are respected"
2097 local f=$DIR/$tdir/$tfile
2100 fid=$(make_small $f) || error "cannot create $f"
2101 $LFS hsm_archive $f || error "cannot archive $f"
2102 wait_request_state $fid ARCHIVE SUCCEED
2103 $LFS hsm_release $f || error "cannot release $f"
2104 while ! $LFS hsm_state $f | grep released; do
2108 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2112 run_test 24e "tar succeeds on HSM released files" # LU-6213
2116 # test needs a running copytool
2119 mkdir -p $DIR/$tdir/d1
2120 local f=$DIR/$tdir/$tfile
2121 local fid=$(copy_file /etc/hosts $f)
2124 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2125 error "hsm_archive failed"
2126 wait_request_state $fid ARCHIVE SUCCEED
2127 $LFS hsm_release $f || error "cannot release $f"
2128 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2131 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2132 error "Can not recover the tar contents"
2134 echo "Sum0 = $sum0, sum1 = $sum1"
2135 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2139 run_test 24f "root can archive, release, and restore tar files"
2142 # test needs a running copytool
2146 copy2archive /etc/hosts $tdir/$tfile
2148 local f=$DIR/$tdir/$tfile
2150 import_file $tdir/$tfile $f
2152 $LFS hsm_set --lost $f
2157 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2161 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2162 " (Operation not permitted)"
2165 # test needs a running copytool
2170 local f=$DIR/$tdir/$tfile
2171 local fid=$(copy_file /etc/passwd $f)
2173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2174 wait_request_state $fid ARCHIVE SUCCEED
2177 $LFS hsm_set --lost $f
2181 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2185 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2186 " (Operation not permitted)"
2189 # test needs a running copytool
2193 local f=$DIR/$tdir/$tfile
2195 fid=$(make_large_for_progress $f)
2196 [ $? != 0 ] && skip "not enough free space" && return
2198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2199 wait_request_state $fid ARCHIVE SUCCEED
2202 wait_request_state $fid REMOVE SUCCEED
2204 check_hsm_flags $f "0x00000000"
2208 run_test 26 "Remove the archive of a valid file"
2211 # test needs a running copytool
2215 make_archive $tdir/$tfile
2216 local f=$DIR/$tdir/$tfile
2217 import_file $tdir/$tfile $f
2218 local fid=$(path2fid $f)
2222 [[ $? != 0 ]] || error "Remove of a released file should fail"
2226 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2229 # test needs a running copytool
2233 local f=$DIR/$tdir/$tfile
2235 fid=$(make_large_for_progress $f)
2236 [ $? != 0 ] && skip "not enough free space" && return
2238 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2239 wait_request_state $fid ARCHIVE SUCCEED
2244 [[ $? != 0 ]] || error "Remove of a released file should fail"
2248 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2251 # test needs a running copytool
2255 local f=$DIR/$tdir/$tfile
2257 fid=$(make_large_for_progress $f)
2258 [ $? != 0 ] && skip "not enough free space" && return
2260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2261 wait_request_state $fid ARCHIVE SUCCEED
2270 wait_request_state $fid REMOVE SUCCEED
2274 run_test 28 "Concurrent archive/file remove"
2277 # Tests --mntpath and --archive options
2280 copytool_setup $SINGLEAGT $MOUNT $archive_id
2282 # Bad archive number
2283 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2284 grep "Invalid argument" ||
2285 error "unexpected hsm_remove failure (1)"
2287 # mntpath is present but file is given
2288 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2289 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2290 error "unexpected hsm_remove failure (2)"
2294 run_test 29a "Tests --mntpath and --archive options"
2297 # test needs a running copytool
2301 local f=$DIR/$tdir/$tfile
2302 local fid=$(make_small $f)
2304 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2305 wait_request_state $fid ARCHIVE SUCCEED
2309 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2310 wait_request_state $fid REMOVE SUCCEED
2314 run_test 29b "Archive/delete/remove by FID from the archive."
2317 # test needs a running copytool
2321 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2322 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2323 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2326 wait_request_state $fid1 ARCHIVE SUCCEED
2327 wait_request_state $fid2 ARCHIVE SUCCEED
2328 wait_request_state $fid3 ARCHIVE SUCCEED
2330 rm -f $DIR/$tdir/$tfile-[1-3]
2332 echo $fid1 > $DIR/$tdir/list
2333 echo $fid2 >> $DIR/$tdir/list
2334 echo $fid3 >> $DIR/$tdir/list
2336 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2337 --filelist $DIR/$tdir/list
2338 wait_request_state $fid1 REMOVE SUCCEED
2339 wait_request_state $fid2 REMOVE SUCCEED
2340 wait_request_state $fid3 REMOVE SUCCEED
2344 run_test 29c "Archive/delete/remove by FID, using a file list."
2347 # restore at exec cannot work on agent node (because of Linux kernel
2348 # protection of executables)
2349 needclients 2 || return 0
2351 # test needs a running copytool
2355 copy2archive /bin/true $tdir/$tfile
2357 local f=$DIR/$tdir/true
2358 import_file $tdir/$tfile $f
2360 local fid=$(path2fid $f)
2362 # set no retry action mode
2368 # remove no try action mode
2372 [[ $st == 0 ]] || error "Failed to exec a released file"
2376 run_test 30a "Restore at exec (import case)"
2379 # restore at exec cannot work on agent node (because of Linux kernel
2380 # protection of executables)
2381 needclients 2 || return 0
2383 # test needs a running copytool
2387 local f=$DIR/$tdir/true
2388 local fid=$(copy_file /bin/true $f)
2390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2391 wait_request_state $fid ARCHIVE SUCCEED
2394 # set no retry action mode
2400 # remove no try action mode
2404 [[ $st == 0 ]] || error "Failed to exec a released file"
2408 run_test 30b "Restore at exec (release case)"
2411 needclients 2 || return 0
2413 # test needs a running copytool
2417 local f=$DIR/$tdir/SLEEP
2418 local slp_sum1=$(md5sum /bin/sleep)
2419 local fid=$(copy_file /bin/sleep $f)
2421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2422 wait_request_state $fid ARCHIVE SUCCEED
2424 check_hsm_flags $f "0x0000000d"
2425 # set no retry action mode
2427 do_node $CLIENT2 "$f 10" &
2431 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2433 [[ $? == 0 ]] || error "Execution failed during run"
2435 if [[ $? != 0 ]]; then
2436 local slp_sum2=$(md5sum /bin/sleep)
2437 # in case sleep file is modified during the test
2438 [[ $slp_sum1 == $slp_sum2 ]] &&
2439 error "Binary overwritten during exec"
2443 # remove no try action mode
2445 check_hsm_flags $f "0x00000009"
2449 run_test 30c "Update during exec of released file must fail"
2451 restore_and_check_size() {
2454 local s=$(stat -c "%s" $f)
2456 local st=$(get_hsm_flags $f)
2460 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2462 n=$(stat -c "%s" $f)
2463 # we echo in both cases to show stat is not
2465 if [[ $n != $s ]]; then
2466 echo "size seen is $n != $s"
2469 echo "size seen is right: $n == $s"
2471 st=$(get_hsm_flags $f)
2475 if [[ $cpt -lt 10 ]]; then
2478 echo " restore is too long"
2479 wait_request_state $fid RESTORE SUCCEED
2485 # test needs a running copytool
2490 make_archive $tdir/$tfile
2491 local f=$DIR/$tdir/$tfile
2492 import_file $tdir/$tfile $f
2493 local fid=$($LFS path2fid $f)
2494 HSM_ARCHIVE_PURGE=false copytool_setup
2496 restore_and_check_size $f $fid
2499 [[ $err -eq 0 ]] || error "File size changed during restore"
2503 run_test 31a "Import a large file and check size during restore"
2507 # test needs a running copytool
2512 local f=$DIR/$tdir/$tfile
2514 fid=$(make_large_for_progress $f)
2515 [ $? != 0 ] && skip "not enough free space" && return
2517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2518 wait_request_state $fid ARCHIVE SUCCEED
2521 restore_and_check_size $f $fid
2524 [[ $err -eq 0 ]] || error "File size changed during restore"
2528 run_test 31b "Restore a large unaligned file and check size during restore"
2531 # test needs a running copytool
2536 local f=$DIR/$tdir/$tfile
2538 fid=$(make_large_for_progress_aligned $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 31c "Restore a large aligned file and check size during restore"
2555 # test needs a running copytool
2560 local f=$DIR/$tdir/$tfile
2562 fid=$(make_large_for_progress $f)
2563 [ $? != 0 ] && skip "not enough free space" && return
2565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2566 wait_request_state $fid ARCHIVE SUCCEED
2569 # to be sure wait_all_done will not be mislead by previous tests
2572 wait_for_grace_delay
2573 # Also raise grace_delay significantly so the Canceled
2574 # Restore action will stay enough long avail.
2575 local old_grace=$(get_hsm_param grace_delay)
2576 set_hsm_param grace_delay 100
2578 md5sum $f >/dev/null &
2580 wait_request_state $fid RESTORE STARTED
2585 # Check restore trigger process was killed
2586 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2590 # instead of waiting+checking both Restore and Cancel ops
2591 # sequentially, wait for both to be finished and then check
2593 wait_all_done 100 $fid
2594 local rstate=$(get_request_state $fid RESTORE)
2595 local cstate=$(get_request_state $fid CANCEL)
2597 # restore orig grace_delay.
2598 set_hsm_param grace_delay $old_grace
2600 if [[ "$rstate" == "CANCELED" ]] ; then
2601 [[ "$cstate" == "SUCCEED" ]] ||
2602 error "Restore state is CANCELED and Cancel state " \
2603 "is not SUCCEED but $cstate"
2604 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2605 elif [[ "$rstate" == "SUCCEED" ]] ; then
2606 [[ "$cstate" == "FAILED" ]] ||
2607 error "Restore state is SUCCEED and Cancel state " \
2608 "is not FAILED but $cstate"
2609 echo "Restore state is SUCCEED, Cancel state is FAILED"
2611 error "Restore state is $rstate and Cancel state is $cstate"
2615 error "Cannot kill process waiting for restore ($killed)"
2619 run_test 33 "Kill a restore waiting process"
2622 # test needs a running copytool
2627 local f=$DIR/$tdir/$tfile
2629 fid=$(make_large_for_progress $f)
2630 [ $? != 0 ] && skip "not enough free space" && return
2632 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2633 wait_request_state $fid ARCHIVE SUCCEED
2636 md5sum $f >/dev/null &
2638 wait_request_state $fid RESTORE STARTED
2640 rm $f || error "rm $f failed"
2641 # rm must not block during restore
2642 wait_request_state $fid RESTORE STARTED
2644 wait_request_state $fid RESTORE SUCCEED
2645 # check md5sum pgm finished
2646 local there=$(ps -o pid,comm hp $pid >/dev/null)
2647 [[ -z $there ]] || error "Restore initiator does not exit"
2649 local rc=$(wait $pid)
2650 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2654 run_test 34 "Remove file during restore"
2657 # test needs a running copytool
2662 local f=$DIR/$tdir/$tfile
2663 local f1=$DIR/$tdir/$tfile-1
2665 fid=$(make_large_for_progress $f)
2666 [ $? != 0 ] && skip "not enough free space" && return
2668 local fid1=$(copy_file /etc/passwd $f1)
2669 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2670 wait_request_state $fid ARCHIVE SUCCEED
2673 md5sum $f >/dev/null &
2675 wait_request_state $fid RESTORE STARTED
2677 mv $f1 $f || error "mv $f1 $f failed"
2678 # mv must not block during restore
2679 wait_request_state $fid RESTORE STARTED
2681 wait_request_state $fid RESTORE SUCCEED
2682 # check md5sum pgm finished
2683 local there=$(ps -o pid,comm hp $pid >/dev/null)
2684 [[ -z $there ]] || error "Restore initiator does not exit"
2686 local rc=$(wait $pid)
2687 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2690 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2694 run_test 35 "Overwrite file during restore"
2697 # test needs a running copytool
2702 local f=$DIR/$tdir/$tfile
2704 fid=$(make_large_for_progress $f)
2705 [ $? != 0 ] && skip "not enough free space" && return
2707 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2708 wait_request_state $fid ARCHIVE SUCCEED
2711 md5sum $f >/dev/null &
2713 wait_request_state $fid RESTORE STARTED
2716 # rm must not block during restore
2717 wait_request_state $fid RESTORE STARTED
2719 wait_request_state $fid RESTORE SUCCEED
2720 # check md5sum pgm finished
2721 local there=$(ps -o pid,comm hp $pid >/dev/null)
2723 error "Restore initiator does not exit"
2725 local rc=$(wait $pid)
2727 error "Restore initiator failed with $rc"
2731 run_test 36 "Move file during restore"
2734 # LU-5683: check that an archived dirty file can be rearchived.
2736 copytool_setup $SINGLEAGT $MOUNT2
2739 local f=$DIR/$tdir/$tfile
2742 fid=$(make_small $f) || error "cannot create small file"
2744 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2745 wait_request_state $fid ARCHIVE SUCCEED
2746 $LFS hsm_release $f || error "cannot release $f"
2749 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2752 wait_request_state $fid ARCHIVE SUCCEED
2756 run_test 37 "re-archive a dirty file"
2763 for n in $(seq 1 $count); do
2764 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2766 echo "$count archive requests submitted"
2770 local stream_count=4
2771 local file_count=100
2773 local f=$DIR/$tdir/$tfile
2778 for i in $(seq 1 $file_count); do
2779 for p in $(seq 1 $stream_count); do
2780 fid=$(copy_file /etc/hosts $f.$p.$i)
2783 # force copytool to use a local/temp archive dir to ensure best
2784 # performance vs remote/NFS mounts used in auto-tests
2785 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2788 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2790 # to be sure wait_all_done will not be mislead by previous tests
2792 wait_for_grace_delay
2794 # start archive streams in background (archive files in parallel)
2795 for p in $(seq 1 $stream_count); do
2796 multi_archive $f.$p $file_count &
2799 echo -n "Wait for all requests being enqueued..."
2805 run_test 40 "Parallel archive requests"
2808 # test needs a running copytool
2812 local f=$DIR/$tdir/$tfile
2813 local fid=$(copy_file /etc/motd $f 1)
2815 $LFS hsm_archive $f || error "could not archive file"
2816 wait_request_state $fid ARCHIVE SUCCEED
2817 check_hsm_flags $f "0x00000009"
2819 multiop_bg_pause $f O_c || error "multiop failed"
2823 client_up || client_up || true
2825 kill -USR1 $MULTIPID
2826 wait $MULTIPID || error "multiop close failed"
2828 check_hsm_flags $f "0x0000000b"
2832 run_test 52 "Opened for write file on an evicted client should be set dirty"
2835 # test needs a running copytool
2839 local f=$DIR/$tdir/$tfile
2840 local fid=$(copy_file /etc/motd $f 1)
2842 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2843 error "could not archive file"
2844 wait_request_state $fid ARCHIVE SUCCEED
2845 check_hsm_flags $f "0x00000009"
2847 multiop_bg_pause $f o_c || error "multiop failed"
2851 client_up || client_up || true
2853 kill -USR1 $MULTIPID
2854 wait $MULTIPID || error "multiop close failed"
2856 check_hsm_flags $f "0x00000009"
2860 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2863 # test needs a running copytool
2867 local f=$DIR/$tdir/$tfile
2868 local fid=$(make_large_for_progress $f)
2870 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2871 error "could not archive file"
2872 wait_request_state $fid ARCHIVE STARTED
2874 check_hsm_flags $f "0x00000001"
2876 # Avoid coordinator resending this request as soon it has failed.
2881 wait_request_state $fid ARCHIVE FAILED
2883 check_hsm_flags $f "0x00000003"
2888 run_test 54 "Write during an archive cancels it"
2891 # test needs a running copytool
2895 local f=$DIR/$tdir/$tfile
2896 local fid=$(make_large_for_progress $f)
2898 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2899 error "could not archive file"
2900 wait_request_state $fid ARCHIVE STARTED
2902 check_hsm_flags $f "0x00000001"
2904 # Avoid coordinator resending this request as soon it has failed.
2907 $TRUNCATE $f 1024 || error "truncate failed"
2909 wait_request_state $fid ARCHIVE FAILED
2911 check_hsm_flags $f "0x00000003"
2916 run_test 55 "Truncate during an archive cancels it"
2919 # test needs a running copytool
2923 local f=$DIR/$tdir/$tfile
2925 fid=$(make_large_for_progress $f)
2926 [ $? != 0 ] && skip "not enough free space" && return
2928 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2929 error "could not archive file"
2930 wait_request_state $fid ARCHIVE STARTED
2932 check_hsm_flags $f "0x00000001"
2934 # Change metadata and sync to be sure we are not changing only
2939 wait_request_state $fid ARCHIVE SUCCEED
2941 check_hsm_flags $f "0x00000009"
2945 run_test 56 "Setattr during an archive is ok"
2948 # Need one client for I/O, one for request
2949 needclients 2 || return 0
2951 # test needs a running copytool
2955 local f=$DIR/$tdir/test_archive_remote
2956 # Create a file on a remote node
2957 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2958 "count=2 conv=fsync"
2961 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2962 error "hsm_archive failed"
2963 local fid=$(path2fid $f)
2964 wait_request_state $fid ARCHIVE SUCCEED
2966 # Release and implicit restore it
2967 do_node $CLIENT2 "$LFS hsm_release $f" ||
2968 error "hsm_release failed"
2969 do_node $CLIENT2 "md5sum $f" ||
2970 error "hsm_restore failed"
2972 wait_request_state $fid RESTORE SUCCEED
2976 run_test 57 "Archive a file with dirty cache on another node"
2978 truncate_released_file() {
2982 local sz=$(stat -c %s $src_file)
2983 local f=$DIR/$tdir/$tfile
2984 local fid=$(copy_file $1 $f)
2988 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2989 error "could not archive file"
2990 wait_request_state $fid ARCHIVE SUCCEED
2992 $LFS hsm_release $f || error "could not release file"
2994 $TRUNCATE $f $trunc_to || error "truncate failed"
2997 local sz1=$(stat -c %s $f)
2998 [[ $sz1 == $trunc_to ]] ||
2999 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3002 check_hsm_flags $f "0x0000000b"
3004 local state=$(get_request_state $fid RESTORE)
3005 [[ "$state" == "SUCCEED" ]] ||
3006 error "truncate $sz does not trig restore, state = $state"
3008 $TRUNCATE $ref $trunc_to
3009 cmp $ref $f || error "file data wrong after truncate"
3015 # test needs a running copytool
3020 local sz=$(stat -c %s /etc/passwd)
3022 echo "truncate up from $sz to $((sz*2))"
3023 truncate_released_file /etc/passwd $((sz*2))
3025 echo "truncate down from $sz to $((sz/2))"
3026 truncate_released_file /etc/passwd $((sz/2))
3028 echo "truncate to 0"
3029 truncate_released_file /etc/passwd 0
3033 run_test 58 "Truncate a released file will trigger restore"
3036 # This test validates the fix for LU-4512. Ensure that the -u
3037 # option changes the progress reporting interval from the
3038 # default (30 seconds) to the user-specified interval.
3040 local progress_timeout=$((interval * 4))
3042 # test needs a new running copytool
3044 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3047 local f=$DIR/$tdir/$tfile
3049 fid=$(make_large_for_progress $f)
3050 [ $? != 0 ] && skip "not enough free space" && return
3053 local mdt=${MDT_PREFIX}${mdtidx}
3054 local mds=mds$((mdtidx + 1))
3056 # Wait for copytool to register
3057 wait_update_facet $mds \
3058 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3059 uuid 100 || error "coyptool failed to register with $mdt"
3061 local start_at=$(date +%s)
3062 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3063 error "could not archive file"
3065 local agent=$(facet_active_host $SINGLEAGT)
3066 local prefix=$TESTLOG_PREFIX
3067 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3068 local copytool_log=$prefix.copytool_log.$agent.log
3071 wait_update $agent \
3072 "grep -o start.copy $copytool_log" "start copy" 100 ||
3073 error "copytool failed to start"
3075 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3076 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3082 echo -n "Expecting a progress update within $progress_timeout seconds... "
3084 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3085 if [ $RESULT -gt 0 ]; then
3086 echo "$RESULT bytes copied in $WAIT seconds."
3088 elif [ $WAIT -ge $progress_timeout ]; then
3089 error "Timed out waiting for progress update!"
3092 WAIT=$((WAIT + sleep))
3096 local finish_at=$(date +%s)
3097 local elapsed=$((finish_at - start_at))
3099 # Ensure that the progress update occurred within the expected window.
3100 if [ $elapsed -lt $interval ]; then
3101 error "Expected progress update after at least $interval seconds"
3107 run_test 60 "Changing progress update interval from default"
3110 # test needs a new running copytool
3112 copytool_monitor_setup
3113 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3115 # Just start and stop the copytool to generate events.
3118 # Wait for the copytool to register.
3119 wait_update --verbose $(facet_active_host mds1) \
3120 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3122 error "copytool failed to register with MDT0000"
3126 local REGISTER_EVENT
3127 local UNREGISTER_EVENT
3128 while read event; do
3129 local parsed=$(parse_json_event "$event")
3130 if [ -z "$parsed" ]; then
3131 error "Copytool sent malformed event: $event"
3135 if [ $event_type == "REGISTER" ]; then
3136 REGISTER_EVENT=$event
3137 elif [ $event_type == "UNREGISTER" ]; then
3138 UNREGISTER_EVENT=$event
3140 done < <(echo $"$(get_copytool_event_log)")
3142 if [ -z "$REGISTER_EVENT" ]; then
3143 error "Copytool failed to send register event to FIFO"
3146 if [ -z "$UNREGISTER_EVENT" ]; then
3147 error "Copytool failed to send unregister event to FIFO"
3150 copytool_monitor_cleanup
3151 echo "Register/Unregister events look OK."
3153 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3156 # Bump progress interval for livelier events.
3159 # test needs a new running copytool
3161 copytool_monitor_setup
3162 HSMTOOL_UPDATE_INTERVAL=$interval \
3163 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3166 local f=$DIR/$tdir/$tfile
3168 fid=$(make_large_for_progress $f)
3169 [ $? != 0 ] && skip "not enough free space" && return
3171 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3172 error "could not archive file"
3173 wait_request_state $fid ARCHIVE SUCCEED
3175 local expected_fields="event_time data_fid source_fid"
3176 expected_fields+=" total_bytes current_bytes"
3180 while read event; do
3181 # Make sure we're not getting anything from previous events.
3182 for field in $expected_fields; do
3186 local parsed=$(parse_json_event "$event")
3187 if [ -z "$parsed" ]; then
3188 error "Copytool sent malformed event: $event"
3192 if [ $event_type == "ARCHIVE_START" ]; then
3195 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3198 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3202 # Do some simple checking of the progress update events.
3203 for expected_field in $expected_fields; do
3204 if [ -z ${!expected_field+x} ]; then
3205 error "Missing $expected_field field in event"
3209 if [ $total_bytes -eq 0 ]; then
3210 error "Expected total_bytes to be > 0"
3213 # These should be identical throughout an archive
3215 if [ $source_fid != $data_fid ]; then
3216 error "Expected source_fid to equal data_fid"
3218 done < <(echo $"$(get_copytool_event_log)")
3220 if [ -z "$START_EVENT" ]; then
3221 error "Copytool failed to send archive start event to FIFO"
3224 if [ -z "$FINISH_EVENT" ]; then
3225 error "Copytool failed to send archive finish event to FIFO"
3228 echo "Archive events look OK."
3232 copytool_monitor_cleanup
3234 run_test 71 "Copytool logs JSON archive events to FIFO"
3237 # Bump progress interval for livelier events.
3240 # test needs a new running copytool
3242 copytool_monitor_setup
3243 HSMTOOL_UPDATE_INTERVAL=$interval \
3244 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3245 local test_file=$HSMTOOL_MONITOR_DIR/file
3247 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3249 do_facet $SINGLEAGT "$cmd" ||
3250 error "cannot create $test_file on $SINGLEAGT"
3251 copy2archive $test_file $tdir/$tfile
3254 local f=$DIR/$tdir/$tfile
3255 import_file $tdir/$tfile $f
3256 f=$DIR2/$tdir/$tfile
3257 echo "Verifying released state: "
3258 check_hsm_flags $f "0x0000000d"
3260 local fid=$(path2fid $f)
3262 wait_request_state $fid RESTORE SUCCEED
3264 local expected_fields="event_time data_fid source_fid"
3265 expected_fields+=" total_bytes current_bytes"
3269 while read event; do
3270 # Make sure we're not getting anything from previous events.
3271 for field in $expected_fields; do
3275 local parsed=$(parse_json_event "$event")
3276 if [ -z "$parsed" ]; then
3277 error "Copytool sent malformed event: $event"
3281 if [ $event_type == "RESTORE_START" ]; then
3283 if [ $source_fid != $data_fid ]; then
3284 error "source_fid should == data_fid at start"
3287 elif [ $event_type == "RESTORE_FINISH" ]; then
3289 if [ $source_fid != $data_fid ]; then
3290 error "source_fid should == data_fid at finish"
3293 elif [ $event_type != "RESTORE_RUNNING" ]; then
3297 # Do some simple checking of the progress update events.
3298 for expected_field in $expected_fields; do
3299 if [ -z ${!expected_field+x} ]; then
3300 error "Missing $expected_field field in event"
3304 if [ $total_bytes -eq 0 ]; then
3305 error "Expected total_bytes to be > 0"
3308 # When a restore starts out, the data fid is the same as the
3309 # source fid. After the restore has gotten going, we learn
3310 # the new data fid. Once the restore has finished, the source
3311 # fid is set to the new data fid.
3313 # We test this because some monitoring software may depend on
3314 # this behavior. If it changes, then the consumers of these
3315 # events may need to be modified.
3316 if [ $source_fid == $data_fid ]; then
3317 error "source_fid should != data_fid during restore"
3319 done < <(echo $"$(get_copytool_event_log)")
3321 if [ -z "$START_EVENT" ]; then
3322 error "Copytool failed to send restore start event to FIFO"
3325 if [ -z "$FINISH_EVENT" ]; then
3326 error "Copytool failed to send restore finish event to FIFO"
3329 echo "Restore events look OK."
3333 copytool_monitor_cleanup
3337 run_test 72 "Copytool logs JSON restore events to FIFO"
3340 file_count=51 # Max number of files constrained by LNET message size
3341 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3342 local f=$DIR/$tdir/$tfile
3343 local FILELIST=/tmp/filelist.txt
3347 for i in $(seq 1 $file_count); do
3348 fid=$(copy_file /etc/hosts $f.$i)
3349 echo $f.$i >> $FILELIST
3351 # force copytool to use a local/temp archive dir to ensure best
3352 # performance vs remote/NFS mounts used in auto-tests
3353 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3356 local dai=$(get_hsm_param default_archive_id)
3357 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3359 # to be sure wait_all_done will not be mislead by previous tests
3361 wait_for_grace_delay
3362 $LFS hsm_archive --filelist $FILELIST ||
3363 error "cannot archive a file list"
3365 $LFS hsm_release --filelist $FILELIST ||
3366 error "cannot release a file list"
3367 $LFS hsm_restore --filelist $FILELIST ||
3368 error "cannot restore a file list"
3372 run_test 90 "Archive/restore a file list"
3374 double_verify_reset_hsm_param() {
3376 echo "Testing $HSM_PARAM.$p"
3377 local val=$(get_hsm_param $p)
3379 local val2=$(($val * 2))
3380 set_hsm_param $p $val2
3381 val=$(get_hsm_param $p)
3382 [[ $val == $val2 ]] ||
3383 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3384 echo "Set $p to 0 must failed"
3388 set_hsm_param $p $save
3390 if [[ $rc == 0 ]]; then
3391 error "we must not be able to set $HSM_PARAM.$p to 0"
3396 double_verify_reset_hsm_param loop_period
3397 double_verify_reset_hsm_param grace_delay
3398 double_verify_reset_hsm_param active_request_timeout
3399 double_verify_reset_hsm_param max_requests
3400 double_verify_reset_hsm_param default_archive_id
3402 run_test 100 "Set coordinator /proc tunables"
3409 run_test 102 "Verify coordinator control"
3412 # test needs a running copytool
3419 for i in $(seq 1 20); do
3420 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3426 echo "Current requests"
3427 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3428 $HSM_PARAM.actions |\
3429 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3431 [[ -z "$res" ]] || error "Some request have not been canceled"
3435 run_test 103 "Purge all requests"
3440 # test needs a running copytool
3444 local f=$DIR/$tdir/$tfile
3446 fid=$(make_large_for_progress $f)
3447 [ $? != 0 ] && skip "not enough free space" && return
3449 # if cdt is on, it can serve too quickly the request
3451 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3452 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3453 $HSM_PARAM.actions |\
3454 grep $fid | cut -f16 -d=")
3457 [[ "$data1" == "$DATAHEX" ]] ||
3458 error "Data field in records is ($data1) and not ($DATAHEX)"
3462 run_test 104 "Copy tool data field"
3469 for i in $(seq -w 1 10); do
3470 cp /etc/passwd $DIR/$tdir/$i
3471 $LFS hsm_archive $DIR/$tdir/$i
3473 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3474 $HSM_PARAM.actions |\
3475 grep WAITING | wc -l")
3478 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3479 $HSM_PARAM.actions |\
3480 grep WAITING | wc -l")
3483 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3484 error "Requests count after shutdown $reqcnt2 != "\
3485 "before shutdown $reqcnt1"
3487 run_test 105 "Restart of coordinator"
3489 get_agent_by_uuid_mdt() {
3492 local mds=mds$(($mdtidx + 1))
3493 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3497 check_agent_registered_by_mdt() {
3500 local mds=mds$(($mdtidx + 1))
3501 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3502 if [[ ! -z "$agent" ]]; then
3503 echo "found agent $agent on $mds"
3505 error "uuid $uuid not found in agent list on $mds"
3509 check_agent_unregistered_by_mdt() {
3512 local mds=mds$(($mdtidx + 1))
3513 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3514 if [[ -z "$agent" ]]; then
3515 echo "uuid not found in agent list on $mds"
3517 error "uuid found in agent list on $mds: $agent"
3521 check_agent_registered() {
3524 for mdsno in $(seq 1 $MDSCOUNT); do
3525 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3529 check_agent_unregistered() {
3532 for mdsno in $(seq 1 $MDSCOUNT); do
3533 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3538 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3540 # Lustre mount-point is mandatory and last parameter on
3541 # copytool cmd-line.
3542 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3543 grep -v pgrep | awk '{print $NF}')
3544 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3546 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3550 # test needs a running copytool
3553 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3555 check_agent_registered $uuid
3557 search_copytools || error "No copytool found"
3560 check_agent_unregistered $uuid
3563 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3564 check_agent_registered $uuid
3568 run_test 106 "Copytool register/unregister"
3571 # test needs a running copytool
3573 # create and archive file
3575 local f1=$DIR/$tdir/$tfile
3576 local fid=$(copy_file /etc/passwd $f1)
3577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3578 wait_request_state $fid ARCHIVE SUCCEED
3579 # shutdown and restart MDS
3581 # check the copytool still gets messages from MDT
3582 local f2=$DIR/$tdir/2
3583 local fid=$(copy_file /etc/passwd $f2)
3584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3585 # main check of this sanity: this request MUST succeed
3586 wait_request_state $fid ARCHIVE SUCCEED
3589 run_test 107 "Copytool re-register after MDS restart"
3591 policy_set_and_test()
3595 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3596 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3597 [[ "$policy" == "$target" ]] ||
3598 error "Wrong policy after '$change': '$policy' != '$target'"
3602 # to force default policy setting if error
3603 CDT_POLICY_HAD_CHANGED=true
3605 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3606 local default="NonBlockingRestore [NoRetryAction]"
3607 [[ "$policy" == "$default" ]] ||
3608 error "default policy has changed,"\
3609 " '$policy' != '$default' update the test"
3610 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3611 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3612 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3613 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3614 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3615 # useless bacause we know but safer for futur changes to use real value
3616 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3617 echo "Next set_param must failed"
3618 policy_set_and_test "wrong" "$policy"
3621 echo "Back to default policy"
3622 cdt_set_sanity_policy
3624 run_test 109 "Policy display/change"
3627 # test needs a running copytool
3632 copy2archive /etc/passwd $tdir/$tfile
3634 local f=$DIR/$tdir/$tfile
3635 import_file $tdir/$tfile $f
3636 local fid=$(path2fid $f)
3638 cdt_set_non_blocking_restore
3643 wait_request_state $fid RESTORE SUCCEED
3644 cdt_clear_non_blocking_restore
3648 error "md5sum returns $st != 1, "\
3649 "should also perror ENODATA (No data available)"
3653 run_test 110a "Non blocking restore policy (import case)"
3656 # test needs a running copytool
3660 local f=$DIR/$tdir/$tfile
3661 local fid=$(copy_file /etc/passwd $f)
3662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3663 wait_request_state $fid ARCHIVE SUCCEED
3666 cdt_set_non_blocking_restore
3671 wait_request_state $fid RESTORE SUCCEED
3672 cdt_clear_non_blocking_restore
3676 error "md5sum returns $st != 1, "\
3677 "should also perror ENODATA (No data available)"
3681 run_test 110b "Non blocking restore policy (release case)"
3684 # test needs a running copytool
3688 copy2archive /etc/passwd $tdir/$tfile
3690 local f=$DIR/$tdir/$tfile
3692 import_file $tdir/$tfile $f
3693 local fid=$(path2fid $f)
3697 copytool_remove_backend $fid
3700 wait_request_state $fid RESTORE FAILED
3707 [[ $st == 0 ]] || error "Restore does not failed"
3711 run_test 111a "No retry policy (import case), restore will error"\
3712 " (No such file or directory)"
3715 # test needs a running copytool
3719 local f=$DIR/$tdir/$tfile
3720 local fid=$(copy_file /etc/passwd $f)
3722 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3723 wait_request_state $fid ARCHIVE SUCCEED
3726 copytool_remove_backend $fid
3729 wait_request_state $fid RESTORE FAILED
3736 [[ $st == 0 ]] || error "Restore does not failed"
3740 run_test 111b "No retry policy (release case), restore will error"\
3741 " (No such file or directory)"
3744 # test needs a running copytool
3748 local f=$DIR/$tdir/$tfile
3749 local fid=$(copy_file /etc/passwd $f)
3751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3752 local l=$($LFS hsm_action $f)
3754 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3758 wait_request_state $fid ARCHIVE SUCCEED
3761 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3765 run_test 112 "State of recorded request"
3768 # test needs a running copytool
3772 local f=$DIR/$tdir/$tfile
3774 fid=$(make_large_for_cancel $f)
3775 [ $? != 0 ] && skip "not enough free space" && return
3777 # test with cdt on is made in test_221
3779 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3780 # wait archive to register at CDT
3781 wait_request_state $fid ARCHIVE WAITING
3784 wait_request_state $fid ARCHIVE CANCELED
3785 wait_request_state $fid CANCEL SUCCEED
3789 run_test 200 "Register/Cancel archive"
3792 # test needs a running copytool
3796 local f=$DIR/$tdir/$tfile
3797 make_archive $tdir/$tfile
3798 import_file $tdir/$tfile $f
3799 local fid=$(path2fid $f)
3801 # test with cdt on is made in test_222
3804 # wait restore to register at CDT
3805 wait_request_state $fid RESTORE WAITING
3808 wait_request_state $fid RESTORE CANCELED
3809 wait_request_state $fid CANCEL SUCCEED
3813 run_test 201 "Register/Cancel restore"
3816 # test needs a running copytool
3820 local f=$DIR/$tdir/$tfile
3822 fid=$(make_large_for_progress $f)
3823 [ $? != 0 ] && skip "not enough free space" && return
3825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3826 wait_request_state $fid ARCHIVE SUCCEED
3830 # wait remove to register at CDT
3831 wait_request_state $fid REMOVE WAITING
3834 wait_request_state $fid REMOVE CANCELED
3838 run_test 202 "Register/Cancel remove"
3841 # test needs a running copytool
3846 local f=$DIR/$tdir/$tfile
3847 local fid=$(copy_file /etc/passwd $f)
3851 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3852 wait_request_state $fid ARCHIVE SUCCEED
3854 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3858 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3862 run_test 220 "Changelog for archive"
3865 # test needs a running copytool
3870 local f=$DIR/$tdir/$tfile
3872 fid=$(make_large_for_cancel $f)
3873 [ $? != 0 ] && skip "not enough free space" && return
3877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3878 wait_request_state $fid ARCHIVE STARTED
3880 wait_request_state $fid ARCHIVE CANCELED
3881 wait_request_state $fid CANCEL SUCCEED
3883 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3886 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3890 run_test 221 "Changelog for archive canceled"
3893 # test needs a running copytool
3897 copy2archive /etc/passwd $tdir/$tfile
3899 local f=$DIR/$tdir/$tfile
3900 import_file $tdir/$tfile $f
3901 local fid=$(path2fid $f)
3906 wait_request_state $fid RESTORE SUCCEED
3908 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3911 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3915 run_test 222a "Changelog for explicit restore"
3918 # test needs a running copytool
3922 local f=$DIR/$tdir/$tfile
3923 local fid=$(copy_file /etc/passwd $f)
3926 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3927 wait_request_state $fid ARCHIVE SUCCEED
3932 wait_request_state $fid RESTORE SUCCEED
3934 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3937 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3941 run_test 222b "Changelog for implicit restore"
3944 # test needs a running copytool
3949 local f=$DIR/$tdir/$tfile
3950 make_archive $tdir/$tfile
3954 import_file $tdir/$tfile $f
3955 local fid=$(path2fid $f)
3958 wait_request_state $fid RESTORE STARTED
3960 wait_request_state $fid RESTORE CANCELED
3961 wait_request_state $fid CANCEL SUCCEED
3963 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3966 [[ $flags == $target ]] ||
3967 error "Changelog flag is $flags not $target"
3971 run_test 223a "Changelog for restore canceled (import case)"
3974 # test needs a running copytool
3979 local f=$DIR/$tdir/$tfile
3981 fid=$(make_large_for_progress $f)
3982 [ $? != 0 ] && skip "not enough free space" && return
3985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3986 wait_request_state $fid ARCHIVE SUCCEED
3989 wait_request_state $fid RESTORE STARTED
3991 wait_request_state $fid RESTORE CANCELED
3992 wait_request_state $fid CANCEL SUCCEED
3994 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3997 [[ $flags == $target ]] ||
3998 error "Changelog flag is $flags not $target"
4002 run_test 223b "Changelog for restore canceled (release case)"
4005 # test needs a running copytool
4010 local f=$DIR/$tdir/$tfile
4011 local fid=$(copy_file /etc/passwd $f)
4014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4015 wait_request_state $fid ARCHIVE SUCCEED
4018 wait_request_state $fid REMOVE SUCCEED
4020 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4023 [[ $flags == $target ]] ||
4024 error "Changelog flag is $flags not $target"
4028 run_test 224 "Changelog for remove"
4031 # test needs a running copytool
4034 # test is not usable because remove request is too fast
4035 # so it is always finished before cancel can be done ...
4036 echo "Test disabled"
4041 local f=$DIR/$tdir/$tfile
4043 fid=$(make_large_for_progress $f)
4044 [ $? != 0 ] && skip "not enough free space" && return
4047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4048 wait_request_state $fid ARCHIVE SUCCEED
4050 # if cdt is on, it can serve too quickly the request
4055 wait_request_state $fid REMOVE CANCELED
4056 wait_request_state $fid CANCEL SUCCEED
4058 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4059 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4060 tail -n 1 | awk '{print $5}')
4063 [[ $flags == $target ]] ||
4064 error "Changelog flag is $flags not $target"
4068 run_test 225 "Changelog for remove canceled"
4071 # test needs a running copytool
4076 local f1=$DIR/$tdir/$tfile-1
4077 local f2=$DIR/$tdir/$tfile-2
4078 local f3=$DIR/$tdir/$tfile-3
4079 local fid1=$(copy_file /etc/passwd $f1)
4080 local fid2=$(copy_file /etc/passwd $f2)
4081 copy_file /etc/passwd $f3
4084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4085 wait_request_state $fid1 ARCHIVE SUCCEED
4087 $LFS hsm_archive $f2
4088 wait_request_state $fid2 ARCHIVE SUCCEED
4090 rm $f1 || error "rm $f1 failed"
4092 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4095 [[ $flags == $target ]] ||
4096 error "Changelog flag is $flags not $target"
4098 mv $f3 $f2 || error "mv $f3 $f2 failed"
4100 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4103 [[ $flags == $target ]] ||
4104 error "Changelog flag is $flags not $target"
4108 run_test 226 "changelog for last rm/mv with exiting archive"
4110 check_flags_changes() {
4118 $LFS hsm_set --$hsm_flag $f ||
4119 error "Cannot set $hsm_flag on $f"
4120 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4121 local seen=${#flags[*]}
4123 [[ $seen == $cnt ]] ||
4124 error "set $hsm_flag: Changelog events $seen != $cnt"
4125 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4126 error "set $hsm_flag: Changelog flags are "\
4127 "${flags[$((cnt - 1))]} not $target"
4129 $LFS hsm_clear --$hsm_flag $f ||
4130 error "Cannot clear $hsm_flag on $f"
4131 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4134 [[ $cnt == $seen ]] ||
4135 error "clear $hsm_flag: Changelog events $seen != $cnt"
4137 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4138 error "clear $hsm_flag: Changelog flag is "\
4139 "${flags[$((cnt - 1))]} not $target"
4143 # test needs a running copytool
4150 for i in norelease noarchive exists archived
4152 local f=$DIR/$tdir/$tfile-$i
4153 local fid=$(copy_file /etc/passwd $f)
4154 check_flags_changes $f $fid $i 0 1
4157 f=$DIR/$tdir/$tfile---lost
4158 fid=$(copy_file /etc/passwd $f)
4159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4160 wait_request_state $fid ARCHIVE SUCCEED
4161 check_flags_changes $f $fid lost 3 1
4165 run_test 227 "changelog when explicit setting of HSM flags"
4168 # test needs a running copytool
4171 local fid=$(make_small_sync $DIR/$tfile)
4172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4173 wait_request_state $fid ARCHIVE SUCCEED
4175 $LFS hsm_release $DIR/$tfile
4176 check_hsm_flags $DIR/$tfile "0x0000000d"
4178 filefrag $DIR/$tfile | grep " 1 extent found" ||
4179 error "filefrag on released file must return only one extent"
4181 # only newer versions of cp detect sparse files by stat/FIEMAP
4183 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4184 error "copying $DIR/$tfile"
4185 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4187 $LFS hsm_release $DIR/$tfile
4188 check_hsm_flags $DIR/$tfile "0x0000000d"
4190 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4192 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4194 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4195 error "comparing untarred $DIR/$tfile"
4197 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4198 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4201 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4204 # test needs a running copytool
4208 local maxrequest=$(get_hsm_param max_requests)
4209 local rqcnt=$(($maxrequest * 3))
4213 for i in $(seq -w 1 $rqcnt); do
4215 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4217 # we do it in 2 steps, so all requests arrive at the same time
4218 for i in $(seq -w 1 $rqcnt); do
4219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4224 while [[ $cnt != 0 || $wt != 0 ]]; do
4226 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4227 $HSM_PARAM.actions |\
4228 grep STARTED | grep -v CANCEL | wc -l")
4229 [[ $cnt -le $maxrequest ]] ||
4230 error "$cnt > $maxrequest too many started requests"
4231 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4232 $HSM_PARAM.actions |\
4233 grep WAITING | wc -l")
4234 echo "max=$maxrequest started=$cnt waiting=$wt"
4239 run_test 250 "Coordinator max request"
4242 # test needs a running copytool
4246 local f=$DIR/$tdir/$tfile
4248 fid=$(make_large_for_cancel $f)
4249 [ $? != 0 ] && skip "not enough free space" && return
4252 # to have a short test
4253 local old_to=$(get_hsm_param active_request_timeout)
4254 set_hsm_param active_request_timeout 4
4255 # to be sure the cdt will wake up frequently so
4256 # it will be able to cancel the "old" request
4257 local old_loop=$(get_hsm_param loop_period)
4258 set_hsm_param loop_period 2
4261 # clear locks to avoid extra delay caused by flush/cancel
4262 # and thus prevent early copytool death to timeout.
4263 cancel_lru_locks osc
4265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4266 wait_request_state $fid ARCHIVE STARTED
4268 wait_request_state $fid ARCHIVE CANCELED
4270 set_hsm_param active_request_timeout $old_to
4271 set_hsm_param loop_period $old_loop
4275 run_test 251 "Coordinator request timeout"
4278 # the only way to test ondisk conf is to restart MDS ...
4279 echo "Stop coordinator and remove coordinator state at mount"
4282 # clean on disk conf set by default
4283 cdt_clear_mount_state
4284 cdt_check_state stopped
4286 # check cdt still off after umount/remount
4288 cdt_check_state stopped
4290 echo "Set coordinator start at mount, and start coordinator"
4291 cdt_set_mount_state enabled
4294 cdt_check_state enabled
4296 # check cdt still on after umount/remount
4298 cdt_check_state enabled
4300 # we are back to original state (cdt started at mount)
4302 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4305 local ai=$(get_hsm_param default_archive_id)
4306 local new=$((ai + 1))
4308 set_hsm_param default_archive_id $new -P
4310 local res=$(get_hsm_param default_archive_id)
4313 set_hsm_param default_archive_id "" "-P -d"
4315 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4317 run_test 301 "HSM tunnable are persistent"
4320 local ai=$(get_hsm_param default_archive_id)
4321 local new=$((ai + 1))
4326 set_hsm_param default_archive_id $new -P
4329 for mdtno in $(seq 1 $MDSCOUNT); do
4334 cdt_check_state enabled
4336 local res=$(get_hsm_param default_archive_id)
4339 set_hsm_param default_archive_id "" "-P -d"
4341 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4343 run_test 302 "HSM tunnable are persistent when CDT is off"
4346 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4352 local dir_mdt0=$DIR/$tdir/mdt0
4353 local dir_mdt1=$DIR/$tdir/mdt1
4355 # create 1 dir per MDT
4356 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4357 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4359 # create 1 file in each MDT
4360 local fid1=$(make_small $dir_mdt0/$tfile)
4361 local fid2=$(make_small $dir_mdt1/$tfile)
4363 # check that hsm request on mdt0 is sent to the right MDS
4364 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4365 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4366 echo "archive successful on mdt0"
4368 # check that hsm request on mdt1 is sent to the right MDS
4369 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4370 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4371 echo "archive successful on mdt1"
4374 # clean test files and directories
4375 rm -rf $dir_mdt0 $dir_mdt1
4377 run_test 400 "Single request is sent to the right MDT"
4380 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4386 local dir_mdt0=$DIR/$tdir/mdt0
4387 local dir_mdt1=$DIR/$tdir/mdt1
4389 # create 1 dir per MDT
4390 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4391 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4393 # create 1 file in each MDT
4394 local fid1=$(make_small $dir_mdt0/$tfile)
4395 local fid2=$(make_small $dir_mdt1/$tfile)
4397 # check that compound requests are shunt to the rights MDTs
4398 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4399 error "lfs hsm_archive"
4400 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4401 echo "archive successful on mdt0"
4402 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4403 echo "archive successful on mdt1"
4406 # clean test files and directories
4407 rm -rf $dir_mdt0 $dir_mdt1
4409 run_test 401 "Compound requests split and sent to their respective MDTs"
4411 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4416 local node=$(facet_active_host $facet)
4418 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4419 awk '{print $4}'); do
4420 echo "$3 $mdc on $node"
4421 do_facet $facet "$LCTL --device $mdc $state" || return 1
4426 # make sure there is no running copytool
4429 # deactivate all mdc on agent1
4430 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4432 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4434 check_agent_unregistered "uuid" # match any agent
4436 # no expected running copytool
4437 search_copytools $agent && error "Copytool start should have failed"
4440 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4442 run_test 402 "Copytool start fails if all MDTs are inactive"
4445 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4447 # make sure there is no running copytool
4450 local agent=$(facet_active_host $SINGLEAGT)
4452 # deactivate all mdc for MDT0001
4453 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4456 local uuid=$(get_agent_uuid $agent)
4457 # check the agent is registered on MDT0000, and not on MDT0001
4458 check_agent_registered_by_mdt $uuid 0
4459 check_agent_unregistered_by_mdt $uuid 1
4461 # check running copytool process
4462 search_copytools $agent || error "No running copytools on $agent"
4464 # reactivate all mdc for MDT0001
4465 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4467 # make sure the copytool is now registered to all MDTs
4468 check_agent_registered $uuid
4472 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4475 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4479 # create files on both MDT0000 and MDT0001
4482 local dir_mdt0=$DIR/$tdir/mdt0
4483 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4485 # create 1 file on mdt0
4486 local fid1=$(make_small $dir_mdt0/$tfile)
4488 # deactivate all mdc for MDT0001
4489 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4491 # send an HSM request for files in MDT0000
4492 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4494 # check for completion of files in MDT0000
4495 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4496 echo "archive successful on mdt0"
4498 # reactivate all mdc for MDT0001
4499 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4502 # clean test files and directories
4505 run_test 404 "Inactive MDT does not block requests for active MDTs"
4508 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4514 local striped_dir=$DIR/$tdir/striped_dir
4516 # create striped dir on all of MDTs
4517 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4519 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4520 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4521 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4522 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4524 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4525 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4526 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4527 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4529 # check that compound requests are shunt to the rights MDTs
4530 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4531 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4532 error "lfs hsm_archive"
4534 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4535 echo "archive successful on $fid1"
4536 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4537 echo "archive successful on $fid2"
4538 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4539 echo "archive successful on $fid3"
4540 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4541 echo "archive successful on $fid4"
4543 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4544 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4545 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4546 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4548 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4549 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4550 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4551 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4555 run_test 405 "archive and release under striped directory"
4559 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4560 skip "HSM migrate is not supported" && return
4562 # Stop the existing copytool
4565 test_mkdir -p $DIR/$tdir
4566 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4568 run_test 500 "various LLAPI HSM tests"
4573 check_and_cleanup_lustre