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-4178
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b"
18 # bug number for skipped test:LU-3852
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MOUNT_2=${MOUNT_2:-"yes"}
34 # script only handles up to 10 MDTs (because of MDT_PREFIX)
35 [ $MDSCOUNT -gt 9 ] &&
36 error "script cannot handle more than 9 MDTs, please fix" && exit
38 check_and_setup_lustre
40 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
41 skip_env "Need MDS version at least 2.4.53" && exit
44 # $RUNAS_ID may get set incorrectly somewhere else
45 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
46 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
54 # the following associated variables are added:
56 # AGTCOUNT: number of agents
57 # AGTDEV{N}: target HSM mount point (root path of the backend)
58 # agt{N}_HOST: hostname of the agent agt{N}
59 # SINGLEAGT: facet of the single agent
61 # The number of agents is initialized as the number of remote client nodes.
62 # By default, only single copytool is started on a remote client/agent. If there
63 # was no remote client, then the copytool will be started on the local client.
69 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
70 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
72 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
73 if [[ $CLIENTCOUNT -gt 1 ]] &&
74 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
75 skip_env "SHARED_DIRECTORY should be accessible"\
80 for n in $(seq $AGTCOUNT); do
81 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
82 agent=CLIENT$((n + 1))
83 if [[ -z "${!agent}" ]]; then
84 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
87 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
90 export SINGLEAGT=${SINGLEAGT:-agt1}
92 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
93 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
94 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
95 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
96 export HSMTOOL_TESTDIR
97 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
98 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
101 # The test only support up to 10 MDTs
102 MDT_PREFIX="mdt.$FSNAME-MDT000"
103 HSM_PARAM="${MDT_PREFIX}0.hsm"
105 # archive is purged at copytool setup
106 HSM_ARCHIVE_PURGE=true
108 # Don't allow copytool error upon start/setup
109 HSMTOOL_NOERROR=false
112 # Get the backend root path for the given agent facet.
115 local dev=AGTDEV$(facet_number $facet)
120 # Stop copytool and unregister an existing changelog user.
122 copytool_monitor_cleanup
125 cdt_set_sanity_policy
130 # get MDT device for each mdc
131 for mdtno in $(seq 1 $MDSCOUNT); do
132 local idx=$(($mdtno - 1))
133 MDT[$idx]=$($LCTL get_param -n \
134 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
135 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
140 local agents=${1:-$(facet_active_host $SINGLEAGT)}
141 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
144 search_and_kill_copytool() {
145 local agents=${1:-$(facet_active_host $SINGLEAGT)}
147 echo "Killing existing copytools on $agents"
148 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
151 copytool_monitor_setup() {
152 local facet=${1:-$SINGLEAGT}
153 local agent=$(facet_active_host $facet)
155 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
156 local test_dir=$(do_node $agent "$cmd") ||
157 error "Failed to create tempdir on $agent"
158 export HSMTOOL_MONITOR_DIR=$test_dir
160 # Create the fifo and a monitor (cat dies when copytool dies)
161 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
162 error "failed to create copytool fifo on $agent"
163 cmd="cat $test_dir/fifo > $test_dir/events &"
164 cmd+=" echo \\\$! > $test_dir/monitor_pid"
166 if [[ $PDSH == *Rmrsh* ]]; then
167 # This is required for pdsh -Rmrsh and its handling of remote
169 # Regular ssh and pdsh -Rssh work fine without this
170 # backgrounded subshell nonsense.
171 (do_node $agent "$cmd") &
172 export HSMTOOL_MONITOR_PDSH=$!
174 # Slightly racy, but just making a best-effort to catch obvious
177 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
178 error "Failed to start copytool monitor on $agent"
180 do_node $agent "$cmd"
182 error "Failed to start copytool monitor on $agent"
187 copytool_monitor_cleanup() {
188 local facet=${1:-$SINGLEAGT}
189 local agent=$(facet_active_host $facet)
191 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
192 # Should die when the copytool dies, but just in case.
193 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
194 cmd+=" 2>/dev/null || true"
195 do_node $agent "$cmd"
196 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
197 export HSMTOOL_MONITOR_DIR=
200 # The pdsh should die on its own when the monitor dies. Just
201 # in case, though, try to clean up to avoid any cruft.
202 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
203 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
204 export HSMTOOL_MONITOR_PDSH=
209 local facet=${1:-$SINGLEAGT}
210 local lustre_mntpnt=${2:-$MOUNT}
212 local hsm_root=${4:-$(copytool_device $facet)}
213 local agent=$(facet_active_host $facet)
215 if [[ -z "$arc_id" ]] &&
216 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
217 echo "Only wakeup running copytool $facet on $agent"
221 if $HSM_ARCHIVE_PURGE; then
222 echo "Purging archive on $agent"
223 do_facet $facet "rm -rf $hsm_root/*"
226 echo "Starting copytool $facet on $agent"
227 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
228 # bandwidth is limited to 1MB/s so the copy time is known and
229 # independent of hardware
230 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
231 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
232 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
233 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
234 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
235 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
236 cmd+=" --bandwidth 1 $lustre_mntpnt"
238 # Redirect the standard output and error to a log file which
239 # can be uploaded to Maloo.
240 local prefix=$TESTLOG_PREFIX
241 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
242 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
244 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
245 if [[ $? != 0 ]]; then
246 [[ $HSMTOOL_NOERROR == true ]] ||
247 error "start copytool $facet on $agent failed"
248 echo "start copytool $facet on $agent failed"
254 get_copytool_event_log() {
255 local facet=${1:-$SINGLEAGT}
256 local agent=$(facet_active_host $facet)
258 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
259 error "Can't get event log: No monitor directory!"
261 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
262 error "Could not collect event log from $agent"
267 local facet=$SINGLEAGT
268 local agents=${1:-$(facet_active_host $facet)}
273 local hsm_root=$(copytool_device $facet)
274 local end_wait=$(( SECONDS + TIMEOUT ))
276 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
278 while (( SECONDS < end_wait )); do
280 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
281 if [ $? -ne 0 ]; then
282 echo "Copytool is stopped on $agents"
285 echo "Copytool still running on $agents"
287 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
288 error "Copytool failed to stop in ${TIMEOUT}s ..."
290 echo "Copytool has stopped in " \
291 "$((TIMEOUT - (end_wait - SECONDS)))s."
294 # clean all CDTs orphans requests from previous tests
295 # that would otherwise need to timeout to clear.
296 for mdtno in $(seq 1 $MDSCOUNT); do
298 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
299 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
301 # skip already stop[ed,ing] CDTs
302 echo $oldstate | grep stop && continue
304 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
305 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
307 error "mds${mdtno} cdt state is not stopped"
308 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
309 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
311 error "mds${mdtno} cdt state is not $oldstate"
313 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
314 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 do_facet $SINGLEAGT "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
3013 # force copytool to use a local/temp archive dir to ensure best
3014 # performance vs remote/NFS mounts used in auto-tests
3015 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3018 local dai=$(get_hsm_param default_archive_id)
3019 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3021 # to be sure wait_all_done will not be mislead by previous tests
3023 wait_for_grace_delay
3024 $LFS hsm_archive --filelist $FILELIST ||
3025 error "cannot archive a file list"
3027 $LFS hsm_release --filelist $FILELIST ||
3028 error "cannot release a file list"
3029 $LFS hsm_restore --filelist $FILELIST ||
3030 error "cannot restore a file list"
3034 run_test 90 "Archive/restore a file list"
3036 double_verify_reset_hsm_param() {
3038 echo "Testing $HSM_PARAM.$p"
3039 local val=$(get_hsm_param $p)
3041 local val2=$(($val * 2))
3042 set_hsm_param $p $val2
3043 val=$(get_hsm_param $p)
3044 [[ $val == $val2 ]] ||
3045 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3046 echo "Set $p to 0 must failed"
3050 set_hsm_param $p $save
3052 if [[ $rc == 0 ]]; then
3053 error "we must not be able to set $HSM_PARAM.$p to 0"
3058 double_verify_reset_hsm_param loop_period
3059 double_verify_reset_hsm_param grace_delay
3060 double_verify_reset_hsm_param active_request_timeout
3061 double_verify_reset_hsm_param max_requests
3062 double_verify_reset_hsm_param default_archive_id
3064 run_test 100 "Set coordinator /proc tunables"
3071 run_test 102 "Verify coordinator control"
3074 # test needs a running copytool
3081 for i in $(seq 1 20); do
3082 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3084 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3088 echo "Current requests"
3089 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3090 $HSM_PARAM.actions |\
3091 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3093 [[ -z "$res" ]] || error "Some request have not been canceled"
3097 run_test 103 "Purge all requests"
3102 # test needs a running copytool
3106 local f=$DIR/$tdir/$tfile
3107 local fid=$(make_large_for_progress $f)
3108 # if cdt is on, it can serve too quickly the request
3110 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3111 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3112 $HSM_PARAM.actions |\
3113 grep $fid | cut -f16 -d=")
3116 [[ "$data1" == "$DATAHEX" ]] ||
3117 error "Data field in records is ($data1) and not ($DATAHEX)"
3121 run_test 104 "Copy tool data field"
3128 for i in $(seq -w 1 10); do
3129 cp /etc/passwd $DIR/$tdir/$i
3130 $LFS hsm_archive $DIR/$tdir/$i
3132 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3133 $HSM_PARAM.actions |\
3134 grep WAITING | wc -l")
3137 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3138 $HSM_PARAM.actions |\
3139 grep WAITING | wc -l")
3142 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3143 error "Requests count after shutdown $reqcnt2 != "\
3144 "before shutdown $reqcnt1"
3146 run_test 105 "Restart of coordinator"
3148 get_agent_by_uuid_mdt() {
3151 local mds=mds$(($mdtidx + 1))
3152 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3156 check_agent_registered_by_mdt() {
3159 local mds=mds$(($mdtidx + 1))
3160 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3161 if [[ ! -z "$agent" ]]; then
3162 echo "found agent $agent on $mds"
3164 error "uuid $uuid not found in agent list on $mds"
3168 check_agent_unregistered_by_mdt() {
3171 local mds=mds$(($mdtidx + 1))
3172 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3173 if [[ -z "$agent" ]]; then
3174 echo "uuid not found in agent list on $mds"
3176 error "uuid found in agent list on $mds: $agent"
3180 check_agent_registered() {
3183 for mdsno in $(seq 1 $MDSCOUNT); do
3184 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3188 check_agent_unregistered() {
3191 for mdsno in $(seq 1 $MDSCOUNT); do
3192 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3197 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3198 get_client_uuid $MOUNT | cut -d' ' -f2)
3201 check_agent_registered $uuid
3203 search_copytools || error "No copytool found"
3206 check_agent_unregistered $uuid
3209 check_agent_registered $uuid
3213 run_test 106 "Copytool register/unregister"
3216 # test needs a running copytool
3218 # create and archive file
3220 local f1=$DIR/$tdir/$tfile
3221 local fid=$(copy_file /etc/passwd $f1)
3222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3223 wait_request_state $fid ARCHIVE SUCCEED
3224 # shutdown and restart MDS
3226 # check the copytool still gets messages from MDT
3227 local f2=$DIR/$tdir/2
3228 local fid=$(copy_file /etc/passwd $f2)
3229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3230 # main check of this sanity: this request MUST succeed
3231 wait_request_state $fid ARCHIVE SUCCEED
3234 run_test 107 "Copytool re-register after MDS restart"
3236 policy_set_and_test()
3240 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3241 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3242 [[ "$policy" == "$target" ]] ||
3243 error "Wrong policy after '$change': '$policy' != '$target'"
3247 # to force default policy setting if error
3248 CDT_POLICY_HAD_CHANGED=true
3250 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3251 local default="NonBlockingRestore [NoRetryAction]"
3252 [[ "$policy" == "$default" ]] ||
3253 error "default policy has changed,"\
3254 " '$policy' != '$default' update the test"
3255 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3256 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3257 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3258 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3259 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3260 # useless bacause we know but safer for futur changes to use real value
3261 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3262 echo "Next set_param must failed"
3263 policy_set_and_test "wrong" "$policy"
3266 echo "Back to default policy"
3267 cdt_set_sanity_policy
3269 run_test 109 "Policy display/change"
3272 # test needs a running copytool
3277 copy2archive /etc/passwd $tdir/$tfile
3279 local f=$DIR/$tdir/$tfile
3280 import_file $tdir/$tfile $f
3281 local fid=$(path2fid $f)
3283 cdt_set_non_blocking_restore
3288 wait_request_state $fid RESTORE SUCCEED
3289 cdt_clear_non_blocking_restore
3293 error "md5sum returns $st != 1, "\
3294 "should also perror ENODATA (No data available)"
3298 run_test 110a "Non blocking restore policy (import case)"
3301 # test needs a running copytool
3305 local f=$DIR/$tdir/$tfile
3306 local fid=$(copy_file /etc/passwd $f)
3307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3308 wait_request_state $fid ARCHIVE SUCCEED
3311 cdt_set_non_blocking_restore
3316 wait_request_state $fid RESTORE SUCCEED
3317 cdt_clear_non_blocking_restore
3321 error "md5sum returns $st != 1, "\
3322 "should also perror ENODATA (No data available)"
3326 run_test 110b "Non blocking restore policy (release case)"
3329 # test needs a running copytool
3333 copy2archive /etc/passwd $tdir/$tfile
3335 local f=$DIR/$tdir/$tfile
3337 import_file $tdir/$tfile $f
3338 local fid=$(path2fid $f)
3342 copytool_remove_backend $fid
3345 wait_request_state $fid RESTORE FAILED
3352 [[ $st == 0 ]] || error "Restore does not failed"
3356 run_test 111a "No retry policy (import case), restore will error"\
3357 " (No such file or directory)"
3360 # test needs a running copytool
3364 local f=$DIR/$tdir/$tfile
3365 local fid=$(copy_file /etc/passwd $f)
3367 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3368 wait_request_state $fid ARCHIVE SUCCEED
3371 copytool_remove_backend $fid
3374 wait_request_state $fid RESTORE FAILED
3381 [[ $st == 0 ]] || error "Restore does not failed"
3385 run_test 111b "No retry policy (release case), restore will error"\
3386 " (No such file or directory)"
3389 # test needs a running copytool
3393 local f=$DIR/$tdir/$tfile
3394 local fid=$(copy_file /etc/passwd $f)
3396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3397 local l=$($LFS hsm_action $f)
3399 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3403 wait_request_state $fid ARCHIVE SUCCEED
3406 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3410 run_test 112 "State of recorded request"
3413 # test needs a running copytool
3417 local f=$DIR/$tdir/$tfile
3418 local fid=$(make_large_for_cancel $f)
3419 # test with cdt on is made in test_221
3421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3424 wait_request_state $fid ARCHIVE CANCELED
3425 wait_request_state $fid CANCEL SUCCEED
3429 run_test 200 "Register/Cancel archive"
3432 # test needs a running copytool
3436 local f=$DIR/$tdir/$tfile
3437 make_archive $tdir/$tfile
3438 import_file $tdir/$tfile $f
3439 local fid=$(path2fid $f)
3441 # test with cdt on is made in test_222
3446 wait_request_state $fid RESTORE CANCELED
3447 wait_request_state $fid CANCEL SUCCEED
3451 run_test 201 "Register/Cancel restore"
3454 # test needs a running copytool
3458 local f=$DIR/$tdir/$tfile
3459 local fid=$(make_large_for_progress $f)
3460 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3461 wait_request_state $fid ARCHIVE SUCCEED
3467 wait_request_state $fid REMOVE CANCELED
3471 run_test 202 "Register/Cancel remove"
3474 # test needs a running copytool
3479 local f=$DIR/$tdir/$tfile
3480 local fid=$(copy_file /etc/passwd $f)
3484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3485 wait_request_state $fid ARCHIVE SUCCEED
3487 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3491 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3495 run_test 220 "Changelog for archive"
3498 # test needs a running copytool
3503 local f=$DIR/$tdir/$tfile
3504 local fid=$(make_large_for_cancel $f)
3508 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3509 wait_request_state $fid ARCHIVE STARTED
3511 wait_request_state $fid ARCHIVE CANCELED
3512 wait_request_state $fid CANCEL SUCCEED
3514 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3517 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3521 run_test 221 "Changelog for archive canceled"
3524 # test needs a running copytool
3528 copy2archive /etc/passwd $tdir/$tfile
3530 local f=$DIR/$tdir/$tfile
3531 import_file $tdir/$tfile $f
3532 local fid=$(path2fid $f)
3537 wait_request_state $fid RESTORE SUCCEED
3539 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3542 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3546 run_test 222a "Changelog for explicit restore"
3549 # test needs a running copytool
3553 local f=$DIR/$tdir/$tfile
3554 local fid=$(copy_file /etc/passwd $f)
3557 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3558 wait_request_state $fid ARCHIVE SUCCEED
3563 wait_request_state $fid RESTORE SUCCEED
3565 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3568 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3572 run_test 222b "Changelog for implicit restore"
3575 # test needs a running copytool
3580 local f=$DIR/$tdir/$tfile
3581 make_archive $tdir/$tfile
3585 import_file $tdir/$tfile $f
3586 local fid=$(path2fid $f)
3589 wait_request_state $fid RESTORE STARTED
3591 wait_request_state $fid RESTORE CANCELED
3592 wait_request_state $fid CANCEL SUCCEED
3594 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3597 [[ $flags == $target ]] ||
3598 error "Changelog flag is $flags not $target"
3602 run_test 223a "Changelog for restore canceled (import case)"
3605 # test needs a running copytool
3610 local f=$DIR/$tdir/$tfile
3611 local fid=$(make_large_for_progress $f)
3614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3615 wait_request_state $fid ARCHIVE SUCCEED
3618 wait_request_state $fid RESTORE STARTED
3620 wait_request_state $fid RESTORE CANCELED
3621 wait_request_state $fid CANCEL SUCCEED
3623 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3626 [[ $flags == $target ]] ||
3627 error "Changelog flag is $flags not $target"
3631 run_test 223b "Changelog for restore canceled (release case)"
3634 # test needs a running copytool
3639 local f=$DIR/$tdir/$tfile
3640 local fid=$(copy_file /etc/passwd $f)
3643 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3644 wait_request_state $fid ARCHIVE SUCCEED
3647 wait_request_state $fid REMOVE SUCCEED
3649 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3652 [[ $flags == $target ]] ||
3653 error "Changelog flag is $flags not $target"
3657 run_test 224 "Changelog for remove"
3660 # test needs a running copytool
3663 # test is not usable because remove request is too fast
3664 # so it is always finished before cancel can be done ...
3665 echo "Test disabled"
3670 local f=$DIR/$tdir/$tfile
3671 local fid=$(make_large_for_progress $f)
3674 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3675 wait_request_state $fid ARCHIVE SUCCEED
3677 # if cdt is on, it can serve too quickly the request
3682 wait_request_state $fid REMOVE CANCELED
3683 wait_request_state $fid CANCEL SUCCEED
3685 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3686 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3687 tail -n 1 | awk '{print $5}')
3690 [[ $flags == $target ]] ||
3691 error "Changelog flag is $flags not $target"
3695 run_test 225 "Changelog for remove canceled"
3698 # test needs a running copytool
3703 local f1=$DIR/$tdir/$tfile-1
3704 local f2=$DIR/$tdir/$tfile-2
3705 local f3=$DIR/$tdir/$tfile-3
3706 local fid1=$(copy_file /etc/passwd $f1)
3707 local fid2=$(copy_file /etc/passwd $f2)
3708 copy_file /etc/passwd $f3
3711 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3712 wait_request_state $fid1 ARCHIVE SUCCEED
3714 $LFS hsm_archive $f2
3715 wait_request_state $fid2 ARCHIVE SUCCEED
3717 rm $f1 || error "rm $f1 failed"
3719 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3722 [[ $flags == $target ]] ||
3723 error "Changelog flag is $flags not $target"
3725 mv $f3 $f2 || error "mv $f3 $f2 failed"
3727 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3730 [[ $flags == $target ]] ||
3731 error "Changelog flag is $flags not $target"
3735 run_test 226 "changelog for last rm/mv with exiting archive"
3737 check_flags_changes() {
3745 $LFS hsm_set --$hsm_flag $f ||
3746 error "Cannot set $hsm_flag on $f"
3747 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3748 local seen=${#flags[*]}
3750 [[ $seen == $cnt ]] ||
3751 error "set $hsm_flag: Changelog events $seen != $cnt"
3752 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3753 error "set $hsm_flag: Changelog flags are "\
3754 "${flags[$((cnt - 1))]} not $target"
3756 $LFS hsm_clear --$hsm_flag $f ||
3757 error "Cannot clear $hsm_flag on $f"
3758 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3761 [[ $cnt == $seen ]] ||
3762 error "clear $hsm_flag: Changelog events $seen != $cnt"
3764 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3765 error "clear $hsm_flag: Changelog flag is "\
3766 "${flags[$((cnt - 1))]} not $target"
3770 # test needs a running copytool
3777 for i in norelease noarchive exists archived
3779 local f=$DIR/$tdir/$tfile-$i
3780 local fid=$(copy_file /etc/passwd $f)
3781 check_flags_changes $f $fid $i 0 1
3784 f=$DIR/$tdir/$tfile---lost
3785 fid=$(copy_file /etc/passwd $f)
3786 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3787 wait_request_state $fid ARCHIVE SUCCEED
3788 check_flags_changes $f $fid lost 3 1
3792 run_test 227 "changelog when explicit setting of HSM flags"
3795 # test needs a running copytool
3798 local fid=$(make_small_sync $DIR/$tfile)
3799 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3800 wait_request_state $fid ARCHIVE SUCCEED
3802 $LFS hsm_release $DIR/$tfile
3803 check_hsm_flags $DIR/$tfile "0x0000000d"
3805 filefrag $DIR/$tfile | grep " 1 extent found" ||
3806 error "filefrag on released file must return only one extent"
3808 # only newer versions of cp detect sparse files by stat/FIEMAP
3810 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3811 error "copying $DIR/$tfile"
3812 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3814 $LFS hsm_release $DIR/$tfile
3815 check_hsm_flags $DIR/$tfile "0x0000000d"
3817 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3819 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3821 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3822 error "comparing untarred $DIR/$tfile"
3824 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3825 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3828 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3831 # test needs a running copytool
3835 local maxrequest=$(get_hsm_param max_requests)
3836 local rqcnt=$(($maxrequest * 3))
3840 for i in $(seq -w 1 $rqcnt); do
3842 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3844 # we do it in 2 steps, so all requests arrive at the same time
3845 for i in $(seq -w 1 $rqcnt); do
3846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3851 while [[ $cnt != 0 || $wt != 0 ]]; do
3853 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3854 $HSM_PARAM.actions |\
3855 grep STARTED | grep -v CANCEL | wc -l")
3856 [[ $cnt -le $maxrequest ]] ||
3857 error "$cnt > $maxrequest too many started requests"
3858 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3859 $HSM_PARAM.actions |\
3860 grep WAITING | wc -l")
3861 echo "max=$maxrequest started=$cnt waiting=$wt"
3866 run_test 250 "Coordinator max request"
3869 # test needs a running copytool
3873 local f=$DIR/$tdir/$tfile
3874 local fid=$(make_large_for_cancel $f)
3877 # to have a short test
3878 local old_to=$(get_hsm_param active_request_timeout)
3879 set_hsm_param active_request_timeout 4
3880 # to be sure the cdt will wake up frequently so
3881 # it will be able to cancel the "old" request
3882 local old_loop=$(get_hsm_param loop_period)
3883 set_hsm_param loop_period 2
3886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3887 wait_request_state $fid ARCHIVE STARTED
3889 wait_request_state $fid ARCHIVE CANCELED
3891 set_hsm_param active_request_timeout $old_to
3892 set_hsm_param loop_period $old_loop
3896 run_test 251 "Coordinator request timeout"
3899 # the only way to test ondisk conf is to restart MDS ...
3900 echo "Stop coordinator and remove coordinator state at mount"
3903 # clean on disk conf set by default
3904 cdt_clear_mount_state
3905 cdt_check_state stopped
3907 # check cdt still off after umount/remount
3909 cdt_check_state stopped
3911 echo "Set coordinator start at mount, and start coordinator"
3912 cdt_set_mount_state enabled
3915 cdt_check_state enabled
3917 # check cdt still on after umount/remount
3919 cdt_check_state enabled
3921 # we are back to original state (cdt started at mount)
3923 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3926 local ai=$(get_hsm_param default_archive_id)
3927 local new=$((ai + 1))
3929 set_hsm_param default_archive_id $new -P
3931 local res=$(get_hsm_param default_archive_id)
3934 set_hsm_param default_archive_id "" "-P -d"
3936 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3938 run_test 301 "HSM tunnable are persistent"
3941 local ai=$(get_hsm_param default_archive_id)
3942 local new=$((ai + 1))
3947 set_hsm_param default_archive_id $new -P
3950 for mdtno in $(seq 1 $MDSCOUNT); do
3955 cdt_check_state enabled
3957 local res=$(get_hsm_param default_archive_id)
3960 set_hsm_param default_archive_id "" "-P -d"
3962 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3964 run_test 302 "HSM tunnable are persistent when CDT is off"
3967 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3973 local dir_mdt0=$DIR/$tdir/mdt0
3974 local dir_mdt1=$DIR/$tdir/mdt1
3976 # create 1 dir per MDT
3977 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3978 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3980 # create 1 file in each MDT
3981 local fid1=$(make_small $dir_mdt0/$tfile)
3982 local fid2=$(make_small $dir_mdt1/$tfile)
3984 # check that hsm request on mdt0 is sent to the right MDS
3985 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3986 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3987 echo "archive successful on mdt0"
3989 # check that hsm request on mdt1 is sent to the right MDS
3990 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3991 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3992 echo "archive successful on mdt1"
3995 # clean test files and directories
3996 rm -rf $dir_mdt0 $dir_mdt1
3998 run_test 400 "Single request is sent to the right MDT"
4001 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4007 local dir_mdt0=$DIR/$tdir/mdt0
4008 local dir_mdt1=$DIR/$tdir/mdt1
4010 # create 1 dir per MDT
4011 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4012 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4014 # create 1 file in each MDT
4015 local fid1=$(make_small $dir_mdt0/$tfile)
4016 local fid2=$(make_small $dir_mdt1/$tfile)
4018 # check that compound requests are shunt to the rights MDTs
4019 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4020 error "lfs hsm_archive"
4021 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4022 echo "archive successful on mdt0"
4023 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4024 echo "archive successful on mdt1"
4027 # clean test files and directories
4028 rm -rf $dir_mdt0 $dir_mdt1
4030 run_test 401 "Compound requests split and sent to their respective MDTs"
4032 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4037 local node=$(facet_active_host $facet)
4039 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4040 awk '{print $4}'); do
4041 echo "$3 $mdc on $node"
4042 do_facet $facet "$LCTL --device $mdc $state" || return 1
4047 # make sure there is no running copytool
4050 # deactivate all mdc on agent1
4051 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4053 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4055 check_agent_unregistered "uuid" # match any agent
4057 # no expected running copytool
4058 search_copytools $agent && error "Copytool start should have failed"
4061 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4063 run_test 402 "Copytool start fails if all MDTs are inactive"
4066 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4068 # make sure there is no running copytool
4071 local agent=$(facet_active_host $SINGLEAGT)
4072 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4074 # deactivate all mdc for MDT0001
4075 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4078 # check the agent is registered on MDT0000, and not on MDT0001
4079 check_agent_registered_by_mdt $uuid 0
4080 check_agent_unregistered_by_mdt $uuid 1
4082 # check running copytool process
4083 search_copytools $agent || error "No running copytools on $agent"
4085 # reactivate all mdc for MDT0001
4086 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4088 # make sure the copytool is now registered to all MDTs
4089 check_agent_registered $uuid
4093 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4096 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4100 # create files on both MDT0000 and MDT0001
4103 local dir_mdt0=$DIR/$tdir/mdt0
4104 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4106 # create 1 file on mdt0
4107 local fid1=$(make_small $dir_mdt0/$tfile)
4109 # deactivate all mdc for MDT0001
4110 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4112 # send an HSM request for files in MDT0000
4113 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4115 # check for completion of files in MDT0000
4116 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4117 echo "archive successful on mdt0"
4119 # reactivate all mdc for MDT0001
4120 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4123 # clean test files and directories
4126 run_test 404 "Inactive MDT does not block requests for active MDTs"
4129 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4135 local striped_dir=$DIR/$tdir/striped_dir
4137 # create striped dir on all of MDTs
4138 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4140 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4141 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4142 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4143 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4145 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4146 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4147 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4148 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4150 # check that compound requests are shunt to the rights MDTs
4151 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4152 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4153 error "lfs hsm_archive"
4155 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4156 echo "archive successful on $fid1"
4157 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4158 echo "archive successful on $fid2"
4159 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4160 echo "archive successful on $fid3"
4161 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4162 echo "archive successful on $fid4"
4164 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4165 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4166 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4167 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4169 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4170 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4171 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4172 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4176 run_test 405 "archive and release under striped directory"
4181 check_and_cleanup_lustre