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 3939
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36 40"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
68 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
71 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72 if [[ $CLIENTCOUNT -gt 1 ]] &&
73 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74 skip_env "SHARED_DIRECTORY should be accessible"\
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81 agent=CLIENT$((n + 1))
82 if [[ -z "${!agent}" ]]; then
83 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89 export SINGLEAGT=${SINGLEAGT:-agt1}
91 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
94 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
95 export HSMTOOL_TESTDIR
96 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
97 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
100 # The test only support up to 10 MDTs
101 MDT_PREFIX="mdt.$FSNAME-MDT000"
102 HSM_PARAM="${MDT_PREFIX}0.hsm"
104 # archive is purged at copytool setup
105 HSM_ARCHIVE_PURGE=true
107 # Don't allow copytool error upon start/setup
108 HSMTOOL_NOERROR=false
111 # Get the backend root path for the given agent facet.
114 local dev=AGTDEV$(facet_number $facet)
119 # Stop copytool and unregister an existing changelog user.
121 copytool_monitor_cleanup
124 cdt_set_sanity_policy
129 # get MDT device for each mdc
130 for mdtno in $(seq 1 $MDSCOUNT); do
131 local idx=$(($mdtno - 1))
132 MDT[$idx]=$($LCTL get_param -n \
133 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
134 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
139 local agents=${1:-$(facet_active_host $SINGLEAGT)}
140 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
143 search_and_kill_copytool() {
144 local agents=${1:-$(facet_active_host $SINGLEAGT)}
146 echo "Killing existing copytools on $agents"
147 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
150 copytool_monitor_setup() {
151 local facet=${1:-$SINGLEAGT}
152 local agent=$(facet_active_host $facet)
154 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
155 local test_dir=$(do_node $agent "$cmd") ||
156 error "Failed to create tempdir on $agent"
157 export HSMTOOL_MONITOR_DIR=$test_dir
159 # Create the fifo and a monitor (cat dies when copytool dies)
160 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
161 error "failed to create copytool fifo on $agent"
162 cmd="cat $test_dir/fifo > $test_dir/events &"
163 cmd+=" echo \\\$! > $test_dir/monitor_pid"
165 if [[ $PDSH == *Rmrsh* ]]; then
166 # This is required for pdsh -Rmrsh and its handling of remote
168 # Regular ssh and pdsh -Rssh work fine without this
169 # backgrounded subshell nonsense.
170 (do_node $agent "$cmd") &
171 export HSMTOOL_MONITOR_PDSH=$!
173 # Slightly racy, but just making a best-effort to catch obvious
176 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
177 error "Failed to start copytool monitor on $agent"
179 do_node $agent "$cmd"
181 error "Failed to start copytool monitor on $agent"
186 copytool_monitor_cleanup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
191 # Should die when the copytool dies, but just in case.
192 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
193 cmd+=" 2>/dev/null || true"
194 do_node $agent "$cmd"
195 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
196 export HSMTOOL_MONITOR_DIR=
199 # The pdsh should die on its own when the monitor dies. Just
200 # in case, though, try to clean up to avoid any cruft.
201 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
202 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
203 export HSMTOOL_MONITOR_PDSH=
208 local facet=${1:-$SINGLEAGT}
209 local lustre_mntpnt=${2:-$MOUNT}
211 local hsm_root=${4:-$(copytool_device $facet)}
212 local agent=$(facet_active_host $facet)
214 if [[ -z "$arc_id" ]] &&
215 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
216 echo "Wakeup copytool $facet on $agent"
220 if $HSM_ARCHIVE_PURGE; then
221 echo "Purging archive on $agent"
222 do_facet $facet "rm -rf $hsm_root/*"
225 echo "Starting copytool $facet on $agent"
226 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
227 # bandwidth is limited to 1MB/s so the copy time is known and
228 # independent of hardware
229 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
230 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
231 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
232 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
233 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
234 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
235 cmd+=" --bandwidth 1 $lustre_mntpnt"
237 # Redirect the standard output and error to a log file which
238 # can be uploaded to Maloo.
239 local prefix=$TESTLOG_PREFIX
240 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
241 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
243 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
244 if [[ $? != 0 ]]; then
245 [[ $HSMTOOL_NOERROR == true ]] ||
246 error "start copytool $facet on $agent failed"
247 echo "start copytool $facet on $agent failed"
253 get_copytool_event_log() {
254 local facet=${1:-$SINGLEAGT}
255 local agent=$(facet_active_host $facet)
257 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
258 error "Can't get event log: No monitor directory!"
260 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
261 error "Could not collect event log from $agent"
266 local facet=$SINGLEAGT
267 local agents=${1:-$(facet_active_host $facet)}
272 local hsm_root=$(copytool_device $facet)
274 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
276 echo "Copytool is stopped on $agents"
278 # clean all CDTs orphans requests from previous tests
279 # that would otherwise need to timeout to clear.
280 for mdtno in $(seq 1 $MDSCOUNT); do
282 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
283 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
285 # skip already stop[ed,ing] CDTs
286 echo $oldstate | grep stop && continue
288 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
289 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
291 error "mds${mdtno} cdt state is not stopped"
292 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
293 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
295 error "mds${mdtno} cdt state is not $oldstate"
297 do_facet $facet "rm -rf $hsm_root"
301 local agents=${1:-$(facet_active_host $SINGLEAGT)}
303 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
304 echo "Copytool is suspended on $agents"
307 copytool_remove_backend() {
309 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
310 echo "Remove from backend: $fid = $be"
311 do_facet $SINGLEAGT rm -f $be
315 do_facet $SINGLEAGT \
316 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
317 --import $1 $2 $MOUNT" ||
318 error "import of $1 to $2 failed"
322 local file=$HSM_ARCHIVE/$1
323 do_facet $SINGLEAGT mkdir -p $(dirname $file)
324 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
325 error "cannot create $file"
329 local file=$HSM_ARCHIVE/$2
330 do_facet $SINGLEAGT mkdir -p $(dirname $file)
331 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
340 if [[ "$value" != "" ]]; then
343 for mdtno in $(seq 1 $MDSCOUNT); do
344 local idx=$(($mdtno - 1))
345 local facet=mds${mdtno}
346 # if $arg include -P option, run 1 set_param per MDT on the MGS
347 # else, run set_param on each MDT
348 [[ $arg = *"-P"* ]] && facet=mgs
349 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
350 [[ $? != 0 ]] && rc=1
360 for mdtno in $(seq 1 $MDSCOUNT); do
361 local idx=$(($mdtno - 1))
362 wait_result mds${mdtno} \
363 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
365 error "$key state is not '$target' on mds${mdtno}"
372 for mdtno in $(seq 1 $MDSCOUNT); do
373 local idx=$(($mdtno - 1))
374 local cl_user=$(do_facet mds${mdtno} $LCTL \
375 --device ${MDT[$idx]} \
376 changelog_register -n)
378 do_facet mds${mdtno} lctl set_param \
379 mdd.${MDT[$idx]}.changelog_mask="+hsm"
380 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
384 changelog_cleanup() {
386 for mdtno in $(seq 1 $MDSCOUNT); do
387 local idx=$(($mdtno - 1))
388 [[ -z ${CL_USERS[$idx]} ]] && continue
389 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
390 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
391 changelog_deregister ${CL_USERS[$idx]}
396 changelog_get_flags() {
401 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
406 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
414 mdts_set_param "$opt -n" "hsm.$param" "$value"
421 mdts_set_param "" hsm_control "$cmd"
422 mdts_check_param hsm_control "$target" 10
425 cdt_set_sanity_policy() {
426 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
429 mdts_set_param "" hsm.policy "+NRA"
430 mdts_set_param "" hsm.policy "-NBR"
431 CDT_POLICY_HAD_CHANGED=
436 mdts_set_param "" hsm.policy "+NRA"
437 CDT_POLICY_HAD_CHANGED=true
440 cdt_clear_no_retry() {
441 mdts_set_param "" hsm.policy "-NRA"
442 CDT_POLICY_HAD_CHANGED=true
445 cdt_set_non_blocking_restore() {
446 mdts_set_param "" hsm.policy "+NBR"
447 CDT_POLICY_HAD_CHANGED=true
450 cdt_clear_non_blocking_restore() {
451 mdts_set_param "" hsm.policy "-NBR"
452 CDT_POLICY_HAD_CHANGED=true
455 cdt_clear_mount_state() {
456 mdts_set_param "-P -d" hsm_control ""
459 cdt_set_mount_state() {
460 mdts_set_param "-P" hsm_control "$1"
464 mdts_check_param hsm_control "$1" 20
468 set_test_state disabled disabled
472 set_test_state enabled enabled
476 set_test_state shutdown stopped
480 set_test_state purge enabled
486 cdt_set_sanity_policy
490 local client_count=$1
491 if [[ $CLIENTCOUNT -lt $client_count ]]; then
492 skip "Need $client_count or more clients, have $CLIENTCOUNT"
499 $LFS path2fid $1 | tr -d '[]'
506 if [[ $u == "user" ]]; then
507 local st=$($RUNAS $LFS hsm_state $f)
509 local st=$($LFS hsm_state $f)
513 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
515 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
519 get_hsm_archive_id() {
521 local st=$($LFS hsm_state $f)
522 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
524 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
533 local st=$(get_hsm_flags $f)
534 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
537 check_hsm_flags_user() {
541 local st=$(get_hsm_flags $f user)
542 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
554 if [[ "$3" != 1 ]]; then
558 cp $1 $f || error "cannot copy $1 to $f"
559 path2fid $f || error "cannot get fid on $f"
563 local file2=${1/$DIR/$DIR2}
564 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
565 error "cannot create $file2"
566 path2fid $1 || error "cannot get fid on $1"
570 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
571 error "cannot create $1"
572 path2fid $1 || error "cannot get fid on $1"
575 cleanup_large_files() {
576 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
578 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
581 make_large_for_striping() {
582 local file2=${1/$DIR/$DIR2}
583 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
587 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
588 error "cannot create $file2"
589 path2fid $1 || error "cannot get fid on $1"
592 make_large_for_progress() {
593 local file2=${1/$DIR/$DIR2}
597 # big file is large enough, so copy time is > 30s
598 # so copytool make 1 progress
599 # size is not a multiple of 1M to avoid stripe
601 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
602 error "cannot create $file2"
603 path2fid $1 || error "cannot get fid on $1"
606 make_large_for_progress_aligned() {
607 local file2=${1/$DIR/$DIR2}
611 # big file is large enough, so copy time is > 30s
612 # so copytool make 1 progress
613 # size is a multiple of 1M to have stripe
615 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
616 error "cannot create $file2"
617 path2fid $1 || error "cannot get fid on $1"
620 make_large_for_cancel() {
621 local file2=${1/$DIR/$DIR2}
625 # Copy timeout is 100s. 105MB => 105s
626 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
627 error "cannot create $file2"
628 path2fid $1 || error "cannot get fid on $1"
634 wait_update --verbose $(facet_active_host $facet) "$@"
637 wait_request_state() {
641 # 4th arg (mdt index) is optional
643 local mds=mds$(($mdtidx + 1))
645 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
646 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
648 wait_result $mds "$cmd" $state 100 ||
649 error "request on $fid is not $state on $mds"
652 get_request_state() {
656 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
657 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
660 get_request_count() {
664 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
665 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
672 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
673 [[ -n $fid ]] && cmd+=" | grep '$fid'"
674 cmd+=" | egrep 'WAITING|STARTED'"
676 wait_result $SINGLEMDS "$cmd" "" $timeout ||
677 error "requests did not complete"
680 wait_for_grace_delay() {
681 local val=$(get_hsm_param grace_delay)
688 # python2.6 in EL6 includes an internal json module
689 local json_parser='import json; import fileinput;'
690 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
691 json_parser+='json.loads([line for line in '
692 json_parser+='fileinput.input()][0]).items()])'
694 echo $raw_event | python -c "$json_parser"
697 # populate MDT device array
703 # cleanup from previous bad setup
704 search_and_kill_copytool
706 # for recovery tests, coordinator needs to be started at mount
708 # the lustre conf must be without hsm on (like for sanity.sh)
709 echo "Set HSM on and start"
710 cdt_set_mount_state enabled
711 cdt_check_state enabled
713 echo "Start copytool"
716 echo "Set sanity-hsm HSM policy"
717 cdt_set_sanity_policy
719 # finished requests are quickly removed from list
720 set_hsm_param grace_delay 10
726 local f=$DIR/$tdir/$tfile
730 check_hsm_flags_user $f "0x00000000"
732 $RUNAS $LFS hsm_set --norelease $f ||
733 error "user could not change hsm flags"
734 check_hsm_flags_user $f "0x00000010"
736 $RUNAS $LFS hsm_clear --norelease $f ||
737 error "user could not clear hsm flags"
738 check_hsm_flags_user $f "0x00000000"
740 # User could not change those flags...
741 $RUNAS $LFS hsm_set --exists $f &&
742 error "user should not set this flag"
743 check_hsm_flags_user $f "0x00000000"
746 $LFS hsm_set --exists $f ||
747 error "root could not change hsm flags"
748 check_hsm_flags_user $f "0x00000001"
750 $LFS hsm_clear --exists $f ||
751 error "root could not clear hsm state"
752 check_hsm_flags_user $f "0x00000000"
755 run_test 1 "lfs hsm flags root/non-root access"
759 local f=$DIR/$tdir/$tfile
761 # New files are not dirty
762 check_hsm_flags $f "0x00000000"
764 # For test, we simulate an archived file.
765 $LFS hsm_set --exists $f || error "user could not change hsm flags"
766 check_hsm_flags $f "0x00000001"
768 # chmod do not put the file dirty
769 chmod 600 $f || error "could not chmod test file"
770 check_hsm_flags $f "0x00000001"
772 # chown do not put the file dirty
773 chown $RUNAS_ID $f || error "could not chown test file"
774 check_hsm_flags $f "0x00000001"
776 # truncate put the file dirty
777 $TRUNCATE $f 1 || error "could not truncate test file"
778 check_hsm_flags $f "0x00000003"
780 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
781 check_hsm_flags $f "0x00000001"
783 run_test 2 "Check file dirtyness when doing setattr"
789 # New files are not dirty
791 check_hsm_flags $f "0x00000000"
793 # For test, we simulate an archived file.
794 $LFS hsm_set --exists $f ||
795 error "user could not change hsm flags"
796 check_hsm_flags $f "0x00000001"
798 # Reading a file, does not set dirty
799 cat $f > /dev/null || error "could not read file"
800 check_hsm_flags $f "0x00000001"
802 # Open for write without modifying data, does not set dirty
803 openfile -f O_WRONLY $f || error "could not open test file"
804 check_hsm_flags $f "0x00000001"
806 # Append to a file sets it dirty
807 cp -p /etc/passwd $f.append || error "could not create file"
808 $LFS hsm_set --exists $f.append ||
809 error "user could not change hsm flags"
810 dd if=/etc/passwd of=$f.append bs=1 count=3\
811 conv=notrunc oflag=append status=noxfer ||
812 error "could not append to test file"
813 check_hsm_flags $f.append "0x00000003"
815 # Modify a file sets it dirty
816 cp -p /etc/passwd $f.modify || error "could not create file"
817 $LFS hsm_set --exists $f.modify ||
818 error "user could not change hsm flags"
819 dd if=/dev/zero of=$f.modify bs=1 count=3\
820 conv=notrunc status=noxfer ||
821 error "could not modify test file"
822 check_hsm_flags $f.modify "0x00000003"
824 # Open O_TRUNC sets dirty
825 cp -p /etc/passwd $f.trunc || error "could not create file"
826 $LFS hsm_set --exists $f.trunc ||
827 error "user could not change hsm flags"
828 cp /etc/group $f.trunc || error "could not override a file"
829 check_hsm_flags $f.trunc "0x00000003"
831 # Mmapped a file sets dirty
832 cp -p /etc/passwd $f.mmap || error "could not create file"
833 $LFS hsm_set --exists $f.mmap ||
834 error "user could not change hsm flags"
835 multiop $f.mmap OSMWUc || error "could not mmap a file"
836 check_hsm_flags $f.mmap "0x00000003"
838 run_test 3 "Check file dirtyness when opening for write"
842 local f=$DIR/$tdir/$tfile
843 local fid=$(make_small $f)
846 local st=$(get_request_state $fid CANCEL)
847 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
849 run_test 4 "Useless cancel must not be registered"
852 # test needs a running copytool
856 local f=$DIR/$tdir/$tfile
857 local fid=$(copy_file /etc/passwd $f)
859 wait_request_state $fid ARCHIVE SUCCEED
861 check_hsm_flags $f "0x00000009"
865 run_test 8 "Test default archive number"
869 local f=$DIR/$tdir/$tfile
870 local fid=$(copy_file /etc/passwd $f)
871 # we do not use the default one to be sure
872 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
874 copytool_setup $SINGLEAGT $MOUNT $new_an
875 $LFS hsm_archive --archive $new_an $f
876 wait_request_state $fid ARCHIVE SUCCEED
878 check_hsm_flags $f "0x00000009"
882 run_test 9 "Use of explict archive number, with dedicated copytool"
885 needclients 3 || return 0
891 copytool_cleanup $(comma_list $(agts_nodes))
893 # start all of the copytools
894 for n in $(seq $AGTCOUNT); do
898 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
901 for n in $(seq $AGTCOUNT); do
902 file=$DIR/$tdir/$tfile.$n
903 fid=$(make_small $file)
905 $LFS hsm_archive $file || error "could not archive file $file"
906 wait_request_state $fid ARCHIVE SUCCEED
907 check_hsm_flags $file "0x00000009"
911 copytool_cleanup $(comma_list $(agts_nodes))
913 run_test 9a "Multiple remote agents"
916 # test needs a running copytool
919 mkdir -p $DIR/$tdir/d1
920 local f=$DIR/$tdir/$tfile
921 local fid=$(copy_file /etc/hosts $f)
922 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
923 error "hsm_archive failed"
924 wait_request_state $fid ARCHIVE SUCCEED
926 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
927 error "fid $fid not in archive $HSM_ARCHIVE"
928 echo "Verifying content"
929 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
930 echo "Verifying hsm state "
931 check_hsm_flags $f "0x00000009"
933 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
934 local st=$(get_hsm_archive_id $f)
935 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
936 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
941 run_test 10a "Archive a file"
944 # test needs a running copytool
948 local f=$DIR/$tdir/$tfile
949 local fid=$(copy_file /etc/hosts $f)
950 $LFS hsm_archive $f || error "archive request failed"
951 wait_request_state $fid ARCHIVE SUCCEED
953 $LFS hsm_archive $f || error "archive of non dirty file failed"
954 local cnt=$(get_request_count $fid ARCHIVE)
955 [[ "$cnt" == "1" ]] ||
956 error "archive of non dirty file must not make a request"
960 run_test 10b "Archive of non dirty file must work without doing request"
963 # test needs a running copytool
967 local f=$DIR/$tdir/$tfile
968 local fid=$(copy_file /etc/hosts $f)
969 $LFS hsm_set --noarchive $f
970 $LFS hsm_archive $f && error "archive a noarchive file must fail"
974 run_test 10c "Check forbidden archive"
977 # test needs a running copytool
981 local f=$DIR/$tdir/$tfile
982 local fid=$(copy_file /etc/hosts $f)
983 $LFS hsm_archive $f || error "cannot archive $f"
984 wait_request_state $fid ARCHIVE SUCCEED
986 local ar=$(get_hsm_archive_id $f)
987 local dflt=$(get_hsm_param default_archive_id)
988 [[ $ar == $dflt ]] ||
989 error "archived file is not on default archive: $ar != $dflt"
993 run_test 10d "Archive a file on the default archive id"
997 copy2archive /etc/hosts $tdir/$tfile
998 local f=$DIR/$tdir/$tfile
1000 import_file $tdir/$tfile $f
1001 echo -n "Verifying released state: "
1002 check_hsm_flags $f "0x0000000d"
1004 local LSZ=$(stat -c "%s" $f)
1005 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1007 echo "Verifying imported size $LSZ=$ASZ"
1008 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1009 echo -n "Verifying released pattern: "
1010 local PTRN=$($GETSTRIPE -L $f)
1012 [[ $PTRN == 80000001 ]] || error "Is not released"
1013 local fid=$(path2fid $f)
1014 echo "Verifying new fid $fid in archive"
1016 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1017 error "fid $fid not in archive $HSM_ARCHIVE"
1019 run_test 11a "Import a file"
1022 # test needs a running copytool
1026 local f=$DIR/$tdir/$tfile
1027 local fid=$(copy_file /etc/hosts $f)
1028 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1029 error "hsm_archive failed"
1030 wait_request_state $fid ARCHIVE SUCCEED
1032 local FILE_HASH=$(md5sum $f)
1037 echo "$FILE_HASH" | md5sum -c
1039 [[ $? -eq 0 ]] || error "Restored file differs"
1043 run_test 11b "Import a deleted file using its FID"
1046 # test needs a running copytool
1050 copy2archive /etc/hosts $tdir/$tfile
1052 local f=$DIR/$tdir/$tfile
1053 import_file $tdir/$tfile $f
1054 local f2=$DIR2/$tdir/$tfile
1055 echo "Verifying released state: "
1056 check_hsm_flags $f2 "0x0000000d"
1058 local fid=$(path2fid $f2)
1059 $LFS hsm_restore $f2
1060 wait_request_state $fid RESTORE SUCCEED
1062 echo "Verifying file state: "
1063 check_hsm_flags $f2 "0x00000009"
1065 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1067 [[ $? -eq 0 ]] || error "Restored file differs"
1071 run_test 12a "Restore an imported file explicitly"
1074 # test needs a running copytool
1078 copy2archive /etc/hosts $tdir/$tfile
1080 local f=$DIR/$tdir/$tfile
1081 import_file $tdir/$tfile $f
1082 echo "Verifying released state: "
1083 check_hsm_flags $f "0x0000000d"
1085 cat $f > /dev/null || error "File read failed"
1087 echo "Verifying file state after restore: "
1088 check_hsm_flags $f "0x00000009"
1090 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1092 [[ $? -eq 0 ]] || error "Restored file differs"
1096 run_test 12b "Restore an imported file implicitly"
1099 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1101 # test needs a running copytool
1105 local f=$DIR/$tdir/$tfile
1106 $LFS setstripe -c 2 $f
1107 local fid=$(make_large_for_striping $f)
1108 local FILE_CRC=$(md5sum $f)
1110 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1111 wait_request_state $fid ARCHIVE SUCCEED
1112 $LFS hsm_release $f || error "release $f failed"
1114 echo "$FILE_CRC" | md5sum -c
1116 [[ $? -eq 0 ]] || error "Restored file differs"
1120 run_test 12c "Restore a file with stripe of 2"
1123 # test needs a running copytool
1128 local f=$DIR/$tdir/$tfile
1129 local fid=$(copy_file /etc/hosts $f)
1130 $LFS hsm_restore $f || error "restore of non archived file failed"
1131 local cnt=$(get_request_count $fid RESTORE)
1132 [[ "$cnt" == "0" ]] ||
1133 error "restore non archived must not make a request"
1134 $LFS hsm_archive $f ||
1135 error "archive request failed"
1136 wait_request_state $fid ARCHIVE SUCCEED
1137 $LFS hsm_restore $f ||
1138 error "restore of non released file failed"
1139 local cnt=$(get_request_count $fid RESTORE)
1140 [[ "$cnt" == "0" ]] ||
1141 error "restore a non dirty file must not make a request"
1145 run_test 12d "Restore of a non archived, non released file must work"\
1146 " without doing request"
1149 # test needs a running copytool
1152 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1153 local f=$DIR/$tdir/$tfile
1154 local fid=$(copy_file /etc/hosts $f)
1155 $LFS hsm_archive $f || error "archive request failed"
1156 wait_request_state $fid ARCHIVE SUCCEED
1159 cat /etc/hosts >> $f
1163 $LFS hsm_restore $f && error "restore a dirty file must fail"
1167 run_test 12e "Check forbidden restore"
1170 # test needs a running copytool
1174 local f=$DIR/$tdir/$tfile
1175 local fid=$(copy_file /etc/hosts $f)
1177 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1178 wait_request_state $fid ARCHIVE SUCCEED
1179 $LFS hsm_release $f || error "release of $f failed"
1181 wait_request_state $fid RESTORE SUCCEED
1183 echo -n "Verifying file state: "
1184 check_hsm_flags $f "0x00000009"
1186 diff -q /etc/hosts $f
1188 [[ $? -eq 0 ]] || error "Restored file differs"
1192 run_test 12f "Restore a released file explicitly"
1195 # test needs a running copytool
1199 local f=$DIR/$tdir/$tfile
1200 local fid=$(copy_file /etc/hosts $f)
1202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1203 wait_request_state $fid ARCHIVE SUCCEED
1204 $LFS hsm_release $f || error "release of $f failed"
1206 diff -q /etc/hosts $f
1209 # we check we had a restore done
1210 wait_request_state $fid RESTORE SUCCEED
1212 [[ $st -eq 0 ]] || error "Restored file differs"
1216 run_test 12g "Restore a released file implicitly"
1219 needclients 2 || return 0
1221 # test needs a running copytool
1225 local f=$DIR/$tdir/$tfile
1226 local fid=$(copy_file /etc/hosts $f)
1228 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1229 wait_request_state $fid ARCHIVE SUCCEED
1230 $LFS hsm_release $f || error "release of $f failed"
1232 do_node $CLIENT2 diff -q /etc/hosts $f
1235 # we check we had a restore done
1236 wait_request_state $fid RESTORE SUCCEED
1238 [[ $st -eq 0 ]] || error "Restored file differs"
1242 run_test 12h "Restore a released file implicitly from a second node"
1245 # test needs a running copytool
1249 local f=$DIR/$tdir/$tfile
1250 local fid=$(copy_file /etc/passwd $f)
1251 $LFS hsm_archive $f || error "archive of $f failed"
1252 wait_request_state $fid ARCHIVE SUCCEED
1254 $LFS hsm_release $f || error "release of $f failed"
1258 [[ $? -eq 0 ]] || error "Restored file differs"
1262 run_test 12m "Archive/release/implicit restore"
1265 # test needs a running copytool
1269 copy2archive /etc/hosts $tdir/$tfile
1271 local f=$DIR/$tdir/$tfile
1272 import_file $tdir/$tfile $f
1274 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1275 error "Restored file differs"
1277 $LFS hsm_release $f || error "release of $f failed"
1281 run_test 12n "Import/implicit restore/release"
1284 # test needs a running copytool
1288 local f=$DIR/$tdir/$tfile
1289 local fid=$(copy_file /etc/hosts $f)
1291 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1292 wait_request_state $fid ARCHIVE SUCCEED
1293 $LFS hsm_release $f || error "release of $f failed"
1295 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1296 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1298 # set no retry action mode
1301 diff -q /etc/hosts $f
1304 # we check we had a restore failure
1305 wait_request_state $fid RESTORE FAILED
1307 [[ $st -eq 0 ]] && error "Restore must fail"
1309 # remove no retry action mode
1312 # check file is still released
1313 check_hsm_flags $f "0x0000000d"
1315 # retry w/o failure injection
1316 do_facet $SINGLEMDS lctl set_param fail_loc=0
1318 # to be sure previous RESTORE result is gone
1320 wait_for_grace_delay
1322 diff -q /etc/hosts $f
1325 # we check we had a restore done
1326 wait_request_state $fid RESTORE SUCCEED
1328 [[ $st -eq 0 ]] || error "Restored file differs"
1332 run_test 12o "Layout-swap failure during Restore leaves file released"
1335 # test needs a running copytool
1338 local ARC_SUBDIR="import.orig"
1342 # populate directory to be imported
1343 for d in $(seq 1 10); do
1344 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1345 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1346 for f in $(seq 1 10); do
1347 CURR_FILE="$CURR_DIR/$tfile.$f"
1348 # write file-specific data
1349 do_facet $SINGLEAGT \
1350 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1351 "file=$CURR_FILE > $CURR_FILE"
1355 import_file "$ARC_SUBDIR" $DIR/$tdir
1356 # diff lustre content and origin (triggers file restoration)
1357 # there must be 10x10 identical files, and no difference
1358 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1359 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1360 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1361 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1363 [ $cnt_diff -eq 0 ] ||
1364 error "$cnt_diff imported files differ from read data"
1365 [ $cnt_ok -eq 100 ] ||
1366 error "not enough identical files ($cnt_ok != 100)"
1370 run_test 13 "Recursively import and restore a directory"
1373 # test needs a running copytool
1378 local f=$DIR/$tdir/$tfile
1379 local fid=$(make_small $f)
1380 local sum=$(md5sum $f | awk '{print $1}')
1381 $LFS hsm_archive $f || error "could not archive file"
1382 wait_request_state $fid ARCHIVE SUCCEED
1386 # create released file (simulate llapi_hsm_import call)
1388 local fid2=$(path2fid $f)
1389 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1390 $LFS hsm_release $f || error "could not release file"
1392 # rebind the archive to the newly created file
1393 echo "rebind $fid to $fid2"
1395 do_facet $SINGLEAGT \
1396 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1397 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1399 # restore file and compare md5sum
1400 local sum2=$(md5sum $f | awk '{print $1}')
1402 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1406 run_test 14 "Rebind archived file to a new fid"
1409 # test needs a running copytool
1414 local f=$DIR/$tdir/$tfile
1416 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1420 for i in $(seq 1 $count); do
1421 fids[$i]=$(make_small $f.$i)
1422 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1423 $LFS hsm_archive $f.$i || error "could not archive file"
1425 wait_all_done $(($count*60))
1429 for i in $(seq 1 $count); do
1432 local fid2=$(path2fid $f.$i)
1433 # add the rebind operation to the list
1434 echo ${fids[$i]} $fid2 >> $tmpfile
1436 # set it released (simulate llapi_hsm_import call)
1437 $LFS hsm_set --archived --exists $f.$i ||
1438 error "could not force hsm flags"
1439 $LFS hsm_release $f.$i || error "could not release file"
1441 nl=$(wc -l < $tmpfile)
1442 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1444 echo "rebind list of files"
1445 do_facet $SINGLEAGT \
1446 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1447 --rebind $tmpfile $DIR" || error "could not rebind file list"
1449 # restore files and compare md5sum
1450 for i in $(seq 1 $count); do
1451 local sum2=$(md5sum $f.$i | awk '{print $1}')
1452 [[ $sum2 == ${sums[$i]} ]] ||
1453 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1459 run_test 15 "Rebind a list of files"
1462 # test needs a running copytool
1466 # create a known size file so we can verify transfer speed
1469 dd if=/dev/zero of=$ref bs=1M count=20
1472 local f=$DIR/$tdir/$tfile
1473 local fid=$(copy_file $ref $f)
1475 local start=$(date +%s)
1477 wait_request_state $fid ARCHIVE SUCCEED
1478 local end=$(date +%s)
1479 local duration=$((end - start))
1481 [[ $duration -ge $goal ]] ||
1482 error "Transfer is too fast $duration < $goal"
1486 run_test 16 "Test CT bandwith control option"
1491 local f=$DIR/$tdir/$tfile
1492 touch $f || error "touch $f failed"
1494 # Could not release a non-archived file
1495 $LFS hsm_release $f && error "release should not succeed"
1497 # For following tests, we must test them with HS_ARCHIVED set
1498 $LFS hsm_set --exists --archived $f || error "could not add flag"
1500 # Could not release a file if no-release is set
1501 $LFS hsm_set --norelease $f || error "could not add flag"
1502 $LFS hsm_release $f && error "release should not succeed"
1503 $LFS hsm_clear --norelease $f || error "could not remove flag"
1505 # Could not release a file if lost
1506 $LFS hsm_set --lost $f || error "could not add flag"
1507 $LFS hsm_release $f && error "release should not succeed"
1508 $LFS hsm_clear --lost $f || error "could not remove flag"
1510 # Could not release a file if dirty
1511 $LFS hsm_set --dirty $f || error "could not add flag"
1512 $LFS hsm_release $f && error "release should not succeed"
1513 $LFS hsm_clear --dirty $f || error "could not remove flag"
1515 run_test 20 "Release is not permitted"
1518 # test needs a running copytool
1522 local f=$DIR/$tdir/test_release
1524 # Create a file and check its states
1525 local fid=$(make_small $f)
1526 check_hsm_flags $f "0x00000000"
1528 $LFS hsm_archive $f || error "could not archive file"
1529 wait_request_state $fid ARCHIVE SUCCEED
1531 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1532 local sz=$(stat -c "%s" $f)
1533 [ $sz -ne "0" ] || error "file size should not be zero"
1535 # Release and check states
1536 $LFS hsm_release $f || error "could not release file"
1537 check_hsm_flags $f "0x0000000d"
1539 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1540 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1542 # Check we can release an file without stripe info
1546 check_hsm_flags $f "0x00000000"
1547 $LFS hsm_archive $f || error "could not archive file"
1548 wait_request_state $fid ARCHIVE SUCCEED
1550 # Release and check states
1551 $LFS hsm_release $f || error "could not release file"
1552 check_hsm_flags $f "0x0000000d"
1554 # Release again a file that is already released is OK
1555 $LFS hsm_release $f || fail "second release should succeed"
1556 check_hsm_flags $f "0x0000000d"
1560 run_test 21 "Simple release tests"
1563 # test needs a running copytool
1568 local f=$DIR/$tdir/test_release
1569 local swap=$DIR/$tdir/test_swap
1571 # Create a file and check its states
1572 local fid=$(make_small $f)
1573 check_hsm_flags $f "0x00000000"
1575 $LFS hsm_archive $f || error "could not archive file"
1576 wait_request_state $fid ARCHIVE SUCCEED
1578 # Release and check states
1579 $LFS hsm_release $f || error "could not release file"
1580 check_hsm_flags $f "0x0000000d"
1583 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1588 run_test 22 "Could not swap a release file"
1591 # test needs a running copytool
1596 local f=$DIR/$tdir/test_mtime
1598 # Create a file and check its states
1599 local fid=$(make_small $f)
1600 check_hsm_flags $f "0x00000000"
1602 $LFS hsm_archive $f || error "could not archive file"
1603 wait_request_state $fid ARCHIVE SUCCEED
1605 # Set modification time in the past
1606 touch -m -a -d @978261179 $f
1608 # Release and check states
1609 $LFS hsm_release $f || error "could not release file"
1610 check_hsm_flags $f "0x0000000d"
1612 local MTIME=$(stat -c "%Y" $f)
1613 local ATIME=$(stat -c "%X" $f)
1614 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1615 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1619 run_test 23 "Release does not change a/mtime (utime)"
1622 local file=$DIR/$tdir/$tfile
1631 # test needs a running copytool
1636 fid=$(make_small $file)
1638 # Create a file and check its states
1639 check_hsm_flags $file "0x00000000"
1641 # Ensure atime is less than mtime and ctime.
1645 atime0=$(stat -c "%X" $file)
1646 mtime0=$(stat -c "%Y" $file)
1647 ctime0=$(stat -c "%Z" $file)
1649 [ $atime0 -lt $mtime0 ] ||
1650 error "atime $atime0 is not less than mtime $mtime0"
1652 [ $atime0 -lt $ctime0 ] ||
1653 error "atime $atime0 is not less than ctime $ctime0"
1655 # Archive should not change any timestamps.
1656 $LFS hsm_archive $file || error "cannot archive '$file'"
1657 wait_request_state $fid ARCHIVE SUCCEED
1659 atime1=$(stat -c "%X" $file)
1660 mtime1=$(stat -c "%Y" $file)
1661 ctime1=$(stat -c "%Z" $file)
1663 [ $atime0 -eq $atime1 ] ||
1664 error "archive changed atime from $atime0 to $atime1"
1666 [ $mtime0 -eq $mtime1 ] ||
1667 error "archive changed mtime from $mtime0 to $mtime1"
1669 [ $ctime0 -eq $ctime1 ] ||
1670 error "archive changed ctime from $ctime0 to $ctime1"
1672 # Release should not change any timestamps.
1673 $LFS hsm_release $file || error "cannot release '$file'"
1674 check_hsm_flags $file "0x0000000d"
1676 atime1=$(stat -c "%X" $file)
1677 mtime1=$(stat -c "%Y" $file)
1678 ctime1=$(stat -c "%Z" $file)
1680 [ $atime0 -eq $atime1 ] ||
1681 error "release changed atime from $atime0 to $atime1"
1683 [ $mtime0 -eq $mtime1 ] ||
1684 error "release changed mtime from $mtime0 to $mtime1"
1686 [ $ctime0 -eq $ctime1 ] ||
1687 error "release changed ctime from $ctime0 to $ctime1"
1689 # Restore should not change atime or mtime and should not
1691 $LFS hsm_restore $file
1692 wait_request_state $fid RESTORE SUCCEED
1694 atime1=$(stat -c "%X" $file)
1695 mtime1=$(stat -c "%Y" $file)
1696 ctime1=$(stat -c "%Z" $file)
1698 [ $atime0 -eq $atime1 ] ||
1699 error "restore changed atime from $atime0 to $atime1"
1701 [ $mtime0 -eq $mtime1 ] ||
1702 error "restore changed mtime from $mtime0 to $mtime1"
1704 [ $ctime0 -le $ctime1 ] ||
1705 error "restore changed ctime from $ctime0 to $ctime1"
1709 # Once more, after unmount and mount.
1710 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1711 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1713 atime1=$(stat -c "%X" $file)
1714 mtime1=$(stat -c "%Y" $file)
1715 ctime1=$(stat -c "%Z" $file)
1717 [ $atime0 -eq $atime1 ] ||
1718 error "remount changed atime from $atime0 to $atime1"
1720 [ $mtime0 -eq $mtime1 ] ||
1721 error "remount changed mtime from $mtime0 to $mtime1"
1723 [ $ctime0 -le $ctime1 ] ||
1724 error "remount changed ctime from $ctime0 to $ctime1"
1726 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1729 local file=$DIR/$tdir/$tfile
1735 # Test needs a running copytool.
1739 # Check that root can do HSM actions on a ordinary user's file.
1741 fid=$(make_small $file)
1742 sum0=$(md5sum $file)
1744 chown $RUNAS_ID:$RUNAS_GID $file ||
1745 error "cannot chown '$file' to '$RUNAS_ID'"
1747 chmod ugo-w $DIR/$tdir ||
1748 error "cannot chmod '$DIR/$tdir'"
1750 $LFS hsm_archive $file
1751 wait_request_state $fid ARCHIVE SUCCEED
1753 $LFS hsm_release $file
1754 check_hsm_flags $file "0x0000000d"
1756 $LFS hsm_restore $file
1757 wait_request_state $fid RESTORE SUCCEED
1759 # Check that ordinary user can get HSM state.
1760 $RUNAS $LFS hsm_state $file ||
1761 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1763 $LFS hsm_release $file
1764 check_hsm_flags $file "0x0000000d"
1766 # Check that ordinary user can accessed released file.
1767 sum1=$($RUNAS md5sum $file) ||
1768 error "user '$RUNAS_ID' cannot read '$file'"
1770 [ "$sum0" == "$sum1" ] ||
1771 error "md5sum mismatch for '$file'"
1775 run_test 24b "root can archive, release, and restore user files"
1777 cleanup_test_24c() {
1779 set_hsm_param user_request_mask RESTORE
1780 set_hsm_param group_request_mask RESTORE
1781 set_hsm_param other_request_mask RESTORE
1785 local file=$DIR/$tdir/$tfile
1786 local action=archive
1791 # test needs a running copytool
1796 # Save the default masks and check that cleanup_24c will
1797 # restore the request masks correctly.
1798 user_save=$(get_hsm_param user_request_mask)
1799 group_save=$(get_hsm_param group_request_mask)
1800 other_save=$(get_hsm_param other_request_mask)
1802 [ "$user_save" == RESTORE ] ||
1803 error "user_request_mask is '$user_save' expected 'RESTORE'"
1804 [ "$group_save" == RESTORE ] ||
1805 error "group_request_mask is '$group_save' expected 'RESTORE'"
1806 [ "$other_save" == RESTORE ] ||
1807 error "other_request_mask is '$other_save' expected 'RESTORE'"
1809 trap cleanup_test_24c EXIT
1814 chown $RUNAS_ID:nobody $file ||
1815 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1817 set_hsm_param user_request_mask ""
1818 $RUNAS $LFS hsm_$action $file &&
1819 error "$action by user should fail"
1821 set_hsm_param user_request_mask $action
1822 $RUNAS $LFS hsm_$action $file ||
1823 error "$action by user should succeed"
1828 chown nobody:$RUNAS_GID $file ||
1829 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1831 set_hsm_param group_request_mask ""
1832 $RUNAS $LFS hsm_$action $file &&
1833 error "$action by group should fail"
1835 set_hsm_param group_request_mask $action
1836 $RUNAS $LFS hsm_$action $file ||
1837 error "$action by group should succeed"
1842 chown nobody:nobody $file ||
1843 error "cannot chown '$file' to 'nobody:nobody'"
1845 set_hsm_param other_request_mask ""
1846 $RUNAS $LFS hsm_$action $file &&
1847 error "$action by other should fail"
1849 set_hsm_param other_request_mask $action
1850 $RUNAS $LFS hsm_$action $file ||
1851 error "$action by other should succeed"
1856 run_test 24c "check that user,group,other request masks work"
1858 cleanup_test_24d() {
1860 mount -o remount,rw $MOUNT2
1864 local file1=$DIR/$tdir/$tfile
1865 local file2=$DIR2/$tdir/$tfile
1873 fid1=$(make_small $file1)
1875 trap cleanup_test_24d EXIT
1877 mount -o remount,ro $MOUNT2
1879 fid2=$(path2fid $file2)
1880 [ "$fid1" == "$fid2" ] ||
1881 error "FID mismatch '$fid1' != '$fid2'"
1883 $LFS hsm_archive $file2 &&
1884 error "archive should fail on read-only mount"
1885 check_hsm_flags $file1 "0x00000000"
1887 $LFS hsm_archive $file1
1888 wait_request_state $fid1 ARCHIVE SUCCEED
1890 $LFS hsm_release $file1
1891 $LFS hsm_restore $file2
1892 wait_request_state $fid1 RESTORE SUCCEED
1894 $LFS hsm_release $file1 || error "cannot release '$file1'"
1895 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1897 $LFS hsm_release $file2 &&
1898 error "release should fail on read-only mount"
1903 run_test 24d "check that read-only mounts are respected"
1906 # test needs a running copytool
1910 copy2archive /etc/hosts $tdir/$tfile
1912 local f=$DIR/$tdir/$tfile
1914 import_file $tdir/$tfile $f
1916 $LFS hsm_set --lost $f
1921 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1925 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1926 " (Operation not permitted)"
1929 # test needs a running copytool
1934 local f=$DIR/$tdir/$tfile
1935 local fid=$(copy_file /etc/passwd $f)
1937 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1938 wait_request_state $fid ARCHIVE SUCCEED
1941 $LFS hsm_set --lost $f
1945 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1949 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1950 " (Operation not permitted)"
1953 # test needs a running copytool
1957 local f=$DIR/$tdir/$tfile
1958 local fid=$(make_large_for_progress $f)
1959 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1960 wait_request_state $fid ARCHIVE SUCCEED
1963 wait_request_state $fid REMOVE SUCCEED
1965 check_hsm_flags $f "0x00000000"
1969 run_test 26 "Remove the archive of a valid file"
1972 # test needs a running copytool
1976 make_archive $tdir/$tfile
1977 local f=$DIR/$tdir/$tfile
1978 import_file $tdir/$tfile $f
1979 local fid=$(path2fid $f)
1983 [[ $? != 0 ]] || error "Remove of a released file should fail"
1987 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1990 # test needs a running copytool
1994 local f=$DIR/$tdir/$tfile
1995 local fid=$(make_large_for_progress $f)
1996 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1997 wait_request_state $fid ARCHIVE SUCCEED
2002 [[ $? != 0 ]] || error "Remove of a released file should fail"
2006 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2009 # test needs a running copytool
2013 local f=$DIR/$tdir/$tfile
2014 local fid=$(make_large_for_progress $f)
2015 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2016 wait_request_state $fid ARCHIVE SUCCEED
2025 wait_request_state $fid REMOVE SUCCEED
2029 run_test 28 "Concurrent archive/file remove"
2032 # restore at exec cannot work on agent node (because of Linux kernel
2033 # protection of executables)
2034 needclients 2 || return 0
2036 # test needs a running copytool
2040 copy2archive /bin/true $tdir/$tfile
2042 local f=$DIR/$tdir/true
2043 import_file $tdir/$tfile $f
2045 local fid=$(path2fid $f)
2047 # set no retry action mode
2053 # remove no try action mode
2057 [[ $st == 0 ]] || error "Failed to exec a released file"
2061 run_test 30a "Restore at exec (import case)"
2064 # restore at exec cannot work on agent node (because of Linux kernel
2065 # protection of executables)
2066 needclients 2 || return 0
2068 # test needs a running copytool
2072 local f=$DIR/$tdir/true
2073 local fid=$(copy_file /bin/true $f)
2075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2076 wait_request_state $fid ARCHIVE SUCCEED
2079 # set no retry action mode
2085 # remove no try action mode
2089 [[ $st == 0 ]] || error "Failed to exec a released file"
2093 run_test 30b "Restore at exec (release case)"
2096 needclients 2 || return 0
2098 # test needs a running copytool
2102 local f=$DIR/$tdir/SLEEP
2103 local fid=$(copy_file /bin/sleep $f)
2105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2106 wait_request_state $fid ARCHIVE SUCCEED
2108 check_hsm_flags $f "0x0000000d"
2109 # set no retry action mode
2111 do_node $CLIENT2 "$f 10" &
2115 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2117 [[ $? == 0 ]] || error "Execution failed during run"
2119 [[ $? == 0 ]] || error "Binary overwritten during exec"
2122 # remove no try action mode
2124 check_hsm_flags $f "0x00000009"
2128 run_test 30c "Update during exec of released file must fail"
2130 restore_and_check_size() {
2133 local s=$(stat -c "%s" $f)
2135 local st=$(get_hsm_flags $f)
2139 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2141 n=$(stat -c "%s" $f)
2142 # we echo in both cases to show stat is not
2144 if [[ $n != $s ]]; then
2145 echo "size seen is $n != $s"
2148 echo "size seen is right: $n == $s"
2150 st=$(get_hsm_flags $f)
2154 if [[ $cpt -lt 10 ]]; then
2157 echo " restore is too long"
2158 wait_request_state $fid RESTORE SUCCEED
2164 # test needs a running copytool
2169 make_archive $tdir/$tfile
2170 local f=$DIR/$tdir/$tfile
2171 import_file $tdir/$tfile $f
2172 local fid=$($LFS path2fid $f)
2173 HSM_ARCHIVE_PURGE=false copytool_setup
2175 restore_and_check_size $f $fid
2178 [[ $err -eq 0 ]] || error "File size changed during restore"
2182 run_test 31a "Import a large file and check size during restore"
2186 # test needs a running copytool
2191 local f=$DIR/$tdir/$tfile
2192 local fid=$(make_large_for_progress $f)
2193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2194 wait_request_state $fid ARCHIVE SUCCEED
2197 restore_and_check_size $f $fid
2200 [[ $err -eq 0 ]] || error "File size changed during restore"
2204 run_test 31b "Restore a large unaligned file and check size during restore"
2207 # test needs a running copytool
2212 local f=$DIR/$tdir/$tfile
2213 local fid=$(make_large_for_progress_aligned $f)
2214 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2215 wait_request_state $fid ARCHIVE SUCCEED
2218 restore_and_check_size $f $fid
2221 [[ $err -eq 0 ]] || error "File size changed during restore"
2225 run_test 31c "Restore a large aligned file and check size during restore"
2228 # test needs a running copytool
2233 local f=$DIR/$tdir/$tfile
2234 local fid=$(make_large_for_progress $f)
2235 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2236 wait_request_state $fid ARCHIVE SUCCEED
2239 # to be sure wait_all_done will not be mislead by previous tests
2242 wait_for_grace_delay
2243 # Also raise grace_delay significantly so the Canceled
2244 # Restore action will stay enough long avail.
2245 local old_grace=$(get_hsm_param grace_delay)
2246 set_hsm_param grace_delay 100
2248 md5sum $f >/dev/null &
2250 wait_request_state $fid RESTORE STARTED
2255 # Check restore trigger process was killed
2256 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2260 # instead of waiting+checking both Restore and Cancel ops
2261 # sequentially, wait for both to be finished and then check
2263 wait_all_done 100 $fid
2264 local rstate=$(get_request_state $fid RESTORE)
2265 local cstate=$(get_request_state $fid CANCEL)
2267 # restore orig grace_delay.
2268 set_hsm_param grace_delay $old_grace
2270 if [[ "$rstate" == "CANCELED" ]] ; then
2271 [[ "$cstate" == "SUCCEED" ]] ||
2272 error "Restore state is CANCELED and Cancel state " \
2273 "is not SUCCEED but $cstate"
2274 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2275 elif [[ "$rstate" == "SUCCEED" ]] ; then
2276 [[ "$cstate" == "FAILED" ]] ||
2277 error "Restore state is SUCCEED and Cancel state " \
2278 "is not FAILED but $cstate"
2279 echo "Restore state is SUCCEED, Cancel state is FAILED"
2281 error "Restore state is $rstate and Cancel state is $cstate"
2285 error "Cannot kill process waiting for restore ($killed)"
2289 run_test 33 "Kill a restore waiting process"
2292 # test needs a running copytool
2297 local f=$DIR/$tdir/$tfile
2298 local fid=$(make_large_for_progress $f)
2299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2300 wait_request_state $fid ARCHIVE SUCCEED
2303 md5sum $f >/dev/null &
2305 wait_request_state $fid RESTORE STARTED
2307 rm $f || error "rm $f failed"
2308 # rm must not block during restore
2309 wait_request_state $fid RESTORE STARTED
2311 wait_request_state $fid RESTORE SUCCEED
2312 # check md5sum pgm finished
2313 local there=$(ps -o pid,comm hp $pid >/dev/null)
2314 [[ -z $there ]] || error "Restore initiator does not exit"
2316 local rc=$(wait $pid)
2317 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2321 run_test 34 "Remove file during restore"
2324 # test needs a running copytool
2329 local f=$DIR/$tdir/$tfile
2330 local f1=$DIR/$tdir/$tfile-1
2331 local fid=$(make_large_for_progress $f)
2332 local fid1=$(copy_file /etc/passwd $f1)
2333 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2334 wait_request_state $fid ARCHIVE SUCCEED
2337 md5sum $f >/dev/null &
2339 wait_request_state $fid RESTORE STARTED
2341 mv $f1 $f || error "mv $f1 $f failed"
2342 # mv must not block during restore
2343 wait_request_state $fid RESTORE STARTED
2345 wait_request_state $fid RESTORE SUCCEED
2346 # check md5sum pgm finished
2347 local there=$(ps -o pid,comm hp $pid >/dev/null)
2348 [[ -z $there ]] || error "Restore initiator does not exit"
2350 local rc=$(wait $pid)
2351 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2354 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2358 run_test 35 "Overwrite file during restore"
2361 # test needs a running copytool
2366 local f=$DIR/$tdir/$tfile
2367 local fid=$(make_large_for_progress $f)
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2369 wait_request_state $fid ARCHIVE SUCCEED
2372 md5sum $f >/dev/null &
2374 wait_request_state $fid RESTORE STARTED
2377 # rm must not block during restore
2378 wait_request_state $fid RESTORE STARTED
2380 wait_request_state $fid RESTORE SUCCEED
2381 # check md5sum pgm finished
2382 local there=$(ps -o pid,comm hp $pid >/dev/null)
2384 error "Restore initiator does not exit"
2386 local rc=$(wait $pid)
2388 error "Restore initiator failed with $rc"
2392 run_test 36 "Move file during restore"
2399 for n in $(seq 1 $count); do
2400 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2402 echo "$count archive requests submitted"
2406 local stream_count=4
2407 local file_count=100
2409 local f=$DIR/$tdir/$tfile
2414 for i in $(seq 1 $file_count); do
2415 for p in $(seq 1 $stream_count); do
2416 fid=$(copy_file /etc/hosts $f.$p.$i)
2419 # force copytool to use a local/temp archive dir to ensure best
2420 # performance vs remote/NFS mounts used in auto-tests
2421 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2424 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2426 # to be sure wait_all_done will not be mislead by previous tests
2428 wait_for_grace_delay
2430 # start archive streams in background (archive files in parallel)
2431 for p in $(seq 1 $stream_count); do
2432 multi_archive $f.$p $file_count &
2435 echo -n "Wait for all requests being enqueued..."
2441 run_test 40 "Parallel archive requests"
2444 # test needs a running copytool
2448 local f=$DIR/$tdir/$tfile
2449 local fid=$(copy_file /etc/motd $f 1)
2451 $LFS hsm_archive $f || error "could not archive file"
2452 wait_request_state $fid ARCHIVE SUCCEED
2453 check_hsm_flags $f "0x00000009"
2455 multiop_bg_pause $f O_c || error "multiop failed"
2459 client_up || client_up || true
2461 kill -USR1 $MULTIPID
2462 wait $MULTIPID || error "multiop close failed"
2464 check_hsm_flags $f "0x0000000b"
2468 run_test 52 "Opened for write file on an evicted client should be set dirty"
2471 # test needs a running copytool
2475 local f=$DIR/$tdir/$tfile
2476 local fid=$(copy_file /etc/motd $f 1)
2478 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2479 error "could not archive file"
2480 wait_request_state $fid ARCHIVE SUCCEED
2481 check_hsm_flags $f "0x00000009"
2483 multiop_bg_pause $f o_c || error "multiop failed"
2487 client_up || client_up || true
2489 kill -USR1 $MULTIPID
2490 wait $MULTIPID || error "multiop close failed"
2492 check_hsm_flags $f "0x00000009"
2496 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2499 # test needs a running copytool
2503 local f=$DIR/$tdir/$tfile
2504 local fid=$(make_small $f)
2506 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2507 error "could not archive file"
2508 wait_request_state $fid ARCHIVE STARTED
2510 check_hsm_flags $f "0x00000001"
2512 # Avoid coordinator resending this request as soon it has failed.
2517 wait_request_state $fid ARCHIVE FAILED
2519 check_hsm_flags $f "0x00000003"
2524 run_test 54 "Write during an archive cancels it"
2527 # test needs a running copytool
2531 local f=$DIR/$tdir/$tfile
2532 local fid=$(make_small $f)
2534 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2535 error "could not archive file"
2536 wait_request_state $fid ARCHIVE STARTED
2538 check_hsm_flags $f "0x00000001"
2540 # Avoid coordinator resending this request as soon it has failed.
2543 $TRUNCATE $f 1024 || error "truncate failed"
2545 wait_request_state $fid ARCHIVE FAILED
2547 check_hsm_flags $f "0x00000003"
2552 run_test 55 "Truncate during an archive cancels it"
2555 # test needs a running copytool
2559 local f=$DIR/$tdir/$tfile
2560 local fid=$(make_large_for_progress $f)
2562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2563 error "could not archive file"
2564 wait_request_state $fid ARCHIVE STARTED
2566 check_hsm_flags $f "0x00000001"
2568 # Change metadata and sync to be sure we are not changing only
2573 wait_request_state $fid ARCHIVE SUCCEED
2575 check_hsm_flags $f "0x00000009"
2579 run_test 56 "Setattr during an archive is ok"
2582 # Need one client for I/O, one for request
2583 needclients 2 || return 0
2585 # test needs a running copytool
2589 local f=$DIR/$tdir/test_archive_remote
2590 # Create a file on a remote node
2591 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2592 "count=2 conv=fsync"
2595 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2596 error "hsm_archive failed"
2597 local fid=$(path2fid $f)
2598 wait_request_state $fid ARCHIVE SUCCEED
2600 # Release and implicit restore it
2601 do_node $CLIENT2 "$LFS hsm_release $f" ||
2602 error "hsm_release failed"
2603 do_node $CLIENT2 "md5sum $f" ||
2604 error "hsm_restore failed"
2606 wait_request_state $fid RESTORE SUCCEED
2610 run_test 57 "Archive a file with dirty cache on another node"
2612 truncate_released_file() {
2616 local sz=$(stat -c %s $src_file)
2617 local f=$DIR/$tdir/$tfile
2618 local fid=$(copy_file $1 $f)
2622 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2623 error "could not archive file"
2624 wait_request_state $fid ARCHIVE SUCCEED
2626 $LFS hsm_release $f || error "could not release file"
2628 $TRUNCATE $f $trunc_to || error "truncate failed"
2631 local sz1=$(stat -c %s $f)
2632 [[ $sz1 == $trunc_to ]] ||
2633 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2636 check_hsm_flags $f "0x0000000b"
2638 local state=$(get_request_state $fid RESTORE)
2639 [[ "$state" == "SUCCEED" ]] ||
2640 error "truncate $sz does not trig restore, state = $state"
2642 $TRUNCATE $ref $trunc_to
2643 cmp $ref $f || error "file data wrong after truncate"
2649 # test needs a running copytool
2654 local sz=$(stat -c %s /etc/passwd)
2656 echo "truncate up from $sz to $((sz*2))"
2657 truncate_released_file /etc/passwd $((sz*2))
2659 echo "truncate down from $sz to $((sz/2))"
2660 truncate_released_file /etc/passwd $((sz/2))
2662 echo "truncate to 0"
2663 truncate_released_file /etc/passwd 0
2667 run_test 58 "Truncate a released file will trigger restore"
2670 # This test validates the fix for LU-4512. Ensure that the -u
2671 # option changes the progress reporting interval from the
2672 # default (30 seconds) to the user-specified interval.
2674 local progress_timeout=$((interval * 4))
2676 # test needs a new running copytool
2678 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2681 local f=$DIR/$tdir/$tfile
2682 local fid=$(make_large_for_progress $f)
2685 local mdt=${MDT_PREFIX}${mdtidx}
2686 local mds=mds$((mdtidx + 1))
2688 # Wait for copytool to register
2689 wait_update_facet $mds \
2690 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2691 uuid 100 || error "coyptool failed to register with $mdt"
2693 local start_at=$(date +%s)
2694 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2695 error "could not archive file"
2697 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2698 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2704 echo -n "Expecting a progress update within $progress_timeout seconds... "
2706 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2707 if [ $RESULT -gt 0 ]; then
2708 echo "$RESULT bytes copied in $WAIT seconds."
2710 elif [ $WAIT -ge $progress_timeout ]; then
2711 error "Timed out waiting for progress update!"
2713 WAIT=$((WAIT + sleep))
2717 local finish_at=$(date +%s)
2718 local elapsed=$((finish_at - start_at))
2720 # Ensure that the progress update occurred within the expected window.
2721 if [ $elapsed -lt $interval ]; then
2722 error "Expected progress update after at least $interval seconds"
2728 run_test 60 "Changing progress update interval from default"
2731 # test needs a new running copytool
2733 copytool_monitor_setup
2734 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2736 # Just start and stop the copytool to generate events.
2740 local REGISTER_EVENT
2741 local UNREGISTER_EVENT
2742 while read event; do
2743 local parsed=$(parse_json_event "$event")
2744 if [ -z "$parsed" ]; then
2745 error "Copytool sent malformed event: $event"
2749 if [ $event_type == "REGISTER" ]; then
2750 REGISTER_EVENT=$event
2751 elif [ $event_type == "UNREGISTER" ]; then
2752 UNREGISTER_EVENT=$event
2754 done < <(echo $"$(get_copytool_event_log)")
2756 if [ -z "$REGISTER_EVENT" ]; then
2757 error "Copytool failed to send register event to FIFO"
2760 if [ -z "$UNREGISTER_EVENT" ]; then
2761 error "Copytool failed to send unregister event to FIFO"
2764 copytool_monitor_cleanup
2765 echo "Register/Unregister events look OK."
2767 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2770 # Bump progress interval for livelier events.
2773 # test needs a new running copytool
2775 copytool_monitor_setup
2776 HSMTOOL_UPDATE_INTERVAL=$interval \
2777 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2780 local f=$DIR/$tdir/$tfile
2781 local fid=$(make_large_for_progress $f)
2783 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2784 error "could not archive file"
2785 wait_request_state $fid ARCHIVE SUCCEED
2787 local expected_fields="event_time data_fid source_fid"
2788 expected_fields+=" total_bytes current_bytes"
2792 while read event; do
2793 # Make sure we're not getting anything from previous events.
2794 for field in $expected_fields; do
2798 local parsed=$(parse_json_event "$event")
2799 if [ -z "$parsed" ]; then
2800 error "Copytool sent malformed event: $event"
2804 if [ $event_type == "ARCHIVE_START" ]; then
2807 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2810 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2814 # Do some simple checking of the progress update events.
2815 for expected_field in $expected_fields; do
2816 if [ -z ${!expected_field+x} ]; then
2817 error "Missing $expected_field field in event"
2821 if [ $total_bytes -eq 0 ]; then
2822 error "Expected total_bytes to be > 0"
2825 # These should be identical throughout an archive
2827 if [ $source_fid != $data_fid ]; then
2828 error "Expected source_fid to equal data_fid"
2830 done < <(echo $"$(get_copytool_event_log)")
2832 if [ -z "$START_EVENT" ]; then
2833 error "Copytool failed to send archive start event to FIFO"
2836 if [ -z "$FINISH_EVENT" ]; then
2837 error "Copytool failed to send archive finish event to FIFO"
2840 echo "Archive events look OK."
2844 copytool_monitor_cleanup
2846 run_test 71 "Copytool logs JSON archive events to FIFO"
2849 # Bump progress interval for livelier events.
2852 # test needs a new running copytool
2854 copytool_monitor_setup
2855 HSMTOOL_UPDATE_INTERVAL=$interval \
2856 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2857 local test_file=$HSMTOOL_MONITOR_DIR/file
2859 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2861 do_facet $SINGLEAGT "$cmd" ||
2862 error "cannot create $test_file on $SINGLEAGT"
2863 copy2archive $test_file $tdir/$tfile
2866 local f=$DIR/$tdir/$tfile
2867 import_file $tdir/$tfile $f
2868 f=$DIR2/$tdir/$tfile
2869 echo "Verifying released state: "
2870 check_hsm_flags $f "0x0000000d"
2872 local fid=$(path2fid $f)
2874 wait_request_state $fid RESTORE SUCCEED
2876 local expected_fields="event_time data_fid source_fid"
2877 expected_fields+=" total_bytes current_bytes"
2881 while read event; do
2882 # Make sure we're not getting anything from previous events.
2883 for field in $expected_fields; do
2887 local parsed=$(parse_json_event "$event")
2888 if [ -z "$parsed" ]; then
2889 error "Copytool sent malformed event: $event"
2893 if [ $event_type == "RESTORE_START" ]; then
2895 if [ $source_fid != $data_fid ]; then
2896 error "source_fid should == data_fid at start"
2899 elif [ $event_type == "RESTORE_FINISH" ]; then
2901 if [ $source_fid != $data_fid ]; then
2902 error "source_fid should == data_fid at finish"
2905 elif [ $event_type != "RESTORE_RUNNING" ]; then
2909 # Do some simple checking of the progress update events.
2910 for expected_field in $expected_fields; do
2911 if [ -z ${!expected_field+x} ]; then
2912 error "Missing $expected_field field in event"
2916 if [ $total_bytes -eq 0 ]; then
2917 error "Expected total_bytes to be > 0"
2920 # When a restore starts out, the data fid is the same as the
2921 # source fid. After the restore has gotten going, we learn
2922 # the new data fid. Once the restore has finished, the source
2923 # fid is set to the new data fid.
2925 # We test this because some monitoring software may depend on
2926 # this behavior. If it changes, then the consumers of these
2927 # events may need to be modified.
2928 if [ $source_fid == $data_fid ]; then
2929 error "source_fid should != data_fid during restore"
2931 done < <(echo $"$(get_copytool_event_log)")
2933 if [ -z "$START_EVENT" ]; then
2934 error "Copytool failed to send restore start event to FIFO"
2937 if [ -z "$FINISH_EVENT" ]; then
2938 error "Copytool failed to send restore finish event to FIFO"
2941 echo "Restore events look OK."
2945 copytool_monitor_cleanup
2949 run_test 72 "Copytool logs JSON restore events to FIFO"
2952 file_count=51 # Max number of files constrained by LNET message size
2953 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2954 local f=$DIR/$tdir/$tfile
2955 local FILELIST=/tmp/filelist.txt
2959 for i in $(seq 1 $file_count); do
2960 fid=$(copy_file /etc/hosts $f.$i)
2961 echo $f.$i >> $FILELIST
2964 # to be sure wait_all_done will not be mislead by previous tests
2966 wait_for_grace_delay
2967 $LFS hsm_archive --filelist $FILELIST ||
2968 error "cannot archive a file list"
2970 $LFS hsm_release --filelist $FILELIST ||
2971 error "cannot release a file list"
2972 $LFS hsm_restore --filelist $FILELIST ||
2973 error "cannot restore a file list"
2977 run_test 90 "Archive/restore a file list"
2979 double_verify_reset_hsm_param() {
2981 echo "Testing $HSM_PARAM.$p"
2982 local val=$(get_hsm_param $p)
2984 local val2=$(($val * 2))
2985 set_hsm_param $p $val2
2986 val=$(get_hsm_param $p)
2987 [[ $val == $val2 ]] ||
2988 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2989 echo "Set $p to 0 must failed"
2993 set_hsm_param $p $save
2995 if [[ $rc == 0 ]]; then
2996 error "we must not be able to set $HSM_PARAM.$p to 0"
3001 double_verify_reset_hsm_param loop_period
3002 double_verify_reset_hsm_param grace_delay
3003 double_verify_reset_hsm_param active_request_timeout
3004 double_verify_reset_hsm_param max_requests
3005 double_verify_reset_hsm_param default_archive_id
3007 run_test 100 "Set coordinator /proc tunables"
3014 run_test 102 "Verify coordinator control"
3017 # test needs a running copytool
3024 for i in $(seq 1 20); do
3025 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3027 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3031 echo "Current requests"
3032 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3033 $HSM_PARAM.actions |\
3034 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3036 [[ -z "$res" ]] || error "Some request have not been canceled"
3040 run_test 103 "Purge all requests"
3045 # test needs a running copytool
3049 local f=$DIR/$tdir/$tfile
3050 local fid=$(make_large_for_progress $f)
3051 # if cdt is on, it can serve too quickly the request
3053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3054 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3055 $HSM_PARAM.actions |\
3056 grep $fid | cut -f16 -d=")
3059 [[ "$data1" == "$DATAHEX" ]] ||
3060 error "Data field in records is ($data1) and not ($DATAHEX)"
3064 run_test 104 "Copy tool data field"
3071 for i in $(seq -w 1 10); do
3072 cp /etc/passwd $DIR/$tdir/$i
3073 $LFS hsm_archive $DIR/$tdir/$i
3075 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3076 $HSM_PARAM.actions |\
3077 grep WAITING | wc -l")
3080 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3081 $HSM_PARAM.actions |\
3082 grep WAITING | wc -l")
3085 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3086 error "Requests count after shutdown $reqcnt2 != "\
3087 "before shutdown $reqcnt1"
3089 run_test 105 "Restart of coordinator"
3091 get_agent_by_uuid_mdt() {
3094 local mds=mds$(($mdtidx + 1))
3095 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3099 check_agent_registered_by_mdt() {
3102 local mds=mds$(($mdtidx + 1))
3103 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3104 if [[ ! -z "$agent" ]]; then
3105 echo "found agent $agent on $mds"
3107 error "uuid $uuid not found in agent list on $mds"
3111 check_agent_unregistered_by_mdt() {
3114 local mds=mds$(($mdtidx + 1))
3115 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3116 if [[ -z "$agent" ]]; then
3117 echo "uuid not found in agent list on $mds"
3119 error "uuid found in agent list on $mds: $agent"
3123 check_agent_registered() {
3126 for mdsno in $(seq 1 $MDSCOUNT); do
3127 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3131 check_agent_unregistered() {
3134 for mdsno in $(seq 1 $MDSCOUNT); do
3135 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3140 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3141 get_client_uuid $MOUNT | cut -d' ' -f2)
3144 check_agent_registered $uuid
3146 search_copytools || error "No copytool found"
3149 check_agent_unregistered $uuid
3152 check_agent_registered $uuid
3156 run_test 106 "Copytool register/unregister"
3159 # test needs a running copytool
3161 # create and archive file
3163 local f1=$DIR/$tdir/$tfile
3164 local fid=$(copy_file /etc/passwd $f1)
3165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3166 wait_request_state $fid ARCHIVE SUCCEED
3167 # shutdown and restart MDS
3169 # check the copytool still gets messages from MDT
3170 local f2=$DIR/$tdir/2
3171 local fid=$(copy_file /etc/passwd $f2)
3172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3173 # main check of this sanity: this request MUST succeed
3174 wait_request_state $fid ARCHIVE SUCCEED
3177 run_test 107 "Copytool re-register after MDS restart"
3179 policy_set_and_test()
3183 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3184 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3185 [[ "$policy" == "$target" ]] ||
3186 error "Wrong policy after '$change': '$policy' != '$target'"
3190 # to force default policy setting if error
3191 CDT_POLICY_HAD_CHANGED=true
3193 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3194 local default="NonBlockingRestore [NoRetryAction]"
3195 [[ "$policy" == "$default" ]] ||
3196 error "default policy has changed,"\
3197 " '$policy' != '$default' update the test"
3198 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3199 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3200 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3201 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3202 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3203 # useless bacause we know but safer for futur changes to use real value
3204 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3205 echo "Next set_param must failed"
3206 policy_set_and_test "wrong" "$policy"
3209 echo "Back to default policy"
3210 cdt_set_sanity_policy
3212 run_test 109 "Policy display/change"
3215 # test needs a running copytool
3220 copy2archive /etc/passwd $tdir/$tfile
3222 local f=$DIR/$tdir/$tfile
3223 import_file $tdir/$tfile $f
3224 local fid=$(path2fid $f)
3226 cdt_set_non_blocking_restore
3231 wait_request_state $fid RESTORE SUCCEED
3232 cdt_clear_non_blocking_restore
3236 error "md5sum returns $st != 1, "\
3237 "should also perror ENODATA (No data available)"
3241 run_test 110a "Non blocking restore policy (import case)"
3244 # test needs a running copytool
3248 local f=$DIR/$tdir/$tfile
3249 local fid=$(copy_file /etc/passwd $f)
3250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3251 wait_request_state $fid ARCHIVE SUCCEED
3254 cdt_set_non_blocking_restore
3259 wait_request_state $fid RESTORE SUCCEED
3260 cdt_clear_non_blocking_restore
3264 error "md5sum returns $st != 1, "\
3265 "should also perror ENODATA (No data available)"
3269 run_test 110b "Non blocking restore policy (release case)"
3272 # test needs a running copytool
3276 copy2archive /etc/passwd $tdir/$tfile
3278 local f=$DIR/$tdir/$tfile
3280 import_file $tdir/$tfile $f
3281 local fid=$(path2fid $f)
3285 copytool_remove_backend $fid
3288 wait_request_state $fid RESTORE FAILED
3295 [[ $st == 0 ]] || error "Restore does not failed"
3299 run_test 111a "No retry policy (import case), restore will error"\
3300 " (No such file or directory)"
3303 # test needs a running copytool
3307 local f=$DIR/$tdir/$tfile
3308 local fid=$(copy_file /etc/passwd $f)
3310 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3311 wait_request_state $fid ARCHIVE SUCCEED
3314 copytool_remove_backend $fid
3317 wait_request_state $fid RESTORE FAILED
3324 [[ $st == 0 ]] || error "Restore does not failed"
3328 run_test 111b "No retry policy (release case), restore will error"\
3329 " (No such file or directory)"
3332 # test needs a running copytool
3336 local f=$DIR/$tdir/$tfile
3337 local fid=$(copy_file /etc/passwd $f)
3339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3340 local l=$($LFS hsm_action $f)
3342 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3346 wait_request_state $fid ARCHIVE SUCCEED
3349 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3353 run_test 112 "State of recorded request"
3356 # test needs a running copytool
3360 local f=$DIR/$tdir/$tfile
3361 local fid=$(make_large_for_cancel $f)
3362 # test with cdt on is made in test_221
3364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3367 wait_request_state $fid ARCHIVE CANCELED
3368 wait_request_state $fid CANCEL SUCCEED
3372 run_test 200 "Register/Cancel archive"
3375 # test needs a running copytool
3379 local f=$DIR/$tdir/$tfile
3380 make_archive $tdir/$tfile
3381 import_file $tdir/$tfile $f
3382 local fid=$(path2fid $f)
3384 # test with cdt on is made in test_222
3389 wait_request_state $fid RESTORE CANCELED
3390 wait_request_state $fid CANCEL SUCCEED
3394 run_test 201 "Register/Cancel restore"
3397 # test needs a running copytool
3401 local f=$DIR/$tdir/$tfile
3402 local fid=$(make_large_for_progress $f)
3403 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3404 wait_request_state $fid ARCHIVE SUCCEED
3410 wait_request_state $fid REMOVE CANCELED
3414 run_test 202 "Register/Cancel remove"
3417 # test needs a running copytool
3422 local f=$DIR/$tdir/$tfile
3423 local fid=$(copy_file /etc/passwd $f)
3427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3428 wait_request_state $fid ARCHIVE SUCCEED
3430 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3434 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3438 run_test 220 "Changelog for archive"
3441 # test needs a running copytool
3446 local f=$DIR/$tdir/$tfile
3447 local fid=$(make_large_for_cancel $f)
3451 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3452 wait_request_state $fid ARCHIVE STARTED
3454 wait_request_state $fid ARCHIVE CANCELED
3455 wait_request_state $fid CANCEL SUCCEED
3457 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3460 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3464 run_test 221 "Changelog for archive canceled"
3467 # test needs a running copytool
3471 copy2archive /etc/passwd $tdir/$tfile
3473 local f=$DIR/$tdir/$tfile
3474 import_file $tdir/$tfile $f
3475 local fid=$(path2fid $f)
3480 wait_request_state $fid RESTORE SUCCEED
3482 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3485 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3489 run_test 222a "Changelog for explicit restore"
3492 # test needs a running copytool
3496 local f=$DIR/$tdir/$tfile
3497 local fid=$(copy_file /etc/passwd $f)
3500 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3501 wait_request_state $fid ARCHIVE SUCCEED
3506 wait_request_state $fid RESTORE SUCCEED
3508 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3511 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3515 run_test 222b "Changelog for implicit restore"
3518 # test needs a running copytool
3523 local f=$DIR/$tdir/$tfile
3524 make_archive $tdir/$tfile
3528 import_file $tdir/$tfile $f
3529 local fid=$(path2fid $f)
3532 wait_request_state $fid RESTORE STARTED
3534 wait_request_state $fid RESTORE CANCELED
3535 wait_request_state $fid CANCEL SUCCEED
3537 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3540 [[ $flags == $target ]] ||
3541 error "Changelog flag is $flags not $target"
3545 run_test 223a "Changelog for restore canceled (import case)"
3548 # test needs a running copytool
3553 local f=$DIR/$tdir/$tfile
3554 local fid=$(make_large_for_progress $f)
3557 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3558 wait_request_state $fid ARCHIVE SUCCEED
3561 wait_request_state $fid RESTORE STARTED
3563 wait_request_state $fid RESTORE CANCELED
3564 wait_request_state $fid CANCEL SUCCEED
3566 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3569 [[ $flags == $target ]] ||
3570 error "Changelog flag is $flags not $target"
3574 run_test 223b "Changelog for restore canceled (release case)"
3577 # test needs a running copytool
3582 local f=$DIR/$tdir/$tfile
3583 local fid=$(copy_file /etc/passwd $f)
3586 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3587 wait_request_state $fid ARCHIVE SUCCEED
3590 wait_request_state $fid REMOVE SUCCEED
3592 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3595 [[ $flags == $target ]] ||
3596 error "Changelog flag is $flags not $target"
3600 run_test 224 "Changelog for remove"
3603 # test needs a running copytool
3606 # test is not usable because remove request is too fast
3607 # so it is always finished before cancel can be done ...
3608 echo "Test disabled"
3613 local f=$DIR/$tdir/$tfile
3614 local fid=$(make_large_for_progress $f)
3617 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3618 wait_request_state $fid ARCHIVE SUCCEED
3620 # if cdt is on, it can serve too quickly the request
3625 wait_request_state $fid REMOVE CANCELED
3626 wait_request_state $fid CANCEL SUCCEED
3628 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3629 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3630 tail -n 1 | awk '{print $5}')
3633 [[ $flags == $target ]] ||
3634 error "Changelog flag is $flags not $target"
3638 run_test 225 "Changelog for remove canceled"
3641 # test needs a running copytool
3646 local f1=$DIR/$tdir/$tfile-1
3647 local f2=$DIR/$tdir/$tfile-2
3648 local f3=$DIR/$tdir/$tfile-3
3649 local fid1=$(copy_file /etc/passwd $f1)
3650 local fid2=$(copy_file /etc/passwd $f2)
3651 copy_file /etc/passwd $f3
3654 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3655 wait_request_state $fid1 ARCHIVE SUCCEED
3657 $LFS hsm_archive $f2
3658 wait_request_state $fid2 ARCHIVE SUCCEED
3660 rm $f1 || error "rm $f1 failed"
3662 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3665 [[ $flags == $target ]] ||
3666 error "Changelog flag is $flags not $target"
3668 mv $f3 $f2 || error "mv $f3 $f2 failed"
3670 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3673 [[ $flags == $target ]] ||
3674 error "Changelog flag is $flags not $target"
3678 run_test 226 "changelog for last rm/mv with exiting archive"
3680 check_flags_changes() {
3688 $LFS hsm_set --$hsm_flag $f ||
3689 error "Cannot set $hsm_flag on $f"
3690 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3691 local seen=${#flags[*]}
3693 [[ $seen == $cnt ]] ||
3694 error "set $hsm_flag: Changelog events $seen != $cnt"
3695 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3696 error "set $hsm_flag: Changelog flags are "\
3697 "${flags[$((cnt - 1))]} not $target"
3699 $LFS hsm_clear --$hsm_flag $f ||
3700 error "Cannot clear $hsm_flag on $f"
3701 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3704 [[ $cnt == $seen ]] ||
3705 error "clear $hsm_flag: Changelog events $seen != $cnt"
3707 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3708 error "clear $hsm_flag: Changelog flag is "\
3709 "${flags[$((cnt - 1))]} not $target"
3713 # test needs a running copytool
3720 for i in norelease noarchive exists archived
3722 local f=$DIR/$tdir/$tfile-$i
3723 local fid=$(copy_file /etc/passwd $f)
3724 check_flags_changes $f $fid $i 0 1
3727 f=$DIR/$tdir/$tfile---lost
3728 fid=$(copy_file /etc/passwd $f)
3729 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3730 wait_request_state $fid ARCHIVE SUCCEED
3731 check_flags_changes $f $fid lost 3 1
3735 run_test 227 "changelog when explicit setting of HSM flags"
3738 # test needs a running copytool
3741 local fid=$(make_small_sync $DIR/$tfile)
3742 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3743 wait_request_state $fid ARCHIVE SUCCEED
3745 $LFS hsm_release $DIR/$tfile
3746 check_hsm_flags $DIR/$tfile "0x0000000d"
3748 filefrag $DIR/$tfile | grep " 1 extent found" ||
3749 error "filefrag on released file must return only one extent"
3751 # only newer versions of cp detect sparse files by stat/FIEMAP
3753 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3754 error "copying $DIR/$tfile"
3755 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3757 $LFS hsm_release $DIR/$tfile
3758 check_hsm_flags $DIR/$tfile "0x0000000d"
3760 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3762 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3764 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3765 error "comparing untarred $DIR/$tfile"
3767 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3768 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3771 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3774 # test needs a running copytool
3778 local maxrequest=$(get_hsm_param max_requests)
3779 local rqcnt=$(($maxrequest * 3))
3783 for i in $(seq -w 1 $rqcnt); do
3785 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3787 # we do it in 2 steps, so all requests arrive at the same time
3788 for i in $(seq -w 1 $rqcnt); do
3789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3794 while [[ $cnt != 0 || $wt != 0 ]]; do
3796 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3797 $HSM_PARAM.actions |\
3798 grep STARTED | grep -v CANCEL | wc -l")
3799 [[ $cnt -le $maxrequest ]] ||
3800 error "$cnt > $maxrequest too many started requests"
3801 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3802 $HSM_PARAM.actions |\
3803 grep WAITING | wc -l")
3804 echo "max=$maxrequest started=$cnt waiting=$wt"
3809 run_test 250 "Coordinator max request"
3812 # test needs a running copytool
3816 local f=$DIR/$tdir/$tfile
3817 local fid=$(make_large_for_cancel $f)
3820 # to have a short test
3821 local old_to=$(get_hsm_param active_request_timeout)
3822 set_hsm_param active_request_timeout 4
3823 # to be sure the cdt will wake up frequently so
3824 # it will be able to cancel the "old" request
3825 local old_loop=$(get_hsm_param loop_period)
3826 set_hsm_param loop_period 2
3829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3830 wait_request_state $fid ARCHIVE STARTED
3832 wait_request_state $fid ARCHIVE CANCELED
3834 set_hsm_param active_request_timeout $old_to
3835 set_hsm_param loop_period $old_loop
3839 run_test 251 "Coordinator request timeout"
3842 # the only way to test ondisk conf is to restart MDS ...
3843 echo "Stop coordinator and remove coordinator state at mount"
3846 # clean on disk conf set by default
3847 cdt_clear_mount_state
3848 cdt_check_state stopped
3850 # check cdt still off after umount/remount
3852 cdt_check_state stopped
3854 echo "Set coordinator start at mount, and start coordinator"
3855 cdt_set_mount_state enabled
3858 cdt_check_state enabled
3860 # check cdt still on after umount/remount
3862 cdt_check_state enabled
3864 # we are back to original state (cdt started at mount)
3866 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3869 local ai=$(get_hsm_param default_archive_id)
3870 local new=$((ai + 1))
3872 set_hsm_param default_archive_id $new -P
3874 local res=$(get_hsm_param default_archive_id)
3877 set_hsm_param default_archive_id "" "-P -d"
3879 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3881 run_test 301 "HSM tunnable are persistent"
3884 local ai=$(get_hsm_param default_archive_id)
3885 local new=$((ai + 1))
3890 set_hsm_param default_archive_id $new -P
3893 for mdtno in $(seq 1 $MDSCOUNT); do
3898 cdt_check_state enabled
3900 local res=$(get_hsm_param default_archive_id)
3903 set_hsm_param default_archive_id "" "-P -d"
3905 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3907 run_test 302 "HSM tunnable are persistent when CDT is off"
3910 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3916 local dir_mdt0=$DIR/$tdir/mdt0
3917 local dir_mdt1=$DIR/$tdir/mdt1
3919 # create 1 dir per MDT
3920 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3921 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3923 # create 1 file in each MDT
3924 local fid1=$(make_small $dir_mdt0/$tfile)
3925 local fid2=$(make_small $dir_mdt1/$tfile)
3927 # check that hsm request on mdt0 is sent to the right MDS
3928 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3929 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3930 echo "archive successful on mdt0"
3932 # check that hsm request on mdt1 is sent to the right MDS
3933 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3934 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3935 echo "archive successful on mdt1"
3938 # clean test files and directories
3939 rm -rf $dir_mdt0 $dir_mdt1
3941 run_test 400 "Single request is sent to the right MDT"
3944 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3950 local dir_mdt0=$DIR/$tdir/mdt0
3951 local dir_mdt1=$DIR/$tdir/mdt1
3953 # create 1 dir per MDT
3954 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3955 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3957 # create 1 file in each MDT
3958 local fid1=$(make_small $dir_mdt0/$tfile)
3959 local fid2=$(make_small $dir_mdt1/$tfile)
3961 # check that compound requests are shunt to the rights MDTs
3962 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3963 error "lfs hsm_archive"
3964 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3965 echo "archive successful on mdt0"
3966 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3967 echo "archive successful on mdt1"
3970 # clean test files and directories
3971 rm -rf $dir_mdt0 $dir_mdt1
3973 run_test 401 "Compound requests split and sent to their respective MDTs"
3975 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3980 local node=$(facet_active_host $facet)
3982 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3983 awk '{print $4}'); do
3984 echo "$3 $mdc on $node"
3985 do_facet $facet "$LCTL --device $mdc $state" || return 1
3990 # make sure there is no running copytool
3993 # deactivate all mdc on agent1
3994 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
3996 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
3998 check_agent_unregistered "uuid" # match any agent
4000 # no expected running copytool
4001 search_copytools $agent && error "Copytool start should have failed"
4004 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4006 run_test 402 "Copytool start fails if all MDTs are inactive"
4009 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4011 # make sure there is no running copytool
4014 local agent=$(facet_active_host $SINGLEAGT)
4015 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4017 # deactivate all mdc for MDT0001
4018 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4021 # check the agent is registered on MDT0000, and not on MDT0001
4022 check_agent_registered_by_mdt $uuid 0
4023 check_agent_unregistered_by_mdt $uuid 1
4025 # check running copytool process
4026 search_copytools $agent || error "No running copytools on $agent"
4028 # reactivate all mdc for MDT0001
4029 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4031 # make sure the copytool is now registered to all MDTs
4032 check_agent_registered $uuid
4036 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4039 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4043 # create files on both MDT0000 and MDT0001
4046 local dir_mdt0=$DIR/$tdir/mdt0
4047 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4049 # create 1 file on mdt0
4050 local fid1=$(make_small $dir_mdt0/$tfile)
4052 # deactivate all mdc for MDT0001
4053 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4055 # send an HSM request for files in MDT0000
4056 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4058 # check for completion of files in MDT0000
4059 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4060 echo "archive successful on mdt0"
4062 # reactivate all mdc for MDT0001
4063 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4066 # clean test files and directories
4069 run_test 404 "Inactive MDT does not block requests for active MDTs"
4074 check_and_cleanup_lustre