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 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MOUNT_2=${MOUNT_2:-"yes"}
30 # script only handles up to 10 MDTs (because of MDT_PREFIX)
31 [ $MDSCOUNT -gt 9 ] &&
32 error "script cannot handle more than 9 MDTs, please fix" && exit
34 check_and_setup_lustre
36 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
37 skip_env "Need MDS version at least 2.4.53" && exit
40 # $RUNAS_ID may get set incorrectly somewhere else
41 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
42 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
50 # the following associated variables are added:
52 # AGTCOUNT: number of agents
53 # AGTDEV{N}: target HSM mount point (root path of the backend)
54 # agt{N}_HOST: hostname of the agent agt{N}
55 # SINGLEAGT: facet of the single agent
57 # The number of agents is initialized as the number of remote client nodes.
58 # By default, only single copytool is started on a remote client/agent. If there
59 # was no remote client, then the copytool will be started on the local client.
65 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
66 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
68 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
69 if [[ $CLIENTCOUNT -gt 1 ]] &&
70 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
71 skip_env "SHARED_DIRECTORY should be accessible"\
76 for n in $(seq $AGTCOUNT); do
77 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
78 agent=CLIENT$((n + 1))
79 if [[ -z "${!agent}" ]]; then
80 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
83 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
86 export SINGLEAGT=${SINGLEAGT:-agt1}
88 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
89 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
90 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
91 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
92 export HSMTOOL_TESTDIR
93 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
94 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
97 # The test only support up to 10 MDTs
98 MDT_PREFIX="mdt.$FSNAME-MDT000"
99 HSM_PARAM="${MDT_PREFIX}0.hsm"
101 # archive is purged at copytool setup
102 HSM_ARCHIVE_PURGE=true
104 # Don't allow copytool error upon start/setup
105 HSMTOOL_NOERROR=false
108 # Get the backend root path for the given agent facet.
111 local dev=AGTDEV$(facet_number $facet)
116 # Stop copytool and unregister an existing changelog user.
118 copytool_monitor_cleanup
121 cdt_set_sanity_policy
126 # get MDT device for each mdc
127 for mdtno in $(seq 1 $MDSCOUNT); do
128 local idx=$(($mdtno - 1))
129 MDT[$idx]=$($LCTL get_param -n \
130 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
131 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
136 local agents=${1:-$(facet_active_host $SINGLEAGT)}
137 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
140 search_and_kill_copytool() {
141 local agents=${1:-$(facet_active_host $SINGLEAGT)}
143 echo "Killing existing copytools on $agents"
144 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
147 copytool_monitor_setup() {
148 local facet=${1:-$SINGLEAGT}
149 local agent=$(facet_active_host $facet)
151 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
152 local test_dir=$(do_node $agent "$cmd") ||
153 error "Failed to create tempdir on $agent"
154 export HSMTOOL_MONITOR_DIR=$test_dir
156 # Create the fifo and a monitor (cat dies when copytool dies)
157 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
158 error "failed to create copytool fifo on $agent"
159 cmd="cat $test_dir/fifo > $test_dir/events &"
160 cmd+=" echo \\\$! > $test_dir/monitor_pid"
162 if [[ $PDSH == *Rmrsh* ]]; then
163 # This is required for pdsh -Rmrsh and its handling of remote
165 # Regular ssh and pdsh -Rssh work fine without this
166 # backgrounded subshell nonsense.
167 (do_node $agent "$cmd") &
168 export HSMTOOL_MONITOR_PDSH=$!
170 # Slightly racy, but just making a best-effort to catch obvious
173 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
174 error "Failed to start copytool monitor on $agent"
176 do_node $agent "$cmd"
178 error "Failed to start copytool monitor on $agent"
183 copytool_monitor_cleanup() {
184 local facet=${1:-$SINGLEAGT}
185 local agent=$(facet_active_host $facet)
187 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
188 # Should die when the copytool dies, but just in case.
189 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
190 cmd+=" 2>/dev/null || true"
191 do_node $agent "$cmd"
192 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
193 export HSMTOOL_MONITOR_DIR=
196 # The pdsh should die on its own when the monitor dies. Just
197 # in case, though, try to clean up to avoid any cruft.
198 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
199 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
200 export HSMTOOL_MONITOR_PDSH=
205 local facet=${1:-$SINGLEAGT}
206 local lustre_mntpnt=${2:-$MOUNT}
208 local hsm_root=${4:-$(copytool_device $facet)}
209 local agent=$(facet_active_host $facet)
211 if [[ -z "$arc_id" ]] &&
212 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
213 echo "Only wakeup running copytool $facet on $agent"
217 if $HSM_ARCHIVE_PURGE; then
218 echo "Purging archive on $agent"
219 do_facet $facet "rm -rf $hsm_root/*"
222 echo "Starting copytool $facet on $agent"
223 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
224 # bandwidth is limited to 1MB/s so the copy time is known and
225 # independent of hardware
226 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
227 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
228 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
229 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
230 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
231 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
232 cmd+=" --bandwidth 1 $lustre_mntpnt"
234 # Redirect the standard output and error to a log file which
235 # can be uploaded to Maloo.
236 local prefix=$TESTLOG_PREFIX
237 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
238 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
240 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
241 if [[ $? != 0 ]]; then
242 [[ $HSMTOOL_NOERROR == true ]] ||
243 error "start copytool $facet on $agent failed"
244 echo "start copytool $facet on $agent failed"
250 get_copytool_event_log() {
251 local facet=${1:-$SINGLEAGT}
252 local agent=$(facet_active_host $facet)
254 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
255 error "Can't get event log: No monitor directory!"
257 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
258 error "Could not collect event log from $agent"
263 local facet=$SINGLEAGT
264 local agents=${1:-$(facet_active_host $facet)}
269 local hsm_root=$(copytool_device $facet)
270 local end_wait=$(( SECONDS + TIMEOUT ))
272 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
274 while (( SECONDS < end_wait )); do
276 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
277 if [ $? -ne 0 ]; then
278 echo "Copytool is stopped on $agents"
281 echo "Copytool still running on $agents"
283 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
284 error "Copytool failed to stop in ${TIMEOUT}s ..."
286 echo "Copytool has stopped in " \
287 "$((TIMEOUT - (end_wait - SECONDS)))s."
290 # clean all CDTs orphans requests from previous tests
291 # that would otherwise need to timeout to clear.
292 for mdtno in $(seq 1 $MDSCOUNT); do
294 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
295 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
297 # skip already stop[ed,ing] CDTs
298 echo $oldstate | grep stop && continue
300 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
301 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
303 error "mds${mdtno} cdt state is not stopped"
304 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
305 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
307 error "mds${mdtno} cdt state is not $oldstate"
309 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
310 do_facet $facet "rm -rf $hsm_root/*"
315 local agents=${1:-$(facet_active_host $SINGLEAGT)}
317 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
318 echo "Copytool is suspended on $agents"
321 copytool_remove_backend() {
323 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
324 echo "Remove from backend: $fid = $be"
325 do_facet $SINGLEAGT rm -f $be
329 do_facet $SINGLEAGT \
330 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
331 --import $1 $2 $MOUNT" ||
332 error "import of $1 to $2 failed"
336 local file=$HSM_ARCHIVE/$1
337 do_facet $SINGLEAGT mkdir -p $(dirname $file)
338 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
339 error "cannot create $file"
343 local file=$HSM_ARCHIVE/$2
344 do_facet $SINGLEAGT mkdir -p $(dirname $file)
345 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
354 if [[ "$value" != "" ]]; then
357 for mdtno in $(seq 1 $MDSCOUNT); do
358 local idx=$(($mdtno - 1))
359 local facet=mds${mdtno}
360 # if $arg include -P option, run 1 set_param per MDT on the MGS
361 # else, run set_param on each MDT
362 [[ $arg = *"-P"* ]] && facet=mgs
363 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
364 [[ $? != 0 ]] && rc=1
374 for mdtno in $(seq 1 $MDSCOUNT); do
375 local idx=$(($mdtno - 1))
376 wait_result mds${mdtno} \
377 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
379 error "$key state is not '$target' on mds${mdtno}"
386 for mdtno in $(seq 1 $MDSCOUNT); do
387 local idx=$(($mdtno - 1))
388 local cl_user=$(do_facet mds${mdtno} $LCTL \
389 --device ${MDT[$idx]} \
390 changelog_register -n)
392 do_facet mds${mdtno} lctl set_param \
393 mdd.${MDT[$idx]}.changelog_mask="+hsm"
394 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
398 changelog_cleanup() {
400 for mdtno in $(seq 1 $MDSCOUNT); do
401 local idx=$(($mdtno - 1))
402 [[ -z ${CL_USERS[$idx]} ]] && continue
403 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
404 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
405 changelog_deregister ${CL_USERS[$idx]}
410 changelog_get_flags() {
415 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
420 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
428 mdts_set_param "$opt -n" "hsm.$param" "$value"
435 mdts_set_param "" hsm_control "$cmd"
436 mdts_check_param hsm_control "$target" 10
439 cdt_set_sanity_policy() {
440 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
443 mdts_set_param "" hsm.policy "+NRA"
444 mdts_set_param "" hsm.policy "-NBR"
445 CDT_POLICY_HAD_CHANGED=
450 mdts_set_param "" hsm.policy "+NRA"
451 CDT_POLICY_HAD_CHANGED=true
454 cdt_clear_no_retry() {
455 mdts_set_param "" hsm.policy "-NRA"
456 CDT_POLICY_HAD_CHANGED=true
459 cdt_set_non_blocking_restore() {
460 mdts_set_param "" hsm.policy "+NBR"
461 CDT_POLICY_HAD_CHANGED=true
464 cdt_clear_non_blocking_restore() {
465 mdts_set_param "" hsm.policy "-NBR"
466 CDT_POLICY_HAD_CHANGED=true
469 cdt_clear_mount_state() {
470 mdts_set_param "-P -d" hsm_control ""
473 cdt_set_mount_state() {
474 mdts_set_param "-P" hsm_control "$1"
478 mdts_check_param hsm_control "$1" 20
482 set_test_state disabled disabled
486 set_test_state enabled enabled
490 set_test_state shutdown stopped
494 set_test_state purge enabled
500 cdt_set_sanity_policy
504 local client_count=$1
505 if [[ $CLIENTCOUNT -lt $client_count ]]; then
506 skip "Need $client_count or more clients, have $CLIENTCOUNT"
513 $LFS path2fid $1 | tr -d '[]'
520 if [[ $u == "user" ]]; then
521 local st=$($RUNAS $LFS hsm_state $f)
523 local st=$($LFS hsm_state $f)
527 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
529 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
533 get_hsm_archive_id() {
535 local st=$($LFS hsm_state $f)
536 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
538 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
547 local st=$(get_hsm_flags $f)
548 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
551 check_hsm_flags_user() {
555 local st=$(get_hsm_flags $f user)
556 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
568 if [[ "$3" != 1 ]]; then
572 cp $1 $f || error "cannot copy $1 to $f"
573 path2fid $f || error "cannot get fid on $f"
577 local file2=${1/$DIR/$DIR2}
578 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
579 error "cannot create $file2"
580 path2fid $1 || error "cannot get fid on $1"
584 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
585 error "cannot create $1"
586 path2fid $1 || error "cannot get fid on $1"
589 cleanup_large_files() {
590 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
592 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
595 check_enough_free_space() {
598 local need=$((nb * unit /1024))
599 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
600 (( $need >= $free )) && return 1
604 make_large_for_striping() {
605 local file2=${1/$DIR/$DIR2}
606 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
610 check_enough_free_space 5 $sz
611 [ $? != 0 ] && return $?
613 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
614 error "cannot create $file2"
615 path2fid $1 || error "cannot get fid on $1"
618 make_large_for_progress() {
619 local file2=${1/$DIR/$DIR2}
623 check_enough_free_space 39 1000000
624 [ $? != 0 ] && return $?
626 # big file is large enough, so copy time is > 30s
627 # so copytool make 1 progress
628 # size is not a multiple of 1M to avoid stripe
630 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
631 error "cannot create $file2"
632 path2fid $1 || error "cannot get fid on $1"
635 make_large_for_progress_aligned() {
636 local file2=${1/$DIR/$DIR2}
640 check_enough_free_space 33 1048576
641 [ $? != 0 ] && return $?
643 # big file is large enough, so copy time is > 30s
644 # so copytool make 1 progress
645 # size is a multiple of 1M to have stripe
647 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
648 error "cannot create $file2"
649 path2fid $1 || error "cannot get fid on $1"
652 make_large_for_cancel() {
653 local file2=${1/$DIR/$DIR2}
657 check_enough_free_space 103 1048576
658 [ $? != 0 ] && return $?
660 # Copy timeout is 100s. 105MB => 105s
661 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
662 error "cannot create $file2"
663 path2fid $1 || error "cannot get fid on $1"
669 wait_update --verbose $(facet_active_host $facet) "$@"
672 wait_request_state() {
676 # 4th arg (mdt index) is optional
678 local mds=mds$(($mdtidx + 1))
680 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
681 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
683 wait_result $mds "$cmd" $state 100 ||
684 error "request on $fid is not $state on $mds"
687 get_request_state() {
691 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
692 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
695 get_request_count() {
699 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
700 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
707 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
708 [[ -n $fid ]] && cmd+=" | grep '$fid'"
709 cmd+=" | egrep 'WAITING|STARTED'"
711 wait_result $SINGLEMDS "$cmd" "" $timeout ||
712 error "requests did not complete"
715 wait_for_grace_delay() {
716 local val=$(get_hsm_param grace_delay)
723 # python2.6 in EL6 includes an internal json module
724 local json_parser='import json; import fileinput;'
725 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
726 json_parser+='json.loads([line for line in '
727 json_parser+='fileinput.input()][0]).items()])'
729 echo $raw_event | python -c "$json_parser"
732 # populate MDT device array
738 # cleanup from previous bad setup
739 search_and_kill_copytool
741 # for recovery tests, coordinator needs to be started at mount
743 # the lustre conf must be without hsm on (like for sanity.sh)
744 echo "Set HSM on and start"
745 cdt_set_mount_state enabled
746 cdt_check_state enabled
748 echo "Start copytool"
751 echo "Set sanity-hsm HSM policy"
752 cdt_set_sanity_policy
754 # finished requests are quickly removed from list
755 set_hsm_param grace_delay 10
761 local f=$DIR/$tdir/$tfile
765 check_hsm_flags_user $f "0x00000000"
767 $RUNAS $LFS hsm_set --norelease $f ||
768 error "user could not change hsm flags"
769 check_hsm_flags_user $f "0x00000010"
771 $RUNAS $LFS hsm_clear --norelease $f ||
772 error "user could not clear hsm flags"
773 check_hsm_flags_user $f "0x00000000"
775 # User could not change those flags...
776 $RUNAS $LFS hsm_set --exists $f &&
777 error "user should not set this flag"
778 check_hsm_flags_user $f "0x00000000"
781 $LFS hsm_set --exists $f ||
782 error "root could not change hsm flags"
783 check_hsm_flags_user $f "0x00000001"
785 $LFS hsm_clear --exists $f ||
786 error "root could not clear hsm state"
787 check_hsm_flags_user $f "0x00000000"
790 run_test 1 "lfs hsm flags root/non-root access"
794 local f=$DIR/$tdir/$tfile
796 # New files are not dirty
797 check_hsm_flags $f "0x00000000"
799 # For test, we simulate an archived file.
800 $LFS hsm_set --exists $f || error "user could not change hsm flags"
801 check_hsm_flags $f "0x00000001"
803 # chmod do not put the file dirty
804 chmod 600 $f || error "could not chmod test file"
805 check_hsm_flags $f "0x00000001"
807 # chown do not put the file dirty
808 chown $RUNAS_ID $f || error "could not chown test file"
809 check_hsm_flags $f "0x00000001"
811 # truncate put the file dirty
812 $TRUNCATE $f 1 || error "could not truncate test file"
813 check_hsm_flags $f "0x00000003"
815 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
816 check_hsm_flags $f "0x00000001"
818 run_test 2 "Check file dirtyness when doing setattr"
824 # New files are not dirty
826 check_hsm_flags $f "0x00000000"
828 # For test, we simulate an archived file.
829 $LFS hsm_set --exists $f ||
830 error "user could not change hsm flags"
831 check_hsm_flags $f "0x00000001"
833 # Reading a file, does not set dirty
834 cat $f > /dev/null || error "could not read file"
835 check_hsm_flags $f "0x00000001"
837 # Open for write without modifying data, does not set dirty
838 openfile -f O_WRONLY $f || error "could not open test file"
839 check_hsm_flags $f "0x00000001"
841 # Append to a file sets it dirty
842 cp -p /etc/passwd $f.append || error "could not create file"
843 $LFS hsm_set --exists $f.append ||
844 error "user could not change hsm flags"
845 dd if=/etc/passwd of=$f.append bs=1 count=3\
846 conv=notrunc oflag=append status=noxfer ||
847 error "could not append to test file"
848 check_hsm_flags $f.append "0x00000003"
850 # Modify a file sets it dirty
851 cp -p /etc/passwd $f.modify || error "could not create file"
852 $LFS hsm_set --exists $f.modify ||
853 error "user could not change hsm flags"
854 dd if=/dev/zero of=$f.modify bs=1 count=3\
855 conv=notrunc status=noxfer ||
856 error "could not modify test file"
857 check_hsm_flags $f.modify "0x00000003"
859 # Open O_TRUNC sets dirty
860 cp -p /etc/passwd $f.trunc || error "could not create file"
861 $LFS hsm_set --exists $f.trunc ||
862 error "user could not change hsm flags"
863 cp /etc/group $f.trunc || error "could not override a file"
864 check_hsm_flags $f.trunc "0x00000003"
866 # Mmapped a file sets dirty
867 cp -p /etc/passwd $f.mmap || error "could not create file"
868 $LFS hsm_set --exists $f.mmap ||
869 error "user could not change hsm flags"
870 multiop $f.mmap OSMWUc || error "could not mmap a file"
871 check_hsm_flags $f.mmap "0x00000003"
873 run_test 3 "Check file dirtyness when opening for write"
877 local f=$DIR/$tdir/$tfile
878 local fid=$(make_small $f)
881 local st=$(get_request_state $fid CANCEL)
882 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
884 run_test 4 "Useless cancel must not be registered"
887 # test needs a running copytool
891 local f=$DIR/$tdir/$tfile
892 local fid=$(copy_file /etc/passwd $f)
894 wait_request_state $fid ARCHIVE SUCCEED
896 check_hsm_flags $f "0x00000009"
900 run_test 8 "Test default archive number"
904 local f=$DIR/$tdir/$tfile
905 local fid=$(copy_file /etc/passwd $f)
906 # we do not use the default one to be sure
907 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
909 copytool_setup $SINGLEAGT $MOUNT $new_an
910 $LFS hsm_archive --archive $new_an $f
911 wait_request_state $fid ARCHIVE SUCCEED
913 check_hsm_flags $f "0x00000009"
917 run_test 9 "Use of explict archive number, with dedicated copytool"
920 needclients 3 || return 0
926 copytool_cleanup $(comma_list $(agts_nodes))
928 # start all of the copytools
929 for n in $(seq $AGTCOUNT); do
933 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
936 for n in $(seq $AGTCOUNT); do
937 file=$DIR/$tdir/$tfile.$n
938 fid=$(make_small $file)
940 $LFS hsm_archive $file || error "could not archive file $file"
941 wait_request_state $fid ARCHIVE SUCCEED
942 check_hsm_flags $file "0x00000009"
946 copytool_cleanup $(comma_list $(agts_nodes))
948 run_test 9a "Multiple remote agents"
951 # test needs a running copytool
954 mkdir -p $DIR/$tdir/d1
955 local f=$DIR/$tdir/$tfile
956 local fid=$(copy_file /etc/hosts $f)
957 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
958 error "hsm_archive failed"
959 wait_request_state $fid ARCHIVE SUCCEED
961 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
962 error "fid $fid not in archive $HSM_ARCHIVE"
963 echo "Verifying content"
964 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
965 echo "Verifying hsm state "
966 check_hsm_flags $f "0x00000009"
968 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
969 local st=$(get_hsm_archive_id $f)
970 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
971 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
976 run_test 10a "Archive a file"
979 # test needs a running copytool
983 local f=$DIR/$tdir/$tfile
984 local fid=$(copy_file /etc/hosts $f)
985 $LFS hsm_archive $f || error "archive request failed"
986 wait_request_state $fid ARCHIVE SUCCEED
988 $LFS hsm_archive $f || error "archive of non dirty file failed"
989 local cnt=$(get_request_count $fid ARCHIVE)
990 [[ "$cnt" == "1" ]] ||
991 error "archive of non dirty file must not make a request"
995 run_test 10b "Archive of non dirty file must work without doing request"
998 # test needs a running copytool
1002 local f=$DIR/$tdir/$tfile
1003 local fid=$(copy_file /etc/hosts $f)
1004 $LFS hsm_set --noarchive $f
1005 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1009 run_test 10c "Check forbidden archive"
1012 # test needs a running copytool
1016 local f=$DIR/$tdir/$tfile
1017 local fid=$(copy_file /etc/hosts $f)
1018 $LFS hsm_archive $f || error "cannot archive $f"
1019 wait_request_state $fid ARCHIVE SUCCEED
1021 local ar=$(get_hsm_archive_id $f)
1022 local dflt=$(get_hsm_param default_archive_id)
1023 [[ $ar == $dflt ]] ||
1024 error "archived file is not on default archive: $ar != $dflt"
1028 run_test 10d "Archive a file on the default archive id"
1032 copy2archive /etc/hosts $tdir/$tfile
1033 local f=$DIR/$tdir/$tfile
1035 import_file $tdir/$tfile $f
1036 echo -n "Verifying released state: "
1037 check_hsm_flags $f "0x0000000d"
1039 local LSZ=$(stat -c "%s" $f)
1040 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1042 echo "Verifying imported size $LSZ=$ASZ"
1043 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1044 echo -n "Verifying released pattern: "
1045 local PTRN=$($GETSTRIPE -L $f)
1047 [[ $PTRN == 80000001 ]] || error "Is not released"
1048 local fid=$(path2fid $f)
1049 echo "Verifying new fid $fid in archive"
1051 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1052 error "fid $fid not in archive $HSM_ARCHIVE"
1054 run_test 11a "Import a file"
1057 # test needs a running copytool
1061 local f=$DIR/$tdir/$tfile
1062 local fid=$(copy_file /etc/hosts $f)
1063 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1064 error "hsm_archive failed"
1065 wait_request_state $fid ARCHIVE SUCCEED
1067 local FILE_HASH=$(md5sum $f)
1072 echo "$FILE_HASH" | md5sum -c
1074 [[ $? -eq 0 ]] || error "Restored file differs"
1078 run_test 11b "Import a deleted file using its FID"
1081 # test needs a running copytool
1085 copy2archive /etc/hosts $tdir/$tfile
1087 local f=$DIR/$tdir/$tfile
1088 import_file $tdir/$tfile $f
1089 local f2=$DIR2/$tdir/$tfile
1090 echo "Verifying released state: "
1091 check_hsm_flags $f2 "0x0000000d"
1093 local fid=$(path2fid $f2)
1094 $LFS hsm_restore $f2
1095 wait_request_state $fid RESTORE SUCCEED
1097 echo "Verifying file state: "
1098 check_hsm_flags $f2 "0x00000009"
1100 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1102 [[ $? -eq 0 ]] || error "Restored file differs"
1106 run_test 12a "Restore an imported file explicitly"
1109 # test needs a running copytool
1113 copy2archive /etc/hosts $tdir/$tfile
1115 local f=$DIR/$tdir/$tfile
1116 import_file $tdir/$tfile $f
1117 echo "Verifying released state: "
1118 check_hsm_flags $f "0x0000000d"
1120 cat $f > /dev/null || error "File read failed"
1122 echo "Verifying file state after restore: "
1123 check_hsm_flags $f "0x00000009"
1125 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1127 [[ $? -eq 0 ]] || error "Restored file differs"
1131 run_test 12b "Restore an imported file implicitly"
1134 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1136 # test needs a running copytool
1140 local f=$DIR/$tdir/$tfile
1141 $LFS setstripe -c 2 $f
1142 local fid=$(make_large_for_striping $f)
1143 [ $? != 0 ] && skip "not enough free space" && return
1145 local FILE_CRC=$(md5sum $f)
1147 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1148 wait_request_state $fid ARCHIVE SUCCEED
1149 $LFS hsm_release $f || error "release $f failed"
1151 echo "$FILE_CRC" | md5sum -c
1153 [[ $? -eq 0 ]] || error "Restored file differs"
1157 run_test 12c "Restore a file with stripe of 2"
1160 # test needs a running copytool
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/hosts $f)
1167 $LFS hsm_restore $f || error "restore of non archived file failed"
1168 local cnt=$(get_request_count $fid RESTORE)
1169 [[ "$cnt" == "0" ]] ||
1170 error "restore non archived must not make a request"
1171 $LFS hsm_archive $f ||
1172 error "archive request failed"
1173 wait_request_state $fid ARCHIVE SUCCEED
1174 $LFS hsm_restore $f ||
1175 error "restore of non released file failed"
1176 local cnt=$(get_request_count $fid RESTORE)
1177 [[ "$cnt" == "0" ]] ||
1178 error "restore a non dirty file must not make a request"
1182 run_test 12d "Restore of a non archived, non released file must work"\
1183 " without doing request"
1186 # test needs a running copytool
1189 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1190 local f=$DIR/$tdir/$tfile
1191 local fid=$(copy_file /etc/hosts $f)
1192 $LFS hsm_archive $f || error "archive request failed"
1193 wait_request_state $fid ARCHIVE SUCCEED
1196 cat /etc/hosts >> $f
1200 $LFS hsm_restore $f && error "restore a dirty file must fail"
1204 run_test 12e "Check forbidden restore"
1207 # test needs a running copytool
1211 local f=$DIR/$tdir/$tfile
1212 local fid=$(copy_file /etc/hosts $f)
1214 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1215 wait_request_state $fid ARCHIVE SUCCEED
1216 $LFS hsm_release $f || error "release of $f failed"
1218 wait_request_state $fid RESTORE SUCCEED
1220 echo -n "Verifying file state: "
1221 check_hsm_flags $f "0x00000009"
1223 diff -q /etc/hosts $f
1225 [[ $? -eq 0 ]] || error "Restored file differs"
1229 run_test 12f "Restore a released file explicitly"
1232 # test needs a running copytool
1236 local f=$DIR/$tdir/$tfile
1237 local fid=$(copy_file /etc/hosts $f)
1239 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1240 wait_request_state $fid ARCHIVE SUCCEED
1241 $LFS hsm_release $f || error "release of $f failed"
1243 diff -q /etc/hosts $f
1246 # we check we had a restore done
1247 wait_request_state $fid RESTORE SUCCEED
1249 [[ $st -eq 0 ]] || error "Restored file differs"
1253 run_test 12g "Restore a released file implicitly"
1256 needclients 2 || return 0
1258 # test needs a running copytool
1262 local f=$DIR/$tdir/$tfile
1263 local fid=$(copy_file /etc/hosts $f)
1265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1266 wait_request_state $fid ARCHIVE SUCCEED
1267 $LFS hsm_release $f || error "release of $f failed"
1269 do_node $CLIENT2 diff -q /etc/hosts $f
1272 # we check we had a restore done
1273 wait_request_state $fid RESTORE SUCCEED
1275 [[ $st -eq 0 ]] || error "Restored file differs"
1279 run_test 12h "Restore a released file implicitly from a second node"
1282 # test needs a running copytool
1286 local f=$DIR/$tdir/$tfile
1287 local fid=$(copy_file /etc/passwd $f)
1288 $LFS hsm_archive $f || error "archive of $f failed"
1289 wait_request_state $fid ARCHIVE SUCCEED
1291 $LFS hsm_release $f || error "release of $f failed"
1295 [[ $? -eq 0 ]] || error "Restored file differs"
1299 run_test 12m "Archive/release/implicit restore"
1302 # test needs a running copytool
1306 copy2archive /etc/hosts $tdir/$tfile
1308 local f=$DIR/$tdir/$tfile
1309 import_file $tdir/$tfile $f
1311 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1312 error "Restored file differs"
1314 $LFS hsm_release $f || error "release of $f failed"
1318 run_test 12n "Import/implicit restore/release"
1321 # test needs a running copytool
1325 local f=$DIR/$tdir/$tfile
1326 local fid=$(copy_file /etc/hosts $f)
1328 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1329 wait_request_state $fid ARCHIVE SUCCEED
1330 $LFS hsm_release $f || error "release of $f failed"
1332 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1333 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1335 # set no retry action mode
1338 diff -q /etc/hosts $f
1341 # we check we had a restore failure
1342 wait_request_state $fid RESTORE FAILED
1344 [[ $st -eq 0 ]] && error "Restore must fail"
1346 # remove no retry action mode
1349 # check file is still released
1350 check_hsm_flags $f "0x0000000d"
1352 # retry w/o failure injection
1353 do_facet $SINGLEMDS lctl set_param fail_loc=0
1355 # to be sure previous RESTORE result is gone
1357 wait_for_grace_delay
1359 diff -q /etc/hosts $f
1362 # we check we had a restore done
1363 wait_request_state $fid RESTORE SUCCEED
1365 [[ $st -eq 0 ]] || error "Restored file differs"
1369 run_test 12o "Layout-swap failure during Restore leaves file released"
1372 # test needs a running copytool
1375 local ARC_SUBDIR="import.orig"
1379 # populate directory to be imported
1380 for d in $(seq 1 10); do
1381 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1382 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1383 for f in $(seq 1 10); do
1384 CURR_FILE="$CURR_DIR/$tfile.$f"
1385 # write file-specific data
1386 do_facet $SINGLEAGT \
1387 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1388 "file=$CURR_FILE > $CURR_FILE"
1392 import_file "$ARC_SUBDIR" $DIR/$tdir
1393 # diff lustre content and origin (triggers file restoration)
1394 # there must be 10x10 identical files, and no difference
1395 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1396 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1397 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1398 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1400 [ $cnt_diff -eq 0 ] ||
1401 error "$cnt_diff imported files differ from read data"
1402 [ $cnt_ok -eq 100 ] ||
1403 error "not enough identical files ($cnt_ok != 100)"
1407 run_test 13 "Recursively import and restore a directory"
1410 # test needs a running copytool
1415 local f=$DIR/$tdir/$tfile
1416 local fid=$(make_small $f)
1417 local sum=$(md5sum $f | awk '{print $1}')
1418 $LFS hsm_archive $f || error "could not archive file"
1419 wait_request_state $fid ARCHIVE SUCCEED
1423 # create released file (simulate llapi_hsm_import call)
1425 local fid2=$(path2fid $f)
1426 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1427 $LFS hsm_release $f || error "could not release file"
1429 # rebind the archive to the newly created file
1430 echo "rebind $fid to $fid2"
1432 do_facet $SINGLEAGT \
1433 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1434 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1436 # restore file and compare md5sum
1437 local sum2=$(md5sum $f | awk '{print $1}')
1439 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1443 run_test 14 "Rebind archived file to a new fid"
1446 # test needs a running copytool
1451 local f=$DIR/$tdir/$tfile
1453 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1457 for i in $(seq 1 $count); do
1458 fids[$i]=$(make_small $f.$i)
1459 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1460 $LFS hsm_archive $f.$i || error "could not archive file"
1462 wait_all_done $(($count*60))
1466 for i in $(seq 1 $count); do
1469 local fid2=$(path2fid $f.$i)
1470 # add the rebind operation to the list
1471 echo ${fids[$i]} $fid2 >> $tmpfile
1473 # set it released (simulate llapi_hsm_import call)
1474 $LFS hsm_set --archived --exists $f.$i ||
1475 error "could not force hsm flags"
1476 $LFS hsm_release $f.$i || error "could not release file"
1478 nl=$(wc -l < $tmpfile)
1479 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1481 echo "rebind list of files"
1482 do_facet $SINGLEAGT \
1483 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1484 --rebind $tmpfile $DIR" || error "could not rebind file list"
1486 # restore files and compare md5sum
1487 for i in $(seq 1 $count); do
1488 local sum2=$(md5sum $f.$i | awk '{print $1}')
1489 [[ $sum2 == ${sums[$i]} ]] ||
1490 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1496 run_test 15 "Rebind a list of files"
1499 # test needs a running copytool
1503 # create a known size file so we can verify transfer speed
1506 dd if=/dev/zero of=$ref bs=1M count=20
1509 local f=$DIR/$tdir/$tfile
1510 local fid=$(copy_file $ref $f)
1512 local start=$(date +%s)
1514 wait_request_state $fid ARCHIVE SUCCEED
1515 local end=$(date +%s)
1516 local duration=$((end - start))
1518 [[ $duration -ge $goal ]] ||
1519 error "Transfer is too fast $duration < $goal"
1523 run_test 16 "Test CT bandwith control option"
1528 local f=$DIR/$tdir/$tfile
1529 touch $f || error "touch $f failed"
1531 # Could not release a non-archived file
1532 $LFS hsm_release $f && error "release should not succeed"
1534 # For following tests, we must test them with HS_ARCHIVED set
1535 $LFS hsm_set --exists --archived $f || error "could not add flag"
1537 # Could not release a file if no-release is set
1538 $LFS hsm_set --norelease $f || error "could not add flag"
1539 $LFS hsm_release $f && error "release should not succeed"
1540 $LFS hsm_clear --norelease $f || error "could not remove flag"
1542 # Could not release a file if lost
1543 $LFS hsm_set --lost $f || error "could not add flag"
1544 $LFS hsm_release $f && error "release should not succeed"
1545 $LFS hsm_clear --lost $f || error "could not remove flag"
1547 # Could not release a file if dirty
1548 $LFS hsm_set --dirty $f || error "could not add flag"
1549 $LFS hsm_release $f && error "release should not succeed"
1550 $LFS hsm_clear --dirty $f || error "could not remove flag"
1552 run_test 20 "Release is not permitted"
1555 # test needs a running copytool
1559 local f=$DIR/$tdir/test_release
1561 # Create a file and check its states
1562 local fid=$(make_small $f)
1563 check_hsm_flags $f "0x00000000"
1565 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1566 # used until file is flushed to disk
1567 if [ $(facet_fstype ost1) == "zfs" ]; then
1568 # this causes an OST_SYNC rpc to be sent
1569 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1570 # clear locks to reread file data
1571 cancel_lru_locks osc
1574 local orig_size=$(stat -c "%s" $f)
1575 local orig_blocks=$(stat -c "%b" $f)
1577 start_full_debug_logging
1579 $LFS hsm_archive $f || error "could not archive file"
1580 wait_request_state $fid ARCHIVE SUCCEED
1582 local blocks=$(stat -c "%b" $f)
1583 [ $blocks -eq $orig_blocks ] ||
1584 error "$f: wrong block number after archive: " \
1585 "$blocks != $orig_blocks"
1586 local size=$(stat -c "%s" $f)
1587 [ $size -eq $orig_size ] ||
1588 error "$f: wrong size after archive: $size != $orig_size"
1590 # Release and check states
1591 $LFS hsm_release $f || error "could not release file"
1592 check_hsm_flags $f "0x0000000d"
1594 blocks=$(stat -c "%b" $f)
1595 [ $blocks -gt 5 ] &&
1596 error "$f: too many blocks after release: $blocks > 5"
1597 size=$(stat -c "%s" $f)
1598 [ $size -ne $orig_size ] &&
1599 error "$f: wrong size after release: $size != $orig_size"
1601 # Check we can release an file without stripe info
1605 check_hsm_flags $f "0x00000000"
1606 $LFS hsm_archive $f || error "could not archive file"
1607 wait_request_state $fid ARCHIVE SUCCEED
1609 # Release and check states
1610 $LFS hsm_release $f || error "could not release file"
1611 check_hsm_flags $f "0x0000000d"
1613 # Release again a file that is already released is OK
1614 $LFS hsm_release $f || fail "second release should succeed"
1615 check_hsm_flags $f "0x0000000d"
1617 stop_full_debug_logging
1621 run_test 21 "Simple release tests"
1624 # test needs a running copytool
1629 local f=$DIR/$tdir/test_release
1630 local swap=$DIR/$tdir/test_swap
1632 # Create a file and check its states
1633 local fid=$(make_small $f)
1634 check_hsm_flags $f "0x00000000"
1636 $LFS hsm_archive $f || error "could not archive file"
1637 wait_request_state $fid ARCHIVE SUCCEED
1639 # Release and check states
1640 $LFS hsm_release $f || error "could not release file"
1641 check_hsm_flags $f "0x0000000d"
1644 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1649 run_test 22 "Could not swap a release file"
1652 # test needs a running copytool
1657 local f=$DIR/$tdir/test_mtime
1659 # Create a file and check its states
1660 local fid=$(make_small $f)
1661 check_hsm_flags $f "0x00000000"
1663 $LFS hsm_archive $f || error "could not archive file"
1664 wait_request_state $fid ARCHIVE SUCCEED
1666 # Set modification time in the past
1667 touch -m -a -d @978261179 $f
1669 # Release and check states
1670 $LFS hsm_release $f || error "could not release file"
1671 check_hsm_flags $f "0x0000000d"
1673 local MTIME=$(stat -c "%Y" $f)
1674 local ATIME=$(stat -c "%X" $f)
1675 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1676 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1680 run_test 23 "Release does not change a/mtime (utime)"
1683 local file=$DIR/$tdir/$tfile
1692 # test needs a running copytool
1697 fid=$(make_small $file)
1699 # Create a file and check its states
1700 check_hsm_flags $file "0x00000000"
1702 # Ensure atime is less than mtime and ctime.
1706 atime0=$(stat -c "%X" $file)
1707 mtime0=$(stat -c "%Y" $file)
1708 ctime0=$(stat -c "%Z" $file)
1710 [ $atime0 -lt $mtime0 ] ||
1711 error "atime $atime0 is not less than mtime $mtime0"
1713 [ $atime0 -lt $ctime0 ] ||
1714 error "atime $atime0 is not less than ctime $ctime0"
1716 # Archive should not change any timestamps.
1717 $LFS hsm_archive $file || error "cannot archive '$file'"
1718 wait_request_state $fid ARCHIVE SUCCEED
1720 atime1=$(stat -c "%X" $file)
1721 mtime1=$(stat -c "%Y" $file)
1722 ctime1=$(stat -c "%Z" $file)
1724 [ $atime0 -eq $atime1 ] ||
1725 error "archive changed atime from $atime0 to $atime1"
1727 [ $mtime0 -eq $mtime1 ] ||
1728 error "archive changed mtime from $mtime0 to $mtime1"
1730 [ $ctime0 -eq $ctime1 ] ||
1731 error "archive changed ctime from $ctime0 to $ctime1"
1733 # Release should not change any timestamps.
1734 $LFS hsm_release $file || error "cannot release '$file'"
1735 check_hsm_flags $file "0x0000000d"
1737 atime1=$(stat -c "%X" $file)
1738 mtime1=$(stat -c "%Y" $file)
1739 ctime1=$(stat -c "%Z" $file)
1741 [ $atime0 -eq $atime1 ] ||
1742 error "release changed atime from $atime0 to $atime1"
1744 [ $mtime0 -eq $mtime1 ] ||
1745 error "release changed mtime from $mtime0 to $mtime1"
1747 [ $ctime0 -eq $ctime1 ] ||
1748 error "release changed ctime from $ctime0 to $ctime1"
1750 # Restore should not change atime or mtime and should not
1752 $LFS hsm_restore $file
1753 wait_request_state $fid RESTORE SUCCEED
1755 atime1=$(stat -c "%X" $file)
1756 mtime1=$(stat -c "%Y" $file)
1757 ctime1=$(stat -c "%Z" $file)
1759 [ $atime0 -eq $atime1 ] ||
1760 error "restore changed atime from $atime0 to $atime1"
1762 [ $mtime0 -eq $mtime1 ] ||
1763 error "restore changed mtime from $mtime0 to $mtime1"
1765 [ $ctime0 -le $ctime1 ] ||
1766 error "restore changed ctime from $ctime0 to $ctime1"
1770 # Once more, after unmount and mount.
1771 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1772 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1774 atime1=$(stat -c "%X" $file)
1775 mtime1=$(stat -c "%Y" $file)
1776 ctime1=$(stat -c "%Z" $file)
1778 [ $atime0 -eq $atime1 ] ||
1779 error "remount changed atime from $atime0 to $atime1"
1781 [ $mtime0 -eq $mtime1 ] ||
1782 error "remount changed mtime from $mtime0 to $mtime1"
1784 [ $ctime0 -le $ctime1 ] ||
1785 error "remount changed ctime from $ctime0 to $ctime1"
1787 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1790 local file=$DIR/$tdir/$tfile
1796 # Test needs a running copytool.
1800 # Check that root can do HSM actions on a ordinary user's file.
1802 fid=$(make_small $file)
1803 sum0=$(md5sum $file)
1805 chown $RUNAS_ID:$RUNAS_GID $file ||
1806 error "cannot chown '$file' to '$RUNAS_ID'"
1808 chmod ugo-w $DIR/$tdir ||
1809 error "cannot chmod '$DIR/$tdir'"
1811 $LFS hsm_archive $file
1812 wait_request_state $fid ARCHIVE SUCCEED
1814 $LFS hsm_release $file
1815 check_hsm_flags $file "0x0000000d"
1817 $LFS hsm_restore $file
1818 wait_request_state $fid RESTORE SUCCEED
1820 # Check that ordinary user can get HSM state.
1821 $RUNAS $LFS hsm_state $file ||
1822 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1824 $LFS hsm_release $file
1825 check_hsm_flags $file "0x0000000d"
1827 # Check that ordinary user can accessed released file.
1828 sum1=$($RUNAS md5sum $file) ||
1829 error "user '$RUNAS_ID' cannot read '$file'"
1831 [ "$sum0" == "$sum1" ] ||
1832 error "md5sum mismatch for '$file'"
1836 run_test 24b "root can archive, release, and restore user files"
1838 cleanup_test_24c() {
1840 set_hsm_param user_request_mask RESTORE
1841 set_hsm_param group_request_mask RESTORE
1842 set_hsm_param other_request_mask RESTORE
1846 local file=$DIR/$tdir/$tfile
1847 local action=archive
1852 # test needs a running copytool
1857 # Save the default masks and check that cleanup_24c will
1858 # restore the request masks correctly.
1859 user_save=$(get_hsm_param user_request_mask)
1860 group_save=$(get_hsm_param group_request_mask)
1861 other_save=$(get_hsm_param other_request_mask)
1863 [ "$user_save" == RESTORE ] ||
1864 error "user_request_mask is '$user_save' expected 'RESTORE'"
1865 [ "$group_save" == RESTORE ] ||
1866 error "group_request_mask is '$group_save' expected 'RESTORE'"
1867 [ "$other_save" == RESTORE ] ||
1868 error "other_request_mask is '$other_save' expected 'RESTORE'"
1870 trap cleanup_test_24c EXIT
1875 chown $RUNAS_ID:nobody $file ||
1876 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1878 set_hsm_param user_request_mask ""
1879 $RUNAS $LFS hsm_$action $file &&
1880 error "$action by user should fail"
1882 set_hsm_param user_request_mask $action
1883 $RUNAS $LFS hsm_$action $file ||
1884 error "$action by user should succeed"
1889 chown nobody:$RUNAS_GID $file ||
1890 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1892 set_hsm_param group_request_mask ""
1893 $RUNAS $LFS hsm_$action $file &&
1894 error "$action by group should fail"
1896 set_hsm_param group_request_mask $action
1897 $RUNAS $LFS hsm_$action $file ||
1898 error "$action by group should succeed"
1903 chown nobody:nobody $file ||
1904 error "cannot chown '$file' to 'nobody:nobody'"
1906 set_hsm_param other_request_mask ""
1907 $RUNAS $LFS hsm_$action $file &&
1908 error "$action by other should fail"
1910 set_hsm_param other_request_mask $action
1911 $RUNAS $LFS hsm_$action $file ||
1912 error "$action by other should succeed"
1917 run_test 24c "check that user,group,other request masks work"
1919 cleanup_test_24d() {
1921 mount -o remount,rw $MOUNT2
1925 local file1=$DIR/$tdir/$tfile
1926 local file2=$DIR2/$tdir/$tfile
1934 fid1=$(make_small $file1)
1936 trap cleanup_test_24d EXIT
1938 mount -o remount,ro $MOUNT2
1940 fid2=$(path2fid $file2)
1941 [ "$fid1" == "$fid2" ] ||
1942 error "FID mismatch '$fid1' != '$fid2'"
1944 $LFS hsm_archive $file2 &&
1945 error "archive should fail on read-only mount"
1946 check_hsm_flags $file1 "0x00000000"
1948 $LFS hsm_archive $file1
1949 wait_request_state $fid1 ARCHIVE SUCCEED
1951 $LFS hsm_release $file1
1952 $LFS hsm_restore $file2
1953 wait_request_state $fid1 RESTORE SUCCEED
1955 $LFS hsm_release $file1 || error "cannot release '$file1'"
1956 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1958 $LFS hsm_release $file2 &&
1959 error "release should fail on read-only mount"
1964 run_test 24d "check that read-only mounts are respected"
1967 # test needs a running copytool
1971 copy2archive /etc/hosts $tdir/$tfile
1973 local f=$DIR/$tdir/$tfile
1975 import_file $tdir/$tfile $f
1977 $LFS hsm_set --lost $f
1982 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1986 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1987 " (Operation not permitted)"
1990 # test needs a running copytool
1995 local f=$DIR/$tdir/$tfile
1996 local fid=$(copy_file /etc/passwd $f)
1998 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1999 wait_request_state $fid ARCHIVE SUCCEED
2002 $LFS hsm_set --lost $f
2006 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2010 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2011 " (Operation not permitted)"
2014 # test needs a running copytool
2018 local f=$DIR/$tdir/$tfile
2019 local fid=$(make_large_for_progress $f)
2020 [ $? != 0 ] && skip "not enough free space" && return
2022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2023 wait_request_state $fid ARCHIVE SUCCEED
2026 wait_request_state $fid REMOVE SUCCEED
2028 check_hsm_flags $f "0x00000000"
2032 run_test 26 "Remove the archive of a valid file"
2035 # test needs a running copytool
2039 make_archive $tdir/$tfile
2040 local f=$DIR/$tdir/$tfile
2041 import_file $tdir/$tfile $f
2042 local fid=$(path2fid $f)
2046 [[ $? != 0 ]] || error "Remove of a released file should fail"
2050 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2053 # test needs a running copytool
2057 local f=$DIR/$tdir/$tfile
2058 local fid=$(make_large_for_progress $f)
2059 [ $? != 0 ] && skip "not enough free space" && return
2061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2062 wait_request_state $fid ARCHIVE SUCCEED
2067 [[ $? != 0 ]] || error "Remove of a released file should fail"
2071 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2074 # test needs a running copytool
2078 local f=$DIR/$tdir/$tfile
2079 local fid=$(make_large_for_progress $f)
2080 [ $? != 0 ] && skip "not enough free space" && return
2082 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2083 wait_request_state $fid ARCHIVE SUCCEED
2092 wait_request_state $fid REMOVE SUCCEED
2096 run_test 28 "Concurrent archive/file remove"
2099 # restore at exec cannot work on agent node (because of Linux kernel
2100 # protection of executables)
2101 needclients 2 || return 0
2103 # test needs a running copytool
2107 copy2archive /bin/true $tdir/$tfile
2109 local f=$DIR/$tdir/true
2110 import_file $tdir/$tfile $f
2112 local fid=$(path2fid $f)
2114 # set no retry action mode
2120 # remove no try action mode
2124 [[ $st == 0 ]] || error "Failed to exec a released file"
2128 run_test 30a "Restore at exec (import case)"
2131 # restore at exec cannot work on agent node (because of Linux kernel
2132 # protection of executables)
2133 needclients 2 || return 0
2135 # test needs a running copytool
2139 local f=$DIR/$tdir/true
2140 local fid=$(copy_file /bin/true $f)
2142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2143 wait_request_state $fid ARCHIVE SUCCEED
2146 # set no retry action mode
2152 # remove no try action mode
2156 [[ $st == 0 ]] || error "Failed to exec a released file"
2160 run_test 30b "Restore at exec (release case)"
2163 needclients 2 || return 0
2165 # test needs a running copytool
2169 local f=$DIR/$tdir/SLEEP
2170 local fid=$(copy_file /bin/sleep $f)
2172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2173 wait_request_state $fid ARCHIVE SUCCEED
2175 check_hsm_flags $f "0x0000000d"
2176 # set no retry action mode
2178 do_node $CLIENT2 "$f 10" &
2182 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2184 [[ $? == 0 ]] || error "Execution failed during run"
2186 [[ $? == 0 ]] || error "Binary overwritten during exec"
2189 # remove no try action mode
2191 check_hsm_flags $f "0x00000009"
2195 run_test 30c "Update during exec of released file must fail"
2197 restore_and_check_size() {
2200 local s=$(stat -c "%s" $f)
2202 local st=$(get_hsm_flags $f)
2206 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2208 n=$(stat -c "%s" $f)
2209 # we echo in both cases to show stat is not
2211 if [[ $n != $s ]]; then
2212 echo "size seen is $n != $s"
2215 echo "size seen is right: $n == $s"
2217 st=$(get_hsm_flags $f)
2221 if [[ $cpt -lt 10 ]]; then
2224 echo " restore is too long"
2225 wait_request_state $fid RESTORE SUCCEED
2231 # test needs a running copytool
2236 make_archive $tdir/$tfile
2237 local f=$DIR/$tdir/$tfile
2238 import_file $tdir/$tfile $f
2239 local fid=$($LFS path2fid $f)
2240 HSM_ARCHIVE_PURGE=false copytool_setup
2242 restore_and_check_size $f $fid
2245 [[ $err -eq 0 ]] || error "File size changed during restore"
2249 run_test 31a "Import a large file and check size during restore"
2253 # test needs a running copytool
2258 local f=$DIR/$tdir/$tfile
2259 local fid=$(make_large_for_progress $f)
2260 [ $? != 0 ] && skip "not enough free space" && return
2262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2263 wait_request_state $fid ARCHIVE SUCCEED
2266 restore_and_check_size $f $fid
2269 [[ $err -eq 0 ]] || error "File size changed during restore"
2273 run_test 31b "Restore a large unaligned file and check size during restore"
2276 # test needs a running copytool
2281 local f=$DIR/$tdir/$tfile
2282 local fid=$(make_large_for_progress_aligned $f)
2283 [ $? != 0 ] && skip "not enough free space" && return
2285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2286 wait_request_state $fid ARCHIVE SUCCEED
2289 restore_and_check_size $f $fid
2292 [[ $err -eq 0 ]] || error "File size changed during restore"
2296 run_test 31c "Restore a large aligned file and check size during restore"
2299 # test needs a running copytool
2304 local f=$DIR/$tdir/$tfile
2305 local fid=$(make_large_for_progress $f)
2306 [ $? != 0 ] && skip "not enough free space" && return
2308 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2309 wait_request_state $fid ARCHIVE SUCCEED
2312 # to be sure wait_all_done will not be mislead by previous tests
2315 wait_for_grace_delay
2316 # Also raise grace_delay significantly so the Canceled
2317 # Restore action will stay enough long avail.
2318 local old_grace=$(get_hsm_param grace_delay)
2319 set_hsm_param grace_delay 100
2321 md5sum $f >/dev/null &
2323 wait_request_state $fid RESTORE STARTED
2328 # Check restore trigger process was killed
2329 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2333 # instead of waiting+checking both Restore and Cancel ops
2334 # sequentially, wait for both to be finished and then check
2336 wait_all_done 100 $fid
2337 local rstate=$(get_request_state $fid RESTORE)
2338 local cstate=$(get_request_state $fid CANCEL)
2340 # restore orig grace_delay.
2341 set_hsm_param grace_delay $old_grace
2343 if [[ "$rstate" == "CANCELED" ]] ; then
2344 [[ "$cstate" == "SUCCEED" ]] ||
2345 error "Restore state is CANCELED and Cancel state " \
2346 "is not SUCCEED but $cstate"
2347 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2348 elif [[ "$rstate" == "SUCCEED" ]] ; then
2349 [[ "$cstate" == "FAILED" ]] ||
2350 error "Restore state is SUCCEED and Cancel state " \
2351 "is not FAILED but $cstate"
2352 echo "Restore state is SUCCEED, Cancel state is FAILED"
2354 error "Restore state is $rstate and Cancel state is $cstate"
2358 error "Cannot kill process waiting for restore ($killed)"
2362 run_test 33 "Kill a restore waiting process"
2365 # test needs a running copytool
2370 local f=$DIR/$tdir/$tfile
2371 local fid=$(make_large_for_progress $f)
2372 [ $? != 0 ] && skip "not enough free space" && return
2374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2375 wait_request_state $fid ARCHIVE SUCCEED
2378 md5sum $f >/dev/null &
2380 wait_request_state $fid RESTORE STARTED
2382 rm $f || error "rm $f failed"
2383 # rm must not block during restore
2384 wait_request_state $fid RESTORE STARTED
2386 wait_request_state $fid RESTORE SUCCEED
2387 # check md5sum pgm finished
2388 local there=$(ps -o pid,comm hp $pid >/dev/null)
2389 [[ -z $there ]] || error "Restore initiator does not exit"
2391 local rc=$(wait $pid)
2392 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2396 run_test 34 "Remove file during restore"
2399 # test needs a running copytool
2404 local f=$DIR/$tdir/$tfile
2405 local f1=$DIR/$tdir/$tfile-1
2406 local fid=$(make_large_for_progress $f)
2407 [ $? != 0 ] && skip "not enough free space" && return
2409 local fid1=$(copy_file /etc/passwd $f1)
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
2418 mv $f1 $f || error "mv $f1 $f failed"
2419 # mv 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)
2425 [[ -z $there ]] || error "Restore initiator does not exit"
2427 local rc=$(wait $pid)
2428 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2431 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2435 run_test 35 "Overwrite file during restore"
2438 # test needs a running copytool
2443 local f=$DIR/$tdir/$tfile
2444 local fid=$(make_large_for_progress $f)
2445 [ $? != 0 ] && skip "not enough free space" && return
2447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2448 wait_request_state $fid ARCHIVE SUCCEED
2451 md5sum $f >/dev/null &
2453 wait_request_state $fid RESTORE STARTED
2456 # rm must not block during restore
2457 wait_request_state $fid RESTORE STARTED
2459 wait_request_state $fid RESTORE SUCCEED
2460 # check md5sum pgm finished
2461 local there=$(ps -o pid,comm hp $pid >/dev/null)
2463 error "Restore initiator does not exit"
2465 local rc=$(wait $pid)
2467 error "Restore initiator failed with $rc"
2471 run_test 36 "Move file during restore"
2478 for n in $(seq 1 $count); do
2479 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2481 echo "$count archive requests submitted"
2485 local stream_count=4
2486 local file_count=100
2488 local f=$DIR/$tdir/$tfile
2493 for i in $(seq 1 $file_count); do
2494 for p in $(seq 1 $stream_count); do
2495 fid=$(copy_file /etc/hosts $f.$p.$i)
2498 # force copytool to use a local/temp archive dir to ensure best
2499 # performance vs remote/NFS mounts used in auto-tests
2500 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2503 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2505 # to be sure wait_all_done will not be mislead by previous tests
2507 wait_for_grace_delay
2509 # start archive streams in background (archive files in parallel)
2510 for p in $(seq 1 $stream_count); do
2511 multi_archive $f.$p $file_count &
2514 echo -n "Wait for all requests being enqueued..."
2520 run_test 40 "Parallel archive requests"
2523 # test needs a running copytool
2527 local f=$DIR/$tdir/$tfile
2528 local fid=$(copy_file /etc/motd $f 1)
2530 $LFS hsm_archive $f || error "could not archive file"
2531 wait_request_state $fid ARCHIVE SUCCEED
2532 check_hsm_flags $f "0x00000009"
2534 multiop_bg_pause $f O_c || error "multiop failed"
2538 client_up || client_up || true
2540 kill -USR1 $MULTIPID
2541 wait $MULTIPID || error "multiop close failed"
2543 check_hsm_flags $f "0x0000000b"
2547 run_test 52 "Opened for write file on an evicted client should be set dirty"
2550 # test needs a running copytool
2554 local f=$DIR/$tdir/$tfile
2555 local fid=$(copy_file /etc/motd $f 1)
2557 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2558 error "could not archive file"
2559 wait_request_state $fid ARCHIVE SUCCEED
2560 check_hsm_flags $f "0x00000009"
2562 multiop_bg_pause $f o_c || error "multiop failed"
2566 client_up || client_up || true
2568 kill -USR1 $MULTIPID
2569 wait $MULTIPID || error "multiop close failed"
2571 check_hsm_flags $f "0x00000009"
2575 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2578 # test needs a running copytool
2582 local f=$DIR/$tdir/$tfile
2583 local fid=$(make_small $f)
2585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2586 error "could not archive file"
2587 wait_request_state $fid ARCHIVE STARTED
2589 check_hsm_flags $f "0x00000001"
2591 # Avoid coordinator resending this request as soon it has failed.
2596 wait_request_state $fid ARCHIVE FAILED
2598 check_hsm_flags $f "0x00000003"
2603 run_test 54 "Write during an archive cancels it"
2606 # test needs a running copytool
2610 local f=$DIR/$tdir/$tfile
2611 local fid=$(make_small $f)
2613 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2614 error "could not archive file"
2615 wait_request_state $fid ARCHIVE STARTED
2617 check_hsm_flags $f "0x00000001"
2619 # Avoid coordinator resending this request as soon it has failed.
2622 $TRUNCATE $f 1024 || error "truncate failed"
2624 wait_request_state $fid ARCHIVE FAILED
2626 check_hsm_flags $f "0x00000003"
2631 run_test 55 "Truncate during an archive cancels it"
2634 # test needs a running copytool
2638 local f=$DIR/$tdir/$tfile
2639 local fid=$(make_large_for_progress $f)
2640 [ $? != 0 ] && skip "not enough free space" && return
2642 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2643 error "could not archive file"
2644 wait_request_state $fid ARCHIVE STARTED
2646 check_hsm_flags $f "0x00000001"
2648 # Change metadata and sync to be sure we are not changing only
2653 wait_request_state $fid ARCHIVE SUCCEED
2655 check_hsm_flags $f "0x00000009"
2659 run_test 56 "Setattr during an archive is ok"
2662 # Need one client for I/O, one for request
2663 needclients 2 || return 0
2665 # test needs a running copytool
2669 local f=$DIR/$tdir/test_archive_remote
2670 # Create a file on a remote node
2671 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2672 "count=2 conv=fsync"
2675 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2676 error "hsm_archive failed"
2677 local fid=$(path2fid $f)
2678 wait_request_state $fid ARCHIVE SUCCEED
2680 # Release and implicit restore it
2681 do_node $CLIENT2 "$LFS hsm_release $f" ||
2682 error "hsm_release failed"
2683 do_node $CLIENT2 "md5sum $f" ||
2684 error "hsm_restore failed"
2686 wait_request_state $fid RESTORE SUCCEED
2690 run_test 57 "Archive a file with dirty cache on another node"
2692 truncate_released_file() {
2696 local sz=$(stat -c %s $src_file)
2697 local f=$DIR/$tdir/$tfile
2698 local fid=$(copy_file $1 $f)
2702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2703 error "could not archive file"
2704 wait_request_state $fid ARCHIVE SUCCEED
2706 $LFS hsm_release $f || error "could not release file"
2708 $TRUNCATE $f $trunc_to || error "truncate failed"
2711 local sz1=$(stat -c %s $f)
2712 [[ $sz1 == $trunc_to ]] ||
2713 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2716 check_hsm_flags $f "0x0000000b"
2718 local state=$(get_request_state $fid RESTORE)
2719 [[ "$state" == "SUCCEED" ]] ||
2720 error "truncate $sz does not trig restore, state = $state"
2722 $TRUNCATE $ref $trunc_to
2723 cmp $ref $f || error "file data wrong after truncate"
2729 # test needs a running copytool
2734 local sz=$(stat -c %s /etc/passwd)
2736 echo "truncate up from $sz to $((sz*2))"
2737 truncate_released_file /etc/passwd $((sz*2))
2739 echo "truncate down from $sz to $((sz/2))"
2740 truncate_released_file /etc/passwd $((sz/2))
2742 echo "truncate to 0"
2743 truncate_released_file /etc/passwd 0
2747 run_test 58 "Truncate a released file will trigger restore"
2750 # This test validates the fix for LU-4512. Ensure that the -u
2751 # option changes the progress reporting interval from the
2752 # default (30 seconds) to the user-specified interval.
2754 local progress_timeout=$((interval * 4))
2756 # test needs a new running copytool
2758 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2761 local f=$DIR/$tdir/$tfile
2762 local fid=$(make_large_for_progress $f)
2763 [ $? != 0 ] && skip "not enough free space" && return
2766 local mdt=${MDT_PREFIX}${mdtidx}
2767 local mds=mds$((mdtidx + 1))
2769 # Wait for copytool to register
2770 wait_update_facet $mds \
2771 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2772 uuid 100 || error "coyptool failed to register with $mdt"
2774 local start_at=$(date +%s)
2775 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2776 error "could not archive file"
2778 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2779 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2785 echo -n "Expecting a progress update within $progress_timeout seconds... "
2787 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2788 if [ $RESULT -gt 0 ]; then
2789 echo "$RESULT bytes copied in $WAIT seconds."
2791 elif [ $WAIT -ge $progress_timeout ]; then
2792 error "Timed out waiting for progress update!"
2795 WAIT=$((WAIT + sleep))
2799 local finish_at=$(date +%s)
2800 local elapsed=$((finish_at - start_at))
2802 # Ensure that the progress update occurred within the expected window.
2803 if [ $elapsed -lt $interval ]; then
2804 error "Expected progress update after at least $interval seconds"
2810 run_test 60 "Changing progress update interval from default"
2813 # test needs a new running copytool
2815 copytool_monitor_setup
2816 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2818 # Just start and stop the copytool to generate events.
2821 # Wait for the copytool to register.
2822 wait_update --verbose $(facet_active_host mds1) \
2823 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2825 error "copytool failed to register with MDT0000"
2829 local REGISTER_EVENT
2830 local UNREGISTER_EVENT
2831 while read event; do
2832 local parsed=$(parse_json_event "$event")
2833 if [ -z "$parsed" ]; then
2834 error "Copytool sent malformed event: $event"
2838 if [ $event_type == "REGISTER" ]; then
2839 REGISTER_EVENT=$event
2840 elif [ $event_type == "UNREGISTER" ]; then
2841 UNREGISTER_EVENT=$event
2843 done < <(echo $"$(get_copytool_event_log)")
2845 if [ -z "$REGISTER_EVENT" ]; then
2846 error "Copytool failed to send register event to FIFO"
2849 if [ -z "$UNREGISTER_EVENT" ]; then
2850 error "Copytool failed to send unregister event to FIFO"
2853 copytool_monitor_cleanup
2854 echo "Register/Unregister events look OK."
2856 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2859 # Bump progress interval for livelier events.
2862 # test needs a new running copytool
2864 copytool_monitor_setup
2865 HSMTOOL_UPDATE_INTERVAL=$interval \
2866 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2869 local f=$DIR/$tdir/$tfile
2870 local fid=$(make_large_for_progress $f)
2871 [ $? != 0 ] && skip "not enough free space" && return
2873 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2874 error "could not archive file"
2875 wait_request_state $fid ARCHIVE SUCCEED
2877 local expected_fields="event_time data_fid source_fid"
2878 expected_fields+=" total_bytes current_bytes"
2882 while read event; do
2883 # Make sure we're not getting anything from previous events.
2884 for field in $expected_fields; do
2888 local parsed=$(parse_json_event "$event")
2889 if [ -z "$parsed" ]; then
2890 error "Copytool sent malformed event: $event"
2894 if [ $event_type == "ARCHIVE_START" ]; then
2897 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2900 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2904 # Do some simple checking of the progress update events.
2905 for expected_field in $expected_fields; do
2906 if [ -z ${!expected_field+x} ]; then
2907 error "Missing $expected_field field in event"
2911 if [ $total_bytes -eq 0 ]; then
2912 error "Expected total_bytes to be > 0"
2915 # These should be identical throughout an archive
2917 if [ $source_fid != $data_fid ]; then
2918 error "Expected source_fid to equal data_fid"
2920 done < <(echo $"$(get_copytool_event_log)")
2922 if [ -z "$START_EVENT" ]; then
2923 error "Copytool failed to send archive start event to FIFO"
2926 if [ -z "$FINISH_EVENT" ]; then
2927 error "Copytool failed to send archive finish event to FIFO"
2930 echo "Archive events look OK."
2934 copytool_monitor_cleanup
2936 run_test 71 "Copytool logs JSON archive events to FIFO"
2939 # Bump progress interval for livelier events.
2942 # test needs a new running copytool
2944 copytool_monitor_setup
2945 HSMTOOL_UPDATE_INTERVAL=$interval \
2946 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2947 local test_file=$HSMTOOL_MONITOR_DIR/file
2949 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2951 do_facet $SINGLEAGT "$cmd" ||
2952 error "cannot create $test_file on $SINGLEAGT"
2953 copy2archive $test_file $tdir/$tfile
2956 local f=$DIR/$tdir/$tfile
2957 import_file $tdir/$tfile $f
2958 f=$DIR2/$tdir/$tfile
2959 echo "Verifying released state: "
2960 check_hsm_flags $f "0x0000000d"
2962 local fid=$(path2fid $f)
2964 wait_request_state $fid RESTORE SUCCEED
2966 local expected_fields="event_time data_fid source_fid"
2967 expected_fields+=" total_bytes current_bytes"
2971 while read event; do
2972 # Make sure we're not getting anything from previous events.
2973 for field in $expected_fields; do
2977 local parsed=$(parse_json_event "$event")
2978 if [ -z "$parsed" ]; then
2979 error "Copytool sent malformed event: $event"
2983 if [ $event_type == "RESTORE_START" ]; then
2985 if [ $source_fid != $data_fid ]; then
2986 error "source_fid should == data_fid at start"
2989 elif [ $event_type == "RESTORE_FINISH" ]; then
2991 if [ $source_fid != $data_fid ]; then
2992 error "source_fid should == data_fid at finish"
2995 elif [ $event_type != "RESTORE_RUNNING" ]; then
2999 # Do some simple checking of the progress update events.
3000 for expected_field in $expected_fields; do
3001 if [ -z ${!expected_field+x} ]; then
3002 error "Missing $expected_field field in event"
3006 if [ $total_bytes -eq 0 ]; then
3007 error "Expected total_bytes to be > 0"
3010 # When a restore starts out, the data fid is the same as the
3011 # source fid. After the restore has gotten going, we learn
3012 # the new data fid. Once the restore has finished, the source
3013 # fid is set to the new data fid.
3015 # We test this because some monitoring software may depend on
3016 # this behavior. If it changes, then the consumers of these
3017 # events may need to be modified.
3018 if [ $source_fid == $data_fid ]; then
3019 error "source_fid should != data_fid during restore"
3021 done < <(echo $"$(get_copytool_event_log)")
3023 if [ -z "$START_EVENT" ]; then
3024 error "Copytool failed to send restore start event to FIFO"
3027 if [ -z "$FINISH_EVENT" ]; then
3028 error "Copytool failed to send restore finish event to FIFO"
3031 echo "Restore events look OK."
3035 copytool_monitor_cleanup
3039 run_test 72 "Copytool logs JSON restore events to FIFO"
3042 file_count=51 # Max number of files constrained by LNET message size
3043 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3044 local f=$DIR/$tdir/$tfile
3045 local FILELIST=/tmp/filelist.txt
3049 for i in $(seq 1 $file_count); do
3050 fid=$(copy_file /etc/hosts $f.$i)
3051 echo $f.$i >> $FILELIST
3053 # force copytool to use a local/temp archive dir to ensure best
3054 # performance vs remote/NFS mounts used in auto-tests
3055 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3058 local dai=$(get_hsm_param default_archive_id)
3059 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3061 # to be sure wait_all_done will not be mislead by previous tests
3063 wait_for_grace_delay
3064 $LFS hsm_archive --filelist $FILELIST ||
3065 error "cannot archive a file list"
3067 $LFS hsm_release --filelist $FILELIST ||
3068 error "cannot release a file list"
3069 $LFS hsm_restore --filelist $FILELIST ||
3070 error "cannot restore a file list"
3074 run_test 90 "Archive/restore a file list"
3076 double_verify_reset_hsm_param() {
3078 echo "Testing $HSM_PARAM.$p"
3079 local val=$(get_hsm_param $p)
3081 local val2=$(($val * 2))
3082 set_hsm_param $p $val2
3083 val=$(get_hsm_param $p)
3084 [[ $val == $val2 ]] ||
3085 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3086 echo "Set $p to 0 must failed"
3090 set_hsm_param $p $save
3092 if [[ $rc == 0 ]]; then
3093 error "we must not be able to set $HSM_PARAM.$p to 0"
3098 double_verify_reset_hsm_param loop_period
3099 double_verify_reset_hsm_param grace_delay
3100 double_verify_reset_hsm_param active_request_timeout
3101 double_verify_reset_hsm_param max_requests
3102 double_verify_reset_hsm_param default_archive_id
3104 run_test 100 "Set coordinator /proc tunables"
3111 run_test 102 "Verify coordinator control"
3114 # test needs a running copytool
3121 for i in $(seq 1 20); do
3122 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3124 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3128 echo "Current requests"
3129 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3130 $HSM_PARAM.actions |\
3131 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3133 [[ -z "$res" ]] || error "Some request have not been canceled"
3137 run_test 103 "Purge all requests"
3142 # test needs a running copytool
3146 local f=$DIR/$tdir/$tfile
3147 local fid=$(make_large_for_progress $f)
3148 [ $? != 0 ] && skip "not enough free space" && return
3150 # if cdt is on, it can serve too quickly the request
3152 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3153 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3154 $HSM_PARAM.actions |\
3155 grep $fid | cut -f16 -d=")
3158 [[ "$data1" == "$DATAHEX" ]] ||
3159 error "Data field in records is ($data1) and not ($DATAHEX)"
3163 run_test 104 "Copy tool data field"
3170 for i in $(seq -w 1 10); do
3171 cp /etc/passwd $DIR/$tdir/$i
3172 $LFS hsm_archive $DIR/$tdir/$i
3174 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3175 $HSM_PARAM.actions |\
3176 grep WAITING | wc -l")
3179 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3180 $HSM_PARAM.actions |\
3181 grep WAITING | wc -l")
3184 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3185 error "Requests count after shutdown $reqcnt2 != "\
3186 "before shutdown $reqcnt1"
3188 run_test 105 "Restart of coordinator"
3190 get_agent_by_uuid_mdt() {
3193 local mds=mds$(($mdtidx + 1))
3194 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3198 check_agent_registered_by_mdt() {
3201 local mds=mds$(($mdtidx + 1))
3202 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3203 if [[ ! -z "$agent" ]]; then
3204 echo "found agent $agent on $mds"
3206 error "uuid $uuid not found in agent list on $mds"
3210 check_agent_unregistered_by_mdt() {
3213 local mds=mds$(($mdtidx + 1))
3214 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3215 if [[ -z "$agent" ]]; then
3216 echo "uuid not found in agent list on $mds"
3218 error "uuid found in agent list on $mds: $agent"
3222 check_agent_registered() {
3225 for mdsno in $(seq 1 $MDSCOUNT); do
3226 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3230 check_agent_unregistered() {
3233 for mdsno in $(seq 1 $MDSCOUNT); do
3234 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3239 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3240 get_client_uuid $MOUNT | cut -d' ' -f2)
3243 check_agent_registered $uuid
3245 search_copytools || error "No copytool found"
3248 check_agent_unregistered $uuid
3251 check_agent_registered $uuid
3255 run_test 106 "Copytool register/unregister"
3258 # test needs a running copytool
3260 # create and archive file
3262 local f1=$DIR/$tdir/$tfile
3263 local fid=$(copy_file /etc/passwd $f1)
3264 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3265 wait_request_state $fid ARCHIVE SUCCEED
3266 # shutdown and restart MDS
3268 # check the copytool still gets messages from MDT
3269 local f2=$DIR/$tdir/2
3270 local fid=$(copy_file /etc/passwd $f2)
3271 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3272 # main check of this sanity: this request MUST succeed
3273 wait_request_state $fid ARCHIVE SUCCEED
3276 run_test 107 "Copytool re-register after MDS restart"
3278 policy_set_and_test()
3282 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3283 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3284 [[ "$policy" == "$target" ]] ||
3285 error "Wrong policy after '$change': '$policy' != '$target'"
3289 # to force default policy setting if error
3290 CDT_POLICY_HAD_CHANGED=true
3292 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3293 local default="NonBlockingRestore [NoRetryAction]"
3294 [[ "$policy" == "$default" ]] ||
3295 error "default policy has changed,"\
3296 " '$policy' != '$default' update the test"
3297 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3298 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3299 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3300 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3301 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3302 # useless bacause we know but safer for futur changes to use real value
3303 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3304 echo "Next set_param must failed"
3305 policy_set_and_test "wrong" "$policy"
3308 echo "Back to default policy"
3309 cdt_set_sanity_policy
3311 run_test 109 "Policy display/change"
3314 # test needs a running copytool
3319 copy2archive /etc/passwd $tdir/$tfile
3321 local f=$DIR/$tdir/$tfile
3322 import_file $tdir/$tfile $f
3323 local fid=$(path2fid $f)
3325 cdt_set_non_blocking_restore
3330 wait_request_state $fid RESTORE SUCCEED
3331 cdt_clear_non_blocking_restore
3335 error "md5sum returns $st != 1, "\
3336 "should also perror ENODATA (No data available)"
3340 run_test 110a "Non blocking restore policy (import case)"
3343 # test needs a running copytool
3347 local f=$DIR/$tdir/$tfile
3348 local fid=$(copy_file /etc/passwd $f)
3349 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3350 wait_request_state $fid ARCHIVE SUCCEED
3353 cdt_set_non_blocking_restore
3358 wait_request_state $fid RESTORE SUCCEED
3359 cdt_clear_non_blocking_restore
3363 error "md5sum returns $st != 1, "\
3364 "should also perror ENODATA (No data available)"
3368 run_test 110b "Non blocking restore policy (release case)"
3371 # test needs a running copytool
3375 copy2archive /etc/passwd $tdir/$tfile
3377 local f=$DIR/$tdir/$tfile
3379 import_file $tdir/$tfile $f
3380 local fid=$(path2fid $f)
3384 copytool_remove_backend $fid
3387 wait_request_state $fid RESTORE FAILED
3394 [[ $st == 0 ]] || error "Restore does not failed"
3398 run_test 111a "No retry policy (import case), restore will error"\
3399 " (No such file or directory)"
3402 # test needs a running copytool
3406 local f=$DIR/$tdir/$tfile
3407 local fid=$(copy_file /etc/passwd $f)
3409 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3410 wait_request_state $fid ARCHIVE SUCCEED
3413 copytool_remove_backend $fid
3416 wait_request_state $fid RESTORE FAILED
3423 [[ $st == 0 ]] || error "Restore does not failed"
3427 run_test 111b "No retry policy (release case), restore will error"\
3428 " (No such file or directory)"
3431 # test needs a running copytool
3435 local f=$DIR/$tdir/$tfile
3436 local fid=$(copy_file /etc/passwd $f)
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3439 local l=$($LFS hsm_action $f)
3441 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3445 wait_request_state $fid ARCHIVE SUCCEED
3448 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3452 run_test 112 "State of recorded request"
3455 # test needs a running copytool
3459 local f=$DIR/$tdir/$tfile
3460 local fid=$(make_large_for_cancel $f)
3461 [ $? != 0 ] && skip "not enough free space" && return
3463 # test with cdt on is made in test_221
3465 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3468 wait_request_state $fid ARCHIVE CANCELED
3469 wait_request_state $fid CANCEL SUCCEED
3473 run_test 200 "Register/Cancel archive"
3476 # test needs a running copytool
3480 local f=$DIR/$tdir/$tfile
3481 make_archive $tdir/$tfile
3482 import_file $tdir/$tfile $f
3483 local fid=$(path2fid $f)
3485 # test with cdt on is made in test_222
3490 wait_request_state $fid RESTORE CANCELED
3491 wait_request_state $fid CANCEL SUCCEED
3495 run_test 201 "Register/Cancel restore"
3498 # test needs a running copytool
3502 local f=$DIR/$tdir/$tfile
3503 local fid=$(make_large_for_progress $f)
3504 [ $? != 0 ] && skip "not enough free space" && return
3506 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3507 wait_request_state $fid ARCHIVE SUCCEED
3513 wait_request_state $fid REMOVE CANCELED
3517 run_test 202 "Register/Cancel remove"
3520 # test needs a running copytool
3525 local f=$DIR/$tdir/$tfile
3526 local fid=$(copy_file /etc/passwd $f)
3530 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3531 wait_request_state $fid ARCHIVE SUCCEED
3533 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3537 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3541 run_test 220 "Changelog for archive"
3544 # test needs a running copytool
3549 local f=$DIR/$tdir/$tfile
3550 local fid=$(make_large_for_cancel $f)
3551 [ $? != 0 ] && skip "not enough free space" && return
3555 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3556 wait_request_state $fid ARCHIVE STARTED
3558 wait_request_state $fid ARCHIVE CANCELED
3559 wait_request_state $fid CANCEL SUCCEED
3561 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3564 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3568 run_test 221 "Changelog for archive canceled"
3571 # test needs a running copytool
3575 copy2archive /etc/passwd $tdir/$tfile
3577 local f=$DIR/$tdir/$tfile
3578 import_file $tdir/$tfile $f
3579 local fid=$(path2fid $f)
3584 wait_request_state $fid RESTORE SUCCEED
3586 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3589 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3593 run_test 222a "Changelog for explicit restore"
3596 # test needs a running copytool
3600 local f=$DIR/$tdir/$tfile
3601 local fid=$(copy_file /etc/passwd $f)
3604 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3605 wait_request_state $fid ARCHIVE SUCCEED
3610 wait_request_state $fid RESTORE SUCCEED
3612 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3615 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3619 run_test 222b "Changelog for implicit restore"
3622 # test needs a running copytool
3627 local f=$DIR/$tdir/$tfile
3628 make_archive $tdir/$tfile
3632 import_file $tdir/$tfile $f
3633 local fid=$(path2fid $f)
3636 wait_request_state $fid RESTORE STARTED
3638 wait_request_state $fid RESTORE CANCELED
3639 wait_request_state $fid CANCEL SUCCEED
3641 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3644 [[ $flags == $target ]] ||
3645 error "Changelog flag is $flags not $target"
3649 run_test 223a "Changelog for restore canceled (import case)"
3652 # test needs a running copytool
3657 local f=$DIR/$tdir/$tfile
3658 local fid=$(make_large_for_progress $f)
3659 [ $? != 0 ] && skip "not enough free space" && return
3662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3663 wait_request_state $fid ARCHIVE SUCCEED
3666 wait_request_state $fid RESTORE STARTED
3668 wait_request_state $fid RESTORE CANCELED
3669 wait_request_state $fid CANCEL SUCCEED
3671 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3674 [[ $flags == $target ]] ||
3675 error "Changelog flag is $flags not $target"
3679 run_test 223b "Changelog for restore canceled (release case)"
3682 # test needs a running copytool
3687 local f=$DIR/$tdir/$tfile
3688 local fid=$(copy_file /etc/passwd $f)
3691 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3692 wait_request_state $fid ARCHIVE SUCCEED
3695 wait_request_state $fid REMOVE SUCCEED
3697 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3700 [[ $flags == $target ]] ||
3701 error "Changelog flag is $flags not $target"
3705 run_test 224 "Changelog for remove"
3708 # test needs a running copytool
3711 # test is not usable because remove request is too fast
3712 # so it is always finished before cancel can be done ...
3713 echo "Test disabled"
3718 local f=$DIR/$tdir/$tfile
3719 local fid=$(make_large_for_progress $f)
3720 [ $? != 0 ] && skip "not enough free space" && return
3723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3724 wait_request_state $fid ARCHIVE SUCCEED
3726 # if cdt is on, it can serve too quickly the request
3731 wait_request_state $fid REMOVE CANCELED
3732 wait_request_state $fid CANCEL SUCCEED
3734 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3735 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3736 tail -n 1 | awk '{print $5}')
3739 [[ $flags == $target ]] ||
3740 error "Changelog flag is $flags not $target"
3744 run_test 225 "Changelog for remove canceled"
3747 # test needs a running copytool
3752 local f1=$DIR/$tdir/$tfile-1
3753 local f2=$DIR/$tdir/$tfile-2
3754 local f3=$DIR/$tdir/$tfile-3
3755 local fid1=$(copy_file /etc/passwd $f1)
3756 local fid2=$(copy_file /etc/passwd $f2)
3757 copy_file /etc/passwd $f3
3760 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3761 wait_request_state $fid1 ARCHIVE SUCCEED
3763 $LFS hsm_archive $f2
3764 wait_request_state $fid2 ARCHIVE SUCCEED
3766 rm $f1 || error "rm $f1 failed"
3768 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3771 [[ $flags == $target ]] ||
3772 error "Changelog flag is $flags not $target"
3774 mv $f3 $f2 || error "mv $f3 $f2 failed"
3776 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3779 [[ $flags == $target ]] ||
3780 error "Changelog flag is $flags not $target"
3784 run_test 226 "changelog for last rm/mv with exiting archive"
3786 check_flags_changes() {
3794 $LFS hsm_set --$hsm_flag $f ||
3795 error "Cannot set $hsm_flag on $f"
3796 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3797 local seen=${#flags[*]}
3799 [[ $seen == $cnt ]] ||
3800 error "set $hsm_flag: Changelog events $seen != $cnt"
3801 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3802 error "set $hsm_flag: Changelog flags are "\
3803 "${flags[$((cnt - 1))]} not $target"
3805 $LFS hsm_clear --$hsm_flag $f ||
3806 error "Cannot clear $hsm_flag on $f"
3807 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3810 [[ $cnt == $seen ]] ||
3811 error "clear $hsm_flag: Changelog events $seen != $cnt"
3813 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3814 error "clear $hsm_flag: Changelog flag is "\
3815 "${flags[$((cnt - 1))]} not $target"
3819 # test needs a running copytool
3826 for i in norelease noarchive exists archived
3828 local f=$DIR/$tdir/$tfile-$i
3829 local fid=$(copy_file /etc/passwd $f)
3830 check_flags_changes $f $fid $i 0 1
3833 f=$DIR/$tdir/$tfile---lost
3834 fid=$(copy_file /etc/passwd $f)
3835 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3836 wait_request_state $fid ARCHIVE SUCCEED
3837 check_flags_changes $f $fid lost 3 1
3841 run_test 227 "changelog when explicit setting of HSM flags"
3844 # test needs a running copytool
3847 local fid=$(make_small_sync $DIR/$tfile)
3848 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3849 wait_request_state $fid ARCHIVE SUCCEED
3851 $LFS hsm_release $DIR/$tfile
3852 check_hsm_flags $DIR/$tfile "0x0000000d"
3854 filefrag $DIR/$tfile | grep " 1 extent found" ||
3855 error "filefrag on released file must return only one extent"
3857 # only newer versions of cp detect sparse files by stat/FIEMAP
3859 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3860 error "copying $DIR/$tfile"
3861 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3863 $LFS hsm_release $DIR/$tfile
3864 check_hsm_flags $DIR/$tfile "0x0000000d"
3866 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3868 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3870 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3871 error "comparing untarred $DIR/$tfile"
3873 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3874 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3877 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3880 # test needs a running copytool
3884 local maxrequest=$(get_hsm_param max_requests)
3885 local rqcnt=$(($maxrequest * 3))
3889 for i in $(seq -w 1 $rqcnt); do
3891 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3893 # we do it in 2 steps, so all requests arrive at the same time
3894 for i in $(seq -w 1 $rqcnt); do
3895 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3900 while [[ $cnt != 0 || $wt != 0 ]]; do
3902 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3903 $HSM_PARAM.actions |\
3904 grep STARTED | grep -v CANCEL | wc -l")
3905 [[ $cnt -le $maxrequest ]] ||
3906 error "$cnt > $maxrequest too many started requests"
3907 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3908 $HSM_PARAM.actions |\
3909 grep WAITING | wc -l")
3910 echo "max=$maxrequest started=$cnt waiting=$wt"
3915 run_test 250 "Coordinator max request"
3918 # test needs a running copytool
3922 local f=$DIR/$tdir/$tfile
3923 local fid=$(make_large_for_cancel $f)
3924 [ $? != 0 ] && skip "not enough free space" && return
3927 # to have a short test
3928 local old_to=$(get_hsm_param active_request_timeout)
3929 set_hsm_param active_request_timeout 4
3930 # to be sure the cdt will wake up frequently so
3931 # it will be able to cancel the "old" request
3932 local old_loop=$(get_hsm_param loop_period)
3933 set_hsm_param loop_period 2
3936 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3937 wait_request_state $fid ARCHIVE STARTED
3939 wait_request_state $fid ARCHIVE CANCELED
3941 set_hsm_param active_request_timeout $old_to
3942 set_hsm_param loop_period $old_loop
3946 run_test 251 "Coordinator request timeout"
3949 # the only way to test ondisk conf is to restart MDS ...
3950 echo "Stop coordinator and remove coordinator state at mount"
3953 # clean on disk conf set by default
3954 cdt_clear_mount_state
3955 cdt_check_state stopped
3957 # check cdt still off after umount/remount
3959 cdt_check_state stopped
3961 echo "Set coordinator start at mount, and start coordinator"
3962 cdt_set_mount_state enabled
3965 cdt_check_state enabled
3967 # check cdt still on after umount/remount
3969 cdt_check_state enabled
3971 # we are back to original state (cdt started at mount)
3973 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3976 local ai=$(get_hsm_param default_archive_id)
3977 local new=$((ai + 1))
3979 set_hsm_param default_archive_id $new -P
3981 local res=$(get_hsm_param default_archive_id)
3984 set_hsm_param default_archive_id "" "-P -d"
3986 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3988 run_test 301 "HSM tunnable are persistent"
3991 local ai=$(get_hsm_param default_archive_id)
3992 local new=$((ai + 1))
3997 set_hsm_param default_archive_id $new -P
4000 for mdtno in $(seq 1 $MDSCOUNT); do
4005 cdt_check_state enabled
4007 local res=$(get_hsm_param default_archive_id)
4010 set_hsm_param default_archive_id "" "-P -d"
4012 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4014 run_test 302 "HSM tunnable are persistent when CDT is off"
4017 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4023 local dir_mdt0=$DIR/$tdir/mdt0
4024 local dir_mdt1=$DIR/$tdir/mdt1
4026 # create 1 dir per MDT
4027 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4028 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4030 # create 1 file in each MDT
4031 local fid1=$(make_small $dir_mdt0/$tfile)
4032 local fid2=$(make_small $dir_mdt1/$tfile)
4034 # check that hsm request on mdt0 is sent to the right MDS
4035 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4036 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4037 echo "archive successful on mdt0"
4039 # check that hsm request on mdt1 is sent to the right MDS
4040 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4041 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4042 echo "archive successful on mdt1"
4045 # clean test files and directories
4046 rm -rf $dir_mdt0 $dir_mdt1
4048 run_test 400 "Single request is sent to the right MDT"
4051 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4057 local dir_mdt0=$DIR/$tdir/mdt0
4058 local dir_mdt1=$DIR/$tdir/mdt1
4060 # create 1 dir per MDT
4061 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4062 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4064 # create 1 file in each MDT
4065 local fid1=$(make_small $dir_mdt0/$tfile)
4066 local fid2=$(make_small $dir_mdt1/$tfile)
4068 # check that compound requests are shunt to the rights MDTs
4069 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4070 error "lfs hsm_archive"
4071 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4072 echo "archive successful on mdt0"
4073 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4074 echo "archive successful on mdt1"
4077 # clean test files and directories
4078 rm -rf $dir_mdt0 $dir_mdt1
4080 run_test 401 "Compound requests split and sent to their respective MDTs"
4082 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4087 local node=$(facet_active_host $facet)
4089 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4090 awk '{print $4}'); do
4091 echo "$3 $mdc on $node"
4092 do_facet $facet "$LCTL --device $mdc $state" || return 1
4097 # make sure there is no running copytool
4100 # deactivate all mdc on agent1
4101 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4103 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4105 check_agent_unregistered "uuid" # match any agent
4107 # no expected running copytool
4108 search_copytools $agent && error "Copytool start should have failed"
4111 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4113 run_test 402 "Copytool start fails if all MDTs are inactive"
4116 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4118 # make sure there is no running copytool
4121 local agent=$(facet_active_host $SINGLEAGT)
4122 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4124 # deactivate all mdc for MDT0001
4125 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4128 # check the agent is registered on MDT0000, and not on MDT0001
4129 check_agent_registered_by_mdt $uuid 0
4130 check_agent_unregistered_by_mdt $uuid 1
4132 # check running copytool process
4133 search_copytools $agent || error "No running copytools on $agent"
4135 # reactivate all mdc for MDT0001
4136 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4138 # make sure the copytool is now registered to all MDTs
4139 check_agent_registered $uuid
4143 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4146 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4150 # create files on both MDT0000 and MDT0001
4153 local dir_mdt0=$DIR/$tdir/mdt0
4154 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4156 # create 1 file on mdt0
4157 local fid1=$(make_small $dir_mdt0/$tfile)
4159 # deactivate all mdc for MDT0001
4160 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4162 # send an HSM request for files in MDT0000
4163 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4165 # check for completion of files in MDT0000
4166 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4167 echo "archive successful on mdt0"
4169 # reactivate all mdc for MDT0001
4170 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4173 # clean test files and directories
4176 run_test 404 "Inactive MDT does not block requests for active MDTs"
4179 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4185 local striped_dir=$DIR/$tdir/striped_dir
4187 # create striped dir on all of MDTs
4188 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4190 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4191 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4192 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4193 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4195 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4196 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4197 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4198 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4200 # check that compound requests are shunt to the rights MDTs
4201 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4202 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4203 error "lfs hsm_archive"
4205 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4206 echo "archive successful on $fid1"
4207 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4208 echo "archive successful on $fid2"
4209 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4210 echo "archive successful on $fid3"
4211 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4212 echo "archive successful on $fid4"
4214 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4215 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4216 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4217 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4219 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4220 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4221 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4222 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4226 run_test 405 "archive and release under striped directory"
4231 check_and_cleanup_lustre