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 "Only wakeup running 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)
276 local end_wait=$(( SECONDS + TIMEOUT ))
278 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
280 while (( SECONDS < end_wait )); do
282 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
283 if [ $? -ne 0 ]; then
284 echo "Copytool is stopped on $agents"
287 echo "Copytool still running on $agents"
289 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
290 error "Copytool failed to stop in ${TIMEOUT}s ..."
292 echo "Copytool has stopped in " \
293 "$((TIMEOUT - (end_wait - SECONDS)))s."
296 # clean all CDTs orphans requests from previous tests
297 # that would otherwise need to timeout to clear.
298 for mdtno in $(seq 1 $MDSCOUNT); do
300 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
301 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
303 # skip already stop[ed,ing] CDTs
304 echo $oldstate | grep stop && continue
306 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
307 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
309 error "mds${mdtno} cdt state is not stopped"
310 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
311 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
313 error "mds${mdtno} cdt state is not $oldstate"
315 do_facet $facet "rm -rf $hsm_root"
319 local agents=${1:-$(facet_active_host $SINGLEAGT)}
321 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
322 echo "Copytool is suspended on $agents"
325 copytool_remove_backend() {
327 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
328 echo "Remove from backend: $fid = $be"
329 do_facet $SINGLEAGT rm -f $be
333 do_facet $SINGLEAGT \
334 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
335 --import $1 $2 $MOUNT" ||
336 error "import of $1 to $2 failed"
340 local file=$HSM_ARCHIVE/$1
341 do_facet $SINGLEAGT mkdir -p $(dirname $file)
342 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
343 error "cannot create $file"
347 local file=$HSM_ARCHIVE/$2
348 do_facet $SINGLEAGT mkdir -p $(dirname $file)
349 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
358 if [[ "$value" != "" ]]; then
361 for mdtno in $(seq 1 $MDSCOUNT); do
362 local idx=$(($mdtno - 1))
363 local facet=mds${mdtno}
364 # if $arg include -P option, run 1 set_param per MDT on the MGS
365 # else, run set_param on each MDT
366 [[ $arg = *"-P"* ]] && facet=mgs
367 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
368 [[ $? != 0 ]] && rc=1
378 for mdtno in $(seq 1 $MDSCOUNT); do
379 local idx=$(($mdtno - 1))
380 wait_result mds${mdtno} \
381 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
383 error "$key state is not '$target' on mds${mdtno}"
390 for mdtno in $(seq 1 $MDSCOUNT); do
391 local idx=$(($mdtno - 1))
392 local cl_user=$(do_facet mds${mdtno} $LCTL \
393 --device ${MDT[$idx]} \
394 changelog_register -n)
396 do_facet mds${mdtno} lctl set_param \
397 mdd.${MDT[$idx]}.changelog_mask="+hsm"
398 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
402 changelog_cleanup() {
404 for mdtno in $(seq 1 $MDSCOUNT); do
405 local idx=$(($mdtno - 1))
406 [[ -z ${CL_USERS[$idx]} ]] && continue
407 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
408 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
409 changelog_deregister ${CL_USERS[$idx]}
414 changelog_get_flags() {
419 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
424 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
432 mdts_set_param "$opt -n" "hsm.$param" "$value"
439 mdts_set_param "" hsm_control "$cmd"
440 mdts_check_param hsm_control "$target" 10
443 cdt_set_sanity_policy() {
444 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
447 mdts_set_param "" hsm.policy "+NRA"
448 mdts_set_param "" hsm.policy "-NBR"
449 CDT_POLICY_HAD_CHANGED=
454 mdts_set_param "" hsm.policy "+NRA"
455 CDT_POLICY_HAD_CHANGED=true
458 cdt_clear_no_retry() {
459 mdts_set_param "" hsm.policy "-NRA"
460 CDT_POLICY_HAD_CHANGED=true
463 cdt_set_non_blocking_restore() {
464 mdts_set_param "" hsm.policy "+NBR"
465 CDT_POLICY_HAD_CHANGED=true
468 cdt_clear_non_blocking_restore() {
469 mdts_set_param "" hsm.policy "-NBR"
470 CDT_POLICY_HAD_CHANGED=true
473 cdt_clear_mount_state() {
474 mdts_set_param "-P -d" hsm_control ""
477 cdt_set_mount_state() {
478 mdts_set_param "-P" hsm_control "$1"
482 mdts_check_param hsm_control "$1" 20
486 set_test_state disabled disabled
490 set_test_state enabled enabled
494 set_test_state shutdown stopped
498 set_test_state purge enabled
504 cdt_set_sanity_policy
508 local client_count=$1
509 if [[ $CLIENTCOUNT -lt $client_count ]]; then
510 skip "Need $client_count or more clients, have $CLIENTCOUNT"
517 $LFS path2fid $1 | tr -d '[]'
524 if [[ $u == "user" ]]; then
525 local st=$($RUNAS $LFS hsm_state $f)
527 local st=$($LFS hsm_state $f)
531 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
533 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
537 get_hsm_archive_id() {
539 local st=$($LFS hsm_state $f)
540 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
542 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
551 local st=$(get_hsm_flags $f)
552 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
555 check_hsm_flags_user() {
559 local st=$(get_hsm_flags $f user)
560 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
572 if [[ "$3" != 1 ]]; then
576 cp $1 $f || error "cannot copy $1 to $f"
577 path2fid $f || error "cannot get fid on $f"
581 local file2=${1/$DIR/$DIR2}
582 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
583 error "cannot create $file2"
584 path2fid $1 || error "cannot get fid on $1"
588 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
589 error "cannot create $1"
590 path2fid $1 || error "cannot get fid on $1"
593 cleanup_large_files() {
594 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
596 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
599 make_large_for_striping() {
600 local file2=${1/$DIR/$DIR2}
601 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
605 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
606 error "cannot create $file2"
607 path2fid $1 || error "cannot get fid on $1"
610 make_large_for_progress() {
611 local file2=${1/$DIR/$DIR2}
615 # big file is large enough, so copy time is > 30s
616 # so copytool make 1 progress
617 # size is not a multiple of 1M to avoid stripe
619 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
620 error "cannot create $file2"
621 path2fid $1 || error "cannot get fid on $1"
624 make_large_for_progress_aligned() {
625 local file2=${1/$DIR/$DIR2}
629 # big file is large enough, so copy time is > 30s
630 # so copytool make 1 progress
631 # size is a multiple of 1M to have stripe
633 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
634 error "cannot create $file2"
635 path2fid $1 || error "cannot get fid on $1"
638 make_large_for_cancel() {
639 local file2=${1/$DIR/$DIR2}
643 # Copy timeout is 100s. 105MB => 105s
644 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
645 error "cannot create $file2"
646 path2fid $1 || error "cannot get fid on $1"
652 wait_update --verbose $(facet_active_host $facet) "$@"
655 wait_request_state() {
659 # 4th arg (mdt index) is optional
661 local mds=mds$(($mdtidx + 1))
663 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
664 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
666 wait_result $mds "$cmd" $state 100 ||
667 error "request on $fid is not $state on $mds"
670 get_request_state() {
674 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
675 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
678 get_request_count() {
682 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
683 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
690 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
691 [[ -n $fid ]] && cmd+=" | grep '$fid'"
692 cmd+=" | egrep 'WAITING|STARTED'"
694 wait_result $SINGLEMDS "$cmd" "" $timeout ||
695 error "requests did not complete"
698 wait_for_grace_delay() {
699 local val=$(get_hsm_param grace_delay)
706 # python2.6 in EL6 includes an internal json module
707 local json_parser='import json; import fileinput;'
708 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
709 json_parser+='json.loads([line for line in '
710 json_parser+='fileinput.input()][0]).items()])'
712 echo $raw_event | python -c "$json_parser"
715 # populate MDT device array
721 # cleanup from previous bad setup
722 search_and_kill_copytool
724 # for recovery tests, coordinator needs to be started at mount
726 # the lustre conf must be without hsm on (like for sanity.sh)
727 echo "Set HSM on and start"
728 cdt_set_mount_state enabled
729 cdt_check_state enabled
731 echo "Start copytool"
734 echo "Set sanity-hsm HSM policy"
735 cdt_set_sanity_policy
737 # finished requests are quickly removed from list
738 set_hsm_param grace_delay 10
744 local f=$DIR/$tdir/$tfile
748 check_hsm_flags_user $f "0x00000000"
750 $RUNAS $LFS hsm_set --norelease $f ||
751 error "user could not change hsm flags"
752 check_hsm_flags_user $f "0x00000010"
754 $RUNAS $LFS hsm_clear --norelease $f ||
755 error "user could not clear hsm flags"
756 check_hsm_flags_user $f "0x00000000"
758 # User could not change those flags...
759 $RUNAS $LFS hsm_set --exists $f &&
760 error "user should not set this flag"
761 check_hsm_flags_user $f "0x00000000"
764 $LFS hsm_set --exists $f ||
765 error "root could not change hsm flags"
766 check_hsm_flags_user $f "0x00000001"
768 $LFS hsm_clear --exists $f ||
769 error "root could not clear hsm state"
770 check_hsm_flags_user $f "0x00000000"
773 run_test 1 "lfs hsm flags root/non-root access"
777 local f=$DIR/$tdir/$tfile
779 # New files are not dirty
780 check_hsm_flags $f "0x00000000"
782 # For test, we simulate an archived file.
783 $LFS hsm_set --exists $f || error "user could not change hsm flags"
784 check_hsm_flags $f "0x00000001"
786 # chmod do not put the file dirty
787 chmod 600 $f || error "could not chmod test file"
788 check_hsm_flags $f "0x00000001"
790 # chown do not put the file dirty
791 chown $RUNAS_ID $f || error "could not chown test file"
792 check_hsm_flags $f "0x00000001"
794 # truncate put the file dirty
795 $TRUNCATE $f 1 || error "could not truncate test file"
796 check_hsm_flags $f "0x00000003"
798 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
799 check_hsm_flags $f "0x00000001"
801 run_test 2 "Check file dirtyness when doing setattr"
807 # New files are not dirty
809 check_hsm_flags $f "0x00000000"
811 # For test, we simulate an archived file.
812 $LFS hsm_set --exists $f ||
813 error "user could not change hsm flags"
814 check_hsm_flags $f "0x00000001"
816 # Reading a file, does not set dirty
817 cat $f > /dev/null || error "could not read file"
818 check_hsm_flags $f "0x00000001"
820 # Open for write without modifying data, does not set dirty
821 openfile -f O_WRONLY $f || error "could not open test file"
822 check_hsm_flags $f "0x00000001"
824 # Append to a file sets it dirty
825 cp -p /etc/passwd $f.append || error "could not create file"
826 $LFS hsm_set --exists $f.append ||
827 error "user could not change hsm flags"
828 dd if=/etc/passwd of=$f.append bs=1 count=3\
829 conv=notrunc oflag=append status=noxfer ||
830 error "could not append to test file"
831 check_hsm_flags $f.append "0x00000003"
833 # Modify a file sets it dirty
834 cp -p /etc/passwd $f.modify || error "could not create file"
835 $LFS hsm_set --exists $f.modify ||
836 error "user could not change hsm flags"
837 dd if=/dev/zero of=$f.modify bs=1 count=3\
838 conv=notrunc status=noxfer ||
839 error "could not modify test file"
840 check_hsm_flags $f.modify "0x00000003"
842 # Open O_TRUNC sets dirty
843 cp -p /etc/passwd $f.trunc || error "could not create file"
844 $LFS hsm_set --exists $f.trunc ||
845 error "user could not change hsm flags"
846 cp /etc/group $f.trunc || error "could not override a file"
847 check_hsm_flags $f.trunc "0x00000003"
849 # Mmapped a file sets dirty
850 cp -p /etc/passwd $f.mmap || error "could not create file"
851 $LFS hsm_set --exists $f.mmap ||
852 error "user could not change hsm flags"
853 multiop $f.mmap OSMWUc || error "could not mmap a file"
854 check_hsm_flags $f.mmap "0x00000003"
856 run_test 3 "Check file dirtyness when opening for write"
860 local f=$DIR/$tdir/$tfile
861 local fid=$(make_small $f)
864 local st=$(get_request_state $fid CANCEL)
865 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
867 run_test 4 "Useless cancel must not be registered"
870 # test needs a running copytool
874 local f=$DIR/$tdir/$tfile
875 local fid=$(copy_file /etc/passwd $f)
877 wait_request_state $fid ARCHIVE SUCCEED
879 check_hsm_flags $f "0x00000009"
883 run_test 8 "Test default archive number"
887 local f=$DIR/$tdir/$tfile
888 local fid=$(copy_file /etc/passwd $f)
889 # we do not use the default one to be sure
890 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
892 copytool_setup $SINGLEAGT $MOUNT $new_an
893 $LFS hsm_archive --archive $new_an $f
894 wait_request_state $fid ARCHIVE SUCCEED
896 check_hsm_flags $f "0x00000009"
900 run_test 9 "Use of explict archive number, with dedicated copytool"
903 needclients 3 || return 0
909 copytool_cleanup $(comma_list $(agts_nodes))
911 # start all of the copytools
912 for n in $(seq $AGTCOUNT); do
916 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
919 for n in $(seq $AGTCOUNT); do
920 file=$DIR/$tdir/$tfile.$n
921 fid=$(make_small $file)
923 $LFS hsm_archive $file || error "could not archive file $file"
924 wait_request_state $fid ARCHIVE SUCCEED
925 check_hsm_flags $file "0x00000009"
929 copytool_cleanup $(comma_list $(agts_nodes))
931 run_test 9a "Multiple remote agents"
934 # test needs a running copytool
937 mkdir -p $DIR/$tdir/d1
938 local f=$DIR/$tdir/$tfile
939 local fid=$(copy_file /etc/hosts $f)
940 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
941 error "hsm_archive failed"
942 wait_request_state $fid ARCHIVE SUCCEED
944 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
945 error "fid $fid not in archive $HSM_ARCHIVE"
946 echo "Verifying content"
947 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
948 echo "Verifying hsm state "
949 check_hsm_flags $f "0x00000009"
951 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
952 local st=$(get_hsm_archive_id $f)
953 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
954 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
959 run_test 10a "Archive a file"
962 # test needs a running copytool
966 local f=$DIR/$tdir/$tfile
967 local fid=$(copy_file /etc/hosts $f)
968 $LFS hsm_archive $f || error "archive request failed"
969 wait_request_state $fid ARCHIVE SUCCEED
971 $LFS hsm_archive $f || error "archive of non dirty file failed"
972 local cnt=$(get_request_count $fid ARCHIVE)
973 [[ "$cnt" == "1" ]] ||
974 error "archive of non dirty file must not make a request"
978 run_test 10b "Archive of non dirty file must work without doing request"
981 # test needs a running copytool
985 local f=$DIR/$tdir/$tfile
986 local fid=$(copy_file /etc/hosts $f)
987 $LFS hsm_set --noarchive $f
988 $LFS hsm_archive $f && error "archive a noarchive file must fail"
992 run_test 10c "Check forbidden archive"
995 # test needs a running copytool
999 local f=$DIR/$tdir/$tfile
1000 local fid=$(copy_file /etc/hosts $f)
1001 $LFS hsm_archive $f || error "cannot archive $f"
1002 wait_request_state $fid ARCHIVE SUCCEED
1004 local ar=$(get_hsm_archive_id $f)
1005 local dflt=$(get_hsm_param default_archive_id)
1006 [[ $ar == $dflt ]] ||
1007 error "archived file is not on default archive: $ar != $dflt"
1011 run_test 10d "Archive a file on the default archive id"
1015 copy2archive /etc/hosts $tdir/$tfile
1016 local f=$DIR/$tdir/$tfile
1018 import_file $tdir/$tfile $f
1019 echo -n "Verifying released state: "
1020 check_hsm_flags $f "0x0000000d"
1022 local LSZ=$(stat -c "%s" $f)
1023 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1025 echo "Verifying imported size $LSZ=$ASZ"
1026 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1027 echo -n "Verifying released pattern: "
1028 local PTRN=$($GETSTRIPE -L $f)
1030 [[ $PTRN == 80000001 ]] || error "Is not released"
1031 local fid=$(path2fid $f)
1032 echo "Verifying new fid $fid in archive"
1034 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1035 error "fid $fid not in archive $HSM_ARCHIVE"
1037 run_test 11a "Import a file"
1040 # test needs a running copytool
1044 local f=$DIR/$tdir/$tfile
1045 local fid=$(copy_file /etc/hosts $f)
1046 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1047 error "hsm_archive failed"
1048 wait_request_state $fid ARCHIVE SUCCEED
1050 local FILE_HASH=$(md5sum $f)
1055 echo "$FILE_HASH" | md5sum -c
1057 [[ $? -eq 0 ]] || error "Restored file differs"
1061 run_test 11b "Import a deleted file using its FID"
1064 # test needs a running copytool
1068 copy2archive /etc/hosts $tdir/$tfile
1070 local f=$DIR/$tdir/$tfile
1071 import_file $tdir/$tfile $f
1072 local f2=$DIR2/$tdir/$tfile
1073 echo "Verifying released state: "
1074 check_hsm_flags $f2 "0x0000000d"
1076 local fid=$(path2fid $f2)
1077 $LFS hsm_restore $f2
1078 wait_request_state $fid RESTORE SUCCEED
1080 echo "Verifying file state: "
1081 check_hsm_flags $f2 "0x00000009"
1083 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1085 [[ $? -eq 0 ]] || error "Restored file differs"
1089 run_test 12a "Restore an imported file explicitly"
1092 # test needs a running copytool
1096 copy2archive /etc/hosts $tdir/$tfile
1098 local f=$DIR/$tdir/$tfile
1099 import_file $tdir/$tfile $f
1100 echo "Verifying released state: "
1101 check_hsm_flags $f "0x0000000d"
1103 cat $f > /dev/null || error "File read failed"
1105 echo "Verifying file state after restore: "
1106 check_hsm_flags $f "0x00000009"
1108 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1110 [[ $? -eq 0 ]] || error "Restored file differs"
1114 run_test 12b "Restore an imported file implicitly"
1117 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1119 # test needs a running copytool
1123 local f=$DIR/$tdir/$tfile
1124 $LFS setstripe -c 2 $f
1125 local fid=$(make_large_for_striping $f)
1126 local FILE_CRC=$(md5sum $f)
1128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1129 wait_request_state $fid ARCHIVE SUCCEED
1130 $LFS hsm_release $f || error "release $f failed"
1132 echo "$FILE_CRC" | md5sum -c
1134 [[ $? -eq 0 ]] || error "Restored file differs"
1138 run_test 12c "Restore a file with stripe of 2"
1141 # test needs a running copytool
1146 local f=$DIR/$tdir/$tfile
1147 local fid=$(copy_file /etc/hosts $f)
1148 $LFS hsm_restore $f || error "restore of non archived file failed"
1149 local cnt=$(get_request_count $fid RESTORE)
1150 [[ "$cnt" == "0" ]] ||
1151 error "restore non archived must not make a request"
1152 $LFS hsm_archive $f ||
1153 error "archive request failed"
1154 wait_request_state $fid ARCHIVE SUCCEED
1155 $LFS hsm_restore $f ||
1156 error "restore of non released file failed"
1157 local cnt=$(get_request_count $fid RESTORE)
1158 [[ "$cnt" == "0" ]] ||
1159 error "restore a non dirty file must not make a request"
1163 run_test 12d "Restore of a non archived, non released file must work"\
1164 " without doing request"
1167 # test needs a running copytool
1170 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1171 local f=$DIR/$tdir/$tfile
1172 local fid=$(copy_file /etc/hosts $f)
1173 $LFS hsm_archive $f || error "archive request failed"
1174 wait_request_state $fid ARCHIVE SUCCEED
1177 cat /etc/hosts >> $f
1181 $LFS hsm_restore $f && error "restore a dirty file must fail"
1185 run_test 12e "Check forbidden restore"
1188 # test needs a running copytool
1192 local f=$DIR/$tdir/$tfile
1193 local fid=$(copy_file /etc/hosts $f)
1195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1196 wait_request_state $fid ARCHIVE SUCCEED
1197 $LFS hsm_release $f || error "release of $f failed"
1199 wait_request_state $fid RESTORE SUCCEED
1201 echo -n "Verifying file state: "
1202 check_hsm_flags $f "0x00000009"
1204 diff -q /etc/hosts $f
1206 [[ $? -eq 0 ]] || error "Restored file differs"
1210 run_test 12f "Restore a released file explicitly"
1213 # test needs a running copytool
1217 local f=$DIR/$tdir/$tfile
1218 local fid=$(copy_file /etc/hosts $f)
1220 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1221 wait_request_state $fid ARCHIVE SUCCEED
1222 $LFS hsm_release $f || error "release of $f failed"
1224 diff -q /etc/hosts $f
1227 # we check we had a restore done
1228 wait_request_state $fid RESTORE SUCCEED
1230 [[ $st -eq 0 ]] || error "Restored file differs"
1234 run_test 12g "Restore a released file implicitly"
1237 needclients 2 || return 0
1239 # test needs a running copytool
1243 local f=$DIR/$tdir/$tfile
1244 local fid=$(copy_file /etc/hosts $f)
1246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1247 wait_request_state $fid ARCHIVE SUCCEED
1248 $LFS hsm_release $f || error "release of $f failed"
1250 do_node $CLIENT2 diff -q /etc/hosts $f
1253 # we check we had a restore done
1254 wait_request_state $fid RESTORE SUCCEED
1256 [[ $st -eq 0 ]] || error "Restored file differs"
1260 run_test 12h "Restore a released file implicitly from a second node"
1263 # test needs a running copytool
1267 local f=$DIR/$tdir/$tfile
1268 local fid=$(copy_file /etc/passwd $f)
1269 $LFS hsm_archive $f || error "archive of $f failed"
1270 wait_request_state $fid ARCHIVE SUCCEED
1272 $LFS hsm_release $f || error "release of $f failed"
1276 [[ $? -eq 0 ]] || error "Restored file differs"
1280 run_test 12m "Archive/release/implicit restore"
1283 # test needs a running copytool
1287 copy2archive /etc/hosts $tdir/$tfile
1289 local f=$DIR/$tdir/$tfile
1290 import_file $tdir/$tfile $f
1292 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1293 error "Restored file differs"
1295 $LFS hsm_release $f || error "release of $f failed"
1299 run_test 12n "Import/implicit restore/release"
1302 # test needs a running copytool
1306 local f=$DIR/$tdir/$tfile
1307 local fid=$(copy_file /etc/hosts $f)
1309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1310 wait_request_state $fid ARCHIVE SUCCEED
1311 $LFS hsm_release $f || error "release of $f failed"
1313 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1314 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1316 # set no retry action mode
1319 diff -q /etc/hosts $f
1322 # we check we had a restore failure
1323 wait_request_state $fid RESTORE FAILED
1325 [[ $st -eq 0 ]] && error "Restore must fail"
1327 # remove no retry action mode
1330 # check file is still released
1331 check_hsm_flags $f "0x0000000d"
1333 # retry w/o failure injection
1334 do_facet $SINGLEMDS lctl set_param fail_loc=0
1336 # to be sure previous RESTORE result is gone
1338 wait_for_grace_delay
1340 diff -q /etc/hosts $f
1343 # we check we had a restore done
1344 wait_request_state $fid RESTORE SUCCEED
1346 [[ $st -eq 0 ]] || error "Restored file differs"
1350 run_test 12o "Layout-swap failure during Restore leaves file released"
1353 # test needs a running copytool
1356 local ARC_SUBDIR="import.orig"
1360 # populate directory to be imported
1361 for d in $(seq 1 10); do
1362 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1363 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1364 for f in $(seq 1 10); do
1365 CURR_FILE="$CURR_DIR/$tfile.$f"
1366 # write file-specific data
1367 do_facet $SINGLEAGT \
1368 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1369 "file=$CURR_FILE > $CURR_FILE"
1373 import_file "$ARC_SUBDIR" $DIR/$tdir
1374 # diff lustre content and origin (triggers file restoration)
1375 # there must be 10x10 identical files, and no difference
1376 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1377 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1378 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1379 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1381 [ $cnt_diff -eq 0 ] ||
1382 error "$cnt_diff imported files differ from read data"
1383 [ $cnt_ok -eq 100 ] ||
1384 error "not enough identical files ($cnt_ok != 100)"
1388 run_test 13 "Recursively import and restore a directory"
1391 # test needs a running copytool
1396 local f=$DIR/$tdir/$tfile
1397 local fid=$(make_small $f)
1398 local sum=$(md5sum $f | awk '{print $1}')
1399 $LFS hsm_archive $f || error "could not archive file"
1400 wait_request_state $fid ARCHIVE SUCCEED
1404 # create released file (simulate llapi_hsm_import call)
1406 local fid2=$(path2fid $f)
1407 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1408 $LFS hsm_release $f || error "could not release file"
1410 # rebind the archive to the newly created file
1411 echo "rebind $fid to $fid2"
1413 do_facet $SINGLEAGT \
1414 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1415 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1417 # restore file and compare md5sum
1418 local sum2=$(md5sum $f | awk '{print $1}')
1420 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1424 run_test 14 "Rebind archived file to a new fid"
1427 # test needs a running copytool
1432 local f=$DIR/$tdir/$tfile
1434 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1438 for i in $(seq 1 $count); do
1439 fids[$i]=$(make_small $f.$i)
1440 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1441 $LFS hsm_archive $f.$i || error "could not archive file"
1443 wait_all_done $(($count*60))
1447 for i in $(seq 1 $count); do
1450 local fid2=$(path2fid $f.$i)
1451 # add the rebind operation to the list
1452 echo ${fids[$i]} $fid2 >> $tmpfile
1454 # set it released (simulate llapi_hsm_import call)
1455 $LFS hsm_set --archived --exists $f.$i ||
1456 error "could not force hsm flags"
1457 $LFS hsm_release $f.$i || error "could not release file"
1459 nl=$(wc -l < $tmpfile)
1460 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1462 echo "rebind list of files"
1463 do_facet $SINGLEAGT \
1464 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1465 --rebind $tmpfile $DIR" || error "could not rebind file list"
1467 # restore files and compare md5sum
1468 for i in $(seq 1 $count); do
1469 local sum2=$(md5sum $f.$i | awk '{print $1}')
1470 [[ $sum2 == ${sums[$i]} ]] ||
1471 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1477 run_test 15 "Rebind a list of files"
1480 # test needs a running copytool
1484 # create a known size file so we can verify transfer speed
1487 dd if=/dev/zero of=$ref bs=1M count=20
1490 local f=$DIR/$tdir/$tfile
1491 local fid=$(copy_file $ref $f)
1493 local start=$(date +%s)
1495 wait_request_state $fid ARCHIVE SUCCEED
1496 local end=$(date +%s)
1497 local duration=$((end - start))
1499 [[ $duration -ge $goal ]] ||
1500 error "Transfer is too fast $duration < $goal"
1504 run_test 16 "Test CT bandwith control option"
1509 local f=$DIR/$tdir/$tfile
1510 touch $f || error "touch $f failed"
1512 # Could not release a non-archived file
1513 $LFS hsm_release $f && error "release should not succeed"
1515 # For following tests, we must test them with HS_ARCHIVED set
1516 $LFS hsm_set --exists --archived $f || error "could not add flag"
1518 # Could not release a file if no-release is set
1519 $LFS hsm_set --norelease $f || error "could not add flag"
1520 $LFS hsm_release $f && error "release should not succeed"
1521 $LFS hsm_clear --norelease $f || error "could not remove flag"
1523 # Could not release a file if lost
1524 $LFS hsm_set --lost $f || error "could not add flag"
1525 $LFS hsm_release $f && error "release should not succeed"
1526 $LFS hsm_clear --lost $f || error "could not remove flag"
1528 # Could not release a file if dirty
1529 $LFS hsm_set --dirty $f || error "could not add flag"
1530 $LFS hsm_release $f && error "release should not succeed"
1531 $LFS hsm_clear --dirty $f || error "could not remove flag"
1533 run_test 20 "Release is not permitted"
1536 # test needs a running copytool
1540 local f=$DIR/$tdir/test_release
1542 # Create a file and check its states
1543 local fid=$(make_small $f)
1544 check_hsm_flags $f "0x00000000"
1546 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1547 # used until file is flushed to disk
1548 if [ $(facet_fstype ost1) == "zfs" ]; then
1549 # this causes an OST_SYNC rpc to be sent
1550 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1551 # clear locks to reread file data
1552 cancel_lru_locks osc
1555 local orig_size=$(stat -c "%s" $f)
1556 local orig_blocks=$(stat -c "%b" $f)
1558 start_full_debug_logging
1560 $LFS hsm_archive $f || error "could not archive file"
1561 wait_request_state $fid ARCHIVE SUCCEED
1563 local blocks=$(stat -c "%b" $f)
1564 [ $blocks -eq $orig_blocks ] ||
1565 error "$f: wrong block number after archive: " \
1566 "$blocks != $orig_blocks"
1567 local size=$(stat -c "%s" $f)
1568 [ $size -eq $orig_size ] ||
1569 error "$f: wrong size after archive: $size != $orig_size"
1571 # Release and check states
1572 $LFS hsm_release $f || error "could not release file"
1573 check_hsm_flags $f "0x0000000d"
1575 blocks=$(stat -c "%b" $f)
1576 [ $blocks -gt 5 ] &&
1577 error "$f: too many blocks after release: $blocks > 5"
1578 size=$(stat -c "%s" $f)
1579 [ $size -ne $orig_size ] &&
1580 error "$f: wrong size after release: $size != $orig_size"
1582 # Check we can release an file without stripe info
1586 check_hsm_flags $f "0x00000000"
1587 $LFS hsm_archive $f || error "could not archive file"
1588 wait_request_state $fid ARCHIVE SUCCEED
1590 # Release and check states
1591 $LFS hsm_release $f || error "could not release file"
1592 check_hsm_flags $f "0x0000000d"
1594 # Release again a file that is already released is OK
1595 $LFS hsm_release $f || fail "second release should succeed"
1596 check_hsm_flags $f "0x0000000d"
1598 stop_full_debug_logging
1602 run_test 21 "Simple release tests"
1605 # test needs a running copytool
1610 local f=$DIR/$tdir/test_release
1611 local swap=$DIR/$tdir/test_swap
1613 # Create a file and check its states
1614 local fid=$(make_small $f)
1615 check_hsm_flags $f "0x00000000"
1617 $LFS hsm_archive $f || error "could not archive file"
1618 wait_request_state $fid ARCHIVE SUCCEED
1620 # Release and check states
1621 $LFS hsm_release $f || error "could not release file"
1622 check_hsm_flags $f "0x0000000d"
1625 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1630 run_test 22 "Could not swap a release file"
1633 # test needs a running copytool
1638 local f=$DIR/$tdir/test_mtime
1640 # Create a file and check its states
1641 local fid=$(make_small $f)
1642 check_hsm_flags $f "0x00000000"
1644 $LFS hsm_archive $f || error "could not archive file"
1645 wait_request_state $fid ARCHIVE SUCCEED
1647 # Set modification time in the past
1648 touch -m -a -d @978261179 $f
1650 # Release and check states
1651 $LFS hsm_release $f || error "could not release file"
1652 check_hsm_flags $f "0x0000000d"
1654 local MTIME=$(stat -c "%Y" $f)
1655 local ATIME=$(stat -c "%X" $f)
1656 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1657 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1661 run_test 23 "Release does not change a/mtime (utime)"
1664 local file=$DIR/$tdir/$tfile
1673 # test needs a running copytool
1678 fid=$(make_small $file)
1680 # Create a file and check its states
1681 check_hsm_flags $file "0x00000000"
1683 # Ensure atime is less than mtime and ctime.
1687 atime0=$(stat -c "%X" $file)
1688 mtime0=$(stat -c "%Y" $file)
1689 ctime0=$(stat -c "%Z" $file)
1691 [ $atime0 -lt $mtime0 ] ||
1692 error "atime $atime0 is not less than mtime $mtime0"
1694 [ $atime0 -lt $ctime0 ] ||
1695 error "atime $atime0 is not less than ctime $ctime0"
1697 # Archive should not change any timestamps.
1698 $LFS hsm_archive $file || error "cannot archive '$file'"
1699 wait_request_state $fid ARCHIVE SUCCEED
1701 atime1=$(stat -c "%X" $file)
1702 mtime1=$(stat -c "%Y" $file)
1703 ctime1=$(stat -c "%Z" $file)
1705 [ $atime0 -eq $atime1 ] ||
1706 error "archive changed atime from $atime0 to $atime1"
1708 [ $mtime0 -eq $mtime1 ] ||
1709 error "archive changed mtime from $mtime0 to $mtime1"
1711 [ $ctime0 -eq $ctime1 ] ||
1712 error "archive changed ctime from $ctime0 to $ctime1"
1714 # Release should not change any timestamps.
1715 $LFS hsm_release $file || error "cannot release '$file'"
1716 check_hsm_flags $file "0x0000000d"
1718 atime1=$(stat -c "%X" $file)
1719 mtime1=$(stat -c "%Y" $file)
1720 ctime1=$(stat -c "%Z" $file)
1722 [ $atime0 -eq $atime1 ] ||
1723 error "release changed atime from $atime0 to $atime1"
1725 [ $mtime0 -eq $mtime1 ] ||
1726 error "release changed mtime from $mtime0 to $mtime1"
1728 [ $ctime0 -eq $ctime1 ] ||
1729 error "release changed ctime from $ctime0 to $ctime1"
1731 # Restore should not change atime or mtime and should not
1733 $LFS hsm_restore $file
1734 wait_request_state $fid RESTORE SUCCEED
1736 atime1=$(stat -c "%X" $file)
1737 mtime1=$(stat -c "%Y" $file)
1738 ctime1=$(stat -c "%Z" $file)
1740 [ $atime0 -eq $atime1 ] ||
1741 error "restore changed atime from $atime0 to $atime1"
1743 [ $mtime0 -eq $mtime1 ] ||
1744 error "restore changed mtime from $mtime0 to $mtime1"
1746 [ $ctime0 -le $ctime1 ] ||
1747 error "restore changed ctime from $ctime0 to $ctime1"
1751 # Once more, after unmount and mount.
1752 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1753 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1755 atime1=$(stat -c "%X" $file)
1756 mtime1=$(stat -c "%Y" $file)
1757 ctime1=$(stat -c "%Z" $file)
1759 [ $atime0 -eq $atime1 ] ||
1760 error "remount changed atime from $atime0 to $atime1"
1762 [ $mtime0 -eq $mtime1 ] ||
1763 error "remount changed mtime from $mtime0 to $mtime1"
1765 [ $ctime0 -le $ctime1 ] ||
1766 error "remount changed ctime from $ctime0 to $ctime1"
1768 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1771 local file=$DIR/$tdir/$tfile
1777 # Test needs a running copytool.
1781 # Check that root can do HSM actions on a ordinary user's file.
1783 fid=$(make_small $file)
1784 sum0=$(md5sum $file)
1786 chown $RUNAS_ID:$RUNAS_GID $file ||
1787 error "cannot chown '$file' to '$RUNAS_ID'"
1789 chmod ugo-w $DIR/$tdir ||
1790 error "cannot chmod '$DIR/$tdir'"
1792 $LFS hsm_archive $file
1793 wait_request_state $fid ARCHIVE SUCCEED
1795 $LFS hsm_release $file
1796 check_hsm_flags $file "0x0000000d"
1798 $LFS hsm_restore $file
1799 wait_request_state $fid RESTORE SUCCEED
1801 # Check that ordinary user can get HSM state.
1802 $RUNAS $LFS hsm_state $file ||
1803 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1805 $LFS hsm_release $file
1806 check_hsm_flags $file "0x0000000d"
1808 # Check that ordinary user can accessed released file.
1809 sum1=$($RUNAS md5sum $file) ||
1810 error "user '$RUNAS_ID' cannot read '$file'"
1812 [ "$sum0" == "$sum1" ] ||
1813 error "md5sum mismatch for '$file'"
1817 run_test 24b "root can archive, release, and restore user files"
1819 cleanup_test_24c() {
1821 set_hsm_param user_request_mask RESTORE
1822 set_hsm_param group_request_mask RESTORE
1823 set_hsm_param other_request_mask RESTORE
1827 local file=$DIR/$tdir/$tfile
1828 local action=archive
1833 # test needs a running copytool
1838 # Save the default masks and check that cleanup_24c will
1839 # restore the request masks correctly.
1840 user_save=$(get_hsm_param user_request_mask)
1841 group_save=$(get_hsm_param group_request_mask)
1842 other_save=$(get_hsm_param other_request_mask)
1844 [ "$user_save" == RESTORE ] ||
1845 error "user_request_mask is '$user_save' expected 'RESTORE'"
1846 [ "$group_save" == RESTORE ] ||
1847 error "group_request_mask is '$group_save' expected 'RESTORE'"
1848 [ "$other_save" == RESTORE ] ||
1849 error "other_request_mask is '$other_save' expected 'RESTORE'"
1851 trap cleanup_test_24c EXIT
1856 chown $RUNAS_ID:nobody $file ||
1857 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1859 set_hsm_param user_request_mask ""
1860 $RUNAS $LFS hsm_$action $file &&
1861 error "$action by user should fail"
1863 set_hsm_param user_request_mask $action
1864 $RUNAS $LFS hsm_$action $file ||
1865 error "$action by user should succeed"
1870 chown nobody:$RUNAS_GID $file ||
1871 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1873 set_hsm_param group_request_mask ""
1874 $RUNAS $LFS hsm_$action $file &&
1875 error "$action by group should fail"
1877 set_hsm_param group_request_mask $action
1878 $RUNAS $LFS hsm_$action $file ||
1879 error "$action by group should succeed"
1884 chown nobody:nobody $file ||
1885 error "cannot chown '$file' to 'nobody:nobody'"
1887 set_hsm_param other_request_mask ""
1888 $RUNAS $LFS hsm_$action $file &&
1889 error "$action by other should fail"
1891 set_hsm_param other_request_mask $action
1892 $RUNAS $LFS hsm_$action $file ||
1893 error "$action by other should succeed"
1898 run_test 24c "check that user,group,other request masks work"
1900 cleanup_test_24d() {
1902 mount -o remount,rw $MOUNT2
1906 local file1=$DIR/$tdir/$tfile
1907 local file2=$DIR2/$tdir/$tfile
1915 fid1=$(make_small $file1)
1917 trap cleanup_test_24d EXIT
1919 mount -o remount,ro $MOUNT2
1921 fid2=$(path2fid $file2)
1922 [ "$fid1" == "$fid2" ] ||
1923 error "FID mismatch '$fid1' != '$fid2'"
1925 $LFS hsm_archive $file2 &&
1926 error "archive should fail on read-only mount"
1927 check_hsm_flags $file1 "0x00000000"
1929 $LFS hsm_archive $file1
1930 wait_request_state $fid1 ARCHIVE SUCCEED
1932 $LFS hsm_release $file1
1933 $LFS hsm_restore $file2
1934 wait_request_state $fid1 RESTORE SUCCEED
1936 $LFS hsm_release $file1 || error "cannot release '$file1'"
1937 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1939 $LFS hsm_release $file2 &&
1940 error "release should fail on read-only mount"
1945 run_test 24d "check that read-only mounts are respected"
1948 # test needs a running copytool
1952 copy2archive /etc/hosts $tdir/$tfile
1954 local f=$DIR/$tdir/$tfile
1956 import_file $tdir/$tfile $f
1958 $LFS hsm_set --lost $f
1963 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1967 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1968 " (Operation not permitted)"
1971 # test needs a running copytool
1976 local f=$DIR/$tdir/$tfile
1977 local fid=$(copy_file /etc/passwd $f)
1979 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1980 wait_request_state $fid ARCHIVE SUCCEED
1983 $LFS hsm_set --lost $f
1987 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1991 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1992 " (Operation not permitted)"
1995 # test needs a running copytool
1999 local f=$DIR/$tdir/$tfile
2000 local fid=$(make_large_for_progress $f)
2001 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2002 wait_request_state $fid ARCHIVE SUCCEED
2005 wait_request_state $fid REMOVE SUCCEED
2007 check_hsm_flags $f "0x00000000"
2011 run_test 26 "Remove the archive of a valid file"
2014 # test needs a running copytool
2018 make_archive $tdir/$tfile
2019 local f=$DIR/$tdir/$tfile
2020 import_file $tdir/$tfile $f
2021 local fid=$(path2fid $f)
2025 [[ $? != 0 ]] || error "Remove of a released file should fail"
2029 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2032 # test needs a running copytool
2036 local f=$DIR/$tdir/$tfile
2037 local fid=$(make_large_for_progress $f)
2038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2039 wait_request_state $fid ARCHIVE SUCCEED
2044 [[ $? != 0 ]] || error "Remove of a released file should fail"
2048 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2051 # test needs a running copytool
2055 local f=$DIR/$tdir/$tfile
2056 local fid=$(make_large_for_progress $f)
2057 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2058 wait_request_state $fid ARCHIVE SUCCEED
2067 wait_request_state $fid REMOVE SUCCEED
2071 run_test 28 "Concurrent archive/file remove"
2074 # restore at exec cannot work on agent node (because of Linux kernel
2075 # protection of executables)
2076 needclients 2 || return 0
2078 # test needs a running copytool
2082 copy2archive /bin/true $tdir/$tfile
2084 local f=$DIR/$tdir/true
2085 import_file $tdir/$tfile $f
2087 local fid=$(path2fid $f)
2089 # set no retry action mode
2095 # remove no try action mode
2099 [[ $st == 0 ]] || error "Failed to exec a released file"
2103 run_test 30a "Restore at exec (import case)"
2106 # restore at exec cannot work on agent node (because of Linux kernel
2107 # protection of executables)
2108 needclients 2 || return 0
2110 # test needs a running copytool
2114 local f=$DIR/$tdir/true
2115 local fid=$(copy_file /bin/true $f)
2117 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2118 wait_request_state $fid ARCHIVE SUCCEED
2121 # set no retry action mode
2127 # remove no try action mode
2131 [[ $st == 0 ]] || error "Failed to exec a released file"
2135 run_test 30b "Restore at exec (release case)"
2138 needclients 2 || return 0
2140 # test needs a running copytool
2144 local f=$DIR/$tdir/SLEEP
2145 local fid=$(copy_file /bin/sleep $f)
2147 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2148 wait_request_state $fid ARCHIVE SUCCEED
2150 check_hsm_flags $f "0x0000000d"
2151 # set no retry action mode
2153 do_node $CLIENT2 "$f 10" &
2157 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2159 [[ $? == 0 ]] || error "Execution failed during run"
2161 [[ $? == 0 ]] || error "Binary overwritten during exec"
2164 # remove no try action mode
2166 check_hsm_flags $f "0x00000009"
2170 run_test 30c "Update during exec of released file must fail"
2172 restore_and_check_size() {
2175 local s=$(stat -c "%s" $f)
2177 local st=$(get_hsm_flags $f)
2181 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2183 n=$(stat -c "%s" $f)
2184 # we echo in both cases to show stat is not
2186 if [[ $n != $s ]]; then
2187 echo "size seen is $n != $s"
2190 echo "size seen is right: $n == $s"
2192 st=$(get_hsm_flags $f)
2196 if [[ $cpt -lt 10 ]]; then
2199 echo " restore is too long"
2200 wait_request_state $fid RESTORE SUCCEED
2206 # test needs a running copytool
2211 make_archive $tdir/$tfile
2212 local f=$DIR/$tdir/$tfile
2213 import_file $tdir/$tfile $f
2214 local fid=$($LFS path2fid $f)
2215 HSM_ARCHIVE_PURGE=false copytool_setup
2217 restore_and_check_size $f $fid
2220 [[ $err -eq 0 ]] || error "File size changed during restore"
2224 run_test 31a "Import a large file and check size during restore"
2228 # test needs a running copytool
2233 local f=$DIR/$tdir/$tfile
2234 local fid=$(make_large_for_progress $f)
2235 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2236 wait_request_state $fid ARCHIVE SUCCEED
2239 restore_and_check_size $f $fid
2242 [[ $err -eq 0 ]] || error "File size changed during restore"
2246 run_test 31b "Restore a large unaligned file and check size during restore"
2249 # test needs a running copytool
2254 local f=$DIR/$tdir/$tfile
2255 local fid=$(make_large_for_progress_aligned $f)
2256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2257 wait_request_state $fid ARCHIVE SUCCEED
2260 restore_and_check_size $f $fid
2263 [[ $err -eq 0 ]] || error "File size changed during restore"
2267 run_test 31c "Restore a large aligned file and check size during restore"
2270 # test needs a running copytool
2275 local f=$DIR/$tdir/$tfile
2276 local fid=$(make_large_for_progress $f)
2277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2278 wait_request_state $fid ARCHIVE SUCCEED
2281 # to be sure wait_all_done will not be mislead by previous tests
2284 wait_for_grace_delay
2285 # Also raise grace_delay significantly so the Canceled
2286 # Restore action will stay enough long avail.
2287 local old_grace=$(get_hsm_param grace_delay)
2288 set_hsm_param grace_delay 100
2290 md5sum $f >/dev/null &
2292 wait_request_state $fid RESTORE STARTED
2297 # Check restore trigger process was killed
2298 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2302 # instead of waiting+checking both Restore and Cancel ops
2303 # sequentially, wait for both to be finished and then check
2305 wait_all_done 100 $fid
2306 local rstate=$(get_request_state $fid RESTORE)
2307 local cstate=$(get_request_state $fid CANCEL)
2309 # restore orig grace_delay.
2310 set_hsm_param grace_delay $old_grace
2312 if [[ "$rstate" == "CANCELED" ]] ; then
2313 [[ "$cstate" == "SUCCEED" ]] ||
2314 error "Restore state is CANCELED and Cancel state " \
2315 "is not SUCCEED but $cstate"
2316 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2317 elif [[ "$rstate" == "SUCCEED" ]] ; then
2318 [[ "$cstate" == "FAILED" ]] ||
2319 error "Restore state is SUCCEED and Cancel state " \
2320 "is not FAILED but $cstate"
2321 echo "Restore state is SUCCEED, Cancel state is FAILED"
2323 error "Restore state is $rstate and Cancel state is $cstate"
2327 error "Cannot kill process waiting for restore ($killed)"
2331 run_test 33 "Kill a restore waiting process"
2334 # test needs a running copytool
2339 local f=$DIR/$tdir/$tfile
2340 local fid=$(make_large_for_progress $f)
2341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2342 wait_request_state $fid ARCHIVE SUCCEED
2345 md5sum $f >/dev/null &
2347 wait_request_state $fid RESTORE STARTED
2349 rm $f || error "rm $f failed"
2350 # rm must not block during restore
2351 wait_request_state $fid RESTORE STARTED
2353 wait_request_state $fid RESTORE SUCCEED
2354 # check md5sum pgm finished
2355 local there=$(ps -o pid,comm hp $pid >/dev/null)
2356 [[ -z $there ]] || error "Restore initiator does not exit"
2358 local rc=$(wait $pid)
2359 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2363 run_test 34 "Remove file during restore"
2366 # test needs a running copytool
2371 local f=$DIR/$tdir/$tfile
2372 local f1=$DIR/$tdir/$tfile-1
2373 local fid=$(make_large_for_progress $f)
2374 local fid1=$(copy_file /etc/passwd $f1)
2375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2376 wait_request_state $fid ARCHIVE SUCCEED
2379 md5sum $f >/dev/null &
2381 wait_request_state $fid RESTORE STARTED
2383 mv $f1 $f || error "mv $f1 $f failed"
2384 # mv must not block during restore
2385 wait_request_state $fid RESTORE STARTED
2387 wait_request_state $fid RESTORE SUCCEED
2388 # check md5sum pgm finished
2389 local there=$(ps -o pid,comm hp $pid >/dev/null)
2390 [[ -z $there ]] || error "Restore initiator does not exit"
2392 local rc=$(wait $pid)
2393 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2396 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2400 run_test 35 "Overwrite file during restore"
2403 # test needs a running copytool
2408 local f=$DIR/$tdir/$tfile
2409 local fid=$(make_large_for_progress $f)
2410 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2411 wait_request_state $fid ARCHIVE SUCCEED
2414 md5sum $f >/dev/null &
2416 wait_request_state $fid RESTORE STARTED
2419 # rm must not block during restore
2420 wait_request_state $fid RESTORE STARTED
2422 wait_request_state $fid RESTORE SUCCEED
2423 # check md5sum pgm finished
2424 local there=$(ps -o pid,comm hp $pid >/dev/null)
2426 error "Restore initiator does not exit"
2428 local rc=$(wait $pid)
2430 error "Restore initiator failed with $rc"
2434 run_test 36 "Move file during restore"
2441 for n in $(seq 1 $count); do
2442 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2444 echo "$count archive requests submitted"
2448 local stream_count=4
2449 local file_count=100
2451 local f=$DIR/$tdir/$tfile
2456 for i in $(seq 1 $file_count); do
2457 for p in $(seq 1 $stream_count); do
2458 fid=$(copy_file /etc/hosts $f.$p.$i)
2461 # force copytool to use a local/temp archive dir to ensure best
2462 # performance vs remote/NFS mounts used in auto-tests
2463 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2466 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2468 # to be sure wait_all_done will not be mislead by previous tests
2470 wait_for_grace_delay
2472 # start archive streams in background (archive files in parallel)
2473 for p in $(seq 1 $stream_count); do
2474 multi_archive $f.$p $file_count &
2477 echo -n "Wait for all requests being enqueued..."
2483 run_test 40 "Parallel archive requests"
2486 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(copy_file /etc/motd $f 1)
2493 $LFS hsm_archive $f || error "could not archive file"
2494 wait_request_state $fid ARCHIVE SUCCEED
2495 check_hsm_flags $f "0x00000009"
2497 multiop_bg_pause $f O_c || error "multiop failed"
2501 client_up || client_up || true
2503 kill -USR1 $MULTIPID
2504 wait $MULTIPID || error "multiop close failed"
2506 check_hsm_flags $f "0x0000000b"
2510 run_test 52 "Opened for write file on an evicted client should be set dirty"
2513 # test needs a running copytool
2517 local f=$DIR/$tdir/$tfile
2518 local fid=$(copy_file /etc/motd $f 1)
2520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2521 error "could not archive file"
2522 wait_request_state $fid ARCHIVE SUCCEED
2523 check_hsm_flags $f "0x00000009"
2525 multiop_bg_pause $f o_c || error "multiop failed"
2529 client_up || client_up || true
2531 kill -USR1 $MULTIPID
2532 wait $MULTIPID || error "multiop close failed"
2534 check_hsm_flags $f "0x00000009"
2538 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2541 # test needs a running copytool
2545 local f=$DIR/$tdir/$tfile
2546 local fid=$(make_small $f)
2548 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2549 error "could not archive file"
2550 wait_request_state $fid ARCHIVE STARTED
2552 check_hsm_flags $f "0x00000001"
2554 # Avoid coordinator resending this request as soon it has failed.
2559 wait_request_state $fid ARCHIVE FAILED
2561 check_hsm_flags $f "0x00000003"
2566 run_test 54 "Write during an archive cancels it"
2569 # test needs a running copytool
2573 local f=$DIR/$tdir/$tfile
2574 local fid=$(make_small $f)
2576 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2577 error "could not archive file"
2578 wait_request_state $fid ARCHIVE STARTED
2580 check_hsm_flags $f "0x00000001"
2582 # Avoid coordinator resending this request as soon it has failed.
2585 $TRUNCATE $f 1024 || error "truncate failed"
2587 wait_request_state $fid ARCHIVE FAILED
2589 check_hsm_flags $f "0x00000003"
2594 run_test 55 "Truncate during an archive cancels it"
2597 # test needs a running copytool
2601 local f=$DIR/$tdir/$tfile
2602 local fid=$(make_large_for_progress $f)
2604 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2605 error "could not archive file"
2606 wait_request_state $fid ARCHIVE STARTED
2608 check_hsm_flags $f "0x00000001"
2610 # Change metadata and sync to be sure we are not changing only
2615 wait_request_state $fid ARCHIVE SUCCEED
2617 check_hsm_flags $f "0x00000009"
2621 run_test 56 "Setattr during an archive is ok"
2624 # Need one client for I/O, one for request
2625 needclients 2 || return 0
2627 # test needs a running copytool
2631 local f=$DIR/$tdir/test_archive_remote
2632 # Create a file on a remote node
2633 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2634 "count=2 conv=fsync"
2637 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2638 error "hsm_archive failed"
2639 local fid=$(path2fid $f)
2640 wait_request_state $fid ARCHIVE SUCCEED
2642 # Release and implicit restore it
2643 do_node $CLIENT2 "$LFS hsm_release $f" ||
2644 error "hsm_release failed"
2645 do_node $CLIENT2 "md5sum $f" ||
2646 error "hsm_restore failed"
2648 wait_request_state $fid RESTORE SUCCEED
2652 run_test 57 "Archive a file with dirty cache on another node"
2654 truncate_released_file() {
2658 local sz=$(stat -c %s $src_file)
2659 local f=$DIR/$tdir/$tfile
2660 local fid=$(copy_file $1 $f)
2664 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2665 error "could not archive file"
2666 wait_request_state $fid ARCHIVE SUCCEED
2668 $LFS hsm_release $f || error "could not release file"
2670 $TRUNCATE $f $trunc_to || error "truncate failed"
2673 local sz1=$(stat -c %s $f)
2674 [[ $sz1 == $trunc_to ]] ||
2675 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2678 check_hsm_flags $f "0x0000000b"
2680 local state=$(get_request_state $fid RESTORE)
2681 [[ "$state" == "SUCCEED" ]] ||
2682 error "truncate $sz does not trig restore, state = $state"
2684 $TRUNCATE $ref $trunc_to
2685 cmp $ref $f || error "file data wrong after truncate"
2691 # test needs a running copytool
2696 local sz=$(stat -c %s /etc/passwd)
2698 echo "truncate up from $sz to $((sz*2))"
2699 truncate_released_file /etc/passwd $((sz*2))
2701 echo "truncate down from $sz to $((sz/2))"
2702 truncate_released_file /etc/passwd $((sz/2))
2704 echo "truncate to 0"
2705 truncate_released_file /etc/passwd 0
2709 run_test 58 "Truncate a released file will trigger restore"
2712 # This test validates the fix for LU-4512. Ensure that the -u
2713 # option changes the progress reporting interval from the
2714 # default (30 seconds) to the user-specified interval.
2716 local progress_timeout=$((interval * 4))
2718 # test needs a new running copytool
2720 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2723 local f=$DIR/$tdir/$tfile
2724 local fid=$(make_large_for_progress $f)
2727 local mdt=${MDT_PREFIX}${mdtidx}
2728 local mds=mds$((mdtidx + 1))
2730 # Wait for copytool to register
2731 wait_update_facet $mds \
2732 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2733 uuid 100 || error "coyptool failed to register with $mdt"
2735 local start_at=$(date +%s)
2736 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2737 error "could not archive file"
2739 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2740 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2746 echo -n "Expecting a progress update within $progress_timeout seconds... "
2748 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2749 if [ $RESULT -gt 0 ]; then
2750 echo "$RESULT bytes copied in $WAIT seconds."
2752 elif [ $WAIT -ge $progress_timeout ]; then
2753 error "Timed out waiting for progress update!"
2756 WAIT=$((WAIT + sleep))
2760 local finish_at=$(date +%s)
2761 local elapsed=$((finish_at - start_at))
2763 # Ensure that the progress update occurred within the expected window.
2764 if [ $elapsed -lt $interval ]; then
2765 error "Expected progress update after at least $interval seconds"
2771 run_test 60 "Changing progress update interval from default"
2774 # test needs a new running copytool
2776 copytool_monitor_setup
2777 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2779 # Just start and stop the copytool to generate events.
2782 # Wait for the copytool to register.
2783 wait_update --verbose $(facet_active_host mds1) \
2784 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2786 error "copytool failed to register with MDT0000"
2790 local REGISTER_EVENT
2791 local UNREGISTER_EVENT
2792 while read event; do
2793 local parsed=$(parse_json_event "$event")
2794 if [ -z "$parsed" ]; then
2795 error "Copytool sent malformed event: $event"
2799 if [ $event_type == "REGISTER" ]; then
2800 REGISTER_EVENT=$event
2801 elif [ $event_type == "UNREGISTER" ]; then
2802 UNREGISTER_EVENT=$event
2804 done < <(echo $"$(get_copytool_event_log)")
2806 if [ -z "$REGISTER_EVENT" ]; then
2807 error "Copytool failed to send register event to FIFO"
2810 if [ -z "$UNREGISTER_EVENT" ]; then
2811 error "Copytool failed to send unregister event to FIFO"
2814 copytool_monitor_cleanup
2815 echo "Register/Unregister events look OK."
2817 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2820 # Bump progress interval for livelier events.
2823 # test needs a new running copytool
2825 copytool_monitor_setup
2826 HSMTOOL_UPDATE_INTERVAL=$interval \
2827 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2830 local f=$DIR/$tdir/$tfile
2831 local fid=$(make_large_for_progress $f)
2833 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2834 error "could not archive file"
2835 wait_request_state $fid ARCHIVE SUCCEED
2837 local expected_fields="event_time data_fid source_fid"
2838 expected_fields+=" total_bytes current_bytes"
2842 while read event; do
2843 # Make sure we're not getting anything from previous events.
2844 for field in $expected_fields; do
2848 local parsed=$(parse_json_event "$event")
2849 if [ -z "$parsed" ]; then
2850 error "Copytool sent malformed event: $event"
2854 if [ $event_type == "ARCHIVE_START" ]; then
2857 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2860 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2864 # Do some simple checking of the progress update events.
2865 for expected_field in $expected_fields; do
2866 if [ -z ${!expected_field+x} ]; then
2867 error "Missing $expected_field field in event"
2871 if [ $total_bytes -eq 0 ]; then
2872 error "Expected total_bytes to be > 0"
2875 # These should be identical throughout an archive
2877 if [ $source_fid != $data_fid ]; then
2878 error "Expected source_fid to equal data_fid"
2880 done < <(echo $"$(get_copytool_event_log)")
2882 if [ -z "$START_EVENT" ]; then
2883 error "Copytool failed to send archive start event to FIFO"
2886 if [ -z "$FINISH_EVENT" ]; then
2887 error "Copytool failed to send archive finish event to FIFO"
2890 echo "Archive events look OK."
2894 copytool_monitor_cleanup
2896 run_test 71 "Copytool logs JSON archive events to FIFO"
2899 # Bump progress interval for livelier events.
2902 # test needs a new running copytool
2904 copytool_monitor_setup
2905 HSMTOOL_UPDATE_INTERVAL=$interval \
2906 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2907 local test_file=$HSMTOOL_MONITOR_DIR/file
2909 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2911 do_facet $SINGLEAGT "$cmd" ||
2912 error "cannot create $test_file on $SINGLEAGT"
2913 copy2archive $test_file $tdir/$tfile
2916 local f=$DIR/$tdir/$tfile
2917 import_file $tdir/$tfile $f
2918 f=$DIR2/$tdir/$tfile
2919 echo "Verifying released state: "
2920 check_hsm_flags $f "0x0000000d"
2922 local fid=$(path2fid $f)
2924 wait_request_state $fid RESTORE SUCCEED
2926 local expected_fields="event_time data_fid source_fid"
2927 expected_fields+=" total_bytes current_bytes"
2931 while read event; do
2932 # Make sure we're not getting anything from previous events.
2933 for field in $expected_fields; do
2937 local parsed=$(parse_json_event "$event")
2938 if [ -z "$parsed" ]; then
2939 error "Copytool sent malformed event: $event"
2943 if [ $event_type == "RESTORE_START" ]; then
2945 if [ $source_fid != $data_fid ]; then
2946 error "source_fid should == data_fid at start"
2949 elif [ $event_type == "RESTORE_FINISH" ]; then
2951 if [ $source_fid != $data_fid ]; then
2952 error "source_fid should == data_fid at finish"
2955 elif [ $event_type != "RESTORE_RUNNING" ]; then
2959 # Do some simple checking of the progress update events.
2960 for expected_field in $expected_fields; do
2961 if [ -z ${!expected_field+x} ]; then
2962 error "Missing $expected_field field in event"
2966 if [ $total_bytes -eq 0 ]; then
2967 error "Expected total_bytes to be > 0"
2970 # When a restore starts out, the data fid is the same as the
2971 # source fid. After the restore has gotten going, we learn
2972 # the new data fid. Once the restore has finished, the source
2973 # fid is set to the new data fid.
2975 # We test this because some monitoring software may depend on
2976 # this behavior. If it changes, then the consumers of these
2977 # events may need to be modified.
2978 if [ $source_fid == $data_fid ]; then
2979 error "source_fid should != data_fid during restore"
2981 done < <(echo $"$(get_copytool_event_log)")
2983 if [ -z "$START_EVENT" ]; then
2984 error "Copytool failed to send restore start event to FIFO"
2987 if [ -z "$FINISH_EVENT" ]; then
2988 error "Copytool failed to send restore finish event to FIFO"
2991 echo "Restore events look OK."
2995 copytool_monitor_cleanup
2999 run_test 72 "Copytool logs JSON restore events to FIFO"
3002 file_count=51 # Max number of files constrained by LNET message size
3003 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3004 local f=$DIR/$tdir/$tfile
3005 local FILELIST=/tmp/filelist.txt
3009 for i in $(seq 1 $file_count); do
3010 fid=$(copy_file /etc/hosts $f.$i)
3011 echo $f.$i >> $FILELIST
3014 # to be sure wait_all_done will not be mislead by previous tests
3016 wait_for_grace_delay
3017 $LFS hsm_archive --filelist $FILELIST ||
3018 error "cannot archive a file list"
3020 $LFS hsm_release --filelist $FILELIST ||
3021 error "cannot release a file list"
3022 $LFS hsm_restore --filelist $FILELIST ||
3023 error "cannot restore a file list"
3027 run_test 90 "Archive/restore a file list"
3029 double_verify_reset_hsm_param() {
3031 echo "Testing $HSM_PARAM.$p"
3032 local val=$(get_hsm_param $p)
3034 local val2=$(($val * 2))
3035 set_hsm_param $p $val2
3036 val=$(get_hsm_param $p)
3037 [[ $val == $val2 ]] ||
3038 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3039 echo "Set $p to 0 must failed"
3043 set_hsm_param $p $save
3045 if [[ $rc == 0 ]]; then
3046 error "we must not be able to set $HSM_PARAM.$p to 0"
3051 double_verify_reset_hsm_param loop_period
3052 double_verify_reset_hsm_param grace_delay
3053 double_verify_reset_hsm_param active_request_timeout
3054 double_verify_reset_hsm_param max_requests
3055 double_verify_reset_hsm_param default_archive_id
3057 run_test 100 "Set coordinator /proc tunables"
3064 run_test 102 "Verify coordinator control"
3067 # test needs a running copytool
3074 for i in $(seq 1 20); do
3075 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3077 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3081 echo "Current requests"
3082 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3083 $HSM_PARAM.actions |\
3084 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3086 [[ -z "$res" ]] || error "Some request have not been canceled"
3090 run_test 103 "Purge all requests"
3095 # test needs a running copytool
3099 local f=$DIR/$tdir/$tfile
3100 local fid=$(make_large_for_progress $f)
3101 # if cdt is on, it can serve too quickly the request
3103 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3104 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3105 $HSM_PARAM.actions |\
3106 grep $fid | cut -f16 -d=")
3109 [[ "$data1" == "$DATAHEX" ]] ||
3110 error "Data field in records is ($data1) and not ($DATAHEX)"
3114 run_test 104 "Copy tool data field"
3121 for i in $(seq -w 1 10); do
3122 cp /etc/passwd $DIR/$tdir/$i
3123 $LFS hsm_archive $DIR/$tdir/$i
3125 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3126 $HSM_PARAM.actions |\
3127 grep WAITING | wc -l")
3130 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3131 $HSM_PARAM.actions |\
3132 grep WAITING | wc -l")
3135 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3136 error "Requests count after shutdown $reqcnt2 != "\
3137 "before shutdown $reqcnt1"
3139 run_test 105 "Restart of coordinator"
3141 get_agent_by_uuid_mdt() {
3144 local mds=mds$(($mdtidx + 1))
3145 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3149 check_agent_registered_by_mdt() {
3152 local mds=mds$(($mdtidx + 1))
3153 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3154 if [[ ! -z "$agent" ]]; then
3155 echo "found agent $agent on $mds"
3157 error "uuid $uuid not found in agent list on $mds"
3161 check_agent_unregistered_by_mdt() {
3164 local mds=mds$(($mdtidx + 1))
3165 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3166 if [[ -z "$agent" ]]; then
3167 echo "uuid not found in agent list on $mds"
3169 error "uuid found in agent list on $mds: $agent"
3173 check_agent_registered() {
3176 for mdsno in $(seq 1 $MDSCOUNT); do
3177 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3181 check_agent_unregistered() {
3184 for mdsno in $(seq 1 $MDSCOUNT); do
3185 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3190 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3191 get_client_uuid $MOUNT | cut -d' ' -f2)
3194 check_agent_registered $uuid
3196 search_copytools || error "No copytool found"
3199 check_agent_unregistered $uuid
3202 check_agent_registered $uuid
3206 run_test 106 "Copytool register/unregister"
3209 # test needs a running copytool
3211 # create and archive file
3213 local f1=$DIR/$tdir/$tfile
3214 local fid=$(copy_file /etc/passwd $f1)
3215 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3216 wait_request_state $fid ARCHIVE SUCCEED
3217 # shutdown and restart MDS
3219 # check the copytool still gets messages from MDT
3220 local f2=$DIR/$tdir/2
3221 local fid=$(copy_file /etc/passwd $f2)
3222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3223 # main check of this sanity: this request MUST succeed
3224 wait_request_state $fid ARCHIVE SUCCEED
3227 run_test 107 "Copytool re-register after MDS restart"
3229 policy_set_and_test()
3233 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3234 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3235 [[ "$policy" == "$target" ]] ||
3236 error "Wrong policy after '$change': '$policy' != '$target'"
3240 # to force default policy setting if error
3241 CDT_POLICY_HAD_CHANGED=true
3243 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3244 local default="NonBlockingRestore [NoRetryAction]"
3245 [[ "$policy" == "$default" ]] ||
3246 error "default policy has changed,"\
3247 " '$policy' != '$default' update the test"
3248 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3249 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3250 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3251 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3252 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3253 # useless bacause we know but safer for futur changes to use real value
3254 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3255 echo "Next set_param must failed"
3256 policy_set_and_test "wrong" "$policy"
3259 echo "Back to default policy"
3260 cdt_set_sanity_policy
3262 run_test 109 "Policy display/change"
3265 # test needs a running copytool
3270 copy2archive /etc/passwd $tdir/$tfile
3272 local f=$DIR/$tdir/$tfile
3273 import_file $tdir/$tfile $f
3274 local fid=$(path2fid $f)
3276 cdt_set_non_blocking_restore
3281 wait_request_state $fid RESTORE SUCCEED
3282 cdt_clear_non_blocking_restore
3286 error "md5sum returns $st != 1, "\
3287 "should also perror ENODATA (No data available)"
3291 run_test 110a "Non blocking restore policy (import case)"
3294 # test needs a running copytool
3298 local f=$DIR/$tdir/$tfile
3299 local fid=$(copy_file /etc/passwd $f)
3300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3301 wait_request_state $fid ARCHIVE SUCCEED
3304 cdt_set_non_blocking_restore
3309 wait_request_state $fid RESTORE SUCCEED
3310 cdt_clear_non_blocking_restore
3314 error "md5sum returns $st != 1, "\
3315 "should also perror ENODATA (No data available)"
3319 run_test 110b "Non blocking restore policy (release case)"
3322 # test needs a running copytool
3326 copy2archive /etc/passwd $tdir/$tfile
3328 local f=$DIR/$tdir/$tfile
3330 import_file $tdir/$tfile $f
3331 local fid=$(path2fid $f)
3335 copytool_remove_backend $fid
3338 wait_request_state $fid RESTORE FAILED
3345 [[ $st == 0 ]] || error "Restore does not failed"
3349 run_test 111a "No retry policy (import case), restore will error"\
3350 " (No such file or directory)"
3353 # test needs a running copytool
3357 local f=$DIR/$tdir/$tfile
3358 local fid=$(copy_file /etc/passwd $f)
3360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3361 wait_request_state $fid ARCHIVE SUCCEED
3364 copytool_remove_backend $fid
3367 wait_request_state $fid RESTORE FAILED
3374 [[ $st == 0 ]] || error "Restore does not failed"
3378 run_test 111b "No retry policy (release case), restore will error"\
3379 " (No such file or directory)"
3382 # test needs a running copytool
3386 local f=$DIR/$tdir/$tfile
3387 local fid=$(copy_file /etc/passwd $f)
3389 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3390 local l=$($LFS hsm_action $f)
3392 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3396 wait_request_state $fid ARCHIVE SUCCEED
3399 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3403 run_test 112 "State of recorded request"
3406 # test needs a running copytool
3410 local f=$DIR/$tdir/$tfile
3411 local fid=$(make_large_for_cancel $f)
3412 # test with cdt on is made in test_221
3414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3417 wait_request_state $fid ARCHIVE CANCELED
3418 wait_request_state $fid CANCEL SUCCEED
3422 run_test 200 "Register/Cancel archive"
3425 # test needs a running copytool
3429 local f=$DIR/$tdir/$tfile
3430 make_archive $tdir/$tfile
3431 import_file $tdir/$tfile $f
3432 local fid=$(path2fid $f)
3434 # test with cdt on is made in test_222
3439 wait_request_state $fid RESTORE CANCELED
3440 wait_request_state $fid CANCEL SUCCEED
3444 run_test 201 "Register/Cancel restore"
3447 # test needs a running copytool
3451 local f=$DIR/$tdir/$tfile
3452 local fid=$(make_large_for_progress $f)
3453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3454 wait_request_state $fid ARCHIVE SUCCEED
3460 wait_request_state $fid REMOVE CANCELED
3464 run_test 202 "Register/Cancel remove"
3467 # test needs a running copytool
3472 local f=$DIR/$tdir/$tfile
3473 local fid=$(copy_file /etc/passwd $f)
3477 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3478 wait_request_state $fid ARCHIVE SUCCEED
3480 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3484 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3488 run_test 220 "Changelog for archive"
3491 # test needs a running copytool
3496 local f=$DIR/$tdir/$tfile
3497 local fid=$(make_large_for_cancel $f)
3501 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3502 wait_request_state $fid ARCHIVE STARTED
3504 wait_request_state $fid ARCHIVE CANCELED
3505 wait_request_state $fid CANCEL SUCCEED
3507 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3510 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3514 run_test 221 "Changelog for archive canceled"
3517 # test needs a running copytool
3521 copy2archive /etc/passwd $tdir/$tfile
3523 local f=$DIR/$tdir/$tfile
3524 import_file $tdir/$tfile $f
3525 local fid=$(path2fid $f)
3530 wait_request_state $fid RESTORE SUCCEED
3532 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3535 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3539 run_test 222a "Changelog for explicit restore"
3542 # test needs a running copytool
3546 local f=$DIR/$tdir/$tfile
3547 local fid=$(copy_file /etc/passwd $f)
3550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3551 wait_request_state $fid ARCHIVE SUCCEED
3556 wait_request_state $fid RESTORE SUCCEED
3558 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3561 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3565 run_test 222b "Changelog for implicit restore"
3568 # test needs a running copytool
3573 local f=$DIR/$tdir/$tfile
3574 make_archive $tdir/$tfile
3578 import_file $tdir/$tfile $f
3579 local fid=$(path2fid $f)
3582 wait_request_state $fid RESTORE STARTED
3584 wait_request_state $fid RESTORE CANCELED
3585 wait_request_state $fid CANCEL SUCCEED
3587 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3590 [[ $flags == $target ]] ||
3591 error "Changelog flag is $flags not $target"
3595 run_test 223a "Changelog for restore canceled (import case)"
3598 # test needs a running copytool
3603 local f=$DIR/$tdir/$tfile
3604 local fid=$(make_large_for_progress $f)
3607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3608 wait_request_state $fid ARCHIVE SUCCEED
3611 wait_request_state $fid RESTORE STARTED
3613 wait_request_state $fid RESTORE CANCELED
3614 wait_request_state $fid CANCEL SUCCEED
3616 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3619 [[ $flags == $target ]] ||
3620 error "Changelog flag is $flags not $target"
3624 run_test 223b "Changelog for restore canceled (release case)"
3627 # test needs a running copytool
3632 local f=$DIR/$tdir/$tfile
3633 local fid=$(copy_file /etc/passwd $f)
3636 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3637 wait_request_state $fid ARCHIVE SUCCEED
3640 wait_request_state $fid REMOVE SUCCEED
3642 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3645 [[ $flags == $target ]] ||
3646 error "Changelog flag is $flags not $target"
3650 run_test 224 "Changelog for remove"
3653 # test needs a running copytool
3656 # test is not usable because remove request is too fast
3657 # so it is always finished before cancel can be done ...
3658 echo "Test disabled"
3663 local f=$DIR/$tdir/$tfile
3664 local fid=$(make_large_for_progress $f)
3667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3668 wait_request_state $fid ARCHIVE SUCCEED
3670 # if cdt is on, it can serve too quickly the request
3675 wait_request_state $fid REMOVE CANCELED
3676 wait_request_state $fid CANCEL SUCCEED
3678 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3679 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3680 tail -n 1 | awk '{print $5}')
3683 [[ $flags == $target ]] ||
3684 error "Changelog flag is $flags not $target"
3688 run_test 225 "Changelog for remove canceled"
3691 # test needs a running copytool
3696 local f1=$DIR/$tdir/$tfile-1
3697 local f2=$DIR/$tdir/$tfile-2
3698 local f3=$DIR/$tdir/$tfile-3
3699 local fid1=$(copy_file /etc/passwd $f1)
3700 local fid2=$(copy_file /etc/passwd $f2)
3701 copy_file /etc/passwd $f3
3704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3705 wait_request_state $fid1 ARCHIVE SUCCEED
3707 $LFS hsm_archive $f2
3708 wait_request_state $fid2 ARCHIVE SUCCEED
3710 rm $f1 || error "rm $f1 failed"
3712 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3715 [[ $flags == $target ]] ||
3716 error "Changelog flag is $flags not $target"
3718 mv $f3 $f2 || error "mv $f3 $f2 failed"
3720 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3723 [[ $flags == $target ]] ||
3724 error "Changelog flag is $flags not $target"
3728 run_test 226 "changelog for last rm/mv with exiting archive"
3730 check_flags_changes() {
3738 $LFS hsm_set --$hsm_flag $f ||
3739 error "Cannot set $hsm_flag on $f"
3740 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3741 local seen=${#flags[*]}
3743 [[ $seen == $cnt ]] ||
3744 error "set $hsm_flag: Changelog events $seen != $cnt"
3745 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3746 error "set $hsm_flag: Changelog flags are "\
3747 "${flags[$((cnt - 1))]} not $target"
3749 $LFS hsm_clear --$hsm_flag $f ||
3750 error "Cannot clear $hsm_flag on $f"
3751 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3754 [[ $cnt == $seen ]] ||
3755 error "clear $hsm_flag: Changelog events $seen != $cnt"
3757 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3758 error "clear $hsm_flag: Changelog flag is "\
3759 "${flags[$((cnt - 1))]} not $target"
3763 # test needs a running copytool
3770 for i in norelease noarchive exists archived
3772 local f=$DIR/$tdir/$tfile-$i
3773 local fid=$(copy_file /etc/passwd $f)
3774 check_flags_changes $f $fid $i 0 1
3777 f=$DIR/$tdir/$tfile---lost
3778 fid=$(copy_file /etc/passwd $f)
3779 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3780 wait_request_state $fid ARCHIVE SUCCEED
3781 check_flags_changes $f $fid lost 3 1
3785 run_test 227 "changelog when explicit setting of HSM flags"
3788 # test needs a running copytool
3791 local fid=$(make_small_sync $DIR/$tfile)
3792 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3793 wait_request_state $fid ARCHIVE SUCCEED
3795 $LFS hsm_release $DIR/$tfile
3796 check_hsm_flags $DIR/$tfile "0x0000000d"
3798 filefrag $DIR/$tfile | grep " 1 extent found" ||
3799 error "filefrag on released file must return only one extent"
3801 # only newer versions of cp detect sparse files by stat/FIEMAP
3803 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3804 error "copying $DIR/$tfile"
3805 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3807 $LFS hsm_release $DIR/$tfile
3808 check_hsm_flags $DIR/$tfile "0x0000000d"
3810 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3812 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3814 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3815 error "comparing untarred $DIR/$tfile"
3817 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3818 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3821 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3824 # test needs a running copytool
3828 local maxrequest=$(get_hsm_param max_requests)
3829 local rqcnt=$(($maxrequest * 3))
3833 for i in $(seq -w 1 $rqcnt); do
3835 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3837 # we do it in 2 steps, so all requests arrive at the same time
3838 for i in $(seq -w 1 $rqcnt); do
3839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3844 while [[ $cnt != 0 || $wt != 0 ]]; do
3846 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3847 $HSM_PARAM.actions |\
3848 grep STARTED | grep -v CANCEL | wc -l")
3849 [[ $cnt -le $maxrequest ]] ||
3850 error "$cnt > $maxrequest too many started requests"
3851 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3852 $HSM_PARAM.actions |\
3853 grep WAITING | wc -l")
3854 echo "max=$maxrequest started=$cnt waiting=$wt"
3859 run_test 250 "Coordinator max request"
3862 # test needs a running copytool
3866 local f=$DIR/$tdir/$tfile
3867 local fid=$(make_large_for_cancel $f)
3870 # to have a short test
3871 local old_to=$(get_hsm_param active_request_timeout)
3872 set_hsm_param active_request_timeout 4
3873 # to be sure the cdt will wake up frequently so
3874 # it will be able to cancel the "old" request
3875 local old_loop=$(get_hsm_param loop_period)
3876 set_hsm_param loop_period 2
3879 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3880 wait_request_state $fid ARCHIVE STARTED
3882 wait_request_state $fid ARCHIVE CANCELED
3884 set_hsm_param active_request_timeout $old_to
3885 set_hsm_param loop_period $old_loop
3889 run_test 251 "Coordinator request timeout"
3892 # the only way to test ondisk conf is to restart MDS ...
3893 echo "Stop coordinator and remove coordinator state at mount"
3896 # clean on disk conf set by default
3897 cdt_clear_mount_state
3898 cdt_check_state stopped
3900 # check cdt still off after umount/remount
3902 cdt_check_state stopped
3904 echo "Set coordinator start at mount, and start coordinator"
3905 cdt_set_mount_state enabled
3908 cdt_check_state enabled
3910 # check cdt still on after umount/remount
3912 cdt_check_state enabled
3914 # we are back to original state (cdt started at mount)
3916 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3919 local ai=$(get_hsm_param default_archive_id)
3920 local new=$((ai + 1))
3922 set_hsm_param default_archive_id $new -P
3924 local res=$(get_hsm_param default_archive_id)
3927 set_hsm_param default_archive_id "" "-P -d"
3929 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3931 run_test 301 "HSM tunnable are persistent"
3934 local ai=$(get_hsm_param default_archive_id)
3935 local new=$((ai + 1))
3940 set_hsm_param default_archive_id $new -P
3943 for mdtno in $(seq 1 $MDSCOUNT); do
3948 cdt_check_state enabled
3950 local res=$(get_hsm_param default_archive_id)
3953 set_hsm_param default_archive_id "" "-P -d"
3955 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3957 run_test 302 "HSM tunnable are persistent when CDT is off"
3960 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3966 local dir_mdt0=$DIR/$tdir/mdt0
3967 local dir_mdt1=$DIR/$tdir/mdt1
3969 # create 1 dir per MDT
3970 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3971 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3973 # create 1 file in each MDT
3974 local fid1=$(make_small $dir_mdt0/$tfile)
3975 local fid2=$(make_small $dir_mdt1/$tfile)
3977 # check that hsm request on mdt0 is sent to the right MDS
3978 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3979 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3980 echo "archive successful on mdt0"
3982 # check that hsm request on mdt1 is sent to the right MDS
3983 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3984 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3985 echo "archive successful on mdt1"
3988 # clean test files and directories
3989 rm -rf $dir_mdt0 $dir_mdt1
3991 run_test 400 "Single request is sent to the right MDT"
3994 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4000 local dir_mdt0=$DIR/$tdir/mdt0
4001 local dir_mdt1=$DIR/$tdir/mdt1
4003 # create 1 dir per MDT
4004 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4005 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4007 # create 1 file in each MDT
4008 local fid1=$(make_small $dir_mdt0/$tfile)
4009 local fid2=$(make_small $dir_mdt1/$tfile)
4011 # check that compound requests are shunt to the rights MDTs
4012 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4013 error "lfs hsm_archive"
4014 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4015 echo "archive successful on mdt0"
4016 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4017 echo "archive successful on mdt1"
4020 # clean test files and directories
4021 rm -rf $dir_mdt0 $dir_mdt1
4023 run_test 401 "Compound requests split and sent to their respective MDTs"
4025 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4030 local node=$(facet_active_host $facet)
4032 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4033 awk '{print $4}'); do
4034 echo "$3 $mdc on $node"
4035 do_facet $facet "$LCTL --device $mdc $state" || return 1
4040 # make sure there is no running copytool
4043 # deactivate all mdc on agent1
4044 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4046 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4048 check_agent_unregistered "uuid" # match any agent
4050 # no expected running copytool
4051 search_copytools $agent && error "Copytool start should have failed"
4054 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4056 run_test 402 "Copytool start fails if all MDTs are inactive"
4059 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4061 # make sure there is no running copytool
4064 local agent=$(facet_active_host $SINGLEAGT)
4065 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4067 # deactivate all mdc for MDT0001
4068 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4071 # check the agent is registered on MDT0000, and not on MDT0001
4072 check_agent_registered_by_mdt $uuid 0
4073 check_agent_unregistered_by_mdt $uuid 1
4075 # check running copytool process
4076 search_copytools $agent || error "No running copytools on $agent"
4078 # reactivate all mdc for MDT0001
4079 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4081 # make sure the copytool is now registered to all MDTs
4082 check_agent_registered $uuid
4086 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4089 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4093 # create files on both MDT0000 and MDT0001
4096 local dir_mdt0=$DIR/$tdir/mdt0
4097 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4099 # create 1 file on mdt0
4100 local fid1=$(make_small $dir_mdt0/$tfile)
4102 # deactivate all mdc for MDT0001
4103 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4105 # send an HSM request for files in MDT0000
4106 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4108 # check for completion of files in MDT0000
4109 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4110 echo "archive successful on mdt0"
4112 # reactivate all mdc for MDT0001
4113 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4116 # clean test files and directories
4119 run_test 404 "Inactive MDT does not block requests for active MDTs"
4122 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4128 local striped_dir=$DIR/$tdir/striped_dir
4130 # create striped dir on all of MDTs
4131 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4133 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4134 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4135 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4136 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4138 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4139 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4140 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4141 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4143 # check that compound requests are shunt to the rights MDTs
4144 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4145 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4146 error "lfs hsm_archive"
4148 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4149 echo "archive successful on $fid1"
4150 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4151 echo "archive successful on $fid2"
4152 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4153 echo "archive successful on $fid3"
4154 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4155 echo "archive successful on $fid4"
4157 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4158 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4159 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4160 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4162 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4163 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4164 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4165 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4169 run_test 405 "archive and release under striped directory"
4174 check_and_cleanup_lustre