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: 3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # bug number for skipped test:LU-3852
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MCREATE=${MCREATE:-mcreate}
32 MOUNT_2=${MOUNT_2:-"yes"}
35 # script only handles up to 10 MDTs (because of MDT_PREFIX)
36 [ $MDSCOUNT -gt 9 ] &&
37 error "script cannot handle more than 9 MDTs, please fix" && exit
39 check_and_setup_lustre
41 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
42 skip_env "Need MDS version at least 2.4.53" && exit
45 # $RUNAS_ID may get set incorrectly somewhere else
46 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
47 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
49 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
54 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
55 # the following associated variables are added:
57 # AGTCOUNT: number of agents
58 # AGTDEV{N}: target HSM mount point (root path of the backend)
59 # agt{N}_HOST: hostname of the agent agt{N}
60 # SINGLEAGT: facet of the single agent
62 # The number of agents is initialized as the number of remote client nodes.
63 # By default, only single copytool is started on a remote client/agent. If there
64 # was no remote client, then the copytool will be started on the local client.
70 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
71 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
73 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
74 if [[ $CLIENTCOUNT -gt 1 ]] &&
75 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
76 skip_env "SHARED_DIRECTORY should be accessible"\
81 for n in $(seq $AGTCOUNT); do
82 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
83 agent=CLIENT$((n + 1))
84 if [[ -z "${!agent}" ]]; then
85 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
88 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
91 export SINGLEAGT=${SINGLEAGT:-agt1}
93 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
94 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
95 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
96 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
97 export HSMTOOL_TESTDIR
98 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
99 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
102 # The test only support up to 10 MDTs
103 MDT_PREFIX="mdt.$FSNAME-MDT000"
104 HSM_PARAM="${MDT_PREFIX}0.hsm"
106 # archive is purged at copytool setup
107 HSM_ARCHIVE_PURGE=true
110 # Get the backend root path for the given agent facet.
113 local dev=AGTDEV$(facet_number $facet)
118 # Stop copytool and unregister an existing changelog user.
120 copytool_monitor_cleanup
123 cdt_set_sanity_policy
128 # get MDT device for each mdc
129 for mdtno in $(seq 1 $MDSCOUNT); do
130 local idx=$(($mdtno - 1))
131 MDT[$idx]=$($LCTL get_param -n \
132 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
133 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
138 local agents=${1:-$(facet_active_host $SINGLEAGT)}
139 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
142 search_and_kill_copytool() {
143 local agents=${1:-$(facet_active_host $SINGLEAGT)}
145 echo "Killing existing copytools on $agents"
146 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
149 copytool_monitor_setup() {
150 local facet=${1:-$SINGLEAGT}
151 local agent=$(facet_active_host $facet)
153 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
154 local test_dir=$(do_node $agent "$cmd") ||
155 error "Failed to create tempdir on $agent"
156 export HSMTOOL_MONITOR_DIR=$test_dir
158 # Create the fifo and a monitor (cat dies when copytool dies)
159 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
160 error "failed to create copytool fifo on $agent"
161 cmd="cat $test_dir/fifo > $test_dir/events &"
162 cmd+=" echo \\\$! > $test_dir/monitor_pid"
164 if [[ $PDSH == *Rmrsh* ]]; then
165 # This is required for pdsh -Rmrsh and its handling of remote
167 # Regular ssh and pdsh -Rssh work fine without this
168 # backgrounded subshell nonsense.
169 (do_node $agent "$cmd") &
170 export HSMTOOL_MONITOR_PDSH=$!
172 # Slightly racy, but just making a best-effort to catch obvious
175 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
176 error "Failed to start copytool monitor on $agent"
178 do_node $agent "$cmd"
180 error "Failed to start copytool monitor on $agent"
185 copytool_monitor_cleanup() {
186 local facet=${1:-$SINGLEAGT}
187 local agent=$(facet_active_host $facet)
189 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
190 # Should die when the copytool dies, but just in case.
191 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
192 cmd+=" 2>/dev/null || true"
193 do_node $agent "$cmd"
194 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
195 export HSMTOOL_MONITOR_DIR=
198 # The pdsh should die on its own when the monitor dies. Just
199 # in case, though, try to clean up to avoid any cruft.
200 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
201 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
202 export HSMTOOL_MONITOR_PDSH=
207 local facet=${1:-$SINGLEAGT}
208 local lustre_mntpnt=${2:-$MOUNT}
210 local hsm_root=${4:-$(copytool_device $facet)}
211 local agent=$(facet_active_host $facet)
213 if [[ -z "$arc_id" ]] &&
214 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
215 echo "Wakeup copytool $facet on $agent"
219 if $HSM_ARCHIVE_PURGE; then
220 echo "Purging archive on $agent"
221 do_facet $facet "rm -rf $hsm_root/*"
224 echo "Starting copytool $facet on $agent"
225 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
226 # bandwidth is limited to 1MB/s so the copy time is known and
227 # independent of hardware
228 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
229 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
230 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
231 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
232 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
233 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
234 cmd+=" --bandwidth 1 $lustre_mntpnt"
236 # Redirect the standard output and error to a log file which
237 # can be uploaded to Maloo.
238 local prefix=$TESTLOG_PREFIX
239 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
240 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
242 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
243 error "start copytool $facet on $agent failed"
247 get_copytool_event_log() {
248 local facet=${1:-$SINGLEAGT}
249 local agent=$(facet_active_host $facet)
251 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
252 error "Can't get event log: No monitor directory!"
254 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
255 error "Could not collect event log from $agent"
260 local agents=${1:-$(facet_active_host $SINGLEAGT)}
266 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
268 echo "Copytool is stopped on $agents"
270 # clean all CDTs orphans requests from previous tests
271 # that would otherwise need to timeout to clear.
272 for mdtno in $(seq 1 $MDSCOUNT); do
274 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
275 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
277 # skip already stop[ed,ing] CDTs
278 echo $oldstate | grep stop && continue
280 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
281 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
283 error "mds${mdtno} cdt state is not stopped"
284 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
285 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
287 error "mds${mdtno} cdt state is not $oldstate"
292 local agents=${1:-$(facet_active_host $SINGLEAGT)}
294 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
295 echo "Copytool is suspended on $agents"
298 copytool_remove_backend() {
300 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
301 echo "Remove from backend: $fid = $be"
302 do_facet $SINGLEAGT rm -f $be
306 do_facet $SINGLEAGT \
307 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
308 --import $1 $2 $MOUNT" ||
309 error "import of $1 to $2 failed"
313 local file=$HSM_ARCHIVE/$1
314 do_facet $SINGLEAGT mkdir -p $(dirname $file)
315 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
316 error "cannot create $file"
320 local file=$HSM_ARCHIVE/$2
321 do_facet $SINGLEAGT mkdir -p $(dirname $file)
322 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
331 if [[ "$value" != "" ]]; then
334 for mdtno in $(seq 1 $MDSCOUNT); do
335 local idx=$(($mdtno - 1))
336 local facet=mds${mdtno}
337 # if $arg include -P option, run 1 set_param per MDT on the MGS
338 # else, run set_param on each MDT
339 [[ $arg = *"-P"* ]] && facet=mgs
340 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
341 [[ $? != 0 ]] && rc=1
351 for mdtno in $(seq 1 $MDSCOUNT); do
352 local idx=$(($mdtno - 1))
353 wait_result mds${mdtno} \
354 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
356 error "$key state is not '$target' on mds${mdtno}"
363 for mdtno in $(seq 1 $MDSCOUNT); do
364 local idx=$(($mdtno - 1))
365 local cl_user=$(do_facet mds${mdtno} $LCTL \
366 --device ${MDT[$idx]} \
367 changelog_register -n)
369 do_facet mds${mdtno} lctl set_param \
370 mdd.${MDT[$idx]}.changelog_mask="+hsm"
371 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
375 changelog_cleanup() {
377 for mdtno in $(seq 1 $MDSCOUNT); do
378 local idx=$(($mdtno - 1))
379 [[ -z ${CL_USERS[$idx]} ]] && continue
380 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
381 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
382 changelog_deregister ${CL_USERS[$idx]}
387 changelog_get_flags() {
392 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
397 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
405 mdts_set_param "$opt -n" "hsm.$param" "$value"
412 mdts_set_param "" hsm_control "$cmd"
413 mdts_check_param hsm_control "$target" 10
416 cdt_set_sanity_policy() {
417 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
420 mdts_set_param "" hsm.policy "+NRA"
421 mdts_set_param "" hsm.policy "-NBR"
422 CDT_POLICY_HAD_CHANGED=
427 mdts_set_param "" hsm.policy "+NRA"
428 CDT_POLICY_HAD_CHANGED=true
431 cdt_clear_no_retry() {
432 mdts_set_param "" hsm.policy "-NRA"
433 CDT_POLICY_HAD_CHANGED=true
436 cdt_set_non_blocking_restore() {
437 mdts_set_param "" hsm.policy "+NBR"
438 CDT_POLICY_HAD_CHANGED=true
441 cdt_clear_non_blocking_restore() {
442 mdts_set_param "" hsm.policy "-NBR"
443 CDT_POLICY_HAD_CHANGED=true
446 cdt_clear_mount_state() {
447 mdts_set_param "-P -d" hsm_control ""
450 cdt_set_mount_state() {
451 mdts_set_param "-P" hsm_control "$1"
455 mdts_check_param hsm_control "$1" 20
459 set_test_state disabled disabled
463 set_test_state enabled enabled
467 set_test_state shutdown stopped
471 set_test_state purge enabled
477 cdt_set_sanity_policy
481 local client_count=$1
482 if [[ $CLIENTCOUNT -lt $client_count ]]; then
483 skip "Need $client_count or more clients, have $CLIENTCOUNT"
490 $LFS path2fid $1 | tr -d '[]'
497 if [[ $u == "user" ]]; then
498 local st=$($RUNAS $LFS hsm_state $f)
500 local st=$($LFS hsm_state $f)
504 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
506 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
510 get_hsm_archive_id() {
512 local st=$($LFS hsm_state $f)
513 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
515 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
524 local st=$(get_hsm_flags $f)
525 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
528 check_hsm_flags_user() {
532 local st=$(get_hsm_flags $f user)
533 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
545 if [[ "$3" != 1 ]]; then
549 cp $1 $f || error "cannot copy $1 to $f"
550 path2fid $f || error "cannot get fid on $f"
554 local file2=${1/$DIR/$DIR2}
555 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
556 error "cannot create $file2"
557 path2fid $1 || error "cannot get fid on $1"
561 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
562 error "cannot create $1"
563 path2fid $1 || error "cannot get fid on $1"
566 cleanup_large_files() {
567 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
569 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
572 make_large_for_striping() {
573 local file2=${1/$DIR/$DIR2}
574 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
578 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
579 error "cannot create $file2"
580 path2fid $1 || error "cannot get fid on $1"
583 make_large_for_progress() {
584 local file2=${1/$DIR/$DIR2}
588 # big file is large enough, so copy time is > 30s
589 # so copytool make 1 progress
590 # size is not a multiple of 1M to avoid stripe
592 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
593 error "cannot create $file2"
594 path2fid $1 || error "cannot get fid on $1"
597 make_large_for_progress_aligned() {
598 local file2=${1/$DIR/$DIR2}
602 # big file is large enough, so copy time is > 30s
603 # so copytool make 1 progress
604 # size is a multiple of 1M to have stripe
606 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
607 error "cannot create $file2"
608 path2fid $1 || error "cannot get fid on $1"
611 make_large_for_cancel() {
612 local file2=${1/$DIR/$DIR2}
616 # Copy timeout is 100s. 105MB => 105s
617 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
618 error "cannot create $file2"
619 path2fid $1 || error "cannot get fid on $1"
625 wait_update --verbose $(facet_active_host $facet) "$@"
628 wait_request_state() {
632 # 4th arg (mdt index) is optional
634 local mds=mds$(($mdtidx + 1))
636 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
637 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
639 wait_result $mds "$cmd" $state 100 ||
640 error "request on $fid is not $state on $mds"
643 get_request_state() {
647 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
648 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
651 get_request_count() {
655 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
656 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
662 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
663 cmd+=" | egrep 'WAITING|STARTED'"
665 wait_result $SINGLEMDS "$cmd" "" $timeout ||
666 error "requests did not complete"
669 wait_for_grace_delay() {
670 local val=$(get_hsm_param grace_delay)
677 # python2.6 in EL6 includes an internal json module
678 local json_parser='import json; import fileinput;'
679 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
680 json_parser+='json.loads([line for line in '
681 json_parser+='fileinput.input()][0]).items()])'
683 echo $raw_event | python -c "$json_parser"
686 # populate MDT device array
692 # cleanup from previous bad setup
693 search_and_kill_copytool
695 # for recovery tests, coordinator needs to be started at mount
697 # the lustre conf must be without hsm on (like for sanity.sh)
698 echo "Set HSM on and start"
699 cdt_set_mount_state enabled
700 cdt_check_state enabled
702 echo "Start copytool"
705 echo "Set sanity-hsm HSM policy"
706 cdt_set_sanity_policy
708 # finished requests are quickly removed from list
709 set_hsm_param grace_delay 10
715 local f=$DIR/$tdir/$tfile
719 check_hsm_flags_user $f "0x00000000"
721 $RUNAS $LFS hsm_set --norelease $f ||
722 error "user could not change hsm flags"
723 check_hsm_flags_user $f "0x00000010"
725 $RUNAS $LFS hsm_clear --norelease $f ||
726 error "user could not clear hsm flags"
727 check_hsm_flags_user $f "0x00000000"
729 # User could not change those flags...
730 $RUNAS $LFS hsm_set --exists $f &&
731 error "user should not set this flag"
732 check_hsm_flags_user $f "0x00000000"
735 $LFS hsm_set --exists $f ||
736 error "root could not change hsm flags"
737 check_hsm_flags_user $f "0x00000001"
739 $LFS hsm_clear --exists $f ||
740 error "root could not clear hsm state"
741 check_hsm_flags_user $f "0x00000000"
744 run_test 1 "lfs hsm flags root/non-root access"
748 local f=$DIR/$tdir/$tfile
750 # New files are not dirty
751 check_hsm_flags $f "0x00000000"
753 # For test, we simulate an archived file.
754 $LFS hsm_set --exists $f || error "user could not change hsm flags"
755 check_hsm_flags $f "0x00000001"
757 # chmod do not put the file dirty
758 chmod 600 $f || error "could not chmod test file"
759 check_hsm_flags $f "0x00000001"
761 # chown do not put the file dirty
762 chown $RUNAS_ID $f || error "could not chown test file"
763 check_hsm_flags $f "0x00000001"
765 # truncate put the file dirty
766 $TRUNCATE $f 1 || error "could not truncate test file"
767 check_hsm_flags $f "0x00000003"
769 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
770 check_hsm_flags $f "0x00000001"
772 run_test 2 "Check file dirtyness when doing setattr"
778 # New files are not dirty
780 check_hsm_flags $f "0x00000000"
782 # For test, we simulate an archived file.
783 $LFS hsm_set --exists $f ||
784 error "user could not change hsm flags"
785 check_hsm_flags $f "0x00000001"
787 # Reading a file, does not set dirty
788 cat $f > /dev/null || error "could not read file"
789 check_hsm_flags $f "0x00000001"
791 # Open for write without modifying data, does not set dirty
792 openfile -f O_WRONLY $f || error "could not open test file"
793 check_hsm_flags $f "0x00000001"
795 # Append to a file sets it dirty
796 cp -p /etc/passwd $f.append || error "could not create file"
797 $LFS hsm_set --exists $f.append ||
798 error "user could not change hsm flags"
799 dd if=/etc/passwd of=$f.append bs=1 count=3\
800 conv=notrunc oflag=append status=noxfer ||
801 error "could not append to test file"
802 check_hsm_flags $f.append "0x00000003"
804 # Modify a file sets it dirty
805 cp -p /etc/passwd $f.modify || error "could not create file"
806 $LFS hsm_set --exists $f.modify ||
807 error "user could not change hsm flags"
808 dd if=/dev/zero of=$f.modify bs=1 count=3\
809 conv=notrunc status=noxfer ||
810 error "could not modify test file"
811 check_hsm_flags $f.modify "0x00000003"
813 # Open O_TRUNC sets dirty
814 cp -p /etc/passwd $f.trunc || error "could not create file"
815 $LFS hsm_set --exists $f.trunc ||
816 error "user could not change hsm flags"
817 cp /etc/group $f.trunc || error "could not override a file"
818 check_hsm_flags $f.trunc "0x00000003"
820 # Mmapped a file sets dirty
821 cp -p /etc/passwd $f.mmap || error "could not create file"
822 $LFS hsm_set --exists $f.mmap ||
823 error "user could not change hsm flags"
824 multiop $f.mmap OSMWUc || error "could not mmap a file"
825 check_hsm_flags $f.mmap "0x00000003"
827 run_test 3 "Check file dirtyness when opening for write"
831 local f=$DIR/$tdir/$tfile
832 local fid=$(make_small $f)
835 local st=$(get_request_state $fid CANCEL)
836 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
838 run_test 4 "Useless cancel must not be registered"
841 # test needs a running copytool
845 local f=$DIR/$tdir/$tfile
846 local fid=$(copy_file /etc/passwd $f)
848 wait_request_state $fid ARCHIVE SUCCEED
850 check_hsm_flags $f "0x00000009"
854 run_test 8 "Test default archive number"
858 local f=$DIR/$tdir/$tfile
859 local fid=$(copy_file /etc/passwd $f)
860 # we do not use the default one to be sure
861 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
863 copytool_setup $SINGLEAGT $MOUNT $new_an
864 $LFS hsm_archive --archive $new_an $f
865 wait_request_state $fid ARCHIVE SUCCEED
867 check_hsm_flags $f "0x00000009"
871 run_test 9 "Use of explict archive number, with dedicated copytool"
874 needclients 3 || return 0
880 copytool_cleanup $(comma_list $(agts_nodes))
882 # start all of the copytools
883 for n in $(seq $AGTCOUNT); do
887 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
890 for n in $(seq $AGTCOUNT); do
891 file=$DIR/$tdir/$tfile.$n
892 fid=$(make_small $file)
894 $LFS hsm_archive $file || error "could not archive file $file"
895 wait_request_state $fid ARCHIVE SUCCEED
896 check_hsm_flags $file "0x00000009"
900 copytool_cleanup $(comma_list $(agts_nodes))
902 run_test 9a "Multiple remote agents"
905 # test needs a running copytool
908 mkdir -p $DIR/$tdir/d1
909 local f=$DIR/$tdir/$tfile
910 local fid=$(copy_file /etc/hosts $f)
911 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
912 error "hsm_archive failed"
913 wait_request_state $fid ARCHIVE SUCCEED
915 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
916 error "fid $fid not in archive $HSM_ARCHIVE"
917 echo "Verifying content"
918 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
919 echo "Verifying hsm state "
920 check_hsm_flags $f "0x00000009"
922 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
923 local st=$(get_hsm_archive_id $f)
924 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
925 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
930 run_test 10a "Archive a file"
933 # test needs a running copytool
937 local f=$DIR/$tdir/$tfile
938 local fid=$(copy_file /etc/hosts $f)
939 $LFS hsm_archive $f || error "archive request failed"
940 wait_request_state $fid ARCHIVE SUCCEED
942 $LFS hsm_archive $f || error "archive of non dirty file failed"
943 local cnt=$(get_request_count $fid ARCHIVE)
944 [[ "$cnt" == "1" ]] ||
945 error "archive of non dirty file must not make a request"
949 run_test 10b "Archive of non dirty file must work without doing request"
952 # test needs a running copytool
956 local f=$DIR/$tdir/$tfile
957 local fid=$(copy_file /etc/hosts $f)
958 $LFS hsm_set --noarchive $f
959 $LFS hsm_archive $f && error "archive a noarchive file must fail"
963 run_test 10c "Check forbidden archive"
966 # test needs a running copytool
970 local f=$DIR/$tdir/$tfile
971 local fid=$(copy_file /etc/hosts $f)
972 $LFS hsm_archive $f || error "cannot archive $f"
973 wait_request_state $fid ARCHIVE SUCCEED
975 local ar=$(get_hsm_archive_id $f)
976 local dflt=$(get_hsm_param default_archive_id)
977 [[ $ar == $dflt ]] ||
978 error "archived file is not on default archive: $ar != $dflt"
982 run_test 10d "Archive a file on the default archive id"
986 copy2archive /etc/hosts $tdir/$tfile
987 local f=$DIR/$tdir/$tfile
989 import_file $tdir/$tfile $f
990 echo -n "Verifying released state: "
991 check_hsm_flags $f "0x0000000d"
993 local LSZ=$(stat -c "%s" $f)
994 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
996 echo "Verifying imported size $LSZ=$ASZ"
997 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
998 echo -n "Verifying released pattern: "
999 local PTRN=$($GETSTRIPE -L $f)
1001 [[ $PTRN == 80000001 ]] || error "Is not released"
1002 local fid=$(path2fid $f)
1003 echo "Verifying new fid $fid in archive"
1005 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1006 error "fid $fid not in archive $HSM_ARCHIVE"
1008 run_test 11 "Import a file"
1011 # test needs a running copytool
1015 copy2archive /etc/hosts $tdir/$tfile
1017 local f=$DIR/$tdir/$tfile
1018 import_file $tdir/$tfile $f
1019 local f=$DIR2/$tdir/$tfile
1020 echo "Verifying released state: "
1021 check_hsm_flags $f "0x0000000d"
1023 local fid=$(path2fid $f)
1025 wait_request_state $fid RESTORE SUCCEED
1027 echo "Verifying file state: "
1028 check_hsm_flags $f "0x00000009"
1030 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1032 [[ $? -eq 0 ]] || error "Restored file differs"
1036 run_test 12a "Restore an imported file explicitly"
1039 # test needs a running copytool
1043 copy2archive /etc/hosts $tdir/$tfile
1045 local f=$DIR/$tdir/$tfile
1046 import_file $tdir/$tfile $f
1047 echo "Verifying released state: "
1048 check_hsm_flags $f "0x0000000d"
1050 cat $f > /dev/null || error "File read failed"
1052 echo "Verifying file state after restore: "
1053 check_hsm_flags $f "0x00000009"
1055 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1057 [[ $? -eq 0 ]] || error "Restored file differs"
1061 run_test 12b "Restore an imported file implicitly"
1064 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1066 # test needs a running copytool
1070 local f=$DIR/$tdir/$tfile
1071 $LFS setstripe -c 2 $f
1072 local fid=$(make_large_for_striping $f)
1073 local FILE_CRC=$(md5sum $f)
1075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1076 wait_request_state $fid ARCHIVE SUCCEED
1077 $LFS hsm_release $f || error "release $f failed"
1079 echo "$FILE_CRC" | md5sum -c
1081 [[ $? -eq 0 ]] || error "Restored file differs"
1085 run_test 12c "Restore a file with stripe of 2"
1088 # test needs a running copytool
1093 local f=$DIR/$tdir/$tfile
1094 local fid=$(copy_file /etc/hosts $f)
1095 $LFS hsm_restore $f || error "restore of non archived file failed"
1096 local cnt=$(get_request_count $fid RESTORE)
1097 [[ "$cnt" == "0" ]] ||
1098 error "restore non archived must not make a request"
1099 $LFS hsm_archive $f ||
1100 error "archive request failed"
1101 wait_request_state $fid ARCHIVE SUCCEED
1102 $LFS hsm_restore $f ||
1103 error "restore of non released file failed"
1104 local cnt=$(get_request_count $fid RESTORE)
1105 [[ "$cnt" == "0" ]] ||
1106 error "restore a non dirty file must not make a request"
1110 run_test 12d "Restore of a non archived, non released file must work"\
1111 " without doing request"
1114 # test needs a running copytool
1117 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1118 local f=$DIR/$tdir/$tfile
1119 local fid=$(copy_file /etc/hosts $f)
1120 $LFS hsm_archive $f || error "archive request failed"
1121 wait_request_state $fid ARCHIVE SUCCEED
1124 cat /etc/hosts >> $f
1128 $LFS hsm_restore $f && error "restore a dirty file must fail"
1132 run_test 12e "Check forbidden restore"
1135 # test needs a running copytool
1139 local f=$DIR/$tdir/$tfile
1140 local fid=$(copy_file /etc/hosts $f)
1142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1143 wait_request_state $fid ARCHIVE SUCCEED
1144 $LFS hsm_release $f || error "release of $f failed"
1146 wait_request_state $fid RESTORE SUCCEED
1148 echo -n "Verifying file state: "
1149 check_hsm_flags $f "0x00000009"
1151 diff -q /etc/hosts $f
1153 [[ $? -eq 0 ]] || error "Restored file differs"
1157 run_test 12f "Restore a released file explicitly"
1160 # test needs a running copytool
1164 local f=$DIR/$tdir/$tfile
1165 local fid=$(copy_file /etc/hosts $f)
1167 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1168 wait_request_state $fid ARCHIVE SUCCEED
1169 $LFS hsm_release $f || error "release of $f failed"
1171 diff -q /etc/hosts $f
1174 # we check we had a restore done
1175 wait_request_state $fid RESTORE SUCCEED
1177 [[ $st -eq 0 ]] || error "Restored file differs"
1181 run_test 12g "Restore a released file implicitly"
1184 needclients 2 || return 0
1186 # test needs a running copytool
1190 local f=$DIR/$tdir/$tfile
1191 local fid=$(copy_file /etc/hosts $f)
1193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1194 wait_request_state $fid ARCHIVE SUCCEED
1195 $LFS hsm_release $f || error "release of $f failed"
1197 do_node $CLIENT2 diff -q /etc/hosts $f
1200 # we check we had a restore done
1201 wait_request_state $fid RESTORE SUCCEED
1203 [[ $st -eq 0 ]] || error "Restored file differs"
1207 run_test 12h "Restore a released file implicitly from a second node"
1210 # test needs a running copytool
1214 local f=$DIR/$tdir/$tfile
1215 local fid=$(copy_file /etc/passwd $f)
1216 $LFS hsm_archive $f || error "archive of $f failed"
1217 wait_request_state $fid ARCHIVE SUCCEED
1219 $LFS hsm_release $f || error "release of $f failed"
1223 [[ $? -eq 0 ]] || error "Restored file differs"
1227 run_test 12m "Archive/release/implicit restore"
1230 # test needs a running copytool
1234 copy2archive /etc/hosts $tdir/$tfile
1236 local f=$DIR/$tdir/$tfile
1237 import_file $tdir/$tfile $f
1239 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1240 error "Restored file differs"
1242 $LFS hsm_release $f || error "release of $f failed"
1246 run_test 12n "Import/implicit restore/release"
1249 # test needs a running copytool
1253 local f=$DIR/$tdir/$tfile
1254 local fid=$(copy_file /etc/hosts $f)
1256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1257 wait_request_state $fid ARCHIVE SUCCEED
1258 $LFS hsm_release $f || error "release of $f failed"
1260 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1261 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1263 # set no retry action mode
1266 diff -q /etc/hosts $f
1269 # we check we had a restore failure
1270 wait_request_state $fid RESTORE FAILED
1272 [[ $st -eq 0 ]] && error "Restore must fail"
1274 # remove no retry action mode
1277 # check file is still released
1278 check_hsm_flags $f "0x0000000d"
1280 # retry w/o failure injection
1281 do_facet $SINGLEMDS lctl set_param fail_loc=0
1283 # to be sure previous RESTORE result is gone
1285 wait_for_grace_delay
1287 diff -q /etc/hosts $f
1290 # we check we had a restore done
1291 wait_request_state $fid RESTORE SUCCEED
1293 [[ $st -eq 0 ]] || error "Restored file differs"
1297 run_test 12o "Layout-swap failure during Restore leaves file released"
1300 # test needs a running copytool
1303 local ARC_SUBDIR="import.orig"
1307 # populate directory to be imported
1308 for d in $(seq 1 10); do
1309 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1310 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1311 for f in $(seq 1 10); do
1312 CURR_FILE="$CURR_DIR/$tfile.$f"
1313 # write file-specific data
1314 do_facet $SINGLEAGT \
1315 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1316 "file=$CURR_FILE > $CURR_FILE"
1320 import_file "$ARC_SUBDIR" $DIR/$tdir
1321 # diff lustre content and origin (triggers file restoration)
1322 # there must be 10x10 identical files, and no difference
1323 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1324 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1325 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1326 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1328 [ $cnt_diff -eq 0 ] ||
1329 error "$cnt_diff imported files differ from read data"
1330 [ $cnt_ok -eq 100 ] ||
1331 error "not enough identical files ($cnt_ok != 100)"
1335 run_test 13 "Recursively import and restore a directory"
1338 # test needs a running copytool
1343 local f=$DIR/$tdir/$tfile
1344 local fid=$(make_small $f)
1345 local sum=$(md5sum $f | awk '{print $1}')
1346 $LFS hsm_archive $f || error "could not archive file"
1347 wait_request_state $fid ARCHIVE SUCCEED
1351 # create released file (simulate llapi_hsm_import call)
1353 local fid2=$(path2fid $f)
1354 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1355 $LFS hsm_release $f || error "could not release file"
1357 # rebind the archive to the newly created file
1358 echo "rebind $fid to $fid2"
1360 do_facet $SINGLEAGT \
1361 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1362 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1364 # restore file and compare md5sum
1365 local sum2=$(md5sum $f | awk '{print $1}')
1367 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1371 run_test 14 "Rebind archived file to a new fid"
1374 # test needs a running copytool
1379 local f=$DIR/$tdir/$tfile
1381 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1385 for i in $(seq 1 $count); do
1386 fids[$i]=$(make_small $f.$i)
1387 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1388 $LFS hsm_archive $f.$i || error "could not archive file"
1390 wait_all_done $(($count*60))
1394 for i in $(seq 1 $count); do
1397 local fid2=$(path2fid $f.$i)
1398 # add the rebind operation to the list
1399 echo ${fids[$i]} $fid2 >> $tmpfile
1401 # set it released (simulate llapi_hsm_import call)
1402 $LFS hsm_set --archived --exists $f.$i ||
1403 error "could not force hsm flags"
1404 $LFS hsm_release $f.$i || error "could not release file"
1406 nl=$(wc -l < $tmpfile)
1407 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1409 echo "rebind list of files"
1410 do_facet $SINGLEAGT \
1411 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1412 --rebind $tmpfile $DIR" || error "could not rebind file list"
1414 # restore files and compare md5sum
1415 for i in $(seq 1 $count); do
1416 local sum2=$(md5sum $f.$i | awk '{print $1}')
1417 [[ $sum2 == ${sums[$i]} ]] ||
1418 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1424 run_test 15 "Rebind a list of files"
1427 # test needs a running copytool
1431 # create a known size file so we can verify transfer speed
1434 dd if=/dev/zero of=$ref bs=1M count=20
1437 local f=$DIR/$tdir/$tfile
1438 local fid=$(copy_file $ref $f)
1440 local start=$(date +%s)
1442 wait_request_state $fid ARCHIVE SUCCEED
1443 local end=$(date +%s)
1444 local duration=$((end - start))
1446 [[ $duration -ge $goal ]] ||
1447 error "Transfer is too fast $duration < $goal"
1451 run_test 16 "Test CT bandwith control option"
1456 local f=$DIR/$tdir/$tfile
1457 touch $f || error "touch $f failed"
1459 # Could not release a non-archived file
1460 $LFS hsm_release $f && error "release should not succeed"
1462 # For following tests, we must test them with HS_ARCHIVED set
1463 $LFS hsm_set --exists --archived $f || error "could not add flag"
1465 # Could not release a file if no-release is set
1466 $LFS hsm_set --norelease $f || error "could not add flag"
1467 $LFS hsm_release $f && error "release should not succeed"
1468 $LFS hsm_clear --norelease $f || error "could not remove flag"
1470 # Could not release a file if lost
1471 $LFS hsm_set --lost $f || error "could not add flag"
1472 $LFS hsm_release $f && error "release should not succeed"
1473 $LFS hsm_clear --lost $f || error "could not remove flag"
1475 # Could not release a file if dirty
1476 $LFS hsm_set --dirty $f || error "could not add flag"
1477 $LFS hsm_release $f && error "release should not succeed"
1478 $LFS hsm_clear --dirty $f || error "could not remove flag"
1480 run_test 20 "Release is not permitted"
1483 # test needs a running copytool
1487 local f=$DIR/$tdir/test_release
1489 # Create a file and check its states
1490 local fid=$(make_small $f)
1491 check_hsm_flags $f "0x00000000"
1493 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1494 # used until file is flushed to disk
1495 if [ $(facet_fstype ost1) == "zfs" ]; then
1496 # this causes an OST_SYNC rpc to be sent
1497 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1498 # clear locks to reread file data
1499 cancel_lru_locks osc
1502 local orig_size=$(stat -c "%s" $f)
1503 local orig_blocks=$(stat -c "%b" $f)
1505 start_full_debug_logging
1507 $LFS hsm_archive $f || error "could not archive file"
1508 wait_request_state $fid ARCHIVE SUCCEED
1510 local blocks=$(stat -c "%b" $f)
1511 [ $blocks -eq $orig_blocks ] ||
1512 error "$f: wrong block number after archive: " \
1513 "$blocks != $orig_blocks"
1514 local size=$(stat -c "%s" $f)
1515 [ $size -eq $orig_size ] ||
1516 error "$f: wrong size after archive: $size != $orig_size"
1518 # Release and check states
1519 $LFS hsm_release $f || error "could not release file"
1520 check_hsm_flags $f "0x0000000d"
1522 blocks=$(stat -c "%b" $f)
1523 [ $blocks -gt 5 ] &&
1524 error "$f: too many blocks after release: $blocks > 5"
1525 size=$(stat -c "%s" $f)
1526 [ $size -ne $orig_size ] &&
1527 error "$f: wrong size after release: $size != $orig_size"
1529 # Check we can release an file without stripe info
1533 check_hsm_flags $f "0x00000000"
1534 $LFS hsm_archive $f || error "could not archive file"
1535 wait_request_state $fid ARCHIVE SUCCEED
1537 # Release and check states
1538 $LFS hsm_release $f || error "could not release file"
1539 check_hsm_flags $f "0x0000000d"
1541 # Release again a file that is already released is OK
1542 $LFS hsm_release $f || fail "second release should succeed"
1543 check_hsm_flags $f "0x0000000d"
1545 stop_full_debug_logging
1549 run_test 21 "Simple release tests"
1552 # test needs a running copytool
1557 local f=$DIR/$tdir/test_release
1558 local swap=$DIR/$tdir/test_swap
1560 # Create a file and check its states
1561 local fid=$(make_small $f)
1562 check_hsm_flags $f "0x00000000"
1564 $LFS hsm_archive $f || error "could not archive file"
1565 wait_request_state $fid ARCHIVE SUCCEED
1567 # Release and check states
1568 $LFS hsm_release $f || error "could not release file"
1569 check_hsm_flags $f "0x0000000d"
1572 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1577 run_test 22 "Could not swap a release file"
1580 # test needs a running copytool
1585 local f=$DIR/$tdir/test_mtime
1587 # Create a file and check its states
1588 local fid=$(make_small $f)
1589 check_hsm_flags $f "0x00000000"
1591 $LFS hsm_archive $f || error "could not archive file"
1592 wait_request_state $fid ARCHIVE SUCCEED
1594 # Set modification time in the past
1595 touch -m -a -d @978261179 $f
1597 # Release and check states
1598 $LFS hsm_release $f || error "could not release file"
1599 check_hsm_flags $f "0x0000000d"
1601 local MTIME=$(stat -c "%Y" $f)
1602 local ATIME=$(stat -c "%X" $f)
1603 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1604 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1608 run_test 23 "Release does not change a/mtime (utime)"
1611 local file=$DIR/$tdir/$tfile
1620 # test needs a running copytool
1625 fid=$(make_small $file)
1627 # Create a file and check its states
1628 check_hsm_flags $file "0x00000000"
1630 # Ensure atime is less than mtime and ctime.
1634 atime0=$(stat -c "%X" $file)
1635 mtime0=$(stat -c "%Y" $file)
1636 ctime0=$(stat -c "%Z" $file)
1638 [ $atime0 -lt $mtime0 ] ||
1639 error "atime $atime0 is not less than mtime $mtime0"
1641 [ $atime0 -lt $ctime0 ] ||
1642 error "atime $atime0 is not less than ctime $ctime0"
1644 # Archive should not change any timestamps.
1645 $LFS hsm_archive $file || error "cannot archive '$file'"
1646 wait_request_state $fid ARCHIVE SUCCEED
1648 atime1=$(stat -c "%X" $file)
1649 mtime1=$(stat -c "%Y" $file)
1650 ctime1=$(stat -c "%Z" $file)
1652 [ $atime0 -eq $atime1 ] ||
1653 error "archive changed atime from $atime0 to $atime1"
1655 [ $mtime0 -eq $mtime1 ] ||
1656 error "archive changed mtime from $mtime0 to $mtime1"
1658 [ $ctime0 -eq $ctime1 ] ||
1659 error "archive changed ctime from $ctime0 to $ctime1"
1661 # Release should not change any timestamps.
1662 $LFS hsm_release $file || error "cannot release '$file'"
1663 check_hsm_flags $file "0x0000000d"
1665 atime1=$(stat -c "%X" $file)
1666 mtime1=$(stat -c "%Y" $file)
1667 ctime1=$(stat -c "%Z" $file)
1669 [ $atime0 -eq $atime1 ] ||
1670 error "release changed atime from $atime0 to $atime1"
1672 [ $mtime0 -eq $mtime1 ] ||
1673 error "release changed mtime from $mtime0 to $mtime1"
1675 [ $ctime0 -eq $ctime1 ] ||
1676 error "release changed ctime from $ctime0 to $ctime1"
1678 # Restore should not change atime or mtime and should not
1680 $LFS hsm_restore $file
1681 wait_request_state $fid RESTORE SUCCEED
1683 atime1=$(stat -c "%X" $file)
1684 mtime1=$(stat -c "%Y" $file)
1685 ctime1=$(stat -c "%Z" $file)
1687 [ $atime0 -eq $atime1 ] ||
1688 error "restore changed atime from $atime0 to $atime1"
1690 [ $mtime0 -eq $mtime1 ] ||
1691 error "restore changed mtime from $mtime0 to $mtime1"
1693 [ $ctime0 -le $ctime1 ] ||
1694 error "restore changed ctime from $ctime0 to $ctime1"
1698 # Once more, after unmount and mount.
1699 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1700 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1702 atime1=$(stat -c "%X" $file)
1703 mtime1=$(stat -c "%Y" $file)
1704 ctime1=$(stat -c "%Z" $file)
1706 [ $atime0 -eq $atime1 ] ||
1707 error "remount changed atime from $atime0 to $atime1"
1709 [ $mtime0 -eq $mtime1 ] ||
1710 error "remount changed mtime from $mtime0 to $mtime1"
1712 [ $ctime0 -le $ctime1 ] ||
1713 error "remount changed ctime from $ctime0 to $ctime1"
1715 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1718 local file=$DIR/$tdir/$tfile
1724 # Test needs a running copytool.
1728 # Check that root can do HSM actions on a ordinary user's file.
1730 fid=$(make_small $file)
1731 sum0=$(md5sum $file)
1733 chown $RUNAS_ID:$RUNAS_GID $file ||
1734 error "cannot chown '$file' to '$RUNAS_ID'"
1736 chmod ugo-w $DIR/$tdir ||
1737 error "cannot chmod '$DIR/$tdir'"
1739 $LFS hsm_archive $file
1740 wait_request_state $fid ARCHIVE SUCCEED
1742 $LFS hsm_release $file
1743 check_hsm_flags $file "0x0000000d"
1745 $LFS hsm_restore $file
1746 wait_request_state $fid RESTORE SUCCEED
1748 # Check that ordinary user can get HSM state.
1749 $RUNAS $LFS hsm_state $file ||
1750 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1752 $LFS hsm_release $file
1753 check_hsm_flags $file "0x0000000d"
1755 # Check that ordinary user can accessed released file.
1756 sum1=$($RUNAS md5sum $file) ||
1757 error "user '$RUNAS_ID' cannot read '$file'"
1759 [ "$sum0" == "$sum1" ] ||
1760 error "md5sum mismatch for '$file'"
1764 run_test 24b "root can archive, release, and restore user files"
1766 cleanup_test_24c() {
1768 set_hsm_param user_request_mask RESTORE
1769 set_hsm_param group_request_mask RESTORE
1770 set_hsm_param other_request_mask RESTORE
1774 local file=$DIR/$tdir/$tfile
1775 local action=archive
1780 # test needs a running copytool
1785 # Save the default masks and check that cleanup_24c will
1786 # restore the request masks correctly.
1787 user_save=$(get_hsm_param user_request_mask)
1788 group_save=$(get_hsm_param group_request_mask)
1789 other_save=$(get_hsm_param other_request_mask)
1791 [ "$user_save" == RESTORE ] ||
1792 error "user_request_mask is '$user_save' expected 'RESTORE'"
1793 [ "$group_save" == RESTORE ] ||
1794 error "group_request_mask is '$group_save' expected 'RESTORE'"
1795 [ "$other_save" == RESTORE ] ||
1796 error "other_request_mask is '$other_save' expected 'RESTORE'"
1798 trap cleanup_test_24c EXIT
1803 chown $RUNAS_ID:nobody $file ||
1804 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1806 set_hsm_param user_request_mask ""
1807 $RUNAS $LFS hsm_$action $file &&
1808 error "$action by user should fail"
1810 set_hsm_param user_request_mask $action
1811 $RUNAS $LFS hsm_$action $file ||
1812 error "$action by user should succeed"
1817 chown nobody:$RUNAS_GID $file ||
1818 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1820 set_hsm_param group_request_mask ""
1821 $RUNAS $LFS hsm_$action $file &&
1822 error "$action by group should fail"
1824 set_hsm_param group_request_mask $action
1825 $RUNAS $LFS hsm_$action $file ||
1826 error "$action by group should succeed"
1831 chown nobody:nobody $file ||
1832 error "cannot chown '$file' to 'nobody:nobody'"
1834 set_hsm_param other_request_mask ""
1835 $RUNAS $LFS hsm_$action $file &&
1836 error "$action by other should fail"
1838 set_hsm_param other_request_mask $action
1839 $RUNAS $LFS hsm_$action $file ||
1840 error "$action by other should succeed"
1845 run_test 24c "check that user,group,other request masks work"
1847 cleanup_test_24d() {
1849 mount -o remount,rw $MOUNT2
1853 local file1=$DIR/$tdir/$tfile
1854 local file2=$DIR2/$tdir/$tfile
1862 fid1=$(make_small $file1)
1864 trap cleanup_test_24d EXIT
1866 mount -o remount,ro $MOUNT2
1868 fid2=$(path2fid $file2)
1869 [ "$fid1" == "$fid2" ] ||
1870 error "FID mismatch '$fid1' != '$fid2'"
1872 $LFS hsm_archive $file2 &&
1873 error "archive should fail on read-only mount"
1874 check_hsm_flags $file1 "0x00000000"
1876 $LFS hsm_archive $file1
1877 wait_request_state $fid1 ARCHIVE SUCCEED
1879 $LFS hsm_release $file1
1880 $LFS hsm_restore $file2
1881 wait_request_state $fid1 RESTORE SUCCEED
1883 $LFS hsm_release $file1 || error "cannot release '$file1'"
1884 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1886 $LFS hsm_release $file2 &&
1887 error "release should fail on read-only mount"
1892 run_test 24d "check that read-only mounts are respected"
1895 # test needs a running copytool
1899 copy2archive /etc/hosts $tdir/$tfile
1901 local f=$DIR/$tdir/$tfile
1903 import_file $tdir/$tfile $f
1905 $LFS hsm_set --lost $f
1910 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1914 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1915 " (Operation not permitted)"
1918 # test needs a running copytool
1923 local f=$DIR/$tdir/$tfile
1924 local fid=$(copy_file /etc/passwd $f)
1926 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1927 wait_request_state $fid ARCHIVE SUCCEED
1930 $LFS hsm_set --lost $f
1934 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1938 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1939 " (Operation not permitted)"
1942 # test needs a running copytool
1946 local f=$DIR/$tdir/$tfile
1947 local fid=$(make_large_for_progress $f)
1948 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1949 wait_request_state $fid ARCHIVE SUCCEED
1952 wait_request_state $fid REMOVE SUCCEED
1954 check_hsm_flags $f "0x00000000"
1958 run_test 26 "Remove the archive of a valid file"
1961 # test needs a running copytool
1965 make_archive $tdir/$tfile
1966 local f=$DIR/$tdir/$tfile
1967 import_file $tdir/$tfile $f
1968 local fid=$(path2fid $f)
1972 [[ $? != 0 ]] || error "Remove of a released file should fail"
1976 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1979 # test needs a running copytool
1983 local f=$DIR/$tdir/$tfile
1984 local fid=$(make_large_for_progress $f)
1985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1986 wait_request_state $fid ARCHIVE SUCCEED
1991 [[ $? != 0 ]] || error "Remove of a released file should fail"
1995 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1998 # test needs a running copytool
2002 local f=$DIR/$tdir/$tfile
2003 local fid=$(make_large_for_progress $f)
2004 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2005 wait_request_state $fid ARCHIVE SUCCEED
2014 wait_request_state $fid REMOVE SUCCEED
2018 run_test 28 "Concurrent archive/file remove"
2021 # restore at exec cannot work on agent node (because of Linux kernel
2022 # protection of executables)
2023 needclients 2 || return 0
2025 # test needs a running copytool
2029 copy2archive /bin/true $tdir/$tfile
2031 local f=$DIR/$tdir/true
2032 import_file $tdir/$tfile $f
2034 local fid=$(path2fid $f)
2036 # set no retry action mode
2042 # remove no try action mode
2046 [[ $st == 0 ]] || error "Failed to exec a released file"
2050 run_test 30a "Restore at exec (import case)"
2053 # restore at exec cannot work on agent node (because of Linux kernel
2054 # protection of executables)
2055 needclients 2 || return 0
2057 # test needs a running copytool
2061 local f=$DIR/$tdir/true
2062 local fid=$(copy_file /bin/true $f)
2064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2065 wait_request_state $fid ARCHIVE SUCCEED
2068 # set no retry action mode
2074 # remove no try action mode
2078 [[ $st == 0 ]] || error "Failed to exec a released file"
2082 run_test 30b "Restore at exec (release case)"
2085 needclients 2 || return 0
2087 # test needs a running copytool
2091 local f=$DIR/$tdir/SLEEP
2092 local fid=$(copy_file /bin/sleep $f)
2094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2095 wait_request_state $fid ARCHIVE SUCCEED
2097 check_hsm_flags $f "0x0000000d"
2098 # set no retry action mode
2100 do_node $CLIENT2 "$f 10" &
2104 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2106 [[ $? == 0 ]] || error "Execution failed during run"
2108 [[ $? == 0 ]] || error "Binary overwritten during exec"
2111 # remove no try action mode
2113 check_hsm_flags $f "0x00000009"
2117 run_test 30c "Update during exec of released file must fail"
2119 restore_and_check_size() {
2122 local s=$(stat -c "%s" $f)
2124 local st=$(get_hsm_flags $f)
2128 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2130 n=$(stat -c "%s" $f)
2131 # we echo in both cases to show stat is not
2133 if [[ $n != $s ]]; then
2134 echo "size seen is $n != $s"
2137 echo "size seen is right: $n == $s"
2139 st=$(get_hsm_flags $f)
2143 if [[ $cpt -lt 10 ]]; then
2146 echo " restore is too long"
2147 wait_request_state $fid RESTORE SUCCEED
2153 # test needs a running copytool
2158 make_archive $tdir/$tfile
2159 local f=$DIR/$tdir/$tfile
2160 import_file $tdir/$tfile $f
2161 local fid=$($LFS path2fid $f)
2162 HSM_ARCHIVE_PURGE=false copytool_setup
2164 restore_and_check_size $f $fid
2167 [[ $err -eq 0 ]] || error "File size changed during restore"
2171 run_test 31a "Import a large file and check size during restore"
2175 # test needs a running copytool
2180 local f=$DIR/$tdir/$tfile
2181 local fid=$(make_large_for_progress $f)
2182 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2183 wait_request_state $fid ARCHIVE SUCCEED
2186 restore_and_check_size $f $fid
2189 [[ $err -eq 0 ]] || error "File size changed during restore"
2193 run_test 31b "Restore a large unaligned file and check size during restore"
2196 # test needs a running copytool
2201 local f=$DIR/$tdir/$tfile
2202 local fid=$(make_large_for_progress_aligned $f)
2203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2204 wait_request_state $fid ARCHIVE SUCCEED
2207 restore_and_check_size $f $fid
2210 [[ $err -eq 0 ]] || error "File size changed during restore"
2214 run_test 31c "Restore a large aligned file and check size during restore"
2217 # test needs a running copytool
2222 local f=$DIR/$tdir/$tfile
2223 local fid=$(make_large_for_progress $f)
2224 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2225 wait_request_state $fid ARCHIVE SUCCEED
2228 md5sum $f >/dev/null &
2230 wait_request_state $fid RESTORE STARTED
2235 # Check restore trigger process was killed
2236 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2240 wait_request_state $fid RESTORE CANCELED
2241 wait_request_state $fid CANCEL SUCCEED
2244 error "Cannot kill process waiting for restore ($killed)"
2248 run_test 33 "Kill a restore waiting process"
2251 # test needs a running copytool
2256 local f=$DIR/$tdir/$tfile
2257 local fid=$(make_large_for_progress $f)
2258 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2259 wait_request_state $fid ARCHIVE SUCCEED
2262 md5sum $f >/dev/null &
2264 wait_request_state $fid RESTORE STARTED
2266 rm $f || error "rm $f failed"
2267 # rm must not block during restore
2268 wait_request_state $fid RESTORE STARTED
2270 wait_request_state $fid RESTORE SUCCEED
2271 # check md5sum pgm finished
2272 local there=$(ps -o pid,comm hp $pid >/dev/null)
2273 [[ -z $there ]] || error "Restore initiator does not exit"
2275 local rc=$(wait $pid)
2276 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2280 run_test 34 "Remove file during restore"
2283 # test needs a running copytool
2288 local f=$DIR/$tdir/$tfile
2289 local f1=$DIR/$tdir/$tfile-1
2290 local fid=$(make_large_for_progress $f)
2291 local fid1=$(copy_file /etc/passwd $f1)
2292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2293 wait_request_state $fid ARCHIVE SUCCEED
2296 md5sum $f >/dev/null &
2298 wait_request_state $fid RESTORE STARTED
2300 mv $f1 $f || error "mv $f1 $f failed"
2301 # mv must not block during restore
2302 wait_request_state $fid RESTORE STARTED
2304 wait_request_state $fid RESTORE SUCCEED
2305 # check md5sum pgm finished
2306 local there=$(ps -o pid,comm hp $pid >/dev/null)
2307 [[ -z $there ]] || error "Restore initiator does not exit"
2309 local rc=$(wait $pid)
2310 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2313 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2317 run_test 35 "Overwrite file during restore"
2320 # test needs a running copytool
2325 local f=$DIR/$tdir/$tfile
2326 local fid=$(make_large_for_progress $f)
2327 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2328 wait_request_state $fid ARCHIVE SUCCEED
2331 md5sum $f >/dev/null &
2333 wait_request_state $fid RESTORE STARTED
2336 # rm must not block during restore
2337 wait_request_state $fid RESTORE STARTED
2339 wait_request_state $fid RESTORE SUCCEED
2340 # check md5sum pgm finished
2341 local there=$(ps -o pid,comm hp $pid >/dev/null)
2343 error "Restore initiator does not exit"
2345 local rc=$(wait $pid)
2347 error "Restore initiator failed with $rc"
2351 run_test 36 "Move file during restore"
2358 for n in $(seq 1 $count); do
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2361 echo "$count archive requests submitted"
2365 local stream_count=4
2366 local file_count=100
2368 local f=$DIR/$tdir/$tfile
2373 for i in $(seq 1 $file_count); do
2374 for p in $(seq 1 $stream_count); do
2375 fid=$(copy_file /etc/hosts $f.$p.$i)
2378 # force copytool to use a local/temp archive dir to ensure best
2379 # performance vs remote/NFS mounts used in auto-tests
2380 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2383 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2385 # to be sure wait_all_done will not be mislead by previous tests
2387 wait_for_grace_delay
2389 # start archive streams in background (archive files in parallel)
2390 for p in $(seq 1 $stream_count); do
2391 multi_archive $f.$p $file_count &
2394 echo -n "Wait for all requests being enqueued..."
2400 run_test 40 "Parallel archive requests"
2403 # test needs a running copytool
2407 local f=$DIR/$tdir/$tfile
2408 local fid=$(copy_file /etc/motd $f 1)
2410 $LFS hsm_archive $f || error "could not archive file"
2411 wait_request_state $fid ARCHIVE SUCCEED
2412 check_hsm_flags $f "0x00000009"
2414 multiop_bg_pause $f O_c || error "multiop failed"
2418 client_up || client_up || true
2420 kill -USR1 $MULTIPID
2421 wait $MULTIPID || error "multiop close failed"
2423 check_hsm_flags $f "0x0000000b"
2427 run_test 52 "Opened for write file on an evicted client should be set dirty"
2430 # test needs a running copytool
2434 local f=$DIR/$tdir/$tfile
2435 local fid=$(copy_file /etc/motd $f 1)
2437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2438 error "could not archive file"
2439 wait_request_state $fid ARCHIVE SUCCEED
2440 check_hsm_flags $f "0x00000009"
2442 multiop_bg_pause $f o_c || error "multiop failed"
2446 client_up || client_up || true
2448 kill -USR1 $MULTIPID
2449 wait $MULTIPID || error "multiop close failed"
2451 check_hsm_flags $f "0x00000009"
2455 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2458 # test needs a running copytool
2462 local f=$DIR/$tdir/$tfile
2463 local fid=$(make_small $f)
2465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2466 error "could not archive file"
2467 wait_request_state $fid ARCHIVE STARTED
2469 check_hsm_flags $f "0x00000001"
2471 # Avoid coordinator resending this request as soon it has failed.
2476 wait_request_state $fid ARCHIVE FAILED
2478 check_hsm_flags $f "0x00000003"
2483 run_test 54 "Write during an archive cancels it"
2486 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(make_small $f)
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2494 error "could not archive file"
2495 wait_request_state $fid ARCHIVE STARTED
2497 check_hsm_flags $f "0x00000001"
2499 # Avoid coordinator resending this request as soon it has failed.
2502 $TRUNCATE $f 1024 || error "truncate failed"
2504 wait_request_state $fid ARCHIVE FAILED
2506 check_hsm_flags $f "0x00000003"
2511 run_test 55 "Truncate during an archive cancels it"
2514 # test needs a running copytool
2518 local f=$DIR/$tdir/$tfile
2519 local fid=$(make_large_for_progress $f)
2521 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2522 error "could not archive file"
2523 wait_request_state $fid ARCHIVE STARTED
2525 check_hsm_flags $f "0x00000001"
2527 # Change metadata and sync to be sure we are not changing only
2532 wait_request_state $fid ARCHIVE SUCCEED
2534 check_hsm_flags $f "0x00000009"
2538 run_test 56 "Setattr during an archive is ok"
2541 # Need one client for I/O, one for request
2542 needclients 2 || return 0
2544 # test needs a running copytool
2548 local f=$DIR/$tdir/test_archive_remote
2549 # Create a file on a remote node
2550 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2551 "count=2 conv=fsync"
2554 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2555 error "hsm_archive failed"
2556 local fid=$(path2fid $f)
2557 wait_request_state $fid ARCHIVE SUCCEED
2559 # Release and implicit restore it
2560 do_node $CLIENT2 "$LFS hsm_release $f" ||
2561 error "hsm_release failed"
2562 do_node $CLIENT2 "md5sum $f" ||
2563 error "hsm_restore failed"
2565 wait_request_state $fid RESTORE SUCCEED
2569 run_test 57 "Archive a file with dirty cache on another node"
2571 truncate_released_file() {
2575 local sz=$(stat -c %s $src_file)
2576 local f=$DIR/$tdir/$tfile
2577 local fid=$(copy_file $1 $f)
2581 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2582 error "could not archive file"
2583 wait_request_state $fid ARCHIVE SUCCEED
2585 $LFS hsm_release $f || error "could not release file"
2587 $TRUNCATE $f $trunc_to || error "truncate failed"
2590 local sz1=$(stat -c %s $f)
2591 [[ $sz1 == $trunc_to ]] ||
2592 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2595 check_hsm_flags $f "0x0000000b"
2597 local state=$(get_request_state $fid RESTORE)
2598 [[ "$state" == "SUCCEED" ]] ||
2599 error "truncate $sz does not trig restore, state = $state"
2601 $TRUNCATE $ref $trunc_to
2602 cmp $ref $f || error "file data wrong after truncate"
2608 # test needs a running copytool
2613 local sz=$(stat -c %s /etc/passwd)
2615 echo "truncate up from $sz to $((sz*2))"
2616 truncate_released_file /etc/passwd $((sz*2))
2618 echo "truncate down from $sz to $((sz/2))"
2619 truncate_released_file /etc/passwd $((sz/2))
2621 echo "truncate to 0"
2622 truncate_released_file /etc/passwd 0
2626 run_test 58 "Truncate a released file will trigger restore"
2629 # This test validates the fix for LU-4512. Ensure that the -u
2630 # option changes the progress reporting interval from the default
2631 # (30 seconds) to the user-specified interval.
2633 local progress_timeout=$((interval * 3))
2635 # test needs a new running copytool
2637 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2640 local f=$DIR/$tdir/$tfile
2641 local fid=$(make_large_for_progress $f)
2643 local start_at=$(date +%s)
2644 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2645 error "could not archive file"
2648 local mdt=${MDT_PREFIX}${mdtidx}
2649 local mds=mds$((mdtidx + 1))
2651 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2652 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2658 echo -n "Expecting a progress update within $progress_timeout seconds... "
2660 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2661 if [ $RESULT -gt 0 ]; then
2662 echo "$RESULT bytes copied in $WAIT seconds."
2664 elif [ $WAIT -ge $progress_timeout ]; then
2665 error "Timed out waiting for progress update!"
2668 WAIT=$((WAIT + sleep))
2672 local finish_at=$(date +%s)
2673 local elapsed=$((finish_at - start_at))
2675 # Ensure that the progress update occurred within the expected window.
2676 if [ $elapsed -lt $interval ]; then
2677 error "Expected progress update after at least $interval seconds"
2683 run_test 60 "Changing progress update interval from default"
2686 # test needs a new running copytool
2688 copytool_monitor_setup
2689 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2691 # Just start and stop the copytool to generate events.
2695 local REGISTER_EVENT
2696 local UNREGISTER_EVENT
2697 while read event; do
2698 local parsed=$(parse_json_event "$event")
2699 if [ -z "$parsed" ]; then
2700 error "Copytool sent malformed event: $event"
2704 if [ $event_type == "REGISTER" ]; then
2705 REGISTER_EVENT=$event
2706 elif [ $event_type == "UNREGISTER" ]; then
2707 UNREGISTER_EVENT=$event
2709 done < <(echo $"$(get_copytool_event_log)")
2711 if [ -z "$REGISTER_EVENT" ]; then
2712 error "Copytool failed to send register event to FIFO"
2715 if [ -z "$UNREGISTER_EVENT" ]; then
2716 error "Copytool failed to send unregister event to FIFO"
2719 copytool_monitor_cleanup
2720 echo "Register/Unregister events look OK."
2722 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2725 # Bump progress interval for livelier events.
2728 # test needs a new running copytool
2730 copytool_monitor_setup
2731 HSMTOOL_UPDATE_INTERVAL=$interval \
2732 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2735 local f=$DIR/$tdir/$tfile
2736 local fid=$(make_large_for_progress $f)
2738 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2739 error "could not archive file"
2740 wait_request_state $fid ARCHIVE SUCCEED
2742 local expected_fields="event_time data_fid source_fid"
2743 expected_fields+=" total_bytes current_bytes"
2747 while read event; do
2748 # Make sure we're not getting anything from previous events.
2749 for field in $expected_fields; do
2753 local parsed=$(parse_json_event "$event")
2754 if [ -z "$parsed" ]; then
2755 error "Copytool sent malformed event: $event"
2759 if [ $event_type == "ARCHIVE_START" ]; then
2762 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2765 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2769 # Do some simple checking of the progress update events.
2770 for expected_field in $expected_fields; do
2771 if [ -z ${!expected_field+x} ]; then
2772 error "Missing $expected_field field in event"
2776 if [ $total_bytes -eq 0 ]; then
2777 error "Expected total_bytes to be > 0"
2780 # These should be identical throughout an archive
2782 if [ $source_fid != $data_fid ]; then
2783 error "Expected source_fid to equal data_fid"
2785 done < <(echo $"$(get_copytool_event_log)")
2787 if [ -z "$START_EVENT" ]; then
2788 error "Copytool failed to send archive start event to FIFO"
2791 if [ -z "$FINISH_EVENT" ]; then
2792 error "Copytool failed to send archive finish event to FIFO"
2795 echo "Archive events look OK."
2799 copytool_monitor_cleanup
2801 run_test 71 "Copytool logs JSON archive events to FIFO"
2804 # Bump progress interval for livelier events.
2807 # test needs a new running copytool
2809 copytool_monitor_setup
2810 HSMTOOL_UPDATE_INTERVAL=$interval \
2811 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2812 local test_file=$HSMTOOL_MONITOR_DIR/file
2814 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2816 do_facet $SINGLEAGT "$cmd" ||
2817 error "cannot create $test_file on $SINGLEAGT"
2818 copy2archive $test_file $tdir/$tfile
2821 local f=$DIR/$tdir/$tfile
2822 import_file $tdir/$tfile $f
2823 f=$DIR2/$tdir/$tfile
2824 echo "Verifying released state: "
2825 check_hsm_flags $f "0x0000000d"
2827 local fid=$(path2fid $f)
2829 wait_request_state $fid RESTORE SUCCEED
2831 local expected_fields="event_time data_fid source_fid"
2832 expected_fields+=" total_bytes current_bytes"
2836 while read event; do
2837 # Make sure we're not getting anything from previous events.
2838 for field in $expected_fields; do
2842 local parsed=$(parse_json_event "$event")
2843 if [ -z "$parsed" ]; then
2844 error "Copytool sent malformed event: $event"
2848 if [ $event_type == "RESTORE_START" ]; then
2850 if [ $source_fid != $data_fid ]; then
2851 error "source_fid should == data_fid at start"
2854 elif [ $event_type == "RESTORE_FINISH" ]; then
2856 if [ $source_fid != $data_fid ]; then
2857 error "source_fid should == data_fid at finish"
2860 elif [ $event_type != "RESTORE_RUNNING" ]; then
2864 # Do some simple checking of the progress update events.
2865 for expected_field in $expected_fields; do
2866 if [ -z ${!expected_field+x} ]; then
2867 error "Missing $expected_field field in event"
2871 if [ $total_bytes -eq 0 ]; then
2872 error "Expected total_bytes to be > 0"
2875 # When a restore starts out, the data fid is the same as the
2876 # source fid. After the restore has gotten going, we learn
2877 # the new data fid. Once the restore has finished, the source
2878 # fid is set to the new data fid.
2880 # We test this because some monitoring software may depend on
2881 # this behavior. If it changes, then the consumers of these
2882 # events may need to be modified.
2883 if [ $source_fid == $data_fid ]; then
2884 error "source_fid should != data_fid during restore"
2886 done < <(echo $"$(get_copytool_event_log)")
2888 if [ -z "$START_EVENT" ]; then
2889 error "Copytool failed to send restore start event to FIFO"
2892 if [ -z "$FINISH_EVENT" ]; then
2893 error "Copytool failed to send restore finish event to FIFO"
2896 echo "Restore events look OK."
2900 copytool_monitor_cleanup
2904 run_test 72 "Copytool logs JSON restore events to FIFO"
2907 file_count=51 # Max number of files constrained by LNET message size
2908 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2909 local f=$DIR/$tdir/$tfile
2910 local FILELIST=/tmp/filelist.txt
2914 for i in $(seq 1 $file_count); do
2915 fid=$(copy_file /etc/hosts $f.$i)
2916 echo $f.$i >> $FILELIST
2919 # to be sure wait_all_done will not be mislead by previous tests
2921 wait_for_grace_delay
2922 $LFS hsm_archive --filelist $FILELIST ||
2923 error "cannot archive a file list"
2925 $LFS hsm_release --filelist $FILELIST ||
2926 error "cannot release a file list"
2927 $LFS hsm_restore --filelist $FILELIST ||
2928 error "cannot restore a file list"
2932 run_test 90 "Archive/restore a file list"
2934 double_verify_reset_hsm_param() {
2936 echo "Testing $HSM_PARAM.$p"
2937 local val=$(get_hsm_param $p)
2939 local val2=$(($val * 2))
2940 set_hsm_param $p $val2
2941 val=$(get_hsm_param $p)
2942 [[ $val == $val2 ]] ||
2943 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2944 echo "Set $p to 0 must failed"
2948 set_hsm_param $p $save
2950 if [[ $rc == 0 ]]; then
2951 error "we must not be able to set $HSM_PARAM.$p to 0"
2956 double_verify_reset_hsm_param loop_period
2957 double_verify_reset_hsm_param grace_delay
2958 double_verify_reset_hsm_param active_request_timeout
2959 double_verify_reset_hsm_param max_requests
2960 double_verify_reset_hsm_param default_archive_id
2962 run_test 100 "Set coordinator /proc tunables"
2969 run_test 102 "Verify coordinator control"
2972 # test needs a running copytool
2979 for i in $(seq 1 20); do
2980 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2982 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2986 echo "Current requests"
2987 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2988 $HSM_PARAM.actions |\
2989 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2991 [[ -z "$res" ]] || error "Some request have not been canceled"
2995 run_test 103 "Purge all requests"
3000 # test needs a running copytool
3004 local f=$DIR/$tdir/$tfile
3005 local fid=$(make_large_for_progress $f)
3006 # if cdt is on, it can serve too quickly the request
3008 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3009 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3010 $HSM_PARAM.actions |\
3011 grep $fid | cut -f16 -d=")
3014 [[ "$data1" == "$DATAHEX" ]] ||
3015 error "Data field in records is ($data1) and not ($DATAHEX)"
3019 run_test 104 "Copy tool data field"
3026 for i in $(seq -w 1 10); do
3027 cp /etc/passwd $DIR/$tdir/$i
3028 $LFS hsm_archive $DIR/$tdir/$i
3030 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3031 $HSM_PARAM.actions |\
3032 grep WAITING | wc -l")
3035 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3036 $HSM_PARAM.actions |\
3037 grep WAITING | wc -l")
3040 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3041 error "Requests count after shutdown $reqcnt2 != "\
3042 "before shutdown $reqcnt1"
3044 run_test 105 "Restart of coordinator"
3046 get_agent_by_uuid_mdt() {
3049 local mds=mds$(($mdtidx + 1))
3050 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3054 check_agent_registered_by_mdt() {
3057 local mds=mds$(($mdtidx + 1))
3058 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3059 if [[ ! -z "$agent" ]]; then
3060 echo "found agent $agent on $mds"
3062 error "uuid $uuid not found in agent list on $mds"
3066 check_agent_unregistered_by_mdt() {
3069 local mds=mds$(($mdtidx + 1))
3070 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3071 if [[ -z "$agent" ]]; then
3072 echo "uuid not found in agent list on $mds"
3074 error "uuid found in agent list on $mds: $agent"
3078 check_agent_registered() {
3081 for mdsno in $(seq 1 $MDSCOUNT); do
3082 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3086 check_agent_unregistered() {
3089 for mdsno in $(seq 1 $MDSCOUNT); do
3090 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3095 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3096 get_client_uuid $MOUNT | cut -d' ' -f2)
3099 check_agent_registered $uuid
3101 search_copytools || error "No copytool found"
3104 check_agent_unregistered $uuid
3107 check_agent_registered $uuid
3111 run_test 106 "Copytool register/unregister"
3114 # test needs a running copytool
3116 # create and archive file
3118 local f1=$DIR/$tdir/$tfile
3119 local fid=$(copy_file /etc/passwd $f1)
3120 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3121 wait_request_state $fid ARCHIVE SUCCEED
3122 # shutdown and restart MDS
3124 # check the copytool still gets messages from MDT
3125 local f2=$DIR/$tdir/2
3126 local fid=$(copy_file /etc/passwd $f2)
3127 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3128 # main check of this sanity: this request MUST succeed
3129 wait_request_state $fid ARCHIVE SUCCEED
3132 run_test 107 "Copytool re-register after MDS restart"
3134 policy_set_and_test()
3138 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3139 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3140 [[ "$policy" == "$target" ]] ||
3141 error "Wrong policy after '$change': '$policy' != '$target'"
3145 # to force default policy setting if error
3146 CDT_POLICY_HAD_CHANGED=true
3148 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3149 local default="NonBlockingRestore [NoRetryAction]"
3150 [[ "$policy" == "$default" ]] ||
3151 error "default policy has changed,"\
3152 " '$policy' != '$default' update the test"
3153 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3154 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3155 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3156 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3157 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3158 # useless bacause we know but safer for futur changes to use real value
3159 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3160 echo "Next set_param must failed"
3161 policy_set_and_test "wrong" "$policy"
3164 echo "Back to default policy"
3165 cdt_set_sanity_policy
3167 run_test 109 "Policy display/change"
3170 # test needs a running copytool
3175 copy2archive /etc/passwd $tdir/$tfile
3177 local f=$DIR/$tdir/$tfile
3178 import_file $tdir/$tfile $f
3179 local fid=$(path2fid $f)
3181 cdt_set_non_blocking_restore
3186 wait_request_state $fid RESTORE SUCCEED
3187 cdt_clear_non_blocking_restore
3191 error "md5sum returns $st != 1, "\
3192 "should also perror ENODATA (No data available)"
3196 run_test 110a "Non blocking restore policy (import case)"
3199 # test needs a running copytool
3203 local f=$DIR/$tdir/$tfile
3204 local fid=$(copy_file /etc/passwd $f)
3205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3206 wait_request_state $fid ARCHIVE SUCCEED
3209 cdt_set_non_blocking_restore
3214 wait_request_state $fid RESTORE SUCCEED
3215 cdt_clear_non_blocking_restore
3219 error "md5sum returns $st != 1, "\
3220 "should also perror ENODATA (No data available)"
3224 run_test 110b "Non blocking restore policy (release case)"
3227 # test needs a running copytool
3231 copy2archive /etc/passwd $tdir/$tfile
3233 local f=$DIR/$tdir/$tfile
3235 import_file $tdir/$tfile $f
3236 local fid=$(path2fid $f)
3240 copytool_remove_backend $fid
3243 wait_request_state $fid RESTORE FAILED
3250 [[ $st == 0 ]] || error "Restore does not failed"
3254 run_test 111a "No retry policy (import case), restore will error"\
3255 " (No such file or directory)"
3258 # test needs a running copytool
3262 local f=$DIR/$tdir/$tfile
3263 local fid=$(copy_file /etc/passwd $f)
3265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3266 wait_request_state $fid ARCHIVE SUCCEED
3269 copytool_remove_backend $fid
3272 wait_request_state $fid RESTORE FAILED
3279 [[ $st == 0 ]] || error "Restore does not failed"
3283 run_test 111b "No retry policy (release case), restore will error"\
3284 " (No such file or directory)"
3287 # test needs a running copytool
3291 local f=$DIR/$tdir/$tfile
3292 local fid=$(copy_file /etc/passwd $f)
3294 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3295 local l=$($LFS hsm_action $f)
3297 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3301 wait_request_state $fid ARCHIVE SUCCEED
3304 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3308 run_test 112 "State of recorded request"
3311 # test needs a running copytool
3315 local f=$DIR/$tdir/$tfile
3316 local fid=$(make_large_for_cancel $f)
3317 # test with cdt on is made in test_221
3319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3322 wait_request_state $fid ARCHIVE CANCELED
3323 wait_request_state $fid CANCEL SUCCEED
3327 run_test 200 "Register/Cancel archive"
3330 # test needs a running copytool
3334 local f=$DIR/$tdir/$tfile
3335 make_archive $tdir/$tfile
3336 import_file $tdir/$tfile $f
3337 local fid=$(path2fid $f)
3339 # test with cdt on is made in test_222
3344 wait_request_state $fid RESTORE CANCELED
3345 wait_request_state $fid CANCEL SUCCEED
3349 run_test 201 "Register/Cancel restore"
3352 # test needs a running copytool
3356 local f=$DIR/$tdir/$tfile
3357 local fid=$(make_large_for_progress $f)
3358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3359 wait_request_state $fid ARCHIVE SUCCEED
3365 wait_request_state $fid REMOVE CANCELED
3369 run_test 202 "Register/Cancel remove"
3372 # test needs a running copytool
3377 local f=$DIR/$tdir/$tfile
3378 local fid=$(copy_file /etc/passwd $f)
3382 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3383 wait_request_state $fid ARCHIVE SUCCEED
3385 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3389 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3393 run_test 220 "Changelog for archive"
3396 # test needs a running copytool
3401 local f=$DIR/$tdir/$tfile
3402 local fid=$(make_large_for_cancel $f)
3406 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3407 wait_request_state $fid ARCHIVE STARTED
3409 wait_request_state $fid ARCHIVE CANCELED
3410 wait_request_state $fid CANCEL SUCCEED
3412 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3415 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3419 run_test 221 "Changelog for archive canceled"
3422 # test needs a running copytool
3426 copy2archive /etc/passwd $tdir/$tfile
3428 local f=$DIR/$tdir/$tfile
3429 import_file $tdir/$tfile $f
3430 local fid=$(path2fid $f)
3435 wait_request_state $fid RESTORE SUCCEED
3437 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3440 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3444 run_test 222a "Changelog for explicit restore"
3447 # test needs a running copytool
3451 local f=$DIR/$tdir/$tfile
3452 local fid=$(copy_file /etc/passwd $f)
3455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3456 wait_request_state $fid ARCHIVE SUCCEED
3461 wait_request_state $fid RESTORE SUCCEED
3463 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3466 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3470 run_test 222b "Changelog for implicit restore"
3473 # test needs a running copytool
3478 local f=$DIR/$tdir/$tfile
3479 make_archive $tdir/$tfile
3483 import_file $tdir/$tfile $f
3484 local fid=$(path2fid $f)
3487 wait_request_state $fid RESTORE STARTED
3489 wait_request_state $fid RESTORE CANCELED
3490 wait_request_state $fid CANCEL SUCCEED
3492 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3495 [[ $flags == $target ]] ||
3496 error "Changelog flag is $flags not $target"
3500 run_test 223a "Changelog for restore canceled (import case)"
3503 # test needs a running copytool
3508 local f=$DIR/$tdir/$tfile
3509 local fid=$(make_large_for_progress $f)
3512 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3513 wait_request_state $fid ARCHIVE SUCCEED
3516 wait_request_state $fid RESTORE STARTED
3518 wait_request_state $fid RESTORE CANCELED
3519 wait_request_state $fid CANCEL SUCCEED
3521 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3524 [[ $flags == $target ]] ||
3525 error "Changelog flag is $flags not $target"
3529 run_test 223b "Changelog for restore canceled (release case)"
3532 # test needs a running copytool
3537 local f=$DIR/$tdir/$tfile
3538 local fid=$(copy_file /etc/passwd $f)
3541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3542 wait_request_state $fid ARCHIVE SUCCEED
3545 wait_request_state $fid REMOVE SUCCEED
3547 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3550 [[ $flags == $target ]] ||
3551 error "Changelog flag is $flags not $target"
3555 run_test 224 "Changelog for remove"
3558 # test needs a running copytool
3561 # test is not usable because remove request is too fast
3562 # so it is always finished before cancel can be done ...
3563 echo "Test disabled"
3568 local f=$DIR/$tdir/$tfile
3569 local fid=$(make_large_for_progress $f)
3572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3573 wait_request_state $fid ARCHIVE SUCCEED
3575 # if cdt is on, it can serve too quickly the request
3580 wait_request_state $fid REMOVE CANCELED
3581 wait_request_state $fid CANCEL SUCCEED
3583 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3584 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3585 tail -n 1 | awk '{print $5}')
3588 [[ $flags == $target ]] ||
3589 error "Changelog flag is $flags not $target"
3593 run_test 225 "Changelog for remove canceled"
3596 # test needs a running copytool
3601 local f1=$DIR/$tdir/$tfile-1
3602 local f2=$DIR/$tdir/$tfile-2
3603 local f3=$DIR/$tdir/$tfile-3
3604 local fid1=$(copy_file /etc/passwd $f1)
3605 local fid2=$(copy_file /etc/passwd $f2)
3606 copy_file /etc/passwd $f3
3609 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3610 wait_request_state $fid1 ARCHIVE SUCCEED
3612 $LFS hsm_archive $f2
3613 wait_request_state $fid2 ARCHIVE SUCCEED
3615 rm $f1 || error "rm $f1 failed"
3617 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3620 [[ $flags == $target ]] ||
3621 error "Changelog flag is $flags not $target"
3623 mv $f3 $f2 || error "mv $f3 $f2 failed"
3625 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3628 [[ $flags == $target ]] ||
3629 error "Changelog flag is $flags not $target"
3633 run_test 226 "changelog for last rm/mv with exiting archive"
3635 check_flags_changes() {
3643 $LFS hsm_set --$hsm_flag $f ||
3644 error "Cannot set $hsm_flag on $f"
3645 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3646 local seen=${#flags[*]}
3648 [[ $seen == $cnt ]] ||
3649 error "set $hsm_flag: Changelog events $seen != $cnt"
3650 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3651 error "set $hsm_flag: Changelog flags are "\
3652 "${flags[$((cnt - 1))]} not $target"
3654 $LFS hsm_clear --$hsm_flag $f ||
3655 error "Cannot clear $hsm_flag on $f"
3656 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3659 [[ $cnt == $seen ]] ||
3660 error "clear $hsm_flag: Changelog events $seen != $cnt"
3662 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3663 error "clear $hsm_flag: Changelog flag is "\
3664 "${flags[$((cnt - 1))]} not $target"
3668 # test needs a running copytool
3675 for i in norelease noarchive exists archived
3677 local f=$DIR/$tdir/$tfile-$i
3678 local fid=$(copy_file /etc/passwd $f)
3679 check_flags_changes $f $fid $i 0 1
3682 f=$DIR/$tdir/$tfile---lost
3683 fid=$(copy_file /etc/passwd $f)
3684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3685 wait_request_state $fid ARCHIVE SUCCEED
3686 check_flags_changes $f $fid lost 3 1
3690 run_test 227 "changelog when explicit setting of HSM flags"
3693 # test needs a running copytool
3696 local fid=$(make_small_sync $DIR/$tfile)
3697 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3698 wait_request_state $fid ARCHIVE SUCCEED
3700 $LFS hsm_release $DIR/$tfile
3701 check_hsm_flags $DIR/$tfile "0x0000000d"
3703 filefrag $DIR/$tfile | grep " 1 extent found" ||
3704 error "filefrag on released file must return only one extent"
3706 # only newer versions of cp detect sparse files by stat/FIEMAP
3708 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3709 error "copying $DIR/$tfile"
3710 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3712 $LFS hsm_release $DIR/$tfile
3713 check_hsm_flags $DIR/$tfile "0x0000000d"
3715 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3717 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3719 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3720 error "comparing untarred $DIR/$tfile"
3722 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3723 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3726 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3729 # test needs a running copytool
3733 local maxrequest=$(get_hsm_param max_requests)
3734 local rqcnt=$(($maxrequest * 3))
3738 for i in $(seq -w 1 $rqcnt); do
3740 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3742 # we do it in 2 steps, so all requests arrive at the same time
3743 for i in $(seq -w 1 $rqcnt); do
3744 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3749 while [[ $cnt != 0 || $wt != 0 ]]; do
3751 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3752 $HSM_PARAM.actions |\
3753 grep STARTED | grep -v CANCEL | wc -l")
3754 [[ $cnt -le $maxrequest ]] ||
3755 error "$cnt > $maxrequest too many started requests"
3756 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3757 $HSM_PARAM.actions |\
3758 grep WAITING | wc -l")
3759 echo "max=$maxrequest started=$cnt waiting=$wt"
3764 run_test 250 "Coordinator max request"
3767 # test needs a running copytool
3771 local f=$DIR/$tdir/$tfile
3772 local fid=$(make_large_for_cancel $f)
3775 # to have a short test
3776 local old_to=$(get_hsm_param active_request_timeout)
3777 set_hsm_param active_request_timeout 4
3778 # to be sure the cdt will wake up frequently so
3779 # it will be able to cancel the "old" request
3780 local old_loop=$(get_hsm_param loop_period)
3781 set_hsm_param loop_period 2
3784 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3785 wait_request_state $fid ARCHIVE STARTED
3787 wait_request_state $fid ARCHIVE CANCELED
3789 set_hsm_param active_request_timeout $old_to
3790 set_hsm_param loop_period $old_loop
3794 run_test 251 "Coordinator request timeout"
3797 # the only way to test ondisk conf is to restart MDS ...
3798 echo "Stop coordinator and remove coordinator state at mount"
3801 # clean on disk conf set by default
3802 cdt_clear_mount_state
3803 cdt_check_state stopped
3805 # check cdt still off after umount/remount
3807 cdt_check_state stopped
3809 echo "Set coordinator start at mount, and start coordinator"
3810 cdt_set_mount_state enabled
3813 cdt_check_state enabled
3815 # check cdt still on after umount/remount
3817 cdt_check_state enabled
3819 # we are back to original state (cdt started at mount)
3821 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3824 local ai=$(get_hsm_param default_archive_id)
3825 local new=$((ai + 1))
3827 set_hsm_param default_archive_id $new -P
3829 local res=$(get_hsm_param default_archive_id)
3832 set_hsm_param default_archive_id "" "-P -d"
3834 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3836 run_test 301 "HSM tunnable are persistent"
3839 local ai=$(get_hsm_param default_archive_id)
3840 local new=$((ai + 1))
3845 set_hsm_param default_archive_id $new -P
3848 for mdtno in $(seq 1 $MDSCOUNT); do
3853 cdt_check_state enabled
3855 local res=$(get_hsm_param default_archive_id)
3858 set_hsm_param default_archive_id "" "-P -d"
3860 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3862 run_test 302 "HSM tunnable are persistent when CDT is off"
3865 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3871 local dir_mdt0=$DIR/$tdir/mdt0
3872 local dir_mdt1=$DIR/$tdir/mdt1
3874 # create 1 dir per MDT
3875 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3876 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3878 # create 1 file in each MDT
3879 local fid1=$(make_small $dir_mdt0/$tfile)
3880 local fid2=$(make_small $dir_mdt1/$tfile)
3882 # check that hsm request on mdt0 is sent to the right MDS
3883 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3884 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3885 echo "archive successful on mdt0"
3887 # check that hsm request on mdt1 is sent to the right MDS
3888 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3889 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3890 echo "archive successful on mdt1"
3893 # clean test files and directories
3894 rm -rf $dir_mdt0 $dir_mdt1
3896 run_test 400 "Single request is sent to the right MDT"
3899 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3905 local dir_mdt0=$DIR/$tdir/mdt0
3906 local dir_mdt1=$DIR/$tdir/mdt1
3908 # create 1 dir per MDT
3909 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3910 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3912 # create 1 file in each MDT
3913 local fid1=$(make_small $dir_mdt0/$tfile)
3914 local fid2=$(make_small $dir_mdt1/$tfile)
3916 # check that compound requests are shunt to the rights MDTs
3917 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3918 error "lfs hsm_archive"
3919 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3920 echo "archive successful on mdt0"
3921 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3922 echo "archive successful on mdt1"
3925 # clean test files and directories
3926 rm -rf $dir_mdt0 $dir_mdt1
3928 run_test 401 "Compound requests split and sent to their respective MDTs"
3930 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3935 local node=$(facet_active_host $facet)
3937 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3938 awk '{print $4}'); do
3939 echo "$3 $mdc on $node"
3940 do_facet $facet "$LCTL --device $mdc $state" || return 1
3945 # make sure there is no running copytool
3948 # deactivate all mdc on agent1
3949 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3951 copytool_setup $SINGLEAGT
3953 check_agent_unregistered "uuid" # match any agent
3955 # no expected running copytool
3956 search_copytools $agent && error "Copytool start should have failed"
3959 mdc_change_state $SINGLEAGT "MDT000." "activate"
3961 run_test 402 "Copytool start fails if all MDTs are inactive"
3964 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3966 # make sure there is no running copytool
3969 local agent=$(facet_active_host $SINGLEAGT)
3970 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3972 # deactivate all mdc for MDT0001
3973 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3976 # check the agent is registered on MDT0000, and not on MDT0001
3977 check_agent_registered_by_mdt $uuid 0
3978 check_agent_unregistered_by_mdt $uuid 1
3980 # check running copytool process
3981 search_copytools $agent || error "No running copytools on $agent"
3983 # reactivate all mdc for MDT0001
3984 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3986 # make sure the copytool is now registered to all MDTs
3987 check_agent_registered $uuid
3991 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3994 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3998 # create files on both MDT0000 and MDT0001
4001 local dir_mdt0=$DIR/$tdir/mdt0
4002 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4004 # create 1 file on mdt0
4005 local fid1=$(make_small $dir_mdt0/$tfile)
4007 # deactivate all mdc for MDT0001
4008 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4010 # send an HSM request for files in MDT0000
4011 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4013 # check for completion of files in MDT0000
4014 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4015 echo "archive successful on mdt0"
4017 # reactivate all mdc for MDT0001
4018 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4021 # clean test files and directories
4024 run_test 404 "Inactive MDT does not block requests for active MDTs"
4029 check_and_cleanup_lustre