3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:LU-5474
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 90"
18 # bug number for skipped test:LU-4178
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b"
20 # bug number for skipped test:LU-3852
21 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
22 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
26 . $LUSTRE/tests/test-framework.sh
28 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
31 MULTIOP=${MULTIOP:-multiop}
32 OPENFILE=${OPENFILE:-openfile}
33 MOUNT_2=${MOUNT_2:-"yes"}
36 # script only handles up to 10 MDTs (because of MDT_PREFIX)
37 [ $MDSCOUNT -gt 9 ] &&
38 error "script cannot handle more than 9 MDTs, please fix" && exit
40 check_and_setup_lustre
42 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
43 skip_env "Need MDS version at least 2.4.53" && exit
46 # $RUNAS_ID may get set incorrectly somewhere else
47 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
48 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
50 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
55 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
56 # the following associated variables are added:
58 # AGTCOUNT: number of agents
59 # AGTDEV{N}: target HSM mount point (root path of the backend)
60 # agt{N}_HOST: hostname of the agent agt{N}
61 # SINGLEAGT: facet of the single agent
63 # The number of agents is initialized as the number of remote client nodes.
64 # By default, only single copytool is started on a remote client/agent. If there
65 # was no remote client, then the copytool will be started on the local client.
71 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
72 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
74 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
75 if [[ $CLIENTCOUNT -gt 1 ]] &&
76 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
77 skip_env "SHARED_DIRECTORY should be accessible"\
82 for n in $(seq $AGTCOUNT); do
83 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
84 agent=CLIENT$((n + 1))
85 if [[ -z "${!agent}" ]]; then
86 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
89 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
92 export SINGLEAGT=${SINGLEAGT:-agt1}
94 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
95 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
96 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
97 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
98 export HSMTOOL_TESTDIR
99 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
100 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
103 # The test only support up to 10 MDTs
104 MDT_PREFIX="mdt.$FSNAME-MDT000"
105 HSM_PARAM="${MDT_PREFIX}0.hsm"
107 # archive is purged at copytool setup
108 HSM_ARCHIVE_PURGE=true
110 # Don't allow copytool error upon start/setup
111 HSMTOOL_NOERROR=false
114 # Get the backend root path for the given agent facet.
117 local dev=AGTDEV$(facet_number $facet)
122 # Stop copytool and unregister an existing changelog user.
124 copytool_monitor_cleanup
127 cdt_set_sanity_policy
132 # get MDT device for each mdc
133 for mdtno in $(seq 1 $MDSCOUNT); do
134 local idx=$(($mdtno - 1))
135 MDT[$idx]=$($LCTL get_param -n \
136 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
137 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
142 local agents=${1:-$(facet_active_host $SINGLEAGT)}
143 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
146 search_and_kill_copytool() {
147 local agents=${1:-$(facet_active_host $SINGLEAGT)}
149 echo "Killing existing copytools on $agents"
150 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
153 copytool_monitor_setup() {
154 local facet=${1:-$SINGLEAGT}
155 local agent=$(facet_active_host $facet)
157 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
158 local test_dir=$(do_node $agent "$cmd") ||
159 error "Failed to create tempdir on $agent"
160 export HSMTOOL_MONITOR_DIR=$test_dir
162 # Create the fifo and a monitor (cat dies when copytool dies)
163 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
164 error "failed to create copytool fifo on $agent"
165 cmd="cat $test_dir/fifo > $test_dir/events &"
166 cmd+=" echo \\\$! > $test_dir/monitor_pid"
168 if [[ $PDSH == *Rmrsh* ]]; then
169 # This is required for pdsh -Rmrsh and its handling of remote
171 # Regular ssh and pdsh -Rssh work fine without this
172 # backgrounded subshell nonsense.
173 (do_node $agent "$cmd") &
174 export HSMTOOL_MONITOR_PDSH=$!
176 # Slightly racy, but just making a best-effort to catch obvious
179 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
180 error "Failed to start copytool monitor on $agent"
182 do_node $agent "$cmd"
184 error "Failed to start copytool monitor on $agent"
189 copytool_monitor_cleanup() {
190 local facet=${1:-$SINGLEAGT}
191 local agent=$(facet_active_host $facet)
193 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
194 # Should die when the copytool dies, but just in case.
195 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
196 cmd+=" 2>/dev/null || true"
197 do_node $agent "$cmd"
198 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
199 export HSMTOOL_MONITOR_DIR=
202 # The pdsh should die on its own when the monitor dies. Just
203 # in case, though, try to clean up to avoid any cruft.
204 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
205 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
206 export HSMTOOL_MONITOR_PDSH=
211 local facet=${1:-$SINGLEAGT}
212 local lustre_mntpnt=${2:-$MOUNT}
214 local hsm_root=${4:-$(copytool_device $facet)}
215 local agent=$(facet_active_host $facet)
217 if [[ -z "$arc_id" ]] &&
218 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
219 echo "Wakeup copytool $facet on $agent"
223 if $HSM_ARCHIVE_PURGE; then
224 echo "Purging archive on $agent"
225 do_facet $facet "rm -rf $hsm_root/*"
228 echo "Starting copytool $facet on $agent"
229 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
230 # bandwidth is limited to 1MB/s so the copy time is known and
231 # independent of hardware
232 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
233 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
234 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
235 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
236 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
237 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
238 cmd+=" --bandwidth 1 $lustre_mntpnt"
240 # Redirect the standard output and error to a log file which
241 # can be uploaded to Maloo.
242 local prefix=$TESTLOG_PREFIX
243 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
244 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
246 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
247 if [[ $? != 0 ]]; then
248 [[ $HSMTOOL_NOERROR == true ]] ||
249 error "start copytool $facet on $agent failed"
250 echo "start copytool $facet on $agent failed"
256 get_copytool_event_log() {
257 local facet=${1:-$SINGLEAGT}
258 local agent=$(facet_active_host $facet)
260 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
261 error "Can't get event log: No monitor directory!"
263 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
264 error "Could not collect event log from $agent"
269 local facet=$SINGLEAGT
270 local agents=${1:-$(facet_active_host $facet)}
275 local hsm_root=$(copytool_device $facet)
277 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
279 echo "Copytool is stopped on $agents"
281 # clean all CDTs orphans requests from previous tests
282 # that would otherwise need to timeout to clear.
283 for mdtno in $(seq 1 $MDSCOUNT); do
285 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
286 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
288 # skip already stop[ed,ing] CDTs
289 echo $oldstate | grep stop && continue
291 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
292 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
294 error "mds${mdtno} cdt state is not stopped"
295 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
296 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
298 error "mds${mdtno} cdt state is not $oldstate"
300 do_facet $facet "rm -rf $hsm_root"
304 local agents=${1:-$(facet_active_host $SINGLEAGT)}
306 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
307 echo "Copytool is suspended on $agents"
310 copytool_remove_backend() {
312 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
313 echo "Remove from backend: $fid = $be"
314 do_facet $SINGLEAGT rm -f $be
318 do_facet $SINGLEAGT \
319 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
320 --import $1 $2 $MOUNT" ||
321 error "import of $1 to $2 failed"
325 local file=$HSM_ARCHIVE/$1
326 do_facet $SINGLEAGT mkdir -p $(dirname $file)
327 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
328 error "cannot create $file"
332 local file=$HSM_ARCHIVE/$2
333 do_facet $SINGLEAGT mkdir -p $(dirname $file)
334 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
343 if [[ "$value" != "" ]]; then
346 for mdtno in $(seq 1 $MDSCOUNT); do
347 local idx=$(($mdtno - 1))
348 local facet=mds${mdtno}
349 # if $arg include -P option, run 1 set_param per MDT on the MGS
350 # else, run set_param on each MDT
351 [[ $arg = *"-P"* ]] && facet=mgs
352 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
353 [[ $? != 0 ]] && rc=1
363 for mdtno in $(seq 1 $MDSCOUNT); do
364 local idx=$(($mdtno - 1))
365 wait_result mds${mdtno} \
366 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
368 error "$key state is not '$target' on mds${mdtno}"
375 for mdtno in $(seq 1 $MDSCOUNT); do
376 local idx=$(($mdtno - 1))
377 local cl_user=$(do_facet mds${mdtno} $LCTL \
378 --device ${MDT[$idx]} \
379 changelog_register -n)
381 do_facet mds${mdtno} lctl set_param \
382 mdd.${MDT[$idx]}.changelog_mask="+hsm"
383 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
387 changelog_cleanup() {
389 for mdtno in $(seq 1 $MDSCOUNT); do
390 local idx=$(($mdtno - 1))
391 [[ -z ${CL_USERS[$idx]} ]] && continue
392 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
393 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
394 changelog_deregister ${CL_USERS[$idx]}
399 changelog_get_flags() {
404 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
409 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
417 mdts_set_param "$opt -n" "hsm.$param" "$value"
424 mdts_set_param "" hsm_control "$cmd"
425 mdts_check_param hsm_control "$target" 10
428 cdt_set_sanity_policy() {
429 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
432 mdts_set_param "" hsm.policy "+NRA"
433 mdts_set_param "" hsm.policy "-NBR"
434 CDT_POLICY_HAD_CHANGED=
439 mdts_set_param "" hsm.policy "+NRA"
440 CDT_POLICY_HAD_CHANGED=true
443 cdt_clear_no_retry() {
444 mdts_set_param "" hsm.policy "-NRA"
445 CDT_POLICY_HAD_CHANGED=true
448 cdt_set_non_blocking_restore() {
449 mdts_set_param "" hsm.policy "+NBR"
450 CDT_POLICY_HAD_CHANGED=true
453 cdt_clear_non_blocking_restore() {
454 mdts_set_param "" hsm.policy "-NBR"
455 CDT_POLICY_HAD_CHANGED=true
458 cdt_clear_mount_state() {
459 mdts_set_param "-P -d" hsm_control ""
462 cdt_set_mount_state() {
463 mdts_set_param "-P" hsm_control "$1"
467 mdts_check_param hsm_control "$1" 20
471 set_test_state disabled disabled
475 set_test_state enabled enabled
479 set_test_state shutdown stopped
483 set_test_state purge enabled
489 cdt_set_sanity_policy
493 local client_count=$1
494 if [[ $CLIENTCOUNT -lt $client_count ]]; then
495 skip "Need $client_count or more clients, have $CLIENTCOUNT"
502 $LFS path2fid $1 | tr -d '[]'
509 if [[ $u == "user" ]]; then
510 local st=$($RUNAS $LFS hsm_state $f)
512 local st=$($LFS hsm_state $f)
516 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
518 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
522 get_hsm_archive_id() {
524 local st=$($LFS hsm_state $f)
525 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
527 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
536 local st=$(get_hsm_flags $f)
537 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
540 check_hsm_flags_user() {
544 local st=$(get_hsm_flags $f user)
545 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
557 if [[ "$3" != 1 ]]; then
561 cp $1 $f || error "cannot copy $1 to $f"
562 path2fid $f || error "cannot get fid on $f"
566 local file2=${1/$DIR/$DIR2}
567 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
568 error "cannot create $file2"
569 path2fid $1 || error "cannot get fid on $1"
573 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
574 error "cannot create $1"
575 path2fid $1 || error "cannot get fid on $1"
578 cleanup_large_files() {
579 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
581 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
584 make_large_for_striping() {
585 local file2=${1/$DIR/$DIR2}
586 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
590 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
591 error "cannot create $file2"
592 path2fid $1 || error "cannot get fid on $1"
595 make_large_for_progress() {
596 local file2=${1/$DIR/$DIR2}
600 # big file is large enough, so copy time is > 30s
601 # so copytool make 1 progress
602 # size is not a multiple of 1M to avoid stripe
604 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
605 error "cannot create $file2"
606 path2fid $1 || error "cannot get fid on $1"
609 make_large_for_progress_aligned() {
610 local file2=${1/$DIR/$DIR2}
614 # big file is large enough, so copy time is > 30s
615 # so copytool make 1 progress
616 # size is a multiple of 1M to have stripe
618 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
619 error "cannot create $file2"
620 path2fid $1 || error "cannot get fid on $1"
623 make_large_for_cancel() {
624 local file2=${1/$DIR/$DIR2}
628 # Copy timeout is 100s. 105MB => 105s
629 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
630 error "cannot create $file2"
631 path2fid $1 || error "cannot get fid on $1"
637 wait_update --verbose $(facet_active_host $facet) "$@"
640 wait_request_state() {
644 # 4th arg (mdt index) is optional
646 local mds=mds$(($mdtidx + 1))
648 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
649 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
651 wait_result $mds "$cmd" $state 100 ||
652 error "request on $fid is not $state on $mds"
655 get_request_state() {
659 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
660 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
663 get_request_count() {
667 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
668 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
675 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
676 [[ -n $fid ]] && cmd+=" | grep '$fid'"
677 cmd+=" | egrep 'WAITING|STARTED'"
679 wait_result $SINGLEMDS "$cmd" "" $timeout ||
680 error "requests did not complete"
683 wait_for_grace_delay() {
684 local val=$(get_hsm_param grace_delay)
691 # python2.6 in EL6 includes an internal json module
692 local json_parser='import json; import fileinput;'
693 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
694 json_parser+='json.loads([line for line in '
695 json_parser+='fileinput.input()][0]).items()])'
697 echo $raw_event | python -c "$json_parser"
700 # populate MDT device array
706 # cleanup from previous bad setup
707 search_and_kill_copytool
709 # for recovery tests, coordinator needs to be started at mount
711 # the lustre conf must be without hsm on (like for sanity.sh)
712 echo "Set HSM on and start"
713 cdt_set_mount_state enabled
714 cdt_check_state enabled
716 echo "Start copytool"
719 echo "Set sanity-hsm HSM policy"
720 cdt_set_sanity_policy
722 # finished requests are quickly removed from list
723 set_hsm_param grace_delay 10
729 local f=$DIR/$tdir/$tfile
733 check_hsm_flags_user $f "0x00000000"
735 $RUNAS $LFS hsm_set --norelease $f ||
736 error "user could not change hsm flags"
737 check_hsm_flags_user $f "0x00000010"
739 $RUNAS $LFS hsm_clear --norelease $f ||
740 error "user could not clear hsm flags"
741 check_hsm_flags_user $f "0x00000000"
743 # User could not change those flags...
744 $RUNAS $LFS hsm_set --exists $f &&
745 error "user should not set this flag"
746 check_hsm_flags_user $f "0x00000000"
749 $LFS hsm_set --exists $f ||
750 error "root could not change hsm flags"
751 check_hsm_flags_user $f "0x00000001"
753 $LFS hsm_clear --exists $f ||
754 error "root could not clear hsm state"
755 check_hsm_flags_user $f "0x00000000"
758 run_test 1 "lfs hsm flags root/non-root access"
762 local f=$DIR/$tdir/$tfile
764 # New files are not dirty
765 check_hsm_flags $f "0x00000000"
767 # For test, we simulate an archived file.
768 $LFS hsm_set --exists $f || error "user could not change hsm flags"
769 check_hsm_flags $f "0x00000001"
771 # chmod do not put the file dirty
772 chmod 600 $f || error "could not chmod test file"
773 check_hsm_flags $f "0x00000001"
775 # chown do not put the file dirty
776 chown $RUNAS_ID $f || error "could not chown test file"
777 check_hsm_flags $f "0x00000001"
779 # truncate put the file dirty
780 $TRUNCATE $f 1 || error "could not truncate test file"
781 check_hsm_flags $f "0x00000003"
783 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
784 check_hsm_flags $f "0x00000001"
786 run_test 2 "Check file dirtyness when doing setattr"
792 # New files are not dirty
794 check_hsm_flags $f "0x00000000"
796 # For test, we simulate an archived file.
797 $LFS hsm_set --exists $f ||
798 error "user could not change hsm flags"
799 check_hsm_flags $f "0x00000001"
801 # Reading a file, does not set dirty
802 cat $f > /dev/null || error "could not read file"
803 check_hsm_flags $f "0x00000001"
805 # Open for write without modifying data, does not set dirty
806 openfile -f O_WRONLY $f || error "could not open test file"
807 check_hsm_flags $f "0x00000001"
809 # Append to a file sets it dirty
810 cp -p /etc/passwd $f.append || error "could not create file"
811 $LFS hsm_set --exists $f.append ||
812 error "user could not change hsm flags"
813 dd if=/etc/passwd of=$f.append bs=1 count=3\
814 conv=notrunc oflag=append status=noxfer ||
815 error "could not append to test file"
816 check_hsm_flags $f.append "0x00000003"
818 # Modify a file sets it dirty
819 cp -p /etc/passwd $f.modify || error "could not create file"
820 $LFS hsm_set --exists $f.modify ||
821 error "user could not change hsm flags"
822 dd if=/dev/zero of=$f.modify bs=1 count=3\
823 conv=notrunc status=noxfer ||
824 error "could not modify test file"
825 check_hsm_flags $f.modify "0x00000003"
827 # Open O_TRUNC sets dirty
828 cp -p /etc/passwd $f.trunc || error "could not create file"
829 $LFS hsm_set --exists $f.trunc ||
830 error "user could not change hsm flags"
831 cp /etc/group $f.trunc || error "could not override a file"
832 check_hsm_flags $f.trunc "0x00000003"
834 # Mmapped a file sets dirty
835 cp -p /etc/passwd $f.mmap || error "could not create file"
836 $LFS hsm_set --exists $f.mmap ||
837 error "user could not change hsm flags"
838 multiop $f.mmap OSMWUc || error "could not mmap a file"
839 check_hsm_flags $f.mmap "0x00000003"
841 run_test 3 "Check file dirtyness when opening for write"
845 local f=$DIR/$tdir/$tfile
846 local fid=$(make_small $f)
849 local st=$(get_request_state $fid CANCEL)
850 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
852 run_test 4 "Useless cancel must not be registered"
855 # test needs a running copytool
859 local f=$DIR/$tdir/$tfile
860 local fid=$(copy_file /etc/passwd $f)
862 wait_request_state $fid ARCHIVE SUCCEED
864 check_hsm_flags $f "0x00000009"
868 run_test 8 "Test default archive number"
872 local f=$DIR/$tdir/$tfile
873 local fid=$(copy_file /etc/passwd $f)
874 # we do not use the default one to be sure
875 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
877 copytool_setup $SINGLEAGT $MOUNT $new_an
878 $LFS hsm_archive --archive $new_an $f
879 wait_request_state $fid ARCHIVE SUCCEED
881 check_hsm_flags $f "0x00000009"
885 run_test 9 "Use of explict archive number, with dedicated copytool"
888 needclients 3 || return 0
894 copytool_cleanup $(comma_list $(agts_nodes))
896 # start all of the copytools
897 for n in $(seq $AGTCOUNT); do
901 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
904 for n in $(seq $AGTCOUNT); do
905 file=$DIR/$tdir/$tfile.$n
906 fid=$(make_small $file)
908 $LFS hsm_archive $file || error "could not archive file $file"
909 wait_request_state $fid ARCHIVE SUCCEED
910 check_hsm_flags $file "0x00000009"
914 copytool_cleanup $(comma_list $(agts_nodes))
916 run_test 9a "Multiple remote agents"
919 # test needs a running copytool
922 mkdir -p $DIR/$tdir/d1
923 local f=$DIR/$tdir/$tfile
924 local fid=$(copy_file /etc/hosts $f)
925 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
926 error "hsm_archive failed"
927 wait_request_state $fid ARCHIVE SUCCEED
929 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
930 error "fid $fid not in archive $HSM_ARCHIVE"
931 echo "Verifying content"
932 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
933 echo "Verifying hsm state "
934 check_hsm_flags $f "0x00000009"
936 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
937 local st=$(get_hsm_archive_id $f)
938 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
939 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
944 run_test 10a "Archive a file"
947 # test needs a running copytool
951 local f=$DIR/$tdir/$tfile
952 local fid=$(copy_file /etc/hosts $f)
953 $LFS hsm_archive $f || error "archive request failed"
954 wait_request_state $fid ARCHIVE SUCCEED
956 $LFS hsm_archive $f || error "archive of non dirty file failed"
957 local cnt=$(get_request_count $fid ARCHIVE)
958 [[ "$cnt" == "1" ]] ||
959 error "archive of non dirty file must not make a request"
963 run_test 10b "Archive of non dirty file must work without doing request"
966 # test needs a running copytool
970 local f=$DIR/$tdir/$tfile
971 local fid=$(copy_file /etc/hosts $f)
972 $LFS hsm_set --noarchive $f
973 $LFS hsm_archive $f && error "archive a noarchive file must fail"
977 run_test 10c "Check forbidden archive"
980 # test needs a running copytool
984 local f=$DIR/$tdir/$tfile
985 local fid=$(copy_file /etc/hosts $f)
986 $LFS hsm_archive $f || error "cannot archive $f"
987 wait_request_state $fid ARCHIVE SUCCEED
989 local ar=$(get_hsm_archive_id $f)
990 local dflt=$(get_hsm_param default_archive_id)
991 [[ $ar == $dflt ]] ||
992 error "archived file is not on default archive: $ar != $dflt"
996 run_test 10d "Archive a file on the default archive id"
1000 copy2archive /etc/hosts $tdir/$tfile
1001 local f=$DIR/$tdir/$tfile
1003 import_file $tdir/$tfile $f
1004 echo -n "Verifying released state: "
1005 check_hsm_flags $f "0x0000000d"
1007 local LSZ=$(stat -c "%s" $f)
1008 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1010 echo "Verifying imported size $LSZ=$ASZ"
1011 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1012 echo -n "Verifying released pattern: "
1013 local PTRN=$($GETSTRIPE -L $f)
1015 [[ $PTRN == 80000001 ]] || error "Is not released"
1016 local fid=$(path2fid $f)
1017 echo "Verifying new fid $fid in archive"
1019 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1020 error "fid $fid not in archive $HSM_ARCHIVE"
1022 run_test 11a "Import a file"
1025 # test needs a running copytool
1029 local f=$DIR/$tdir/$tfile
1030 local fid=$(copy_file /etc/hosts $f)
1031 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1032 error "hsm_archive failed"
1033 wait_request_state $fid ARCHIVE SUCCEED
1035 local FILE_HASH=$(md5sum $f)
1040 echo "$FILE_HASH" | md5sum -c
1042 [[ $? -eq 0 ]] || error "Restored file differs"
1046 run_test 11b "Import a deleted file using its FID"
1049 # test needs a running copytool
1053 copy2archive /etc/hosts $tdir/$tfile
1055 local f=$DIR/$tdir/$tfile
1056 import_file $tdir/$tfile $f
1057 local f2=$DIR2/$tdir/$tfile
1058 echo "Verifying released state: "
1059 check_hsm_flags $f2 "0x0000000d"
1061 local fid=$(path2fid $f2)
1062 $LFS hsm_restore $f2
1063 wait_request_state $fid RESTORE SUCCEED
1065 echo "Verifying file state: "
1066 check_hsm_flags $f2 "0x00000009"
1068 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1070 [[ $? -eq 0 ]] || error "Restored file differs"
1074 run_test 12a "Restore an imported file explicitly"
1077 # test needs a running copytool
1081 copy2archive /etc/hosts $tdir/$tfile
1083 local f=$DIR/$tdir/$tfile
1084 import_file $tdir/$tfile $f
1085 echo "Verifying released state: "
1086 check_hsm_flags $f "0x0000000d"
1088 cat $f > /dev/null || error "File read failed"
1090 echo "Verifying file state after restore: "
1091 check_hsm_flags $f "0x00000009"
1093 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1095 [[ $? -eq 0 ]] || error "Restored file differs"
1099 run_test 12b "Restore an imported file implicitly"
1102 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1104 # test needs a running copytool
1108 local f=$DIR/$tdir/$tfile
1109 $LFS setstripe -c 2 $f
1110 local fid=$(make_large_for_striping $f)
1111 local FILE_CRC=$(md5sum $f)
1113 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1114 wait_request_state $fid ARCHIVE SUCCEED
1115 $LFS hsm_release $f || error "release $f failed"
1117 echo "$FILE_CRC" | md5sum -c
1119 [[ $? -eq 0 ]] || error "Restored file differs"
1123 run_test 12c "Restore a file with stripe of 2"
1126 # test needs a running copytool
1131 local f=$DIR/$tdir/$tfile
1132 local fid=$(copy_file /etc/hosts $f)
1133 $LFS hsm_restore $f || error "restore of non archived file failed"
1134 local cnt=$(get_request_count $fid RESTORE)
1135 [[ "$cnt" == "0" ]] ||
1136 error "restore non archived must not make a request"
1137 $LFS hsm_archive $f ||
1138 error "archive request failed"
1139 wait_request_state $fid ARCHIVE SUCCEED
1140 $LFS hsm_restore $f ||
1141 error "restore of non released file failed"
1142 local cnt=$(get_request_count $fid RESTORE)
1143 [[ "$cnt" == "0" ]] ||
1144 error "restore a non dirty file must not make a request"
1148 run_test 12d "Restore of a non archived, non released file must work"\
1149 " without doing request"
1152 # test needs a running copytool
1155 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1156 local f=$DIR/$tdir/$tfile
1157 local fid=$(copy_file /etc/hosts $f)
1158 $LFS hsm_archive $f || error "archive request failed"
1159 wait_request_state $fid ARCHIVE SUCCEED
1162 cat /etc/hosts >> $f
1166 $LFS hsm_restore $f && error "restore a dirty file must fail"
1170 run_test 12e "Check forbidden restore"
1173 # test needs a running copytool
1177 local f=$DIR/$tdir/$tfile
1178 local fid=$(copy_file /etc/hosts $f)
1180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1181 wait_request_state $fid ARCHIVE SUCCEED
1182 $LFS hsm_release $f || error "release of $f failed"
1184 wait_request_state $fid RESTORE SUCCEED
1186 echo -n "Verifying file state: "
1187 check_hsm_flags $f "0x00000009"
1189 diff -q /etc/hosts $f
1191 [[ $? -eq 0 ]] || error "Restored file differs"
1195 run_test 12f "Restore a released file explicitly"
1198 # test needs a running copytool
1202 local f=$DIR/$tdir/$tfile
1203 local fid=$(copy_file /etc/hosts $f)
1205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1206 wait_request_state $fid ARCHIVE SUCCEED
1207 $LFS hsm_release $f || error "release of $f failed"
1209 diff -q /etc/hosts $f
1212 # we check we had a restore done
1213 wait_request_state $fid RESTORE SUCCEED
1215 [[ $st -eq 0 ]] || error "Restored file differs"
1219 run_test 12g "Restore a released file implicitly"
1222 needclients 2 || return 0
1224 # test needs a running copytool
1228 local f=$DIR/$tdir/$tfile
1229 local fid=$(copy_file /etc/hosts $f)
1231 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1232 wait_request_state $fid ARCHIVE SUCCEED
1233 $LFS hsm_release $f || error "release of $f failed"
1235 do_node $CLIENT2 diff -q /etc/hosts $f
1238 # we check we had a restore done
1239 wait_request_state $fid RESTORE SUCCEED
1241 [[ $st -eq 0 ]] || error "Restored file differs"
1245 run_test 12h "Restore a released file implicitly from a second node"
1248 # test needs a running copytool
1252 local f=$DIR/$tdir/$tfile
1253 local fid=$(copy_file /etc/passwd $f)
1254 $LFS hsm_archive $f || error "archive of $f failed"
1255 wait_request_state $fid ARCHIVE SUCCEED
1257 $LFS hsm_release $f || error "release of $f failed"
1261 [[ $? -eq 0 ]] || error "Restored file differs"
1265 run_test 12m "Archive/release/implicit restore"
1268 # test needs a running copytool
1272 copy2archive /etc/hosts $tdir/$tfile
1274 local f=$DIR/$tdir/$tfile
1275 import_file $tdir/$tfile $f
1277 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1278 error "Restored file differs"
1280 $LFS hsm_release $f || error "release of $f failed"
1284 run_test 12n "Import/implicit restore/release"
1287 # test needs a running copytool
1291 local f=$DIR/$tdir/$tfile
1292 local fid=$(copy_file /etc/hosts $f)
1294 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1295 wait_request_state $fid ARCHIVE SUCCEED
1296 $LFS hsm_release $f || error "release of $f failed"
1298 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1299 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1301 # set no retry action mode
1304 diff -q /etc/hosts $f
1307 # we check we had a restore failure
1308 wait_request_state $fid RESTORE FAILED
1310 [[ $st -eq 0 ]] && error "Restore must fail"
1312 # remove no retry action mode
1315 # check file is still released
1316 check_hsm_flags $f "0x0000000d"
1318 # retry w/o failure injection
1319 do_facet $SINGLEMDS lctl set_param fail_loc=0
1321 # to be sure previous RESTORE result is gone
1323 wait_for_grace_delay
1325 diff -q /etc/hosts $f
1328 # we check we had a restore done
1329 wait_request_state $fid RESTORE SUCCEED
1331 [[ $st -eq 0 ]] || error "Restored file differs"
1335 run_test 12o "Layout-swap failure during Restore leaves file released"
1338 # test needs a running copytool
1341 local ARC_SUBDIR="import.orig"
1345 # populate directory to be imported
1346 for d in $(seq 1 10); do
1347 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1348 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1349 for f in $(seq 1 10); do
1350 CURR_FILE="$CURR_DIR/$tfile.$f"
1351 # write file-specific data
1352 do_facet $SINGLEAGT \
1353 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1354 "file=$CURR_FILE > $CURR_FILE"
1358 import_file "$ARC_SUBDIR" $DIR/$tdir
1359 # diff lustre content and origin (triggers file restoration)
1360 # there must be 10x10 identical files, and no difference
1361 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1362 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1363 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1364 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1366 [ $cnt_diff -eq 0 ] ||
1367 error "$cnt_diff imported files differ from read data"
1368 [ $cnt_ok -eq 100 ] ||
1369 error "not enough identical files ($cnt_ok != 100)"
1373 run_test 13 "Recursively import and restore a directory"
1376 # test needs a running copytool
1381 local f=$DIR/$tdir/$tfile
1382 local fid=$(make_small $f)
1383 local sum=$(md5sum $f | awk '{print $1}')
1384 $LFS hsm_archive $f || error "could not archive file"
1385 wait_request_state $fid ARCHIVE SUCCEED
1389 # create released file (simulate llapi_hsm_import call)
1391 local fid2=$(path2fid $f)
1392 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1393 $LFS hsm_release $f || error "could not release file"
1395 # rebind the archive to the newly created file
1396 echo "rebind $fid to $fid2"
1398 do_facet $SINGLEAGT \
1399 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1400 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1402 # restore file and compare md5sum
1403 local sum2=$(md5sum $f | awk '{print $1}')
1405 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1409 run_test 14 "Rebind archived file to a new fid"
1412 # test needs a running copytool
1417 local f=$DIR/$tdir/$tfile
1419 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1423 for i in $(seq 1 $count); do
1424 fids[$i]=$(make_small $f.$i)
1425 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1426 $LFS hsm_archive $f.$i || error "could not archive file"
1428 wait_all_done $(($count*60))
1432 for i in $(seq 1 $count); do
1435 local fid2=$(path2fid $f.$i)
1436 # add the rebind operation to the list
1437 echo ${fids[$i]} $fid2 >> $tmpfile
1439 # set it released (simulate llapi_hsm_import call)
1440 $LFS hsm_set --archived --exists $f.$i ||
1441 error "could not force hsm flags"
1442 $LFS hsm_release $f.$i || error "could not release file"
1444 nl=$(wc -l < $tmpfile)
1445 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1447 echo "rebind list of files"
1448 do_facet $SINGLEAGT \
1449 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1450 --rebind $tmpfile $DIR" || error "could not rebind file list"
1452 # restore files and compare md5sum
1453 for i in $(seq 1 $count); do
1454 local sum2=$(md5sum $f.$i | awk '{print $1}')
1455 [[ $sum2 == ${sums[$i]} ]] ||
1456 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1462 run_test 15 "Rebind a list of files"
1465 # test needs a running copytool
1469 # create a known size file so we can verify transfer speed
1472 dd if=/dev/zero of=$ref bs=1M count=20
1475 local f=$DIR/$tdir/$tfile
1476 local fid=$(copy_file $ref $f)
1478 local start=$(date +%s)
1480 wait_request_state $fid ARCHIVE SUCCEED
1481 local end=$(date +%s)
1482 local duration=$((end - start))
1484 [[ $duration -ge $goal ]] ||
1485 error "Transfer is too fast $duration < $goal"
1489 run_test 16 "Test CT bandwith control option"
1494 local f=$DIR/$tdir/$tfile
1495 touch $f || error "touch $f failed"
1497 # Could not release a non-archived file
1498 $LFS hsm_release $f && error "release should not succeed"
1500 # For following tests, we must test them with HS_ARCHIVED set
1501 $LFS hsm_set --exists --archived $f || error "could not add flag"
1503 # Could not release a file if no-release is set
1504 $LFS hsm_set --norelease $f || error "could not add flag"
1505 $LFS hsm_release $f && error "release should not succeed"
1506 $LFS hsm_clear --norelease $f || error "could not remove flag"
1508 # Could not release a file if lost
1509 $LFS hsm_set --lost $f || error "could not add flag"
1510 $LFS hsm_release $f && error "release should not succeed"
1511 $LFS hsm_clear --lost $f || error "could not remove flag"
1513 # Could not release a file if dirty
1514 $LFS hsm_set --dirty $f || error "could not add flag"
1515 $LFS hsm_release $f && error "release should not succeed"
1516 $LFS hsm_clear --dirty $f || error "could not remove flag"
1518 run_test 20 "Release is not permitted"
1521 # test needs a running copytool
1525 local f=$DIR/$tdir/test_release
1527 # Create a file and check its states
1528 local fid=$(make_small $f)
1529 check_hsm_flags $f "0x00000000"
1531 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1532 # used until file is flushed to disk
1533 if [ $(facet_fstype ost1) == "zfs" ]; then
1534 # this causes an OST_SYNC rpc to be sent
1535 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1536 # clear locks to reread file data
1537 cancel_lru_locks osc
1540 local orig_size=$(stat -c "%s" $f)
1541 local orig_blocks=$(stat -c "%b" $f)
1543 start_full_debug_logging
1545 $LFS hsm_archive $f || error "could not archive file"
1546 wait_request_state $fid ARCHIVE SUCCEED
1548 local blocks=$(stat -c "%b" $f)
1549 [ $blocks -eq $orig_blocks ] ||
1550 error "$f: wrong block number after archive: " \
1551 "$blocks != $orig_blocks"
1552 local size=$(stat -c "%s" $f)
1553 [ $size -eq $orig_size ] ||
1554 error "$f: wrong size after archive: $size != $orig_size"
1556 # Release and check states
1557 $LFS hsm_release $f || error "could not release file"
1558 check_hsm_flags $f "0x0000000d"
1560 blocks=$(stat -c "%b" $f)
1561 [ $blocks -gt 5 ] &&
1562 error "$f: too many blocks after release: $blocks > 5"
1563 size=$(stat -c "%s" $f)
1564 [ $size -ne $orig_size ] &&
1565 error "$f: wrong size after release: $size != $orig_size"
1567 # Check we can release an file without stripe info
1571 check_hsm_flags $f "0x00000000"
1572 $LFS hsm_archive $f || error "could not archive file"
1573 wait_request_state $fid ARCHIVE SUCCEED
1575 # Release and check states
1576 $LFS hsm_release $f || error "could not release file"
1577 check_hsm_flags $f "0x0000000d"
1579 # Release again a file that is already released is OK
1580 $LFS hsm_release $f || fail "second release should succeed"
1581 check_hsm_flags $f "0x0000000d"
1583 stop_full_debug_logging
1587 run_test 21 "Simple release tests"
1590 # test needs a running copytool
1595 local f=$DIR/$tdir/test_release
1596 local swap=$DIR/$tdir/test_swap
1598 # Create a file and check its states
1599 local fid=$(make_small $f)
1600 check_hsm_flags $f "0x00000000"
1602 $LFS hsm_archive $f || error "could not archive file"
1603 wait_request_state $fid ARCHIVE SUCCEED
1605 # Release and check states
1606 $LFS hsm_release $f || error "could not release file"
1607 check_hsm_flags $f "0x0000000d"
1610 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1615 run_test 22 "Could not swap a release file"
1618 # test needs a running copytool
1623 local f=$DIR/$tdir/test_mtime
1625 # Create a file and check its states
1626 local fid=$(make_small $f)
1627 check_hsm_flags $f "0x00000000"
1629 $LFS hsm_archive $f || error "could not archive file"
1630 wait_request_state $fid ARCHIVE SUCCEED
1632 # Set modification time in the past
1633 touch -m -a -d @978261179 $f
1635 # Release and check states
1636 $LFS hsm_release $f || error "could not release file"
1637 check_hsm_flags $f "0x0000000d"
1639 local MTIME=$(stat -c "%Y" $f)
1640 local ATIME=$(stat -c "%X" $f)
1641 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1642 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1646 run_test 23 "Release does not change a/mtime (utime)"
1649 local file=$DIR/$tdir/$tfile
1658 # test needs a running copytool
1663 fid=$(make_small $file)
1665 # Create a file and check its states
1666 check_hsm_flags $file "0x00000000"
1668 # Ensure atime is less than mtime and ctime.
1672 atime0=$(stat -c "%X" $file)
1673 mtime0=$(stat -c "%Y" $file)
1674 ctime0=$(stat -c "%Z" $file)
1676 [ $atime0 -lt $mtime0 ] ||
1677 error "atime $atime0 is not less than mtime $mtime0"
1679 [ $atime0 -lt $ctime0 ] ||
1680 error "atime $atime0 is not less than ctime $ctime0"
1682 # Archive should not change any timestamps.
1683 $LFS hsm_archive $file || error "cannot archive '$file'"
1684 wait_request_state $fid ARCHIVE SUCCEED
1686 atime1=$(stat -c "%X" $file)
1687 mtime1=$(stat -c "%Y" $file)
1688 ctime1=$(stat -c "%Z" $file)
1690 [ $atime0 -eq $atime1 ] ||
1691 error "archive changed atime from $atime0 to $atime1"
1693 [ $mtime0 -eq $mtime1 ] ||
1694 error "archive changed mtime from $mtime0 to $mtime1"
1696 [ $ctime0 -eq $ctime1 ] ||
1697 error "archive changed ctime from $ctime0 to $ctime1"
1699 # Release should not change any timestamps.
1700 $LFS hsm_release $file || error "cannot release '$file'"
1701 check_hsm_flags $file "0x0000000d"
1703 atime1=$(stat -c "%X" $file)
1704 mtime1=$(stat -c "%Y" $file)
1705 ctime1=$(stat -c "%Z" $file)
1707 [ $atime0 -eq $atime1 ] ||
1708 error "release changed atime from $atime0 to $atime1"
1710 [ $mtime0 -eq $mtime1 ] ||
1711 error "release changed mtime from $mtime0 to $mtime1"
1713 [ $ctime0 -eq $ctime1 ] ||
1714 error "release changed ctime from $ctime0 to $ctime1"
1716 # Restore should not change atime or mtime and should not
1718 $LFS hsm_restore $file
1719 wait_request_state $fid RESTORE SUCCEED
1721 atime1=$(stat -c "%X" $file)
1722 mtime1=$(stat -c "%Y" $file)
1723 ctime1=$(stat -c "%Z" $file)
1725 [ $atime0 -eq $atime1 ] ||
1726 error "restore changed atime from $atime0 to $atime1"
1728 [ $mtime0 -eq $mtime1 ] ||
1729 error "restore changed mtime from $mtime0 to $mtime1"
1731 [ $ctime0 -le $ctime1 ] ||
1732 error "restore changed ctime from $ctime0 to $ctime1"
1736 # Once more, after unmount and mount.
1737 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1738 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1740 atime1=$(stat -c "%X" $file)
1741 mtime1=$(stat -c "%Y" $file)
1742 ctime1=$(stat -c "%Z" $file)
1744 [ $atime0 -eq $atime1 ] ||
1745 error "remount changed atime from $atime0 to $atime1"
1747 [ $mtime0 -eq $mtime1 ] ||
1748 error "remount changed mtime from $mtime0 to $mtime1"
1750 [ $ctime0 -le $ctime1 ] ||
1751 error "remount changed ctime from $ctime0 to $ctime1"
1753 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1756 local file=$DIR/$tdir/$tfile
1762 # Test needs a running copytool.
1766 # Check that root can do HSM actions on a ordinary user's file.
1768 fid=$(make_small $file)
1769 sum0=$(md5sum $file)
1771 chown $RUNAS_ID:$RUNAS_GID $file ||
1772 error "cannot chown '$file' to '$RUNAS_ID'"
1774 chmod ugo-w $DIR/$tdir ||
1775 error "cannot chmod '$DIR/$tdir'"
1777 $LFS hsm_archive $file
1778 wait_request_state $fid ARCHIVE SUCCEED
1780 $LFS hsm_release $file
1781 check_hsm_flags $file "0x0000000d"
1783 $LFS hsm_restore $file
1784 wait_request_state $fid RESTORE SUCCEED
1786 # Check that ordinary user can get HSM state.
1787 $RUNAS $LFS hsm_state $file ||
1788 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1790 $LFS hsm_release $file
1791 check_hsm_flags $file "0x0000000d"
1793 # Check that ordinary user can accessed released file.
1794 sum1=$($RUNAS md5sum $file) ||
1795 error "user '$RUNAS_ID' cannot read '$file'"
1797 [ "$sum0" == "$sum1" ] ||
1798 error "md5sum mismatch for '$file'"
1802 run_test 24b "root can archive, release, and restore user files"
1804 cleanup_test_24c() {
1806 set_hsm_param user_request_mask RESTORE
1807 set_hsm_param group_request_mask RESTORE
1808 set_hsm_param other_request_mask RESTORE
1812 local file=$DIR/$tdir/$tfile
1813 local action=archive
1818 # test needs a running copytool
1823 # Save the default masks and check that cleanup_24c will
1824 # restore the request masks correctly.
1825 user_save=$(get_hsm_param user_request_mask)
1826 group_save=$(get_hsm_param group_request_mask)
1827 other_save=$(get_hsm_param other_request_mask)
1829 [ "$user_save" == RESTORE ] ||
1830 error "user_request_mask is '$user_save' expected 'RESTORE'"
1831 [ "$group_save" == RESTORE ] ||
1832 error "group_request_mask is '$group_save' expected 'RESTORE'"
1833 [ "$other_save" == RESTORE ] ||
1834 error "other_request_mask is '$other_save' expected 'RESTORE'"
1836 trap cleanup_test_24c EXIT
1841 chown $RUNAS_ID:nobody $file ||
1842 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1844 set_hsm_param user_request_mask ""
1845 $RUNAS $LFS hsm_$action $file &&
1846 error "$action by user should fail"
1848 set_hsm_param user_request_mask $action
1849 $RUNAS $LFS hsm_$action $file ||
1850 error "$action by user should succeed"
1855 chown nobody:$RUNAS_GID $file ||
1856 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1858 set_hsm_param group_request_mask ""
1859 $RUNAS $LFS hsm_$action $file &&
1860 error "$action by group should fail"
1862 set_hsm_param group_request_mask $action
1863 $RUNAS $LFS hsm_$action $file ||
1864 error "$action by group should succeed"
1869 chown nobody:nobody $file ||
1870 error "cannot chown '$file' to 'nobody:nobody'"
1872 set_hsm_param other_request_mask ""
1873 $RUNAS $LFS hsm_$action $file &&
1874 error "$action by other should fail"
1876 set_hsm_param other_request_mask $action
1877 $RUNAS $LFS hsm_$action $file ||
1878 error "$action by other should succeed"
1883 run_test 24c "check that user,group,other request masks work"
1885 cleanup_test_24d() {
1887 mount -o remount,rw $MOUNT2
1891 local file1=$DIR/$tdir/$tfile
1892 local file2=$DIR2/$tdir/$tfile
1900 fid1=$(make_small $file1)
1902 trap cleanup_test_24d EXIT
1904 mount -o remount,ro $MOUNT2
1906 fid2=$(path2fid $file2)
1907 [ "$fid1" == "$fid2" ] ||
1908 error "FID mismatch '$fid1' != '$fid2'"
1910 $LFS hsm_archive $file2 &&
1911 error "archive should fail on read-only mount"
1912 check_hsm_flags $file1 "0x00000000"
1914 $LFS hsm_archive $file1
1915 wait_request_state $fid1 ARCHIVE SUCCEED
1917 $LFS hsm_release $file1
1918 $LFS hsm_restore $file2
1919 wait_request_state $fid1 RESTORE SUCCEED
1921 $LFS hsm_release $file1 || error "cannot release '$file1'"
1922 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1924 $LFS hsm_release $file2 &&
1925 error "release should fail on read-only mount"
1930 run_test 24d "check that read-only mounts are respected"
1933 # test needs a running copytool
1937 copy2archive /etc/hosts $tdir/$tfile
1939 local f=$DIR/$tdir/$tfile
1941 import_file $tdir/$tfile $f
1943 $LFS hsm_set --lost $f
1948 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1952 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1953 " (Operation not permitted)"
1956 # test needs a running copytool
1961 local f=$DIR/$tdir/$tfile
1962 local fid=$(copy_file /etc/passwd $f)
1964 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1965 wait_request_state $fid ARCHIVE SUCCEED
1968 $LFS hsm_set --lost $f
1972 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1976 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1977 " (Operation not permitted)"
1980 # test needs a running copytool
1984 local f=$DIR/$tdir/$tfile
1985 local fid=$(make_large_for_progress $f)
1986 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1987 wait_request_state $fid ARCHIVE SUCCEED
1990 wait_request_state $fid REMOVE SUCCEED
1992 check_hsm_flags $f "0x00000000"
1996 run_test 26 "Remove the archive of a valid file"
1999 # test needs a running copytool
2003 make_archive $tdir/$tfile
2004 local f=$DIR/$tdir/$tfile
2005 import_file $tdir/$tfile $f
2006 local fid=$(path2fid $f)
2010 [[ $? != 0 ]] || error "Remove of a released file should fail"
2014 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2017 # test needs a running copytool
2021 local f=$DIR/$tdir/$tfile
2022 local fid=$(make_large_for_progress $f)
2023 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2024 wait_request_state $fid ARCHIVE SUCCEED
2029 [[ $? != 0 ]] || error "Remove of a released file should fail"
2033 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2036 # test needs a running copytool
2040 local f=$DIR/$tdir/$tfile
2041 local fid=$(make_large_for_progress $f)
2042 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2043 wait_request_state $fid ARCHIVE SUCCEED
2052 wait_request_state $fid REMOVE SUCCEED
2056 run_test 28 "Concurrent archive/file remove"
2059 # restore at exec cannot work on agent node (because of Linux kernel
2060 # protection of executables)
2061 needclients 2 || return 0
2063 # test needs a running copytool
2067 copy2archive /bin/true $tdir/$tfile
2069 local f=$DIR/$tdir/true
2070 import_file $tdir/$tfile $f
2072 local fid=$(path2fid $f)
2074 # set no retry action mode
2080 # remove no try action mode
2084 [[ $st == 0 ]] || error "Failed to exec a released file"
2088 run_test 30a "Restore at exec (import case)"
2091 # restore at exec cannot work on agent node (because of Linux kernel
2092 # protection of executables)
2093 needclients 2 || return 0
2095 # test needs a running copytool
2099 local f=$DIR/$tdir/true
2100 local fid=$(copy_file /bin/true $f)
2102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2103 wait_request_state $fid ARCHIVE SUCCEED
2106 # set no retry action mode
2112 # remove no try action mode
2116 [[ $st == 0 ]] || error "Failed to exec a released file"
2120 run_test 30b "Restore at exec (release case)"
2123 needclients 2 || return 0
2125 # test needs a running copytool
2129 local f=$DIR/$tdir/SLEEP
2130 local fid=$(copy_file /bin/sleep $f)
2132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2133 wait_request_state $fid ARCHIVE SUCCEED
2135 check_hsm_flags $f "0x0000000d"
2136 # set no retry action mode
2138 do_node $CLIENT2 "$f 10" &
2142 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2144 [[ $? == 0 ]] || error "Execution failed during run"
2146 [[ $? == 0 ]] || error "Binary overwritten during exec"
2149 # remove no try action mode
2151 check_hsm_flags $f "0x00000009"
2155 run_test 30c "Update during exec of released file must fail"
2157 restore_and_check_size() {
2160 local s=$(stat -c "%s" $f)
2162 local st=$(get_hsm_flags $f)
2166 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2168 n=$(stat -c "%s" $f)
2169 # we echo in both cases to show stat is not
2171 if [[ $n != $s ]]; then
2172 echo "size seen is $n != $s"
2175 echo "size seen is right: $n == $s"
2177 st=$(get_hsm_flags $f)
2181 if [[ $cpt -lt 10 ]]; then
2184 echo " restore is too long"
2185 wait_request_state $fid RESTORE SUCCEED
2191 # test needs a running copytool
2196 make_archive $tdir/$tfile
2197 local f=$DIR/$tdir/$tfile
2198 import_file $tdir/$tfile $f
2199 local fid=$($LFS path2fid $f)
2200 HSM_ARCHIVE_PURGE=false copytool_setup
2202 restore_and_check_size $f $fid
2205 [[ $err -eq 0 ]] || error "File size changed during restore"
2209 run_test 31a "Import a large file and check size during restore"
2213 # test needs a running copytool
2218 local f=$DIR/$tdir/$tfile
2219 local fid=$(make_large_for_progress $f)
2220 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2221 wait_request_state $fid ARCHIVE SUCCEED
2224 restore_and_check_size $f $fid
2227 [[ $err -eq 0 ]] || error "File size changed during restore"
2231 run_test 31b "Restore a large unaligned file and check size during restore"
2234 # test needs a running copytool
2239 local f=$DIR/$tdir/$tfile
2240 local fid=$(make_large_for_progress_aligned $f)
2241 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2242 wait_request_state $fid ARCHIVE SUCCEED
2245 restore_and_check_size $f $fid
2248 [[ $err -eq 0 ]] || error "File size changed during restore"
2252 run_test 31c "Restore a large aligned file and check size during restore"
2255 # test needs a running copytool
2260 local f=$DIR/$tdir/$tfile
2261 local fid=$(make_large_for_progress $f)
2262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2263 wait_request_state $fid ARCHIVE SUCCEED
2266 # to be sure wait_all_done will not be mislead by previous tests
2269 wait_for_grace_delay
2270 # Also raise grace_delay significantly so the Canceled
2271 # Restore action will stay enough long avail.
2272 local old_grace=$(get_hsm_param grace_delay)
2273 set_hsm_param grace_delay 100
2275 md5sum $f >/dev/null &
2277 wait_request_state $fid RESTORE STARTED
2282 # Check restore trigger process was killed
2283 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2287 # instead of waiting+checking both Restore and Cancel ops
2288 # sequentially, wait for both to be finished and then check
2290 wait_all_done 100 $fid
2291 local rstate=$(get_request_state $fid RESTORE)
2292 local cstate=$(get_request_state $fid CANCEL)
2294 # restore orig grace_delay.
2295 set_hsm_param grace_delay $old_grace
2297 if [[ "$rstate" == "CANCELED" ]] ; then
2298 [[ "$cstate" == "SUCCEED" ]] ||
2299 error "Restore state is CANCELED and Cancel state " \
2300 "is not SUCCEED but $cstate"
2301 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2302 elif [[ "$rstate" == "SUCCEED" ]] ; then
2303 [[ "$cstate" == "FAILED" ]] ||
2304 error "Restore state is SUCCEED and Cancel state " \
2305 "is not FAILED but $cstate"
2306 echo "Restore state is SUCCEED, Cancel state is FAILED"
2308 error "Restore state is $rstate and Cancel state is $cstate"
2312 error "Cannot kill process waiting for restore ($killed)"
2316 run_test 33 "Kill a restore waiting process"
2319 # test needs a running copytool
2324 local f=$DIR/$tdir/$tfile
2325 local fid=$(make_large_for_progress $f)
2326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2327 wait_request_state $fid ARCHIVE SUCCEED
2330 md5sum $f >/dev/null &
2332 wait_request_state $fid RESTORE STARTED
2334 rm $f || error "rm $f failed"
2335 # rm must not block during restore
2336 wait_request_state $fid RESTORE STARTED
2338 wait_request_state $fid RESTORE SUCCEED
2339 # check md5sum pgm finished
2340 local there=$(ps -o pid,comm hp $pid >/dev/null)
2341 [[ -z $there ]] || error "Restore initiator does not exit"
2343 local rc=$(wait $pid)
2344 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2348 run_test 34 "Remove file during restore"
2351 # test needs a running copytool
2356 local f=$DIR/$tdir/$tfile
2357 local f1=$DIR/$tdir/$tfile-1
2358 local fid=$(make_large_for_progress $f)
2359 local fid1=$(copy_file /etc/passwd $f1)
2360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2361 wait_request_state $fid ARCHIVE SUCCEED
2364 md5sum $f >/dev/null &
2366 wait_request_state $fid RESTORE STARTED
2368 mv $f1 $f || error "mv $f1 $f failed"
2369 # mv must not block during restore
2370 wait_request_state $fid RESTORE STARTED
2372 wait_request_state $fid RESTORE SUCCEED
2373 # check md5sum pgm finished
2374 local there=$(ps -o pid,comm hp $pid >/dev/null)
2375 [[ -z $there ]] || error "Restore initiator does not exit"
2377 local rc=$(wait $pid)
2378 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2381 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2385 run_test 35 "Overwrite file during restore"
2388 # test needs a running copytool
2393 local f=$DIR/$tdir/$tfile
2394 local fid=$(make_large_for_progress $f)
2395 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2396 wait_request_state $fid ARCHIVE SUCCEED
2399 md5sum $f >/dev/null &
2401 wait_request_state $fid RESTORE STARTED
2404 # rm must not block during restore
2405 wait_request_state $fid RESTORE STARTED
2407 wait_request_state $fid RESTORE SUCCEED
2408 # check md5sum pgm finished
2409 local there=$(ps -o pid,comm hp $pid >/dev/null)
2411 error "Restore initiator does not exit"
2413 local rc=$(wait $pid)
2415 error "Restore initiator failed with $rc"
2419 run_test 36 "Move file during restore"
2426 for n in $(seq 1 $count); do
2427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2429 echo "$count archive requests submitted"
2433 local stream_count=4
2434 local file_count=100
2436 local f=$DIR/$tdir/$tfile
2441 for i in $(seq 1 $file_count); do
2442 for p in $(seq 1 $stream_count); do
2443 fid=$(copy_file /etc/hosts $f.$p.$i)
2446 # force copytool to use a local/temp archive dir to ensure best
2447 # performance vs remote/NFS mounts used in auto-tests
2448 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2451 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2453 # to be sure wait_all_done will not be mislead by previous tests
2455 wait_for_grace_delay
2457 # start archive streams in background (archive files in parallel)
2458 for p in $(seq 1 $stream_count); do
2459 multi_archive $f.$p $file_count &
2462 echo -n "Wait for all requests being enqueued..."
2468 run_test 40 "Parallel archive requests"
2471 # test needs a running copytool
2475 local f=$DIR/$tdir/$tfile
2476 local fid=$(copy_file /etc/motd $f 1)
2478 $LFS hsm_archive $f || error "could not archive file"
2479 wait_request_state $fid ARCHIVE SUCCEED
2480 check_hsm_flags $f "0x00000009"
2482 multiop_bg_pause $f O_c || error "multiop failed"
2486 client_up || client_up || true
2488 kill -USR1 $MULTIPID
2489 wait $MULTIPID || error "multiop close failed"
2491 check_hsm_flags $f "0x0000000b"
2495 run_test 52 "Opened for write file on an evicted client should be set dirty"
2498 # test needs a running copytool
2502 local f=$DIR/$tdir/$tfile
2503 local fid=$(copy_file /etc/motd $f 1)
2505 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2506 error "could not archive file"
2507 wait_request_state $fid ARCHIVE SUCCEED
2508 check_hsm_flags $f "0x00000009"
2510 multiop_bg_pause $f o_c || error "multiop failed"
2514 client_up || client_up || true
2516 kill -USR1 $MULTIPID
2517 wait $MULTIPID || error "multiop close failed"
2519 check_hsm_flags $f "0x00000009"
2523 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2526 # test needs a running copytool
2530 local f=$DIR/$tdir/$tfile
2531 local fid=$(make_small $f)
2533 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2534 error "could not archive file"
2535 wait_request_state $fid ARCHIVE STARTED
2537 check_hsm_flags $f "0x00000001"
2539 # Avoid coordinator resending this request as soon it has failed.
2544 wait_request_state $fid ARCHIVE FAILED
2546 check_hsm_flags $f "0x00000003"
2551 run_test 54 "Write during an archive cancels it"
2554 # test needs a running copytool
2558 local f=$DIR/$tdir/$tfile
2559 local fid=$(make_small $f)
2561 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2562 error "could not archive file"
2563 wait_request_state $fid ARCHIVE STARTED
2565 check_hsm_flags $f "0x00000001"
2567 # Avoid coordinator resending this request as soon it has failed.
2570 $TRUNCATE $f 1024 || error "truncate failed"
2572 wait_request_state $fid ARCHIVE FAILED
2574 check_hsm_flags $f "0x00000003"
2579 run_test 55 "Truncate during an archive cancels it"
2582 # test needs a running copytool
2586 local f=$DIR/$tdir/$tfile
2587 local fid=$(make_large_for_progress $f)
2589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2590 error "could not archive file"
2591 wait_request_state $fid ARCHIVE STARTED
2593 check_hsm_flags $f "0x00000001"
2595 # Change metadata and sync to be sure we are not changing only
2600 wait_request_state $fid ARCHIVE SUCCEED
2602 check_hsm_flags $f "0x00000009"
2606 run_test 56 "Setattr during an archive is ok"
2609 # Need one client for I/O, one for request
2610 needclients 2 || return 0
2612 # test needs a running copytool
2616 local f=$DIR/$tdir/test_archive_remote
2617 # Create a file on a remote node
2618 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2619 "count=2 conv=fsync"
2622 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2623 error "hsm_archive failed"
2624 local fid=$(path2fid $f)
2625 wait_request_state $fid ARCHIVE SUCCEED
2627 # Release and implicit restore it
2628 do_node $CLIENT2 "$LFS hsm_release $f" ||
2629 error "hsm_release failed"
2630 do_node $CLIENT2 "md5sum $f" ||
2631 error "hsm_restore failed"
2633 wait_request_state $fid RESTORE SUCCEED
2637 run_test 57 "Archive a file with dirty cache on another node"
2639 truncate_released_file() {
2643 local sz=$(stat -c %s $src_file)
2644 local f=$DIR/$tdir/$tfile
2645 local fid=$(copy_file $1 $f)
2649 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2650 error "could not archive file"
2651 wait_request_state $fid ARCHIVE SUCCEED
2653 $LFS hsm_release $f || error "could not release file"
2655 $TRUNCATE $f $trunc_to || error "truncate failed"
2658 local sz1=$(stat -c %s $f)
2659 [[ $sz1 == $trunc_to ]] ||
2660 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2663 check_hsm_flags $f "0x0000000b"
2665 local state=$(get_request_state $fid RESTORE)
2666 [[ "$state" == "SUCCEED" ]] ||
2667 error "truncate $sz does not trig restore, state = $state"
2669 $TRUNCATE $ref $trunc_to
2670 cmp $ref $f || error "file data wrong after truncate"
2676 # test needs a running copytool
2681 local sz=$(stat -c %s /etc/passwd)
2683 echo "truncate up from $sz to $((sz*2))"
2684 truncate_released_file /etc/passwd $((sz*2))
2686 echo "truncate down from $sz to $((sz/2))"
2687 truncate_released_file /etc/passwd $((sz/2))
2689 echo "truncate to 0"
2690 truncate_released_file /etc/passwd 0
2694 run_test 58 "Truncate a released file will trigger restore"
2697 # This test validates the fix for LU-4512. Ensure that the -u
2698 # option changes the progress reporting interval from the default
2699 # (30 seconds) to the user-specified interval.
2701 local progress_timeout=$((interval * 3))
2703 # test needs a new running copytool
2705 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2708 local f=$DIR/$tdir/$tfile
2709 local fid=$(make_large_for_progress $f)
2711 local start_at=$(date +%s)
2712 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2713 error "could not archive file"
2716 local mdt=${MDT_PREFIX}${mdtidx}
2717 local mds=mds$((mdtidx + 1))
2719 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2720 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2726 echo -n "Expecting a progress update within $progress_timeout seconds... "
2728 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2729 if [ $RESULT -gt 0 ]; then
2730 echo "$RESULT bytes copied in $WAIT seconds."
2732 elif [ $WAIT -ge $progress_timeout ]; then
2733 error "Timed out waiting for progress update!"
2736 WAIT=$((WAIT + sleep))
2740 local finish_at=$(date +%s)
2741 local elapsed=$((finish_at - start_at))
2743 # Ensure that the progress update occurred within the expected window.
2744 if [ $elapsed -lt $interval ]; then
2745 error "Expected progress update after at least $interval seconds"
2751 run_test 60 "Changing progress update interval from default"
2754 # test needs a new running copytool
2756 copytool_monitor_setup
2757 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2759 # Just start and stop the copytool to generate events.
2762 # Wait for the copytool to register.
2763 wait_update --verbose $(facet_active_host mds1) \
2764 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2766 error "copytool failed to register with MDT0000"
2770 local REGISTER_EVENT
2771 local UNREGISTER_EVENT
2772 while read event; do
2773 local parsed=$(parse_json_event "$event")
2774 if [ -z "$parsed" ]; then
2775 error "Copytool sent malformed event: $event"
2779 if [ $event_type == "REGISTER" ]; then
2780 REGISTER_EVENT=$event
2781 elif [ $event_type == "UNREGISTER" ]; then
2782 UNREGISTER_EVENT=$event
2784 done < <(echo $"$(get_copytool_event_log)")
2786 if [ -z "$REGISTER_EVENT" ]; then
2787 error "Copytool failed to send register event to FIFO"
2790 if [ -z "$UNREGISTER_EVENT" ]; then
2791 error "Copytool failed to send unregister event to FIFO"
2794 copytool_monitor_cleanup
2795 echo "Register/Unregister events look OK."
2797 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2800 # Bump progress interval for livelier events.
2803 # test needs a new running copytool
2805 copytool_monitor_setup
2806 HSMTOOL_UPDATE_INTERVAL=$interval \
2807 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2810 local f=$DIR/$tdir/$tfile
2811 local fid=$(make_large_for_progress $f)
2813 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2814 error "could not archive file"
2815 wait_request_state $fid ARCHIVE SUCCEED
2817 local expected_fields="event_time data_fid source_fid"
2818 expected_fields+=" total_bytes current_bytes"
2822 while read event; do
2823 # Make sure we're not getting anything from previous events.
2824 for field in $expected_fields; do
2828 local parsed=$(parse_json_event "$event")
2829 if [ -z "$parsed" ]; then
2830 error "Copytool sent malformed event: $event"
2834 if [ $event_type == "ARCHIVE_START" ]; then
2837 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2840 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2844 # Do some simple checking of the progress update events.
2845 for expected_field in $expected_fields; do
2846 if [ -z ${!expected_field+x} ]; then
2847 error "Missing $expected_field field in event"
2851 if [ $total_bytes -eq 0 ]; then
2852 error "Expected total_bytes to be > 0"
2855 # These should be identical throughout an archive
2857 if [ $source_fid != $data_fid ]; then
2858 error "Expected source_fid to equal data_fid"
2860 done < <(echo $"$(get_copytool_event_log)")
2862 if [ -z "$START_EVENT" ]; then
2863 error "Copytool failed to send archive start event to FIFO"
2866 if [ -z "$FINISH_EVENT" ]; then
2867 error "Copytool failed to send archive finish event to FIFO"
2870 echo "Archive events look OK."
2874 copytool_monitor_cleanup
2876 run_test 71 "Copytool logs JSON archive events to FIFO"
2879 # Bump progress interval for livelier events.
2882 # test needs a new running copytool
2884 copytool_monitor_setup
2885 HSMTOOL_UPDATE_INTERVAL=$interval \
2886 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2887 local test_file=$HSMTOOL_MONITOR_DIR/file
2889 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2891 do_facet $SINGLEAGT "$cmd" ||
2892 error "cannot create $test_file on $SINGLEAGT"
2893 copy2archive $test_file $tdir/$tfile
2896 local f=$DIR/$tdir/$tfile
2897 import_file $tdir/$tfile $f
2898 f=$DIR2/$tdir/$tfile
2899 echo "Verifying released state: "
2900 check_hsm_flags $f "0x0000000d"
2902 local fid=$(path2fid $f)
2904 wait_request_state $fid RESTORE SUCCEED
2906 local expected_fields="event_time data_fid source_fid"
2907 expected_fields+=" total_bytes current_bytes"
2911 while read event; do
2912 # Make sure we're not getting anything from previous events.
2913 for field in $expected_fields; do
2917 local parsed=$(parse_json_event "$event")
2918 if [ -z "$parsed" ]; then
2919 error "Copytool sent malformed event: $event"
2923 if [ $event_type == "RESTORE_START" ]; then
2925 if [ $source_fid != $data_fid ]; then
2926 error "source_fid should == data_fid at start"
2929 elif [ $event_type == "RESTORE_FINISH" ]; then
2931 if [ $source_fid != $data_fid ]; then
2932 error "source_fid should == data_fid at finish"
2935 elif [ $event_type != "RESTORE_RUNNING" ]; then
2939 # Do some simple checking of the progress update events.
2940 for expected_field in $expected_fields; do
2941 if [ -z ${!expected_field+x} ]; then
2942 error "Missing $expected_field field in event"
2946 if [ $total_bytes -eq 0 ]; then
2947 error "Expected total_bytes to be > 0"
2950 # When a restore starts out, the data fid is the same as the
2951 # source fid. After the restore has gotten going, we learn
2952 # the new data fid. Once the restore has finished, the source
2953 # fid is set to the new data fid.
2955 # We test this because some monitoring software may depend on
2956 # this behavior. If it changes, then the consumers of these
2957 # events may need to be modified.
2958 if [ $source_fid == $data_fid ]; then
2959 error "source_fid should != data_fid during restore"
2961 done < <(echo $"$(get_copytool_event_log)")
2963 if [ -z "$START_EVENT" ]; then
2964 error "Copytool failed to send restore start event to FIFO"
2967 if [ -z "$FINISH_EVENT" ]; then
2968 error "Copytool failed to send restore finish event to FIFO"
2971 echo "Restore events look OK."
2975 copytool_monitor_cleanup
2979 run_test 72 "Copytool logs JSON restore events to FIFO"
2982 file_count=51 # Max number of files constrained by LNET message size
2983 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2984 local f=$DIR/$tdir/$tfile
2985 local FILELIST=/tmp/filelist.txt
2989 for i in $(seq 1 $file_count); do
2990 fid=$(copy_file /etc/hosts $f.$i)
2991 echo $f.$i >> $FILELIST
2994 # to be sure wait_all_done will not be mislead by previous tests
2996 wait_for_grace_delay
2997 $LFS hsm_archive --filelist $FILELIST ||
2998 error "cannot archive a file list"
3000 $LFS hsm_release --filelist $FILELIST ||
3001 error "cannot release a file list"
3002 $LFS hsm_restore --filelist $FILELIST ||
3003 error "cannot restore a file list"
3007 run_test 90 "Archive/restore a file list"
3009 double_verify_reset_hsm_param() {
3011 echo "Testing $HSM_PARAM.$p"
3012 local val=$(get_hsm_param $p)
3014 local val2=$(($val * 2))
3015 set_hsm_param $p $val2
3016 val=$(get_hsm_param $p)
3017 [[ $val == $val2 ]] ||
3018 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3019 echo "Set $p to 0 must failed"
3023 set_hsm_param $p $save
3025 if [[ $rc == 0 ]]; then
3026 error "we must not be able to set $HSM_PARAM.$p to 0"
3031 double_verify_reset_hsm_param loop_period
3032 double_verify_reset_hsm_param grace_delay
3033 double_verify_reset_hsm_param active_request_timeout
3034 double_verify_reset_hsm_param max_requests
3035 double_verify_reset_hsm_param default_archive_id
3037 run_test 100 "Set coordinator /proc tunables"
3044 run_test 102 "Verify coordinator control"
3047 # test needs a running copytool
3054 for i in $(seq 1 20); do
3055 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3057 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3061 echo "Current requests"
3062 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3063 $HSM_PARAM.actions |\
3064 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3066 [[ -z "$res" ]] || error "Some request have not been canceled"
3070 run_test 103 "Purge all requests"
3075 # test needs a running copytool
3079 local f=$DIR/$tdir/$tfile
3080 local fid=$(make_large_for_progress $f)
3081 # if cdt is on, it can serve too quickly the request
3083 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3084 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3085 $HSM_PARAM.actions |\
3086 grep $fid | cut -f16 -d=")
3089 [[ "$data1" == "$DATAHEX" ]] ||
3090 error "Data field in records is ($data1) and not ($DATAHEX)"
3094 run_test 104 "Copy tool data field"
3101 for i in $(seq -w 1 10); do
3102 cp /etc/passwd $DIR/$tdir/$i
3103 $LFS hsm_archive $DIR/$tdir/$i
3105 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3106 $HSM_PARAM.actions |\
3107 grep WAITING | wc -l")
3110 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3111 $HSM_PARAM.actions |\
3112 grep WAITING | wc -l")
3115 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3116 error "Requests count after shutdown $reqcnt2 != "\
3117 "before shutdown $reqcnt1"
3119 run_test 105 "Restart of coordinator"
3121 get_agent_by_uuid_mdt() {
3124 local mds=mds$(($mdtidx + 1))
3125 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3129 check_agent_registered_by_mdt() {
3132 local mds=mds$(($mdtidx + 1))
3133 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3134 if [[ ! -z "$agent" ]]; then
3135 echo "found agent $agent on $mds"
3137 error "uuid $uuid not found in agent list on $mds"
3141 check_agent_unregistered_by_mdt() {
3144 local mds=mds$(($mdtidx + 1))
3145 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3146 if [[ -z "$agent" ]]; then
3147 echo "uuid not found in agent list on $mds"
3149 error "uuid found in agent list on $mds: $agent"
3153 check_agent_registered() {
3156 for mdsno in $(seq 1 $MDSCOUNT); do
3157 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3161 check_agent_unregistered() {
3164 for mdsno in $(seq 1 $MDSCOUNT); do
3165 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3170 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3171 get_client_uuid $MOUNT | cut -d' ' -f2)
3174 check_agent_registered $uuid
3176 search_copytools || error "No copytool found"
3179 check_agent_unregistered $uuid
3182 check_agent_registered $uuid
3186 run_test 106 "Copytool register/unregister"
3189 # test needs a running copytool
3191 # create and archive file
3193 local f1=$DIR/$tdir/$tfile
3194 local fid=$(copy_file /etc/passwd $f1)
3195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3196 wait_request_state $fid ARCHIVE SUCCEED
3197 # shutdown and restart MDS
3199 # check the copytool still gets messages from MDT
3200 local f2=$DIR/$tdir/2
3201 local fid=$(copy_file /etc/passwd $f2)
3202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3203 # main check of this sanity: this request MUST succeed
3204 wait_request_state $fid ARCHIVE SUCCEED
3207 run_test 107 "Copytool re-register after MDS restart"
3209 policy_set_and_test()
3213 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3214 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3215 [[ "$policy" == "$target" ]] ||
3216 error "Wrong policy after '$change': '$policy' != '$target'"
3220 # to force default policy setting if error
3221 CDT_POLICY_HAD_CHANGED=true
3223 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3224 local default="NonBlockingRestore [NoRetryAction]"
3225 [[ "$policy" == "$default" ]] ||
3226 error "default policy has changed,"\
3227 " '$policy' != '$default' update the test"
3228 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3229 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3230 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3231 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3232 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3233 # useless bacause we know but safer for futur changes to use real value
3234 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3235 echo "Next set_param must failed"
3236 policy_set_and_test "wrong" "$policy"
3239 echo "Back to default policy"
3240 cdt_set_sanity_policy
3242 run_test 109 "Policy display/change"
3245 # test needs a running copytool
3250 copy2archive /etc/passwd $tdir/$tfile
3252 local f=$DIR/$tdir/$tfile
3253 import_file $tdir/$tfile $f
3254 local fid=$(path2fid $f)
3256 cdt_set_non_blocking_restore
3261 wait_request_state $fid RESTORE SUCCEED
3262 cdt_clear_non_blocking_restore
3266 error "md5sum returns $st != 1, "\
3267 "should also perror ENODATA (No data available)"
3271 run_test 110a "Non blocking restore policy (import case)"
3274 # test needs a running copytool
3278 local f=$DIR/$tdir/$tfile
3279 local fid=$(copy_file /etc/passwd $f)
3280 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3281 wait_request_state $fid ARCHIVE SUCCEED
3284 cdt_set_non_blocking_restore
3289 wait_request_state $fid RESTORE SUCCEED
3290 cdt_clear_non_blocking_restore
3294 error "md5sum returns $st != 1, "\
3295 "should also perror ENODATA (No data available)"
3299 run_test 110b "Non blocking restore policy (release case)"
3302 # test needs a running copytool
3306 copy2archive /etc/passwd $tdir/$tfile
3308 local f=$DIR/$tdir/$tfile
3310 import_file $tdir/$tfile $f
3311 local fid=$(path2fid $f)
3315 copytool_remove_backend $fid
3318 wait_request_state $fid RESTORE FAILED
3325 [[ $st == 0 ]] || error "Restore does not failed"
3329 run_test 111a "No retry policy (import case), restore will error"\
3330 " (No such file or directory)"
3333 # test needs a running copytool
3337 local f=$DIR/$tdir/$tfile
3338 local fid=$(copy_file /etc/passwd $f)
3340 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3341 wait_request_state $fid ARCHIVE SUCCEED
3344 copytool_remove_backend $fid
3347 wait_request_state $fid RESTORE FAILED
3354 [[ $st == 0 ]] || error "Restore does not failed"
3358 run_test 111b "No retry policy (release case), restore will error"\
3359 " (No such file or directory)"
3362 # test needs a running copytool
3366 local f=$DIR/$tdir/$tfile
3367 local fid=$(copy_file /etc/passwd $f)
3369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3370 local l=$($LFS hsm_action $f)
3372 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3376 wait_request_state $fid ARCHIVE SUCCEED
3379 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3383 run_test 112 "State of recorded request"
3386 # test needs a running copytool
3390 local f=$DIR/$tdir/$tfile
3391 local fid=$(make_large_for_cancel $f)
3392 # test with cdt on is made in test_221
3394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3397 wait_request_state $fid ARCHIVE CANCELED
3398 wait_request_state $fid CANCEL SUCCEED
3402 run_test 200 "Register/Cancel archive"
3405 # test needs a running copytool
3409 local f=$DIR/$tdir/$tfile
3410 make_archive $tdir/$tfile
3411 import_file $tdir/$tfile $f
3412 local fid=$(path2fid $f)
3414 # test with cdt on is made in test_222
3419 wait_request_state $fid RESTORE CANCELED
3420 wait_request_state $fid CANCEL SUCCEED
3424 run_test 201 "Register/Cancel restore"
3427 # test needs a running copytool
3431 local f=$DIR/$tdir/$tfile
3432 local fid=$(make_large_for_progress $f)
3433 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3434 wait_request_state $fid ARCHIVE SUCCEED
3440 wait_request_state $fid REMOVE CANCELED
3444 run_test 202 "Register/Cancel remove"
3447 # test needs a running copytool
3452 local f=$DIR/$tdir/$tfile
3453 local fid=$(copy_file /etc/passwd $f)
3457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3458 wait_request_state $fid ARCHIVE SUCCEED
3460 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3464 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3468 run_test 220 "Changelog for archive"
3471 # test needs a running copytool
3476 local f=$DIR/$tdir/$tfile
3477 local fid=$(make_large_for_cancel $f)
3481 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3482 wait_request_state $fid ARCHIVE STARTED
3484 wait_request_state $fid ARCHIVE CANCELED
3485 wait_request_state $fid CANCEL SUCCEED
3487 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3490 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3494 run_test 221 "Changelog for archive canceled"
3497 # test needs a running copytool
3501 copy2archive /etc/passwd $tdir/$tfile
3503 local f=$DIR/$tdir/$tfile
3504 import_file $tdir/$tfile $f
3505 local fid=$(path2fid $f)
3510 wait_request_state $fid RESTORE SUCCEED
3512 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3515 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3519 run_test 222a "Changelog for explicit restore"
3522 # test needs a running copytool
3526 local f=$DIR/$tdir/$tfile
3527 local fid=$(copy_file /etc/passwd $f)
3530 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3531 wait_request_state $fid ARCHIVE SUCCEED
3536 wait_request_state $fid RESTORE SUCCEED
3538 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3541 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3545 run_test 222b "Changelog for implicit restore"
3548 # test needs a running copytool
3553 local f=$DIR/$tdir/$tfile
3554 make_archive $tdir/$tfile
3558 import_file $tdir/$tfile $f
3559 local fid=$(path2fid $f)
3562 wait_request_state $fid RESTORE STARTED
3564 wait_request_state $fid RESTORE CANCELED
3565 wait_request_state $fid CANCEL SUCCEED
3567 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3570 [[ $flags == $target ]] ||
3571 error "Changelog flag is $flags not $target"
3575 run_test 223a "Changelog for restore canceled (import case)"
3578 # test needs a running copytool
3583 local f=$DIR/$tdir/$tfile
3584 local fid=$(make_large_for_progress $f)
3587 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3588 wait_request_state $fid ARCHIVE SUCCEED
3591 wait_request_state $fid RESTORE STARTED
3593 wait_request_state $fid RESTORE CANCELED
3594 wait_request_state $fid CANCEL SUCCEED
3596 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3599 [[ $flags == $target ]] ||
3600 error "Changelog flag is $flags not $target"
3604 run_test 223b "Changelog for restore canceled (release case)"
3607 # test needs a running copytool
3612 local f=$DIR/$tdir/$tfile
3613 local fid=$(copy_file /etc/passwd $f)
3616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3617 wait_request_state $fid ARCHIVE SUCCEED
3620 wait_request_state $fid REMOVE SUCCEED
3622 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3625 [[ $flags == $target ]] ||
3626 error "Changelog flag is $flags not $target"
3630 run_test 224 "Changelog for remove"
3633 # test needs a running copytool
3636 # test is not usable because remove request is too fast
3637 # so it is always finished before cancel can be done ...
3638 echo "Test disabled"
3643 local f=$DIR/$tdir/$tfile
3644 local fid=$(make_large_for_progress $f)
3647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3648 wait_request_state $fid ARCHIVE SUCCEED
3650 # if cdt is on, it can serve too quickly the request
3655 wait_request_state $fid REMOVE CANCELED
3656 wait_request_state $fid CANCEL SUCCEED
3658 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3659 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3660 tail -n 1 | awk '{print $5}')
3663 [[ $flags == $target ]] ||
3664 error "Changelog flag is $flags not $target"
3668 run_test 225 "Changelog for remove canceled"
3671 # test needs a running copytool
3676 local f1=$DIR/$tdir/$tfile-1
3677 local f2=$DIR/$tdir/$tfile-2
3678 local f3=$DIR/$tdir/$tfile-3
3679 local fid1=$(copy_file /etc/passwd $f1)
3680 local fid2=$(copy_file /etc/passwd $f2)
3681 copy_file /etc/passwd $f3
3684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3685 wait_request_state $fid1 ARCHIVE SUCCEED
3687 $LFS hsm_archive $f2
3688 wait_request_state $fid2 ARCHIVE SUCCEED
3690 rm $f1 || error "rm $f1 failed"
3692 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3695 [[ $flags == $target ]] ||
3696 error "Changelog flag is $flags not $target"
3698 mv $f3 $f2 || error "mv $f3 $f2 failed"
3700 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3703 [[ $flags == $target ]] ||
3704 error "Changelog flag is $flags not $target"
3708 run_test 226 "changelog for last rm/mv with exiting archive"
3710 check_flags_changes() {
3718 $LFS hsm_set --$hsm_flag $f ||
3719 error "Cannot set $hsm_flag on $f"
3720 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3721 local seen=${#flags[*]}
3723 [[ $seen == $cnt ]] ||
3724 error "set $hsm_flag: Changelog events $seen != $cnt"
3725 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3726 error "set $hsm_flag: Changelog flags are "\
3727 "${flags[$((cnt - 1))]} not $target"
3729 $LFS hsm_clear --$hsm_flag $f ||
3730 error "Cannot clear $hsm_flag on $f"
3731 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3734 [[ $cnt == $seen ]] ||
3735 error "clear $hsm_flag: Changelog events $seen != $cnt"
3737 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3738 error "clear $hsm_flag: Changelog flag is "\
3739 "${flags[$((cnt - 1))]} not $target"
3743 # test needs a running copytool
3750 for i in norelease noarchive exists archived
3752 local f=$DIR/$tdir/$tfile-$i
3753 local fid=$(copy_file /etc/passwd $f)
3754 check_flags_changes $f $fid $i 0 1
3757 f=$DIR/$tdir/$tfile---lost
3758 fid=$(copy_file /etc/passwd $f)
3759 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3760 wait_request_state $fid ARCHIVE SUCCEED
3761 check_flags_changes $f $fid lost 3 1
3765 run_test 227 "changelog when explicit setting of HSM flags"
3768 # test needs a running copytool
3771 local fid=$(make_small_sync $DIR/$tfile)
3772 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3773 wait_request_state $fid ARCHIVE SUCCEED
3775 $LFS hsm_release $DIR/$tfile
3776 check_hsm_flags $DIR/$tfile "0x0000000d"
3778 filefrag $DIR/$tfile | grep " 1 extent found" ||
3779 error "filefrag on released file must return only one extent"
3781 # only newer versions of cp detect sparse files by stat/FIEMAP
3783 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3784 error "copying $DIR/$tfile"
3785 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3787 $LFS hsm_release $DIR/$tfile
3788 check_hsm_flags $DIR/$tfile "0x0000000d"
3790 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3792 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3794 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3795 error "comparing untarred $DIR/$tfile"
3797 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3798 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3801 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3804 # test needs a running copytool
3808 local maxrequest=$(get_hsm_param max_requests)
3809 local rqcnt=$(($maxrequest * 3))
3813 for i in $(seq -w 1 $rqcnt); do
3815 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3817 # we do it in 2 steps, so all requests arrive at the same time
3818 for i in $(seq -w 1 $rqcnt); do
3819 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3824 while [[ $cnt != 0 || $wt != 0 ]]; do
3826 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3827 $HSM_PARAM.actions |\
3828 grep STARTED | grep -v CANCEL | wc -l")
3829 [[ $cnt -le $maxrequest ]] ||
3830 error "$cnt > $maxrequest too many started requests"
3831 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3832 $HSM_PARAM.actions |\
3833 grep WAITING | wc -l")
3834 echo "max=$maxrequest started=$cnt waiting=$wt"
3839 run_test 250 "Coordinator max request"
3842 # test needs a running copytool
3846 local f=$DIR/$tdir/$tfile
3847 local fid=$(make_large_for_cancel $f)
3850 # to have a short test
3851 local old_to=$(get_hsm_param active_request_timeout)
3852 set_hsm_param active_request_timeout 4
3853 # to be sure the cdt will wake up frequently so
3854 # it will be able to cancel the "old" request
3855 local old_loop=$(get_hsm_param loop_period)
3856 set_hsm_param loop_period 2
3859 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3860 wait_request_state $fid ARCHIVE STARTED
3862 wait_request_state $fid ARCHIVE CANCELED
3864 set_hsm_param active_request_timeout $old_to
3865 set_hsm_param loop_period $old_loop
3869 run_test 251 "Coordinator request timeout"
3872 # the only way to test ondisk conf is to restart MDS ...
3873 echo "Stop coordinator and remove coordinator state at mount"
3876 # clean on disk conf set by default
3877 cdt_clear_mount_state
3878 cdt_check_state stopped
3880 # check cdt still off after umount/remount
3882 cdt_check_state stopped
3884 echo "Set coordinator start at mount, and start coordinator"
3885 cdt_set_mount_state enabled
3888 cdt_check_state enabled
3890 # check cdt still on after umount/remount
3892 cdt_check_state enabled
3894 # we are back to original state (cdt started at mount)
3896 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3899 local ai=$(get_hsm_param default_archive_id)
3900 local new=$((ai + 1))
3902 set_hsm_param default_archive_id $new -P
3904 local res=$(get_hsm_param default_archive_id)
3907 set_hsm_param default_archive_id "" "-P -d"
3909 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3911 run_test 301 "HSM tunnable are persistent"
3914 local ai=$(get_hsm_param default_archive_id)
3915 local new=$((ai + 1))
3920 set_hsm_param default_archive_id $new -P
3923 for mdtno in $(seq 1 $MDSCOUNT); do
3928 cdt_check_state enabled
3930 local res=$(get_hsm_param default_archive_id)
3933 set_hsm_param default_archive_id "" "-P -d"
3935 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3937 run_test 302 "HSM tunnable are persistent when CDT is off"
3940 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3946 local dir_mdt0=$DIR/$tdir/mdt0
3947 local dir_mdt1=$DIR/$tdir/mdt1
3949 # create 1 dir per MDT
3950 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3951 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3953 # create 1 file in each MDT
3954 local fid1=$(make_small $dir_mdt0/$tfile)
3955 local fid2=$(make_small $dir_mdt1/$tfile)
3957 # check that hsm request on mdt0 is sent to the right MDS
3958 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3959 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3960 echo "archive successful on mdt0"
3962 # check that hsm request on mdt1 is sent to the right MDS
3963 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3964 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3965 echo "archive successful on mdt1"
3968 # clean test files and directories
3969 rm -rf $dir_mdt0 $dir_mdt1
3971 run_test 400 "Single request is sent to the right MDT"
3974 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3980 local dir_mdt0=$DIR/$tdir/mdt0
3981 local dir_mdt1=$DIR/$tdir/mdt1
3983 # create 1 dir per MDT
3984 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3985 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3987 # create 1 file in each MDT
3988 local fid1=$(make_small $dir_mdt0/$tfile)
3989 local fid2=$(make_small $dir_mdt1/$tfile)
3991 # check that compound requests are shunt to the rights MDTs
3992 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3993 error "lfs hsm_archive"
3994 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3995 echo "archive successful on mdt0"
3996 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3997 echo "archive successful on mdt1"
4000 # clean test files and directories
4001 rm -rf $dir_mdt0 $dir_mdt1
4003 run_test 401 "Compound requests split and sent to their respective MDTs"
4005 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4010 local node=$(facet_active_host $facet)
4012 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4013 awk '{print $4}'); do
4014 echo "$3 $mdc on $node"
4015 do_facet $facet "$LCTL --device $mdc $state" || return 1
4020 # make sure there is no running copytool
4023 # deactivate all mdc on agent1
4024 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4026 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4028 check_agent_unregistered "uuid" # match any agent
4030 # no expected running copytool
4031 search_copytools $agent && error "Copytool start should have failed"
4034 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4036 run_test 402 "Copytool start fails if all MDTs are inactive"
4039 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4041 # make sure there is no running copytool
4044 local agent=$(facet_active_host $SINGLEAGT)
4045 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4047 # deactivate all mdc for MDT0001
4048 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4051 # check the agent is registered on MDT0000, and not on MDT0001
4052 check_agent_registered_by_mdt $uuid 0
4053 check_agent_unregistered_by_mdt $uuid 1
4055 # check running copytool process
4056 search_copytools $agent || error "No running copytools on $agent"
4058 # reactivate all mdc for MDT0001
4059 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4061 # make sure the copytool is now registered to all MDTs
4062 check_agent_registered $uuid
4066 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4069 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4073 # create files on both MDT0000 and MDT0001
4076 local dir_mdt0=$DIR/$tdir/mdt0
4077 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4079 # create 1 file on mdt0
4080 local fid1=$(make_small $dir_mdt0/$tfile)
4082 # deactivate all mdc for MDT0001
4083 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4085 # send an HSM request for files in MDT0000
4086 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4088 # check for completion of files in MDT0000
4089 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4090 echo "archive successful on mdt0"
4092 # reactivate all mdc for MDT0001
4093 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4096 # clean test files and directories
4099 run_test 404 "Inactive MDT does not block requests for active MDTs"
4102 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4108 local striped_dir=$DIR/$tdir/striped_dir
4110 # create striped dir on all of MDTs
4111 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4113 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4114 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4115 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4116 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4118 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4119 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4120 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4121 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4123 # check that compound requests are shunt to the rights MDTs
4124 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4125 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4126 error "lfs hsm_archive"
4128 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4129 echo "archive successful on $fid1"
4130 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4131 echo "archive successful on $fid2"
4132 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4133 echo "archive successful on $fid3"
4134 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4135 echo "archive successful on $fid4"
4137 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4138 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4139 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4140 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4142 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4143 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4144 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4145 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4149 run_test 405 "archive and release under striped directory"
4154 check_and_cleanup_lustre