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 -1)
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 # This is required for pdsh -Rmrsh and its handling of remote shells.
163 # Regular ssh and pdsh -Rssh work fine without this backgrounded
165 (do_node $agent "$cmd") &
166 export HSMTOOL_MONITOR_PDSH=$!
168 # Slightly racy, but just making a best-effort to catch obvious
169 # problems. If we get rid of the ridiculous backgrounded subshell,
170 # this check will need to be updated to just look at the returncode
173 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
174 error "Failed to start copytool monitor on $agent"
177 copytool_monitor_cleanup() {
178 local facet=${1:-$SINGLEAGT}
179 local agent=$(facet_active_host $facet)
181 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
182 # Should die when the copytool dies, but just in case.
183 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
184 cmd+=" 2>/dev/null || true"
185 do_node $agent "$cmd"
186 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
187 export HSMTOOL_MONITOR_DIR=
190 # The pdsh should die on its own when the monitor dies. Just
191 # in case, though, try to clean up to avoid any cruft.
192 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
193 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
194 export HSMTOOL_MONITOR_PDSH=
199 local facet=${1:-$SINGLEAGT}
200 local lustre_mntpnt=${2:-$MOUNT}
202 local hsm_root=${4:-$(copytool_device $facet)}
203 local agent=$(facet_active_host $facet)
205 if [[ -z "$arc_id" ]] &&
206 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
207 echo "Wakeup copytool $facet on $agent"
211 if $HSM_ARCHIVE_PURGE; then
212 echo "Purging archive on $agent"
213 do_facet $facet "rm -rf $hsm_root/*"
216 echo "Starting copytool $facet on $agent"
217 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
218 # bandwidth is limited to 1MB/s so the copy time is known and
219 # independent of hardware
220 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
221 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
222 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
223 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
224 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
225 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
226 cmd+=" --bandwidth 1 $lustre_mntpnt"
228 # Redirect the standard output and error to a log file which
229 # can be uploaded to Maloo.
230 local prefix=$TESTLOG_PREFIX
231 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
232 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
234 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1" ||
235 error "start copytool $facet on $agent failed"
239 get_copytool_event_log() {
240 local facet=${1:-$SINGLEAGT}
241 local agent=$(facet_active_host $facet)
243 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
244 error "Can't get event log: No monitor directory!"
246 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
247 error "Could not collect event log from $agent"
252 local agents=${1:-$(facet_active_host $SINGLEAGT)}
258 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
260 echo "Copytool is stopped on $agents"
262 # clean all CDTs orphans requests from previous tests
263 # that would otherwise need to timeout to clear.
264 for mdtno in $(seq 1 $MDSCOUNT); do
266 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
267 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
269 # skip already stop[ed,ing] CDTs
270 echo $oldstate | grep stop && continue
272 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
273 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
275 error "mds${mdtno} cdt state is not stopped"
276 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
277 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
279 error "mds${mdtno} cdt state is not $oldstate"
284 local agents=${1:-$(facet_active_host $SINGLEAGT)}
286 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
287 echo "Copytool is suspended on $agents"
290 copytool_remove_backend() {
292 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
293 echo "Remove from backend: $fid = $be"
294 do_facet $SINGLEAGT rm -f $be
298 do_facet $SINGLEAGT \
299 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
300 --import $1 $2 $MOUNT" ||
301 error "import of $1 to $2 failed"
305 local file=$HSM_ARCHIVE/$1
306 do_facet $SINGLEAGT mkdir -p $(dirname $file)
307 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
308 error "cannot create $file"
312 local file=$HSM_ARCHIVE/$2
313 do_facet $SINGLEAGT mkdir -p $(dirname $file)
314 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
323 if [[ "$value" != "" ]]; then
326 for mdtno in $(seq 1 $MDSCOUNT); do
327 local idx=$(($mdtno - 1))
328 local facet=mds${mdtno}
329 # if $arg include -P option, run 1 set_param per MDT on the MGS
330 # else, run set_param on each MDT
331 [[ $arg = *"-P"* ]] && facet=mgs
332 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
333 [[ $? != 0 ]] && rc=1
343 for mdtno in $(seq 1 $MDSCOUNT); do
344 local idx=$(($mdtno - 1))
345 wait_result mds${mdtno} \
346 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
348 error "$key state is not '$target' on mds${mdtno}"
355 for mdtno in $(seq 1 $MDSCOUNT); do
356 local idx=$(($mdtno - 1))
357 local cl_user=$(do_facet mds${mdtno} $LCTL \
358 --device ${MDT[$idx]} \
359 changelog_register -n)
361 do_facet mds${mdtno} lctl set_param \
362 mdd.${MDT[$idx]}.changelog_mask="+hsm"
363 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
367 changelog_cleanup() {
369 for mdtno in $(seq 1 $MDSCOUNT); do
370 local idx=$(($mdtno - 1))
371 [[ -z ${CL_USERS[$idx]} ]] && continue
372 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
373 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
374 changelog_deregister ${CL_USERS[$idx]}
379 changelog_get_flags() {
384 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
389 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
397 mdts_set_param "$opt -n" "hsm.$param" "$value"
404 mdts_set_param "" hsm_control "$cmd"
405 mdts_check_param hsm_control "$target" 10
408 cdt_set_sanity_policy() {
409 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
412 mdts_set_param "" hsm.policy "+NRA"
413 mdts_set_param "" hsm.policy "-NBR"
414 CDT_POLICY_HAD_CHANGED=
419 mdts_set_param "" hsm.policy "+NRA"
420 CDT_POLICY_HAD_CHANGED=true
423 cdt_clear_no_retry() {
424 mdts_set_param "" hsm.policy "-NRA"
425 CDT_POLICY_HAD_CHANGED=true
428 cdt_set_non_blocking_restore() {
429 mdts_set_param "" hsm.policy "+NBR"
430 CDT_POLICY_HAD_CHANGED=true
433 cdt_clear_non_blocking_restore() {
434 mdts_set_param "" hsm.policy "-NBR"
435 CDT_POLICY_HAD_CHANGED=true
438 cdt_clear_mount_state() {
439 mdts_set_param "-P -d" hsm_control ""
442 cdt_set_mount_state() {
443 mdts_set_param "-P" hsm_control "$1"
447 mdts_check_param hsm_control "$1" 20
451 set_test_state disabled disabled
455 set_test_state enabled enabled
459 set_test_state shutdown stopped
463 set_test_state purge enabled
469 cdt_set_sanity_policy
473 local client_count=$1
474 if [[ $CLIENTCOUNT -lt $client_count ]]; then
475 skip "Need $client_count or more clients, have $CLIENTCOUNT"
482 $LFS path2fid $1 | tr -d '[]'
489 if [[ $u == "user" ]]; then
490 local st=$($RUNAS $LFS hsm_state $f)
492 local st=$($LFS hsm_state $f)
496 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
498 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
502 get_hsm_archive_id() {
504 local st=$($LFS hsm_state $f)
505 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
507 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
516 local st=$(get_hsm_flags $f)
517 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
520 check_hsm_flags_user() {
524 local st=$(get_hsm_flags $f user)
525 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
537 if [[ "$3" != 1 ]]; then
541 cp $1 $f || error "cannot copy $1 to $f"
542 path2fid $f || error "cannot get fid on $f"
546 local file2=${1/$DIR/$DIR2}
547 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
548 error "cannot create $file2"
549 path2fid $1 || error "cannot get fid on $1"
553 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
554 error "cannot create $1"
555 path2fid $1 || error "cannot get fid on $1"
558 cleanup_large_files() {
559 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
561 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
564 make_large_for_striping() {
565 local file2=${1/$DIR/$DIR2}
566 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -1)
570 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
571 error "cannot create $file2"
572 path2fid $1 || error "cannot get fid on $1"
575 make_large_for_progress() {
576 local file2=${1/$DIR/$DIR2}
580 # big file is large enough, so copy time is > 30s
581 # so copytool make 1 progress
582 # size is not a multiple of 1M to avoid stripe
584 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
585 error "cannot create $file2"
586 path2fid $1 || error "cannot get fid on $1"
589 make_large_for_progress_aligned() {
590 local file2=${1/$DIR/$DIR2}
594 # big file is large enough, so copy time is > 30s
595 # so copytool make 1 progress
596 # size is a multiple of 1M to have stripe
598 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
599 error "cannot create $file2"
600 path2fid $1 || error "cannot get fid on $1"
603 make_large_for_cancel() {
604 local file2=${1/$DIR/$DIR2}
608 # Copy timeout is 100s. 105MB => 105s
609 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
610 error "cannot create $file2"
611 path2fid $1 || error "cannot get fid on $1"
617 wait_update --verbose $(facet_active_host $facet) "$@"
620 wait_request_state() {
624 # 4th arg (mdt index) is optional
626 local mds=mds$(($mdtidx + 1))
628 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
629 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
631 wait_result $mds "$cmd" $state 100 ||
632 error "request on $fid is not $state on $mds"
635 get_request_state() {
639 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
640 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
643 get_request_count() {
647 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
648 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
654 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
655 cmd+=" | egrep 'WAITING|STARTED'"
657 wait_result $SINGLEMDS "$cmd" "" $timeout ||
658 error "requests did not complete"
661 wait_for_grace_delay() {
662 local val=$(get_hsm_param grace_delay)
669 # python2.6 in EL6 includes an internal json module
670 local json_parser='import json; import fileinput;'
671 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
672 json_parser+='json.loads([line for line in '
673 json_parser+='fileinput.input()][0]).items()])'
675 echo $raw_event | python -c "$json_parser"
678 # populate MDT device array
684 # cleanup from previous bad setup
685 search_and_kill_copytool
687 # for recovery tests, coordinator needs to be started at mount
689 # the lustre conf must be without hsm on (like for sanity.sh)
690 echo "Set HSM on and start"
691 cdt_set_mount_state enabled
692 cdt_check_state enabled
694 echo "Start copytool"
697 echo "Set sanity-hsm HSM policy"
698 cdt_set_sanity_policy
700 # finished requests are quickly removed from list
701 set_hsm_param grace_delay 10
707 local f=$DIR/$tdir/$tfile
711 check_hsm_flags_user $f "0x00000000"
713 $RUNAS $LFS hsm_set --norelease $f ||
714 error "user could not change hsm flags"
715 check_hsm_flags_user $f "0x00000010"
717 $RUNAS $LFS hsm_clear --norelease $f ||
718 error "user could not clear hsm flags"
719 check_hsm_flags_user $f "0x00000000"
721 # User could not change those flags...
722 $RUNAS $LFS hsm_set --exists $f &&
723 error "user should not set this flag"
724 check_hsm_flags_user $f "0x00000000"
727 $LFS hsm_set --exists $f ||
728 error "root could not change hsm flags"
729 check_hsm_flags_user $f "0x00000001"
731 $LFS hsm_clear --exists $f ||
732 error "root could not clear hsm state"
733 check_hsm_flags_user $f "0x00000000"
736 run_test 1 "lfs hsm flags root/non-root access"
740 local f=$DIR/$tdir/$tfile
742 # New files are not dirty
743 check_hsm_flags $f "0x00000000"
745 # For test, we simulate an archived file.
746 $LFS hsm_set --exists $f || error "user could not change hsm flags"
747 check_hsm_flags $f "0x00000001"
749 # chmod do not put the file dirty
750 chmod 600 $f || error "could not chmod test file"
751 check_hsm_flags $f "0x00000001"
753 # chown do not put the file dirty
754 chown $RUNAS_ID $f || error "could not chown test file"
755 check_hsm_flags $f "0x00000001"
757 # truncate put the file dirty
758 $TRUNCATE $f 1 || error "could not truncate test file"
759 check_hsm_flags $f "0x00000003"
761 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
762 check_hsm_flags $f "0x00000001"
764 run_test 2 "Check file dirtyness when doing setattr"
770 # New files are not dirty
772 check_hsm_flags $f "0x00000000"
774 # For test, we simulate an archived file.
775 $LFS hsm_set --exists $f ||
776 error "user could not change hsm flags"
777 check_hsm_flags $f "0x00000001"
779 # Reading a file, does not set dirty
780 cat $f > /dev/null || error "could not read file"
781 check_hsm_flags $f "0x00000001"
783 # Open for write without modifying data, does not set dirty
784 openfile -f O_WRONLY $f || error "could not open test file"
785 check_hsm_flags $f "0x00000001"
787 # Append to a file sets it dirty
788 cp -p /etc/passwd $f.append || error "could not create file"
789 $LFS hsm_set --exists $f.append ||
790 error "user could not change hsm flags"
791 dd if=/etc/passwd of=$f.append bs=1 count=3\
792 conv=notrunc oflag=append status=noxfer ||
793 error "could not append to test file"
794 check_hsm_flags $f.append "0x00000003"
796 # Modify a file sets it dirty
797 cp -p /etc/passwd $f.modify || error "could not create file"
798 $LFS hsm_set --exists $f.modify ||
799 error "user could not change hsm flags"
800 dd if=/dev/zero of=$f.modify bs=1 count=3\
801 conv=notrunc status=noxfer ||
802 error "could not modify test file"
803 check_hsm_flags $f.modify "0x00000003"
805 # Open O_TRUNC sets dirty
806 cp -p /etc/passwd $f.trunc || error "could not create file"
807 $LFS hsm_set --exists $f.trunc ||
808 error "user could not change hsm flags"
809 cp /etc/group $f.trunc || error "could not override a file"
810 check_hsm_flags $f.trunc "0x00000003"
812 # Mmapped a file sets dirty
813 cp -p /etc/passwd $f.mmap || error "could not create file"
814 $LFS hsm_set --exists $f.mmap ||
815 error "user could not change hsm flags"
816 multiop $f.mmap OSMWUc || error "could not mmap a file"
817 check_hsm_flags $f.mmap "0x00000003"
819 run_test 3 "Check file dirtyness when opening for write"
823 local f=$DIR/$tdir/$tfile
824 local fid=$(make_small $f)
827 local st=$(get_request_state $fid CANCEL)
828 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
830 run_test 4 "Useless cancel must not be registered"
833 # test needs a running copytool
837 local f=$DIR/$tdir/$tfile
838 local fid=$(copy_file /etc/passwd $f)
840 wait_request_state $fid ARCHIVE SUCCEED
842 check_hsm_flags $f "0x00000009"
846 run_test 8 "Test default archive number"
850 local f=$DIR/$tdir/$tfile
851 local fid=$(copy_file /etc/passwd $f)
852 # we do not use the default one to be sure
853 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
855 copytool_setup $SINGLEAGT $MOUNT $new_an
856 $LFS hsm_archive --archive $new_an $f
857 wait_request_state $fid ARCHIVE SUCCEED
859 check_hsm_flags $f "0x00000009"
863 run_test 9 "Use of explict archive number, with dedicated copytool"
866 needclients 3 || return 0
872 copytool_cleanup $(comma_list $(agts_nodes))
874 # start all of the copytools
875 for n in $(seq $AGTCOUNT); do
879 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
882 for n in $(seq $AGTCOUNT); do
883 file=$DIR/$tdir/$tfile.$n
884 fid=$(make_small $file)
886 $LFS hsm_archive $file || error "could not archive file $file"
887 wait_request_state $fid ARCHIVE SUCCEED
888 check_hsm_flags $file "0x00000009"
892 copytool_cleanup $(comma_list $(agts_nodes))
894 run_test 9a "Multiple remote agents"
897 # test needs a running copytool
900 mkdir -p $DIR/$tdir/d1
901 local f=$DIR/$tdir/$tfile
902 local fid=$(copy_file /etc/hosts $f)
903 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
904 error "hsm_archive failed"
905 wait_request_state $fid ARCHIVE SUCCEED
907 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
908 error "fid $fid not in archive $HSM_ARCHIVE"
909 echo "Verifying content"
910 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
911 echo "Verifying hsm state "
912 check_hsm_flags $f "0x00000009"
914 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
915 local st=$(get_hsm_archive_id $f)
916 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
917 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
922 run_test 10a "Archive a file"
925 # test needs a running copytool
929 local f=$DIR/$tdir/$tfile
930 local fid=$(copy_file /etc/hosts $f)
931 $LFS hsm_archive $f || error "archive request failed"
932 wait_request_state $fid ARCHIVE SUCCEED
934 $LFS hsm_archive $f || error "archive of non dirty file failed"
935 local cnt=$(get_request_count $fid ARCHIVE)
936 [[ "$cnt" == "1" ]] ||
937 error "archive of non dirty file must not make a request"
941 run_test 10b "Archive of non dirty file must work without doing request"
944 # test needs a running copytool
948 local f=$DIR/$tdir/$tfile
949 local fid=$(copy_file /etc/hosts $f)
950 $LFS hsm_set --noarchive $f
951 $LFS hsm_archive $f && error "archive a noarchive file must fail"
955 run_test 10c "Check forbidden archive"
958 # test needs a running copytool
962 local f=$DIR/$tdir/$tfile
963 local fid=$(copy_file /etc/hosts $f)
964 $LFS hsm_archive $f || error "cannot archive $f"
965 wait_request_state $fid ARCHIVE SUCCEED
967 local ar=$(get_hsm_archive_id $f)
968 local dflt=$(get_hsm_param default_archive_id)
969 [[ $ar == $dflt ]] ||
970 error "archived file is not on default archive: $ar != $dflt"
974 run_test 10d "Archive a file on the default archive id"
978 copy2archive /etc/hosts $tdir/$tfile
979 local f=$DIR/$tdir/$tfile
981 import_file $tdir/$tfile $f
982 echo -n "Verifying released state: "
983 check_hsm_flags $f "0x0000000d"
985 local LSZ=$(stat -c "%s" $f)
986 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
988 echo "Verifying imported size $LSZ=$ASZ"
989 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
990 echo -n "Verifying released pattern: "
991 local PTRN=$($GETSTRIPE -L $f)
993 [[ $PTRN == 80000001 ]] || error "Is not released"
994 local fid=$(path2fid $f)
995 echo "Verifying new fid $fid in archive"
997 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
998 error "fid $fid not in archive $HSM_ARCHIVE"
1000 run_test 11 "Import a file"
1003 # test needs a running copytool
1007 copy2archive /etc/hosts $tdir/$tfile
1009 local f=$DIR/$tdir/$tfile
1010 import_file $tdir/$tfile $f
1011 local f=$DIR2/$tdir/$tfile
1012 echo "Verifying released state: "
1013 check_hsm_flags $f "0x0000000d"
1015 local fid=$(path2fid $f)
1017 wait_request_state $fid RESTORE SUCCEED
1019 echo "Verifying file state: "
1020 check_hsm_flags $f "0x00000009"
1022 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1024 [[ $? -eq 0 ]] || error "Restored file differs"
1028 run_test 12a "Restore an imported file explicitly"
1031 # test needs a running copytool
1035 copy2archive /etc/hosts $tdir/$tfile
1037 local f=$DIR/$tdir/$tfile
1038 import_file $tdir/$tfile $f
1039 echo "Verifying released state: "
1040 check_hsm_flags $f "0x0000000d"
1042 cat $f > /dev/null || error "File read failed"
1044 echo "Verifying file state after restore: "
1045 check_hsm_flags $f "0x00000009"
1047 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1049 [[ $? -eq 0 ]] || error "Restored file differs"
1053 run_test 12b "Restore an imported file implicitly"
1056 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1058 # test needs a running copytool
1062 local f=$DIR/$tdir/$tfile
1063 $LFS setstripe -c 2 $f
1064 local fid=$(make_large_for_striping $f)
1065 local FILE_CRC=$(md5sum $f)
1067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1068 wait_request_state $fid ARCHIVE SUCCEED
1069 $LFS hsm_release $f || error "release $f failed"
1071 echo "$FILE_CRC" | md5sum -c
1073 [[ $? -eq 0 ]] || error "Restored file differs"
1077 run_test 12c "Restore a file with stripe of 2"
1080 # test needs a running copytool
1085 local f=$DIR/$tdir/$tfile
1086 local fid=$(copy_file /etc/hosts $f)
1087 $LFS hsm_restore $f || error "restore of non archived file failed"
1088 local cnt=$(get_request_count $fid RESTORE)
1089 [[ "$cnt" == "0" ]] ||
1090 error "restore non archived must not make a request"
1091 $LFS hsm_archive $f ||
1092 error "archive request failed"
1093 wait_request_state $fid ARCHIVE SUCCEED
1094 $LFS hsm_restore $f ||
1095 error "restore of non released file failed"
1096 local cnt=$(get_request_count $fid RESTORE)
1097 [[ "$cnt" == "0" ]] ||
1098 error "restore a non dirty file must not make a request"
1102 run_test 12d "Restore of a non archived, non released file must work"\
1103 " without doing request"
1106 # test needs a running copytool
1109 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1110 local f=$DIR/$tdir/$tfile
1111 local fid=$(copy_file /etc/hosts $f)
1112 $LFS hsm_archive $f || error "archive request failed"
1113 wait_request_state $fid ARCHIVE SUCCEED
1116 cat /etc/hosts >> $f
1120 $LFS hsm_restore $f && error "restore a dirty file must fail"
1124 run_test 12e "Check forbidden restore"
1127 # test needs a running copytool
1131 local f=$DIR/$tdir/$tfile
1132 local fid=$(copy_file /etc/hosts $f)
1134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1135 wait_request_state $fid ARCHIVE SUCCEED
1136 $LFS hsm_release $f || error "release of $f failed"
1138 wait_request_state $fid RESTORE SUCCEED
1140 echo -n "Verifying file state: "
1141 check_hsm_flags $f "0x00000009"
1143 diff -q /etc/hosts $f
1145 [[ $? -eq 0 ]] || error "Restored file differs"
1149 run_test 12f "Restore a released file explicitly"
1152 # test needs a running copytool
1156 local f=$DIR/$tdir/$tfile
1157 local fid=$(copy_file /etc/hosts $f)
1159 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1160 wait_request_state $fid ARCHIVE SUCCEED
1161 $LFS hsm_release $f || error "release of $f failed"
1163 diff -q /etc/hosts $f
1166 # we check we had a restore done
1167 wait_request_state $fid RESTORE SUCCEED
1169 [[ $st -eq 0 ]] || error "Restored file differs"
1173 run_test 12g "Restore a released file implicitly"
1176 needclients 2 || return 0
1178 # test needs a running copytool
1182 local f=$DIR/$tdir/$tfile
1183 local fid=$(copy_file /etc/hosts $f)
1185 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1186 wait_request_state $fid ARCHIVE SUCCEED
1187 $LFS hsm_release $f || error "release of $f failed"
1189 do_node $CLIENT2 diff -q /etc/hosts $f
1192 # we check we had a restore done
1193 wait_request_state $fid RESTORE SUCCEED
1195 [[ $st -eq 0 ]] || error "Restored file differs"
1199 run_test 12h "Restore a released file implicitly from a second node"
1202 # test needs a running copytool
1206 local f=$DIR/$tdir/$tfile
1207 local fid=$(copy_file /etc/passwd $f)
1208 $LFS hsm_archive $f || error "archive of $f failed"
1209 wait_request_state $fid ARCHIVE SUCCEED
1211 $LFS hsm_release $f || error "release of $f failed"
1215 [[ $? -eq 0 ]] || error "Restored file differs"
1219 run_test 12m "Archive/release/implicit restore"
1222 # test needs a running copytool
1226 copy2archive /etc/hosts $tdir/$tfile
1228 local f=$DIR/$tdir/$tfile
1229 import_file $tdir/$tfile $f
1231 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1232 error "Restored file differs"
1234 $LFS hsm_release $f || error "release of $f failed"
1238 run_test 12n "Import/implicit restore/release"
1241 # test needs a running copytool
1245 local f=$DIR/$tdir/$tfile
1246 local fid=$(copy_file /etc/hosts $f)
1248 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1249 wait_request_state $fid ARCHIVE SUCCEED
1250 $LFS hsm_release $f || error "release of $f failed"
1252 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1253 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1255 # set no retry action mode
1258 diff -q /etc/hosts $f
1261 # we check we had a restore failure
1262 wait_request_state $fid RESTORE FAILED
1264 [[ $st -eq 0 ]] && error "Restore must fail"
1266 # remove no retry action mode
1269 # check file is still released
1270 check_hsm_flags $f "0x0000000d"
1272 # retry w/o failure injection
1273 do_facet $SINGLEMDS lctl set_param fail_loc=0
1275 # to be sure previous RESTORE result is gone
1277 wait_for_grace_delay
1279 diff -q /etc/hosts $f
1282 # we check we had a restore done
1283 wait_request_state $fid RESTORE SUCCEED
1285 [[ $st -eq 0 ]] || error "Restored file differs"
1289 run_test 12o "Layout-swap failure during Restore leaves file released"
1292 # test needs a running copytool
1295 local ARC_SUBDIR="import.orig"
1299 # populate directory to be imported
1300 for d in $(seq 1 10); do
1301 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1302 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1303 for f in $(seq 1 10); do
1304 CURR_FILE="$CURR_DIR/$tfile.$f"
1305 # write file-specific data
1306 do_facet $SINGLEAGT \
1307 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1308 "file=$CURR_FILE > $CURR_FILE"
1312 import_file "$ARC_SUBDIR" $DIR/$tdir
1313 # diff lustre content and origin (triggers file restoration)
1314 # there must be 10x10 identical files, and no difference
1315 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1316 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1317 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1318 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1320 [ $cnt_diff -eq 0 ] ||
1321 error "$cnt_diff imported files differ from read data"
1322 [ $cnt_ok -eq 100 ] ||
1323 error "not enough identical files ($cnt_ok != 100)"
1327 run_test 13 "Recursively import and restore a directory"
1330 # test needs a running copytool
1335 local f=$DIR/$tdir/$tfile
1336 local fid=$(make_small $f)
1337 local sum=$(md5sum $f | awk '{print $1}')
1338 $LFS hsm_archive $f || error "could not archive file"
1339 wait_request_state $fid ARCHIVE SUCCEED
1343 # create released file (simulate llapi_hsm_import call)
1345 local fid2=$(path2fid $f)
1346 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1347 $LFS hsm_release $f || error "could not release file"
1349 # rebind the archive to the newly created file
1350 echo "rebind $fid to $fid2"
1352 do_facet $SINGLEAGT \
1353 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1354 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1356 # restore file and compare md5sum
1357 local sum2=$(md5sum $f | awk '{print $1}')
1359 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1363 run_test 14 "Rebind archived file to a new fid"
1366 # test needs a running copytool
1371 local f=$DIR/$tdir/$tfile
1373 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1377 for i in $(seq 1 $count); do
1378 fids[$i]=$(make_small $f.$i)
1379 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1380 $LFS hsm_archive $f.$i || error "could not archive file"
1382 wait_all_done $(($count*60))
1386 for i in $(seq 1 $count); do
1389 local fid2=$(path2fid $f.$i)
1390 # add the rebind operation to the list
1391 echo ${fids[$i]} $fid2 >> $tmpfile
1393 # set it released (simulate llapi_hsm_import call)
1394 $LFS hsm_set --archived --exists $f.$i ||
1395 error "could not force hsm flags"
1396 $LFS hsm_release $f.$i || error "could not release file"
1398 nl=$(wc -l < $tmpfile)
1399 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1401 echo "rebind list of files"
1402 do_facet $SINGLEAGT \
1403 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1404 --rebind $tmpfile $DIR" || error "could not rebind file list"
1406 # restore files and compare md5sum
1407 for i in $(seq 1 $count); do
1408 local sum2=$(md5sum $f.$i | awk '{print $1}')
1409 [[ $sum2 == ${sums[$i]} ]] ||
1410 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1416 run_test 15 "Rebind a list of files"
1419 # test needs a running copytool
1423 # create a known size file so we can verify transfer speed
1426 dd if=/dev/zero of=$ref bs=1M count=20
1429 local f=$DIR/$tdir/$tfile
1430 local fid=$(copy_file $ref $f)
1432 local start=$(date +%s)
1434 wait_request_state $fid ARCHIVE SUCCEED
1435 local end=$(date +%s)
1436 local duration=$((end - start))
1438 [[ $duration -ge $goal ]] ||
1439 error "Transfer is too fast $duration < $goal"
1443 run_test 16 "Test CT bandwith control option"
1448 local f=$DIR/$tdir/$tfile
1449 touch $f || error "touch $f failed"
1451 # Could not release a non-archived file
1452 $LFS hsm_release $f && error "release should not succeed"
1454 # For following tests, we must test them with HS_ARCHIVED set
1455 $LFS hsm_set --exists --archived $f || error "could not add flag"
1457 # Could not release a file if no-release is set
1458 $LFS hsm_set --norelease $f || error "could not add flag"
1459 $LFS hsm_release $f && error "release should not succeed"
1460 $LFS hsm_clear --norelease $f || error "could not remove flag"
1462 # Could not release a file if lost
1463 $LFS hsm_set --lost $f || error "could not add flag"
1464 $LFS hsm_release $f && error "release should not succeed"
1465 $LFS hsm_clear --lost $f || error "could not remove flag"
1467 # Could not release a file if dirty
1468 $LFS hsm_set --dirty $f || error "could not add flag"
1469 $LFS hsm_release $f && error "release should not succeed"
1470 $LFS hsm_clear --dirty $f || error "could not remove flag"
1472 run_test 20 "Release is not permitted"
1475 # test needs a running copytool
1479 local f=$DIR/$tdir/test_release
1481 # Create a file and check its states
1482 local fid=$(make_small $f)
1483 check_hsm_flags $f "0x00000000"
1485 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1486 # used until file is flushed to disk
1487 if [ $(facet_fstype ost1) == "zfs" ]; then
1488 # this causes an OST_SYNC rpc to be sent
1489 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1490 # clear locks to reread file data
1491 cancel_lru_locks osc
1494 local orig_size=$(stat -c "%s" $f)
1495 local orig_blocks=$(stat -c "%b" $f)
1497 start_full_debug_logging
1499 $LFS hsm_archive $f || error "could not archive file"
1500 wait_request_state $fid ARCHIVE SUCCEED
1502 local blocks=$(stat -c "%b" $f)
1503 [ $blocks -eq $orig_blocks ] ||
1504 error "$f: wrong block number after archive: " \
1505 "$blocks != $orig_blocks"
1506 local size=$(stat -c "%s" $f)
1507 [ $size -eq $orig_size ] ||
1508 error "$f: wrong size after archive: $size != $orig_size"
1510 # Release and check states
1511 $LFS hsm_release $f || error "could not release file"
1512 check_hsm_flags $f "0x0000000d"
1514 blocks=$(stat -c "%b" $f)
1515 [ $blocks -gt 5 ] &&
1516 error "$f: too many blocks after release: $blocks > 5"
1517 size=$(stat -c "%s" $f)
1518 [ $size -ne $orig_size ] &&
1519 error "$f: wrong size after release: $size != $orig_size"
1521 # Check we can release an file without stripe info
1525 check_hsm_flags $f "0x00000000"
1526 $LFS hsm_archive $f || error "could not archive file"
1527 wait_request_state $fid ARCHIVE SUCCEED
1529 # Release and check states
1530 $LFS hsm_release $f || error "could not release file"
1531 check_hsm_flags $f "0x0000000d"
1533 # Release again a file that is already released is OK
1534 $LFS hsm_release $f || fail "second release should succeed"
1535 check_hsm_flags $f "0x0000000d"
1537 stop_full_debug_logging
1541 run_test 21 "Simple release tests"
1544 # test needs a running copytool
1549 local f=$DIR/$tdir/test_release
1550 local swap=$DIR/$tdir/test_swap
1552 # Create a file and check its states
1553 local fid=$(make_small $f)
1554 check_hsm_flags $f "0x00000000"
1556 $LFS hsm_archive $f || error "could not archive file"
1557 wait_request_state $fid ARCHIVE SUCCEED
1559 # Release and check states
1560 $LFS hsm_release $f || error "could not release file"
1561 check_hsm_flags $f "0x0000000d"
1564 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1569 run_test 22 "Could not swap a release file"
1572 # test needs a running copytool
1577 local f=$DIR/$tdir/test_mtime
1579 # Create a file and check its states
1580 local fid=$(make_small $f)
1581 check_hsm_flags $f "0x00000000"
1583 $LFS hsm_archive $f || error "could not archive file"
1584 wait_request_state $fid ARCHIVE SUCCEED
1586 # Set modification time in the past
1587 touch -m -a -d @978261179 $f
1589 # Release and check states
1590 $LFS hsm_release $f || error "could not release file"
1591 check_hsm_flags $f "0x0000000d"
1593 local MTIME=$(stat -c "%Y" $f)
1594 local ATIME=$(stat -c "%X" $f)
1595 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1596 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1600 run_test 23 "Release does not change a/mtime (utime)"
1603 local file=$DIR/$tdir/$tfile
1612 # test needs a running copytool
1617 fid=$(make_small $file)
1619 # Create a file and check its states
1620 check_hsm_flags $file "0x00000000"
1622 # Ensure atime is less than mtime and ctime.
1626 atime0=$(stat -c "%X" $file)
1627 mtime0=$(stat -c "%Y" $file)
1628 ctime0=$(stat -c "%Z" $file)
1630 [ $atime0 -lt $mtime0 ] ||
1631 error "atime $atime0 is not less than mtime $mtime0"
1633 [ $atime0 -lt $ctime0 ] ||
1634 error "atime $atime0 is not less than ctime $ctime0"
1636 # Archive should not change any timestamps.
1637 $LFS hsm_archive $file || error "cannot archive '$file'"
1638 wait_request_state $fid ARCHIVE SUCCEED
1640 atime1=$(stat -c "%X" $file)
1641 mtime1=$(stat -c "%Y" $file)
1642 ctime1=$(stat -c "%Z" $file)
1644 [ $atime0 -eq $atime1 ] ||
1645 error "archive changed atime from $atime0 to $atime1"
1647 [ $mtime0 -eq $mtime1 ] ||
1648 error "archive changed mtime from $mtime0 to $mtime1"
1650 [ $ctime0 -eq $ctime1 ] ||
1651 error "archive changed ctime from $ctime0 to $ctime1"
1653 # Release should not change any timestamps.
1654 $LFS hsm_release $file || error "cannot release '$file'"
1655 check_hsm_flags $file "0x0000000d"
1657 atime1=$(stat -c "%X" $file)
1658 mtime1=$(stat -c "%Y" $file)
1659 ctime1=$(stat -c "%Z" $file)
1661 [ $atime0 -eq $atime1 ] ||
1662 error "release changed atime from $atime0 to $atime1"
1664 [ $mtime0 -eq $mtime1 ] ||
1665 error "release changed mtime from $mtime0 to $mtime1"
1667 [ $ctime0 -eq $ctime1 ] ||
1668 error "release changed ctime from $ctime0 to $ctime1"
1670 # Restore should not change atime or mtime and should not
1672 $LFS hsm_restore $file
1673 wait_request_state $fid RESTORE SUCCEED
1675 atime1=$(stat -c "%X" $file)
1676 mtime1=$(stat -c "%Y" $file)
1677 ctime1=$(stat -c "%Z" $file)
1679 [ $atime0 -eq $atime1 ] ||
1680 error "restore changed atime from $atime0 to $atime1"
1682 [ $mtime0 -eq $mtime1 ] ||
1683 error "restore changed mtime from $mtime0 to $mtime1"
1685 [ $ctime0 -le $ctime1 ] ||
1686 error "restore changed ctime from $ctime0 to $ctime1"
1690 # Once more, after unmount and mount.
1691 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1692 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1694 atime1=$(stat -c "%X" $file)
1695 mtime1=$(stat -c "%Y" $file)
1696 ctime1=$(stat -c "%Z" $file)
1698 [ $atime0 -eq $atime1 ] ||
1699 error "remount changed atime from $atime0 to $atime1"
1701 [ $mtime0 -eq $mtime1 ] ||
1702 error "remount changed mtime from $mtime0 to $mtime1"
1704 [ $ctime0 -le $ctime1 ] ||
1705 error "remount changed ctime from $ctime0 to $ctime1"
1707 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1710 local file=$DIR/$tdir/$tfile
1716 # Test needs a running copytool.
1720 # Check that root can do HSM actions on a ordinary user's file.
1722 fid=$(make_small $file)
1723 sum0=$(md5sum $file)
1725 chown $RUNAS_ID:$RUNAS_GID $file ||
1726 error "cannot chown '$file' to '$RUNAS_ID'"
1728 chmod ugo-w $DIR/$tdir ||
1729 error "cannot chmod '$DIR/$tdir'"
1731 $LFS hsm_archive $file
1732 wait_request_state $fid ARCHIVE SUCCEED
1734 $LFS hsm_release $file
1735 check_hsm_flags $file "0x0000000d"
1737 $LFS hsm_restore $file
1738 wait_request_state $fid RESTORE SUCCEED
1740 # Check that ordinary user can get HSM state.
1741 $RUNAS $LFS hsm_state $file ||
1742 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1744 $LFS hsm_release $file
1745 check_hsm_flags $file "0x0000000d"
1747 # Check that ordinary user can accessed released file.
1748 sum1=$($RUNAS md5sum $file) ||
1749 error "user '$RUNAS_ID' cannot read '$file'"
1751 [ "$sum0" == "$sum1" ] ||
1752 error "md5sum mismatch for '$file'"
1756 run_test 24b "root can archive, release, and restore user files"
1758 cleanup_test_24c() {
1760 set_hsm_param user_request_mask RESTORE
1761 set_hsm_param group_request_mask RESTORE
1762 set_hsm_param other_request_mask RESTORE
1766 local file=$DIR/$tdir/$tfile
1767 local action=archive
1772 # test needs a running copytool
1777 # Save the default masks and check that cleanup_24c will
1778 # restore the request masks correctly.
1779 user_save=$(get_hsm_param user_request_mask)
1780 group_save=$(get_hsm_param group_request_mask)
1781 other_save=$(get_hsm_param other_request_mask)
1783 [ "$user_save" == RESTORE ] ||
1784 error "user_request_mask is '$user_save' expected 'RESTORE'"
1785 [ "$group_save" == RESTORE ] ||
1786 error "group_request_mask is '$group_save' expected 'RESTORE'"
1787 [ "$other_save" == RESTORE ] ||
1788 error "other_request_mask is '$other_save' expected 'RESTORE'"
1790 trap cleanup_test_24c EXIT
1795 chown $RUNAS_ID:nobody $file ||
1796 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1798 set_hsm_param user_request_mask ""
1799 $RUNAS $LFS hsm_$action $file &&
1800 error "$action by user should fail"
1802 set_hsm_param user_request_mask $action
1803 $RUNAS $LFS hsm_$action $file ||
1804 error "$action by user should succeed"
1809 chown nobody:$RUNAS_GID $file ||
1810 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1812 set_hsm_param group_request_mask ""
1813 $RUNAS $LFS hsm_$action $file &&
1814 error "$action by group should fail"
1816 set_hsm_param group_request_mask $action
1817 $RUNAS $LFS hsm_$action $file ||
1818 error "$action by group should succeed"
1823 chown nobody:nobody $file ||
1824 error "cannot chown '$file' to 'nobody:nobody'"
1826 set_hsm_param other_request_mask ""
1827 $RUNAS $LFS hsm_$action $file &&
1828 error "$action by other should fail"
1830 set_hsm_param other_request_mask $action
1831 $RUNAS $LFS hsm_$action $file ||
1832 error "$action by other should succeed"
1837 run_test 24c "check that user,group,other request masks work"
1839 cleanup_test_24d() {
1841 mount -o remount,rw $MOUNT2
1845 local file1=$DIR/$tdir/$tfile
1846 local file2=$DIR2/$tdir/$tfile
1854 fid1=$(make_small $file1)
1856 trap cleanup_test_24d EXIT
1858 mount -o remount,ro $MOUNT2
1860 fid2=$(path2fid $file2)
1861 [ "$fid1" == "$fid2" ] ||
1862 error "FID mismatch '$fid1' != '$fid2'"
1864 $LFS hsm_archive $file2 &&
1865 error "archive should fail on read-only mount"
1866 check_hsm_flags $file1 "0x00000000"
1868 $LFS hsm_archive $file1
1869 wait_request_state $fid1 ARCHIVE SUCCEED
1871 $LFS hsm_release $file1
1872 $LFS hsm_restore $file2
1873 wait_request_state $fid1 RESTORE SUCCEED
1875 $LFS hsm_release $file1 || error "cannot release '$file1'"
1876 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1878 $LFS hsm_release $file2 &&
1879 error "release should fail on read-only mount"
1884 run_test 24d "check that read-only mounts are respected"
1887 # test needs a running copytool
1891 copy2archive /etc/hosts $tdir/$tfile
1893 local f=$DIR/$tdir/$tfile
1895 import_file $tdir/$tfile $f
1897 $LFS hsm_set --lost $f
1902 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1906 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1907 " (Operation not permitted)"
1910 # test needs a running copytool
1915 local f=$DIR/$tdir/$tfile
1916 local fid=$(copy_file /etc/passwd $f)
1918 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1919 wait_request_state $fid ARCHIVE SUCCEED
1922 $LFS hsm_set --lost $f
1926 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1930 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1931 " (Operation not permitted)"
1934 # test needs a running copytool
1938 local f=$DIR/$tdir/$tfile
1939 local fid=$(make_large_for_progress $f)
1940 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1941 wait_request_state $fid ARCHIVE SUCCEED
1944 wait_request_state $fid REMOVE SUCCEED
1946 check_hsm_flags $f "0x00000000"
1950 run_test 26 "Remove the archive of a valid file"
1953 # test needs a running copytool
1957 make_archive $tdir/$tfile
1958 local f=$DIR/$tdir/$tfile
1959 import_file $tdir/$tfile $f
1960 local fid=$(path2fid $f)
1964 [[ $? != 0 ]] || error "Remove of a released file should fail"
1968 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1971 # test needs a running copytool
1975 local f=$DIR/$tdir/$tfile
1976 local fid=$(make_large_for_progress $f)
1977 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1978 wait_request_state $fid ARCHIVE SUCCEED
1983 [[ $? != 0 ]] || error "Remove of a released file should fail"
1987 run_test 27b "Remove the archive of a relased 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
2006 wait_request_state $fid REMOVE SUCCEED
2010 run_test 28 "Concurrent archive/file remove"
2013 # restore at exec cannot work on agent node (because of Linux kernel
2014 # protection of executables)
2015 needclients 2 || return 0
2017 # test needs a running copytool
2021 copy2archive /bin/true $tdir/$tfile
2023 local f=$DIR/$tdir/true
2024 import_file $tdir/$tfile $f
2026 local fid=$(path2fid $f)
2028 # set no retry action mode
2034 # remove no try action mode
2038 [[ $st == 0 ]] || error "Failed to exec a released file"
2042 run_test 30a "Restore at exec (import case)"
2045 # restore at exec cannot work on agent node (because of Linux kernel
2046 # protection of executables)
2047 needclients 2 || return 0
2049 # test needs a running copytool
2053 local f=$DIR/$tdir/true
2054 local fid=$(copy_file /bin/true $f)
2056 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2057 wait_request_state $fid ARCHIVE SUCCEED
2060 # set no retry action mode
2066 # remove no try action mode
2070 [[ $st == 0 ]] || error "Failed to exec a released file"
2074 run_test 30b "Restore at exec (release case)"
2077 needclients 2 || return 0
2079 # test needs a running copytool
2083 local f=$DIR/$tdir/SLEEP
2084 local fid=$(copy_file /bin/sleep $f)
2086 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2087 wait_request_state $fid ARCHIVE SUCCEED
2089 check_hsm_flags $f "0x0000000d"
2090 # set no retry action mode
2092 do_node $CLIENT2 "$f 10" &
2096 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2098 [[ $? == 0 ]] || error "Execution failed during run"
2100 [[ $? == 0 ]] || error "Binary overwritten during exec"
2103 # remove no try action mode
2105 check_hsm_flags $f "0x00000009"
2109 run_test 30c "Update during exec of released file must fail"
2111 restore_and_check_size() {
2114 local s=$(stat -c "%s" $f)
2116 local st=$(get_hsm_flags $f)
2120 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2122 n=$(stat -c "%s" $f)
2123 # we echo in both cases to show stat is not
2125 if [[ $n != $s ]]; then
2126 echo "size seen is $n != $s"
2129 echo "size seen is right: $n == $s"
2131 st=$(get_hsm_flags $f)
2135 if [[ $cpt -lt 10 ]]; then
2138 echo " restore is too long"
2139 wait_request_state $fid RESTORE SUCCEED
2145 # test needs a running copytool
2150 make_archive $tdir/$tfile
2151 local f=$DIR/$tdir/$tfile
2152 import_file $tdir/$tfile $f
2153 local fid=$($LFS path2fid $f)
2154 HSM_ARCHIVE_PURGE=false copytool_setup
2156 restore_and_check_size $f $fid
2159 [[ $err -eq 0 ]] || error "File size changed during restore"
2163 run_test 31a "Import a large file and check size during restore"
2167 # test needs a running copytool
2172 local f=$DIR/$tdir/$tfile
2173 local fid=$(make_large_for_progress $f)
2174 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2175 wait_request_state $fid ARCHIVE SUCCEED
2178 restore_and_check_size $f $fid
2181 [[ $err -eq 0 ]] || error "File size changed during restore"
2185 run_test 31b "Restore a large unaligned file and check size during restore"
2188 # test needs a running copytool
2193 local f=$DIR/$tdir/$tfile
2194 local fid=$(make_large_for_progress_aligned $f)
2195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2196 wait_request_state $fid ARCHIVE SUCCEED
2199 restore_and_check_size $f $fid
2202 [[ $err -eq 0 ]] || error "File size changed during restore"
2206 run_test 31c "Restore a large aligned file and check size during restore"
2209 # test needs a running copytool
2214 local f=$DIR/$tdir/$tfile
2215 local fid=$(make_large_for_progress $f)
2216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2217 wait_request_state $fid ARCHIVE SUCCEED
2220 md5sum $f >/dev/null &
2222 wait_request_state $fid RESTORE STARTED
2227 # Check restore trigger process was killed
2228 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2232 wait_request_state $fid RESTORE CANCELED
2233 wait_request_state $fid CANCEL SUCCEED
2236 error "Cannot kill process waiting for restore ($killed)"
2240 run_test 33 "Kill a restore waiting process"
2243 # test needs a running copytool
2248 local f=$DIR/$tdir/$tfile
2249 local fid=$(make_large_for_progress $f)
2250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2251 wait_request_state $fid ARCHIVE SUCCEED
2254 md5sum $f >/dev/null &
2256 wait_request_state $fid RESTORE STARTED
2258 rm $f || error "rm $f failed"
2259 # rm must not block during restore
2260 wait_request_state $fid RESTORE STARTED
2262 wait_request_state $fid RESTORE SUCCEED
2263 # check md5sum pgm finished
2264 local there=$(ps -o pid,comm hp $pid >/dev/null)
2265 [[ -z $there ]] || error "Restore initiator does not exit"
2267 local rc=$(wait $pid)
2268 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2272 run_test 34 "Remove file during restore"
2275 # test needs a running copytool
2280 local f=$DIR/$tdir/$tfile
2281 local f1=$DIR/$tdir/$tfile-1
2282 local fid=$(make_large_for_progress $f)
2283 local fid1=$(copy_file /etc/passwd $f1)
2284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2285 wait_request_state $fid ARCHIVE SUCCEED
2288 md5sum $f >/dev/null &
2290 wait_request_state $fid RESTORE STARTED
2292 mv $f1 $f || error "mv $f1 $f failed"
2293 # mv must not block during restore
2294 wait_request_state $fid RESTORE STARTED
2296 wait_request_state $fid RESTORE SUCCEED
2297 # check md5sum pgm finished
2298 local there=$(ps -o pid,comm hp $pid >/dev/null)
2299 [[ -z $there ]] || error "Restore initiator does not exit"
2301 local rc=$(wait $pid)
2302 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2305 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2309 run_test 35 "Overwrite file during restore"
2312 # test needs a running copytool
2317 local f=$DIR/$tdir/$tfile
2318 local fid=$(make_large_for_progress $f)
2319 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2320 wait_request_state $fid ARCHIVE SUCCEED
2323 md5sum $f >/dev/null &
2325 wait_request_state $fid RESTORE STARTED
2328 # rm must not block during restore
2329 wait_request_state $fid RESTORE STARTED
2331 wait_request_state $fid RESTORE SUCCEED
2332 # check md5sum pgm finished
2333 local there=$(ps -o pid,comm hp $pid >/dev/null)
2335 error "Restore initiator does not exit"
2337 local rc=$(wait $pid)
2339 error "Restore initiator failed with $rc"
2343 run_test 36 "Move file during restore"
2350 for n in $(seq 1 $count); do
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2353 echo "$count archive requests submitted"
2357 local stream_count=4
2358 local file_count=100
2360 local f=$DIR/$tdir/$tfile
2365 for i in $(seq 1 $file_count); do
2366 for p in $(seq 1 $stream_count); do
2367 fid=$(copy_file /etc/hosts $f.$p.$i)
2370 # force copytool to use a local/temp archive dir to ensure best
2371 # performance vs remote/NFS mounts used in auto-tests
2372 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2375 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2377 # to be sure wait_all_done will not be mislead by previous tests
2379 wait_for_grace_delay
2381 # start archive streams in background (archive files in parallel)
2382 for p in $(seq 1 $stream_count); do
2383 multi_archive $f.$p $file_count &
2386 echo -n "Wait for all requests being enqueued..."
2392 run_test 40 "Parallel archive requests"
2395 # test needs a running copytool
2399 local f=$DIR/$tdir/$tfile
2400 local fid=$(copy_file /etc/motd $f 1)
2402 $LFS hsm_archive $f || error "could not archive file"
2403 wait_request_state $fid ARCHIVE SUCCEED
2404 check_hsm_flags $f "0x00000009"
2406 multiop_bg_pause $f O_c || error "multiop failed"
2410 client_up || client_up || true
2412 kill -USR1 $MULTIPID
2413 wait $MULTIPID || error "multiop close failed"
2415 check_hsm_flags $f "0x0000000b"
2419 run_test 52 "Opened for write file on an evicted client should be set dirty"
2422 # test needs a running copytool
2426 local f=$DIR/$tdir/$tfile
2427 local fid=$(copy_file /etc/motd $f 1)
2429 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2430 error "could not archive file"
2431 wait_request_state $fid ARCHIVE SUCCEED
2432 check_hsm_flags $f "0x00000009"
2434 multiop_bg_pause $f o_c || error "multiop failed"
2438 client_up || client_up || true
2440 kill -USR1 $MULTIPID
2441 wait $MULTIPID || error "multiop close failed"
2443 check_hsm_flags $f "0x00000009"
2447 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2450 # test needs a running copytool
2454 local f=$DIR/$tdir/$tfile
2455 local fid=$(make_small $f)
2457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2458 error "could not archive file"
2459 wait_request_state $fid ARCHIVE STARTED
2461 check_hsm_flags $f "0x00000001"
2463 # Avoid coordinator resending this request as soon it has failed.
2468 wait_request_state $fid ARCHIVE FAILED
2470 check_hsm_flags $f "0x00000003"
2475 run_test 54 "Write during an archive cancels it"
2478 # test needs a running copytool
2482 local f=$DIR/$tdir/$tfile
2483 local fid=$(make_small $f)
2485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2486 error "could not archive file"
2487 wait_request_state $fid ARCHIVE STARTED
2489 check_hsm_flags $f "0x00000001"
2491 # Avoid coordinator resending this request as soon it has failed.
2494 $TRUNCATE $f 1024 || error "truncate failed"
2496 wait_request_state $fid ARCHIVE FAILED
2498 check_hsm_flags $f "0x00000003"
2503 run_test 55 "Truncate during an archive cancels it"
2506 # test needs a running copytool
2510 local f=$DIR/$tdir/$tfile
2511 local fid=$(make_large_for_progress $f)
2513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2514 error "could not archive file"
2515 wait_request_state $fid ARCHIVE STARTED
2517 check_hsm_flags $f "0x00000001"
2519 # Change metadata and sync to be sure we are not changing only
2524 wait_request_state $fid ARCHIVE SUCCEED
2526 check_hsm_flags $f "0x00000009"
2530 run_test 56 "Setattr during an archive is ok"
2533 # Need one client for I/O, one for request
2534 needclients 2 || return 0
2536 # test needs a running copytool
2540 local f=$DIR/$tdir/test_archive_remote
2541 # Create a file on a remote node
2542 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2543 "count=2 conv=fsync"
2546 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2547 error "hsm_archive failed"
2548 local fid=$(path2fid $f)
2549 wait_request_state $fid ARCHIVE SUCCEED
2551 # Release and implicit restore it
2552 do_node $CLIENT2 "$LFS hsm_release $f" ||
2553 error "hsm_release failed"
2554 do_node $CLIENT2 "md5sum $f" ||
2555 error "hsm_restore failed"
2557 wait_request_state $fid RESTORE SUCCEED
2561 run_test 57 "Archive a file with dirty cache on another node"
2563 truncate_released_file() {
2567 local sz=$(stat -c %s $src_file)
2568 local f=$DIR/$tdir/$tfile
2569 local fid=$(copy_file $1 $f)
2573 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2574 error "could not archive file"
2575 wait_request_state $fid ARCHIVE SUCCEED
2577 $LFS hsm_release $f || error "could not release file"
2579 $TRUNCATE $f $trunc_to || error "truncate failed"
2582 local sz1=$(stat -c %s $f)
2583 [[ $sz1 == $trunc_to ]] ||
2584 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2587 check_hsm_flags $f "0x0000000b"
2589 local state=$(get_request_state $fid RESTORE)
2590 [[ "$state" == "SUCCEED" ]] ||
2591 error "truncate $sz does not trig restore, state = $state"
2593 $TRUNCATE $ref $trunc_to
2594 cmp $ref $f || error "file data wrong after truncate"
2600 # test needs a running copytool
2605 local sz=$(stat -c %s /etc/passwd)
2607 echo "truncate up from $sz to $((sz*2))"
2608 truncate_released_file /etc/passwd $((sz*2))
2610 echo "truncate down from $sz to $((sz/2))"
2611 truncate_released_file /etc/passwd $((sz/2))
2613 echo "truncate to 0"
2614 truncate_released_file /etc/passwd 0
2618 run_test 58 "Truncate a released file will trigger restore"
2621 # This test validates the fix for LU-4512. Ensure that the -u
2622 # option changes the progress reporting interval from the default
2623 # (30 seconds) to the user-specified interval.
2625 local progress_timeout=$((interval * 3))
2627 # test needs a new running copytool
2629 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2632 local f=$DIR/$tdir/$tfile
2633 local fid=$(make_large_for_progress $f)
2635 local start_at=$(date +%s)
2636 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2637 error "could not archive file"
2640 local mdt=${MDT_PREFIX}${mdtidx}
2641 local mds=mds$((mdtidx + 1))
2643 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2644 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2650 echo -n "Expecting a progress update within $progress_timeout seconds... "
2652 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2653 if [ $RESULT -gt 0 ]; then
2654 echo "$RESULT bytes copied in $WAIT seconds."
2656 elif [ $WAIT -ge $progress_timeout ]; then
2657 error "Timed out waiting for progress update!"
2660 WAIT=$((WAIT + sleep))
2664 local finish_at=$(date +%s)
2665 local elapsed=$((finish_at - start_at))
2667 # Ensure that the progress update occurred within the expected window.
2668 if [ $elapsed -lt $interval ]; then
2669 error "Expected progress update after at least $interval seconds"
2675 run_test 60 "Changing progress update interval from default"
2678 # test needs a new running copytool
2680 copytool_monitor_setup
2681 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2683 # Just start and stop the copytool to generate events.
2687 local REGISTER_EVENT
2688 local UNREGISTER_EVENT
2689 while read event; do
2690 local parsed=$(parse_json_event "$event")
2691 if [ -z "$parsed" ]; then
2692 error "Copytool sent malformed event: $event"
2696 if [ $event_type == "REGISTER" ]; then
2697 REGISTER_EVENT=$event
2698 elif [ $event_type == "UNREGISTER" ]; then
2699 UNREGISTER_EVENT=$event
2701 done < <(echo $"$(get_copytool_event_log)")
2703 if [ -z "$REGISTER_EVENT" ]; then
2704 error "Copytool failed to send register event to FIFO"
2707 if [ -z "$UNREGISTER_EVENT" ]; then
2708 error "Copytool failed to send unregister event to FIFO"
2711 copytool_monitor_cleanup
2712 echo "Register/Unregister events look OK."
2714 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2717 # Bump progress interval for livelier events.
2720 # test needs a new running copytool
2722 copytool_monitor_setup
2723 HSMTOOL_UPDATE_INTERVAL=$interval \
2724 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2727 local f=$DIR/$tdir/$tfile
2728 local fid=$(make_large_for_progress $f)
2730 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2731 error "could not archive file"
2732 wait_request_state $fid ARCHIVE SUCCEED
2734 local expected_fields="event_time data_fid source_fid"
2735 expected_fields+=" total_bytes current_bytes"
2739 while read event; do
2740 # Make sure we're not getting anything from previous events.
2741 for field in $expected_fields; do
2745 local parsed=$(parse_json_event "$event")
2746 if [ -z "$parsed" ]; then
2747 error "Copytool sent malformed event: $event"
2751 if [ $event_type == "ARCHIVE_START" ]; then
2754 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2757 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2761 # Do some simple checking of the progress update events.
2762 for expected_field in $expected_fields; do
2763 if [ -z ${!expected_field+x} ]; then
2764 error "Missing $expected_field field in event"
2768 if [ $total_bytes -eq 0 ]; then
2769 error "Expected total_bytes to be > 0"
2772 # These should be identical throughout an archive
2774 if [ $source_fid != $data_fid ]; then
2775 error "Expected source_fid to equal data_fid"
2777 done < <(echo $"$(get_copytool_event_log)")
2779 if [ -z "$START_EVENT" ]; then
2780 error "Copytool failed to send archive start event to FIFO"
2783 if [ -z "$FINISH_EVENT" ]; then
2784 error "Copytool failed to send archive finish event to FIFO"
2787 echo "Archive events look OK."
2791 copytool_monitor_cleanup
2793 run_test 71 "Copytool logs JSON archive events to FIFO"
2796 # Bump progress interval for livelier events.
2799 # test needs a new running copytool
2801 copytool_monitor_setup
2802 HSMTOOL_UPDATE_INTERVAL=$interval \
2803 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2804 local test_file=$HSMTOOL_MONITOR_DIR/file
2806 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2808 do_facet $SINGLEAGT "$cmd" ||
2809 error "cannot create $test_file on $SINGLEAGT"
2810 copy2archive $test_file $tdir/$tfile
2813 local f=$DIR/$tdir/$tfile
2814 import_file $tdir/$tfile $f
2815 f=$DIR2/$tdir/$tfile
2816 echo "Verifying released state: "
2817 check_hsm_flags $f "0x0000000d"
2819 local fid=$(path2fid $f)
2821 wait_request_state $fid RESTORE SUCCEED
2823 local expected_fields="event_time data_fid source_fid"
2824 expected_fields+=" total_bytes current_bytes"
2828 while read event; do
2829 # Make sure we're not getting anything from previous events.
2830 for field in $expected_fields; do
2834 local parsed=$(parse_json_event "$event")
2835 if [ -z "$parsed" ]; then
2836 error "Copytool sent malformed event: $event"
2840 if [ $event_type == "RESTORE_START" ]; then
2842 if [ $source_fid != $data_fid ]; then
2843 error "source_fid should == data_fid at start"
2846 elif [ $event_type == "RESTORE_FINISH" ]; then
2848 if [ $source_fid != $data_fid ]; then
2849 error "source_fid should == data_fid at finish"
2852 elif [ $event_type != "RESTORE_RUNNING" ]; then
2856 # Do some simple checking of the progress update events.
2857 for expected_field in $expected_fields; do
2858 if [ -z ${!expected_field+x} ]; then
2859 error "Missing $expected_field field in event"
2863 if [ $total_bytes -eq 0 ]; then
2864 error "Expected total_bytes to be > 0"
2867 # When a restore starts out, the data fid is the same as the
2868 # source fid. After the restore has gotten going, we learn
2869 # the new data fid. Once the restore has finished, the source
2870 # fid is set to the new data fid.
2872 # We test this because some monitoring software may depend on
2873 # this behavior. If it changes, then the consumers of these
2874 # events may need to be modified.
2875 if [ $source_fid == $data_fid ]; then
2876 error "source_fid should != data_fid during restore"
2878 done < <(echo $"$(get_copytool_event_log)")
2880 if [ -z "$START_EVENT" ]; then
2881 error "Copytool failed to send restore start event to FIFO"
2884 if [ -z "$FINISH_EVENT" ]; then
2885 error "Copytool failed to send restore finish event to FIFO"
2888 echo "Restore events look OK."
2892 copytool_monitor_cleanup
2896 run_test 72 "Copytool logs JSON restore events to FIFO"
2899 file_count=51 # Max number of files constrained by LNET message size
2900 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2901 local f=$DIR/$tdir/$tfile
2902 local FILELIST=/tmp/filelist.txt
2906 for i in $(seq 1 $file_count); do
2907 fid=$(copy_file /etc/hosts $f.$i)
2908 echo $f.$i >> $FILELIST
2911 # to be sure wait_all_done will not be mislead by previous tests
2913 wait_for_grace_delay
2914 $LFS hsm_archive --filelist $FILELIST ||
2915 error "cannot archive a file list"
2917 $LFS hsm_release --filelist $FILELIST ||
2918 error "cannot release a file list"
2919 $LFS hsm_restore --filelist $FILELIST ||
2920 error "cannot restore a file list"
2924 run_test 90 "Archive/restore a file list"
2926 double_verify_reset_hsm_param() {
2928 echo "Testing $HSM_PARAM.$p"
2929 local val=$(get_hsm_param $p)
2931 local val2=$(($val * 2))
2932 set_hsm_param $p $val2
2933 val=$(get_hsm_param $p)
2934 [[ $val == $val2 ]] ||
2935 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2936 echo "Set $p to 0 must failed"
2940 set_hsm_param $p $save
2942 if [[ $rc == 0 ]]; then
2943 error "we must not be able to set $HSM_PARAM.$p to 0"
2948 double_verify_reset_hsm_param loop_period
2949 double_verify_reset_hsm_param grace_delay
2950 double_verify_reset_hsm_param active_request_timeout
2951 double_verify_reset_hsm_param max_requests
2952 double_verify_reset_hsm_param default_archive_id
2954 run_test 100 "Set coordinator /proc tunables"
2961 run_test 102 "Verify coordinator control"
2964 # test needs a running copytool
2971 for i in $(seq 1 20); do
2972 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2974 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2978 echo "Current requests"
2979 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2980 $HSM_PARAM.actions |\
2981 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2983 [[ -z "$res" ]] || error "Some request have not been canceled"
2987 run_test 103 "Purge all requests"
2992 # test needs a running copytool
2996 local f=$DIR/$tdir/$tfile
2997 local fid=$(make_large_for_progress $f)
2998 # if cdt is on, it can serve too quickly the request
3000 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3001 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3002 $HSM_PARAM.actions |\
3003 grep $fid | cut -f16 -d=")
3006 [[ "$data1" == "$DATAHEX" ]] ||
3007 error "Data field in records is ($data1) and not ($DATAHEX)"
3011 run_test 104 "Copy tool data field"
3018 for i in $(seq -w 1 10); do
3019 cp /etc/passwd $DIR/$tdir/$i
3020 $LFS hsm_archive $DIR/$tdir/$i
3022 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3023 $HSM_PARAM.actions |\
3024 grep WAITING | wc -l")
3027 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3028 $HSM_PARAM.actions |\
3029 grep WAITING | wc -l")
3032 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3033 error "Requests count after shutdown $reqcnt2 != "\
3034 "before shutdown $reqcnt1"
3036 run_test 105 "Restart of coordinator"
3038 get_agent_by_uuid_mdt() {
3041 local mds=mds$(($mdtidx + 1))
3042 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3046 check_agent_registered_by_mdt() {
3049 local mds=mds$(($mdtidx + 1))
3050 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3051 if [[ ! -z "$agent" ]]; then
3052 echo "found agent $agent on $mds"
3054 error "uuid $uuid not found in agent list on $mds"
3058 check_agent_unregistered_by_mdt() {
3061 local mds=mds$(($mdtidx + 1))
3062 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3063 if [[ -z "$agent" ]]; then
3064 echo "uuid not found in agent list on $mds"
3066 error "uuid found in agent list on $mds: $agent"
3070 check_agent_registered() {
3073 for mdsno in $(seq 1 $MDSCOUNT); do
3074 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3078 check_agent_unregistered() {
3081 for mdsno in $(seq 1 $MDSCOUNT); do
3082 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3087 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3088 get_client_uuid $MOUNT | cut -d' ' -f2)
3091 check_agent_registered $uuid
3093 search_copytools || error "No copytool found"
3096 check_agent_unregistered $uuid
3099 check_agent_registered $uuid
3103 run_test 106 "Copytool register/unregister"
3106 # test needs a running copytool
3108 # create and archive file
3110 local f1=$DIR/$tdir/$tfile
3111 local fid=$(copy_file /etc/passwd $f1)
3112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3113 wait_request_state $fid ARCHIVE SUCCEED
3114 # shutdown and restart MDS
3116 # check the copytool still gets messages from MDT
3117 local f2=$DIR/$tdir/2
3118 local fid=$(copy_file /etc/passwd $f2)
3119 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3120 # main check of this sanity: this request MUST succeed
3121 wait_request_state $fid ARCHIVE SUCCEED
3124 run_test 107 "Copytool re-register after MDS restart"
3126 policy_set_and_test()
3130 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3131 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3132 [[ "$policy" == "$target" ]] ||
3133 error "Wrong policy after '$change': '$policy' != '$target'"
3137 # to force default policy setting if error
3138 CDT_POLICY_HAD_CHANGED=true
3140 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3141 local default="NonBlockingRestore [NoRetryAction]"
3142 [[ "$policy" == "$default" ]] ||
3143 error "default policy has changed,"\
3144 " '$policy' != '$default' update the test"
3145 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3146 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3147 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3148 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3149 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3150 # useless bacause we know but safer for futur changes to use real value
3151 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3152 echo "Next set_param must failed"
3153 policy_set_and_test "wrong" "$policy"
3156 echo "Back to default policy"
3157 cdt_set_sanity_policy
3159 run_test 109 "Policy display/change"
3162 # test needs a running copytool
3167 copy2archive /etc/passwd $tdir/$tfile
3169 local f=$DIR/$tdir/$tfile
3170 import_file $tdir/$tfile $f
3171 local fid=$(path2fid $f)
3173 cdt_set_non_blocking_restore
3178 wait_request_state $fid RESTORE SUCCEED
3179 cdt_clear_non_blocking_restore
3183 error "md5sum returns $st != 1, "\
3184 "should also perror ENODATA (No data available)"
3188 run_test 110a "Non blocking restore policy (import case)"
3191 # test needs a running copytool
3195 local f=$DIR/$tdir/$tfile
3196 local fid=$(copy_file /etc/passwd $f)
3197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3198 wait_request_state $fid ARCHIVE SUCCEED
3201 cdt_set_non_blocking_restore
3206 wait_request_state $fid RESTORE SUCCEED
3207 cdt_clear_non_blocking_restore
3211 error "md5sum returns $st != 1, "\
3212 "should also perror ENODATA (No data available)"
3216 run_test 110b "Non blocking restore policy (release case)"
3219 # test needs a running copytool
3223 copy2archive /etc/passwd $tdir/$tfile
3225 local f=$DIR/$tdir/$tfile
3227 import_file $tdir/$tfile $f
3228 local fid=$(path2fid $f)
3232 copytool_remove_backend $fid
3235 wait_request_state $fid RESTORE FAILED
3242 [[ $st == 0 ]] || error "Restore does not failed"
3246 run_test 111a "No retry policy (import case), restore will error"\
3247 " (No such file or directory)"
3250 # test needs a running copytool
3254 local f=$DIR/$tdir/$tfile
3255 local fid=$(copy_file /etc/passwd $f)
3257 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3258 wait_request_state $fid ARCHIVE SUCCEED
3261 copytool_remove_backend $fid
3264 wait_request_state $fid RESTORE FAILED
3271 [[ $st == 0 ]] || error "Restore does not failed"
3275 run_test 111b "No retry policy (release case), restore will error"\
3276 " (No such file or directory)"
3279 # test needs a running copytool
3283 local f=$DIR/$tdir/$tfile
3284 local fid=$(copy_file /etc/passwd $f)
3286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3287 local l=$($LFS hsm_action $f)
3289 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3293 wait_request_state $fid ARCHIVE SUCCEED
3296 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3300 run_test 112 "State of recorded request"
3303 # test needs a running copytool
3307 local f=$DIR/$tdir/$tfile
3308 local fid=$(make_large_for_cancel $f)
3309 # test with cdt on is made in test_221
3311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3314 wait_request_state $fid ARCHIVE CANCELED
3315 wait_request_state $fid CANCEL SUCCEED
3319 run_test 200 "Register/Cancel archive"
3322 # test needs a running copytool
3326 local f=$DIR/$tdir/$tfile
3327 make_archive $tdir/$tfile
3328 import_file $tdir/$tfile $f
3329 local fid=$(path2fid $f)
3331 # test with cdt on is made in test_222
3336 wait_request_state $fid RESTORE CANCELED
3337 wait_request_state $fid CANCEL SUCCEED
3341 run_test 201 "Register/Cancel restore"
3344 # test needs a running copytool
3348 local f=$DIR/$tdir/$tfile
3349 local fid=$(make_large_for_progress $f)
3350 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3351 wait_request_state $fid ARCHIVE SUCCEED
3357 wait_request_state $fid REMOVE CANCELED
3361 run_test 202 "Register/Cancel remove"
3364 # test needs a running copytool
3369 local f=$DIR/$tdir/$tfile
3370 local fid=$(copy_file /etc/passwd $f)
3374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3375 wait_request_state $fid ARCHIVE SUCCEED
3377 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3381 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3385 run_test 220 "Changelog for archive"
3388 # test needs a running copytool
3393 local f=$DIR/$tdir/$tfile
3394 local fid=$(make_large_for_cancel $f)
3398 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3399 wait_request_state $fid ARCHIVE STARTED
3401 wait_request_state $fid ARCHIVE CANCELED
3402 wait_request_state $fid CANCEL SUCCEED
3404 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3407 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3411 run_test 221 "Changelog for archive canceled"
3414 # test needs a running copytool
3418 copy2archive /etc/passwd $tdir/$tfile
3420 local f=$DIR/$tdir/$tfile
3421 import_file $tdir/$tfile $f
3422 local fid=$(path2fid $f)
3427 wait_request_state $fid RESTORE SUCCEED
3429 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3432 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3436 run_test 222a "Changelog for explicit restore"
3439 # test needs a running copytool
3443 local f=$DIR/$tdir/$tfile
3444 local fid=$(copy_file /etc/passwd $f)
3447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3448 wait_request_state $fid ARCHIVE SUCCEED
3453 wait_request_state $fid RESTORE SUCCEED
3455 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3458 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3462 run_test 222b "Changelog for implicit restore"
3465 # test needs a running copytool
3470 local f=$DIR/$tdir/$tfile
3471 make_archive $tdir/$tfile
3475 import_file $tdir/$tfile $f
3476 local fid=$(path2fid $f)
3479 wait_request_state $fid RESTORE STARTED
3481 wait_request_state $fid RESTORE CANCELED
3482 wait_request_state $fid CANCEL SUCCEED
3484 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3487 [[ $flags == $target ]] ||
3488 error "Changelog flag is $flags not $target"
3492 run_test 223a "Changelog for restore canceled (import case)"
3495 # test needs a running copytool
3500 local f=$DIR/$tdir/$tfile
3501 local fid=$(make_large_for_progress $f)
3504 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3505 wait_request_state $fid ARCHIVE SUCCEED
3508 wait_request_state $fid RESTORE STARTED
3510 wait_request_state $fid RESTORE CANCELED
3511 wait_request_state $fid CANCEL SUCCEED
3513 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3516 [[ $flags == $target ]] ||
3517 error "Changelog flag is $flags not $target"
3521 run_test 223b "Changelog for restore canceled (release case)"
3524 # test needs a running copytool
3529 local f=$DIR/$tdir/$tfile
3530 local fid=$(copy_file /etc/passwd $f)
3533 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3534 wait_request_state $fid ARCHIVE SUCCEED
3537 wait_request_state $fid REMOVE SUCCEED
3539 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3542 [[ $flags == $target ]] ||
3543 error "Changelog flag is $flags not $target"
3547 run_test 224 "Changelog for remove"
3550 # test needs a running copytool
3553 # test is not usable because remove request is too fast
3554 # so it is always finished before cancel can be done ...
3555 echo "Test disabled"
3560 local f=$DIR/$tdir/$tfile
3561 local fid=$(make_large_for_progress $f)
3564 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3565 wait_request_state $fid ARCHIVE SUCCEED
3567 # if cdt is on, it can serve too quickly the request
3572 wait_request_state $fid REMOVE CANCELED
3573 wait_request_state $fid CANCEL SUCCEED
3575 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3576 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3577 tail -n 1 | awk '{print $5}')
3580 [[ $flags == $target ]] ||
3581 error "Changelog flag is $flags not $target"
3585 run_test 225 "Changelog for remove canceled"
3588 # test needs a running copytool
3593 local f1=$DIR/$tdir/$tfile-1
3594 local f2=$DIR/$tdir/$tfile-2
3595 local f3=$DIR/$tdir/$tfile-3
3596 local fid1=$(copy_file /etc/passwd $f1)
3597 local fid2=$(copy_file /etc/passwd $f2)
3598 copy_file /etc/passwd $f3
3601 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3602 wait_request_state $fid1 ARCHIVE SUCCEED
3604 $LFS hsm_archive $f2
3605 wait_request_state $fid2 ARCHIVE SUCCEED
3607 rm $f1 || error "rm $f1 failed"
3609 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3612 [[ $flags == $target ]] ||
3613 error "Changelog flag is $flags not $target"
3615 mv $f3 $f2 || error "mv $f3 $f2 failed"
3617 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3620 [[ $flags == $target ]] ||
3621 error "Changelog flag is $flags not $target"
3625 run_test 226 "changelog for last rm/mv with exiting archive"
3627 check_flags_changes() {
3635 $LFS hsm_set --$hsm_flag $f ||
3636 error "Cannot set $hsm_flag on $f"
3637 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3638 local seen=${#flags[*]}
3640 [[ $seen == $cnt ]] ||
3641 error "set $hsm_flag: Changelog events $seen != $cnt"
3642 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3643 error "set $hsm_flag: Changelog flags are "\
3644 "${flags[$((cnt - 1))]} not $target"
3646 $LFS hsm_clear --$hsm_flag $f ||
3647 error "Cannot clear $hsm_flag on $f"
3648 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3651 [[ $cnt == $seen ]] ||
3652 error "clear $hsm_flag: Changelog events $seen != $cnt"
3654 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3655 error "clear $hsm_flag: Changelog flag is "\
3656 "${flags[$((cnt - 1))]} not $target"
3660 # test needs a running copytool
3667 for i in norelease noarchive exists archived
3669 local f=$DIR/$tdir/$tfile-$i
3670 local fid=$(copy_file /etc/passwd $f)
3671 check_flags_changes $f $fid $i 0 1
3674 f=$DIR/$tdir/$tfile---lost
3675 fid=$(copy_file /etc/passwd $f)
3676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3677 wait_request_state $fid ARCHIVE SUCCEED
3678 check_flags_changes $f $fid lost 3 1
3682 run_test 227 "changelog when explicit setting of HSM flags"
3685 # test needs a running copytool
3688 local fid=$(make_small_sync $DIR/$tfile)
3689 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3690 wait_request_state $fid ARCHIVE SUCCEED
3692 $LFS hsm_release $DIR/$tfile
3693 check_hsm_flags $DIR/$tfile "0x0000000d"
3695 filefrag $DIR/$tfile | grep " 1 extent found" ||
3696 error "filefrag on released file must return only one extent"
3698 # only newer versions of cp detect sparse files by stat/FIEMAP
3700 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3701 error "copying $DIR/$tfile"
3702 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3704 $LFS hsm_release $DIR/$tfile
3705 check_hsm_flags $DIR/$tfile "0x0000000d"
3707 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3709 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3711 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3712 error "comparing untarred $DIR/$tfile"
3714 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3715 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3718 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3721 # test needs a running copytool
3725 local maxrequest=$(get_hsm_param max_requests)
3726 local rqcnt=$(($maxrequest * 3))
3730 for i in $(seq -w 1 $rqcnt); do
3732 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3734 # we do it in 2 steps, so all requests arrive at the same time
3735 for i in $(seq -w 1 $rqcnt); do
3736 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3741 while [[ $cnt != 0 || $wt != 0 ]]; do
3743 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3744 $HSM_PARAM.actions |\
3745 grep STARTED | grep -v CANCEL | wc -l")
3746 [[ $cnt -le $maxrequest ]] ||
3747 error "$cnt > $maxrequest too many started requests"
3748 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3749 $HSM_PARAM.actions |\
3750 grep WAITING | wc -l")
3751 echo "max=$maxrequest started=$cnt waiting=$wt"
3756 run_test 250 "Coordinator max request"
3759 # test needs a running copytool
3763 local f=$DIR/$tdir/$tfile
3764 local fid=$(make_large_for_cancel $f)
3767 # to have a short test
3768 local old_to=$(get_hsm_param active_request_timeout)
3769 set_hsm_param active_request_timeout 4
3770 # to be sure the cdt will wake up frequently so
3771 # it will be able to cancel the "old" request
3772 local old_loop=$(get_hsm_param loop_period)
3773 set_hsm_param loop_period 2
3776 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3777 wait_request_state $fid ARCHIVE STARTED
3779 wait_request_state $fid ARCHIVE CANCELED
3781 set_hsm_param active_request_timeout $old_to
3782 set_hsm_param loop_period $old_loop
3786 run_test 251 "Coordinator request timeout"
3789 # the only way to test ondisk conf is to restart MDS ...
3790 echo "Stop coordinator and remove coordinator state at mount"
3793 # clean on disk conf set by default
3794 cdt_clear_mount_state
3795 cdt_check_state stopped
3797 # check cdt still off after umount/remount
3799 cdt_check_state stopped
3801 echo "Set coordinator start at mount, and start coordinator"
3802 cdt_set_mount_state enabled
3805 cdt_check_state enabled
3807 # check cdt still on after umount/remount
3809 cdt_check_state enabled
3811 # we are back to original state (cdt started at mount)
3813 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3816 local ai=$(get_hsm_param default_archive_id)
3817 local new=$((ai + 1))
3819 set_hsm_param default_archive_id $new -P
3821 local res=$(get_hsm_param default_archive_id)
3824 set_hsm_param default_archive_id "" "-P -d"
3826 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3828 run_test 301 "HSM tunnable are persistent"
3831 local ai=$(get_hsm_param default_archive_id)
3832 local new=$((ai + 1))
3837 set_hsm_param default_archive_id $new -P
3840 for mdtno in $(seq 1 $MDSCOUNT); do
3845 cdt_check_state enabled
3847 local res=$(get_hsm_param default_archive_id)
3850 set_hsm_param default_archive_id "" "-P -d"
3852 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3854 run_test 302 "HSM tunnable are persistent when CDT is off"
3857 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3863 local dir_mdt0=$DIR/$tdir/mdt0
3864 local dir_mdt1=$DIR/$tdir/mdt1
3866 # create 1 dir per MDT
3867 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3868 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3870 # create 1 file in each MDT
3871 local fid1=$(make_small $dir_mdt0/$tfile)
3872 local fid2=$(make_small $dir_mdt1/$tfile)
3874 # check that hsm request on mdt0 is sent to the right MDS
3875 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3876 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3877 echo "archive successful on mdt0"
3879 # check that hsm request on mdt1 is sent to the right MDS
3880 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3881 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3882 echo "archive successful on mdt1"
3885 # clean test files and directories
3886 rm -rf $dir_mdt0 $dir_mdt1
3888 run_test 400 "Single request is sent to the right MDT"
3891 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3897 local dir_mdt0=$DIR/$tdir/mdt0
3898 local dir_mdt1=$DIR/$tdir/mdt1
3900 # create 1 dir per MDT
3901 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3902 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3904 # create 1 file in each MDT
3905 local fid1=$(make_small $dir_mdt0/$tfile)
3906 local fid2=$(make_small $dir_mdt1/$tfile)
3908 # check that compound requests are shunt to the rights MDTs
3909 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3910 error "lfs hsm_archive"
3911 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3912 echo "archive successful on mdt0"
3913 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3914 echo "archive successful on mdt1"
3917 # clean test files and directories
3918 rm -rf $dir_mdt0 $dir_mdt1
3920 run_test 401 "Compound requests split and sent to their respective MDTs"
3922 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3927 local node=$(facet_active_host $facet)
3929 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3930 awk '{print $4}'); do
3931 echo "$3 $mdc on $node"
3932 do_facet $facet "$LCTL --device $mdc $state" || return 1
3937 # make sure there is no running copytool
3940 # deactivate all mdc on agent1
3941 mdc_change_state $SINGLEAGT "MDT000." "deactivate"
3943 copytool_setup $SINGLEAGT
3945 check_agent_unregistered "uuid" # match any agent
3947 # no expected running copytool
3948 search_copytools $agent && error "Copytool start should have failed"
3951 mdc_change_state $SINGLEAGT "MDT000." "activate"
3953 run_test 402 "Copytool start fails if all MDTs are inactive"
3956 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3958 # make sure there is no running copytool
3961 local agent=$(facet_active_host $SINGLEAGT)
3962 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3964 # deactivate all mdc for MDT0001
3965 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
3968 # check the agent is registered on MDT0000, and not on MDT0001
3969 check_agent_registered_by_mdt $uuid 0
3970 check_agent_unregistered_by_mdt $uuid 1
3972 # check running copytool process
3973 search_copytools $agent || error "No running copytools on $agent"
3975 # reactivate all mdc for MDT0001
3976 mdc_change_state $SINGLEAGT "MDT0001" "activate"
3978 # make sure the copytool is now registered to all MDTs
3979 check_agent_registered $uuid
3983 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3986 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3990 # create files on both MDT0000 and MDT0001
3993 local dir_mdt0=$DIR/$tdir/mdt0
3994 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3996 # create 1 file on mdt0
3997 local fid1=$(make_small $dir_mdt0/$tfile)
3999 # deactivate all mdc for MDT0001
4000 mdc_change_state $SINGLEAGT "MDT0001" "deactivate"
4002 # send an HSM request for files in MDT0000
4003 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4005 # check for completion of files in MDT0000
4006 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4007 echo "archive successful on mdt0"
4009 # reactivate all mdc for MDT0001
4010 mdc_change_state $SINGLEAGT "MDT0001" "activate"
4013 # clean test files and directories
4016 run_test 404 "Inactive MDT does not block requests for active MDTs"
4021 check_and_cleanup_lustre