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}'"
663 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
664 [[ -n $fid ]] && cmd+=" | grep '$fid'"
665 cmd+=" | egrep 'WAITING|STARTED'"
667 wait_result $SINGLEMDS "$cmd" "" $timeout ||
668 error "requests did not complete"
671 wait_for_grace_delay() {
672 local val=$(get_hsm_param grace_delay)
679 # python2.6 in EL6 includes an internal json module
680 local json_parser='import json; import fileinput;'
681 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
682 json_parser+='json.loads([line for line in '
683 json_parser+='fileinput.input()][0]).items()])'
685 echo $raw_event | python -c "$json_parser"
688 # populate MDT device array
694 # cleanup from previous bad setup
695 search_and_kill_copytool
697 # for recovery tests, coordinator needs to be started at mount
699 # the lustre conf must be without hsm on (like for sanity.sh)
700 echo "Set HSM on and start"
701 cdt_set_mount_state enabled
702 cdt_check_state enabled
704 echo "Start copytool"
707 echo "Set sanity-hsm HSM policy"
708 cdt_set_sanity_policy
710 # finished requests are quickly removed from list
711 set_hsm_param grace_delay 10
717 local f=$DIR/$tdir/$tfile
721 check_hsm_flags_user $f "0x00000000"
723 $RUNAS $LFS hsm_set --norelease $f ||
724 error "user could not change hsm flags"
725 check_hsm_flags_user $f "0x00000010"
727 $RUNAS $LFS hsm_clear --norelease $f ||
728 error "user could not clear hsm flags"
729 check_hsm_flags_user $f "0x00000000"
731 # User could not change those flags...
732 $RUNAS $LFS hsm_set --exists $f &&
733 error "user should not set this flag"
734 check_hsm_flags_user $f "0x00000000"
737 $LFS hsm_set --exists $f ||
738 error "root could not change hsm flags"
739 check_hsm_flags_user $f "0x00000001"
741 $LFS hsm_clear --exists $f ||
742 error "root could not clear hsm state"
743 check_hsm_flags_user $f "0x00000000"
746 run_test 1 "lfs hsm flags root/non-root access"
750 local f=$DIR/$tdir/$tfile
752 # New files are not dirty
753 check_hsm_flags $f "0x00000000"
755 # For test, we simulate an archived file.
756 $LFS hsm_set --exists $f || error "user could not change hsm flags"
757 check_hsm_flags $f "0x00000001"
759 # chmod do not put the file dirty
760 chmod 600 $f || error "could not chmod test file"
761 check_hsm_flags $f "0x00000001"
763 # chown do not put the file dirty
764 chown $RUNAS_ID $f || error "could not chown test file"
765 check_hsm_flags $f "0x00000001"
767 # truncate put the file dirty
768 $TRUNCATE $f 1 || error "could not truncate test file"
769 check_hsm_flags $f "0x00000003"
771 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
772 check_hsm_flags $f "0x00000001"
774 run_test 2 "Check file dirtyness when doing setattr"
780 # New files are not dirty
782 check_hsm_flags $f "0x00000000"
784 # For test, we simulate an archived file.
785 $LFS hsm_set --exists $f ||
786 error "user could not change hsm flags"
787 check_hsm_flags $f "0x00000001"
789 # Reading a file, does not set dirty
790 cat $f > /dev/null || error "could not read file"
791 check_hsm_flags $f "0x00000001"
793 # Open for write without modifying data, does not set dirty
794 openfile -f O_WRONLY $f || error "could not open test file"
795 check_hsm_flags $f "0x00000001"
797 # Append to a file sets it dirty
798 cp -p /etc/passwd $f.append || error "could not create file"
799 $LFS hsm_set --exists $f.append ||
800 error "user could not change hsm flags"
801 dd if=/etc/passwd of=$f.append bs=1 count=3\
802 conv=notrunc oflag=append status=noxfer ||
803 error "could not append to test file"
804 check_hsm_flags $f.append "0x00000003"
806 # Modify a file sets it dirty
807 cp -p /etc/passwd $f.modify || error "could not create file"
808 $LFS hsm_set --exists $f.modify ||
809 error "user could not change hsm flags"
810 dd if=/dev/zero of=$f.modify bs=1 count=3\
811 conv=notrunc status=noxfer ||
812 error "could not modify test file"
813 check_hsm_flags $f.modify "0x00000003"
815 # Open O_TRUNC sets dirty
816 cp -p /etc/passwd $f.trunc || error "could not create file"
817 $LFS hsm_set --exists $f.trunc ||
818 error "user could not change hsm flags"
819 cp /etc/group $f.trunc || error "could not override a file"
820 check_hsm_flags $f.trunc "0x00000003"
822 # Mmapped a file sets dirty
823 cp -p /etc/passwd $f.mmap || error "could not create file"
824 $LFS hsm_set --exists $f.mmap ||
825 error "user could not change hsm flags"
826 multiop $f.mmap OSMWUc || error "could not mmap a file"
827 check_hsm_flags $f.mmap "0x00000003"
829 run_test 3 "Check file dirtyness when opening for write"
833 local f=$DIR/$tdir/$tfile
834 local fid=$(make_small $f)
837 local st=$(get_request_state $fid CANCEL)
838 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
840 run_test 4 "Useless cancel must not be registered"
843 # test needs a running copytool
847 local f=$DIR/$tdir/$tfile
848 local fid=$(copy_file /etc/passwd $f)
850 wait_request_state $fid ARCHIVE SUCCEED
852 check_hsm_flags $f "0x00000009"
856 run_test 8 "Test default archive number"
860 local f=$DIR/$tdir/$tfile
861 local fid=$(copy_file /etc/passwd $f)
862 # we do not use the default one to be sure
863 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
865 copytool_setup $SINGLEAGT $MOUNT $new_an
866 $LFS hsm_archive --archive $new_an $f
867 wait_request_state $fid ARCHIVE SUCCEED
869 check_hsm_flags $f "0x00000009"
873 run_test 9 "Use of explict archive number, with dedicated copytool"
876 needclients 3 || return 0
882 copytool_cleanup $(comma_list $(agts_nodes))
884 # start all of the copytools
885 for n in $(seq $AGTCOUNT); do
889 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
892 for n in $(seq $AGTCOUNT); do
893 file=$DIR/$tdir/$tfile.$n
894 fid=$(make_small $file)
896 $LFS hsm_archive $file || error "could not archive file $file"
897 wait_request_state $fid ARCHIVE SUCCEED
898 check_hsm_flags $file "0x00000009"
902 copytool_cleanup $(comma_list $(agts_nodes))
904 run_test 9a "Multiple remote agents"
907 # test needs a running copytool
910 mkdir -p $DIR/$tdir/d1
911 local f=$DIR/$tdir/$tfile
912 local fid=$(copy_file /etc/hosts $f)
913 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
914 error "hsm_archive failed"
915 wait_request_state $fid ARCHIVE SUCCEED
917 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
918 error "fid $fid not in archive $HSM_ARCHIVE"
919 echo "Verifying content"
920 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
921 echo "Verifying hsm state "
922 check_hsm_flags $f "0x00000009"
924 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
925 local st=$(get_hsm_archive_id $f)
926 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
927 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
932 run_test 10a "Archive a file"
935 # test needs a running copytool
939 local f=$DIR/$tdir/$tfile
940 local fid=$(copy_file /etc/hosts $f)
941 $LFS hsm_archive $f || error "archive request failed"
942 wait_request_state $fid ARCHIVE SUCCEED
944 $LFS hsm_archive $f || error "archive of non dirty file failed"
945 local cnt=$(get_request_count $fid ARCHIVE)
946 [[ "$cnt" == "1" ]] ||
947 error "archive of non dirty file must not make a request"
951 run_test 10b "Archive of non dirty file must work without doing request"
954 # test needs a running copytool
958 local f=$DIR/$tdir/$tfile
959 local fid=$(copy_file /etc/hosts $f)
960 $LFS hsm_set --noarchive $f
961 $LFS hsm_archive $f && error "archive a noarchive file must fail"
965 run_test 10c "Check forbidden archive"
968 # test needs a running copytool
972 local f=$DIR/$tdir/$tfile
973 local fid=$(copy_file /etc/hosts $f)
974 $LFS hsm_archive $f || error "cannot archive $f"
975 wait_request_state $fid ARCHIVE SUCCEED
977 local ar=$(get_hsm_archive_id $f)
978 local dflt=$(get_hsm_param default_archive_id)
979 [[ $ar == $dflt ]] ||
980 error "archived file is not on default archive: $ar != $dflt"
984 run_test 10d "Archive a file on the default archive id"
988 copy2archive /etc/hosts $tdir/$tfile
989 local f=$DIR/$tdir/$tfile
991 import_file $tdir/$tfile $f
992 echo -n "Verifying released state: "
993 check_hsm_flags $f "0x0000000d"
995 local LSZ=$(stat -c "%s" $f)
996 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
998 echo "Verifying imported size $LSZ=$ASZ"
999 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1000 echo -n "Verifying released pattern: "
1001 local PTRN=$($GETSTRIPE -L $f)
1003 [[ $PTRN == 80000001 ]] || error "Is not released"
1004 local fid=$(path2fid $f)
1005 echo "Verifying new fid $fid in archive"
1007 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1008 error "fid $fid not in archive $HSM_ARCHIVE"
1010 run_test 11 "Import a file"
1013 # test needs a running copytool
1017 copy2archive /etc/hosts $tdir/$tfile
1019 local f=$DIR/$tdir/$tfile
1020 import_file $tdir/$tfile $f
1021 local f2=$DIR2/$tdir/$tfile
1022 echo "Verifying released state: "
1023 check_hsm_flags $f2 "0x0000000d"
1025 local fid=$(path2fid $f2)
1026 $LFS hsm_restore $f2
1027 wait_request_state $fid RESTORE SUCCEED
1029 echo "Verifying file state: "
1030 check_hsm_flags $f2 "0x00000009"
1032 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1034 [[ $? -eq 0 ]] || error "Restored file differs"
1038 run_test 12a "Restore an imported file explicitly"
1041 # test needs a running copytool
1045 copy2archive /etc/hosts $tdir/$tfile
1047 local f=$DIR/$tdir/$tfile
1048 import_file $tdir/$tfile $f
1049 echo "Verifying released state: "
1050 check_hsm_flags $f "0x0000000d"
1052 cat $f > /dev/null || error "File read failed"
1054 echo "Verifying file state after restore: "
1055 check_hsm_flags $f "0x00000009"
1057 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1059 [[ $? -eq 0 ]] || error "Restored file differs"
1063 run_test 12b "Restore an imported file implicitly"
1066 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1068 # test needs a running copytool
1072 local f=$DIR/$tdir/$tfile
1073 $LFS setstripe -c 2 $f
1074 local fid=$(make_large_for_striping $f)
1075 local FILE_CRC=$(md5sum $f)
1077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1078 wait_request_state $fid ARCHIVE SUCCEED
1079 $LFS hsm_release $f || error "release $f failed"
1081 echo "$FILE_CRC" | md5sum -c
1083 [[ $? -eq 0 ]] || error "Restored file differs"
1087 run_test 12c "Restore a file with stripe of 2"
1090 # test needs a running copytool
1095 local f=$DIR/$tdir/$tfile
1096 local fid=$(copy_file /etc/hosts $f)
1097 $LFS hsm_restore $f || error "restore of non archived file failed"
1098 local cnt=$(get_request_count $fid RESTORE)
1099 [[ "$cnt" == "0" ]] ||
1100 error "restore non archived must not make a request"
1101 $LFS hsm_archive $f ||
1102 error "archive request failed"
1103 wait_request_state $fid ARCHIVE SUCCEED
1104 $LFS hsm_restore $f ||
1105 error "restore of non released file failed"
1106 local cnt=$(get_request_count $fid RESTORE)
1107 [[ "$cnt" == "0" ]] ||
1108 error "restore a non dirty file must not make a request"
1112 run_test 12d "Restore of a non archived, non released file must work"\
1113 " without doing request"
1116 # test needs a running copytool
1119 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1120 local f=$DIR/$tdir/$tfile
1121 local fid=$(copy_file /etc/hosts $f)
1122 $LFS hsm_archive $f || error "archive request failed"
1123 wait_request_state $fid ARCHIVE SUCCEED
1126 cat /etc/hosts >> $f
1130 $LFS hsm_restore $f && error "restore a dirty file must fail"
1134 run_test 12e "Check forbidden restore"
1137 # test needs a running copytool
1141 local f=$DIR/$tdir/$tfile
1142 local fid=$(copy_file /etc/hosts $f)
1144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1145 wait_request_state $fid ARCHIVE SUCCEED
1146 $LFS hsm_release $f || error "release of $f failed"
1148 wait_request_state $fid RESTORE SUCCEED
1150 echo -n "Verifying file state: "
1151 check_hsm_flags $f "0x00000009"
1153 diff -q /etc/hosts $f
1155 [[ $? -eq 0 ]] || error "Restored file differs"
1159 run_test 12f "Restore a released file explicitly"
1162 # test needs a running copytool
1166 local f=$DIR/$tdir/$tfile
1167 local fid=$(copy_file /etc/hosts $f)
1169 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1170 wait_request_state $fid ARCHIVE SUCCEED
1171 $LFS hsm_release $f || error "release of $f failed"
1173 diff -q /etc/hosts $f
1176 # we check we had a restore done
1177 wait_request_state $fid RESTORE SUCCEED
1179 [[ $st -eq 0 ]] || error "Restored file differs"
1183 run_test 12g "Restore a released file implicitly"
1186 needclients 2 || return 0
1188 # test needs a running copytool
1192 local f=$DIR/$tdir/$tfile
1193 local fid=$(copy_file /etc/hosts $f)
1195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1196 wait_request_state $fid ARCHIVE SUCCEED
1197 $LFS hsm_release $f || error "release of $f failed"
1199 do_node $CLIENT2 diff -q /etc/hosts $f
1202 # we check we had a restore done
1203 wait_request_state $fid RESTORE SUCCEED
1205 [[ $st -eq 0 ]] || error "Restored file differs"
1209 run_test 12h "Restore a released file implicitly from a second node"
1212 # test needs a running copytool
1216 local f=$DIR/$tdir/$tfile
1217 local fid=$(copy_file /etc/passwd $f)
1218 $LFS hsm_archive $f || error "archive of $f failed"
1219 wait_request_state $fid ARCHIVE SUCCEED
1221 $LFS hsm_release $f || error "release of $f failed"
1225 [[ $? -eq 0 ]] || error "Restored file differs"
1229 run_test 12m "Archive/release/implicit restore"
1232 # test needs a running copytool
1236 copy2archive /etc/hosts $tdir/$tfile
1238 local f=$DIR/$tdir/$tfile
1239 import_file $tdir/$tfile $f
1241 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1242 error "Restored file differs"
1244 $LFS hsm_release $f || error "release of $f failed"
1248 run_test 12n "Import/implicit restore/release"
1251 # test needs a running copytool
1255 local f=$DIR/$tdir/$tfile
1256 local fid=$(copy_file /etc/hosts $f)
1258 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1259 wait_request_state $fid ARCHIVE SUCCEED
1260 $LFS hsm_release $f || error "release of $f failed"
1262 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1263 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1265 # set no retry action mode
1268 diff -q /etc/hosts $f
1271 # we check we had a restore failure
1272 wait_request_state $fid RESTORE FAILED
1274 [[ $st -eq 0 ]] && error "Restore must fail"
1276 # remove no retry action mode
1279 # check file is still released
1280 check_hsm_flags $f "0x0000000d"
1282 # retry w/o failure injection
1283 do_facet $SINGLEMDS lctl set_param fail_loc=0
1285 # to be sure previous RESTORE result is gone
1287 wait_for_grace_delay
1289 diff -q /etc/hosts $f
1292 # we check we had a restore done
1293 wait_request_state $fid RESTORE SUCCEED
1295 [[ $st -eq 0 ]] || error "Restored file differs"
1299 run_test 12o "Layout-swap failure during Restore leaves file released"
1302 # test needs a running copytool
1305 local ARC_SUBDIR="import.orig"
1309 # populate directory to be imported
1310 for d in $(seq 1 10); do
1311 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1312 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1313 for f in $(seq 1 10); do
1314 CURR_FILE="$CURR_DIR/$tfile.$f"
1315 # write file-specific data
1316 do_facet $SINGLEAGT \
1317 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1318 "file=$CURR_FILE > $CURR_FILE"
1322 import_file "$ARC_SUBDIR" $DIR/$tdir
1323 # diff lustre content and origin (triggers file restoration)
1324 # there must be 10x10 identical files, and no difference
1325 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1326 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1327 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1328 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1330 [ $cnt_diff -eq 0 ] ||
1331 error "$cnt_diff imported files differ from read data"
1332 [ $cnt_ok -eq 100 ] ||
1333 error "not enough identical files ($cnt_ok != 100)"
1337 run_test 13 "Recursively import and restore a directory"
1340 # test needs a running copytool
1345 local f=$DIR/$tdir/$tfile
1346 local fid=$(make_small $f)
1347 local sum=$(md5sum $f | awk '{print $1}')
1348 $LFS hsm_archive $f || error "could not archive file"
1349 wait_request_state $fid ARCHIVE SUCCEED
1353 # create released file (simulate llapi_hsm_import call)
1355 local fid2=$(path2fid $f)
1356 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1357 $LFS hsm_release $f || error "could not release file"
1359 # rebind the archive to the newly created file
1360 echo "rebind $fid to $fid2"
1362 do_facet $SINGLEAGT \
1363 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1364 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1366 # restore file and compare md5sum
1367 local sum2=$(md5sum $f | awk '{print $1}')
1369 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1373 run_test 14 "Rebind archived file to a new fid"
1376 # test needs a running copytool
1381 local f=$DIR/$tdir/$tfile
1383 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1387 for i in $(seq 1 $count); do
1388 fids[$i]=$(make_small $f.$i)
1389 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1390 $LFS hsm_archive $f.$i || error "could not archive file"
1392 wait_all_done $(($count*60))
1396 for i in $(seq 1 $count); do
1399 local fid2=$(path2fid $f.$i)
1400 # add the rebind operation to the list
1401 echo ${fids[$i]} $fid2 >> $tmpfile
1403 # set it released (simulate llapi_hsm_import call)
1404 $LFS hsm_set --archived --exists $f.$i ||
1405 error "could not force hsm flags"
1406 $LFS hsm_release $f.$i || error "could not release file"
1408 nl=$(wc -l < $tmpfile)
1409 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1411 echo "rebind list of files"
1412 do_facet $SINGLEAGT \
1413 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1414 --rebind $tmpfile $DIR" || error "could not rebind file list"
1416 # restore files and compare md5sum
1417 for i in $(seq 1 $count); do
1418 local sum2=$(md5sum $f.$i | awk '{print $1}')
1419 [[ $sum2 == ${sums[$i]} ]] ||
1420 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1426 run_test 15 "Rebind a list of files"
1429 # test needs a running copytool
1433 # create a known size file so we can verify transfer speed
1436 dd if=/dev/zero of=$ref bs=1M count=20
1439 local f=$DIR/$tdir/$tfile
1440 local fid=$(copy_file $ref $f)
1442 local start=$(date +%s)
1444 wait_request_state $fid ARCHIVE SUCCEED
1445 local end=$(date +%s)
1446 local duration=$((end - start))
1448 [[ $duration -ge $goal ]] ||
1449 error "Transfer is too fast $duration < $goal"
1453 run_test 16 "Test CT bandwith control option"
1458 local f=$DIR/$tdir/$tfile
1459 touch $f || error "touch $f failed"
1461 # Could not release a non-archived file
1462 $LFS hsm_release $f && error "release should not succeed"
1464 # For following tests, we must test them with HS_ARCHIVED set
1465 $LFS hsm_set --exists --archived $f || error "could not add flag"
1467 # Could not release a file if no-release is set
1468 $LFS hsm_set --norelease $f || error "could not add flag"
1469 $LFS hsm_release $f && error "release should not succeed"
1470 $LFS hsm_clear --norelease $f || error "could not remove flag"
1472 # Could not release a file if lost
1473 $LFS hsm_set --lost $f || error "could not add flag"
1474 $LFS hsm_release $f && error "release should not succeed"
1475 $LFS hsm_clear --lost $f || error "could not remove flag"
1477 # Could not release a file if dirty
1478 $LFS hsm_set --dirty $f || error "could not add flag"
1479 $LFS hsm_release $f && error "release should not succeed"
1480 $LFS hsm_clear --dirty $f || error "could not remove flag"
1482 run_test 20 "Release is not permitted"
1485 # test needs a running copytool
1489 local f=$DIR/$tdir/test_release
1491 # Create a file and check its states
1492 local fid=$(make_small $f)
1493 check_hsm_flags $f "0x00000000"
1495 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1496 # used until file is flushed to disk
1497 if [ $(facet_fstype ost1) == "zfs" ]; then
1498 # this causes an OST_SYNC rpc to be sent
1499 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1500 # clear locks to reread file data
1501 cancel_lru_locks osc
1504 local orig_size=$(stat -c "%s" $f)
1505 local orig_blocks=$(stat -c "%b" $f)
1507 start_full_debug_logging
1509 $LFS hsm_archive $f || error "could not archive file"
1510 wait_request_state $fid ARCHIVE SUCCEED
1512 local blocks=$(stat -c "%b" $f)
1513 [ $blocks -eq $orig_blocks ] ||
1514 error "$f: wrong block number after archive: " \
1515 "$blocks != $orig_blocks"
1516 local size=$(stat -c "%s" $f)
1517 [ $size -eq $orig_size ] ||
1518 error "$f: wrong size after archive: $size != $orig_size"
1520 # Release and check states
1521 $LFS hsm_release $f || error "could not release file"
1522 check_hsm_flags $f "0x0000000d"
1524 blocks=$(stat -c "%b" $f)
1525 [ $blocks -gt 5 ] &&
1526 error "$f: too many blocks after release: $blocks > 5"
1527 size=$(stat -c "%s" $f)
1528 [ $size -ne $orig_size ] &&
1529 error "$f: wrong size after release: $size != $orig_size"
1531 # Check we can release an file without stripe info
1535 check_hsm_flags $f "0x00000000"
1536 $LFS hsm_archive $f || error "could not archive file"
1537 wait_request_state $fid ARCHIVE SUCCEED
1539 # Release and check states
1540 $LFS hsm_release $f || error "could not release file"
1541 check_hsm_flags $f "0x0000000d"
1543 # Release again a file that is already released is OK
1544 $LFS hsm_release $f || fail "second release should succeed"
1545 check_hsm_flags $f "0x0000000d"
1547 stop_full_debug_logging
1551 run_test 21 "Simple release tests"
1554 # test needs a running copytool
1559 local f=$DIR/$tdir/test_release
1560 local swap=$DIR/$tdir/test_swap
1562 # Create a file and check its states
1563 local fid=$(make_small $f)
1564 check_hsm_flags $f "0x00000000"
1566 $LFS hsm_archive $f || error "could not archive file"
1567 wait_request_state $fid ARCHIVE SUCCEED
1569 # Release and check states
1570 $LFS hsm_release $f || error "could not release file"
1571 check_hsm_flags $f "0x0000000d"
1574 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1579 run_test 22 "Could not swap a release file"
1582 # test needs a running copytool
1587 local f=$DIR/$tdir/test_mtime
1589 # Create a file and check its states
1590 local fid=$(make_small $f)
1591 check_hsm_flags $f "0x00000000"
1593 $LFS hsm_archive $f || error "could not archive file"
1594 wait_request_state $fid ARCHIVE SUCCEED
1596 # Set modification time in the past
1597 touch -m -a -d @978261179 $f
1599 # Release and check states
1600 $LFS hsm_release $f || error "could not release file"
1601 check_hsm_flags $f "0x0000000d"
1603 local MTIME=$(stat -c "%Y" $f)
1604 local ATIME=$(stat -c "%X" $f)
1605 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1606 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1610 run_test 23 "Release does not change a/mtime (utime)"
1613 local file=$DIR/$tdir/$tfile
1622 # test needs a running copytool
1627 fid=$(make_small $file)
1629 # Create a file and check its states
1630 check_hsm_flags $file "0x00000000"
1632 # Ensure atime is less than mtime and ctime.
1636 atime0=$(stat -c "%X" $file)
1637 mtime0=$(stat -c "%Y" $file)
1638 ctime0=$(stat -c "%Z" $file)
1640 [ $atime0 -lt $mtime0 ] ||
1641 error "atime $atime0 is not less than mtime $mtime0"
1643 [ $atime0 -lt $ctime0 ] ||
1644 error "atime $atime0 is not less than ctime $ctime0"
1646 # Archive should not change any timestamps.
1647 $LFS hsm_archive $file || error "cannot archive '$file'"
1648 wait_request_state $fid ARCHIVE SUCCEED
1650 atime1=$(stat -c "%X" $file)
1651 mtime1=$(stat -c "%Y" $file)
1652 ctime1=$(stat -c "%Z" $file)
1654 [ $atime0 -eq $atime1 ] ||
1655 error "archive changed atime from $atime0 to $atime1"
1657 [ $mtime0 -eq $mtime1 ] ||
1658 error "archive changed mtime from $mtime0 to $mtime1"
1660 [ $ctime0 -eq $ctime1 ] ||
1661 error "archive changed ctime from $ctime0 to $ctime1"
1663 # Release should not change any timestamps.
1664 $LFS hsm_release $file || error "cannot release '$file'"
1665 check_hsm_flags $file "0x0000000d"
1667 atime1=$(stat -c "%X" $file)
1668 mtime1=$(stat -c "%Y" $file)
1669 ctime1=$(stat -c "%Z" $file)
1671 [ $atime0 -eq $atime1 ] ||
1672 error "release changed atime from $atime0 to $atime1"
1674 [ $mtime0 -eq $mtime1 ] ||
1675 error "release changed mtime from $mtime0 to $mtime1"
1677 [ $ctime0 -eq $ctime1 ] ||
1678 error "release changed ctime from $ctime0 to $ctime1"
1680 # Restore should not change atime or mtime and should not
1682 $LFS hsm_restore $file
1683 wait_request_state $fid RESTORE SUCCEED
1685 atime1=$(stat -c "%X" $file)
1686 mtime1=$(stat -c "%Y" $file)
1687 ctime1=$(stat -c "%Z" $file)
1689 [ $atime0 -eq $atime1 ] ||
1690 error "restore changed atime from $atime0 to $atime1"
1692 [ $mtime0 -eq $mtime1 ] ||
1693 error "restore changed mtime from $mtime0 to $mtime1"
1695 [ $ctime0 -le $ctime1 ] ||
1696 error "restore changed ctime from $ctime0 to $ctime1"
1700 # Once more, after unmount and mount.
1701 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1702 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1704 atime1=$(stat -c "%X" $file)
1705 mtime1=$(stat -c "%Y" $file)
1706 ctime1=$(stat -c "%Z" $file)
1708 [ $atime0 -eq $atime1 ] ||
1709 error "remount changed atime from $atime0 to $atime1"
1711 [ $mtime0 -eq $mtime1 ] ||
1712 error "remount changed mtime from $mtime0 to $mtime1"
1714 [ $ctime0 -le $ctime1 ] ||
1715 error "remount changed ctime from $ctime0 to $ctime1"
1717 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1720 local file=$DIR/$tdir/$tfile
1726 # Test needs a running copytool.
1730 # Check that root can do HSM actions on a ordinary user's file.
1732 fid=$(make_small $file)
1733 sum0=$(md5sum $file)
1735 chown $RUNAS_ID:$RUNAS_GID $file ||
1736 error "cannot chown '$file' to '$RUNAS_ID'"
1738 chmod ugo-w $DIR/$tdir ||
1739 error "cannot chmod '$DIR/$tdir'"
1741 $LFS hsm_archive $file
1742 wait_request_state $fid ARCHIVE SUCCEED
1744 $LFS hsm_release $file
1745 check_hsm_flags $file "0x0000000d"
1747 $LFS hsm_restore $file
1748 wait_request_state $fid RESTORE SUCCEED
1750 # Check that ordinary user can get HSM state.
1751 $RUNAS $LFS hsm_state $file ||
1752 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1754 $LFS hsm_release $file
1755 check_hsm_flags $file "0x0000000d"
1757 # Check that ordinary user can accessed released file.
1758 sum1=$($RUNAS md5sum $file) ||
1759 error "user '$RUNAS_ID' cannot read '$file'"
1761 [ "$sum0" == "$sum1" ] ||
1762 error "md5sum mismatch for '$file'"
1766 run_test 24b "root can archive, release, and restore user files"
1768 cleanup_test_24c() {
1770 set_hsm_param user_request_mask RESTORE
1771 set_hsm_param group_request_mask RESTORE
1772 set_hsm_param other_request_mask RESTORE
1776 local file=$DIR/$tdir/$tfile
1777 local action=archive
1782 # test needs a running copytool
1787 # Save the default masks and check that cleanup_24c will
1788 # restore the request masks correctly.
1789 user_save=$(get_hsm_param user_request_mask)
1790 group_save=$(get_hsm_param group_request_mask)
1791 other_save=$(get_hsm_param other_request_mask)
1793 [ "$user_save" == RESTORE ] ||
1794 error "user_request_mask is '$user_save' expected 'RESTORE'"
1795 [ "$group_save" == RESTORE ] ||
1796 error "group_request_mask is '$group_save' expected 'RESTORE'"
1797 [ "$other_save" == RESTORE ] ||
1798 error "other_request_mask is '$other_save' expected 'RESTORE'"
1800 trap cleanup_test_24c EXIT
1805 chown $RUNAS_ID:nobody $file ||
1806 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1808 set_hsm_param user_request_mask ""
1809 $RUNAS $LFS hsm_$action $file &&
1810 error "$action by user should fail"
1812 set_hsm_param user_request_mask $action
1813 $RUNAS $LFS hsm_$action $file ||
1814 error "$action by user should succeed"
1819 chown nobody:$RUNAS_GID $file ||
1820 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1822 set_hsm_param group_request_mask ""
1823 $RUNAS $LFS hsm_$action $file &&
1824 error "$action by group should fail"
1826 set_hsm_param group_request_mask $action
1827 $RUNAS $LFS hsm_$action $file ||
1828 error "$action by group should succeed"
1833 chown nobody:nobody $file ||
1834 error "cannot chown '$file' to 'nobody:nobody'"
1836 set_hsm_param other_request_mask ""
1837 $RUNAS $LFS hsm_$action $file &&
1838 error "$action by other should fail"
1840 set_hsm_param other_request_mask $action
1841 $RUNAS $LFS hsm_$action $file ||
1842 error "$action by other should succeed"
1847 run_test 24c "check that user,group,other request masks work"
1849 cleanup_test_24d() {
1851 mount -o remount,rw $MOUNT2
1855 local file1=$DIR/$tdir/$tfile
1856 local file2=$DIR2/$tdir/$tfile
1864 fid1=$(make_small $file1)
1866 trap cleanup_test_24d EXIT
1868 mount -o remount,ro $MOUNT2
1870 fid2=$(path2fid $file2)
1871 [ "$fid1" == "$fid2" ] ||
1872 error "FID mismatch '$fid1' != '$fid2'"
1874 $LFS hsm_archive $file2 &&
1875 error "archive should fail on read-only mount"
1876 check_hsm_flags $file1 "0x00000000"
1878 $LFS hsm_archive $file1
1879 wait_request_state $fid1 ARCHIVE SUCCEED
1881 $LFS hsm_release $file1
1882 $LFS hsm_restore $file2
1883 wait_request_state $fid1 RESTORE SUCCEED
1885 $LFS hsm_release $file1 || error "cannot release '$file1'"
1886 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1888 $LFS hsm_release $file2 &&
1889 error "release should fail on read-only mount"
1894 run_test 24d "check that read-only mounts are respected"
1897 # test needs a running copytool
1901 copy2archive /etc/hosts $tdir/$tfile
1903 local f=$DIR/$tdir/$tfile
1905 import_file $tdir/$tfile $f
1907 $LFS hsm_set --lost $f
1912 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1916 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1917 " (Operation not permitted)"
1920 # test needs a running copytool
1925 local f=$DIR/$tdir/$tfile
1926 local fid=$(copy_file /etc/passwd $f)
1928 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1929 wait_request_state $fid ARCHIVE SUCCEED
1932 $LFS hsm_set --lost $f
1936 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1940 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1941 " (Operation not permitted)"
1944 # test needs a running copytool
1948 local f=$DIR/$tdir/$tfile
1949 local fid=$(make_large_for_progress $f)
1950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1951 wait_request_state $fid ARCHIVE SUCCEED
1954 wait_request_state $fid REMOVE SUCCEED
1956 check_hsm_flags $f "0x00000000"
1960 run_test 26 "Remove the archive of a valid file"
1963 # test needs a running copytool
1967 make_archive $tdir/$tfile
1968 local f=$DIR/$tdir/$tfile
1969 import_file $tdir/$tfile $f
1970 local fid=$(path2fid $f)
1974 [[ $? != 0 ]] || error "Remove of a released file should fail"
1978 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1981 # test needs a running copytool
1985 local f=$DIR/$tdir/$tfile
1986 local fid=$(make_large_for_progress $f)
1987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1988 wait_request_state $fid ARCHIVE SUCCEED
1993 [[ $? != 0 ]] || error "Remove of a released file should fail"
1997 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2000 # test needs a running copytool
2004 local f=$DIR/$tdir/$tfile
2005 local fid=$(make_large_for_progress $f)
2006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2007 wait_request_state $fid ARCHIVE SUCCEED
2016 wait_request_state $fid REMOVE SUCCEED
2020 run_test 28 "Concurrent archive/file remove"
2023 # restore at exec cannot work on agent node (because of Linux kernel
2024 # protection of executables)
2025 needclients 2 || return 0
2027 # test needs a running copytool
2031 copy2archive /bin/true $tdir/$tfile
2033 local f=$DIR/$tdir/true
2034 import_file $tdir/$tfile $f
2036 local fid=$(path2fid $f)
2038 # set no retry action mode
2044 # remove no try action mode
2048 [[ $st == 0 ]] || error "Failed to exec a released file"
2052 run_test 30a "Restore at exec (import case)"
2055 # restore at exec cannot work on agent node (because of Linux kernel
2056 # protection of executables)
2057 needclients 2 || return 0
2059 # test needs a running copytool
2063 local f=$DIR/$tdir/true
2064 local fid=$(copy_file /bin/true $f)
2066 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2067 wait_request_state $fid ARCHIVE SUCCEED
2070 # set no retry action mode
2076 # remove no try action mode
2080 [[ $st == 0 ]] || error "Failed to exec a released file"
2084 run_test 30b "Restore at exec (release case)"
2087 needclients 2 || return 0
2089 # test needs a running copytool
2093 local f=$DIR/$tdir/SLEEP
2094 local fid=$(copy_file /bin/sleep $f)
2096 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2097 wait_request_state $fid ARCHIVE SUCCEED
2099 check_hsm_flags $f "0x0000000d"
2100 # set no retry action mode
2102 do_node $CLIENT2 "$f 10" &
2106 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2108 [[ $? == 0 ]] || error "Execution failed during run"
2110 [[ $? == 0 ]] || error "Binary overwritten during exec"
2113 # remove no try action mode
2115 check_hsm_flags $f "0x00000009"
2119 run_test 30c "Update during exec of released file must fail"
2121 restore_and_check_size() {
2124 local s=$(stat -c "%s" $f)
2126 local st=$(get_hsm_flags $f)
2130 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2132 n=$(stat -c "%s" $f)
2133 # we echo in both cases to show stat is not
2135 if [[ $n != $s ]]; then
2136 echo "size seen is $n != $s"
2139 echo "size seen is right: $n == $s"
2141 st=$(get_hsm_flags $f)
2145 if [[ $cpt -lt 10 ]]; then
2148 echo " restore is too long"
2149 wait_request_state $fid RESTORE SUCCEED
2155 # test needs a running copytool
2160 make_archive $tdir/$tfile
2161 local f=$DIR/$tdir/$tfile
2162 import_file $tdir/$tfile $f
2163 local fid=$($LFS path2fid $f)
2164 HSM_ARCHIVE_PURGE=false copytool_setup
2166 restore_and_check_size $f $fid
2169 [[ $err -eq 0 ]] || error "File size changed during restore"
2173 run_test 31a "Import a large file and check size during restore"
2177 # test needs a running copytool
2182 local f=$DIR/$tdir/$tfile
2183 local fid=$(make_large_for_progress $f)
2184 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2185 wait_request_state $fid ARCHIVE SUCCEED
2188 restore_and_check_size $f $fid
2191 [[ $err -eq 0 ]] || error "File size changed during restore"
2195 run_test 31b "Restore a large unaligned file and check size during restore"
2198 # test needs a running copytool
2203 local f=$DIR/$tdir/$tfile
2204 local fid=$(make_large_for_progress_aligned $f)
2205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2206 wait_request_state $fid ARCHIVE SUCCEED
2209 restore_and_check_size $f $fid
2212 [[ $err -eq 0 ]] || error "File size changed during restore"
2216 run_test 31c "Restore a large aligned file and check size during restore"
2219 # test needs a running copytool
2224 local f=$DIR/$tdir/$tfile
2225 local fid=$(make_large_for_progress $f)
2226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2227 wait_request_state $fid ARCHIVE SUCCEED
2230 # to be sure wait_all_done will not be mislead by previous tests
2233 wait_for_grace_delay
2234 # Also raise grace_delay significantly so the Canceled
2235 # Restore action will stay enough long avail.
2236 local old_grace=$(get_hsm_param grace_delay)
2237 set_hsm_param grace_delay 100
2239 md5sum $f >/dev/null &
2241 wait_request_state $fid RESTORE STARTED
2246 # Check restore trigger process was killed
2247 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2251 # instead of waiting+checking both Restore and Cancel ops
2252 # sequentially, wait for both to be finished and then check
2254 wait_all_done 100 $fid
2255 local rstate=$(get_request_state $fid RESTORE)
2256 local cstate=$(get_request_state $fid CANCEL)
2258 # restore orig grace_delay.
2259 set_hsm_param grace_delay $old_grace
2261 if [[ "$rstate" == "CANCELED" ]] ; then
2262 [[ "$cstate" == "SUCCEED" ]] ||
2263 error "Restore state is CANCELED and Cancel state " \
2264 "is not SUCCEED but $cstate"
2265 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2266 elif [[ "$rstate" == "SUCCEED" ]] ; then
2267 [[ "$cstate" == "FAILED" ]] ||
2268 error "Restore state is SUCCEED and Cancel state " \
2269 "is not FAILED but $cstate"
2270 echo "Restore state is SUCCEED, Cancel state is FAILED"
2272 error "Restore state is $rstate and Cancel state is $cstate"
2276 error "Cannot kill process waiting for restore ($killed)"
2280 run_test 33 "Kill a restore waiting process"
2283 # test needs a running copytool
2288 local f=$DIR/$tdir/$tfile
2289 local fid=$(make_large_for_progress $f)
2290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2291 wait_request_state $fid ARCHIVE SUCCEED
2294 md5sum $f >/dev/null &
2296 wait_request_state $fid RESTORE STARTED
2298 rm $f || error "rm $f failed"
2299 # rm must not block during restore
2300 wait_request_state $fid RESTORE STARTED
2302 wait_request_state $fid RESTORE SUCCEED
2303 # check md5sum pgm finished
2304 local there=$(ps -o pid,comm hp $pid >/dev/null)
2305 [[ -z $there ]] || error "Restore initiator does not exit"
2307 local rc=$(wait $pid)
2308 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2312 run_test 34 "Remove file during restore"
2315 # test needs a running copytool
2320 local f=$DIR/$tdir/$tfile
2321 local f1=$DIR/$tdir/$tfile-1
2322 local fid=$(make_large_for_progress $f)
2323 local fid1=$(copy_file /etc/passwd $f1)
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2325 wait_request_state $fid ARCHIVE SUCCEED
2328 md5sum $f >/dev/null &
2330 wait_request_state $fid RESTORE STARTED
2332 mv $f1 $f || error "mv $f1 $f failed"
2333 # mv must not block during restore
2334 wait_request_state $fid RESTORE STARTED
2336 wait_request_state $fid RESTORE SUCCEED
2337 # check md5sum pgm finished
2338 local there=$(ps -o pid,comm hp $pid >/dev/null)
2339 [[ -z $there ]] || error "Restore initiator does not exit"
2341 local rc=$(wait $pid)
2342 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2345 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2349 run_test 35 "Overwrite file during restore"
2352 # test needs a running copytool
2357 local f=$DIR/$tdir/$tfile
2358 local fid=$(make_large_for_progress $f)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2360 wait_request_state $fid ARCHIVE SUCCEED
2363 md5sum $f >/dev/null &
2365 wait_request_state $fid RESTORE STARTED
2368 # rm must not block during restore
2369 wait_request_state $fid RESTORE STARTED
2371 wait_request_state $fid RESTORE SUCCEED
2372 # check md5sum pgm finished
2373 local there=$(ps -o pid,comm hp $pid >/dev/null)
2375 error "Restore initiator does not exit"
2377 local rc=$(wait $pid)
2379 error "Restore initiator failed with $rc"
2383 run_test 36 "Move file during restore"
2390 for n in $(seq 1 $count); do
2391 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2393 echo "$count archive requests submitted"
2397 local stream_count=4
2398 local file_count=100
2400 local f=$DIR/$tdir/$tfile
2405 for i in $(seq 1 $file_count); do
2406 for p in $(seq 1 $stream_count); do
2407 fid=$(copy_file /etc/hosts $f.$p.$i)
2410 # force copytool to use a local/temp archive dir to ensure best
2411 # performance vs remote/NFS mounts used in auto-tests
2412 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2415 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2417 # to be sure wait_all_done will not be mislead by previous tests
2419 wait_for_grace_delay
2421 # start archive streams in background (archive files in parallel)
2422 for p in $(seq 1 $stream_count); do
2423 multi_archive $f.$p $file_count &
2426 echo -n "Wait for all requests being enqueued..."
2432 run_test 40 "Parallel archive requests"
2435 # test needs a running copytool
2439 local f=$DIR/$tdir/$tfile
2440 local fid=$(copy_file /etc/motd $f 1)
2442 $LFS hsm_archive $f || error "could not archive file"
2443 wait_request_state $fid ARCHIVE SUCCEED
2444 check_hsm_flags $f "0x00000009"
2446 multiop_bg_pause $f O_c || error "multiop failed"
2450 client_up || client_up || true
2452 kill -USR1 $MULTIPID
2453 wait $MULTIPID || error "multiop close failed"
2455 check_hsm_flags $f "0x0000000b"
2459 run_test 52 "Opened for write file on an evicted client should be set dirty"
2462 # test needs a running copytool
2466 local f=$DIR/$tdir/$tfile
2467 local fid=$(copy_file /etc/motd $f 1)
2469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2470 error "could not archive file"
2471 wait_request_state $fid ARCHIVE SUCCEED
2472 check_hsm_flags $f "0x00000009"
2474 multiop_bg_pause $f o_c || error "multiop failed"
2478 client_up || client_up || true
2480 kill -USR1 $MULTIPID
2481 wait $MULTIPID || error "multiop close failed"
2483 check_hsm_flags $f "0x00000009"
2487 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2490 # test needs a running copytool
2494 local f=$DIR/$tdir/$tfile
2495 local fid=$(make_small $f)
2497 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2498 error "could not archive file"
2499 wait_request_state $fid ARCHIVE STARTED
2501 check_hsm_flags $f "0x00000001"
2503 # Avoid coordinator resending this request as soon it has failed.
2508 wait_request_state $fid ARCHIVE FAILED
2510 check_hsm_flags $f "0x00000003"
2515 run_test 54 "Write during an archive cancels it"
2518 # test needs a running copytool
2522 local f=$DIR/$tdir/$tfile
2523 local fid=$(make_small $f)
2525 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2526 error "could not archive file"
2527 wait_request_state $fid ARCHIVE STARTED
2529 check_hsm_flags $f "0x00000001"
2531 # Avoid coordinator resending this request as soon it has failed.
2534 $TRUNCATE $f 1024 || error "truncate failed"
2536 wait_request_state $fid ARCHIVE FAILED
2538 check_hsm_flags $f "0x00000003"
2543 run_test 55 "Truncate during an archive cancels it"
2546 # test needs a running copytool
2550 local f=$DIR/$tdir/$tfile
2551 local fid=$(make_large_for_progress $f)
2553 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2554 error "could not archive file"
2555 wait_request_state $fid ARCHIVE STARTED
2557 check_hsm_flags $f "0x00000001"
2559 # Change metadata and sync to be sure we are not changing only
2564 wait_request_state $fid ARCHIVE SUCCEED
2566 check_hsm_flags $f "0x00000009"
2570 run_test 56 "Setattr during an archive is ok"
2573 # Need one client for I/O, one for request
2574 needclients 2 || return 0
2576 # test needs a running copytool
2580 local f=$DIR/$tdir/test_archive_remote
2581 # Create a file on a remote node
2582 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2583 "count=2 conv=fsync"
2586 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2587 error "hsm_archive failed"
2588 local fid=$(path2fid $f)
2589 wait_request_state $fid ARCHIVE SUCCEED
2591 # Release and implicit restore it
2592 do_node $CLIENT2 "$LFS hsm_release $f" ||
2593 error "hsm_release failed"
2594 do_node $CLIENT2 "md5sum $f" ||
2595 error "hsm_restore failed"
2597 wait_request_state $fid RESTORE SUCCEED
2601 run_test 57 "Archive a file with dirty cache on another node"
2603 truncate_released_file() {
2607 local sz=$(stat -c %s $src_file)
2608 local f=$DIR/$tdir/$tfile
2609 local fid=$(copy_file $1 $f)
2613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2614 error "could not archive file"
2615 wait_request_state $fid ARCHIVE SUCCEED
2617 $LFS hsm_release $f || error "could not release file"
2619 $TRUNCATE $f $trunc_to || error "truncate failed"
2622 local sz1=$(stat -c %s $f)
2623 [[ $sz1 == $trunc_to ]] ||
2624 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2627 check_hsm_flags $f "0x0000000b"
2629 local state=$(get_request_state $fid RESTORE)
2630 [[ "$state" == "SUCCEED" ]] ||
2631 error "truncate $sz does not trig restore, state = $state"
2633 $TRUNCATE $ref $trunc_to
2634 cmp $ref $f || error "file data wrong after truncate"
2640 # test needs a running copytool
2645 local sz=$(stat -c %s /etc/passwd)
2647 echo "truncate up from $sz to $((sz*2))"
2648 truncate_released_file /etc/passwd $((sz*2))
2650 echo "truncate down from $sz to $((sz/2))"
2651 truncate_released_file /etc/passwd $((sz/2))
2653 echo "truncate to 0"
2654 truncate_released_file /etc/passwd 0
2658 run_test 58 "Truncate a released file will trigger restore"
2661 # This test validates the fix for LU-4512. Ensure that the -u
2662 # option changes the progress reporting interval from the default
2663 # (30 seconds) to the user-specified interval.
2665 local progress_timeout=$((interval * 3))
2667 # test needs a new running copytool
2669 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2672 local f=$DIR/$tdir/$tfile
2673 local fid=$(make_large_for_progress $f)
2675 local start_at=$(date +%s)
2676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2677 error "could not archive file"
2680 local mdt=${MDT_PREFIX}${mdtidx}
2681 local mds=mds$((mdtidx + 1))
2683 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2684 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2690 echo -n "Expecting a progress update within $progress_timeout seconds... "
2692 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2693 if [ $RESULT -gt 0 ]; then
2694 echo "$RESULT bytes copied in $WAIT seconds."
2696 elif [ $WAIT -ge $progress_timeout ]; then
2697 error "Timed out waiting for progress update!"
2700 WAIT=$((WAIT + sleep))
2704 local finish_at=$(date +%s)
2705 local elapsed=$((finish_at - start_at))
2707 # Ensure that the progress update occurred within the expected window.
2708 if [ $elapsed -lt $interval ]; then
2709 error "Expected progress update after at least $interval seconds"
2715 run_test 60 "Changing progress update interval from default"
2718 # test needs a new running copytool
2720 copytool_monitor_setup
2721 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2723 # Just start and stop the copytool to generate events.
2727 local REGISTER_EVENT
2728 local UNREGISTER_EVENT
2729 while read event; do
2730 local parsed=$(parse_json_event "$event")
2731 if [ -z "$parsed" ]; then
2732 error "Copytool sent malformed event: $event"
2736 if [ $event_type == "REGISTER" ]; then
2737 REGISTER_EVENT=$event
2738 elif [ $event_type == "UNREGISTER" ]; then
2739 UNREGISTER_EVENT=$event
2741 done < <(echo $"$(get_copytool_event_log)")
2743 if [ -z "$REGISTER_EVENT" ]; then
2744 error "Copytool failed to send register event to FIFO"
2747 if [ -z "$UNREGISTER_EVENT" ]; then
2748 error "Copytool failed to send unregister event to FIFO"
2751 copytool_monitor_cleanup
2752 echo "Register/Unregister events look OK."
2754 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2757 # Bump progress interval for livelier events.
2760 # test needs a new running copytool
2762 copytool_monitor_setup
2763 HSMTOOL_UPDATE_INTERVAL=$interval \
2764 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2767 local f=$DIR/$tdir/$tfile
2768 local fid=$(make_large_for_progress $f)
2770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2771 error "could not archive file"
2772 wait_request_state $fid ARCHIVE SUCCEED
2774 local expected_fields="event_time data_fid source_fid"
2775 expected_fields+=" total_bytes current_bytes"
2779 while read event; do
2780 # Make sure we're not getting anything from previous events.
2781 for field in $expected_fields; do
2785 local parsed=$(parse_json_event "$event")
2786 if [ -z "$parsed" ]; then
2787 error "Copytool sent malformed event: $event"
2791 if [ $event_type == "ARCHIVE_START" ]; then
2794 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2797 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2801 # Do some simple checking of the progress update events.
2802 for expected_field in $expected_fields; do
2803 if [ -z ${!expected_field+x} ]; then
2804 error "Missing $expected_field field in event"
2808 if [ $total_bytes -eq 0 ]; then
2809 error "Expected total_bytes to be > 0"
2812 # These should be identical throughout an archive
2814 if [ $source_fid != $data_fid ]; then
2815 error "Expected source_fid to equal data_fid"
2817 done < <(echo $"$(get_copytool_event_log)")
2819 if [ -z "$START_EVENT" ]; then
2820 error "Copytool failed to send archive start event to FIFO"
2823 if [ -z "$FINISH_EVENT" ]; then
2824 error "Copytool failed to send archive finish event to FIFO"
2827 echo "Archive events look OK."
2831 copytool_monitor_cleanup
2833 run_test 71 "Copytool logs JSON archive events to FIFO"
2836 # Bump progress interval for livelier events.
2839 # test needs a new running copytool
2841 copytool_monitor_setup
2842 HSMTOOL_UPDATE_INTERVAL=$interval \
2843 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2844 local test_file=$HSMTOOL_MONITOR_DIR/file
2846 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2848 do_facet $SINGLEAGT "$cmd" ||
2849 error "cannot create $test_file on $SINGLEAGT"
2850 copy2archive $test_file $tdir/$tfile
2853 local f=$DIR/$tdir/$tfile
2854 import_file $tdir/$tfile $f
2855 f=$DIR2/$tdir/$tfile
2856 echo "Verifying released state: "
2857 check_hsm_flags $f "0x0000000d"
2859 local fid=$(path2fid $f)
2861 wait_request_state $fid RESTORE SUCCEED
2863 local expected_fields="event_time data_fid source_fid"
2864 expected_fields+=" total_bytes current_bytes"
2868 while read event; do
2869 # Make sure we're not getting anything from previous events.
2870 for field in $expected_fields; do
2874 local parsed=$(parse_json_event "$event")
2875 if [ -z "$parsed" ]; then
2876 error "Copytool sent malformed event: $event"
2880 if [ $event_type == "RESTORE_START" ]; then
2882 if [ $source_fid != $data_fid ]; then
2883 error "source_fid should == data_fid at start"
2886 elif [ $event_type == "RESTORE_FINISH" ]; then
2888 if [ $source_fid != $data_fid ]; then
2889 error "source_fid should == data_fid at finish"
2892 elif [ $event_type != "RESTORE_RUNNING" ]; then
2896 # Do some simple checking of the progress update events.
2897 for expected_field in $expected_fields; do
2898 if [ -z ${!expected_field+x} ]; then
2899 error "Missing $expected_field field in event"
2903 if [ $total_bytes -eq 0 ]; then
2904 error "Expected total_bytes to be > 0"
2907 # When a restore starts out, the data fid is the same as the
2908 # source fid. After the restore has gotten going, we learn
2909 # the new data fid. Once the restore has finished, the source
2910 # fid is set to the new data fid.
2912 # We test this because some monitoring software may depend on
2913 # this behavior. If it changes, then the consumers of these
2914 # events may need to be modified.
2915 if [ $source_fid == $data_fid ]; then
2916 error "source_fid should != data_fid during restore"
2918 done < <(echo $"$(get_copytool_event_log)")
2920 if [ -z "$START_EVENT" ]; then
2921 error "Copytool failed to send restore start event to FIFO"
2924 if [ -z "$FINISH_EVENT" ]; then
2925 error "Copytool failed to send restore finish event to FIFO"
2928 echo "Restore events look OK."
2932 copytool_monitor_cleanup
2936 run_test 72 "Copytool logs JSON restore events to FIFO"
2939 file_count=51 # Max number of files constrained by LNET message size
2940 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2941 local f=$DIR/$tdir/$tfile
2942 local FILELIST=/tmp/filelist.txt
2946 for i in $(seq 1 $file_count); do
2947 fid=$(copy_file /etc/hosts $f.$i)
2948 echo $f.$i >> $FILELIST
2951 # to be sure wait_all_done will not be mislead by previous tests
2953 wait_for_grace_delay
2954 $LFS hsm_archive --filelist $FILELIST ||
2955 error "cannot archive a file list"
2957 $LFS hsm_release --filelist $FILELIST ||
2958 error "cannot release a file list"
2959 $LFS hsm_restore --filelist $FILELIST ||
2960 error "cannot restore a file list"
2964 run_test 90 "Archive/restore a file list"
2966 double_verify_reset_hsm_param() {
2968 echo "Testing $HSM_PARAM.$p"
2969 local val=$(get_hsm_param $p)
2971 local val2=$(($val * 2))
2972 set_hsm_param $p $val2
2973 val=$(get_hsm_param $p)
2974 [[ $val == $val2 ]] ||
2975 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2976 echo "Set $p to 0 must failed"
2980 set_hsm_param $p $save
2982 if [[ $rc == 0 ]]; then
2983 error "we must not be able to set $HSM_PARAM.$p to 0"
2988 double_verify_reset_hsm_param loop_period
2989 double_verify_reset_hsm_param grace_delay
2990 double_verify_reset_hsm_param active_request_timeout
2991 double_verify_reset_hsm_param max_requests
2992 double_verify_reset_hsm_param default_archive_id
2994 run_test 100 "Set coordinator /proc tunables"
3001 run_test 102 "Verify coordinator control"
3004 # test needs a running copytool
3011 for i in $(seq 1 20); do
3012 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3018 echo "Current requests"
3019 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3020 $HSM_PARAM.actions |\
3021 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3023 [[ -z "$res" ]] || error "Some request have not been canceled"
3027 run_test 103 "Purge all requests"
3032 # test needs a running copytool
3036 local f=$DIR/$tdir/$tfile
3037 local fid=$(make_large_for_progress $f)
3038 # if cdt is on, it can serve too quickly the request
3040 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3041 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3042 $HSM_PARAM.actions |\
3043 grep $fid | cut -f16 -d=")
3046 [[ "$data1" == "$DATAHEX" ]] ||
3047 error "Data field in records is ($data1) and not ($DATAHEX)"
3051 run_test 104 "Copy tool data field"
3058 for i in $(seq -w 1 10); do
3059 cp /etc/passwd $DIR/$tdir/$i
3060 $LFS hsm_archive $DIR/$tdir/$i
3062 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3063 $HSM_PARAM.actions |\
3064 grep WAITING | wc -l")
3067 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3068 $HSM_PARAM.actions |\
3069 grep WAITING | wc -l")
3072 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3073 error "Requests count after shutdown $reqcnt2 != "\
3074 "before shutdown $reqcnt1"
3076 run_test 105 "Restart of coordinator"
3078 get_agent_by_uuid_mdt() {
3081 local mds=mds$(($mdtidx + 1))
3082 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3086 check_agent_registered_by_mdt() {
3089 local mds=mds$(($mdtidx + 1))
3090 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3091 if [[ ! -z "$agent" ]]; then
3092 echo "found agent $agent on $mds"
3094 error "uuid $uuid not found in agent list on $mds"
3098 check_agent_unregistered_by_mdt() {
3101 local mds=mds$(($mdtidx + 1))
3102 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3103 if [[ -z "$agent" ]]; then
3104 echo "uuid not found in agent list on $mds"
3106 error "uuid found in agent list on $mds: $agent"
3110 check_agent_registered() {
3113 for mdsno in $(seq 1 $MDSCOUNT); do
3114 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3118 check_agent_unregistered() {
3121 for mdsno in $(seq 1 $MDSCOUNT); do
3122 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3127 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3128 get_client_uuid $MOUNT | cut -d' ' -f2)
3131 check_agent_registered $uuid
3133 search_copytools || error "No copytool found"
3136 check_agent_unregistered $uuid
3139 check_agent_registered $uuid
3143 run_test 106 "Copytool register/unregister"
3146 # test needs a running copytool
3148 # create and archive file
3150 local f1=$DIR/$tdir/$tfile
3151 local fid=$(copy_file /etc/passwd $f1)
3152 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3153 wait_request_state $fid ARCHIVE SUCCEED
3154 # shutdown and restart MDS
3156 # check the copytool still gets messages from MDT
3157 local f2=$DIR/$tdir/2
3158 local fid=$(copy_file /etc/passwd $f2)
3159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3160 # main check of this sanity: this request MUST succeed
3161 wait_request_state $fid ARCHIVE SUCCEED
3164 run_test 107 "Copytool re-register after MDS restart"
3166 policy_set_and_test()
3170 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3171 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3172 [[ "$policy" == "$target" ]] ||
3173 error "Wrong policy after '$change': '$policy' != '$target'"
3177 # to force default policy setting if error
3178 CDT_POLICY_HAD_CHANGED=true
3180 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3181 local default="NonBlockingRestore [NoRetryAction]"
3182 [[ "$policy" == "$default" ]] ||
3183 error "default policy has changed,"\
3184 " '$policy' != '$default' update the test"
3185 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3186 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3187 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3188 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3189 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3190 # useless bacause we know but safer for futur changes to use real value
3191 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3192 echo "Next set_param must failed"
3193 policy_set_and_test "wrong" "$policy"
3196 echo "Back to default policy"
3197 cdt_set_sanity_policy
3199 run_test 109 "Policy display/change"
3202 # test needs a running copytool
3207 copy2archive /etc/passwd $tdir/$tfile
3209 local f=$DIR/$tdir/$tfile
3210 import_file $tdir/$tfile $f
3211 local fid=$(path2fid $f)
3213 cdt_set_non_blocking_restore
3218 wait_request_state $fid RESTORE SUCCEED
3219 cdt_clear_non_blocking_restore
3223 error "md5sum returns $st != 1, "\
3224 "should also perror ENODATA (No data available)"
3228 run_test 110a "Non blocking restore policy (import case)"
3231 # test needs a running copytool
3235 local f=$DIR/$tdir/$tfile
3236 local fid=$(copy_file /etc/passwd $f)
3237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3238 wait_request_state $fid ARCHIVE SUCCEED
3241 cdt_set_non_blocking_restore
3246 wait_request_state $fid RESTORE SUCCEED
3247 cdt_clear_non_blocking_restore
3251 error "md5sum returns $st != 1, "\
3252 "should also perror ENODATA (No data available)"
3256 run_test 110b "Non blocking restore policy (release case)"
3259 # test needs a running copytool
3263 copy2archive /etc/passwd $tdir/$tfile
3265 local f=$DIR/$tdir/$tfile
3267 import_file $tdir/$tfile $f
3268 local fid=$(path2fid $f)
3272 copytool_remove_backend $fid
3275 wait_request_state $fid RESTORE FAILED
3282 [[ $st == 0 ]] || error "Restore does not failed"
3286 run_test 111a "No retry policy (import case), restore will error"\
3287 " (No such file or directory)"
3290 # test needs a running copytool
3294 local f=$DIR/$tdir/$tfile
3295 local fid=$(copy_file /etc/passwd $f)
3297 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3298 wait_request_state $fid ARCHIVE SUCCEED
3301 copytool_remove_backend $fid
3304 wait_request_state $fid RESTORE FAILED
3311 [[ $st == 0 ]] || error "Restore does not failed"
3315 run_test 111b "No retry policy (release case), restore will error"\
3316 " (No such file or directory)"
3319 # test needs a running copytool
3323 local f=$DIR/$tdir/$tfile
3324 local fid=$(copy_file /etc/passwd $f)
3326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3327 local l=$($LFS hsm_action $f)
3329 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3333 wait_request_state $fid ARCHIVE SUCCEED
3336 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3340 run_test 112 "State of recorded request"
3343 # test needs a running copytool
3347 local f=$DIR/$tdir/$tfile
3348 local fid=$(make_large_for_cancel $f)
3349 # test with cdt on is made in test_221
3351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3354 wait_request_state $fid ARCHIVE CANCELED
3355 wait_request_state $fid CANCEL SUCCEED
3359 run_test 200 "Register/Cancel archive"
3362 # test needs a running copytool
3366 local f=$DIR/$tdir/$tfile
3367 make_archive $tdir/$tfile
3368 import_file $tdir/$tfile $f
3369 local fid=$(path2fid $f)
3371 # test with cdt on is made in test_222
3376 wait_request_state $fid RESTORE CANCELED
3377 wait_request_state $fid CANCEL SUCCEED
3381 run_test 201 "Register/Cancel restore"
3384 # test needs a running copytool
3388 local f=$DIR/$tdir/$tfile
3389 local fid=$(make_large_for_progress $f)
3390 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3391 wait_request_state $fid ARCHIVE SUCCEED
3397 wait_request_state $fid REMOVE CANCELED
3401 run_test 202 "Register/Cancel remove"
3404 # test needs a running copytool
3409 local f=$DIR/$tdir/$tfile
3410 local fid=$(copy_file /etc/passwd $f)
3414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3415 wait_request_state $fid ARCHIVE SUCCEED
3417 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3421 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3425 run_test 220 "Changelog for archive"
3428 # test needs a running copytool
3433 local f=$DIR/$tdir/$tfile
3434 local fid=$(make_large_for_cancel $f)
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3439 wait_request_state $fid ARCHIVE STARTED
3441 wait_request_state $fid ARCHIVE CANCELED
3442 wait_request_state $fid CANCEL SUCCEED
3444 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3447 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3451 run_test 221 "Changelog for archive canceled"
3454 # test needs a running copytool
3458 copy2archive /etc/passwd $tdir/$tfile
3460 local f=$DIR/$tdir/$tfile
3461 import_file $tdir/$tfile $f
3462 local fid=$(path2fid $f)
3467 wait_request_state $fid RESTORE SUCCEED
3469 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3472 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3476 run_test 222a "Changelog for explicit restore"
3479 # test needs a running copytool
3483 local f=$DIR/$tdir/$tfile
3484 local fid=$(copy_file /etc/passwd $f)
3487 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3488 wait_request_state $fid ARCHIVE SUCCEED
3493 wait_request_state $fid RESTORE SUCCEED
3495 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3498 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3502 run_test 222b "Changelog for implicit restore"
3505 # test needs a running copytool
3510 local f=$DIR/$tdir/$tfile
3511 make_archive $tdir/$tfile
3515 import_file $tdir/$tfile $f
3516 local fid=$(path2fid $f)
3519 wait_request_state $fid RESTORE STARTED
3521 wait_request_state $fid RESTORE CANCELED
3522 wait_request_state $fid CANCEL SUCCEED
3524 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3527 [[ $flags == $target ]] ||
3528 error "Changelog flag is $flags not $target"
3532 run_test 223a "Changelog for restore canceled (import case)"
3535 # test needs a running copytool
3540 local f=$DIR/$tdir/$tfile
3541 local fid=$(make_large_for_progress $f)
3544 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3545 wait_request_state $fid ARCHIVE SUCCEED
3548 wait_request_state $fid RESTORE STARTED
3550 wait_request_state $fid RESTORE CANCELED
3551 wait_request_state $fid CANCEL SUCCEED
3553 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3556 [[ $flags == $target ]] ||
3557 error "Changelog flag is $flags not $target"
3561 run_test 223b "Changelog for restore canceled (release case)"
3564 # test needs a running copytool
3569 local f=$DIR/$tdir/$tfile
3570 local fid=$(copy_file /etc/passwd $f)
3573 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3574 wait_request_state $fid ARCHIVE SUCCEED
3577 wait_request_state $fid REMOVE SUCCEED
3579 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3582 [[ $flags == $target ]] ||
3583 error "Changelog flag is $flags not $target"
3587 run_test 224 "Changelog for remove"
3590 # test needs a running copytool
3593 # test is not usable because remove request is too fast
3594 # so it is always finished before cancel can be done ...
3595 echo "Test disabled"
3600 local f=$DIR/$tdir/$tfile
3601 local fid=$(make_large_for_progress $f)
3604 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3605 wait_request_state $fid ARCHIVE SUCCEED
3607 # if cdt is on, it can serve too quickly the request
3612 wait_request_state $fid REMOVE CANCELED
3613 wait_request_state $fid CANCEL SUCCEED
3615 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3616 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3617 tail -n 1 | awk '{print $5}')
3620 [[ $flags == $target ]] ||
3621 error "Changelog flag is $flags not $target"
3625 run_test 225 "Changelog for remove canceled"
3628 # test needs a running copytool
3633 local f1=$DIR/$tdir/$tfile-1
3634 local f2=$DIR/$tdir/$tfile-2
3635 local f3=$DIR/$tdir/$tfile-3
3636 local fid1=$(copy_file /etc/passwd $f1)
3637 local fid2=$(copy_file /etc/passwd $f2)
3638 copy_file /etc/passwd $f3
3641 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3642 wait_request_state $fid1 ARCHIVE SUCCEED
3644 $LFS hsm_archive $f2
3645 wait_request_state $fid2 ARCHIVE SUCCEED
3647 rm $f1 || error "rm $f1 failed"
3649 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3652 [[ $flags == $target ]] ||
3653 error "Changelog flag is $flags not $target"
3655 mv $f3 $f2 || error "mv $f3 $f2 failed"
3657 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3660 [[ $flags == $target ]] ||
3661 error "Changelog flag is $flags not $target"
3665 run_test 226 "changelog for last rm/mv with exiting archive"
3667 check_flags_changes() {
3675 $LFS hsm_set --$hsm_flag $f ||
3676 error "Cannot set $hsm_flag on $f"
3677 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3678 local seen=${#flags[*]}
3680 [[ $seen == $cnt ]] ||
3681 error "set $hsm_flag: Changelog events $seen != $cnt"
3682 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3683 error "set $hsm_flag: Changelog flags are "\
3684 "${flags[$((cnt - 1))]} not $target"
3686 $LFS hsm_clear --$hsm_flag $f ||
3687 error "Cannot clear $hsm_flag on $f"
3688 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3691 [[ $cnt == $seen ]] ||
3692 error "clear $hsm_flag: Changelog events $seen != $cnt"
3694 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3695 error "clear $hsm_flag: Changelog flag is "\
3696 "${flags[$((cnt - 1))]} not $target"
3700 # test needs a running copytool
3707 for i in norelease noarchive exists archived
3709 local f=$DIR/$tdir/$tfile-$i
3710 local fid=$(copy_file /etc/passwd $f)
3711 check_flags_changes $f $fid $i 0 1
3714 f=$DIR/$tdir/$tfile---lost
3715 fid=$(copy_file /etc/passwd $f)
3716 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3717 wait_request_state $fid ARCHIVE SUCCEED
3718 check_flags_changes $f $fid lost 3 1
3722 run_test 227 "changelog when explicit setting of HSM flags"
3725 # test needs a running copytool
3728 local fid=$(make_small_sync $DIR/$tfile)
3729 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3730 wait_request_state $fid ARCHIVE SUCCEED
3732 $LFS hsm_release $DIR/$tfile
3733 check_hsm_flags $DIR/$tfile "0x0000000d"
3735 filefrag $DIR/$tfile | grep " 1 extent found" ||
3736 error "filefrag on released file must return only one extent"
3738 # only newer versions of cp detect sparse files by stat/FIEMAP
3740 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3741 error "copying $DIR/$tfile"
3742 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3744 $LFS hsm_release $DIR/$tfile
3745 check_hsm_flags $DIR/$tfile "0x0000000d"
3747 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3749 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3751 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3752 error "comparing untarred $DIR/$tfile"
3754 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3755 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3758 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3761 # test needs a running copytool
3765 local maxrequest=$(get_hsm_param max_requests)
3766 local rqcnt=$(($maxrequest * 3))
3770 for i in $(seq -w 1 $rqcnt); do
3772 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3774 # we do it in 2 steps, so all requests arrive at the same time
3775 for i in $(seq -w 1 $rqcnt); do
3776 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3781 while [[ $cnt != 0 || $wt != 0 ]]; do
3783 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3784 $HSM_PARAM.actions |\
3785 grep STARTED | grep -v CANCEL | wc -l")
3786 [[ $cnt -le $maxrequest ]] ||
3787 error "$cnt > $maxrequest too many started requests"
3788 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3789 $HSM_PARAM.actions |\
3790 grep WAITING | wc -l")
3791 echo "max=$maxrequest started=$cnt waiting=$wt"
3796 run_test 250 "Coordinator max request"
3799 # test needs a running copytool
3803 local f=$DIR/$tdir/$tfile
3804 local fid=$(make_large_for_cancel $f)
3807 # to have a short test
3808 local old_to=$(get_hsm_param active_request_timeout)
3809 set_hsm_param active_request_timeout 4
3810 # to be sure the cdt will wake up frequently so
3811 # it will be able to cancel the "old" request
3812 local old_loop=$(get_hsm_param loop_period)
3813 set_hsm_param loop_period 2
3816 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3817 wait_request_state $fid ARCHIVE STARTED
3819 wait_request_state $fid ARCHIVE CANCELED
3821 set_hsm_param active_request_timeout $old_to
3822 set_hsm_param loop_period $old_loop
3826 run_test 251 "Coordinator request timeout"
3829 # the only way to test ondisk conf is to restart MDS ...
3830 echo "Stop coordinator and remove coordinator state at mount"
3833 # clean on disk conf set by default
3834 cdt_clear_mount_state
3835 cdt_check_state stopped
3837 # check cdt still off after umount/remount
3839 cdt_check_state stopped
3841 echo "Set coordinator start at mount, and start coordinator"
3842 cdt_set_mount_state enabled
3845 cdt_check_state enabled
3847 # check cdt still on after umount/remount
3849 cdt_check_state enabled
3851 # we are back to original state (cdt started at mount)
3853 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3856 local ai=$(get_hsm_param default_archive_id)
3857 local new=$((ai + 1))
3859 set_hsm_param default_archive_id $new -P
3861 local res=$(get_hsm_param default_archive_id)
3864 set_hsm_param default_archive_id "" "-P -d"
3866 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3868 run_test 301 "HSM tunnable are persistent"
3871 local ai=$(get_hsm_param default_archive_id)
3872 local new=$((ai + 1))
3877 set_hsm_param default_archive_id $new -P
3880 for mdtno in $(seq 1 $MDSCOUNT); do
3885 cdt_check_state enabled
3887 local res=$(get_hsm_param default_archive_id)
3890 set_hsm_param default_archive_id "" "-P -d"
3892 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3894 run_test 302 "HSM tunnable are persistent when CDT is off"
3897 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3903 local dir_mdt0=$DIR/$tdir/mdt0
3904 local dir_mdt1=$DIR/$tdir/mdt1
3906 # create 1 dir per MDT
3907 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3908 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3910 # create 1 file in each MDT
3911 local fid1=$(make_small $dir_mdt0/$tfile)
3912 local fid2=$(make_small $dir_mdt1/$tfile)
3914 # check that hsm request on mdt0 is sent to the right MDS
3915 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3916 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3917 echo "archive successful on mdt0"
3919 # check that hsm request on mdt1 is sent to the right MDS
3920 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
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 400 "Single request is sent to the right MDT"
3931 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3937 local dir_mdt0=$DIR/$tdir/mdt0
3938 local dir_mdt1=$DIR/$tdir/mdt1
3940 # create 1 dir per MDT
3941 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3942 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3944 # create 1 file in each MDT
3945 local fid1=$(make_small $dir_mdt0/$tfile)
3946 local fid2=$(make_small $dir_mdt1/$tfile)
3948 # check that compound requests are shunt to the rights MDTs
3949 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3950 error "lfs hsm_archive"
3951 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3952 echo "archive successful on mdt0"
3953 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3954 echo "archive successful on mdt1"
3957 # clean test files and directories
3958 rm -rf $dir_mdt0 $dir_mdt1
3960 run_test 401 "Compound requests split and sent to their respective MDTs"
3962 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3967 local node=$(facet_active_host $facet)
3969 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3970 awk '{print $4}'); do
3971 echo "$3 $mdc on $node"
3972 do_facet $facet "$LCTL --device $mdc $state" || return 1
3977 # make sure there is no running copytool
3980 # deactivate all mdc on agent1
3981 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3983 copytool_setup $SINGLEAGT
3985 check_agent_unregistered "uuid" # match any agent
3987 # no expected running copytool
3988 search_copytools $agent && error "Copytool start should have failed"
3991 mdc_change_state $SINGLEAGT "MDT000." "activate"
3993 run_test 402 "Copytool start fails if all MDTs are inactive"
3996 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3998 # make sure there is no running copytool
4001 local agent=$(facet_active_host $SINGLEAGT)
4002 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4004 # deactivate all mdc for MDT0001
4005 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4008 # check the agent is registered on MDT0000, and not on MDT0001
4009 check_agent_registered_by_mdt $uuid 0
4010 check_agent_unregistered_by_mdt $uuid 1
4012 # check running copytool process
4013 search_copytools $agent || error "No running copytools on $agent"
4015 # reactivate all mdc for MDT0001
4016 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4018 # make sure the copytool is now registered to all MDTs
4019 check_agent_registered $uuid
4023 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4026 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4030 # create files on both MDT0000 and MDT0001
4033 local dir_mdt0=$DIR/$tdir/mdt0
4034 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4036 # create 1 file on mdt0
4037 local fid1=$(make_small $dir_mdt0/$tfile)
4039 # deactivate all mdc for MDT0001
4040 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4042 # send an HSM request for files in MDT0000
4043 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4045 # check for completion of files in MDT0000
4046 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4047 echo "archive successful on mdt0"
4049 # reactivate all mdc for MDT0001
4050 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4053 # clean test files and directories
4056 run_test 404 "Inactive MDT does not block requests for active MDTs"
4061 check_and_cleanup_lustre