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 11a "Import a file"
1013 # test needs a running copytool
1017 local f=$DIR/$tdir/$tfile
1018 local fid=$(copy_file /etc/hosts $f)
1019 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1020 error "hsm_archive failed"
1021 wait_request_state $fid ARCHIVE SUCCEED
1023 local FILE_HASH=$(md5sum $f)
1028 echo "$FILE_HASH" | md5sum -c
1030 [[ $? -eq 0 ]] || error "Restored file differs"
1034 run_test 11b "Import a deleted file using its FID"
1037 # test needs a running copytool
1041 copy2archive /etc/hosts $tdir/$tfile
1043 local f=$DIR/$tdir/$tfile
1044 import_file $tdir/$tfile $f
1045 local f2=$DIR2/$tdir/$tfile
1046 echo "Verifying released state: "
1047 check_hsm_flags $f2 "0x0000000d"
1049 local fid=$(path2fid $f2)
1050 $LFS hsm_restore $f2
1051 wait_request_state $fid RESTORE SUCCEED
1053 echo "Verifying file state: "
1054 check_hsm_flags $f2 "0x00000009"
1056 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1058 [[ $? -eq 0 ]] || error "Restored file differs"
1062 run_test 12a "Restore an imported file explicitly"
1065 # test needs a running copytool
1069 copy2archive /etc/hosts $tdir/$tfile
1071 local f=$DIR/$tdir/$tfile
1072 import_file $tdir/$tfile $f
1073 echo "Verifying released state: "
1074 check_hsm_flags $f "0x0000000d"
1076 cat $f > /dev/null || error "File read failed"
1078 echo "Verifying file state after restore: "
1079 check_hsm_flags $f "0x00000009"
1081 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1083 [[ $? -eq 0 ]] || error "Restored file differs"
1087 run_test 12b "Restore an imported file implicitly"
1090 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1092 # test needs a running copytool
1096 local f=$DIR/$tdir/$tfile
1097 $LFS setstripe -c 2 $f
1098 local fid=$(make_large_for_striping $f)
1099 local FILE_CRC=$(md5sum $f)
1101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1102 wait_request_state $fid ARCHIVE SUCCEED
1103 $LFS hsm_release $f || error "release $f failed"
1105 echo "$FILE_CRC" | md5sum -c
1107 [[ $? -eq 0 ]] || error "Restored file differs"
1111 run_test 12c "Restore a file with stripe of 2"
1114 # test needs a running copytool
1119 local f=$DIR/$tdir/$tfile
1120 local fid=$(copy_file /etc/hosts $f)
1121 $LFS hsm_restore $f || error "restore of non archived file failed"
1122 local cnt=$(get_request_count $fid RESTORE)
1123 [[ "$cnt" == "0" ]] ||
1124 error "restore non archived must not make a request"
1125 $LFS hsm_archive $f ||
1126 error "archive request failed"
1127 wait_request_state $fid ARCHIVE SUCCEED
1128 $LFS hsm_restore $f ||
1129 error "restore of non released file failed"
1130 local cnt=$(get_request_count $fid RESTORE)
1131 [[ "$cnt" == "0" ]] ||
1132 error "restore a non dirty file must not make a request"
1136 run_test 12d "Restore of a non archived, non released file must work"\
1137 " without doing request"
1140 # test needs a running copytool
1143 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1144 local f=$DIR/$tdir/$tfile
1145 local fid=$(copy_file /etc/hosts $f)
1146 $LFS hsm_archive $f || error "archive request failed"
1147 wait_request_state $fid ARCHIVE SUCCEED
1150 cat /etc/hosts >> $f
1154 $LFS hsm_restore $f && error "restore a dirty file must fail"
1158 run_test 12e "Check forbidden restore"
1161 # test needs a running copytool
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/hosts $f)
1168 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1169 wait_request_state $fid ARCHIVE SUCCEED
1170 $LFS hsm_release $f || error "release of $f failed"
1172 wait_request_state $fid RESTORE SUCCEED
1174 echo -n "Verifying file state: "
1175 check_hsm_flags $f "0x00000009"
1177 diff -q /etc/hosts $f
1179 [[ $? -eq 0 ]] || error "Restored file differs"
1183 run_test 12f "Restore a released file explicitly"
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 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 12g "Restore a released file implicitly"
1210 needclients 2 || return 0
1212 # test needs a running copytool
1216 local f=$DIR/$tdir/$tfile
1217 local fid=$(copy_file /etc/hosts $f)
1219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1220 wait_request_state $fid ARCHIVE SUCCEED
1221 $LFS hsm_release $f || error "release of $f failed"
1223 do_node $CLIENT2 diff -q /etc/hosts $f
1226 # we check we had a restore done
1227 wait_request_state $fid RESTORE SUCCEED
1229 [[ $st -eq 0 ]] || error "Restored file differs"
1233 run_test 12h "Restore a released file implicitly from a second node"
1236 # test needs a running copytool
1240 local f=$DIR/$tdir/$tfile
1241 local fid=$(copy_file /etc/passwd $f)
1242 $LFS hsm_archive $f || error "archive of $f failed"
1243 wait_request_state $fid ARCHIVE SUCCEED
1245 $LFS hsm_release $f || error "release of $f failed"
1249 [[ $? -eq 0 ]] || error "Restored file differs"
1253 run_test 12m "Archive/release/implicit restore"
1256 # test needs a running copytool
1260 copy2archive /etc/hosts $tdir/$tfile
1262 local f=$DIR/$tdir/$tfile
1263 import_file $tdir/$tfile $f
1265 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1266 error "Restored file differs"
1268 $LFS hsm_release $f || error "release of $f failed"
1272 run_test 12n "Import/implicit restore/release"
1275 # test needs a running copytool
1279 local f=$DIR/$tdir/$tfile
1280 local fid=$(copy_file /etc/hosts $f)
1282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1283 wait_request_state $fid ARCHIVE SUCCEED
1284 $LFS hsm_release $f || error "release of $f failed"
1286 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1287 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1289 # set no retry action mode
1292 diff -q /etc/hosts $f
1295 # we check we had a restore failure
1296 wait_request_state $fid RESTORE FAILED
1298 [[ $st -eq 0 ]] && error "Restore must fail"
1300 # remove no retry action mode
1303 # check file is still released
1304 check_hsm_flags $f "0x0000000d"
1306 # retry w/o failure injection
1307 do_facet $SINGLEMDS lctl set_param fail_loc=0
1309 # to be sure previous RESTORE result is gone
1311 wait_for_grace_delay
1313 diff -q /etc/hosts $f
1316 # we check we had a restore done
1317 wait_request_state $fid RESTORE SUCCEED
1319 [[ $st -eq 0 ]] || error "Restored file differs"
1323 run_test 12o "Layout-swap failure during Restore leaves file released"
1326 # test needs a running copytool
1329 local ARC_SUBDIR="import.orig"
1333 # populate directory to be imported
1334 for d in $(seq 1 10); do
1335 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1336 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1337 for f in $(seq 1 10); do
1338 CURR_FILE="$CURR_DIR/$tfile.$f"
1339 # write file-specific data
1340 do_facet $SINGLEAGT \
1341 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1342 "file=$CURR_FILE > $CURR_FILE"
1346 import_file "$ARC_SUBDIR" $DIR/$tdir
1347 # diff lustre content and origin (triggers file restoration)
1348 # there must be 10x10 identical files, and no difference
1349 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1350 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1351 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1352 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1354 [ $cnt_diff -eq 0 ] ||
1355 error "$cnt_diff imported files differ from read data"
1356 [ $cnt_ok -eq 100 ] ||
1357 error "not enough identical files ($cnt_ok != 100)"
1361 run_test 13 "Recursively import and restore a directory"
1364 # test needs a running copytool
1369 local f=$DIR/$tdir/$tfile
1370 local fid=$(make_small $f)
1371 local sum=$(md5sum $f | awk '{print $1}')
1372 $LFS hsm_archive $f || error "could not archive file"
1373 wait_request_state $fid ARCHIVE SUCCEED
1377 # create released file (simulate llapi_hsm_import call)
1379 local fid2=$(path2fid $f)
1380 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1381 $LFS hsm_release $f || error "could not release file"
1383 # rebind the archive to the newly created file
1384 echo "rebind $fid to $fid2"
1386 do_facet $SINGLEAGT \
1387 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1388 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1390 # restore file and compare md5sum
1391 local sum2=$(md5sum $f | awk '{print $1}')
1393 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1397 run_test 14 "Rebind archived file to a new fid"
1400 # test needs a running copytool
1405 local f=$DIR/$tdir/$tfile
1407 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1411 for i in $(seq 1 $count); do
1412 fids[$i]=$(make_small $f.$i)
1413 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1414 $LFS hsm_archive $f.$i || error "could not archive file"
1416 wait_all_done $(($count*60))
1420 for i in $(seq 1 $count); do
1423 local fid2=$(path2fid $f.$i)
1424 # add the rebind operation to the list
1425 echo ${fids[$i]} $fid2 >> $tmpfile
1427 # set it released (simulate llapi_hsm_import call)
1428 $LFS hsm_set --archived --exists $f.$i ||
1429 error "could not force hsm flags"
1430 $LFS hsm_release $f.$i || error "could not release file"
1432 nl=$(wc -l < $tmpfile)
1433 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1435 echo "rebind list of files"
1436 do_facet $SINGLEAGT \
1437 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1438 --rebind $tmpfile $DIR" || error "could not rebind file list"
1440 # restore files and compare md5sum
1441 for i in $(seq 1 $count); do
1442 local sum2=$(md5sum $f.$i | awk '{print $1}')
1443 [[ $sum2 == ${sums[$i]} ]] ||
1444 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1450 run_test 15 "Rebind a list of files"
1453 # test needs a running copytool
1457 # create a known size file so we can verify transfer speed
1460 dd if=/dev/zero of=$ref bs=1M count=20
1463 local f=$DIR/$tdir/$tfile
1464 local fid=$(copy_file $ref $f)
1466 local start=$(date +%s)
1468 wait_request_state $fid ARCHIVE SUCCEED
1469 local end=$(date +%s)
1470 local duration=$((end - start))
1472 [[ $duration -ge $goal ]] ||
1473 error "Transfer is too fast $duration < $goal"
1477 run_test 16 "Test CT bandwith control option"
1482 local f=$DIR/$tdir/$tfile
1483 touch $f || error "touch $f failed"
1485 # Could not release a non-archived file
1486 $LFS hsm_release $f && error "release should not succeed"
1488 # For following tests, we must test them with HS_ARCHIVED set
1489 $LFS hsm_set --exists --archived $f || error "could not add flag"
1491 # Could not release a file if no-release is set
1492 $LFS hsm_set --norelease $f || error "could not add flag"
1493 $LFS hsm_release $f && error "release should not succeed"
1494 $LFS hsm_clear --norelease $f || error "could not remove flag"
1496 # Could not release a file if lost
1497 $LFS hsm_set --lost $f || error "could not add flag"
1498 $LFS hsm_release $f && error "release should not succeed"
1499 $LFS hsm_clear --lost $f || error "could not remove flag"
1501 # Could not release a file if dirty
1502 $LFS hsm_set --dirty $f || error "could not add flag"
1503 $LFS hsm_release $f && error "release should not succeed"
1504 $LFS hsm_clear --dirty $f || error "could not remove flag"
1506 run_test 20 "Release is not permitted"
1509 # test needs a running copytool
1513 local f=$DIR/$tdir/test_release
1515 # Create a file and check its states
1516 local fid=$(make_small $f)
1517 check_hsm_flags $f "0x00000000"
1519 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1520 # used until file is flushed to disk
1521 if [ $(facet_fstype ost1) == "zfs" ]; then
1522 # this causes an OST_SYNC rpc to be sent
1523 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1524 # clear locks to reread file data
1525 cancel_lru_locks osc
1528 local orig_size=$(stat -c "%s" $f)
1529 local orig_blocks=$(stat -c "%b" $f)
1531 start_full_debug_logging
1533 $LFS hsm_archive $f || error "could not archive file"
1534 wait_request_state $fid ARCHIVE SUCCEED
1536 local blocks=$(stat -c "%b" $f)
1537 [ $blocks -eq $orig_blocks ] ||
1538 error "$f: wrong block number after archive: " \
1539 "$blocks != $orig_blocks"
1540 local size=$(stat -c "%s" $f)
1541 [ $size -eq $orig_size ] ||
1542 error "$f: wrong size after archive: $size != $orig_size"
1544 # Release and check states
1545 $LFS hsm_release $f || error "could not release file"
1546 check_hsm_flags $f "0x0000000d"
1548 blocks=$(stat -c "%b" $f)
1549 [ $blocks -gt 5 ] &&
1550 error "$f: too many blocks after release: $blocks > 5"
1551 size=$(stat -c "%s" $f)
1552 [ $size -ne $orig_size ] &&
1553 error "$f: wrong size after release: $size != $orig_size"
1555 # Check we can release an file without stripe info
1559 check_hsm_flags $f "0x00000000"
1560 $LFS hsm_archive $f || error "could not archive file"
1561 wait_request_state $fid ARCHIVE SUCCEED
1563 # Release and check states
1564 $LFS hsm_release $f || error "could not release file"
1565 check_hsm_flags $f "0x0000000d"
1567 # Release again a file that is already released is OK
1568 $LFS hsm_release $f || fail "second release should succeed"
1569 check_hsm_flags $f "0x0000000d"
1571 stop_full_debug_logging
1575 run_test 21 "Simple release tests"
1578 # test needs a running copytool
1583 local f=$DIR/$tdir/test_release
1584 local swap=$DIR/$tdir/test_swap
1586 # Create a file and check its states
1587 local fid=$(make_small $f)
1588 check_hsm_flags $f "0x00000000"
1590 $LFS hsm_archive $f || error "could not archive file"
1591 wait_request_state $fid ARCHIVE SUCCEED
1593 # Release and check states
1594 $LFS hsm_release $f || error "could not release file"
1595 check_hsm_flags $f "0x0000000d"
1598 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1603 run_test 22 "Could not swap a release file"
1606 # test needs a running copytool
1611 local f=$DIR/$tdir/test_mtime
1613 # Create a file and check its states
1614 local fid=$(make_small $f)
1615 check_hsm_flags $f "0x00000000"
1617 $LFS hsm_archive $f || error "could not archive file"
1618 wait_request_state $fid ARCHIVE SUCCEED
1620 # Set modification time in the past
1621 touch -m -a -d @978261179 $f
1623 # Release and check states
1624 $LFS hsm_release $f || error "could not release file"
1625 check_hsm_flags $f "0x0000000d"
1627 local MTIME=$(stat -c "%Y" $f)
1628 local ATIME=$(stat -c "%X" $f)
1629 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1630 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1634 run_test 23 "Release does not change a/mtime (utime)"
1637 local file=$DIR/$tdir/$tfile
1646 # test needs a running copytool
1651 fid=$(make_small $file)
1653 # Create a file and check its states
1654 check_hsm_flags $file "0x00000000"
1656 # Ensure atime is less than mtime and ctime.
1660 atime0=$(stat -c "%X" $file)
1661 mtime0=$(stat -c "%Y" $file)
1662 ctime0=$(stat -c "%Z" $file)
1664 [ $atime0 -lt $mtime0 ] ||
1665 error "atime $atime0 is not less than mtime $mtime0"
1667 [ $atime0 -lt $ctime0 ] ||
1668 error "atime $atime0 is not less than ctime $ctime0"
1670 # Archive should not change any timestamps.
1671 $LFS hsm_archive $file || error "cannot archive '$file'"
1672 wait_request_state $fid ARCHIVE SUCCEED
1674 atime1=$(stat -c "%X" $file)
1675 mtime1=$(stat -c "%Y" $file)
1676 ctime1=$(stat -c "%Z" $file)
1678 [ $atime0 -eq $atime1 ] ||
1679 error "archive changed atime from $atime0 to $atime1"
1681 [ $mtime0 -eq $mtime1 ] ||
1682 error "archive changed mtime from $mtime0 to $mtime1"
1684 [ $ctime0 -eq $ctime1 ] ||
1685 error "archive changed ctime from $ctime0 to $ctime1"
1687 # Release should not change any timestamps.
1688 $LFS hsm_release $file || error "cannot release '$file'"
1689 check_hsm_flags $file "0x0000000d"
1691 atime1=$(stat -c "%X" $file)
1692 mtime1=$(stat -c "%Y" $file)
1693 ctime1=$(stat -c "%Z" $file)
1695 [ $atime0 -eq $atime1 ] ||
1696 error "release changed atime from $atime0 to $atime1"
1698 [ $mtime0 -eq $mtime1 ] ||
1699 error "release changed mtime from $mtime0 to $mtime1"
1701 [ $ctime0 -eq $ctime1 ] ||
1702 error "release changed ctime from $ctime0 to $ctime1"
1704 # Restore should not change atime or mtime and should not
1706 $LFS hsm_restore $file
1707 wait_request_state $fid RESTORE SUCCEED
1709 atime1=$(stat -c "%X" $file)
1710 mtime1=$(stat -c "%Y" $file)
1711 ctime1=$(stat -c "%Z" $file)
1713 [ $atime0 -eq $atime1 ] ||
1714 error "restore changed atime from $atime0 to $atime1"
1716 [ $mtime0 -eq $mtime1 ] ||
1717 error "restore changed mtime from $mtime0 to $mtime1"
1719 [ $ctime0 -le $ctime1 ] ||
1720 error "restore changed ctime from $ctime0 to $ctime1"
1724 # Once more, after unmount and mount.
1725 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1726 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1728 atime1=$(stat -c "%X" $file)
1729 mtime1=$(stat -c "%Y" $file)
1730 ctime1=$(stat -c "%Z" $file)
1732 [ $atime0 -eq $atime1 ] ||
1733 error "remount changed atime from $atime0 to $atime1"
1735 [ $mtime0 -eq $mtime1 ] ||
1736 error "remount changed mtime from $mtime0 to $mtime1"
1738 [ $ctime0 -le $ctime1 ] ||
1739 error "remount changed ctime from $ctime0 to $ctime1"
1741 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1744 local file=$DIR/$tdir/$tfile
1750 # Test needs a running copytool.
1754 # Check that root can do HSM actions on a ordinary user's file.
1756 fid=$(make_small $file)
1757 sum0=$(md5sum $file)
1759 chown $RUNAS_ID:$RUNAS_GID $file ||
1760 error "cannot chown '$file' to '$RUNAS_ID'"
1762 chmod ugo-w $DIR/$tdir ||
1763 error "cannot chmod '$DIR/$tdir'"
1765 $LFS hsm_archive $file
1766 wait_request_state $fid ARCHIVE SUCCEED
1768 $LFS hsm_release $file
1769 check_hsm_flags $file "0x0000000d"
1771 $LFS hsm_restore $file
1772 wait_request_state $fid RESTORE SUCCEED
1774 # Check that ordinary user can get HSM state.
1775 $RUNAS $LFS hsm_state $file ||
1776 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1778 $LFS hsm_release $file
1779 check_hsm_flags $file "0x0000000d"
1781 # Check that ordinary user can accessed released file.
1782 sum1=$($RUNAS md5sum $file) ||
1783 error "user '$RUNAS_ID' cannot read '$file'"
1785 [ "$sum0" == "$sum1" ] ||
1786 error "md5sum mismatch for '$file'"
1790 run_test 24b "root can archive, release, and restore user files"
1792 cleanup_test_24c() {
1794 set_hsm_param user_request_mask RESTORE
1795 set_hsm_param group_request_mask RESTORE
1796 set_hsm_param other_request_mask RESTORE
1800 local file=$DIR/$tdir/$tfile
1801 local action=archive
1806 # test needs a running copytool
1811 # Save the default masks and check that cleanup_24c will
1812 # restore the request masks correctly.
1813 user_save=$(get_hsm_param user_request_mask)
1814 group_save=$(get_hsm_param group_request_mask)
1815 other_save=$(get_hsm_param other_request_mask)
1817 [ "$user_save" == RESTORE ] ||
1818 error "user_request_mask is '$user_save' expected 'RESTORE'"
1819 [ "$group_save" == RESTORE ] ||
1820 error "group_request_mask is '$group_save' expected 'RESTORE'"
1821 [ "$other_save" == RESTORE ] ||
1822 error "other_request_mask is '$other_save' expected 'RESTORE'"
1824 trap cleanup_test_24c EXIT
1829 chown $RUNAS_ID:nobody $file ||
1830 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1832 set_hsm_param user_request_mask ""
1833 $RUNAS $LFS hsm_$action $file &&
1834 error "$action by user should fail"
1836 set_hsm_param user_request_mask $action
1837 $RUNAS $LFS hsm_$action $file ||
1838 error "$action by user should succeed"
1843 chown nobody:$RUNAS_GID $file ||
1844 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1846 set_hsm_param group_request_mask ""
1847 $RUNAS $LFS hsm_$action $file &&
1848 error "$action by group should fail"
1850 set_hsm_param group_request_mask $action
1851 $RUNAS $LFS hsm_$action $file ||
1852 error "$action by group should succeed"
1857 chown nobody:nobody $file ||
1858 error "cannot chown '$file' to 'nobody:nobody'"
1860 set_hsm_param other_request_mask ""
1861 $RUNAS $LFS hsm_$action $file &&
1862 error "$action by other should fail"
1864 set_hsm_param other_request_mask $action
1865 $RUNAS $LFS hsm_$action $file ||
1866 error "$action by other should succeed"
1871 run_test 24c "check that user,group,other request masks work"
1873 cleanup_test_24d() {
1875 mount -o remount,rw $MOUNT2
1879 local file1=$DIR/$tdir/$tfile
1880 local file2=$DIR2/$tdir/$tfile
1888 fid1=$(make_small $file1)
1890 trap cleanup_test_24d EXIT
1892 mount -o remount,ro $MOUNT2
1894 fid2=$(path2fid $file2)
1895 [ "$fid1" == "$fid2" ] ||
1896 error "FID mismatch '$fid1' != '$fid2'"
1898 $LFS hsm_archive $file2 &&
1899 error "archive should fail on read-only mount"
1900 check_hsm_flags $file1 "0x00000000"
1902 $LFS hsm_archive $file1
1903 wait_request_state $fid1 ARCHIVE SUCCEED
1905 $LFS hsm_release $file1
1906 $LFS hsm_restore $file2
1907 wait_request_state $fid1 RESTORE SUCCEED
1909 $LFS hsm_release $file1 || error "cannot release '$file1'"
1910 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1912 $LFS hsm_release $file2 &&
1913 error "release should fail on read-only mount"
1918 run_test 24d "check that read-only mounts are respected"
1921 # test needs a running copytool
1925 copy2archive /etc/hosts $tdir/$tfile
1927 local f=$DIR/$tdir/$tfile
1929 import_file $tdir/$tfile $f
1931 $LFS hsm_set --lost $f
1936 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1940 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1941 " (Operation not permitted)"
1944 # test needs a running copytool
1949 local f=$DIR/$tdir/$tfile
1950 local fid=$(copy_file /etc/passwd $f)
1952 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1953 wait_request_state $fid ARCHIVE SUCCEED
1956 $LFS hsm_set --lost $f
1960 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1964 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1965 " (Operation not permitted)"
1968 # test needs a running copytool
1972 local f=$DIR/$tdir/$tfile
1973 local fid=$(make_large_for_progress $f)
1974 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1975 wait_request_state $fid ARCHIVE SUCCEED
1978 wait_request_state $fid REMOVE SUCCEED
1980 check_hsm_flags $f "0x00000000"
1984 run_test 26 "Remove the archive of a valid file"
1987 # test needs a running copytool
1991 make_archive $tdir/$tfile
1992 local f=$DIR/$tdir/$tfile
1993 import_file $tdir/$tfile $f
1994 local fid=$(path2fid $f)
1998 [[ $? != 0 ]] || error "Remove of a released file should fail"
2002 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2005 # test needs a running copytool
2009 local f=$DIR/$tdir/$tfile
2010 local fid=$(make_large_for_progress $f)
2011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2012 wait_request_state $fid ARCHIVE SUCCEED
2017 [[ $? != 0 ]] || error "Remove of a released file should fail"
2021 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2024 # test needs a running copytool
2028 local f=$DIR/$tdir/$tfile
2029 local fid=$(make_large_for_progress $f)
2030 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2031 wait_request_state $fid ARCHIVE SUCCEED
2040 wait_request_state $fid REMOVE SUCCEED
2044 run_test 28 "Concurrent archive/file remove"
2047 # restore at exec cannot work on agent node (because of Linux kernel
2048 # protection of executables)
2049 needclients 2 || return 0
2051 # test needs a running copytool
2055 copy2archive /bin/true $tdir/$tfile
2057 local f=$DIR/$tdir/true
2058 import_file $tdir/$tfile $f
2060 local fid=$(path2fid $f)
2062 # set no retry action mode
2068 # remove no try action mode
2072 [[ $st == 0 ]] || error "Failed to exec a released file"
2076 run_test 30a "Restore at exec (import case)"
2079 # restore at exec cannot work on agent node (because of Linux kernel
2080 # protection of executables)
2081 needclients 2 || return 0
2083 # test needs a running copytool
2087 local f=$DIR/$tdir/true
2088 local fid=$(copy_file /bin/true $f)
2090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2091 wait_request_state $fid ARCHIVE SUCCEED
2094 # set no retry action mode
2100 # remove no try action mode
2104 [[ $st == 0 ]] || error "Failed to exec a released file"
2108 run_test 30b "Restore at exec (release case)"
2111 needclients 2 || return 0
2113 # test needs a running copytool
2117 local f=$DIR/$tdir/SLEEP
2118 local fid=$(copy_file /bin/sleep $f)
2120 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2121 wait_request_state $fid ARCHIVE SUCCEED
2123 check_hsm_flags $f "0x0000000d"
2124 # set no retry action mode
2126 do_node $CLIENT2 "$f 10" &
2130 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2132 [[ $? == 0 ]] || error "Execution failed during run"
2134 [[ $? == 0 ]] || error "Binary overwritten during exec"
2137 # remove no try action mode
2139 check_hsm_flags $f "0x00000009"
2143 run_test 30c "Update during exec of released file must fail"
2145 restore_and_check_size() {
2148 local s=$(stat -c "%s" $f)
2150 local st=$(get_hsm_flags $f)
2154 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2156 n=$(stat -c "%s" $f)
2157 # we echo in both cases to show stat is not
2159 if [[ $n != $s ]]; then
2160 echo "size seen is $n != $s"
2163 echo "size seen is right: $n == $s"
2165 st=$(get_hsm_flags $f)
2169 if [[ $cpt -lt 10 ]]; then
2172 echo " restore is too long"
2173 wait_request_state $fid RESTORE SUCCEED
2179 # test needs a running copytool
2184 make_archive $tdir/$tfile
2185 local f=$DIR/$tdir/$tfile
2186 import_file $tdir/$tfile $f
2187 local fid=$($LFS path2fid $f)
2188 HSM_ARCHIVE_PURGE=false copytool_setup
2190 restore_and_check_size $f $fid
2193 [[ $err -eq 0 ]] || error "File size changed during restore"
2197 run_test 31a "Import a large file and check size during restore"
2201 # test needs a running copytool
2206 local f=$DIR/$tdir/$tfile
2207 local fid=$(make_large_for_progress $f)
2208 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2209 wait_request_state $fid ARCHIVE SUCCEED
2212 restore_and_check_size $f $fid
2215 [[ $err -eq 0 ]] || error "File size changed during restore"
2219 run_test 31b "Restore a large unaligned file and check size during restore"
2222 # test needs a running copytool
2227 local f=$DIR/$tdir/$tfile
2228 local fid=$(make_large_for_progress_aligned $f)
2229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2230 wait_request_state $fid ARCHIVE SUCCEED
2233 restore_and_check_size $f $fid
2236 [[ $err -eq 0 ]] || error "File size changed during restore"
2240 run_test 31c "Restore a large aligned file and check size during restore"
2243 # test needs a running copytool
2248 local f=$DIR/$tdir/$tfile
2249 local fid=$(make_large_for_progress $f)
2250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2251 wait_request_state $fid ARCHIVE SUCCEED
2254 # to be sure wait_all_done will not be mislead by previous tests
2257 wait_for_grace_delay
2258 # Also raise grace_delay significantly so the Canceled
2259 # Restore action will stay enough long avail.
2260 local old_grace=$(get_hsm_param grace_delay)
2261 set_hsm_param grace_delay 100
2263 md5sum $f >/dev/null &
2265 wait_request_state $fid RESTORE STARTED
2270 # Check restore trigger process was killed
2271 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2275 # instead of waiting+checking both Restore and Cancel ops
2276 # sequentially, wait for both to be finished and then check
2278 wait_all_done 100 $fid
2279 local rstate=$(get_request_state $fid RESTORE)
2280 local cstate=$(get_request_state $fid CANCEL)
2282 # restore orig grace_delay.
2283 set_hsm_param grace_delay $old_grace
2285 if [[ "$rstate" == "CANCELED" ]] ; then
2286 [[ "$cstate" == "SUCCEED" ]] ||
2287 error "Restore state is CANCELED and Cancel state " \
2288 "is not SUCCEED but $cstate"
2289 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2290 elif [[ "$rstate" == "SUCCEED" ]] ; then
2291 [[ "$cstate" == "FAILED" ]] ||
2292 error "Restore state is SUCCEED and Cancel state " \
2293 "is not FAILED but $cstate"
2294 echo "Restore state is SUCCEED, Cancel state is FAILED"
2296 error "Restore state is $rstate and Cancel state is $cstate"
2300 error "Cannot kill process waiting for restore ($killed)"
2304 run_test 33 "Kill a restore waiting process"
2307 # test needs a running copytool
2312 local f=$DIR/$tdir/$tfile
2313 local fid=$(make_large_for_progress $f)
2314 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2315 wait_request_state $fid ARCHIVE SUCCEED
2318 md5sum $f >/dev/null &
2320 wait_request_state $fid RESTORE STARTED
2322 rm $f || error "rm $f failed"
2323 # rm must not block during restore
2324 wait_request_state $fid RESTORE STARTED
2326 wait_request_state $fid RESTORE SUCCEED
2327 # check md5sum pgm finished
2328 local there=$(ps -o pid,comm hp $pid >/dev/null)
2329 [[ -z $there ]] || error "Restore initiator does not exit"
2331 local rc=$(wait $pid)
2332 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2336 run_test 34 "Remove file during restore"
2339 # test needs a running copytool
2344 local f=$DIR/$tdir/$tfile
2345 local f1=$DIR/$tdir/$tfile-1
2346 local fid=$(make_large_for_progress $f)
2347 local fid1=$(copy_file /etc/passwd $f1)
2348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2349 wait_request_state $fid ARCHIVE SUCCEED
2352 md5sum $f >/dev/null &
2354 wait_request_state $fid RESTORE STARTED
2356 mv $f1 $f || error "mv $f1 $f failed"
2357 # mv must not block during restore
2358 wait_request_state $fid RESTORE STARTED
2360 wait_request_state $fid RESTORE SUCCEED
2361 # check md5sum pgm finished
2362 local there=$(ps -o pid,comm hp $pid >/dev/null)
2363 [[ -z $there ]] || error "Restore initiator does not exit"
2365 local rc=$(wait $pid)
2366 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2369 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2373 run_test 35 "Overwrite file during restore"
2376 # test needs a running copytool
2381 local f=$DIR/$tdir/$tfile
2382 local fid=$(make_large_for_progress $f)
2383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2384 wait_request_state $fid ARCHIVE SUCCEED
2387 md5sum $f >/dev/null &
2389 wait_request_state $fid RESTORE STARTED
2392 # rm must not block during restore
2393 wait_request_state $fid RESTORE STARTED
2395 wait_request_state $fid RESTORE SUCCEED
2396 # check md5sum pgm finished
2397 local there=$(ps -o pid,comm hp $pid >/dev/null)
2399 error "Restore initiator does not exit"
2401 local rc=$(wait $pid)
2403 error "Restore initiator failed with $rc"
2407 run_test 36 "Move file during restore"
2414 for n in $(seq 1 $count); do
2415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2417 echo "$count archive requests submitted"
2421 local stream_count=4
2422 local file_count=100
2424 local f=$DIR/$tdir/$tfile
2429 for i in $(seq 1 $file_count); do
2430 for p in $(seq 1 $stream_count); do
2431 fid=$(copy_file /etc/hosts $f.$p.$i)
2434 # force copytool to use a local/temp archive dir to ensure best
2435 # performance vs remote/NFS mounts used in auto-tests
2436 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2439 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2441 # to be sure wait_all_done will not be mislead by previous tests
2443 wait_for_grace_delay
2445 # start archive streams in background (archive files in parallel)
2446 for p in $(seq 1 $stream_count); do
2447 multi_archive $f.$p $file_count &
2450 echo -n "Wait for all requests being enqueued..."
2456 run_test 40 "Parallel archive requests"
2459 # test needs a running copytool
2463 local f=$DIR/$tdir/$tfile
2464 local fid=$(copy_file /etc/motd $f 1)
2466 $LFS hsm_archive $f || error "could not archive file"
2467 wait_request_state $fid ARCHIVE SUCCEED
2468 check_hsm_flags $f "0x00000009"
2470 multiop_bg_pause $f O_c || error "multiop failed"
2474 client_up || client_up || true
2476 kill -USR1 $MULTIPID
2477 wait $MULTIPID || error "multiop close failed"
2479 check_hsm_flags $f "0x0000000b"
2483 run_test 52 "Opened for write file on an evicted client should be set dirty"
2486 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(copy_file /etc/motd $f 1)
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2494 error "could not archive file"
2495 wait_request_state $fid ARCHIVE SUCCEED
2496 check_hsm_flags $f "0x00000009"
2498 multiop_bg_pause $f o_c || error "multiop failed"
2502 client_up || client_up || true
2504 kill -USR1 $MULTIPID
2505 wait $MULTIPID || error "multiop close failed"
2507 check_hsm_flags $f "0x00000009"
2511 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2514 # test needs a running copytool
2518 local f=$DIR/$tdir/$tfile
2519 local fid=$(make_small $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 # Avoid coordinator resending this request as soon it has failed.
2532 wait_request_state $fid ARCHIVE FAILED
2534 check_hsm_flags $f "0x00000003"
2539 run_test 54 "Write during an archive cancels it"
2542 # test needs a running copytool
2546 local f=$DIR/$tdir/$tfile
2547 local fid=$(make_small $f)
2549 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2550 error "could not archive file"
2551 wait_request_state $fid ARCHIVE STARTED
2553 check_hsm_flags $f "0x00000001"
2555 # Avoid coordinator resending this request as soon it has failed.
2558 $TRUNCATE $f 1024 || error "truncate failed"
2560 wait_request_state $fid ARCHIVE FAILED
2562 check_hsm_flags $f "0x00000003"
2567 run_test 55 "Truncate during an archive cancels it"
2570 # test needs a running copytool
2574 local f=$DIR/$tdir/$tfile
2575 local fid=$(make_large_for_progress $f)
2577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2578 error "could not archive file"
2579 wait_request_state $fid ARCHIVE STARTED
2581 check_hsm_flags $f "0x00000001"
2583 # Change metadata and sync to be sure we are not changing only
2588 wait_request_state $fid ARCHIVE SUCCEED
2590 check_hsm_flags $f "0x00000009"
2594 run_test 56 "Setattr during an archive is ok"
2597 # Need one client for I/O, one for request
2598 needclients 2 || return 0
2600 # test needs a running copytool
2604 local f=$DIR/$tdir/test_archive_remote
2605 # Create a file on a remote node
2606 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2607 "count=2 conv=fsync"
2610 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2611 error "hsm_archive failed"
2612 local fid=$(path2fid $f)
2613 wait_request_state $fid ARCHIVE SUCCEED
2615 # Release and implicit restore it
2616 do_node $CLIENT2 "$LFS hsm_release $f" ||
2617 error "hsm_release failed"
2618 do_node $CLIENT2 "md5sum $f" ||
2619 error "hsm_restore failed"
2621 wait_request_state $fid RESTORE SUCCEED
2625 run_test 57 "Archive a file with dirty cache on another node"
2627 truncate_released_file() {
2631 local sz=$(stat -c %s $src_file)
2632 local f=$DIR/$tdir/$tfile
2633 local fid=$(copy_file $1 $f)
2637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2638 error "could not archive file"
2639 wait_request_state $fid ARCHIVE SUCCEED
2641 $LFS hsm_release $f || error "could not release file"
2643 $TRUNCATE $f $trunc_to || error "truncate failed"
2646 local sz1=$(stat -c %s $f)
2647 [[ $sz1 == $trunc_to ]] ||
2648 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2651 check_hsm_flags $f "0x0000000b"
2653 local state=$(get_request_state $fid RESTORE)
2654 [[ "$state" == "SUCCEED" ]] ||
2655 error "truncate $sz does not trig restore, state = $state"
2657 $TRUNCATE $ref $trunc_to
2658 cmp $ref $f || error "file data wrong after truncate"
2664 # test needs a running copytool
2669 local sz=$(stat -c %s /etc/passwd)
2671 echo "truncate up from $sz to $((sz*2))"
2672 truncate_released_file /etc/passwd $((sz*2))
2674 echo "truncate down from $sz to $((sz/2))"
2675 truncate_released_file /etc/passwd $((sz/2))
2677 echo "truncate to 0"
2678 truncate_released_file /etc/passwd 0
2682 run_test 58 "Truncate a released file will trigger restore"
2685 # This test validates the fix for LU-4512. Ensure that the -u
2686 # option changes the progress reporting interval from the default
2687 # (30 seconds) to the user-specified interval.
2689 local progress_timeout=$((interval * 3))
2691 # test needs a new running copytool
2693 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2696 local f=$DIR/$tdir/$tfile
2697 local fid=$(make_large_for_progress $f)
2699 local start_at=$(date +%s)
2700 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2701 error "could not archive file"
2704 local mdt=${MDT_PREFIX}${mdtidx}
2705 local mds=mds$((mdtidx + 1))
2707 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2708 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2714 echo -n "Expecting a progress update within $progress_timeout seconds... "
2716 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2717 if [ $RESULT -gt 0 ]; then
2718 echo "$RESULT bytes copied in $WAIT seconds."
2720 elif [ $WAIT -ge $progress_timeout ]; then
2721 error "Timed out waiting for progress update!"
2724 WAIT=$((WAIT + sleep))
2728 local finish_at=$(date +%s)
2729 local elapsed=$((finish_at - start_at))
2731 # Ensure that the progress update occurred within the expected window.
2732 if [ $elapsed -lt $interval ]; then
2733 error "Expected progress update after at least $interval seconds"
2739 run_test 60 "Changing progress update interval from default"
2742 # test needs a new running copytool
2744 copytool_monitor_setup
2745 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2747 # Just start and stop the copytool to generate events.
2751 local REGISTER_EVENT
2752 local UNREGISTER_EVENT
2753 while read event; do
2754 local parsed=$(parse_json_event "$event")
2755 if [ -z "$parsed" ]; then
2756 error "Copytool sent malformed event: $event"
2760 if [ $event_type == "REGISTER" ]; then
2761 REGISTER_EVENT=$event
2762 elif [ $event_type == "UNREGISTER" ]; then
2763 UNREGISTER_EVENT=$event
2765 done < <(echo $"$(get_copytool_event_log)")
2767 if [ -z "$REGISTER_EVENT" ]; then
2768 error "Copytool failed to send register event to FIFO"
2771 if [ -z "$UNREGISTER_EVENT" ]; then
2772 error "Copytool failed to send unregister event to FIFO"
2775 copytool_monitor_cleanup
2776 echo "Register/Unregister events look OK."
2778 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2781 # Bump progress interval for livelier events.
2784 # test needs a new running copytool
2786 copytool_monitor_setup
2787 HSMTOOL_UPDATE_INTERVAL=$interval \
2788 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2791 local f=$DIR/$tdir/$tfile
2792 local fid=$(make_large_for_progress $f)
2794 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2795 error "could not archive file"
2796 wait_request_state $fid ARCHIVE SUCCEED
2798 local expected_fields="event_time data_fid source_fid"
2799 expected_fields+=" total_bytes current_bytes"
2803 while read event; do
2804 # Make sure we're not getting anything from previous events.
2805 for field in $expected_fields; do
2809 local parsed=$(parse_json_event "$event")
2810 if [ -z "$parsed" ]; then
2811 error "Copytool sent malformed event: $event"
2815 if [ $event_type == "ARCHIVE_START" ]; then
2818 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2821 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2825 # Do some simple checking of the progress update events.
2826 for expected_field in $expected_fields; do
2827 if [ -z ${!expected_field+x} ]; then
2828 error "Missing $expected_field field in event"
2832 if [ $total_bytes -eq 0 ]; then
2833 error "Expected total_bytes to be > 0"
2836 # These should be identical throughout an archive
2838 if [ $source_fid != $data_fid ]; then
2839 error "Expected source_fid to equal data_fid"
2841 done < <(echo $"$(get_copytool_event_log)")
2843 if [ -z "$START_EVENT" ]; then
2844 error "Copytool failed to send archive start event to FIFO"
2847 if [ -z "$FINISH_EVENT" ]; then
2848 error "Copytool failed to send archive finish event to FIFO"
2851 echo "Archive events look OK."
2855 copytool_monitor_cleanup
2857 run_test 71 "Copytool logs JSON archive events to FIFO"
2860 # Bump progress interval for livelier events.
2863 # test needs a new running copytool
2865 copytool_monitor_setup
2866 HSMTOOL_UPDATE_INTERVAL=$interval \
2867 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2868 local test_file=$HSMTOOL_MONITOR_DIR/file
2870 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2872 do_facet $SINGLEAGT "$cmd" ||
2873 error "cannot create $test_file on $SINGLEAGT"
2874 copy2archive $test_file $tdir/$tfile
2877 local f=$DIR/$tdir/$tfile
2878 import_file $tdir/$tfile $f
2879 f=$DIR2/$tdir/$tfile
2880 echo "Verifying released state: "
2881 check_hsm_flags $f "0x0000000d"
2883 local fid=$(path2fid $f)
2885 wait_request_state $fid RESTORE SUCCEED
2887 local expected_fields="event_time data_fid source_fid"
2888 expected_fields+=" total_bytes current_bytes"
2892 while read event; do
2893 # Make sure we're not getting anything from previous events.
2894 for field in $expected_fields; do
2898 local parsed=$(parse_json_event "$event")
2899 if [ -z "$parsed" ]; then
2900 error "Copytool sent malformed event: $event"
2904 if [ $event_type == "RESTORE_START" ]; then
2906 if [ $source_fid != $data_fid ]; then
2907 error "source_fid should == data_fid at start"
2910 elif [ $event_type == "RESTORE_FINISH" ]; then
2912 if [ $source_fid != $data_fid ]; then
2913 error "source_fid should == data_fid at finish"
2916 elif [ $event_type != "RESTORE_RUNNING" ]; then
2920 # Do some simple checking of the progress update events.
2921 for expected_field in $expected_fields; do
2922 if [ -z ${!expected_field+x} ]; then
2923 error "Missing $expected_field field in event"
2927 if [ $total_bytes -eq 0 ]; then
2928 error "Expected total_bytes to be > 0"
2931 # When a restore starts out, the data fid is the same as the
2932 # source fid. After the restore has gotten going, we learn
2933 # the new data fid. Once the restore has finished, the source
2934 # fid is set to the new data fid.
2936 # We test this because some monitoring software may depend on
2937 # this behavior. If it changes, then the consumers of these
2938 # events may need to be modified.
2939 if [ $source_fid == $data_fid ]; then
2940 error "source_fid should != data_fid during restore"
2942 done < <(echo $"$(get_copytool_event_log)")
2944 if [ -z "$START_EVENT" ]; then
2945 error "Copytool failed to send restore start event to FIFO"
2948 if [ -z "$FINISH_EVENT" ]; then
2949 error "Copytool failed to send restore finish event to FIFO"
2952 echo "Restore events look OK."
2956 copytool_monitor_cleanup
2960 run_test 72 "Copytool logs JSON restore events to FIFO"
2963 file_count=51 # Max number of files constrained by LNET message size
2964 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2965 local f=$DIR/$tdir/$tfile
2966 local FILELIST=/tmp/filelist.txt
2970 for i in $(seq 1 $file_count); do
2971 fid=$(copy_file /etc/hosts $f.$i)
2972 echo $f.$i >> $FILELIST
2975 # to be sure wait_all_done will not be mislead by previous tests
2977 wait_for_grace_delay
2978 $LFS hsm_archive --filelist $FILELIST ||
2979 error "cannot archive a file list"
2981 $LFS hsm_release --filelist $FILELIST ||
2982 error "cannot release a file list"
2983 $LFS hsm_restore --filelist $FILELIST ||
2984 error "cannot restore a file list"
2988 run_test 90 "Archive/restore a file list"
2990 double_verify_reset_hsm_param() {
2992 echo "Testing $HSM_PARAM.$p"
2993 local val=$(get_hsm_param $p)
2995 local val2=$(($val * 2))
2996 set_hsm_param $p $val2
2997 val=$(get_hsm_param $p)
2998 [[ $val == $val2 ]] ||
2999 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3000 echo "Set $p to 0 must failed"
3004 set_hsm_param $p $save
3006 if [[ $rc == 0 ]]; then
3007 error "we must not be able to set $HSM_PARAM.$p to 0"
3012 double_verify_reset_hsm_param loop_period
3013 double_verify_reset_hsm_param grace_delay
3014 double_verify_reset_hsm_param active_request_timeout
3015 double_verify_reset_hsm_param max_requests
3016 double_verify_reset_hsm_param default_archive_id
3018 run_test 100 "Set coordinator /proc tunables"
3025 run_test 102 "Verify coordinator control"
3028 # test needs a running copytool
3035 for i in $(seq 1 20); do
3036 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3042 echo "Current requests"
3043 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3044 $HSM_PARAM.actions |\
3045 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3047 [[ -z "$res" ]] || error "Some request have not been canceled"
3051 run_test 103 "Purge all requests"
3056 # test needs a running copytool
3060 local f=$DIR/$tdir/$tfile
3061 local fid=$(make_large_for_progress $f)
3062 # if cdt is on, it can serve too quickly the request
3064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3065 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3066 $HSM_PARAM.actions |\
3067 grep $fid | cut -f16 -d=")
3070 [[ "$data1" == "$DATAHEX" ]] ||
3071 error "Data field in records is ($data1) and not ($DATAHEX)"
3075 run_test 104 "Copy tool data field"
3082 for i in $(seq -w 1 10); do
3083 cp /etc/passwd $DIR/$tdir/$i
3084 $LFS hsm_archive $DIR/$tdir/$i
3086 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3087 $HSM_PARAM.actions |\
3088 grep WAITING | wc -l")
3091 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3092 $HSM_PARAM.actions |\
3093 grep WAITING | wc -l")
3096 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3097 error "Requests count after shutdown $reqcnt2 != "\
3098 "before shutdown $reqcnt1"
3100 run_test 105 "Restart of coordinator"
3102 get_agent_by_uuid_mdt() {
3105 local mds=mds$(($mdtidx + 1))
3106 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3110 check_agent_registered_by_mdt() {
3113 local mds=mds$(($mdtidx + 1))
3114 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3115 if [[ ! -z "$agent" ]]; then
3116 echo "found agent $agent on $mds"
3118 error "uuid $uuid not found in agent list on $mds"
3122 check_agent_unregistered_by_mdt() {
3125 local mds=mds$(($mdtidx + 1))
3126 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3127 if [[ -z "$agent" ]]; then
3128 echo "uuid not found in agent list on $mds"
3130 error "uuid found in agent list on $mds: $agent"
3134 check_agent_registered() {
3137 for mdsno in $(seq 1 $MDSCOUNT); do
3138 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3142 check_agent_unregistered() {
3145 for mdsno in $(seq 1 $MDSCOUNT); do
3146 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3151 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3152 get_client_uuid $MOUNT | cut -d' ' -f2)
3155 check_agent_registered $uuid
3157 search_copytools || error "No copytool found"
3160 check_agent_unregistered $uuid
3163 check_agent_registered $uuid
3167 run_test 106 "Copytool register/unregister"
3170 # test needs a running copytool
3172 # create and archive file
3174 local f1=$DIR/$tdir/$tfile
3175 local fid=$(copy_file /etc/passwd $f1)
3176 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3177 wait_request_state $fid ARCHIVE SUCCEED
3178 # shutdown and restart MDS
3180 # check the copytool still gets messages from MDT
3181 local f2=$DIR/$tdir/2
3182 local fid=$(copy_file /etc/passwd $f2)
3183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3184 # main check of this sanity: this request MUST succeed
3185 wait_request_state $fid ARCHIVE SUCCEED
3188 run_test 107 "Copytool re-register after MDS restart"
3190 policy_set_and_test()
3194 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3195 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3196 [[ "$policy" == "$target" ]] ||
3197 error "Wrong policy after '$change': '$policy' != '$target'"
3201 # to force default policy setting if error
3202 CDT_POLICY_HAD_CHANGED=true
3204 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3205 local default="NonBlockingRestore [NoRetryAction]"
3206 [[ "$policy" == "$default" ]] ||
3207 error "default policy has changed,"\
3208 " '$policy' != '$default' update the test"
3209 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3210 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3211 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3212 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3213 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3214 # useless bacause we know but safer for futur changes to use real value
3215 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3216 echo "Next set_param must failed"
3217 policy_set_and_test "wrong" "$policy"
3220 echo "Back to default policy"
3221 cdt_set_sanity_policy
3223 run_test 109 "Policy display/change"
3226 # test needs a running copytool
3231 copy2archive /etc/passwd $tdir/$tfile
3233 local f=$DIR/$tdir/$tfile
3234 import_file $tdir/$tfile $f
3235 local fid=$(path2fid $f)
3237 cdt_set_non_blocking_restore
3242 wait_request_state $fid RESTORE SUCCEED
3243 cdt_clear_non_blocking_restore
3247 error "md5sum returns $st != 1, "\
3248 "should also perror ENODATA (No data available)"
3252 run_test 110a "Non blocking restore policy (import case)"
3255 # test needs a running copytool
3259 local f=$DIR/$tdir/$tfile
3260 local fid=$(copy_file /etc/passwd $f)
3261 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3262 wait_request_state $fid ARCHIVE SUCCEED
3265 cdt_set_non_blocking_restore
3270 wait_request_state $fid RESTORE SUCCEED
3271 cdt_clear_non_blocking_restore
3275 error "md5sum returns $st != 1, "\
3276 "should also perror ENODATA (No data available)"
3280 run_test 110b "Non blocking restore policy (release case)"
3283 # test needs a running copytool
3287 copy2archive /etc/passwd $tdir/$tfile
3289 local f=$DIR/$tdir/$tfile
3291 import_file $tdir/$tfile $f
3292 local fid=$(path2fid $f)
3296 copytool_remove_backend $fid
3299 wait_request_state $fid RESTORE FAILED
3306 [[ $st == 0 ]] || error "Restore does not failed"
3310 run_test 111a "No retry policy (import case), restore will error"\
3311 " (No such file or directory)"
3314 # test needs a running copytool
3318 local f=$DIR/$tdir/$tfile
3319 local fid=$(copy_file /etc/passwd $f)
3321 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3322 wait_request_state $fid ARCHIVE SUCCEED
3325 copytool_remove_backend $fid
3328 wait_request_state $fid RESTORE FAILED
3335 [[ $st == 0 ]] || error "Restore does not failed"
3339 run_test 111b "No retry policy (release case), restore will error"\
3340 " (No such file or directory)"
3343 # test needs a running copytool
3347 local f=$DIR/$tdir/$tfile
3348 local fid=$(copy_file /etc/passwd $f)
3350 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3351 local l=$($LFS hsm_action $f)
3353 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3357 wait_request_state $fid ARCHIVE SUCCEED
3360 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3364 run_test 112 "State of recorded request"
3367 # test needs a running copytool
3371 local f=$DIR/$tdir/$tfile
3372 local fid=$(make_large_for_cancel $f)
3373 # test with cdt on is made in test_221
3375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3378 wait_request_state $fid ARCHIVE CANCELED
3379 wait_request_state $fid CANCEL SUCCEED
3383 run_test 200 "Register/Cancel archive"
3386 # test needs a running copytool
3390 local f=$DIR/$tdir/$tfile
3391 make_archive $tdir/$tfile
3392 import_file $tdir/$tfile $f
3393 local fid=$(path2fid $f)
3395 # test with cdt on is made in test_222
3400 wait_request_state $fid RESTORE CANCELED
3401 wait_request_state $fid CANCEL SUCCEED
3405 run_test 201 "Register/Cancel restore"
3408 # test needs a running copytool
3412 local f=$DIR/$tdir/$tfile
3413 local fid=$(make_large_for_progress $f)
3414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3415 wait_request_state $fid ARCHIVE SUCCEED
3421 wait_request_state $fid REMOVE CANCELED
3425 run_test 202 "Register/Cancel remove"
3428 # test needs a running copytool
3433 local f=$DIR/$tdir/$tfile
3434 local fid=$(copy_file /etc/passwd $f)
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3439 wait_request_state $fid ARCHIVE SUCCEED
3441 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3445 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3449 run_test 220 "Changelog for archive"
3452 # test needs a running copytool
3457 local f=$DIR/$tdir/$tfile
3458 local fid=$(make_large_for_cancel $f)
3462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3463 wait_request_state $fid ARCHIVE STARTED
3465 wait_request_state $fid ARCHIVE CANCELED
3466 wait_request_state $fid CANCEL SUCCEED
3468 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3471 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3475 run_test 221 "Changelog for archive canceled"
3478 # test needs a running copytool
3482 copy2archive /etc/passwd $tdir/$tfile
3484 local f=$DIR/$tdir/$tfile
3485 import_file $tdir/$tfile $f
3486 local fid=$(path2fid $f)
3491 wait_request_state $fid RESTORE SUCCEED
3493 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3496 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3500 run_test 222a "Changelog for explicit restore"
3503 # test needs a running copytool
3507 local f=$DIR/$tdir/$tfile
3508 local fid=$(copy_file /etc/passwd $f)
3511 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3512 wait_request_state $fid ARCHIVE SUCCEED
3517 wait_request_state $fid RESTORE SUCCEED
3519 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3522 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3526 run_test 222b "Changelog for implicit restore"
3529 # test needs a running copytool
3534 local f=$DIR/$tdir/$tfile
3535 make_archive $tdir/$tfile
3539 import_file $tdir/$tfile $f
3540 local fid=$(path2fid $f)
3543 wait_request_state $fid RESTORE STARTED
3545 wait_request_state $fid RESTORE CANCELED
3546 wait_request_state $fid CANCEL SUCCEED
3548 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3551 [[ $flags == $target ]] ||
3552 error "Changelog flag is $flags not $target"
3556 run_test 223a "Changelog for restore canceled (import case)"
3559 # test needs a running copytool
3564 local f=$DIR/$tdir/$tfile
3565 local fid=$(make_large_for_progress $f)
3568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3569 wait_request_state $fid ARCHIVE SUCCEED
3572 wait_request_state $fid RESTORE STARTED
3574 wait_request_state $fid RESTORE CANCELED
3575 wait_request_state $fid CANCEL SUCCEED
3577 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3580 [[ $flags == $target ]] ||
3581 error "Changelog flag is $flags not $target"
3585 run_test 223b "Changelog for restore canceled (release case)"
3588 # test needs a running copytool
3593 local f=$DIR/$tdir/$tfile
3594 local fid=$(copy_file /etc/passwd $f)
3597 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3598 wait_request_state $fid ARCHIVE SUCCEED
3601 wait_request_state $fid REMOVE SUCCEED
3603 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3606 [[ $flags == $target ]] ||
3607 error "Changelog flag is $flags not $target"
3611 run_test 224 "Changelog for remove"
3614 # test needs a running copytool
3617 # test is not usable because remove request is too fast
3618 # so it is always finished before cancel can be done ...
3619 echo "Test disabled"
3624 local f=$DIR/$tdir/$tfile
3625 local fid=$(make_large_for_progress $f)
3628 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3629 wait_request_state $fid ARCHIVE SUCCEED
3631 # if cdt is on, it can serve too quickly the request
3636 wait_request_state $fid REMOVE CANCELED
3637 wait_request_state $fid CANCEL SUCCEED
3639 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3640 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3641 tail -n 1 | awk '{print $5}')
3644 [[ $flags == $target ]] ||
3645 error "Changelog flag is $flags not $target"
3649 run_test 225 "Changelog for remove canceled"
3652 # test needs a running copytool
3657 local f1=$DIR/$tdir/$tfile-1
3658 local f2=$DIR/$tdir/$tfile-2
3659 local f3=$DIR/$tdir/$tfile-3
3660 local fid1=$(copy_file /etc/passwd $f1)
3661 local fid2=$(copy_file /etc/passwd $f2)
3662 copy_file /etc/passwd $f3
3665 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3666 wait_request_state $fid1 ARCHIVE SUCCEED
3668 $LFS hsm_archive $f2
3669 wait_request_state $fid2 ARCHIVE SUCCEED
3671 rm $f1 || error "rm $f1 failed"
3673 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3676 [[ $flags == $target ]] ||
3677 error "Changelog flag is $flags not $target"
3679 mv $f3 $f2 || error "mv $f3 $f2 failed"
3681 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3684 [[ $flags == $target ]] ||
3685 error "Changelog flag is $flags not $target"
3689 run_test 226 "changelog for last rm/mv with exiting archive"
3691 check_flags_changes() {
3699 $LFS hsm_set --$hsm_flag $f ||
3700 error "Cannot set $hsm_flag on $f"
3701 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3702 local seen=${#flags[*]}
3704 [[ $seen == $cnt ]] ||
3705 error "set $hsm_flag: Changelog events $seen != $cnt"
3706 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3707 error "set $hsm_flag: Changelog flags are "\
3708 "${flags[$((cnt - 1))]} not $target"
3710 $LFS hsm_clear --$hsm_flag $f ||
3711 error "Cannot clear $hsm_flag on $f"
3712 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3715 [[ $cnt == $seen ]] ||
3716 error "clear $hsm_flag: Changelog events $seen != $cnt"
3718 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3719 error "clear $hsm_flag: Changelog flag is "\
3720 "${flags[$((cnt - 1))]} not $target"
3724 # test needs a running copytool
3731 for i in norelease noarchive exists archived
3733 local f=$DIR/$tdir/$tfile-$i
3734 local fid=$(copy_file /etc/passwd $f)
3735 check_flags_changes $f $fid $i 0 1
3738 f=$DIR/$tdir/$tfile---lost
3739 fid=$(copy_file /etc/passwd $f)
3740 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3741 wait_request_state $fid ARCHIVE SUCCEED
3742 check_flags_changes $f $fid lost 3 1
3746 run_test 227 "changelog when explicit setting of HSM flags"
3749 # test needs a running copytool
3752 local fid=$(make_small_sync $DIR/$tfile)
3753 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3754 wait_request_state $fid ARCHIVE SUCCEED
3756 $LFS hsm_release $DIR/$tfile
3757 check_hsm_flags $DIR/$tfile "0x0000000d"
3759 filefrag $DIR/$tfile | grep " 1 extent found" ||
3760 error "filefrag on released file must return only one extent"
3762 # only newer versions of cp detect sparse files by stat/FIEMAP
3764 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3765 error "copying $DIR/$tfile"
3766 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3768 $LFS hsm_release $DIR/$tfile
3769 check_hsm_flags $DIR/$tfile "0x0000000d"
3771 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3773 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3775 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3776 error "comparing untarred $DIR/$tfile"
3778 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3779 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3782 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3785 # test needs a running copytool
3789 local maxrequest=$(get_hsm_param max_requests)
3790 local rqcnt=$(($maxrequest * 3))
3794 for i in $(seq -w 1 $rqcnt); do
3796 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3798 # we do it in 2 steps, so all requests arrive at the same time
3799 for i in $(seq -w 1 $rqcnt); do
3800 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3805 while [[ $cnt != 0 || $wt != 0 ]]; do
3807 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3808 $HSM_PARAM.actions |\
3809 grep STARTED | grep -v CANCEL | wc -l")
3810 [[ $cnt -le $maxrequest ]] ||
3811 error "$cnt > $maxrequest too many started requests"
3812 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3813 $HSM_PARAM.actions |\
3814 grep WAITING | wc -l")
3815 echo "max=$maxrequest started=$cnt waiting=$wt"
3820 run_test 250 "Coordinator max request"
3823 # test needs a running copytool
3827 local f=$DIR/$tdir/$tfile
3828 local fid=$(make_large_for_cancel $f)
3831 # to have a short test
3832 local old_to=$(get_hsm_param active_request_timeout)
3833 set_hsm_param active_request_timeout 4
3834 # to be sure the cdt will wake up frequently so
3835 # it will be able to cancel the "old" request
3836 local old_loop=$(get_hsm_param loop_period)
3837 set_hsm_param loop_period 2
3840 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3841 wait_request_state $fid ARCHIVE STARTED
3843 wait_request_state $fid ARCHIVE CANCELED
3845 set_hsm_param active_request_timeout $old_to
3846 set_hsm_param loop_period $old_loop
3850 run_test 251 "Coordinator request timeout"
3853 # the only way to test ondisk conf is to restart MDS ...
3854 echo "Stop coordinator and remove coordinator state at mount"
3857 # clean on disk conf set by default
3858 cdt_clear_mount_state
3859 cdt_check_state stopped
3861 # check cdt still off after umount/remount
3863 cdt_check_state stopped
3865 echo "Set coordinator start at mount, and start coordinator"
3866 cdt_set_mount_state enabled
3869 cdt_check_state enabled
3871 # check cdt still on after umount/remount
3873 cdt_check_state enabled
3875 # we are back to original state (cdt started at mount)
3877 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3880 local ai=$(get_hsm_param default_archive_id)
3881 local new=$((ai + 1))
3883 set_hsm_param default_archive_id $new -P
3885 local res=$(get_hsm_param default_archive_id)
3888 set_hsm_param default_archive_id "" "-P -d"
3890 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3892 run_test 301 "HSM tunnable are persistent"
3895 local ai=$(get_hsm_param default_archive_id)
3896 local new=$((ai + 1))
3901 set_hsm_param default_archive_id $new -P
3904 for mdtno in $(seq 1 $MDSCOUNT); do
3909 cdt_check_state enabled
3911 local res=$(get_hsm_param default_archive_id)
3914 set_hsm_param default_archive_id "" "-P -d"
3916 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3918 run_test 302 "HSM tunnable are persistent when CDT is off"
3921 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3927 local dir_mdt0=$DIR/$tdir/mdt0
3928 local dir_mdt1=$DIR/$tdir/mdt1
3930 # create 1 dir per MDT
3931 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3932 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3934 # create 1 file in each MDT
3935 local fid1=$(make_small $dir_mdt0/$tfile)
3936 local fid2=$(make_small $dir_mdt1/$tfile)
3938 # check that hsm request on mdt0 is sent to the right MDS
3939 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3940 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3941 echo "archive successful on mdt0"
3943 # check that hsm request on mdt1 is sent to the right MDS
3944 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3945 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3946 echo "archive successful on mdt1"
3949 # clean test files and directories
3950 rm -rf $dir_mdt0 $dir_mdt1
3952 run_test 400 "Single request is sent to the right MDT"
3955 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3961 local dir_mdt0=$DIR/$tdir/mdt0
3962 local dir_mdt1=$DIR/$tdir/mdt1
3964 # create 1 dir per MDT
3965 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3966 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3968 # create 1 file in each MDT
3969 local fid1=$(make_small $dir_mdt0/$tfile)
3970 local fid2=$(make_small $dir_mdt1/$tfile)
3972 # check that compound requests are shunt to the rights MDTs
3973 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3974 error "lfs hsm_archive"
3975 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3976 echo "archive successful on mdt0"
3977 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3978 echo "archive successful on mdt1"
3981 # clean test files and directories
3982 rm -rf $dir_mdt0 $dir_mdt1
3984 run_test 401 "Compound requests split and sent to their respective MDTs"
3986 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3991 local node=$(facet_active_host $facet)
3993 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3994 awk '{print $4}'); do
3995 echo "$3 $mdc on $node"
3996 do_facet $facet "$LCTL --device $mdc $state" || return 1
4001 # make sure there is no running copytool
4004 # deactivate all mdc on agent1
4005 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
4007 copytool_setup $SINGLEAGT
4009 check_agent_unregistered "uuid" # match any agent
4011 # no expected running copytool
4012 search_copytools $agent && error "Copytool start should have failed"
4015 mdc_change_state $SINGLEAGT "MDT000." "activate"
4017 run_test 402 "Copytool start fails if all MDTs are inactive"
4020 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4022 # make sure there is no running copytool
4025 local agent=$(facet_active_host $SINGLEAGT)
4026 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4028 # deactivate all mdc for MDT0001
4029 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4032 # check the agent is registered on MDT0000, and not on MDT0001
4033 check_agent_registered_by_mdt $uuid 0
4034 check_agent_unregistered_by_mdt $uuid 1
4036 # check running copytool process
4037 search_copytools $agent || error "No running copytools on $agent"
4039 # reactivate all mdc for MDT0001
4040 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4042 # make sure the copytool is now registered to all MDTs
4043 check_agent_registered $uuid
4047 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4050 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4054 # create files on both MDT0000 and MDT0001
4057 local dir_mdt0=$DIR/$tdir/mdt0
4058 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4060 # create 1 file on mdt0
4061 local fid1=$(make_small $dir_mdt0/$tfile)
4063 # deactivate all mdc for MDT0001
4064 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4066 # send an HSM request for files in MDT0000
4067 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4069 # check for completion of files in MDT0000
4070 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4071 echo "archive successful on mdt0"
4073 # reactivate all mdc for MDT0001
4074 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4077 # clean test files and directories
4080 run_test 404 "Inactive MDT does not block requests for active MDTs"
4085 check_and_cleanup_lustre