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 file_creation_failure dd $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 '[]'
514 return ${PIPESTATUS[0]}
521 if [[ $u == "user" ]]; then
522 local st=$($RUNAS $LFS hsm_state $f)
524 local st=$($LFS hsm_state $f)
528 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
530 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
534 get_hsm_archive_id() {
536 local st=$($LFS hsm_state $f)
537 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
539 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
548 local st=$(get_hsm_flags $f)
549 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
552 check_hsm_flags_user() {
556 local st=$(get_hsm_flags $f user)
557 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
560 file_creation_failure() {
565 df $MOUNT $MOUNT2 >&2
566 error "cannot create $f with $cmd, status=$err"
578 if [[ "$3" != 1 ]]; then
582 cp $1 $f || file_creation_failure cp $f $?
584 path2fid $f || error "cannot get fid on $f"
588 local file2=${1/$DIR/$DIR2}
589 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
590 file_creation_failure dd $file2 $?
592 path2fid $1 || error "cannot get fid on $1"
596 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
597 file_creation_failure dd $1 $?
598 path2fid $1 || error "cannot get fid on $1"
601 cleanup_large_files() {
602 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
604 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
607 check_enough_free_space() {
610 local need=$((nb * unit /1024))
611 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
612 (( $need >= $free )) && return 1
616 make_large_for_striping() {
617 local file2=${1/$DIR/$DIR2}
618 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
622 check_enough_free_space 5 $sz
623 [ $? != 0 ] && return $?
625 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
626 file_creation_failure dd $file2 $?
628 path2fid $1 || error "cannot get fid on $1"
631 make_large_for_progress() {
632 local file2=${1/$DIR/$DIR2}
636 check_enough_free_space 39 1000000
637 [ $? != 0 ] && return $?
639 # big file is large enough, so copy time is > 30s
640 # so copytool make 1 progress
641 # size is not a multiple of 1M to avoid stripe
643 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
644 file_creation_failure dd $file2 $?
646 path2fid $1 || error "cannot get fid on $1"
649 make_large_for_progress_aligned() {
650 local file2=${1/$DIR/$DIR2}
654 check_enough_free_space 33 1048576
655 [ $? != 0 ] && return $?
657 # big file is large enough, so copy time is > 30s
658 # so copytool make 1 progress
659 # size is a multiple of 1M to have stripe
661 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
662 file_creation_failure dd $file2 $?
663 path2fid $1 || error "cannot get fid on $1"
666 make_large_for_cancel() {
667 local file2=${1/$DIR/$DIR2}
671 check_enough_free_space 103 1048576
672 [ $? != 0 ] && return $?
674 # Copy timeout is 100s. 105MB => 105s
675 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
676 file_creation_failure dd $file2 $?
677 path2fid $1 || error "cannot get fid on $1"
683 wait_update --verbose $(facet_active_host $facet) "$@"
686 wait_request_state() {
690 # 4th arg (mdt index) is optional
692 local mds=mds$(($mdtidx + 1))
694 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
695 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
697 wait_result $mds "$cmd" $state 200 ||
698 error "request on $fid is not $state on $mds"
701 get_request_state() {
705 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
706 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
709 get_request_count() {
713 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
714 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
721 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
722 [[ -n $fid ]] && cmd+=" | grep '$fid'"
723 cmd+=" | egrep 'WAITING|STARTED'"
725 wait_result $SINGLEMDS "$cmd" "" $timeout ||
726 error "requests did not complete"
729 wait_for_grace_delay() {
730 local val=$(get_hsm_param grace_delay)
737 # python2.6 in EL6 includes an internal json module
738 local json_parser='import json; import fileinput;'
739 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
740 json_parser+='json.loads([line for line in '
741 json_parser+='fileinput.input()][0]).items()])'
743 echo $raw_event | python -c "$json_parser"
746 # populate MDT device array
752 # cleanup from previous bad setup
753 search_and_kill_copytool
755 # for recovery tests, coordinator needs to be started at mount
757 # the lustre conf must be without hsm on (like for sanity.sh)
758 echo "Set HSM on and start"
759 cdt_set_mount_state enabled
760 cdt_check_state enabled
762 echo "Start copytool"
765 echo "Set sanity-hsm HSM policy"
766 cdt_set_sanity_policy
768 # finished requests are quickly removed from list
769 set_hsm_param grace_delay 10
775 local f=$DIR/$tdir/$tfile
779 check_hsm_flags_user $f "0x00000000"
781 $RUNAS $LFS hsm_set --norelease $f ||
782 error "user could not change hsm flags"
783 check_hsm_flags_user $f "0x00000010"
785 $RUNAS $LFS hsm_clear --norelease $f ||
786 error "user could not clear hsm flags"
787 check_hsm_flags_user $f "0x00000000"
789 # User could not change those flags...
790 $RUNAS $LFS hsm_set --exists $f &&
791 error "user should not set this flag"
792 check_hsm_flags_user $f "0x00000000"
795 $LFS hsm_set --exists $f ||
796 error "root could not change hsm flags"
797 check_hsm_flags_user $f "0x00000001"
799 $LFS hsm_clear --exists $f ||
800 error "root could not clear hsm state"
801 check_hsm_flags_user $f "0x00000000"
804 run_test 1 "lfs hsm flags root/non-root access"
808 local f=$DIR/$tdir/$tfile
810 # New files are not dirty
811 check_hsm_flags $f "0x00000000"
813 # For test, we simulate an archived file.
814 $LFS hsm_set --exists $f || error "user could not change hsm flags"
815 check_hsm_flags $f "0x00000001"
817 # chmod do not put the file dirty
818 chmod 600 $f || error "could not chmod test file"
819 check_hsm_flags $f "0x00000001"
821 # chown do not put the file dirty
822 chown $RUNAS_ID $f || error "could not chown test file"
823 check_hsm_flags $f "0x00000001"
825 # truncate put the file dirty
826 $TRUNCATE $f 1 || error "could not truncate test file"
827 check_hsm_flags $f "0x00000003"
829 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
830 check_hsm_flags $f "0x00000001"
832 run_test 2 "Check file dirtyness when doing setattr"
838 # New files are not dirty
840 check_hsm_flags $f "0x00000000"
842 # For test, we simulate an archived file.
843 $LFS hsm_set --exists $f ||
844 error "user could not change hsm flags"
845 check_hsm_flags $f "0x00000001"
847 # Reading a file, does not set dirty
848 cat $f > /dev/null || error "could not read file"
849 check_hsm_flags $f "0x00000001"
851 # Open for write without modifying data, does not set dirty
852 openfile -f O_WRONLY $f || error "could not open test file"
853 check_hsm_flags $f "0x00000001"
855 # Append to a file sets it dirty
856 cp -p /etc/passwd $f.append || error "could not create file"
857 $LFS hsm_set --exists $f.append ||
858 error "user could not change hsm flags"
859 dd if=/etc/passwd of=$f.append bs=1 count=3\
860 conv=notrunc oflag=append status=noxfer ||
861 file_creation_failure dd $f.append $?
862 check_hsm_flags $f.append "0x00000003"
864 # Modify a file sets it dirty
865 cp -p /etc/passwd $f.modify || error "could not create file"
866 $LFS hsm_set --exists $f.modify ||
867 error "user could not change hsm flags"
868 dd if=/dev/zero of=$f.modify bs=1 count=3\
869 conv=notrunc status=noxfer ||
870 file_creation_failure dd $f.modify $?
871 check_hsm_flags $f.modify "0x00000003"
873 # Open O_TRUNC sets dirty
874 cp -p /etc/passwd $f.trunc || error "could not create file"
875 $LFS hsm_set --exists $f.trunc ||
876 error "user could not change hsm flags"
877 cp /etc/group $f.trunc || error "could not override a file"
878 check_hsm_flags $f.trunc "0x00000003"
880 # Mmapped a file sets dirty
881 cp -p /etc/passwd $f.mmap || error "could not create file"
882 $LFS hsm_set --exists $f.mmap ||
883 error "user could not change hsm flags"
884 multiop $f.mmap OSMWUc || error "could not mmap a file"
885 check_hsm_flags $f.mmap "0x00000003"
887 run_test 3 "Check file dirtyness when opening for write"
891 local f=$DIR/$tdir/$tfile
892 local fid=$(make_small $f)
895 local st=$(get_request_state $fid CANCEL)
896 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
898 run_test 4 "Useless cancel must not be registered"
901 # test needs a running copytool
905 local f=$DIR/$tdir/$tfile
906 local fid=$(copy_file /etc/passwd $f)
908 wait_request_state $fid ARCHIVE SUCCEED
910 check_hsm_flags $f "0x00000009"
914 run_test 8 "Test default archive number"
918 local f=$DIR/$tdir/$tfile
919 local fid=$(copy_file /etc/passwd $f)
920 # we do not use the default one to be sure
921 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
923 copytool_setup $SINGLEAGT $MOUNT $new_an
924 $LFS hsm_archive --archive $new_an $f
925 wait_request_state $fid ARCHIVE SUCCEED
927 check_hsm_flags $f "0x00000009"
931 run_test 9 "Use of explict archive number, with dedicated copytool"
934 needclients 3 || return 0
940 copytool_cleanup $(comma_list $(agts_nodes))
942 # start all of the copytools
943 for n in $(seq $AGTCOUNT); do
947 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
950 for n in $(seq $AGTCOUNT); do
951 file=$DIR/$tdir/$tfile.$n
952 fid=$(make_small $file)
954 $LFS hsm_archive $file || error "could not archive file $file"
955 wait_request_state $fid ARCHIVE SUCCEED
956 check_hsm_flags $file "0x00000009"
960 copytool_cleanup $(comma_list $(agts_nodes))
962 run_test 9a "Multiple remote agents"
965 # test needs a running copytool
968 mkdir -p $DIR/$tdir/d1
969 local f=$DIR/$tdir/$tfile
970 local fid=$(copy_file /etc/hosts $f)
971 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
972 error "hsm_archive failed"
973 wait_request_state $fid ARCHIVE SUCCEED
975 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
976 error "fid $fid not in archive $HSM_ARCHIVE"
977 echo "Verifying content"
978 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
979 echo "Verifying hsm state "
980 check_hsm_flags $f "0x00000009"
982 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
983 local st=$(get_hsm_archive_id $f)
984 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
985 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
990 run_test 10a "Archive a file"
993 # test needs a running copytool
997 local f=$DIR/$tdir/$tfile
998 local fid=$(copy_file /etc/hosts $f)
999 $LFS hsm_archive $f || error "archive request failed"
1000 wait_request_state $fid ARCHIVE SUCCEED
1002 $LFS hsm_archive $f || error "archive of non dirty file failed"
1003 local cnt=$(get_request_count $fid ARCHIVE)
1004 [[ "$cnt" == "1" ]] ||
1005 error "archive of non dirty file must not make a request"
1009 run_test 10b "Archive of non dirty file must work without doing request"
1012 # test needs a running copytool
1016 local f=$DIR/$tdir/$tfile
1017 local fid=$(copy_file /etc/hosts $f)
1018 $LFS hsm_set --noarchive $f
1019 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1023 run_test 10c "Check forbidden archive"
1026 # test needs a running copytool
1030 local f=$DIR/$tdir/$tfile
1031 local fid=$(copy_file /etc/hosts $f)
1032 $LFS hsm_archive $f || error "cannot archive $f"
1033 wait_request_state $fid ARCHIVE SUCCEED
1035 local ar=$(get_hsm_archive_id $f)
1036 local dflt=$(get_hsm_param default_archive_id)
1037 [[ $ar == $dflt ]] ||
1038 error "archived file is not on default archive: $ar != $dflt"
1042 run_test 10d "Archive a file on the default archive id"
1046 copy2archive /etc/hosts $tdir/$tfile
1047 local f=$DIR/$tdir/$tfile
1049 import_file $tdir/$tfile $f
1050 echo -n "Verifying released state: "
1051 check_hsm_flags $f "0x0000000d"
1053 local LSZ=$(stat -c "%s" $f)
1054 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1056 echo "Verifying imported size $LSZ=$ASZ"
1057 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1058 echo -n "Verifying released pattern: "
1059 local PTRN=$($GETSTRIPE -L $f)
1061 [[ $PTRN == 80000001 ]] || error "Is not released"
1062 local fid=$(path2fid $f)
1063 echo "Verifying new fid $fid in archive"
1065 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1066 error "fid $fid not in archive $HSM_ARCHIVE"
1068 run_test 11a "Import a file"
1071 # test needs a running copytool
1075 local f=$DIR/$tdir/$tfile
1076 local fid=$(copy_file /etc/hosts $f)
1077 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1078 error "hsm_archive failed"
1079 wait_request_state $fid ARCHIVE SUCCEED
1081 local FILE_HASH=$(md5sum $f)
1086 echo "$FILE_HASH" | md5sum -c
1088 [[ $? -eq 0 ]] || error "Restored file differs"
1092 run_test 11b "Import a deleted file using its FID"
1095 # test needs a running copytool
1099 copy2archive /etc/hosts $tdir/$tfile
1101 local f=$DIR/$tdir/$tfile
1102 import_file $tdir/$tfile $f
1103 local f2=$DIR2/$tdir/$tfile
1104 echo "Verifying released state: "
1105 check_hsm_flags $f2 "0x0000000d"
1107 local fid=$(path2fid $f2)
1108 $LFS hsm_restore $f2
1109 wait_request_state $fid RESTORE SUCCEED
1111 echo "Verifying file state: "
1112 check_hsm_flags $f2 "0x00000009"
1114 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1116 [[ $? -eq 0 ]] || error "Restored file differs"
1120 run_test 12a "Restore an imported file explicitly"
1123 # test needs a running copytool
1127 copy2archive /etc/hosts $tdir/$tfile
1129 local f=$DIR/$tdir/$tfile
1130 import_file $tdir/$tfile $f
1131 echo "Verifying released state: "
1132 check_hsm_flags $f "0x0000000d"
1134 cat $f > /dev/null || error "File read failed"
1136 echo "Verifying file state after restore: "
1137 check_hsm_flags $f "0x00000009"
1139 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1141 [[ $? -eq 0 ]] || error "Restored file differs"
1145 run_test 12b "Restore an imported file implicitly"
1148 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1150 # test needs a running copytool
1154 local f=$DIR/$tdir/$tfile
1155 $LFS setstripe -c 2 $f
1156 local fid=$(make_large_for_striping $f)
1157 [ $? != 0 ] && skip "not enough free space" && return
1159 local FILE_CRC=$(md5sum $f)
1161 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1162 wait_request_state $fid ARCHIVE SUCCEED
1163 $LFS hsm_release $f || error "release $f failed"
1165 echo "$FILE_CRC" | md5sum -c
1167 [[ $? -eq 0 ]] || error "Restored file differs"
1171 run_test 12c "Restore a file with stripe of 2"
1174 # test needs a running copytool
1179 local f=$DIR/$tdir/$tfile
1180 local fid=$(copy_file /etc/hosts $f)
1181 $LFS hsm_restore $f || error "restore of non archived file failed"
1182 local cnt=$(get_request_count $fid RESTORE)
1183 [[ "$cnt" == "0" ]] ||
1184 error "restore non archived must not make a request"
1185 $LFS hsm_archive $f ||
1186 error "archive request failed"
1187 wait_request_state $fid ARCHIVE SUCCEED
1188 $LFS hsm_restore $f ||
1189 error "restore of non released file failed"
1190 local cnt=$(get_request_count $fid RESTORE)
1191 [[ "$cnt" == "0" ]] ||
1192 error "restore a non dirty file must not make a request"
1196 run_test 12d "Restore of a non archived, non released file must work"\
1197 " without doing request"
1200 # test needs a running copytool
1203 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1204 local f=$DIR/$tdir/$tfile
1205 local fid=$(copy_file /etc/hosts $f)
1206 $LFS hsm_archive $f || error "archive request failed"
1207 wait_request_state $fid ARCHIVE SUCCEED
1210 cat /etc/hosts >> $f
1214 $LFS hsm_restore $f && error "restore a dirty file must fail"
1218 run_test 12e "Check forbidden restore"
1221 # test needs a running copytool
1225 local f=$DIR/$tdir/$tfile
1226 local fid=$(copy_file /etc/hosts $f)
1228 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1229 wait_request_state $fid ARCHIVE SUCCEED
1230 $LFS hsm_release $f || error "release of $f failed"
1232 wait_request_state $fid RESTORE SUCCEED
1234 echo -n "Verifying file state: "
1235 check_hsm_flags $f "0x00000009"
1237 diff -q /etc/hosts $f
1239 [[ $? -eq 0 ]] || error "Restored file differs"
1243 run_test 12f "Restore a released file explicitly"
1246 # test needs a running copytool
1250 local f=$DIR/$tdir/$tfile
1251 local fid=$(copy_file /etc/hosts $f)
1253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1254 wait_request_state $fid ARCHIVE SUCCEED
1255 $LFS hsm_release $f || error "release of $f failed"
1257 diff -q /etc/hosts $f
1260 # we check we had a restore done
1261 wait_request_state $fid RESTORE SUCCEED
1263 [[ $st -eq 0 ]] || error "Restored file differs"
1267 run_test 12g "Restore a released file implicitly"
1270 needclients 2 || return 0
1272 # test needs a running copytool
1276 local f=$DIR/$tdir/$tfile
1277 local fid=$(copy_file /etc/hosts $f)
1279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1280 wait_request_state $fid ARCHIVE SUCCEED
1281 $LFS hsm_release $f || error "release of $f failed"
1283 do_node $CLIENT2 diff -q /etc/hosts $f
1286 # we check we had a restore done
1287 wait_request_state $fid RESTORE SUCCEED
1289 [[ $st -eq 0 ]] || error "Restored file differs"
1293 run_test 12h "Restore a released file implicitly from a second node"
1296 # test needs a running copytool
1300 local f=$DIR/$tdir/$tfile
1301 local fid=$(copy_file /etc/passwd $f)
1302 $LFS hsm_archive $f || error "archive of $f failed"
1303 wait_request_state $fid ARCHIVE SUCCEED
1305 $LFS hsm_release $f || error "release of $f failed"
1309 [[ $? -eq 0 ]] || error "Restored file differs"
1313 run_test 12m "Archive/release/implicit restore"
1316 # test needs a running copytool
1320 copy2archive /etc/hosts $tdir/$tfile
1322 local f=$DIR/$tdir/$tfile
1323 import_file $tdir/$tfile $f
1325 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1326 error "Restored file differs"
1328 $LFS hsm_release $f || error "release of $f failed"
1332 run_test 12n "Import/implicit restore/release"
1335 # test needs a running copytool
1339 local f=$DIR/$tdir/$tfile
1340 local fid=$(copy_file /etc/hosts $f)
1342 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1343 wait_request_state $fid ARCHIVE SUCCEED
1344 $LFS hsm_release $f || error "release of $f failed"
1346 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1347 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1349 # set no retry action mode
1352 diff -q /etc/hosts $f
1355 # we check we had a restore failure
1356 wait_request_state $fid RESTORE FAILED
1358 [[ $st -eq 0 ]] && error "Restore must fail"
1360 # remove no retry action mode
1363 # check file is still released
1364 check_hsm_flags $f "0x0000000d"
1366 # retry w/o failure injection
1367 do_facet $SINGLEMDS lctl set_param fail_loc=0
1369 # to be sure previous RESTORE result is gone
1371 wait_for_grace_delay
1373 diff -q /etc/hosts $f
1376 # we check we had a restore done
1377 wait_request_state $fid RESTORE SUCCEED
1379 [[ $st -eq 0 ]] || error "Restored file differs"
1383 run_test 12o "Layout-swap failure during Restore leaves file released"
1386 # test needs a running copytool
1389 local ARC_SUBDIR="import.orig"
1393 # populate directory to be imported
1394 for d in $(seq 1 10); do
1395 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1396 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1397 for f in $(seq 1 10); do
1398 CURR_FILE="$CURR_DIR/$tfile.$f"
1399 # write file-specific data
1400 do_facet $SINGLEAGT \
1401 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1402 "file=$CURR_FILE > $CURR_FILE"
1406 import_file "$ARC_SUBDIR" $DIR/$tdir
1407 # diff lustre content and origin (triggers file restoration)
1408 # there must be 10x10 identical files, and no difference
1409 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1410 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1411 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1412 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1414 [ $cnt_diff -eq 0 ] ||
1415 error "$cnt_diff imported files differ from read data"
1416 [ $cnt_ok -eq 100 ] ||
1417 error "not enough identical files ($cnt_ok != 100)"
1421 run_test 13 "Recursively import and restore a directory"
1424 # test needs a running copytool
1429 local f=$DIR/$tdir/$tfile
1430 local fid=$(make_small $f)
1431 local sum=$(md5sum $f | awk '{print $1}')
1432 $LFS hsm_archive $f || error "could not archive file"
1433 wait_request_state $fid ARCHIVE SUCCEED
1437 # create released file (simulate llapi_hsm_import call)
1439 local fid2=$(path2fid $f)
1440 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1441 $LFS hsm_release $f || error "could not release file"
1443 # rebind the archive to the newly created file
1444 echo "rebind $fid to $fid2"
1446 do_facet $SINGLEAGT \
1447 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1448 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1450 # restore file and compare md5sum
1451 local sum2=$(md5sum $f | awk '{print $1}')
1453 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1457 run_test 14 "Rebind archived file to a new fid"
1460 # test needs a running copytool
1465 local f=$DIR/$tdir/$tfile
1467 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1471 for i in $(seq 1 $count); do
1472 fids[$i]=$(make_small $f.$i)
1473 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1474 $LFS hsm_archive $f.$i || error "could not archive file"
1476 wait_all_done $(($count*60))
1480 for i in $(seq 1 $count); do
1483 local fid2=$(path2fid $f.$i)
1484 # add the rebind operation to the list
1485 echo ${fids[$i]} $fid2 >> $tmpfile
1487 # set it released (simulate llapi_hsm_import call)
1488 $LFS hsm_set --archived --exists $f.$i ||
1489 error "could not force hsm flags"
1490 $LFS hsm_release $f.$i || error "could not release file"
1492 nl=$(wc -l < $tmpfile)
1493 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1495 echo "rebind list of files"
1496 do_facet $SINGLEAGT \
1497 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1498 --rebind $tmpfile $DIR" || error "could not rebind file list"
1500 # restore files and compare md5sum
1501 for i in $(seq 1 $count); do
1502 local sum2=$(md5sum $f.$i | awk '{print $1}')
1503 [[ $sum2 == ${sums[$i]} ]] ||
1504 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1510 run_test 15 "Rebind a list of files"
1513 # test needs a running copytool
1517 # create a known size file so we can verify transfer speed
1520 dd if=/dev/zero of=$ref bs=1M count=20
1523 local f=$DIR/$tdir/$tfile
1524 local fid=$(copy_file $ref $f)
1526 local start=$(date +%s)
1528 wait_request_state $fid ARCHIVE SUCCEED
1529 local end=$(date +%s)
1530 local duration=$((end - start))
1532 [[ $duration -ge $goal ]] ||
1533 error "Transfer is too fast $duration < $goal"
1537 run_test 16 "Test CT bandwith control option"
1542 local f=$DIR/$tdir/$tfile
1543 touch $f || error "touch $f failed"
1545 # Could not release a non-archived file
1546 $LFS hsm_release $f && error "release should not succeed"
1548 # For following tests, we must test them with HS_ARCHIVED set
1549 $LFS hsm_set --exists --archived $f || error "could not add flag"
1551 # Could not release a file if no-release is set
1552 $LFS hsm_set --norelease $f || error "could not add flag"
1553 $LFS hsm_release $f && error "release should not succeed"
1554 $LFS hsm_clear --norelease $f || error "could not remove flag"
1556 # Could not release a file if lost
1557 $LFS hsm_set --lost $f || error "could not add flag"
1558 $LFS hsm_release $f && error "release should not succeed"
1559 $LFS hsm_clear --lost $f || error "could not remove flag"
1561 # Could not release a file if dirty
1562 $LFS hsm_set --dirty $f || error "could not add flag"
1563 $LFS hsm_release $f && error "release should not succeed"
1564 $LFS hsm_clear --dirty $f || error "could not remove flag"
1566 run_test 20 "Release is not permitted"
1569 # test needs a running copytool
1573 local f=$DIR/$tdir/test_release
1575 # Create a file and check its states
1576 local fid=$(make_small $f)
1577 check_hsm_flags $f "0x00000000"
1579 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1580 # used until file is flushed to disk
1581 if [ $(facet_fstype ost1) == "zfs" ]; then
1582 # this causes an OST_SYNC rpc to be sent
1583 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1584 # clear locks to reread file data
1585 cancel_lru_locks osc
1588 local orig_size=$(stat -c "%s" $f)
1589 local orig_blocks=$(stat -c "%b" $f)
1591 start_full_debug_logging
1593 $LFS hsm_archive $f || error "could not archive file"
1594 wait_request_state $fid ARCHIVE SUCCEED
1596 local blocks=$(stat -c "%b" $f)
1597 [ $blocks -eq $orig_blocks ] ||
1598 error "$f: wrong block number after archive: " \
1599 "$blocks != $orig_blocks"
1600 local size=$(stat -c "%s" $f)
1601 [ $size -eq $orig_size ] ||
1602 error "$f: wrong size after archive: $size != $orig_size"
1604 # Release and check states
1605 $LFS hsm_release $f || error "could not release file"
1606 check_hsm_flags $f "0x0000000d"
1608 blocks=$(stat -c "%b" $f)
1609 [ $blocks -gt 5 ] &&
1610 error "$f: too many blocks after release: $blocks > 5"
1611 size=$(stat -c "%s" $f)
1612 [ $size -ne $orig_size ] &&
1613 error "$f: wrong size after release: $size != $orig_size"
1615 # Check we can release an file without stripe info
1619 check_hsm_flags $f "0x00000000"
1620 $LFS hsm_archive $f || error "could not archive file"
1621 wait_request_state $fid ARCHIVE SUCCEED
1623 # Release and check states
1624 $LFS hsm_release $f || error "could not release file"
1625 check_hsm_flags $f "0x0000000d"
1627 # Release again a file that is already released is OK
1628 $LFS hsm_release $f || fail "second release should succeed"
1629 check_hsm_flags $f "0x0000000d"
1631 stop_full_debug_logging
1635 run_test 21 "Simple release tests"
1638 # test needs a running copytool
1643 local f=$DIR/$tdir/test_release
1644 local swap=$DIR/$tdir/test_swap
1646 # Create a file and check its states
1647 local fid=$(make_small $f)
1648 check_hsm_flags $f "0x00000000"
1650 $LFS hsm_archive $f || error "could not archive file"
1651 wait_request_state $fid ARCHIVE SUCCEED
1653 # Release and check states
1654 $LFS hsm_release $f || error "could not release file"
1655 check_hsm_flags $f "0x0000000d"
1658 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1663 run_test 22 "Could not swap a release file"
1666 # test needs a running copytool
1671 local f=$DIR/$tdir/test_mtime
1673 # Create a file and check its states
1674 local fid=$(make_small $f)
1675 check_hsm_flags $f "0x00000000"
1677 $LFS hsm_archive $f || error "could not archive file"
1678 wait_request_state $fid ARCHIVE SUCCEED
1680 # Set modification time in the past
1681 touch -m -a -d @978261179 $f
1683 # Release and check states
1684 $LFS hsm_release $f || error "could not release file"
1685 check_hsm_flags $f "0x0000000d"
1687 local MTIME=$(stat -c "%Y" $f)
1688 local ATIME=$(stat -c "%X" $f)
1689 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1690 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1694 run_test 23 "Release does not change a/mtime (utime)"
1697 local file=$DIR/$tdir/$tfile
1706 # test needs a running copytool
1711 fid=$(make_small $file)
1713 # Create a file and check its states
1714 check_hsm_flags $file "0x00000000"
1716 # Ensure atime is less than mtime and ctime.
1720 atime0=$(stat -c "%X" $file)
1721 mtime0=$(stat -c "%Y" $file)
1722 ctime0=$(stat -c "%Z" $file)
1724 [ $atime0 -lt $mtime0 ] ||
1725 error "atime $atime0 is not less than mtime $mtime0"
1727 [ $atime0 -lt $ctime0 ] ||
1728 error "atime $atime0 is not less than ctime $ctime0"
1730 # Archive should not change any timestamps.
1731 $LFS hsm_archive $file || error "cannot archive '$file'"
1732 wait_request_state $fid ARCHIVE SUCCEED
1734 atime1=$(stat -c "%X" $file)
1735 mtime1=$(stat -c "%Y" $file)
1736 ctime1=$(stat -c "%Z" $file)
1738 [ $atime0 -eq $atime1 ] ||
1739 error "archive changed atime from $atime0 to $atime1"
1741 [ $mtime0 -eq $mtime1 ] ||
1742 error "archive changed mtime from $mtime0 to $mtime1"
1744 [ $ctime0 -eq $ctime1 ] ||
1745 error "archive changed ctime from $ctime0 to $ctime1"
1747 # Release should not change any timestamps.
1748 $LFS hsm_release $file || error "cannot release '$file'"
1749 check_hsm_flags $file "0x0000000d"
1751 atime1=$(stat -c "%X" $file)
1752 mtime1=$(stat -c "%Y" $file)
1753 ctime1=$(stat -c "%Z" $file)
1755 [ $atime0 -eq $atime1 ] ||
1756 error "release changed atime from $atime0 to $atime1"
1758 [ $mtime0 -eq $mtime1 ] ||
1759 error "release changed mtime from $mtime0 to $mtime1"
1761 [ $ctime0 -eq $ctime1 ] ||
1762 error "release changed ctime from $ctime0 to $ctime1"
1764 # Restore should not change atime or mtime and should not
1766 $LFS hsm_restore $file
1767 wait_request_state $fid RESTORE SUCCEED
1769 atime1=$(stat -c "%X" $file)
1770 mtime1=$(stat -c "%Y" $file)
1771 ctime1=$(stat -c "%Z" $file)
1773 [ $atime0 -eq $atime1 ] ||
1774 error "restore changed atime from $atime0 to $atime1"
1776 [ $mtime0 -eq $mtime1 ] ||
1777 error "restore changed mtime from $mtime0 to $mtime1"
1779 [ $ctime0 -le $ctime1 ] ||
1780 error "restore changed ctime from $ctime0 to $ctime1"
1784 # Once more, after unmount and mount.
1785 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1786 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1788 atime1=$(stat -c "%X" $file)
1789 mtime1=$(stat -c "%Y" $file)
1790 ctime1=$(stat -c "%Z" $file)
1792 [ $atime0 -eq $atime1 ] ||
1793 error "remount changed atime from $atime0 to $atime1"
1795 [ $mtime0 -eq $mtime1 ] ||
1796 error "remount changed mtime from $mtime0 to $mtime1"
1798 [ $ctime0 -le $ctime1 ] ||
1799 error "remount changed ctime from $ctime0 to $ctime1"
1801 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1804 local file=$DIR/$tdir/$tfile
1810 # Test needs a running copytool.
1814 # Check that root can do HSM actions on a ordinary user's file.
1816 fid=$(make_small $file)
1817 sum0=$(md5sum $file)
1819 chown $RUNAS_ID:$RUNAS_GID $file ||
1820 error "cannot chown '$file' to '$RUNAS_ID'"
1822 chmod ugo-w $DIR/$tdir ||
1823 error "cannot chmod '$DIR/$tdir'"
1825 $LFS hsm_archive $file
1826 wait_request_state $fid ARCHIVE SUCCEED
1828 $LFS hsm_release $file
1829 check_hsm_flags $file "0x0000000d"
1831 $LFS hsm_restore $file
1832 wait_request_state $fid RESTORE SUCCEED
1834 # Check that ordinary user can get HSM state.
1835 $RUNAS $LFS hsm_state $file ||
1836 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1838 $LFS hsm_release $file
1839 check_hsm_flags $file "0x0000000d"
1841 # Check that ordinary user can accessed released file.
1842 sum1=$($RUNAS md5sum $file) ||
1843 error "user '$RUNAS_ID' cannot read '$file'"
1845 [ "$sum0" == "$sum1" ] ||
1846 error "md5sum mismatch for '$file'"
1850 run_test 24b "root can archive, release, and restore user files"
1852 cleanup_test_24c() {
1854 set_hsm_param user_request_mask RESTORE
1855 set_hsm_param group_request_mask RESTORE
1856 set_hsm_param other_request_mask RESTORE
1860 local file=$DIR/$tdir/$tfile
1861 local action=archive
1866 # test needs a running copytool
1871 # Save the default masks and check that cleanup_24c will
1872 # restore the request masks correctly.
1873 user_save=$(get_hsm_param user_request_mask)
1874 group_save=$(get_hsm_param group_request_mask)
1875 other_save=$(get_hsm_param other_request_mask)
1877 [ "$user_save" == RESTORE ] ||
1878 error "user_request_mask is '$user_save' expected 'RESTORE'"
1879 [ "$group_save" == RESTORE ] ||
1880 error "group_request_mask is '$group_save' expected 'RESTORE'"
1881 [ "$other_save" == RESTORE ] ||
1882 error "other_request_mask is '$other_save' expected 'RESTORE'"
1884 trap cleanup_test_24c EXIT
1889 chown $RUNAS_ID:nobody $file ||
1890 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1892 set_hsm_param user_request_mask ""
1893 $RUNAS $LFS hsm_$action $file &&
1894 error "$action by user should fail"
1896 set_hsm_param user_request_mask $action
1897 $RUNAS $LFS hsm_$action $file ||
1898 error "$action by user should succeed"
1903 chown nobody:$RUNAS_GID $file ||
1904 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1906 set_hsm_param group_request_mask ""
1907 $RUNAS $LFS hsm_$action $file &&
1908 error "$action by group should fail"
1910 set_hsm_param group_request_mask $action
1911 $RUNAS $LFS hsm_$action $file ||
1912 error "$action by group should succeed"
1917 chown nobody:nobody $file ||
1918 error "cannot chown '$file' to 'nobody:nobody'"
1920 set_hsm_param other_request_mask ""
1921 $RUNAS $LFS hsm_$action $file &&
1922 error "$action by other should fail"
1924 set_hsm_param other_request_mask $action
1925 $RUNAS $LFS hsm_$action $file ||
1926 error "$action by other should succeed"
1931 run_test 24c "check that user,group,other request masks work"
1933 cleanup_test_24d() {
1935 mount -o remount,rw $MOUNT2
1939 local file1=$DIR/$tdir/$tfile
1940 local file2=$DIR2/$tdir/$tfile
1948 fid1=$(make_small $file1)
1950 trap cleanup_test_24d EXIT
1952 mount -o remount,ro $MOUNT2
1954 fid2=$(path2fid $file2)
1955 [ "$fid1" == "$fid2" ] ||
1956 error "FID mismatch '$fid1' != '$fid2'"
1958 $LFS hsm_archive $file2 &&
1959 error "archive should fail on read-only mount"
1960 check_hsm_flags $file1 "0x00000000"
1962 $LFS hsm_archive $file1
1963 wait_request_state $fid1 ARCHIVE SUCCEED
1965 $LFS hsm_release $file1
1966 $LFS hsm_restore $file2
1967 wait_request_state $fid1 RESTORE SUCCEED
1969 $LFS hsm_release $file1 || error "cannot release '$file1'"
1970 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1972 $LFS hsm_release $file2 &&
1973 error "release should fail on read-only mount"
1978 run_test 24d "check that read-only mounts are respected"
1981 # test needs a running copytool
1985 copy2archive /etc/hosts $tdir/$tfile
1987 local f=$DIR/$tdir/$tfile
1989 import_file $tdir/$tfile $f
1991 $LFS hsm_set --lost $f
1996 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2000 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2001 " (Operation not permitted)"
2004 # test needs a running copytool
2009 local f=$DIR/$tdir/$tfile
2010 local fid=$(copy_file /etc/passwd $f)
2012 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2013 wait_request_state $fid ARCHIVE SUCCEED
2016 $LFS hsm_set --lost $f
2020 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2024 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2025 " (Operation not permitted)"
2028 # test needs a running copytool
2032 local f=$DIR/$tdir/$tfile
2033 local fid=$(make_large_for_progress $f)
2034 [ $? != 0 ] && skip "not enough free space" && return
2036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2037 wait_request_state $fid ARCHIVE SUCCEED
2040 wait_request_state $fid REMOVE SUCCEED
2042 check_hsm_flags $f "0x00000000"
2046 run_test 26 "Remove the archive of a valid file"
2049 # test needs a running copytool
2053 make_archive $tdir/$tfile
2054 local f=$DIR/$tdir/$tfile
2055 import_file $tdir/$tfile $f
2056 local fid=$(path2fid $f)
2060 [[ $? != 0 ]] || error "Remove of a released file should fail"
2064 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2067 # test needs a running copytool
2071 local f=$DIR/$tdir/$tfile
2072 local fid=$(make_large_for_progress $f)
2073 [ $? != 0 ] && skip "not enough free space" && return
2075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2076 wait_request_state $fid ARCHIVE SUCCEED
2081 [[ $? != 0 ]] || error "Remove of a released file should fail"
2085 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2088 # test needs a running copytool
2092 local f=$DIR/$tdir/$tfile
2093 local fid=$(make_large_for_progress $f)
2094 [ $? != 0 ] && skip "not enough free space" && return
2096 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2097 wait_request_state $fid ARCHIVE SUCCEED
2106 wait_request_state $fid REMOVE SUCCEED
2110 run_test 28 "Concurrent archive/file remove"
2113 # restore at exec cannot work on agent node (because of Linux kernel
2114 # protection of executables)
2115 needclients 2 || return 0
2117 # test needs a running copytool
2121 copy2archive /bin/true $tdir/$tfile
2123 local f=$DIR/$tdir/true
2124 import_file $tdir/$tfile $f
2126 local fid=$(path2fid $f)
2128 # set no retry action mode
2134 # remove no try action mode
2138 [[ $st == 0 ]] || error "Failed to exec a released file"
2142 run_test 30a "Restore at exec (import case)"
2145 # restore at exec cannot work on agent node (because of Linux kernel
2146 # protection of executables)
2147 needclients 2 || return 0
2149 # test needs a running copytool
2153 local f=$DIR/$tdir/true
2154 local fid=$(copy_file /bin/true $f)
2156 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2157 wait_request_state $fid ARCHIVE SUCCEED
2160 # set no retry action mode
2166 # remove no try action mode
2170 [[ $st == 0 ]] || error "Failed to exec a released file"
2174 run_test 30b "Restore at exec (release case)"
2177 needclients 2 || return 0
2179 # test needs a running copytool
2183 local f=$DIR/$tdir/SLEEP
2184 local fid=$(copy_file /bin/sleep $f)
2186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2187 wait_request_state $fid ARCHIVE SUCCEED
2189 check_hsm_flags $f "0x0000000d"
2190 # set no retry action mode
2192 do_node $CLIENT2 "$f 10" &
2196 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2198 [[ $? == 0 ]] || error "Execution failed during run"
2200 [[ $? == 0 ]] || error "Binary overwritten during exec"
2203 # remove no try action mode
2205 check_hsm_flags $f "0x00000009"
2209 run_test 30c "Update during exec of released file must fail"
2211 restore_and_check_size() {
2214 local s=$(stat -c "%s" $f)
2216 local st=$(get_hsm_flags $f)
2220 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2222 n=$(stat -c "%s" $f)
2223 # we echo in both cases to show stat is not
2225 if [[ $n != $s ]]; then
2226 echo "size seen is $n != $s"
2229 echo "size seen is right: $n == $s"
2231 st=$(get_hsm_flags $f)
2235 if [[ $cpt -lt 10 ]]; then
2238 echo " restore is too long"
2239 wait_request_state $fid RESTORE SUCCEED
2245 # test needs a running copytool
2250 make_archive $tdir/$tfile
2251 local f=$DIR/$tdir/$tfile
2252 import_file $tdir/$tfile $f
2253 local fid=$($LFS path2fid $f)
2254 HSM_ARCHIVE_PURGE=false copytool_setup
2256 restore_and_check_size $f $fid
2259 [[ $err -eq 0 ]] || error "File size changed during restore"
2263 run_test 31a "Import a large file and check size during restore"
2267 # test needs a running copytool
2272 local f=$DIR/$tdir/$tfile
2273 local fid=$(make_large_for_progress $f)
2274 [ $? != 0 ] && skip "not enough free space" && return
2276 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2277 wait_request_state $fid ARCHIVE SUCCEED
2280 restore_and_check_size $f $fid
2283 [[ $err -eq 0 ]] || error "File size changed during restore"
2287 run_test 31b "Restore a large unaligned file and check size during restore"
2290 # test needs a running copytool
2295 local f=$DIR/$tdir/$tfile
2296 local fid=$(make_large_for_progress_aligned $f)
2297 [ $? != 0 ] && skip "not enough free space" && return
2299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2300 wait_request_state $fid ARCHIVE SUCCEED
2303 restore_and_check_size $f $fid
2306 [[ $err -eq 0 ]] || error "File size changed during restore"
2310 run_test 31c "Restore a large aligned file and check size during restore"
2313 # test needs a running copytool
2318 local f=$DIR/$tdir/$tfile
2319 local fid=$(make_large_for_progress $f)
2320 [ $? != 0 ] && skip "not enough free space" && return
2322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2323 wait_request_state $fid ARCHIVE SUCCEED
2326 # to be sure wait_all_done will not be mislead by previous tests
2329 wait_for_grace_delay
2330 # Also raise grace_delay significantly so the Canceled
2331 # Restore action will stay enough long avail.
2332 local old_grace=$(get_hsm_param grace_delay)
2333 set_hsm_param grace_delay 100
2335 md5sum $f >/dev/null &
2337 wait_request_state $fid RESTORE STARTED
2342 # Check restore trigger process was killed
2343 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2347 # instead of waiting+checking both Restore and Cancel ops
2348 # sequentially, wait for both to be finished and then check
2350 wait_all_done 100 $fid
2351 local rstate=$(get_request_state $fid RESTORE)
2352 local cstate=$(get_request_state $fid CANCEL)
2354 # restore orig grace_delay.
2355 set_hsm_param grace_delay $old_grace
2357 if [[ "$rstate" == "CANCELED" ]] ; then
2358 [[ "$cstate" == "SUCCEED" ]] ||
2359 error "Restore state is CANCELED and Cancel state " \
2360 "is not SUCCEED but $cstate"
2361 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2362 elif [[ "$rstate" == "SUCCEED" ]] ; then
2363 [[ "$cstate" == "FAILED" ]] ||
2364 error "Restore state is SUCCEED and Cancel state " \
2365 "is not FAILED but $cstate"
2366 echo "Restore state is SUCCEED, Cancel state is FAILED"
2368 error "Restore state is $rstate and Cancel state is $cstate"
2372 error "Cannot kill process waiting for restore ($killed)"
2376 run_test 33 "Kill a restore waiting process"
2379 # test needs a running copytool
2384 local f=$DIR/$tdir/$tfile
2385 local fid=$(make_large_for_progress $f)
2386 [ $? != 0 ] && skip "not enough free space" && return
2388 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2389 wait_request_state $fid ARCHIVE SUCCEED
2392 md5sum $f >/dev/null &
2394 wait_request_state $fid RESTORE STARTED
2396 rm $f || error "rm $f failed"
2397 # rm must not block during restore
2398 wait_request_state $fid RESTORE STARTED
2400 wait_request_state $fid RESTORE SUCCEED
2401 # check md5sum pgm finished
2402 local there=$(ps -o pid,comm hp $pid >/dev/null)
2403 [[ -z $there ]] || error "Restore initiator does not exit"
2405 local rc=$(wait $pid)
2406 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2410 run_test 34 "Remove file during restore"
2413 # test needs a running copytool
2418 local f=$DIR/$tdir/$tfile
2419 local f1=$DIR/$tdir/$tfile-1
2420 local fid=$(make_large_for_progress $f)
2421 [ $? != 0 ] && skip "not enough free space" && return
2423 local fid1=$(copy_file /etc/passwd $f1)
2424 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2425 wait_request_state $fid ARCHIVE SUCCEED
2428 md5sum $f >/dev/null &
2430 wait_request_state $fid RESTORE STARTED
2432 mv $f1 $f || error "mv $f1 $f failed"
2433 # mv must not block during restore
2434 wait_request_state $fid RESTORE STARTED
2436 wait_request_state $fid RESTORE SUCCEED
2437 # check md5sum pgm finished
2438 local there=$(ps -o pid,comm hp $pid >/dev/null)
2439 [[ -z $there ]] || error "Restore initiator does not exit"
2441 local rc=$(wait $pid)
2442 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2445 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2449 run_test 35 "Overwrite file during restore"
2452 # test needs a running copytool
2457 local f=$DIR/$tdir/$tfile
2458 local fid=$(make_large_for_progress $f)
2459 [ $? != 0 ] && skip "not enough free space" && return
2461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2462 wait_request_state $fid ARCHIVE SUCCEED
2465 md5sum $f >/dev/null &
2467 wait_request_state $fid RESTORE STARTED
2470 # rm must not block during restore
2471 wait_request_state $fid RESTORE STARTED
2473 wait_request_state $fid RESTORE SUCCEED
2474 # check md5sum pgm finished
2475 local there=$(ps -o pid,comm hp $pid >/dev/null)
2477 error "Restore initiator does not exit"
2479 local rc=$(wait $pid)
2481 error "Restore initiator failed with $rc"
2485 run_test 36 "Move file during restore"
2492 for n in $(seq 1 $count); do
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2495 echo "$count archive requests submitted"
2499 local stream_count=4
2500 local file_count=100
2502 local f=$DIR/$tdir/$tfile
2507 for i in $(seq 1 $file_count); do
2508 for p in $(seq 1 $stream_count); do
2509 fid=$(copy_file /etc/hosts $f.$p.$i)
2512 # force copytool to use a local/temp archive dir to ensure best
2513 # performance vs remote/NFS mounts used in auto-tests
2514 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2517 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2519 # to be sure wait_all_done will not be mislead by previous tests
2521 wait_for_grace_delay
2523 # start archive streams in background (archive files in parallel)
2524 for p in $(seq 1 $stream_count); do
2525 multi_archive $f.$p $file_count &
2528 echo -n "Wait for all requests being enqueued..."
2534 run_test 40 "Parallel archive requests"
2537 # test needs a running copytool
2541 local f=$DIR/$tdir/$tfile
2542 local fid=$(copy_file /etc/motd $f 1)
2544 $LFS hsm_archive $f || error "could not archive file"
2545 wait_request_state $fid ARCHIVE SUCCEED
2546 check_hsm_flags $f "0x00000009"
2548 multiop_bg_pause $f O_c || error "multiop failed"
2552 client_up || client_up || true
2554 kill -USR1 $MULTIPID
2555 wait $MULTIPID || error "multiop close failed"
2557 check_hsm_flags $f "0x0000000b"
2561 run_test 52 "Opened for write file on an evicted client should be set dirty"
2564 # test needs a running copytool
2568 local f=$DIR/$tdir/$tfile
2569 local fid=$(copy_file /etc/motd $f 1)
2571 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2572 error "could not archive file"
2573 wait_request_state $fid ARCHIVE SUCCEED
2574 check_hsm_flags $f "0x00000009"
2576 multiop_bg_pause $f o_c || error "multiop failed"
2580 client_up || client_up || true
2582 kill -USR1 $MULTIPID
2583 wait $MULTIPID || error "multiop close failed"
2585 check_hsm_flags $f "0x00000009"
2589 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2592 # test needs a running copytool
2596 local f=$DIR/$tdir/$tfile
2597 local fid=$(make_small $f)
2599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2600 error "could not archive file"
2601 wait_request_state $fid ARCHIVE STARTED
2603 check_hsm_flags $f "0x00000001"
2605 # Avoid coordinator resending this request as soon it has failed.
2610 wait_request_state $fid ARCHIVE FAILED
2612 check_hsm_flags $f "0x00000003"
2617 run_test 54 "Write during an archive cancels it"
2620 # test needs a running copytool
2624 local f=$DIR/$tdir/$tfile
2625 local fid=$(make_small $f)
2627 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2628 error "could not archive file"
2629 wait_request_state $fid ARCHIVE STARTED
2631 check_hsm_flags $f "0x00000001"
2633 # Avoid coordinator resending this request as soon it has failed.
2636 $TRUNCATE $f 1024 || error "truncate failed"
2638 wait_request_state $fid ARCHIVE FAILED
2640 check_hsm_flags $f "0x00000003"
2645 run_test 55 "Truncate during an archive cancels it"
2648 # test needs a running copytool
2652 local f=$DIR/$tdir/$tfile
2653 local fid=$(make_large_for_progress $f)
2654 [ $? != 0 ] && skip "not enough free space" && return
2656 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2657 error "could not archive file"
2658 wait_request_state $fid ARCHIVE STARTED
2660 check_hsm_flags $f "0x00000001"
2662 # Change metadata and sync to be sure we are not changing only
2667 wait_request_state $fid ARCHIVE SUCCEED
2669 check_hsm_flags $f "0x00000009"
2673 run_test 56 "Setattr during an archive is ok"
2676 # Need one client for I/O, one for request
2677 needclients 2 || return 0
2679 # test needs a running copytool
2683 local f=$DIR/$tdir/test_archive_remote
2684 # Create a file on a remote node
2685 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2686 "count=2 conv=fsync"
2689 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2690 error "hsm_archive failed"
2691 local fid=$(path2fid $f)
2692 wait_request_state $fid ARCHIVE SUCCEED
2694 # Release and implicit restore it
2695 do_node $CLIENT2 "$LFS hsm_release $f" ||
2696 error "hsm_release failed"
2697 do_node $CLIENT2 "md5sum $f" ||
2698 error "hsm_restore failed"
2700 wait_request_state $fid RESTORE SUCCEED
2704 run_test 57 "Archive a file with dirty cache on another node"
2706 truncate_released_file() {
2710 local sz=$(stat -c %s $src_file)
2711 local f=$DIR/$tdir/$tfile
2712 local fid=$(copy_file $1 $f)
2716 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2717 error "could not archive file"
2718 wait_request_state $fid ARCHIVE SUCCEED
2720 $LFS hsm_release $f || error "could not release file"
2722 $TRUNCATE $f $trunc_to || error "truncate failed"
2725 local sz1=$(stat -c %s $f)
2726 [[ $sz1 == $trunc_to ]] ||
2727 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2730 check_hsm_flags $f "0x0000000b"
2732 local state=$(get_request_state $fid RESTORE)
2733 [[ "$state" == "SUCCEED" ]] ||
2734 error "truncate $sz does not trig restore, state = $state"
2736 $TRUNCATE $ref $trunc_to
2737 cmp $ref $f || error "file data wrong after truncate"
2743 # test needs a running copytool
2748 local sz=$(stat -c %s /etc/passwd)
2750 echo "truncate up from $sz to $((sz*2))"
2751 truncate_released_file /etc/passwd $((sz*2))
2753 echo "truncate down from $sz to $((sz/2))"
2754 truncate_released_file /etc/passwd $((sz/2))
2756 echo "truncate to 0"
2757 truncate_released_file /etc/passwd 0
2761 run_test 58 "Truncate a released file will trigger restore"
2764 # This test validates the fix for LU-4512. Ensure that the -u
2765 # option changes the progress reporting interval from the
2766 # default (30 seconds) to the user-specified interval.
2768 local progress_timeout=$((interval * 4))
2770 # test needs a new running copytool
2772 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2775 local f=$DIR/$tdir/$tfile
2776 local fid=$(make_large_for_progress $f)
2777 [ $? != 0 ] && skip "not enough free space" && return
2780 local mdt=${MDT_PREFIX}${mdtidx}
2781 local mds=mds$((mdtidx + 1))
2783 # Wait for copytool to register
2784 wait_update_facet $mds \
2785 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2786 uuid 100 || error "coyptool failed to register with $mdt"
2788 local start_at=$(date +%s)
2789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2790 error "could not archive file"
2792 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2793 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2799 echo -n "Expecting a progress update within $progress_timeout seconds... "
2801 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2802 if [ $RESULT -gt 0 ]; then
2803 echo "$RESULT bytes copied in $WAIT seconds."
2805 elif [ $WAIT -ge $progress_timeout ]; then
2806 error "Timed out waiting for progress update!"
2809 WAIT=$((WAIT + sleep))
2813 local finish_at=$(date +%s)
2814 local elapsed=$((finish_at - start_at))
2816 # Ensure that the progress update occurred within the expected window.
2817 if [ $elapsed -lt $interval ]; then
2818 error "Expected progress update after at least $interval seconds"
2824 run_test 60 "Changing progress update interval from default"
2827 # test needs a new running copytool
2829 copytool_monitor_setup
2830 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2832 # Just start and stop the copytool to generate events.
2835 # Wait for the copytool to register.
2836 wait_update --verbose $(facet_active_host mds1) \
2837 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2839 error "copytool failed to register with MDT0000"
2843 local REGISTER_EVENT
2844 local UNREGISTER_EVENT
2845 while read event; do
2846 local parsed=$(parse_json_event "$event")
2847 if [ -z "$parsed" ]; then
2848 error "Copytool sent malformed event: $event"
2852 if [ $event_type == "REGISTER" ]; then
2853 REGISTER_EVENT=$event
2854 elif [ $event_type == "UNREGISTER" ]; then
2855 UNREGISTER_EVENT=$event
2857 done < <(echo $"$(get_copytool_event_log)")
2859 if [ -z "$REGISTER_EVENT" ]; then
2860 error "Copytool failed to send register event to FIFO"
2863 if [ -z "$UNREGISTER_EVENT" ]; then
2864 error "Copytool failed to send unregister event to FIFO"
2867 copytool_monitor_cleanup
2868 echo "Register/Unregister events look OK."
2870 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2873 # Bump progress interval for livelier events.
2876 # test needs a new running copytool
2878 copytool_monitor_setup
2879 HSMTOOL_UPDATE_INTERVAL=$interval \
2880 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2883 local f=$DIR/$tdir/$tfile
2884 local fid=$(make_large_for_progress $f)
2885 [ $? != 0 ] && skip "not enough free space" && return
2887 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2888 error "could not archive file"
2889 wait_request_state $fid ARCHIVE SUCCEED
2891 local expected_fields="event_time data_fid source_fid"
2892 expected_fields+=" total_bytes current_bytes"
2896 while read event; do
2897 # Make sure we're not getting anything from previous events.
2898 for field in $expected_fields; do
2902 local parsed=$(parse_json_event "$event")
2903 if [ -z "$parsed" ]; then
2904 error "Copytool sent malformed event: $event"
2908 if [ $event_type == "ARCHIVE_START" ]; then
2911 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2914 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2918 # Do some simple checking of the progress update events.
2919 for expected_field in $expected_fields; do
2920 if [ -z ${!expected_field+x} ]; then
2921 error "Missing $expected_field field in event"
2925 if [ $total_bytes -eq 0 ]; then
2926 error "Expected total_bytes to be > 0"
2929 # These should be identical throughout an archive
2931 if [ $source_fid != $data_fid ]; then
2932 error "Expected source_fid to equal data_fid"
2934 done < <(echo $"$(get_copytool_event_log)")
2936 if [ -z "$START_EVENT" ]; then
2937 error "Copytool failed to send archive start event to FIFO"
2940 if [ -z "$FINISH_EVENT" ]; then
2941 error "Copytool failed to send archive finish event to FIFO"
2944 echo "Archive events look OK."
2948 copytool_monitor_cleanup
2950 run_test 71 "Copytool logs JSON archive events to FIFO"
2953 # Bump progress interval for livelier events.
2956 # test needs a new running copytool
2958 copytool_monitor_setup
2959 HSMTOOL_UPDATE_INTERVAL=$interval \
2960 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2961 local test_file=$HSMTOOL_MONITOR_DIR/file
2963 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2965 do_facet $SINGLEAGT "$cmd" ||
2966 error "cannot create $test_file on $SINGLEAGT"
2967 copy2archive $test_file $tdir/$tfile
2970 local f=$DIR/$tdir/$tfile
2971 import_file $tdir/$tfile $f
2972 f=$DIR2/$tdir/$tfile
2973 echo "Verifying released state: "
2974 check_hsm_flags $f "0x0000000d"
2976 local fid=$(path2fid $f)
2978 wait_request_state $fid RESTORE SUCCEED
2980 local expected_fields="event_time data_fid source_fid"
2981 expected_fields+=" total_bytes current_bytes"
2985 while read event; do
2986 # Make sure we're not getting anything from previous events.
2987 for field in $expected_fields; do
2991 local parsed=$(parse_json_event "$event")
2992 if [ -z "$parsed" ]; then
2993 error "Copytool sent malformed event: $event"
2997 if [ $event_type == "RESTORE_START" ]; then
2999 if [ $source_fid != $data_fid ]; then
3000 error "source_fid should == data_fid at start"
3003 elif [ $event_type == "RESTORE_FINISH" ]; then
3005 if [ $source_fid != $data_fid ]; then
3006 error "source_fid should == data_fid at finish"
3009 elif [ $event_type != "RESTORE_RUNNING" ]; then
3013 # Do some simple checking of the progress update events.
3014 for expected_field in $expected_fields; do
3015 if [ -z ${!expected_field+x} ]; then
3016 error "Missing $expected_field field in event"
3020 if [ $total_bytes -eq 0 ]; then
3021 error "Expected total_bytes to be > 0"
3024 # When a restore starts out, the data fid is the same as the
3025 # source fid. After the restore has gotten going, we learn
3026 # the new data fid. Once the restore has finished, the source
3027 # fid is set to the new data fid.
3029 # We test this because some monitoring software may depend on
3030 # this behavior. If it changes, then the consumers of these
3031 # events may need to be modified.
3032 if [ $source_fid == $data_fid ]; then
3033 error "source_fid should != data_fid during restore"
3035 done < <(echo $"$(get_copytool_event_log)")
3037 if [ -z "$START_EVENT" ]; then
3038 error "Copytool failed to send restore start event to FIFO"
3041 if [ -z "$FINISH_EVENT" ]; then
3042 error "Copytool failed to send restore finish event to FIFO"
3045 echo "Restore events look OK."
3049 copytool_monitor_cleanup
3053 run_test 72 "Copytool logs JSON restore events to FIFO"
3056 file_count=51 # Max number of files constrained by LNET message size
3057 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3058 local f=$DIR/$tdir/$tfile
3059 local FILELIST=/tmp/filelist.txt
3063 for i in $(seq 1 $file_count); do
3064 fid=$(copy_file /etc/hosts $f.$i)
3065 echo $f.$i >> $FILELIST
3067 # force copytool to use a local/temp archive dir to ensure best
3068 # performance vs remote/NFS mounts used in auto-tests
3069 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3072 local dai=$(get_hsm_param default_archive_id)
3073 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3075 # to be sure wait_all_done will not be mislead by previous tests
3077 wait_for_grace_delay
3078 $LFS hsm_archive --filelist $FILELIST ||
3079 error "cannot archive a file list"
3081 $LFS hsm_release --filelist $FILELIST ||
3082 error "cannot release a file list"
3083 $LFS hsm_restore --filelist $FILELIST ||
3084 error "cannot restore a file list"
3088 run_test 90 "Archive/restore a file list"
3090 double_verify_reset_hsm_param() {
3092 echo "Testing $HSM_PARAM.$p"
3093 local val=$(get_hsm_param $p)
3095 local val2=$(($val * 2))
3096 set_hsm_param $p $val2
3097 val=$(get_hsm_param $p)
3098 [[ $val == $val2 ]] ||
3099 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3100 echo "Set $p to 0 must failed"
3104 set_hsm_param $p $save
3106 if [[ $rc == 0 ]]; then
3107 error "we must not be able to set $HSM_PARAM.$p to 0"
3112 double_verify_reset_hsm_param loop_period
3113 double_verify_reset_hsm_param grace_delay
3114 double_verify_reset_hsm_param active_request_timeout
3115 double_verify_reset_hsm_param max_requests
3116 double_verify_reset_hsm_param default_archive_id
3118 run_test 100 "Set coordinator /proc tunables"
3125 run_test 102 "Verify coordinator control"
3128 # test needs a running copytool
3135 for i in $(seq 1 20); do
3136 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3138 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3142 echo "Current requests"
3143 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3144 $HSM_PARAM.actions |\
3145 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3147 [[ -z "$res" ]] || error "Some request have not been canceled"
3151 run_test 103 "Purge all requests"
3156 # test needs a running copytool
3160 local f=$DIR/$tdir/$tfile
3161 local fid=$(make_large_for_progress $f)
3162 [ $? != 0 ] && skip "not enough free space" && return
3164 # if cdt is on, it can serve too quickly the request
3166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3167 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3168 $HSM_PARAM.actions |\
3169 grep $fid | cut -f16 -d=")
3172 [[ "$data1" == "$DATAHEX" ]] ||
3173 error "Data field in records is ($data1) and not ($DATAHEX)"
3177 run_test 104 "Copy tool data field"
3184 for i in $(seq -w 1 10); do
3185 cp /etc/passwd $DIR/$tdir/$i
3186 $LFS hsm_archive $DIR/$tdir/$i
3188 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3189 $HSM_PARAM.actions |\
3190 grep WAITING | wc -l")
3193 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3194 $HSM_PARAM.actions |\
3195 grep WAITING | wc -l")
3198 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3199 error "Requests count after shutdown $reqcnt2 != "\
3200 "before shutdown $reqcnt1"
3202 run_test 105 "Restart of coordinator"
3204 get_agent_by_uuid_mdt() {
3207 local mds=mds$(($mdtidx + 1))
3208 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3212 check_agent_registered_by_mdt() {
3215 local mds=mds$(($mdtidx + 1))
3216 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3217 if [[ ! -z "$agent" ]]; then
3218 echo "found agent $agent on $mds"
3220 error "uuid $uuid not found in agent list on $mds"
3224 check_agent_unregistered_by_mdt() {
3227 local mds=mds$(($mdtidx + 1))
3228 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3229 if [[ -z "$agent" ]]; then
3230 echo "uuid not found in agent list on $mds"
3232 error "uuid found in agent list on $mds: $agent"
3236 check_agent_registered() {
3239 for mdsno in $(seq 1 $MDSCOUNT); do
3240 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3244 check_agent_unregistered() {
3247 for mdsno in $(seq 1 $MDSCOUNT); do
3248 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3253 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3254 get_client_uuid $MOUNT | cut -d' ' -f2)
3257 check_agent_registered $uuid
3259 search_copytools || error "No copytool found"
3262 check_agent_unregistered $uuid
3265 check_agent_registered $uuid
3269 run_test 106 "Copytool register/unregister"
3272 # test needs a running copytool
3274 # create and archive file
3276 local f1=$DIR/$tdir/$tfile
3277 local fid=$(copy_file /etc/passwd $f1)
3278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3279 wait_request_state $fid ARCHIVE SUCCEED
3280 # shutdown and restart MDS
3282 # check the copytool still gets messages from MDT
3283 local f2=$DIR/$tdir/2
3284 local fid=$(copy_file /etc/passwd $f2)
3285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3286 # main check of this sanity: this request MUST succeed
3287 wait_request_state $fid ARCHIVE SUCCEED
3290 run_test 107 "Copytool re-register after MDS restart"
3292 policy_set_and_test()
3296 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3297 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3298 [[ "$policy" == "$target" ]] ||
3299 error "Wrong policy after '$change': '$policy' != '$target'"
3303 # to force default policy setting if error
3304 CDT_POLICY_HAD_CHANGED=true
3306 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3307 local default="NonBlockingRestore [NoRetryAction]"
3308 [[ "$policy" == "$default" ]] ||
3309 error "default policy has changed,"\
3310 " '$policy' != '$default' update the test"
3311 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3312 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3313 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3314 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3315 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3316 # useless bacause we know but safer for futur changes to use real value
3317 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3318 echo "Next set_param must failed"
3319 policy_set_and_test "wrong" "$policy"
3322 echo "Back to default policy"
3323 cdt_set_sanity_policy
3325 run_test 109 "Policy display/change"
3328 # test needs a running copytool
3333 copy2archive /etc/passwd $tdir/$tfile
3335 local f=$DIR/$tdir/$tfile
3336 import_file $tdir/$tfile $f
3337 local fid=$(path2fid $f)
3339 cdt_set_non_blocking_restore
3344 wait_request_state $fid RESTORE SUCCEED
3345 cdt_clear_non_blocking_restore
3349 error "md5sum returns $st != 1, "\
3350 "should also perror ENODATA (No data available)"
3354 run_test 110a "Non blocking restore policy (import case)"
3357 # test needs a running copytool
3361 local f=$DIR/$tdir/$tfile
3362 local fid=$(copy_file /etc/passwd $f)
3363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3364 wait_request_state $fid ARCHIVE SUCCEED
3367 cdt_set_non_blocking_restore
3372 wait_request_state $fid RESTORE SUCCEED
3373 cdt_clear_non_blocking_restore
3377 error "md5sum returns $st != 1, "\
3378 "should also perror ENODATA (No data available)"
3382 run_test 110b "Non blocking restore policy (release case)"
3385 # test needs a running copytool
3389 copy2archive /etc/passwd $tdir/$tfile
3391 local f=$DIR/$tdir/$tfile
3393 import_file $tdir/$tfile $f
3394 local fid=$(path2fid $f)
3398 copytool_remove_backend $fid
3401 wait_request_state $fid RESTORE FAILED
3408 [[ $st == 0 ]] || error "Restore does not failed"
3412 run_test 111a "No retry policy (import case), restore will error"\
3413 " (No such file or directory)"
3416 # test needs a running copytool
3420 local f=$DIR/$tdir/$tfile
3421 local fid=$(copy_file /etc/passwd $f)
3423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3424 wait_request_state $fid ARCHIVE SUCCEED
3427 copytool_remove_backend $fid
3430 wait_request_state $fid RESTORE FAILED
3437 [[ $st == 0 ]] || error "Restore does not failed"
3441 run_test 111b "No retry policy (release case), restore will error"\
3442 " (No such file or directory)"
3445 # test needs a running copytool
3449 local f=$DIR/$tdir/$tfile
3450 local fid=$(copy_file /etc/passwd $f)
3452 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3453 local l=$($LFS hsm_action $f)
3455 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3459 wait_request_state $fid ARCHIVE SUCCEED
3462 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3466 run_test 112 "State of recorded request"
3469 # test needs a running copytool
3473 local f=$DIR/$tdir/$tfile
3474 local fid=$(make_large_for_cancel $f)
3475 [ $? != 0 ] && skip "not enough free space" && return
3477 # test with cdt on is made in test_221
3479 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3482 wait_request_state $fid ARCHIVE CANCELED
3483 wait_request_state $fid CANCEL SUCCEED
3487 run_test 200 "Register/Cancel archive"
3490 # test needs a running copytool
3494 local f=$DIR/$tdir/$tfile
3495 make_archive $tdir/$tfile
3496 import_file $tdir/$tfile $f
3497 local fid=$(path2fid $f)
3499 # test with cdt on is made in test_222
3504 wait_request_state $fid RESTORE CANCELED
3505 wait_request_state $fid CANCEL SUCCEED
3509 run_test 201 "Register/Cancel restore"
3512 # test needs a running copytool
3516 local f=$DIR/$tdir/$tfile
3517 local fid=$(make_large_for_progress $f)
3518 [ $? != 0 ] && skip "not enough free space" && return
3520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3521 wait_request_state $fid ARCHIVE SUCCEED
3527 wait_request_state $fid REMOVE CANCELED
3531 run_test 202 "Register/Cancel remove"
3534 # test needs a running copytool
3539 local f=$DIR/$tdir/$tfile
3540 local fid=$(copy_file /etc/passwd $f)
3544 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3545 wait_request_state $fid ARCHIVE SUCCEED
3547 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3551 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3555 run_test 220 "Changelog for archive"
3558 # test needs a running copytool
3563 local f=$DIR/$tdir/$tfile
3564 local fid=$(make_large_for_cancel $f)
3565 [ $? != 0 ] && skip "not enough free space" && return
3569 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3570 wait_request_state $fid ARCHIVE STARTED
3572 wait_request_state $fid ARCHIVE CANCELED
3573 wait_request_state $fid CANCEL SUCCEED
3575 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3578 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3582 run_test 221 "Changelog for archive canceled"
3585 # test needs a running copytool
3589 copy2archive /etc/passwd $tdir/$tfile
3591 local f=$DIR/$tdir/$tfile
3592 import_file $tdir/$tfile $f
3593 local fid=$(path2fid $f)
3598 wait_request_state $fid RESTORE SUCCEED
3600 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3603 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3607 run_test 222a "Changelog for explicit restore"
3610 # test needs a running copytool
3614 local f=$DIR/$tdir/$tfile
3615 local fid=$(copy_file /etc/passwd $f)
3618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3619 wait_request_state $fid ARCHIVE SUCCEED
3624 wait_request_state $fid RESTORE SUCCEED
3626 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3629 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3633 run_test 222b "Changelog for implicit restore"
3636 # test needs a running copytool
3641 local f=$DIR/$tdir/$tfile
3642 make_archive $tdir/$tfile
3646 import_file $tdir/$tfile $f
3647 local fid=$(path2fid $f)
3650 wait_request_state $fid RESTORE STARTED
3652 wait_request_state $fid RESTORE CANCELED
3653 wait_request_state $fid CANCEL SUCCEED
3655 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3658 [[ $flags == $target ]] ||
3659 error "Changelog flag is $flags not $target"
3663 run_test 223a "Changelog for restore canceled (import case)"
3666 # test needs a running copytool
3671 local f=$DIR/$tdir/$tfile
3672 local fid=$(make_large_for_progress $f)
3673 [ $? != 0 ] && skip "not enough free space" && return
3676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3677 wait_request_state $fid ARCHIVE SUCCEED
3680 wait_request_state $fid RESTORE STARTED
3682 wait_request_state $fid RESTORE CANCELED
3683 wait_request_state $fid CANCEL SUCCEED
3685 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3688 [[ $flags == $target ]] ||
3689 error "Changelog flag is $flags not $target"
3693 run_test 223b "Changelog for restore canceled (release case)"
3696 # test needs a running copytool
3701 local f=$DIR/$tdir/$tfile
3702 local fid=$(copy_file /etc/passwd $f)
3705 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3706 wait_request_state $fid ARCHIVE SUCCEED
3709 wait_request_state $fid REMOVE SUCCEED
3711 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3714 [[ $flags == $target ]] ||
3715 error "Changelog flag is $flags not $target"
3719 run_test 224 "Changelog for remove"
3722 # test needs a running copytool
3725 # test is not usable because remove request is too fast
3726 # so it is always finished before cancel can be done ...
3727 echo "Test disabled"
3732 local f=$DIR/$tdir/$tfile
3733 local fid=$(make_large_for_progress $f)
3734 [ $? != 0 ] && skip "not enough free space" && return
3737 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3738 wait_request_state $fid ARCHIVE SUCCEED
3740 # if cdt is on, it can serve too quickly the request
3745 wait_request_state $fid REMOVE CANCELED
3746 wait_request_state $fid CANCEL SUCCEED
3748 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3749 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3750 tail -n 1 | awk '{print $5}')
3753 [[ $flags == $target ]] ||
3754 error "Changelog flag is $flags not $target"
3758 run_test 225 "Changelog for remove canceled"
3761 # test needs a running copytool
3766 local f1=$DIR/$tdir/$tfile-1
3767 local f2=$DIR/$tdir/$tfile-2
3768 local f3=$DIR/$tdir/$tfile-3
3769 local fid1=$(copy_file /etc/passwd $f1)
3770 local fid2=$(copy_file /etc/passwd $f2)
3771 copy_file /etc/passwd $f3
3774 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3775 wait_request_state $fid1 ARCHIVE SUCCEED
3777 $LFS hsm_archive $f2
3778 wait_request_state $fid2 ARCHIVE SUCCEED
3780 rm $f1 || error "rm $f1 failed"
3782 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3785 [[ $flags == $target ]] ||
3786 error "Changelog flag is $flags not $target"
3788 mv $f3 $f2 || error "mv $f3 $f2 failed"
3790 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3793 [[ $flags == $target ]] ||
3794 error "Changelog flag is $flags not $target"
3798 run_test 226 "changelog for last rm/mv with exiting archive"
3800 check_flags_changes() {
3808 $LFS hsm_set --$hsm_flag $f ||
3809 error "Cannot set $hsm_flag on $f"
3810 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3811 local seen=${#flags[*]}
3813 [[ $seen == $cnt ]] ||
3814 error "set $hsm_flag: Changelog events $seen != $cnt"
3815 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3816 error "set $hsm_flag: Changelog flags are "\
3817 "${flags[$((cnt - 1))]} not $target"
3819 $LFS hsm_clear --$hsm_flag $f ||
3820 error "Cannot clear $hsm_flag on $f"
3821 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3824 [[ $cnt == $seen ]] ||
3825 error "clear $hsm_flag: Changelog events $seen != $cnt"
3827 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3828 error "clear $hsm_flag: Changelog flag is "\
3829 "${flags[$((cnt - 1))]} not $target"
3833 # test needs a running copytool
3840 for i in norelease noarchive exists archived
3842 local f=$DIR/$tdir/$tfile-$i
3843 local fid=$(copy_file /etc/passwd $f)
3844 check_flags_changes $f $fid $i 0 1
3847 f=$DIR/$tdir/$tfile---lost
3848 fid=$(copy_file /etc/passwd $f)
3849 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3850 wait_request_state $fid ARCHIVE SUCCEED
3851 check_flags_changes $f $fid lost 3 1
3855 run_test 227 "changelog when explicit setting of HSM flags"
3858 # test needs a running copytool
3861 local fid=$(make_small_sync $DIR/$tfile)
3862 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3863 wait_request_state $fid ARCHIVE SUCCEED
3865 $LFS hsm_release $DIR/$tfile
3866 check_hsm_flags $DIR/$tfile "0x0000000d"
3868 filefrag $DIR/$tfile | grep " 1 extent found" ||
3869 error "filefrag on released file must return only one extent"
3871 # only newer versions of cp detect sparse files by stat/FIEMAP
3873 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3874 error "copying $DIR/$tfile"
3875 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3877 $LFS hsm_release $DIR/$tfile
3878 check_hsm_flags $DIR/$tfile "0x0000000d"
3880 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3882 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3884 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3885 error "comparing untarred $DIR/$tfile"
3887 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3888 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3891 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3894 # test needs a running copytool
3898 local maxrequest=$(get_hsm_param max_requests)
3899 local rqcnt=$(($maxrequest * 3))
3903 for i in $(seq -w 1 $rqcnt); do
3905 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3907 # we do it in 2 steps, so all requests arrive at the same time
3908 for i in $(seq -w 1 $rqcnt); do
3909 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3914 while [[ $cnt != 0 || $wt != 0 ]]; do
3916 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3917 $HSM_PARAM.actions |\
3918 grep STARTED | grep -v CANCEL | wc -l")
3919 [[ $cnt -le $maxrequest ]] ||
3920 error "$cnt > $maxrequest too many started requests"
3921 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3922 $HSM_PARAM.actions |\
3923 grep WAITING | wc -l")
3924 echo "max=$maxrequest started=$cnt waiting=$wt"
3929 run_test 250 "Coordinator max request"
3932 # test needs a running copytool
3936 local f=$DIR/$tdir/$tfile
3937 local fid=$(make_large_for_cancel $f)
3938 [ $? != 0 ] && skip "not enough free space" && return
3941 # to have a short test
3942 local old_to=$(get_hsm_param active_request_timeout)
3943 set_hsm_param active_request_timeout 4
3944 # to be sure the cdt will wake up frequently so
3945 # it will be able to cancel the "old" request
3946 local old_loop=$(get_hsm_param loop_period)
3947 set_hsm_param loop_period 2
3950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3951 wait_request_state $fid ARCHIVE STARTED
3953 wait_request_state $fid ARCHIVE CANCELED
3955 set_hsm_param active_request_timeout $old_to
3956 set_hsm_param loop_period $old_loop
3960 run_test 251 "Coordinator request timeout"
3963 # the only way to test ondisk conf is to restart MDS ...
3964 echo "Stop coordinator and remove coordinator state at mount"
3967 # clean on disk conf set by default
3968 cdt_clear_mount_state
3969 cdt_check_state stopped
3971 # check cdt still off after umount/remount
3973 cdt_check_state stopped
3975 echo "Set coordinator start at mount, and start coordinator"
3976 cdt_set_mount_state enabled
3979 cdt_check_state enabled
3981 # check cdt still on after umount/remount
3983 cdt_check_state enabled
3985 # we are back to original state (cdt started at mount)
3987 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3990 local ai=$(get_hsm_param default_archive_id)
3991 local new=$((ai + 1))
3993 set_hsm_param default_archive_id $new -P
3995 local res=$(get_hsm_param default_archive_id)
3998 set_hsm_param default_archive_id "" "-P -d"
4000 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4002 run_test 301 "HSM tunnable are persistent"
4005 local ai=$(get_hsm_param default_archive_id)
4006 local new=$((ai + 1))
4011 set_hsm_param default_archive_id $new -P
4014 for mdtno in $(seq 1 $MDSCOUNT); do
4019 cdt_check_state enabled
4021 local res=$(get_hsm_param default_archive_id)
4024 set_hsm_param default_archive_id "" "-P -d"
4026 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4028 run_test 302 "HSM tunnable are persistent when CDT is off"
4031 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4037 local dir_mdt0=$DIR/$tdir/mdt0
4038 local dir_mdt1=$DIR/$tdir/mdt1
4040 # create 1 dir per MDT
4041 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4042 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4044 # create 1 file in each MDT
4045 local fid1=$(make_small $dir_mdt0/$tfile)
4046 local fid2=$(make_small $dir_mdt1/$tfile)
4048 # check that hsm request on mdt0 is sent to the right MDS
4049 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4050 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4051 echo "archive successful on mdt0"
4053 # check that hsm request on mdt1 is sent to the right MDS
4054 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4055 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4056 echo "archive successful on mdt1"
4059 # clean test files and directories
4060 rm -rf $dir_mdt0 $dir_mdt1
4062 run_test 400 "Single request is sent to the right MDT"
4065 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4071 local dir_mdt0=$DIR/$tdir/mdt0
4072 local dir_mdt1=$DIR/$tdir/mdt1
4074 # create 1 dir per MDT
4075 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4076 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4078 # create 1 file in each MDT
4079 local fid1=$(make_small $dir_mdt0/$tfile)
4080 local fid2=$(make_small $dir_mdt1/$tfile)
4082 # check that compound requests are shunt to the rights MDTs
4083 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4084 error "lfs hsm_archive"
4085 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4086 echo "archive successful on mdt0"
4087 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4088 echo "archive successful on mdt1"
4091 # clean test files and directories
4092 rm -rf $dir_mdt0 $dir_mdt1
4094 run_test 401 "Compound requests split and sent to their respective MDTs"
4096 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4101 local node=$(facet_active_host $facet)
4103 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4104 awk '{print $4}'); do
4105 echo "$3 $mdc on $node"
4106 do_facet $facet "$LCTL --device $mdc $state" || return 1
4111 # make sure there is no running copytool
4114 # deactivate all mdc on agent1
4115 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4117 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4119 check_agent_unregistered "uuid" # match any agent
4121 # no expected running copytool
4122 search_copytools $agent && error "Copytool start should have failed"
4125 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4127 run_test 402 "Copytool start fails if all MDTs are inactive"
4130 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4132 # make sure there is no running copytool
4135 local agent=$(facet_active_host $SINGLEAGT)
4136 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4138 # deactivate all mdc for MDT0001
4139 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4142 # check the agent is registered on MDT0000, and not on MDT0001
4143 check_agent_registered_by_mdt $uuid 0
4144 check_agent_unregistered_by_mdt $uuid 1
4146 # check running copytool process
4147 search_copytools $agent || error "No running copytools on $agent"
4149 # reactivate all mdc for MDT0001
4150 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4152 # make sure the copytool is now registered to all MDTs
4153 check_agent_registered $uuid
4157 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4160 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4164 # create files on both MDT0000 and MDT0001
4167 local dir_mdt0=$DIR/$tdir/mdt0
4168 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4170 # create 1 file on mdt0
4171 local fid1=$(make_small $dir_mdt0/$tfile)
4173 # deactivate all mdc for MDT0001
4174 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4176 # send an HSM request for files in MDT0000
4177 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4179 # check for completion of files in MDT0000
4180 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4181 echo "archive successful on mdt0"
4183 # reactivate all mdc for MDT0001
4184 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4187 # clean test files and directories
4190 run_test 404 "Inactive MDT does not block requests for active MDTs"
4193 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4199 local striped_dir=$DIR/$tdir/striped_dir
4201 # create striped dir on all of MDTs
4202 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4204 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4205 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4206 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4207 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4209 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4210 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4211 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4212 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4214 # check that compound requests are shunt to the rights MDTs
4215 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4216 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4217 error "lfs hsm_archive"
4219 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4220 echo "archive successful on $fid1"
4221 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4222 echo "archive successful on $fid2"
4223 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4224 echo "archive successful on $fid3"
4225 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4226 echo "archive successful on $fid4"
4228 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4229 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4230 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4231 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4233 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4234 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4235 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4236 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4240 run_test 405 "archive and release under striped directory"
4245 check_and_cleanup_lustre