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 # 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
108 # Get the backend root path for the given agent facet.
111 local dev=AGTDEV$(facet_number $facet)
116 # Stop copytool and unregister an existing changelog user.
118 copytool_monitor_cleanup
121 cdt_set_sanity_policy
126 # get MDT device for each mdc
127 for mdtno in $(seq 1 $MDSCOUNT); do
128 local idx=$(($mdtno - 1))
129 MDT[$idx]=$($LCTL get_param -n \
130 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
131 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
136 local agents=${1:-$(facet_active_host $SINGLEAGT)}
137 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
140 search_and_kill_copytool() {
141 local agents=${1:-$(facet_active_host $SINGLEAGT)}
143 echo "Killing existing copytools on $agents"
144 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
147 copytool_monitor_setup() {
148 local facet=${1:-$SINGLEAGT}
149 local agent=$(facet_active_host $facet)
151 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
152 local test_dir=$(do_node $agent "$cmd") ||
153 error "Failed to create tempdir on $agent"
154 export HSMTOOL_MONITOR_DIR=$test_dir
156 # Create the fifo and a monitor (cat dies when copytool dies)
157 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
158 error "failed to create copytool fifo on $agent"
159 cmd="cat $test_dir/fifo > $test_dir/events &"
160 cmd+=" echo \\\$! > $test_dir/monitor_pid"
162 if [[ $PDSH == *Rmrsh* ]]; then
163 # This is required for pdsh -Rmrsh and its handling of remote
165 # Regular ssh and pdsh -Rssh work fine without this
166 # backgrounded subshell nonsense.
167 (do_node $agent "$cmd") &
168 export HSMTOOL_MONITOR_PDSH=$!
170 # Slightly racy, but just making a best-effort to catch obvious
173 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
174 error "Failed to start copytool monitor on $agent"
176 do_node $agent "$cmd"
178 error "Failed to start copytool monitor on $agent"
183 copytool_monitor_cleanup() {
184 local facet=${1:-$SINGLEAGT}
185 local agent=$(facet_active_host $facet)
187 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
188 # Should die when the copytool dies, but just in case.
189 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
190 cmd+=" 2>/dev/null || true"
191 do_node $agent "$cmd"
192 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
193 export HSMTOOL_MONITOR_DIR=
196 # The pdsh should die on its own when the monitor dies. Just
197 # in case, though, try to clean up to avoid any cruft.
198 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
199 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
200 export HSMTOOL_MONITOR_PDSH=
205 local facet=${1:-$SINGLEAGT}
206 local lustre_mntpnt=${2:-$MOUNT}
208 local hsm_root=${4:-$(copytool_device $facet)}
209 local agent=$(facet_active_host $facet)
211 if [[ -z "$arc_id" ]] &&
212 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
213 echo "Wakeup copytool $facet on $agent"
217 if $HSM_ARCHIVE_PURGE; then
218 echo "Purging archive on $agent"
219 do_facet $facet "rm -rf $hsm_root/*"
222 echo "Starting copytool $facet on $agent"
223 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
224 # bandwidth is limited to 1MB/s so the copy time is known and
225 # independent of hardware
226 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
227 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
228 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
229 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
230 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
231 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
232 cmd+=" --bandwidth 1 $lustre_mntpnt"
234 # Redirect the standard output and error to a log file which
235 # can be uploaded to Maloo.
236 local prefix=$TESTLOG_PREFIX
237 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
238 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
240 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
241 error "start copytool $facet on $agent failed"
245 get_copytool_event_log() {
246 local facet=${1:-$SINGLEAGT}
247 local agent=$(facet_active_host $facet)
249 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
250 error "Can't get event log: No monitor directory!"
252 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
253 error "Could not collect event log from $agent"
258 local agents=${1:-$(facet_active_host $SINGLEAGT)}
264 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
266 echo "Copytool is stopped on $agents"
268 # clean all CDTs orphans requests from previous tests
269 # that would otherwise need to timeout to clear.
270 for mdtno in $(seq 1 $MDSCOUNT); do
272 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
273 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
275 # skip already stop[ed,ing] CDTs
276 echo $oldstate | grep stop && continue
278 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
279 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
281 error "mds${mdtno} cdt state is not stopped"
282 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
283 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
285 error "mds${mdtno} cdt state is not $oldstate"
290 local agents=${1:-$(facet_active_host $SINGLEAGT)}
292 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
293 echo "Copytool is suspended on $agents"
296 copytool_remove_backend() {
298 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
299 echo "Remove from backend: $fid = $be"
300 do_facet $SINGLEAGT rm -f $be
304 do_facet $SINGLEAGT \
305 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
306 --import $1 $2 $MOUNT" ||
307 error "import of $1 to $2 failed"
311 local file=$HSM_ARCHIVE/$1
312 do_facet $SINGLEAGT mkdir -p $(dirname $file)
313 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
314 error "cannot create $file"
318 local file=$HSM_ARCHIVE/$2
319 do_facet $SINGLEAGT mkdir -p $(dirname $file)
320 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
329 if [[ "$value" != "" ]]; then
332 for mdtno in $(seq 1 $MDSCOUNT); do
333 local idx=$(($mdtno - 1))
334 local facet=mds${mdtno}
335 # if $arg include -P option, run 1 set_param per MDT on the MGS
336 # else, run set_param on each MDT
337 [[ $arg = *"-P"* ]] && facet=mgs
338 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
339 [[ $? != 0 ]] && rc=1
349 for mdtno in $(seq 1 $MDSCOUNT); do
350 local idx=$(($mdtno - 1))
351 wait_result mds${mdtno} \
352 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
354 error "$key state is not '$target' on mds${mdtno}"
361 for mdtno in $(seq 1 $MDSCOUNT); do
362 local idx=$(($mdtno - 1))
363 local cl_user=$(do_facet mds${mdtno} $LCTL \
364 --device ${MDT[$idx]} \
365 changelog_register -n)
367 do_facet mds${mdtno} lctl set_param \
368 mdd.${MDT[$idx]}.changelog_mask="+hsm"
369 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
373 changelog_cleanup() {
375 for mdtno in $(seq 1 $MDSCOUNT); do
376 local idx=$(($mdtno - 1))
377 [[ -z ${CL_USERS[$idx]} ]] && continue
378 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
379 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
380 changelog_deregister ${CL_USERS[$idx]}
385 changelog_get_flags() {
390 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
395 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
403 mdts_set_param "$opt -n" "hsm.$param" "$value"
410 mdts_set_param "" hsm_control "$cmd"
411 mdts_check_param hsm_control "$target" 10
414 cdt_set_sanity_policy() {
415 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
418 mdts_set_param "" hsm.policy "+NRA"
419 mdts_set_param "" hsm.policy "-NBR"
420 CDT_POLICY_HAD_CHANGED=
425 mdts_set_param "" hsm.policy "+NRA"
426 CDT_POLICY_HAD_CHANGED=true
429 cdt_clear_no_retry() {
430 mdts_set_param "" hsm.policy "-NRA"
431 CDT_POLICY_HAD_CHANGED=true
434 cdt_set_non_blocking_restore() {
435 mdts_set_param "" hsm.policy "+NBR"
436 CDT_POLICY_HAD_CHANGED=true
439 cdt_clear_non_blocking_restore() {
440 mdts_set_param "" hsm.policy "-NBR"
441 CDT_POLICY_HAD_CHANGED=true
444 cdt_clear_mount_state() {
445 mdts_set_param "-P -d" hsm_control ""
448 cdt_set_mount_state() {
449 mdts_set_param "-P" hsm_control "$1"
453 mdts_check_param hsm_control "$1" 20
457 set_test_state disabled disabled
461 set_test_state enabled enabled
465 set_test_state shutdown stopped
469 set_test_state purge enabled
475 cdt_set_sanity_policy
479 local client_count=$1
480 if [[ $CLIENTCOUNT -lt $client_count ]]; then
481 skip "Need $client_count or more clients, have $CLIENTCOUNT"
488 $LFS path2fid $1 | tr -d '[]'
495 if [[ $u == "user" ]]; then
496 local st=$($RUNAS $LFS hsm_state $f)
498 local st=$($LFS hsm_state $f)
502 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
504 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
508 get_hsm_archive_id() {
510 local st=$($LFS hsm_state $f)
511 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
513 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
522 local st=$(get_hsm_flags $f)
523 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
526 check_hsm_flags_user() {
530 local st=$(get_hsm_flags $f user)
531 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
543 if [[ "$3" != 1 ]]; then
547 cp $1 $f || error "cannot copy $1 to $f"
548 path2fid $f || error "cannot get fid on $f"
552 local file2=${1/$DIR/$DIR2}
553 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
554 error "cannot create $file2"
555 path2fid $1 || error "cannot get fid on $1"
559 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
560 error "cannot create $1"
561 path2fid $1 || error "cannot get fid on $1"
564 cleanup_large_files() {
565 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
567 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
570 make_large_for_striping() {
571 local file2=${1/$DIR/$DIR2}
572 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
576 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
577 error "cannot create $file2"
578 path2fid $1 || error "cannot get fid on $1"
581 make_large_for_progress() {
582 local file2=${1/$DIR/$DIR2}
586 # big file is large enough, so copy time is > 30s
587 # so copytool make 1 progress
588 # size is not a multiple of 1M to avoid stripe
590 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
591 error "cannot create $file2"
592 path2fid $1 || error "cannot get fid on $1"
595 make_large_for_progress_aligned() {
596 local file2=${1/$DIR/$DIR2}
600 # big file is large enough, so copy time is > 30s
601 # so copytool make 1 progress
602 # size is a multiple of 1M to have stripe
604 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
605 error "cannot create $file2"
606 path2fid $1 || error "cannot get fid on $1"
609 make_large_for_cancel() {
610 local file2=${1/$DIR/$DIR2}
614 # Copy timeout is 100s. 105MB => 105s
615 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
616 error "cannot create $file2"
617 path2fid $1 || error "cannot get fid on $1"
623 wait_update --verbose $(facet_active_host $facet) "$@"
626 wait_request_state() {
630 # 4th arg (mdt index) is optional
632 local mds=mds$(($mdtidx + 1))
634 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
635 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
637 wait_result $mds "$cmd" $state 100 ||
638 error "request on $fid is not $state on $mds"
641 get_request_state() {
645 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
646 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
649 get_request_count() {
653 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
654 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
660 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
661 cmd+=" | egrep 'WAITING|STARTED'"
663 wait_result $SINGLEMDS "$cmd" "" $timeout ||
664 error "requests did not complete"
667 wait_for_grace_delay() {
668 local val=$(get_hsm_param grace_delay)
675 # python2.6 in EL6 includes an internal json module
676 local json_parser='import json; import fileinput;'
677 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
678 json_parser+='json.loads([line for line in '
679 json_parser+='fileinput.input()][0]).items()])'
681 echo $raw_event | python -c "$json_parser"
684 # populate MDT device array
690 # cleanup from previous bad setup
691 search_and_kill_copytool
693 # for recovery tests, coordinator needs to be started at mount
695 # the lustre conf must be without hsm on (like for sanity.sh)
696 echo "Set HSM on and start"
697 cdt_set_mount_state enabled
698 cdt_check_state enabled
700 echo "Start copytool"
703 echo "Set sanity-hsm HSM policy"
704 cdt_set_sanity_policy
706 # finished requests are quickly removed from list
707 set_hsm_param grace_delay 10
713 local f=$DIR/$tdir/$tfile
717 check_hsm_flags_user $f "0x00000000"
719 $RUNAS $LFS hsm_set --norelease $f ||
720 error "user could not change hsm flags"
721 check_hsm_flags_user $f "0x00000010"
723 $RUNAS $LFS hsm_clear --norelease $f ||
724 error "user could not clear hsm flags"
725 check_hsm_flags_user $f "0x00000000"
727 # User could not change those flags...
728 $RUNAS $LFS hsm_set --exists $f &&
729 error "user should not set this flag"
730 check_hsm_flags_user $f "0x00000000"
733 $LFS hsm_set --exists $f ||
734 error "root could not change hsm flags"
735 check_hsm_flags_user $f "0x00000001"
737 $LFS hsm_clear --exists $f ||
738 error "root could not clear hsm state"
739 check_hsm_flags_user $f "0x00000000"
742 run_test 1 "lfs hsm flags root/non-root access"
746 local f=$DIR/$tdir/$tfile
748 # New files are not dirty
749 check_hsm_flags $f "0x00000000"
751 # For test, we simulate an archived file.
752 $LFS hsm_set --exists $f || error "user could not change hsm flags"
753 check_hsm_flags $f "0x00000001"
755 # chmod do not put the file dirty
756 chmod 600 $f || error "could not chmod test file"
757 check_hsm_flags $f "0x00000001"
759 # chown do not put the file dirty
760 chown $RUNAS_ID $f || error "could not chown test file"
761 check_hsm_flags $f "0x00000001"
763 # truncate put the file dirty
764 $TRUNCATE $f 1 || error "could not truncate test file"
765 check_hsm_flags $f "0x00000003"
767 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
768 check_hsm_flags $f "0x00000001"
770 run_test 2 "Check file dirtyness when doing setattr"
776 # New files are not dirty
778 check_hsm_flags $f "0x00000000"
780 # For test, we simulate an archived file.
781 $LFS hsm_set --exists $f ||
782 error "user could not change hsm flags"
783 check_hsm_flags $f "0x00000001"
785 # Reading a file, does not set dirty
786 cat $f > /dev/null || error "could not read file"
787 check_hsm_flags $f "0x00000001"
789 # Open for write without modifying data, does not set dirty
790 openfile -f O_WRONLY $f || error "could not open test file"
791 check_hsm_flags $f "0x00000001"
793 # Append to a file sets it dirty
794 cp -p /etc/passwd $f.append || error "could not create file"
795 $LFS hsm_set --exists $f.append ||
796 error "user could not change hsm flags"
797 dd if=/etc/passwd of=$f.append bs=1 count=3\
798 conv=notrunc oflag=append status=noxfer ||
799 error "could not append to test file"
800 check_hsm_flags $f.append "0x00000003"
802 # Modify a file sets it dirty
803 cp -p /etc/passwd $f.modify || error "could not create file"
804 $LFS hsm_set --exists $f.modify ||
805 error "user could not change hsm flags"
806 dd if=/dev/zero of=$f.modify bs=1 count=3\
807 conv=notrunc status=noxfer ||
808 error "could not modify test file"
809 check_hsm_flags $f.modify "0x00000003"
811 # Open O_TRUNC sets dirty
812 cp -p /etc/passwd $f.trunc || error "could not create file"
813 $LFS hsm_set --exists $f.trunc ||
814 error "user could not change hsm flags"
815 cp /etc/group $f.trunc || error "could not override a file"
816 check_hsm_flags $f.trunc "0x00000003"
818 # Mmapped a file sets dirty
819 cp -p /etc/passwd $f.mmap || error "could not create file"
820 $LFS hsm_set --exists $f.mmap ||
821 error "user could not change hsm flags"
822 multiop $f.mmap OSMWUc || error "could not mmap a file"
823 check_hsm_flags $f.mmap "0x00000003"
825 run_test 3 "Check file dirtyness when opening for write"
829 local f=$DIR/$tdir/$tfile
830 local fid=$(make_small $f)
833 local st=$(get_request_state $fid CANCEL)
834 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
836 run_test 4 "Useless cancel must not be registered"
839 # test needs a running copytool
843 local f=$DIR/$tdir/$tfile
844 local fid=$(copy_file /etc/passwd $f)
846 wait_request_state $fid ARCHIVE SUCCEED
848 check_hsm_flags $f "0x00000009"
852 run_test 8 "Test default archive number"
856 local f=$DIR/$tdir/$tfile
857 local fid=$(copy_file /etc/passwd $f)
858 # we do not use the default one to be sure
859 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
861 copytool_setup $SINGLEAGT $MOUNT $new_an
862 $LFS hsm_archive --archive $new_an $f
863 wait_request_state $fid ARCHIVE SUCCEED
865 check_hsm_flags $f "0x00000009"
869 run_test 9 "Use of explict archive number, with dedicated copytool"
872 needclients 3 || return 0
878 copytool_cleanup $(comma_list $(agts_nodes))
880 # start all of the copytools
881 for n in $(seq $AGTCOUNT); do
885 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
888 for n in $(seq $AGTCOUNT); do
889 file=$DIR/$tdir/$tfile.$n
890 fid=$(make_small $file)
892 $LFS hsm_archive $file || error "could not archive file $file"
893 wait_request_state $fid ARCHIVE SUCCEED
894 check_hsm_flags $file "0x00000009"
898 copytool_cleanup $(comma_list $(agts_nodes))
900 run_test 9a "Multiple remote agents"
903 # test needs a running copytool
906 mkdir -p $DIR/$tdir/d1
907 local f=$DIR/$tdir/$tfile
908 local fid=$(copy_file /etc/hosts $f)
909 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
910 error "hsm_archive failed"
911 wait_request_state $fid ARCHIVE SUCCEED
913 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
914 error "fid $fid not in archive $HSM_ARCHIVE"
915 echo "Verifying content"
916 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
917 echo "Verifying hsm state "
918 check_hsm_flags $f "0x00000009"
920 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
921 local st=$(get_hsm_archive_id $f)
922 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
923 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
928 run_test 10a "Archive a file"
931 # test needs a running copytool
935 local f=$DIR/$tdir/$tfile
936 local fid=$(copy_file /etc/hosts $f)
937 $LFS hsm_archive $f || error "archive request failed"
938 wait_request_state $fid ARCHIVE SUCCEED
940 $LFS hsm_archive $f || error "archive of non dirty file failed"
941 local cnt=$(get_request_count $fid ARCHIVE)
942 [[ "$cnt" == "1" ]] ||
943 error "archive of non dirty file must not make a request"
947 run_test 10b "Archive of non dirty file must work without doing request"
950 # test needs a running copytool
954 local f=$DIR/$tdir/$tfile
955 local fid=$(copy_file /etc/hosts $f)
956 $LFS hsm_set --noarchive $f
957 $LFS hsm_archive $f && error "archive a noarchive file must fail"
961 run_test 10c "Check forbidden archive"
964 # test needs a running copytool
968 local f=$DIR/$tdir/$tfile
969 local fid=$(copy_file /etc/hosts $f)
970 $LFS hsm_archive $f || error "cannot archive $f"
971 wait_request_state $fid ARCHIVE SUCCEED
973 local ar=$(get_hsm_archive_id $f)
974 local dflt=$(get_hsm_param default_archive_id)
975 [[ $ar == $dflt ]] ||
976 error "archived file is not on default archive: $ar != $dflt"
980 run_test 10d "Archive a file on the default archive id"
984 copy2archive /etc/hosts $tdir/$tfile
985 local f=$DIR/$tdir/$tfile
987 import_file $tdir/$tfile $f
988 echo -n "Verifying released state: "
989 check_hsm_flags $f "0x0000000d"
991 local LSZ=$(stat -c "%s" $f)
992 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
994 echo "Verifying imported size $LSZ=$ASZ"
995 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
996 echo -n "Verifying released pattern: "
997 local PTRN=$($GETSTRIPE -L $f)
999 [[ $PTRN == 80000001 ]] || error "Is not released"
1000 local fid=$(path2fid $f)
1001 echo "Verifying new fid $fid in archive"
1003 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1004 error "fid $fid not in archive $HSM_ARCHIVE"
1006 run_test 11 "Import a file"
1009 # test needs a running copytool
1013 copy2archive /etc/hosts $tdir/$tfile
1015 local f=$DIR/$tdir/$tfile
1016 import_file $tdir/$tfile $f
1017 local f=$DIR2/$tdir/$tfile
1018 echo "Verifying released state: "
1019 check_hsm_flags $f "0x0000000d"
1021 local fid=$(path2fid $f)
1023 wait_request_state $fid RESTORE SUCCEED
1025 echo "Verifying file state: "
1026 check_hsm_flags $f "0x00000009"
1028 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1030 [[ $? -eq 0 ]] || error "Restored file differs"
1034 run_test 12a "Restore an imported file explicitly"
1037 # test needs a running copytool
1041 copy2archive /etc/hosts $tdir/$tfile
1043 local f=$DIR/$tdir/$tfile
1044 import_file $tdir/$tfile $f
1045 echo "Verifying released state: "
1046 check_hsm_flags $f "0x0000000d"
1048 cat $f > /dev/null || error "File read failed"
1050 echo "Verifying file state after restore: "
1051 check_hsm_flags $f "0x00000009"
1053 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1055 [[ $? -eq 0 ]] || error "Restored file differs"
1059 run_test 12b "Restore an imported file implicitly"
1062 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1064 # test needs a running copytool
1068 local f=$DIR/$tdir/$tfile
1069 $LFS setstripe -c 2 $f
1070 local fid=$(make_large_for_striping $f)
1071 local FILE_CRC=$(md5sum $f)
1073 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1074 wait_request_state $fid ARCHIVE SUCCEED
1075 $LFS hsm_release $f || error "release $f failed"
1077 echo "$FILE_CRC" | md5sum -c
1079 [[ $? -eq 0 ]] || error "Restored file differs"
1083 run_test 12c "Restore a file with stripe of 2"
1086 # test needs a running copytool
1091 local f=$DIR/$tdir/$tfile
1092 local fid=$(copy_file /etc/hosts $f)
1093 $LFS hsm_restore $f || error "restore of non archived file failed"
1094 local cnt=$(get_request_count $fid RESTORE)
1095 [[ "$cnt" == "0" ]] ||
1096 error "restore non archived must not make a request"
1097 $LFS hsm_archive $f ||
1098 error "archive request failed"
1099 wait_request_state $fid ARCHIVE SUCCEED
1100 $LFS hsm_restore $f ||
1101 error "restore of non released file failed"
1102 local cnt=$(get_request_count $fid RESTORE)
1103 [[ "$cnt" == "0" ]] ||
1104 error "restore a non dirty file must not make a request"
1108 run_test 12d "Restore of a non archived, non released file must work"\
1109 " without doing request"
1112 # test needs a running copytool
1115 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1116 local f=$DIR/$tdir/$tfile
1117 local fid=$(copy_file /etc/hosts $f)
1118 $LFS hsm_archive $f || error "archive request failed"
1119 wait_request_state $fid ARCHIVE SUCCEED
1122 cat /etc/hosts >> $f
1126 $LFS hsm_restore $f && error "restore a dirty file must fail"
1130 run_test 12e "Check forbidden restore"
1133 # test needs a running copytool
1137 local f=$DIR/$tdir/$tfile
1138 local fid=$(copy_file /etc/hosts $f)
1140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1141 wait_request_state $fid ARCHIVE SUCCEED
1142 $LFS hsm_release $f || error "release of $f failed"
1144 wait_request_state $fid RESTORE SUCCEED
1146 echo -n "Verifying file state: "
1147 check_hsm_flags $f "0x00000009"
1149 diff -q /etc/hosts $f
1151 [[ $? -eq 0 ]] || error "Restored file differs"
1155 run_test 12f "Restore a released file explicitly"
1158 # test needs a running copytool
1162 local f=$DIR/$tdir/$tfile
1163 local fid=$(copy_file /etc/hosts $f)
1165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1166 wait_request_state $fid ARCHIVE SUCCEED
1167 $LFS hsm_release $f || error "release of $f failed"
1169 diff -q /etc/hosts $f
1172 # we check we had a restore done
1173 wait_request_state $fid RESTORE SUCCEED
1175 [[ $st -eq 0 ]] || error "Restored file differs"
1179 run_test 12g "Restore a released file implicitly"
1182 needclients 2 || return 0
1184 # test needs a running copytool
1188 local f=$DIR/$tdir/$tfile
1189 local fid=$(copy_file /etc/hosts $f)
1191 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1192 wait_request_state $fid ARCHIVE SUCCEED
1193 $LFS hsm_release $f || error "release of $f failed"
1195 do_node $CLIENT2 diff -q /etc/hosts $f
1198 # we check we had a restore done
1199 wait_request_state $fid RESTORE SUCCEED
1201 [[ $st -eq 0 ]] || error "Restored file differs"
1205 run_test 12h "Restore a released file implicitly from a second node"
1208 # test needs a running copytool
1212 local f=$DIR/$tdir/$tfile
1213 local fid=$(copy_file /etc/passwd $f)
1214 $LFS hsm_archive $f || error "archive of $f failed"
1215 wait_request_state $fid ARCHIVE SUCCEED
1217 $LFS hsm_release $f || error "release of $f failed"
1221 [[ $? -eq 0 ]] || error "Restored file differs"
1225 run_test 12m "Archive/release/implicit restore"
1228 # test needs a running copytool
1232 copy2archive /etc/hosts $tdir/$tfile
1234 local f=$DIR/$tdir/$tfile
1235 import_file $tdir/$tfile $f
1237 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1238 error "Restored file differs"
1240 $LFS hsm_release $f || error "release of $f failed"
1244 run_test 12n "Import/implicit restore/release"
1247 # test needs a running copytool
1251 local f=$DIR/$tdir/$tfile
1252 local fid=$(copy_file /etc/hosts $f)
1254 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1255 wait_request_state $fid ARCHIVE SUCCEED
1256 $LFS hsm_release $f || error "release of $f failed"
1258 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1259 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1261 # set no retry action mode
1264 diff -q /etc/hosts $f
1267 # we check we had a restore failure
1268 wait_request_state $fid RESTORE FAILED
1270 [[ $st -eq 0 ]] && error "Restore must fail"
1272 # remove no retry action mode
1275 # check file is still released
1276 check_hsm_flags $f "0x0000000d"
1278 # retry w/o failure injection
1279 do_facet $SINGLEMDS lctl set_param fail_loc=0
1281 # to be sure previous RESTORE result is gone
1283 wait_for_grace_delay
1285 diff -q /etc/hosts $f
1288 # we check we had a restore done
1289 wait_request_state $fid RESTORE SUCCEED
1291 [[ $st -eq 0 ]] || error "Restored file differs"
1295 run_test 12o "Layout-swap failure during Restore leaves file released"
1298 # test needs a running copytool
1301 local ARC_SUBDIR="import.orig"
1305 # populate directory to be imported
1306 for d in $(seq 1 10); do
1307 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1308 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1309 for f in $(seq 1 10); do
1310 CURR_FILE="$CURR_DIR/$tfile.$f"
1311 # write file-specific data
1312 do_facet $SINGLEAGT \
1313 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1314 "file=$CURR_FILE > $CURR_FILE"
1318 import_file "$ARC_SUBDIR" $DIR/$tdir
1319 # diff lustre content and origin (triggers file restoration)
1320 # there must be 10x10 identical files, and no difference
1321 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1322 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1323 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1324 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1326 [ $cnt_diff -eq 0 ] ||
1327 error "$cnt_diff imported files differ from read data"
1328 [ $cnt_ok -eq 100 ] ||
1329 error "not enough identical files ($cnt_ok != 100)"
1333 run_test 13 "Recursively import and restore a directory"
1336 # test needs a running copytool
1341 local f=$DIR/$tdir/$tfile
1342 local fid=$(make_small $f)
1343 local sum=$(md5sum $f | awk '{print $1}')
1344 $LFS hsm_archive $f || error "could not archive file"
1345 wait_request_state $fid ARCHIVE SUCCEED
1349 # create released file (simulate llapi_hsm_import call)
1351 local fid2=$(path2fid $f)
1352 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1353 $LFS hsm_release $f || error "could not release file"
1355 # rebind the archive to the newly created file
1356 echo "rebind $fid to $fid2"
1358 do_facet $SINGLEAGT \
1359 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1360 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1362 # restore file and compare md5sum
1363 local sum2=$(md5sum $f | awk '{print $1}')
1365 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1369 run_test 14 "Rebind archived file to a new fid"
1372 # test needs a running copytool
1377 local f=$DIR/$tdir/$tfile
1379 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1383 for i in $(seq 1 $count); do
1384 fids[$i]=$(make_small $f.$i)
1385 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1386 $LFS hsm_archive $f.$i || error "could not archive file"
1388 wait_all_done $(($count*60))
1392 for i in $(seq 1 $count); do
1395 local fid2=$(path2fid $f.$i)
1396 # add the rebind operation to the list
1397 echo ${fids[$i]} $fid2 >> $tmpfile
1399 # set it released (simulate llapi_hsm_import call)
1400 $LFS hsm_set --archived --exists $f.$i ||
1401 error "could not force hsm flags"
1402 $LFS hsm_release $f.$i || error "could not release file"
1404 nl=$(wc -l < $tmpfile)
1405 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1407 echo "rebind list of files"
1408 do_facet $SINGLEAGT \
1409 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1410 --rebind $tmpfile $DIR" || error "could not rebind file list"
1412 # restore files and compare md5sum
1413 for i in $(seq 1 $count); do
1414 local sum2=$(md5sum $f.$i | awk '{print $1}')
1415 [[ $sum2 == ${sums[$i]} ]] ||
1416 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1422 run_test 15 "Rebind a list of files"
1425 # test needs a running copytool
1429 # create a known size file so we can verify transfer speed
1432 dd if=/dev/zero of=$ref bs=1M count=20
1435 local f=$DIR/$tdir/$tfile
1436 local fid=$(copy_file $ref $f)
1438 local start=$(date +%s)
1440 wait_request_state $fid ARCHIVE SUCCEED
1441 local end=$(date +%s)
1442 local duration=$((end - start))
1444 [[ $duration -ge $goal ]] ||
1445 error "Transfer is too fast $duration < $goal"
1449 run_test 16 "Test CT bandwith control option"
1454 local f=$DIR/$tdir/$tfile
1455 touch $f || error "touch $f failed"
1457 # Could not release a non-archived file
1458 $LFS hsm_release $f && error "release should not succeed"
1460 # For following tests, we must test them with HS_ARCHIVED set
1461 $LFS hsm_set --exists --archived $f || error "could not add flag"
1463 # Could not release a file if no-release is set
1464 $LFS hsm_set --norelease $f || error "could not add flag"
1465 $LFS hsm_release $f && error "release should not succeed"
1466 $LFS hsm_clear --norelease $f || error "could not remove flag"
1468 # Could not release a file if lost
1469 $LFS hsm_set --lost $f || error "could not add flag"
1470 $LFS hsm_release $f && error "release should not succeed"
1471 $LFS hsm_clear --lost $f || error "could not remove flag"
1473 # Could not release a file if dirty
1474 $LFS hsm_set --dirty $f || error "could not add flag"
1475 $LFS hsm_release $f && error "release should not succeed"
1476 $LFS hsm_clear --dirty $f || error "could not remove flag"
1478 run_test 20 "Release is not permitted"
1481 # test needs a running copytool
1485 local f=$DIR/$tdir/test_release
1487 # Create a file and check its states
1488 local fid=$(make_small $f)
1489 check_hsm_flags $f "0x00000000"
1491 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1492 # used until file is flushed to disk
1493 if [ $(facet_fstype ost1) == "zfs" ]; then
1494 # this causes an OST_SYNC rpc to be sent
1495 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1496 # clear locks to reread file data
1497 cancel_lru_locks osc
1500 local orig_size=$(stat -c "%s" $f)
1501 local orig_blocks=$(stat -c "%b" $f)
1503 start_full_debug_logging
1505 $LFS hsm_archive $f || error "could not archive file"
1506 wait_request_state $fid ARCHIVE SUCCEED
1508 local blocks=$(stat -c "%b" $f)
1509 [ $blocks -eq $orig_blocks ] ||
1510 error "$f: wrong block number after archive: " \
1511 "$blocks != $orig_blocks"
1512 local size=$(stat -c "%s" $f)
1513 [ $size -eq $orig_size ] ||
1514 error "$f: wrong size after archive: $size != $orig_size"
1516 # Release and check states
1517 $LFS hsm_release $f || error "could not release file"
1518 check_hsm_flags $f "0x0000000d"
1520 blocks=$(stat -c "%b" $f)
1521 [ $blocks -gt 5 ] &&
1522 error "$f: too many blocks after release: $blocks > 5"
1523 size=$(stat -c "%s" $f)
1524 [ $size -ne $orig_size ] &&
1525 error "$f: wrong size after release: $size != $orig_size"
1527 # Check we can release an file without stripe info
1531 check_hsm_flags $f "0x00000000"
1532 $LFS hsm_archive $f || error "could not archive file"
1533 wait_request_state $fid ARCHIVE SUCCEED
1535 # Release and check states
1536 $LFS hsm_release $f || error "could not release file"
1537 check_hsm_flags $f "0x0000000d"
1539 # Release again a file that is already released is OK
1540 $LFS hsm_release $f || fail "second release should succeed"
1541 check_hsm_flags $f "0x0000000d"
1543 stop_full_debug_logging
1547 run_test 21 "Simple release tests"
1550 # test needs a running copytool
1555 local f=$DIR/$tdir/test_release
1556 local swap=$DIR/$tdir/test_swap
1558 # Create a file and check its states
1559 local fid=$(make_small $f)
1560 check_hsm_flags $f "0x00000000"
1562 $LFS hsm_archive $f || error "could not archive file"
1563 wait_request_state $fid ARCHIVE SUCCEED
1565 # Release and check states
1566 $LFS hsm_release $f || error "could not release file"
1567 check_hsm_flags $f "0x0000000d"
1570 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1575 run_test 22 "Could not swap a release file"
1578 # test needs a running copytool
1583 local f=$DIR/$tdir/test_mtime
1585 # Create a file and check its states
1586 local fid=$(make_small $f)
1587 check_hsm_flags $f "0x00000000"
1589 $LFS hsm_archive $f || error "could not archive file"
1590 wait_request_state $fid ARCHIVE SUCCEED
1592 # Set modification time in the past
1593 touch -m -a -d @978261179 $f
1595 # Release and check states
1596 $LFS hsm_release $f || error "could not release file"
1597 check_hsm_flags $f "0x0000000d"
1599 local MTIME=$(stat -c "%Y" $f)
1600 local ATIME=$(stat -c "%X" $f)
1601 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1602 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1606 run_test 23 "Release does not change a/mtime (utime)"
1609 local file=$DIR/$tdir/$tfile
1618 # test needs a running copytool
1623 fid=$(make_small $file)
1625 # Create a file and check its states
1626 check_hsm_flags $file "0x00000000"
1628 # Ensure atime is less than mtime and ctime.
1632 atime0=$(stat -c "%X" $file)
1633 mtime0=$(stat -c "%Y" $file)
1634 ctime0=$(stat -c "%Z" $file)
1636 [ $atime0 -lt $mtime0 ] ||
1637 error "atime $atime0 is not less than mtime $mtime0"
1639 [ $atime0 -lt $ctime0 ] ||
1640 error "atime $atime0 is not less than ctime $ctime0"
1642 # Archive should not change any timestamps.
1643 $LFS hsm_archive $file || error "cannot archive '$file'"
1644 wait_request_state $fid ARCHIVE SUCCEED
1646 atime1=$(stat -c "%X" $file)
1647 mtime1=$(stat -c "%Y" $file)
1648 ctime1=$(stat -c "%Z" $file)
1650 [ $atime0 -eq $atime1 ] ||
1651 error "archive changed atime from $atime0 to $atime1"
1653 [ $mtime0 -eq $mtime1 ] ||
1654 error "archive changed mtime from $mtime0 to $mtime1"
1656 [ $ctime0 -eq $ctime1 ] ||
1657 error "archive changed ctime from $ctime0 to $ctime1"
1659 # Release should not change any timestamps.
1660 $LFS hsm_release $file || error "cannot release '$file'"
1661 check_hsm_flags $file "0x0000000d"
1663 atime1=$(stat -c "%X" $file)
1664 mtime1=$(stat -c "%Y" $file)
1665 ctime1=$(stat -c "%Z" $file)
1667 [ $atime0 -eq $atime1 ] ||
1668 error "release changed atime from $atime0 to $atime1"
1670 [ $mtime0 -eq $mtime1 ] ||
1671 error "release changed mtime from $mtime0 to $mtime1"
1673 [ $ctime0 -eq $ctime1 ] ||
1674 error "release changed ctime from $ctime0 to $ctime1"
1676 # Restore should not change atime or mtime and should not
1678 $LFS hsm_restore $file
1679 wait_request_state $fid RESTORE SUCCEED
1681 atime1=$(stat -c "%X" $file)
1682 mtime1=$(stat -c "%Y" $file)
1683 ctime1=$(stat -c "%Z" $file)
1685 [ $atime0 -eq $atime1 ] ||
1686 error "restore changed atime from $atime0 to $atime1"
1688 [ $mtime0 -eq $mtime1 ] ||
1689 error "restore changed mtime from $mtime0 to $mtime1"
1691 [ $ctime0 -le $ctime1 ] ||
1692 error "restore changed ctime from $ctime0 to $ctime1"
1696 # Once more, after unmount and mount.
1697 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1698 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1700 atime1=$(stat -c "%X" $file)
1701 mtime1=$(stat -c "%Y" $file)
1702 ctime1=$(stat -c "%Z" $file)
1704 [ $atime0 -eq $atime1 ] ||
1705 error "remount changed atime from $atime0 to $atime1"
1707 [ $mtime0 -eq $mtime1 ] ||
1708 error "remount changed mtime from $mtime0 to $mtime1"
1710 [ $ctime0 -le $ctime1 ] ||
1711 error "remount changed ctime from $ctime0 to $ctime1"
1713 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1716 local file=$DIR/$tdir/$tfile
1722 # Test needs a running copytool.
1726 # Check that root can do HSM actions on a ordinary user's file.
1728 fid=$(make_small $file)
1729 sum0=$(md5sum $file)
1731 chown $RUNAS_ID:$RUNAS_GID $file ||
1732 error "cannot chown '$file' to '$RUNAS_ID'"
1734 chmod ugo-w $DIR/$tdir ||
1735 error "cannot chmod '$DIR/$tdir'"
1737 $LFS hsm_archive $file
1738 wait_request_state $fid ARCHIVE SUCCEED
1740 $LFS hsm_release $file
1741 check_hsm_flags $file "0x0000000d"
1743 $LFS hsm_restore $file
1744 wait_request_state $fid RESTORE SUCCEED
1746 # Check that ordinary user can get HSM state.
1747 $RUNAS $LFS hsm_state $file ||
1748 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1750 $LFS hsm_release $file
1751 check_hsm_flags $file "0x0000000d"
1753 # Check that ordinary user can accessed released file.
1754 sum1=$($RUNAS md5sum $file) ||
1755 error "user '$RUNAS_ID' cannot read '$file'"
1757 [ "$sum0" == "$sum1" ] ||
1758 error "md5sum mismatch for '$file'"
1762 run_test 24b "root can archive, release, and restore user files"
1764 cleanup_test_24c() {
1766 set_hsm_param user_request_mask RESTORE
1767 set_hsm_param group_request_mask RESTORE
1768 set_hsm_param other_request_mask RESTORE
1772 local file=$DIR/$tdir/$tfile
1773 local action=archive
1778 # test needs a running copytool
1783 # Save the default masks and check that cleanup_24c will
1784 # restore the request masks correctly.
1785 user_save=$(get_hsm_param user_request_mask)
1786 group_save=$(get_hsm_param group_request_mask)
1787 other_save=$(get_hsm_param other_request_mask)
1789 [ "$user_save" == RESTORE ] ||
1790 error "user_request_mask is '$user_save' expected 'RESTORE'"
1791 [ "$group_save" == RESTORE ] ||
1792 error "group_request_mask is '$group_save' expected 'RESTORE'"
1793 [ "$other_save" == RESTORE ] ||
1794 error "other_request_mask is '$other_save' expected 'RESTORE'"
1796 trap cleanup_test_24c EXIT
1801 chown $RUNAS_ID:nobody $file ||
1802 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1804 set_hsm_param user_request_mask ""
1805 $RUNAS $LFS hsm_$action $file &&
1806 error "$action by user should fail"
1808 set_hsm_param user_request_mask $action
1809 $RUNAS $LFS hsm_$action $file ||
1810 error "$action by user should succeed"
1815 chown nobody:$RUNAS_GID $file ||
1816 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1818 set_hsm_param group_request_mask ""
1819 $RUNAS $LFS hsm_$action $file &&
1820 error "$action by group should fail"
1822 set_hsm_param group_request_mask $action
1823 $RUNAS $LFS hsm_$action $file ||
1824 error "$action by group should succeed"
1829 chown nobody:nobody $file ||
1830 error "cannot chown '$file' to 'nobody:nobody'"
1832 set_hsm_param other_request_mask ""
1833 $RUNAS $LFS hsm_$action $file &&
1834 error "$action by other should fail"
1836 set_hsm_param other_request_mask $action
1837 $RUNAS $LFS hsm_$action $file ||
1838 error "$action by other should succeed"
1843 run_test 24c "check that user,group,other request masks work"
1845 cleanup_test_24d() {
1847 mount -o remount,rw $MOUNT2
1851 local file1=$DIR/$tdir/$tfile
1852 local file2=$DIR2/$tdir/$tfile
1860 fid1=$(make_small $file1)
1862 trap cleanup_test_24d EXIT
1864 mount -o remount,ro $MOUNT2
1866 fid2=$(path2fid $file2)
1867 [ "$fid1" == "$fid2" ] ||
1868 error "FID mismatch '$fid1' != '$fid2'"
1870 $LFS hsm_archive $file2 &&
1871 error "archive should fail on read-only mount"
1872 check_hsm_flags $file1 "0x00000000"
1874 $LFS hsm_archive $file1
1875 wait_request_state $fid1 ARCHIVE SUCCEED
1877 $LFS hsm_release $file1
1878 $LFS hsm_restore $file2
1879 wait_request_state $fid1 RESTORE SUCCEED
1881 $LFS hsm_release $file1 || error "cannot release '$file1'"
1882 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1884 $LFS hsm_release $file2 &&
1885 error "release should fail on read-only mount"
1890 run_test 24d "check that read-only mounts are respected"
1893 # test needs a running copytool
1897 copy2archive /etc/hosts $tdir/$tfile
1899 local f=$DIR/$tdir/$tfile
1901 import_file $tdir/$tfile $f
1903 $LFS hsm_set --lost $f
1908 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1912 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1913 " (Operation not permitted)"
1916 # test needs a running copytool
1921 local f=$DIR/$tdir/$tfile
1922 local fid=$(copy_file /etc/passwd $f)
1924 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1925 wait_request_state $fid ARCHIVE SUCCEED
1928 $LFS hsm_set --lost $f
1932 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1936 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1937 " (Operation not permitted)"
1940 # test needs a running copytool
1944 local f=$DIR/$tdir/$tfile
1945 local fid=$(make_large_for_progress $f)
1946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1947 wait_request_state $fid ARCHIVE SUCCEED
1950 wait_request_state $fid REMOVE SUCCEED
1952 check_hsm_flags $f "0x00000000"
1956 run_test 26 "Remove the archive of a valid file"
1959 # test needs a running copytool
1963 make_archive $tdir/$tfile
1964 local f=$DIR/$tdir/$tfile
1965 import_file $tdir/$tfile $f
1966 local fid=$(path2fid $f)
1970 [[ $? != 0 ]] || error "Remove of a released file should fail"
1974 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1977 # test needs a running copytool
1981 local f=$DIR/$tdir/$tfile
1982 local fid=$(make_large_for_progress $f)
1983 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1984 wait_request_state $fid ARCHIVE SUCCEED
1989 [[ $? != 0 ]] || error "Remove of a released file should fail"
1993 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
1996 # test needs a running copytool
2000 local f=$DIR/$tdir/$tfile
2001 local fid=$(make_large_for_progress $f)
2002 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2003 wait_request_state $fid ARCHIVE SUCCEED
2012 wait_request_state $fid REMOVE SUCCEED
2016 run_test 28 "Concurrent archive/file remove"
2019 # restore at exec cannot work on agent node (because of Linux kernel
2020 # protection of executables)
2021 needclients 2 || return 0
2023 # test needs a running copytool
2027 copy2archive /bin/true $tdir/$tfile
2029 local f=$DIR/$tdir/true
2030 import_file $tdir/$tfile $f
2032 local fid=$(path2fid $f)
2034 # set no retry action mode
2040 # remove no try action mode
2044 [[ $st == 0 ]] || error "Failed to exec a released file"
2048 run_test 30a "Restore at exec (import case)"
2051 # restore at exec cannot work on agent node (because of Linux kernel
2052 # protection of executables)
2053 needclients 2 || return 0
2055 # test needs a running copytool
2059 local f=$DIR/$tdir/true
2060 local fid=$(copy_file /bin/true $f)
2062 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2063 wait_request_state $fid ARCHIVE SUCCEED
2066 # set no retry action mode
2072 # remove no try action mode
2076 [[ $st == 0 ]] || error "Failed to exec a released file"
2080 run_test 30b "Restore at exec (release case)"
2083 needclients 2 || return 0
2085 # test needs a running copytool
2089 local f=$DIR/$tdir/SLEEP
2090 local fid=$(copy_file /bin/sleep $f)
2092 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2093 wait_request_state $fid ARCHIVE SUCCEED
2095 check_hsm_flags $f "0x0000000d"
2096 # set no retry action mode
2098 do_node $CLIENT2 "$f 10" &
2102 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2104 [[ $? == 0 ]] || error "Execution failed during run"
2106 [[ $? == 0 ]] || error "Binary overwritten during exec"
2109 # remove no try action mode
2111 check_hsm_flags $f "0x00000009"
2115 run_test 30c "Update during exec of released file must fail"
2117 restore_and_check_size() {
2120 local s=$(stat -c "%s" $f)
2122 local st=$(get_hsm_flags $f)
2126 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2128 n=$(stat -c "%s" $f)
2129 # we echo in both cases to show stat is not
2131 if [[ $n != $s ]]; then
2132 echo "size seen is $n != $s"
2135 echo "size seen is right: $n == $s"
2137 st=$(get_hsm_flags $f)
2141 if [[ $cpt -lt 10 ]]; then
2144 echo " restore is too long"
2145 wait_request_state $fid RESTORE SUCCEED
2151 # test needs a running copytool
2156 make_archive $tdir/$tfile
2157 local f=$DIR/$tdir/$tfile
2158 import_file $tdir/$tfile $f
2159 local fid=$($LFS path2fid $f)
2160 HSM_ARCHIVE_PURGE=false copytool_setup
2162 restore_and_check_size $f $fid
2165 [[ $err -eq 0 ]] || error "File size changed during restore"
2169 run_test 31a "Import a large file and check size during restore"
2173 # test needs a running copytool
2178 local f=$DIR/$tdir/$tfile
2179 local fid=$(make_large_for_progress $f)
2180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2181 wait_request_state $fid ARCHIVE SUCCEED
2184 restore_and_check_size $f $fid
2187 [[ $err -eq 0 ]] || error "File size changed during restore"
2191 run_test 31b "Restore a large unaligned file and check size during restore"
2194 # test needs a running copytool
2199 local f=$DIR/$tdir/$tfile
2200 local fid=$(make_large_for_progress_aligned $f)
2201 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2202 wait_request_state $fid ARCHIVE SUCCEED
2205 restore_and_check_size $f $fid
2208 [[ $err -eq 0 ]] || error "File size changed during restore"
2212 run_test 31c "Restore a large aligned file and check size during restore"
2215 # test needs a running copytool
2220 local f=$DIR/$tdir/$tfile
2221 local fid=$(make_large_for_progress $f)
2222 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2223 wait_request_state $fid ARCHIVE SUCCEED
2226 md5sum $f >/dev/null &
2228 wait_request_state $fid RESTORE STARTED
2233 # Check restore trigger process was killed
2234 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2238 wait_request_state $fid RESTORE CANCELED
2239 wait_request_state $fid CANCEL SUCCEED
2242 error "Cannot kill process waiting for restore ($killed)"
2246 run_test 33 "Kill a restore waiting process"
2249 # test needs a running copytool
2254 local f=$DIR/$tdir/$tfile
2255 local fid=$(make_large_for_progress $f)
2256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2257 wait_request_state $fid ARCHIVE SUCCEED
2260 md5sum $f >/dev/null &
2262 wait_request_state $fid RESTORE STARTED
2264 rm $f || error "rm $f failed"
2265 # rm must not block during restore
2266 wait_request_state $fid RESTORE STARTED
2268 wait_request_state $fid RESTORE SUCCEED
2269 # check md5sum pgm finished
2270 local there=$(ps -o pid,comm hp $pid >/dev/null)
2271 [[ -z $there ]] || error "Restore initiator does not exit"
2273 local rc=$(wait $pid)
2274 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2278 run_test 34 "Remove file during restore"
2281 # test needs a running copytool
2286 local f=$DIR/$tdir/$tfile
2287 local f1=$DIR/$tdir/$tfile-1
2288 local fid=$(make_large_for_progress $f)
2289 local fid1=$(copy_file /etc/passwd $f1)
2290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2291 wait_request_state $fid ARCHIVE SUCCEED
2294 md5sum $f >/dev/null &
2296 wait_request_state $fid RESTORE STARTED
2298 mv $f1 $f || error "mv $f1 $f failed"
2299 # mv must not block during restore
2300 wait_request_state $fid RESTORE STARTED
2302 wait_request_state $fid RESTORE SUCCEED
2303 # check md5sum pgm finished
2304 local there=$(ps -o pid,comm hp $pid >/dev/null)
2305 [[ -z $there ]] || error "Restore initiator does not exit"
2307 local rc=$(wait $pid)
2308 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2311 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2315 run_test 35 "Overwrite file during restore"
2318 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2324 local fid=$(make_large_for_progress $f)
2325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2326 wait_request_state $fid ARCHIVE SUCCEED
2329 md5sum $f >/dev/null &
2331 wait_request_state $fid RESTORE STARTED
2334 # rm must not block during restore
2335 wait_request_state $fid RESTORE STARTED
2337 wait_request_state $fid RESTORE SUCCEED
2338 # check md5sum pgm finished
2339 local there=$(ps -o pid,comm hp $pid >/dev/null)
2341 error "Restore initiator does not exit"
2343 local rc=$(wait $pid)
2345 error "Restore initiator failed with $rc"
2349 run_test 36 "Move file during restore"
2356 for n in $(seq 1 $count); do
2357 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2359 echo "$count archive requests submitted"
2363 local stream_count=4
2364 local file_count=100
2366 local f=$DIR/$tdir/$tfile
2371 for i in $(seq 1 $file_count); do
2372 for p in $(seq 1 $stream_count); do
2373 fid=$(copy_file /etc/hosts $f.$p.$i)
2376 # force copytool to use a local/temp archive dir to ensure best
2377 # performance vs remote/NFS mounts used in auto-tests
2378 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2381 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2383 # to be sure wait_all_done will not be mislead by previous tests
2385 wait_for_grace_delay
2387 # start archive streams in background (archive files in parallel)
2388 for p in $(seq 1 $stream_count); do
2389 multi_archive $f.$p $file_count &
2392 echo -n "Wait for all requests being enqueued..."
2398 run_test 40 "Parallel archive requests"
2401 # test needs a running copytool
2405 local f=$DIR/$tdir/$tfile
2406 local fid=$(copy_file /etc/motd $f 1)
2408 $LFS hsm_archive $f || error "could not archive file"
2409 wait_request_state $fid ARCHIVE SUCCEED
2410 check_hsm_flags $f "0x00000009"
2412 multiop_bg_pause $f O_c || error "multiop failed"
2416 client_up || client_up || true
2418 kill -USR1 $MULTIPID
2419 wait $MULTIPID || error "multiop close failed"
2421 check_hsm_flags $f "0x0000000b"
2425 run_test 52 "Opened for write file on an evicted client should be set dirty"
2428 # test needs a running copytool
2432 local f=$DIR/$tdir/$tfile
2433 local fid=$(copy_file /etc/motd $f 1)
2435 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2436 error "could not archive file"
2437 wait_request_state $fid ARCHIVE SUCCEED
2438 check_hsm_flags $f "0x00000009"
2440 multiop_bg_pause $f o_c || error "multiop failed"
2444 client_up || client_up || true
2446 kill -USR1 $MULTIPID
2447 wait $MULTIPID || error "multiop close failed"
2449 check_hsm_flags $f "0x00000009"
2453 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2456 # test needs a running copytool
2460 local f=$DIR/$tdir/$tfile
2461 local fid=$(make_small $f)
2463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2464 error "could not archive file"
2465 wait_request_state $fid ARCHIVE STARTED
2467 check_hsm_flags $f "0x00000001"
2469 # Avoid coordinator resending this request as soon it has failed.
2474 wait_request_state $fid ARCHIVE FAILED
2476 check_hsm_flags $f "0x00000003"
2481 run_test 54 "Write during an archive cancels it"
2484 # test needs a running copytool
2488 local f=$DIR/$tdir/$tfile
2489 local fid=$(make_small $f)
2491 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2492 error "could not archive file"
2493 wait_request_state $fid ARCHIVE STARTED
2495 check_hsm_flags $f "0x00000001"
2497 # Avoid coordinator resending this request as soon it has failed.
2500 $TRUNCATE $f 1024 || error "truncate failed"
2502 wait_request_state $fid ARCHIVE FAILED
2504 check_hsm_flags $f "0x00000003"
2509 run_test 55 "Truncate during an archive cancels it"
2512 # test needs a running copytool
2516 local f=$DIR/$tdir/$tfile
2517 local fid=$(make_large_for_progress $f)
2519 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2520 error "could not archive file"
2521 wait_request_state $fid ARCHIVE STARTED
2523 check_hsm_flags $f "0x00000001"
2525 # Change metadata and sync to be sure we are not changing only
2530 wait_request_state $fid ARCHIVE SUCCEED
2532 check_hsm_flags $f "0x00000009"
2536 run_test 56 "Setattr during an archive is ok"
2539 # Need one client for I/O, one for request
2540 needclients 2 || return 0
2542 # test needs a running copytool
2546 local f=$DIR/$tdir/test_archive_remote
2547 # Create a file on a remote node
2548 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2549 "count=2 conv=fsync"
2552 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2553 error "hsm_archive failed"
2554 local fid=$(path2fid $f)
2555 wait_request_state $fid ARCHIVE SUCCEED
2557 # Release and implicit restore it
2558 do_node $CLIENT2 "$LFS hsm_release $f" ||
2559 error "hsm_release failed"
2560 do_node $CLIENT2 "md5sum $f" ||
2561 error "hsm_restore failed"
2563 wait_request_state $fid RESTORE SUCCEED
2567 run_test 57 "Archive a file with dirty cache on another node"
2569 truncate_released_file() {
2573 local sz=$(stat -c %s $src_file)
2574 local f=$DIR/$tdir/$tfile
2575 local fid=$(copy_file $1 $f)
2579 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2580 error "could not archive file"
2581 wait_request_state $fid ARCHIVE SUCCEED
2583 $LFS hsm_release $f || error "could not release file"
2585 $TRUNCATE $f $trunc_to || error "truncate failed"
2588 local sz1=$(stat -c %s $f)
2589 [[ $sz1 == $trunc_to ]] ||
2590 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2593 check_hsm_flags $f "0x0000000b"
2595 local state=$(get_request_state $fid RESTORE)
2596 [[ "$state" == "SUCCEED" ]] ||
2597 error "truncate $sz does not trig restore, state = $state"
2599 $TRUNCATE $ref $trunc_to
2600 cmp $ref $f || error "file data wrong after truncate"
2606 # test needs a running copytool
2611 local sz=$(stat -c %s /etc/passwd)
2613 echo "truncate up from $sz to $((sz*2))"
2614 truncate_released_file /etc/passwd $((sz*2))
2616 echo "truncate down from $sz to $((sz/2))"
2617 truncate_released_file /etc/passwd $((sz/2))
2619 echo "truncate to 0"
2620 truncate_released_file /etc/passwd 0
2624 run_test 58 "Truncate a released file will trigger restore"
2627 # This test validates the fix for LU-4512. Ensure that the -u
2628 # option changes the progress reporting interval from the default
2629 # (30 seconds) to the user-specified interval.
2631 local progress_timeout=$((interval * 3))
2633 # test needs a new running copytool
2635 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2638 local f=$DIR/$tdir/$tfile
2639 local fid=$(make_large_for_progress $f)
2641 local start_at=$(date +%s)
2642 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2643 error "could not archive file"
2646 local mdt=${MDT_PREFIX}${mdtidx}
2647 local mds=mds$((mdtidx + 1))
2649 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2650 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2656 echo -n "Expecting a progress update within $progress_timeout seconds... "
2658 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2659 if [ $RESULT -gt 0 ]; then
2660 echo "$RESULT bytes copied in $WAIT seconds."
2662 elif [ $WAIT -ge $progress_timeout ]; then
2663 error "Timed out waiting for progress update!"
2666 WAIT=$((WAIT + sleep))
2670 local finish_at=$(date +%s)
2671 local elapsed=$((finish_at - start_at))
2673 # Ensure that the progress update occurred within the expected window.
2674 if [ $elapsed -lt $interval ]; then
2675 error "Expected progress update after at least $interval seconds"
2681 run_test 60 "Changing progress update interval from default"
2684 # test needs a new running copytool
2686 copytool_monitor_setup
2687 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2689 # Just start and stop the copytool to generate events.
2693 local REGISTER_EVENT
2694 local UNREGISTER_EVENT
2695 while read event; do
2696 local parsed=$(parse_json_event "$event")
2697 if [ -z "$parsed" ]; then
2698 error "Copytool sent malformed event: $event"
2702 if [ $event_type == "REGISTER" ]; then
2703 REGISTER_EVENT=$event
2704 elif [ $event_type == "UNREGISTER" ]; then
2705 UNREGISTER_EVENT=$event
2707 done < <(echo $"$(get_copytool_event_log)")
2709 if [ -z "$REGISTER_EVENT" ]; then
2710 error "Copytool failed to send register event to FIFO"
2713 if [ -z "$UNREGISTER_EVENT" ]; then
2714 error "Copytool failed to send unregister event to FIFO"
2717 copytool_monitor_cleanup
2718 echo "Register/Unregister events look OK."
2720 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2723 # Bump progress interval for livelier events.
2726 # test needs a new running copytool
2728 copytool_monitor_setup
2729 HSMTOOL_UPDATE_INTERVAL=$interval \
2730 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2733 local f=$DIR/$tdir/$tfile
2734 local fid=$(make_large_for_progress $f)
2736 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2737 error "could not archive file"
2738 wait_request_state $fid ARCHIVE SUCCEED
2740 local expected_fields="event_time data_fid source_fid"
2741 expected_fields+=" total_bytes current_bytes"
2745 while read event; do
2746 # Make sure we're not getting anything from previous events.
2747 for field in $expected_fields; do
2751 local parsed=$(parse_json_event "$event")
2752 if [ -z "$parsed" ]; then
2753 error "Copytool sent malformed event: $event"
2757 if [ $event_type == "ARCHIVE_START" ]; then
2760 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2763 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2767 # Do some simple checking of the progress update events.
2768 for expected_field in $expected_fields; do
2769 if [ -z ${!expected_field+x} ]; then
2770 error "Missing $expected_field field in event"
2774 if [ $total_bytes -eq 0 ]; then
2775 error "Expected total_bytes to be > 0"
2778 # These should be identical throughout an archive
2780 if [ $source_fid != $data_fid ]; then
2781 error "Expected source_fid to equal data_fid"
2783 done < <(echo $"$(get_copytool_event_log)")
2785 if [ -z "$START_EVENT" ]; then
2786 error "Copytool failed to send archive start event to FIFO"
2789 if [ -z "$FINISH_EVENT" ]; then
2790 error "Copytool failed to send archive finish event to FIFO"
2793 echo "Archive events look OK."
2797 copytool_monitor_cleanup
2799 run_test 71 "Copytool logs JSON archive events to FIFO"
2802 # Bump progress interval for livelier events.
2805 # test needs a new running copytool
2807 copytool_monitor_setup
2808 HSMTOOL_UPDATE_INTERVAL=$interval \
2809 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2810 local test_file=$HSMTOOL_MONITOR_DIR/file
2812 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2814 do_facet $SINGLEAGT "$cmd" ||
2815 error "cannot create $test_file on $SINGLEAGT"
2816 copy2archive $test_file $tdir/$tfile
2819 local f=$DIR/$tdir/$tfile
2820 import_file $tdir/$tfile $f
2821 f=$DIR2/$tdir/$tfile
2822 echo "Verifying released state: "
2823 check_hsm_flags $f "0x0000000d"
2825 local fid=$(path2fid $f)
2827 wait_request_state $fid RESTORE SUCCEED
2829 local expected_fields="event_time data_fid source_fid"
2830 expected_fields+=" total_bytes current_bytes"
2834 while read event; do
2835 # Make sure we're not getting anything from previous events.
2836 for field in $expected_fields; do
2840 local parsed=$(parse_json_event "$event")
2841 if [ -z "$parsed" ]; then
2842 error "Copytool sent malformed event: $event"
2846 if [ $event_type == "RESTORE_START" ]; then
2848 if [ $source_fid != $data_fid ]; then
2849 error "source_fid should == data_fid at start"
2852 elif [ $event_type == "RESTORE_FINISH" ]; then
2854 if [ $source_fid != $data_fid ]; then
2855 error "source_fid should == data_fid at finish"
2858 elif [ $event_type != "RESTORE_RUNNING" ]; then
2862 # Do some simple checking of the progress update events.
2863 for expected_field in $expected_fields; do
2864 if [ -z ${!expected_field+x} ]; then
2865 error "Missing $expected_field field in event"
2869 if [ $total_bytes -eq 0 ]; then
2870 error "Expected total_bytes to be > 0"
2873 # When a restore starts out, the data fid is the same as the
2874 # source fid. After the restore has gotten going, we learn
2875 # the new data fid. Once the restore has finished, the source
2876 # fid is set to the new data fid.
2878 # We test this because some monitoring software may depend on
2879 # this behavior. If it changes, then the consumers of these
2880 # events may need to be modified.
2881 if [ $source_fid == $data_fid ]; then
2882 error "source_fid should != data_fid during restore"
2884 done < <(echo $"$(get_copytool_event_log)")
2886 if [ -z "$START_EVENT" ]; then
2887 error "Copytool failed to send restore start event to FIFO"
2890 if [ -z "$FINISH_EVENT" ]; then
2891 error "Copytool failed to send restore finish event to FIFO"
2894 echo "Restore events look OK."
2898 copytool_monitor_cleanup
2902 run_test 72 "Copytool logs JSON restore events to FIFO"
2905 file_count=51 # Max number of files constrained by LNET message size
2906 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2907 local f=$DIR/$tdir/$tfile
2908 local FILELIST=/tmp/filelist.txt
2912 for i in $(seq 1 $file_count); do
2913 fid=$(copy_file /etc/hosts $f.$i)
2914 echo $f.$i >> $FILELIST
2917 # to be sure wait_all_done will not be mislead by previous tests
2919 wait_for_grace_delay
2920 $LFS hsm_archive --filelist $FILELIST ||
2921 error "cannot archive a file list"
2923 $LFS hsm_release --filelist $FILELIST ||
2924 error "cannot release a file list"
2925 $LFS hsm_restore --filelist $FILELIST ||
2926 error "cannot restore a file list"
2930 run_test 90 "Archive/restore a file list"
2932 double_verify_reset_hsm_param() {
2934 echo "Testing $HSM_PARAM.$p"
2935 local val=$(get_hsm_param $p)
2937 local val2=$(($val * 2))
2938 set_hsm_param $p $val2
2939 val=$(get_hsm_param $p)
2940 [[ $val == $val2 ]] ||
2941 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2942 echo "Set $p to 0 must failed"
2946 set_hsm_param $p $save
2948 if [[ $rc == 0 ]]; then
2949 error "we must not be able to set $HSM_PARAM.$p to 0"
2954 double_verify_reset_hsm_param loop_period
2955 double_verify_reset_hsm_param grace_delay
2956 double_verify_reset_hsm_param active_request_timeout
2957 double_verify_reset_hsm_param max_requests
2958 double_verify_reset_hsm_param default_archive_id
2960 run_test 100 "Set coordinator /proc tunables"
2967 run_test 102 "Verify coordinator control"
2970 # test needs a running copytool
2977 for i in $(seq 1 20); do
2978 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2980 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2984 echo "Current requests"
2985 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2986 $HSM_PARAM.actions |\
2987 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2989 [[ -z "$res" ]] || error "Some request have not been canceled"
2993 run_test 103 "Purge all requests"
2998 # test needs a running copytool
3002 local f=$DIR/$tdir/$tfile
3003 local fid=$(make_large_for_progress $f)
3004 # if cdt is on, it can serve too quickly the request
3006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3007 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3008 $HSM_PARAM.actions |\
3009 grep $fid | cut -f16 -d=")
3012 [[ "$data1" == "$DATAHEX" ]] ||
3013 error "Data field in records is ($data1) and not ($DATAHEX)"
3017 run_test 104 "Copy tool data field"
3024 for i in $(seq -w 1 10); do
3025 cp /etc/passwd $DIR/$tdir/$i
3026 $LFS hsm_archive $DIR/$tdir/$i
3028 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3029 $HSM_PARAM.actions |\
3030 grep WAITING | wc -l")
3033 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3034 $HSM_PARAM.actions |\
3035 grep WAITING | wc -l")
3038 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3039 error "Requests count after shutdown $reqcnt2 != "\
3040 "before shutdown $reqcnt1"
3042 run_test 105 "Restart of coordinator"
3044 get_agent_by_uuid_mdt() {
3047 local mds=mds$(($mdtidx + 1))
3048 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3052 check_agent_registered_by_mdt() {
3055 local mds=mds$(($mdtidx + 1))
3056 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3057 if [[ ! -z "$agent" ]]; then
3058 echo "found agent $agent on $mds"
3060 error "uuid $uuid not found in agent list on $mds"
3064 check_agent_unregistered_by_mdt() {
3067 local mds=mds$(($mdtidx + 1))
3068 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3069 if [[ -z "$agent" ]]; then
3070 echo "uuid not found in agent list on $mds"
3072 error "uuid found in agent list on $mds: $agent"
3076 check_agent_registered() {
3079 for mdsno in $(seq 1 $MDSCOUNT); do
3080 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3084 check_agent_unregistered() {
3087 for mdsno in $(seq 1 $MDSCOUNT); do
3088 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3093 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3094 get_client_uuid $MOUNT | cut -d' ' -f2)
3097 check_agent_registered $uuid
3099 search_copytools || error "No copytool found"
3102 check_agent_unregistered $uuid
3105 check_agent_registered $uuid
3109 run_test 106 "Copytool register/unregister"
3112 # test needs a running copytool
3114 # create and archive file
3116 local f1=$DIR/$tdir/$tfile
3117 local fid=$(copy_file /etc/passwd $f1)
3118 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3119 wait_request_state $fid ARCHIVE SUCCEED
3120 # shutdown and restart MDS
3122 # check the copytool still gets messages from MDT
3123 local f2=$DIR/$tdir/2
3124 local fid=$(copy_file /etc/passwd $f2)
3125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3126 # main check of this sanity: this request MUST succeed
3127 wait_request_state $fid ARCHIVE SUCCEED
3130 run_test 107 "Copytool re-register after MDS restart"
3132 policy_set_and_test()
3136 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3137 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3138 [[ "$policy" == "$target" ]] ||
3139 error "Wrong policy after '$change': '$policy' != '$target'"
3143 # to force default policy setting if error
3144 CDT_POLICY_HAD_CHANGED=true
3146 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3147 local default="NonBlockingRestore [NoRetryAction]"
3148 [[ "$policy" == "$default" ]] ||
3149 error "default policy has changed,"\
3150 " '$policy' != '$default' update the test"
3151 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3152 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3153 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3154 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3155 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3156 # useless bacause we know but safer for futur changes to use real value
3157 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3158 echo "Next set_param must failed"
3159 policy_set_and_test "wrong" "$policy"
3162 echo "Back to default policy"
3163 cdt_set_sanity_policy
3165 run_test 109 "Policy display/change"
3168 # test needs a running copytool
3173 copy2archive /etc/passwd $tdir/$tfile
3175 local f=$DIR/$tdir/$tfile
3176 import_file $tdir/$tfile $f
3177 local fid=$(path2fid $f)
3179 cdt_set_non_blocking_restore
3184 wait_request_state $fid RESTORE SUCCEED
3185 cdt_clear_non_blocking_restore
3189 error "md5sum returns $st != 1, "\
3190 "should also perror ENODATA (No data available)"
3194 run_test 110a "Non blocking restore policy (import case)"
3197 # test needs a running copytool
3201 local f=$DIR/$tdir/$tfile
3202 local fid=$(copy_file /etc/passwd $f)
3203 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3204 wait_request_state $fid ARCHIVE SUCCEED
3207 cdt_set_non_blocking_restore
3212 wait_request_state $fid RESTORE SUCCEED
3213 cdt_clear_non_blocking_restore
3217 error "md5sum returns $st != 1, "\
3218 "should also perror ENODATA (No data available)"
3222 run_test 110b "Non blocking restore policy (release case)"
3225 # test needs a running copytool
3229 copy2archive /etc/passwd $tdir/$tfile
3231 local f=$DIR/$tdir/$tfile
3233 import_file $tdir/$tfile $f
3234 local fid=$(path2fid $f)
3238 copytool_remove_backend $fid
3241 wait_request_state $fid RESTORE FAILED
3248 [[ $st == 0 ]] || error "Restore does not failed"
3252 run_test 111a "No retry policy (import case), restore will error"\
3253 " (No such file or directory)"
3256 # test needs a running copytool
3260 local f=$DIR/$tdir/$tfile
3261 local fid=$(copy_file /etc/passwd $f)
3263 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3264 wait_request_state $fid ARCHIVE SUCCEED
3267 copytool_remove_backend $fid
3270 wait_request_state $fid RESTORE FAILED
3277 [[ $st == 0 ]] || error "Restore does not failed"
3281 run_test 111b "No retry policy (release case), restore will error"\
3282 " (No such file or directory)"
3285 # test needs a running copytool
3289 local f=$DIR/$tdir/$tfile
3290 local fid=$(copy_file /etc/passwd $f)
3292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3293 local l=$($LFS hsm_action $f)
3295 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3299 wait_request_state $fid ARCHIVE SUCCEED
3302 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3306 run_test 112 "State of recorded request"
3309 # test needs a running copytool
3313 local f=$DIR/$tdir/$tfile
3314 local fid=$(make_large_for_cancel $f)
3315 # test with cdt on is made in test_221
3317 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3320 wait_request_state $fid ARCHIVE CANCELED
3321 wait_request_state $fid CANCEL SUCCEED
3325 run_test 200 "Register/Cancel archive"
3328 # test needs a running copytool
3332 local f=$DIR/$tdir/$tfile
3333 make_archive $tdir/$tfile
3334 import_file $tdir/$tfile $f
3335 local fid=$(path2fid $f)
3337 # test with cdt on is made in test_222
3342 wait_request_state $fid RESTORE CANCELED
3343 wait_request_state $fid CANCEL SUCCEED
3347 run_test 201 "Register/Cancel restore"
3350 # test needs a running copytool
3354 local f=$DIR/$tdir/$tfile
3355 local fid=$(make_large_for_progress $f)
3356 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3357 wait_request_state $fid ARCHIVE SUCCEED
3363 wait_request_state $fid REMOVE CANCELED
3367 run_test 202 "Register/Cancel remove"
3370 # test needs a running copytool
3375 local f=$DIR/$tdir/$tfile
3376 local fid=$(copy_file /etc/passwd $f)
3380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3381 wait_request_state $fid ARCHIVE SUCCEED
3383 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3387 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3391 run_test 220 "Changelog for archive"
3394 # test needs a running copytool
3399 local f=$DIR/$tdir/$tfile
3400 local fid=$(make_large_for_cancel $f)
3404 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3405 wait_request_state $fid ARCHIVE STARTED
3407 wait_request_state $fid ARCHIVE CANCELED
3408 wait_request_state $fid CANCEL SUCCEED
3410 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3413 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3417 run_test 221 "Changelog for archive canceled"
3420 # test needs a running copytool
3424 copy2archive /etc/passwd $tdir/$tfile
3426 local f=$DIR/$tdir/$tfile
3427 import_file $tdir/$tfile $f
3428 local fid=$(path2fid $f)
3433 wait_request_state $fid RESTORE SUCCEED
3435 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3438 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3442 run_test 222a "Changelog for explicit restore"
3445 # test needs a running copytool
3449 local f=$DIR/$tdir/$tfile
3450 local fid=$(copy_file /etc/passwd $f)
3453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3454 wait_request_state $fid ARCHIVE SUCCEED
3459 wait_request_state $fid RESTORE SUCCEED
3461 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3464 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3468 run_test 222b "Changelog for implicit restore"
3471 # test needs a running copytool
3476 local f=$DIR/$tdir/$tfile
3477 make_archive $tdir/$tfile
3481 import_file $tdir/$tfile $f
3482 local fid=$(path2fid $f)
3485 wait_request_state $fid RESTORE STARTED
3487 wait_request_state $fid RESTORE CANCELED
3488 wait_request_state $fid CANCEL SUCCEED
3490 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3493 [[ $flags == $target ]] ||
3494 error "Changelog flag is $flags not $target"
3498 run_test 223a "Changelog for restore canceled (import case)"
3501 # test needs a running copytool
3506 local f=$DIR/$tdir/$tfile
3507 local fid=$(make_large_for_progress $f)
3510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3511 wait_request_state $fid ARCHIVE SUCCEED
3514 wait_request_state $fid RESTORE STARTED
3516 wait_request_state $fid RESTORE CANCELED
3517 wait_request_state $fid CANCEL SUCCEED
3519 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3522 [[ $flags == $target ]] ||
3523 error "Changelog flag is $flags not $target"
3527 run_test 223b "Changelog for restore canceled (release case)"
3530 # test needs a running copytool
3535 local f=$DIR/$tdir/$tfile
3536 local fid=$(copy_file /etc/passwd $f)
3539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3540 wait_request_state $fid ARCHIVE SUCCEED
3543 wait_request_state $fid REMOVE SUCCEED
3545 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3548 [[ $flags == $target ]] ||
3549 error "Changelog flag is $flags not $target"
3553 run_test 224 "Changelog for remove"
3556 # test needs a running copytool
3559 # test is not usable because remove request is too fast
3560 # so it is always finished before cancel can be done ...
3561 echo "Test disabled"
3566 local f=$DIR/$tdir/$tfile
3567 local fid=$(make_large_for_progress $f)
3570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3571 wait_request_state $fid ARCHIVE SUCCEED
3573 # if cdt is on, it can serve too quickly the request
3578 wait_request_state $fid REMOVE CANCELED
3579 wait_request_state $fid CANCEL SUCCEED
3581 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3582 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3583 tail -n 1 | awk '{print $5}')
3586 [[ $flags == $target ]] ||
3587 error "Changelog flag is $flags not $target"
3591 run_test 225 "Changelog for remove canceled"
3594 # test needs a running copytool
3599 local f1=$DIR/$tdir/$tfile-1
3600 local f2=$DIR/$tdir/$tfile-2
3601 local f3=$DIR/$tdir/$tfile-3
3602 local fid1=$(copy_file /etc/passwd $f1)
3603 local fid2=$(copy_file /etc/passwd $f2)
3604 copy_file /etc/passwd $f3
3607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3608 wait_request_state $fid1 ARCHIVE SUCCEED
3610 $LFS hsm_archive $f2
3611 wait_request_state $fid2 ARCHIVE SUCCEED
3613 rm $f1 || error "rm $f1 failed"
3615 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3618 [[ $flags == $target ]] ||
3619 error "Changelog flag is $flags not $target"
3621 mv $f3 $f2 || error "mv $f3 $f2 failed"
3623 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3626 [[ $flags == $target ]] ||
3627 error "Changelog flag is $flags not $target"
3631 run_test 226 "changelog for last rm/mv with exiting archive"
3633 check_flags_changes() {
3641 $LFS hsm_set --$hsm_flag $f ||
3642 error "Cannot set $hsm_flag on $f"
3643 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3644 local seen=${#flags[*]}
3646 [[ $seen == $cnt ]] ||
3647 error "set $hsm_flag: Changelog events $seen != $cnt"
3648 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3649 error "set $hsm_flag: Changelog flags are "\
3650 "${flags[$((cnt - 1))]} not $target"
3652 $LFS hsm_clear --$hsm_flag $f ||
3653 error "Cannot clear $hsm_flag on $f"
3654 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3657 [[ $cnt == $seen ]] ||
3658 error "clear $hsm_flag: Changelog events $seen != $cnt"
3660 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3661 error "clear $hsm_flag: Changelog flag is "\
3662 "${flags[$((cnt - 1))]} not $target"
3666 # test needs a running copytool
3673 for i in norelease noarchive exists archived
3675 local f=$DIR/$tdir/$tfile-$i
3676 local fid=$(copy_file /etc/passwd $f)
3677 check_flags_changes $f $fid $i 0 1
3680 f=$DIR/$tdir/$tfile---lost
3681 fid=$(copy_file /etc/passwd $f)
3682 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3683 wait_request_state $fid ARCHIVE SUCCEED
3684 check_flags_changes $f $fid lost 3 1
3688 run_test 227 "changelog when explicit setting of HSM flags"
3691 # test needs a running copytool
3694 local fid=$(make_small_sync $DIR/$tfile)
3695 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3696 wait_request_state $fid ARCHIVE SUCCEED
3698 $LFS hsm_release $DIR/$tfile
3699 check_hsm_flags $DIR/$tfile "0x0000000d"
3701 filefrag $DIR/$tfile | grep " 1 extent found" ||
3702 error "filefrag on released file must return only one extent"
3704 # only newer versions of cp detect sparse files by stat/FIEMAP
3706 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3707 error "copying $DIR/$tfile"
3708 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3710 $LFS hsm_release $DIR/$tfile
3711 check_hsm_flags $DIR/$tfile "0x0000000d"
3713 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3715 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3717 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3718 error "comparing untarred $DIR/$tfile"
3720 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3721 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3724 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3727 # test needs a running copytool
3731 local maxrequest=$(get_hsm_param max_requests)
3732 local rqcnt=$(($maxrequest * 3))
3736 for i in $(seq -w 1 $rqcnt); do
3738 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3740 # we do it in 2 steps, so all requests arrive at the same time
3741 for i in $(seq -w 1 $rqcnt); do
3742 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3747 while [[ $cnt != 0 || $wt != 0 ]]; do
3749 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3750 $HSM_PARAM.actions |\
3751 grep STARTED | grep -v CANCEL | wc -l")
3752 [[ $cnt -le $maxrequest ]] ||
3753 error "$cnt > $maxrequest too many started requests"
3754 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3755 $HSM_PARAM.actions |\
3756 grep WAITING | wc -l")
3757 echo "max=$maxrequest started=$cnt waiting=$wt"
3762 run_test 250 "Coordinator max request"
3765 # test needs a running copytool
3769 local f=$DIR/$tdir/$tfile
3770 local fid=$(make_large_for_cancel $f)
3773 # to have a short test
3774 local old_to=$(get_hsm_param active_request_timeout)
3775 set_hsm_param active_request_timeout 4
3776 # to be sure the cdt will wake up frequently so
3777 # it will be able to cancel the "old" request
3778 local old_loop=$(get_hsm_param loop_period)
3779 set_hsm_param loop_period 2
3782 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3783 wait_request_state $fid ARCHIVE STARTED
3785 wait_request_state $fid ARCHIVE CANCELED
3787 set_hsm_param active_request_timeout $old_to
3788 set_hsm_param loop_period $old_loop
3792 run_test 251 "Coordinator request timeout"
3795 # the only way to test ondisk conf is to restart MDS ...
3796 echo "Stop coordinator and remove coordinator state at mount"
3799 # clean on disk conf set by default
3800 cdt_clear_mount_state
3801 cdt_check_state stopped
3803 # check cdt still off after umount/remount
3805 cdt_check_state stopped
3807 echo "Set coordinator start at mount, and start coordinator"
3808 cdt_set_mount_state enabled
3811 cdt_check_state enabled
3813 # check cdt still on after umount/remount
3815 cdt_check_state enabled
3817 # we are back to original state (cdt started at mount)
3819 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3822 local ai=$(get_hsm_param default_archive_id)
3823 local new=$((ai + 1))
3825 set_hsm_param default_archive_id $new -P
3827 local res=$(get_hsm_param default_archive_id)
3830 set_hsm_param default_archive_id "" "-P -d"
3832 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3834 run_test 301 "HSM tunnable are persistent"
3837 local ai=$(get_hsm_param default_archive_id)
3838 local new=$((ai + 1))
3843 set_hsm_param default_archive_id $new -P
3846 for mdtno in $(seq 1 $MDSCOUNT); do
3851 cdt_check_state enabled
3853 local res=$(get_hsm_param default_archive_id)
3856 set_hsm_param default_archive_id "" "-P -d"
3858 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3860 run_test 302 "HSM tunnable are persistent when CDT is off"
3863 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3869 local dir_mdt0=$DIR/$tdir/mdt0
3870 local dir_mdt1=$DIR/$tdir/mdt1
3872 # create 1 dir per MDT
3873 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3874 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3876 # create 1 file in each MDT
3877 local fid1=$(make_small $dir_mdt0/$tfile)
3878 local fid2=$(make_small $dir_mdt1/$tfile)
3880 # check that hsm request on mdt0 is sent to the right MDS
3881 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3882 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3883 echo "archive successful on mdt0"
3885 # check that hsm request on mdt1 is sent to the right MDS
3886 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3887 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3888 echo "archive successful on mdt1"
3891 # clean test files and directories
3892 rm -rf $dir_mdt0 $dir_mdt1
3894 run_test 400 "Single request is sent to the right MDT"
3897 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3903 local dir_mdt0=$DIR/$tdir/mdt0
3904 local dir_mdt1=$DIR/$tdir/mdt1
3906 # create 1 dir per MDT
3907 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3908 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3910 # create 1 file in each MDT
3911 local fid1=$(make_small $dir_mdt0/$tfile)
3912 local fid2=$(make_small $dir_mdt1/$tfile)
3914 # check that compound requests are shunt to the rights MDTs
3915 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3916 error "lfs hsm_archive"
3917 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3918 echo "archive successful on mdt0"
3919 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3920 echo "archive successful on mdt1"
3923 # clean test files and directories
3924 rm -rf $dir_mdt0 $dir_mdt1
3926 run_test 401 "Compound requests split and sent to their respective MDTs"
3928 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3933 local node=$(facet_active_host $facet)
3935 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3936 awk '{print $4}'); do
3937 echo "$3 $mdc on $node"
3938 do_facet $facet "$LCTL --device $mdc $state" || return 1
3943 # make sure there is no running copytool
3946 # deactivate all mdc on agent1
3947 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3949 copytool_setup $SINGLEAGT
3951 check_agent_unregistered "uuid" # match any agent
3953 # no expected running copytool
3954 search_copytools $agent && error "Copytool start should have failed"
3957 mdc_change_state $SINGLEAGT "MDT000." "activate"
3959 run_test 402 "Copytool start fails if all MDTs are inactive"
3962 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3964 # make sure there is no running copytool
3967 local agent=$(facet_active_host $SINGLEAGT)
3968 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3970 # deactivate all mdc for MDT0001
3971 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3974 # check the agent is registered on MDT0000, and not on MDT0001
3975 check_agent_registered_by_mdt $uuid 0
3976 check_agent_unregistered_by_mdt $uuid 1
3978 # check running copytool process
3979 search_copytools $agent || error "No running copytools on $agent"
3981 # reactivate all mdc for MDT0001
3982 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3984 # make sure the copytool is now registered to all MDTs
3985 check_agent_registered $uuid
3989 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3992 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3996 # create files on both MDT0000 and MDT0001
3999 local dir_mdt0=$DIR/$tdir/mdt0
4000 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4002 # create 1 file on mdt0
4003 local fid1=$(make_small $dir_mdt0/$tfile)
4005 # deactivate all mdc for MDT0001
4006 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4008 # send an HSM request for files in MDT0000
4009 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4011 # check for completion of files in MDT0000
4012 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4013 echo "archive successful on mdt0"
4015 # reactivate all mdc for MDT0001
4016 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4019 # clean test files and directories
4022 run_test 404 "Inactive MDT does not block requests for active MDTs"
4027 check_and_cleanup_lustre