3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: 3815 3939
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36 40"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
68 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
71 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72 if [[ $CLIENTCOUNT -gt 1 ]] &&
73 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74 skip_env "SHARED_DIRECTORY should be accessible"\
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81 agent=CLIENT$((n + 1))
82 if [[ -z "${!agent}" ]]; then
83 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89 export SINGLEAGT=${SINGLEAGT:-agt1}
91 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
94 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
95 export HSMTOOL_TESTDIR
96 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
97 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
100 # The test only support up to 10 MDTs
101 MDT_PREFIX="mdt.$FSNAME-MDT000"
102 HSM_PARAM="${MDT_PREFIX}0.hsm"
104 # archive is purged at copytool setup
105 HSM_ARCHIVE_PURGE=true
107 # Don't allow copytool error upon start/setup
108 HSMTOOL_NOERROR=false
111 # Get the backend root path for the given agent facet.
114 local dev=AGTDEV$(facet_number $facet)
119 # Stop copytool and unregister an existing changelog user.
121 copytool_monitor_cleanup
124 cdt_set_sanity_policy
129 # get MDT device for each mdc
130 for mdtno in $(seq 1 $MDSCOUNT); do
131 local idx=$(($mdtno - 1))
132 MDT[$idx]=$($LCTL get_param -n \
133 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
134 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
139 local agents=${1:-$(facet_active_host $SINGLEAGT)}
140 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
143 search_and_kill_copytool() {
144 local agents=${1:-$(facet_active_host $SINGLEAGT)}
146 echo "Killing existing copytools on $agents"
147 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
150 copytool_monitor_setup() {
151 local facet=${1:-$SINGLEAGT}
152 local agent=$(facet_active_host $facet)
154 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
155 local test_dir=$(do_node $agent "$cmd") ||
156 error "Failed to create tempdir on $agent"
157 export HSMTOOL_MONITOR_DIR=$test_dir
159 # Create the fifo and a monitor (cat dies when copytool dies)
160 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
161 error "failed to create copytool fifo on $agent"
162 cmd="cat $test_dir/fifo > $test_dir/events &"
163 cmd+=" echo \\\$! > $test_dir/monitor_pid"
165 if [[ $PDSH == *Rmrsh* ]]; then
166 # This is required for pdsh -Rmrsh and its handling of remote
168 # Regular ssh and pdsh -Rssh work fine without this
169 # backgrounded subshell nonsense.
170 (do_node $agent "$cmd") &
171 export HSMTOOL_MONITOR_PDSH=$!
173 # Slightly racy, but just making a best-effort to catch obvious
176 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
177 error "Failed to start copytool monitor on $agent"
179 do_node $agent "$cmd"
181 error "Failed to start copytool monitor on $agent"
186 copytool_monitor_cleanup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
191 # Should die when the copytool dies, but just in case.
192 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
193 cmd+=" 2>/dev/null || true"
194 do_node $agent "$cmd"
195 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
196 export HSMTOOL_MONITOR_DIR=
199 # The pdsh should die on its own when the monitor dies. Just
200 # in case, though, try to clean up to avoid any cruft.
201 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
202 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
203 export HSMTOOL_MONITOR_PDSH=
208 local facet=${1:-$SINGLEAGT}
209 local lustre_mntpnt=${2:-$MOUNT}
211 local hsm_root=${4:-$(copytool_device $facet)}
212 local agent=$(facet_active_host $facet)
214 if [[ -z "$arc_id" ]] &&
215 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
216 echo "Only wakeup running copytool $facet on $agent"
220 if $HSM_ARCHIVE_PURGE; then
221 echo "Purging archive on $agent"
222 do_facet $facet "rm -rf $hsm_root/*"
225 echo "Starting copytool $facet on $agent"
226 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
227 # bandwidth is limited to 1MB/s so the copy time is known and
228 # independent of hardware
229 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
230 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
231 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
232 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
233 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
234 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
235 cmd+=" --bandwidth 1 $lustre_mntpnt"
237 # Redirect the standard output and error to a log file which
238 # can be uploaded to Maloo.
239 local prefix=$TESTLOG_PREFIX
240 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
241 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
243 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
244 if [[ $? != 0 ]]; then
245 [[ $HSMTOOL_NOERROR == true ]] ||
246 error "start copytool $facet on $agent failed"
247 echo "start copytool $facet on $agent failed"
253 get_copytool_event_log() {
254 local facet=${1:-$SINGLEAGT}
255 local agent=$(facet_active_host $facet)
257 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
258 error "Can't get event log: No monitor directory!"
260 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
261 error "Could not collect event log from $agent"
266 local facet=$SINGLEAGT
267 local agents=${1:-$(facet_active_host $facet)}
272 local hsm_root=$(copytool_device $facet)
273 local end_wait=$(( SECONDS + TIMEOUT ))
275 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
277 while (( SECONDS < end_wait )); do
279 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
280 if [ $? -ne 0 ]; then
281 echo "Copytool is stopped on $agents"
284 echo "Copytool still running on $agents"
286 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
287 error "Copytool failed to stop in ${TIMEOUT}s ..."
289 echo "Copytool has stopped in " \
290 "$((TIMEOUT - (end_wait - SECONDS)))s."
293 # clean all CDTs orphans requests from previous tests
294 # that would otherwise need to timeout to clear.
295 for mdtno in $(seq 1 $MDSCOUNT); do
297 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
298 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
300 # skip already stop[ed,ing] CDTs
301 echo $oldstate | grep stop && continue
303 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
304 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
306 error "mds${mdtno} cdt state is not stopped"
307 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
308 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
310 error "mds${mdtno} cdt state is not $oldstate"
312 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
313 do_facet $facet "rm -rf $hsm_root/*"
318 local agents=${1:-$(facet_active_host $SINGLEAGT)}
320 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
321 echo "Copytool is suspended on $agents"
324 copytool_remove_backend() {
326 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
327 echo "Remove from backend: $fid = $be"
328 do_facet $SINGLEAGT rm -f $be
332 do_facet $SINGLEAGT \
333 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
334 --import $1 $2 $MOUNT" ||
335 error "import of $1 to $2 failed"
339 local file=$HSM_ARCHIVE/$1
340 do_facet $SINGLEAGT mkdir -p $(dirname $file)
341 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
342 file_creation_failure dd $file $?
346 local file=$HSM_ARCHIVE/$2
347 do_facet $SINGLEAGT mkdir -p $(dirname $file)
348 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
357 if [[ "$value" != "" ]]; then
360 for mdtno in $(seq 1 $MDSCOUNT); do
361 local idx=$(($mdtno - 1))
362 local facet=mds${mdtno}
363 # if $arg include -P option, run 1 set_param per MDT on the MGS
364 # else, run set_param on each MDT
365 [[ $arg = *"-P"* ]] && facet=mgs
366 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
367 [[ $? != 0 ]] && rc=1
377 for mdtno in $(seq 1 $MDSCOUNT); do
378 local idx=$(($mdtno - 1))
379 wait_result mds${mdtno} \
380 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
382 error "$key state is not '$target' on mds${mdtno}"
389 for mdtno in $(seq 1 $MDSCOUNT); do
390 local idx=$(($mdtno - 1))
391 local cl_user=$(do_facet mds${mdtno} $LCTL \
392 --device ${MDT[$idx]} \
393 changelog_register -n)
395 do_facet mds${mdtno} lctl set_param \
396 mdd.${MDT[$idx]}.changelog_mask="+hsm"
397 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
401 changelog_cleanup() {
403 for mdtno in $(seq 1 $MDSCOUNT); do
404 local idx=$(($mdtno - 1))
405 [[ -z ${CL_USERS[$idx]} ]] && continue
406 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
407 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
408 changelog_deregister ${CL_USERS[$idx]}
413 changelog_get_flags() {
418 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
423 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
431 mdts_set_param "$opt -n" "hsm.$param" "$value"
438 mdts_set_param "" hsm_control "$cmd"
439 mdts_check_param hsm_control "$target" 10
442 cdt_set_sanity_policy() {
443 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
446 mdts_set_param "" hsm.policy "+NRA"
447 mdts_set_param "" hsm.policy "-NBR"
448 CDT_POLICY_HAD_CHANGED=
453 mdts_set_param "" hsm.policy "+NRA"
454 CDT_POLICY_HAD_CHANGED=true
457 cdt_clear_no_retry() {
458 mdts_set_param "" hsm.policy "-NRA"
459 CDT_POLICY_HAD_CHANGED=true
462 cdt_set_non_blocking_restore() {
463 mdts_set_param "" hsm.policy "+NBR"
464 CDT_POLICY_HAD_CHANGED=true
467 cdt_clear_non_blocking_restore() {
468 mdts_set_param "" hsm.policy "-NBR"
469 CDT_POLICY_HAD_CHANGED=true
472 cdt_clear_mount_state() {
473 mdts_set_param "-P -d" hsm_control ""
476 cdt_set_mount_state() {
477 mdts_set_param "-P" hsm_control "$1"
481 mdts_check_param hsm_control "$1" 20
485 set_test_state disabled disabled
489 set_test_state enabled enabled
493 set_test_state shutdown stopped
497 set_test_state purge enabled
503 cdt_set_sanity_policy
507 local client_count=$1
508 if [[ $CLIENTCOUNT -lt $client_count ]]; then
509 skip "Need $client_count or more clients, have $CLIENTCOUNT"
516 $LFS path2fid $1 | tr -d '[]'
523 if [[ $u == "user" ]]; then
524 local st=$($RUNAS $LFS hsm_state $f)
526 local st=$($LFS hsm_state $f)
530 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
532 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
536 get_hsm_archive_id() {
538 local st=$($LFS hsm_state $f)
539 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
541 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
550 local st=$(get_hsm_flags $f)
551 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
554 check_hsm_flags_user() {
558 local st=$(get_hsm_flags $f user)
559 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
562 file_creation_failure() {
568 error "cannot create $f with $cmd, status=$err"
580 if [[ "$3" != 1 ]]; then
584 cp $1 $f || file_creation_failure cp $f $?
586 path2fid $f || error "cannot get fid on $f"
590 local file2=${1/$DIR/$DIR2}
591 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
592 file_creation_failure dd $file2 $?
594 path2fid $1 || error "cannot get fid on $1"
598 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
599 file_creation_failure dd $1 $?
600 path2fid $1 || error "cannot get fid on $1"
603 cleanup_large_files() {
604 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
606 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
609 make_large_for_striping() {
610 local file2=${1/$DIR/$DIR2}
611 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
615 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
616 file_creation_failure dd $file2 $?
618 path2fid $1 || error "cannot get fid on $1"
621 make_large_for_progress() {
622 local file2=${1/$DIR/$DIR2}
626 # big file is large enough, so copy time is > 30s
627 # so copytool make 1 progress
628 # size is not a multiple of 1M to avoid stripe
630 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
631 file_creation_failure dd $file2 $?
633 path2fid $1 || error "cannot get fid on $1"
636 make_large_for_progress_aligned() {
637 local file2=${1/$DIR/$DIR2}
641 # big file is large enough, so copy time is > 30s
642 # so copytool make 1 progress
643 # size is a multiple of 1M to have stripe
645 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
646 file_creation_failure dd $file2 $?
647 path2fid $1 || error "cannot get fid on $1"
650 make_large_for_cancel() {
651 local file2=${1/$DIR/$DIR2}
655 # Copy timeout is 100s. 105MB => 105s
656 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
657 file_creation_failure dd $file2 $?
658 path2fid $1 || error "cannot get fid on $1"
664 wait_update --verbose $(facet_active_host $facet) "$@"
667 wait_request_state() {
671 # 4th arg (mdt index) is optional
673 local mds=mds$(($mdtidx + 1))
675 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
676 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
678 wait_result $mds "$cmd" $state 100 ||
679 error "request on $fid is not $state on $mds"
682 get_request_state() {
686 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
687 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
690 get_request_count() {
694 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
695 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
702 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
703 [[ -n $fid ]] && cmd+=" | grep '$fid'"
704 cmd+=" | egrep 'WAITING|STARTED'"
706 wait_result $SINGLEMDS "$cmd" "" $timeout ||
707 error "requests did not complete"
710 wait_for_grace_delay() {
711 local val=$(get_hsm_param grace_delay)
718 # python2.6 in EL6 includes an internal json module
719 local json_parser='import json; import fileinput;'
720 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
721 json_parser+='json.loads([line for line in '
722 json_parser+='fileinput.input()][0]).items()])'
724 echo $raw_event | python -c "$json_parser"
727 # populate MDT device array
733 # cleanup from previous bad setup
734 search_and_kill_copytool
736 # for recovery tests, coordinator needs to be started at mount
738 # the lustre conf must be without hsm on (like for sanity.sh)
739 echo "Set HSM on and start"
740 cdt_set_mount_state enabled
741 cdt_check_state enabled
743 echo "Start copytool"
746 echo "Set sanity-hsm HSM policy"
747 cdt_set_sanity_policy
749 # finished requests are quickly removed from list
750 set_hsm_param grace_delay 10
756 local f=$DIR/$tdir/$tfile
760 check_hsm_flags_user $f "0x00000000"
762 $RUNAS $LFS hsm_set --norelease $f ||
763 error "user could not change hsm flags"
764 check_hsm_flags_user $f "0x00000010"
766 $RUNAS $LFS hsm_clear --norelease $f ||
767 error "user could not clear hsm flags"
768 check_hsm_flags_user $f "0x00000000"
770 # User could not change those flags...
771 $RUNAS $LFS hsm_set --exists $f &&
772 error "user should not set this flag"
773 check_hsm_flags_user $f "0x00000000"
776 $LFS hsm_set --exists $f ||
777 error "root could not change hsm flags"
778 check_hsm_flags_user $f "0x00000001"
780 $LFS hsm_clear --exists $f ||
781 error "root could not clear hsm state"
782 check_hsm_flags_user $f "0x00000000"
785 run_test 1 "lfs hsm flags root/non-root access"
789 local f=$DIR/$tdir/$tfile
791 # New files are not dirty
792 check_hsm_flags $f "0x00000000"
794 # For test, we simulate an archived file.
795 $LFS hsm_set --exists $f || error "user could not change hsm flags"
796 check_hsm_flags $f "0x00000001"
798 # chmod do not put the file dirty
799 chmod 600 $f || error "could not chmod test file"
800 check_hsm_flags $f "0x00000001"
802 # chown do not put the file dirty
803 chown $RUNAS_ID $f || error "could not chown test file"
804 check_hsm_flags $f "0x00000001"
806 # truncate put the file dirty
807 $TRUNCATE $f 1 || error "could not truncate test file"
808 check_hsm_flags $f "0x00000003"
810 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
811 check_hsm_flags $f "0x00000001"
813 run_test 2 "Check file dirtyness when doing setattr"
819 # New files are not dirty
821 check_hsm_flags $f "0x00000000"
823 # For test, we simulate an archived file.
824 $LFS hsm_set --exists $f ||
825 error "user could not change hsm flags"
826 check_hsm_flags $f "0x00000001"
828 # Reading a file, does not set dirty
829 cat $f > /dev/null || error "could not read file"
830 check_hsm_flags $f "0x00000001"
832 # Open for write without modifying data, does not set dirty
833 openfile -f O_WRONLY $f || error "could not open test file"
834 check_hsm_flags $f "0x00000001"
836 # Append to a file sets it dirty
837 cp -p /etc/passwd $f.append || error "could not create file"
838 $LFS hsm_set --exists $f.append ||
839 error "user could not change hsm flags"
840 dd if=/etc/passwd of=$f.append bs=1 count=3\
841 conv=notrunc oflag=append status=noxfer ||
842 file_creation_failure dd $f.append $?
843 check_hsm_flags $f.append "0x00000003"
845 # Modify a file sets it dirty
846 cp -p /etc/passwd $f.modify || error "could not create file"
847 $LFS hsm_set --exists $f.modify ||
848 error "user could not change hsm flags"
849 dd if=/dev/zero of=$f.modify bs=1 count=3\
850 conv=notrunc status=noxfer ||
851 file_creation_failure dd $f.modify $?
852 check_hsm_flags $f.modify "0x00000003"
854 # Open O_TRUNC sets dirty
855 cp -p /etc/passwd $f.trunc || error "could not create file"
856 $LFS hsm_set --exists $f.trunc ||
857 error "user could not change hsm flags"
858 cp /etc/group $f.trunc || error "could not override a file"
859 check_hsm_flags $f.trunc "0x00000003"
861 # Mmapped a file sets dirty
862 cp -p /etc/passwd $f.mmap || error "could not create file"
863 $LFS hsm_set --exists $f.mmap ||
864 error "user could not change hsm flags"
865 multiop $f.mmap OSMWUc || error "could not mmap a file"
866 check_hsm_flags $f.mmap "0x00000003"
868 run_test 3 "Check file dirtyness when opening for write"
872 local f=$DIR/$tdir/$tfile
873 local fid=$(make_small $f)
876 local st=$(get_request_state $fid CANCEL)
877 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
879 run_test 4 "Useless cancel must not be registered"
882 # test needs a running copytool
886 local f=$DIR/$tdir/$tfile
887 local fid=$(copy_file /etc/passwd $f)
889 wait_request_state $fid ARCHIVE SUCCEED
891 check_hsm_flags $f "0x00000009"
895 run_test 8 "Test default archive number"
899 local f=$DIR/$tdir/$tfile
900 local fid=$(copy_file /etc/passwd $f)
901 # we do not use the default one to be sure
902 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
904 copytool_setup $SINGLEAGT $MOUNT $new_an
905 $LFS hsm_archive --archive $new_an $f
906 wait_request_state $fid ARCHIVE SUCCEED
908 check_hsm_flags $f "0x00000009"
912 run_test 9 "Use of explict archive number, with dedicated copytool"
915 needclients 3 || return 0
921 copytool_cleanup $(comma_list $(agts_nodes))
923 # start all of the copytools
924 for n in $(seq $AGTCOUNT); do
928 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
931 for n in $(seq $AGTCOUNT); do
932 file=$DIR/$tdir/$tfile.$n
933 fid=$(make_small $file)
935 $LFS hsm_archive $file || error "could not archive file $file"
936 wait_request_state $fid ARCHIVE SUCCEED
937 check_hsm_flags $file "0x00000009"
941 copytool_cleanup $(comma_list $(agts_nodes))
943 run_test 9a "Multiple remote agents"
946 # test needs a running copytool
949 mkdir -p $DIR/$tdir/d1
950 local f=$DIR/$tdir/$tfile
951 local fid=$(copy_file /etc/hosts $f)
952 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
953 error "hsm_archive failed"
954 wait_request_state $fid ARCHIVE SUCCEED
956 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
957 error "fid $fid not in archive $HSM_ARCHIVE"
958 echo "Verifying content"
959 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
960 echo "Verifying hsm state "
961 check_hsm_flags $f "0x00000009"
963 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
964 local st=$(get_hsm_archive_id $f)
965 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
966 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
971 run_test 10a "Archive a file"
974 # test needs a running copytool
978 local f=$DIR/$tdir/$tfile
979 local fid=$(copy_file /etc/hosts $f)
980 $LFS hsm_archive $f || error "archive request failed"
981 wait_request_state $fid ARCHIVE SUCCEED
983 $LFS hsm_archive $f || error "archive of non dirty file failed"
984 local cnt=$(get_request_count $fid ARCHIVE)
985 [[ "$cnt" == "1" ]] ||
986 error "archive of non dirty file must not make a request"
990 run_test 10b "Archive of non dirty file must work without doing request"
993 # test needs a running copytool
997 local f=$DIR/$tdir/$tfile
998 local fid=$(copy_file /etc/hosts $f)
999 $LFS hsm_set --noarchive $f
1000 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1004 run_test 10c "Check forbidden archive"
1007 # test needs a running copytool
1011 local f=$DIR/$tdir/$tfile
1012 local fid=$(copy_file /etc/hosts $f)
1013 $LFS hsm_archive $f || error "cannot archive $f"
1014 wait_request_state $fid ARCHIVE SUCCEED
1016 local ar=$(get_hsm_archive_id $f)
1017 local dflt=$(get_hsm_param default_archive_id)
1018 [[ $ar == $dflt ]] ||
1019 error "archived file is not on default archive: $ar != $dflt"
1023 run_test 10d "Archive a file on the default archive id"
1027 copy2archive /etc/hosts $tdir/$tfile
1028 local f=$DIR/$tdir/$tfile
1030 import_file $tdir/$tfile $f
1031 echo -n "Verifying released state: "
1032 check_hsm_flags $f "0x0000000d"
1034 local LSZ=$(stat -c "%s" $f)
1035 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1037 echo "Verifying imported size $LSZ=$ASZ"
1038 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1039 echo -n "Verifying released pattern: "
1040 local PTRN=$($GETSTRIPE -L $f)
1042 [[ $PTRN == 80000001 ]] || error "Is not released"
1043 local fid=$(path2fid $f)
1044 echo "Verifying new fid $fid in archive"
1046 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1047 error "fid $fid not in archive $HSM_ARCHIVE"
1049 run_test 11a "Import a file"
1052 # test needs a running copytool
1056 local f=$DIR/$tdir/$tfile
1057 local fid=$(copy_file /etc/hosts $f)
1058 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1059 error "hsm_archive failed"
1060 wait_request_state $fid ARCHIVE SUCCEED
1062 local FILE_HASH=$(md5sum $f)
1067 echo "$FILE_HASH" | md5sum -c
1069 [[ $? -eq 0 ]] || error "Restored file differs"
1073 run_test 11b "Import a deleted file using its FID"
1076 # test needs a running copytool
1080 copy2archive /etc/hosts $tdir/$tfile
1082 local f=$DIR/$tdir/$tfile
1083 import_file $tdir/$tfile $f
1084 local f2=$DIR2/$tdir/$tfile
1085 echo "Verifying released state: "
1086 check_hsm_flags $f2 "0x0000000d"
1088 local fid=$(path2fid $f2)
1089 $LFS hsm_restore $f2
1090 wait_request_state $fid RESTORE SUCCEED
1092 echo "Verifying file state: "
1093 check_hsm_flags $f2 "0x00000009"
1095 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1097 [[ $? -eq 0 ]] || error "Restored file differs"
1101 run_test 12a "Restore an imported file explicitly"
1104 # test needs a running copytool
1108 copy2archive /etc/hosts $tdir/$tfile
1110 local f=$DIR/$tdir/$tfile
1111 import_file $tdir/$tfile $f
1112 echo "Verifying released state: "
1113 check_hsm_flags $f "0x0000000d"
1115 cat $f > /dev/null || error "File read failed"
1117 echo "Verifying file state after restore: "
1118 check_hsm_flags $f "0x00000009"
1120 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1122 [[ $? -eq 0 ]] || error "Restored file differs"
1126 run_test 12b "Restore an imported file implicitly"
1129 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1131 # test needs a running copytool
1135 local f=$DIR/$tdir/$tfile
1136 $LFS setstripe -c 2 $f
1137 local fid=$(make_large_for_striping $f)
1138 local FILE_CRC=$(md5sum $f)
1140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1141 wait_request_state $fid ARCHIVE SUCCEED
1142 $LFS hsm_release $f || error "release $f failed"
1144 echo "$FILE_CRC" | md5sum -c
1146 [[ $? -eq 0 ]] || error "Restored file differs"
1150 run_test 12c "Restore a file with stripe of 2"
1153 # test needs a running copytool
1158 local f=$DIR/$tdir/$tfile
1159 local fid=$(copy_file /etc/hosts $f)
1160 $LFS hsm_restore $f || error "restore of non archived file failed"
1161 local cnt=$(get_request_count $fid RESTORE)
1162 [[ "$cnt" == "0" ]] ||
1163 error "restore non archived must not make a request"
1164 $LFS hsm_archive $f ||
1165 error "archive request failed"
1166 wait_request_state $fid ARCHIVE SUCCEED
1167 $LFS hsm_restore $f ||
1168 error "restore of non released file failed"
1169 local cnt=$(get_request_count $fid RESTORE)
1170 [[ "$cnt" == "0" ]] ||
1171 error "restore a non dirty file must not make a request"
1175 run_test 12d "Restore of a non archived, non released file must work"\
1176 " without doing request"
1179 # test needs a running copytool
1182 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1183 local f=$DIR/$tdir/$tfile
1184 local fid=$(copy_file /etc/hosts $f)
1185 $LFS hsm_archive $f || error "archive request failed"
1186 wait_request_state $fid ARCHIVE SUCCEED
1189 cat /etc/hosts >> $f
1193 $LFS hsm_restore $f && error "restore a dirty file must fail"
1197 run_test 12e "Check forbidden restore"
1200 # test needs a running copytool
1204 local f=$DIR/$tdir/$tfile
1205 local fid=$(copy_file /etc/hosts $f)
1207 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1208 wait_request_state $fid ARCHIVE SUCCEED
1209 $LFS hsm_release $f || error "release of $f failed"
1211 wait_request_state $fid RESTORE SUCCEED
1213 echo -n "Verifying file state: "
1214 check_hsm_flags $f "0x00000009"
1216 diff -q /etc/hosts $f
1218 [[ $? -eq 0 ]] || error "Restored file differs"
1222 run_test 12f "Restore a released file explicitly"
1225 # test needs a running copytool
1229 local f=$DIR/$tdir/$tfile
1230 local fid=$(copy_file /etc/hosts $f)
1232 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1233 wait_request_state $fid ARCHIVE SUCCEED
1234 $LFS hsm_release $f || error "release of $f failed"
1236 diff -q /etc/hosts $f
1239 # we check we had a restore done
1240 wait_request_state $fid RESTORE SUCCEED
1242 [[ $st -eq 0 ]] || error "Restored file differs"
1246 run_test 12g "Restore a released file implicitly"
1249 needclients 2 || return 0
1251 # test needs a running copytool
1255 local f=$DIR/$tdir/$tfile
1256 local fid=$(copy_file /etc/hosts $f)
1258 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1259 wait_request_state $fid ARCHIVE SUCCEED
1260 $LFS hsm_release $f || error "release of $f failed"
1262 do_node $CLIENT2 diff -q /etc/hosts $f
1265 # we check we had a restore done
1266 wait_request_state $fid RESTORE SUCCEED
1268 [[ $st -eq 0 ]] || error "Restored file differs"
1272 run_test 12h "Restore a released file implicitly from a second node"
1275 # test needs a running copytool
1279 local f=$DIR/$tdir/$tfile
1280 local fid=$(copy_file /etc/passwd $f)
1281 $LFS hsm_archive $f || error "archive of $f failed"
1282 wait_request_state $fid ARCHIVE SUCCEED
1284 $LFS hsm_release $f || error "release of $f failed"
1288 [[ $? -eq 0 ]] || error "Restored file differs"
1292 run_test 12m "Archive/release/implicit restore"
1295 # test needs a running copytool
1299 copy2archive /etc/hosts $tdir/$tfile
1301 local f=$DIR/$tdir/$tfile
1302 import_file $tdir/$tfile $f
1304 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1305 error "Restored file differs"
1307 $LFS hsm_release $f || error "release of $f failed"
1311 run_test 12n "Import/implicit restore/release"
1314 # test needs a running copytool
1318 local f=$DIR/$tdir/$tfile
1319 local fid=$(copy_file /etc/hosts $f)
1321 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1322 wait_request_state $fid ARCHIVE SUCCEED
1323 $LFS hsm_release $f || error "release of $f failed"
1325 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1326 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1328 # set no retry action mode
1331 diff -q /etc/hosts $f
1334 # we check we had a restore failure
1335 wait_request_state $fid RESTORE FAILED
1337 [[ $st -eq 0 ]] && error "Restore must fail"
1339 # remove no retry action mode
1342 # check file is still released
1343 check_hsm_flags $f "0x0000000d"
1345 # retry w/o failure injection
1346 do_facet $SINGLEMDS lctl set_param fail_loc=0
1348 # to be sure previous RESTORE result is gone
1350 wait_for_grace_delay
1352 diff -q /etc/hosts $f
1355 # we check we had a restore done
1356 wait_request_state $fid RESTORE SUCCEED
1358 [[ $st -eq 0 ]] || error "Restored file differs"
1362 run_test 12o "Layout-swap failure during Restore leaves file released"
1365 # test needs a running copytool
1368 local ARC_SUBDIR="import.orig"
1372 # populate directory to be imported
1373 for d in $(seq 1 10); do
1374 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1375 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1376 for f in $(seq 1 10); do
1377 CURR_FILE="$CURR_DIR/$tfile.$f"
1378 # write file-specific data
1379 do_facet $SINGLEAGT \
1380 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1381 "file=$CURR_FILE > $CURR_FILE"
1385 import_file "$ARC_SUBDIR" $DIR/$tdir
1386 # diff lustre content and origin (triggers file restoration)
1387 # there must be 10x10 identical files, and no difference
1388 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1389 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1390 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1391 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1393 [ $cnt_diff -eq 0 ] ||
1394 error "$cnt_diff imported files differ from read data"
1395 [ $cnt_ok -eq 100 ] ||
1396 error "not enough identical files ($cnt_ok != 100)"
1400 run_test 13 "Recursively import and restore a directory"
1403 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(make_small $f)
1410 local sum=$(md5sum $f | awk '{print $1}')
1411 $LFS hsm_archive $f || error "could not archive file"
1412 wait_request_state $fid ARCHIVE SUCCEED
1416 # create released file (simulate llapi_hsm_import call)
1418 local fid2=$(path2fid $f)
1419 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1420 $LFS hsm_release $f || error "could not release file"
1422 # rebind the archive to the newly created file
1423 echo "rebind $fid to $fid2"
1425 do_facet $SINGLEAGT \
1426 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1427 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1429 # restore file and compare md5sum
1430 local sum2=$(md5sum $f | awk '{print $1}')
1432 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1436 run_test 14 "Rebind archived file to a new fid"
1439 # test needs a running copytool
1444 local f=$DIR/$tdir/$tfile
1446 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1450 for i in $(seq 1 $count); do
1451 fids[$i]=$(make_small $f.$i)
1452 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1453 $LFS hsm_archive $f.$i || error "could not archive file"
1455 wait_all_done $(($count*60))
1459 for i in $(seq 1 $count); do
1462 local fid2=$(path2fid $f.$i)
1463 # add the rebind operation to the list
1464 echo ${fids[$i]} $fid2 >> $tmpfile
1466 # set it released (simulate llapi_hsm_import call)
1467 $LFS hsm_set --archived --exists $f.$i ||
1468 error "could not force hsm flags"
1469 $LFS hsm_release $f.$i || error "could not release file"
1471 nl=$(wc -l < $tmpfile)
1472 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1474 echo "rebind list of files"
1475 do_facet $SINGLEAGT \
1476 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1477 --rebind $tmpfile $DIR" || error "could not rebind file list"
1479 # restore files and compare md5sum
1480 for i in $(seq 1 $count); do
1481 local sum2=$(md5sum $f.$i | awk '{print $1}')
1482 [[ $sum2 == ${sums[$i]} ]] ||
1483 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1489 run_test 15 "Rebind a list of files"
1492 # test needs a running copytool
1496 # create a known size file so we can verify transfer speed
1499 dd if=/dev/zero of=$ref bs=1M count=20
1502 local f=$DIR/$tdir/$tfile
1503 local fid=$(copy_file $ref $f)
1505 local start=$(date +%s)
1507 wait_request_state $fid ARCHIVE SUCCEED
1508 local end=$(date +%s)
1509 local duration=$((end - start))
1511 [[ $duration -ge $goal ]] ||
1512 error "Transfer is too fast $duration < $goal"
1516 run_test 16 "Test CT bandwith control option"
1521 local f=$DIR/$tdir/$tfile
1522 touch $f || error "touch $f failed"
1524 # Could not release a non-archived file
1525 $LFS hsm_release $f && error "release should not succeed"
1527 # For following tests, we must test them with HS_ARCHIVED set
1528 $LFS hsm_set --exists --archived $f || error "could not add flag"
1530 # Could not release a file if no-release is set
1531 $LFS hsm_set --norelease $f || error "could not add flag"
1532 $LFS hsm_release $f && error "release should not succeed"
1533 $LFS hsm_clear --norelease $f || error "could not remove flag"
1535 # Could not release a file if lost
1536 $LFS hsm_set --lost $f || error "could not add flag"
1537 $LFS hsm_release $f && error "release should not succeed"
1538 $LFS hsm_clear --lost $f || error "could not remove flag"
1540 # Could not release a file if dirty
1541 $LFS hsm_set --dirty $f || error "could not add flag"
1542 $LFS hsm_release $f && error "release should not succeed"
1543 $LFS hsm_clear --dirty $f || error "could not remove flag"
1545 run_test 20 "Release is not permitted"
1548 # test needs a running copytool
1552 local f=$DIR/$tdir/test_release
1554 # Create a file and check its states
1555 local fid=$(make_small $f)
1556 check_hsm_flags $f "0x00000000"
1558 $LFS hsm_archive $f || error "could not archive file"
1559 wait_request_state $fid ARCHIVE SUCCEED
1561 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1562 local sz=$(stat -c "%s" $f)
1563 [ $sz -ne "0" ] || error "file size should not be zero"
1565 # Release and check states
1566 $LFS hsm_release $f || error "could not release file"
1567 check_hsm_flags $f "0x0000000d"
1569 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1570 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1572 # Check we can release an file without stripe info
1576 check_hsm_flags $f "0x00000000"
1577 $LFS hsm_archive $f || error "could not archive file"
1578 wait_request_state $fid ARCHIVE SUCCEED
1580 # Release and check states
1581 $LFS hsm_release $f || error "could not release file"
1582 check_hsm_flags $f "0x0000000d"
1584 # Release again a file that is already released is OK
1585 $LFS hsm_release $f || fail "second release should succeed"
1586 check_hsm_flags $f "0x0000000d"
1590 run_test 21 "Simple release tests"
1593 # test needs a running copytool
1598 local f=$DIR/$tdir/test_release
1599 local swap=$DIR/$tdir/test_swap
1601 # Create a file and check its states
1602 local fid=$(make_small $f)
1603 check_hsm_flags $f "0x00000000"
1605 $LFS hsm_archive $f || error "could not archive file"
1606 wait_request_state $fid ARCHIVE SUCCEED
1608 # Release and check states
1609 $LFS hsm_release $f || error "could not release file"
1610 check_hsm_flags $f "0x0000000d"
1613 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1618 run_test 22 "Could not swap a release file"
1621 # test needs a running copytool
1626 local f=$DIR/$tdir/test_mtime
1628 # Create a file and check its states
1629 local fid=$(make_small $f)
1630 check_hsm_flags $f "0x00000000"
1632 $LFS hsm_archive $f || error "could not archive file"
1633 wait_request_state $fid ARCHIVE SUCCEED
1635 # Set modification time in the past
1636 touch -m -a -d @978261179 $f
1638 # Release and check states
1639 $LFS hsm_release $f || error "could not release file"
1640 check_hsm_flags $f "0x0000000d"
1642 local MTIME=$(stat -c "%Y" $f)
1643 local ATIME=$(stat -c "%X" $f)
1644 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1645 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1649 run_test 23 "Release does not change a/mtime (utime)"
1652 local file=$DIR/$tdir/$tfile
1661 # test needs a running copytool
1666 fid=$(make_small $file)
1668 # Create a file and check its states
1669 check_hsm_flags $file "0x00000000"
1671 # Ensure atime is less than mtime and ctime.
1675 atime0=$(stat -c "%X" $file)
1676 mtime0=$(stat -c "%Y" $file)
1677 ctime0=$(stat -c "%Z" $file)
1679 [ $atime0 -lt $mtime0 ] ||
1680 error "atime $atime0 is not less than mtime $mtime0"
1682 [ $atime0 -lt $ctime0 ] ||
1683 error "atime $atime0 is not less than ctime $ctime0"
1685 # Archive should not change any timestamps.
1686 $LFS hsm_archive $file || error "cannot archive '$file'"
1687 wait_request_state $fid ARCHIVE SUCCEED
1689 atime1=$(stat -c "%X" $file)
1690 mtime1=$(stat -c "%Y" $file)
1691 ctime1=$(stat -c "%Z" $file)
1693 [ $atime0 -eq $atime1 ] ||
1694 error "archive changed atime from $atime0 to $atime1"
1696 [ $mtime0 -eq $mtime1 ] ||
1697 error "archive changed mtime from $mtime0 to $mtime1"
1699 [ $ctime0 -eq $ctime1 ] ||
1700 error "archive changed ctime from $ctime0 to $ctime1"
1702 # Release should not change any timestamps.
1703 $LFS hsm_release $file || error "cannot release '$file'"
1704 check_hsm_flags $file "0x0000000d"
1706 atime1=$(stat -c "%X" $file)
1707 mtime1=$(stat -c "%Y" $file)
1708 ctime1=$(stat -c "%Z" $file)
1710 [ $atime0 -eq $atime1 ] ||
1711 error "release changed atime from $atime0 to $atime1"
1713 [ $mtime0 -eq $mtime1 ] ||
1714 error "release changed mtime from $mtime0 to $mtime1"
1716 [ $ctime0 -eq $ctime1 ] ||
1717 error "release changed ctime from $ctime0 to $ctime1"
1719 # Restore should not change atime or mtime and should not
1721 $LFS hsm_restore $file
1722 wait_request_state $fid RESTORE SUCCEED
1724 atime1=$(stat -c "%X" $file)
1725 mtime1=$(stat -c "%Y" $file)
1726 ctime1=$(stat -c "%Z" $file)
1728 [ $atime0 -eq $atime1 ] ||
1729 error "restore changed atime from $atime0 to $atime1"
1731 [ $mtime0 -eq $mtime1 ] ||
1732 error "restore changed mtime from $mtime0 to $mtime1"
1734 [ $ctime0 -le $ctime1 ] ||
1735 error "restore changed ctime from $ctime0 to $ctime1"
1739 # Once more, after unmount and mount.
1740 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1741 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1743 atime1=$(stat -c "%X" $file)
1744 mtime1=$(stat -c "%Y" $file)
1745 ctime1=$(stat -c "%Z" $file)
1747 [ $atime0 -eq $atime1 ] ||
1748 error "remount changed atime from $atime0 to $atime1"
1750 [ $mtime0 -eq $mtime1 ] ||
1751 error "remount changed mtime from $mtime0 to $mtime1"
1753 [ $ctime0 -le $ctime1 ] ||
1754 error "remount changed ctime from $ctime0 to $ctime1"
1756 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1759 local file=$DIR/$tdir/$tfile
1765 # Test needs a running copytool.
1769 # Check that root can do HSM actions on a ordinary user's file.
1771 fid=$(make_small $file)
1772 sum0=$(md5sum $file)
1774 chown $RUNAS_ID:$RUNAS_GID $file ||
1775 error "cannot chown '$file' to '$RUNAS_ID'"
1777 chmod ugo-w $DIR/$tdir ||
1778 error "cannot chmod '$DIR/$tdir'"
1780 $LFS hsm_archive $file
1781 wait_request_state $fid ARCHIVE SUCCEED
1783 $LFS hsm_release $file
1784 check_hsm_flags $file "0x0000000d"
1786 $LFS hsm_restore $file
1787 wait_request_state $fid RESTORE SUCCEED
1789 # Check that ordinary user can get HSM state.
1790 $RUNAS $LFS hsm_state $file ||
1791 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1793 $LFS hsm_release $file
1794 check_hsm_flags $file "0x0000000d"
1796 # Check that ordinary user can accessed released file.
1797 sum1=$($RUNAS md5sum $file) ||
1798 error "user '$RUNAS_ID' cannot read '$file'"
1800 [ "$sum0" == "$sum1" ] ||
1801 error "md5sum mismatch for '$file'"
1805 run_test 24b "root can archive, release, and restore user files"
1807 cleanup_test_24c() {
1809 set_hsm_param user_request_mask RESTORE
1810 set_hsm_param group_request_mask RESTORE
1811 set_hsm_param other_request_mask RESTORE
1815 local file=$DIR/$tdir/$tfile
1816 local action=archive
1821 # test needs a running copytool
1826 # Save the default masks and check that cleanup_24c will
1827 # restore the request masks correctly.
1828 user_save=$(get_hsm_param user_request_mask)
1829 group_save=$(get_hsm_param group_request_mask)
1830 other_save=$(get_hsm_param other_request_mask)
1832 [ "$user_save" == RESTORE ] ||
1833 error "user_request_mask is '$user_save' expected 'RESTORE'"
1834 [ "$group_save" == RESTORE ] ||
1835 error "group_request_mask is '$group_save' expected 'RESTORE'"
1836 [ "$other_save" == RESTORE ] ||
1837 error "other_request_mask is '$other_save' expected 'RESTORE'"
1839 trap cleanup_test_24c EXIT
1844 chown $RUNAS_ID:nobody $file ||
1845 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1847 set_hsm_param user_request_mask ""
1848 $RUNAS $LFS hsm_$action $file &&
1849 error "$action by user should fail"
1851 set_hsm_param user_request_mask $action
1852 $RUNAS $LFS hsm_$action $file ||
1853 error "$action by user should succeed"
1858 chown nobody:$RUNAS_GID $file ||
1859 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1861 set_hsm_param group_request_mask ""
1862 $RUNAS $LFS hsm_$action $file &&
1863 error "$action by group should fail"
1865 set_hsm_param group_request_mask $action
1866 $RUNAS $LFS hsm_$action $file ||
1867 error "$action by group should succeed"
1872 chown nobody:nobody $file ||
1873 error "cannot chown '$file' to 'nobody:nobody'"
1875 set_hsm_param other_request_mask ""
1876 $RUNAS $LFS hsm_$action $file &&
1877 error "$action by other should fail"
1879 set_hsm_param other_request_mask $action
1880 $RUNAS $LFS hsm_$action $file ||
1881 error "$action by other should succeed"
1886 run_test 24c "check that user,group,other request masks work"
1888 cleanup_test_24d() {
1890 mount -o remount,rw $MOUNT2
1894 local file1=$DIR/$tdir/$tfile
1895 local file2=$DIR2/$tdir/$tfile
1903 fid1=$(make_small $file1)
1905 trap cleanup_test_24d EXIT
1907 mount -o remount,ro $MOUNT2
1909 fid2=$(path2fid $file2)
1910 [ "$fid1" == "$fid2" ] ||
1911 error "FID mismatch '$fid1' != '$fid2'"
1913 $LFS hsm_archive $file2 &&
1914 error "archive should fail on read-only mount"
1915 check_hsm_flags $file1 "0x00000000"
1917 $LFS hsm_archive $file1
1918 wait_request_state $fid1 ARCHIVE SUCCEED
1920 $LFS hsm_release $file1
1921 $LFS hsm_restore $file2
1922 wait_request_state $fid1 RESTORE SUCCEED
1924 $LFS hsm_release $file1 || error "cannot release '$file1'"
1925 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1927 $LFS hsm_release $file2 &&
1928 error "release should fail on read-only mount"
1933 run_test 24d "check that read-only mounts are respected"
1936 # test needs a running copytool
1940 copy2archive /etc/hosts $tdir/$tfile
1942 local f=$DIR/$tdir/$tfile
1944 import_file $tdir/$tfile $f
1946 $LFS hsm_set --lost $f
1951 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1955 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1956 " (Operation not permitted)"
1959 # test needs a running copytool
1964 local f=$DIR/$tdir/$tfile
1965 local fid=$(copy_file /etc/passwd $f)
1967 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1968 wait_request_state $fid ARCHIVE SUCCEED
1971 $LFS hsm_set --lost $f
1975 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1979 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1980 " (Operation not permitted)"
1983 # test needs a running copytool
1987 local f=$DIR/$tdir/$tfile
1988 local fid=$(make_large_for_progress $f)
1989 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1990 wait_request_state $fid ARCHIVE SUCCEED
1993 wait_request_state $fid REMOVE SUCCEED
1995 check_hsm_flags $f "0x00000000"
1999 run_test 26 "Remove the archive of a valid file"
2002 # test needs a running copytool
2006 make_archive $tdir/$tfile
2007 local f=$DIR/$tdir/$tfile
2008 import_file $tdir/$tfile $f
2009 local fid=$(path2fid $f)
2013 [[ $? != 0 ]] || error "Remove of a released file should fail"
2017 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2020 # test needs a running copytool
2024 local f=$DIR/$tdir/$tfile
2025 local fid=$(make_large_for_progress $f)
2026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2027 wait_request_state $fid ARCHIVE SUCCEED
2032 [[ $? != 0 ]] || error "Remove of a released file should fail"
2036 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2039 # test needs a running copytool
2043 local f=$DIR/$tdir/$tfile
2044 local fid=$(make_large_for_progress $f)
2045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2046 wait_request_state $fid ARCHIVE SUCCEED
2055 wait_request_state $fid REMOVE SUCCEED
2059 run_test 28 "Concurrent archive/file remove"
2062 # restore at exec cannot work on agent node (because of Linux kernel
2063 # protection of executables)
2064 needclients 2 || return 0
2066 # test needs a running copytool
2070 copy2archive /bin/true $tdir/$tfile
2072 local f=$DIR/$tdir/true
2073 import_file $tdir/$tfile $f
2075 local fid=$(path2fid $f)
2077 # set no retry action mode
2083 # remove no try action mode
2087 [[ $st == 0 ]] || error "Failed to exec a released file"
2091 run_test 30a "Restore at exec (import case)"
2094 # restore at exec cannot work on agent node (because of Linux kernel
2095 # protection of executables)
2096 needclients 2 || return 0
2098 # test needs a running copytool
2102 local f=$DIR/$tdir/true
2103 local fid=$(copy_file /bin/true $f)
2105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2106 wait_request_state $fid ARCHIVE SUCCEED
2109 # set no retry action mode
2115 # remove no try action mode
2119 [[ $st == 0 ]] || error "Failed to exec a released file"
2123 run_test 30b "Restore at exec (release case)"
2126 needclients 2 || return 0
2128 # test needs a running copytool
2132 local f=$DIR/$tdir/SLEEP
2133 local fid=$(copy_file /bin/sleep $f)
2135 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2136 wait_request_state $fid ARCHIVE SUCCEED
2138 check_hsm_flags $f "0x0000000d"
2139 # set no retry action mode
2141 do_node $CLIENT2 "$f 10" &
2145 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2147 [[ $? == 0 ]] || error "Execution failed during run"
2149 [[ $? == 0 ]] || error "Binary overwritten during exec"
2152 # remove no try action mode
2154 check_hsm_flags $f "0x00000009"
2158 run_test 30c "Update during exec of released file must fail"
2160 restore_and_check_size() {
2163 local s=$(stat -c "%s" $f)
2165 local st=$(get_hsm_flags $f)
2169 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2171 n=$(stat -c "%s" $f)
2172 # we echo in both cases to show stat is not
2174 if [[ $n != $s ]]; then
2175 echo "size seen is $n != $s"
2178 echo "size seen is right: $n == $s"
2180 st=$(get_hsm_flags $f)
2184 if [[ $cpt -lt 10 ]]; then
2187 echo " restore is too long"
2188 wait_request_state $fid RESTORE SUCCEED
2194 # test needs a running copytool
2199 make_archive $tdir/$tfile
2200 local f=$DIR/$tdir/$tfile
2201 import_file $tdir/$tfile $f
2202 local fid=$($LFS path2fid $f)
2203 HSM_ARCHIVE_PURGE=false copytool_setup
2205 restore_and_check_size $f $fid
2208 [[ $err -eq 0 ]] || error "File size changed during restore"
2212 run_test 31a "Import a large file and check size during restore"
2216 # test needs a running copytool
2221 local f=$DIR/$tdir/$tfile
2222 local fid=$(make_large_for_progress $f)
2223 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2224 wait_request_state $fid ARCHIVE SUCCEED
2227 restore_and_check_size $f $fid
2230 [[ $err -eq 0 ]] || error "File size changed during restore"
2234 run_test 31b "Restore a large unaligned file and check size during restore"
2237 # test needs a running copytool
2242 local f=$DIR/$tdir/$tfile
2243 local fid=$(make_large_for_progress_aligned $f)
2244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2245 wait_request_state $fid ARCHIVE SUCCEED
2248 restore_and_check_size $f $fid
2251 [[ $err -eq 0 ]] || error "File size changed during restore"
2255 run_test 31c "Restore a large aligned file and check size during restore"
2258 # test needs a running copytool
2263 local f=$DIR/$tdir/$tfile
2264 local fid=$(make_large_for_progress $f)
2265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2266 wait_request_state $fid ARCHIVE SUCCEED
2269 # to be sure wait_all_done will not be mislead by previous tests
2272 wait_for_grace_delay
2273 # Also raise grace_delay significantly so the Canceled
2274 # Restore action will stay enough long avail.
2275 local old_grace=$(get_hsm_param grace_delay)
2276 set_hsm_param grace_delay 100
2278 md5sum $f >/dev/null &
2280 wait_request_state $fid RESTORE STARTED
2285 # Check restore trigger process was killed
2286 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2290 # instead of waiting+checking both Restore and Cancel ops
2291 # sequentially, wait for both to be finished and then check
2293 wait_all_done 100 $fid
2294 local rstate=$(get_request_state $fid RESTORE)
2295 local cstate=$(get_request_state $fid CANCEL)
2297 # restore orig grace_delay.
2298 set_hsm_param grace_delay $old_grace
2300 if [[ "$rstate" == "CANCELED" ]] ; then
2301 [[ "$cstate" == "SUCCEED" ]] ||
2302 error "Restore state is CANCELED and Cancel state " \
2303 "is not SUCCEED but $cstate"
2304 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2305 elif [[ "$rstate" == "SUCCEED" ]] ; then
2306 [[ "$cstate" == "FAILED" ]] ||
2307 error "Restore state is SUCCEED and Cancel state " \
2308 "is not FAILED but $cstate"
2309 echo "Restore state is SUCCEED, Cancel state is FAILED"
2311 error "Restore state is $rstate and Cancel state is $cstate"
2315 error "Cannot kill process waiting for restore ($killed)"
2319 run_test 33 "Kill a restore waiting process"
2322 # test needs a running copytool
2327 local f=$DIR/$tdir/$tfile
2328 local fid=$(make_large_for_progress $f)
2329 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2330 wait_request_state $fid ARCHIVE SUCCEED
2333 md5sum $f >/dev/null &
2335 wait_request_state $fid RESTORE STARTED
2337 rm $f || error "rm $f failed"
2338 # rm must not block during restore
2339 wait_request_state $fid RESTORE STARTED
2341 wait_request_state $fid RESTORE SUCCEED
2342 # check md5sum pgm finished
2343 local there=$(ps -o pid,comm hp $pid >/dev/null)
2344 [[ -z $there ]] || error "Restore initiator does not exit"
2346 local rc=$(wait $pid)
2347 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2351 run_test 34 "Remove file during restore"
2354 # test needs a running copytool
2359 local f=$DIR/$tdir/$tfile
2360 local f1=$DIR/$tdir/$tfile-1
2361 local fid=$(make_large_for_progress $f)
2362 local fid1=$(copy_file /etc/passwd $f1)
2363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2364 wait_request_state $fid ARCHIVE SUCCEED
2367 md5sum $f >/dev/null &
2369 wait_request_state $fid RESTORE STARTED
2371 mv $f1 $f || error "mv $f1 $f failed"
2372 # mv must not block during restore
2373 wait_request_state $fid RESTORE STARTED
2375 wait_request_state $fid RESTORE SUCCEED
2376 # check md5sum pgm finished
2377 local there=$(ps -o pid,comm hp $pid >/dev/null)
2378 [[ -z $there ]] || error "Restore initiator does not exit"
2380 local rc=$(wait $pid)
2381 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2384 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2388 run_test 35 "Overwrite file during restore"
2391 # test needs a running copytool
2396 local f=$DIR/$tdir/$tfile
2397 local fid=$(make_large_for_progress $f)
2398 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2399 wait_request_state $fid ARCHIVE SUCCEED
2402 md5sum $f >/dev/null &
2404 wait_request_state $fid RESTORE STARTED
2407 # rm must not block during restore
2408 wait_request_state $fid RESTORE STARTED
2410 wait_request_state $fid RESTORE SUCCEED
2411 # check md5sum pgm finished
2412 local there=$(ps -o pid,comm hp $pid >/dev/null)
2414 error "Restore initiator does not exit"
2416 local rc=$(wait $pid)
2418 error "Restore initiator failed with $rc"
2422 run_test 36 "Move file during restore"
2429 for n in $(seq 1 $count); do
2430 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2432 echo "$count archive requests submitted"
2436 local stream_count=4
2437 local file_count=100
2439 local f=$DIR/$tdir/$tfile
2444 for i in $(seq 1 $file_count); do
2445 for p in $(seq 1 $stream_count); do
2446 fid=$(copy_file /etc/hosts $f.$p.$i)
2449 # force copytool to use a local/temp archive dir to ensure best
2450 # performance vs remote/NFS mounts used in auto-tests
2451 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2454 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2456 # to be sure wait_all_done will not be mislead by previous tests
2458 wait_for_grace_delay
2460 # start archive streams in background (archive files in parallel)
2461 for p in $(seq 1 $stream_count); do
2462 multi_archive $f.$p $file_count &
2465 echo -n "Wait for all requests being enqueued..."
2471 run_test 40 "Parallel archive requests"
2474 # test needs a running copytool
2478 local f=$DIR/$tdir/$tfile
2479 local fid=$(copy_file /etc/motd $f 1)
2481 $LFS hsm_archive $f || error "could not archive file"
2482 wait_request_state $fid ARCHIVE SUCCEED
2483 check_hsm_flags $f "0x00000009"
2485 multiop_bg_pause $f O_c || error "multiop failed"
2489 client_up || client_up || true
2491 kill -USR1 $MULTIPID
2492 wait $MULTIPID || error "multiop close failed"
2494 check_hsm_flags $f "0x0000000b"
2498 run_test 52 "Opened for write file on an evicted client should be set dirty"
2501 # test needs a running copytool
2505 local f=$DIR/$tdir/$tfile
2506 local fid=$(copy_file /etc/motd $f 1)
2508 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2509 error "could not archive file"
2510 wait_request_state $fid ARCHIVE SUCCEED
2511 check_hsm_flags $f "0x00000009"
2513 multiop_bg_pause $f o_c || error "multiop failed"
2517 client_up || client_up || true
2519 kill -USR1 $MULTIPID
2520 wait $MULTIPID || error "multiop close failed"
2522 check_hsm_flags $f "0x00000009"
2526 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2529 # test needs a running copytool
2533 local f=$DIR/$tdir/$tfile
2534 local fid=$(make_small $f)
2536 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2537 error "could not archive file"
2538 wait_request_state $fid ARCHIVE STARTED
2540 check_hsm_flags $f "0x00000001"
2542 # Avoid coordinator resending this request as soon it has failed.
2547 wait_request_state $fid ARCHIVE FAILED
2549 check_hsm_flags $f "0x00000003"
2554 run_test 54 "Write during an archive cancels it"
2557 # test needs a running copytool
2561 local f=$DIR/$tdir/$tfile
2562 local fid=$(make_small $f)
2564 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2565 error "could not archive file"
2566 wait_request_state $fid ARCHIVE STARTED
2568 check_hsm_flags $f "0x00000001"
2570 # Avoid coordinator resending this request as soon it has failed.
2573 $TRUNCATE $f 1024 || error "truncate failed"
2575 wait_request_state $fid ARCHIVE FAILED
2577 check_hsm_flags $f "0x00000003"
2582 run_test 55 "Truncate during an archive cancels it"
2585 # test needs a running copytool
2589 local f=$DIR/$tdir/$tfile
2590 local fid=$(make_large_for_progress $f)
2592 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2593 error "could not archive file"
2594 wait_request_state $fid ARCHIVE STARTED
2596 check_hsm_flags $f "0x00000001"
2598 # Change metadata and sync to be sure we are not changing only
2603 wait_request_state $fid ARCHIVE SUCCEED
2605 check_hsm_flags $f "0x00000009"
2609 run_test 56 "Setattr during an archive is ok"
2612 # Need one client for I/O, one for request
2613 needclients 2 || return 0
2615 # test needs a running copytool
2619 local f=$DIR/$tdir/test_archive_remote
2620 # Create a file on a remote node
2621 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2622 "count=2 conv=fsync"
2625 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2626 error "hsm_archive failed"
2627 local fid=$(path2fid $f)
2628 wait_request_state $fid ARCHIVE SUCCEED
2630 # Release and implicit restore it
2631 do_node $CLIENT2 "$LFS hsm_release $f" ||
2632 error "hsm_release failed"
2633 do_node $CLIENT2 "md5sum $f" ||
2634 error "hsm_restore failed"
2636 wait_request_state $fid RESTORE SUCCEED
2640 run_test 57 "Archive a file with dirty cache on another node"
2642 truncate_released_file() {
2646 local sz=$(stat -c %s $src_file)
2647 local f=$DIR/$tdir/$tfile
2648 local fid=$(copy_file $1 $f)
2652 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2653 error "could not archive file"
2654 wait_request_state $fid ARCHIVE SUCCEED
2656 $LFS hsm_release $f || error "could not release file"
2658 $TRUNCATE $f $trunc_to || error "truncate failed"
2661 local sz1=$(stat -c %s $f)
2662 [[ $sz1 == $trunc_to ]] ||
2663 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2666 check_hsm_flags $f "0x0000000b"
2668 local state=$(get_request_state $fid RESTORE)
2669 [[ "$state" == "SUCCEED" ]] ||
2670 error "truncate $sz does not trig restore, state = $state"
2672 $TRUNCATE $ref $trunc_to
2673 cmp $ref $f || error "file data wrong after truncate"
2679 # test needs a running copytool
2684 local sz=$(stat -c %s /etc/passwd)
2686 echo "truncate up from $sz to $((sz*2))"
2687 truncate_released_file /etc/passwd $((sz*2))
2689 echo "truncate down from $sz to $((sz/2))"
2690 truncate_released_file /etc/passwd $((sz/2))
2692 echo "truncate to 0"
2693 truncate_released_file /etc/passwd 0
2697 run_test 58 "Truncate a released file will trigger restore"
2700 # This test validates the fix for LU-4512. Ensure that the -u
2701 # option changes the progress reporting interval from the
2702 # default (30 seconds) to the user-specified interval.
2704 local progress_timeout=$((interval * 4))
2706 # test needs a new running copytool
2708 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2711 local f=$DIR/$tdir/$tfile
2712 local fid=$(make_large_for_progress $f)
2715 local mdt=${MDT_PREFIX}${mdtidx}
2716 local mds=mds$((mdtidx + 1))
2718 # Wait for copytool to register
2719 wait_update_facet $mds \
2720 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2721 uuid 100 || error "coyptool failed to register with $mdt"
2723 local start_at=$(date +%s)
2724 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2725 error "could not archive file"
2727 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2728 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2734 echo -n "Expecting a progress update within $progress_timeout seconds... "
2736 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2737 if [ $RESULT -gt 0 ]; then
2738 echo "$RESULT bytes copied in $WAIT seconds."
2740 elif [ $WAIT -ge $progress_timeout ]; then
2741 error "Timed out waiting for progress update!"
2743 WAIT=$((WAIT + sleep))
2747 local finish_at=$(date +%s)
2748 local elapsed=$((finish_at - start_at))
2750 # Ensure that the progress update occurred within the expected window.
2751 if [ $elapsed -lt $interval ]; then
2752 error "Expected progress update after at least $interval seconds"
2758 run_test 60 "Changing progress update interval from default"
2761 # test needs a new running copytool
2763 copytool_monitor_setup
2764 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2766 # Just start and stop the copytool to generate events.
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
2993 # force copytool to use a local/temp archive dir to ensure best
2994 # performance vs remote/NFS mounts used in auto-tests
2995 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2998 local dai=$(get_hsm_param default_archive_id)
2999 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3001 # to be sure wait_all_done will not be mislead by previous tests
3003 wait_for_grace_delay
3004 $LFS hsm_archive --filelist $FILELIST ||
3005 error "cannot archive a file list"
3007 $LFS hsm_release --filelist $FILELIST ||
3008 error "cannot release a file list"
3009 $LFS hsm_restore --filelist $FILELIST ||
3010 error "cannot restore a file list"
3014 run_test 90 "Archive/restore a file list"
3016 double_verify_reset_hsm_param() {
3018 echo "Testing $HSM_PARAM.$p"
3019 local val=$(get_hsm_param $p)
3021 local val2=$(($val * 2))
3022 set_hsm_param $p $val2
3023 val=$(get_hsm_param $p)
3024 [[ $val == $val2 ]] ||
3025 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3026 echo "Set $p to 0 must failed"
3030 set_hsm_param $p $save
3032 if [[ $rc == 0 ]]; then
3033 error "we must not be able to set $HSM_PARAM.$p to 0"
3038 double_verify_reset_hsm_param loop_period
3039 double_verify_reset_hsm_param grace_delay
3040 double_verify_reset_hsm_param active_request_timeout
3041 double_verify_reset_hsm_param max_requests
3042 double_verify_reset_hsm_param default_archive_id
3044 run_test 100 "Set coordinator /proc tunables"
3051 run_test 102 "Verify coordinator control"
3054 # test needs a running copytool
3061 for i in $(seq 1 20); do
3062 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3068 echo "Current requests"
3069 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3070 $HSM_PARAM.actions |\
3071 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3073 [[ -z "$res" ]] || error "Some request have not been canceled"
3077 run_test 103 "Purge all requests"
3082 # test needs a running copytool
3086 local f=$DIR/$tdir/$tfile
3087 local fid=$(make_large_for_progress $f)
3088 # if cdt is on, it can serve too quickly the request
3090 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3091 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3092 $HSM_PARAM.actions |\
3093 grep $fid | cut -f16 -d=")
3096 [[ "$data1" == "$DATAHEX" ]] ||
3097 error "Data field in records is ($data1) and not ($DATAHEX)"
3101 run_test 104 "Copy tool data field"
3108 for i in $(seq -w 1 10); do
3109 cp /etc/passwd $DIR/$tdir/$i
3110 $LFS hsm_archive $DIR/$tdir/$i
3112 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3113 $HSM_PARAM.actions |\
3114 grep WAITING | wc -l")
3117 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3118 $HSM_PARAM.actions |\
3119 grep WAITING | wc -l")
3122 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3123 error "Requests count after shutdown $reqcnt2 != "\
3124 "before shutdown $reqcnt1"
3126 run_test 105 "Restart of coordinator"
3128 get_agent_by_uuid_mdt() {
3131 local mds=mds$(($mdtidx + 1))
3132 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3136 check_agent_registered_by_mdt() {
3139 local mds=mds$(($mdtidx + 1))
3140 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3141 if [[ ! -z "$agent" ]]; then
3142 echo "found agent $agent on $mds"
3144 error "uuid $uuid not found in agent list on $mds"
3148 check_agent_unregistered_by_mdt() {
3151 local mds=mds$(($mdtidx + 1))
3152 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3153 if [[ -z "$agent" ]]; then
3154 echo "uuid not found in agent list on $mds"
3156 error "uuid found in agent list on $mds: $agent"
3160 check_agent_registered() {
3163 for mdsno in $(seq 1 $MDSCOUNT); do
3164 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3168 check_agent_unregistered() {
3171 for mdsno in $(seq 1 $MDSCOUNT); do
3172 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3177 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3178 get_client_uuid $MOUNT | cut -d' ' -f2)
3181 check_agent_registered $uuid
3183 search_copytools || error "No copytool found"
3186 check_agent_unregistered $uuid
3189 check_agent_registered $uuid
3193 run_test 106 "Copytool register/unregister"
3196 # test needs a running copytool
3198 # create and archive file
3200 local f1=$DIR/$tdir/$tfile
3201 local fid=$(copy_file /etc/passwd $f1)
3202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3203 wait_request_state $fid ARCHIVE SUCCEED
3204 # shutdown and restart MDS
3206 # check the copytool still gets messages from MDT
3207 local f2=$DIR/$tdir/2
3208 local fid=$(copy_file /etc/passwd $f2)
3209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3210 # main check of this sanity: this request MUST succeed
3211 wait_request_state $fid ARCHIVE SUCCEED
3214 run_test 107 "Copytool re-register after MDS restart"
3216 policy_set_and_test()
3220 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3221 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3222 [[ "$policy" == "$target" ]] ||
3223 error "Wrong policy after '$change': '$policy' != '$target'"
3227 # to force default policy setting if error
3228 CDT_POLICY_HAD_CHANGED=true
3230 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3231 local default="NonBlockingRestore [NoRetryAction]"
3232 [[ "$policy" == "$default" ]] ||
3233 error "default policy has changed,"\
3234 " '$policy' != '$default' update the test"
3235 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3236 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3237 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3238 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3239 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3240 # useless bacause we know but safer for futur changes to use real value
3241 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3242 echo "Next set_param must failed"
3243 policy_set_and_test "wrong" "$policy"
3246 echo "Back to default policy"
3247 cdt_set_sanity_policy
3249 run_test 109 "Policy display/change"
3252 # test needs a running copytool
3257 copy2archive /etc/passwd $tdir/$tfile
3259 local f=$DIR/$tdir/$tfile
3260 import_file $tdir/$tfile $f
3261 local fid=$(path2fid $f)
3263 cdt_set_non_blocking_restore
3268 wait_request_state $fid RESTORE SUCCEED
3269 cdt_clear_non_blocking_restore
3273 error "md5sum returns $st != 1, "\
3274 "should also perror ENODATA (No data available)"
3278 run_test 110a "Non blocking restore policy (import case)"
3281 # test needs a running copytool
3285 local f=$DIR/$tdir/$tfile
3286 local fid=$(copy_file /etc/passwd $f)
3287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3288 wait_request_state $fid ARCHIVE SUCCEED
3291 cdt_set_non_blocking_restore
3296 wait_request_state $fid RESTORE SUCCEED
3297 cdt_clear_non_blocking_restore
3301 error "md5sum returns $st != 1, "\
3302 "should also perror ENODATA (No data available)"
3306 run_test 110b "Non blocking restore policy (release case)"
3309 # test needs a running copytool
3313 copy2archive /etc/passwd $tdir/$tfile
3315 local f=$DIR/$tdir/$tfile
3317 import_file $tdir/$tfile $f
3318 local fid=$(path2fid $f)
3322 copytool_remove_backend $fid
3325 wait_request_state $fid RESTORE FAILED
3332 [[ $st == 0 ]] || error "Restore does not failed"
3336 run_test 111a "No retry policy (import case), restore will error"\
3337 " (No such file or directory)"
3340 # test needs a running copytool
3344 local f=$DIR/$tdir/$tfile
3345 local fid=$(copy_file /etc/passwd $f)
3347 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3348 wait_request_state $fid ARCHIVE SUCCEED
3351 copytool_remove_backend $fid
3354 wait_request_state $fid RESTORE FAILED
3361 [[ $st == 0 ]] || error "Restore does not failed"
3365 run_test 111b "No retry policy (release case), restore will error"\
3366 " (No such file or directory)"
3369 # test needs a running copytool
3373 local f=$DIR/$tdir/$tfile
3374 local fid=$(copy_file /etc/passwd $f)
3376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3377 local l=$($LFS hsm_action $f)
3379 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3383 wait_request_state $fid ARCHIVE SUCCEED
3386 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3390 run_test 112 "State of recorded request"
3393 # test needs a running copytool
3397 local f=$DIR/$tdir/$tfile
3398 local fid=$(make_large_for_cancel $f)
3399 # test with cdt on is made in test_221
3401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3404 wait_request_state $fid ARCHIVE CANCELED
3405 wait_request_state $fid CANCEL SUCCEED
3409 run_test 200 "Register/Cancel archive"
3412 # test needs a running copytool
3416 local f=$DIR/$tdir/$tfile
3417 make_archive $tdir/$tfile
3418 import_file $tdir/$tfile $f
3419 local fid=$(path2fid $f)
3421 # test with cdt on is made in test_222
3426 wait_request_state $fid RESTORE CANCELED
3427 wait_request_state $fid CANCEL SUCCEED
3431 run_test 201 "Register/Cancel restore"
3434 # test needs a running copytool
3438 local f=$DIR/$tdir/$tfile
3439 local fid=$(make_large_for_progress $f)
3440 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3441 wait_request_state $fid ARCHIVE SUCCEED
3447 wait_request_state $fid REMOVE CANCELED
3451 run_test 202 "Register/Cancel remove"
3454 # test needs a running copytool
3459 local f=$DIR/$tdir/$tfile
3460 local fid=$(copy_file /etc/passwd $f)
3464 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3465 wait_request_state $fid ARCHIVE SUCCEED
3467 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3471 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3475 run_test 220 "Changelog for archive"
3478 # test needs a running copytool
3483 local f=$DIR/$tdir/$tfile
3484 local fid=$(make_large_for_cancel $f)
3488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3489 wait_request_state $fid ARCHIVE STARTED
3491 wait_request_state $fid ARCHIVE CANCELED
3492 wait_request_state $fid CANCEL SUCCEED
3494 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3497 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3501 run_test 221 "Changelog for archive canceled"
3504 # test needs a running copytool
3508 copy2archive /etc/passwd $tdir/$tfile
3510 local f=$DIR/$tdir/$tfile
3511 import_file $tdir/$tfile $f
3512 local fid=$(path2fid $f)
3517 wait_request_state $fid RESTORE SUCCEED
3519 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3522 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3526 run_test 222a "Changelog for explicit restore"
3529 # test needs a running copytool
3533 local f=$DIR/$tdir/$tfile
3534 local fid=$(copy_file /etc/passwd $f)
3537 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3538 wait_request_state $fid ARCHIVE SUCCEED
3543 wait_request_state $fid RESTORE SUCCEED
3545 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3548 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3552 run_test 222b "Changelog for implicit restore"
3555 # test needs a running copytool
3560 local f=$DIR/$tdir/$tfile
3561 make_archive $tdir/$tfile
3565 import_file $tdir/$tfile $f
3566 local fid=$(path2fid $f)
3569 wait_request_state $fid RESTORE STARTED
3571 wait_request_state $fid RESTORE CANCELED
3572 wait_request_state $fid CANCEL SUCCEED
3574 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3577 [[ $flags == $target ]] ||
3578 error "Changelog flag is $flags not $target"
3582 run_test 223a "Changelog for restore canceled (import case)"
3585 # test needs a running copytool
3590 local f=$DIR/$tdir/$tfile
3591 local fid=$(make_large_for_progress $f)
3594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3595 wait_request_state $fid ARCHIVE SUCCEED
3598 wait_request_state $fid RESTORE STARTED
3600 wait_request_state $fid RESTORE CANCELED
3601 wait_request_state $fid CANCEL SUCCEED
3603 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3606 [[ $flags == $target ]] ||
3607 error "Changelog flag is $flags not $target"
3611 run_test 223b "Changelog for restore canceled (release case)"
3614 # test needs a running copytool
3619 local f=$DIR/$tdir/$tfile
3620 local fid=$(copy_file /etc/passwd $f)
3623 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3624 wait_request_state $fid ARCHIVE SUCCEED
3627 wait_request_state $fid REMOVE SUCCEED
3629 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3632 [[ $flags == $target ]] ||
3633 error "Changelog flag is $flags not $target"
3637 run_test 224 "Changelog for remove"
3640 # test needs a running copytool
3643 # test is not usable because remove request is too fast
3644 # so it is always finished before cancel can be done ...
3645 echo "Test disabled"
3650 local f=$DIR/$tdir/$tfile
3651 local fid=$(make_large_for_progress $f)
3654 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3655 wait_request_state $fid ARCHIVE SUCCEED
3657 # if cdt is on, it can serve too quickly the request
3662 wait_request_state $fid REMOVE CANCELED
3663 wait_request_state $fid CANCEL SUCCEED
3665 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3666 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3667 tail -n 1 | awk '{print $5}')
3670 [[ $flags == $target ]] ||
3671 error "Changelog flag is $flags not $target"
3675 run_test 225 "Changelog for remove canceled"
3678 # test needs a running copytool
3683 local f1=$DIR/$tdir/$tfile-1
3684 local f2=$DIR/$tdir/$tfile-2
3685 local f3=$DIR/$tdir/$tfile-3
3686 local fid1=$(copy_file /etc/passwd $f1)
3687 local fid2=$(copy_file /etc/passwd $f2)
3688 copy_file /etc/passwd $f3
3691 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3692 wait_request_state $fid1 ARCHIVE SUCCEED
3694 $LFS hsm_archive $f2
3695 wait_request_state $fid2 ARCHIVE SUCCEED
3697 rm $f1 || error "rm $f1 failed"
3699 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3702 [[ $flags == $target ]] ||
3703 error "Changelog flag is $flags not $target"
3705 mv $f3 $f2 || error "mv $f3 $f2 failed"
3707 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3710 [[ $flags == $target ]] ||
3711 error "Changelog flag is $flags not $target"
3715 run_test 226 "changelog for last rm/mv with exiting archive"
3717 check_flags_changes() {
3725 $LFS hsm_set --$hsm_flag $f ||
3726 error "Cannot set $hsm_flag on $f"
3727 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3728 local seen=${#flags[*]}
3730 [[ $seen == $cnt ]] ||
3731 error "set $hsm_flag: Changelog events $seen != $cnt"
3732 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3733 error "set $hsm_flag: Changelog flags are "\
3734 "${flags[$((cnt - 1))]} not $target"
3736 $LFS hsm_clear --$hsm_flag $f ||
3737 error "Cannot clear $hsm_flag on $f"
3738 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3741 [[ $cnt == $seen ]] ||
3742 error "clear $hsm_flag: Changelog events $seen != $cnt"
3744 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3745 error "clear $hsm_flag: Changelog flag is "\
3746 "${flags[$((cnt - 1))]} not $target"
3750 # test needs a running copytool
3757 for i in norelease noarchive exists archived
3759 local f=$DIR/$tdir/$tfile-$i
3760 local fid=$(copy_file /etc/passwd $f)
3761 check_flags_changes $f $fid $i 0 1
3764 f=$DIR/$tdir/$tfile---lost
3765 fid=$(copy_file /etc/passwd $f)
3766 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3767 wait_request_state $fid ARCHIVE SUCCEED
3768 check_flags_changes $f $fid lost 3 1
3772 run_test 227 "changelog when explicit setting of HSM flags"
3775 # test needs a running copytool
3778 local fid=$(make_small_sync $DIR/$tfile)
3779 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3780 wait_request_state $fid ARCHIVE SUCCEED
3782 $LFS hsm_release $DIR/$tfile
3783 check_hsm_flags $DIR/$tfile "0x0000000d"
3785 filefrag $DIR/$tfile | grep " 1 extent found" ||
3786 error "filefrag on released file must return only one extent"
3788 # only newer versions of cp detect sparse files by stat/FIEMAP
3790 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3791 error "copying $DIR/$tfile"
3792 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3794 $LFS hsm_release $DIR/$tfile
3795 check_hsm_flags $DIR/$tfile "0x0000000d"
3797 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3799 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3801 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3802 error "comparing untarred $DIR/$tfile"
3804 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3805 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3808 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3811 # test needs a running copytool
3815 local maxrequest=$(get_hsm_param max_requests)
3816 local rqcnt=$(($maxrequest * 3))
3820 for i in $(seq -w 1 $rqcnt); do
3822 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3824 # we do it in 2 steps, so all requests arrive at the same time
3825 for i in $(seq -w 1 $rqcnt); do
3826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3831 while [[ $cnt != 0 || $wt != 0 ]]; do
3833 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3834 $HSM_PARAM.actions |\
3835 grep STARTED | grep -v CANCEL | wc -l")
3836 [[ $cnt -le $maxrequest ]] ||
3837 error "$cnt > $maxrequest too many started requests"
3838 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3839 $HSM_PARAM.actions |\
3840 grep WAITING | wc -l")
3841 echo "max=$maxrequest started=$cnt waiting=$wt"
3846 run_test 250 "Coordinator max request"
3849 # test needs a running copytool
3853 local f=$DIR/$tdir/$tfile
3854 local fid=$(make_large_for_cancel $f)
3857 # to have a short test
3858 local old_to=$(get_hsm_param active_request_timeout)
3859 set_hsm_param active_request_timeout 4
3860 # to be sure the cdt will wake up frequently so
3861 # it will be able to cancel the "old" request
3862 local old_loop=$(get_hsm_param loop_period)
3863 set_hsm_param loop_period 2
3866 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3867 wait_request_state $fid ARCHIVE STARTED
3869 wait_request_state $fid ARCHIVE CANCELED
3871 set_hsm_param active_request_timeout $old_to
3872 set_hsm_param loop_period $old_loop
3876 run_test 251 "Coordinator request timeout"
3879 # the only way to test ondisk conf is to restart MDS ...
3880 echo "Stop coordinator and remove coordinator state at mount"
3883 # clean on disk conf set by default
3884 cdt_clear_mount_state
3885 cdt_check_state stopped
3887 # check cdt still off after umount/remount
3889 cdt_check_state stopped
3891 echo "Set coordinator start at mount, and start coordinator"
3892 cdt_set_mount_state enabled
3895 cdt_check_state enabled
3897 # check cdt still on after umount/remount
3899 cdt_check_state enabled
3901 # we are back to original state (cdt started at mount)
3903 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3906 local ai=$(get_hsm_param default_archive_id)
3907 local new=$((ai + 1))
3909 set_hsm_param default_archive_id $new -P
3911 local res=$(get_hsm_param default_archive_id)
3914 set_hsm_param default_archive_id "" "-P -d"
3916 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3918 run_test 301 "HSM tunnable are persistent"
3921 local ai=$(get_hsm_param default_archive_id)
3922 local new=$((ai + 1))
3927 set_hsm_param default_archive_id $new -P
3930 for mdtno in $(seq 1 $MDSCOUNT); do
3935 cdt_check_state enabled
3937 local res=$(get_hsm_param default_archive_id)
3940 set_hsm_param default_archive_id "" "-P -d"
3942 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3944 run_test 302 "HSM tunnable are persistent when CDT is off"
3947 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3953 local dir_mdt0=$DIR/$tdir/mdt0
3954 local dir_mdt1=$DIR/$tdir/mdt1
3956 # create 1 dir per MDT
3957 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3958 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3960 # create 1 file in each MDT
3961 local fid1=$(make_small $dir_mdt0/$tfile)
3962 local fid2=$(make_small $dir_mdt1/$tfile)
3964 # check that hsm request on mdt0 is sent to the right MDS
3965 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3966 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3967 echo "archive successful on mdt0"
3969 # check that hsm request on mdt1 is sent to the right MDS
3970 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3971 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3972 echo "archive successful on mdt1"
3975 # clean test files and directories
3976 rm -rf $dir_mdt0 $dir_mdt1
3978 run_test 400 "Single request is sent to the right MDT"
3981 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3987 local dir_mdt0=$DIR/$tdir/mdt0
3988 local dir_mdt1=$DIR/$tdir/mdt1
3990 # create 1 dir per MDT
3991 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3992 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3994 # create 1 file in each MDT
3995 local fid1=$(make_small $dir_mdt0/$tfile)
3996 local fid2=$(make_small $dir_mdt1/$tfile)
3998 # check that compound requests are shunt to the rights MDTs
3999 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4000 error "lfs hsm_archive"
4001 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4002 echo "archive successful on mdt0"
4003 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4004 echo "archive successful on mdt1"
4007 # clean test files and directories
4008 rm -rf $dir_mdt0 $dir_mdt1
4010 run_test 401 "Compound requests split and sent to their respective MDTs"
4012 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4017 local node=$(facet_active_host $facet)
4019 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4020 awk '{print $4}'); do
4021 echo "$3 $mdc on $node"
4022 do_facet $facet "$LCTL --device $mdc $state" || return 1
4027 # make sure there is no running copytool
4030 # deactivate all mdc on agent1
4031 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4033 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4035 check_agent_unregistered "uuid" # match any agent
4037 # no expected running copytool
4038 search_copytools $agent && error "Copytool start should have failed"
4041 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4043 run_test 402 "Copytool start fails if all MDTs are inactive"
4046 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4048 # make sure there is no running copytool
4051 local agent=$(facet_active_host $SINGLEAGT)
4052 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4054 # deactivate all mdc for MDT0001
4055 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4058 # check the agent is registered on MDT0000, and not on MDT0001
4059 check_agent_registered_by_mdt $uuid 0
4060 check_agent_unregistered_by_mdt $uuid 1
4062 # check running copytool process
4063 search_copytools $agent || error "No running copytools on $agent"
4065 # reactivate all mdc for MDT0001
4066 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4068 # make sure the copytool is now registered to all MDTs
4069 check_agent_registered $uuid
4073 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4076 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4080 # create files on both MDT0000 and MDT0001
4083 local dir_mdt0=$DIR/$tdir/mdt0
4084 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4086 # create 1 file on mdt0
4087 local fid1=$(make_small $dir_mdt0/$tfile)
4089 # deactivate all mdc for MDT0001
4090 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4092 # send an HSM request for files in MDT0000
4093 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4095 # check for completion of files in MDT0000
4096 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4097 echo "archive successful on mdt0"
4099 # reactivate all mdc for MDT0001
4100 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4103 # clean test files and directories
4106 run_test 404 "Inactive MDT does not block requests for active MDTs"
4111 check_and_cleanup_lustre