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 '[]'
520 if [[ $u == "user" ]]; then
521 local st=$($RUNAS $LFS hsm_state $f)
523 local st=$($LFS hsm_state $f)
527 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
529 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
533 get_hsm_archive_id() {
535 local st=$($LFS hsm_state $f)
536 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
538 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
547 local st=$(get_hsm_flags $f)
548 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
551 check_hsm_flags_user() {
555 local st=$(get_hsm_flags $f user)
556 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
559 file_creation_failure() {
565 error "cannot create $f with $cmd, status=$err"
577 if [[ "$3" != 1 ]]; then
581 cp $1 $f || file_creation_failure cp $f $?
583 path2fid $f || error "cannot get fid on $f"
587 local file2=${1/$DIR/$DIR2}
588 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
589 file_creation_failure dd $file2 $?
591 path2fid $1 || error "cannot get fid on $1"
595 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
596 file_creation_failure dd $1 $?
597 path2fid $1 || error "cannot get fid on $1"
600 cleanup_large_files() {
601 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
603 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
606 check_enough_free_space() {
609 local need=$((nb * unit /1024))
610 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
611 (( $need >= $free )) && return 1
615 make_large_for_striping() {
616 local file2=${1/$DIR/$DIR2}
617 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
621 check_enough_free_space 5 $sz
622 [ $? != 0 ] && return $?
624 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
625 file_creation_failure dd $file2 $?
627 path2fid $1 || error "cannot get fid on $1"
630 make_large_for_progress() {
631 local file2=${1/$DIR/$DIR2}
635 check_enough_free_space 39 1000000
636 [ $? != 0 ] && return $?
638 # big file is large enough, so copy time is > 30s
639 # so copytool make 1 progress
640 # size is not a multiple of 1M to avoid stripe
642 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
643 file_creation_failure dd $file2 $?
645 path2fid $1 || error "cannot get fid on $1"
648 make_large_for_progress_aligned() {
649 local file2=${1/$DIR/$DIR2}
653 check_enough_free_space 33 1048576
654 [ $? != 0 ] && return $?
656 # big file is large enough, so copy time is > 30s
657 # so copytool make 1 progress
658 # size is a multiple of 1M to have stripe
660 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
661 file_creation_failure dd $file2 $?
662 path2fid $1 || error "cannot get fid on $1"
665 make_large_for_cancel() {
666 local file2=${1/$DIR/$DIR2}
670 check_enough_free_space 103 1048576
671 [ $? != 0 ] && return $?
673 # Copy timeout is 100s. 105MB => 105s
674 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
675 file_creation_failure dd $file2 $?
676 path2fid $1 || error "cannot get fid on $1"
682 wait_update --verbose $(facet_active_host $facet) "$@"
685 wait_request_state() {
689 # 4th arg (mdt index) is optional
691 local mds=mds$(($mdtidx + 1))
693 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
694 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
696 wait_result $mds "$cmd" $state 100 ||
697 error "request on $fid is not $state on $mds"
700 get_request_state() {
704 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
705 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
708 get_request_count() {
712 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
713 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
720 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
721 [[ -n $fid ]] && cmd+=" | grep '$fid'"
722 cmd+=" | egrep 'WAITING|STARTED'"
724 wait_result $SINGLEMDS "$cmd" "" $timeout ||
725 error "requests did not complete"
728 wait_for_grace_delay() {
729 local val=$(get_hsm_param grace_delay)
736 # python2.6 in EL6 includes an internal json module
737 local json_parser='import json; import fileinput;'
738 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
739 json_parser+='json.loads([line for line in '
740 json_parser+='fileinput.input()][0]).items()])'
742 echo $raw_event | python -c "$json_parser"
745 # populate MDT device array
751 # cleanup from previous bad setup
752 search_and_kill_copytool
754 # for recovery tests, coordinator needs to be started at mount
756 # the lustre conf must be without hsm on (like for sanity.sh)
757 echo "Set HSM on and start"
758 cdt_set_mount_state enabled
759 cdt_check_state enabled
761 echo "Start copytool"
764 echo "Set sanity-hsm HSM policy"
765 cdt_set_sanity_policy
767 # finished requests are quickly removed from list
768 set_hsm_param grace_delay 10
774 local f=$DIR/$tdir/$tfile
778 check_hsm_flags_user $f "0x00000000"
780 $RUNAS $LFS hsm_set --norelease $f ||
781 error "user could not change hsm flags"
782 check_hsm_flags_user $f "0x00000010"
784 $RUNAS $LFS hsm_clear --norelease $f ||
785 error "user could not clear hsm flags"
786 check_hsm_flags_user $f "0x00000000"
788 # User could not change those flags...
789 $RUNAS $LFS hsm_set --exists $f &&
790 error "user should not set this flag"
791 check_hsm_flags_user $f "0x00000000"
794 $LFS hsm_set --exists $f ||
795 error "root could not change hsm flags"
796 check_hsm_flags_user $f "0x00000001"
798 $LFS hsm_clear --exists $f ||
799 error "root could not clear hsm state"
800 check_hsm_flags_user $f "0x00000000"
803 run_test 1 "lfs hsm flags root/non-root access"
807 local f=$DIR/$tdir/$tfile
809 # New files are not dirty
810 check_hsm_flags $f "0x00000000"
812 # For test, we simulate an archived file.
813 $LFS hsm_set --exists $f || error "user could not change hsm flags"
814 check_hsm_flags $f "0x00000001"
816 # chmod do not put the file dirty
817 chmod 600 $f || error "could not chmod test file"
818 check_hsm_flags $f "0x00000001"
820 # chown do not put the file dirty
821 chown $RUNAS_ID $f || error "could not chown test file"
822 check_hsm_flags $f "0x00000001"
824 # truncate put the file dirty
825 $TRUNCATE $f 1 || error "could not truncate test file"
826 check_hsm_flags $f "0x00000003"
828 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
829 check_hsm_flags $f "0x00000001"
831 run_test 2 "Check file dirtyness when doing setattr"
837 # New files are not dirty
839 check_hsm_flags $f "0x00000000"
841 # For test, we simulate an archived file.
842 $LFS hsm_set --exists $f ||
843 error "user could not change hsm flags"
844 check_hsm_flags $f "0x00000001"
846 # Reading a file, does not set dirty
847 cat $f > /dev/null || error "could not read file"
848 check_hsm_flags $f "0x00000001"
850 # Open for write without modifying data, does not set dirty
851 openfile -f O_WRONLY $f || error "could not open test file"
852 check_hsm_flags $f "0x00000001"
854 # Append to a file sets it dirty
855 cp -p /etc/passwd $f.append || error "could not create file"
856 $LFS hsm_set --exists $f.append ||
857 error "user could not change hsm flags"
858 dd if=/etc/passwd of=$f.append bs=1 count=3\
859 conv=notrunc oflag=append status=noxfer ||
860 file_creation_failure dd $f.append $?
861 check_hsm_flags $f.append "0x00000003"
863 # Modify a file sets it dirty
864 cp -p /etc/passwd $f.modify || error "could not create file"
865 $LFS hsm_set --exists $f.modify ||
866 error "user could not change hsm flags"
867 dd if=/dev/zero of=$f.modify bs=1 count=3\
868 conv=notrunc status=noxfer ||
869 file_creation_failure dd $f.modify $?
870 check_hsm_flags $f.modify "0x00000003"
872 # Open O_TRUNC sets dirty
873 cp -p /etc/passwd $f.trunc || error "could not create file"
874 $LFS hsm_set --exists $f.trunc ||
875 error "user could not change hsm flags"
876 cp /etc/group $f.trunc || error "could not override a file"
877 check_hsm_flags $f.trunc "0x00000003"
879 # Mmapped a file sets dirty
880 cp -p /etc/passwd $f.mmap || error "could not create file"
881 $LFS hsm_set --exists $f.mmap ||
882 error "user could not change hsm flags"
883 multiop $f.mmap OSMWUc || error "could not mmap a file"
884 check_hsm_flags $f.mmap "0x00000003"
886 run_test 3 "Check file dirtyness when opening for write"
890 local f=$DIR/$tdir/$tfile
891 local fid=$(make_small $f)
894 local st=$(get_request_state $fid CANCEL)
895 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
897 run_test 4 "Useless cancel must not be registered"
900 # test needs a running copytool
904 local f=$DIR/$tdir/$tfile
905 local fid=$(copy_file /etc/passwd $f)
907 wait_request_state $fid ARCHIVE SUCCEED
909 check_hsm_flags $f "0x00000009"
913 run_test 8 "Test default archive number"
917 local f=$DIR/$tdir/$tfile
918 local fid=$(copy_file /etc/passwd $f)
919 # we do not use the default one to be sure
920 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
922 copytool_setup $SINGLEAGT $MOUNT $new_an
923 $LFS hsm_archive --archive $new_an $f
924 wait_request_state $fid ARCHIVE SUCCEED
926 check_hsm_flags $f "0x00000009"
930 run_test 9 "Use of explict archive number, with dedicated copytool"
933 needclients 3 || return 0
939 copytool_cleanup $(comma_list $(agts_nodes))
941 # start all of the copytools
942 for n in $(seq $AGTCOUNT); do
946 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
949 for n in $(seq $AGTCOUNT); do
950 file=$DIR/$tdir/$tfile.$n
951 fid=$(make_small $file)
953 $LFS hsm_archive $file || error "could not archive file $file"
954 wait_request_state $fid ARCHIVE SUCCEED
955 check_hsm_flags $file "0x00000009"
959 copytool_cleanup $(comma_list $(agts_nodes))
961 run_test 9a "Multiple remote agents"
964 # test needs a running copytool
967 mkdir -p $DIR/$tdir/d1
968 local f=$DIR/$tdir/$tfile
969 local fid=$(copy_file /etc/hosts $f)
970 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
971 error "hsm_archive failed"
972 wait_request_state $fid ARCHIVE SUCCEED
974 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
975 error "fid $fid not in archive $HSM_ARCHIVE"
976 echo "Verifying content"
977 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
978 echo "Verifying hsm state "
979 check_hsm_flags $f "0x00000009"
981 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
982 local st=$(get_hsm_archive_id $f)
983 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
984 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
989 run_test 10a "Archive a file"
992 # test needs a running copytool
996 local f=$DIR/$tdir/$tfile
997 local fid=$(copy_file /etc/hosts $f)
998 $LFS hsm_archive $f || error "archive request failed"
999 wait_request_state $fid ARCHIVE SUCCEED
1001 $LFS hsm_archive $f || error "archive of non dirty file failed"
1002 local cnt=$(get_request_count $fid ARCHIVE)
1003 [[ "$cnt" == "1" ]] ||
1004 error "archive of non dirty file must not make a request"
1008 run_test 10b "Archive of non dirty file must work without doing request"
1011 # test needs a running copytool
1015 local f=$DIR/$tdir/$tfile
1016 local fid=$(copy_file /etc/hosts $f)
1017 $LFS hsm_set --noarchive $f
1018 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1022 run_test 10c "Check forbidden archive"
1025 # test needs a running copytool
1029 local f=$DIR/$tdir/$tfile
1030 local fid=$(copy_file /etc/hosts $f)
1031 $LFS hsm_archive $f || error "cannot archive $f"
1032 wait_request_state $fid ARCHIVE SUCCEED
1034 local ar=$(get_hsm_archive_id $f)
1035 local dflt=$(get_hsm_param default_archive_id)
1036 [[ $ar == $dflt ]] ||
1037 error "archived file is not on default archive: $ar != $dflt"
1041 run_test 10d "Archive a file on the default archive id"
1045 copy2archive /etc/hosts $tdir/$tfile
1046 local f=$DIR/$tdir/$tfile
1048 import_file $tdir/$tfile $f
1049 echo -n "Verifying released state: "
1050 check_hsm_flags $f "0x0000000d"
1052 local LSZ=$(stat -c "%s" $f)
1053 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1055 echo "Verifying imported size $LSZ=$ASZ"
1056 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1057 echo -n "Verifying released pattern: "
1058 local PTRN=$($GETSTRIPE -L $f)
1060 [[ $PTRN == 80000001 ]] || error "Is not released"
1061 local fid=$(path2fid $f)
1062 echo "Verifying new fid $fid in archive"
1064 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1065 error "fid $fid not in archive $HSM_ARCHIVE"
1067 run_test 11a "Import a file"
1070 # test needs a running copytool
1074 local f=$DIR/$tdir/$tfile
1075 local fid=$(copy_file /etc/hosts $f)
1076 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1077 error "hsm_archive failed"
1078 wait_request_state $fid ARCHIVE SUCCEED
1080 local FILE_HASH=$(md5sum $f)
1085 echo "$FILE_HASH" | md5sum -c
1087 [[ $? -eq 0 ]] || error "Restored file differs"
1091 run_test 11b "Import a deleted file using its FID"
1094 # test needs a running copytool
1098 copy2archive /etc/hosts $tdir/$tfile
1100 local f=$DIR/$tdir/$tfile
1101 import_file $tdir/$tfile $f
1102 local f2=$DIR2/$tdir/$tfile
1103 echo "Verifying released state: "
1104 check_hsm_flags $f2 "0x0000000d"
1106 local fid=$(path2fid $f2)
1107 $LFS hsm_restore $f2
1108 wait_request_state $fid RESTORE SUCCEED
1110 echo "Verifying file state: "
1111 check_hsm_flags $f2 "0x00000009"
1113 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1115 [[ $? -eq 0 ]] || error "Restored file differs"
1119 run_test 12a "Restore an imported file explicitly"
1122 # test needs a running copytool
1126 copy2archive /etc/hosts $tdir/$tfile
1128 local f=$DIR/$tdir/$tfile
1129 import_file $tdir/$tfile $f
1130 echo "Verifying released state: "
1131 check_hsm_flags $f "0x0000000d"
1133 cat $f > /dev/null || error "File read failed"
1135 echo "Verifying file state after restore: "
1136 check_hsm_flags $f "0x00000009"
1138 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1140 [[ $? -eq 0 ]] || error "Restored file differs"
1144 run_test 12b "Restore an imported file implicitly"
1147 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1149 # test needs a running copytool
1153 local f=$DIR/$tdir/$tfile
1154 $LFS setstripe -c 2 $f
1155 local fid=$(make_large_for_striping $f)
1156 [ $? != 0 ] && skip "not enough free space" && return
1158 local FILE_CRC=$(md5sum $f)
1160 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1161 wait_request_state $fid ARCHIVE SUCCEED
1162 $LFS hsm_release $f || error "release $f failed"
1164 echo "$FILE_CRC" | md5sum -c
1166 [[ $? -eq 0 ]] || error "Restored file differs"
1170 run_test 12c "Restore a file with stripe of 2"
1173 # test needs a running copytool
1178 local f=$DIR/$tdir/$tfile
1179 local fid=$(copy_file /etc/hosts $f)
1180 $LFS hsm_restore $f || error "restore of non archived file failed"
1181 local cnt=$(get_request_count $fid RESTORE)
1182 [[ "$cnt" == "0" ]] ||
1183 error "restore non archived must not make a request"
1184 $LFS hsm_archive $f ||
1185 error "archive request failed"
1186 wait_request_state $fid ARCHIVE SUCCEED
1187 $LFS hsm_restore $f ||
1188 error "restore of non released file failed"
1189 local cnt=$(get_request_count $fid RESTORE)
1190 [[ "$cnt" == "0" ]] ||
1191 error "restore a non dirty file must not make a request"
1195 run_test 12d "Restore of a non archived, non released file must work"\
1196 " without doing request"
1199 # test needs a running copytool
1202 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1203 local f=$DIR/$tdir/$tfile
1204 local fid=$(copy_file /etc/hosts $f)
1205 $LFS hsm_archive $f || error "archive request failed"
1206 wait_request_state $fid ARCHIVE SUCCEED
1209 cat /etc/hosts >> $f
1213 $LFS hsm_restore $f && error "restore a dirty file must fail"
1217 run_test 12e "Check forbidden restore"
1220 # test needs a running copytool
1224 local f=$DIR/$tdir/$tfile
1225 local fid=$(copy_file /etc/hosts $f)
1227 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1228 wait_request_state $fid ARCHIVE SUCCEED
1229 $LFS hsm_release $f || error "release of $f failed"
1231 wait_request_state $fid RESTORE SUCCEED
1233 echo -n "Verifying file state: "
1234 check_hsm_flags $f "0x00000009"
1236 diff -q /etc/hosts $f
1238 [[ $? -eq 0 ]] || error "Restored file differs"
1242 run_test 12f "Restore a released file explicitly"
1245 # test needs a running copytool
1249 local f=$DIR/$tdir/$tfile
1250 local fid=$(copy_file /etc/hosts $f)
1252 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1253 wait_request_state $fid ARCHIVE SUCCEED
1254 $LFS hsm_release $f || error "release of $f failed"
1256 diff -q /etc/hosts $f
1259 # we check we had a restore done
1260 wait_request_state $fid RESTORE SUCCEED
1262 [[ $st -eq 0 ]] || error "Restored file differs"
1266 run_test 12g "Restore a released file implicitly"
1269 needclients 2 || return 0
1271 # test needs a running copytool
1275 local f=$DIR/$tdir/$tfile
1276 local fid=$(copy_file /etc/hosts $f)
1278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1279 wait_request_state $fid ARCHIVE SUCCEED
1280 $LFS hsm_release $f || error "release of $f failed"
1282 do_node $CLIENT2 diff -q /etc/hosts $f
1285 # we check we had a restore done
1286 wait_request_state $fid RESTORE SUCCEED
1288 [[ $st -eq 0 ]] || error "Restored file differs"
1292 run_test 12h "Restore a released file implicitly from a second node"
1295 # test needs a running copytool
1299 local f=$DIR/$tdir/$tfile
1300 local fid=$(copy_file /etc/passwd $f)
1301 $LFS hsm_archive $f || error "archive of $f failed"
1302 wait_request_state $fid ARCHIVE SUCCEED
1304 $LFS hsm_release $f || error "release of $f failed"
1308 [[ $? -eq 0 ]] || error "Restored file differs"
1312 run_test 12m "Archive/release/implicit restore"
1315 # test needs a running copytool
1319 copy2archive /etc/hosts $tdir/$tfile
1321 local f=$DIR/$tdir/$tfile
1322 import_file $tdir/$tfile $f
1324 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1325 error "Restored file differs"
1327 $LFS hsm_release $f || error "release of $f failed"
1331 run_test 12n "Import/implicit restore/release"
1334 # test needs a running copytool
1338 local f=$DIR/$tdir/$tfile
1339 local fid=$(copy_file /etc/hosts $f)
1341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1342 wait_request_state $fid ARCHIVE SUCCEED
1343 $LFS hsm_release $f || error "release of $f failed"
1345 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1346 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1348 # set no retry action mode
1351 diff -q /etc/hosts $f
1354 # we check we had a restore failure
1355 wait_request_state $fid RESTORE FAILED
1357 [[ $st -eq 0 ]] && error "Restore must fail"
1359 # remove no retry action mode
1362 # check file is still released
1363 check_hsm_flags $f "0x0000000d"
1365 # retry w/o failure injection
1366 do_facet $SINGLEMDS lctl set_param fail_loc=0
1368 # to be sure previous RESTORE result is gone
1370 wait_for_grace_delay
1372 diff -q /etc/hosts $f
1375 # we check we had a restore done
1376 wait_request_state $fid RESTORE SUCCEED
1378 [[ $st -eq 0 ]] || error "Restored file differs"
1382 run_test 12o "Layout-swap failure during Restore leaves file released"
1385 # test needs a running copytool
1388 local ARC_SUBDIR="import.orig"
1392 # populate directory to be imported
1393 for d in $(seq 1 10); do
1394 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1395 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1396 for f in $(seq 1 10); do
1397 CURR_FILE="$CURR_DIR/$tfile.$f"
1398 # write file-specific data
1399 do_facet $SINGLEAGT \
1400 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1401 "file=$CURR_FILE > $CURR_FILE"
1405 import_file "$ARC_SUBDIR" $DIR/$tdir
1406 # diff lustre content and origin (triggers file restoration)
1407 # there must be 10x10 identical files, and no difference
1408 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1409 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1410 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1411 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1413 [ $cnt_diff -eq 0 ] ||
1414 error "$cnt_diff imported files differ from read data"
1415 [ $cnt_ok -eq 100 ] ||
1416 error "not enough identical files ($cnt_ok != 100)"
1420 run_test 13 "Recursively import and restore a directory"
1423 # test needs a running copytool
1428 local f=$DIR/$tdir/$tfile
1429 local fid=$(make_small $f)
1430 local sum=$(md5sum $f | awk '{print $1}')
1431 $LFS hsm_archive $f || error "could not archive file"
1432 wait_request_state $fid ARCHIVE SUCCEED
1436 # create released file (simulate llapi_hsm_import call)
1438 local fid2=$(path2fid $f)
1439 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1440 $LFS hsm_release $f || error "could not release file"
1442 # rebind the archive to the newly created file
1443 echo "rebind $fid to $fid2"
1445 do_facet $SINGLEAGT \
1446 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1447 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1449 # restore file and compare md5sum
1450 local sum2=$(md5sum $f | awk '{print $1}')
1452 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1456 run_test 14 "Rebind archived file to a new fid"
1459 # test needs a running copytool
1464 local f=$DIR/$tdir/$tfile
1466 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1470 for i in $(seq 1 $count); do
1471 fids[$i]=$(make_small $f.$i)
1472 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1473 $LFS hsm_archive $f.$i || error "could not archive file"
1475 wait_all_done $(($count*60))
1479 for i in $(seq 1 $count); do
1482 local fid2=$(path2fid $f.$i)
1483 # add the rebind operation to the list
1484 echo ${fids[$i]} $fid2 >> $tmpfile
1486 # set it released (simulate llapi_hsm_import call)
1487 $LFS hsm_set --archived --exists $f.$i ||
1488 error "could not force hsm flags"
1489 $LFS hsm_release $f.$i || error "could not release file"
1491 nl=$(wc -l < $tmpfile)
1492 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1494 echo "rebind list of files"
1495 do_facet $SINGLEAGT \
1496 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1497 --rebind $tmpfile $DIR" || error "could not rebind file list"
1499 # restore files and compare md5sum
1500 for i in $(seq 1 $count); do
1501 local sum2=$(md5sum $f.$i | awk '{print $1}')
1502 [[ $sum2 == ${sums[$i]} ]] ||
1503 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1509 run_test 15 "Rebind a list of files"
1512 # test needs a running copytool
1516 # create a known size file so we can verify transfer speed
1519 dd if=/dev/zero of=$ref bs=1M count=20
1522 local f=$DIR/$tdir/$tfile
1523 local fid=$(copy_file $ref $f)
1525 local start=$(date +%s)
1527 wait_request_state $fid ARCHIVE SUCCEED
1528 local end=$(date +%s)
1529 local duration=$((end - start))
1531 [[ $duration -ge $goal ]] ||
1532 error "Transfer is too fast $duration < $goal"
1536 run_test 16 "Test CT bandwith control option"
1541 local f=$DIR/$tdir/$tfile
1542 touch $f || error "touch $f failed"
1544 # Could not release a non-archived file
1545 $LFS hsm_release $f && error "release should not succeed"
1547 # For following tests, we must test them with HS_ARCHIVED set
1548 $LFS hsm_set --exists --archived $f || error "could not add flag"
1550 # Could not release a file if no-release is set
1551 $LFS hsm_set --norelease $f || error "could not add flag"
1552 $LFS hsm_release $f && error "release should not succeed"
1553 $LFS hsm_clear --norelease $f || error "could not remove flag"
1555 # Could not release a file if lost
1556 $LFS hsm_set --lost $f || error "could not add flag"
1557 $LFS hsm_release $f && error "release should not succeed"
1558 $LFS hsm_clear --lost $f || error "could not remove flag"
1560 # Could not release a file if dirty
1561 $LFS hsm_set --dirty $f || error "could not add flag"
1562 $LFS hsm_release $f && error "release should not succeed"
1563 $LFS hsm_clear --dirty $f || error "could not remove flag"
1565 run_test 20 "Release is not permitted"
1568 # test needs a running copytool
1572 local f=$DIR/$tdir/test_release
1574 # Create a file and check its states
1575 local fid=$(make_small $f)
1576 check_hsm_flags $f "0x00000000"
1578 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1579 # used until file is flushed to disk
1580 if [ $(facet_fstype ost1) == "zfs" ]; then
1581 # this causes an OST_SYNC rpc to be sent
1582 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1583 # clear locks to reread file data
1584 cancel_lru_locks osc
1587 local orig_size=$(stat -c "%s" $f)
1588 local orig_blocks=$(stat -c "%b" $f)
1590 start_full_debug_logging
1592 $LFS hsm_archive $f || error "could not archive file"
1593 wait_request_state $fid ARCHIVE SUCCEED
1595 local blocks=$(stat -c "%b" $f)
1596 [ $blocks -eq $orig_blocks ] ||
1597 error "$f: wrong block number after archive: " \
1598 "$blocks != $orig_blocks"
1599 local size=$(stat -c "%s" $f)
1600 [ $size -eq $orig_size ] ||
1601 error "$f: wrong size after archive: $size != $orig_size"
1603 # Release and check states
1604 $LFS hsm_release $f || error "could not release file"
1605 check_hsm_flags $f "0x0000000d"
1607 blocks=$(stat -c "%b" $f)
1608 [ $blocks -gt 5 ] &&
1609 error "$f: too many blocks after release: $blocks > 5"
1610 size=$(stat -c "%s" $f)
1611 [ $size -ne $orig_size ] &&
1612 error "$f: wrong size after release: $size != $orig_size"
1614 # Check we can release an file without stripe info
1618 check_hsm_flags $f "0x00000000"
1619 $LFS hsm_archive $f || error "could not archive file"
1620 wait_request_state $fid ARCHIVE SUCCEED
1622 # Release and check states
1623 $LFS hsm_release $f || error "could not release file"
1624 check_hsm_flags $f "0x0000000d"
1626 # Release again a file that is already released is OK
1627 $LFS hsm_release $f || fail "second release should succeed"
1628 check_hsm_flags $f "0x0000000d"
1630 stop_full_debug_logging
1634 run_test 21 "Simple release tests"
1637 # test needs a running copytool
1642 local f=$DIR/$tdir/test_release
1643 local swap=$DIR/$tdir/test_swap
1645 # Create a file and check its states
1646 local fid=$(make_small $f)
1647 check_hsm_flags $f "0x00000000"
1649 $LFS hsm_archive $f || error "could not archive file"
1650 wait_request_state $fid ARCHIVE SUCCEED
1652 # Release and check states
1653 $LFS hsm_release $f || error "could not release file"
1654 check_hsm_flags $f "0x0000000d"
1657 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1662 run_test 22 "Could not swap a release file"
1665 # test needs a running copytool
1670 local f=$DIR/$tdir/test_mtime
1672 # Create a file and check its states
1673 local fid=$(make_small $f)
1674 check_hsm_flags $f "0x00000000"
1676 $LFS hsm_archive $f || error "could not archive file"
1677 wait_request_state $fid ARCHIVE SUCCEED
1679 # Set modification time in the past
1680 touch -m -a -d @978261179 $f
1682 # Release and check states
1683 $LFS hsm_release $f || error "could not release file"
1684 check_hsm_flags $f "0x0000000d"
1686 local MTIME=$(stat -c "%Y" $f)
1687 local ATIME=$(stat -c "%X" $f)
1688 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1689 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1693 run_test 23 "Release does not change a/mtime (utime)"
1696 local file=$DIR/$tdir/$tfile
1705 # test needs a running copytool
1710 fid=$(make_small $file)
1712 # Create a file and check its states
1713 check_hsm_flags $file "0x00000000"
1715 # Ensure atime is less than mtime and ctime.
1719 atime0=$(stat -c "%X" $file)
1720 mtime0=$(stat -c "%Y" $file)
1721 ctime0=$(stat -c "%Z" $file)
1723 [ $atime0 -lt $mtime0 ] ||
1724 error "atime $atime0 is not less than mtime $mtime0"
1726 [ $atime0 -lt $ctime0 ] ||
1727 error "atime $atime0 is not less than ctime $ctime0"
1729 # Archive should not change any timestamps.
1730 $LFS hsm_archive $file || error "cannot archive '$file'"
1731 wait_request_state $fid ARCHIVE SUCCEED
1733 atime1=$(stat -c "%X" $file)
1734 mtime1=$(stat -c "%Y" $file)
1735 ctime1=$(stat -c "%Z" $file)
1737 [ $atime0 -eq $atime1 ] ||
1738 error "archive changed atime from $atime0 to $atime1"
1740 [ $mtime0 -eq $mtime1 ] ||
1741 error "archive changed mtime from $mtime0 to $mtime1"
1743 [ $ctime0 -eq $ctime1 ] ||
1744 error "archive changed ctime from $ctime0 to $ctime1"
1746 # Release should not change any timestamps.
1747 $LFS hsm_release $file || error "cannot release '$file'"
1748 check_hsm_flags $file "0x0000000d"
1750 atime1=$(stat -c "%X" $file)
1751 mtime1=$(stat -c "%Y" $file)
1752 ctime1=$(stat -c "%Z" $file)
1754 [ $atime0 -eq $atime1 ] ||
1755 error "release changed atime from $atime0 to $atime1"
1757 [ $mtime0 -eq $mtime1 ] ||
1758 error "release changed mtime from $mtime0 to $mtime1"
1760 [ $ctime0 -eq $ctime1 ] ||
1761 error "release changed ctime from $ctime0 to $ctime1"
1763 # Restore should not change atime or mtime and should not
1765 $LFS hsm_restore $file
1766 wait_request_state $fid RESTORE SUCCEED
1768 atime1=$(stat -c "%X" $file)
1769 mtime1=$(stat -c "%Y" $file)
1770 ctime1=$(stat -c "%Z" $file)
1772 [ $atime0 -eq $atime1 ] ||
1773 error "restore changed atime from $atime0 to $atime1"
1775 [ $mtime0 -eq $mtime1 ] ||
1776 error "restore changed mtime from $mtime0 to $mtime1"
1778 [ $ctime0 -le $ctime1 ] ||
1779 error "restore changed ctime from $ctime0 to $ctime1"
1783 # Once more, after unmount and mount.
1784 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1785 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1787 atime1=$(stat -c "%X" $file)
1788 mtime1=$(stat -c "%Y" $file)
1789 ctime1=$(stat -c "%Z" $file)
1791 [ $atime0 -eq $atime1 ] ||
1792 error "remount changed atime from $atime0 to $atime1"
1794 [ $mtime0 -eq $mtime1 ] ||
1795 error "remount changed mtime from $mtime0 to $mtime1"
1797 [ $ctime0 -le $ctime1 ] ||
1798 error "remount changed ctime from $ctime0 to $ctime1"
1800 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1803 local file=$DIR/$tdir/$tfile
1809 # Test needs a running copytool.
1813 # Check that root can do HSM actions on a ordinary user's file.
1815 fid=$(make_small $file)
1816 sum0=$(md5sum $file)
1818 chown $RUNAS_ID:$RUNAS_GID $file ||
1819 error "cannot chown '$file' to '$RUNAS_ID'"
1821 chmod ugo-w $DIR/$tdir ||
1822 error "cannot chmod '$DIR/$tdir'"
1824 $LFS hsm_archive $file
1825 wait_request_state $fid ARCHIVE SUCCEED
1827 $LFS hsm_release $file
1828 check_hsm_flags $file "0x0000000d"
1830 $LFS hsm_restore $file
1831 wait_request_state $fid RESTORE SUCCEED
1833 # Check that ordinary user can get HSM state.
1834 $RUNAS $LFS hsm_state $file ||
1835 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1837 $LFS hsm_release $file
1838 check_hsm_flags $file "0x0000000d"
1840 # Check that ordinary user can accessed released file.
1841 sum1=$($RUNAS md5sum $file) ||
1842 error "user '$RUNAS_ID' cannot read '$file'"
1844 [ "$sum0" == "$sum1" ] ||
1845 error "md5sum mismatch for '$file'"
1849 run_test 24b "root can archive, release, and restore user files"
1851 cleanup_test_24c() {
1853 set_hsm_param user_request_mask RESTORE
1854 set_hsm_param group_request_mask RESTORE
1855 set_hsm_param other_request_mask RESTORE
1859 local file=$DIR/$tdir/$tfile
1860 local action=archive
1865 # test needs a running copytool
1870 # Save the default masks and check that cleanup_24c will
1871 # restore the request masks correctly.
1872 user_save=$(get_hsm_param user_request_mask)
1873 group_save=$(get_hsm_param group_request_mask)
1874 other_save=$(get_hsm_param other_request_mask)
1876 [ "$user_save" == RESTORE ] ||
1877 error "user_request_mask is '$user_save' expected 'RESTORE'"
1878 [ "$group_save" == RESTORE ] ||
1879 error "group_request_mask is '$group_save' expected 'RESTORE'"
1880 [ "$other_save" == RESTORE ] ||
1881 error "other_request_mask is '$other_save' expected 'RESTORE'"
1883 trap cleanup_test_24c EXIT
1888 chown $RUNAS_ID:nobody $file ||
1889 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1891 set_hsm_param user_request_mask ""
1892 $RUNAS $LFS hsm_$action $file &&
1893 error "$action by user should fail"
1895 set_hsm_param user_request_mask $action
1896 $RUNAS $LFS hsm_$action $file ||
1897 error "$action by user should succeed"
1902 chown nobody:$RUNAS_GID $file ||
1903 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1905 set_hsm_param group_request_mask ""
1906 $RUNAS $LFS hsm_$action $file &&
1907 error "$action by group should fail"
1909 set_hsm_param group_request_mask $action
1910 $RUNAS $LFS hsm_$action $file ||
1911 error "$action by group should succeed"
1916 chown nobody:nobody $file ||
1917 error "cannot chown '$file' to 'nobody:nobody'"
1919 set_hsm_param other_request_mask ""
1920 $RUNAS $LFS hsm_$action $file &&
1921 error "$action by other should fail"
1923 set_hsm_param other_request_mask $action
1924 $RUNAS $LFS hsm_$action $file ||
1925 error "$action by other should succeed"
1930 run_test 24c "check that user,group,other request masks work"
1932 cleanup_test_24d() {
1934 mount -o remount,rw $MOUNT2
1938 local file1=$DIR/$tdir/$tfile
1939 local file2=$DIR2/$tdir/$tfile
1947 fid1=$(make_small $file1)
1949 trap cleanup_test_24d EXIT
1951 mount -o remount,ro $MOUNT2
1953 fid2=$(path2fid $file2)
1954 [ "$fid1" == "$fid2" ] ||
1955 error "FID mismatch '$fid1' != '$fid2'"
1957 $LFS hsm_archive $file2 &&
1958 error "archive should fail on read-only mount"
1959 check_hsm_flags $file1 "0x00000000"
1961 $LFS hsm_archive $file1
1962 wait_request_state $fid1 ARCHIVE SUCCEED
1964 $LFS hsm_release $file1
1965 $LFS hsm_restore $file2
1966 wait_request_state $fid1 RESTORE SUCCEED
1968 $LFS hsm_release $file1 || error "cannot release '$file1'"
1969 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1971 $LFS hsm_release $file2 &&
1972 error "release should fail on read-only mount"
1977 run_test 24d "check that read-only mounts are respected"
1980 # test needs a running copytool
1984 copy2archive /etc/hosts $tdir/$tfile
1986 local f=$DIR/$tdir/$tfile
1988 import_file $tdir/$tfile $f
1990 $LFS hsm_set --lost $f
1995 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1999 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2000 " (Operation not permitted)"
2003 # test needs a running copytool
2008 local f=$DIR/$tdir/$tfile
2009 local fid=$(copy_file /etc/passwd $f)
2011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2012 wait_request_state $fid ARCHIVE SUCCEED
2015 $LFS hsm_set --lost $f
2019 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2023 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2024 " (Operation not permitted)"
2027 # test needs a running copytool
2031 local f=$DIR/$tdir/$tfile
2032 local fid=$(make_large_for_progress $f)
2033 [ $? != 0 ] && skip "not enough free space" && return
2035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2036 wait_request_state $fid ARCHIVE SUCCEED
2039 wait_request_state $fid REMOVE SUCCEED
2041 check_hsm_flags $f "0x00000000"
2045 run_test 26 "Remove the archive of a valid file"
2048 # test needs a running copytool
2052 make_archive $tdir/$tfile
2053 local f=$DIR/$tdir/$tfile
2054 import_file $tdir/$tfile $f
2055 local fid=$(path2fid $f)
2059 [[ $? != 0 ]] || error "Remove of a released file should fail"
2063 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2066 # test needs a running copytool
2070 local f=$DIR/$tdir/$tfile
2071 local fid=$(make_large_for_progress $f)
2072 [ $? != 0 ] && skip "not enough free space" && return
2074 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2075 wait_request_state $fid ARCHIVE SUCCEED
2080 [[ $? != 0 ]] || error "Remove of a released file should fail"
2084 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2087 # test needs a running copytool
2091 local f=$DIR/$tdir/$tfile
2092 local fid=$(make_large_for_progress $f)
2093 [ $? != 0 ] && skip "not enough free space" && return
2095 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2096 wait_request_state $fid ARCHIVE SUCCEED
2105 wait_request_state $fid REMOVE SUCCEED
2109 run_test 28 "Concurrent archive/file remove"
2112 # restore at exec cannot work on agent node (because of Linux kernel
2113 # protection of executables)
2114 needclients 2 || return 0
2116 # test needs a running copytool
2120 copy2archive /bin/true $tdir/$tfile
2122 local f=$DIR/$tdir/true
2123 import_file $tdir/$tfile $f
2125 local fid=$(path2fid $f)
2127 # set no retry action mode
2133 # remove no try action mode
2137 [[ $st == 0 ]] || error "Failed to exec a released file"
2141 run_test 30a "Restore at exec (import case)"
2144 # restore at exec cannot work on agent node (because of Linux kernel
2145 # protection of executables)
2146 needclients 2 || return 0
2148 # test needs a running copytool
2152 local f=$DIR/$tdir/true
2153 local fid=$(copy_file /bin/true $f)
2155 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2156 wait_request_state $fid ARCHIVE SUCCEED
2159 # set no retry action mode
2165 # remove no try action mode
2169 [[ $st == 0 ]] || error "Failed to exec a released file"
2173 run_test 30b "Restore at exec (release case)"
2176 needclients 2 || return 0
2178 # test needs a running copytool
2182 local f=$DIR/$tdir/SLEEP
2183 local fid=$(copy_file /bin/sleep $f)
2185 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2186 wait_request_state $fid ARCHIVE SUCCEED
2188 check_hsm_flags $f "0x0000000d"
2189 # set no retry action mode
2191 do_node $CLIENT2 "$f 10" &
2195 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2197 [[ $? == 0 ]] || error "Execution failed during run"
2199 [[ $? == 0 ]] || error "Binary overwritten during exec"
2202 # remove no try action mode
2204 check_hsm_flags $f "0x00000009"
2208 run_test 30c "Update during exec of released file must fail"
2210 restore_and_check_size() {
2213 local s=$(stat -c "%s" $f)
2215 local st=$(get_hsm_flags $f)
2219 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2221 n=$(stat -c "%s" $f)
2222 # we echo in both cases to show stat is not
2224 if [[ $n != $s ]]; then
2225 echo "size seen is $n != $s"
2228 echo "size seen is right: $n == $s"
2230 st=$(get_hsm_flags $f)
2234 if [[ $cpt -lt 10 ]]; then
2237 echo " restore is too long"
2238 wait_request_state $fid RESTORE SUCCEED
2244 # test needs a running copytool
2249 make_archive $tdir/$tfile
2250 local f=$DIR/$tdir/$tfile
2251 import_file $tdir/$tfile $f
2252 local fid=$($LFS path2fid $f)
2253 HSM_ARCHIVE_PURGE=false copytool_setup
2255 restore_and_check_size $f $fid
2258 [[ $err -eq 0 ]] || error "File size changed during restore"
2262 run_test 31a "Import a large file and check size during restore"
2266 # test needs a running copytool
2271 local f=$DIR/$tdir/$tfile
2272 local fid=$(make_large_for_progress $f)
2273 [ $? != 0 ] && skip "not enough free space" && return
2275 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2276 wait_request_state $fid ARCHIVE SUCCEED
2279 restore_and_check_size $f $fid
2282 [[ $err -eq 0 ]] || error "File size changed during restore"
2286 run_test 31b "Restore a large unaligned file and check size during restore"
2289 # test needs a running copytool
2294 local f=$DIR/$tdir/$tfile
2295 local fid=$(make_large_for_progress_aligned $f)
2296 [ $? != 0 ] && skip "not enough free space" && return
2298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2299 wait_request_state $fid ARCHIVE SUCCEED
2302 restore_and_check_size $f $fid
2305 [[ $err -eq 0 ]] || error "File size changed during restore"
2309 run_test 31c "Restore a large aligned file and check size during restore"
2312 # test needs a running copytool
2317 local f=$DIR/$tdir/$tfile
2318 local fid=$(make_large_for_progress $f)
2319 [ $? != 0 ] && skip "not enough free space" && return
2321 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2322 wait_request_state $fid ARCHIVE SUCCEED
2325 # to be sure wait_all_done will not be mislead by previous tests
2328 wait_for_grace_delay
2329 # Also raise grace_delay significantly so the Canceled
2330 # Restore action will stay enough long avail.
2331 local old_grace=$(get_hsm_param grace_delay)
2332 set_hsm_param grace_delay 100
2334 md5sum $f >/dev/null &
2336 wait_request_state $fid RESTORE STARTED
2341 # Check restore trigger process was killed
2342 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2346 # instead of waiting+checking both Restore and Cancel ops
2347 # sequentially, wait for both to be finished and then check
2349 wait_all_done 100 $fid
2350 local rstate=$(get_request_state $fid RESTORE)
2351 local cstate=$(get_request_state $fid CANCEL)
2353 # restore orig grace_delay.
2354 set_hsm_param grace_delay $old_grace
2356 if [[ "$rstate" == "CANCELED" ]] ; then
2357 [[ "$cstate" == "SUCCEED" ]] ||
2358 error "Restore state is CANCELED and Cancel state " \
2359 "is not SUCCEED but $cstate"
2360 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2361 elif [[ "$rstate" == "SUCCEED" ]] ; then
2362 [[ "$cstate" == "FAILED" ]] ||
2363 error "Restore state is SUCCEED and Cancel state " \
2364 "is not FAILED but $cstate"
2365 echo "Restore state is SUCCEED, Cancel state is FAILED"
2367 error "Restore state is $rstate and Cancel state is $cstate"
2371 error "Cannot kill process waiting for restore ($killed)"
2375 run_test 33 "Kill a restore waiting process"
2378 # test needs a running copytool
2383 local f=$DIR/$tdir/$tfile
2384 local fid=$(make_large_for_progress $f)
2385 [ $? != 0 ] && skip "not enough free space" && return
2387 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2388 wait_request_state $fid ARCHIVE SUCCEED
2391 md5sum $f >/dev/null &
2393 wait_request_state $fid RESTORE STARTED
2395 rm $f || error "rm $f failed"
2396 # rm must not block during restore
2397 wait_request_state $fid RESTORE STARTED
2399 wait_request_state $fid RESTORE SUCCEED
2400 # check md5sum pgm finished
2401 local there=$(ps -o pid,comm hp $pid >/dev/null)
2402 [[ -z $there ]] || error "Restore initiator does not exit"
2404 local rc=$(wait $pid)
2405 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2409 run_test 34 "Remove file during restore"
2412 # test needs a running copytool
2417 local f=$DIR/$tdir/$tfile
2418 local f1=$DIR/$tdir/$tfile-1
2419 local fid=$(make_large_for_progress $f)
2420 [ $? != 0 ] && skip "not enough free space" && return
2422 local fid1=$(copy_file /etc/passwd $f1)
2423 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2424 wait_request_state $fid ARCHIVE SUCCEED
2427 md5sum $f >/dev/null &
2429 wait_request_state $fid RESTORE STARTED
2431 mv $f1 $f || error "mv $f1 $f failed"
2432 # mv must not block during restore
2433 wait_request_state $fid RESTORE STARTED
2435 wait_request_state $fid RESTORE SUCCEED
2436 # check md5sum pgm finished
2437 local there=$(ps -o pid,comm hp $pid >/dev/null)
2438 [[ -z $there ]] || error "Restore initiator does not exit"
2440 local rc=$(wait $pid)
2441 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2444 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2448 run_test 35 "Overwrite file during restore"
2451 # test needs a running copytool
2456 local f=$DIR/$tdir/$tfile
2457 local fid=$(make_large_for_progress $f)
2458 [ $? != 0 ] && skip "not enough free space" && return
2460 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2461 wait_request_state $fid ARCHIVE SUCCEED
2464 md5sum $f >/dev/null &
2466 wait_request_state $fid RESTORE STARTED
2469 # rm must not block during restore
2470 wait_request_state $fid RESTORE STARTED
2472 wait_request_state $fid RESTORE SUCCEED
2473 # check md5sum pgm finished
2474 local there=$(ps -o pid,comm hp $pid >/dev/null)
2476 error "Restore initiator does not exit"
2478 local rc=$(wait $pid)
2480 error "Restore initiator failed with $rc"
2484 run_test 36 "Move file during restore"
2491 for n in $(seq 1 $count); do
2492 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2494 echo "$count archive requests submitted"
2498 local stream_count=4
2499 local file_count=100
2501 local f=$DIR/$tdir/$tfile
2506 for i in $(seq 1 $file_count); do
2507 for p in $(seq 1 $stream_count); do
2508 fid=$(copy_file /etc/hosts $f.$p.$i)
2511 # force copytool to use a local/temp archive dir to ensure best
2512 # performance vs remote/NFS mounts used in auto-tests
2513 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2516 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2518 # to be sure wait_all_done will not be mislead by previous tests
2520 wait_for_grace_delay
2522 # start archive streams in background (archive files in parallel)
2523 for p in $(seq 1 $stream_count); do
2524 multi_archive $f.$p $file_count &
2527 echo -n "Wait for all requests being enqueued..."
2533 run_test 40 "Parallel archive requests"
2536 # test needs a running copytool
2540 local f=$DIR/$tdir/$tfile
2541 local fid=$(copy_file /etc/motd $f 1)
2543 $LFS hsm_archive $f || error "could not archive file"
2544 wait_request_state $fid ARCHIVE SUCCEED
2545 check_hsm_flags $f "0x00000009"
2547 multiop_bg_pause $f O_c || error "multiop failed"
2551 client_up || client_up || true
2553 kill -USR1 $MULTIPID
2554 wait $MULTIPID || error "multiop close failed"
2556 check_hsm_flags $f "0x0000000b"
2560 run_test 52 "Opened for write file on an evicted client should be set dirty"
2563 # test needs a running copytool
2567 local f=$DIR/$tdir/$tfile
2568 local fid=$(copy_file /etc/motd $f 1)
2570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2571 error "could not archive file"
2572 wait_request_state $fid ARCHIVE SUCCEED
2573 check_hsm_flags $f "0x00000009"
2575 multiop_bg_pause $f o_c || error "multiop failed"
2579 client_up || client_up || true
2581 kill -USR1 $MULTIPID
2582 wait $MULTIPID || error "multiop close failed"
2584 check_hsm_flags $f "0x00000009"
2588 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2591 # test needs a running copytool
2595 local f=$DIR/$tdir/$tfile
2596 local fid=$(make_small $f)
2598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2599 error "could not archive file"
2600 wait_request_state $fid ARCHIVE STARTED
2602 check_hsm_flags $f "0x00000001"
2604 # Avoid coordinator resending this request as soon it has failed.
2609 wait_request_state $fid ARCHIVE FAILED
2611 check_hsm_flags $f "0x00000003"
2616 run_test 54 "Write during an archive cancels it"
2619 # test needs a running copytool
2623 local f=$DIR/$tdir/$tfile
2624 local fid=$(make_small $f)
2626 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2627 error "could not archive file"
2628 wait_request_state $fid ARCHIVE STARTED
2630 check_hsm_flags $f "0x00000001"
2632 # Avoid coordinator resending this request as soon it has failed.
2635 $TRUNCATE $f 1024 || error "truncate failed"
2637 wait_request_state $fid ARCHIVE FAILED
2639 check_hsm_flags $f "0x00000003"
2644 run_test 55 "Truncate during an archive cancels it"
2647 # test needs a running copytool
2651 local f=$DIR/$tdir/$tfile
2652 local fid=$(make_large_for_progress $f)
2653 [ $? != 0 ] && skip "not enough free space" && return
2655 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2656 error "could not archive file"
2657 wait_request_state $fid ARCHIVE STARTED
2659 check_hsm_flags $f "0x00000001"
2661 # Change metadata and sync to be sure we are not changing only
2666 wait_request_state $fid ARCHIVE SUCCEED
2668 check_hsm_flags $f "0x00000009"
2672 run_test 56 "Setattr during an archive is ok"
2675 # Need one client for I/O, one for request
2676 needclients 2 || return 0
2678 # test needs a running copytool
2682 local f=$DIR/$tdir/test_archive_remote
2683 # Create a file on a remote node
2684 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2685 "count=2 conv=fsync"
2688 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2689 error "hsm_archive failed"
2690 local fid=$(path2fid $f)
2691 wait_request_state $fid ARCHIVE SUCCEED
2693 # Release and implicit restore it
2694 do_node $CLIENT2 "$LFS hsm_release $f" ||
2695 error "hsm_release failed"
2696 do_node $CLIENT2 "md5sum $f" ||
2697 error "hsm_restore failed"
2699 wait_request_state $fid RESTORE SUCCEED
2703 run_test 57 "Archive a file with dirty cache on another node"
2705 truncate_released_file() {
2709 local sz=$(stat -c %s $src_file)
2710 local f=$DIR/$tdir/$tfile
2711 local fid=$(copy_file $1 $f)
2715 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2716 error "could not archive file"
2717 wait_request_state $fid ARCHIVE SUCCEED
2719 $LFS hsm_release $f || error "could not release file"
2721 $TRUNCATE $f $trunc_to || error "truncate failed"
2724 local sz1=$(stat -c %s $f)
2725 [[ $sz1 == $trunc_to ]] ||
2726 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2729 check_hsm_flags $f "0x0000000b"
2731 local state=$(get_request_state $fid RESTORE)
2732 [[ "$state" == "SUCCEED" ]] ||
2733 error "truncate $sz does not trig restore, state = $state"
2735 $TRUNCATE $ref $trunc_to
2736 cmp $ref $f || error "file data wrong after truncate"
2742 # test needs a running copytool
2747 local sz=$(stat -c %s /etc/passwd)
2749 echo "truncate up from $sz to $((sz*2))"
2750 truncate_released_file /etc/passwd $((sz*2))
2752 echo "truncate down from $sz to $((sz/2))"
2753 truncate_released_file /etc/passwd $((sz/2))
2755 echo "truncate to 0"
2756 truncate_released_file /etc/passwd 0
2760 run_test 58 "Truncate a released file will trigger restore"
2763 # This test validates the fix for LU-4512. Ensure that the -u
2764 # option changes the progress reporting interval from the
2765 # default (30 seconds) to the user-specified interval.
2767 local progress_timeout=$((interval * 4))
2769 # test needs a new running copytool
2771 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2774 local f=$DIR/$tdir/$tfile
2775 local fid=$(make_large_for_progress $f)
2776 [ $? != 0 ] && skip "not enough free space" && return
2779 local mdt=${MDT_PREFIX}${mdtidx}
2780 local mds=mds$((mdtidx + 1))
2782 # Wait for copytool to register
2783 wait_update_facet $mds \
2784 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2785 uuid 100 || error "coyptool failed to register with $mdt"
2787 local start_at=$(date +%s)
2788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2789 error "could not archive file"
2791 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2792 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2798 echo -n "Expecting a progress update within $progress_timeout seconds... "
2800 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2801 if [ $RESULT -gt 0 ]; then
2802 echo "$RESULT bytes copied in $WAIT seconds."
2804 elif [ $WAIT -ge $progress_timeout ]; then
2805 error "Timed out waiting for progress update!"
2808 WAIT=$((WAIT + sleep))
2812 local finish_at=$(date +%s)
2813 local elapsed=$((finish_at - start_at))
2815 # Ensure that the progress update occurred within the expected window.
2816 if [ $elapsed -lt $interval ]; then
2817 error "Expected progress update after at least $interval seconds"
2823 run_test 60 "Changing progress update interval from default"
2826 # test needs a new running copytool
2828 copytool_monitor_setup
2829 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2831 # Just start and stop the copytool to generate events.
2834 # Wait for the copytool to register.
2835 wait_update --verbose $(facet_active_host mds1) \
2836 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2838 error "copytool failed to register with MDT0000"
2842 local REGISTER_EVENT
2843 local UNREGISTER_EVENT
2844 while read event; do
2845 local parsed=$(parse_json_event "$event")
2846 if [ -z "$parsed" ]; then
2847 error "Copytool sent malformed event: $event"
2851 if [ $event_type == "REGISTER" ]; then
2852 REGISTER_EVENT=$event
2853 elif [ $event_type == "UNREGISTER" ]; then
2854 UNREGISTER_EVENT=$event
2856 done < <(echo $"$(get_copytool_event_log)")
2858 if [ -z "$REGISTER_EVENT" ]; then
2859 error "Copytool failed to send register event to FIFO"
2862 if [ -z "$UNREGISTER_EVENT" ]; then
2863 error "Copytool failed to send unregister event to FIFO"
2866 copytool_monitor_cleanup
2867 echo "Register/Unregister events look OK."
2869 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2872 # Bump progress interval for livelier events.
2875 # test needs a new running copytool
2877 copytool_monitor_setup
2878 HSMTOOL_UPDATE_INTERVAL=$interval \
2879 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2882 local f=$DIR/$tdir/$tfile
2883 local fid=$(make_large_for_progress $f)
2884 [ $? != 0 ] && skip "not enough free space" && return
2886 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2887 error "could not archive file"
2888 wait_request_state $fid ARCHIVE SUCCEED
2890 local expected_fields="event_time data_fid source_fid"
2891 expected_fields+=" total_bytes current_bytes"
2895 while read event; do
2896 # Make sure we're not getting anything from previous events.
2897 for field in $expected_fields; do
2901 local parsed=$(parse_json_event "$event")
2902 if [ -z "$parsed" ]; then
2903 error "Copytool sent malformed event: $event"
2907 if [ $event_type == "ARCHIVE_START" ]; then
2910 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2913 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2917 # Do some simple checking of the progress update events.
2918 for expected_field in $expected_fields; do
2919 if [ -z ${!expected_field+x} ]; then
2920 error "Missing $expected_field field in event"
2924 if [ $total_bytes -eq 0 ]; then
2925 error "Expected total_bytes to be > 0"
2928 # These should be identical throughout an archive
2930 if [ $source_fid != $data_fid ]; then
2931 error "Expected source_fid to equal data_fid"
2933 done < <(echo $"$(get_copytool_event_log)")
2935 if [ -z "$START_EVENT" ]; then
2936 error "Copytool failed to send archive start event to FIFO"
2939 if [ -z "$FINISH_EVENT" ]; then
2940 error "Copytool failed to send archive finish event to FIFO"
2943 echo "Archive events look OK."
2947 copytool_monitor_cleanup
2949 run_test 71 "Copytool logs JSON archive events to FIFO"
2952 # Bump progress interval for livelier events.
2955 # test needs a new running copytool
2957 copytool_monitor_setup
2958 HSMTOOL_UPDATE_INTERVAL=$interval \
2959 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2960 local test_file=$HSMTOOL_MONITOR_DIR/file
2962 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2964 do_facet $SINGLEAGT "$cmd" ||
2965 error "cannot create $test_file on $SINGLEAGT"
2966 copy2archive $test_file $tdir/$tfile
2969 local f=$DIR/$tdir/$tfile
2970 import_file $tdir/$tfile $f
2971 f=$DIR2/$tdir/$tfile
2972 echo "Verifying released state: "
2973 check_hsm_flags $f "0x0000000d"
2975 local fid=$(path2fid $f)
2977 wait_request_state $fid RESTORE SUCCEED
2979 local expected_fields="event_time data_fid source_fid"
2980 expected_fields+=" total_bytes current_bytes"
2984 while read event; do
2985 # Make sure we're not getting anything from previous events.
2986 for field in $expected_fields; do
2990 local parsed=$(parse_json_event "$event")
2991 if [ -z "$parsed" ]; then
2992 error "Copytool sent malformed event: $event"
2996 if [ $event_type == "RESTORE_START" ]; then
2998 if [ $source_fid != $data_fid ]; then
2999 error "source_fid should == data_fid at start"
3002 elif [ $event_type == "RESTORE_FINISH" ]; then
3004 if [ $source_fid != $data_fid ]; then
3005 error "source_fid should == data_fid at finish"
3008 elif [ $event_type != "RESTORE_RUNNING" ]; then
3012 # Do some simple checking of the progress update events.
3013 for expected_field in $expected_fields; do
3014 if [ -z ${!expected_field+x} ]; then
3015 error "Missing $expected_field field in event"
3019 if [ $total_bytes -eq 0 ]; then
3020 error "Expected total_bytes to be > 0"
3023 # When a restore starts out, the data fid is the same as the
3024 # source fid. After the restore has gotten going, we learn
3025 # the new data fid. Once the restore has finished, the source
3026 # fid is set to the new data fid.
3028 # We test this because some monitoring software may depend on
3029 # this behavior. If it changes, then the consumers of these
3030 # events may need to be modified.
3031 if [ $source_fid == $data_fid ]; then
3032 error "source_fid should != data_fid during restore"
3034 done < <(echo $"$(get_copytool_event_log)")
3036 if [ -z "$START_EVENT" ]; then
3037 error "Copytool failed to send restore start event to FIFO"
3040 if [ -z "$FINISH_EVENT" ]; then
3041 error "Copytool failed to send restore finish event to FIFO"
3044 echo "Restore events look OK."
3048 copytool_monitor_cleanup
3052 run_test 72 "Copytool logs JSON restore events to FIFO"
3055 file_count=51 # Max number of files constrained by LNET message size
3056 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3057 local f=$DIR/$tdir/$tfile
3058 local FILELIST=/tmp/filelist.txt
3062 for i in $(seq 1 $file_count); do
3063 fid=$(copy_file /etc/hosts $f.$i)
3064 echo $f.$i >> $FILELIST
3066 # force copytool to use a local/temp archive dir to ensure best
3067 # performance vs remote/NFS mounts used in auto-tests
3068 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3071 local dai=$(get_hsm_param default_archive_id)
3072 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3074 # to be sure wait_all_done will not be mislead by previous tests
3076 wait_for_grace_delay
3077 $LFS hsm_archive --filelist $FILELIST ||
3078 error "cannot archive a file list"
3080 $LFS hsm_release --filelist $FILELIST ||
3081 error "cannot release a file list"
3082 $LFS hsm_restore --filelist $FILELIST ||
3083 error "cannot restore a file list"
3087 run_test 90 "Archive/restore a file list"
3089 double_verify_reset_hsm_param() {
3091 echo "Testing $HSM_PARAM.$p"
3092 local val=$(get_hsm_param $p)
3094 local val2=$(($val * 2))
3095 set_hsm_param $p $val2
3096 val=$(get_hsm_param $p)
3097 [[ $val == $val2 ]] ||
3098 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3099 echo "Set $p to 0 must failed"
3103 set_hsm_param $p $save
3105 if [[ $rc == 0 ]]; then
3106 error "we must not be able to set $HSM_PARAM.$p to 0"
3111 double_verify_reset_hsm_param loop_period
3112 double_verify_reset_hsm_param grace_delay
3113 double_verify_reset_hsm_param active_request_timeout
3114 double_verify_reset_hsm_param max_requests
3115 double_verify_reset_hsm_param default_archive_id
3117 run_test 100 "Set coordinator /proc tunables"
3124 run_test 102 "Verify coordinator control"
3127 # test needs a running copytool
3134 for i in $(seq 1 20); do
3135 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3137 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3141 echo "Current requests"
3142 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3143 $HSM_PARAM.actions |\
3144 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3146 [[ -z "$res" ]] || error "Some request have not been canceled"
3150 run_test 103 "Purge all requests"
3155 # test needs a running copytool
3159 local f=$DIR/$tdir/$tfile
3160 local fid=$(make_large_for_progress $f)
3161 [ $? != 0 ] && skip "not enough free space" && return
3163 # if cdt is on, it can serve too quickly the request
3165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3166 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3167 $HSM_PARAM.actions |\
3168 grep $fid | cut -f16 -d=")
3171 [[ "$data1" == "$DATAHEX" ]] ||
3172 error "Data field in records is ($data1) and not ($DATAHEX)"
3176 run_test 104 "Copy tool data field"
3183 for i in $(seq -w 1 10); do
3184 cp /etc/passwd $DIR/$tdir/$i
3185 $LFS hsm_archive $DIR/$tdir/$i
3187 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3188 $HSM_PARAM.actions |\
3189 grep WAITING | wc -l")
3192 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3193 $HSM_PARAM.actions |\
3194 grep WAITING | wc -l")
3197 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3198 error "Requests count after shutdown $reqcnt2 != "\
3199 "before shutdown $reqcnt1"
3201 run_test 105 "Restart of coordinator"
3203 get_agent_by_uuid_mdt() {
3206 local mds=mds$(($mdtidx + 1))
3207 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3211 check_agent_registered_by_mdt() {
3214 local mds=mds$(($mdtidx + 1))
3215 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3216 if [[ ! -z "$agent" ]]; then
3217 echo "found agent $agent on $mds"
3219 error "uuid $uuid not found in agent list on $mds"
3223 check_agent_unregistered_by_mdt() {
3226 local mds=mds$(($mdtidx + 1))
3227 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3228 if [[ -z "$agent" ]]; then
3229 echo "uuid not found in agent list on $mds"
3231 error "uuid found in agent list on $mds: $agent"
3235 check_agent_registered() {
3238 for mdsno in $(seq 1 $MDSCOUNT); do
3239 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3243 check_agent_unregistered() {
3246 for mdsno in $(seq 1 $MDSCOUNT); do
3247 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3252 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3253 get_client_uuid $MOUNT | cut -d' ' -f2)
3256 check_agent_registered $uuid
3258 search_copytools || error "No copytool found"
3261 check_agent_unregistered $uuid
3264 check_agent_registered $uuid
3268 run_test 106 "Copytool register/unregister"
3271 # test needs a running copytool
3273 # create and archive file
3275 local f1=$DIR/$tdir/$tfile
3276 local fid=$(copy_file /etc/passwd $f1)
3277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3278 wait_request_state $fid ARCHIVE SUCCEED
3279 # shutdown and restart MDS
3281 # check the copytool still gets messages from MDT
3282 local f2=$DIR/$tdir/2
3283 local fid=$(copy_file /etc/passwd $f2)
3284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3285 # main check of this sanity: this request MUST succeed
3286 wait_request_state $fid ARCHIVE SUCCEED
3289 run_test 107 "Copytool re-register after MDS restart"
3291 policy_set_and_test()
3295 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3296 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3297 [[ "$policy" == "$target" ]] ||
3298 error "Wrong policy after '$change': '$policy' != '$target'"
3302 # to force default policy setting if error
3303 CDT_POLICY_HAD_CHANGED=true
3305 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3306 local default="NonBlockingRestore [NoRetryAction]"
3307 [[ "$policy" == "$default" ]] ||
3308 error "default policy has changed,"\
3309 " '$policy' != '$default' update the test"
3310 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3311 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3312 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3313 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3314 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3315 # useless bacause we know but safer for futur changes to use real value
3316 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3317 echo "Next set_param must failed"
3318 policy_set_and_test "wrong" "$policy"
3321 echo "Back to default policy"
3322 cdt_set_sanity_policy
3324 run_test 109 "Policy display/change"
3327 # test needs a running copytool
3332 copy2archive /etc/passwd $tdir/$tfile
3334 local f=$DIR/$tdir/$tfile
3335 import_file $tdir/$tfile $f
3336 local fid=$(path2fid $f)
3338 cdt_set_non_blocking_restore
3343 wait_request_state $fid RESTORE SUCCEED
3344 cdt_clear_non_blocking_restore
3348 error "md5sum returns $st != 1, "\
3349 "should also perror ENODATA (No data available)"
3353 run_test 110a "Non blocking restore policy (import case)"
3356 # test needs a running copytool
3360 local f=$DIR/$tdir/$tfile
3361 local fid=$(copy_file /etc/passwd $f)
3362 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3363 wait_request_state $fid ARCHIVE SUCCEED
3366 cdt_set_non_blocking_restore
3371 wait_request_state $fid RESTORE SUCCEED
3372 cdt_clear_non_blocking_restore
3376 error "md5sum returns $st != 1, "\
3377 "should also perror ENODATA (No data available)"
3381 run_test 110b "Non blocking restore policy (release case)"
3384 # test needs a running copytool
3388 copy2archive /etc/passwd $tdir/$tfile
3390 local f=$DIR/$tdir/$tfile
3392 import_file $tdir/$tfile $f
3393 local fid=$(path2fid $f)
3397 copytool_remove_backend $fid
3400 wait_request_state $fid RESTORE FAILED
3407 [[ $st == 0 ]] || error "Restore does not failed"
3411 run_test 111a "No retry policy (import case), restore will error"\
3412 " (No such file or directory)"
3415 # test needs a running copytool
3419 local f=$DIR/$tdir/$tfile
3420 local fid=$(copy_file /etc/passwd $f)
3422 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3423 wait_request_state $fid ARCHIVE SUCCEED
3426 copytool_remove_backend $fid
3429 wait_request_state $fid RESTORE FAILED
3436 [[ $st == 0 ]] || error "Restore does not failed"
3440 run_test 111b "No retry policy (release case), restore will error"\
3441 " (No such file or directory)"
3444 # test needs a running copytool
3448 local f=$DIR/$tdir/$tfile
3449 local fid=$(copy_file /etc/passwd $f)
3451 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3452 local l=$($LFS hsm_action $f)
3454 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3458 wait_request_state $fid ARCHIVE SUCCEED
3461 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3465 run_test 112 "State of recorded request"
3468 # test needs a running copytool
3472 local f=$DIR/$tdir/$tfile
3473 local fid=$(make_large_for_cancel $f)
3474 [ $? != 0 ] && skip "not enough free space" && return
3476 # test with cdt on is made in test_221
3478 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3481 wait_request_state $fid ARCHIVE CANCELED
3482 wait_request_state $fid CANCEL SUCCEED
3486 run_test 200 "Register/Cancel archive"
3489 # test needs a running copytool
3493 local f=$DIR/$tdir/$tfile
3494 make_archive $tdir/$tfile
3495 import_file $tdir/$tfile $f
3496 local fid=$(path2fid $f)
3498 # test with cdt on is made in test_222
3503 wait_request_state $fid RESTORE CANCELED
3504 wait_request_state $fid CANCEL SUCCEED
3508 run_test 201 "Register/Cancel restore"
3511 # test needs a running copytool
3515 local f=$DIR/$tdir/$tfile
3516 local fid=$(make_large_for_progress $f)
3517 [ $? != 0 ] && skip "not enough free space" && return
3519 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3520 wait_request_state $fid ARCHIVE SUCCEED
3526 wait_request_state $fid REMOVE CANCELED
3530 run_test 202 "Register/Cancel remove"
3533 # test needs a running copytool
3538 local f=$DIR/$tdir/$tfile
3539 local fid=$(copy_file /etc/passwd $f)
3543 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3544 wait_request_state $fid ARCHIVE SUCCEED
3546 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3550 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3554 run_test 220 "Changelog for archive"
3557 # test needs a running copytool
3562 local f=$DIR/$tdir/$tfile
3563 local fid=$(make_large_for_cancel $f)
3564 [ $? != 0 ] && skip "not enough free space" && return
3568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3569 wait_request_state $fid ARCHIVE STARTED
3571 wait_request_state $fid ARCHIVE CANCELED
3572 wait_request_state $fid CANCEL SUCCEED
3574 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3577 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3581 run_test 221 "Changelog for archive canceled"
3584 # test needs a running copytool
3588 copy2archive /etc/passwd $tdir/$tfile
3590 local f=$DIR/$tdir/$tfile
3591 import_file $tdir/$tfile $f
3592 local fid=$(path2fid $f)
3597 wait_request_state $fid RESTORE SUCCEED
3599 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3602 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3606 run_test 222a "Changelog for explicit restore"
3609 # test needs a running copytool
3613 local f=$DIR/$tdir/$tfile
3614 local fid=$(copy_file /etc/passwd $f)
3617 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3618 wait_request_state $fid ARCHIVE SUCCEED
3623 wait_request_state $fid RESTORE SUCCEED
3625 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3628 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3632 run_test 222b "Changelog for implicit restore"
3635 # test needs a running copytool
3640 local f=$DIR/$tdir/$tfile
3641 make_archive $tdir/$tfile
3645 import_file $tdir/$tfile $f
3646 local fid=$(path2fid $f)
3649 wait_request_state $fid RESTORE STARTED
3651 wait_request_state $fid RESTORE CANCELED
3652 wait_request_state $fid CANCEL SUCCEED
3654 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3657 [[ $flags == $target ]] ||
3658 error "Changelog flag is $flags not $target"
3662 run_test 223a "Changelog for restore canceled (import case)"
3665 # test needs a running copytool
3670 local f=$DIR/$tdir/$tfile
3671 local fid=$(make_large_for_progress $f)
3672 [ $? != 0 ] && skip "not enough free space" && return
3675 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3676 wait_request_state $fid ARCHIVE SUCCEED
3679 wait_request_state $fid RESTORE STARTED
3681 wait_request_state $fid RESTORE CANCELED
3682 wait_request_state $fid CANCEL SUCCEED
3684 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3687 [[ $flags == $target ]] ||
3688 error "Changelog flag is $flags not $target"
3692 run_test 223b "Changelog for restore canceled (release case)"
3695 # test needs a running copytool
3700 local f=$DIR/$tdir/$tfile
3701 local fid=$(copy_file /etc/passwd $f)
3704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3705 wait_request_state $fid ARCHIVE SUCCEED
3708 wait_request_state $fid REMOVE SUCCEED
3710 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3713 [[ $flags == $target ]] ||
3714 error "Changelog flag is $flags not $target"
3718 run_test 224 "Changelog for remove"
3721 # test needs a running copytool
3724 # test is not usable because remove request is too fast
3725 # so it is always finished before cancel can be done ...
3726 echo "Test disabled"
3731 local f=$DIR/$tdir/$tfile
3732 local fid=$(make_large_for_progress $f)
3733 [ $? != 0 ] && skip "not enough free space" && return
3736 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3737 wait_request_state $fid ARCHIVE SUCCEED
3739 # if cdt is on, it can serve too quickly the request
3744 wait_request_state $fid REMOVE CANCELED
3745 wait_request_state $fid CANCEL SUCCEED
3747 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3748 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3749 tail -n 1 | awk '{print $5}')
3752 [[ $flags == $target ]] ||
3753 error "Changelog flag is $flags not $target"
3757 run_test 225 "Changelog for remove canceled"
3760 # test needs a running copytool
3765 local f1=$DIR/$tdir/$tfile-1
3766 local f2=$DIR/$tdir/$tfile-2
3767 local f3=$DIR/$tdir/$tfile-3
3768 local fid1=$(copy_file /etc/passwd $f1)
3769 local fid2=$(copy_file /etc/passwd $f2)
3770 copy_file /etc/passwd $f3
3773 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3774 wait_request_state $fid1 ARCHIVE SUCCEED
3776 $LFS hsm_archive $f2
3777 wait_request_state $fid2 ARCHIVE SUCCEED
3779 rm $f1 || error "rm $f1 failed"
3781 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3784 [[ $flags == $target ]] ||
3785 error "Changelog flag is $flags not $target"
3787 mv $f3 $f2 || error "mv $f3 $f2 failed"
3789 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3792 [[ $flags == $target ]] ||
3793 error "Changelog flag is $flags not $target"
3797 run_test 226 "changelog for last rm/mv with exiting archive"
3799 check_flags_changes() {
3807 $LFS hsm_set --$hsm_flag $f ||
3808 error "Cannot set $hsm_flag on $f"
3809 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3810 local seen=${#flags[*]}
3812 [[ $seen == $cnt ]] ||
3813 error "set $hsm_flag: Changelog events $seen != $cnt"
3814 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3815 error "set $hsm_flag: Changelog flags are "\
3816 "${flags[$((cnt - 1))]} not $target"
3818 $LFS hsm_clear --$hsm_flag $f ||
3819 error "Cannot clear $hsm_flag on $f"
3820 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3823 [[ $cnt == $seen ]] ||
3824 error "clear $hsm_flag: Changelog events $seen != $cnt"
3826 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3827 error "clear $hsm_flag: Changelog flag is "\
3828 "${flags[$((cnt - 1))]} not $target"
3832 # test needs a running copytool
3839 for i in norelease noarchive exists archived
3841 local f=$DIR/$tdir/$tfile-$i
3842 local fid=$(copy_file /etc/passwd $f)
3843 check_flags_changes $f $fid $i 0 1
3846 f=$DIR/$tdir/$tfile---lost
3847 fid=$(copy_file /etc/passwd $f)
3848 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3849 wait_request_state $fid ARCHIVE SUCCEED
3850 check_flags_changes $f $fid lost 3 1
3854 run_test 227 "changelog when explicit setting of HSM flags"
3857 # test needs a running copytool
3860 local fid=$(make_small_sync $DIR/$tfile)
3861 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3862 wait_request_state $fid ARCHIVE SUCCEED
3864 $LFS hsm_release $DIR/$tfile
3865 check_hsm_flags $DIR/$tfile "0x0000000d"
3867 filefrag $DIR/$tfile | grep " 1 extent found" ||
3868 error "filefrag on released file must return only one extent"
3870 # only newer versions of cp detect sparse files by stat/FIEMAP
3872 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3873 error "copying $DIR/$tfile"
3874 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3876 $LFS hsm_release $DIR/$tfile
3877 check_hsm_flags $DIR/$tfile "0x0000000d"
3879 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3881 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3883 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3884 error "comparing untarred $DIR/$tfile"
3886 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3887 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3890 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3893 # test needs a running copytool
3897 local maxrequest=$(get_hsm_param max_requests)
3898 local rqcnt=$(($maxrequest * 3))
3902 for i in $(seq -w 1 $rqcnt); do
3904 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3906 # we do it in 2 steps, so all requests arrive at the same time
3907 for i in $(seq -w 1 $rqcnt); do
3908 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3913 while [[ $cnt != 0 || $wt != 0 ]]; do
3915 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3916 $HSM_PARAM.actions |\
3917 grep STARTED | grep -v CANCEL | wc -l")
3918 [[ $cnt -le $maxrequest ]] ||
3919 error "$cnt > $maxrequest too many started requests"
3920 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3921 $HSM_PARAM.actions |\
3922 grep WAITING | wc -l")
3923 echo "max=$maxrequest started=$cnt waiting=$wt"
3928 run_test 250 "Coordinator max request"
3931 # test needs a running copytool
3935 local f=$DIR/$tdir/$tfile
3936 local fid=$(make_large_for_cancel $f)
3937 [ $? != 0 ] && skip "not enough free space" && return
3940 # to have a short test
3941 local old_to=$(get_hsm_param active_request_timeout)
3942 set_hsm_param active_request_timeout 4
3943 # to be sure the cdt will wake up frequently so
3944 # it will be able to cancel the "old" request
3945 local old_loop=$(get_hsm_param loop_period)
3946 set_hsm_param loop_period 2
3949 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3950 wait_request_state $fid ARCHIVE STARTED
3952 wait_request_state $fid ARCHIVE CANCELED
3954 set_hsm_param active_request_timeout $old_to
3955 set_hsm_param loop_period $old_loop
3959 run_test 251 "Coordinator request timeout"
3962 # the only way to test ondisk conf is to restart MDS ...
3963 echo "Stop coordinator and remove coordinator state at mount"
3966 # clean on disk conf set by default
3967 cdt_clear_mount_state
3968 cdt_check_state stopped
3970 # check cdt still off after umount/remount
3972 cdt_check_state stopped
3974 echo "Set coordinator start at mount, and start coordinator"
3975 cdt_set_mount_state enabled
3978 cdt_check_state enabled
3980 # check cdt still on after umount/remount
3982 cdt_check_state enabled
3984 # we are back to original state (cdt started at mount)
3986 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3989 local ai=$(get_hsm_param default_archive_id)
3990 local new=$((ai + 1))
3992 set_hsm_param default_archive_id $new -P
3994 local res=$(get_hsm_param default_archive_id)
3997 set_hsm_param default_archive_id "" "-P -d"
3999 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4001 run_test 301 "HSM tunnable are persistent"
4004 local ai=$(get_hsm_param default_archive_id)
4005 local new=$((ai + 1))
4010 set_hsm_param default_archive_id $new -P
4013 for mdtno in $(seq 1 $MDSCOUNT); do
4018 cdt_check_state enabled
4020 local res=$(get_hsm_param default_archive_id)
4023 set_hsm_param default_archive_id "" "-P -d"
4025 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4027 run_test 302 "HSM tunnable are persistent when CDT is off"
4030 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4036 local dir_mdt0=$DIR/$tdir/mdt0
4037 local dir_mdt1=$DIR/$tdir/mdt1
4039 # create 1 dir per MDT
4040 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4041 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4043 # create 1 file in each MDT
4044 local fid1=$(make_small $dir_mdt0/$tfile)
4045 local fid2=$(make_small $dir_mdt1/$tfile)
4047 # check that hsm request on mdt0 is sent to the right MDS
4048 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4049 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4050 echo "archive successful on mdt0"
4052 # check that hsm request on mdt1 is sent to the right MDS
4053 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4054 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4055 echo "archive successful on mdt1"
4058 # clean test files and directories
4059 rm -rf $dir_mdt0 $dir_mdt1
4061 run_test 400 "Single request is sent to the right MDT"
4064 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4070 local dir_mdt0=$DIR/$tdir/mdt0
4071 local dir_mdt1=$DIR/$tdir/mdt1
4073 # create 1 dir per MDT
4074 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4075 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4077 # create 1 file in each MDT
4078 local fid1=$(make_small $dir_mdt0/$tfile)
4079 local fid2=$(make_small $dir_mdt1/$tfile)
4081 # check that compound requests are shunt to the rights MDTs
4082 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4083 error "lfs hsm_archive"
4084 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4085 echo "archive successful on mdt0"
4086 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4087 echo "archive successful on mdt1"
4090 # clean test files and directories
4091 rm -rf $dir_mdt0 $dir_mdt1
4093 run_test 401 "Compound requests split and sent to their respective MDTs"
4095 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4100 local node=$(facet_active_host $facet)
4102 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4103 awk '{print $4}'); do
4104 echo "$3 $mdc on $node"
4105 do_facet $facet "$LCTL --device $mdc $state" || return 1
4110 # make sure there is no running copytool
4113 # deactivate all mdc on agent1
4114 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4116 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4118 check_agent_unregistered "uuid" # match any agent
4120 # no expected running copytool
4121 search_copytools $agent && error "Copytool start should have failed"
4124 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4126 run_test 402 "Copytool start fails if all MDTs are inactive"
4129 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4131 # make sure there is no running copytool
4134 local agent=$(facet_active_host $SINGLEAGT)
4135 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4137 # deactivate all mdc for MDT0001
4138 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4141 # check the agent is registered on MDT0000, and not on MDT0001
4142 check_agent_registered_by_mdt $uuid 0
4143 check_agent_unregistered_by_mdt $uuid 1
4145 # check running copytool process
4146 search_copytools $agent || error "No running copytools on $agent"
4148 # reactivate all mdc for MDT0001
4149 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4151 # make sure the copytool is now registered to all MDTs
4152 check_agent_registered $uuid
4156 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4159 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4163 # create files on both MDT0000 and MDT0001
4166 local dir_mdt0=$DIR/$tdir/mdt0
4167 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4169 # create 1 file on mdt0
4170 local fid1=$(make_small $dir_mdt0/$tfile)
4172 # deactivate all mdc for MDT0001
4173 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4175 # send an HSM request for files in MDT0000
4176 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4178 # check for completion of files in MDT0000
4179 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4180 echo "archive successful on mdt0"
4182 # reactivate all mdc for MDT0001
4183 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4186 # clean test files and directories
4189 run_test 404 "Inactive MDT does not block requests for active MDTs"
4192 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4198 local striped_dir=$DIR/$tdir/striped_dir
4200 # create striped dir on all of MDTs
4201 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4203 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4204 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4205 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4206 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4208 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4209 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4210 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4211 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4213 # check that compound requests are shunt to the rights MDTs
4214 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4215 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4216 error "lfs hsm_archive"
4218 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4219 echo "archive successful on $fid1"
4220 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4221 echo "archive successful on $fid2"
4222 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4223 echo "archive successful on $fid3"
4224 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4225 echo "archive successful on $fid4"
4227 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4228 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4229 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4230 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4232 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4233 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4234 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4235 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4239 run_test 405 "archive and release under striped directory"
4244 check_and_cleanup_lustre