3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test: 3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # bug number for skipped test:4178 4176
17 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 200 221 223b 31a"
18 # bug number for skipped test:LU-3852
19 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 251"
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MCREATE=${MCREATE:-mcreate}
32 MOUNT_2=${MOUNT_2:-"yes"}
35 # script only handles up to 10 MDTs (because of MDT_PREFIX)
36 [ $MDSCOUNT -gt 9 ] &&
37 error "script cannot handle more than 9 MDTs, please fix" && exit
39 check_and_setup_lustre
41 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
42 skip_env "Need MDS version at least 2.4.53" && exit
45 # $RUNAS_ID may get set incorrectly somewhere else
46 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
47 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
49 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
54 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
55 # the following associated variables are added:
57 # AGTCOUNT: number of agents
58 # AGTDEV{N}: target HSM mount point (root path of the backend)
59 # agt{N}_HOST: hostname of the agent agt{N}
60 # SINGLEAGT: facet of the single agent
62 # The number of agents is initialized as the number of remote client nodes.
63 # By default, only single copytool is started on a remote client/agent. If there
64 # was no remote client, then the copytool will be started on the local client.
70 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
71 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
73 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
74 if [[ $CLIENTCOUNT -gt 1 ]] &&
75 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
76 skip_env "SHARED_DIRECTORY should be accessible"\
81 for n in $(seq $AGTCOUNT); do
82 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
83 agent=CLIENT$((n + 1))
84 if [[ -z "${!agent}" ]]; then
85 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
88 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
91 export SINGLEAGT=${SINGLEAGT:-agt1}
93 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
94 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
95 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
96 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
97 export HSMTOOL_TESTDIR
98 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
99 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
102 # The test only support up to 10 MDTs
103 MDT_PREFIX="mdt.$FSNAME-MDT000"
104 HSM_PARAM="${MDT_PREFIX}0.hsm"
106 # archive is purged at copytool setup
107 HSM_ARCHIVE_PURGE=true
109 # Don't allow copytool error upon start/setup
110 HSMTOOL_NOERROR=false
113 # Get the backend root path for the given agent facet.
116 local dev=AGTDEV$(facet_number $facet)
121 # Stop copytool and unregister an existing changelog user.
123 copytool_monitor_cleanup
126 cdt_set_sanity_policy
131 # get MDT device for each mdc
132 for mdtno in $(seq 1 $MDSCOUNT); do
133 local idx=$(($mdtno - 1))
134 MDT[$idx]=$($LCTL get_param -n \
135 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
136 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
141 local agents=${1:-$(facet_active_host $SINGLEAGT)}
142 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
145 search_and_kill_copytool() {
146 local agents=${1:-$(facet_active_host $SINGLEAGT)}
148 echo "Killing existing copytools on $agents"
149 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
152 copytool_monitor_setup() {
153 local facet=${1:-$SINGLEAGT}
154 local agent=$(facet_active_host $facet)
156 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
157 local test_dir=$(do_node $agent "$cmd") ||
158 error "Failed to create tempdir on $agent"
159 export HSMTOOL_MONITOR_DIR=$test_dir
161 # Create the fifo and a monitor (cat dies when copytool dies)
162 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
163 error "failed to create copytool fifo on $agent"
164 cmd="cat $test_dir/fifo > $test_dir/events &"
165 cmd+=" echo \\\$! > $test_dir/monitor_pid"
167 if [[ $PDSH == *Rmrsh* ]]; then
168 # This is required for pdsh -Rmrsh and its handling of remote
170 # Regular ssh and pdsh -Rssh work fine without this
171 # backgrounded subshell nonsense.
172 (do_node $agent "$cmd") &
173 export HSMTOOL_MONITOR_PDSH=$!
175 # Slightly racy, but just making a best-effort to catch obvious
178 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
179 error "Failed to start copytool monitor on $agent"
181 do_node $agent "$cmd"
183 error "Failed to start copytool monitor on $agent"
188 copytool_monitor_cleanup() {
189 local facet=${1:-$SINGLEAGT}
190 local agent=$(facet_active_host $facet)
192 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
193 # Should die when the copytool dies, but just in case.
194 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
195 cmd+=" 2>/dev/null || true"
196 do_node $agent "$cmd"
197 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
198 export HSMTOOL_MONITOR_DIR=
201 # The pdsh should die on its own when the monitor dies. Just
202 # in case, though, try to clean up to avoid any cruft.
203 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
204 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
205 export HSMTOOL_MONITOR_PDSH=
210 local facet=${1:-$SINGLEAGT}
211 local lustre_mntpnt=${2:-$MOUNT}
213 local hsm_root=${4:-$(copytool_device $facet)}
214 local agent=$(facet_active_host $facet)
216 if [[ -z "$arc_id" ]] &&
217 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
218 echo "Wakeup copytool $facet on $agent"
222 if $HSM_ARCHIVE_PURGE; then
223 echo "Purging archive on $agent"
224 do_facet $facet "rm -rf $hsm_root/*"
227 echo "Starting copytool $facet on $agent"
228 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
229 # bandwidth is limited to 1MB/s so the copy time is known and
230 # independent of hardware
231 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
232 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
233 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
234 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
235 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
236 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
237 cmd+=" --bandwidth 1 $lustre_mntpnt"
239 # Redirect the standard output and error to a log file which
240 # can be uploaded to Maloo.
241 local prefix=$TESTLOG_PREFIX
242 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
243 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
245 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
246 if [[ $? != 0 ]]; then
247 [[ $HSMTOOL_NOERROR == true ]] ||
248 error "start copytool $facet on $agent failed"
249 echo "start copytool $facet on $agent failed"
255 get_copytool_event_log() {
256 local facet=${1:-$SINGLEAGT}
257 local agent=$(facet_active_host $facet)
259 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
260 error "Can't get event log: No monitor directory!"
262 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
263 error "Could not collect event log from $agent"
268 local facet=$SINGLEAGT
269 local agents=${1:-$(facet_active_host $facet)}
274 local hsm_root=$(copytool_device $facet)
276 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
278 echo "Copytool is stopped on $agents"
280 # clean all CDTs orphans requests from previous tests
281 # that would otherwise need to timeout to clear.
282 for mdtno in $(seq 1 $MDSCOUNT); do
284 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
285 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
287 # skip already stop[ed,ing] CDTs
288 echo $oldstate | grep stop && continue
290 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
291 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
293 error "mds${mdtno} cdt state is not stopped"
294 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
295 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
297 error "mds${mdtno} cdt state is not $oldstate"
299 do_facet $facet "rm -rf $hsm_root"
303 local agents=${1:-$(facet_active_host $SINGLEAGT)}
305 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
306 echo "Copytool is suspended on $agents"
309 copytool_remove_backend() {
311 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
312 echo "Remove from backend: $fid = $be"
313 do_facet $SINGLEAGT rm -f $be
317 do_facet $SINGLEAGT \
318 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
319 --import $1 $2 $MOUNT" ||
320 error "import of $1 to $2 failed"
324 local file=$HSM_ARCHIVE/$1
325 do_facet $SINGLEAGT mkdir -p $(dirname $file)
326 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
327 error "cannot create $file"
331 local file=$HSM_ARCHIVE/$2
332 do_facet $SINGLEAGT mkdir -p $(dirname $file)
333 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
342 if [[ "$value" != "" ]]; then
345 for mdtno in $(seq 1 $MDSCOUNT); do
346 local idx=$(($mdtno - 1))
347 local facet=mds${mdtno}
348 # if $arg include -P option, run 1 set_param per MDT on the MGS
349 # else, run set_param on each MDT
350 [[ $arg = *"-P"* ]] && facet=mgs
351 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
352 [[ $? != 0 ]] && rc=1
362 for mdtno in $(seq 1 $MDSCOUNT); do
363 local idx=$(($mdtno - 1))
364 wait_result mds${mdtno} \
365 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
367 error "$key state is not '$target' on mds${mdtno}"
374 for mdtno in $(seq 1 $MDSCOUNT); do
375 local idx=$(($mdtno - 1))
376 local cl_user=$(do_facet mds${mdtno} $LCTL \
377 --device ${MDT[$idx]} \
378 changelog_register -n)
380 do_facet mds${mdtno} lctl set_param \
381 mdd.${MDT[$idx]}.changelog_mask="+hsm"
382 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
386 changelog_cleanup() {
388 for mdtno in $(seq 1 $MDSCOUNT); do
389 local idx=$(($mdtno - 1))
390 [[ -z ${CL_USERS[$idx]} ]] && continue
391 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
392 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
393 changelog_deregister ${CL_USERS[$idx]}
398 changelog_get_flags() {
403 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
408 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
416 mdts_set_param "$opt -n" "hsm.$param" "$value"
423 mdts_set_param "" hsm_control "$cmd"
424 mdts_check_param hsm_control "$target" 10
427 cdt_set_sanity_policy() {
428 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
431 mdts_set_param "" hsm.policy "+NRA"
432 mdts_set_param "" hsm.policy "-NBR"
433 CDT_POLICY_HAD_CHANGED=
438 mdts_set_param "" hsm.policy "+NRA"
439 CDT_POLICY_HAD_CHANGED=true
442 cdt_clear_no_retry() {
443 mdts_set_param "" hsm.policy "-NRA"
444 CDT_POLICY_HAD_CHANGED=true
447 cdt_set_non_blocking_restore() {
448 mdts_set_param "" hsm.policy "+NBR"
449 CDT_POLICY_HAD_CHANGED=true
452 cdt_clear_non_blocking_restore() {
453 mdts_set_param "" hsm.policy "-NBR"
454 CDT_POLICY_HAD_CHANGED=true
457 cdt_clear_mount_state() {
458 mdts_set_param "-P -d" hsm_control ""
461 cdt_set_mount_state() {
462 mdts_set_param "-P" hsm_control "$1"
466 mdts_check_param hsm_control "$1" 20
470 set_test_state disabled disabled
474 set_test_state enabled enabled
478 set_test_state shutdown stopped
482 set_test_state purge enabled
488 cdt_set_sanity_policy
492 local client_count=$1
493 if [[ $CLIENTCOUNT -lt $client_count ]]; then
494 skip "Need $client_count or more clients, have $CLIENTCOUNT"
501 $LFS path2fid $1 | tr -d '[]'
508 if [[ $u == "user" ]]; then
509 local st=$($RUNAS $LFS hsm_state $f)
511 local st=$($LFS hsm_state $f)
515 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
517 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
521 get_hsm_archive_id() {
523 local st=$($LFS hsm_state $f)
524 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
526 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
535 local st=$(get_hsm_flags $f)
536 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
539 check_hsm_flags_user() {
543 local st=$(get_hsm_flags $f user)
544 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
556 if [[ "$3" != 1 ]]; then
560 cp $1 $f || error "cannot copy $1 to $f"
561 path2fid $f || error "cannot get fid on $f"
565 local file2=${1/$DIR/$DIR2}
566 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
567 error "cannot create $file2"
568 path2fid $1 || error "cannot get fid on $1"
572 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
573 error "cannot create $1"
574 path2fid $1 || error "cannot get fid on $1"
577 cleanup_large_files() {
578 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
580 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
583 make_large_for_striping() {
584 local file2=${1/$DIR/$DIR2}
585 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
589 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
590 error "cannot create $file2"
591 path2fid $1 || error "cannot get fid on $1"
594 make_large_for_progress() {
595 local file2=${1/$DIR/$DIR2}
599 # big file is large enough, so copy time is > 30s
600 # so copytool make 1 progress
601 # size is not a multiple of 1M to avoid stripe
603 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
604 error "cannot create $file2"
605 path2fid $1 || error "cannot get fid on $1"
608 make_large_for_progress_aligned() {
609 local file2=${1/$DIR/$DIR2}
613 # big file is large enough, so copy time is > 30s
614 # so copytool make 1 progress
615 # size is a multiple of 1M to have stripe
617 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
618 error "cannot create $file2"
619 path2fid $1 || error "cannot get fid on $1"
622 make_large_for_cancel() {
623 local file2=${1/$DIR/$DIR2}
627 # Copy timeout is 100s. 105MB => 105s
628 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
629 error "cannot create $file2"
630 path2fid $1 || error "cannot get fid on $1"
636 wait_update --verbose $(facet_active_host $facet) "$@"
639 wait_request_state() {
643 # 4th arg (mdt index) is optional
645 local mds=mds$(($mdtidx + 1))
647 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
648 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
650 wait_result $mds "$cmd" $state 100 ||
651 error "request on $fid is not $state on $mds"
654 get_request_state() {
658 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
659 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
662 get_request_count() {
666 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
667 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
674 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
675 [[ -n $fid ]] && cmd+=" | grep '$fid'"
676 cmd+=" | egrep 'WAITING|STARTED'"
678 wait_result $SINGLEMDS "$cmd" "" $timeout ||
679 error "requests did not complete"
682 wait_for_grace_delay() {
683 local val=$(get_hsm_param grace_delay)
690 # python2.6 in EL6 includes an internal json module
691 local json_parser='import json; import fileinput;'
692 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
693 json_parser+='json.loads([line for line in '
694 json_parser+='fileinput.input()][0]).items()])'
696 echo $raw_event | python -c "$json_parser"
699 # populate MDT device array
705 # cleanup from previous bad setup
706 search_and_kill_copytool
708 # for recovery tests, coordinator needs to be started at mount
710 # the lustre conf must be without hsm on (like for sanity.sh)
711 echo "Set HSM on and start"
712 cdt_set_mount_state enabled
713 cdt_check_state enabled
715 echo "Start copytool"
718 echo "Set sanity-hsm HSM policy"
719 cdt_set_sanity_policy
721 # finished requests are quickly removed from list
722 set_hsm_param grace_delay 10
728 local f=$DIR/$tdir/$tfile
732 check_hsm_flags_user $f "0x00000000"
734 $RUNAS $LFS hsm_set --norelease $f ||
735 error "user could not change hsm flags"
736 check_hsm_flags_user $f "0x00000010"
738 $RUNAS $LFS hsm_clear --norelease $f ||
739 error "user could not clear hsm flags"
740 check_hsm_flags_user $f "0x00000000"
742 # User could not change those flags...
743 $RUNAS $LFS hsm_set --exists $f &&
744 error "user should not set this flag"
745 check_hsm_flags_user $f "0x00000000"
748 $LFS hsm_set --exists $f ||
749 error "root could not change hsm flags"
750 check_hsm_flags_user $f "0x00000001"
752 $LFS hsm_clear --exists $f ||
753 error "root could not clear hsm state"
754 check_hsm_flags_user $f "0x00000000"
757 run_test 1 "lfs hsm flags root/non-root access"
761 local f=$DIR/$tdir/$tfile
763 # New files are not dirty
764 check_hsm_flags $f "0x00000000"
766 # For test, we simulate an archived file.
767 $LFS hsm_set --exists $f || error "user could not change hsm flags"
768 check_hsm_flags $f "0x00000001"
770 # chmod do not put the file dirty
771 chmod 600 $f || error "could not chmod test file"
772 check_hsm_flags $f "0x00000001"
774 # chown do not put the file dirty
775 chown $RUNAS_ID $f || error "could not chown test file"
776 check_hsm_flags $f "0x00000001"
778 # truncate put the file dirty
779 $TRUNCATE $f 1 || error "could not truncate test file"
780 check_hsm_flags $f "0x00000003"
782 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
783 check_hsm_flags $f "0x00000001"
785 run_test 2 "Check file dirtyness when doing setattr"
791 # New files are not dirty
793 check_hsm_flags $f "0x00000000"
795 # For test, we simulate an archived file.
796 $LFS hsm_set --exists $f ||
797 error "user could not change hsm flags"
798 check_hsm_flags $f "0x00000001"
800 # Reading a file, does not set dirty
801 cat $f > /dev/null || error "could not read file"
802 check_hsm_flags $f "0x00000001"
804 # Open for write without modifying data, does not set dirty
805 openfile -f O_WRONLY $f || error "could not open test file"
806 check_hsm_flags $f "0x00000001"
808 # Append to a file sets it dirty
809 cp -p /etc/passwd $f.append || error "could not create file"
810 $LFS hsm_set --exists $f.append ||
811 error "user could not change hsm flags"
812 dd if=/etc/passwd of=$f.append bs=1 count=3\
813 conv=notrunc oflag=append status=noxfer ||
814 error "could not append to test file"
815 check_hsm_flags $f.append "0x00000003"
817 # Modify a file sets it dirty
818 cp -p /etc/passwd $f.modify || error "could not create file"
819 $LFS hsm_set --exists $f.modify ||
820 error "user could not change hsm flags"
821 dd if=/dev/zero of=$f.modify bs=1 count=3\
822 conv=notrunc status=noxfer ||
823 error "could not modify test file"
824 check_hsm_flags $f.modify "0x00000003"
826 # Open O_TRUNC sets dirty
827 cp -p /etc/passwd $f.trunc || error "could not create file"
828 $LFS hsm_set --exists $f.trunc ||
829 error "user could not change hsm flags"
830 cp /etc/group $f.trunc || error "could not override a file"
831 check_hsm_flags $f.trunc "0x00000003"
833 # Mmapped a file sets dirty
834 cp -p /etc/passwd $f.mmap || error "could not create file"
835 $LFS hsm_set --exists $f.mmap ||
836 error "user could not change hsm flags"
837 multiop $f.mmap OSMWUc || error "could not mmap a file"
838 check_hsm_flags $f.mmap "0x00000003"
840 run_test 3 "Check file dirtyness when opening for write"
844 local f=$DIR/$tdir/$tfile
845 local fid=$(make_small $f)
848 local st=$(get_request_state $fid CANCEL)
849 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
851 run_test 4 "Useless cancel must not be registered"
854 # test needs a running copytool
858 local f=$DIR/$tdir/$tfile
859 local fid=$(copy_file /etc/passwd $f)
861 wait_request_state $fid ARCHIVE SUCCEED
863 check_hsm_flags $f "0x00000009"
867 run_test 8 "Test default archive number"
871 local f=$DIR/$tdir/$tfile
872 local fid=$(copy_file /etc/passwd $f)
873 # we do not use the default one to be sure
874 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
876 copytool_setup $SINGLEAGT $MOUNT $new_an
877 $LFS hsm_archive --archive $new_an $f
878 wait_request_state $fid ARCHIVE SUCCEED
880 check_hsm_flags $f "0x00000009"
884 run_test 9 "Use of explict archive number, with dedicated copytool"
887 needclients 3 || return 0
893 copytool_cleanup $(comma_list $(agts_nodes))
895 # start all of the copytools
896 for n in $(seq $AGTCOUNT); do
900 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
903 for n in $(seq $AGTCOUNT); do
904 file=$DIR/$tdir/$tfile.$n
905 fid=$(make_small $file)
907 $LFS hsm_archive $file || error "could not archive file $file"
908 wait_request_state $fid ARCHIVE SUCCEED
909 check_hsm_flags $file "0x00000009"
913 copytool_cleanup $(comma_list $(agts_nodes))
915 run_test 9a "Multiple remote agents"
918 # test needs a running copytool
921 mkdir -p $DIR/$tdir/d1
922 local f=$DIR/$tdir/$tfile
923 local fid=$(copy_file /etc/hosts $f)
924 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
925 error "hsm_archive failed"
926 wait_request_state $fid ARCHIVE SUCCEED
928 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
929 error "fid $fid not in archive $HSM_ARCHIVE"
930 echo "Verifying content"
931 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
932 echo "Verifying hsm state "
933 check_hsm_flags $f "0x00000009"
935 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
936 local st=$(get_hsm_archive_id $f)
937 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
938 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
943 run_test 10a "Archive a file"
946 # test needs a running copytool
950 local f=$DIR/$tdir/$tfile
951 local fid=$(copy_file /etc/hosts $f)
952 $LFS hsm_archive $f || error "archive request failed"
953 wait_request_state $fid ARCHIVE SUCCEED
955 $LFS hsm_archive $f || error "archive of non dirty file failed"
956 local cnt=$(get_request_count $fid ARCHIVE)
957 [[ "$cnt" == "1" ]] ||
958 error "archive of non dirty file must not make a request"
962 run_test 10b "Archive of non dirty file must work without doing request"
965 # test needs a running copytool
969 local f=$DIR/$tdir/$tfile
970 local fid=$(copy_file /etc/hosts $f)
971 $LFS hsm_set --noarchive $f
972 $LFS hsm_archive $f && error "archive a noarchive file must fail"
976 run_test 10c "Check forbidden archive"
979 # test needs a running copytool
983 local f=$DIR/$tdir/$tfile
984 local fid=$(copy_file /etc/hosts $f)
985 $LFS hsm_archive $f || error "cannot archive $f"
986 wait_request_state $fid ARCHIVE SUCCEED
988 local ar=$(get_hsm_archive_id $f)
989 local dflt=$(get_hsm_param default_archive_id)
990 [[ $ar == $dflt ]] ||
991 error "archived file is not on default archive: $ar != $dflt"
995 run_test 10d "Archive a file on the default archive id"
999 copy2archive /etc/hosts $tdir/$tfile
1000 local f=$DIR/$tdir/$tfile
1002 import_file $tdir/$tfile $f
1003 echo -n "Verifying released state: "
1004 check_hsm_flags $f "0x0000000d"
1006 local LSZ=$(stat -c "%s" $f)
1007 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1009 echo "Verifying imported size $LSZ=$ASZ"
1010 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1011 echo -n "Verifying released pattern: "
1012 local PTRN=$($GETSTRIPE -L $f)
1014 [[ $PTRN == 80000001 ]] || error "Is not released"
1015 local fid=$(path2fid $f)
1016 echo "Verifying new fid $fid in archive"
1018 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1019 error "fid $fid not in archive $HSM_ARCHIVE"
1021 run_test 11a "Import a file"
1024 # test needs a running copytool
1028 local f=$DIR/$tdir/$tfile
1029 local fid=$(copy_file /etc/hosts $f)
1030 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1031 error "hsm_archive failed"
1032 wait_request_state $fid ARCHIVE SUCCEED
1034 local FILE_HASH=$(md5sum $f)
1039 echo "$FILE_HASH" | md5sum -c
1041 [[ $? -eq 0 ]] || error "Restored file differs"
1045 run_test 11b "Import a deleted file using its FID"
1048 # test needs a running copytool
1052 copy2archive /etc/hosts $tdir/$tfile
1054 local f=$DIR/$tdir/$tfile
1055 import_file $tdir/$tfile $f
1056 local f2=$DIR2/$tdir/$tfile
1057 echo "Verifying released state: "
1058 check_hsm_flags $f2 "0x0000000d"
1060 local fid=$(path2fid $f2)
1061 $LFS hsm_restore $f2
1062 wait_request_state $fid RESTORE SUCCEED
1064 echo "Verifying file state: "
1065 check_hsm_flags $f2 "0x00000009"
1067 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1069 [[ $? -eq 0 ]] || error "Restored file differs"
1073 run_test 12a "Restore an imported file explicitly"
1076 # test needs a running copytool
1080 copy2archive /etc/hosts $tdir/$tfile
1082 local f=$DIR/$tdir/$tfile
1083 import_file $tdir/$tfile $f
1084 echo "Verifying released state: "
1085 check_hsm_flags $f "0x0000000d"
1087 cat $f > /dev/null || error "File read failed"
1089 echo "Verifying file state after restore: "
1090 check_hsm_flags $f "0x00000009"
1092 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1094 [[ $? -eq 0 ]] || error "Restored file differs"
1098 run_test 12b "Restore an imported file implicitly"
1101 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1103 # test needs a running copytool
1107 local f=$DIR/$tdir/$tfile
1108 $LFS setstripe -c 2 $f
1109 local fid=$(make_large_for_striping $f)
1110 local FILE_CRC=$(md5sum $f)
1112 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1113 wait_request_state $fid ARCHIVE SUCCEED
1114 $LFS hsm_release $f || error "release $f failed"
1116 echo "$FILE_CRC" | md5sum -c
1118 [[ $? -eq 0 ]] || error "Restored file differs"
1122 run_test 12c "Restore a file with stripe of 2"
1125 # test needs a running copytool
1130 local f=$DIR/$tdir/$tfile
1131 local fid=$(copy_file /etc/hosts $f)
1132 $LFS hsm_restore $f || error "restore of non archived file failed"
1133 local cnt=$(get_request_count $fid RESTORE)
1134 [[ "$cnt" == "0" ]] ||
1135 error "restore non archived must not make a request"
1136 $LFS hsm_archive $f ||
1137 error "archive request failed"
1138 wait_request_state $fid ARCHIVE SUCCEED
1139 $LFS hsm_restore $f ||
1140 error "restore of non released file failed"
1141 local cnt=$(get_request_count $fid RESTORE)
1142 [[ "$cnt" == "0" ]] ||
1143 error "restore a non dirty file must not make a request"
1147 run_test 12d "Restore of a non archived, non released file must work"\
1148 " without doing request"
1151 # test needs a running copytool
1154 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1155 local f=$DIR/$tdir/$tfile
1156 local fid=$(copy_file /etc/hosts $f)
1157 $LFS hsm_archive $f || error "archive request failed"
1158 wait_request_state $fid ARCHIVE SUCCEED
1161 cat /etc/hosts >> $f
1165 $LFS hsm_restore $f && error "restore a dirty file must fail"
1169 run_test 12e "Check forbidden restore"
1172 # test needs a running copytool
1176 local f=$DIR/$tdir/$tfile
1177 local fid=$(copy_file /etc/hosts $f)
1179 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1180 wait_request_state $fid ARCHIVE SUCCEED
1181 $LFS hsm_release $f || error "release of $f failed"
1183 wait_request_state $fid RESTORE SUCCEED
1185 echo -n "Verifying file state: "
1186 check_hsm_flags $f "0x00000009"
1188 diff -q /etc/hosts $f
1190 [[ $? -eq 0 ]] || error "Restored file differs"
1194 run_test 12f "Restore a released file explicitly"
1197 # test needs a running copytool
1201 local f=$DIR/$tdir/$tfile
1202 local fid=$(copy_file /etc/hosts $f)
1204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1205 wait_request_state $fid ARCHIVE SUCCEED
1206 $LFS hsm_release $f || error "release of $f failed"
1208 diff -q /etc/hosts $f
1211 # we check we had a restore done
1212 wait_request_state $fid RESTORE SUCCEED
1214 [[ $st -eq 0 ]] || error "Restored file differs"
1218 run_test 12g "Restore a released file implicitly"
1221 needclients 2 || return 0
1223 # test needs a running copytool
1227 local f=$DIR/$tdir/$tfile
1228 local fid=$(copy_file /etc/hosts $f)
1230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1231 wait_request_state $fid ARCHIVE SUCCEED
1232 $LFS hsm_release $f || error "release of $f failed"
1234 do_node $CLIENT2 diff -q /etc/hosts $f
1237 # we check we had a restore done
1238 wait_request_state $fid RESTORE SUCCEED
1240 [[ $st -eq 0 ]] || error "Restored file differs"
1244 run_test 12h "Restore a released file implicitly from a second node"
1247 # test needs a running copytool
1251 local f=$DIR/$tdir/$tfile
1252 local fid=$(copy_file /etc/passwd $f)
1253 $LFS hsm_archive $f || error "archive of $f failed"
1254 wait_request_state $fid ARCHIVE SUCCEED
1256 $LFS hsm_release $f || error "release of $f failed"
1260 [[ $? -eq 0 ]] || error "Restored file differs"
1264 run_test 12m "Archive/release/implicit restore"
1267 # test needs a running copytool
1271 copy2archive /etc/hosts $tdir/$tfile
1273 local f=$DIR/$tdir/$tfile
1274 import_file $tdir/$tfile $f
1276 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1277 error "Restored file differs"
1279 $LFS hsm_release $f || error "release of $f failed"
1283 run_test 12n "Import/implicit restore/release"
1286 # test needs a running copytool
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/hosts $f)
1293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1294 wait_request_state $fid ARCHIVE SUCCEED
1295 $LFS hsm_release $f || error "release of $f failed"
1297 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1298 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1300 # set no retry action mode
1303 diff -q /etc/hosts $f
1306 # we check we had a restore failure
1307 wait_request_state $fid RESTORE FAILED
1309 [[ $st -eq 0 ]] && error "Restore must fail"
1311 # remove no retry action mode
1314 # check file is still released
1315 check_hsm_flags $f "0x0000000d"
1317 # retry w/o failure injection
1318 do_facet $SINGLEMDS lctl set_param fail_loc=0
1320 # to be sure previous RESTORE result is gone
1322 wait_for_grace_delay
1324 diff -q /etc/hosts $f
1327 # we check we had a restore done
1328 wait_request_state $fid RESTORE SUCCEED
1330 [[ $st -eq 0 ]] || error "Restored file differs"
1334 run_test 12o "Layout-swap failure during Restore leaves file released"
1337 # test needs a running copytool
1340 local ARC_SUBDIR="import.orig"
1344 # populate directory to be imported
1345 for d in $(seq 1 10); do
1346 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1347 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1348 for f in $(seq 1 10); do
1349 CURR_FILE="$CURR_DIR/$tfile.$f"
1350 # write file-specific data
1351 do_facet $SINGLEAGT \
1352 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1353 "file=$CURR_FILE > $CURR_FILE"
1357 import_file "$ARC_SUBDIR" $DIR/$tdir
1358 # diff lustre content and origin (triggers file restoration)
1359 # there must be 10x10 identical files, and no difference
1360 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1361 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1362 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1363 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1365 [ $cnt_diff -eq 0 ] ||
1366 error "$cnt_diff imported files differ from read data"
1367 [ $cnt_ok -eq 100 ] ||
1368 error "not enough identical files ($cnt_ok != 100)"
1372 run_test 13 "Recursively import and restore a directory"
1375 # test needs a running copytool
1380 local f=$DIR/$tdir/$tfile
1381 local fid=$(make_small $f)
1382 local sum=$(md5sum $f | awk '{print $1}')
1383 $LFS hsm_archive $f || error "could not archive file"
1384 wait_request_state $fid ARCHIVE SUCCEED
1388 # create released file (simulate llapi_hsm_import call)
1390 local fid2=$(path2fid $f)
1391 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1392 $LFS hsm_release $f || error "could not release file"
1394 # rebind the archive to the newly created file
1395 echo "rebind $fid to $fid2"
1397 do_facet $SINGLEAGT \
1398 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1399 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1401 # restore file and compare md5sum
1402 local sum2=$(md5sum $f | awk '{print $1}')
1404 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1408 run_test 14 "Rebind archived file to a new fid"
1411 # test needs a running copytool
1416 local f=$DIR/$tdir/$tfile
1418 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1422 for i in $(seq 1 $count); do
1423 fids[$i]=$(make_small $f.$i)
1424 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1425 $LFS hsm_archive $f.$i || error "could not archive file"
1427 wait_all_done $(($count*60))
1431 for i in $(seq 1 $count); do
1434 local fid2=$(path2fid $f.$i)
1435 # add the rebind operation to the list
1436 echo ${fids[$i]} $fid2 >> $tmpfile
1438 # set it released (simulate llapi_hsm_import call)
1439 $LFS hsm_set --archived --exists $f.$i ||
1440 error "could not force hsm flags"
1441 $LFS hsm_release $f.$i || error "could not release file"
1443 nl=$(wc -l < $tmpfile)
1444 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1446 echo "rebind list of files"
1447 do_facet $SINGLEAGT \
1448 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1449 --rebind $tmpfile $DIR" || error "could not rebind file list"
1451 # restore files and compare md5sum
1452 for i in $(seq 1 $count); do
1453 local sum2=$(md5sum $f.$i | awk '{print $1}')
1454 [[ $sum2 == ${sums[$i]} ]] ||
1455 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1461 run_test 15 "Rebind a list of files"
1464 # test needs a running copytool
1468 # create a known size file so we can verify transfer speed
1471 dd if=/dev/zero of=$ref bs=1M count=20
1474 local f=$DIR/$tdir/$tfile
1475 local fid=$(copy_file $ref $f)
1477 local start=$(date +%s)
1479 wait_request_state $fid ARCHIVE SUCCEED
1480 local end=$(date +%s)
1481 local duration=$((end - start))
1483 [[ $duration -ge $goal ]] ||
1484 error "Transfer is too fast $duration < $goal"
1488 run_test 16 "Test CT bandwith control option"
1493 local f=$DIR/$tdir/$tfile
1494 touch $f || error "touch $f failed"
1496 # Could not release a non-archived file
1497 $LFS hsm_release $f && error "release should not succeed"
1499 # For following tests, we must test them with HS_ARCHIVED set
1500 $LFS hsm_set --exists --archived $f || error "could not add flag"
1502 # Could not release a file if no-release is set
1503 $LFS hsm_set --norelease $f || error "could not add flag"
1504 $LFS hsm_release $f && error "release should not succeed"
1505 $LFS hsm_clear --norelease $f || error "could not remove flag"
1507 # Could not release a file if lost
1508 $LFS hsm_set --lost $f || error "could not add flag"
1509 $LFS hsm_release $f && error "release should not succeed"
1510 $LFS hsm_clear --lost $f || error "could not remove flag"
1512 # Could not release a file if dirty
1513 $LFS hsm_set --dirty $f || error "could not add flag"
1514 $LFS hsm_release $f && error "release should not succeed"
1515 $LFS hsm_clear --dirty $f || error "could not remove flag"
1517 run_test 20 "Release is not permitted"
1520 # test needs a running copytool
1524 local f=$DIR/$tdir/test_release
1526 # Create a file and check its states
1527 local fid=$(make_small $f)
1528 check_hsm_flags $f "0x00000000"
1530 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1531 # used until file is flushed to disk
1532 if [ $(facet_fstype ost1) == "zfs" ]; then
1533 # this causes an OST_SYNC rpc to be sent
1534 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1535 # clear locks to reread file data
1536 cancel_lru_locks osc
1539 local orig_size=$(stat -c "%s" $f)
1540 local orig_blocks=$(stat -c "%b" $f)
1542 start_full_debug_logging
1544 $LFS hsm_archive $f || error "could not archive file"
1545 wait_request_state $fid ARCHIVE SUCCEED
1547 local blocks=$(stat -c "%b" $f)
1548 [ $blocks -eq $orig_blocks ] ||
1549 error "$f: wrong block number after archive: " \
1550 "$blocks != $orig_blocks"
1551 local size=$(stat -c "%s" $f)
1552 [ $size -eq $orig_size ] ||
1553 error "$f: wrong size after archive: $size != $orig_size"
1555 # Release and check states
1556 $LFS hsm_release $f || error "could not release file"
1557 check_hsm_flags $f "0x0000000d"
1559 blocks=$(stat -c "%b" $f)
1560 [ $blocks -gt 5 ] &&
1561 error "$f: too many blocks after release: $blocks > 5"
1562 size=$(stat -c "%s" $f)
1563 [ $size -ne $orig_size ] &&
1564 error "$f: wrong size after release: $size != $orig_size"
1566 # Check we can release an file without stripe info
1570 check_hsm_flags $f "0x00000000"
1571 $LFS hsm_archive $f || error "could not archive file"
1572 wait_request_state $fid ARCHIVE SUCCEED
1574 # Release and check states
1575 $LFS hsm_release $f || error "could not release file"
1576 check_hsm_flags $f "0x0000000d"
1578 # Release again a file that is already released is OK
1579 $LFS hsm_release $f || fail "second release should succeed"
1580 check_hsm_flags $f "0x0000000d"
1582 stop_full_debug_logging
1586 run_test 21 "Simple release tests"
1589 # test needs a running copytool
1594 local f=$DIR/$tdir/test_release
1595 local swap=$DIR/$tdir/test_swap
1597 # Create a file and check its states
1598 local fid=$(make_small $f)
1599 check_hsm_flags $f "0x00000000"
1601 $LFS hsm_archive $f || error "could not archive file"
1602 wait_request_state $fid ARCHIVE SUCCEED
1604 # Release and check states
1605 $LFS hsm_release $f || error "could not release file"
1606 check_hsm_flags $f "0x0000000d"
1609 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1614 run_test 22 "Could not swap a release file"
1617 # test needs a running copytool
1622 local f=$DIR/$tdir/test_mtime
1624 # Create a file and check its states
1625 local fid=$(make_small $f)
1626 check_hsm_flags $f "0x00000000"
1628 $LFS hsm_archive $f || error "could not archive file"
1629 wait_request_state $fid ARCHIVE SUCCEED
1631 # Set modification time in the past
1632 touch -m -a -d @978261179 $f
1634 # Release and check states
1635 $LFS hsm_release $f || error "could not release file"
1636 check_hsm_flags $f "0x0000000d"
1638 local MTIME=$(stat -c "%Y" $f)
1639 local ATIME=$(stat -c "%X" $f)
1640 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1641 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1645 run_test 23 "Release does not change a/mtime (utime)"
1648 local file=$DIR/$tdir/$tfile
1657 # test needs a running copytool
1662 fid=$(make_small $file)
1664 # Create a file and check its states
1665 check_hsm_flags $file "0x00000000"
1667 # Ensure atime is less than mtime and ctime.
1671 atime0=$(stat -c "%X" $file)
1672 mtime0=$(stat -c "%Y" $file)
1673 ctime0=$(stat -c "%Z" $file)
1675 [ $atime0 -lt $mtime0 ] ||
1676 error "atime $atime0 is not less than mtime $mtime0"
1678 [ $atime0 -lt $ctime0 ] ||
1679 error "atime $atime0 is not less than ctime $ctime0"
1681 # Archive should not change any timestamps.
1682 $LFS hsm_archive $file || error "cannot archive '$file'"
1683 wait_request_state $fid ARCHIVE SUCCEED
1685 atime1=$(stat -c "%X" $file)
1686 mtime1=$(stat -c "%Y" $file)
1687 ctime1=$(stat -c "%Z" $file)
1689 [ $atime0 -eq $atime1 ] ||
1690 error "archive changed atime from $atime0 to $atime1"
1692 [ $mtime0 -eq $mtime1 ] ||
1693 error "archive changed mtime from $mtime0 to $mtime1"
1695 [ $ctime0 -eq $ctime1 ] ||
1696 error "archive changed ctime from $ctime0 to $ctime1"
1698 # Release should not change any timestamps.
1699 $LFS hsm_release $file || error "cannot release '$file'"
1700 check_hsm_flags $file "0x0000000d"
1702 atime1=$(stat -c "%X" $file)
1703 mtime1=$(stat -c "%Y" $file)
1704 ctime1=$(stat -c "%Z" $file)
1706 [ $atime0 -eq $atime1 ] ||
1707 error "release changed atime from $atime0 to $atime1"
1709 [ $mtime0 -eq $mtime1 ] ||
1710 error "release changed mtime from $mtime0 to $mtime1"
1712 [ $ctime0 -eq $ctime1 ] ||
1713 error "release changed ctime from $ctime0 to $ctime1"
1715 # Restore should not change atime or mtime and should not
1717 $LFS hsm_restore $file
1718 wait_request_state $fid RESTORE SUCCEED
1720 atime1=$(stat -c "%X" $file)
1721 mtime1=$(stat -c "%Y" $file)
1722 ctime1=$(stat -c "%Z" $file)
1724 [ $atime0 -eq $atime1 ] ||
1725 error "restore changed atime from $atime0 to $atime1"
1727 [ $mtime0 -eq $mtime1 ] ||
1728 error "restore changed mtime from $mtime0 to $mtime1"
1730 [ $ctime0 -le $ctime1 ] ||
1731 error "restore changed ctime from $ctime0 to $ctime1"
1735 # Once more, after unmount and mount.
1736 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1737 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1739 atime1=$(stat -c "%X" $file)
1740 mtime1=$(stat -c "%Y" $file)
1741 ctime1=$(stat -c "%Z" $file)
1743 [ $atime0 -eq $atime1 ] ||
1744 error "remount changed atime from $atime0 to $atime1"
1746 [ $mtime0 -eq $mtime1 ] ||
1747 error "remount changed mtime from $mtime0 to $mtime1"
1749 [ $ctime0 -le $ctime1 ] ||
1750 error "remount changed ctime from $ctime0 to $ctime1"
1752 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1755 local file=$DIR/$tdir/$tfile
1761 # Test needs a running copytool.
1765 # Check that root can do HSM actions on a ordinary user's file.
1767 fid=$(make_small $file)
1768 sum0=$(md5sum $file)
1770 chown $RUNAS_ID:$RUNAS_GID $file ||
1771 error "cannot chown '$file' to '$RUNAS_ID'"
1773 chmod ugo-w $DIR/$tdir ||
1774 error "cannot chmod '$DIR/$tdir'"
1776 $LFS hsm_archive $file
1777 wait_request_state $fid ARCHIVE SUCCEED
1779 $LFS hsm_release $file
1780 check_hsm_flags $file "0x0000000d"
1782 $LFS hsm_restore $file
1783 wait_request_state $fid RESTORE SUCCEED
1785 # Check that ordinary user can get HSM state.
1786 $RUNAS $LFS hsm_state $file ||
1787 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1789 $LFS hsm_release $file
1790 check_hsm_flags $file "0x0000000d"
1792 # Check that ordinary user can accessed released file.
1793 sum1=$($RUNAS md5sum $file) ||
1794 error "user '$RUNAS_ID' cannot read '$file'"
1796 [ "$sum0" == "$sum1" ] ||
1797 error "md5sum mismatch for '$file'"
1801 run_test 24b "root can archive, release, and restore user files"
1803 cleanup_test_24c() {
1805 set_hsm_param user_request_mask RESTORE
1806 set_hsm_param group_request_mask RESTORE
1807 set_hsm_param other_request_mask RESTORE
1811 local file=$DIR/$tdir/$tfile
1812 local action=archive
1817 # test needs a running copytool
1822 # Save the default masks and check that cleanup_24c will
1823 # restore the request masks correctly.
1824 user_save=$(get_hsm_param user_request_mask)
1825 group_save=$(get_hsm_param group_request_mask)
1826 other_save=$(get_hsm_param other_request_mask)
1828 [ "$user_save" == RESTORE ] ||
1829 error "user_request_mask is '$user_save' expected 'RESTORE'"
1830 [ "$group_save" == RESTORE ] ||
1831 error "group_request_mask is '$group_save' expected 'RESTORE'"
1832 [ "$other_save" == RESTORE ] ||
1833 error "other_request_mask is '$other_save' expected 'RESTORE'"
1835 trap cleanup_test_24c EXIT
1840 chown $RUNAS_ID:nobody $file ||
1841 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1843 set_hsm_param user_request_mask ""
1844 $RUNAS $LFS hsm_$action $file &&
1845 error "$action by user should fail"
1847 set_hsm_param user_request_mask $action
1848 $RUNAS $LFS hsm_$action $file ||
1849 error "$action by user should succeed"
1854 chown nobody:$RUNAS_GID $file ||
1855 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1857 set_hsm_param group_request_mask ""
1858 $RUNAS $LFS hsm_$action $file &&
1859 error "$action by group should fail"
1861 set_hsm_param group_request_mask $action
1862 $RUNAS $LFS hsm_$action $file ||
1863 error "$action by group should succeed"
1868 chown nobody:nobody $file ||
1869 error "cannot chown '$file' to 'nobody:nobody'"
1871 set_hsm_param other_request_mask ""
1872 $RUNAS $LFS hsm_$action $file &&
1873 error "$action by other should fail"
1875 set_hsm_param other_request_mask $action
1876 $RUNAS $LFS hsm_$action $file ||
1877 error "$action by other should succeed"
1882 run_test 24c "check that user,group,other request masks work"
1884 cleanup_test_24d() {
1886 mount -o remount,rw $MOUNT2
1890 local file1=$DIR/$tdir/$tfile
1891 local file2=$DIR2/$tdir/$tfile
1899 fid1=$(make_small $file1)
1901 trap cleanup_test_24d EXIT
1903 mount -o remount,ro $MOUNT2
1905 fid2=$(path2fid $file2)
1906 [ "$fid1" == "$fid2" ] ||
1907 error "FID mismatch '$fid1' != '$fid2'"
1909 $LFS hsm_archive $file2 &&
1910 error "archive should fail on read-only mount"
1911 check_hsm_flags $file1 "0x00000000"
1913 $LFS hsm_archive $file1
1914 wait_request_state $fid1 ARCHIVE SUCCEED
1916 $LFS hsm_release $file1
1917 $LFS hsm_restore $file2
1918 wait_request_state $fid1 RESTORE SUCCEED
1920 $LFS hsm_release $file1 || error "cannot release '$file1'"
1921 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1923 $LFS hsm_release $file2 &&
1924 error "release should fail on read-only mount"
1929 run_test 24d "check that read-only mounts are respected"
1932 # test needs a running copytool
1936 copy2archive /etc/hosts $tdir/$tfile
1938 local f=$DIR/$tdir/$tfile
1940 import_file $tdir/$tfile $f
1942 $LFS hsm_set --lost $f
1947 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1951 run_test 25a "Restore lost file (HS_LOST flag) from import"\
1952 " (Operation not permitted)"
1955 # test needs a running copytool
1960 local f=$DIR/$tdir/$tfile
1961 local fid=$(copy_file /etc/passwd $f)
1963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1964 wait_request_state $fid ARCHIVE SUCCEED
1967 $LFS hsm_set --lost $f
1971 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
1975 run_test 25b "Restore lost file (HS_LOST flag) after release"\
1976 " (Operation not permitted)"
1979 # test needs a running copytool
1983 local f=$DIR/$tdir/$tfile
1984 local fid=$(make_large_for_progress $f)
1985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1986 wait_request_state $fid ARCHIVE SUCCEED
1989 wait_request_state $fid REMOVE SUCCEED
1991 check_hsm_flags $f "0x00000000"
1995 run_test 26 "Remove the archive of a valid file"
1998 # test needs a running copytool
2002 make_archive $tdir/$tfile
2003 local f=$DIR/$tdir/$tfile
2004 import_file $tdir/$tfile $f
2005 local fid=$(path2fid $f)
2009 [[ $? != 0 ]] || error "Remove of a released file should fail"
2013 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2016 # test needs a running copytool
2020 local f=$DIR/$tdir/$tfile
2021 local fid=$(make_large_for_progress $f)
2022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2023 wait_request_state $fid ARCHIVE SUCCEED
2028 [[ $? != 0 ]] || error "Remove of a released file should fail"
2032 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2035 # test needs a running copytool
2039 local f=$DIR/$tdir/$tfile
2040 local fid=$(make_large_for_progress $f)
2041 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2042 wait_request_state $fid ARCHIVE SUCCEED
2051 wait_request_state $fid REMOVE SUCCEED
2055 run_test 28 "Concurrent archive/file remove"
2058 # restore at exec cannot work on agent node (because of Linux kernel
2059 # protection of executables)
2060 needclients 2 || return 0
2062 # test needs a running copytool
2066 copy2archive /bin/true $tdir/$tfile
2068 local f=$DIR/$tdir/true
2069 import_file $tdir/$tfile $f
2071 local fid=$(path2fid $f)
2073 # set no retry action mode
2079 # remove no try action mode
2083 [[ $st == 0 ]] || error "Failed to exec a released file"
2087 run_test 30a "Restore at exec (import case)"
2090 # restore at exec cannot work on agent node (because of Linux kernel
2091 # protection of executables)
2092 needclients 2 || return 0
2094 # test needs a running copytool
2098 local f=$DIR/$tdir/true
2099 local fid=$(copy_file /bin/true $f)
2101 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2102 wait_request_state $fid ARCHIVE SUCCEED
2105 # set no retry action mode
2111 # remove no try action mode
2115 [[ $st == 0 ]] || error "Failed to exec a released file"
2119 run_test 30b "Restore at exec (release case)"
2122 needclients 2 || return 0
2124 # test needs a running copytool
2128 local f=$DIR/$tdir/SLEEP
2129 local fid=$(copy_file /bin/sleep $f)
2131 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2132 wait_request_state $fid ARCHIVE SUCCEED
2134 check_hsm_flags $f "0x0000000d"
2135 # set no retry action mode
2137 do_node $CLIENT2 "$f 10" &
2141 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2143 [[ $? == 0 ]] || error "Execution failed during run"
2145 [[ $? == 0 ]] || error "Binary overwritten during exec"
2148 # remove no try action mode
2150 check_hsm_flags $f "0x00000009"
2154 run_test 30c "Update during exec of released file must fail"
2156 restore_and_check_size() {
2159 local s=$(stat -c "%s" $f)
2161 local st=$(get_hsm_flags $f)
2165 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2167 n=$(stat -c "%s" $f)
2168 # we echo in both cases to show stat is not
2170 if [[ $n != $s ]]; then
2171 echo "size seen is $n != $s"
2174 echo "size seen is right: $n == $s"
2176 st=$(get_hsm_flags $f)
2180 if [[ $cpt -lt 10 ]]; then
2183 echo " restore is too long"
2184 wait_request_state $fid RESTORE SUCCEED
2190 # test needs a running copytool
2195 make_archive $tdir/$tfile
2196 local f=$DIR/$tdir/$tfile
2197 import_file $tdir/$tfile $f
2198 local fid=$($LFS path2fid $f)
2199 HSM_ARCHIVE_PURGE=false copytool_setup
2201 restore_and_check_size $f $fid
2204 [[ $err -eq 0 ]] || error "File size changed during restore"
2208 run_test 31a "Import a large file and check size during restore"
2212 # test needs a running copytool
2217 local f=$DIR/$tdir/$tfile
2218 local fid=$(make_large_for_progress $f)
2219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2220 wait_request_state $fid ARCHIVE SUCCEED
2223 restore_and_check_size $f $fid
2226 [[ $err -eq 0 ]] || error "File size changed during restore"
2230 run_test 31b "Restore a large unaligned file and check size during restore"
2233 # test needs a running copytool
2238 local f=$DIR/$tdir/$tfile
2239 local fid=$(make_large_for_progress_aligned $f)
2240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2241 wait_request_state $fid ARCHIVE SUCCEED
2244 restore_and_check_size $f $fid
2247 [[ $err -eq 0 ]] || error "File size changed during restore"
2251 run_test 31c "Restore a large aligned file and check size during restore"
2254 # test needs a running copytool
2259 local f=$DIR/$tdir/$tfile
2260 local fid=$(make_large_for_progress $f)
2261 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2262 wait_request_state $fid ARCHIVE SUCCEED
2265 # to be sure wait_all_done will not be mislead by previous tests
2268 wait_for_grace_delay
2269 # Also raise grace_delay significantly so the Canceled
2270 # Restore action will stay enough long avail.
2271 local old_grace=$(get_hsm_param grace_delay)
2272 set_hsm_param grace_delay 100
2274 md5sum $f >/dev/null &
2276 wait_request_state $fid RESTORE STARTED
2281 # Check restore trigger process was killed
2282 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2286 # instead of waiting+checking both Restore and Cancel ops
2287 # sequentially, wait for both to be finished and then check
2289 wait_all_done 100 $fid
2290 local rstate=$(get_request_state $fid RESTORE)
2291 local cstate=$(get_request_state $fid CANCEL)
2293 # restore orig grace_delay.
2294 set_hsm_param grace_delay $old_grace
2296 if [[ "$rstate" == "CANCELED" ]] ; then
2297 [[ "$cstate" == "SUCCEED" ]] ||
2298 error "Restore state is CANCELED and Cancel state " \
2299 "is not SUCCEED but $cstate"
2300 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2301 elif [[ "$rstate" == "SUCCEED" ]] ; then
2302 [[ "$cstate" == "FAILED" ]] ||
2303 error "Restore state is SUCCEED and Cancel state " \
2304 "is not FAILED but $cstate"
2305 echo "Restore state is SUCCEED, Cancel state is FAILED"
2307 error "Restore state is $rstate and Cancel state is $cstate"
2311 error "Cannot kill process waiting for restore ($killed)"
2315 run_test 33 "Kill a restore waiting process"
2318 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2324 local fid=$(make_large_for_progress $f)
2325 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2326 wait_request_state $fid ARCHIVE SUCCEED
2329 md5sum $f >/dev/null &
2331 wait_request_state $fid RESTORE STARTED
2333 rm $f || error "rm $f failed"
2334 # rm must not block during restore
2335 wait_request_state $fid RESTORE STARTED
2337 wait_request_state $fid RESTORE SUCCEED
2338 # check md5sum pgm finished
2339 local there=$(ps -o pid,comm hp $pid >/dev/null)
2340 [[ -z $there ]] || error "Restore initiator does not exit"
2342 local rc=$(wait $pid)
2343 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2347 run_test 34 "Remove file during restore"
2350 # test needs a running copytool
2355 local f=$DIR/$tdir/$tfile
2356 local f1=$DIR/$tdir/$tfile-1
2357 local fid=$(make_large_for_progress $f)
2358 local fid1=$(copy_file /etc/passwd $f1)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2360 wait_request_state $fid ARCHIVE SUCCEED
2363 md5sum $f >/dev/null &
2365 wait_request_state $fid RESTORE STARTED
2367 mv $f1 $f || error "mv $f1 $f failed"
2368 # mv must not block during restore
2369 wait_request_state $fid RESTORE STARTED
2371 wait_request_state $fid RESTORE SUCCEED
2372 # check md5sum pgm finished
2373 local there=$(ps -o pid,comm hp $pid >/dev/null)
2374 [[ -z $there ]] || error "Restore initiator does not exit"
2376 local rc=$(wait $pid)
2377 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2380 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2384 run_test 35 "Overwrite file during restore"
2387 # test needs a running copytool
2392 local f=$DIR/$tdir/$tfile
2393 local fid=$(make_large_for_progress $f)
2394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2395 wait_request_state $fid ARCHIVE SUCCEED
2398 md5sum $f >/dev/null &
2400 wait_request_state $fid RESTORE STARTED
2403 # rm must not block during restore
2404 wait_request_state $fid RESTORE STARTED
2406 wait_request_state $fid RESTORE SUCCEED
2407 # check md5sum pgm finished
2408 local there=$(ps -o pid,comm hp $pid >/dev/null)
2410 error "Restore initiator does not exit"
2412 local rc=$(wait $pid)
2414 error "Restore initiator failed with $rc"
2418 run_test 36 "Move file during restore"
2425 for n in $(seq 1 $count); do
2426 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2428 echo "$count archive requests submitted"
2432 local stream_count=4
2433 local file_count=100
2435 local f=$DIR/$tdir/$tfile
2440 for i in $(seq 1 $file_count); do
2441 for p in $(seq 1 $stream_count); do
2442 fid=$(copy_file /etc/hosts $f.$p.$i)
2445 # force copytool to use a local/temp archive dir to ensure best
2446 # performance vs remote/NFS mounts used in auto-tests
2447 if df --local $HSM_ARCHIVE >/dev/null 2>&1 ; then
2450 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2452 # to be sure wait_all_done will not be mislead by previous tests
2454 wait_for_grace_delay
2456 # start archive streams in background (archive files in parallel)
2457 for p in $(seq 1 $stream_count); do
2458 multi_archive $f.$p $file_count &
2461 echo -n "Wait for all requests being enqueued..."
2467 run_test 40 "Parallel archive requests"
2470 # test needs a running copytool
2474 local f=$DIR/$tdir/$tfile
2475 local fid=$(copy_file /etc/motd $f 1)
2477 $LFS hsm_archive $f || error "could not archive file"
2478 wait_request_state $fid ARCHIVE SUCCEED
2479 check_hsm_flags $f "0x00000009"
2481 multiop_bg_pause $f O_c || error "multiop failed"
2485 client_up || client_up || true
2487 kill -USR1 $MULTIPID
2488 wait $MULTIPID || error "multiop close failed"
2490 check_hsm_flags $f "0x0000000b"
2494 run_test 52 "Opened for write file on an evicted client should be set dirty"
2497 # test needs a running copytool
2501 local f=$DIR/$tdir/$tfile
2502 local fid=$(copy_file /etc/motd $f 1)
2504 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2505 error "could not archive file"
2506 wait_request_state $fid ARCHIVE SUCCEED
2507 check_hsm_flags $f "0x00000009"
2509 multiop_bg_pause $f o_c || error "multiop failed"
2513 client_up || client_up || true
2515 kill -USR1 $MULTIPID
2516 wait $MULTIPID || error "multiop close failed"
2518 check_hsm_flags $f "0x00000009"
2522 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2525 # test needs a running copytool
2529 local f=$DIR/$tdir/$tfile
2530 local fid=$(make_small $f)
2532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2533 error "could not archive file"
2534 wait_request_state $fid ARCHIVE STARTED
2536 check_hsm_flags $f "0x00000001"
2538 # Avoid coordinator resending this request as soon it has failed.
2543 wait_request_state $fid ARCHIVE FAILED
2545 check_hsm_flags $f "0x00000003"
2550 run_test 54 "Write during an archive cancels it"
2553 # test needs a running copytool
2557 local f=$DIR/$tdir/$tfile
2558 local fid=$(make_small $f)
2560 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2561 error "could not archive file"
2562 wait_request_state $fid ARCHIVE STARTED
2564 check_hsm_flags $f "0x00000001"
2566 # Avoid coordinator resending this request as soon it has failed.
2569 $TRUNCATE $f 1024 || error "truncate failed"
2571 wait_request_state $fid ARCHIVE FAILED
2573 check_hsm_flags $f "0x00000003"
2578 run_test 55 "Truncate during an archive cancels it"
2581 # test needs a running copytool
2585 local f=$DIR/$tdir/$tfile
2586 local fid=$(make_large_for_progress $f)
2588 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2589 error "could not archive file"
2590 wait_request_state $fid ARCHIVE STARTED
2592 check_hsm_flags $f "0x00000001"
2594 # Change metadata and sync to be sure we are not changing only
2599 wait_request_state $fid ARCHIVE SUCCEED
2601 check_hsm_flags $f "0x00000009"
2605 run_test 56 "Setattr during an archive is ok"
2608 # Need one client for I/O, one for request
2609 needclients 2 || return 0
2611 # test needs a running copytool
2615 local f=$DIR/$tdir/test_archive_remote
2616 # Create a file on a remote node
2617 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2618 "count=2 conv=fsync"
2621 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2622 error "hsm_archive failed"
2623 local fid=$(path2fid $f)
2624 wait_request_state $fid ARCHIVE SUCCEED
2626 # Release and implicit restore it
2627 do_node $CLIENT2 "$LFS hsm_release $f" ||
2628 error "hsm_release failed"
2629 do_node $CLIENT2 "md5sum $f" ||
2630 error "hsm_restore failed"
2632 wait_request_state $fid RESTORE SUCCEED
2636 run_test 57 "Archive a file with dirty cache on another node"
2638 truncate_released_file() {
2642 local sz=$(stat -c %s $src_file)
2643 local f=$DIR/$tdir/$tfile
2644 local fid=$(copy_file $1 $f)
2648 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2649 error "could not archive file"
2650 wait_request_state $fid ARCHIVE SUCCEED
2652 $LFS hsm_release $f || error "could not release file"
2654 $TRUNCATE $f $trunc_to || error "truncate failed"
2657 local sz1=$(stat -c %s $f)
2658 [[ $sz1 == $trunc_to ]] ||
2659 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2662 check_hsm_flags $f "0x0000000b"
2664 local state=$(get_request_state $fid RESTORE)
2665 [[ "$state" == "SUCCEED" ]] ||
2666 error "truncate $sz does not trig restore, state = $state"
2668 $TRUNCATE $ref $trunc_to
2669 cmp $ref $f || error "file data wrong after truncate"
2675 # test needs a running copytool
2680 local sz=$(stat -c %s /etc/passwd)
2682 echo "truncate up from $sz to $((sz*2))"
2683 truncate_released_file /etc/passwd $((sz*2))
2685 echo "truncate down from $sz to $((sz/2))"
2686 truncate_released_file /etc/passwd $((sz/2))
2688 echo "truncate to 0"
2689 truncate_released_file /etc/passwd 0
2693 run_test 58 "Truncate a released file will trigger restore"
2696 # This test validates the fix for LU-4512. Ensure that the -u
2697 # option changes the progress reporting interval from the default
2698 # (30 seconds) to the user-specified interval.
2700 local progress_timeout=$((interval * 3))
2702 # test needs a new running copytool
2704 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2707 local f=$DIR/$tdir/$tfile
2708 local fid=$(make_large_for_progress $f)
2710 local start_at=$(date +%s)
2711 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2712 error "could not archive file"
2715 local mdt=${MDT_PREFIX}${mdtidx}
2716 local mds=mds$((mdtidx + 1))
2718 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2719 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2725 echo -n "Expecting a progress update within $progress_timeout seconds... "
2727 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2728 if [ $RESULT -gt 0 ]; then
2729 echo "$RESULT bytes copied in $WAIT seconds."
2731 elif [ $WAIT -ge $progress_timeout ]; then
2732 error "Timed out waiting for progress update!"
2735 WAIT=$((WAIT + sleep))
2739 local finish_at=$(date +%s)
2740 local elapsed=$((finish_at - start_at))
2742 # Ensure that the progress update occurred within the expected window.
2743 if [ $elapsed -lt $interval ]; then
2744 error "Expected progress update after at least $interval seconds"
2750 run_test 60 "Changing progress update interval from default"
2753 # test needs a new running copytool
2755 copytool_monitor_setup
2756 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2758 # Just start and stop the copytool to generate events.
2762 local REGISTER_EVENT
2763 local UNREGISTER_EVENT
2764 while read event; do
2765 local parsed=$(parse_json_event "$event")
2766 if [ -z "$parsed" ]; then
2767 error "Copytool sent malformed event: $event"
2771 if [ $event_type == "REGISTER" ]; then
2772 REGISTER_EVENT=$event
2773 elif [ $event_type == "UNREGISTER" ]; then
2774 UNREGISTER_EVENT=$event
2776 done < <(echo $"$(get_copytool_event_log)")
2778 if [ -z "$REGISTER_EVENT" ]; then
2779 error "Copytool failed to send register event to FIFO"
2782 if [ -z "$UNREGISTER_EVENT" ]; then
2783 error "Copytool failed to send unregister event to FIFO"
2786 copytool_monitor_cleanup
2787 echo "Register/Unregister events look OK."
2789 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2792 # Bump progress interval for livelier events.
2795 # test needs a new running copytool
2797 copytool_monitor_setup
2798 HSMTOOL_UPDATE_INTERVAL=$interval \
2799 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2802 local f=$DIR/$tdir/$tfile
2803 local fid=$(make_large_for_progress $f)
2805 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2806 error "could not archive file"
2807 wait_request_state $fid ARCHIVE SUCCEED
2809 local expected_fields="event_time data_fid source_fid"
2810 expected_fields+=" total_bytes current_bytes"
2814 while read event; do
2815 # Make sure we're not getting anything from previous events.
2816 for field in $expected_fields; do
2820 local parsed=$(parse_json_event "$event")
2821 if [ -z "$parsed" ]; then
2822 error "Copytool sent malformed event: $event"
2826 if [ $event_type == "ARCHIVE_START" ]; then
2829 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2832 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2836 # Do some simple checking of the progress update events.
2837 for expected_field in $expected_fields; do
2838 if [ -z ${!expected_field+x} ]; then
2839 error "Missing $expected_field field in event"
2843 if [ $total_bytes -eq 0 ]; then
2844 error "Expected total_bytes to be > 0"
2847 # These should be identical throughout an archive
2849 if [ $source_fid != $data_fid ]; then
2850 error "Expected source_fid to equal data_fid"
2852 done < <(echo $"$(get_copytool_event_log)")
2854 if [ -z "$START_EVENT" ]; then
2855 error "Copytool failed to send archive start event to FIFO"
2858 if [ -z "$FINISH_EVENT" ]; then
2859 error "Copytool failed to send archive finish event to FIFO"
2862 echo "Archive events look OK."
2866 copytool_monitor_cleanup
2868 run_test 71 "Copytool logs JSON archive events to FIFO"
2871 # Bump progress interval for livelier events.
2874 # test needs a new running copytool
2876 copytool_monitor_setup
2877 HSMTOOL_UPDATE_INTERVAL=$interval \
2878 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2879 local test_file=$HSMTOOL_MONITOR_DIR/file
2881 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
2883 do_facet $SINGLEAGT "$cmd" ||
2884 error "cannot create $test_file on $SINGLEAGT"
2885 copy2archive $test_file $tdir/$tfile
2888 local f=$DIR/$tdir/$tfile
2889 import_file $tdir/$tfile $f
2890 f=$DIR2/$tdir/$tfile
2891 echo "Verifying released state: "
2892 check_hsm_flags $f "0x0000000d"
2894 local fid=$(path2fid $f)
2896 wait_request_state $fid RESTORE SUCCEED
2898 local expected_fields="event_time data_fid source_fid"
2899 expected_fields+=" total_bytes current_bytes"
2903 while read event; do
2904 # Make sure we're not getting anything from previous events.
2905 for field in $expected_fields; do
2909 local parsed=$(parse_json_event "$event")
2910 if [ -z "$parsed" ]; then
2911 error "Copytool sent malformed event: $event"
2915 if [ $event_type == "RESTORE_START" ]; then
2917 if [ $source_fid != $data_fid ]; then
2918 error "source_fid should == data_fid at start"
2921 elif [ $event_type == "RESTORE_FINISH" ]; then
2923 if [ $source_fid != $data_fid ]; then
2924 error "source_fid should == data_fid at finish"
2927 elif [ $event_type != "RESTORE_RUNNING" ]; then
2931 # Do some simple checking of the progress update events.
2932 for expected_field in $expected_fields; do
2933 if [ -z ${!expected_field+x} ]; then
2934 error "Missing $expected_field field in event"
2938 if [ $total_bytes -eq 0 ]; then
2939 error "Expected total_bytes to be > 0"
2942 # When a restore starts out, the data fid is the same as the
2943 # source fid. After the restore has gotten going, we learn
2944 # the new data fid. Once the restore has finished, the source
2945 # fid is set to the new data fid.
2947 # We test this because some monitoring software may depend on
2948 # this behavior. If it changes, then the consumers of these
2949 # events may need to be modified.
2950 if [ $source_fid == $data_fid ]; then
2951 error "source_fid should != data_fid during restore"
2953 done < <(echo $"$(get_copytool_event_log)")
2955 if [ -z "$START_EVENT" ]; then
2956 error "Copytool failed to send restore start event to FIFO"
2959 if [ -z "$FINISH_EVENT" ]; then
2960 error "Copytool failed to send restore finish event to FIFO"
2963 echo "Restore events look OK."
2967 copytool_monitor_cleanup
2971 run_test 72 "Copytool logs JSON restore events to FIFO"
2974 file_count=51 # Max number of files constrained by LNET message size
2975 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2976 local f=$DIR/$tdir/$tfile
2977 local FILELIST=/tmp/filelist.txt
2981 for i in $(seq 1 $file_count); do
2982 fid=$(copy_file /etc/hosts $f.$i)
2983 echo $f.$i >> $FILELIST
2986 # to be sure wait_all_done will not be mislead by previous tests
2988 wait_for_grace_delay
2989 $LFS hsm_archive --filelist $FILELIST ||
2990 error "cannot archive a file list"
2992 $LFS hsm_release --filelist $FILELIST ||
2993 error "cannot release a file list"
2994 $LFS hsm_restore --filelist $FILELIST ||
2995 error "cannot restore a file list"
2999 run_test 90 "Archive/restore a file list"
3001 double_verify_reset_hsm_param() {
3003 echo "Testing $HSM_PARAM.$p"
3004 local val=$(get_hsm_param $p)
3006 local val2=$(($val * 2))
3007 set_hsm_param $p $val2
3008 val=$(get_hsm_param $p)
3009 [[ $val == $val2 ]] ||
3010 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3011 echo "Set $p to 0 must failed"
3015 set_hsm_param $p $save
3017 if [[ $rc == 0 ]]; then
3018 error "we must not be able to set $HSM_PARAM.$p to 0"
3023 double_verify_reset_hsm_param loop_period
3024 double_verify_reset_hsm_param grace_delay
3025 double_verify_reset_hsm_param active_request_timeout
3026 double_verify_reset_hsm_param max_requests
3027 double_verify_reset_hsm_param default_archive_id
3029 run_test 100 "Set coordinator /proc tunables"
3036 run_test 102 "Verify coordinator control"
3039 # test needs a running copytool
3046 for i in $(seq 1 20); do
3047 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3049 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3053 echo "Current requests"
3054 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3055 $HSM_PARAM.actions |\
3056 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3058 [[ -z "$res" ]] || error "Some request have not been canceled"
3062 run_test 103 "Purge all requests"
3067 # test needs a running copytool
3071 local f=$DIR/$tdir/$tfile
3072 local fid=$(make_large_for_progress $f)
3073 # if cdt is on, it can serve too quickly the request
3075 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3076 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3077 $HSM_PARAM.actions |\
3078 grep $fid | cut -f16 -d=")
3081 [[ "$data1" == "$DATAHEX" ]] ||
3082 error "Data field in records is ($data1) and not ($DATAHEX)"
3086 run_test 104 "Copy tool data field"
3093 for i in $(seq -w 1 10); do
3094 cp /etc/passwd $DIR/$tdir/$i
3095 $LFS hsm_archive $DIR/$tdir/$i
3097 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3098 $HSM_PARAM.actions |\
3099 grep WAITING | wc -l")
3102 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3103 $HSM_PARAM.actions |\
3104 grep WAITING | wc -l")
3107 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3108 error "Requests count after shutdown $reqcnt2 != "\
3109 "before shutdown $reqcnt1"
3111 run_test 105 "Restart of coordinator"
3113 get_agent_by_uuid_mdt() {
3116 local mds=mds$(($mdtidx + 1))
3117 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3121 check_agent_registered_by_mdt() {
3124 local mds=mds$(($mdtidx + 1))
3125 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3126 if [[ ! -z "$agent" ]]; then
3127 echo "found agent $agent on $mds"
3129 error "uuid $uuid not found in agent list on $mds"
3133 check_agent_unregistered_by_mdt() {
3136 local mds=mds$(($mdtidx + 1))
3137 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3138 if [[ -z "$agent" ]]; then
3139 echo "uuid not found in agent list on $mds"
3141 error "uuid found in agent list on $mds: $agent"
3145 check_agent_registered() {
3148 for mdsno in $(seq 1 $MDSCOUNT); do
3149 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3153 check_agent_unregistered() {
3156 for mdsno in $(seq 1 $MDSCOUNT); do
3157 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3162 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3163 get_client_uuid $MOUNT | cut -d' ' -f2)
3166 check_agent_registered $uuid
3168 search_copytools || error "No copytool found"
3171 check_agent_unregistered $uuid
3174 check_agent_registered $uuid
3178 run_test 106 "Copytool register/unregister"
3181 # test needs a running copytool
3183 # create and archive file
3185 local f1=$DIR/$tdir/$tfile
3186 local fid=$(copy_file /etc/passwd $f1)
3187 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3188 wait_request_state $fid ARCHIVE SUCCEED
3189 # shutdown and restart MDS
3191 # check the copytool still gets messages from MDT
3192 local f2=$DIR/$tdir/2
3193 local fid=$(copy_file /etc/passwd $f2)
3194 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3195 # main check of this sanity: this request MUST succeed
3196 wait_request_state $fid ARCHIVE SUCCEED
3199 run_test 107 "Copytool re-register after MDS restart"
3201 policy_set_and_test()
3205 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3206 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3207 [[ "$policy" == "$target" ]] ||
3208 error "Wrong policy after '$change': '$policy' != '$target'"
3212 # to force default policy setting if error
3213 CDT_POLICY_HAD_CHANGED=true
3215 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3216 local default="NonBlockingRestore [NoRetryAction]"
3217 [[ "$policy" == "$default" ]] ||
3218 error "default policy has changed,"\
3219 " '$policy' != '$default' update the test"
3220 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3221 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3222 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3223 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3224 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3225 # useless bacause we know but safer for futur changes to use real value
3226 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3227 echo "Next set_param must failed"
3228 policy_set_and_test "wrong" "$policy"
3231 echo "Back to default policy"
3232 cdt_set_sanity_policy
3234 run_test 109 "Policy display/change"
3237 # test needs a running copytool
3242 copy2archive /etc/passwd $tdir/$tfile
3244 local f=$DIR/$tdir/$tfile
3245 import_file $tdir/$tfile $f
3246 local fid=$(path2fid $f)
3248 cdt_set_non_blocking_restore
3253 wait_request_state $fid RESTORE SUCCEED
3254 cdt_clear_non_blocking_restore
3258 error "md5sum returns $st != 1, "\
3259 "should also perror ENODATA (No data available)"
3263 run_test 110a "Non blocking restore policy (import case)"
3266 # test needs a running copytool
3270 local f=$DIR/$tdir/$tfile
3271 local fid=$(copy_file /etc/passwd $f)
3272 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3273 wait_request_state $fid ARCHIVE SUCCEED
3276 cdt_set_non_blocking_restore
3281 wait_request_state $fid RESTORE SUCCEED
3282 cdt_clear_non_blocking_restore
3286 error "md5sum returns $st != 1, "\
3287 "should also perror ENODATA (No data available)"
3291 run_test 110b "Non blocking restore policy (release case)"
3294 # test needs a running copytool
3298 copy2archive /etc/passwd $tdir/$tfile
3300 local f=$DIR/$tdir/$tfile
3302 import_file $tdir/$tfile $f
3303 local fid=$(path2fid $f)
3307 copytool_remove_backend $fid
3310 wait_request_state $fid RESTORE FAILED
3317 [[ $st == 0 ]] || error "Restore does not failed"
3321 run_test 111a "No retry policy (import case), restore will error"\
3322 " (No such file or directory)"
3325 # test needs a running copytool
3329 local f=$DIR/$tdir/$tfile
3330 local fid=$(copy_file /etc/passwd $f)
3332 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3333 wait_request_state $fid ARCHIVE SUCCEED
3336 copytool_remove_backend $fid
3339 wait_request_state $fid RESTORE FAILED
3346 [[ $st == 0 ]] || error "Restore does not failed"
3350 run_test 111b "No retry policy (release case), restore will error"\
3351 " (No such file or directory)"
3354 # test needs a running copytool
3358 local f=$DIR/$tdir/$tfile
3359 local fid=$(copy_file /etc/passwd $f)
3361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3362 local l=$($LFS hsm_action $f)
3364 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3368 wait_request_state $fid ARCHIVE SUCCEED
3371 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3375 run_test 112 "State of recorded request"
3378 # test needs a running copytool
3382 local f=$DIR/$tdir/$tfile
3383 local fid=$(make_large_for_cancel $f)
3384 # test with cdt on is made in test_221
3386 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3389 wait_request_state $fid ARCHIVE CANCELED
3390 wait_request_state $fid CANCEL SUCCEED
3394 run_test 200 "Register/Cancel archive"
3397 # test needs a running copytool
3401 local f=$DIR/$tdir/$tfile
3402 make_archive $tdir/$tfile
3403 import_file $tdir/$tfile $f
3404 local fid=$(path2fid $f)
3406 # test with cdt on is made in test_222
3411 wait_request_state $fid RESTORE CANCELED
3412 wait_request_state $fid CANCEL SUCCEED
3416 run_test 201 "Register/Cancel restore"
3419 # test needs a running copytool
3423 local f=$DIR/$tdir/$tfile
3424 local fid=$(make_large_for_progress $f)
3425 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3426 wait_request_state $fid ARCHIVE SUCCEED
3432 wait_request_state $fid REMOVE CANCELED
3436 run_test 202 "Register/Cancel remove"
3439 # test needs a running copytool
3444 local f=$DIR/$tdir/$tfile
3445 local fid=$(copy_file /etc/passwd $f)
3449 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3450 wait_request_state $fid ARCHIVE SUCCEED
3452 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3456 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3460 run_test 220 "Changelog for archive"
3463 # test needs a running copytool
3468 local f=$DIR/$tdir/$tfile
3469 local fid=$(make_large_for_cancel $f)
3473 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3474 wait_request_state $fid ARCHIVE STARTED
3476 wait_request_state $fid ARCHIVE CANCELED
3477 wait_request_state $fid CANCEL SUCCEED
3479 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3482 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3486 run_test 221 "Changelog for archive canceled"
3489 # test needs a running copytool
3493 copy2archive /etc/passwd $tdir/$tfile
3495 local f=$DIR/$tdir/$tfile
3496 import_file $tdir/$tfile $f
3497 local fid=$(path2fid $f)
3502 wait_request_state $fid RESTORE SUCCEED
3504 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3507 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3511 run_test 222a "Changelog for explicit restore"
3514 # test needs a running copytool
3518 local f=$DIR/$tdir/$tfile
3519 local fid=$(copy_file /etc/passwd $f)
3522 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3523 wait_request_state $fid ARCHIVE SUCCEED
3528 wait_request_state $fid RESTORE SUCCEED
3530 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3533 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3537 run_test 222b "Changelog for implicit restore"
3540 # test needs a running copytool
3545 local f=$DIR/$tdir/$tfile
3546 make_archive $tdir/$tfile
3550 import_file $tdir/$tfile $f
3551 local fid=$(path2fid $f)
3554 wait_request_state $fid RESTORE STARTED
3556 wait_request_state $fid RESTORE CANCELED
3557 wait_request_state $fid CANCEL SUCCEED
3559 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3562 [[ $flags == $target ]] ||
3563 error "Changelog flag is $flags not $target"
3567 run_test 223a "Changelog for restore canceled (import case)"
3570 # test needs a running copytool
3575 local f=$DIR/$tdir/$tfile
3576 local fid=$(make_large_for_progress $f)
3579 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3580 wait_request_state $fid ARCHIVE SUCCEED
3583 wait_request_state $fid RESTORE STARTED
3585 wait_request_state $fid RESTORE CANCELED
3586 wait_request_state $fid CANCEL SUCCEED
3588 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3591 [[ $flags == $target ]] ||
3592 error "Changelog flag is $flags not $target"
3596 run_test 223b "Changelog for restore canceled (release case)"
3599 # test needs a running copytool
3604 local f=$DIR/$tdir/$tfile
3605 local fid=$(copy_file /etc/passwd $f)
3608 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3609 wait_request_state $fid ARCHIVE SUCCEED
3612 wait_request_state $fid REMOVE SUCCEED
3614 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3617 [[ $flags == $target ]] ||
3618 error "Changelog flag is $flags not $target"
3622 run_test 224 "Changelog for remove"
3625 # test needs a running copytool
3628 # test is not usable because remove request is too fast
3629 # so it is always finished before cancel can be done ...
3630 echo "Test disabled"
3635 local f=$DIR/$tdir/$tfile
3636 local fid=$(make_large_for_progress $f)
3639 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3640 wait_request_state $fid ARCHIVE SUCCEED
3642 # if cdt is on, it can serve too quickly the request
3647 wait_request_state $fid REMOVE CANCELED
3648 wait_request_state $fid CANCEL SUCCEED
3650 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3651 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3652 tail -n 1 | awk '{print $5}')
3655 [[ $flags == $target ]] ||
3656 error "Changelog flag is $flags not $target"
3660 run_test 225 "Changelog for remove canceled"
3663 # test needs a running copytool
3668 local f1=$DIR/$tdir/$tfile-1
3669 local f2=$DIR/$tdir/$tfile-2
3670 local f3=$DIR/$tdir/$tfile-3
3671 local fid1=$(copy_file /etc/passwd $f1)
3672 local fid2=$(copy_file /etc/passwd $f2)
3673 copy_file /etc/passwd $f3
3676 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3677 wait_request_state $fid1 ARCHIVE SUCCEED
3679 $LFS hsm_archive $f2
3680 wait_request_state $fid2 ARCHIVE SUCCEED
3682 rm $f1 || error "rm $f1 failed"
3684 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3687 [[ $flags == $target ]] ||
3688 error "Changelog flag is $flags not $target"
3690 mv $f3 $f2 || error "mv $f3 $f2 failed"
3692 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3695 [[ $flags == $target ]] ||
3696 error "Changelog flag is $flags not $target"
3700 run_test 226 "changelog for last rm/mv with exiting archive"
3702 check_flags_changes() {
3710 $LFS hsm_set --$hsm_flag $f ||
3711 error "Cannot set $hsm_flag on $f"
3712 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3713 local seen=${#flags[*]}
3715 [[ $seen == $cnt ]] ||
3716 error "set $hsm_flag: Changelog events $seen != $cnt"
3717 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3718 error "set $hsm_flag: Changelog flags are "\
3719 "${flags[$((cnt - 1))]} not $target"
3721 $LFS hsm_clear --$hsm_flag $f ||
3722 error "Cannot clear $hsm_flag on $f"
3723 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3726 [[ $cnt == $seen ]] ||
3727 error "clear $hsm_flag: Changelog events $seen != $cnt"
3729 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3730 error "clear $hsm_flag: Changelog flag is "\
3731 "${flags[$((cnt - 1))]} not $target"
3735 # test needs a running copytool
3742 for i in norelease noarchive exists archived
3744 local f=$DIR/$tdir/$tfile-$i
3745 local fid=$(copy_file /etc/passwd $f)
3746 check_flags_changes $f $fid $i 0 1
3749 f=$DIR/$tdir/$tfile---lost
3750 fid=$(copy_file /etc/passwd $f)
3751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3752 wait_request_state $fid ARCHIVE SUCCEED
3753 check_flags_changes $f $fid lost 3 1
3757 run_test 227 "changelog when explicit setting of HSM flags"
3760 # test needs a running copytool
3763 local fid=$(make_small_sync $DIR/$tfile)
3764 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3765 wait_request_state $fid ARCHIVE SUCCEED
3767 $LFS hsm_release $DIR/$tfile
3768 check_hsm_flags $DIR/$tfile "0x0000000d"
3770 filefrag $DIR/$tfile | grep " 1 extent found" ||
3771 error "filefrag on released file must return only one extent"
3773 # only newer versions of cp detect sparse files by stat/FIEMAP
3775 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3776 error "copying $DIR/$tfile"
3777 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3779 $LFS hsm_release $DIR/$tfile
3780 check_hsm_flags $DIR/$tfile "0x0000000d"
3782 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3784 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3786 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3787 error "comparing untarred $DIR/$tfile"
3789 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3790 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3793 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3796 # test needs a running copytool
3800 local maxrequest=$(get_hsm_param max_requests)
3801 local rqcnt=$(($maxrequest * 3))
3805 for i in $(seq -w 1 $rqcnt); do
3807 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3809 # we do it in 2 steps, so all requests arrive at the same time
3810 for i in $(seq -w 1 $rqcnt); do
3811 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3816 while [[ $cnt != 0 || $wt != 0 ]]; do
3818 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3819 $HSM_PARAM.actions |\
3820 grep STARTED | grep -v CANCEL | wc -l")
3821 [[ $cnt -le $maxrequest ]] ||
3822 error "$cnt > $maxrequest too many started requests"
3823 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3824 $HSM_PARAM.actions |\
3825 grep WAITING | wc -l")
3826 echo "max=$maxrequest started=$cnt waiting=$wt"
3831 run_test 250 "Coordinator max request"
3834 # test needs a running copytool
3838 local f=$DIR/$tdir/$tfile
3839 local fid=$(make_large_for_cancel $f)
3842 # to have a short test
3843 local old_to=$(get_hsm_param active_request_timeout)
3844 set_hsm_param active_request_timeout 4
3845 # to be sure the cdt will wake up frequently so
3846 # it will be able to cancel the "old" request
3847 local old_loop=$(get_hsm_param loop_period)
3848 set_hsm_param loop_period 2
3851 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3852 wait_request_state $fid ARCHIVE STARTED
3854 wait_request_state $fid ARCHIVE CANCELED
3856 set_hsm_param active_request_timeout $old_to
3857 set_hsm_param loop_period $old_loop
3861 run_test 251 "Coordinator request timeout"
3864 # the only way to test ondisk conf is to restart MDS ...
3865 echo "Stop coordinator and remove coordinator state at mount"
3868 # clean on disk conf set by default
3869 cdt_clear_mount_state
3870 cdt_check_state stopped
3872 # check cdt still off after umount/remount
3874 cdt_check_state stopped
3876 echo "Set coordinator start at mount, and start coordinator"
3877 cdt_set_mount_state enabled
3880 cdt_check_state enabled
3882 # check cdt still on after umount/remount
3884 cdt_check_state enabled
3886 # we are back to original state (cdt started at mount)
3888 run_test 300 "On disk coordinator state kept between MDT umount/mount"
3891 local ai=$(get_hsm_param default_archive_id)
3892 local new=$((ai + 1))
3894 set_hsm_param default_archive_id $new -P
3896 local res=$(get_hsm_param default_archive_id)
3899 set_hsm_param default_archive_id "" "-P -d"
3901 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3903 run_test 301 "HSM tunnable are persistent"
3906 local ai=$(get_hsm_param default_archive_id)
3907 local new=$((ai + 1))
3912 set_hsm_param default_archive_id $new -P
3915 for mdtno in $(seq 1 $MDSCOUNT); do
3920 cdt_check_state enabled
3922 local res=$(get_hsm_param default_archive_id)
3925 set_hsm_param default_archive_id "" "-P -d"
3927 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
3929 run_test 302 "HSM tunnable are persistent when CDT is off"
3932 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3938 local dir_mdt0=$DIR/$tdir/mdt0
3939 local dir_mdt1=$DIR/$tdir/mdt1
3941 # create 1 dir per MDT
3942 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3943 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3945 # create 1 file in each MDT
3946 local fid1=$(make_small $dir_mdt0/$tfile)
3947 local fid2=$(make_small $dir_mdt1/$tfile)
3949 # check that hsm request on mdt0 is sent to the right MDS
3950 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
3951 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3952 echo "archive successful on mdt0"
3954 # check that hsm request on mdt1 is sent to the right MDS
3955 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
3956 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3957 echo "archive successful on mdt1"
3960 # clean test files and directories
3961 rm -rf $dir_mdt0 $dir_mdt1
3963 run_test 400 "Single request is sent to the right MDT"
3966 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3972 local dir_mdt0=$DIR/$tdir/mdt0
3973 local dir_mdt1=$DIR/$tdir/mdt1
3975 # create 1 dir per MDT
3976 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
3977 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
3979 # create 1 file in each MDT
3980 local fid1=$(make_small $dir_mdt0/$tfile)
3981 local fid2=$(make_small $dir_mdt1/$tfile)
3983 # check that compound requests are shunt to the rights MDTs
3984 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
3985 error "lfs hsm_archive"
3986 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
3987 echo "archive successful on mdt0"
3988 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
3989 echo "archive successful on mdt1"
3992 # clean test files and directories
3993 rm -rf $dir_mdt0 $dir_mdt1
3995 run_test 401 "Compound requests split and sent to their respective MDTs"
3997 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4002 local node=$(facet_active_host $facet)
4004 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4005 awk '{print $4}'); do
4006 echo "$3 $mdc on $node"
4007 do_facet $facet "$LCTL --device $mdc $state" || return 1
4012 # make sure there is no running copytool
4015 # deactivate all mdc on agent1
4016 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4018 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4020 check_agent_unregistered "uuid" # match any agent
4022 # no expected running copytool
4023 search_copytools $agent && error "Copytool start should have failed"
4026 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4028 run_test 402 "Copytool start fails if all MDTs are inactive"
4031 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4033 # make sure there is no running copytool
4036 local agent=$(facet_active_host $SINGLEAGT)
4037 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4039 # deactivate all mdc for MDT0001
4040 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4043 # check the agent is registered on MDT0000, and not on MDT0001
4044 check_agent_registered_by_mdt $uuid 0
4045 check_agent_unregistered_by_mdt $uuid 1
4047 # check running copytool process
4048 search_copytools $agent || error "No running copytools on $agent"
4050 # reactivate all mdc for MDT0001
4051 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4053 # make sure the copytool is now registered to all MDTs
4054 check_agent_registered $uuid
4058 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4061 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4065 # create files on both MDT0000 and MDT0001
4068 local dir_mdt0=$DIR/$tdir/mdt0
4069 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4071 # create 1 file on mdt0
4072 local fid1=$(make_small $dir_mdt0/$tfile)
4074 # deactivate all mdc for MDT0001
4075 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4077 # send an HSM request for files in MDT0000
4078 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4080 # check for completion of files in MDT0000
4081 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4082 echo "archive successful on mdt0"
4084 # reactivate all mdc for MDT0001
4085 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4088 # clean test files and directories
4091 run_test 404 "Inactive MDT does not block requests for active MDTs"
4094 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4100 local striped_dir=$DIR/$tdir/striped_dir
4102 # create striped dir on all of MDTs
4103 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4105 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4106 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4107 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4108 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4110 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4111 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4112 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4113 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4115 # check that compound requests are shunt to the rights MDTs
4116 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4117 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4118 error "lfs hsm_archive"
4120 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4121 echo "archive successful on $fid1"
4122 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4123 echo "archive successful on $fid2"
4124 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4125 echo "archive successful on $fid3"
4126 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4127 echo "archive successful on $fid4"
4129 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4130 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4131 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4132 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4134 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4135 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4136 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4137 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4141 run_test 405 "archive and release under striped directory"
4146 check_and_cleanup_lustre