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 facet=$SINGLEAGT
261 local agents=${1:-$(facet_active_host $facet)}
266 local hsm_root=$(copytool_device $facet)
268 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
270 echo "Copytool is stopped on $agents"
272 # clean all CDTs orphans requests from previous tests
273 # that would otherwise need to timeout to clear.
274 for mdtno in $(seq 1 $MDSCOUNT); do
276 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
277 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
279 # skip already stop[ed,ing] CDTs
280 echo $oldstate | grep stop && continue
282 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
283 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
285 error "mds${mdtno} cdt state is not stopped"
286 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
287 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
289 error "mds${mdtno} cdt state is not $oldstate"
291 do_facet $facet "rm -rf $hsm_root"
295 local agents=${1:-$(facet_active_host $SINGLEAGT)}
297 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
298 echo "Copytool is suspended on $agents"
301 copytool_remove_backend() {
303 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
304 echo "Remove from backend: $fid = $be"
305 do_facet $SINGLEAGT rm -f $be
309 do_facet $SINGLEAGT \
310 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
311 --import $1 $2 $MOUNT" ||
312 error "import of $1 to $2 failed"
316 local file=$HSM_ARCHIVE/$1
317 do_facet $SINGLEAGT mkdir -p $(dirname $file)
318 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
319 error "cannot create $file"
323 local file=$HSM_ARCHIVE/$2
324 do_facet $SINGLEAGT mkdir -p $(dirname $file)
325 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
334 if [[ "$value" != "" ]]; then
337 for mdtno in $(seq 1 $MDSCOUNT); do
338 local idx=$(($mdtno - 1))
339 local facet=mds${mdtno}
340 # if $arg include -P option, run 1 set_param per MDT on the MGS
341 # else, run set_param on each MDT
342 [[ $arg = *"-P"* ]] && facet=mgs
343 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
344 [[ $? != 0 ]] && rc=1
354 for mdtno in $(seq 1 $MDSCOUNT); do
355 local idx=$(($mdtno - 1))
356 wait_result mds${mdtno} \
357 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
359 error "$key state is not '$target' on mds${mdtno}"
366 for mdtno in $(seq 1 $MDSCOUNT); do
367 local idx=$(($mdtno - 1))
368 local cl_user=$(do_facet mds${mdtno} $LCTL \
369 --device ${MDT[$idx]} \
370 changelog_register -n)
372 do_facet mds${mdtno} lctl set_param \
373 mdd.${MDT[$idx]}.changelog_mask="+hsm"
374 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
378 changelog_cleanup() {
380 for mdtno in $(seq 1 $MDSCOUNT); do
381 local idx=$(($mdtno - 1))
382 [[ -z ${CL_USERS[$idx]} ]] && continue
383 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
384 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
385 changelog_deregister ${CL_USERS[$idx]}
390 changelog_get_flags() {
395 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
400 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
408 mdts_set_param "$opt -n" "hsm.$param" "$value"
415 mdts_set_param "" hsm_control "$cmd"
416 mdts_check_param hsm_control "$target" 10
419 cdt_set_sanity_policy() {
420 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
423 mdts_set_param "" hsm.policy "+NRA"
424 mdts_set_param "" hsm.policy "-NBR"
425 CDT_POLICY_HAD_CHANGED=
430 mdts_set_param "" hsm.policy "+NRA"
431 CDT_POLICY_HAD_CHANGED=true
434 cdt_clear_no_retry() {
435 mdts_set_param "" hsm.policy "-NRA"
436 CDT_POLICY_HAD_CHANGED=true
439 cdt_set_non_blocking_restore() {
440 mdts_set_param "" hsm.policy "+NBR"
441 CDT_POLICY_HAD_CHANGED=true
444 cdt_clear_non_blocking_restore() {
445 mdts_set_param "" hsm.policy "-NBR"
446 CDT_POLICY_HAD_CHANGED=true
449 cdt_clear_mount_state() {
450 mdts_set_param "-P -d" hsm_control ""
453 cdt_set_mount_state() {
454 mdts_set_param "-P" hsm_control "$1"
458 mdts_check_param hsm_control "$1" 20
462 set_test_state disabled disabled
466 set_test_state enabled enabled
470 set_test_state shutdown stopped
474 set_test_state purge enabled
480 cdt_set_sanity_policy
484 local client_count=$1
485 if [[ $CLIENTCOUNT -lt $client_count ]]; then
486 skip "Need $client_count or more clients, have $CLIENTCOUNT"
493 $LFS path2fid $1 | tr -d '[]'
500 if [[ $u == "user" ]]; then
501 local st=$($RUNAS $LFS hsm_state $f)
503 local st=$($LFS hsm_state $f)
507 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
509 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
513 get_hsm_archive_id() {
515 local st=$($LFS hsm_state $f)
516 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
518 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
527 local st=$(get_hsm_flags $f)
528 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
531 check_hsm_flags_user() {
535 local st=$(get_hsm_flags $f user)
536 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
548 if [[ "$3" != 1 ]]; then
552 cp $1 $f || error "cannot copy $1 to $f"
553 path2fid $f || error "cannot get fid on $f"
557 local file2=${1/$DIR/$DIR2}
558 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
559 error "cannot create $file2"
560 path2fid $1 || error "cannot get fid on $1"
564 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
565 error "cannot create $1"
566 path2fid $1 || error "cannot get fid on $1"
569 cleanup_large_files() {
570 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
572 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
575 make_large_for_striping() {
576 local file2=${1/$DIR/$DIR2}
577 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
581 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
582 error "cannot create $file2"
583 path2fid $1 || error "cannot get fid on $1"
586 make_large_for_progress() {
587 local file2=${1/$DIR/$DIR2}
591 # big file is large enough, so copy time is > 30s
592 # so copytool make 1 progress
593 # size is not a multiple of 1M to avoid stripe
595 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
596 error "cannot create $file2"
597 path2fid $1 || error "cannot get fid on $1"
600 make_large_for_progress_aligned() {
601 local file2=${1/$DIR/$DIR2}
605 # big file is large enough, so copy time is > 30s
606 # so copytool make 1 progress
607 # size is a multiple of 1M to have stripe
609 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
610 error "cannot create $file2"
611 path2fid $1 || error "cannot get fid on $1"
614 make_large_for_cancel() {
615 local file2=${1/$DIR/$DIR2}
619 # Copy timeout is 100s. 105MB => 105s
620 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
621 error "cannot create $file2"
622 path2fid $1 || error "cannot get fid on $1"
628 wait_update --verbose $(facet_active_host $facet) "$@"
631 wait_request_state() {
635 # 4th arg (mdt index) is optional
637 local mds=mds$(($mdtidx + 1))
639 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
640 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
642 wait_result $mds "$cmd" $state 100 ||
643 error "request on $fid is not $state on $mds"
646 get_request_state() {
650 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
651 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
654 get_request_count() {
658 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
659 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
666 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
667 [[ -n $fid ]] && cmd+=" | grep '$fid'"
668 cmd+=" | egrep 'WAITING|STARTED'"
670 wait_result $SINGLEMDS "$cmd" "" $timeout ||
671 error "requests did not complete"
674 wait_for_grace_delay() {
675 local val=$(get_hsm_param grace_delay)
682 # python2.6 in EL6 includes an internal json module
683 local json_parser='import json; import fileinput;'
684 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
685 json_parser+='json.loads([line for line in '
686 json_parser+='fileinput.input()][0]).items()])'
688 echo $raw_event | python -c "$json_parser"
691 # populate MDT device array
697 # cleanup from previous bad setup
698 search_and_kill_copytool
700 # for recovery tests, coordinator needs to be started at mount
702 # the lustre conf must be without hsm on (like for sanity.sh)
703 echo "Set HSM on and start"
704 cdt_set_mount_state enabled
705 cdt_check_state enabled
707 echo "Start copytool"
710 echo "Set sanity-hsm HSM policy"
711 cdt_set_sanity_policy
713 # finished requests are quickly removed from list
714 set_hsm_param grace_delay 10
720 local f=$DIR/$tdir/$tfile
724 check_hsm_flags_user $f "0x00000000"
726 $RUNAS $LFS hsm_set --norelease $f ||
727 error "user could not change hsm flags"
728 check_hsm_flags_user $f "0x00000010"
730 $RUNAS $LFS hsm_clear --norelease $f ||
731 error "user could not clear hsm flags"
732 check_hsm_flags_user $f "0x00000000"
734 # User could not change those flags...
735 $RUNAS $LFS hsm_set --exists $f &&
736 error "user should not set this flag"
737 check_hsm_flags_user $f "0x00000000"
740 $LFS hsm_set --exists $f ||
741 error "root could not change hsm flags"
742 check_hsm_flags_user $f "0x00000001"
744 $LFS hsm_clear --exists $f ||
745 error "root could not clear hsm state"
746 check_hsm_flags_user $f "0x00000000"
749 run_test 1 "lfs hsm flags root/non-root access"
753 local f=$DIR/$tdir/$tfile
755 # New files are not dirty
756 check_hsm_flags $f "0x00000000"
758 # For test, we simulate an archived file.
759 $LFS hsm_set --exists $f || error "user could not change hsm flags"
760 check_hsm_flags $f "0x00000001"
762 # chmod do not put the file dirty
763 chmod 600 $f || error "could not chmod test file"
764 check_hsm_flags $f "0x00000001"
766 # chown do not put the file dirty
767 chown $RUNAS_ID $f || error "could not chown test file"
768 check_hsm_flags $f "0x00000001"
770 # truncate put the file dirty
771 $TRUNCATE $f 1 || error "could not truncate test file"
772 check_hsm_flags $f "0x00000003"
774 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
775 check_hsm_flags $f "0x00000001"
777 run_test 2 "Check file dirtyness when doing setattr"
783 # New files are not dirty
785 check_hsm_flags $f "0x00000000"
787 # For test, we simulate an archived file.
788 $LFS hsm_set --exists $f ||
789 error "user could not change hsm flags"
790 check_hsm_flags $f "0x00000001"
792 # Reading a file, does not set dirty
793 cat $f > /dev/null || error "could not read file"
794 check_hsm_flags $f "0x00000001"
796 # Open for write without modifying data, does not set dirty
797 openfile -f O_WRONLY $f || error "could not open test file"
798 check_hsm_flags $f "0x00000001"
800 # Append to a file sets it dirty
801 cp -p /etc/passwd $f.append || error "could not create file"
802 $LFS hsm_set --exists $f.append ||
803 error "user could not change hsm flags"
804 dd if=/etc/passwd of=$f.append bs=1 count=3\
805 conv=notrunc oflag=append status=noxfer ||
806 error "could not append to test file"
807 check_hsm_flags $f.append "0x00000003"
809 # Modify a file sets it dirty
810 cp -p /etc/passwd $f.modify || error "could not create file"
811 $LFS hsm_set --exists $f.modify ||
812 error "user could not change hsm flags"
813 dd if=/dev/zero of=$f.modify bs=1 count=3\
814 conv=notrunc status=noxfer ||
815 error "could not modify test file"
816 check_hsm_flags $f.modify "0x00000003"
818 # Open O_TRUNC sets dirty
819 cp -p /etc/passwd $f.trunc || error "could not create file"
820 $LFS hsm_set --exists $f.trunc ||
821 error "user could not change hsm flags"
822 cp /etc/group $f.trunc || error "could not override a file"
823 check_hsm_flags $f.trunc "0x00000003"
825 # Mmapped a file sets dirty
826 cp -p /etc/passwd $f.mmap || error "could not create file"
827 $LFS hsm_set --exists $f.mmap ||
828 error "user could not change hsm flags"
829 multiop $f.mmap OSMWUc || error "could not mmap a file"
830 check_hsm_flags $f.mmap "0x00000003"
832 run_test 3 "Check file dirtyness when opening for write"
836 local f=$DIR/$tdir/$tfile
837 local fid=$(make_small $f)
840 local st=$(get_request_state $fid CANCEL)
841 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
843 run_test 4 "Useless cancel must not be registered"
846 # test needs a running copytool
850 local f=$DIR/$tdir/$tfile
851 local fid=$(copy_file /etc/passwd $f)
853 wait_request_state $fid ARCHIVE SUCCEED
855 check_hsm_flags $f "0x00000009"
859 run_test 8 "Test default archive number"
863 local f=$DIR/$tdir/$tfile
864 local fid=$(copy_file /etc/passwd $f)
865 # we do not use the default one to be sure
866 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
868 copytool_setup $SINGLEAGT $MOUNT $new_an
869 $LFS hsm_archive --archive $new_an $f
870 wait_request_state $fid ARCHIVE SUCCEED
872 check_hsm_flags $f "0x00000009"
876 run_test 9 "Use of explict archive number, with dedicated copytool"
879 needclients 3 || return 0
885 copytool_cleanup $(comma_list $(agts_nodes))
887 # start all of the copytools
888 for n in $(seq $AGTCOUNT); do
892 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
895 for n in $(seq $AGTCOUNT); do
896 file=$DIR/$tdir/$tfile.$n
897 fid=$(make_small $file)
899 $LFS hsm_archive $file || error "could not archive file $file"
900 wait_request_state $fid ARCHIVE SUCCEED
901 check_hsm_flags $file "0x00000009"
905 copytool_cleanup $(comma_list $(agts_nodes))
907 run_test 9a "Multiple remote agents"
910 # test needs a running copytool
913 mkdir -p $DIR/$tdir/d1
914 local f=$DIR/$tdir/$tfile
915 local fid=$(copy_file /etc/hosts $f)
916 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
917 error "hsm_archive failed"
918 wait_request_state $fid ARCHIVE SUCCEED
920 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
921 error "fid $fid not in archive $HSM_ARCHIVE"
922 echo "Verifying content"
923 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
924 echo "Verifying hsm state "
925 check_hsm_flags $f "0x00000009"
927 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
928 local st=$(get_hsm_archive_id $f)
929 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
930 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
935 run_test 10a "Archive a file"
938 # test needs a running copytool
942 local f=$DIR/$tdir/$tfile
943 local fid=$(copy_file /etc/hosts $f)
944 $LFS hsm_archive $f || error "archive request failed"
945 wait_request_state $fid ARCHIVE SUCCEED
947 $LFS hsm_archive $f || error "archive of non dirty file failed"
948 local cnt=$(get_request_count $fid ARCHIVE)
949 [[ "$cnt" == "1" ]] ||
950 error "archive of non dirty file must not make a request"
954 run_test 10b "Archive of non dirty file must work without doing request"
957 # test needs a running copytool
961 local f=$DIR/$tdir/$tfile
962 local fid=$(copy_file /etc/hosts $f)
963 $LFS hsm_set --noarchive $f
964 $LFS hsm_archive $f && error "archive a noarchive file must fail"
968 run_test 10c "Check forbidden archive"
971 # test needs a running copytool
975 local f=$DIR/$tdir/$tfile
976 local fid=$(copy_file /etc/hosts $f)
977 $LFS hsm_archive $f || error "cannot archive $f"
978 wait_request_state $fid ARCHIVE SUCCEED
980 local ar=$(get_hsm_archive_id $f)
981 local dflt=$(get_hsm_param default_archive_id)
982 [[ $ar == $dflt ]] ||
983 error "archived file is not on default archive: $ar != $dflt"
987 run_test 10d "Archive a file on the default archive id"
991 copy2archive /etc/hosts $tdir/$tfile
992 local f=$DIR/$tdir/$tfile
994 import_file $tdir/$tfile $f
995 echo -n "Verifying released state: "
996 check_hsm_flags $f "0x0000000d"
998 local LSZ=$(stat -c "%s" $f)
999 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1001 echo "Verifying imported size $LSZ=$ASZ"
1002 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1003 echo -n "Verifying released pattern: "
1004 local PTRN=$($GETSTRIPE -L $f)
1006 [[ $PTRN == 80000001 ]] || error "Is not released"
1007 local fid=$(path2fid $f)
1008 echo "Verifying new fid $fid in archive"
1010 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1011 error "fid $fid not in archive $HSM_ARCHIVE"
1013 run_test 11a "Import a file"
1016 # test needs a running copytool
1020 local f=$DIR/$tdir/$tfile
1021 local fid=$(copy_file /etc/hosts $f)
1022 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1023 error "hsm_archive failed"
1024 wait_request_state $fid ARCHIVE SUCCEED
1026 local FILE_HASH=$(md5sum $f)
1031 echo "$FILE_HASH" | md5sum -c
1033 [[ $? -eq 0 ]] || error "Restored file differs"
1037 run_test 11b "Import a deleted file using its FID"
1040 # test needs a running copytool
1044 copy2archive /etc/hosts $tdir/$tfile
1046 local f=$DIR/$tdir/$tfile
1047 import_file $tdir/$tfile $f
1048 local f2=$DIR2/$tdir/$tfile
1049 echo "Verifying released state: "
1050 check_hsm_flags $f2 "0x0000000d"
1052 local fid=$(path2fid $f2)
1053 $LFS hsm_restore $f2
1054 wait_request_state $fid RESTORE SUCCEED
1056 echo "Verifying file state: "
1057 check_hsm_flags $f2 "0x00000009"
1059 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1061 [[ $? -eq 0 ]] || error "Restored file differs"
1065 run_test 12a "Restore an imported file explicitly"
1068 # test needs a running copytool
1072 copy2archive /etc/hosts $tdir/$tfile
1074 local f=$DIR/$tdir/$tfile
1075 import_file $tdir/$tfile $f
1076 echo "Verifying released state: "
1077 check_hsm_flags $f "0x0000000d"
1079 cat $f > /dev/null || error "File read failed"
1081 echo "Verifying file state after restore: "
1082 check_hsm_flags $f "0x00000009"
1084 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1086 [[ $? -eq 0 ]] || error "Restored file differs"
1090 run_test 12b "Restore an imported file implicitly"
1093 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1095 # test needs a running copytool
1099 local f=$DIR/$tdir/$tfile
1100 $LFS setstripe -c 2 $f
1101 local fid=$(make_large_for_striping $f)
1102 local FILE_CRC=$(md5sum $f)
1104 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1105 wait_request_state $fid ARCHIVE SUCCEED
1106 $LFS hsm_release $f || error "release $f failed"
1108 echo "$FILE_CRC" | md5sum -c
1110 [[ $? -eq 0 ]] || error "Restored file differs"
1114 run_test 12c "Restore a file with stripe of 2"
1117 # test needs a running copytool
1122 local f=$DIR/$tdir/$tfile
1123 local fid=$(copy_file /etc/hosts $f)
1124 $LFS hsm_restore $f || error "restore of non archived file failed"
1125 local cnt=$(get_request_count $fid RESTORE)
1126 [[ "$cnt" == "0" ]] ||
1127 error "restore non archived must not make a request"
1128 $LFS hsm_archive $f ||
1129 error "archive request failed"
1130 wait_request_state $fid ARCHIVE SUCCEED
1131 $LFS hsm_restore $f ||
1132 error "restore of non released file failed"
1133 local cnt=$(get_request_count $fid RESTORE)
1134 [[ "$cnt" == "0" ]] ||
1135 error "restore a non dirty file must not make a request"
1139 run_test 12d "Restore of a non archived, non released file must work"\
1140 " without doing request"
1143 # test needs a running copytool
1146 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1147 local f=$DIR/$tdir/$tfile
1148 local fid=$(copy_file /etc/hosts $f)
1149 $LFS hsm_archive $f || error "archive request failed"
1150 wait_request_state $fid ARCHIVE SUCCEED
1153 cat /etc/hosts >> $f
1157 $LFS hsm_restore $f && error "restore a dirty file must fail"
1161 run_test 12e "Check forbidden restore"
1164 # test needs a running copytool
1168 local f=$DIR/$tdir/$tfile
1169 local fid=$(copy_file /etc/hosts $f)
1171 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1172 wait_request_state $fid ARCHIVE SUCCEED
1173 $LFS hsm_release $f || error "release of $f failed"
1175 wait_request_state $fid RESTORE SUCCEED
1177 echo -n "Verifying file state: "
1178 check_hsm_flags $f "0x00000009"
1180 diff -q /etc/hosts $f
1182 [[ $? -eq 0 ]] || error "Restored file differs"
1186 run_test 12f "Restore a released file explicitly"
1189 # test needs a running copytool
1193 local f=$DIR/$tdir/$tfile
1194 local fid=$(copy_file /etc/hosts $f)
1196 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1197 wait_request_state $fid ARCHIVE SUCCEED
1198 $LFS hsm_release $f || error "release of $f failed"
1200 diff -q /etc/hosts $f
1203 # we check we had a restore done
1204 wait_request_state $fid RESTORE SUCCEED
1206 [[ $st -eq 0 ]] || error "Restored file differs"
1210 run_test 12g "Restore a released file implicitly"
1213 needclients 2 || return 0
1215 # test needs a running copytool
1219 local f=$DIR/$tdir/$tfile
1220 local fid=$(copy_file /etc/hosts $f)
1222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1223 wait_request_state $fid ARCHIVE SUCCEED
1224 $LFS hsm_release $f || error "release of $f failed"
1226 do_node $CLIENT2 diff -q /etc/hosts $f
1229 # we check we had a restore done
1230 wait_request_state $fid RESTORE SUCCEED
1232 [[ $st -eq 0 ]] || error "Restored file differs"
1236 run_test 12h "Restore a released file implicitly from a second node"
1239 # test needs a running copytool
1243 local f=$DIR/$tdir/$tfile
1244 local fid=$(copy_file /etc/passwd $f)
1245 $LFS hsm_archive $f || error "archive of $f failed"
1246 wait_request_state $fid ARCHIVE SUCCEED
1248 $LFS hsm_release $f || error "release of $f failed"
1252 [[ $? -eq 0 ]] || error "Restored file differs"
1256 run_test 12m "Archive/release/implicit restore"
1259 # test needs a running copytool
1263 copy2archive /etc/hosts $tdir/$tfile
1265 local f=$DIR/$tdir/$tfile
1266 import_file $tdir/$tfile $f
1268 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1269 error "Restored file differs"
1271 $LFS hsm_release $f || error "release of $f failed"
1275 run_test 12n "Import/implicit restore/release"
1278 # test needs a running copytool
1282 local f=$DIR/$tdir/$tfile
1283 local fid=$(copy_file /etc/hosts $f)
1285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1286 wait_request_state $fid ARCHIVE SUCCEED
1287 $LFS hsm_release $f || error "release of $f failed"
1289 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1290 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1292 # set no retry action mode
1295 diff -q /etc/hosts $f
1298 # we check we had a restore failure
1299 wait_request_state $fid RESTORE FAILED
1301 [[ $st -eq 0 ]] && error "Restore must fail"
1303 # remove no retry action mode
1306 # check file is still released
1307 check_hsm_flags $f "0x0000000d"
1309 # retry w/o failure injection
1310 do_facet $SINGLEMDS lctl set_param fail_loc=0
1312 # to be sure previous RESTORE result is gone
1314 wait_for_grace_delay
1316 diff -q /etc/hosts $f
1319 # we check we had a restore done
1320 wait_request_state $fid RESTORE SUCCEED
1322 [[ $st -eq 0 ]] || error "Restored file differs"
1326 run_test 12o "Layout-swap failure during Restore leaves file released"
1329 # test needs a running copytool
1332 local ARC_SUBDIR="import.orig"
1336 # populate directory to be imported
1337 for d in $(seq 1 10); do
1338 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1339 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1340 for f in $(seq 1 10); do
1341 CURR_FILE="$CURR_DIR/$tfile.$f"
1342 # write file-specific data
1343 do_facet $SINGLEAGT \
1344 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1345 "file=$CURR_FILE > $CURR_FILE"
1349 import_file "$ARC_SUBDIR" $DIR/$tdir
1350 # diff lustre content and origin (triggers file restoration)
1351 # there must be 10x10 identical files, and no difference
1352 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1353 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1354 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1355 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1357 [ $cnt_diff -eq 0 ] ||
1358 error "$cnt_diff imported files differ from read data"
1359 [ $cnt_ok -eq 100 ] ||
1360 error "not enough identical files ($cnt_ok != 100)"
1364 run_test 13 "Recursively import and restore a directory"
1367 # test needs a running copytool
1372 local f=$DIR/$tdir/$tfile
1373 local fid=$(make_small $f)
1374 local sum=$(md5sum $f | awk '{print $1}')
1375 $LFS hsm_archive $f || error "could not archive file"
1376 wait_request_state $fid ARCHIVE SUCCEED
1380 # create released file (simulate llapi_hsm_import call)
1382 local fid2=$(path2fid $f)
1383 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1384 $LFS hsm_release $f || error "could not release file"
1386 # rebind the archive to the newly created file
1387 echo "rebind $fid to $fid2"
1389 do_facet $SINGLEAGT \
1390 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1391 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1393 # restore file and compare md5sum
1394 local sum2=$(md5sum $f | awk '{print $1}')
1396 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1400 run_test 14 "Rebind archived file to a new fid"
1403 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1410 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1414 for i in $(seq 1 $count); do
1415 fids[$i]=$(make_small $f.$i)
1416 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1417 $LFS hsm_archive $f.$i || error "could not archive file"
1419 wait_all_done $(($count*60))
1423 for i in $(seq 1 $count); do
1426 local fid2=$(path2fid $f.$i)
1427 # add the rebind operation to the list
1428 echo ${fids[$i]} $fid2 >> $tmpfile
1430 # set it released (simulate llapi_hsm_import call)
1431 $LFS hsm_set --archived --exists $f.$i ||
1432 error "could not force hsm flags"
1433 $LFS hsm_release $f.$i || error "could not release file"
1435 nl=$(wc -l < $tmpfile)
1436 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1438 echo "rebind list of files"
1439 do_facet $SINGLEAGT \
1440 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1441 --rebind $tmpfile $DIR" || error "could not rebind file list"
1443 # restore files and compare md5sum
1444 for i in $(seq 1 $count); do
1445 local sum2=$(md5sum $f.$i | awk '{print $1}')
1446 [[ $sum2 == ${sums[$i]} ]] ||
1447 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1453 run_test 15 "Rebind a list of files"
1456 # test needs a running copytool
1460 # create a known size file so we can verify transfer speed
1463 dd if=/dev/zero of=$ref bs=1M count=20
1466 local f=$DIR/$tdir/$tfile
1467 local fid=$(copy_file $ref $f)
1469 local start=$(date +%s)
1471 wait_request_state $fid ARCHIVE SUCCEED
1472 local end=$(date +%s)
1473 local duration=$((end - start))
1475 [[ $duration -ge $goal ]] ||
1476 error "Transfer is too fast $duration < $goal"
1480 run_test 16 "Test CT bandwith control option"
1485 local f=$DIR/$tdir/$tfile
1486 touch $f || error "touch $f failed"
1488 # Could not release a non-archived file
1489 $LFS hsm_release $f && error "release should not succeed"
1491 # For following tests, we must test them with HS_ARCHIVED set
1492 $LFS hsm_set --exists --archived $f || error "could not add flag"
1494 # Could not release a file if no-release is set
1495 $LFS hsm_set --norelease $f || error "could not add flag"
1496 $LFS hsm_release $f && error "release should not succeed"
1497 $LFS hsm_clear --norelease $f || error "could not remove flag"
1499 # Could not release a file if lost
1500 $LFS hsm_set --lost $f || error "could not add flag"
1501 $LFS hsm_release $f && error "release should not succeed"
1502 $LFS hsm_clear --lost $f || error "could not remove flag"
1504 # Could not release a file if dirty
1505 $LFS hsm_set --dirty $f || error "could not add flag"
1506 $LFS hsm_release $f && error "release should not succeed"
1507 $LFS hsm_clear --dirty $f || error "could not remove flag"
1509 run_test 20 "Release is not permitted"
1512 # test needs a running copytool
1516 local f=$DIR/$tdir/test_release
1518 # Create a file and check its states
1519 local fid=$(make_small $f)
1520 check_hsm_flags $f "0x00000000"
1522 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1523 # used until file is flushed to disk
1524 if [ $(facet_fstype ost1) == "zfs" ]; then
1525 # this causes an OST_SYNC rpc to be sent
1526 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1527 # clear locks to reread file data
1528 cancel_lru_locks osc
1531 local orig_size=$(stat -c "%s" $f)
1532 local orig_blocks=$(stat -c "%b" $f)
1534 start_full_debug_logging
1536 $LFS hsm_archive $f || error "could not archive file"
1537 wait_request_state $fid ARCHIVE SUCCEED
1539 local blocks=$(stat -c "%b" $f)
1540 [ $blocks -eq $orig_blocks ] ||
1541 error "$f: wrong block number after archive: " \
1542 "$blocks != $orig_blocks"
1543 local size=$(stat -c "%s" $f)
1544 [ $size -eq $orig_size ] ||
1545 error "$f: wrong size after archive: $size != $orig_size"
1547 # Release and check states
1548 $LFS hsm_release $f || error "could not release file"
1549 check_hsm_flags $f "0x0000000d"
1551 blocks=$(stat -c "%b" $f)
1552 [ $blocks -gt 5 ] &&
1553 error "$f: too many blocks after release: $blocks > 5"
1554 size=$(stat -c "%s" $f)
1555 [ $size -ne $orig_size ] &&
1556 error "$f: wrong size after release: $size != $orig_size"
1558 # Check we can release an file without stripe info
1562 check_hsm_flags $f "0x00000000"
1563 $LFS hsm_archive $f || error "could not archive file"
1564 wait_request_state $fid ARCHIVE SUCCEED
1566 # Release and check states
1567 $LFS hsm_release $f || error "could not release file"
1568 check_hsm_flags $f "0x0000000d"
1570 # Release again a file that is already released is OK
1571 $LFS hsm_release $f || fail "second release should succeed"
1572 check_hsm_flags $f "0x0000000d"
1574 stop_full_debug_logging
1578 run_test 21 "Simple release tests"
1581 # test needs a running copytool
1586 local f=$DIR/$tdir/test_release
1587 local swap=$DIR/$tdir/test_swap
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 # Release and check states
1597 $LFS hsm_release $f || error "could not release file"
1598 check_hsm_flags $f "0x0000000d"
1601 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1606 run_test 22 "Could not swap a release file"
1609 # test needs a running copytool
1614 local f=$DIR/$tdir/test_mtime
1616 # Create a file and check its states
1617 local fid=$(make_small $f)
1618 check_hsm_flags $f "0x00000000"
1620 $LFS hsm_archive $f || error "could not archive file"
1621 wait_request_state $fid ARCHIVE SUCCEED
1623 # Set modification time in the past
1624 touch -m -a -d @978261179 $f
1626 # Release and check states
1627 $LFS hsm_release $f || error "could not release file"
1628 check_hsm_flags $f "0x0000000d"
1630 local MTIME=$(stat -c "%Y" $f)
1631 local ATIME=$(stat -c "%X" $f)
1632 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1633 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1637 run_test 23 "Release does not change a/mtime (utime)"
1640 local file=$DIR/$tdir/$tfile
1649 # test needs a running copytool
1654 fid=$(make_small $file)
1656 # Create a file and check its states
1657 check_hsm_flags $file "0x00000000"
1659 # Ensure atime is less than mtime and ctime.
1663 atime0=$(stat -c "%X" $file)
1664 mtime0=$(stat -c "%Y" $file)
1665 ctime0=$(stat -c "%Z" $file)
1667 [ $atime0 -lt $mtime0 ] ||
1668 error "atime $atime0 is not less than mtime $mtime0"
1670 [ $atime0 -lt $ctime0 ] ||
1671 error "atime $atime0 is not less than ctime $ctime0"
1673 # Archive should not change any timestamps.
1674 $LFS hsm_archive $file || error "cannot archive '$file'"
1675 wait_request_state $fid ARCHIVE SUCCEED
1677 atime1=$(stat -c "%X" $file)
1678 mtime1=$(stat -c "%Y" $file)
1679 ctime1=$(stat -c "%Z" $file)
1681 [ $atime0 -eq $atime1 ] ||
1682 error "archive changed atime from $atime0 to $atime1"
1684 [ $mtime0 -eq $mtime1 ] ||
1685 error "archive changed mtime from $mtime0 to $mtime1"
1687 [ $ctime0 -eq $ctime1 ] ||
1688 error "archive changed ctime from $ctime0 to $ctime1"
1690 # Release should not change any timestamps.
1691 $LFS hsm_release $file || error "cannot release '$file'"
1692 check_hsm_flags $file "0x0000000d"
1694 atime1=$(stat -c "%X" $file)
1695 mtime1=$(stat -c "%Y" $file)
1696 ctime1=$(stat -c "%Z" $file)
1698 [ $atime0 -eq $atime1 ] ||
1699 error "release changed atime from $atime0 to $atime1"
1701 [ $mtime0 -eq $mtime1 ] ||
1702 error "release changed mtime from $mtime0 to $mtime1"
1704 [ $ctime0 -eq $ctime1 ] ||
1705 error "release changed ctime from $ctime0 to $ctime1"
1707 # Restore should not change atime or mtime and should not
1709 $LFS hsm_restore $file
1710 wait_request_state $fid RESTORE SUCCEED
1712 atime1=$(stat -c "%X" $file)
1713 mtime1=$(stat -c "%Y" $file)
1714 ctime1=$(stat -c "%Z" $file)
1716 [ $atime0 -eq $atime1 ] ||
1717 error "restore changed atime from $atime0 to $atime1"
1719 [ $mtime0 -eq $mtime1 ] ||
1720 error "restore changed mtime from $mtime0 to $mtime1"
1722 [ $ctime0 -le $ctime1 ] ||
1723 error "restore changed ctime from $ctime0 to $ctime1"
1727 # Once more, after unmount and mount.
1728 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1729 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1731 atime1=$(stat -c "%X" $file)
1732 mtime1=$(stat -c "%Y" $file)
1733 ctime1=$(stat -c "%Z" $file)
1735 [ $atime0 -eq $atime1 ] ||
1736 error "remount changed atime from $atime0 to $atime1"
1738 [ $mtime0 -eq $mtime1 ] ||
1739 error "remount changed mtime from $mtime0 to $mtime1"
1741 [ $ctime0 -le $ctime1 ] ||
1742 error "remount changed ctime from $ctime0 to $ctime1"
1744 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1747 local file=$DIR/$tdir/$tfile
1753 # Test needs a running copytool.
1757 # Check that root can do HSM actions on a ordinary user's file.
1759 fid=$(make_small $file)
1760 sum0=$(md5sum $file)
1762 chown $RUNAS_ID:$RUNAS_GID $file ||
1763 error "cannot chown '$file' to '$RUNAS_ID'"
1765 chmod ugo-w $DIR/$tdir ||
1766 error "cannot chmod '$DIR/$tdir'"
1768 $LFS hsm_archive $file
1769 wait_request_state $fid ARCHIVE SUCCEED
1771 $LFS hsm_release $file
1772 check_hsm_flags $file "0x0000000d"
1774 $LFS hsm_restore $file
1775 wait_request_state $fid RESTORE SUCCEED
1777 # Check that ordinary user can get HSM state.
1778 $RUNAS $LFS hsm_state $file ||
1779 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1781 $LFS hsm_release $file
1782 check_hsm_flags $file "0x0000000d"
1784 # Check that ordinary user can accessed released file.
1785 sum1=$($RUNAS md5sum $file) ||
1786 error "user '$RUNAS_ID' cannot read '$file'"
1788 [ "$sum0" == "$sum1" ] ||
1789 error "md5sum mismatch for '$file'"
1793 run_test 24b "root can archive, release, and restore user files"
1795 cleanup_test_24c() {
1797 set_hsm_param user_request_mask RESTORE
1798 set_hsm_param group_request_mask RESTORE
1799 set_hsm_param other_request_mask RESTORE
1803 local file=$DIR/$tdir/$tfile
1804 local action=archive
1809 # test needs a running copytool
1814 # Save the default masks and check that cleanup_24c will
1815 # restore the request masks correctly.
1816 user_save=$(get_hsm_param user_request_mask)
1817 group_save=$(get_hsm_param group_request_mask)
1818 other_save=$(get_hsm_param other_request_mask)
1820 [ "$user_save" == RESTORE ] ||
1821 error "user_request_mask is '$user_save' expected 'RESTORE'"
1822 [ "$group_save" == RESTORE ] ||
1823 error "group_request_mask is '$group_save' expected 'RESTORE'"
1824 [ "$other_save" == RESTORE ] ||
1825 error "other_request_mask is '$other_save' expected 'RESTORE'"
1827 trap cleanup_test_24c EXIT
1832 chown $RUNAS_ID:nobody $file ||
1833 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1835 set_hsm_param user_request_mask ""
1836 $RUNAS $LFS hsm_$action $file &&
1837 error "$action by user should fail"
1839 set_hsm_param user_request_mask $action
1840 $RUNAS $LFS hsm_$action $file ||
1841 error "$action by user should succeed"
1846 chown nobody:$RUNAS_GID $file ||
1847 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1849 set_hsm_param group_request_mask ""
1850 $RUNAS $LFS hsm_$action $file &&
1851 error "$action by group should fail"
1853 set_hsm_param group_request_mask $action
1854 $RUNAS $LFS hsm_$action $file ||
1855 error "$action by group should succeed"
1860 chown nobody:nobody $file ||
1861 error "cannot chown '$file' to 'nobody:nobody'"
1863 set_hsm_param other_request_mask ""
1864 $RUNAS $LFS hsm_$action $file &&
1865 error "$action by other should fail"
1867 set_hsm_param other_request_mask $action
1868 $RUNAS $LFS hsm_$action $file ||
1869 error "$action by other should succeed"
1874 run_test 24c "check that user,group,other request masks work"
1876 cleanup_test_24d() {
1878 mount -o remount,rw $MOUNT2
1882 local file1=$DIR/$tdir/$tfile
1883 local file2=$DIR2/$tdir/$tfile
1891 fid1=$(make_small $file1)
1893 trap cleanup_test_24d EXIT
1895 mount -o remount,ro $MOUNT2
1897 fid2=$(path2fid $file2)
1898 [ "$fid1" == "$fid2" ] ||
1899 error "FID mismatch '$fid1' != '$fid2'"
1901 $LFS hsm_archive $file2 &&
1902 error "archive should fail on read-only mount"
1903 check_hsm_flags $file1 "0x00000000"
1905 $LFS hsm_archive $file1
1906 wait_request_state $fid1 ARCHIVE SUCCEED
1908 $LFS hsm_release $file1
1909 $LFS hsm_restore $file2
1910 wait_request_state $fid1 RESTORE SUCCEED
1912 $LFS hsm_release $file1 || error "cannot release '$file1'"
1913 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1915 $LFS hsm_release $file2 &&
1916 error "release should fail on read-only mount"
1921 run_test 24d "check that read-only mounts are respected"
1924 # test needs a running copytool
1928 copy2archive /etc/hosts $tdir/$tfile
1930 local f=$DIR/$tdir/$tfile
1932 import_file $tdir/$tfile $f
1934 $LFS hsm_set --lost $f
1939 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1943 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1944 " (Operation not permitted)"
1947 # test needs a running copytool
1952 local f=$DIR/$tdir/$tfile
1953 local fid=$(copy_file /etc/passwd $f)
1955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1956 wait_request_state $fid ARCHIVE SUCCEED
1959 $LFS hsm_set --lost $f
1963 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1967 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1968 " (Operation not permitted)"
1971 # test needs a running copytool
1975 local f=$DIR/$tdir/$tfile
1976 local fid=$(make_large_for_progress $f)
1977 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1978 wait_request_state $fid ARCHIVE SUCCEED
1981 wait_request_state $fid REMOVE SUCCEED
1983 check_hsm_flags $f "0x00000000"
1987 run_test 26 "Remove the archive of a valid file"
1990 # test needs a running copytool
1994 make_archive $tdir/$tfile
1995 local f=$DIR/$tdir/$tfile
1996 import_file $tdir/$tfile $f
1997 local fid=$(path2fid $f)
2001 [[ $? != 0 ]] || error "Remove of a released file should fail"
2005 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2008 # test needs a running copytool
2012 local f=$DIR/$tdir/$tfile
2013 local fid=$(make_large_for_progress $f)
2014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2015 wait_request_state $fid ARCHIVE SUCCEED
2020 [[ $? != 0 ]] || error "Remove of a released file should fail"
2024 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2027 # test needs a running copytool
2031 local f=$DIR/$tdir/$tfile
2032 local fid=$(make_large_for_progress $f)
2033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2034 wait_request_state $fid ARCHIVE SUCCEED
2043 wait_request_state $fid REMOVE SUCCEED
2047 run_test 28 "Concurrent archive/file remove"
2050 # restore at exec cannot work on agent node (because of Linux kernel
2051 # protection of executables)
2052 needclients 2 || return 0
2054 # test needs a running copytool
2058 copy2archive /bin/true $tdir/$tfile
2060 local f=$DIR/$tdir/true
2061 import_file $tdir/$tfile $f
2063 local fid=$(path2fid $f)
2065 # set no retry action mode
2071 # remove no try action mode
2075 [[ $st == 0 ]] || error "Failed to exec a released file"
2079 run_test 30a "Restore at exec (import case)"
2082 # restore at exec cannot work on agent node (because of Linux kernel
2083 # protection of executables)
2084 needclients 2 || return 0
2086 # test needs a running copytool
2090 local f=$DIR/$tdir/true
2091 local fid=$(copy_file /bin/true $f)
2093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2094 wait_request_state $fid ARCHIVE SUCCEED
2097 # set no retry action mode
2103 # remove no try action mode
2107 [[ $st == 0 ]] || error "Failed to exec a released file"
2111 run_test 30b "Restore at exec (release case)"
2114 needclients 2 || return 0
2116 # test needs a running copytool
2120 local f=$DIR/$tdir/SLEEP
2121 local fid=$(copy_file /bin/sleep $f)
2123 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2124 wait_request_state $fid ARCHIVE SUCCEED
2126 check_hsm_flags $f "0x0000000d"
2127 # set no retry action mode
2129 do_node $CLIENT2 "$f 10" &
2133 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2135 [[ $? == 0 ]] || error "Execution failed during run"
2137 [[ $? == 0 ]] || error "Binary overwritten during exec"
2140 # remove no try action mode
2142 check_hsm_flags $f "0x00000009"
2146 run_test 30c "Update during exec of released file must fail"
2148 restore_and_check_size() {
2151 local s=$(stat -c "%s" $f)
2153 local st=$(get_hsm_flags $f)
2157 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2159 n=$(stat -c "%s" $f)
2160 # we echo in both cases to show stat is not
2162 if [[ $n != $s ]]; then
2163 echo "size seen is $n != $s"
2166 echo "size seen is right: $n == $s"
2168 st=$(get_hsm_flags $f)
2172 if [[ $cpt -lt 10 ]]; then
2175 echo " restore is too long"
2176 wait_request_state $fid RESTORE SUCCEED
2182 # test needs a running copytool
2187 make_archive $tdir/$tfile
2188 local f=$DIR/$tdir/$tfile
2189 import_file $tdir/$tfile $f
2190 local fid=$($LFS path2fid $f)
2191 HSM_ARCHIVE_PURGE=false copytool_setup
2193 restore_and_check_size $f $fid
2196 [[ $err -eq 0 ]] || error "File size changed during restore"
2200 run_test 31a "Import a large file and check size during restore"
2204 # test needs a running copytool
2209 local f=$DIR/$tdir/$tfile
2210 local fid=$(make_large_for_progress $f)
2211 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2212 wait_request_state $fid ARCHIVE SUCCEED
2215 restore_and_check_size $f $fid
2218 [[ $err -eq 0 ]] || error "File size changed during restore"
2222 run_test 31b "Restore a large unaligned file and check size during restore"
2225 # test needs a running copytool
2230 local f=$DIR/$tdir/$tfile
2231 local fid=$(make_large_for_progress_aligned $f)
2232 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2233 wait_request_state $fid ARCHIVE SUCCEED
2236 restore_and_check_size $f $fid
2239 [[ $err -eq 0 ]] || error "File size changed during restore"
2243 run_test 31c "Restore a large aligned file and check size during restore"
2246 # test needs a running copytool
2251 local f=$DIR/$tdir/$tfile
2252 local fid=$(make_large_for_progress $f)
2253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2254 wait_request_state $fid ARCHIVE SUCCEED
2257 # to be sure wait_all_done will not be mislead by previous tests
2260 wait_for_grace_delay
2261 # Also raise grace_delay significantly so the Canceled
2262 # Restore action will stay enough long avail.
2263 local old_grace=$(get_hsm_param grace_delay)
2264 set_hsm_param grace_delay 100
2266 md5sum $f >/dev/null &
2268 wait_request_state $fid RESTORE STARTED
2273 # Check restore trigger process was killed
2274 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2278 # instead of waiting+checking both Restore and Cancel ops
2279 # sequentially, wait for both to be finished and then check
2281 wait_all_done 100 $fid
2282 local rstate=$(get_request_state $fid RESTORE)
2283 local cstate=$(get_request_state $fid CANCEL)
2285 # restore orig grace_delay.
2286 set_hsm_param grace_delay $old_grace
2288 if [[ "$rstate" == "CANCELED" ]] ; then
2289 [[ "$cstate" == "SUCCEED" ]] ||
2290 error "Restore state is CANCELED and Cancel state " \
2291 "is not SUCCEED but $cstate"
2292 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2293 elif [[ "$rstate" == "SUCCEED" ]] ; then
2294 [[ "$cstate" == "FAILED" ]] ||
2295 error "Restore state is SUCCEED and Cancel state " \
2296 "is not FAILED but $cstate"
2297 echo "Restore state is SUCCEED, Cancel state is FAILED"
2299 error "Restore state is $rstate and Cancel state is $cstate"
2303 error "Cannot kill process waiting for restore ($killed)"
2307 run_test 33 "Kill a restore waiting process"
2310 # test needs a running copytool
2315 local f=$DIR/$tdir/$tfile
2316 local fid=$(make_large_for_progress $f)
2317 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2318 wait_request_state $fid ARCHIVE SUCCEED
2321 md5sum $f >/dev/null &
2323 wait_request_state $fid RESTORE STARTED
2325 rm $f || error "rm $f failed"
2326 # rm must not block during restore
2327 wait_request_state $fid RESTORE STARTED
2329 wait_request_state $fid RESTORE SUCCEED
2330 # check md5sum pgm finished
2331 local there=$(ps -o pid,comm hp $pid >/dev/null)
2332 [[ -z $there ]] || error "Restore initiator does not exit"
2334 local rc=$(wait $pid)
2335 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2339 run_test 34 "Remove file during restore"
2342 # test needs a running copytool
2347 local f=$DIR/$tdir/$tfile
2348 local f1=$DIR/$tdir/$tfile-1
2349 local fid=$(make_large_for_progress $f)
2350 local fid1=$(copy_file /etc/passwd $f1)
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2352 wait_request_state $fid ARCHIVE SUCCEED
2355 md5sum $f >/dev/null &
2357 wait_request_state $fid RESTORE STARTED
2359 mv $f1 $f || error "mv $f1 $f failed"
2360 # mv must not block during restore
2361 wait_request_state $fid RESTORE STARTED
2363 wait_request_state $fid RESTORE SUCCEED
2364 # check md5sum pgm finished
2365 local there=$(ps -o pid,comm hp $pid >/dev/null)
2366 [[ -z $there ]] || error "Restore initiator does not exit"
2368 local rc=$(wait $pid)
2369 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2372 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2376 run_test 35 "Overwrite file during restore"
2379 # test needs a running copytool
2384 local f=$DIR/$tdir/$tfile
2385 local fid=$(make_large_for_progress $f)
2386 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2387 wait_request_state $fid ARCHIVE SUCCEED
2390 md5sum $f >/dev/null &
2392 wait_request_state $fid RESTORE STARTED
2395 # rm must not block during restore
2396 wait_request_state $fid RESTORE STARTED
2398 wait_request_state $fid RESTORE SUCCEED
2399 # check md5sum pgm finished
2400 local there=$(ps -o pid,comm hp $pid >/dev/null)
2402 error "Restore initiator does not exit"
2404 local rc=$(wait $pid)
2406 error "Restore initiator failed with $rc"
2410 run_test 36 "Move file during restore"
2417 for n in $(seq 1 $count); do
2418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2420 echo "$count archive requests submitted"
2424 local stream_count=4
2425 local file_count=100
2427 local f=$DIR/$tdir/$tfile
2432 for i in $(seq 1 $file_count); do
2433 for p in $(seq 1 $stream_count); do
2434 fid=$(copy_file /etc/hosts $f.$p.$i)
2437 # force copytool to use a local/temp archive dir to ensure best
2438 # performance vs remote/NFS mounts used in auto-tests
2439 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2442 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2444 # to be sure wait_all_done will not be mislead by previous tests
2446 wait_for_grace_delay
2448 # start archive streams in background (archive files in parallel)
2449 for p in $(seq 1 $stream_count); do
2450 multi_archive $f.$p $file_count &
2453 echo -n "Wait for all requests being enqueued..."
2459 run_test 40 "Parallel archive requests"
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 $f || error "could not archive file"
2470 wait_request_state $fid ARCHIVE SUCCEED
2471 check_hsm_flags $f "0x00000009"
2473 multiop_bg_pause $f O_c || error "multiop failed"
2477 client_up || client_up || true
2479 kill -USR1 $MULTIPID
2480 wait $MULTIPID || error "multiop close failed"
2482 check_hsm_flags $f "0x0000000b"
2486 run_test 52 "Opened for write file on an evicted client should be set dirty"
2489 # test needs a running copytool
2493 local f=$DIR/$tdir/$tfile
2494 local fid=$(copy_file /etc/motd $f 1)
2496 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2497 error "could not archive file"
2498 wait_request_state $fid ARCHIVE SUCCEED
2499 check_hsm_flags $f "0x00000009"
2501 multiop_bg_pause $f o_c || error "multiop failed"
2505 client_up || client_up || true
2507 kill -USR1 $MULTIPID
2508 wait $MULTIPID || error "multiop close failed"
2510 check_hsm_flags $f "0x00000009"
2514 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2517 # test needs a running copytool
2521 local f=$DIR/$tdir/$tfile
2522 local fid=$(make_small $f)
2524 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2525 error "could not archive file"
2526 wait_request_state $fid ARCHIVE STARTED
2528 check_hsm_flags $f "0x00000001"
2530 # Avoid coordinator resending this request as soon it has failed.
2535 wait_request_state $fid ARCHIVE FAILED
2537 check_hsm_flags $f "0x00000003"
2542 run_test 54 "Write during an archive cancels it"
2545 # test needs a running copytool
2549 local f=$DIR/$tdir/$tfile
2550 local fid=$(make_small $f)
2552 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2553 error "could not archive file"
2554 wait_request_state $fid ARCHIVE STARTED
2556 check_hsm_flags $f "0x00000001"
2558 # Avoid coordinator resending this request as soon it has failed.
2561 $TRUNCATE $f 1024 || error "truncate failed"
2563 wait_request_state $fid ARCHIVE FAILED
2565 check_hsm_flags $f "0x00000003"
2570 run_test 55 "Truncate during an archive cancels it"
2573 # test needs a running copytool
2577 local f=$DIR/$tdir/$tfile
2578 local fid=$(make_large_for_progress $f)
2580 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2581 error "could not archive file"
2582 wait_request_state $fid ARCHIVE STARTED
2584 check_hsm_flags $f "0x00000001"
2586 # Change metadata and sync to be sure we are not changing only
2591 wait_request_state $fid ARCHIVE SUCCEED
2593 check_hsm_flags $f "0x00000009"
2597 run_test 56 "Setattr during an archive is ok"
2600 # Need one client for I/O, one for request
2601 needclients 2 || return 0
2603 # test needs a running copytool
2607 local f=$DIR/$tdir/test_archive_remote
2608 # Create a file on a remote node
2609 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2610 "count=2 conv=fsync"
2613 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2614 error "hsm_archive failed"
2615 local fid=$(path2fid $f)
2616 wait_request_state $fid ARCHIVE SUCCEED
2618 # Release and implicit restore it
2619 do_node $CLIENT2 "$LFS hsm_release $f" ||
2620 error "hsm_release failed"
2621 do_node $CLIENT2 "md5sum $f" ||
2622 error "hsm_restore failed"
2624 wait_request_state $fid RESTORE SUCCEED
2628 run_test 57 "Archive a file with dirty cache on another node"
2630 truncate_released_file() {
2634 local sz=$(stat -c %s $src_file)
2635 local f=$DIR/$tdir/$tfile
2636 local fid=$(copy_file $1 $f)
2640 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2641 error "could not archive file"
2642 wait_request_state $fid ARCHIVE SUCCEED
2644 $LFS hsm_release $f || error "could not release file"
2646 $TRUNCATE $f $trunc_to || error "truncate failed"
2649 local sz1=$(stat -c %s $f)
2650 [[ $sz1 == $trunc_to ]] ||
2651 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2654 check_hsm_flags $f "0x0000000b"
2656 local state=$(get_request_state $fid RESTORE)
2657 [[ "$state" == "SUCCEED" ]] ||
2658 error "truncate $sz does not trig restore, state = $state"
2660 $TRUNCATE $ref $trunc_to
2661 cmp $ref $f || error "file data wrong after truncate"
2667 # test needs a running copytool
2672 local sz=$(stat -c %s /etc/passwd)
2674 echo "truncate up from $sz to $((sz*2))"
2675 truncate_released_file /etc/passwd $((sz*2))
2677 echo "truncate down from $sz to $((sz/2))"
2678 truncate_released_file /etc/passwd $((sz/2))
2680 echo "truncate to 0"
2681 truncate_released_file /etc/passwd 0
2685 run_test 58 "Truncate a released file will trigger restore"
2688 # This test validates the fix for LU-4512. Ensure that the -u
2689 # option changes the progress reporting interval from the default
2690 # (30 seconds) to the user-specified interval.
2692 local progress_timeout=$((interval * 3))
2694 # test needs a new running copytool
2696 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2699 local f=$DIR/$tdir/$tfile
2700 local fid=$(make_large_for_progress $f)
2702 local start_at=$(date +%s)
2703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2704 error "could not archive file"
2707 local mdt=${MDT_PREFIX}${mdtidx}
2708 local mds=mds$((mdtidx + 1))
2710 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2711 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2717 echo -n "Expecting a progress update within $progress_timeout seconds... "
2719 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2720 if [ $RESULT -gt 0 ]; then
2721 echo "$RESULT bytes copied in $WAIT seconds."
2723 elif [ $WAIT -ge $progress_timeout ]; then
2724 error "Timed out waiting for progress update!"
2727 WAIT=$((WAIT + sleep))
2731 local finish_at=$(date +%s)
2732 local elapsed=$((finish_at - start_at))
2734 # Ensure that the progress update occurred within the expected window.
2735 if [ $elapsed -lt $interval ]; then
2736 error "Expected progress update after at least $interval seconds"
2742 run_test 60 "Changing progress update interval from default"
2745 # test needs a new running copytool
2747 copytool_monitor_setup
2748 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2750 # Just start and stop the copytool to generate events.
2754 local REGISTER_EVENT
2755 local UNREGISTER_EVENT
2756 while read event; do
2757 local parsed=$(parse_json_event "$event")
2758 if [ -z "$parsed" ]; then
2759 error "Copytool sent malformed event: $event"
2763 if [ $event_type == "REGISTER" ]; then
2764 REGISTER_EVENT=$event
2765 elif [ $event_type == "UNREGISTER" ]; then
2766 UNREGISTER_EVENT=$event
2768 done < <(echo $"$(get_copytool_event_log)")
2770 if [ -z "$REGISTER_EVENT" ]; then
2771 error "Copytool failed to send register event to FIFO"
2774 if [ -z "$UNREGISTER_EVENT" ]; then
2775 error "Copytool failed to send unregister event to FIFO"
2778 copytool_monitor_cleanup
2779 echo "Register/Unregister events look OK."
2781 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2784 # Bump progress interval for livelier events.
2787 # test needs a new running copytool
2789 copytool_monitor_setup
2790 HSMTOOL_UPDATE_INTERVAL=$interval \
2791 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2794 local f=$DIR/$tdir/$tfile
2795 local fid=$(make_large_for_progress $f)
2797 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2798 error "could not archive file"
2799 wait_request_state $fid ARCHIVE SUCCEED
2801 local expected_fields="event_time data_fid source_fid"
2802 expected_fields+=" total_bytes current_bytes"
2806 while read event; do
2807 # Make sure we're not getting anything from previous events.
2808 for field in $expected_fields; do
2812 local parsed=$(parse_json_event "$event")
2813 if [ -z "$parsed" ]; then
2814 error "Copytool sent malformed event: $event"
2818 if [ $event_type == "ARCHIVE_START" ]; then
2821 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2824 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2828 # Do some simple checking of the progress update events.
2829 for expected_field in $expected_fields; do
2830 if [ -z ${!expected_field+x} ]; then
2831 error "Missing $expected_field field in event"
2835 if [ $total_bytes -eq 0 ]; then
2836 error "Expected total_bytes to be > 0"
2839 # These should be identical throughout an archive
2841 if [ $source_fid != $data_fid ]; then
2842 error "Expected source_fid to equal data_fid"
2844 done < <(echo $"$(get_copytool_event_log)")
2846 if [ -z "$START_EVENT" ]; then
2847 error "Copytool failed to send archive start event to FIFO"
2850 if [ -z "$FINISH_EVENT" ]; then
2851 error "Copytool failed to send archive finish event to FIFO"
2854 echo "Archive events look OK."
2858 copytool_monitor_cleanup
2860 run_test 71 "Copytool logs JSON archive events to FIFO"
2863 # Bump progress interval for livelier events.
2866 # test needs a new running copytool
2868 copytool_monitor_setup
2869 HSMTOOL_UPDATE_INTERVAL=$interval \
2870 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2871 local test_file=$HSMTOOL_MONITOR_DIR/file
2873 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2875 do_facet $SINGLEAGT "$cmd" ||
2876 error "cannot create $test_file on $SINGLEAGT"
2877 copy2archive $test_file $tdir/$tfile
2880 local f=$DIR/$tdir/$tfile
2881 import_file $tdir/$tfile $f
2882 f=$DIR2/$tdir/$tfile
2883 echo "Verifying released state: "
2884 check_hsm_flags $f "0x0000000d"
2886 local fid=$(path2fid $f)
2888 wait_request_state $fid RESTORE SUCCEED
2890 local expected_fields="event_time data_fid source_fid"
2891 expected_fields+=" total_bytes current_bytes"
2895 while read event; do
2896 # Make sure we're not getting anything from previous events.
2897 for field in $expected_fields; do
2901 local parsed=$(parse_json_event "$event")
2902 if [ -z "$parsed" ]; then
2903 error "Copytool sent malformed event: $event"
2907 if [ $event_type == "RESTORE_START" ]; then
2909 if [ $source_fid != $data_fid ]; then
2910 error "source_fid should == data_fid at start"
2913 elif [ $event_type == "RESTORE_FINISH" ]; then
2915 if [ $source_fid != $data_fid ]; then
2916 error "source_fid should == data_fid at finish"
2919 elif [ $event_type != "RESTORE_RUNNING" ]; then
2923 # Do some simple checking of the progress update events.
2924 for expected_field in $expected_fields; do
2925 if [ -z ${!expected_field+x} ]; then
2926 error "Missing $expected_field field in event"
2930 if [ $total_bytes -eq 0 ]; then
2931 error "Expected total_bytes to be > 0"
2934 # When a restore starts out, the data fid is the same as the
2935 # source fid. After the restore has gotten going, we learn
2936 # the new data fid. Once the restore has finished, the source
2937 # fid is set to the new data fid.
2939 # We test this because some monitoring software may depend on
2940 # this behavior. If it changes, then the consumers of these
2941 # events may need to be modified.
2942 if [ $source_fid == $data_fid ]; then
2943 error "source_fid should != data_fid during restore"
2945 done < <(echo $"$(get_copytool_event_log)")
2947 if [ -z "$START_EVENT" ]; then
2948 error "Copytool failed to send restore start event to FIFO"
2951 if [ -z "$FINISH_EVENT" ]; then
2952 error "Copytool failed to send restore finish event to FIFO"
2955 echo "Restore events look OK."
2959 copytool_monitor_cleanup
2963 run_test 72 "Copytool logs JSON restore events to FIFO"
2966 file_count=51 # Max number of files constrained by LNET message size
2967 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2968 local f=$DIR/$tdir/$tfile
2969 local FILELIST=/tmp/filelist.txt
2973 for i in $(seq 1 $file_count); do
2974 fid=$(copy_file /etc/hosts $f.$i)
2975 echo $f.$i >> $FILELIST
2978 # to be sure wait_all_done will not be mislead by previous tests
2980 wait_for_grace_delay
2981 $LFS hsm_archive --filelist $FILELIST ||
2982 error "cannot archive a file list"
2984 $LFS hsm_release --filelist $FILELIST ||
2985 error "cannot release a file list"
2986 $LFS hsm_restore --filelist $FILELIST ||
2987 error "cannot restore a file list"
2991 run_test 90 "Archive/restore a file list"
2993 double_verify_reset_hsm_param() {
2995 echo "Testing $HSM_PARAM.$p"
2996 local val=$(get_hsm_param $p)
2998 local val2=$(($val * 2))
2999 set_hsm_param $p $val2
3000 val=$(get_hsm_param $p)
3001 [[ $val == $val2 ]] ||
3002 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3003 echo "Set $p to 0 must failed"
3007 set_hsm_param $p $save
3009 if [[ $rc == 0 ]]; then
3010 error "we must not be able to set $HSM_PARAM.$p to 0"
3015 double_verify_reset_hsm_param loop_period
3016 double_verify_reset_hsm_param grace_delay
3017 double_verify_reset_hsm_param active_request_timeout
3018 double_verify_reset_hsm_param max_requests
3019 double_verify_reset_hsm_param default_archive_id
3021 run_test 100 "Set coordinator /proc tunables"
3028 run_test 102 "Verify coordinator control"
3031 # test needs a running copytool
3038 for i in $(seq 1 20); do
3039 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3041 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3045 echo "Current requests"
3046 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3047 $HSM_PARAM.actions |\
3048 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3050 [[ -z "$res" ]] || error "Some request have not been canceled"
3054 run_test 103 "Purge all requests"
3059 # test needs a running copytool
3063 local f=$DIR/$tdir/$tfile
3064 local fid=$(make_large_for_progress $f)
3065 # if cdt is on, it can serve too quickly the request
3067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3068 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3069 $HSM_PARAM.actions |\
3070 grep $fid | cut -f16 -d=")
3073 [[ "$data1" == "$DATAHEX" ]] ||
3074 error "Data field in records is ($data1) and not ($DATAHEX)"
3078 run_test 104 "Copy tool data field"
3085 for i in $(seq -w 1 10); do
3086 cp /etc/passwd $DIR/$tdir/$i
3087 $LFS hsm_archive $DIR/$tdir/$i
3089 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3090 $HSM_PARAM.actions |\
3091 grep WAITING | wc -l")
3094 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3095 $HSM_PARAM.actions |\
3096 grep WAITING | wc -l")
3099 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3100 error "Requests count after shutdown $reqcnt2 != "\
3101 "before shutdown $reqcnt1"
3103 run_test 105 "Restart of coordinator"
3105 get_agent_by_uuid_mdt() {
3108 local mds=mds$(($mdtidx + 1))
3109 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3113 check_agent_registered_by_mdt() {
3116 local mds=mds$(($mdtidx + 1))
3117 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3118 if [[ ! -z "$agent" ]]; then
3119 echo "found agent $agent on $mds"
3121 error "uuid $uuid not found in agent list on $mds"
3125 check_agent_unregistered_by_mdt() {
3128 local mds=mds$(($mdtidx + 1))
3129 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3130 if [[ -z "$agent" ]]; then
3131 echo "uuid not found in agent list on $mds"
3133 error "uuid found in agent list on $mds: $agent"
3137 check_agent_registered() {
3140 for mdsno in $(seq 1 $MDSCOUNT); do
3141 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3145 check_agent_unregistered() {
3148 for mdsno in $(seq 1 $MDSCOUNT); do
3149 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3154 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3155 get_client_uuid $MOUNT | cut -d' ' -f2)
3158 check_agent_registered $uuid
3160 search_copytools || error "No copytool found"
3163 check_agent_unregistered $uuid
3166 check_agent_registered $uuid
3170 run_test 106 "Copytool register/unregister"
3173 # test needs a running copytool
3175 # create and archive file
3177 local f1=$DIR/$tdir/$tfile
3178 local fid=$(copy_file /etc/passwd $f1)
3179 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3180 wait_request_state $fid ARCHIVE SUCCEED
3181 # shutdown and restart MDS
3183 # check the copytool still gets messages from MDT
3184 local f2=$DIR/$tdir/2
3185 local fid=$(copy_file /etc/passwd $f2)
3186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3187 # main check of this sanity: this request MUST succeed
3188 wait_request_state $fid ARCHIVE SUCCEED
3191 run_test 107 "Copytool re-register after MDS restart"
3193 policy_set_and_test()
3197 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3198 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3199 [[ "$policy" == "$target" ]] ||
3200 error "Wrong policy after '$change': '$policy' != '$target'"
3204 # to force default policy setting if error
3205 CDT_POLICY_HAD_CHANGED=true
3207 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3208 local default="NonBlockingRestore [NoRetryAction]"
3209 [[ "$policy" == "$default" ]] ||
3210 error "default policy has changed,"\
3211 " '$policy' != '$default' update the test"
3212 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3213 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3214 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3215 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3216 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3217 # useless bacause we know but safer for futur changes to use real value
3218 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3219 echo "Next set_param must failed"
3220 policy_set_and_test "wrong" "$policy"
3223 echo "Back to default policy"
3224 cdt_set_sanity_policy
3226 run_test 109 "Policy display/change"
3229 # test needs a running copytool
3234 copy2archive /etc/passwd $tdir/$tfile
3236 local f=$DIR/$tdir/$tfile
3237 import_file $tdir/$tfile $f
3238 local fid=$(path2fid $f)
3240 cdt_set_non_blocking_restore
3245 wait_request_state $fid RESTORE SUCCEED
3246 cdt_clear_non_blocking_restore
3250 error "md5sum returns $st != 1, "\
3251 "should also perror ENODATA (No data available)"
3255 run_test 110a "Non blocking restore policy (import case)"
3258 # test needs a running copytool
3262 local f=$DIR/$tdir/$tfile
3263 local fid=$(copy_file /etc/passwd $f)
3264 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3265 wait_request_state $fid ARCHIVE SUCCEED
3268 cdt_set_non_blocking_restore
3273 wait_request_state $fid RESTORE SUCCEED
3274 cdt_clear_non_blocking_restore
3278 error "md5sum returns $st != 1, "\
3279 "should also perror ENODATA (No data available)"
3283 run_test 110b "Non blocking restore policy (release case)"
3286 # test needs a running copytool
3290 copy2archive /etc/passwd $tdir/$tfile
3292 local f=$DIR/$tdir/$tfile
3294 import_file $tdir/$tfile $f
3295 local fid=$(path2fid $f)
3299 copytool_remove_backend $fid
3302 wait_request_state $fid RESTORE FAILED
3309 [[ $st == 0 ]] || error "Restore does not failed"
3313 run_test 111a "No retry policy (import case), restore will error"\
3314 " (No such file or directory)"
3317 # test needs a running copytool
3321 local f=$DIR/$tdir/$tfile
3322 local fid=$(copy_file /etc/passwd $f)
3324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3325 wait_request_state $fid ARCHIVE SUCCEED
3328 copytool_remove_backend $fid
3331 wait_request_state $fid RESTORE FAILED
3338 [[ $st == 0 ]] || error "Restore does not failed"
3342 run_test 111b "No retry policy (release case), restore will error"\
3343 " (No such file or directory)"
3346 # test needs a running copytool
3350 local f=$DIR/$tdir/$tfile
3351 local fid=$(copy_file /etc/passwd $f)
3353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3354 local l=$($LFS hsm_action $f)
3356 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3360 wait_request_state $fid ARCHIVE SUCCEED
3363 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3367 run_test 112 "State of recorded request"
3370 # test needs a running copytool
3374 local f=$DIR/$tdir/$tfile
3375 local fid=$(make_large_for_cancel $f)
3376 # test with cdt on is made in test_221
3378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3381 wait_request_state $fid ARCHIVE CANCELED
3382 wait_request_state $fid CANCEL SUCCEED
3386 run_test 200 "Register/Cancel archive"
3389 # test needs a running copytool
3393 local f=$DIR/$tdir/$tfile
3394 make_archive $tdir/$tfile
3395 import_file $tdir/$tfile $f
3396 local fid=$(path2fid $f)
3398 # test with cdt on is made in test_222
3403 wait_request_state $fid RESTORE CANCELED
3404 wait_request_state $fid CANCEL SUCCEED
3408 run_test 201 "Register/Cancel restore"
3411 # test needs a running copytool
3415 local f=$DIR/$tdir/$tfile
3416 local fid=$(make_large_for_progress $f)
3417 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3418 wait_request_state $fid ARCHIVE SUCCEED
3424 wait_request_state $fid REMOVE CANCELED
3428 run_test 202 "Register/Cancel remove"
3431 # test needs a running copytool
3436 local f=$DIR/$tdir/$tfile
3437 local fid=$(copy_file /etc/passwd $f)
3441 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3442 wait_request_state $fid ARCHIVE SUCCEED
3444 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3448 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3452 run_test 220 "Changelog for archive"
3455 # test needs a running copytool
3460 local f=$DIR/$tdir/$tfile
3461 local fid=$(make_large_for_cancel $f)
3465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3466 wait_request_state $fid ARCHIVE STARTED
3468 wait_request_state $fid ARCHIVE CANCELED
3469 wait_request_state $fid CANCEL SUCCEED
3471 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3474 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3478 run_test 221 "Changelog for archive canceled"
3481 # test needs a running copytool
3485 copy2archive /etc/passwd $tdir/$tfile
3487 local f=$DIR/$tdir/$tfile
3488 import_file $tdir/$tfile $f
3489 local fid=$(path2fid $f)
3494 wait_request_state $fid RESTORE SUCCEED
3496 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3499 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3503 run_test 222a "Changelog for explicit restore"
3506 # test needs a running copytool
3510 local f=$DIR/$tdir/$tfile
3511 local fid=$(copy_file /etc/passwd $f)
3514 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3515 wait_request_state $fid ARCHIVE SUCCEED
3520 wait_request_state $fid RESTORE SUCCEED
3522 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3525 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3529 run_test 222b "Changelog for implicit restore"
3532 # test needs a running copytool
3537 local f=$DIR/$tdir/$tfile
3538 make_archive $tdir/$tfile
3542 import_file $tdir/$tfile $f
3543 local fid=$(path2fid $f)
3546 wait_request_state $fid RESTORE STARTED
3548 wait_request_state $fid RESTORE CANCELED
3549 wait_request_state $fid CANCEL SUCCEED
3551 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3554 [[ $flags == $target ]] ||
3555 error "Changelog flag is $flags not $target"
3559 run_test 223a "Changelog for restore canceled (import case)"
3562 # test needs a running copytool
3567 local f=$DIR/$tdir/$tfile
3568 local fid=$(make_large_for_progress $f)
3571 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3572 wait_request_state $fid ARCHIVE SUCCEED
3575 wait_request_state $fid RESTORE STARTED
3577 wait_request_state $fid RESTORE CANCELED
3578 wait_request_state $fid CANCEL SUCCEED
3580 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3583 [[ $flags == $target ]] ||
3584 error "Changelog flag is $flags not $target"
3588 run_test 223b "Changelog for restore canceled (release case)"
3591 # test needs a running copytool
3596 local f=$DIR/$tdir/$tfile
3597 local fid=$(copy_file /etc/passwd $f)
3600 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3601 wait_request_state $fid ARCHIVE SUCCEED
3604 wait_request_state $fid REMOVE SUCCEED
3606 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3609 [[ $flags == $target ]] ||
3610 error "Changelog flag is $flags not $target"
3614 run_test 224 "Changelog for remove"
3617 # test needs a running copytool
3620 # test is not usable because remove request is too fast
3621 # so it is always finished before cancel can be done ...
3622 echo "Test disabled"
3627 local f=$DIR/$tdir/$tfile
3628 local fid=$(make_large_for_progress $f)
3631 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3632 wait_request_state $fid ARCHIVE SUCCEED
3634 # if cdt is on, it can serve too quickly the request
3639 wait_request_state $fid REMOVE CANCELED
3640 wait_request_state $fid CANCEL SUCCEED
3642 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3643 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3644 tail -n 1 | awk '{print $5}')
3647 [[ $flags == $target ]] ||
3648 error "Changelog flag is $flags not $target"
3652 run_test 225 "Changelog for remove canceled"
3655 # test needs a running copytool
3660 local f1=$DIR/$tdir/$tfile-1
3661 local f2=$DIR/$tdir/$tfile-2
3662 local f3=$DIR/$tdir/$tfile-3
3663 local fid1=$(copy_file /etc/passwd $f1)
3664 local fid2=$(copy_file /etc/passwd $f2)
3665 copy_file /etc/passwd $f3
3668 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3669 wait_request_state $fid1 ARCHIVE SUCCEED
3671 $LFS hsm_archive $f2
3672 wait_request_state $fid2 ARCHIVE SUCCEED
3674 rm $f1 || error "rm $f1 failed"
3676 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3679 [[ $flags == $target ]] ||
3680 error "Changelog flag is $flags not $target"
3682 mv $f3 $f2 || error "mv $f3 $f2 failed"
3684 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3687 [[ $flags == $target ]] ||
3688 error "Changelog flag is $flags not $target"
3692 run_test 226 "changelog for last rm/mv with exiting archive"
3694 check_flags_changes() {
3702 $LFS hsm_set --$hsm_flag $f ||
3703 error "Cannot set $hsm_flag on $f"
3704 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3705 local seen=${#flags[*]}
3707 [[ $seen == $cnt ]] ||
3708 error "set $hsm_flag: Changelog events $seen != $cnt"
3709 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3710 error "set $hsm_flag: Changelog flags are "\
3711 "${flags[$((cnt - 1))]} not $target"
3713 $LFS hsm_clear --$hsm_flag $f ||
3714 error "Cannot clear $hsm_flag on $f"
3715 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3718 [[ $cnt == $seen ]] ||
3719 error "clear $hsm_flag: Changelog events $seen != $cnt"
3721 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3722 error "clear $hsm_flag: Changelog flag is "\
3723 "${flags[$((cnt - 1))]} not $target"
3727 # test needs a running copytool
3734 for i in norelease noarchive exists archived
3736 local f=$DIR/$tdir/$tfile-$i
3737 local fid=$(copy_file /etc/passwd $f)
3738 check_flags_changes $f $fid $i 0 1
3741 f=$DIR/$tdir/$tfile---lost
3742 fid=$(copy_file /etc/passwd $f)
3743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3744 wait_request_state $fid ARCHIVE SUCCEED
3745 check_flags_changes $f $fid lost 3 1
3749 run_test 227 "changelog when explicit setting of HSM flags"
3752 # test needs a running copytool
3755 local fid=$(make_small_sync $DIR/$tfile)
3756 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3757 wait_request_state $fid ARCHIVE SUCCEED
3759 $LFS hsm_release $DIR/$tfile
3760 check_hsm_flags $DIR/$tfile "0x0000000d"
3762 filefrag $DIR/$tfile | grep " 1 extent found" ||
3763 error "filefrag on released file must return only one extent"
3765 # only newer versions of cp detect sparse files by stat/FIEMAP
3767 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3768 error "copying $DIR/$tfile"
3769 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3771 $LFS hsm_release $DIR/$tfile
3772 check_hsm_flags $DIR/$tfile "0x0000000d"
3774 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3776 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3778 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3779 error "comparing untarred $DIR/$tfile"
3781 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3782 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3785 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3788 # test needs a running copytool
3792 local maxrequest=$(get_hsm_param max_requests)
3793 local rqcnt=$(($maxrequest * 3))
3797 for i in $(seq -w 1 $rqcnt); do
3799 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3801 # we do it in 2 steps, so all requests arrive at the same time
3802 for i in $(seq -w 1 $rqcnt); do
3803 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3808 while [[ $cnt != 0 || $wt != 0 ]]; do
3810 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3811 $HSM_PARAM.actions |\
3812 grep STARTED | grep -v CANCEL | wc -l")
3813 [[ $cnt -le $maxrequest ]] ||
3814 error "$cnt > $maxrequest too many started requests"
3815 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3816 $HSM_PARAM.actions |\
3817 grep WAITING | wc -l")
3818 echo "max=$maxrequest started=$cnt waiting=$wt"
3823 run_test 250 "Coordinator max request"
3826 # test needs a running copytool
3830 local f=$DIR/$tdir/$tfile
3831 local fid=$(make_large_for_cancel $f)
3834 # to have a short test
3835 local old_to=$(get_hsm_param active_request_timeout)
3836 set_hsm_param active_request_timeout 4
3837 # to be sure the cdt will wake up frequently so
3838 # it will be able to cancel the "old" request
3839 local old_loop=$(get_hsm_param loop_period)
3840 set_hsm_param loop_period 2
3843 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3844 wait_request_state $fid ARCHIVE STARTED
3846 wait_request_state $fid ARCHIVE CANCELED
3848 set_hsm_param active_request_timeout $old_to
3849 set_hsm_param loop_period $old_loop
3853 run_test 251 "Coordinator request timeout"
3856 # the only way to test ondisk conf is to restart MDS ...
3857 echo "Stop coordinator and remove coordinator state at mount"
3860 # clean on disk conf set by default
3861 cdt_clear_mount_state
3862 cdt_check_state stopped
3864 # check cdt still off after umount/remount
3866 cdt_check_state stopped
3868 echo "Set coordinator start at mount, and start coordinator"
3869 cdt_set_mount_state enabled
3872 cdt_check_state enabled
3874 # check cdt still on after umount/remount
3876 cdt_check_state enabled
3878 # we are back to original state (cdt started at mount)
3880 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3883 local ai=$(get_hsm_param default_archive_id)
3884 local new=$((ai + 1))
3886 set_hsm_param default_archive_id $new -P
3888 local res=$(get_hsm_param default_archive_id)
3891 set_hsm_param default_archive_id "" "-P -d"
3893 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3895 run_test 301 "HSM tunnable are persistent"
3898 local ai=$(get_hsm_param default_archive_id)
3899 local new=$((ai + 1))
3904 set_hsm_param default_archive_id $new -P
3907 for mdtno in $(seq 1 $MDSCOUNT); do
3912 cdt_check_state enabled
3914 local res=$(get_hsm_param default_archive_id)
3917 set_hsm_param default_archive_id "" "-P -d"
3919 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3921 run_test 302 "HSM tunnable are persistent when CDT is off"
3924 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3930 local dir_mdt0=$DIR/$tdir/mdt0
3931 local dir_mdt1=$DIR/$tdir/mdt1
3933 # create 1 dir per MDT
3934 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3935 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3937 # create 1 file in each MDT
3938 local fid1=$(make_small $dir_mdt0/$tfile)
3939 local fid2=$(make_small $dir_mdt1/$tfile)
3941 # check that hsm request on mdt0 is sent to the right MDS
3942 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3943 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3944 echo "archive successful on mdt0"
3946 # check that hsm request on mdt1 is sent to the right MDS
3947 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3948 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3949 echo "archive successful on mdt1"
3952 # clean test files and directories
3953 rm -rf $dir_mdt0 $dir_mdt1
3955 run_test 400 "Single request is sent to the right MDT"
3958 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3964 local dir_mdt0=$DIR/$tdir/mdt0
3965 local dir_mdt1=$DIR/$tdir/mdt1
3967 # create 1 dir per MDT
3968 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3969 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3971 # create 1 file in each MDT
3972 local fid1=$(make_small $dir_mdt0/$tfile)
3973 local fid2=$(make_small $dir_mdt1/$tfile)
3975 # check that compound requests are shunt to the rights MDTs
3976 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3977 error "lfs hsm_archive"
3978 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3979 echo "archive successful on mdt0"
3980 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3981 echo "archive successful on mdt1"
3984 # clean test files and directories
3985 rm -rf $dir_mdt0 $dir_mdt1
3987 run_test 401 "Compound requests split and sent to their respective MDTs"
3989 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3994 local node=$(facet_active_host $facet)
3996 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3997 awk '{print $4}'); do
3998 echo "$3 $mdc on $node"
3999 do_facet $facet "$LCTL --device $mdc $state" || return 1
4004 # make sure there is no running copytool
4007 # deactivate all mdc on agent1
4008 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4010 copytool_setup $SINGLEAGT
4012 check_agent_unregistered "uuid" # match any agent
4014 # no expected running copytool
4015 search_copytools $agent && error "Copytool start should have failed"
4018 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4020 run_test 402 "Copytool start fails if all MDTs are inactive"
4023 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4025 # make sure there is no running copytool
4028 local agent=$(facet_active_host $SINGLEAGT)
4029 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4031 # deactivate all mdc for MDT0001
4032 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4035 # check the agent is registered on MDT0000, and not on MDT0001
4036 check_agent_registered_by_mdt $uuid 0
4037 check_agent_unregistered_by_mdt $uuid 1
4039 # check running copytool process
4040 search_copytools $agent || error "No running copytools on $agent"
4042 # reactivate all mdc for MDT0001
4043 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4045 # make sure the copytool is now registered to all MDTs
4046 check_agent_registered $uuid
4050 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4053 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4057 # create files on both MDT0000 and MDT0001
4060 local dir_mdt0=$DIR/$tdir/mdt0
4061 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4063 # create 1 file on mdt0
4064 local fid1=$(make_small $dir_mdt0/$tfile)
4066 # deactivate all mdc for MDT0001
4067 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4069 # send an HSM request for files in MDT0000
4070 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4072 # check for completion of files in MDT0000
4073 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4074 echo "archive successful on mdt0"
4076 # reactivate all mdc for MDT0001
4077 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4080 # clean test files and directories
4083 run_test 404 "Inactive MDT does not block requests for active MDTs"
4088 check_and_cleanup_lustre