3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: 3815 3939
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36 40"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
27 MULTIOP=${MULTIOP:-multiop}
28 OPENFILE=${OPENFILE:-openfile}
29 MCREATE=${MCREATE:-mcreate}
30 MOUNT_2=${MOUNT_2:-"yes"}
33 # script only handles up to 10 MDTs (because of MDT_PREFIX)
34 [ $MDSCOUNT -gt 9 ] &&
35 error "script cannot handle more than 9 MDTs, please fix" && exit
37 check_and_setup_lustre
39 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
40 skip_env "Need MDS version at least 2.4.53" && exit
43 # $RUNAS_ID may get set incorrectly somewhere else
44 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
45 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
47 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
53 # the following associated variables are added:
55 # AGTCOUNT: number of agents
56 # AGTDEV{N}: target HSM mount point (root path of the backend)
57 # agt{N}_HOST: hostname of the agent agt{N}
58 # SINGLEAGT: facet of the single agent
60 # The number of agents is initialized as the number of remote client nodes.
61 # By default, only single copytool is started on a remote client/agent. If there
62 # was no remote client, then the copytool will be started on the local client.
68 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
69 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
71 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
72 if [[ $CLIENTCOUNT -gt 1 ]] &&
73 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
74 skip_env "SHARED_DIRECTORY should be accessible"\
79 for n in $(seq $AGTCOUNT); do
80 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
81 agent=CLIENT$((n + 1))
82 if [[ -z "${!agent}" ]]; then
83 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
86 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
89 export SINGLEAGT=${SINGLEAGT:-agt1}
91 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
92 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
93 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
94 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
95 export HSMTOOL_TESTDIR
96 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
97 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
100 # The test only support up to 10 MDTs
101 MDT_PREFIX="mdt.$FSNAME-MDT000"
102 HSM_PARAM="${MDT_PREFIX}0.hsm"
104 # archive is purged at copytool setup
105 HSM_ARCHIVE_PURGE=true
107 # Don't allow copytool error upon start/setup
108 HSMTOOL_NOERROR=false
111 # Get the backend root path for the given agent facet.
114 local dev=AGTDEV$(facet_number $facet)
119 # Stop copytool and unregister an existing changelog user.
121 copytool_monitor_cleanup
124 cdt_set_sanity_policy
129 # get MDT device for each mdc
130 for mdtno in $(seq 1 $MDSCOUNT); do
131 local idx=$(($mdtno - 1))
132 MDT[$idx]=$($LCTL get_param -n \
133 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
134 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
139 local agents=${1:-$(facet_active_host $SINGLEAGT)}
140 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
143 search_and_kill_copytool() {
144 local agents=${1:-$(facet_active_host $SINGLEAGT)}
146 echo "Killing existing copytools on $agents"
147 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
150 copytool_monitor_setup() {
151 local facet=${1:-$SINGLEAGT}
152 local agent=$(facet_active_host $facet)
154 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
155 local test_dir=$(do_node $agent "$cmd") ||
156 error "Failed to create tempdir on $agent"
157 export HSMTOOL_MONITOR_DIR=$test_dir
159 # Create the fifo and a monitor (cat dies when copytool dies)
160 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
161 error "failed to create copytool fifo on $agent"
162 cmd="cat $test_dir/fifo > $test_dir/events &"
163 cmd+=" echo \\\$! > $test_dir/monitor_pid"
165 if [[ $PDSH == *Rmrsh* ]]; then
166 # This is required for pdsh -Rmrsh and its handling of remote
168 # Regular ssh and pdsh -Rssh work fine without this
169 # backgrounded subshell nonsense.
170 (do_node $agent "$cmd") &
171 export HSMTOOL_MONITOR_PDSH=$!
173 # Slightly racy, but just making a best-effort to catch obvious
176 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
177 error "Failed to start copytool monitor on $agent"
179 do_node $agent "$cmd"
181 error "Failed to start copytool monitor on $agent"
186 copytool_monitor_cleanup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
191 # Should die when the copytool dies, but just in case.
192 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
193 cmd+=" 2>/dev/null || true"
194 do_node $agent "$cmd"
195 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
196 export HSMTOOL_MONITOR_DIR=
199 # The pdsh should die on its own when the monitor dies. Just
200 # in case, though, try to clean up to avoid any cruft.
201 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
202 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
203 export HSMTOOL_MONITOR_PDSH=
208 local facet=${1:-$SINGLEAGT}
209 local lustre_mntpnt=${2:-$MOUNT}
211 local hsm_root=${4:-$(copytool_device $facet)}
212 local agent=$(facet_active_host $facet)
214 if [[ -z "$arc_id" ]] &&
215 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
216 echo "Wakeup copytool $facet on $agent"
220 if $HSM_ARCHIVE_PURGE; then
221 echo "Purging archive on $agent"
222 do_facet $facet "rm -rf $hsm_root/*"
225 echo "Starting copytool $facet on $agent"
226 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
227 # bandwidth is limited to 1MB/s so the copy time is known and
228 # independent of hardware
229 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
230 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
231 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
232 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
233 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
234 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
235 cmd+=" --bandwidth 1 $lustre_mntpnt"
237 # Redirect the standard output and error to a log file which
238 # can be uploaded to Maloo.
239 local prefix=$TESTLOG_PREFIX
240 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
241 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
243 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
244 if [[ $? != 0 ]]; then
245 [[ $HSMTOOL_NOERROR == true ]] ||
246 error "start copytool $facet on $agent failed"
247 echo "start copytool $facet on $agent failed"
253 get_copytool_event_log() {
254 local facet=${1:-$SINGLEAGT}
255 local agent=$(facet_active_host $facet)
257 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
258 error "Can't get event log: No monitor directory!"
260 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
261 error "Could not collect event log from $agent"
266 local agents=${1:-$(facet_active_host $SINGLEAGT)}
272 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
274 echo "Copytool is stopped on $agents"
276 # clean all CDTs orphans requests from previous tests
277 # that would otherwise need to timeout to clear.
278 for mdtno in $(seq 1 $MDSCOUNT); do
280 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
281 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
283 # skip already stop[ed,ing] CDTs
284 echo $oldstate | grep stop && continue
286 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
287 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
289 error "mds${mdtno} cdt state is not stopped"
290 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
291 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
293 error "mds${mdtno} cdt state is not $oldstate"
298 local agents=${1:-$(facet_active_host $SINGLEAGT)}
300 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
301 echo "Copytool is suspended on $agents"
304 copytool_remove_backend() {
306 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
307 echo "Remove from backend: $fid = $be"
308 do_facet $SINGLEAGT rm -f $be
312 do_facet $SINGLEAGT \
313 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
314 --import $1 $2 $MOUNT" ||
315 error "import of $1 to $2 failed"
319 local file=$HSM_ARCHIVE/$1
320 do_facet $SINGLEAGT mkdir -p $(dirname $file)
321 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
322 error "cannot create $file"
326 local file=$HSM_ARCHIVE/$2
327 do_facet $SINGLEAGT mkdir -p $(dirname $file)
328 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
337 if [[ "$value" != "" ]]; then
340 for mdtno in $(seq 1 $MDSCOUNT); do
341 local idx=$(($mdtno - 1))
342 local facet=mds${mdtno}
343 # if $arg include -P option, run 1 set_param per MDT on the MGS
344 # else, run set_param on each MDT
345 [[ $arg = *"-P"* ]] && facet=mgs
346 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
347 [[ $? != 0 ]] && rc=1
357 for mdtno in $(seq 1 $MDSCOUNT); do
358 local idx=$(($mdtno - 1))
359 wait_result mds${mdtno} \
360 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
362 error "$key state is not '$target' on mds${mdtno}"
369 for mdtno in $(seq 1 $MDSCOUNT); do
370 local idx=$(($mdtno - 1))
371 local cl_user=$(do_facet mds${mdtno} $LCTL \
372 --device ${MDT[$idx]} \
373 changelog_register -n)
375 do_facet mds${mdtno} lctl set_param \
376 mdd.${MDT[$idx]}.changelog_mask="+hsm"
377 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
381 changelog_cleanup() {
383 for mdtno in $(seq 1 $MDSCOUNT); do
384 local idx=$(($mdtno - 1))
385 [[ -z ${CL_USERS[$idx]} ]] && continue
386 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
387 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
388 changelog_deregister ${CL_USERS[$idx]}
393 changelog_get_flags() {
398 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
403 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
411 mdts_set_param "$opt -n" "hsm.$param" "$value"
418 mdts_set_param "" hsm_control "$cmd"
419 mdts_check_param hsm_control "$target" 10
422 cdt_set_sanity_policy() {
423 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
426 mdts_set_param "" hsm.policy "+NRA"
427 mdts_set_param "" hsm.policy "-NBR"
428 CDT_POLICY_HAD_CHANGED=
433 mdts_set_param "" hsm.policy "+NRA"
434 CDT_POLICY_HAD_CHANGED=true
437 cdt_clear_no_retry() {
438 mdts_set_param "" hsm.policy "-NRA"
439 CDT_POLICY_HAD_CHANGED=true
442 cdt_set_non_blocking_restore() {
443 mdts_set_param "" hsm.policy "+NBR"
444 CDT_POLICY_HAD_CHANGED=true
447 cdt_clear_non_blocking_restore() {
448 mdts_set_param "" hsm.policy "-NBR"
449 CDT_POLICY_HAD_CHANGED=true
452 cdt_clear_mount_state() {
453 mdts_set_param "-P -d" hsm_control ""
456 cdt_set_mount_state() {
457 mdts_set_param "-P" hsm_control "$1"
461 mdts_check_param hsm_control "$1" 20
465 set_test_state disabled disabled
469 set_test_state enabled enabled
473 set_test_state shutdown stopped
477 set_test_state purge enabled
483 cdt_set_sanity_policy
487 local client_count=$1
488 if [[ $CLIENTCOUNT -lt $client_count ]]; then
489 skip "Need $client_count or more clients, have $CLIENTCOUNT"
496 $LFS path2fid $1 | tr -d '[]'
503 if [[ $u == "user" ]]; then
504 local st=$($RUNAS $LFS hsm_state $f)
506 local st=$($LFS hsm_state $f)
510 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
512 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
516 get_hsm_archive_id() {
518 local st=$($LFS hsm_state $f)
519 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
521 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
530 local st=$(get_hsm_flags $f)
531 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
534 check_hsm_flags_user() {
538 local st=$(get_hsm_flags $f user)
539 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
551 if [[ "$3" != 1 ]]; then
555 cp $1 $f || error "cannot copy $1 to $f"
556 path2fid $f || error "cannot get fid on $f"
560 local file2=${1/$DIR/$DIR2}
561 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
562 error "cannot create $file2"
563 path2fid $1 || error "cannot get fid on $1"
567 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
568 error "cannot create $1"
569 path2fid $1 || error "cannot get fid on $1"
572 cleanup_large_files() {
573 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
575 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
578 make_large_for_striping() {
579 local file2=${1/$DIR/$DIR2}
580 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
584 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
585 error "cannot create $file2"
586 path2fid $1 || error "cannot get fid on $1"
589 make_large_for_progress() {
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 not a multiple of 1M to avoid stripe
598 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
599 error "cannot create $file2"
600 path2fid $1 || error "cannot get fid on $1"
603 make_large_for_progress_aligned() {
604 local file2=${1/$DIR/$DIR2}
608 # big file is large enough, so copy time is > 30s
609 # so copytool make 1 progress
610 # size is a multiple of 1M to have stripe
612 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
613 error "cannot create $file2"
614 path2fid $1 || error "cannot get fid on $1"
617 make_large_for_cancel() {
618 local file2=${1/$DIR/$DIR2}
622 # Copy timeout is 100s. 105MB => 105s
623 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
624 error "cannot create $file2"
625 path2fid $1 || error "cannot get fid on $1"
631 wait_update --verbose $(facet_active_host $facet) "$@"
634 wait_request_state() {
638 # 4th arg (mdt index) is optional
640 local mds=mds$(($mdtidx + 1))
642 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
643 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
645 wait_result $mds "$cmd" $state 100 ||
646 error "request on $fid is not $state on $mds"
649 get_request_state() {
653 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
654 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
657 get_request_count() {
661 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
662 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
668 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
669 cmd+=" | egrep 'WAITING|STARTED'"
671 wait_result $SINGLEMDS "$cmd" "" $timeout ||
672 error "requests did not complete"
675 wait_for_grace_delay() {
676 local val=$(get_hsm_param grace_delay)
683 # python2.6 in EL6 includes an internal json module
684 local json_parser='import json; import fileinput;'
685 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
686 json_parser+='json.loads([line for line in '
687 json_parser+='fileinput.input()][0]).items()])'
689 echo $raw_event | python -c "$json_parser"
692 # populate MDT device array
698 # cleanup from previous bad setup
699 search_and_kill_copytool
701 # for recovery tests, coordinator needs to be started at mount
703 # the lustre conf must be without hsm on (like for sanity.sh)
704 echo "Set HSM on and start"
705 cdt_set_mount_state enabled
706 cdt_check_state enabled
708 echo "Start copytool"
711 echo "Set sanity-hsm HSM policy"
712 cdt_set_sanity_policy
714 # finished requests are quickly removed from list
715 set_hsm_param grace_delay 10
721 local f=$DIR/$tdir/$tfile
725 check_hsm_flags_user $f "0x00000000"
727 $RUNAS $LFS hsm_set --norelease $f ||
728 error "user could not change hsm flags"
729 check_hsm_flags_user $f "0x00000010"
731 $RUNAS $LFS hsm_clear --norelease $f ||
732 error "user could not clear hsm flags"
733 check_hsm_flags_user $f "0x00000000"
735 # User could not change those flags...
736 $RUNAS $LFS hsm_set --exists $f &&
737 error "user should not set this flag"
738 check_hsm_flags_user $f "0x00000000"
741 $LFS hsm_set --exists $f ||
742 error "root could not change hsm flags"
743 check_hsm_flags_user $f "0x00000001"
745 $LFS hsm_clear --exists $f ||
746 error "root could not clear hsm state"
747 check_hsm_flags_user $f "0x00000000"
750 run_test 1 "lfs hsm flags root/non-root access"
754 local f=$DIR/$tdir/$tfile
756 # New files are not dirty
757 check_hsm_flags $f "0x00000000"
759 # For test, we simulate an archived file.
760 $LFS hsm_set --exists $f || error "user could not change hsm flags"
761 check_hsm_flags $f "0x00000001"
763 # chmod do not put the file dirty
764 chmod 600 $f || error "could not chmod test file"
765 check_hsm_flags $f "0x00000001"
767 # chown do not put the file dirty
768 chown $RUNAS_ID $f || error "could not chown test file"
769 check_hsm_flags $f "0x00000001"
771 # truncate put the file dirty
772 $TRUNCATE $f 1 || error "could not truncate test file"
773 check_hsm_flags $f "0x00000003"
775 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
776 check_hsm_flags $f "0x00000001"
778 run_test 2 "Check file dirtyness when doing setattr"
784 # New files are not dirty
786 check_hsm_flags $f "0x00000000"
788 # For test, we simulate an archived file.
789 $LFS hsm_set --exists $f ||
790 error "user could not change hsm flags"
791 check_hsm_flags $f "0x00000001"
793 # Reading a file, does not set dirty
794 cat $f > /dev/null || error "could not read file"
795 check_hsm_flags $f "0x00000001"
797 # Open for write without modifying data, does not set dirty
798 openfile -f O_WRONLY $f || error "could not open test file"
799 check_hsm_flags $f "0x00000001"
801 # Append to a file sets it dirty
802 cp -p /etc/passwd $f.append || error "could not create file"
803 $LFS hsm_set --exists $f.append ||
804 error "user could not change hsm flags"
805 dd if=/etc/passwd of=$f.append bs=1 count=3\
806 conv=notrunc oflag=append status=noxfer ||
807 error "could not append to test file"
808 check_hsm_flags $f.append "0x00000003"
810 # Modify a file sets it dirty
811 cp -p /etc/passwd $f.modify || error "could not create file"
812 $LFS hsm_set --exists $f.modify ||
813 error "user could not change hsm flags"
814 dd if=/dev/zero of=$f.modify bs=1 count=3\
815 conv=notrunc status=noxfer ||
816 error "could not modify test file"
817 check_hsm_flags $f.modify "0x00000003"
819 # Open O_TRUNC sets dirty
820 cp -p /etc/passwd $f.trunc || error "could not create file"
821 $LFS hsm_set --exists $f.trunc ||
822 error "user could not change hsm flags"
823 cp /etc/group $f.trunc || error "could not override a file"
824 check_hsm_flags $f.trunc "0x00000003"
826 # Mmapped a file sets dirty
827 cp -p /etc/passwd $f.mmap || error "could not create file"
828 $LFS hsm_set --exists $f.mmap ||
829 error "user could not change hsm flags"
830 multiop $f.mmap OSMWUc || error "could not mmap a file"
831 check_hsm_flags $f.mmap "0x00000003"
833 run_test 3 "Check file dirtyness when opening for write"
837 local f=$DIR/$tdir/$tfile
838 local fid=$(make_small $f)
841 local st=$(get_request_state $fid CANCEL)
842 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
844 run_test 4 "Useless cancel must not be registered"
847 # test needs a running copytool
851 local f=$DIR/$tdir/$tfile
852 local fid=$(copy_file /etc/passwd $f)
854 wait_request_state $fid ARCHIVE SUCCEED
856 check_hsm_flags $f "0x00000009"
860 run_test 8 "Test default archive number"
864 local f=$DIR/$tdir/$tfile
865 local fid=$(copy_file /etc/passwd $f)
866 # we do not use the default one to be sure
867 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
869 copytool_setup $SINGLEAGT $MOUNT $new_an
870 $LFS hsm_archive --archive $new_an $f
871 wait_request_state $fid ARCHIVE SUCCEED
873 check_hsm_flags $f "0x00000009"
877 run_test 9 "Use of explict archive number, with dedicated copytool"
880 needclients 3 || return 0
886 copytool_cleanup $(comma_list $(agts_nodes))
888 # start all of the copytools
889 for n in $(seq $AGTCOUNT); do
893 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
896 for n in $(seq $AGTCOUNT); do
897 file=$DIR/$tdir/$tfile.$n
898 fid=$(make_small $file)
900 $LFS hsm_archive $file || error "could not archive file $file"
901 wait_request_state $fid ARCHIVE SUCCEED
902 check_hsm_flags $file "0x00000009"
906 copytool_cleanup $(comma_list $(agts_nodes))
908 run_test 9a "Multiple remote agents"
911 # test needs a running copytool
914 mkdir -p $DIR/$tdir/d1
915 local f=$DIR/$tdir/$tfile
916 local fid=$(copy_file /etc/hosts $f)
917 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
918 error "hsm_archive failed"
919 wait_request_state $fid ARCHIVE SUCCEED
921 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
922 error "fid $fid not in archive $HSM_ARCHIVE"
923 echo "Verifying content"
924 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
925 echo "Verifying hsm state "
926 check_hsm_flags $f "0x00000009"
928 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
929 local st=$(get_hsm_archive_id $f)
930 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
931 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
936 run_test 10a "Archive a file"
939 # test needs a running copytool
943 local f=$DIR/$tdir/$tfile
944 local fid=$(copy_file /etc/hosts $f)
945 $LFS hsm_archive $f || error "archive request failed"
946 wait_request_state $fid ARCHIVE SUCCEED
948 $LFS hsm_archive $f || error "archive of non dirty file failed"
949 local cnt=$(get_request_count $fid ARCHIVE)
950 [[ "$cnt" == "1" ]] ||
951 error "archive of non dirty file must not make a request"
955 run_test 10b "Archive of non dirty file must work without doing request"
958 # test needs a running copytool
962 local f=$DIR/$tdir/$tfile
963 local fid=$(copy_file /etc/hosts $f)
964 $LFS hsm_set --noarchive $f
965 $LFS hsm_archive $f && error "archive a noarchive file must fail"
969 run_test 10c "Check forbidden archive"
972 # test needs a running copytool
976 local f=$DIR/$tdir/$tfile
977 local fid=$(copy_file /etc/hosts $f)
978 $LFS hsm_archive $f || error "cannot archive $f"
979 wait_request_state $fid ARCHIVE SUCCEED
981 local ar=$(get_hsm_archive_id $f)
982 local dflt=$(get_hsm_param default_archive_id)
983 [[ $ar == $dflt ]] ||
984 error "archived file is not on default archive: $ar != $dflt"
988 run_test 10d "Archive a file on the default archive id"
992 copy2archive /etc/hosts $tdir/$tfile
993 local f=$DIR/$tdir/$tfile
995 import_file $tdir/$tfile $f
996 echo -n "Verifying released state: "
997 check_hsm_flags $f "0x0000000d"
999 local LSZ=$(stat -c "%s" $f)
1000 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1002 echo "Verifying imported size $LSZ=$ASZ"
1003 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1004 echo -n "Verifying released pattern: "
1005 local PTRN=$($GETSTRIPE -L $f)
1007 [[ $PTRN == 80000001 ]] || error "Is not released"
1008 local fid=$(path2fid $f)
1009 echo "Verifying new fid $fid in archive"
1011 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1012 error "fid $fid not in archive $HSM_ARCHIVE"
1014 run_test 11a "Import a file"
1017 # test needs a running copytool
1021 local f=$DIR/$tdir/$tfile
1022 local fid=$(copy_file /etc/hosts $f)
1023 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1024 error "hsm_archive failed"
1025 wait_request_state $fid ARCHIVE SUCCEED
1027 local FILE_HASH=$(md5sum $f)
1032 echo "$FILE_HASH" | md5sum -c
1034 [[ $? -eq 0 ]] || error "Restored file differs"
1038 run_test 11b "Import a deleted file using its FID"
1041 # test needs a running copytool
1045 copy2archive /etc/hosts $tdir/$tfile
1047 local f=$DIR/$tdir/$tfile
1048 import_file $tdir/$tfile $f
1049 local f2=$DIR2/$tdir/$tfile
1050 echo "Verifying released state: "
1051 check_hsm_flags $f2 "0x0000000d"
1053 local fid=$(path2fid $f2)
1054 $LFS hsm_restore $f2
1055 wait_request_state $fid RESTORE SUCCEED
1057 echo "Verifying file state: "
1058 check_hsm_flags $f2 "0x00000009"
1060 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1062 [[ $? -eq 0 ]] || error "Restored file differs"
1066 run_test 12a "Restore an imported file explicitly"
1069 # test needs a running copytool
1073 copy2archive /etc/hosts $tdir/$tfile
1075 local f=$DIR/$tdir/$tfile
1076 import_file $tdir/$tfile $f
1077 echo "Verifying released state: "
1078 check_hsm_flags $f "0x0000000d"
1080 cat $f > /dev/null || error "File read failed"
1082 echo "Verifying file state after restore: "
1083 check_hsm_flags $f "0x00000009"
1085 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1087 [[ $? -eq 0 ]] || error "Restored file differs"
1091 run_test 12b "Restore an imported file implicitly"
1094 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1096 # test needs a running copytool
1100 local f=$DIR/$tdir/$tfile
1101 $LFS setstripe -c 2 $f
1102 local fid=$(make_large_for_striping $f)
1103 local FILE_CRC=$(md5sum $f)
1105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1106 wait_request_state $fid ARCHIVE SUCCEED
1107 $LFS hsm_release $f || error "release $f failed"
1109 echo "$FILE_CRC" | md5sum -c
1111 [[ $? -eq 0 ]] || error "Restored file differs"
1115 run_test 12c "Restore a file with stripe of 2"
1118 # test needs a running copytool
1123 local f=$DIR/$tdir/$tfile
1124 local fid=$(copy_file /etc/hosts $f)
1125 $LFS hsm_restore $f || error "restore of non archived file failed"
1126 local cnt=$(get_request_count $fid RESTORE)
1127 [[ "$cnt" == "0" ]] ||
1128 error "restore non archived must not make a request"
1129 $LFS hsm_archive $f ||
1130 error "archive request failed"
1131 wait_request_state $fid ARCHIVE SUCCEED
1132 $LFS hsm_restore $f ||
1133 error "restore of non released file failed"
1134 local cnt=$(get_request_count $fid RESTORE)
1135 [[ "$cnt" == "0" ]] ||
1136 error "restore a non dirty file must not make a request"
1140 run_test 12d "Restore of a non archived, non released file must work"\
1141 " without doing request"
1144 # test needs a running copytool
1147 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1148 local f=$DIR/$tdir/$tfile
1149 local fid=$(copy_file /etc/hosts $f)
1150 $LFS hsm_archive $f || error "archive request failed"
1151 wait_request_state $fid ARCHIVE SUCCEED
1154 cat /etc/hosts >> $f
1158 $LFS hsm_restore $f && error "restore a dirty file must fail"
1162 run_test 12e "Check forbidden restore"
1165 # test needs a running copytool
1169 local f=$DIR/$tdir/$tfile
1170 local fid=$(copy_file /etc/hosts $f)
1172 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1173 wait_request_state $fid ARCHIVE SUCCEED
1174 $LFS hsm_release $f || error "release of $f failed"
1176 wait_request_state $fid RESTORE SUCCEED
1178 echo -n "Verifying file state: "
1179 check_hsm_flags $f "0x00000009"
1181 diff -q /etc/hosts $f
1183 [[ $? -eq 0 ]] || error "Restored file differs"
1187 run_test 12f "Restore a released file explicitly"
1190 # test needs a running copytool
1194 local f=$DIR/$tdir/$tfile
1195 local fid=$(copy_file /etc/hosts $f)
1197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1198 wait_request_state $fid ARCHIVE SUCCEED
1199 $LFS hsm_release $f || error "release of $f failed"
1201 diff -q /etc/hosts $f
1204 # we check we had a restore done
1205 wait_request_state $fid RESTORE SUCCEED
1207 [[ $st -eq 0 ]] || error "Restored file differs"
1211 run_test 12g "Restore a released file implicitly"
1214 needclients 2 || return 0
1216 # test needs a running copytool
1220 local f=$DIR/$tdir/$tfile
1221 local fid=$(copy_file /etc/hosts $f)
1223 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1224 wait_request_state $fid ARCHIVE SUCCEED
1225 $LFS hsm_release $f || error "release of $f failed"
1227 do_node $CLIENT2 diff -q /etc/hosts $f
1230 # we check we had a restore done
1231 wait_request_state $fid RESTORE SUCCEED
1233 [[ $st -eq 0 ]] || error "Restored file differs"
1237 run_test 12h "Restore a released file implicitly from a second node"
1240 # test needs a running copytool
1244 local f=$DIR/$tdir/$tfile
1245 local fid=$(copy_file /etc/passwd $f)
1246 $LFS hsm_archive $f || error "archive of $f failed"
1247 wait_request_state $fid ARCHIVE SUCCEED
1249 $LFS hsm_release $f || error "release of $f failed"
1253 [[ $? -eq 0 ]] || error "Restored file differs"
1257 run_test 12m "Archive/release/implicit restore"
1260 # test needs a running copytool
1264 copy2archive /etc/hosts $tdir/$tfile
1266 local f=$DIR/$tdir/$tfile
1267 import_file $tdir/$tfile $f
1269 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1270 error "Restored file differs"
1272 $LFS hsm_release $f || error "release of $f failed"
1276 run_test 12n "Import/implicit restore/release"
1279 # test needs a running copytool
1283 local f=$DIR/$tdir/$tfile
1284 local fid=$(copy_file /etc/hosts $f)
1286 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1287 wait_request_state $fid ARCHIVE SUCCEED
1288 $LFS hsm_release $f || error "release of $f failed"
1290 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1291 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1293 # set no retry action mode
1296 diff -q /etc/hosts $f
1299 # we check we had a restore failure
1300 wait_request_state $fid RESTORE FAILED
1302 [[ $st -eq 0 ]] && error "Restore must fail"
1304 # remove no retry action mode
1307 # check file is still released
1308 check_hsm_flags $f "0x0000000d"
1310 # retry w/o failure injection
1311 do_facet $SINGLEMDS lctl set_param fail_loc=0
1313 # to be sure previous RESTORE result is gone
1315 wait_for_grace_delay
1317 diff -q /etc/hosts $f
1320 # we check we had a restore done
1321 wait_request_state $fid RESTORE SUCCEED
1323 [[ $st -eq 0 ]] || error "Restored file differs"
1327 run_test 12o "Layout-swap failure during Restore leaves file released"
1330 # test needs a running copytool
1333 local ARC_SUBDIR="import.orig"
1337 # populate directory to be imported
1338 for d in $(seq 1 10); do
1339 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1340 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1341 for f in $(seq 1 10); do
1342 CURR_FILE="$CURR_DIR/$tfile.$f"
1343 # write file-specific data
1344 do_facet $SINGLEAGT \
1345 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1346 "file=$CURR_FILE > $CURR_FILE"
1350 import_file "$ARC_SUBDIR" $DIR/$tdir
1351 # diff lustre content and origin (triggers file restoration)
1352 # there must be 10x10 identical files, and no difference
1353 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1354 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1355 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1356 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1358 [ $cnt_diff -eq 0 ] ||
1359 error "$cnt_diff imported files differ from read data"
1360 [ $cnt_ok -eq 100 ] ||
1361 error "not enough identical files ($cnt_ok != 100)"
1365 run_test 13 "Recursively import and restore a directory"
1368 # test needs a running copytool
1373 local f=$DIR/$tdir/$tfile
1374 local fid=$(make_small $f)
1375 local sum=$(md5sum $f | awk '{print $1}')
1376 $LFS hsm_archive $f || error "could not archive file"
1377 wait_request_state $fid ARCHIVE SUCCEED
1381 # create released file (simulate llapi_hsm_import call)
1383 local fid2=$(path2fid $f)
1384 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1385 $LFS hsm_release $f || error "could not release file"
1387 # rebind the archive to the newly created file
1388 echo "rebind $fid to $fid2"
1390 do_facet $SINGLEAGT \
1391 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1392 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1394 # restore file and compare md5sum
1395 local sum2=$(md5sum $f | awk '{print $1}')
1397 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1401 run_test 14 "Rebind archived file to a new fid"
1404 # test needs a running copytool
1409 local f=$DIR/$tdir/$tfile
1411 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1415 for i in $(seq 1 $count); do
1416 fids[$i]=$(make_small $f.$i)
1417 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1418 $LFS hsm_archive $f.$i || error "could not archive file"
1420 wait_all_done $(($count*60))
1424 for i in $(seq 1 $count); do
1427 local fid2=$(path2fid $f.$i)
1428 # add the rebind operation to the list
1429 echo ${fids[$i]} $fid2 >> $tmpfile
1431 # set it released (simulate llapi_hsm_import call)
1432 $LFS hsm_set --archived --exists $f.$i ||
1433 error "could not force hsm flags"
1434 $LFS hsm_release $f.$i || error "could not release file"
1436 nl=$(wc -l < $tmpfile)
1437 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1439 echo "rebind list of files"
1440 do_facet $SINGLEAGT \
1441 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1442 --rebind $tmpfile $DIR" || error "could not rebind file list"
1444 # restore files and compare md5sum
1445 for i in $(seq 1 $count); do
1446 local sum2=$(md5sum $f.$i | awk '{print $1}')
1447 [[ $sum2 == ${sums[$i]} ]] ||
1448 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1454 run_test 15 "Rebind a list of files"
1457 # test needs a running copytool
1461 # create a known size file so we can verify transfer speed
1464 dd if=/dev/zero of=$ref bs=1M count=20
1467 local f=$DIR/$tdir/$tfile
1468 local fid=$(copy_file $ref $f)
1470 local start=$(date +%s)
1472 wait_request_state $fid ARCHIVE SUCCEED
1473 local end=$(date +%s)
1474 local duration=$((end - start))
1476 [[ $duration -ge $goal ]] ||
1477 error "Transfer is too fast $duration < $goal"
1481 run_test 16 "Test CT bandwith control option"
1486 local f=$DIR/$tdir/$tfile
1487 touch $f || error "touch $f failed"
1489 # Could not release a non-archived file
1490 $LFS hsm_release $f && error "release should not succeed"
1492 # For following tests, we must test them with HS_ARCHIVED set
1493 $LFS hsm_set --exists --archived $f || error "could not add flag"
1495 # Could not release a file if no-release is set
1496 $LFS hsm_set --norelease $f || error "could not add flag"
1497 $LFS hsm_release $f && error "release should not succeed"
1498 $LFS hsm_clear --norelease $f || error "could not remove flag"
1500 # Could not release a file if lost
1501 $LFS hsm_set --lost $f || error "could not add flag"
1502 $LFS hsm_release $f && error "release should not succeed"
1503 $LFS hsm_clear --lost $f || error "could not remove flag"
1505 # Could not release a file if dirty
1506 $LFS hsm_set --dirty $f || error "could not add flag"
1507 $LFS hsm_release $f && error "release should not succeed"
1508 $LFS hsm_clear --dirty $f || error "could not remove flag"
1510 run_test 20 "Release is not permitted"
1513 # test needs a running copytool
1517 local f=$DIR/$tdir/test_release
1519 # Create a file and check its states
1520 local fid=$(make_small $f)
1521 check_hsm_flags $f "0x00000000"
1523 $LFS hsm_archive $f || error "could not archive file"
1524 wait_request_state $fid ARCHIVE SUCCEED
1526 [ $(stat -c "%b" $f) -ne "1" ] || error "wrong block number"
1527 local sz=$(stat -c "%s" $f)
1528 [ $sz -ne "0" ] || error "file size should not be zero"
1530 # Release and check states
1531 $LFS hsm_release $f || error "could not release file"
1532 check_hsm_flags $f "0x0000000d"
1534 [ $(stat -c "%b" $f) -eq "1" ] || error "wrong block number"
1535 [ $(stat -c "%s" $f) -eq $sz ] || error "wrong file size"
1537 # Check we can release an file without stripe info
1541 check_hsm_flags $f "0x00000000"
1542 $LFS hsm_archive $f || error "could not archive file"
1543 wait_request_state $fid ARCHIVE SUCCEED
1545 # Release and check states
1546 $LFS hsm_release $f || error "could not release file"
1547 check_hsm_flags $f "0x0000000d"
1549 # Release again a file that is already released is OK
1550 $LFS hsm_release $f || fail "second release should succeed"
1551 check_hsm_flags $f "0x0000000d"
1555 run_test 21 "Simple release tests"
1558 # test needs a running copytool
1563 local f=$DIR/$tdir/test_release
1564 local swap=$DIR/$tdir/test_swap
1566 # Create a file and check its states
1567 local fid=$(make_small $f)
1568 check_hsm_flags $f "0x00000000"
1570 $LFS hsm_archive $f || error "could not archive file"
1571 wait_request_state $fid ARCHIVE SUCCEED
1573 # Release and check states
1574 $LFS hsm_release $f || error "could not release file"
1575 check_hsm_flags $f "0x0000000d"
1578 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1583 run_test 22 "Could not swap a release file"
1586 # test needs a running copytool
1591 local f=$DIR/$tdir/test_mtime
1593 # Create a file and check its states
1594 local fid=$(make_small $f)
1595 check_hsm_flags $f "0x00000000"
1597 $LFS hsm_archive $f || error "could not archive file"
1598 wait_request_state $fid ARCHIVE SUCCEED
1600 # Set modification time in the past
1601 touch -m -a -d @978261179 $f
1603 # Release and check states
1604 $LFS hsm_release $f || error "could not release file"
1605 check_hsm_flags $f "0x0000000d"
1607 local MTIME=$(stat -c "%Y" $f)
1608 local ATIME=$(stat -c "%X" $f)
1609 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1610 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1614 run_test 23 "Release does not change a/mtime (utime)"
1617 local file=$DIR/$tdir/$tfile
1626 # test needs a running copytool
1631 fid=$(make_small $file)
1633 # Create a file and check its states
1634 check_hsm_flags $file "0x00000000"
1636 # Ensure atime is less than mtime and ctime.
1640 atime0=$(stat -c "%X" $file)
1641 mtime0=$(stat -c "%Y" $file)
1642 ctime0=$(stat -c "%Z" $file)
1644 [ $atime0 -lt $mtime0 ] ||
1645 error "atime $atime0 is not less than mtime $mtime0"
1647 [ $atime0 -lt $ctime0 ] ||
1648 error "atime $atime0 is not less than ctime $ctime0"
1650 # Archive should not change any timestamps.
1651 $LFS hsm_archive $file || error "cannot archive '$file'"
1652 wait_request_state $fid ARCHIVE SUCCEED
1654 atime1=$(stat -c "%X" $file)
1655 mtime1=$(stat -c "%Y" $file)
1656 ctime1=$(stat -c "%Z" $file)
1658 [ $atime0 -eq $atime1 ] ||
1659 error "archive changed atime from $atime0 to $atime1"
1661 [ $mtime0 -eq $mtime1 ] ||
1662 error "archive changed mtime from $mtime0 to $mtime1"
1664 [ $ctime0 -eq $ctime1 ] ||
1665 error "archive changed ctime from $ctime0 to $ctime1"
1667 # Release should not change any timestamps.
1668 $LFS hsm_release $file || error "cannot release '$file'"
1669 check_hsm_flags $file "0x0000000d"
1671 atime1=$(stat -c "%X" $file)
1672 mtime1=$(stat -c "%Y" $file)
1673 ctime1=$(stat -c "%Z" $file)
1675 [ $atime0 -eq $atime1 ] ||
1676 error "release changed atime from $atime0 to $atime1"
1678 [ $mtime0 -eq $mtime1 ] ||
1679 error "release changed mtime from $mtime0 to $mtime1"
1681 [ $ctime0 -eq $ctime1 ] ||
1682 error "release changed ctime from $ctime0 to $ctime1"
1684 # Restore should not change atime or mtime and should not
1686 $LFS hsm_restore $file
1687 wait_request_state $fid RESTORE SUCCEED
1689 atime1=$(stat -c "%X" $file)
1690 mtime1=$(stat -c "%Y" $file)
1691 ctime1=$(stat -c "%Z" $file)
1693 [ $atime0 -eq $atime1 ] ||
1694 error "restore changed atime from $atime0 to $atime1"
1696 [ $mtime0 -eq $mtime1 ] ||
1697 error "restore changed mtime from $mtime0 to $mtime1"
1699 [ $ctime0 -le $ctime1 ] ||
1700 error "restore changed ctime from $ctime0 to $ctime1"
1704 # Once more, after unmount and mount.
1705 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1706 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1708 atime1=$(stat -c "%X" $file)
1709 mtime1=$(stat -c "%Y" $file)
1710 ctime1=$(stat -c "%Z" $file)
1712 [ $atime0 -eq $atime1 ] ||
1713 error "remount changed atime from $atime0 to $atime1"
1715 [ $mtime0 -eq $mtime1 ] ||
1716 error "remount changed mtime from $mtime0 to $mtime1"
1718 [ $ctime0 -le $ctime1 ] ||
1719 error "remount changed ctime from $ctime0 to $ctime1"
1721 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1724 local file=$DIR/$tdir/$tfile
1730 # Test needs a running copytool.
1734 # Check that root can do HSM actions on a ordinary user's file.
1736 fid=$(make_small $file)
1737 sum0=$(md5sum $file)
1739 chown $RUNAS_ID:$RUNAS_GID $file ||
1740 error "cannot chown '$file' to '$RUNAS_ID'"
1742 chmod ugo-w $DIR/$tdir ||
1743 error "cannot chmod '$DIR/$tdir'"
1745 $LFS hsm_archive $file
1746 wait_request_state $fid ARCHIVE SUCCEED
1748 $LFS hsm_release $file
1749 check_hsm_flags $file "0x0000000d"
1751 $LFS hsm_restore $file
1752 wait_request_state $fid RESTORE SUCCEED
1754 # Check that ordinary user can get HSM state.
1755 $RUNAS $LFS hsm_state $file ||
1756 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1758 $LFS hsm_release $file
1759 check_hsm_flags $file "0x0000000d"
1761 # Check that ordinary user can accessed released file.
1762 sum1=$($RUNAS md5sum $file) ||
1763 error "user '$RUNAS_ID' cannot read '$file'"
1765 [ "$sum0" == "$sum1" ] ||
1766 error "md5sum mismatch for '$file'"
1770 run_test 24b "root can archive, release, and restore user files"
1772 cleanup_test_24c() {
1774 set_hsm_param user_request_mask RESTORE
1775 set_hsm_param group_request_mask RESTORE
1776 set_hsm_param other_request_mask RESTORE
1780 local file=$DIR/$tdir/$tfile
1781 local action=archive
1786 # test needs a running copytool
1791 # Save the default masks and check that cleanup_24c will
1792 # restore the request masks correctly.
1793 user_save=$(get_hsm_param user_request_mask)
1794 group_save=$(get_hsm_param group_request_mask)
1795 other_save=$(get_hsm_param other_request_mask)
1797 [ "$user_save" == RESTORE ] ||
1798 error "user_request_mask is '$user_save' expected 'RESTORE'"
1799 [ "$group_save" == RESTORE ] ||
1800 error "group_request_mask is '$group_save' expected 'RESTORE'"
1801 [ "$other_save" == RESTORE ] ||
1802 error "other_request_mask is '$other_save' expected 'RESTORE'"
1804 trap cleanup_test_24c EXIT
1809 chown $RUNAS_ID:nobody $file ||
1810 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1812 set_hsm_param user_request_mask ""
1813 $RUNAS $LFS hsm_$action $file &&
1814 error "$action by user should fail"
1816 set_hsm_param user_request_mask $action
1817 $RUNAS $LFS hsm_$action $file ||
1818 error "$action by user should succeed"
1823 chown nobody:$RUNAS_GID $file ||
1824 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1826 set_hsm_param group_request_mask ""
1827 $RUNAS $LFS hsm_$action $file &&
1828 error "$action by group should fail"
1830 set_hsm_param group_request_mask $action
1831 $RUNAS $LFS hsm_$action $file ||
1832 error "$action by group should succeed"
1837 chown nobody:nobody $file ||
1838 error "cannot chown '$file' to 'nobody:nobody'"
1840 set_hsm_param other_request_mask ""
1841 $RUNAS $LFS hsm_$action $file &&
1842 error "$action by other should fail"
1844 set_hsm_param other_request_mask $action
1845 $RUNAS $LFS hsm_$action $file ||
1846 error "$action by other should succeed"
1851 run_test 24c "check that user,group,other request masks work"
1853 cleanup_test_24d() {
1855 mount -o remount,rw $MOUNT2
1859 local file1=$DIR/$tdir/$tfile
1860 local file2=$DIR2/$tdir/$tfile
1868 fid1=$(make_small $file1)
1870 trap cleanup_test_24d EXIT
1872 mount -o remount,ro $MOUNT2
1874 fid2=$(path2fid $file2)
1875 [ "$fid1" == "$fid2" ] ||
1876 error "FID mismatch '$fid1' != '$fid2'"
1878 $LFS hsm_archive $file2 &&
1879 error "archive should fail on read-only mount"
1880 check_hsm_flags $file1 "0x00000000"
1882 $LFS hsm_archive $file1
1883 wait_request_state $fid1 ARCHIVE SUCCEED
1885 $LFS hsm_release $file1
1886 $LFS hsm_restore $file2
1887 wait_request_state $fid1 RESTORE SUCCEED
1889 $LFS hsm_release $file1 || error "cannot release '$file1'"
1890 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1892 $LFS hsm_release $file2 &&
1893 error "release should fail on read-only mount"
1898 run_test 24d "check that read-only mounts are respected"
1901 # test needs a running copytool
1905 copy2archive /etc/hosts $tdir/$tfile
1907 local f=$DIR/$tdir/$tfile
1909 import_file $tdir/$tfile $f
1911 $LFS hsm_set --lost $f
1916 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1920 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1921 " (Operation not permitted)"
1924 # test needs a running copytool
1929 local f=$DIR/$tdir/$tfile
1930 local fid=$(copy_file /etc/passwd $f)
1932 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1933 wait_request_state $fid ARCHIVE SUCCEED
1936 $LFS hsm_set --lost $f
1940 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1944 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1945 " (Operation not permitted)"
1948 # test needs a running copytool
1952 local f=$DIR/$tdir/$tfile
1953 local fid=$(make_large_for_progress $f)
1954 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1955 wait_request_state $fid ARCHIVE SUCCEED
1958 wait_request_state $fid REMOVE SUCCEED
1960 check_hsm_flags $f "0x00000000"
1964 run_test 26 "Remove the archive of a valid file"
1967 # test needs a running copytool
1971 make_archive $tdir/$tfile
1972 local f=$DIR/$tdir/$tfile
1973 import_file $tdir/$tfile $f
1974 local fid=$(path2fid $f)
1978 [[ $? != 0 ]] || error "Remove of a released file should fail"
1982 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
1985 # test needs a running copytool
1989 local f=$DIR/$tdir/$tfile
1990 local fid=$(make_large_for_progress $f)
1991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1992 wait_request_state $fid ARCHIVE SUCCEED
1997 [[ $? != 0 ]] || error "Remove of a released file should fail"
2001 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2004 # test needs a running copytool
2008 local f=$DIR/$tdir/$tfile
2009 local fid=$(make_large_for_progress $f)
2010 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2011 wait_request_state $fid ARCHIVE SUCCEED
2020 wait_request_state $fid REMOVE SUCCEED
2024 run_test 28 "Concurrent archive/file remove"
2027 # restore at exec cannot work on agent node (because of Linux kernel
2028 # protection of executables)
2029 needclients 2 || return 0
2031 # test needs a running copytool
2035 copy2archive /bin/true $tdir/$tfile
2037 local f=$DIR/$tdir/true
2038 import_file $tdir/$tfile $f
2040 local fid=$(path2fid $f)
2042 # set no retry action mode
2048 # remove no try action mode
2052 [[ $st == 0 ]] || error "Failed to exec a released file"
2056 run_test 30a "Restore at exec (import case)"
2059 # restore at exec cannot work on agent node (because of Linux kernel
2060 # protection of executables)
2061 needclients 2 || return 0
2063 # test needs a running copytool
2067 local f=$DIR/$tdir/true
2068 local fid=$(copy_file /bin/true $f)
2070 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2071 wait_request_state $fid ARCHIVE SUCCEED
2074 # set no retry action mode
2080 # remove no try action mode
2084 [[ $st == 0 ]] || error "Failed to exec a released file"
2088 run_test 30b "Restore at exec (release case)"
2091 needclients 2 || return 0
2093 # test needs a running copytool
2097 local f=$DIR/$tdir/SLEEP
2098 local fid=$(copy_file /bin/sleep $f)
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2101 wait_request_state $fid ARCHIVE SUCCEED
2103 check_hsm_flags $f "0x0000000d"
2104 # set no retry action mode
2106 do_node $CLIENT2 "$f 10" &
2110 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2112 [[ $? == 0 ]] || error "Execution failed during run"
2114 [[ $? == 0 ]] || error "Binary overwritten during exec"
2117 # remove no try action mode
2119 check_hsm_flags $f "0x00000009"
2123 run_test 30c "Update during exec of released file must fail"
2125 restore_and_check_size() {
2128 local s=$(stat -c "%s" $f)
2130 local st=$(get_hsm_flags $f)
2134 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2136 n=$(stat -c "%s" $f)
2137 # we echo in both cases to show stat is not
2139 if [[ $n != $s ]]; then
2140 echo "size seen is $n != $s"
2143 echo "size seen is right: $n == $s"
2145 st=$(get_hsm_flags $f)
2149 if [[ $cpt -lt 10 ]]; then
2152 echo " restore is too long"
2153 wait_request_state $fid RESTORE SUCCEED
2159 # test needs a running copytool
2164 make_archive $tdir/$tfile
2165 local f=$DIR/$tdir/$tfile
2166 import_file $tdir/$tfile $f
2167 local fid=$($LFS path2fid $f)
2168 HSM_ARCHIVE_PURGE=false copytool_setup
2170 restore_and_check_size $f $fid
2173 [[ $err -eq 0 ]] || error "File size changed during restore"
2177 run_test 31a "Import a large file and check size during restore"
2181 # test needs a running copytool
2186 local f=$DIR/$tdir/$tfile
2187 local fid=$(make_large_for_progress $f)
2188 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2189 wait_request_state $fid ARCHIVE SUCCEED
2192 restore_and_check_size $f $fid
2195 [[ $err -eq 0 ]] || error "File size changed during restore"
2199 run_test 31b "Restore a large unaligned file and check size during restore"
2202 # test needs a running copytool
2207 local f=$DIR/$tdir/$tfile
2208 local fid=$(make_large_for_progress_aligned $f)
2209 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2210 wait_request_state $fid ARCHIVE SUCCEED
2213 restore_and_check_size $f $fid
2216 [[ $err -eq 0 ]] || error "File size changed during restore"
2220 run_test 31c "Restore a large aligned file and check size during restore"
2223 # test needs a running copytool
2228 local f=$DIR/$tdir/$tfile
2229 local fid=$(make_large_for_progress $f)
2230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2231 wait_request_state $fid ARCHIVE SUCCEED
2234 md5sum $f >/dev/null &
2236 wait_request_state $fid RESTORE STARTED
2241 # Check restore trigger process was killed
2242 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2246 wait_request_state $fid RESTORE CANCELED
2247 wait_request_state $fid CANCEL SUCCEED
2250 error "Cannot kill process waiting for restore ($killed)"
2254 run_test 33 "Kill a restore waiting process"
2257 # test needs a running copytool
2262 local f=$DIR/$tdir/$tfile
2263 local fid=$(make_large_for_progress $f)
2264 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2265 wait_request_state $fid ARCHIVE SUCCEED
2268 md5sum $f >/dev/null &
2270 wait_request_state $fid RESTORE STARTED
2272 rm $f || error "rm $f failed"
2273 # rm must not block during restore
2274 wait_request_state $fid RESTORE STARTED
2276 wait_request_state $fid RESTORE SUCCEED
2277 # check md5sum pgm finished
2278 local there=$(ps -o pid,comm hp $pid >/dev/null)
2279 [[ -z $there ]] || error "Restore initiator does not exit"
2281 local rc=$(wait $pid)
2282 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2286 run_test 34 "Remove file during restore"
2289 # test needs a running copytool
2294 local f=$DIR/$tdir/$tfile
2295 local f1=$DIR/$tdir/$tfile-1
2296 local fid=$(make_large_for_progress $f)
2297 local fid1=$(copy_file /etc/passwd $f1)
2298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2299 wait_request_state $fid ARCHIVE SUCCEED
2302 md5sum $f >/dev/null &
2304 wait_request_state $fid RESTORE STARTED
2306 mv $f1 $f || error "mv $f1 $f failed"
2307 # mv must not block during restore
2308 wait_request_state $fid RESTORE STARTED
2310 wait_request_state $fid RESTORE SUCCEED
2311 # check md5sum pgm finished
2312 local there=$(ps -o pid,comm hp $pid >/dev/null)
2313 [[ -z $there ]] || error "Restore initiator does not exit"
2315 local rc=$(wait $pid)
2316 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2319 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2323 run_test 35 "Overwrite file during restore"
2326 # test needs a running copytool
2331 local f=$DIR/$tdir/$tfile
2332 local fid=$(make_large_for_progress $f)
2333 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2334 wait_request_state $fid ARCHIVE SUCCEED
2337 md5sum $f >/dev/null &
2339 wait_request_state $fid RESTORE STARTED
2342 # rm must not block during restore
2343 wait_request_state $fid RESTORE STARTED
2345 wait_request_state $fid RESTORE SUCCEED
2346 # check md5sum pgm finished
2347 local there=$(ps -o pid,comm hp $pid >/dev/null)
2349 error "Restore initiator does not exit"
2351 local rc=$(wait $pid)
2353 error "Restore initiator failed with $rc"
2357 run_test 36 "Move file during restore"
2364 for n in $(seq 1 $count); do
2365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2367 echo "$count archive requests submitted"
2371 local stream_count=4
2372 local file_count=100
2374 local f=$DIR/$tdir/$tfile
2379 for i in $(seq 1 $file_count); do
2380 for p in $(seq 1 $stream_count); do
2381 fid=$(copy_file /etc/hosts $f.$p.$i)
2384 # force copytool to use a local/temp archive dir to ensure best
2385 # performance vs remote/NFS mounts used in auto-tests
2386 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2389 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2391 # to be sure wait_all_done will not be mislead by previous tests
2393 wait_for_grace_delay
2395 # start archive streams in background (archive files in parallel)
2396 for p in $(seq 1 $stream_count); do
2397 multi_archive $f.$p $file_count &
2400 echo -n "Wait for all requests being enqueued..."
2406 run_test 40 "Parallel archive requests"
2409 # test needs a running copytool
2413 local f=$DIR/$tdir/$tfile
2414 local fid=$(copy_file /etc/motd $f 1)
2416 $LFS hsm_archive $f || error "could not archive file"
2417 wait_request_state $fid ARCHIVE SUCCEED
2418 check_hsm_flags $f "0x00000009"
2420 multiop_bg_pause $f O_c || error "multiop failed"
2424 client_up || client_up || true
2426 kill -USR1 $MULTIPID
2427 wait $MULTIPID || error "multiop close failed"
2429 check_hsm_flags $f "0x0000000b"
2433 run_test 52 "Opened for write file on an evicted client should be set dirty"
2436 # test needs a running copytool
2440 local f=$DIR/$tdir/$tfile
2441 local fid=$(copy_file /etc/motd $f 1)
2443 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2444 error "could not archive file"
2445 wait_request_state $fid ARCHIVE SUCCEED
2446 check_hsm_flags $f "0x00000009"
2448 multiop_bg_pause $f o_c || error "multiop failed"
2452 client_up || client_up || true
2454 kill -USR1 $MULTIPID
2455 wait $MULTIPID || error "multiop close failed"
2457 check_hsm_flags $f "0x00000009"
2461 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2464 # test needs a running copytool
2468 local f=$DIR/$tdir/$tfile
2469 local fid=$(make_small $f)
2471 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2472 error "could not archive file"
2473 wait_request_state $fid ARCHIVE STARTED
2475 check_hsm_flags $f "0x00000001"
2477 # Avoid coordinator resending this request as soon it has failed.
2482 wait_request_state $fid ARCHIVE FAILED
2484 check_hsm_flags $f "0x00000003"
2489 run_test 54 "Write during an archive cancels it"
2492 # test needs a running copytool
2496 local f=$DIR/$tdir/$tfile
2497 local fid=$(make_small $f)
2499 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2500 error "could not archive file"
2501 wait_request_state $fid ARCHIVE STARTED
2503 check_hsm_flags $f "0x00000001"
2505 # Avoid coordinator resending this request as soon it has failed.
2508 $TRUNCATE $f 1024 || error "truncate failed"
2510 wait_request_state $fid ARCHIVE FAILED
2512 check_hsm_flags $f "0x00000003"
2517 run_test 55 "Truncate during an archive cancels it"
2520 # test needs a running copytool
2524 local f=$DIR/$tdir/$tfile
2525 local fid=$(make_large_for_progress $f)
2527 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2528 error "could not archive file"
2529 wait_request_state $fid ARCHIVE STARTED
2531 check_hsm_flags $f "0x00000001"
2533 # Change metadata and sync to be sure we are not changing only
2538 wait_request_state $fid ARCHIVE SUCCEED
2540 check_hsm_flags $f "0x00000009"
2544 run_test 56 "Setattr during an archive is ok"
2547 # Need one client for I/O, one for request
2548 needclients 2 || return 0
2550 # test needs a running copytool
2554 local f=$DIR/$tdir/test_archive_remote
2555 # Create a file on a remote node
2556 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2557 "count=2 conv=fsync"
2560 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2561 error "hsm_archive failed"
2562 local fid=$(path2fid $f)
2563 wait_request_state $fid ARCHIVE SUCCEED
2565 # Release and implicit restore it
2566 do_node $CLIENT2 "$LFS hsm_release $f" ||
2567 error "hsm_release failed"
2568 do_node $CLIENT2 "md5sum $f" ||
2569 error "hsm_restore failed"
2571 wait_request_state $fid RESTORE SUCCEED
2575 run_test 57 "Archive a file with dirty cache on another node"
2577 truncate_released_file() {
2581 local sz=$(stat -c %s $src_file)
2582 local f=$DIR/$tdir/$tfile
2583 local fid=$(copy_file $1 $f)
2587 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2588 error "could not archive file"
2589 wait_request_state $fid ARCHIVE SUCCEED
2591 $LFS hsm_release $f || error "could not release file"
2593 $TRUNCATE $f $trunc_to || error "truncate failed"
2596 local sz1=$(stat -c %s $f)
2597 [[ $sz1 == $trunc_to ]] ||
2598 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2601 check_hsm_flags $f "0x0000000b"
2603 local state=$(get_request_state $fid RESTORE)
2604 [[ "$state" == "SUCCEED" ]] ||
2605 error "truncate $sz does not trig restore, state = $state"
2607 $TRUNCATE $ref $trunc_to
2608 cmp $ref $f || error "file data wrong after truncate"
2614 # test needs a running copytool
2619 local sz=$(stat -c %s /etc/passwd)
2621 echo "truncate up from $sz to $((sz*2))"
2622 truncate_released_file /etc/passwd $((sz*2))
2624 echo "truncate down from $sz to $((sz/2))"
2625 truncate_released_file /etc/passwd $((sz/2))
2627 echo "truncate to 0"
2628 truncate_released_file /etc/passwd 0
2632 run_test 58 "Truncate a released file will trigger restore"
2635 # This test validates the fix for LU-4512. Ensure that the -u
2636 # option changes the progress reporting interval from the default
2637 # (30 seconds) to the user-specified interval.
2639 local progress_timeout=$((interval * 3))
2641 # test needs a new running copytool
2643 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2646 local f=$DIR/$tdir/$tfile
2647 local fid=$(make_large_for_progress $f)
2649 local start_at=$(date +%s)
2650 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2651 error "could not archive file"
2654 local mdt=${MDT_PREFIX}${mdtidx}
2655 local mds=mds$((mdtidx + 1))
2657 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2658 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2664 echo -n "Expecting a progress update within $progress_timeout seconds... "
2666 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2667 if [ $RESULT -gt 0 ]; then
2668 echo "$RESULT bytes copied in $WAIT seconds."
2670 elif [ $WAIT -ge $progress_timeout ]; then
2671 error "Timed out waiting for progress update!"
2673 WAIT=$((WAIT + sleep))
2677 local finish_at=$(date +%s)
2678 local elapsed=$((finish_at - start_at))
2680 # Ensure that the progress update occurred within the expected window.
2681 if [ $elapsed -lt $interval ]; then
2682 error "Expected progress update after at least $interval seconds"
2688 run_test 60 "Changing progress update interval from default"
2691 # test needs a new running copytool
2693 copytool_monitor_setup
2694 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2696 # Just start and stop the copytool to generate events.
2700 local REGISTER_EVENT
2701 local UNREGISTER_EVENT
2702 while read event; do
2703 local parsed=$(parse_json_event "$event")
2704 if [ -z "$parsed" ]; then
2705 error "Copytool sent malformed event: $event"
2709 if [ $event_type == "REGISTER" ]; then
2710 REGISTER_EVENT=$event
2711 elif [ $event_type == "UNREGISTER" ]; then
2712 UNREGISTER_EVENT=$event
2714 done < <(echo $"$(get_copytool_event_log)")
2716 if [ -z "$REGISTER_EVENT" ]; then
2717 error "Copytool failed to send register event to FIFO"
2720 if [ -z "$UNREGISTER_EVENT" ]; then
2721 error "Copytool failed to send unregister event to FIFO"
2724 copytool_monitor_cleanup
2725 echo "Register/Unregister events look OK."
2727 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2730 # Bump progress interval for livelier events.
2733 # test needs a new running copytool
2735 copytool_monitor_setup
2736 HSMTOOL_UPDATE_INTERVAL=$interval \
2737 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2740 local f=$DIR/$tdir/$tfile
2741 local fid=$(make_large_for_progress $f)
2743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2744 error "could not archive file"
2745 wait_request_state $fid ARCHIVE SUCCEED
2747 local expected_fields="event_time data_fid source_fid"
2748 expected_fields+=" total_bytes current_bytes"
2752 while read event; do
2753 # Make sure we're not getting anything from previous events.
2754 for field in $expected_fields; do
2758 local parsed=$(parse_json_event "$event")
2759 if [ -z "$parsed" ]; then
2760 error "Copytool sent malformed event: $event"
2764 if [ $event_type == "ARCHIVE_START" ]; then
2767 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2770 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2774 # Do some simple checking of the progress update events.
2775 for expected_field in $expected_fields; do
2776 if [ -z ${!expected_field+x} ]; then
2777 error "Missing $expected_field field in event"
2781 if [ $total_bytes -eq 0 ]; then
2782 error "Expected total_bytes to be > 0"
2785 # These should be identical throughout an archive
2787 if [ $source_fid != $data_fid ]; then
2788 error "Expected source_fid to equal data_fid"
2790 done < <(echo $"$(get_copytool_event_log)")
2792 if [ -z "$START_EVENT" ]; then
2793 error "Copytool failed to send archive start event to FIFO"
2796 if [ -z "$FINISH_EVENT" ]; then
2797 error "Copytool failed to send archive finish event to FIFO"
2800 echo "Archive events look OK."
2804 copytool_monitor_cleanup
2806 run_test 71 "Copytool logs JSON archive events to FIFO"
2809 # Bump progress interval for livelier events.
2812 # test needs a new running copytool
2814 copytool_monitor_setup
2815 HSMTOOL_UPDATE_INTERVAL=$interval \
2816 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2817 local test_file=$HSMTOOL_MONITOR_DIR/file
2819 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2821 do_facet $SINGLEAGT "$cmd" ||
2822 error "cannot create $test_file on $SINGLEAGT"
2823 copy2archive $test_file $tdir/$tfile
2826 local f=$DIR/$tdir/$tfile
2827 import_file $tdir/$tfile $f
2828 f=$DIR2/$tdir/$tfile
2829 echo "Verifying released state: "
2830 check_hsm_flags $f "0x0000000d"
2832 local fid=$(path2fid $f)
2834 wait_request_state $fid RESTORE SUCCEED
2836 local expected_fields="event_time data_fid source_fid"
2837 expected_fields+=" total_bytes current_bytes"
2841 while read event; do
2842 # Make sure we're not getting anything from previous events.
2843 for field in $expected_fields; do
2847 local parsed=$(parse_json_event "$event")
2848 if [ -z "$parsed" ]; then
2849 error "Copytool sent malformed event: $event"
2853 if [ $event_type == "RESTORE_START" ]; then
2855 if [ $source_fid != $data_fid ]; then
2856 error "source_fid should == data_fid at start"
2859 elif [ $event_type == "RESTORE_FINISH" ]; then
2861 if [ $source_fid != $data_fid ]; then
2862 error "source_fid should == data_fid at finish"
2865 elif [ $event_type != "RESTORE_RUNNING" ]; then
2869 # Do some simple checking of the progress update events.
2870 for expected_field in $expected_fields; do
2871 if [ -z ${!expected_field+x} ]; then
2872 error "Missing $expected_field field in event"
2876 if [ $total_bytes -eq 0 ]; then
2877 error "Expected total_bytes to be > 0"
2880 # When a restore starts out, the data fid is the same as the
2881 # source fid. After the restore has gotten going, we learn
2882 # the new data fid. Once the restore has finished, the source
2883 # fid is set to the new data fid.
2885 # We test this because some monitoring software may depend on
2886 # this behavior. If it changes, then the consumers of these
2887 # events may need to be modified.
2888 if [ $source_fid == $data_fid ]; then
2889 error "source_fid should != data_fid during restore"
2891 done < <(echo $"$(get_copytool_event_log)")
2893 if [ -z "$START_EVENT" ]; then
2894 error "Copytool failed to send restore start event to FIFO"
2897 if [ -z "$FINISH_EVENT" ]; then
2898 error "Copytool failed to send restore finish event to FIFO"
2901 echo "Restore events look OK."
2905 copytool_monitor_cleanup
2909 run_test 72 "Copytool logs JSON restore events to FIFO"
2912 file_count=51 # Max number of files constrained by LNET message size
2913 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2914 local f=$DIR/$tdir/$tfile
2915 local FILELIST=/tmp/filelist.txt
2919 for i in $(seq 1 $file_count); do
2920 fid=$(copy_file /etc/hosts $f.$i)
2921 echo $f.$i >> $FILELIST
2924 # to be sure wait_all_done will not be mislead by previous tests
2926 wait_for_grace_delay
2927 $LFS hsm_archive --filelist $FILELIST ||
2928 error "cannot archive a file list"
2930 $LFS hsm_release --filelist $FILELIST ||
2931 error "cannot release a file list"
2932 $LFS hsm_restore --filelist $FILELIST ||
2933 error "cannot restore a file list"
2937 run_test 90 "Archive/restore a file list"
2939 double_verify_reset_hsm_param() {
2941 echo "Testing $HSM_PARAM.$p"
2942 local val=$(get_hsm_param $p)
2944 local val2=$(($val * 2))
2945 set_hsm_param $p $val2
2946 val=$(get_hsm_param $p)
2947 [[ $val == $val2 ]] ||
2948 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
2949 echo "Set $p to 0 must failed"
2953 set_hsm_param $p $save
2955 if [[ $rc == 0 ]]; then
2956 error "we must not be able to set $HSM_PARAM.$p to 0"
2961 double_verify_reset_hsm_param loop_period
2962 double_verify_reset_hsm_param grace_delay
2963 double_verify_reset_hsm_param active_request_timeout
2964 double_verify_reset_hsm_param max_requests
2965 double_verify_reset_hsm_param default_archive_id
2967 run_test 100 "Set coordinator /proc tunables"
2974 run_test 102 "Verify coordinator control"
2977 # test needs a running copytool
2984 for i in $(seq 1 20); do
2985 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
2987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
2991 echo "Current requests"
2992 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
2993 $HSM_PARAM.actions |\
2994 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
2996 [[ -z "$res" ]] || error "Some request have not been canceled"
3000 run_test 103 "Purge all requests"
3005 # test needs a running copytool
3009 local f=$DIR/$tdir/$tfile
3010 local fid=$(make_large_for_progress $f)
3011 # if cdt is on, it can serve too quickly the request
3013 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3014 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3015 $HSM_PARAM.actions |\
3016 grep $fid | cut -f16 -d=")
3019 [[ "$data1" == "$DATAHEX" ]] ||
3020 error "Data field in records is ($data1) and not ($DATAHEX)"
3024 run_test 104 "Copy tool data field"
3031 for i in $(seq -w 1 10); do
3032 cp /etc/passwd $DIR/$tdir/$i
3033 $LFS hsm_archive $DIR/$tdir/$i
3035 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3036 $HSM_PARAM.actions |\
3037 grep WAITING | wc -l")
3040 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3041 $HSM_PARAM.actions |\
3042 grep WAITING | wc -l")
3045 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3046 error "Requests count after shutdown $reqcnt2 != "\
3047 "before shutdown $reqcnt1"
3049 run_test 105 "Restart of coordinator"
3051 get_agent_by_uuid_mdt() {
3054 local mds=mds$(($mdtidx + 1))
3055 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3059 check_agent_registered_by_mdt() {
3062 local mds=mds$(($mdtidx + 1))
3063 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3064 if [[ ! -z "$agent" ]]; then
3065 echo "found agent $agent on $mds"
3067 error "uuid $uuid not found in agent list on $mds"
3071 check_agent_unregistered_by_mdt() {
3074 local mds=mds$(($mdtidx + 1))
3075 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3076 if [[ -z "$agent" ]]; then
3077 echo "uuid not found in agent list on $mds"
3079 error "uuid found in agent list on $mds: $agent"
3083 check_agent_registered() {
3086 for mdsno in $(seq 1 $MDSCOUNT); do
3087 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3091 check_agent_unregistered() {
3094 for mdsno in $(seq 1 $MDSCOUNT); do
3095 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3100 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3101 get_client_uuid $MOUNT | cut -d' ' -f2)
3104 check_agent_registered $uuid
3106 search_copytools || error "No copytool found"
3109 check_agent_unregistered $uuid
3112 check_agent_registered $uuid
3116 run_test 106 "Copytool register/unregister"
3119 # test needs a running copytool
3121 # create and archive file
3123 local f1=$DIR/$tdir/$tfile
3124 local fid=$(copy_file /etc/passwd $f1)
3125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3126 wait_request_state $fid ARCHIVE SUCCEED
3127 # shutdown and restart MDS
3129 # check the copytool still gets messages from MDT
3130 local f2=$DIR/$tdir/2
3131 local fid=$(copy_file /etc/passwd $f2)
3132 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3133 # main check of this sanity: this request MUST succeed
3134 wait_request_state $fid ARCHIVE SUCCEED
3137 run_test 107 "Copytool re-register after MDS restart"
3139 policy_set_and_test()
3143 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3144 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3145 [[ "$policy" == "$target" ]] ||
3146 error "Wrong policy after '$change': '$policy' != '$target'"
3150 # to force default policy setting if error
3151 CDT_POLICY_HAD_CHANGED=true
3153 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3154 local default="NonBlockingRestore [NoRetryAction]"
3155 [[ "$policy" == "$default" ]] ||
3156 error "default policy has changed,"\
3157 " '$policy' != '$default' update the test"
3158 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3159 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3160 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3161 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3162 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3163 # useless bacause we know but safer for futur changes to use real value
3164 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3165 echo "Next set_param must failed"
3166 policy_set_and_test "wrong" "$policy"
3169 echo "Back to default policy"
3170 cdt_set_sanity_policy
3172 run_test 109 "Policy display/change"
3175 # test needs a running copytool
3180 copy2archive /etc/passwd $tdir/$tfile
3182 local f=$DIR/$tdir/$tfile
3183 import_file $tdir/$tfile $f
3184 local fid=$(path2fid $f)
3186 cdt_set_non_blocking_restore
3191 wait_request_state $fid RESTORE SUCCEED
3192 cdt_clear_non_blocking_restore
3196 error "md5sum returns $st != 1, "\
3197 "should also perror ENODATA (No data available)"
3201 run_test 110a "Non blocking restore policy (import case)"
3204 # test needs a running copytool
3208 local f=$DIR/$tdir/$tfile
3209 local fid=$(copy_file /etc/passwd $f)
3210 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3211 wait_request_state $fid ARCHIVE SUCCEED
3214 cdt_set_non_blocking_restore
3219 wait_request_state $fid RESTORE SUCCEED
3220 cdt_clear_non_blocking_restore
3224 error "md5sum returns $st != 1, "\
3225 "should also perror ENODATA (No data available)"
3229 run_test 110b "Non blocking restore policy (release case)"
3232 # test needs a running copytool
3236 copy2archive /etc/passwd $tdir/$tfile
3238 local f=$DIR/$tdir/$tfile
3240 import_file $tdir/$tfile $f
3241 local fid=$(path2fid $f)
3245 copytool_remove_backend $fid
3248 wait_request_state $fid RESTORE FAILED
3255 [[ $st == 0 ]] || error "Restore does not failed"
3259 run_test 111a "No retry policy (import case), restore will error"\
3260 " (No such file or directory)"
3263 # test needs a running copytool
3267 local f=$DIR/$tdir/$tfile
3268 local fid=$(copy_file /etc/passwd $f)
3270 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3271 wait_request_state $fid ARCHIVE SUCCEED
3274 copytool_remove_backend $fid
3277 wait_request_state $fid RESTORE FAILED
3284 [[ $st == 0 ]] || error "Restore does not failed"
3288 run_test 111b "No retry policy (release case), restore will error"\
3289 " (No such file or directory)"
3292 # test needs a running copytool
3296 local f=$DIR/$tdir/$tfile
3297 local fid=$(copy_file /etc/passwd $f)
3299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3300 local l=$($LFS hsm_action $f)
3302 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3306 wait_request_state $fid ARCHIVE SUCCEED
3309 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3313 run_test 112 "State of recorded request"
3316 # test needs a running copytool
3320 local f=$DIR/$tdir/$tfile
3321 local fid=$(make_large_for_cancel $f)
3322 # test with cdt on is made in test_221
3324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3327 wait_request_state $fid ARCHIVE CANCELED
3328 wait_request_state $fid CANCEL SUCCEED
3332 run_test 200 "Register/Cancel archive"
3335 # test needs a running copytool
3339 local f=$DIR/$tdir/$tfile
3340 make_archive $tdir/$tfile
3341 import_file $tdir/$tfile $f
3342 local fid=$(path2fid $f)
3344 # test with cdt on is made in test_222
3349 wait_request_state $fid RESTORE CANCELED
3350 wait_request_state $fid CANCEL SUCCEED
3354 run_test 201 "Register/Cancel restore"
3357 # test needs a running copytool
3361 local f=$DIR/$tdir/$tfile
3362 local fid=$(make_large_for_progress $f)
3363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3364 wait_request_state $fid ARCHIVE SUCCEED
3370 wait_request_state $fid REMOVE CANCELED
3374 run_test 202 "Register/Cancel remove"
3377 # test needs a running copytool
3382 local f=$DIR/$tdir/$tfile
3383 local fid=$(copy_file /etc/passwd $f)
3387 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3388 wait_request_state $fid ARCHIVE SUCCEED
3390 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3394 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3398 run_test 220 "Changelog for archive"
3401 # test needs a running copytool
3406 local f=$DIR/$tdir/$tfile
3407 local fid=$(make_large_for_cancel $f)
3411 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3412 wait_request_state $fid ARCHIVE STARTED
3414 wait_request_state $fid ARCHIVE CANCELED
3415 wait_request_state $fid CANCEL SUCCEED
3417 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3420 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3424 run_test 221 "Changelog for archive canceled"
3427 # test needs a running copytool
3431 copy2archive /etc/passwd $tdir/$tfile
3433 local f=$DIR/$tdir/$tfile
3434 import_file $tdir/$tfile $f
3435 local fid=$(path2fid $f)
3440 wait_request_state $fid RESTORE SUCCEED
3442 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3445 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3449 run_test 222a "Changelog for explicit restore"
3452 # test needs a running copytool
3456 local f=$DIR/$tdir/$tfile
3457 local fid=$(copy_file /etc/passwd $f)
3460 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3461 wait_request_state $fid ARCHIVE SUCCEED
3466 wait_request_state $fid RESTORE SUCCEED
3468 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3471 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3475 run_test 222b "Changelog for implicit restore"
3478 # test needs a running copytool
3483 local f=$DIR/$tdir/$tfile
3484 make_archive $tdir/$tfile
3488 import_file $tdir/$tfile $f
3489 local fid=$(path2fid $f)
3492 wait_request_state $fid RESTORE STARTED
3494 wait_request_state $fid RESTORE CANCELED
3495 wait_request_state $fid CANCEL SUCCEED
3497 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3500 [[ $flags == $target ]] ||
3501 error "Changelog flag is $flags not $target"
3505 run_test 223a "Changelog for restore canceled (import case)"
3508 # test needs a running copytool
3513 local f=$DIR/$tdir/$tfile
3514 local fid=$(make_large_for_progress $f)
3517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3518 wait_request_state $fid ARCHIVE SUCCEED
3521 wait_request_state $fid RESTORE STARTED
3523 wait_request_state $fid RESTORE CANCELED
3524 wait_request_state $fid CANCEL SUCCEED
3526 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3529 [[ $flags == $target ]] ||
3530 error "Changelog flag is $flags not $target"
3534 run_test 223b "Changelog for restore canceled (release case)"
3537 # test needs a running copytool
3542 local f=$DIR/$tdir/$tfile
3543 local fid=$(copy_file /etc/passwd $f)
3546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3547 wait_request_state $fid ARCHIVE SUCCEED
3550 wait_request_state $fid REMOVE SUCCEED
3552 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3555 [[ $flags == $target ]] ||
3556 error "Changelog flag is $flags not $target"
3560 run_test 224 "Changelog for remove"
3563 # test needs a running copytool
3566 # test is not usable because remove request is too fast
3567 # so it is always finished before cancel can be done ...
3568 echo "Test disabled"
3573 local f=$DIR/$tdir/$tfile
3574 local fid=$(make_large_for_progress $f)
3577 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3578 wait_request_state $fid ARCHIVE SUCCEED
3580 # if cdt is on, it can serve too quickly the request
3585 wait_request_state $fid REMOVE CANCELED
3586 wait_request_state $fid CANCEL SUCCEED
3588 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3589 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3590 tail -n 1 | awk '{print $5}')
3593 [[ $flags == $target ]] ||
3594 error "Changelog flag is $flags not $target"
3598 run_test 225 "Changelog for remove canceled"
3601 # test needs a running copytool
3606 local f1=$DIR/$tdir/$tfile-1
3607 local f2=$DIR/$tdir/$tfile-2
3608 local f3=$DIR/$tdir/$tfile-3
3609 local fid1=$(copy_file /etc/passwd $f1)
3610 local fid2=$(copy_file /etc/passwd $f2)
3611 copy_file /etc/passwd $f3
3614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3615 wait_request_state $fid1 ARCHIVE SUCCEED
3617 $LFS hsm_archive $f2
3618 wait_request_state $fid2 ARCHIVE SUCCEED
3620 rm $f1 || error "rm $f1 failed"
3622 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3625 [[ $flags == $target ]] ||
3626 error "Changelog flag is $flags not $target"
3628 mv $f3 $f2 || error "mv $f3 $f2 failed"
3630 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3633 [[ $flags == $target ]] ||
3634 error "Changelog flag is $flags not $target"
3638 run_test 226 "changelog for last rm/mv with exiting archive"
3640 check_flags_changes() {
3648 $LFS hsm_set --$hsm_flag $f ||
3649 error "Cannot set $hsm_flag on $f"
3650 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3651 local seen=${#flags[*]}
3653 [[ $seen == $cnt ]] ||
3654 error "set $hsm_flag: Changelog events $seen != $cnt"
3655 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3656 error "set $hsm_flag: Changelog flags are "\
3657 "${flags[$((cnt - 1))]} not $target"
3659 $LFS hsm_clear --$hsm_flag $f ||
3660 error "Cannot clear $hsm_flag on $f"
3661 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3664 [[ $cnt == $seen ]] ||
3665 error "clear $hsm_flag: Changelog events $seen != $cnt"
3667 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3668 error "clear $hsm_flag: Changelog flag is "\
3669 "${flags[$((cnt - 1))]} not $target"
3673 # test needs a running copytool
3680 for i in norelease noarchive exists archived
3682 local f=$DIR/$tdir/$tfile-$i
3683 local fid=$(copy_file /etc/passwd $f)
3684 check_flags_changes $f $fid $i 0 1
3687 f=$DIR/$tdir/$tfile---lost
3688 fid=$(copy_file /etc/passwd $f)
3689 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3690 wait_request_state $fid ARCHIVE SUCCEED
3691 check_flags_changes $f $fid lost 3 1
3695 run_test 227 "changelog when explicit setting of HSM flags"
3698 # test needs a running copytool
3701 local fid=$(make_small_sync $DIR/$tfile)
3702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3703 wait_request_state $fid ARCHIVE SUCCEED
3705 $LFS hsm_release $DIR/$tfile
3706 check_hsm_flags $DIR/$tfile "0x0000000d"
3708 filefrag $DIR/$tfile | grep " 1 extent found" ||
3709 error "filefrag on released file must return only one extent"
3711 # only newer versions of cp detect sparse files by stat/FIEMAP
3713 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3714 error "copying $DIR/$tfile"
3715 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3717 $LFS hsm_release $DIR/$tfile
3718 check_hsm_flags $DIR/$tfile "0x0000000d"
3720 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3722 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3724 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3725 error "comparing untarred $DIR/$tfile"
3727 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3728 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3731 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3734 # test needs a running copytool
3738 local maxrequest=$(get_hsm_param max_requests)
3739 local rqcnt=$(($maxrequest * 3))
3743 for i in $(seq -w 1 $rqcnt); do
3745 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3747 # we do it in 2 steps, so all requests arrive at the same time
3748 for i in $(seq -w 1 $rqcnt); do
3749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3754 while [[ $cnt != 0 || $wt != 0 ]]; do
3756 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3757 $HSM_PARAM.actions |\
3758 grep STARTED | grep -v CANCEL | wc -l")
3759 [[ $cnt -le $maxrequest ]] ||
3760 error "$cnt > $maxrequest too many started requests"
3761 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3762 $HSM_PARAM.actions |\
3763 grep WAITING | wc -l")
3764 echo "max=$maxrequest started=$cnt waiting=$wt"
3769 run_test 250 "Coordinator max request"
3772 # test needs a running copytool
3776 local f=$DIR/$tdir/$tfile
3777 local fid=$(make_large_for_cancel $f)
3780 # to have a short test
3781 local old_to=$(get_hsm_param active_request_timeout)
3782 set_hsm_param active_request_timeout 4
3783 # to be sure the cdt will wake up frequently so
3784 # it will be able to cancel the "old" request
3785 local old_loop=$(get_hsm_param loop_period)
3786 set_hsm_param loop_period 2
3789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3790 wait_request_state $fid ARCHIVE STARTED
3792 wait_request_state $fid ARCHIVE CANCELED
3794 set_hsm_param active_request_timeout $old_to
3795 set_hsm_param loop_period $old_loop
3799 run_test 251 "Coordinator request timeout"
3802 # the only way to test ondisk conf is to restart MDS ...
3803 echo "Stop coordinator and remove coordinator state at mount"
3806 # clean on disk conf set by default
3807 cdt_clear_mount_state
3808 cdt_check_state stopped
3810 # check cdt still off after umount/remount
3812 cdt_check_state stopped
3814 echo "Set coordinator start at mount, and start coordinator"
3815 cdt_set_mount_state enabled
3818 cdt_check_state enabled
3820 # check cdt still on after umount/remount
3822 cdt_check_state enabled
3824 # we are back to original state (cdt started at mount)
3826 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3829 local ai=$(get_hsm_param default_archive_id)
3830 local new=$((ai + 1))
3832 set_hsm_param default_archive_id $new -P
3834 local res=$(get_hsm_param default_archive_id)
3837 set_hsm_param default_archive_id "" "-P -d"
3839 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3841 run_test 301 "HSM tunnable are persistent"
3844 local ai=$(get_hsm_param default_archive_id)
3845 local new=$((ai + 1))
3850 set_hsm_param default_archive_id $new -P
3853 for mdtno in $(seq 1 $MDSCOUNT); do
3858 cdt_check_state enabled
3860 local res=$(get_hsm_param default_archive_id)
3863 set_hsm_param default_archive_id "" "-P -d"
3865 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3867 run_test 302 "HSM tunnable are persistent when CDT is off"
3870 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3876 local dir_mdt0=$DIR/$tdir/mdt0
3877 local dir_mdt1=$DIR/$tdir/mdt1
3879 # create 1 dir per MDT
3880 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3881 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3883 # create 1 file in each MDT
3884 local fid1=$(make_small $dir_mdt0/$tfile)
3885 local fid2=$(make_small $dir_mdt1/$tfile)
3887 # check that hsm request on mdt0 is sent to the right MDS
3888 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3889 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3890 echo "archive successful on mdt0"
3892 # check that hsm request on mdt1 is sent to the right MDS
3893 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3894 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3895 echo "archive successful on mdt1"
3898 # clean test files and directories
3899 rm -rf $dir_mdt0 $dir_mdt1
3901 run_test 400 "Single request is sent to the right MDT"
3904 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3910 local dir_mdt0=$DIR/$tdir/mdt0
3911 local dir_mdt1=$DIR/$tdir/mdt1
3913 # create 1 dir per MDT
3914 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3915 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3917 # create 1 file in each MDT
3918 local fid1=$(make_small $dir_mdt0/$tfile)
3919 local fid2=$(make_small $dir_mdt1/$tfile)
3921 # check that compound requests are shunt to the rights MDTs
3922 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3923 error "lfs hsm_archive"
3924 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3925 echo "archive successful on mdt0"
3926 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3927 echo "archive successful on mdt1"
3930 # clean test files and directories
3931 rm -rf $dir_mdt0 $dir_mdt1
3933 run_test 401 "Compound requests split and sent to their respective MDTs"
3935 mdc_change_state() # facet, MDT_pattern, activate|deactivate
3940 local node=$(facet_active_host $facet)
3942 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
3943 awk '{print $4}'); do
3944 echo "$3 $mdc on $node"
3945 do_facet $facet "$LCTL --device $mdc $state" || return 1
3950 # make sure there is no running copytool
3953 # deactivate all mdc on agent1
3954 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
3956 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
3958 check_agent_unregistered "uuid" # match any agent
3960 # no expected running copytool
3961 search_copytools $agent && error "Copytool start should have failed"
3964 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
3966 run_test 402 "Copytool start fails if all MDTs are inactive"
3969 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3971 # make sure there is no running copytool
3974 local agent=$(facet_active_host $SINGLEAGT)
3975 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
3977 # deactivate all mdc for MDT0001
3978 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
3981 # check the agent is registered on MDT0000, and not on MDT0001
3982 check_agent_registered_by_mdt $uuid 0
3983 check_agent_unregistered_by_mdt $uuid 1
3985 # check running copytool process
3986 search_copytools $agent || error "No running copytools on $agent"
3988 # reactivate all mdc for MDT0001
3989 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
3991 # make sure the copytool is now registered to all MDTs
3992 check_agent_registered $uuid
3996 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
3999 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4003 # create files on both MDT0000 and MDT0001
4006 local dir_mdt0=$DIR/$tdir/mdt0
4007 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4009 # create 1 file on mdt0
4010 local fid1=$(make_small $dir_mdt0/$tfile)
4012 # deactivate all mdc for MDT0001
4013 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4015 # send an HSM request for files in MDT0000
4016 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4018 # check for completion of files in MDT0000
4019 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4020 echo "archive successful on mdt0"
4022 # reactivate all mdc for MDT0001
4023 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4026 # clean test files and directories
4029 run_test 404 "Inactive MDT does not block requests for active MDTs"
4034 check_and_cleanup_lustre