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: 3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # bug number for skipped test:LU-3852
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MOUNT_2=${MOUNT_2:-"yes"}
34 # script only handles up to 10 MDTs (because of MDT_PREFIX)
35 [ $MDSCOUNT -gt 9 ] &&
36 error "script cannot handle more than 9 MDTs, please fix" && exit
38 check_and_setup_lustre
40 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
41 skip_env "Need MDS version at least 2.4.53" && exit
44 # $RUNAS_ID may get set incorrectly somewhere else
45 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
46 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
48 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
53 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
54 # the following associated variables are added:
56 # AGTCOUNT: number of agents
57 # AGTDEV{N}: target HSM mount point (root path of the backend)
58 # agt{N}_HOST: hostname of the agent agt{N}
59 # SINGLEAGT: facet of the single agent
61 # The number of agents is initialized as the number of remote client nodes.
62 # By default, only single copytool is started on a remote client/agent. If there
63 # was no remote client, then the copytool will be started on the local client.
69 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
70 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
72 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
73 if [[ $CLIENTCOUNT -gt 1 ]] &&
74 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
75 skip_env "SHARED_DIRECTORY should be accessible"\
80 for n in $(seq $AGTCOUNT); do
81 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
82 agent=CLIENT$((n + 1))
83 if [[ -z "${!agent}" ]]; then
84 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
87 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
90 export SINGLEAGT=${SINGLEAGT:-agt1}
92 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
93 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
94 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
95 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
96 export HSMTOOL_TESTDIR
97 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
98 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
101 # The test only support up to 10 MDTs
102 MDT_PREFIX="mdt.$FSNAME-MDT000"
103 HSM_PARAM="${MDT_PREFIX}0.hsm"
105 # archive is purged at copytool setup
106 HSM_ARCHIVE_PURGE=true
108 # Don't allow copytool error upon start/setup
109 HSMTOOL_NOERROR=false
112 # Get the backend root path for the given agent facet.
115 local dev=AGTDEV$(facet_number $facet)
120 # Stop copytool and unregister an existing changelog user.
122 copytool_monitor_cleanup
125 cdt_set_sanity_policy
130 # get MDT device for each mdc
131 for mdtno in $(seq 1 $MDSCOUNT); do
132 local idx=$(($mdtno - 1))
133 MDT[$idx]=$($LCTL get_param -n \
134 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
135 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
140 local agents=${1:-$(facet_active_host $SINGLEAGT)}
141 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
144 search_and_kill_copytool() {
145 local agents=${1:-$(facet_active_host $SINGLEAGT)}
147 echo "Killing existing copytools on $agents"
148 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
151 copytool_monitor_setup() {
152 local facet=${1:-$SINGLEAGT}
153 local agent=$(facet_active_host $facet)
155 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
156 local test_dir=$(do_node $agent "$cmd") ||
157 error "Failed to create tempdir on $agent"
158 export HSMTOOL_MONITOR_DIR=$test_dir
160 # Create the fifo and a monitor (cat dies when copytool dies)
161 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
162 error "failed to create copytool fifo on $agent"
163 cmd="cat $test_dir/fifo > $test_dir/events &"
164 cmd+=" echo \\\$! > $test_dir/monitor_pid"
166 if [[ $PDSH == *Rmrsh* ]]; then
167 # This is required for pdsh -Rmrsh and its handling of remote
169 # Regular ssh and pdsh -Rssh work fine without this
170 # backgrounded subshell nonsense.
171 (do_node $agent "$cmd") &
172 export HSMTOOL_MONITOR_PDSH=$!
174 # Slightly racy, but just making a best-effort to catch obvious
177 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
178 error "Failed to start copytool monitor on $agent"
180 do_node $agent "$cmd"
182 error "Failed to start copytool monitor on $agent"
187 copytool_monitor_cleanup() {
188 local facet=${1:-$SINGLEAGT}
189 local agent=$(facet_active_host $facet)
191 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
192 # Should die when the copytool dies, but just in case.
193 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
194 cmd+=" 2>/dev/null || true"
195 do_node $agent "$cmd"
196 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
197 export HSMTOOL_MONITOR_DIR=
200 # The pdsh should die on its own when the monitor dies. Just
201 # in case, though, try to clean up to avoid any cruft.
202 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
203 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
204 export HSMTOOL_MONITOR_PDSH=
209 local facet=${1:-$SINGLEAGT}
210 local lustre_mntpnt=${2:-$MOUNT}
212 local hsm_root=${4:-$(copytool_device $facet)}
213 local agent=$(facet_active_host $facet)
215 if [[ -z "$arc_id" ]] &&
216 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
217 echo "Wakeup copytool $facet on $agent"
221 if $HSM_ARCHIVE_PURGE; then
222 echo "Purging archive on $agent"
223 do_facet $facet "rm -rf $hsm_root/*"
226 echo "Starting copytool $facet on $agent"
227 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
228 # bandwidth is limited to 1MB/s so the copy time is known and
229 # independent of hardware
230 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
231 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
232 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
233 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
234 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
235 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
236 cmd+=" --bandwidth 1 $lustre_mntpnt"
238 # Redirect the standard output and error to a log file which
239 # can be uploaded to Maloo.
240 local prefix=$TESTLOG_PREFIX
241 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
242 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
244 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
245 if [[ $? != 0 ]]; then
246 [[ $HSMTOOL_NOERROR == true ]] ||
247 error "start copytool $facet on $agent failed"
248 echo "start copytool $facet on $agent failed"
254 get_copytool_event_log() {
255 local facet=${1:-$SINGLEAGT}
256 local agent=$(facet_active_host $facet)
258 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
259 error "Can't get event log: No monitor directory!"
261 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
262 error "Could not collect event log from $agent"
267 local facet=$SINGLEAGT
268 local agents=${1:-$(facet_active_host $facet)}
273 local hsm_root=$(copytool_device $facet)
275 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
277 echo "Copytool is stopped on $agents"
279 # clean all CDTs orphans requests from previous tests
280 # that would otherwise need to timeout to clear.
281 for mdtno in $(seq 1 $MDSCOUNT); do
283 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
284 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
286 # skip already stop[ed,ing] CDTs
287 echo $oldstate | grep stop && continue
289 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
290 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
292 error "mds${mdtno} cdt state is not stopped"
293 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
294 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
296 error "mds${mdtno} cdt state is not $oldstate"
298 do_facet $facet "rm -rf $hsm_root"
302 local agents=${1:-$(facet_active_host $SINGLEAGT)}
304 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
305 echo "Copytool is suspended on $agents"
308 copytool_remove_backend() {
310 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
311 echo "Remove from backend: $fid = $be"
312 do_facet $SINGLEAGT rm -f $be
316 do_facet $SINGLEAGT \
317 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
318 --import $1 $2 $MOUNT" ||
319 error "import of $1 to $2 failed"
323 local file=$HSM_ARCHIVE/$1
324 do_facet $SINGLEAGT mkdir -p $(dirname $file)
325 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
326 error "cannot create $file"
330 local file=$HSM_ARCHIVE/$2
331 do_facet $SINGLEAGT mkdir -p $(dirname $file)
332 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
341 if [[ "$value" != "" ]]; then
344 for mdtno in $(seq 1 $MDSCOUNT); do
345 local idx=$(($mdtno - 1))
346 local facet=mds${mdtno}
347 # if $arg include -P option, run 1 set_param per MDT on the MGS
348 # else, run set_param on each MDT
349 [[ $arg = *"-P"* ]] && facet=mgs
350 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
351 [[ $? != 0 ]] && rc=1
361 for mdtno in $(seq 1 $MDSCOUNT); do
362 local idx=$(($mdtno - 1))
363 wait_result mds${mdtno} \
364 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
366 error "$key state is not '$target' on mds${mdtno}"
373 for mdtno in $(seq 1 $MDSCOUNT); do
374 local idx=$(($mdtno - 1))
375 local cl_user=$(do_facet mds${mdtno} $LCTL \
376 --device ${MDT[$idx]} \
377 changelog_register -n)
379 do_facet mds${mdtno} lctl set_param \
380 mdd.${MDT[$idx]}.changelog_mask="+hsm"
381 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
385 changelog_cleanup() {
387 for mdtno in $(seq 1 $MDSCOUNT); do
388 local idx=$(($mdtno - 1))
389 [[ -z ${CL_USERS[$idx]} ]] && continue
390 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
391 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
392 changelog_deregister ${CL_USERS[$idx]}
397 changelog_get_flags() {
402 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
407 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
415 mdts_set_param "$opt -n" "hsm.$param" "$value"
422 mdts_set_param "" hsm_control "$cmd"
423 mdts_check_param hsm_control "$target" 10
426 cdt_set_sanity_policy() {
427 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
430 mdts_set_param "" hsm.policy "+NRA"
431 mdts_set_param "" hsm.policy "-NBR"
432 CDT_POLICY_HAD_CHANGED=
437 mdts_set_param "" hsm.policy "+NRA"
438 CDT_POLICY_HAD_CHANGED=true
441 cdt_clear_no_retry() {
442 mdts_set_param "" hsm.policy "-NRA"
443 CDT_POLICY_HAD_CHANGED=true
446 cdt_set_non_blocking_restore() {
447 mdts_set_param "" hsm.policy "+NBR"
448 CDT_POLICY_HAD_CHANGED=true
451 cdt_clear_non_blocking_restore() {
452 mdts_set_param "" hsm.policy "-NBR"
453 CDT_POLICY_HAD_CHANGED=true
456 cdt_clear_mount_state() {
457 mdts_set_param "-P -d" hsm_control ""
460 cdt_set_mount_state() {
461 mdts_set_param "-P" hsm_control "$1"
465 mdts_check_param hsm_control "$1" 20
469 set_test_state disabled disabled
473 set_test_state enabled enabled
477 set_test_state shutdown stopped
481 set_test_state purge enabled
487 cdt_set_sanity_policy
491 local client_count=$1
492 if [[ $CLIENTCOUNT -lt $client_count ]]; then
493 skip "Need $client_count or more clients, have $CLIENTCOUNT"
500 $LFS path2fid $1 | tr -d '[]'
507 if [[ $u == "user" ]]; then
508 local st=$($RUNAS $LFS hsm_state $f)
510 local st=$($LFS hsm_state $f)
514 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
516 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
520 get_hsm_archive_id() {
522 local st=$($LFS hsm_state $f)
523 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
525 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
534 local st=$(get_hsm_flags $f)
535 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
538 check_hsm_flags_user() {
542 local st=$(get_hsm_flags $f user)
543 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
555 if [[ "$3" != 1 ]]; then
559 cp $1 $f || error "cannot copy $1 to $f"
560 path2fid $f || error "cannot get fid on $f"
564 local file2=${1/$DIR/$DIR2}
565 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
566 error "cannot create $file2"
567 path2fid $1 || error "cannot get fid on $1"
571 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
572 error "cannot create $1"
573 path2fid $1 || error "cannot get fid on $1"
576 cleanup_large_files() {
577 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
579 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
582 make_large_for_striping() {
583 local file2=${1/$DIR/$DIR2}
584 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
588 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
589 error "cannot create $file2"
590 path2fid $1 || error "cannot get fid on $1"
593 make_large_for_progress() {
594 local file2=${1/$DIR/$DIR2}
598 # big file is large enough, so copy time is > 30s
599 # so copytool make 1 progress
600 # size is not a multiple of 1M to avoid stripe
602 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
603 error "cannot create $file2"
604 path2fid $1 || error "cannot get fid on $1"
607 make_large_for_progress_aligned() {
608 local file2=${1/$DIR/$DIR2}
612 # big file is large enough, so copy time is > 30s
613 # so copytool make 1 progress
614 # size is a multiple of 1M to have stripe
616 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
617 error "cannot create $file2"
618 path2fid $1 || error "cannot get fid on $1"
621 make_large_for_cancel() {
622 local file2=${1/$DIR/$DIR2}
626 # Copy timeout is 100s. 105MB => 105s
627 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
628 error "cannot create $file2"
629 path2fid $1 || error "cannot get fid on $1"
635 wait_update --verbose $(facet_active_host $facet) "$@"
638 wait_request_state() {
642 # 4th arg (mdt index) is optional
644 local mds=mds$(($mdtidx + 1))
646 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
647 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
649 wait_result $mds "$cmd" $state 100 ||
650 error "request on $fid is not $state on $mds"
653 get_request_state() {
657 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
658 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
661 get_request_count() {
665 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
666 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
673 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
674 [[ -n $fid ]] && cmd+=" | grep '$fid'"
675 cmd+=" | egrep 'WAITING|STARTED'"
677 wait_result $SINGLEMDS "$cmd" "" $timeout ||
678 error "requests did not complete"
681 wait_for_grace_delay() {
682 local val=$(get_hsm_param grace_delay)
689 # python2.6 in EL6 includes an internal json module
690 local json_parser='import json; import fileinput;'
691 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
692 json_parser+='json.loads([line for line in '
693 json_parser+='fileinput.input()][0]).items()])'
695 echo $raw_event | python -c "$json_parser"
698 # populate MDT device array
704 # cleanup from previous bad setup
705 search_and_kill_copytool
707 # for recovery tests, coordinator needs to be started at mount
709 # the lustre conf must be without hsm on (like for sanity.sh)
710 echo "Set HSM on and start"
711 cdt_set_mount_state enabled
712 cdt_check_state enabled
714 echo "Start copytool"
717 echo "Set sanity-hsm HSM policy"
718 cdt_set_sanity_policy
720 # finished requests are quickly removed from list
721 set_hsm_param grace_delay 10
727 local f=$DIR/$tdir/$tfile
731 check_hsm_flags_user $f "0x00000000"
733 $RUNAS $LFS hsm_set --norelease $f ||
734 error "user could not change hsm flags"
735 check_hsm_flags_user $f "0x00000010"
737 $RUNAS $LFS hsm_clear --norelease $f ||
738 error "user could not clear hsm flags"
739 check_hsm_flags_user $f "0x00000000"
741 # User could not change those flags...
742 $RUNAS $LFS hsm_set --exists $f &&
743 error "user should not set this flag"
744 check_hsm_flags_user $f "0x00000000"
747 $LFS hsm_set --exists $f ||
748 error "root could not change hsm flags"
749 check_hsm_flags_user $f "0x00000001"
751 $LFS hsm_clear --exists $f ||
752 error "root could not clear hsm state"
753 check_hsm_flags_user $f "0x00000000"
756 run_test 1 "lfs hsm flags root/non-root access"
760 local f=$DIR/$tdir/$tfile
762 # New files are not dirty
763 check_hsm_flags $f "0x00000000"
765 # For test, we simulate an archived file.
766 $LFS hsm_set --exists $f || error "user could not change hsm flags"
767 check_hsm_flags $f "0x00000001"
769 # chmod do not put the file dirty
770 chmod 600 $f || error "could not chmod test file"
771 check_hsm_flags $f "0x00000001"
773 # chown do not put the file dirty
774 chown $RUNAS_ID $f || error "could not chown test file"
775 check_hsm_flags $f "0x00000001"
777 # truncate put the file dirty
778 $TRUNCATE $f 1 || error "could not truncate test file"
779 check_hsm_flags $f "0x00000003"
781 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
782 check_hsm_flags $f "0x00000001"
784 run_test 2 "Check file dirtyness when doing setattr"
790 # New files are not dirty
792 check_hsm_flags $f "0x00000000"
794 # For test, we simulate an archived file.
795 $LFS hsm_set --exists $f ||
796 error "user could not change hsm flags"
797 check_hsm_flags $f "0x00000001"
799 # Reading a file, does not set dirty
800 cat $f > /dev/null || error "could not read file"
801 check_hsm_flags $f "0x00000001"
803 # Open for write without modifying data, does not set dirty
804 openfile -f O_WRONLY $f || error "could not open test file"
805 check_hsm_flags $f "0x00000001"
807 # Append to a file sets it dirty
808 cp -p /etc/passwd $f.append || error "could not create file"
809 $LFS hsm_set --exists $f.append ||
810 error "user could not change hsm flags"
811 dd if=/etc/passwd of=$f.append bs=1 count=3\
812 conv=notrunc oflag=append status=noxfer ||
813 error "could not append to test file"
814 check_hsm_flags $f.append "0x00000003"
816 # Modify a file sets it dirty
817 cp -p /etc/passwd $f.modify || error "could not create file"
818 $LFS hsm_set --exists $f.modify ||
819 error "user could not change hsm flags"
820 dd if=/dev/zero of=$f.modify bs=1 count=3\
821 conv=notrunc status=noxfer ||
822 error "could not modify test file"
823 check_hsm_flags $f.modify "0x00000003"
825 # Open O_TRUNC sets dirty
826 cp -p /etc/passwd $f.trunc || error "could not create file"
827 $LFS hsm_set --exists $f.trunc ||
828 error "user could not change hsm flags"
829 cp /etc/group $f.trunc || error "could not override a file"
830 check_hsm_flags $f.trunc "0x00000003"
832 # Mmapped a file sets dirty
833 cp -p /etc/passwd $f.mmap || error "could not create file"
834 $LFS hsm_set --exists $f.mmap ||
835 error "user could not change hsm flags"
836 multiop $f.mmap OSMWUc || error "could not mmap a file"
837 check_hsm_flags $f.mmap "0x00000003"
839 run_test 3 "Check file dirtyness when opening for write"
843 local f=$DIR/$tdir/$tfile
844 local fid=$(make_small $f)
847 local st=$(get_request_state $fid CANCEL)
848 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
850 run_test 4 "Useless cancel must not be registered"
853 # test needs a running copytool
857 local f=$DIR/$tdir/$tfile
858 local fid=$(copy_file /etc/passwd $f)
860 wait_request_state $fid ARCHIVE SUCCEED
862 check_hsm_flags $f "0x00000009"
866 run_test 8 "Test default archive number"
870 local f=$DIR/$tdir/$tfile
871 local fid=$(copy_file /etc/passwd $f)
872 # we do not use the default one to be sure
873 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
875 copytool_setup $SINGLEAGT $MOUNT $new_an
876 $LFS hsm_archive --archive $new_an $f
877 wait_request_state $fid ARCHIVE SUCCEED
879 check_hsm_flags $f "0x00000009"
883 run_test 9 "Use of explict archive number, with dedicated copytool"
886 needclients 3 || return 0
892 copytool_cleanup $(comma_list $(agts_nodes))
894 # start all of the copytools
895 for n in $(seq $AGTCOUNT); do
899 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
902 for n in $(seq $AGTCOUNT); do
903 file=$DIR/$tdir/$tfile.$n
904 fid=$(make_small $file)
906 $LFS hsm_archive $file || error "could not archive file $file"
907 wait_request_state $fid ARCHIVE SUCCEED
908 check_hsm_flags $file "0x00000009"
912 copytool_cleanup $(comma_list $(agts_nodes))
914 run_test 9a "Multiple remote agents"
917 # test needs a running copytool
920 mkdir -p $DIR/$tdir/d1
921 local f=$DIR/$tdir/$tfile
922 local fid=$(copy_file /etc/hosts $f)
923 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
924 error "hsm_archive failed"
925 wait_request_state $fid ARCHIVE SUCCEED
927 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
928 error "fid $fid not in archive $HSM_ARCHIVE"
929 echo "Verifying content"
930 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
931 echo "Verifying hsm state "
932 check_hsm_flags $f "0x00000009"
934 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
935 local st=$(get_hsm_archive_id $f)
936 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
937 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
942 run_test 10a "Archive a file"
945 # test needs a running copytool
949 local f=$DIR/$tdir/$tfile
950 local fid=$(copy_file /etc/hosts $f)
951 $LFS hsm_archive $f || error "archive request failed"
952 wait_request_state $fid ARCHIVE SUCCEED
954 $LFS hsm_archive $f || error "archive of non dirty file failed"
955 local cnt=$(get_request_count $fid ARCHIVE)
956 [[ "$cnt" == "1" ]] ||
957 error "archive of non dirty file must not make a request"
961 run_test 10b "Archive of non dirty file must work without doing request"
964 # test needs a running copytool
968 local f=$DIR/$tdir/$tfile
969 local fid=$(copy_file /etc/hosts $f)
970 $LFS hsm_set --noarchive $f
971 $LFS hsm_archive $f && error "archive a noarchive file must fail"
975 run_test 10c "Check forbidden archive"
978 # test needs a running copytool
982 local f=$DIR/$tdir/$tfile
983 local fid=$(copy_file /etc/hosts $f)
984 $LFS hsm_archive $f || error "cannot archive $f"
985 wait_request_state $fid ARCHIVE SUCCEED
987 local ar=$(get_hsm_archive_id $f)
988 local dflt=$(get_hsm_param default_archive_id)
989 [[ $ar == $dflt ]] ||
990 error "archived file is not on default archive: $ar != $dflt"
994 run_test 10d "Archive a file on the default archive id"
998 copy2archive /etc/hosts $tdir/$tfile
999 local f=$DIR/$tdir/$tfile
1001 import_file $tdir/$tfile $f
1002 echo -n "Verifying released state: "
1003 check_hsm_flags $f "0x0000000d"
1005 local LSZ=$(stat -c "%s" $f)
1006 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1008 echo "Verifying imported size $LSZ=$ASZ"
1009 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1010 echo -n "Verifying released pattern: "
1011 local PTRN=$($GETSTRIPE -L $f)
1013 [[ $PTRN == 80000001 ]] || error "Is not released"
1014 local fid=$(path2fid $f)
1015 echo "Verifying new fid $fid in archive"
1017 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1018 error "fid $fid not in archive $HSM_ARCHIVE"
1020 run_test 11a "Import a file"
1023 # test needs a running copytool
1027 local f=$DIR/$tdir/$tfile
1028 local fid=$(copy_file /etc/hosts $f)
1029 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1030 error "hsm_archive failed"
1031 wait_request_state $fid ARCHIVE SUCCEED
1033 local FILE_HASH=$(md5sum $f)
1038 echo "$FILE_HASH" | md5sum -c
1040 [[ $? -eq 0 ]] || error "Restored file differs"
1044 run_test 11b "Import a deleted file using its FID"
1047 # test needs a running copytool
1051 copy2archive /etc/hosts $tdir/$tfile
1053 local f=$DIR/$tdir/$tfile
1054 import_file $tdir/$tfile $f
1055 local f2=$DIR2/$tdir/$tfile
1056 echo "Verifying released state: "
1057 check_hsm_flags $f2 "0x0000000d"
1059 local fid=$(path2fid $f2)
1060 $LFS hsm_restore $f2
1061 wait_request_state $fid RESTORE SUCCEED
1063 echo "Verifying file state: "
1064 check_hsm_flags $f2 "0x00000009"
1066 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1068 [[ $? -eq 0 ]] || error "Restored file differs"
1072 run_test 12a "Restore an imported file explicitly"
1075 # test needs a running copytool
1079 copy2archive /etc/hosts $tdir/$tfile
1081 local f=$DIR/$tdir/$tfile
1082 import_file $tdir/$tfile $f
1083 echo "Verifying released state: "
1084 check_hsm_flags $f "0x0000000d"
1086 cat $f > /dev/null || error "File read failed"
1088 echo "Verifying file state after restore: "
1089 check_hsm_flags $f "0x00000009"
1091 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1093 [[ $? -eq 0 ]] || error "Restored file differs"
1097 run_test 12b "Restore an imported file implicitly"
1100 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1102 # test needs a running copytool
1106 local f=$DIR/$tdir/$tfile
1107 $LFS setstripe -c 2 $f
1108 local fid=$(make_large_for_striping $f)
1109 local FILE_CRC=$(md5sum $f)
1111 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1112 wait_request_state $fid ARCHIVE SUCCEED
1113 $LFS hsm_release $f || error "release $f failed"
1115 echo "$FILE_CRC" | md5sum -c
1117 [[ $? -eq 0 ]] || error "Restored file differs"
1121 run_test 12c "Restore a file with stripe of 2"
1124 # test needs a running copytool
1129 local f=$DIR/$tdir/$tfile
1130 local fid=$(copy_file /etc/hosts $f)
1131 $LFS hsm_restore $f || error "restore of non archived file failed"
1132 local cnt=$(get_request_count $fid RESTORE)
1133 [[ "$cnt" == "0" ]] ||
1134 error "restore non archived must not make a request"
1135 $LFS hsm_archive $f ||
1136 error "archive request failed"
1137 wait_request_state $fid ARCHIVE SUCCEED
1138 $LFS hsm_restore $f ||
1139 error "restore of non released file failed"
1140 local cnt=$(get_request_count $fid RESTORE)
1141 [[ "$cnt" == "0" ]] ||
1142 error "restore a non dirty file must not make a request"
1146 run_test 12d "Restore of a non archived, non released file must work"\
1147 " without doing request"
1150 # test needs a running copytool
1153 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1154 local f=$DIR/$tdir/$tfile
1155 local fid=$(copy_file /etc/hosts $f)
1156 $LFS hsm_archive $f || error "archive request failed"
1157 wait_request_state $fid ARCHIVE SUCCEED
1160 cat /etc/hosts >> $f
1164 $LFS hsm_restore $f && error "restore a dirty file must fail"
1168 run_test 12e "Check forbidden restore"
1171 # test needs a running copytool
1175 local f=$DIR/$tdir/$tfile
1176 local fid=$(copy_file /etc/hosts $f)
1178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1179 wait_request_state $fid ARCHIVE SUCCEED
1180 $LFS hsm_release $f || error "release of $f failed"
1182 wait_request_state $fid RESTORE SUCCEED
1184 echo -n "Verifying file state: "
1185 check_hsm_flags $f "0x00000009"
1187 diff -q /etc/hosts $f
1189 [[ $? -eq 0 ]] || error "Restored file differs"
1193 run_test 12f "Restore a released file explicitly"
1196 # test needs a running copytool
1200 local f=$DIR/$tdir/$tfile
1201 local fid=$(copy_file /etc/hosts $f)
1203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1204 wait_request_state $fid ARCHIVE SUCCEED
1205 $LFS hsm_release $f || error "release of $f failed"
1207 diff -q /etc/hosts $f
1210 # we check we had a restore done
1211 wait_request_state $fid RESTORE SUCCEED
1213 [[ $st -eq 0 ]] || error "Restored file differs"
1217 run_test 12g "Restore a released file implicitly"
1220 needclients 2 || return 0
1222 # test needs a running copytool
1226 local f=$DIR/$tdir/$tfile
1227 local fid=$(copy_file /etc/hosts $f)
1229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1230 wait_request_state $fid ARCHIVE SUCCEED
1231 $LFS hsm_release $f || error "release of $f failed"
1233 do_node $CLIENT2 diff -q /etc/hosts $f
1236 # we check we had a restore done
1237 wait_request_state $fid RESTORE SUCCEED
1239 [[ $st -eq 0 ]] || error "Restored file differs"
1243 run_test 12h "Restore a released file implicitly from a second node"
1246 # test needs a running copytool
1250 local f=$DIR/$tdir/$tfile
1251 local fid=$(copy_file /etc/passwd $f)
1252 $LFS hsm_archive $f || error "archive of $f failed"
1253 wait_request_state $fid ARCHIVE SUCCEED
1255 $LFS hsm_release $f || error "release of $f failed"
1259 [[ $? -eq 0 ]] || error "Restored file differs"
1263 run_test 12m "Archive/release/implicit restore"
1266 # test needs a running copytool
1270 copy2archive /etc/hosts $tdir/$tfile
1272 local f=$DIR/$tdir/$tfile
1273 import_file $tdir/$tfile $f
1275 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1276 error "Restored file differs"
1278 $LFS hsm_release $f || error "release of $f failed"
1282 run_test 12n "Import/implicit restore/release"
1285 # test needs a running copytool
1289 local f=$DIR/$tdir/$tfile
1290 local fid=$(copy_file /etc/hosts $f)
1292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1293 wait_request_state $fid ARCHIVE SUCCEED
1294 $LFS hsm_release $f || error "release of $f failed"
1296 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1297 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1299 # set no retry action mode
1302 diff -q /etc/hosts $f
1305 # we check we had a restore failure
1306 wait_request_state $fid RESTORE FAILED
1308 [[ $st -eq 0 ]] && error "Restore must fail"
1310 # remove no retry action mode
1313 # check file is still released
1314 check_hsm_flags $f "0x0000000d"
1316 # retry w/o failure injection
1317 do_facet $SINGLEMDS lctl set_param fail_loc=0
1319 # to be sure previous RESTORE result is gone
1321 wait_for_grace_delay
1323 diff -q /etc/hosts $f
1326 # we check we had a restore done
1327 wait_request_state $fid RESTORE SUCCEED
1329 [[ $st -eq 0 ]] || error "Restored file differs"
1333 run_test 12o "Layout-swap failure during Restore leaves file released"
1336 # test needs a running copytool
1339 local ARC_SUBDIR="import.orig"
1343 # populate directory to be imported
1344 for d in $(seq 1 10); do
1345 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1346 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1347 for f in $(seq 1 10); do
1348 CURR_FILE="$CURR_DIR/$tfile.$f"
1349 # write file-specific data
1350 do_facet $SINGLEAGT \
1351 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1352 "file=$CURR_FILE > $CURR_FILE"
1356 import_file "$ARC_SUBDIR" $DIR/$tdir
1357 # diff lustre content and origin (triggers file restoration)
1358 # there must be 10x10 identical files, and no difference
1359 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1360 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1361 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1362 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1364 [ $cnt_diff -eq 0 ] ||
1365 error "$cnt_diff imported files differ from read data"
1366 [ $cnt_ok -eq 100 ] ||
1367 error "not enough identical files ($cnt_ok != 100)"
1371 run_test 13 "Recursively import and restore a directory"
1374 # test needs a running copytool
1379 local f=$DIR/$tdir/$tfile
1380 local fid=$(make_small $f)
1381 local sum=$(md5sum $f | awk '{print $1}')
1382 $LFS hsm_archive $f || error "could not archive file"
1383 wait_request_state $fid ARCHIVE SUCCEED
1387 # create released file (simulate llapi_hsm_import call)
1389 local fid2=$(path2fid $f)
1390 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1391 $LFS hsm_release $f || error "could not release file"
1393 # rebind the archive to the newly created file
1394 echo "rebind $fid to $fid2"
1396 do_facet $SINGLEAGT \
1397 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1398 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1400 # restore file and compare md5sum
1401 local sum2=$(md5sum $f | awk '{print $1}')
1403 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1407 run_test 14 "Rebind archived file to a new fid"
1410 # test needs a running copytool
1415 local f=$DIR/$tdir/$tfile
1417 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1421 for i in $(seq 1 $count); do
1422 fids[$i]=$(make_small $f.$i)
1423 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1424 $LFS hsm_archive $f.$i || error "could not archive file"
1426 wait_all_done $(($count*60))
1430 for i in $(seq 1 $count); do
1433 local fid2=$(path2fid $f.$i)
1434 # add the rebind operation to the list
1435 echo ${fids[$i]} $fid2 >> $tmpfile
1437 # set it released (simulate llapi_hsm_import call)
1438 $LFS hsm_set --archived --exists $f.$i ||
1439 error "could not force hsm flags"
1440 $LFS hsm_release $f.$i || error "could not release file"
1442 nl=$(wc -l < $tmpfile)
1443 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1445 echo "rebind list of files"
1446 do_facet $SINGLEAGT \
1447 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1448 --rebind $tmpfile $DIR" || error "could not rebind file list"
1450 # restore files and compare md5sum
1451 for i in $(seq 1 $count); do
1452 local sum2=$(md5sum $f.$i | awk '{print $1}')
1453 [[ $sum2 == ${sums[$i]} ]] ||
1454 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1460 run_test 15 "Rebind a list of files"
1463 # test needs a running copytool
1467 # create a known size file so we can verify transfer speed
1470 dd if=/dev/zero of=$ref bs=1M count=20
1473 local f=$DIR/$tdir/$tfile
1474 local fid=$(copy_file $ref $f)
1476 local start=$(date +%s)
1478 wait_request_state $fid ARCHIVE SUCCEED
1479 local end=$(date +%s)
1480 local duration=$((end - start))
1482 [[ $duration -ge $goal ]] ||
1483 error "Transfer is too fast $duration < $goal"
1487 run_test 16 "Test CT bandwith control option"
1492 local f=$DIR/$tdir/$tfile
1493 touch $f || error "touch $f failed"
1495 # Could not release a non-archived file
1496 $LFS hsm_release $f && error "release should not succeed"
1498 # For following tests, we must test them with HS_ARCHIVED set
1499 $LFS hsm_set --exists --archived $f || error "could not add flag"
1501 # Could not release a file if no-release is set
1502 $LFS hsm_set --norelease $f || error "could not add flag"
1503 $LFS hsm_release $f && error "release should not succeed"
1504 $LFS hsm_clear --norelease $f || error "could not remove flag"
1506 # Could not release a file if lost
1507 $LFS hsm_set --lost $f || error "could not add flag"
1508 $LFS hsm_release $f && error "release should not succeed"
1509 $LFS hsm_clear --lost $f || error "could not remove flag"
1511 # Could not release a file if dirty
1512 $LFS hsm_set --dirty $f || error "could not add flag"
1513 $LFS hsm_release $f && error "release should not succeed"
1514 $LFS hsm_clear --dirty $f || error "could not remove flag"
1516 run_test 20 "Release is not permitted"
1519 # test needs a running copytool
1523 local f=$DIR/$tdir/test_release
1525 # Create a file and check its states
1526 local fid=$(make_small $f)
1527 check_hsm_flags $f "0x00000000"
1529 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1530 # used until file is flushed to disk
1531 if [ $(facet_fstype ost1) == "zfs" ]; then
1532 # this causes an OST_SYNC rpc to be sent
1533 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1534 # clear locks to reread file data
1535 cancel_lru_locks osc
1538 local orig_size=$(stat -c "%s" $f)
1539 local orig_blocks=$(stat -c "%b" $f)
1541 start_full_debug_logging
1543 $LFS hsm_archive $f || error "could not archive file"
1544 wait_request_state $fid ARCHIVE SUCCEED
1546 local blocks=$(stat -c "%b" $f)
1547 [ $blocks -eq $orig_blocks ] ||
1548 error "$f: wrong block number after archive: " \
1549 "$blocks != $orig_blocks"
1550 local size=$(stat -c "%s" $f)
1551 [ $size -eq $orig_size ] ||
1552 error "$f: wrong size after archive: $size != $orig_size"
1554 # Release and check states
1555 $LFS hsm_release $f || error "could not release file"
1556 check_hsm_flags $f "0x0000000d"
1558 blocks=$(stat -c "%b" $f)
1559 [ $blocks -gt 5 ] &&
1560 error "$f: too many blocks after release: $blocks > 5"
1561 size=$(stat -c "%s" $f)
1562 [ $size -ne $orig_size ] &&
1563 error "$f: wrong size after release: $size != $orig_size"
1565 # Check we can release an file without stripe info
1569 check_hsm_flags $f "0x00000000"
1570 $LFS hsm_archive $f || error "could not archive file"
1571 wait_request_state $fid ARCHIVE SUCCEED
1573 # Release and check states
1574 $LFS hsm_release $f || error "could not release file"
1575 check_hsm_flags $f "0x0000000d"
1577 # Release again a file that is already released is OK
1578 $LFS hsm_release $f || fail "second release should succeed"
1579 check_hsm_flags $f "0x0000000d"
1581 stop_full_debug_logging
1585 run_test 21 "Simple release tests"
1588 # test needs a running copytool
1593 local f=$DIR/$tdir/test_release
1594 local swap=$DIR/$tdir/test_swap
1596 # Create a file and check its states
1597 local fid=$(make_small $f)
1598 check_hsm_flags $f "0x00000000"
1600 $LFS hsm_archive $f || error "could not archive file"
1601 wait_request_state $fid ARCHIVE SUCCEED
1603 # Release and check states
1604 $LFS hsm_release $f || error "could not release file"
1605 check_hsm_flags $f "0x0000000d"
1608 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1613 run_test 22 "Could not swap a release file"
1616 # test needs a running copytool
1621 local f=$DIR/$tdir/test_mtime
1623 # Create a file and check its states
1624 local fid=$(make_small $f)
1625 check_hsm_flags $f "0x00000000"
1627 $LFS hsm_archive $f || error "could not archive file"
1628 wait_request_state $fid ARCHIVE SUCCEED
1630 # Set modification time in the past
1631 touch -m -a -d @978261179 $f
1633 # Release and check states
1634 $LFS hsm_release $f || error "could not release file"
1635 check_hsm_flags $f "0x0000000d"
1637 local MTIME=$(stat -c "%Y" $f)
1638 local ATIME=$(stat -c "%X" $f)
1639 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1640 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1644 run_test 23 "Release does not change a/mtime (utime)"
1647 local file=$DIR/$tdir/$tfile
1656 # test needs a running copytool
1661 fid=$(make_small $file)
1663 # Create a file and check its states
1664 check_hsm_flags $file "0x00000000"
1666 # Ensure atime is less than mtime and ctime.
1670 atime0=$(stat -c "%X" $file)
1671 mtime0=$(stat -c "%Y" $file)
1672 ctime0=$(stat -c "%Z" $file)
1674 [ $atime0 -lt $mtime0 ] ||
1675 error "atime $atime0 is not less than mtime $mtime0"
1677 [ $atime0 -lt $ctime0 ] ||
1678 error "atime $atime0 is not less than ctime $ctime0"
1680 # Archive should not change any timestamps.
1681 $LFS hsm_archive $file || error "cannot archive '$file'"
1682 wait_request_state $fid ARCHIVE SUCCEED
1684 atime1=$(stat -c "%X" $file)
1685 mtime1=$(stat -c "%Y" $file)
1686 ctime1=$(stat -c "%Z" $file)
1688 [ $atime0 -eq $atime1 ] ||
1689 error "archive changed atime from $atime0 to $atime1"
1691 [ $mtime0 -eq $mtime1 ] ||
1692 error "archive changed mtime from $mtime0 to $mtime1"
1694 [ $ctime0 -eq $ctime1 ] ||
1695 error "archive changed ctime from $ctime0 to $ctime1"
1697 # Release should not change any timestamps.
1698 $LFS hsm_release $file || error "cannot release '$file'"
1699 check_hsm_flags $file "0x0000000d"
1701 atime1=$(stat -c "%X" $file)
1702 mtime1=$(stat -c "%Y" $file)
1703 ctime1=$(stat -c "%Z" $file)
1705 [ $atime0 -eq $atime1 ] ||
1706 error "release changed atime from $atime0 to $atime1"
1708 [ $mtime0 -eq $mtime1 ] ||
1709 error "release changed mtime from $mtime0 to $mtime1"
1711 [ $ctime0 -eq $ctime1 ] ||
1712 error "release changed ctime from $ctime0 to $ctime1"
1714 # Restore should not change atime or mtime and should not
1716 $LFS hsm_restore $file
1717 wait_request_state $fid RESTORE SUCCEED
1719 atime1=$(stat -c "%X" $file)
1720 mtime1=$(stat -c "%Y" $file)
1721 ctime1=$(stat -c "%Z" $file)
1723 [ $atime0 -eq $atime1 ] ||
1724 error "restore changed atime from $atime0 to $atime1"
1726 [ $mtime0 -eq $mtime1 ] ||
1727 error "restore changed mtime from $mtime0 to $mtime1"
1729 [ $ctime0 -le $ctime1 ] ||
1730 error "restore changed ctime from $ctime0 to $ctime1"
1734 # Once more, after unmount and mount.
1735 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1736 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1738 atime1=$(stat -c "%X" $file)
1739 mtime1=$(stat -c "%Y" $file)
1740 ctime1=$(stat -c "%Z" $file)
1742 [ $atime0 -eq $atime1 ] ||
1743 error "remount changed atime from $atime0 to $atime1"
1745 [ $mtime0 -eq $mtime1 ] ||
1746 error "remount changed mtime from $mtime0 to $mtime1"
1748 [ $ctime0 -le $ctime1 ] ||
1749 error "remount changed ctime from $ctime0 to $ctime1"
1751 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1754 local file=$DIR/$tdir/$tfile
1760 # Test needs a running copytool.
1764 # Check that root can do HSM actions on a ordinary user's file.
1766 fid=$(make_small $file)
1767 sum0=$(md5sum $file)
1769 chown $RUNAS_ID:$RUNAS_GID $file ||
1770 error "cannot chown '$file' to '$RUNAS_ID'"
1772 chmod ugo-w $DIR/$tdir ||
1773 error "cannot chmod '$DIR/$tdir'"
1775 $LFS hsm_archive $file
1776 wait_request_state $fid ARCHIVE SUCCEED
1778 $LFS hsm_release $file
1779 check_hsm_flags $file "0x0000000d"
1781 $LFS hsm_restore $file
1782 wait_request_state $fid RESTORE SUCCEED
1784 # Check that ordinary user can get HSM state.
1785 $RUNAS $LFS hsm_state $file ||
1786 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1788 $LFS hsm_release $file
1789 check_hsm_flags $file "0x0000000d"
1791 # Check that ordinary user can accessed released file.
1792 sum1=$($RUNAS md5sum $file) ||
1793 error "user '$RUNAS_ID' cannot read '$file'"
1795 [ "$sum0" == "$sum1" ] ||
1796 error "md5sum mismatch for '$file'"
1800 run_test 24b "root can archive, release, and restore user files"
1802 cleanup_test_24c() {
1804 set_hsm_param user_request_mask RESTORE
1805 set_hsm_param group_request_mask RESTORE
1806 set_hsm_param other_request_mask RESTORE
1810 local file=$DIR/$tdir/$tfile
1811 local action=archive
1816 # test needs a running copytool
1821 # Save the default masks and check that cleanup_24c will
1822 # restore the request masks correctly.
1823 user_save=$(get_hsm_param user_request_mask)
1824 group_save=$(get_hsm_param group_request_mask)
1825 other_save=$(get_hsm_param other_request_mask)
1827 [ "$user_save" == RESTORE ] ||
1828 error "user_request_mask is '$user_save' expected 'RESTORE'"
1829 [ "$group_save" == RESTORE ] ||
1830 error "group_request_mask is '$group_save' expected 'RESTORE'"
1831 [ "$other_save" == RESTORE ] ||
1832 error "other_request_mask is '$other_save' expected 'RESTORE'"
1834 trap cleanup_test_24c EXIT
1839 chown $RUNAS_ID:nobody $file ||
1840 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1842 set_hsm_param user_request_mask ""
1843 $RUNAS $LFS hsm_$action $file &&
1844 error "$action by user should fail"
1846 set_hsm_param user_request_mask $action
1847 $RUNAS $LFS hsm_$action $file ||
1848 error "$action by user should succeed"
1853 chown nobody:$RUNAS_GID $file ||
1854 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1856 set_hsm_param group_request_mask ""
1857 $RUNAS $LFS hsm_$action $file &&
1858 error "$action by group should fail"
1860 set_hsm_param group_request_mask $action
1861 $RUNAS $LFS hsm_$action $file ||
1862 error "$action by group should succeed"
1867 chown nobody:nobody $file ||
1868 error "cannot chown '$file' to 'nobody:nobody'"
1870 set_hsm_param other_request_mask ""
1871 $RUNAS $LFS hsm_$action $file &&
1872 error "$action by other should fail"
1874 set_hsm_param other_request_mask $action
1875 $RUNAS $LFS hsm_$action $file ||
1876 error "$action by other should succeed"
1881 run_test 24c "check that user,group,other request masks work"
1883 cleanup_test_24d() {
1885 mount -o remount,rw $MOUNT2
1889 local file1=$DIR/$tdir/$tfile
1890 local file2=$DIR2/$tdir/$tfile
1898 fid1=$(make_small $file1)
1900 trap cleanup_test_24d EXIT
1902 mount -o remount,ro $MOUNT2
1904 fid2=$(path2fid $file2)
1905 [ "$fid1" == "$fid2" ] ||
1906 error "FID mismatch '$fid1' != '$fid2'"
1908 $LFS hsm_archive $file2 &&
1909 error "archive should fail on read-only mount"
1910 check_hsm_flags $file1 "0x00000000"
1912 $LFS hsm_archive $file1
1913 wait_request_state $fid1 ARCHIVE SUCCEED
1915 $LFS hsm_release $file1
1916 $LFS hsm_restore $file2
1917 wait_request_state $fid1 RESTORE SUCCEED
1919 $LFS hsm_release $file1 || error "cannot release '$file1'"
1920 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1922 $LFS hsm_release $file2 &&
1923 error "release should fail on read-only mount"
1928 run_test 24d "check that read-only mounts are respected"
1931 # test needs a running copytool
1935 copy2archive /etc/hosts $tdir/$tfile
1937 local f=$DIR/$tdir/$tfile
1939 import_file $tdir/$tfile $f
1941 $LFS hsm_set --lost $f
1946 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1950 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1951 " (Operation not permitted)"
1954 # test needs a running copytool
1959 local f=$DIR/$tdir/$tfile
1960 local fid=$(copy_file /etc/passwd $f)
1962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1963 wait_request_state $fid ARCHIVE SUCCEED
1966 $LFS hsm_set --lost $f
1970 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1974 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1975 " (Operation not permitted)"
1978 # test needs a running copytool
1982 local f=$DIR/$tdir/$tfile
1983 local fid=$(make_large_for_progress $f)
1984 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1985 wait_request_state $fid ARCHIVE SUCCEED
1988 wait_request_state $fid REMOVE SUCCEED
1990 check_hsm_flags $f "0x00000000"
1994 run_test 26 "Remove the archive of a valid file"
1997 # test needs a running copytool
2001 make_archive $tdir/$tfile
2002 local f=$DIR/$tdir/$tfile
2003 import_file $tdir/$tfile $f
2004 local fid=$(path2fid $f)
2008 [[ $? != 0 ]] || error "Remove of a released file should fail"
2012 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2015 # test needs a running copytool
2019 local f=$DIR/$tdir/$tfile
2020 local fid=$(make_large_for_progress $f)
2021 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2022 wait_request_state $fid ARCHIVE SUCCEED
2027 [[ $? != 0 ]] || error "Remove of a released file should fail"
2031 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2034 # test needs a running copytool
2038 local f=$DIR/$tdir/$tfile
2039 local fid=$(make_large_for_progress $f)
2040 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2041 wait_request_state $fid ARCHIVE SUCCEED
2050 wait_request_state $fid REMOVE SUCCEED
2054 run_test 28 "Concurrent archive/file remove"
2057 # restore at exec cannot work on agent node (because of Linux kernel
2058 # protection of executables)
2059 needclients 2 || return 0
2061 # test needs a running copytool
2065 copy2archive /bin/true $tdir/$tfile
2067 local f=$DIR/$tdir/true
2068 import_file $tdir/$tfile $f
2070 local fid=$(path2fid $f)
2072 # set no retry action mode
2078 # remove no try action mode
2082 [[ $st == 0 ]] || error "Failed to exec a released file"
2086 run_test 30a "Restore at exec (import case)"
2089 # restore at exec cannot work on agent node (because of Linux kernel
2090 # protection of executables)
2091 needclients 2 || return 0
2093 # test needs a running copytool
2097 local f=$DIR/$tdir/true
2098 local fid=$(copy_file /bin/true $f)
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2101 wait_request_state $fid ARCHIVE SUCCEED
2104 # set no retry action mode
2110 # remove no try action mode
2114 [[ $st == 0 ]] || error "Failed to exec a released file"
2118 run_test 30b "Restore at exec (release case)"
2121 needclients 2 || return 0
2123 # test needs a running copytool
2127 local f=$DIR/$tdir/SLEEP
2128 local fid=$(copy_file /bin/sleep $f)
2130 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2131 wait_request_state $fid ARCHIVE SUCCEED
2133 check_hsm_flags $f "0x0000000d"
2134 # set no retry action mode
2136 do_node $CLIENT2 "$f 10" &
2140 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2142 [[ $? == 0 ]] || error "Execution failed during run"
2144 [[ $? == 0 ]] || error "Binary overwritten during exec"
2147 # remove no try action mode
2149 check_hsm_flags $f "0x00000009"
2153 run_test 30c "Update during exec of released file must fail"
2155 restore_and_check_size() {
2158 local s=$(stat -c "%s" $f)
2160 local st=$(get_hsm_flags $f)
2164 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2166 n=$(stat -c "%s" $f)
2167 # we echo in both cases to show stat is not
2169 if [[ $n != $s ]]; then
2170 echo "size seen is $n != $s"
2173 echo "size seen is right: $n == $s"
2175 st=$(get_hsm_flags $f)
2179 if [[ $cpt -lt 10 ]]; then
2182 echo " restore is too long"
2183 wait_request_state $fid RESTORE SUCCEED
2189 # test needs a running copytool
2194 make_archive $tdir/$tfile
2195 local f=$DIR/$tdir/$tfile
2196 import_file $tdir/$tfile $f
2197 local fid=$($LFS path2fid $f)
2198 HSM_ARCHIVE_PURGE=false copytool_setup
2200 restore_and_check_size $f $fid
2203 [[ $err -eq 0 ]] || error "File size changed during restore"
2207 run_test 31a "Import a large file and check size during restore"
2211 # test needs a running copytool
2216 local f=$DIR/$tdir/$tfile
2217 local fid=$(make_large_for_progress $f)
2218 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2219 wait_request_state $fid ARCHIVE SUCCEED
2222 restore_and_check_size $f $fid
2225 [[ $err -eq 0 ]] || error "File size changed during restore"
2229 run_test 31b "Restore a large unaligned file and check size during restore"
2232 # test needs a running copytool
2237 local f=$DIR/$tdir/$tfile
2238 local fid=$(make_large_for_progress_aligned $f)
2239 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2240 wait_request_state $fid ARCHIVE SUCCEED
2243 restore_and_check_size $f $fid
2246 [[ $err -eq 0 ]] || error "File size changed during restore"
2250 run_test 31c "Restore a large aligned file and check size during restore"
2253 # test needs a running copytool
2258 local f=$DIR/$tdir/$tfile
2259 local fid=$(make_large_for_progress $f)
2260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2261 wait_request_state $fid ARCHIVE SUCCEED
2264 # to be sure wait_all_done will not be mislead by previous tests
2267 wait_for_grace_delay
2268 # Also raise grace_delay significantly so the Canceled
2269 # Restore action will stay enough long avail.
2270 local old_grace=$(get_hsm_param grace_delay)
2271 set_hsm_param grace_delay 100
2273 md5sum $f >/dev/null &
2275 wait_request_state $fid RESTORE STARTED
2280 # Check restore trigger process was killed
2281 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2285 # instead of waiting+checking both Restore and Cancel ops
2286 # sequentially, wait for both to be finished and then check
2288 wait_all_done 100 $fid
2289 local rstate=$(get_request_state $fid RESTORE)
2290 local cstate=$(get_request_state $fid CANCEL)
2292 # restore orig grace_delay.
2293 set_hsm_param grace_delay $old_grace
2295 if [[ "$rstate" == "CANCELED" ]] ; then
2296 [[ "$cstate" == "SUCCEED" ]] ||
2297 error "Restore state is CANCELED and Cancel state " \
2298 "is not SUCCEED but $cstate"
2299 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2300 elif [[ "$rstate" == "SUCCEED" ]] ; then
2301 [[ "$cstate" == "FAILED" ]] ||
2302 error "Restore state is SUCCEED and Cancel state " \
2303 "is not FAILED but $cstate"
2304 echo "Restore state is SUCCEED, Cancel state is FAILED"
2306 error "Restore state is $rstate and Cancel state is $cstate"
2310 error "Cannot kill process waiting for restore ($killed)"
2314 run_test 33 "Kill a restore waiting process"
2317 # test needs a running copytool
2322 local f=$DIR/$tdir/$tfile
2323 local fid=$(make_large_for_progress $f)
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2325 wait_request_state $fid ARCHIVE SUCCEED
2328 md5sum $f >/dev/null &
2330 wait_request_state $fid RESTORE STARTED
2332 rm $f || error "rm $f failed"
2333 # rm must not block during restore
2334 wait_request_state $fid RESTORE STARTED
2336 wait_request_state $fid RESTORE SUCCEED
2337 # check md5sum pgm finished
2338 local there=$(ps -o pid,comm hp $pid >/dev/null)
2339 [[ -z $there ]] || error "Restore initiator does not exit"
2341 local rc=$(wait $pid)
2342 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2346 run_test 34 "Remove file during restore"
2349 # test needs a running copytool
2354 local f=$DIR/$tdir/$tfile
2355 local f1=$DIR/$tdir/$tfile-1
2356 local fid=$(make_large_for_progress $f)
2357 local fid1=$(copy_file /etc/passwd $f1)
2358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2359 wait_request_state $fid ARCHIVE SUCCEED
2362 md5sum $f >/dev/null &
2364 wait_request_state $fid RESTORE STARTED
2366 mv $f1 $f || error "mv $f1 $f failed"
2367 # mv must not block during restore
2368 wait_request_state $fid RESTORE STARTED
2370 wait_request_state $fid RESTORE SUCCEED
2371 # check md5sum pgm finished
2372 local there=$(ps -o pid,comm hp $pid >/dev/null)
2373 [[ -z $there ]] || error "Restore initiator does not exit"
2375 local rc=$(wait $pid)
2376 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2379 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2383 run_test 35 "Overwrite file during restore"
2386 # test needs a running copytool
2391 local f=$DIR/$tdir/$tfile
2392 local fid=$(make_large_for_progress $f)
2393 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2394 wait_request_state $fid ARCHIVE SUCCEED
2397 md5sum $f >/dev/null &
2399 wait_request_state $fid RESTORE STARTED
2402 # rm must not block during restore
2403 wait_request_state $fid RESTORE STARTED
2405 wait_request_state $fid RESTORE SUCCEED
2406 # check md5sum pgm finished
2407 local there=$(ps -o pid,comm hp $pid >/dev/null)
2409 error "Restore initiator does not exit"
2411 local rc=$(wait $pid)
2413 error "Restore initiator failed with $rc"
2417 run_test 36 "Move file during restore"
2424 for n in $(seq 1 $count); do
2425 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2427 echo "$count archive requests submitted"
2431 local stream_count=4
2432 local file_count=100
2434 local f=$DIR/$tdir/$tfile
2439 for i in $(seq 1 $file_count); do
2440 for p in $(seq 1 $stream_count); do
2441 fid=$(copy_file /etc/hosts $f.$p.$i)
2444 # force copytool to use a local/temp archive dir to ensure best
2445 # performance vs remote/NFS mounts used in auto-tests
2446 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2449 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2451 # to be sure wait_all_done will not be mislead by previous tests
2453 wait_for_grace_delay
2455 # start archive streams in background (archive files in parallel)
2456 for p in $(seq 1 $stream_count); do
2457 multi_archive $f.$p $file_count &
2460 echo -n "Wait for all requests being enqueued..."
2466 run_test 40 "Parallel archive requests"
2469 # test needs a running copytool
2473 local f=$DIR/$tdir/$tfile
2474 local fid=$(copy_file /etc/motd $f 1)
2476 $LFS hsm_archive $f || error "could not archive file"
2477 wait_request_state $fid ARCHIVE SUCCEED
2478 check_hsm_flags $f "0x00000009"
2480 multiop_bg_pause $f O_c || error "multiop failed"
2484 client_up || client_up || true
2486 kill -USR1 $MULTIPID
2487 wait $MULTIPID || error "multiop close failed"
2489 check_hsm_flags $f "0x0000000b"
2493 run_test 52 "Opened for write file on an evicted client should be set dirty"
2496 # test needs a running copytool
2500 local f=$DIR/$tdir/$tfile
2501 local fid=$(copy_file /etc/motd $f 1)
2503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2504 error "could not archive file"
2505 wait_request_state $fid ARCHIVE SUCCEED
2506 check_hsm_flags $f "0x00000009"
2508 multiop_bg_pause $f o_c || error "multiop failed"
2512 client_up || client_up || true
2514 kill -USR1 $MULTIPID
2515 wait $MULTIPID || error "multiop close failed"
2517 check_hsm_flags $f "0x00000009"
2521 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2524 # test needs a running copytool
2528 local f=$DIR/$tdir/$tfile
2529 local fid=$(make_small $f)
2531 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2532 error "could not archive file"
2533 wait_request_state $fid ARCHIVE STARTED
2535 check_hsm_flags $f "0x00000001"
2537 # Avoid coordinator resending this request as soon it has failed.
2542 wait_request_state $fid ARCHIVE FAILED
2544 check_hsm_flags $f "0x00000003"
2549 run_test 54 "Write during an archive cancels it"
2552 # test needs a running copytool
2556 local f=$DIR/$tdir/$tfile
2557 local fid=$(make_small $f)
2559 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2560 error "could not archive file"
2561 wait_request_state $fid ARCHIVE STARTED
2563 check_hsm_flags $f "0x00000001"
2565 # Avoid coordinator resending this request as soon it has failed.
2568 $TRUNCATE $f 1024 || error "truncate failed"
2570 wait_request_state $fid ARCHIVE FAILED
2572 check_hsm_flags $f "0x00000003"
2577 run_test 55 "Truncate during an archive cancels it"
2580 # test needs a running copytool
2584 local f=$DIR/$tdir/$tfile
2585 local fid=$(make_large_for_progress $f)
2587 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2588 error "could not archive file"
2589 wait_request_state $fid ARCHIVE STARTED
2591 check_hsm_flags $f "0x00000001"
2593 # Change metadata and sync to be sure we are not changing only
2598 wait_request_state $fid ARCHIVE SUCCEED
2600 check_hsm_flags $f "0x00000009"
2604 run_test 56 "Setattr during an archive is ok"
2607 # Need one client for I/O, one for request
2608 needclients 2 || return 0
2610 # test needs a running copytool
2614 local f=$DIR/$tdir/test_archive_remote
2615 # Create a file on a remote node
2616 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2617 "count=2 conv=fsync"
2620 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2621 error "hsm_archive failed"
2622 local fid=$(path2fid $f)
2623 wait_request_state $fid ARCHIVE SUCCEED
2625 # Release and implicit restore it
2626 do_node $CLIENT2 "$LFS hsm_release $f" ||
2627 error "hsm_release failed"
2628 do_node $CLIENT2 "md5sum $f" ||
2629 error "hsm_restore failed"
2631 wait_request_state $fid RESTORE SUCCEED
2635 run_test 57 "Archive a file with dirty cache on another node"
2637 truncate_released_file() {
2641 local sz=$(stat -c %s $src_file)
2642 local f=$DIR/$tdir/$tfile
2643 local fid=$(copy_file $1 $f)
2647 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2648 error "could not archive file"
2649 wait_request_state $fid ARCHIVE SUCCEED
2651 $LFS hsm_release $f || error "could not release file"
2653 $TRUNCATE $f $trunc_to || error "truncate failed"
2656 local sz1=$(stat -c %s $f)
2657 [[ $sz1 == $trunc_to ]] ||
2658 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2661 check_hsm_flags $f "0x0000000b"
2663 local state=$(get_request_state $fid RESTORE)
2664 [[ "$state" == "SUCCEED" ]] ||
2665 error "truncate $sz does not trig restore, state = $state"
2667 $TRUNCATE $ref $trunc_to
2668 cmp $ref $f || error "file data wrong after truncate"
2674 # test needs a running copytool
2679 local sz=$(stat -c %s /etc/passwd)
2681 echo "truncate up from $sz to $((sz*2))"
2682 truncate_released_file /etc/passwd $((sz*2))
2684 echo "truncate down from $sz to $((sz/2))"
2685 truncate_released_file /etc/passwd $((sz/2))
2687 echo "truncate to 0"
2688 truncate_released_file /etc/passwd 0
2692 run_test 58 "Truncate a released file will trigger restore"
2695 # This test validates the fix for LU-4512. Ensure that the -u
2696 # option changes the progress reporting interval from the default
2697 # (30 seconds) to the user-specified interval.
2699 local progress_timeout=$((interval * 3))
2701 # test needs a new running copytool
2703 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2706 local f=$DIR/$tdir/$tfile
2707 local fid=$(make_large_for_progress $f)
2709 local start_at=$(date +%s)
2710 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2711 error "could not archive file"
2714 local mdt=${MDT_PREFIX}${mdtidx}
2715 local mds=mds$((mdtidx + 1))
2717 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2718 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2724 echo -n "Expecting a progress update within $progress_timeout seconds... "
2726 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2727 if [ $RESULT -gt 0 ]; then
2728 echo "$RESULT bytes copied in $WAIT seconds."
2730 elif [ $WAIT -ge $progress_timeout ]; then
2731 error "Timed out waiting for progress update!"
2734 WAIT=$((WAIT + sleep))
2738 local finish_at=$(date +%s)
2739 local elapsed=$((finish_at - start_at))
2741 # Ensure that the progress update occurred within the expected window.
2742 if [ $elapsed -lt $interval ]; then
2743 error "Expected progress update after at least $interval seconds"
2749 run_test 60 "Changing progress update interval from default"
2752 # test needs a new running copytool
2754 copytool_monitor_setup
2755 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2757 # Just start and stop the copytool to generate events.
2761 local REGISTER_EVENT
2762 local UNREGISTER_EVENT
2763 while read event; do
2764 local parsed=$(parse_json_event "$event")
2765 if [ -z "$parsed" ]; then
2766 error "Copytool sent malformed event: $event"
2770 if [ $event_type == "REGISTER" ]; then
2771 REGISTER_EVENT=$event
2772 elif [ $event_type == "UNREGISTER" ]; then
2773 UNREGISTER_EVENT=$event
2775 done < <(echo $"$(get_copytool_event_log)")
2777 if [ -z "$REGISTER_EVENT" ]; then
2778 error "Copytool failed to send register event to FIFO"
2781 if [ -z "$UNREGISTER_EVENT" ]; then
2782 error "Copytool failed to send unregister event to FIFO"
2785 copytool_monitor_cleanup
2786 echo "Register/Unregister events look OK."
2788 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2791 # Bump progress interval for livelier events.
2794 # test needs a new running copytool
2796 copytool_monitor_setup
2797 HSMTOOL_UPDATE_INTERVAL=$interval \
2798 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2801 local f=$DIR/$tdir/$tfile
2802 local fid=$(make_large_for_progress $f)
2804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2805 error "could not archive file"
2806 wait_request_state $fid ARCHIVE SUCCEED
2808 local expected_fields="event_time data_fid source_fid"
2809 expected_fields+=" total_bytes current_bytes"
2813 while read event; do
2814 # Make sure we're not getting anything from previous events.
2815 for field in $expected_fields; do
2819 local parsed=$(parse_json_event "$event")
2820 if [ -z "$parsed" ]; then
2821 error "Copytool sent malformed event: $event"
2825 if [ $event_type == "ARCHIVE_START" ]; then
2828 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2831 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2835 # Do some simple checking of the progress update events.
2836 for expected_field in $expected_fields; do
2837 if [ -z ${!expected_field+x} ]; then
2838 error "Missing $expected_field field in event"
2842 if [ $total_bytes -eq 0 ]; then
2843 error "Expected total_bytes to be > 0"
2846 # These should be identical throughout an archive
2848 if [ $source_fid != $data_fid ]; then
2849 error "Expected source_fid to equal data_fid"
2851 done < <(echo $"$(get_copytool_event_log)")
2853 if [ -z "$START_EVENT" ]; then
2854 error "Copytool failed to send archive start event to FIFO"
2857 if [ -z "$FINISH_EVENT" ]; then
2858 error "Copytool failed to send archive finish event to FIFO"
2861 echo "Archive events look OK."
2865 copytool_monitor_cleanup
2867 run_test 71 "Copytool logs JSON archive events to FIFO"
2870 # Bump progress interval for livelier events.
2873 # test needs a new running copytool
2875 copytool_monitor_setup
2876 HSMTOOL_UPDATE_INTERVAL=$interval \
2877 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2878 local test_file=$HSMTOOL_MONITOR_DIR/file
2880 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2882 do_facet $SINGLEAGT "$cmd" ||
2883 error "cannot create $test_file on $SINGLEAGT"
2884 copy2archive $test_file $tdir/$tfile
2887 local f=$DIR/$tdir/$tfile
2888 import_file $tdir/$tfile $f
2889 f=$DIR2/$tdir/$tfile
2890 echo "Verifying released state: "
2891 check_hsm_flags $f "0x0000000d"
2893 local fid=$(path2fid $f)
2895 wait_request_state $fid RESTORE SUCCEED
2897 local expected_fields="event_time data_fid source_fid"
2898 expected_fields+=" total_bytes current_bytes"
2902 while read event; do
2903 # Make sure we're not getting anything from previous events.
2904 for field in $expected_fields; do
2908 local parsed=$(parse_json_event "$event")
2909 if [ -z "$parsed" ]; then
2910 error "Copytool sent malformed event: $event"
2914 if [ $event_type == "RESTORE_START" ]; then
2916 if [ $source_fid != $data_fid ]; then
2917 error "source_fid should == data_fid at start"
2920 elif [ $event_type == "RESTORE_FINISH" ]; then
2922 if [ $source_fid != $data_fid ]; then
2923 error "source_fid should == data_fid at finish"
2926 elif [ $event_type != "RESTORE_RUNNING" ]; then
2930 # Do some simple checking of the progress update events.
2931 for expected_field in $expected_fields; do
2932 if [ -z ${!expected_field+x} ]; then
2933 error "Missing $expected_field field in event"
2937 if [ $total_bytes -eq 0 ]; then
2938 error "Expected total_bytes to be > 0"
2941 # When a restore starts out, the data fid is the same as the
2942 # source fid. After the restore has gotten going, we learn
2943 # the new data fid. Once the restore has finished, the source
2944 # fid is set to the new data fid.
2946 # We test this because some monitoring software may depend on
2947 # this behavior. If it changes, then the consumers of these
2948 # events may need to be modified.
2949 if [ $source_fid == $data_fid ]; then
2950 error "source_fid should != data_fid during restore"
2952 done < <(echo $"$(get_copytool_event_log)")
2954 if [ -z "$START_EVENT" ]; then
2955 error "Copytool failed to send restore start event to FIFO"
2958 if [ -z "$FINISH_EVENT" ]; then
2959 error "Copytool failed to send restore finish event to FIFO"
2962 echo "Restore events look OK."
2966 copytool_monitor_cleanup
2970 run_test 72 "Copytool logs JSON restore events to FIFO"
2973 file_count=51 # Max number of files constrained by LNET message size
2974 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2975 local f=$DIR/$tdir/$tfile
2976 local FILELIST=/tmp/filelist.txt
2980 for i in $(seq 1 $file_count); do
2981 fid=$(copy_file /etc/hosts $f.$i)
2982 echo $f.$i >> $FILELIST
2985 # to be sure wait_all_done will not be mislead by previous tests
2987 wait_for_grace_delay
2988 $LFS hsm_archive --filelist $FILELIST ||
2989 error "cannot archive a file list"
2991 $LFS hsm_release --filelist $FILELIST ||
2992 error "cannot release a file list"
2993 $LFS hsm_restore --filelist $FILELIST ||
2994 error "cannot restore a file list"
2998 run_test 90 "Archive/restore a file list"
3000 double_verify_reset_hsm_param() {
3002 echo "Testing $HSM_PARAM.$p"
3003 local val=$(get_hsm_param $p)
3005 local val2=$(($val * 2))
3006 set_hsm_param $p $val2
3007 val=$(get_hsm_param $p)
3008 [[ $val == $val2 ]] ||
3009 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3010 echo "Set $p to 0 must failed"
3014 set_hsm_param $p $save
3016 if [[ $rc == 0 ]]; then
3017 error "we must not be able to set $HSM_PARAM.$p to 0"
3022 double_verify_reset_hsm_param loop_period
3023 double_verify_reset_hsm_param grace_delay
3024 double_verify_reset_hsm_param active_request_timeout
3025 double_verify_reset_hsm_param max_requests
3026 double_verify_reset_hsm_param default_archive_id
3028 run_test 100 "Set coordinator /proc tunables"
3035 run_test 102 "Verify coordinator control"
3038 # test needs a running copytool
3045 for i in $(seq 1 20); do
3046 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3052 echo "Current requests"
3053 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3054 $HSM_PARAM.actions |\
3055 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3057 [[ -z "$res" ]] || error "Some request have not been canceled"
3061 run_test 103 "Purge all requests"
3066 # test needs a running copytool
3070 local f=$DIR/$tdir/$tfile
3071 local fid=$(make_large_for_progress $f)
3072 # if cdt is on, it can serve too quickly the request
3074 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3075 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3076 $HSM_PARAM.actions |\
3077 grep $fid | cut -f16 -d=")
3080 [[ "$data1" == "$DATAHEX" ]] ||
3081 error "Data field in records is ($data1) and not ($DATAHEX)"
3085 run_test 104 "Copy tool data field"
3092 for i in $(seq -w 1 10); do
3093 cp /etc/passwd $DIR/$tdir/$i
3094 $LFS hsm_archive $DIR/$tdir/$i
3096 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3097 $HSM_PARAM.actions |\
3098 grep WAITING | wc -l")
3101 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3102 $HSM_PARAM.actions |\
3103 grep WAITING | wc -l")
3106 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3107 error "Requests count after shutdown $reqcnt2 != "\
3108 "before shutdown $reqcnt1"
3110 run_test 105 "Restart of coordinator"
3112 get_agent_by_uuid_mdt() {
3115 local mds=mds$(($mdtidx + 1))
3116 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3120 check_agent_registered_by_mdt() {
3123 local mds=mds$(($mdtidx + 1))
3124 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3125 if [[ ! -z "$agent" ]]; then
3126 echo "found agent $agent on $mds"
3128 error "uuid $uuid not found in agent list on $mds"
3132 check_agent_unregistered_by_mdt() {
3135 local mds=mds$(($mdtidx + 1))
3136 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3137 if [[ -z "$agent" ]]; then
3138 echo "uuid not found in agent list on $mds"
3140 error "uuid found in agent list on $mds: $agent"
3144 check_agent_registered() {
3147 for mdsno in $(seq 1 $MDSCOUNT); do
3148 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3152 check_agent_unregistered() {
3155 for mdsno in $(seq 1 $MDSCOUNT); do
3156 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3161 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3162 get_client_uuid $MOUNT | cut -d' ' -f2)
3165 check_agent_registered $uuid
3167 search_copytools || error "No copytool found"
3170 check_agent_unregistered $uuid
3173 check_agent_registered $uuid
3177 run_test 106 "Copytool register/unregister"
3180 # test needs a running copytool
3182 # create and archive file
3184 local f1=$DIR/$tdir/$tfile
3185 local fid=$(copy_file /etc/passwd $f1)
3186 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3187 wait_request_state $fid ARCHIVE SUCCEED
3188 # shutdown and restart MDS
3190 # check the copytool still gets messages from MDT
3191 local f2=$DIR/$tdir/2
3192 local fid=$(copy_file /etc/passwd $f2)
3193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3194 # main check of this sanity: this request MUST succeed
3195 wait_request_state $fid ARCHIVE SUCCEED
3198 run_test 107 "Copytool re-register after MDS restart"
3200 policy_set_and_test()
3204 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3205 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3206 [[ "$policy" == "$target" ]] ||
3207 error "Wrong policy after '$change': '$policy' != '$target'"
3211 # to force default policy setting if error
3212 CDT_POLICY_HAD_CHANGED=true
3214 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3215 local default="NonBlockingRestore [NoRetryAction]"
3216 [[ "$policy" == "$default" ]] ||
3217 error "default policy has changed,"\
3218 " '$policy' != '$default' update the test"
3219 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3220 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3221 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3222 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3223 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3224 # useless bacause we know but safer for futur changes to use real value
3225 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3226 echo "Next set_param must failed"
3227 policy_set_and_test "wrong" "$policy"
3230 echo "Back to default policy"
3231 cdt_set_sanity_policy
3233 run_test 109 "Policy display/change"
3236 # test needs a running copytool
3241 copy2archive /etc/passwd $tdir/$tfile
3243 local f=$DIR/$tdir/$tfile
3244 import_file $tdir/$tfile $f
3245 local fid=$(path2fid $f)
3247 cdt_set_non_blocking_restore
3252 wait_request_state $fid RESTORE SUCCEED
3253 cdt_clear_non_blocking_restore
3257 error "md5sum returns $st != 1, "\
3258 "should also perror ENODATA (No data available)"
3262 run_test 110a "Non blocking restore policy (import case)"
3265 # test needs a running copytool
3269 local f=$DIR/$tdir/$tfile
3270 local fid=$(copy_file /etc/passwd $f)
3271 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3272 wait_request_state $fid ARCHIVE SUCCEED
3275 cdt_set_non_blocking_restore
3280 wait_request_state $fid RESTORE SUCCEED
3281 cdt_clear_non_blocking_restore
3285 error "md5sum returns $st != 1, "\
3286 "should also perror ENODATA (No data available)"
3290 run_test 110b "Non blocking restore policy (release case)"
3293 # test needs a running copytool
3297 copy2archive /etc/passwd $tdir/$tfile
3299 local f=$DIR/$tdir/$tfile
3301 import_file $tdir/$tfile $f
3302 local fid=$(path2fid $f)
3306 copytool_remove_backend $fid
3309 wait_request_state $fid RESTORE FAILED
3316 [[ $st == 0 ]] || error "Restore does not failed"
3320 run_test 111a "No retry policy (import case), restore will error"\
3321 " (No such file or directory)"
3324 # test needs a running copytool
3328 local f=$DIR/$tdir/$tfile
3329 local fid=$(copy_file /etc/passwd $f)
3331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3332 wait_request_state $fid ARCHIVE SUCCEED
3335 copytool_remove_backend $fid
3338 wait_request_state $fid RESTORE FAILED
3345 [[ $st == 0 ]] || error "Restore does not failed"
3349 run_test 111b "No retry policy (release case), restore will error"\
3350 " (No such file or directory)"
3353 # test needs a running copytool
3357 local f=$DIR/$tdir/$tfile
3358 local fid=$(copy_file /etc/passwd $f)
3360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3361 local l=$($LFS hsm_action $f)
3363 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3367 wait_request_state $fid ARCHIVE SUCCEED
3370 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3374 run_test 112 "State of recorded request"
3377 # test needs a running copytool
3381 local f=$DIR/$tdir/$tfile
3382 local fid=$(make_large_for_cancel $f)
3383 # test with cdt on is made in test_221
3385 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3388 wait_request_state $fid ARCHIVE CANCELED
3389 wait_request_state $fid CANCEL SUCCEED
3393 run_test 200 "Register/Cancel archive"
3396 # test needs a running copytool
3400 local f=$DIR/$tdir/$tfile
3401 make_archive $tdir/$tfile
3402 import_file $tdir/$tfile $f
3403 local fid=$(path2fid $f)
3405 # test with cdt on is made in test_222
3410 wait_request_state $fid RESTORE CANCELED
3411 wait_request_state $fid CANCEL SUCCEED
3415 run_test 201 "Register/Cancel restore"
3418 # test needs a running copytool
3422 local f=$DIR/$tdir/$tfile
3423 local fid=$(make_large_for_progress $f)
3424 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3425 wait_request_state $fid ARCHIVE SUCCEED
3431 wait_request_state $fid REMOVE CANCELED
3435 run_test 202 "Register/Cancel remove"
3438 # test needs a running copytool
3443 local f=$DIR/$tdir/$tfile
3444 local fid=$(copy_file /etc/passwd $f)
3448 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3449 wait_request_state $fid ARCHIVE SUCCEED
3451 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3455 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3459 run_test 220 "Changelog for archive"
3462 # test needs a running copytool
3467 local f=$DIR/$tdir/$tfile
3468 local fid=$(make_large_for_cancel $f)
3472 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3473 wait_request_state $fid ARCHIVE STARTED
3475 wait_request_state $fid ARCHIVE CANCELED
3476 wait_request_state $fid CANCEL SUCCEED
3478 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3481 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3485 run_test 221 "Changelog for archive canceled"
3488 # test needs a running copytool
3492 copy2archive /etc/passwd $tdir/$tfile
3494 local f=$DIR/$tdir/$tfile
3495 import_file $tdir/$tfile $f
3496 local fid=$(path2fid $f)
3501 wait_request_state $fid RESTORE SUCCEED
3503 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3506 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3510 run_test 222a "Changelog for explicit restore"
3513 # test needs a running copytool
3517 local f=$DIR/$tdir/$tfile
3518 local fid=$(copy_file /etc/passwd $f)
3521 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3522 wait_request_state $fid ARCHIVE SUCCEED
3527 wait_request_state $fid RESTORE SUCCEED
3529 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3532 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3536 run_test 222b "Changelog for implicit restore"
3539 # test needs a running copytool
3544 local f=$DIR/$tdir/$tfile
3545 make_archive $tdir/$tfile
3549 import_file $tdir/$tfile $f
3550 local fid=$(path2fid $f)
3553 wait_request_state $fid RESTORE STARTED
3555 wait_request_state $fid RESTORE CANCELED
3556 wait_request_state $fid CANCEL SUCCEED
3558 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3561 [[ $flags == $target ]] ||
3562 error "Changelog flag is $flags not $target"
3566 run_test 223a "Changelog for restore canceled (import case)"
3569 # test needs a running copytool
3574 local f=$DIR/$tdir/$tfile
3575 local fid=$(make_large_for_progress $f)
3578 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3579 wait_request_state $fid ARCHIVE SUCCEED
3582 wait_request_state $fid RESTORE STARTED
3584 wait_request_state $fid RESTORE CANCELED
3585 wait_request_state $fid CANCEL SUCCEED
3587 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3590 [[ $flags == $target ]] ||
3591 error "Changelog flag is $flags not $target"
3595 run_test 223b "Changelog for restore canceled (release case)"
3598 # test needs a running copytool
3603 local f=$DIR/$tdir/$tfile
3604 local fid=$(copy_file /etc/passwd $f)
3607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3608 wait_request_state $fid ARCHIVE SUCCEED
3611 wait_request_state $fid REMOVE SUCCEED
3613 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3616 [[ $flags == $target ]] ||
3617 error "Changelog flag is $flags not $target"
3621 run_test 224 "Changelog for remove"
3624 # test needs a running copytool
3627 # test is not usable because remove request is too fast
3628 # so it is always finished before cancel can be done ...
3629 echo "Test disabled"
3634 local f=$DIR/$tdir/$tfile
3635 local fid=$(make_large_for_progress $f)
3638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3639 wait_request_state $fid ARCHIVE SUCCEED
3641 # if cdt is on, it can serve too quickly the request
3646 wait_request_state $fid REMOVE CANCELED
3647 wait_request_state $fid CANCEL SUCCEED
3649 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3650 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3651 tail -n 1 | awk '{print $5}')
3654 [[ $flags == $target ]] ||
3655 error "Changelog flag is $flags not $target"
3659 run_test 225 "Changelog for remove canceled"
3662 # test needs a running copytool
3667 local f1=$DIR/$tdir/$tfile-1
3668 local f2=$DIR/$tdir/$tfile-2
3669 local f3=$DIR/$tdir/$tfile-3
3670 local fid1=$(copy_file /etc/passwd $f1)
3671 local fid2=$(copy_file /etc/passwd $f2)
3672 copy_file /etc/passwd $f3
3675 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3676 wait_request_state $fid1 ARCHIVE SUCCEED
3678 $LFS hsm_archive $f2
3679 wait_request_state $fid2 ARCHIVE SUCCEED
3681 rm $f1 || error "rm $f1 failed"
3683 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3686 [[ $flags == $target ]] ||
3687 error "Changelog flag is $flags not $target"
3689 mv $f3 $f2 || error "mv $f3 $f2 failed"
3691 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3694 [[ $flags == $target ]] ||
3695 error "Changelog flag is $flags not $target"
3699 run_test 226 "changelog for last rm/mv with exiting archive"
3701 check_flags_changes() {
3709 $LFS hsm_set --$hsm_flag $f ||
3710 error "Cannot set $hsm_flag on $f"
3711 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3712 local seen=${#flags[*]}
3714 [[ $seen == $cnt ]] ||
3715 error "set $hsm_flag: Changelog events $seen != $cnt"
3716 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3717 error "set $hsm_flag: Changelog flags are "\
3718 "${flags[$((cnt - 1))]} not $target"
3720 $LFS hsm_clear --$hsm_flag $f ||
3721 error "Cannot clear $hsm_flag on $f"
3722 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3725 [[ $cnt == $seen ]] ||
3726 error "clear $hsm_flag: Changelog events $seen != $cnt"
3728 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3729 error "clear $hsm_flag: Changelog flag is "\
3730 "${flags[$((cnt - 1))]} not $target"
3734 # test needs a running copytool
3741 for i in norelease noarchive exists archived
3743 local f=$DIR/$tdir/$tfile-$i
3744 local fid=$(copy_file /etc/passwd $f)
3745 check_flags_changes $f $fid $i 0 1
3748 f=$DIR/$tdir/$tfile---lost
3749 fid=$(copy_file /etc/passwd $f)
3750 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3751 wait_request_state $fid ARCHIVE SUCCEED
3752 check_flags_changes $f $fid lost 3 1
3756 run_test 227 "changelog when explicit setting of HSM flags"
3759 # test needs a running copytool
3762 local fid=$(make_small_sync $DIR/$tfile)
3763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3764 wait_request_state $fid ARCHIVE SUCCEED
3766 $LFS hsm_release $DIR/$tfile
3767 check_hsm_flags $DIR/$tfile "0x0000000d"
3769 filefrag $DIR/$tfile | grep " 1 extent found" ||
3770 error "filefrag on released file must return only one extent"
3772 # only newer versions of cp detect sparse files by stat/FIEMAP
3774 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3775 error "copying $DIR/$tfile"
3776 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3778 $LFS hsm_release $DIR/$tfile
3779 check_hsm_flags $DIR/$tfile "0x0000000d"
3781 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3783 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3785 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3786 error "comparing untarred $DIR/$tfile"
3788 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3789 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3792 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3795 # test needs a running copytool
3799 local maxrequest=$(get_hsm_param max_requests)
3800 local rqcnt=$(($maxrequest * 3))
3804 for i in $(seq -w 1 $rqcnt); do
3806 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3808 # we do it in 2 steps, so all requests arrive at the same time
3809 for i in $(seq -w 1 $rqcnt); do
3810 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3815 while [[ $cnt != 0 || $wt != 0 ]]; do
3817 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3818 $HSM_PARAM.actions |\
3819 grep STARTED | grep -v CANCEL | wc -l")
3820 [[ $cnt -le $maxrequest ]] ||
3821 error "$cnt > $maxrequest too many started requests"
3822 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3823 $HSM_PARAM.actions |\
3824 grep WAITING | wc -l")
3825 echo "max=$maxrequest started=$cnt waiting=$wt"
3830 run_test 250 "Coordinator max request"
3833 # test needs a running copytool
3837 local f=$DIR/$tdir/$tfile
3838 local fid=$(make_large_for_cancel $f)
3841 # to have a short test
3842 local old_to=$(get_hsm_param active_request_timeout)
3843 set_hsm_param active_request_timeout 4
3844 # to be sure the cdt will wake up frequently so
3845 # it will be able to cancel the "old" request
3846 local old_loop=$(get_hsm_param loop_period)
3847 set_hsm_param loop_period 2
3850 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3851 wait_request_state $fid ARCHIVE STARTED
3853 wait_request_state $fid ARCHIVE CANCELED
3855 set_hsm_param active_request_timeout $old_to
3856 set_hsm_param loop_period $old_loop
3860 run_test 251 "Coordinator request timeout"
3863 # the only way to test ondisk conf is to restart MDS ...
3864 echo "Stop coordinator and remove coordinator state at mount"
3867 # clean on disk conf set by default
3868 cdt_clear_mount_state
3869 cdt_check_state stopped
3871 # check cdt still off after umount/remount
3873 cdt_check_state stopped
3875 echo "Set coordinator start at mount, and start coordinator"
3876 cdt_set_mount_state enabled
3879 cdt_check_state enabled
3881 # check cdt still on after umount/remount
3883 cdt_check_state enabled
3885 # we are back to original state (cdt started at mount)
3887 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3890 local ai=$(get_hsm_param default_archive_id)
3891 local new=$((ai + 1))
3893 set_hsm_param default_archive_id $new -P
3895 local res=$(get_hsm_param default_archive_id)
3898 set_hsm_param default_archive_id "" "-P -d"
3900 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3902 run_test 301 "HSM tunnable are persistent"
3905 local ai=$(get_hsm_param default_archive_id)
3906 local new=$((ai + 1))
3911 set_hsm_param default_archive_id $new -P
3914 for mdtno in $(seq 1 $MDSCOUNT); do
3919 cdt_check_state enabled
3921 local res=$(get_hsm_param default_archive_id)
3924 set_hsm_param default_archive_id "" "-P -d"
3926 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3928 run_test 302 "HSM tunnable are persistent when CDT is off"
3931 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3937 local dir_mdt0=$DIR/$tdir/mdt0
3938 local dir_mdt1=$DIR/$tdir/mdt1
3940 # create 1 dir per MDT
3941 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3942 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3944 # create 1 file in each MDT
3945 local fid1=$(make_small $dir_mdt0/$tfile)
3946 local fid2=$(make_small $dir_mdt1/$tfile)
3948 # check that hsm request on mdt0 is sent to the right MDS
3949 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3950 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3951 echo "archive successful on mdt0"
3953 # check that hsm request on mdt1 is sent to the right MDS
3954 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3955 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3956 echo "archive successful on mdt1"
3959 # clean test files and directories
3960 rm -rf $dir_mdt0 $dir_mdt1
3962 run_test 400 "Single request is sent to the right MDT"
3965 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3971 local dir_mdt0=$DIR/$tdir/mdt0
3972 local dir_mdt1=$DIR/$tdir/mdt1
3974 # create 1 dir per MDT
3975 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3976 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3978 # create 1 file in each MDT
3979 local fid1=$(make_small $dir_mdt0/$tfile)
3980 local fid2=$(make_small $dir_mdt1/$tfile)
3982 # check that compound requests are shunt to the rights MDTs
3983 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3984 error "lfs hsm_archive"
3985 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3986 echo "archive successful on mdt0"
3987 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3988 echo "archive successful on mdt1"
3991 # clean test files and directories
3992 rm -rf $dir_mdt0 $dir_mdt1
3994 run_test 401 "Compound requests split and sent to their respective MDTs"
3996 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4001 local node=$(facet_active_host $facet)
4003 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4004 awk '{print $4}'); do
4005 echo "$3 $mdc on $node"
4006 do_facet $facet "$LCTL --device $mdc $state" || return 1
4011 # make sure there is no running copytool
4014 # deactivate all mdc on agent1
4015 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4017 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4019 check_agent_unregistered "uuid" # match any agent
4021 # no expected running copytool
4022 search_copytools $agent && error "Copytool start should have failed"
4025 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4027 run_test 402 "Copytool start fails if all MDTs are inactive"
4030 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4032 # make sure there is no running copytool
4035 local agent=$(facet_active_host $SINGLEAGT)
4036 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4038 # deactivate all mdc for MDT0001
4039 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4042 # check the agent is registered on MDT0000, and not on MDT0001
4043 check_agent_registered_by_mdt $uuid 0
4044 check_agent_unregistered_by_mdt $uuid 1
4046 # check running copytool process
4047 search_copytools $agent || error "No running copytools on $agent"
4049 # reactivate all mdc for MDT0001
4050 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4052 # make sure the copytool is now registered to all MDTs
4053 check_agent_registered $uuid
4057 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4060 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4064 # create files on both MDT0000 and MDT0001
4067 local dir_mdt0=$DIR/$tdir/mdt0
4068 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4070 # create 1 file on mdt0
4071 local fid1=$(make_small $dir_mdt0/$tfile)
4073 # deactivate all mdc for MDT0001
4074 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4076 # send an HSM request for files in MDT0000
4077 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4079 # check for completion of files in MDT0000
4080 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4081 echo "archive successful on mdt0"
4083 # reactivate all mdc for MDT0001
4084 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4087 # clean test files and directories
4090 run_test 404 "Inactive MDT does not block requests for active MDTs"
4093 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4099 local striped_dir=$DIR/$tdir/striped_dir
4101 # create striped dir on all of MDTs
4102 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4104 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4105 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4106 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4107 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4109 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4110 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4111 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4112 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4114 # check that compound requests are shunt to the rights MDTs
4115 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4116 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4117 error "lfs hsm_archive"
4119 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4120 echo "archive successful on $fid1"
4121 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4122 echo "archive successful on $fid2"
4123 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4124 echo "archive successful on $fid3"
4125 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4126 echo "archive successful on $fid4"
4128 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4129 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4130 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4131 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4133 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4134 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4135 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4136 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4140 run_test 405 "archive and release under striped directory"
4145 check_and_cleanup_lustre