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: LU-3815
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT 34 35 36"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MOUNT_2=${MOUNT_2:-"yes"}
30 # script only handles up to 10 MDTs (because of MDT_PREFIX)
31 [ $MDSCOUNT -gt 9 ] &&
32 error "script cannot handle more than 9 MDTs, please fix" && exit
34 check_and_setup_lustre
36 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
37 skip_env "Need MDS version at least 2.4.53" && exit
40 # $RUNAS_ID may get set incorrectly somewhere else
41 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
42 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
44 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
50 # the following associated variables are added:
52 # AGTCOUNT: number of agents
53 # AGTDEV{N}: target HSM mount point (root path of the backend)
54 # agt{N}_HOST: hostname of the agent agt{N}
55 # SINGLEAGT: facet of the single agent
57 # The number of agents is initialized as the number of remote client nodes.
58 # By default, only single copytool is started on a remote client/agent. If there
59 # was no remote client, then the copytool will be started on the local client.
65 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
66 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
68 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
69 if [[ $CLIENTCOUNT -gt 1 ]] &&
70 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
71 skip_env "SHARED_DIRECTORY should be accessible"\
76 for n in $(seq $AGTCOUNT); do
77 eval export AGTDEV$n=\$\{AGTDEV$n:-"$SHARED_DIRECTORY/arc$n"\}
78 agent=CLIENT$((n + 1))
79 if [[ -z "${!agent}" ]]; then
80 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
83 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
86 export SINGLEAGT=${SINGLEAGT:-agt1}
88 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
89 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
90 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
91 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
92 export HSMTOOL_TESTDIR
93 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
94 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
97 # The test only support up to 10 MDTs
98 MDT_PREFIX="mdt.$FSNAME-MDT000"
99 HSM_PARAM="${MDT_PREFIX}0.hsm"
101 # archive is purged at copytool setup
102 HSM_ARCHIVE_PURGE=true
104 # Don't allow copytool error upon start/setup
105 HSMTOOL_NOERROR=false
108 # Get the backend root path for the given agent facet.
111 local dev=AGTDEV$(facet_number $facet)
116 # Stop copytool and unregister an existing changelog user.
118 copytool_monitor_cleanup
121 cdt_set_sanity_policy
126 # get MDT device for each mdc
127 for mdtno in $(seq 1 $MDSCOUNT); do
128 local idx=$(($mdtno - 1))
129 MDT[$idx]=$($LCTL get_param -n \
130 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
131 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
136 local agents=${1:-$(facet_active_host $SINGLEAGT)}
137 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
140 search_and_kill_copytool() {
141 local agents=${1:-$(facet_active_host $SINGLEAGT)}
143 echo "Killing existing copytools on $agents"
144 do_nodesv $agents "killall -q $HSMTOOL_BASE" || true
147 copytool_monitor_setup() {
148 local facet=${1:-$SINGLEAGT}
149 local agent=$(facet_active_host $facet)
151 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
152 local test_dir=$(do_node $agent "$cmd") ||
153 error "Failed to create tempdir on $agent"
154 export HSMTOOL_MONITOR_DIR=$test_dir
156 # Create the fifo and a monitor (cat dies when copytool dies)
157 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
158 error "failed to create copytool fifo on $agent"
159 cmd="cat $test_dir/fifo > $test_dir/events &"
160 cmd+=" echo \\\$! > $test_dir/monitor_pid"
162 if [[ $PDSH == *Rmrsh* ]]; then
163 # This is required for pdsh -Rmrsh and its handling of remote
165 # Regular ssh and pdsh -Rssh work fine without this
166 # backgrounded subshell nonsense.
167 (do_node $agent "$cmd") &
168 export HSMTOOL_MONITOR_PDSH=$!
170 # Slightly racy, but just making a best-effort to catch obvious
173 ps -p $HSMTOOL_MONITOR_PDSH >&- ||
174 error "Failed to start copytool monitor on $agent"
176 do_node $agent "$cmd"
178 error "Failed to start copytool monitor on $agent"
183 copytool_monitor_cleanup() {
184 local facet=${1:-$SINGLEAGT}
185 local agent=$(facet_active_host $facet)
187 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
188 # Should die when the copytool dies, but just in case.
189 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
190 cmd+=" 2>/dev/null || true"
191 do_node $agent "$cmd"
192 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
193 export HSMTOOL_MONITOR_DIR=
196 # The pdsh should die on its own when the monitor dies. Just
197 # in case, though, try to clean up to avoid any cruft.
198 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
199 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
200 export HSMTOOL_MONITOR_PDSH=
205 local facet=${1:-$SINGLEAGT}
206 local lustre_mntpnt=${2:-$MOUNT}
208 local hsm_root=${4:-$(copytool_device $facet)}
209 local agent=$(facet_active_host $facet)
211 if [[ -z "$arc_id" ]] &&
212 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
213 echo "Only wakeup running copytool $facet on $agent"
217 if $HSM_ARCHIVE_PURGE; then
218 echo "Purging archive on $agent"
219 do_facet $facet "rm -rf $hsm_root/*"
222 echo "Starting copytool $facet on $agent"
223 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
224 # bandwidth is limited to 1MB/s so the copy time is known and
225 # independent of hardware
226 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
227 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
228 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
229 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
230 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
231 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
232 cmd+=" --bandwidth 1 $lustre_mntpnt"
234 # Redirect the standard output and error to a log file which
235 # can be uploaded to Maloo.
236 local prefix=$TESTLOG_PREFIX
237 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
238 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
240 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
241 if [[ $? != 0 ]]; then
242 [[ $HSMTOOL_NOERROR == true ]] ||
243 error "start copytool $facet on $agent failed"
244 echo "start copytool $facet on $agent failed"
250 get_copytool_event_log() {
251 local facet=${1:-$SINGLEAGT}
252 local agent=$(facet_active_host $facet)
254 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
255 error "Can't get event log: No monitor directory!"
257 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
258 error "Could not collect event log from $agent"
263 local facet=$SINGLEAGT
264 local agents=${1:-$(facet_active_host $facet)}
269 local hsm_root=$(copytool_device $facet)
270 local end_wait=$(( SECONDS + TIMEOUT ))
272 do_nodesv $agents "pkill -INT -x $HSMTOOL_BASE" || return 0
274 while (( SECONDS < end_wait )); do
276 do_nodesv $agents "pgrep -x $HSMTOOL_BASE"
277 if [ $? -ne 0 ]; then
278 echo "Copytool is stopped on $agents"
281 echo "Copytool still running on $agents"
283 if do_nodesv $agents "pgrep -x $HSMTOOL_BASE"; then
284 error "Copytool failed to stop in ${TIMEOUT}s ..."
286 echo "Copytool has stopped in " \
287 "$((TIMEOUT - (end_wait - SECONDS)))s."
290 # clean all CDTs orphans requests from previous tests
291 # that would otherwise need to timeout to clear.
292 for mdtno in $(seq 1 $MDSCOUNT); do
294 mdt_hsmctrl="mdt.$FSNAME-MDT000${idx}.hsm_control"
295 oldstate=$(do_facet mds${mdtno} "$LCTL get_param -n " \
297 # skip already stop[ed,ing] CDTs
298 echo $oldstate | grep stop && continue
300 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=shutdown"
301 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
303 error "mds${mdtno} cdt state is not stopped"
304 do_facet mds${mdtno} "$LCTL set_param $mdt_hsmctrl=$oldstate"
305 wait_result mds${mdtno} "$LCTL get_param -n $mdt_hsmctrl" \
307 error "mds${mdtno} cdt state is not $oldstate"
309 if do_facet $facet "df $hsm_root" >/dev/null 2>&1 ; then
310 do_facet $facet "rm -rf $hsm_root/*"
315 local agents=${1:-$(facet_active_host $SINGLEAGT)}
317 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
318 echo "Copytool is suspended on $agents"
321 copytool_remove_backend() {
323 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
324 echo "Remove from backend: $fid = $be"
325 do_facet $SINGLEAGT rm -f $be
329 do_facet $SINGLEAGT \
330 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
331 --import $1 $2 $MOUNT" ||
332 error "import of $1 to $2 failed"
336 local file=$HSM_ARCHIVE/$1
337 do_facet $SINGLEAGT mkdir -p $(dirname $file)
338 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
339 file_creation_failure dd $file $?
343 local file=$HSM_ARCHIVE/$2
344 do_facet $SINGLEAGT mkdir -p $(dirname $file)
345 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
354 if [[ "$value" != "" ]]; then
357 for mdtno in $(seq 1 $MDSCOUNT); do
358 local idx=$(($mdtno - 1))
359 local facet=mds${mdtno}
360 # if $arg include -P option, run 1 set_param per MDT on the MGS
361 # else, run set_param on each MDT
362 [[ $arg = *"-P"* ]] && facet=mgs
363 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
364 [[ $? != 0 ]] && rc=1
374 for mdtno in $(seq 1 $MDSCOUNT); do
375 local idx=$(($mdtno - 1))
376 wait_result mds${mdtno} \
377 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
379 error "$key state is not '$target' on mds${mdtno}"
386 for mdtno in $(seq 1 $MDSCOUNT); do
387 local idx=$(($mdtno - 1))
388 local cl_user=$(do_facet mds${mdtno} $LCTL \
389 --device ${MDT[$idx]} \
390 changelog_register -n)
392 do_facet mds${mdtno} lctl set_param \
393 mdd.${MDT[$idx]}.changelog_mask="+hsm"
394 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
398 changelog_cleanup() {
400 for mdtno in $(seq 1 $MDSCOUNT); do
401 local idx=$(($mdtno - 1))
402 [[ -z ${CL_USERS[$idx]} ]] && continue
403 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
404 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
405 changelog_deregister ${CL_USERS[$idx]}
410 changelog_get_flags() {
415 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
420 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
428 mdts_set_param "$opt -n" "hsm.$param" "$value"
435 mdts_set_param "" hsm_control "$cmd"
436 mdts_check_param hsm_control "$target" 10
439 cdt_set_sanity_policy() {
440 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
443 mdts_set_param "" hsm.policy "+NRA"
444 mdts_set_param "" hsm.policy "-NBR"
445 CDT_POLICY_HAD_CHANGED=
450 mdts_set_param "" hsm.policy "+NRA"
451 CDT_POLICY_HAD_CHANGED=true
454 cdt_clear_no_retry() {
455 mdts_set_param "" hsm.policy "-NRA"
456 CDT_POLICY_HAD_CHANGED=true
459 cdt_set_non_blocking_restore() {
460 mdts_set_param "" hsm.policy "+NBR"
461 CDT_POLICY_HAD_CHANGED=true
464 cdt_clear_non_blocking_restore() {
465 mdts_set_param "" hsm.policy "-NBR"
466 CDT_POLICY_HAD_CHANGED=true
469 cdt_clear_mount_state() {
470 mdts_set_param "-P -d" hsm_control ""
473 cdt_set_mount_state() {
474 mdts_set_param "-P" hsm_control "$1"
478 mdts_check_param hsm_control "$1" 20
482 set_test_state disabled disabled
486 set_test_state enabled enabled
490 set_test_state shutdown stopped
494 set_test_state purge enabled
500 cdt_set_sanity_policy
504 local client_count=$1
505 if [[ $CLIENTCOUNT -lt $client_count ]]; then
506 skip "Need $client_count or more clients, have $CLIENTCOUNT"
513 $LFS path2fid $1 | tr -d '[]'
514 return ${PIPESTATUS[0]}
522 if [[ $u == "user" ]]; then
523 st=$($RUNAS $LFS hsm_state $f)
526 st=$($LFS hsm_state $f)
529 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
531 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
535 get_hsm_archive_id() {
538 st=$($LFS hsm_state $f)
539 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
541 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
550 local st=$(get_hsm_flags $f)
551 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
554 check_hsm_flags_user() {
558 local st=$(get_hsm_flags $f user)
559 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
562 file_creation_failure() {
567 df $MOUNT $MOUNT2 >&2
568 error "cannot create $f with $cmd, status=$err"
580 if [[ "$3" != 1 ]]; then
584 cp $1 $f || file_creation_failure cp $f $?
586 path2fid $f || error "cannot get fid on $f"
590 local file2=${1/$DIR/$DIR2}
591 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
592 file_creation_failure dd $file2 $?
594 path2fid $1 || error "cannot get fid on $1"
598 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
599 file_creation_failure dd $1 $?
600 path2fid $1 || error "cannot get fid on $1"
603 cleanup_large_files() {
604 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
606 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
609 check_enough_free_space() {
612 local need=$((nb * unit /1024))
613 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
614 (( $need >= $free )) && return 1
618 make_large_for_striping() {
619 local file2=${1/$DIR/$DIR2}
620 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
624 check_enough_free_space 5 $sz
625 [ $? != 0 ] && return $?
627 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
628 file_creation_failure dd $file2 $?
630 path2fid $1 || error "cannot get fid on $1"
633 make_large_for_progress() {
634 local file2=${1/$DIR/$DIR2}
638 check_enough_free_space 39 1000000
639 [ $? != 0 ] && return $?
641 # big file is large enough, so copy time is > 30s
642 # so copytool make 1 progress
643 # size is not a multiple of 1M to avoid stripe
645 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
646 file_creation_failure dd $file2 $?
648 path2fid $1 || error "cannot get fid on $1"
651 make_large_for_progress_aligned() {
652 local file2=${1/$DIR/$DIR2}
656 check_enough_free_space 33 1048576
657 [ $? != 0 ] && return $?
659 # big file is large enough, so copy time is > 30s
660 # so copytool make 1 progress
661 # size is a multiple of 1M to have stripe
663 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
664 file_creation_failure dd $file2 $?
665 path2fid $1 || error "cannot get fid on $1"
668 make_large_for_cancel() {
669 local file2=${1/$DIR/$DIR2}
673 check_enough_free_space 103 1048576
674 [ $? != 0 ] && return $?
676 # Copy timeout is 100s. 105MB => 105s
677 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
678 file_creation_failure dd $file2 $?
679 path2fid $1 || error "cannot get fid on $1"
685 wait_update --verbose $(facet_active_host $facet) "$@"
688 wait_request_state() {
692 # 4th arg (mdt index) is optional
694 local mds=mds$(($mdtidx + 1))
696 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
697 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
699 wait_result $mds "$cmd" $state 200 ||
700 error "request on $fid is not $state on $mds"
703 get_request_state() {
707 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
708 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
711 get_request_count() {
715 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
716 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
723 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
724 [[ -n $fid ]] && cmd+=" | grep '$fid'"
725 cmd+=" | egrep 'WAITING|STARTED'"
727 wait_result $SINGLEMDS "$cmd" "" $timeout ||
728 error "requests did not complete"
731 wait_for_grace_delay() {
732 local val=$(get_hsm_param grace_delay)
739 # python2.6 in EL6 includes an internal json module
740 local json_parser='import json; import fileinput;'
741 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
742 json_parser+='json.loads([line for line in '
743 json_parser+='fileinput.input()][0]).items()])'
745 echo $raw_event | python -c "$json_parser"
748 # populate MDT device array
754 # cleanup from previous bad setup
755 search_and_kill_copytool
757 # for recovery tests, coordinator needs to be started at mount
759 # the lustre conf must be without hsm on (like for sanity.sh)
760 echo "Set HSM on and start"
761 cdt_set_mount_state enabled
762 cdt_check_state enabled
764 echo "Start copytool"
767 echo "Set sanity-hsm HSM policy"
768 cdt_set_sanity_policy
770 # finished requests are quickly removed from list
771 set_hsm_param grace_delay 10
777 local f=$DIR/$tdir/$tfile
781 check_hsm_flags_user $f "0x00000000"
783 $RUNAS $LFS hsm_set --norelease $f ||
784 error "user could not change hsm flags"
785 check_hsm_flags_user $f "0x00000010"
787 $RUNAS $LFS hsm_clear --norelease $f ||
788 error "user could not clear hsm flags"
789 check_hsm_flags_user $f "0x00000000"
791 # User could not change those flags...
792 $RUNAS $LFS hsm_set --exists $f &&
793 error "user should not set this flag"
794 check_hsm_flags_user $f "0x00000000"
797 $LFS hsm_set --exists $f ||
798 error "root could not change hsm flags"
799 check_hsm_flags_user $f "0x00000001"
801 $LFS hsm_clear --exists $f ||
802 error "root could not clear hsm state"
803 check_hsm_flags_user $f "0x00000000"
806 run_test 1 "lfs hsm flags root/non-root access"
810 local f=$DIR/$tdir/$tfile
812 # New files are not dirty
813 check_hsm_flags $f "0x00000000"
815 # For test, we simulate an archived file.
816 $LFS hsm_set --exists $f || error "user could not change hsm flags"
817 check_hsm_flags $f "0x00000001"
819 # chmod do not put the file dirty
820 chmod 600 $f || error "could not chmod test file"
821 check_hsm_flags $f "0x00000001"
823 # chown do not put the file dirty
824 chown $RUNAS_ID $f || error "could not chown test file"
825 check_hsm_flags $f "0x00000001"
827 # truncate put the file dirty
828 $TRUNCATE $f 1 || error "could not truncate test file"
829 check_hsm_flags $f "0x00000003"
831 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
832 check_hsm_flags $f "0x00000001"
834 run_test 2 "Check file dirtyness when doing setattr"
840 # New files are not dirty
842 check_hsm_flags $f "0x00000000"
844 # For test, we simulate an archived file.
845 $LFS hsm_set --exists $f ||
846 error "user could not change hsm flags"
847 check_hsm_flags $f "0x00000001"
849 # Reading a file, does not set dirty
850 cat $f > /dev/null || error "could not read file"
851 check_hsm_flags $f "0x00000001"
853 # Open for write without modifying data, does not set dirty
854 openfile -f O_WRONLY $f || error "could not open test file"
855 check_hsm_flags $f "0x00000001"
857 # Append to a file sets it dirty
858 cp -p /etc/passwd $f.append || error "could not create file"
859 $LFS hsm_set --exists $f.append ||
860 error "user could not change hsm flags"
861 dd if=/etc/passwd of=$f.append bs=1 count=3\
862 conv=notrunc oflag=append status=noxfer ||
863 file_creation_failure dd $f.append $?
864 check_hsm_flags $f.append "0x00000003"
866 # Modify a file sets it dirty
867 cp -p /etc/passwd $f.modify || error "could not create file"
868 $LFS hsm_set --exists $f.modify ||
869 error "user could not change hsm flags"
870 dd if=/dev/zero of=$f.modify bs=1 count=3\
871 conv=notrunc status=noxfer ||
872 file_creation_failure dd $f.modify $?
873 check_hsm_flags $f.modify "0x00000003"
875 # Open O_TRUNC sets dirty
876 cp -p /etc/passwd $f.trunc || error "could not create file"
877 $LFS hsm_set --exists $f.trunc ||
878 error "user could not change hsm flags"
879 cp /etc/group $f.trunc || error "could not override a file"
880 check_hsm_flags $f.trunc "0x00000003"
882 # Mmapped a file sets dirty
883 cp -p /etc/passwd $f.mmap || error "could not create file"
884 $LFS hsm_set --exists $f.mmap ||
885 error "user could not change hsm flags"
886 multiop $f.mmap OSMWUc || error "could not mmap a file"
887 check_hsm_flags $f.mmap "0x00000003"
889 run_test 3 "Check file dirtyness when opening for write"
893 local f=$DIR/$tdir/$tfile
894 local fid=$(make_small $f)
897 local st=$(get_request_state $fid CANCEL)
898 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
900 run_test 4 "Useless cancel must not be registered"
903 # test needs a running copytool
907 local f=$DIR/$tdir/$tfile
908 local fid=$(copy_file /etc/passwd $f)
910 wait_request_state $fid ARCHIVE SUCCEED
912 check_hsm_flags $f "0x00000009"
916 run_test 8 "Test default archive number"
920 local f=$DIR/$tdir/$tfile
921 local fid=$(copy_file /etc/passwd $f)
922 # we do not use the default one to be sure
923 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
925 copytool_setup $SINGLEAGT $MOUNT $new_an
926 $LFS hsm_archive --archive $new_an $f
927 wait_request_state $fid ARCHIVE SUCCEED
929 check_hsm_flags $f "0x00000009"
933 run_test 9 "Use of explict archive number, with dedicated copytool"
936 needclients 3 || return 0
942 copytool_cleanup $(comma_list $(agts_nodes))
944 # start all of the copytools
945 for n in $(seq $AGTCOUNT); do
949 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
952 for n in $(seq $AGTCOUNT); do
953 file=$DIR/$tdir/$tfile.$n
954 fid=$(make_small $file)
956 $LFS hsm_archive $file || error "could not archive file $file"
957 wait_request_state $fid ARCHIVE SUCCEED
958 check_hsm_flags $file "0x00000009"
962 copytool_cleanup $(comma_list $(agts_nodes))
964 run_test 9a "Multiple remote agents"
967 # test needs a running copytool
970 mkdir -p $DIR/$tdir/d1
971 local f=$DIR/$tdir/$tfile
972 local fid=$(copy_file /etc/hosts $f)
973 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
974 error "hsm_archive failed"
975 wait_request_state $fid ARCHIVE SUCCEED
977 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
978 error "fid $fid not in archive $HSM_ARCHIVE"
979 echo "Verifying content"
980 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
981 echo "Verifying hsm state "
982 check_hsm_flags $f "0x00000009"
984 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
985 local st=$(get_hsm_archive_id $f)
986 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
987 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
992 run_test 10a "Archive a file"
995 # test needs a running copytool
999 local f=$DIR/$tdir/$tfile
1000 local fid=$(copy_file /etc/hosts $f)
1001 $LFS hsm_archive $f || error "archive request failed"
1002 wait_request_state $fid ARCHIVE SUCCEED
1004 $LFS hsm_archive $f || error "archive of non dirty file failed"
1005 local cnt=$(get_request_count $fid ARCHIVE)
1006 [[ "$cnt" == "1" ]] ||
1007 error "archive of non dirty file must not make a request"
1011 run_test 10b "Archive of non dirty file must work without doing request"
1014 # test needs a running copytool
1018 local f=$DIR/$tdir/$tfile
1019 local fid=$(copy_file /etc/hosts $f)
1020 $LFS hsm_set --noarchive $f
1021 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1025 run_test 10c "Check forbidden archive"
1028 # test needs a running copytool
1032 local f=$DIR/$tdir/$tfile
1033 local fid=$(copy_file /etc/hosts $f)
1034 $LFS hsm_archive $f || error "cannot archive $f"
1035 wait_request_state $fid ARCHIVE SUCCEED
1037 local ar=$(get_hsm_archive_id $f)
1038 local dflt=$(get_hsm_param default_archive_id)
1039 [[ $ar == $dflt ]] ||
1040 error "archived file is not on default archive: $ar != $dflt"
1044 run_test 10d "Archive a file on the default archive id"
1048 copy2archive /etc/hosts $tdir/$tfile
1049 local f=$DIR/$tdir/$tfile
1051 import_file $tdir/$tfile $f
1052 echo -n "Verifying released state: "
1053 check_hsm_flags $f "0x0000000d"
1055 local LSZ=$(stat -c "%s" $f)
1056 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1058 echo "Verifying imported size $LSZ=$ASZ"
1059 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1060 echo -n "Verifying released pattern: "
1061 local PTRN=$($GETSTRIPE -L $f)
1063 [[ $PTRN == 80000001 ]] || error "Is not released"
1064 local fid=$(path2fid $f)
1065 echo "Verifying new fid $fid in archive"
1067 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1068 error "fid $fid not in archive $HSM_ARCHIVE"
1070 run_test 11a "Import a file"
1073 # test needs a running copytool
1077 local f=$DIR/$tdir/$tfile
1078 local fid=$(copy_file /etc/hosts $f)
1079 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1080 error "hsm_archive failed"
1081 wait_request_state $fid ARCHIVE SUCCEED
1083 local FILE_HASH=$(md5sum $f)
1088 echo "$FILE_HASH" | md5sum -c
1090 [[ $? -eq 0 ]] || error "Restored file differs"
1094 run_test 11b "Import a deleted file using its FID"
1097 # test needs a running copytool
1101 copy2archive /etc/hosts $tdir/$tfile
1103 local f=$DIR/$tdir/$tfile
1104 import_file $tdir/$tfile $f
1105 local f2=$DIR2/$tdir/$tfile
1106 echo "Verifying released state: "
1107 check_hsm_flags $f2 "0x0000000d"
1109 local fid=$(path2fid $f2)
1110 $LFS hsm_restore $f2
1111 wait_request_state $fid RESTORE SUCCEED
1113 echo "Verifying file state: "
1114 check_hsm_flags $f2 "0x00000009"
1116 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1118 [[ $? -eq 0 ]] || error "Restored file differs"
1122 run_test 12a "Restore an imported file explicitly"
1125 # test needs a running copytool
1129 copy2archive /etc/hosts $tdir/$tfile
1131 local f=$DIR/$tdir/$tfile
1132 import_file $tdir/$tfile $f
1133 echo "Verifying released state: "
1134 check_hsm_flags $f "0x0000000d"
1136 cat $f > /dev/null || error "File read failed"
1138 echo "Verifying file state after restore: "
1139 check_hsm_flags $f "0x00000009"
1141 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1143 [[ $? -eq 0 ]] || error "Restored file differs"
1147 run_test 12b "Restore an imported file implicitly"
1150 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1152 # test needs a running copytool
1156 local f=$DIR/$tdir/$tfile
1157 $LFS setstripe -c 2 $f
1159 fid=$(make_large_for_striping $f)
1160 [ $? != 0 ] && skip "not enough free space" && return
1162 local FILE_CRC=$(md5sum $f)
1164 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1165 wait_request_state $fid ARCHIVE SUCCEED
1166 $LFS hsm_release $f || error "release $f failed"
1168 echo "$FILE_CRC" | md5sum -c
1170 [[ $? -eq 0 ]] || error "Restored file differs"
1174 run_test 12c "Restore a file with stripe of 2"
1177 # test needs a running copytool
1182 local f=$DIR/$tdir/$tfile
1183 local fid=$(copy_file /etc/hosts $f)
1184 $LFS hsm_restore $f || error "restore of non archived file failed"
1185 local cnt=$(get_request_count $fid RESTORE)
1186 [[ "$cnt" == "0" ]] ||
1187 error "restore non archived must not make a request"
1188 $LFS hsm_archive $f ||
1189 error "archive request failed"
1190 wait_request_state $fid ARCHIVE SUCCEED
1191 $LFS hsm_restore $f ||
1192 error "restore of non released file failed"
1193 local cnt=$(get_request_count $fid RESTORE)
1194 [[ "$cnt" == "0" ]] ||
1195 error "restore a non dirty file must not make a request"
1199 run_test 12d "Restore of a non archived, non released file must work"\
1200 " without doing request"
1203 # test needs a running copytool
1206 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1207 local f=$DIR/$tdir/$tfile
1208 local fid=$(copy_file /etc/hosts $f)
1209 $LFS hsm_archive $f || error "archive request failed"
1210 wait_request_state $fid ARCHIVE SUCCEED
1213 cat /etc/hosts >> $f
1217 $LFS hsm_restore $f && error "restore a dirty file must fail"
1221 run_test 12e "Check forbidden restore"
1224 # test needs a running copytool
1228 local f=$DIR/$tdir/$tfile
1229 local fid=$(copy_file /etc/hosts $f)
1231 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1232 wait_request_state $fid ARCHIVE SUCCEED
1233 $LFS hsm_release $f || error "release of $f failed"
1235 wait_request_state $fid RESTORE SUCCEED
1237 echo -n "Verifying file state: "
1238 check_hsm_flags $f "0x00000009"
1240 diff -q /etc/hosts $f
1242 [[ $? -eq 0 ]] || error "Restored file differs"
1246 run_test 12f "Restore a released file explicitly"
1249 # test needs a running copytool
1253 local f=$DIR/$tdir/$tfile
1254 local fid=$(copy_file /etc/hosts $f)
1256 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1257 wait_request_state $fid ARCHIVE SUCCEED
1258 $LFS hsm_release $f || error "release of $f failed"
1260 diff -q /etc/hosts $f
1263 # we check we had a restore done
1264 wait_request_state $fid RESTORE SUCCEED
1266 [[ $st -eq 0 ]] || error "Restored file differs"
1270 run_test 12g "Restore a released file implicitly"
1273 needclients 2 || return 0
1275 # test needs a running copytool
1279 local f=$DIR/$tdir/$tfile
1280 local fid=$(copy_file /etc/hosts $f)
1282 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1283 wait_request_state $fid ARCHIVE SUCCEED
1284 $LFS hsm_release $f || error "release of $f failed"
1286 do_node $CLIENT2 diff -q /etc/hosts $f
1289 # we check we had a restore done
1290 wait_request_state $fid RESTORE SUCCEED
1292 [[ $st -eq 0 ]] || error "Restored file differs"
1296 run_test 12h "Restore a released file implicitly from a second node"
1299 # test needs a running copytool
1303 local f=$DIR/$tdir/$tfile
1304 local fid=$(copy_file /etc/passwd $f)
1305 $LFS hsm_archive $f || error "archive of $f failed"
1306 wait_request_state $fid ARCHIVE SUCCEED
1308 $LFS hsm_release $f || error "release of $f failed"
1312 [[ $? -eq 0 ]] || error "Restored file differs"
1316 run_test 12m "Archive/release/implicit restore"
1319 # test needs a running copytool
1323 copy2archive /etc/hosts $tdir/$tfile
1325 local f=$DIR/$tdir/$tfile
1326 import_file $tdir/$tfile $f
1328 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1329 error "Restored file differs"
1331 $LFS hsm_release $f || error "release of $f failed"
1335 run_test 12n "Import/implicit restore/release"
1338 # test needs a running copytool
1342 local f=$DIR/$tdir/$tfile
1343 local fid=$(copy_file /etc/hosts $f)
1345 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1346 wait_request_state $fid ARCHIVE SUCCEED
1347 $LFS hsm_release $f || error "release of $f failed"
1349 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1350 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1352 # set no retry action mode
1355 diff -q /etc/hosts $f
1358 # we check we had a restore failure
1359 wait_request_state $fid RESTORE FAILED
1361 [[ $st -eq 0 ]] && error "Restore must fail"
1363 # remove no retry action mode
1366 # check file is still released
1367 check_hsm_flags $f "0x0000000d"
1369 # retry w/o failure injection
1370 do_facet $SINGLEMDS lctl set_param fail_loc=0
1372 # to be sure previous RESTORE result is gone
1374 wait_for_grace_delay
1376 diff -q /etc/hosts $f
1379 # we check we had a restore done
1380 wait_request_state $fid RESTORE SUCCEED
1382 [[ $st -eq 0 ]] || error "Restored file differs"
1386 run_test 12o "Layout-swap failure during Restore leaves file released"
1389 # test needs a running copytool
1393 local f=$DIR/$tdir/$tfile
1394 local fid=$(copy_file /etc/hosts $f)
1396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1397 wait_request_state $fid ARCHIVE SUCCEED
1398 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1399 $LFS hsm_release $f || error "cannot release $f"
1400 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1401 $LFS hsm_release $f || error "cannot release $f"
1402 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1406 run_test 12p "implicit restore of a file on copytool mount point"
1409 # test needs a running copytool
1412 local ARC_SUBDIR="import.orig"
1416 # populate directory to be imported
1417 for d in $(seq 1 10); do
1418 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1419 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1420 for f in $(seq 1 10); do
1421 CURR_FILE="$CURR_DIR/$tfile.$f"
1422 # write file-specific data
1423 do_facet $SINGLEAGT \
1424 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1425 "file=$CURR_FILE > $CURR_FILE"
1429 import_file "$ARC_SUBDIR" $DIR/$tdir
1430 # diff lustre content and origin (triggers file restoration)
1431 # there must be 10x10 identical files, and no difference
1432 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1433 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1434 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1435 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1437 [ $cnt_diff -eq 0 ] ||
1438 error "$cnt_diff imported files differ from read data"
1439 [ $cnt_ok -eq 100 ] ||
1440 error "not enough identical files ($cnt_ok != 100)"
1444 run_test 13 "Recursively import and restore a directory"
1447 # test needs a running copytool
1452 local f=$DIR/$tdir/$tfile
1453 local fid=$(make_small $f)
1454 local sum=$(md5sum $f | awk '{print $1}')
1455 $LFS hsm_archive $f || error "could not archive file"
1456 wait_request_state $fid ARCHIVE SUCCEED
1460 # create released file (simulate llapi_hsm_import call)
1462 local fid2=$(path2fid $f)
1463 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1464 $LFS hsm_release $f || error "could not release file"
1466 # rebind the archive to the newly created file
1467 echo "rebind $fid to $fid2"
1469 do_facet $SINGLEAGT \
1470 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1471 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1473 # restore file and compare md5sum
1474 local sum2=$(md5sum $f | awk '{print $1}')
1476 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1480 run_test 14 "Rebind archived file to a new fid"
1483 # test needs a running copytool
1488 local f=$DIR/$tdir/$tfile
1490 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1494 for i in $(seq 1 $count); do
1495 fids[$i]=$(make_small $f.$i)
1496 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1497 $LFS hsm_archive $f.$i || error "could not archive file"
1499 wait_all_done $(($count*60))
1503 for i in $(seq 1 $count); do
1506 local fid2=$(path2fid $f.$i)
1507 # add the rebind operation to the list
1508 echo ${fids[$i]} $fid2 >> $tmpfile
1510 # set it released (simulate llapi_hsm_import call)
1511 $LFS hsm_set --archived --exists $f.$i ||
1512 error "could not force hsm flags"
1513 $LFS hsm_release $f.$i || error "could not release file"
1515 nl=$(wc -l < $tmpfile)
1516 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1518 echo "rebind list of files"
1519 do_facet $SINGLEAGT \
1520 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1521 --rebind $tmpfile $DIR" || error "could not rebind file list"
1523 # restore files and compare md5sum
1524 for i in $(seq 1 $count); do
1525 local sum2=$(md5sum $f.$i | awk '{print $1}')
1526 [[ $sum2 == ${sums[$i]} ]] ||
1527 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1533 run_test 15 "Rebind a list of files"
1536 # test needs a running copytool
1540 # create a known size file so we can verify transfer speed
1543 dd if=/dev/zero of=$ref bs=1M count=20
1546 local f=$DIR/$tdir/$tfile
1547 local fid=$(copy_file $ref $f)
1549 local start=$(date +%s)
1551 wait_request_state $fid ARCHIVE SUCCEED
1552 local end=$(date +%s)
1553 local duration=$((end - start))
1555 [[ $duration -ge $goal ]] ||
1556 error "Transfer is too fast $duration < $goal"
1560 run_test 16 "Test CT bandwith control option"
1565 local f=$DIR/$tdir/$tfile
1566 touch $f || error "touch $f failed"
1568 # Could not release a non-archived file
1569 $LFS hsm_release $f && error "release should not succeed"
1571 # For following tests, we must test them with HS_ARCHIVED set
1572 $LFS hsm_set --exists --archived $f || error "could not add flag"
1574 # Could not release a file if no-release is set
1575 $LFS hsm_set --norelease $f || error "could not add flag"
1576 $LFS hsm_release $f && error "release should not succeed"
1577 $LFS hsm_clear --norelease $f || error "could not remove flag"
1579 # Could not release a file if lost
1580 $LFS hsm_set --lost $f || error "could not add flag"
1581 $LFS hsm_release $f && error "release should not succeed"
1582 $LFS hsm_clear --lost $f || error "could not remove flag"
1584 # Could not release a file if dirty
1585 $LFS hsm_set --dirty $f || error "could not add flag"
1586 $LFS hsm_release $f && error "release should not succeed"
1587 $LFS hsm_clear --dirty $f || error "could not remove flag"
1589 run_test 20 "Release is not permitted"
1592 # test needs a running copytool
1596 local f=$DIR/$tdir/test_release
1598 # Create a file and check its states
1599 local fid=$(make_small $f)
1600 check_hsm_flags $f "0x00000000"
1602 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1603 # used until file is flushed to disk
1604 if [ $(facet_fstype ost1) == "zfs" ]; then
1605 # this causes an OST_SYNC rpc to be sent
1606 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1607 # clear locks to reread file data
1608 cancel_lru_locks osc
1611 local orig_size=$(stat -c "%s" $f)
1612 local orig_blocks=$(stat -c "%b" $f)
1614 start_full_debug_logging
1616 $LFS hsm_archive $f || error "could not archive file"
1617 wait_request_state $fid ARCHIVE SUCCEED
1619 local blocks=$(stat -c "%b" $f)
1620 [ $blocks -eq $orig_blocks ] ||
1621 error "$f: wrong block number after archive: " \
1622 "$blocks != $orig_blocks"
1623 local size=$(stat -c "%s" $f)
1624 [ $size -eq $orig_size ] ||
1625 error "$f: wrong size after archive: $size != $orig_size"
1627 # Release and check states
1628 $LFS hsm_release $f || error "could not release file"
1629 check_hsm_flags $f "0x0000000d"
1631 blocks=$(stat -c "%b" $f)
1632 [ $blocks -gt 5 ] &&
1633 error "$f: too many blocks after release: $blocks > 5"
1634 size=$(stat -c "%s" $f)
1635 [ $size -ne $orig_size ] &&
1636 error "$f: wrong size after release: $size != $orig_size"
1638 # Check we can release an file without stripe info
1642 check_hsm_flags $f "0x00000000"
1643 $LFS hsm_archive $f || error "could not archive file"
1644 wait_request_state $fid ARCHIVE SUCCEED
1646 # Release and check states
1647 $LFS hsm_release $f || error "could not release file"
1648 check_hsm_flags $f "0x0000000d"
1650 # Release again a file that is already released is OK
1651 $LFS hsm_release $f || fail "second release should succeed"
1652 check_hsm_flags $f "0x0000000d"
1654 stop_full_debug_logging
1658 run_test 21 "Simple release tests"
1661 # test needs a running copytool
1666 local f=$DIR/$tdir/test_release
1667 local swap=$DIR/$tdir/test_swap
1669 # Create a file and check its states
1670 local fid=$(make_small $f)
1671 check_hsm_flags $f "0x00000000"
1673 $LFS hsm_archive $f || error "could not archive file"
1674 wait_request_state $fid ARCHIVE SUCCEED
1676 # Release and check states
1677 $LFS hsm_release $f || error "could not release file"
1678 check_hsm_flags $f "0x0000000d"
1681 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1686 run_test 22 "Could not swap a release file"
1689 # test needs a running copytool
1694 local f=$DIR/$tdir/test_mtime
1696 # Create a file and check its states
1697 local fid=$(make_small $f)
1698 check_hsm_flags $f "0x00000000"
1700 $LFS hsm_archive $f || error "could not archive file"
1701 wait_request_state $fid ARCHIVE SUCCEED
1703 # Set modification time in the past
1704 touch -m -a -d @978261179 $f
1706 # Release and check states
1707 $LFS hsm_release $f || error "could not release file"
1708 check_hsm_flags $f "0x0000000d"
1710 local MTIME=$(stat -c "%Y" $f)
1711 local ATIME=$(stat -c "%X" $f)
1712 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1713 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1717 run_test 23 "Release does not change a/mtime (utime)"
1720 local file=$DIR/$tdir/$tfile
1729 # test needs a running copytool
1734 fid=$(make_small $file)
1736 # Create a file and check its states
1737 check_hsm_flags $file "0x00000000"
1739 # Ensure atime is less than mtime and ctime.
1743 atime0=$(stat -c "%X" $file)
1744 mtime0=$(stat -c "%Y" $file)
1745 ctime0=$(stat -c "%Z" $file)
1747 [ $atime0 -lt $mtime0 ] ||
1748 error "atime $atime0 is not less than mtime $mtime0"
1750 [ $atime0 -lt $ctime0 ] ||
1751 error "atime $atime0 is not less than ctime $ctime0"
1753 # Archive should not change any timestamps.
1754 $LFS hsm_archive $file || error "cannot archive '$file'"
1755 wait_request_state $fid ARCHIVE SUCCEED
1757 atime1=$(stat -c "%X" $file)
1758 mtime1=$(stat -c "%Y" $file)
1759 ctime1=$(stat -c "%Z" $file)
1761 [ $atime0 -eq $atime1 ] ||
1762 error "archive changed atime from $atime0 to $atime1"
1764 [ $mtime0 -eq $mtime1 ] ||
1765 error "archive changed mtime from $mtime0 to $mtime1"
1767 [ $ctime0 -eq $ctime1 ] ||
1768 error "archive changed ctime from $ctime0 to $ctime1"
1770 # Release should not change any timestamps.
1771 $LFS hsm_release $file || error "cannot release '$file'"
1772 check_hsm_flags $file "0x0000000d"
1774 atime1=$(stat -c "%X" $file)
1775 mtime1=$(stat -c "%Y" $file)
1776 ctime1=$(stat -c "%Z" $file)
1778 [ $atime0 -eq $atime1 ] ||
1779 error "release changed atime from $atime0 to $atime1"
1781 [ $mtime0 -eq $mtime1 ] ||
1782 error "release changed mtime from $mtime0 to $mtime1"
1784 [ $ctime0 -eq $ctime1 ] ||
1785 error "release changed ctime from $ctime0 to $ctime1"
1787 # Restore should not change atime or mtime and should not
1789 $LFS hsm_restore $file
1790 wait_request_state $fid RESTORE SUCCEED
1792 atime1=$(stat -c "%X" $file)
1793 mtime1=$(stat -c "%Y" $file)
1794 ctime1=$(stat -c "%Z" $file)
1796 [ $atime0 -eq $atime1 ] ||
1797 error "restore changed atime from $atime0 to $atime1"
1799 [ $mtime0 -eq $mtime1 ] ||
1800 error "restore changed mtime from $mtime0 to $mtime1"
1802 [ $ctime0 -le $ctime1 ] ||
1803 error "restore changed ctime from $ctime0 to $ctime1"
1807 # Once more, after unmount and mount.
1808 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1809 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1811 atime1=$(stat -c "%X" $file)
1812 mtime1=$(stat -c "%Y" $file)
1813 ctime1=$(stat -c "%Z" $file)
1815 [ $atime0 -eq $atime1 ] ||
1816 error "remount changed atime from $atime0 to $atime1"
1818 [ $mtime0 -eq $mtime1 ] ||
1819 error "remount changed mtime from $mtime0 to $mtime1"
1821 [ $ctime0 -le $ctime1 ] ||
1822 error "remount changed ctime from $ctime0 to $ctime1"
1824 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1827 local file=$DIR/$tdir/$tfile
1833 # Test needs a running copytool.
1837 # Check that root can do HSM actions on a ordinary user's file.
1839 fid=$(make_small $file)
1840 sum0=$(md5sum $file)
1842 chown $RUNAS_ID:$RUNAS_GID $file ||
1843 error "cannot chown '$file' to '$RUNAS_ID'"
1845 chmod ugo-w $DIR/$tdir ||
1846 error "cannot chmod '$DIR/$tdir'"
1848 $LFS hsm_archive $file
1849 wait_request_state $fid ARCHIVE SUCCEED
1851 $LFS hsm_release $file
1852 check_hsm_flags $file "0x0000000d"
1854 $LFS hsm_restore $file
1855 wait_request_state $fid RESTORE SUCCEED
1857 # Check that ordinary user can get HSM state.
1858 $RUNAS $LFS hsm_state $file ||
1859 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1861 $LFS hsm_release $file
1862 check_hsm_flags $file "0x0000000d"
1864 # Check that ordinary user can accessed released file.
1865 sum1=$($RUNAS md5sum $file) ||
1866 error "user '$RUNAS_ID' cannot read '$file'"
1868 [ "$sum0" == "$sum1" ] ||
1869 error "md5sum mismatch for '$file'"
1873 run_test 24b "root can archive, release, and restore user files"
1875 cleanup_test_24c() {
1877 set_hsm_param user_request_mask RESTORE
1878 set_hsm_param group_request_mask RESTORE
1879 set_hsm_param other_request_mask RESTORE
1883 local file=$DIR/$tdir/$tfile
1884 local action=archive
1889 # test needs a running copytool
1894 # Save the default masks and check that cleanup_24c will
1895 # restore the request masks correctly.
1896 user_save=$(get_hsm_param user_request_mask)
1897 group_save=$(get_hsm_param group_request_mask)
1898 other_save=$(get_hsm_param other_request_mask)
1900 [ "$user_save" == RESTORE ] ||
1901 error "user_request_mask is '$user_save' expected 'RESTORE'"
1902 [ "$group_save" == RESTORE ] ||
1903 error "group_request_mask is '$group_save' expected 'RESTORE'"
1904 [ "$other_save" == RESTORE ] ||
1905 error "other_request_mask is '$other_save' expected 'RESTORE'"
1907 trap cleanup_test_24c EXIT
1912 chown $RUNAS_ID:nobody $file ||
1913 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
1915 set_hsm_param user_request_mask ""
1916 $RUNAS $LFS hsm_$action $file &&
1917 error "$action by user should fail"
1919 set_hsm_param user_request_mask $action
1920 $RUNAS $LFS hsm_$action $file ||
1921 error "$action by user should succeed"
1926 chown nobody:$RUNAS_GID $file ||
1927 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1929 set_hsm_param group_request_mask ""
1930 $RUNAS $LFS hsm_$action $file &&
1931 error "$action by group should fail"
1933 set_hsm_param group_request_mask $action
1934 $RUNAS $LFS hsm_$action $file ||
1935 error "$action by group should succeed"
1940 chown nobody:nobody $file ||
1941 error "cannot chown '$file' to 'nobody:nobody'"
1943 set_hsm_param other_request_mask ""
1944 $RUNAS $LFS hsm_$action $file &&
1945 error "$action by other should fail"
1947 set_hsm_param other_request_mask $action
1948 $RUNAS $LFS hsm_$action $file ||
1949 error "$action by other should succeed"
1954 run_test 24c "check that user,group,other request masks work"
1956 cleanup_test_24d() {
1958 mount -o remount,rw $MOUNT2
1962 local file1=$DIR/$tdir/$tfile
1963 local file2=$DIR2/$tdir/$tfile
1971 fid1=$(make_small $file1)
1973 trap cleanup_test_24d EXIT
1975 mount -o remount,ro $MOUNT2
1977 fid2=$(path2fid $file2)
1978 [ "$fid1" == "$fid2" ] ||
1979 error "FID mismatch '$fid1' != '$fid2'"
1981 $LFS hsm_archive $file2 &&
1982 error "archive should fail on read-only mount"
1983 check_hsm_flags $file1 "0x00000000"
1985 $LFS hsm_archive $file1
1986 wait_request_state $fid1 ARCHIVE SUCCEED
1988 $LFS hsm_release $file1
1989 $LFS hsm_restore $file2
1990 wait_request_state $fid1 RESTORE SUCCEED
1992 $LFS hsm_release $file1 || error "cannot release '$file1'"
1993 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
1995 $LFS hsm_release $file2 &&
1996 error "release should fail on read-only mount"
2001 run_test 24d "check that read-only mounts are respected"
2004 # test needs a running copytool
2008 copy2archive /etc/hosts $tdir/$tfile
2010 local f=$DIR/$tdir/$tfile
2012 import_file $tdir/$tfile $f
2014 $LFS hsm_set --lost $f
2019 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2023 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2024 " (Operation not permitted)"
2027 # test needs a running copytool
2032 local f=$DIR/$tdir/$tfile
2033 local fid=$(copy_file /etc/passwd $f)
2035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2036 wait_request_state $fid ARCHIVE SUCCEED
2039 $LFS hsm_set --lost $f
2043 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2047 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2048 " (Operation not permitted)"
2051 # test needs a running copytool
2055 local f=$DIR/$tdir/$tfile
2057 fid=$(make_large_for_progress $f)
2058 [ $? != 0 ] && skip "not enough free space" && return
2060 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2061 wait_request_state $fid ARCHIVE SUCCEED
2064 wait_request_state $fid REMOVE SUCCEED
2066 check_hsm_flags $f "0x00000000"
2070 run_test 26 "Remove the archive of a valid file"
2073 # test needs a running copytool
2077 make_archive $tdir/$tfile
2078 local f=$DIR/$tdir/$tfile
2079 import_file $tdir/$tfile $f
2080 local fid=$(path2fid $f)
2084 [[ $? != 0 ]] || error "Remove of a released file should fail"
2088 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2091 # test needs a running copytool
2095 local f=$DIR/$tdir/$tfile
2097 fid=$(make_large_for_progress $f)
2098 [ $? != 0 ] && skip "not enough free space" && return
2100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2101 wait_request_state $fid ARCHIVE SUCCEED
2106 [[ $? != 0 ]] || error "Remove of a released file should fail"
2110 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2113 # test needs a running copytool
2117 local f=$DIR/$tdir/$tfile
2119 fid=$(make_large_for_progress $f)
2120 [ $? != 0 ] && skip "not enough free space" && return
2122 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2123 wait_request_state $fid ARCHIVE SUCCEED
2132 wait_request_state $fid REMOVE SUCCEED
2136 run_test 28 "Concurrent archive/file remove"
2139 # restore at exec cannot work on agent node (because of Linux kernel
2140 # protection of executables)
2141 needclients 2 || return 0
2143 # test needs a running copytool
2147 copy2archive /bin/true $tdir/$tfile
2149 local f=$DIR/$tdir/true
2150 import_file $tdir/$tfile $f
2152 local fid=$(path2fid $f)
2154 # set no retry action mode
2160 # remove no try action mode
2164 [[ $st == 0 ]] || error "Failed to exec a released file"
2168 run_test 30a "Restore at exec (import case)"
2171 # restore at exec cannot work on agent node (because of Linux kernel
2172 # protection of executables)
2173 needclients 2 || return 0
2175 # test needs a running copytool
2179 local f=$DIR/$tdir/true
2180 local fid=$(copy_file /bin/true $f)
2182 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2183 wait_request_state $fid ARCHIVE SUCCEED
2186 # set no retry action mode
2192 # remove no try action mode
2196 [[ $st == 0 ]] || error "Failed to exec a released file"
2200 run_test 30b "Restore at exec (release case)"
2203 needclients 2 || return 0
2205 # test needs a running copytool
2209 local f=$DIR/$tdir/SLEEP
2210 local fid=$(copy_file /bin/sleep $f)
2212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2213 wait_request_state $fid ARCHIVE SUCCEED
2215 check_hsm_flags $f "0x0000000d"
2216 # set no retry action mode
2218 do_node $CLIENT2 "$f 10" &
2222 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2224 [[ $? == 0 ]] || error "Execution failed during run"
2226 [[ $? == 0 ]] || error "Binary overwritten during exec"
2229 # remove no try action mode
2231 check_hsm_flags $f "0x00000009"
2235 run_test 30c "Update during exec of released file must fail"
2237 restore_and_check_size() {
2240 local s=$(stat -c "%s" $f)
2242 local st=$(get_hsm_flags $f)
2246 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2248 n=$(stat -c "%s" $f)
2249 # we echo in both cases to show stat is not
2251 if [[ $n != $s ]]; then
2252 echo "size seen is $n != $s"
2255 echo "size seen is right: $n == $s"
2257 st=$(get_hsm_flags $f)
2261 if [[ $cpt -lt 10 ]]; then
2264 echo " restore is too long"
2265 wait_request_state $fid RESTORE SUCCEED
2271 # test needs a running copytool
2276 make_archive $tdir/$tfile
2277 local f=$DIR/$tdir/$tfile
2278 import_file $tdir/$tfile $f
2279 local fid=$($LFS path2fid $f)
2280 HSM_ARCHIVE_PURGE=false copytool_setup
2282 restore_and_check_size $f $fid
2285 [[ $err -eq 0 ]] || error "File size changed during restore"
2289 run_test 31a "Import a large file and check size during restore"
2293 # test needs a running copytool
2298 local f=$DIR/$tdir/$tfile
2300 fid=$(make_large_for_progress $f)
2301 [ $? != 0 ] && skip "not enough free space" && return
2303 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2304 wait_request_state $fid ARCHIVE SUCCEED
2307 restore_and_check_size $f $fid
2310 [[ $err -eq 0 ]] || error "File size changed during restore"
2314 run_test 31b "Restore a large unaligned file and check size during restore"
2317 # test needs a running copytool
2322 local f=$DIR/$tdir/$tfile
2324 fid=$(make_large_for_progress_aligned $f)
2325 [ $? != 0 ] && skip "not enough free space" && return
2327 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2328 wait_request_state $fid ARCHIVE SUCCEED
2331 restore_and_check_size $f $fid
2334 [[ $err -eq 0 ]] || error "File size changed during restore"
2338 run_test 31c "Restore a large aligned file and check size during restore"
2341 # test needs a running copytool
2346 local f=$DIR/$tdir/$tfile
2348 fid=$(make_large_for_progress $f)
2349 [ $? != 0 ] && skip "not enough free space" && return
2351 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2352 wait_request_state $fid ARCHIVE SUCCEED
2355 # to be sure wait_all_done will not be mislead by previous tests
2358 wait_for_grace_delay
2359 # Also raise grace_delay significantly so the Canceled
2360 # Restore action will stay enough long avail.
2361 local old_grace=$(get_hsm_param grace_delay)
2362 set_hsm_param grace_delay 100
2364 md5sum $f >/dev/null &
2366 wait_request_state $fid RESTORE STARTED
2371 # Check restore trigger process was killed
2372 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2376 # instead of waiting+checking both Restore and Cancel ops
2377 # sequentially, wait for both to be finished and then check
2379 wait_all_done 100 $fid
2380 local rstate=$(get_request_state $fid RESTORE)
2381 local cstate=$(get_request_state $fid CANCEL)
2383 # restore orig grace_delay.
2384 set_hsm_param grace_delay $old_grace
2386 if [[ "$rstate" == "CANCELED" ]] ; then
2387 [[ "$cstate" == "SUCCEED" ]] ||
2388 error "Restore state is CANCELED and Cancel state " \
2389 "is not SUCCEED but $cstate"
2390 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2391 elif [[ "$rstate" == "SUCCEED" ]] ; then
2392 [[ "$cstate" == "FAILED" ]] ||
2393 error "Restore state is SUCCEED and Cancel state " \
2394 "is not FAILED but $cstate"
2395 echo "Restore state is SUCCEED, Cancel state is FAILED"
2397 error "Restore state is $rstate and Cancel state is $cstate"
2401 error "Cannot kill process waiting for restore ($killed)"
2405 run_test 33 "Kill a restore waiting process"
2408 # test needs a running copytool
2413 local f=$DIR/$tdir/$tfile
2415 fid=$(make_large_for_progress $f)
2416 [ $? != 0 ] && skip "not enough free space" && return
2418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2419 wait_request_state $fid ARCHIVE SUCCEED
2422 md5sum $f >/dev/null &
2424 wait_request_state $fid RESTORE STARTED
2426 rm $f || error "rm $f failed"
2427 # rm must not block during restore
2428 wait_request_state $fid RESTORE STARTED
2430 wait_request_state $fid RESTORE SUCCEED
2431 # check md5sum pgm finished
2432 local there=$(ps -o pid,comm hp $pid >/dev/null)
2433 [[ -z $there ]] || error "Restore initiator does not exit"
2435 local rc=$(wait $pid)
2436 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2440 run_test 34 "Remove file during restore"
2443 # test needs a running copytool
2448 local f=$DIR/$tdir/$tfile
2449 local f1=$DIR/$tdir/$tfile-1
2451 fid=$(make_large_for_progress $f)
2452 [ $? != 0 ] && skip "not enough free space" && return
2454 local fid1=$(copy_file /etc/passwd $f1)
2455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2456 wait_request_state $fid ARCHIVE SUCCEED
2459 md5sum $f >/dev/null &
2461 wait_request_state $fid RESTORE STARTED
2463 mv $f1 $f || error "mv $f1 $f failed"
2464 # mv must not block during restore
2465 wait_request_state $fid RESTORE STARTED
2467 wait_request_state $fid RESTORE SUCCEED
2468 # check md5sum pgm finished
2469 local there=$(ps -o pid,comm hp $pid >/dev/null)
2470 [[ -z $there ]] || error "Restore initiator does not exit"
2472 local rc=$(wait $pid)
2473 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2476 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2480 run_test 35 "Overwrite file during restore"
2483 # test needs a running copytool
2488 local f=$DIR/$tdir/$tfile
2490 fid=$(make_large_for_progress $f)
2491 [ $? != 0 ] && skip "not enough free space" && return
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2494 wait_request_state $fid ARCHIVE SUCCEED
2497 md5sum $f >/dev/null &
2499 wait_request_state $fid RESTORE STARTED
2502 # rm must not block during restore
2503 wait_request_state $fid RESTORE STARTED
2505 wait_request_state $fid RESTORE SUCCEED
2506 # check md5sum pgm finished
2507 local there=$(ps -o pid,comm hp $pid >/dev/null)
2509 error "Restore initiator does not exit"
2511 local rc=$(wait $pid)
2513 error "Restore initiator failed with $rc"
2517 run_test 36 "Move file during restore"
2524 for n in $(seq 1 $count); do
2525 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2527 echo "$count archive requests submitted"
2531 local stream_count=4
2532 local file_count=100
2534 local f=$DIR/$tdir/$tfile
2539 for i in $(seq 1 $file_count); do
2540 for p in $(seq 1 $stream_count); do
2541 fid=$(copy_file /etc/hosts $f.$p.$i)
2544 # force copytool to use a local/temp archive dir to ensure best
2545 # performance vs remote/NFS mounts used in auto-tests
2546 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2549 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2551 # to be sure wait_all_done will not be mislead by previous tests
2553 wait_for_grace_delay
2555 # start archive streams in background (archive files in parallel)
2556 for p in $(seq 1 $stream_count); do
2557 multi_archive $f.$p $file_count &
2560 echo -n "Wait for all requests being enqueued..."
2566 run_test 40 "Parallel archive requests"
2569 # test needs a running copytool
2573 local f=$DIR/$tdir/$tfile
2574 local fid=$(copy_file /etc/motd $f 1)
2576 $LFS hsm_archive $f || error "could not archive file"
2577 wait_request_state $fid ARCHIVE SUCCEED
2578 check_hsm_flags $f "0x00000009"
2580 multiop_bg_pause $f O_c || error "multiop failed"
2584 client_up || client_up || true
2586 kill -USR1 $MULTIPID
2587 wait $MULTIPID || error "multiop close failed"
2589 check_hsm_flags $f "0x0000000b"
2593 run_test 52 "Opened for write file on an evicted client should be set dirty"
2596 # test needs a running copytool
2600 local f=$DIR/$tdir/$tfile
2601 local fid=$(copy_file /etc/motd $f 1)
2603 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2604 error "could not archive file"
2605 wait_request_state $fid ARCHIVE SUCCEED
2606 check_hsm_flags $f "0x00000009"
2608 multiop_bg_pause $f o_c || error "multiop failed"
2612 client_up || client_up || true
2614 kill -USR1 $MULTIPID
2615 wait $MULTIPID || error "multiop close failed"
2617 check_hsm_flags $f "0x00000009"
2621 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2624 # test needs a running copytool
2628 local f=$DIR/$tdir/$tfile
2629 local fid=$(make_small $f)
2631 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2632 error "could not archive file"
2633 wait_request_state $fid ARCHIVE STARTED
2635 check_hsm_flags $f "0x00000001"
2637 # Avoid coordinator resending this request as soon it has failed.
2642 wait_request_state $fid ARCHIVE FAILED
2644 check_hsm_flags $f "0x00000003"
2649 run_test 54 "Write during an archive cancels it"
2652 # test needs a running copytool
2656 local f=$DIR/$tdir/$tfile
2657 local fid=$(make_small $f)
2659 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2660 error "could not archive file"
2661 wait_request_state $fid ARCHIVE STARTED
2663 check_hsm_flags $f "0x00000001"
2665 # Avoid coordinator resending this request as soon it has failed.
2668 $TRUNCATE $f 1024 || error "truncate failed"
2670 wait_request_state $fid ARCHIVE FAILED
2672 check_hsm_flags $f "0x00000003"
2677 run_test 55 "Truncate during an archive cancels it"
2680 # test needs a running copytool
2684 local f=$DIR/$tdir/$tfile
2686 fid=$(make_large_for_progress $f)
2687 [ $? != 0 ] && skip "not enough free space" && return
2689 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2690 error "could not archive file"
2691 wait_request_state $fid ARCHIVE STARTED
2693 check_hsm_flags $f "0x00000001"
2695 # Change metadata and sync to be sure we are not changing only
2700 wait_request_state $fid ARCHIVE SUCCEED
2702 check_hsm_flags $f "0x00000009"
2706 run_test 56 "Setattr during an archive is ok"
2709 # Need one client for I/O, one for request
2710 needclients 2 || return 0
2712 # test needs a running copytool
2716 local f=$DIR/$tdir/test_archive_remote
2717 # Create a file on a remote node
2718 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2719 "count=2 conv=fsync"
2722 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2723 error "hsm_archive failed"
2724 local fid=$(path2fid $f)
2725 wait_request_state $fid ARCHIVE SUCCEED
2727 # Release and implicit restore it
2728 do_node $CLIENT2 "$LFS hsm_release $f" ||
2729 error "hsm_release failed"
2730 do_node $CLIENT2 "md5sum $f" ||
2731 error "hsm_restore failed"
2733 wait_request_state $fid RESTORE SUCCEED
2737 run_test 57 "Archive a file with dirty cache on another node"
2739 truncate_released_file() {
2743 local sz=$(stat -c %s $src_file)
2744 local f=$DIR/$tdir/$tfile
2745 local fid=$(copy_file $1 $f)
2749 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2750 error "could not archive file"
2751 wait_request_state $fid ARCHIVE SUCCEED
2753 $LFS hsm_release $f || error "could not release file"
2755 $TRUNCATE $f $trunc_to || error "truncate failed"
2758 local sz1=$(stat -c %s $f)
2759 [[ $sz1 == $trunc_to ]] ||
2760 error "size after trunc: $sz1 expect $trunc_to, original $sz"
2763 check_hsm_flags $f "0x0000000b"
2765 local state=$(get_request_state $fid RESTORE)
2766 [[ "$state" == "SUCCEED" ]] ||
2767 error "truncate $sz does not trig restore, state = $state"
2769 $TRUNCATE $ref $trunc_to
2770 cmp $ref $f || error "file data wrong after truncate"
2776 # test needs a running copytool
2781 local sz=$(stat -c %s /etc/passwd)
2783 echo "truncate up from $sz to $((sz*2))"
2784 truncate_released_file /etc/passwd $((sz*2))
2786 echo "truncate down from $sz to $((sz/2))"
2787 truncate_released_file /etc/passwd $((sz/2))
2789 echo "truncate to 0"
2790 truncate_released_file /etc/passwd 0
2794 run_test 58 "Truncate a released file will trigger restore"
2797 # This test validates the fix for LU-4512. Ensure that the -u
2798 # option changes the progress reporting interval from the
2799 # default (30 seconds) to the user-specified interval.
2801 local progress_timeout=$((interval * 4))
2803 # test needs a new running copytool
2805 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
2808 local f=$DIR/$tdir/$tfile
2810 fid=$(make_large_for_progress $f)
2811 [ $? != 0 ] && skip "not enough free space" && return
2814 local mdt=${MDT_PREFIX}${mdtidx}
2815 local mds=mds$((mdtidx + 1))
2817 # Wait for copytool to register
2818 wait_update_facet $mds \
2819 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
2820 uuid 100 || error "coyptool failed to register with $mdt"
2822 local start_at=$(date +%s)
2823 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2824 error "could not archive file"
2826 local agent=$(facet_active_host $SINGLEAGT)
2827 local prefix=$TESTLOG_PREFIX
2828 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
2829 local copytool_log=$prefix.copytool_log.$agent.log
2832 wait_update $agent \
2833 "grep -o start.copy $copytool_log" "start copy" 100 ||
2834 error "copytool failed to start"
2836 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
2837 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
2843 echo -n "Expecting a progress update within $progress_timeout seconds... "
2845 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
2846 if [ $RESULT -gt 0 ]; then
2847 echo "$RESULT bytes copied in $WAIT seconds."
2849 elif [ $WAIT -ge $progress_timeout ]; then
2850 error "Timed out waiting for progress update!"
2853 WAIT=$((WAIT + sleep))
2857 local finish_at=$(date +%s)
2858 local elapsed=$((finish_at - start_at))
2860 # Ensure that the progress update occurred within the expected window.
2861 if [ $elapsed -lt $interval ]; then
2862 error "Expected progress update after at least $interval seconds"
2868 run_test 60 "Changing progress update interval from default"
2871 # test needs a new running copytool
2873 copytool_monitor_setup
2874 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2876 # Just start and stop the copytool to generate events.
2879 # Wait for the copytool to register.
2880 wait_update --verbose $(facet_active_host mds1) \
2881 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
2883 error "copytool failed to register with MDT0000"
2887 local REGISTER_EVENT
2888 local UNREGISTER_EVENT
2889 while read event; do
2890 local parsed=$(parse_json_event "$event")
2891 if [ -z "$parsed" ]; then
2892 error "Copytool sent malformed event: $event"
2896 if [ $event_type == "REGISTER" ]; then
2897 REGISTER_EVENT=$event
2898 elif [ $event_type == "UNREGISTER" ]; then
2899 UNREGISTER_EVENT=$event
2901 done < <(echo $"$(get_copytool_event_log)")
2903 if [ -z "$REGISTER_EVENT" ]; then
2904 error "Copytool failed to send register event to FIFO"
2907 if [ -z "$UNREGISTER_EVENT" ]; then
2908 error "Copytool failed to send unregister event to FIFO"
2911 copytool_monitor_cleanup
2912 echo "Register/Unregister events look OK."
2914 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
2917 # Bump progress interval for livelier events.
2920 # test needs a new running copytool
2922 copytool_monitor_setup
2923 HSMTOOL_UPDATE_INTERVAL=$interval \
2924 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
2927 local f=$DIR/$tdir/$tfile
2929 fid=$(make_large_for_progress $f)
2930 [ $? != 0 ] && skip "not enough free space" && return
2932 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2933 error "could not archive file"
2934 wait_request_state $fid ARCHIVE SUCCEED
2936 local expected_fields="event_time data_fid source_fid"
2937 expected_fields+=" total_bytes current_bytes"
2941 while read event; do
2942 # Make sure we're not getting anything from previous events.
2943 for field in $expected_fields; do
2947 local parsed=$(parse_json_event "$event")
2948 if [ -z "$parsed" ]; then
2949 error "Copytool sent malformed event: $event"
2953 if [ $event_type == "ARCHIVE_START" ]; then
2956 elif [ $event_type == "ARCHIVE_FINISH" ]; then
2959 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
2963 # Do some simple checking of the progress update events.
2964 for expected_field in $expected_fields; do
2965 if [ -z ${!expected_field+x} ]; then
2966 error "Missing $expected_field field in event"
2970 if [ $total_bytes -eq 0 ]; then
2971 error "Expected total_bytes to be > 0"
2974 # These should be identical throughout an archive
2976 if [ $source_fid != $data_fid ]; then
2977 error "Expected source_fid to equal data_fid"
2979 done < <(echo $"$(get_copytool_event_log)")
2981 if [ -z "$START_EVENT" ]; then
2982 error "Copytool failed to send archive start event to FIFO"
2985 if [ -z "$FINISH_EVENT" ]; then
2986 error "Copytool failed to send archive finish event to FIFO"
2989 echo "Archive events look OK."
2993 copytool_monitor_cleanup
2995 run_test 71 "Copytool logs JSON archive events to FIFO"
2998 # Bump progress interval for livelier events.
3001 # test needs a new running copytool
3003 copytool_monitor_setup
3004 HSMTOOL_UPDATE_INTERVAL=$interval \
3005 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3006 local test_file=$HSMTOOL_MONITOR_DIR/file
3008 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3010 do_facet $SINGLEAGT "$cmd" ||
3011 error "cannot create $test_file on $SINGLEAGT"
3012 copy2archive $test_file $tdir/$tfile
3015 local f=$DIR/$tdir/$tfile
3016 import_file $tdir/$tfile $f
3017 f=$DIR2/$tdir/$tfile
3018 echo "Verifying released state: "
3019 check_hsm_flags $f "0x0000000d"
3021 local fid=$(path2fid $f)
3023 wait_request_state $fid RESTORE SUCCEED
3025 local expected_fields="event_time data_fid source_fid"
3026 expected_fields+=" total_bytes current_bytes"
3030 while read event; do
3031 # Make sure we're not getting anything from previous events.
3032 for field in $expected_fields; do
3036 local parsed=$(parse_json_event "$event")
3037 if [ -z "$parsed" ]; then
3038 error "Copytool sent malformed event: $event"
3042 if [ $event_type == "RESTORE_START" ]; then
3044 if [ $source_fid != $data_fid ]; then
3045 error "source_fid should == data_fid at start"
3048 elif [ $event_type == "RESTORE_FINISH" ]; then
3050 if [ $source_fid != $data_fid ]; then
3051 error "source_fid should == data_fid at finish"
3054 elif [ $event_type != "RESTORE_RUNNING" ]; then
3058 # Do some simple checking of the progress update events.
3059 for expected_field in $expected_fields; do
3060 if [ -z ${!expected_field+x} ]; then
3061 error "Missing $expected_field field in event"
3065 if [ $total_bytes -eq 0 ]; then
3066 error "Expected total_bytes to be > 0"
3069 # When a restore starts out, the data fid is the same as the
3070 # source fid. After the restore has gotten going, we learn
3071 # the new data fid. Once the restore has finished, the source
3072 # fid is set to the new data fid.
3074 # We test this because some monitoring software may depend on
3075 # this behavior. If it changes, then the consumers of these
3076 # events may need to be modified.
3077 if [ $source_fid == $data_fid ]; then
3078 error "source_fid should != data_fid during restore"
3080 done < <(echo $"$(get_copytool_event_log)")
3082 if [ -z "$START_EVENT" ]; then
3083 error "Copytool failed to send restore start event to FIFO"
3086 if [ -z "$FINISH_EVENT" ]; then
3087 error "Copytool failed to send restore finish event to FIFO"
3090 echo "Restore events look OK."
3094 copytool_monitor_cleanup
3098 run_test 72 "Copytool logs JSON restore events to FIFO"
3101 file_count=51 # Max number of files constrained by LNET message size
3102 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3103 local f=$DIR/$tdir/$tfile
3104 local FILELIST=/tmp/filelist.txt
3108 for i in $(seq 1 $file_count); do
3109 fid=$(copy_file /etc/hosts $f.$i)
3110 echo $f.$i >> $FILELIST
3112 # force copytool to use a local/temp archive dir to ensure best
3113 # performance vs remote/NFS mounts used in auto-tests
3114 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3117 local dai=$(get_hsm_param default_archive_id)
3118 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3120 # to be sure wait_all_done will not be mislead by previous tests
3122 wait_for_grace_delay
3123 $LFS hsm_archive --filelist $FILELIST ||
3124 error "cannot archive a file list"
3126 $LFS hsm_release --filelist $FILELIST ||
3127 error "cannot release a file list"
3128 $LFS hsm_restore --filelist $FILELIST ||
3129 error "cannot restore a file list"
3133 run_test 90 "Archive/restore a file list"
3135 double_verify_reset_hsm_param() {
3137 echo "Testing $HSM_PARAM.$p"
3138 local val=$(get_hsm_param $p)
3140 local val2=$(($val * 2))
3141 set_hsm_param $p $val2
3142 val=$(get_hsm_param $p)
3143 [[ $val == $val2 ]] ||
3144 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3145 echo "Set $p to 0 must failed"
3149 set_hsm_param $p $save
3151 if [[ $rc == 0 ]]; then
3152 error "we must not be able to set $HSM_PARAM.$p to 0"
3157 double_verify_reset_hsm_param loop_period
3158 double_verify_reset_hsm_param grace_delay
3159 double_verify_reset_hsm_param active_request_timeout
3160 double_verify_reset_hsm_param max_requests
3161 double_verify_reset_hsm_param default_archive_id
3163 run_test 100 "Set coordinator /proc tunables"
3170 run_test 102 "Verify coordinator control"
3173 # test needs a running copytool
3180 for i in $(seq 1 20); do
3181 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3187 echo "Current requests"
3188 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3189 $HSM_PARAM.actions |\
3190 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3192 [[ -z "$res" ]] || error "Some request have not been canceled"
3196 run_test 103 "Purge all requests"
3201 # test needs a running copytool
3205 local f=$DIR/$tdir/$tfile
3207 fid=$(make_large_for_progress $f)
3208 [ $? != 0 ] && skip "not enough free space" && return
3210 # if cdt is on, it can serve too quickly the request
3212 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3213 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3214 $HSM_PARAM.actions |\
3215 grep $fid | cut -f16 -d=")
3218 [[ "$data1" == "$DATAHEX" ]] ||
3219 error "Data field in records is ($data1) and not ($DATAHEX)"
3223 run_test 104 "Copy tool data field"
3230 for i in $(seq -w 1 10); do
3231 cp /etc/passwd $DIR/$tdir/$i
3232 $LFS hsm_archive $DIR/$tdir/$i
3234 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3235 $HSM_PARAM.actions |\
3236 grep WAITING | wc -l")
3239 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3240 $HSM_PARAM.actions |\
3241 grep WAITING | wc -l")
3244 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3245 error "Requests count after shutdown $reqcnt2 != "\
3246 "before shutdown $reqcnt1"
3248 run_test 105 "Restart of coordinator"
3250 get_agent_by_uuid_mdt() {
3253 local mds=mds$(($mdtidx + 1))
3254 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3258 check_agent_registered_by_mdt() {
3261 local mds=mds$(($mdtidx + 1))
3262 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3263 if [[ ! -z "$agent" ]]; then
3264 echo "found agent $agent on $mds"
3266 error "uuid $uuid not found in agent list on $mds"
3270 check_agent_unregistered_by_mdt() {
3273 local mds=mds$(($mdtidx + 1))
3274 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3275 if [[ -z "$agent" ]]; then
3276 echo "uuid not found in agent list on $mds"
3278 error "uuid found in agent list on $mds: $agent"
3282 check_agent_registered() {
3285 for mdsno in $(seq 1 $MDSCOUNT); do
3286 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3290 check_agent_unregistered() {
3293 for mdsno in $(seq 1 $MDSCOUNT); do
3294 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3299 local uuid=$(do_rpc_nodes $(facet_active_host $SINGLEAGT) \
3300 get_client_uuid $MOUNT | cut -d' ' -f2)
3303 check_agent_registered $uuid
3305 search_copytools || error "No copytool found"
3308 check_agent_unregistered $uuid
3311 check_agent_registered $uuid
3315 run_test 106 "Copytool register/unregister"
3318 # test needs a running copytool
3320 # create and archive file
3322 local f1=$DIR/$tdir/$tfile
3323 local fid=$(copy_file /etc/passwd $f1)
3324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3325 wait_request_state $fid ARCHIVE SUCCEED
3326 # shutdown and restart MDS
3328 # check the copytool still gets messages from MDT
3329 local f2=$DIR/$tdir/2
3330 local fid=$(copy_file /etc/passwd $f2)
3331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3332 # main check of this sanity: this request MUST succeed
3333 wait_request_state $fid ARCHIVE SUCCEED
3336 run_test 107 "Copytool re-register after MDS restart"
3338 policy_set_and_test()
3342 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3343 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3344 [[ "$policy" == "$target" ]] ||
3345 error "Wrong policy after '$change': '$policy' != '$target'"
3349 # to force default policy setting if error
3350 CDT_POLICY_HAD_CHANGED=true
3352 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3353 local default="NonBlockingRestore [NoRetryAction]"
3354 [[ "$policy" == "$default" ]] ||
3355 error "default policy has changed,"\
3356 " '$policy' != '$default' update the test"
3357 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3358 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3359 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3360 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3361 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3362 # useless bacause we know but safer for futur changes to use real value
3363 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3364 echo "Next set_param must failed"
3365 policy_set_and_test "wrong" "$policy"
3368 echo "Back to default policy"
3369 cdt_set_sanity_policy
3371 run_test 109 "Policy display/change"
3374 # test needs a running copytool
3379 copy2archive /etc/passwd $tdir/$tfile
3381 local f=$DIR/$tdir/$tfile
3382 import_file $tdir/$tfile $f
3383 local fid=$(path2fid $f)
3385 cdt_set_non_blocking_restore
3390 wait_request_state $fid RESTORE SUCCEED
3391 cdt_clear_non_blocking_restore
3395 error "md5sum returns $st != 1, "\
3396 "should also perror ENODATA (No data available)"
3400 run_test 110a "Non blocking restore policy (import case)"
3403 # test needs a running copytool
3407 local f=$DIR/$tdir/$tfile
3408 local fid=$(copy_file /etc/passwd $f)
3409 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3410 wait_request_state $fid ARCHIVE SUCCEED
3413 cdt_set_non_blocking_restore
3418 wait_request_state $fid RESTORE SUCCEED
3419 cdt_clear_non_blocking_restore
3423 error "md5sum returns $st != 1, "\
3424 "should also perror ENODATA (No data available)"
3428 run_test 110b "Non blocking restore policy (release case)"
3431 # test needs a running copytool
3435 copy2archive /etc/passwd $tdir/$tfile
3437 local f=$DIR/$tdir/$tfile
3439 import_file $tdir/$tfile $f
3440 local fid=$(path2fid $f)
3444 copytool_remove_backend $fid
3447 wait_request_state $fid RESTORE FAILED
3454 [[ $st == 0 ]] || error "Restore does not failed"
3458 run_test 111a "No retry policy (import case), restore will error"\
3459 " (No such file or directory)"
3462 # test needs a running copytool
3466 local f=$DIR/$tdir/$tfile
3467 local fid=$(copy_file /etc/passwd $f)
3469 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3470 wait_request_state $fid ARCHIVE SUCCEED
3473 copytool_remove_backend $fid
3476 wait_request_state $fid RESTORE FAILED
3483 [[ $st == 0 ]] || error "Restore does not failed"
3487 run_test 111b "No retry policy (release case), restore will error"\
3488 " (No such file or directory)"
3491 # test needs a running copytool
3495 local f=$DIR/$tdir/$tfile
3496 local fid=$(copy_file /etc/passwd $f)
3498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3499 local l=$($LFS hsm_action $f)
3501 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3505 wait_request_state $fid ARCHIVE SUCCEED
3508 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3512 run_test 112 "State of recorded request"
3515 # test needs a running copytool
3519 local f=$DIR/$tdir/$tfile
3521 fid=$(make_large_for_cancel $f)
3522 [ $? != 0 ] && skip "not enough free space" && return
3524 # test with cdt on is made in test_221
3526 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3529 wait_request_state $fid ARCHIVE CANCELED
3530 wait_request_state $fid CANCEL SUCCEED
3534 run_test 200 "Register/Cancel archive"
3537 # test needs a running copytool
3541 local f=$DIR/$tdir/$tfile
3542 make_archive $tdir/$tfile
3543 import_file $tdir/$tfile $f
3544 local fid=$(path2fid $f)
3546 # test with cdt on is made in test_222
3551 wait_request_state $fid RESTORE CANCELED
3552 wait_request_state $fid CANCEL SUCCEED
3556 run_test 201 "Register/Cancel restore"
3559 # test needs a running copytool
3563 local f=$DIR/$tdir/$tfile
3565 fid=$(make_large_for_progress $f)
3566 [ $? != 0 ] && skip "not enough free space" && return
3568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3569 wait_request_state $fid ARCHIVE SUCCEED
3575 wait_request_state $fid REMOVE CANCELED
3579 run_test 202 "Register/Cancel remove"
3582 # test needs a running copytool
3587 local f=$DIR/$tdir/$tfile
3588 local fid=$(copy_file /etc/passwd $f)
3592 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3593 wait_request_state $fid ARCHIVE SUCCEED
3595 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3599 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3603 run_test 220 "Changelog for archive"
3606 # test needs a running copytool
3611 local f=$DIR/$tdir/$tfile
3613 fid=$(make_large_for_cancel $f)
3614 [ $? != 0 ] && skip "not enough free space" && return
3618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3619 wait_request_state $fid ARCHIVE STARTED
3621 wait_request_state $fid ARCHIVE CANCELED
3622 wait_request_state $fid CANCEL SUCCEED
3624 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3627 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3631 run_test 221 "Changelog for archive canceled"
3634 # test needs a running copytool
3638 copy2archive /etc/passwd $tdir/$tfile
3640 local f=$DIR/$tdir/$tfile
3641 import_file $tdir/$tfile $f
3642 local fid=$(path2fid $f)
3647 wait_request_state $fid RESTORE SUCCEED
3649 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3652 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3656 run_test 222a "Changelog for explicit restore"
3659 # test needs a running copytool
3663 local f=$DIR/$tdir/$tfile
3664 local fid=$(copy_file /etc/passwd $f)
3667 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3668 wait_request_state $fid ARCHIVE SUCCEED
3673 wait_request_state $fid RESTORE SUCCEED
3675 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3678 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3682 run_test 222b "Changelog for implicit restore"
3685 # test needs a running copytool
3690 local f=$DIR/$tdir/$tfile
3691 make_archive $tdir/$tfile
3695 import_file $tdir/$tfile $f
3696 local fid=$(path2fid $f)
3699 wait_request_state $fid RESTORE STARTED
3701 wait_request_state $fid RESTORE CANCELED
3702 wait_request_state $fid CANCEL SUCCEED
3704 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3707 [[ $flags == $target ]] ||
3708 error "Changelog flag is $flags not $target"
3712 run_test 223a "Changelog for restore canceled (import case)"
3715 # test needs a running copytool
3720 local f=$DIR/$tdir/$tfile
3722 fid=$(make_large_for_progress $f)
3723 [ $? != 0 ] && skip "not enough free space" && return
3726 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3727 wait_request_state $fid ARCHIVE SUCCEED
3730 wait_request_state $fid RESTORE STARTED
3732 wait_request_state $fid RESTORE CANCELED
3733 wait_request_state $fid CANCEL SUCCEED
3735 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3738 [[ $flags == $target ]] ||
3739 error "Changelog flag is $flags not $target"
3743 run_test 223b "Changelog for restore canceled (release case)"
3746 # test needs a running copytool
3751 local f=$DIR/$tdir/$tfile
3752 local fid=$(copy_file /etc/passwd $f)
3755 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3756 wait_request_state $fid ARCHIVE SUCCEED
3759 wait_request_state $fid REMOVE SUCCEED
3761 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
3764 [[ $flags == $target ]] ||
3765 error "Changelog flag is $flags not $target"
3769 run_test 224 "Changelog for remove"
3772 # test needs a running copytool
3775 # test is not usable because remove request is too fast
3776 # so it is always finished before cancel can be done ...
3777 echo "Test disabled"
3782 local f=$DIR/$tdir/$tfile
3784 fid=$(make_large_for_progress $f)
3785 [ $? != 0 ] && skip "not enough free space" && return
3788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3789 wait_request_state $fid ARCHIVE SUCCEED
3791 # if cdt is on, it can serve too quickly the request
3796 wait_request_state $fid REMOVE CANCELED
3797 wait_request_state $fid CANCEL SUCCEED
3799 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3800 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
3801 tail -n 1 | awk '{print $5}')
3804 [[ $flags == $target ]] ||
3805 error "Changelog flag is $flags not $target"
3809 run_test 225 "Changelog for remove canceled"
3812 # test needs a running copytool
3817 local f1=$DIR/$tdir/$tfile-1
3818 local f2=$DIR/$tdir/$tfile-2
3819 local f3=$DIR/$tdir/$tfile-3
3820 local fid1=$(copy_file /etc/passwd $f1)
3821 local fid2=$(copy_file /etc/passwd $f2)
3822 copy_file /etc/passwd $f3
3825 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3826 wait_request_state $fid1 ARCHIVE SUCCEED
3828 $LFS hsm_archive $f2
3829 wait_request_state $fid2 ARCHIVE SUCCEED
3831 rm $f1 || error "rm $f1 failed"
3833 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
3836 [[ $flags == $target ]] ||
3837 error "Changelog flag is $flags not $target"
3839 mv $f3 $f2 || error "mv $f3 $f2 failed"
3841 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
3844 [[ $flags == $target ]] ||
3845 error "Changelog flag is $flags not $target"
3849 run_test 226 "changelog for last rm/mv with exiting archive"
3851 check_flags_changes() {
3859 $LFS hsm_set --$hsm_flag $f ||
3860 error "Cannot set $hsm_flag on $f"
3861 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3862 local seen=${#flags[*]}
3864 [[ $seen == $cnt ]] ||
3865 error "set $hsm_flag: Changelog events $seen != $cnt"
3866 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3867 error "set $hsm_flag: Changelog flags are "\
3868 "${flags[$((cnt - 1))]} not $target"
3870 $LFS hsm_clear --$hsm_flag $f ||
3871 error "Cannot clear $hsm_flag on $f"
3872 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
3875 [[ $cnt == $seen ]] ||
3876 error "clear $hsm_flag: Changelog events $seen != $cnt"
3878 [[ ${flags[$((cnt - 1))]} == $target ]] ||
3879 error "clear $hsm_flag: Changelog flag is "\
3880 "${flags[$((cnt - 1))]} not $target"
3884 # test needs a running copytool
3891 for i in norelease noarchive exists archived
3893 local f=$DIR/$tdir/$tfile-$i
3894 local fid=$(copy_file /etc/passwd $f)
3895 check_flags_changes $f $fid $i 0 1
3898 f=$DIR/$tdir/$tfile---lost
3899 fid=$(copy_file /etc/passwd $f)
3900 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3901 wait_request_state $fid ARCHIVE SUCCEED
3902 check_flags_changes $f $fid lost 3 1
3906 run_test 227 "changelog when explicit setting of HSM flags"
3909 # test needs a running copytool
3912 local fid=$(make_small_sync $DIR/$tfile)
3913 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
3914 wait_request_state $fid ARCHIVE SUCCEED
3916 $LFS hsm_release $DIR/$tfile
3917 check_hsm_flags $DIR/$tfile "0x0000000d"
3919 filefrag $DIR/$tfile | grep " 1 extent found" ||
3920 error "filefrag on released file must return only one extent"
3922 # only newer versions of cp detect sparse files by stat/FIEMAP
3924 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
3925 error "copying $DIR/$tfile"
3926 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
3928 $LFS hsm_release $DIR/$tfile
3929 check_hsm_flags $DIR/$tfile "0x0000000d"
3931 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
3933 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
3935 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
3936 error "comparing untarred $DIR/$tfile"
3938 rm -f $DIR/$tfile $DIR/$tfile.2 ||
3939 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
3942 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
3945 # test needs a running copytool
3949 local maxrequest=$(get_hsm_param max_requests)
3950 local rqcnt=$(($maxrequest * 3))
3954 for i in $(seq -w 1 $rqcnt); do
3956 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
3958 # we do it in 2 steps, so all requests arrive at the same time
3959 for i in $(seq -w 1 $rqcnt); do
3960 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
3965 while [[ $cnt != 0 || $wt != 0 ]]; do
3967 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3968 $HSM_PARAM.actions |\
3969 grep STARTED | grep -v CANCEL | wc -l")
3970 [[ $cnt -le $maxrequest ]] ||
3971 error "$cnt > $maxrequest too many started requests"
3972 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
3973 $HSM_PARAM.actions |\
3974 grep WAITING | wc -l")
3975 echo "max=$maxrequest started=$cnt waiting=$wt"
3980 run_test 250 "Coordinator max request"
3983 # test needs a running copytool
3987 local f=$DIR/$tdir/$tfile
3989 fid=$(make_large_for_cancel $f)
3990 [ $? != 0 ] && skip "not enough free space" && return
3993 # to have a short test
3994 local old_to=$(get_hsm_param active_request_timeout)
3995 set_hsm_param active_request_timeout 4
3996 # to be sure the cdt will wake up frequently so
3997 # it will be able to cancel the "old" request
3998 local old_loop=$(get_hsm_param loop_period)
3999 set_hsm_param loop_period 2
4002 # clear locks to avoid extra delay caused by flush/cancel
4003 # and thus prevent early copytool death to timeout.
4004 cancel_lru_locks osc
4006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4007 wait_request_state $fid ARCHIVE STARTED
4009 wait_request_state $fid ARCHIVE CANCELED
4011 set_hsm_param active_request_timeout $old_to
4012 set_hsm_param loop_period $old_loop
4016 run_test 251 "Coordinator request timeout"
4019 # the only way to test ondisk conf is to restart MDS ...
4020 echo "Stop coordinator and remove coordinator state at mount"
4023 # clean on disk conf set by default
4024 cdt_clear_mount_state
4025 cdt_check_state stopped
4027 # check cdt still off after umount/remount
4029 cdt_check_state stopped
4031 echo "Set coordinator start at mount, and start coordinator"
4032 cdt_set_mount_state enabled
4035 cdt_check_state enabled
4037 # check cdt still on after umount/remount
4039 cdt_check_state enabled
4041 # we are back to original state (cdt started at mount)
4043 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4046 local ai=$(get_hsm_param default_archive_id)
4047 local new=$((ai + 1))
4049 set_hsm_param default_archive_id $new -P
4051 local res=$(get_hsm_param default_archive_id)
4054 set_hsm_param default_archive_id "" "-P -d"
4056 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4058 run_test 301 "HSM tunnable are persistent"
4061 local ai=$(get_hsm_param default_archive_id)
4062 local new=$((ai + 1))
4067 set_hsm_param default_archive_id $new -P
4070 for mdtno in $(seq 1 $MDSCOUNT); do
4075 cdt_check_state enabled
4077 local res=$(get_hsm_param default_archive_id)
4080 set_hsm_param default_archive_id "" "-P -d"
4082 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4084 run_test 302 "HSM tunnable are persistent when CDT is off"
4087 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4093 local dir_mdt0=$DIR/$tdir/mdt0
4094 local dir_mdt1=$DIR/$tdir/mdt1
4096 # create 1 dir per MDT
4097 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4098 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4100 # create 1 file in each MDT
4101 local fid1=$(make_small $dir_mdt0/$tfile)
4102 local fid2=$(make_small $dir_mdt1/$tfile)
4104 # check that hsm request on mdt0 is sent to the right MDS
4105 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4106 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4107 echo "archive successful on mdt0"
4109 # check that hsm request on mdt1 is sent to the right MDS
4110 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4111 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4112 echo "archive successful on mdt1"
4115 # clean test files and directories
4116 rm -rf $dir_mdt0 $dir_mdt1
4118 run_test 400 "Single request is sent to the right MDT"
4121 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4127 local dir_mdt0=$DIR/$tdir/mdt0
4128 local dir_mdt1=$DIR/$tdir/mdt1
4130 # create 1 dir per MDT
4131 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4132 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4134 # create 1 file in each MDT
4135 local fid1=$(make_small $dir_mdt0/$tfile)
4136 local fid2=$(make_small $dir_mdt1/$tfile)
4138 # check that compound requests are shunt to the rights MDTs
4139 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4140 error "lfs hsm_archive"
4141 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4142 echo "archive successful on mdt0"
4143 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4144 echo "archive successful on mdt1"
4147 # clean test files and directories
4148 rm -rf $dir_mdt0 $dir_mdt1
4150 run_test 401 "Compound requests split and sent to their respective MDTs"
4152 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4157 local node=$(facet_active_host $facet)
4159 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4160 awk '{print $4}'); do
4161 echo "$3 $mdc on $node"
4162 do_facet $facet "$LCTL --device $mdc $state" || return 1
4167 # make sure there is no running copytool
4170 # deactivate all mdc on agent1
4171 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4173 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4175 check_agent_unregistered "uuid" # match any agent
4177 # no expected running copytool
4178 search_copytools $agent && error "Copytool start should have failed"
4181 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4183 run_test 402 "Copytool start fails if all MDTs are inactive"
4186 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4188 # make sure there is no running copytool
4191 local agent=$(facet_active_host $SINGLEAGT)
4192 local uuid=$(do_rpc_nodes $agent get_client_uuid | cut -d' ' -f2)
4194 # deactivate all mdc for MDT0001
4195 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4198 # check the agent is registered on MDT0000, and not on MDT0001
4199 check_agent_registered_by_mdt $uuid 0
4200 check_agent_unregistered_by_mdt $uuid 1
4202 # check running copytool process
4203 search_copytools $agent || error "No running copytools on $agent"
4205 # reactivate all mdc for MDT0001
4206 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4208 # make sure the copytool is now registered to all MDTs
4209 check_agent_registered $uuid
4213 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4216 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4220 # create files on both MDT0000 and MDT0001
4223 local dir_mdt0=$DIR/$tdir/mdt0
4224 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4226 # create 1 file on mdt0
4227 local fid1=$(make_small $dir_mdt0/$tfile)
4229 # deactivate all mdc for MDT0001
4230 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4232 # send an HSM request for files in MDT0000
4233 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4235 # check for completion of files in MDT0000
4236 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4237 echo "archive successful on mdt0"
4239 # reactivate all mdc for MDT0001
4240 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4243 # clean test files and directories
4246 run_test 404 "Inactive MDT does not block requests for active MDTs"
4249 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4255 local striped_dir=$DIR/$tdir/striped_dir
4257 # create striped dir on all of MDTs
4258 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4260 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4261 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4262 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4263 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4265 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4266 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4267 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4268 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4270 # check that compound requests are shunt to the rights MDTs
4271 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4272 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4273 error "lfs hsm_archive"
4275 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4276 echo "archive successful on $fid1"
4277 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4278 echo "archive successful on $fid2"
4279 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4280 echo "archive successful on $fid3"
4281 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4282 echo "archive successful on $fid4"
4284 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4285 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4286 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4287 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4289 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4290 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4291 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4292 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4296 run_test 405 "archive and release under striped directory"
4300 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4301 skip "HSM migrate is not supported" && return
4303 # Stop the existing copytool
4306 test_mkdir -p $DIR/$tdir
4307 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4309 run_test 500 "various LLAPI HSM tests"
4314 check_and_cleanup_lustre