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 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
109 # The test only support up to 10 MDTs
110 MDT_PREFIX="mdt.$FSNAME-MDT000"
111 HSM_PARAM="${MDT_PREFIX}0.hsm"
113 # archive is purged at copytool setup
114 HSM_ARCHIVE_PURGE=true
116 # Don't allow copytool error upon start/setup
117 HSMTOOL_NOERROR=false
120 # Get the backend root path for the given agent facet.
123 local dev=AGTDEV$(facet_number $facet)
128 # Stop copytool and unregister an existing changelog user.
130 copytool_monitor_cleanup
133 cdt_set_sanity_policy
138 # get MDT device for each mdc
139 for mdtno in $(seq 1 $MDSCOUNT); do
140 local idx=$(($mdtno - 1))
141 MDT[$idx]=$($LCTL get_param -n \
142 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
143 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
148 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
149 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
153 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
155 echo "Killing existing copytools on $hosts"
156 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
160 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
161 local wait_timeout=200
162 local wait_start=$SECONDS
163 local wait_end=$((wait_start + wait_timeout))
165 while ((SECONDS < wait_end)); do
167 if ! search_copytools $hosts; then
168 echo "copytools stopped in $((SECONDS - wait_start))s"
172 echo "copytools still running on $hosts"
175 # try to dump Copytool's stack
176 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
177 "echo t >/proc/sysrq-trigger"
179 echo "copytools failed to stop in ${wait_timeout}s"
184 copytool_monitor_setup() {
185 local facet=${1:-$SINGLEAGT}
186 local agent=$(facet_active_host $facet)
188 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
189 local test_dir=$(do_node $agent "$cmd") ||
190 error "Failed to create tempdir on $agent"
191 export HSMTOOL_MONITOR_DIR=$test_dir
193 # Create the fifo and a monitor (cat dies when copytool dies)
194 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
195 error "failed to create copytool fifo on $agent"
196 cmd="cat $test_dir/fifo > $test_dir/events &"
197 cmd+=" echo \\\$! > $test_dir/monitor_pid"
199 if [[ $PDSH == *Rmrsh* ]]; then
200 # This is required for pdsh -Rmrsh and its handling of remote
202 # Regular ssh and pdsh -Rssh work fine without this
203 # backgrounded subshell nonsense.
204 (do_node $agent "$cmd") &
205 export HSMTOOL_MONITOR_PDSH=$!
207 # Slightly racy, but just making a best-effort to catch obvious
210 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
211 error "Failed to start copytool monitor on $agent"
213 do_node $agent "$cmd"
215 error "Failed to start copytool monitor on $agent"
220 copytool_monitor_cleanup() {
221 local facet=${1:-$SINGLEAGT}
222 local agent=$(facet_active_host $facet)
224 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
225 # Should die when the copytool dies, but just in case.
226 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
227 cmd+=" 2>/dev/null || true"
228 do_node $agent "$cmd"
229 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
230 export HSMTOOL_MONITOR_DIR=
233 # The pdsh should die on its own when the monitor dies. Just
234 # in case, though, try to clean up to avoid any cruft.
235 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
236 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
237 export HSMTOOL_MONITOR_PDSH=
242 local facet=${1:-$SINGLEAGT}
243 # Use MOUNT2 by default if defined
244 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
246 local hsm_root=${4:-$(copytool_device $facet)}
247 local agent=$(facet_active_host $facet)
249 if [[ -z "$arc_id" ]] &&
250 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
251 echo "Only wakeup running copytool $facet on $agent"
255 if $HSM_ARCHIVE_PURGE; then
256 echo "Purging archive on $agent"
257 do_facet $facet "rm -rf $hsm_root/*"
260 echo "Starting copytool $facet on $agent"
261 do_facet $facet "mkdir -p $hsm_root" || error "mkdir '$hsm_root' failed"
262 # bandwidth is limited to 1MB/s so the copy time is known and
263 # independent of hardware
264 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root $hsm_root"
265 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
266 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
267 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
268 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
269 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
270 cmd+=" --bandwidth 1 $lustre_mntpnt"
272 # Redirect the standard output and error to a log file which
273 # can be uploaded to Maloo.
274 local prefix=$TESTLOG_PREFIX
275 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
276 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
278 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
279 if [[ $? != 0 ]]; then
280 [[ $HSMTOOL_NOERROR == true ]] ||
281 error "start copytool $facet on $agent failed"
282 echo "start copytool $facet on $agent failed"
288 get_copytool_event_log() {
289 local facet=${1:-$SINGLEAGT}
290 local agent=$(facet_active_host $facet)
292 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
293 error "Can't get event log: No monitor directory!"
295 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
296 error "Could not collect event log from $agent"
301 local agt_facet=$SINGLEAGT
302 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
303 local hsm_root=$(copytool_device $agt_facet)
309 kill_copytools $agt_hosts
310 wait_copytools $agt_hosts || error "copytools failed to stop"
312 # Clean all CDTs orphans requests from previous tests that
313 # would otherwise need to timeout to clear.
314 for ((i = 0; i < MDSCOUNT; i++)); do
316 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
317 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
319 # Skip already stopping or stopped CDTs.
320 [[ "${state[$i]}" =~ ^stop ]] && continue
322 do_facet $facet "$LCTL set_param $param=shutdown"
325 for ((i = 0; i < MDSCOUNT; i++)); do
326 # Only check and restore CDTs that we stopped in the first loop.
327 [[ "${state[$i]}" =~ ^stop ]] && continue
330 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
332 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
333 error "$facet CDT state is not stopped"
335 # Restore old CDT state.
336 do_facet $facet "$LCTL set_param $param=${state[$i]}"
339 for ((i = 0; i < MDSCOUNT; i++)); do
340 # Only check CDTs that we stopped in the first loop.
341 [[ "${state[$i]}" =~ ^stop ]] && continue
344 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
346 # Check that the old CDT state was restored.
347 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
348 20 || error "$facet CDT state is not '${state[$i]}'"
351 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
352 do_facet $agt_facet "rm -rf $hsm_root/*"
357 local agents=${1:-$(facet_active_host $SINGLEAGT)}
359 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
360 echo "Copytool is suspended on $agents"
363 copytool_remove_backend() {
365 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
366 echo "Remove from backend: $fid = $be"
367 do_facet $SINGLEAGT rm -f $be
371 do_facet $SINGLEAGT \
372 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
373 --import $1 $2 $MOUNT" ||
374 error "import of $1 to $2 failed"
378 local file=$HSM_ARCHIVE/$1
379 do_facet $SINGLEAGT mkdir -p $(dirname $file)
380 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
381 file_creation_failure dd $file $?
385 local file=$HSM_ARCHIVE/$2
386 do_facet $SINGLEAGT mkdir -p $(dirname $file)
387 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
396 if [[ "$value" != "" ]]; then
399 for mdtno in $(seq 1 $MDSCOUNT); do
400 local idx=$(($mdtno - 1))
401 local facet=mds${mdtno}
402 # if $arg include -P option, run 1 set_param per MDT on the MGS
403 # else, run set_param on each MDT
404 [[ $arg = *"-P"* ]] && facet=mgs
405 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
406 [[ $? != 0 ]] && rc=1
416 for mdtno in $(seq 1 $MDSCOUNT); do
417 local idx=$(($mdtno - 1))
418 wait_result mds${mdtno} \
419 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
421 error "$key state is not '$target' on mds${mdtno}"
428 for mdtno in $(seq 1 $MDSCOUNT); do
429 local idx=$(($mdtno - 1))
430 local cl_user=$(do_facet mds${mdtno} $LCTL \
431 --device ${MDT[$idx]} \
432 changelog_register -n)
434 do_facet mds${mdtno} lctl set_param \
435 mdd.${MDT[$idx]}.changelog_mask="+hsm"
436 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
440 changelog_cleanup() {
442 for mdtno in $(seq 1 $MDSCOUNT); do
443 local idx=$(($mdtno - 1))
444 [[ -z ${CL_USERS[$idx]} ]] && continue
445 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
446 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
447 changelog_deregister ${CL_USERS[$idx]}
452 changelog_get_flags() {
457 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
462 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
470 mdts_set_param "$opt -n" "hsm.$param" "$value"
477 mdts_set_param "" hsm_control "$cmd"
478 mdts_check_param hsm_control "$target" 10
481 cdt_set_sanity_policy() {
482 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
485 mdts_set_param "" hsm.policy "+NRA"
486 mdts_set_param "" hsm.policy "-NBR"
487 CDT_POLICY_HAD_CHANGED=
492 mdts_set_param "" hsm.policy "+NRA"
493 CDT_POLICY_HAD_CHANGED=true
496 cdt_clear_no_retry() {
497 mdts_set_param "" hsm.policy "-NRA"
498 CDT_POLICY_HAD_CHANGED=true
501 cdt_set_non_blocking_restore() {
502 mdts_set_param "" hsm.policy "+NBR"
503 CDT_POLICY_HAD_CHANGED=true
506 cdt_clear_non_blocking_restore() {
507 mdts_set_param "" hsm.policy "-NBR"
508 CDT_POLICY_HAD_CHANGED=true
511 cdt_clear_mount_state() {
512 mdts_set_param "-P -d" hsm_control ""
515 cdt_set_mount_state() {
516 mdts_set_param "-P" hsm_control "$1"
517 # set_param -P is asynchronous operation and could race with set_param.
518 # In such case configs could be retrieved and applied at mgc after
519 # set_param -P completion. Sleep here to avoid race with set_param.
520 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
521 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
522 # and 10 seconds to retrieve config from server.
527 mdts_check_param hsm_control "$1" 20
531 set_test_state disabled disabled
535 set_test_state enabled enabled
539 set_test_state shutdown stopped
543 set_test_state purge enabled
549 cdt_set_sanity_policy
553 local client_count=$1
554 if [[ $CLIENTCOUNT -lt $client_count ]]; then
555 skip "Need $client_count or more clients, have $CLIENTCOUNT"
562 $LFS path2fid $1 | tr -d '[]'
563 return ${PIPESTATUS[0]}
571 if [[ $u == "user" ]]; then
572 st=$($RUNAS $LFS hsm_state $f)
575 st=$($LFS hsm_state $f)
578 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
580 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
584 get_hsm_archive_id() {
587 st=$($LFS hsm_state $f)
588 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
590 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
599 local st=$(get_hsm_flags $f)
600 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
603 check_hsm_flags_user() {
607 local st=$(get_hsm_flags $f user)
608 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
611 file_creation_failure() {
616 df $MOUNT $MOUNT2 >&2
617 error "cannot create $f with $cmd, status=$err"
629 if [[ "$3" != 1 ]]; then
633 cp $1 $f || file_creation_failure cp $f $?
635 path2fid $f || error "cannot get fid on $f"
639 local file2=${1/$DIR/$DIR2}
640 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
641 file_creation_failure dd $file2 $?
643 path2fid $1 || error "cannot get fid on $1"
647 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
648 file_creation_failure dd $1 $?
649 path2fid $1 || error "cannot get fid on $1"
652 cleanup_large_files() {
653 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
655 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
658 check_enough_free_space() {
661 local need=$((nb * unit /1024))
662 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
663 (( $need >= $free )) && return 1
667 make_large_for_striping() {
668 local file2=${1/$DIR/$DIR2}
669 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
673 check_enough_free_space 5 $sz
674 [ $? != 0 ] && return $?
676 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
677 file_creation_failure dd $file2 $?
679 path2fid $1 || error "cannot get fid on $1"
682 make_large_for_progress() {
683 local file2=${1/$DIR/$DIR2}
687 check_enough_free_space 39 1000000
688 [ $? != 0 ] && return $?
690 # big file is large enough, so copy time is > 30s
691 # so copytool make 1 progress
692 # size is not a multiple of 1M to avoid stripe
694 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
695 file_creation_failure dd $file2 $?
697 path2fid $1 || error "cannot get fid on $1"
700 make_large_for_progress_aligned() {
701 local file2=${1/$DIR/$DIR2}
705 check_enough_free_space 33 1048576
706 [ $? != 0 ] && return $?
708 # big file is large enough, so copy time is > 30s
709 # so copytool make 1 progress
710 # size is a multiple of 1M to have stripe
712 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
713 file_creation_failure dd $file2 $?
714 path2fid $1 || error "cannot get fid on $1"
717 make_large_for_cancel() {
718 local file2=${1/$DIR/$DIR2}
722 check_enough_free_space 103 1048576
723 [ $? != 0 ] && return $?
725 # Copy timeout is 100s. 105MB => 105s
726 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
727 file_creation_failure dd $file2 $?
728 path2fid $1 || error "cannot get fid on $1"
734 wait_update --verbose $(facet_active_host $facet) "$@"
737 wait_request_state() {
741 # 4th arg (mdt index) is optional
743 local mds=mds$(($mdtidx + 1))
745 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
746 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
748 wait_result $mds "$cmd" $state 200 ||
749 error "request on $fid is not $state on $mds"
752 get_request_state() {
756 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
757 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
760 get_request_count() {
764 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
765 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
772 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
773 [[ -n $fid ]] && cmd+=" | grep '$fid'"
774 cmd+=" | egrep 'WAITING|STARTED'"
776 wait_result $SINGLEMDS "$cmd" "" $timeout ||
777 error "requests did not complete"
780 wait_for_grace_delay() {
781 local val=$(get_hsm_param grace_delay)
788 # python2.6 in EL6 includes an internal json module
789 local json_parser='import json; import fileinput;'
790 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
791 json_parser+='json.loads([line for line in '
792 json_parser+='fileinput.input()][0]).items()])'
794 echo $raw_event | python -c "$json_parser"
797 # populate MDT device array
803 # cleanup from previous bad setup
806 # for recovery tests, coordinator needs to be started at mount
808 # the lustre conf must be without hsm on (like for sanity.sh)
809 echo "Set HSM on and start"
810 cdt_set_mount_state enabled
811 cdt_check_state enabled
813 echo "Start copytool"
816 echo "Set sanity-hsm HSM policy"
817 cdt_set_sanity_policy
819 # finished requests are quickly removed from list
820 set_hsm_param grace_delay 10
826 local f=$DIR/$tdir/$tfile
830 check_hsm_flags_user $f "0x00000000"
832 $RUNAS $LFS hsm_set --norelease $f ||
833 error "user could not change hsm flags"
834 check_hsm_flags_user $f "0x00000010"
836 $RUNAS $LFS hsm_clear --norelease $f ||
837 error "user could not clear hsm flags"
838 check_hsm_flags_user $f "0x00000000"
840 # User could not change those flags...
841 $RUNAS $LFS hsm_set --exists $f &&
842 error "user should not set this flag"
843 check_hsm_flags_user $f "0x00000000"
846 $LFS hsm_set --exists $f ||
847 error "root could not change hsm flags"
848 check_hsm_flags_user $f "0x00000001"
850 $LFS hsm_clear --exists $f ||
851 error "root could not clear hsm state"
852 check_hsm_flags_user $f "0x00000000"
855 run_test 1 "lfs hsm flags root/non-root access"
859 local f=$DIR/$tdir/$tfile
860 local fid=$(make_small $f)
862 $LFS hsm_archive $f || error "could not archive file"
863 wait_request_state $fid ARCHIVE SUCCEED
865 # Release and check states
866 $LFS hsm_release $f || error "could not release file"
867 echo -n "Verifying released state: "
868 check_hsm_flags $f "0x0000000d"
870 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
872 run_test 1a "mmap & cat a HSM released file"
876 local f=$DIR/$tdir/$tfile
878 # New files are not dirty
879 check_hsm_flags $f "0x00000000"
881 # For test, we simulate an archived file.
882 $LFS hsm_set --exists $f || error "user could not change hsm flags"
883 check_hsm_flags $f "0x00000001"
885 # chmod do not put the file dirty
886 chmod 600 $f || error "could not chmod test file"
887 check_hsm_flags $f "0x00000001"
889 # chown do not put the file dirty
890 chown $RUNAS_ID $f || error "could not chown test file"
891 check_hsm_flags $f "0x00000001"
893 # truncate put the file dirty
894 $TRUNCATE $f 1 || error "could not truncate test file"
895 check_hsm_flags $f "0x00000003"
897 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
898 check_hsm_flags $f "0x00000001"
900 run_test 2 "Check file dirtyness when doing setattr"
906 # New files are not dirty
908 check_hsm_flags $f "0x00000000"
910 # For test, we simulate an archived file.
911 $LFS hsm_set --exists $f ||
912 error "user could not change hsm flags"
913 check_hsm_flags $f "0x00000001"
915 # Reading a file, does not set dirty
916 cat $f > /dev/null || error "could not read file"
917 check_hsm_flags $f "0x00000001"
919 # Open for write without modifying data, does not set dirty
920 openfile -f O_WRONLY $f || error "could not open test file"
921 check_hsm_flags $f "0x00000001"
923 # Append to a file sets it dirty
924 cp -p /etc/passwd $f.append || error "could not create file"
925 $LFS hsm_set --exists $f.append ||
926 error "user could not change hsm flags"
927 dd if=/etc/passwd of=$f.append bs=1 count=3\
928 conv=notrunc oflag=append status=noxfer ||
929 file_creation_failure dd $f.append $?
930 check_hsm_flags $f.append "0x00000003"
932 # Modify a file sets it dirty
933 cp -p /etc/passwd $f.modify || error "could not create file"
934 $LFS hsm_set --exists $f.modify ||
935 error "user could not change hsm flags"
936 dd if=/dev/zero of=$f.modify bs=1 count=3\
937 conv=notrunc status=noxfer ||
938 file_creation_failure dd $f.modify $?
939 check_hsm_flags $f.modify "0x00000003"
941 # Open O_TRUNC sets dirty
942 cp -p /etc/passwd $f.trunc || error "could not create file"
943 $LFS hsm_set --exists $f.trunc ||
944 error "user could not change hsm flags"
945 cp /etc/group $f.trunc || error "could not override a file"
946 check_hsm_flags $f.trunc "0x00000003"
948 # Mmapped a file sets dirty
949 cp -p /etc/passwd $f.mmap || error "could not create file"
950 $LFS hsm_set --exists $f.mmap ||
951 error "user could not change hsm flags"
952 multiop $f.mmap OSMWUc || error "could not mmap a file"
953 check_hsm_flags $f.mmap "0x00000003"
955 run_test 3 "Check file dirtyness when opening for write"
959 local f=$DIR/$tdir/$tfile
960 local fid=$(make_small $f)
963 local st=$(get_request_state $fid CANCEL)
964 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
966 run_test 4 "Useless cancel must not be registered"
969 # test needs a running copytool
973 local f=$DIR/$tdir/$tfile
974 local fid=$(copy_file /etc/passwd $f)
976 wait_request_state $fid ARCHIVE SUCCEED
978 check_hsm_flags $f "0x00000009"
982 run_test 8 "Test default archive number"
986 local f=$DIR/$tdir/$tfile
987 local fid=$(copy_file /etc/passwd $f)
988 # we do not use the default one to be sure
989 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
991 copytool_setup $SINGLEAGT $MOUNT $new_an
992 $LFS hsm_archive --archive $new_an $f
993 wait_request_state $fid ARCHIVE SUCCEED
995 check_hsm_flags $f "0x00000009"
999 run_test 9 "Use of explicit archive number, with dedicated copytool"
1002 needclients 3 || return 0
1008 copytool_cleanup $(comma_list $(agts_nodes))
1010 # start all of the copytools
1011 for n in $(seq $AGTCOUNT); do
1012 copytool_setup agt$n
1015 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1018 for n in $(seq $AGTCOUNT); do
1019 file=$DIR/$tdir/$tfile.$n
1020 fid=$(make_small $file)
1022 $LFS hsm_archive $file || error "could not archive file $file"
1023 wait_request_state $fid ARCHIVE SUCCEED
1024 check_hsm_flags $file "0x00000009"
1028 copytool_cleanup $(comma_list $(agts_nodes))
1030 run_test 9a "Multiple remote agents"
1033 # test needs a running copytool
1036 mkdir -p $DIR/$tdir/d1
1037 local f=$DIR/$tdir/$tfile
1038 local fid=$(copy_file /etc/hosts $f)
1039 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1040 error "hsm_archive failed"
1041 wait_request_state $fid ARCHIVE SUCCEED
1043 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1044 error "fid $fid not in archive $HSM_ARCHIVE"
1045 echo "Verifying content"
1046 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1047 echo "Verifying hsm state "
1048 check_hsm_flags $f "0x00000009"
1050 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1051 local st=$(get_hsm_archive_id $f)
1052 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1053 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1058 run_test 10a "Archive a file"
1061 # test needs a running copytool
1065 local f=$DIR/$tdir/$tfile
1066 local fid=$(copy_file /etc/hosts $f)
1067 $LFS hsm_archive $f || error "archive request failed"
1068 wait_request_state $fid ARCHIVE SUCCEED
1070 $LFS hsm_archive $f || error "archive of non dirty file failed"
1071 local cnt=$(get_request_count $fid ARCHIVE)
1072 [[ "$cnt" == "1" ]] ||
1073 error "archive of non dirty file must not make a request"
1077 run_test 10b "Archive of non dirty file must work without doing request"
1080 # test needs a running copytool
1084 local f=$DIR/$tdir/$tfile
1085 local fid=$(copy_file /etc/hosts $f)
1086 $LFS hsm_set --noarchive $f
1087 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1091 run_test 10c "Check forbidden archive"
1094 # test needs a running copytool
1098 local f=$DIR/$tdir/$tfile
1099 local fid=$(copy_file /etc/hosts $f)
1100 $LFS hsm_archive $f || error "cannot archive $f"
1101 wait_request_state $fid ARCHIVE SUCCEED
1103 local ar=$(get_hsm_archive_id $f)
1104 local dflt=$(get_hsm_param default_archive_id)
1105 [[ $ar == $dflt ]] ||
1106 error "archived file is not on default archive: $ar != $dflt"
1110 run_test 10d "Archive a file on the default archive id"
1114 copy2archive /etc/hosts $tdir/$tfile
1115 local f=$DIR/$tdir/$tfile
1117 import_file $tdir/$tfile $f
1118 echo -n "Verifying released state: "
1119 check_hsm_flags $f "0x0000000d"
1121 local LSZ=$(stat -c "%s" $f)
1122 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1124 echo "Verifying imported size $LSZ=$ASZ"
1125 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1126 echo -n "Verifying released pattern: "
1127 local PTRN=$($GETSTRIPE -L $f)
1129 [[ $PTRN == 80000001 ]] || error "Is not released"
1130 local fid=$(path2fid $f)
1131 echo "Verifying new fid $fid in archive"
1133 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1134 error "fid $fid not in archive $HSM_ARCHIVE"
1136 run_test 11a "Import a file"
1139 # test needs a running copytool
1143 local f=$DIR/$tdir/$tfile
1144 local fid=$(copy_file /etc/hosts $f)
1145 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1146 error "hsm_archive failed"
1147 wait_request_state $fid ARCHIVE SUCCEED
1149 local FILE_HASH=$(md5sum $f)
1154 echo "$FILE_HASH" | md5sum -c
1156 [[ $? -eq 0 ]] || error "Restored file differs"
1160 run_test 11b "Import a deleted file using its FID"
1163 # test needs a running copytool
1167 copy2archive /etc/hosts $tdir/$tfile
1169 local f=$DIR/$tdir/$tfile
1170 import_file $tdir/$tfile $f
1171 local f2=$DIR2/$tdir/$tfile
1172 echo "Verifying released state: "
1173 check_hsm_flags $f2 "0x0000000d"
1175 local fid=$(path2fid $f2)
1176 $LFS hsm_restore $f2
1177 wait_request_state $fid RESTORE SUCCEED
1179 echo "Verifying file state: "
1180 check_hsm_flags $f2 "0x00000009"
1182 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1184 [[ $? -eq 0 ]] || error "Restored file differs"
1188 run_test 12a "Restore an imported file explicitly"
1191 # test needs a running copytool
1195 copy2archive /etc/hosts $tdir/$tfile
1197 local f=$DIR/$tdir/$tfile
1198 import_file $tdir/$tfile $f
1199 echo "Verifying released state: "
1200 check_hsm_flags $f "0x0000000d"
1202 cat $f > /dev/null || error "File read failed"
1204 echo "Verifying file state after restore: "
1205 check_hsm_flags $f "0x00000009"
1207 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1209 [[ $? -eq 0 ]] || error "Restored file differs"
1213 run_test 12b "Restore an imported file implicitly"
1216 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1218 # test needs a running copytool
1222 local f=$DIR/$tdir/$tfile
1223 $LFS setstripe -c 2 $f
1225 fid=$(make_large_for_striping $f)
1226 [ $? != 0 ] && skip "not enough free space" && return
1228 local FILE_CRC=$(md5sum $f)
1230 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1231 wait_request_state $fid ARCHIVE SUCCEED
1232 $LFS hsm_release $f || error "release $f failed"
1234 echo "$FILE_CRC" | md5sum -c
1236 [[ $? -eq 0 ]] || error "Restored file differs"
1240 run_test 12c "Restore a file with stripe of 2"
1243 # test needs a running copytool
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_restore $f || error "restore of non archived file failed"
1251 local cnt=$(get_request_count $fid RESTORE)
1252 [[ "$cnt" == "0" ]] ||
1253 error "restore non archived must not make a request"
1254 $LFS hsm_archive $f ||
1255 error "archive request failed"
1256 wait_request_state $fid ARCHIVE SUCCEED
1257 $LFS hsm_restore $f ||
1258 error "restore of non released file failed"
1259 local cnt=$(get_request_count $fid RESTORE)
1260 [[ "$cnt" == "0" ]] ||
1261 error "restore a non dirty file must not make a request"
1265 run_test 12d "Restore of a non archived, non released file must work"\
1266 " without doing request"
1269 # test needs a running copytool
1272 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1273 local f=$DIR/$tdir/$tfile
1274 local fid=$(copy_file /etc/hosts $f)
1275 $LFS hsm_archive $f || error "archive request failed"
1276 wait_request_state $fid ARCHIVE SUCCEED
1279 cat /etc/hosts >> $f
1283 $LFS hsm_restore $f && error "restore a dirty file must fail"
1287 run_test 12e "Check forbidden restore"
1290 # test needs a running copytool
1294 local f=$DIR/$tdir/$tfile
1295 local fid=$(copy_file /etc/hosts $f)
1297 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1298 wait_request_state $fid ARCHIVE SUCCEED
1299 $LFS hsm_release $f || error "release of $f failed"
1301 wait_request_state $fid RESTORE SUCCEED
1303 echo -n "Verifying file state: "
1304 check_hsm_flags $f "0x00000009"
1306 diff -q /etc/hosts $f
1308 [[ $? -eq 0 ]] || error "Restored file differs"
1312 run_test 12f "Restore a released file explicitly"
1315 # test needs a running copytool
1319 local f=$DIR/$tdir/$tfile
1320 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1323 wait_request_state $fid ARCHIVE SUCCEED
1324 $LFS hsm_release $f || error "release of $f failed"
1326 diff -q /etc/hosts $f
1329 # we check we had a restore done
1330 wait_request_state $fid RESTORE SUCCEED
1332 [[ $st -eq 0 ]] || error "Restored file differs"
1336 run_test 12g "Restore a released file implicitly"
1339 needclients 2 || return 0
1341 # test needs a running copytool
1345 local f=$DIR/$tdir/$tfile
1346 local fid=$(copy_file /etc/hosts $f)
1348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1349 wait_request_state $fid ARCHIVE SUCCEED
1350 $LFS hsm_release $f || error "release of $f failed"
1352 do_node $CLIENT2 diff -q /etc/hosts $f
1355 # we check we had a restore done
1356 wait_request_state $fid RESTORE SUCCEED
1358 [[ $st -eq 0 ]] || error "Restored file differs"
1362 run_test 12h "Restore a released file implicitly from a second node"
1365 # test needs a running copytool
1369 local f=$DIR/$tdir/$tfile
1370 local fid=$(copy_file /etc/passwd $f)
1371 $LFS hsm_archive $f || error "archive of $f failed"
1372 wait_request_state $fid ARCHIVE SUCCEED
1374 $LFS hsm_release $f || error "release of $f failed"
1378 [[ $? -eq 0 ]] || error "Restored file differs"
1382 run_test 12m "Archive/release/implicit restore"
1385 # test needs a running copytool
1389 copy2archive /etc/hosts $tdir/$tfile
1391 local f=$DIR/$tdir/$tfile
1392 import_file $tdir/$tfile $f
1394 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1395 error "Restored file differs"
1397 $LFS hsm_release $f || error "release of $f failed"
1401 run_test 12n "Import/implicit restore/release"
1404 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(copy_file /etc/hosts $f)
1411 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1412 wait_request_state $fid ARCHIVE SUCCEED
1413 $LFS hsm_release $f || error "release of $f failed"
1415 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1416 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1418 # set no retry action mode
1421 diff -q /etc/hosts $f
1424 # we check we had a restore failure
1425 wait_request_state $fid RESTORE FAILED
1427 [[ $st -eq 0 ]] && error "Restore must fail"
1429 # remove no retry action mode
1432 # check file is still released
1433 check_hsm_flags $f "0x0000000d"
1435 # retry w/o failure injection
1436 do_facet $SINGLEMDS lctl set_param fail_loc=0
1438 # to be sure previous RESTORE result is gone
1440 wait_for_grace_delay
1442 diff -q /etc/hosts $f
1445 # we check we had a restore done
1446 wait_request_state $fid RESTORE SUCCEED
1448 [[ $st -eq 0 ]] || error "Restored file differs"
1452 run_test 12o "Layout-swap failure during Restore leaves file released"
1455 # test needs a running copytool
1459 local f=$DIR/$tdir/$tfile
1460 local fid=$(copy_file /etc/hosts $f)
1462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1463 wait_request_state $fid ARCHIVE SUCCEED
1464 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1465 $LFS hsm_release $f || error "cannot release $f"
1466 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1467 $LFS hsm_release $f || error "cannot release $f"
1468 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1472 run_test 12p "implicit restore of a file on copytool mount point"
1474 cleanup_test_12q() {
1476 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1477 error "cannot umount $MOUNT3 on $SINGLEAGT"
1481 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1482 skip "need MDS version at least 2.7.58" && return 0
1484 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1485 error "cannot mount $MOUNT3 on $SINGLEAGT"
1487 trap cleanup_test_12q EXIT
1489 # test needs a running copytool
1490 copytool_setup $SINGLEAGT $MOUNT3
1493 local f=$DIR/$tdir/$tfile
1494 local f2=$DIR2/$tdir/$tfile
1495 local fid=$(make_small $f)
1496 local orig_size=$(stat -c "%s" $f)
1498 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1499 wait_request_state $fid ARCHIVE SUCCEED
1501 $LFS hsm_release $f || error "could not release file"
1502 check_hsm_flags $f "0x0000000d"
1505 wait_copytools || error "copytool failed to stop"
1507 cat $f > /dev/null &
1509 # wait a bit to allow implicit restore request to be handled.
1510 # if not, next stat would also block on layout-lock.
1513 local size=$(stat -c "%s" $f2)
1514 [ $size -eq $orig_size ] ||
1515 error "$f2: wrong size after archive: $size != $orig_size"
1517 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1521 size=$(stat -c "%s" $f)
1522 [ $size -eq $orig_size ] ||
1523 error "$f: wrong size after restore: $size != $orig_size"
1525 size=$(stat -c "%s" $f2)
1526 [ $size -eq $orig_size ] ||
1527 error "$f2: wrong size after restore: $size != $orig_size"
1531 size=$(stat -c "%s" $f)
1533 error "$f: wrong size after overwrite: $size != 0"
1535 size=$(stat -c "%s" $f2)
1537 error "$f2: wrong size after overwrite: $size != 0"
1540 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1541 error "cannot umount $MOUNT3 on $SINGLEAGT"
1543 run_test 12q "file attributes are refreshed after restore"
1546 # test needs a running copytool
1549 local ARC_SUBDIR="import.orig"
1553 # populate directory to be imported
1554 for d in $(seq 1 10); do
1555 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1556 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1557 for f in $(seq 1 10); do
1558 CURR_FILE="$CURR_DIR/$tfile.$f"
1559 # write file-specific data
1560 do_facet $SINGLEAGT \
1561 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1562 "file=$CURR_FILE > $CURR_FILE"
1566 import_file "$ARC_SUBDIR" $DIR/$tdir
1567 # diff lustre content and origin (triggers file restoration)
1568 # there must be 10x10 identical files, and no difference
1569 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1570 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1571 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1572 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1574 [ $cnt_diff -eq 0 ] ||
1575 error "$cnt_diff imported files differ from read data"
1576 [ $cnt_ok -eq 100 ] ||
1577 error "not enough identical files ($cnt_ok != 100)"
1581 run_test 13 "Recursively import and restore a directory"
1584 # test needs a running copytool
1589 local f=$DIR/$tdir/$tfile
1590 local fid=$(make_small $f)
1591 local sum=$(md5sum $f | awk '{print $1}')
1592 $LFS hsm_archive $f || error "could not archive file"
1593 wait_request_state $fid ARCHIVE SUCCEED
1597 # create released file (simulate llapi_hsm_import call)
1599 local fid2=$(path2fid $f)
1600 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1601 $LFS hsm_release $f || error "could not release file"
1603 # rebind the archive to the newly created file
1604 echo "rebind $fid to $fid2"
1606 do_facet $SINGLEAGT \
1607 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1608 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1610 # restore file and compare md5sum
1611 local sum2=$(md5sum $f | awk '{print $1}')
1613 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1617 run_test 14 "Rebind archived file to a new fid"
1620 # test needs a running copytool
1625 local f=$DIR/$tdir/$tfile
1627 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1631 for i in $(seq 1 $count); do
1632 fids[$i]=$(make_small $f.$i)
1633 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1634 $LFS hsm_archive $f.$i || error "could not archive file"
1636 wait_all_done $(($count*60))
1640 for i in $(seq 1 $count); do
1643 local fid2=$(path2fid $f.$i)
1644 # add the rebind operation to the list
1645 echo ${fids[$i]} $fid2 >> $tmpfile
1647 # set it released (simulate llapi_hsm_import call)
1648 $LFS hsm_set --archived --exists $f.$i ||
1649 error "could not force hsm flags"
1650 $LFS hsm_release $f.$i || error "could not release file"
1652 nl=$(wc -l < $tmpfile)
1653 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1655 echo "rebind list of files"
1656 do_facet $SINGLEAGT \
1657 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1658 --rebind $tmpfile $DIR" || error "could not rebind file list"
1660 # restore files and compare md5sum
1661 for i in $(seq 1 $count); do
1662 local sum2=$(md5sum $f.$i | awk '{print $1}')
1663 [[ $sum2 == ${sums[$i]} ]] ||
1664 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1670 run_test 15 "Rebind a list of files"
1673 # test needs a running copytool
1677 # create a known size file so we can verify transfer speed
1680 dd if=/dev/zero of=$ref bs=1M count=20
1683 local f=$DIR/$tdir/$tfile
1684 local fid=$(copy_file $ref $f)
1686 local start=$(date +%s)
1688 wait_request_state $fid ARCHIVE SUCCEED
1689 local end=$(date +%s)
1690 local duration=$((end - start))
1692 [[ $duration -ge $goal ]] ||
1693 error "Transfer is too fast $duration < $goal"
1697 run_test 16 "Test CT bandwith control option"
1702 local f=$DIR/$tdir/$tfile
1703 touch $f || error "touch $f failed"
1705 # Could not release a non-archived file
1706 $LFS hsm_release $f && error "release should not succeed"
1708 # For following tests, we must test them with HS_ARCHIVED set
1709 $LFS hsm_set --exists --archived $f || error "could not add flag"
1711 # Could not release a file if no-release is set
1712 $LFS hsm_set --norelease $f || error "could not add flag"
1713 $LFS hsm_release $f && error "release should not succeed"
1714 $LFS hsm_clear --norelease $f || error "could not remove flag"
1716 # Could not release a file if lost
1717 $LFS hsm_set --lost $f || error "could not add flag"
1718 $LFS hsm_release $f && error "release should not succeed"
1719 $LFS hsm_clear --lost $f || error "could not remove flag"
1721 # Could not release a file if dirty
1722 $LFS hsm_set --dirty $f || error "could not add flag"
1723 $LFS hsm_release $f && error "release should not succeed"
1724 $LFS hsm_clear --dirty $f || error "could not remove flag"
1726 run_test 20 "Release is not permitted"
1729 # test needs a running copytool
1733 local f=$DIR/$tdir/test_release
1735 # Create a file and check its states
1736 local fid=$(make_small $f)
1737 check_hsm_flags $f "0x00000000"
1739 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1740 # used until file is flushed to disk
1741 if [ $(facet_fstype ost1) == "zfs" ]; then
1742 # this causes an OST_SYNC rpc to be sent
1743 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1744 # clear locks to reread file data
1745 cancel_lru_locks osc
1748 local orig_size=$(stat -c "%s" $f)
1749 local orig_blocks=$(stat -c "%b" $f)
1751 start_full_debug_logging
1753 $LFS hsm_archive $f || error "could not archive file"
1754 wait_request_state $fid ARCHIVE SUCCEED
1756 local blocks=$(stat -c "%b" $f)
1757 [ $blocks -eq $orig_blocks ] ||
1758 error "$f: wrong block number after archive: " \
1759 "$blocks != $orig_blocks"
1760 local size=$(stat -c "%s" $f)
1761 [ $size -eq $orig_size ] ||
1762 error "$f: wrong size after archive: $size != $orig_size"
1764 # Release and check states
1765 $LFS hsm_release $f || error "could not release file"
1766 check_hsm_flags $f "0x0000000d"
1768 blocks=$(stat -c "%b" $f)
1769 [ $blocks -gt 5 ] &&
1770 error "$f: too many blocks after release: $blocks > 5"
1771 size=$(stat -c "%s" $f)
1772 [ $size -ne $orig_size ] &&
1773 error "$f: wrong size after release: $size != $orig_size"
1775 # Check we can release an file without stripe info
1779 check_hsm_flags $f "0x00000000"
1780 $LFS hsm_archive $f || error "could not archive file"
1781 wait_request_state $fid ARCHIVE SUCCEED
1783 # Release and check states
1784 $LFS hsm_release $f || error "could not release file"
1785 check_hsm_flags $f "0x0000000d"
1787 # Release again a file that is already released is OK
1788 $LFS hsm_release $f || fail "second release should succeed"
1789 check_hsm_flags $f "0x0000000d"
1791 stop_full_debug_logging
1795 run_test 21 "Simple release tests"
1798 # test needs a running copytool
1803 local f=$DIR/$tdir/test_release
1804 local swap=$DIR/$tdir/test_swap
1806 # Create a file and check its states
1807 local fid=$(make_small $f)
1808 check_hsm_flags $f "0x00000000"
1810 $LFS hsm_archive $f || error "could not archive file"
1811 wait_request_state $fid ARCHIVE SUCCEED
1813 # Release and check states
1814 $LFS hsm_release $f || error "could not release file"
1815 check_hsm_flags $f "0x0000000d"
1818 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1823 run_test 22 "Could not swap a release file"
1826 # test needs a running copytool
1831 local f=$DIR/$tdir/test_mtime
1833 # Create a file and check its states
1834 local fid=$(make_small $f)
1835 check_hsm_flags $f "0x00000000"
1837 $LFS hsm_archive $f || error "could not archive file"
1838 wait_request_state $fid ARCHIVE SUCCEED
1840 # Set modification time in the past
1841 touch -m -a -d @978261179 $f
1843 # Release and check states
1844 $LFS hsm_release $f || error "could not release file"
1845 check_hsm_flags $f "0x0000000d"
1847 local MTIME=$(stat -c "%Y" $f)
1848 local ATIME=$(stat -c "%X" $f)
1849 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1850 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1854 run_test 23 "Release does not change a/mtime (utime)"
1857 local file=$DIR/$tdir/$tfile
1866 # test needs a running copytool
1871 fid=$(make_small $file)
1873 # Create a file and check its states
1874 check_hsm_flags $file "0x00000000"
1876 # Ensure atime is less than mtime and ctime.
1880 atime0=$(stat -c "%X" $file)
1881 mtime0=$(stat -c "%Y" $file)
1882 ctime0=$(stat -c "%Z" $file)
1884 [ $atime0 -lt $mtime0 ] ||
1885 error "atime $atime0 is not less than mtime $mtime0"
1887 [ $atime0 -lt $ctime0 ] ||
1888 error "atime $atime0 is not less than ctime $ctime0"
1890 # Archive should not change any timestamps.
1891 $LFS hsm_archive $file || error "cannot archive '$file'"
1892 wait_request_state $fid ARCHIVE SUCCEED
1894 atime1=$(stat -c "%X" $file)
1895 mtime1=$(stat -c "%Y" $file)
1896 ctime1=$(stat -c "%Z" $file)
1898 [ $atime0 -eq $atime1 ] ||
1899 error "archive changed atime from $atime0 to $atime1"
1901 [ $mtime0 -eq $mtime1 ] ||
1902 error "archive changed mtime from $mtime0 to $mtime1"
1904 [ $ctime0 -eq $ctime1 ] ||
1905 error "archive changed ctime from $ctime0 to $ctime1"
1907 # Release should not change any timestamps.
1908 $LFS hsm_release $file || error "cannot release '$file'"
1909 check_hsm_flags $file "0x0000000d"
1911 atime1=$(stat -c "%X" $file)
1912 mtime1=$(stat -c "%Y" $file)
1913 ctime1=$(stat -c "%Z" $file)
1915 [ $atime0 -eq $atime1 ] ||
1916 error "release changed atime from $atime0 to $atime1"
1918 [ $mtime0 -eq $mtime1 ] ||
1919 error "release changed mtime from $mtime0 to $mtime1"
1921 [ $ctime0 -eq $ctime1 ] ||
1922 error "release changed ctime from $ctime0 to $ctime1"
1924 # Restore should not change atime or mtime and should not
1926 $LFS hsm_restore $file
1927 wait_request_state $fid RESTORE SUCCEED
1929 atime1=$(stat -c "%X" $file)
1930 mtime1=$(stat -c "%Y" $file)
1931 ctime1=$(stat -c "%Z" $file)
1933 [ $atime0 -eq $atime1 ] ||
1934 error "restore changed atime from $atime0 to $atime1"
1936 [ $mtime0 -eq $mtime1 ] ||
1937 error "restore changed mtime from $mtime0 to $mtime1"
1939 [ $ctime0 -eq $ctime1 ] ||
1940 error "restore changed ctime from $ctime0 to $ctime1"
1944 # Once more, after unmount and mount.
1945 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1946 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1948 atime1=$(stat -c "%X" $file)
1949 mtime1=$(stat -c "%Y" $file)
1950 ctime1=$(stat -c "%Z" $file)
1952 [ $atime0 -eq $atime1 ] ||
1953 error "remount changed atime from $atime0 to $atime1"
1955 [ $mtime0 -eq $mtime1 ] ||
1956 error "remount changed mtime from $mtime0 to $mtime1"
1958 [ $ctime0 -eq $ctime1 ] ||
1959 error "remount changed ctime from $ctime0 to $ctime1"
1961 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1964 local file=$DIR/$tdir/$tfile
1970 # Test needs a running copytool.
1974 # Check that root can do HSM actions on a regular user's file.
1976 fid=$(make_small $file)
1977 sum0=$(md5sum $file)
1979 chown $RUNAS_ID:$RUNAS_GID $file ||
1980 error "cannot chown '$file' to '$RUNAS_ID'"
1982 chmod ugo-w $DIR/$tdir ||
1983 error "cannot chmod '$DIR/$tdir'"
1985 $LFS hsm_archive $file
1986 wait_request_state $fid ARCHIVE SUCCEED
1988 $LFS hsm_release $file
1989 check_hsm_flags $file "0x0000000d"
1991 $LFS hsm_restore $file
1992 wait_request_state $fid RESTORE SUCCEED
1994 # Check that ordinary user can get HSM state.
1995 $RUNAS $LFS hsm_state $file ||
1996 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1998 $LFS hsm_release $file
1999 check_hsm_flags $file "0x0000000d"
2001 # Check that ordinary user can accessed released file.
2002 sum1=$($RUNAS md5sum $file) ||
2003 error "user '$RUNAS_ID' cannot read '$file'"
2005 [ "$sum0" == "$sum1" ] ||
2006 error "md5sum mismatch for '$file'"
2010 run_test 24b "root can archive, release, and restore user files"
2012 cleanup_test_24c() {
2014 set_hsm_param user_request_mask RESTORE
2015 set_hsm_param group_request_mask RESTORE
2016 set_hsm_param other_request_mask RESTORE
2020 local file=$DIR/$tdir/$tfile
2021 local action=archive
2026 # test needs a running copytool
2031 # Save the default masks and check that cleanup_24c will
2032 # restore the request masks correctly.
2033 user_save=$(get_hsm_param user_request_mask)
2034 group_save=$(get_hsm_param group_request_mask)
2035 other_save=$(get_hsm_param other_request_mask)
2037 [ "$user_save" == RESTORE ] ||
2038 error "user_request_mask is '$user_save' expected 'RESTORE'"
2039 [ "$group_save" == RESTORE ] ||
2040 error "group_request_mask is '$group_save' expected 'RESTORE'"
2041 [ "$other_save" == RESTORE ] ||
2042 error "other_request_mask is '$other_save' expected 'RESTORE'"
2044 trap cleanup_test_24c EXIT
2049 chown $RUNAS_ID:nobody $file ||
2050 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2052 set_hsm_param user_request_mask ""
2053 $RUNAS $LFS hsm_$action $file &&
2054 error "$action by user should fail"
2056 set_hsm_param user_request_mask $action
2057 $RUNAS $LFS hsm_$action $file ||
2058 error "$action by user should succeed"
2063 chown nobody:$RUNAS_GID $file ||
2064 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2066 set_hsm_param group_request_mask ""
2067 $RUNAS $LFS hsm_$action $file &&
2068 error "$action by group should fail"
2070 set_hsm_param group_request_mask $action
2071 $RUNAS $LFS hsm_$action $file ||
2072 error "$action by group should succeed"
2077 chown nobody:nobody $file ||
2078 error "cannot chown '$file' to 'nobody:nobody'"
2080 set_hsm_param other_request_mask ""
2081 $RUNAS $LFS hsm_$action $file &&
2082 error "$action by other should fail"
2084 set_hsm_param other_request_mask $action
2085 $RUNAS $LFS hsm_$action $file ||
2086 error "$action by other should succeed"
2091 run_test 24c "check that user,group,other request masks work"
2093 cleanup_test_24d() {
2095 mount -o remount,rw $MOUNT2
2099 local file1=$DIR/$tdir/$tfile
2100 local file2=$DIR2/$tdir/$tfile
2108 fid1=$(make_small $file1)
2110 trap cleanup_test_24d EXIT
2112 mount -o remount,ro $MOUNT2
2114 fid2=$(path2fid $file2)
2115 [ "$fid1" == "$fid2" ] ||
2116 error "FID mismatch '$fid1' != '$fid2'"
2118 $LFS hsm_archive $file2 &&
2119 error "archive should fail on read-only mount"
2120 check_hsm_flags $file1 "0x00000000"
2122 $LFS hsm_archive $file1
2123 wait_request_state $fid1 ARCHIVE SUCCEED
2125 $LFS hsm_release $file1
2126 $LFS hsm_restore $file2
2127 wait_request_state $fid1 RESTORE SUCCEED
2129 $LFS hsm_release $file1 || error "cannot release '$file1'"
2130 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2132 $LFS hsm_release $file2 &&
2133 error "release should fail on read-only mount"
2138 run_test 24d "check that read-only mounts are respected"
2145 local f=$DIR/$tdir/$tfile
2148 fid=$(make_small $f) || error "cannot create $f"
2149 $LFS hsm_archive $f || error "cannot archive $f"
2150 wait_request_state $fid ARCHIVE SUCCEED
2151 $LFS hsm_release $f || error "cannot release $f"
2152 while ! $LFS hsm_state $f | grep released; do
2156 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2160 run_test 24e "tar succeeds on HSM released files" # LU-6213
2164 # test needs a running copytool
2167 mkdir -p $DIR/$tdir/d1
2168 local f=$DIR/$tdir/$tfile
2169 local fid=$(copy_file /etc/hosts $f)
2172 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2173 error "hsm_archive failed"
2174 wait_request_state $fid ARCHIVE SUCCEED
2175 $LFS hsm_release $f || error "cannot release $f"
2176 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2179 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2180 error "Can not recover the tar contents"
2182 echo "Sum0 = $sum0, sum1 = $sum1"
2183 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2187 run_test 24f "root can archive, release, and restore tar files"
2190 # test needs a running copytool
2194 copy2archive /etc/hosts $tdir/$tfile
2196 local f=$DIR/$tdir/$tfile
2198 import_file $tdir/$tfile $f
2200 $LFS hsm_set --lost $f
2205 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2209 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2210 " (Operation not permitted)"
2213 # test needs a running copytool
2218 local f=$DIR/$tdir/$tfile
2219 local fid=$(copy_file /etc/passwd $f)
2221 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2222 wait_request_state $fid ARCHIVE SUCCEED
2225 $LFS hsm_set --lost $f
2229 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2233 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2234 " (Operation not permitted)"
2237 # test needs a running copytool
2241 local f=$DIR/$tdir/$tfile
2243 fid=$(make_large_for_progress $f)
2244 [ $? != 0 ] && skip "not enough free space" && return
2246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2247 wait_request_state $fid ARCHIVE SUCCEED
2250 wait_request_state $fid REMOVE SUCCEED
2252 check_hsm_flags $f "0x00000000"
2256 run_test 26 "Remove the archive of a valid file"
2258 cleanup_test_26a() {
2260 set_hsm_param remove_archive_on_last_unlink 0
2261 set_hsm_param loop_period $orig_loop_period
2262 set_hsm_param grace_delay $orig_grace_delay
2267 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2268 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2270 # test needs a running copytool
2274 local f=$DIR/$tdir/$tfile
2275 local fid=$(copy_file /etc/passwd $f)
2277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2278 wait_request_state $fid ARCHIVE SUCCEED
2282 local f2=$DIR/$tdir/${tfile}_2
2283 local fid2=$(copy_file /etc/passwd $f2)
2285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2286 wait_request_state $fid2 ARCHIVE SUCCEED
2290 local f3=$DIR/$tdir/${tfile}_3
2291 local fid3=$(copy_file /etc/passwd $f3)
2293 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2294 wait_request_state $fid3 ARCHIVE SUCCEED
2296 local f4=$DIR/$tdir/${tfile}_4
2297 local fid4=$(copy_file /etc/passwd $f4)
2299 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f4
2300 wait_request_state $fid4 ARCHIVE SUCCEED
2302 trap cleanup_test_26a EXIT
2304 # set a long grace_delay vs short loop_period
2305 local orig_loop_period=$(get_hsm_param loop_period)
2306 local orig_grace_delay=$(get_hsm_param grace_delay)
2307 set_hsm_param loop_period 10
2308 set_hsm_param grace_delay 100
2310 set_hsm_param remove_archive_on_last_unlink 1
2314 local f4bis=$DIR/$tdir/${tfile}_4bis
2316 [[ $? -eq 0 ]] || error "Unable to create hard-link"
2319 # Since CDT is not signaled for RAoLU requests to be sure it
2320 # will wake-up to send remove request and copytool will process
2321 # it, wait for loop_period + some extra-time.
2322 local loop_period=$(get_hsm_param loop_period)
2323 sleep $((loop_period + 5))
2325 set_hsm_param remove_archive_on_last_unlink 0
2327 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid
2328 [[ $? -eq 0 ]] || error "File being removed on archive"
2330 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid2
2331 [[ $? -eq 0 ]] || error "File being removed on archive"
2333 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid3
2334 [[ $? -eq 0 ]] && error "File not being removed on archive"
2336 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid4
2337 [[ $? -eq 0 ]] || error "File being removed on archive"
2339 # previous actions elapsed time should be < grace_delay
2340 wait_request_state $fid3 REMOVE SUCCEED
2344 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2346 cleanup_test_26b() {
2348 set_hsm_param remove_archive_on_last_unlink 0
2354 # test needs a running copytool
2358 local f=$DIR/$tdir/$tfile
2359 local fid=$(copy_file /etc/passwd $f)
2361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2362 wait_request_state $fid ARCHIVE SUCCEED
2364 trap cleanup_test_26b EXIT
2366 set_hsm_param remove_archive_on_last_unlink 1
2369 cdt_check_state stopped
2373 set_hsm_param remove_archive_on_last_unlink 0
2375 wait_request_state $fid REMOVE WAITING
2378 # copytool must re-register
2379 search_and_kill_copytool
2381 search_copytools && error "Copytool should have stopped"
2382 HSM_ARCHIVE_PURGE=false copytool_setup
2384 wait_request_state $fid REMOVE SUCCEED
2385 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid
2386 [[ $? -eq 0 ]] && error "File not being removed on archive"
2390 run_test 26b "RAoLU policy when CDT off"
2392 cleanup_test_26c() {
2394 set_hsm_param remove_archive_on_last_unlink 0
2395 set_hsm_param loop_period $orig_loop_period
2396 set_hsm_param grace_delay $orig_grace_delay
2402 # test needs a running copytool
2406 local f=$DIR/$tdir/$tfile
2407 local fid=$(copy_file /etc/passwd $f)
2409 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2410 wait_request_state $fid ARCHIVE SUCCEED
2412 trap cleanup_test_26c EXIT
2414 # set a long grace_delay vs short loop_period
2415 local orig_loop_period=$(get_hsm_param loop_period)
2416 local orig_grace_delay=$(get_hsm_param grace_delay)
2417 set_hsm_param loop_period 10
2418 set_hsm_param grace_delay 100
2420 set_hsm_param remove_archive_on_last_unlink 1
2422 multiop_bg_pause $f O_c || error "open $f failed"
2424 # give multiop a chance to open
2429 # Since CDT is not signaled for RAoLU requests to be sure it
2430 # will wake-up to send remove request and copytool will process
2431 # it, wait for loop_period + some extra-time.
2432 local loop_period=$(get_hsm_param loop_period)
2433 sleep $((loop_period + 5))
2435 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid
2436 [[ $? -eq 0 ]] || error "File being removed on archive"
2438 kill -USR1 $pid || error "multiop early exit"
2439 # should reach autotest timeout if multiop fails to trap
2440 # signal, close file, and exit ...
2443 # again, wait for loop_period + some extra-time, to allow
2444 # CDT enough time to handle remove request.
2445 sleep $((loop_period + 5))
2447 set_hsm_param remove_archive_on_last_unlink 0
2449 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid
2450 [[ $? -eq 0 ]] && error "File not being removed on archive"
2452 # previous actions elapsed time should be < grace_delay
2453 wait_request_state $fid REMOVE SUCCEED
2457 run_test 26c "RAoLU effective when file closed"
2459 cleanup_test_26d() {
2461 set_hsm_param remove_archive_on_last_unlink 0
2462 set_hsm_param loop_period $orig_loop_period
2463 set_hsm_param grace_delay $orig_grace_delay
2469 # test needs a running copytool
2473 local f=$DIR/$tdir/$tfile
2474 local fid=$(copy_file /etc/motd $f 1)
2476 $LFS hsm_archive $f || error "could not archive file"
2477 wait_request_state $fid ARCHIVE SUCCEED
2478 check_hsm_flags $f "0x00000009"
2480 trap cleanup_test_26d EXIT
2482 # set a long grace_delay vs short loop_period
2483 local orig_loop_period=$(get_hsm_param loop_period)
2484 local orig_grace_delay=$(get_hsm_param grace_delay)
2485 set_hsm_param loop_period 10
2486 set_hsm_param grace_delay 100
2488 set_hsm_param remove_archive_on_last_unlink 1
2490 multiop_bg_pause $f O_c || error "multiop failed"
2492 # give multiop a chance to open
2499 # Since CDT is not signaled for RAoLU requests to be sure it
2500 # will wake-up to send remove request and copytool will process
2501 # it, wait for loop_period + some extra-time.
2502 local loop_period=$(get_hsm_param loop_period)
2503 sleep $((loop_period + 5))
2505 set_hsm_param remove_archive_on_last_unlink 0
2507 do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid
2508 [[ $? -eq 0 ]] && error "File not being removed on archive"
2510 # previous actions elapsed time should be < grace_delay
2511 wait_request_state $fid REMOVE SUCCEED
2513 client_up || client_up || true
2515 kill -USR1 $MULTIPID
2516 wait $MULTIPID || error "multiop close failed"
2520 run_test 26d "RAoLU when Client eviction"
2523 # test needs a running copytool
2527 make_archive $tdir/$tfile
2528 local f=$DIR/$tdir/$tfile
2529 import_file $tdir/$tfile $f
2530 local fid=$(path2fid $f)
2534 [[ $? != 0 ]] || error "Remove of a released file should fail"
2538 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2541 # test needs a running copytool
2545 local f=$DIR/$tdir/$tfile
2547 fid=$(make_large_for_progress $f)
2548 [ $? != 0 ] && skip "not enough free space" && return
2550 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2551 wait_request_state $fid ARCHIVE SUCCEED
2556 [[ $? != 0 ]] || error "Remove of a released file should fail"
2560 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2563 # test needs a running copytool
2567 local f=$DIR/$tdir/$tfile
2569 fid=$(make_large_for_progress $f)
2570 [ $? != 0 ] && skip "not enough free space" && return
2572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2573 wait_request_state $fid ARCHIVE SUCCEED
2582 wait_request_state $fid REMOVE SUCCEED
2586 run_test 28 "Concurrent archive/file remove"
2589 # Tests --mntpath and --archive options
2592 copytool_setup $SINGLEAGT $MOUNT $archive_id
2594 # Bad archive number
2595 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2596 grep "Invalid argument" ||
2597 error "unexpected hsm_remove failure (1)"
2599 # mntpath is present but file is given
2600 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2601 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2602 error "unexpected hsm_remove failure (2)"
2606 run_test 29a "Tests --mntpath and --archive options"
2609 # test needs a running copytool
2613 local f=$DIR/$tdir/$tfile
2614 local fid=$(make_small $f)
2616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2617 wait_request_state $fid ARCHIVE SUCCEED
2621 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2622 wait_request_state $fid REMOVE SUCCEED
2626 run_test 29b "Archive/delete/remove by FID from the archive."
2629 # test needs a running copytool
2633 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2634 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2635 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2638 wait_request_state $fid1 ARCHIVE SUCCEED
2639 wait_request_state $fid2 ARCHIVE SUCCEED
2640 wait_request_state $fid3 ARCHIVE SUCCEED
2642 rm -f $DIR/$tdir/$tfile-[1-3]
2644 echo $fid1 > $DIR/$tdir/list
2645 echo $fid2 >> $DIR/$tdir/list
2646 echo $fid3 >> $DIR/$tdir/list
2648 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2649 --filelist $DIR/$tdir/list
2650 wait_request_state $fid1 REMOVE SUCCEED
2651 wait_request_state $fid2 REMOVE SUCCEED
2652 wait_request_state $fid3 REMOVE SUCCEED
2656 run_test 29c "Archive/delete/remove by FID, using a file list."
2659 # restore at exec cannot work on agent node (because of Linux kernel
2660 # protection of executables)
2661 needclients 2 || return 0
2663 # test needs a running copytool
2667 copy2archive /bin/true $tdir/$tfile
2669 local f=$DIR/$tdir/true
2670 import_file $tdir/$tfile $f
2672 local fid=$(path2fid $f)
2674 # set no retry action mode
2680 # remove no try action mode
2684 [[ $st == 0 ]] || error "Failed to exec a released file"
2688 run_test 30a "Restore at exec (import case)"
2691 # restore at exec cannot work on agent node (because of Linux kernel
2692 # protection of executables)
2693 needclients 2 || return 0
2695 # test needs a running copytool
2699 local f=$DIR/$tdir/true
2700 local fid=$(copy_file /bin/true $f)
2702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2703 wait_request_state $fid ARCHIVE SUCCEED
2706 # set no retry action mode
2712 # remove no try action mode
2716 [[ $st == 0 ]] || error "Failed to exec a released file"
2720 run_test 30b "Restore at exec (release case)"
2723 needclients 2 || return 0
2725 # test needs a running copytool
2729 local f=$DIR/$tdir/SLEEP
2730 local slp_sum1=$(md5sum /bin/sleep)
2731 local fid=$(copy_file /bin/sleep $f)
2733 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2734 wait_request_state $fid ARCHIVE SUCCEED
2736 check_hsm_flags $f "0x0000000d"
2737 # set no retry action mode
2739 do_node $CLIENT2 "$f 10" &
2743 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2745 [[ $? == 0 ]] || error "Execution failed during run"
2747 if [[ $? != 0 ]]; then
2748 local slp_sum2=$(md5sum /bin/sleep)
2749 # in case sleep file is modified during the test
2750 [[ $slp_sum1 == $slp_sum2 ]] &&
2751 error "Binary overwritten during exec"
2755 # remove no try action mode
2757 check_hsm_flags $f "0x00000009"
2761 run_test 30c "Update during exec of released file must fail"
2763 restore_and_check_size() {
2766 local s=$(stat -c "%s" $f)
2768 local st=$(get_hsm_flags $f)
2772 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2774 n=$(stat -c "%s" $f)
2775 # we echo in both cases to show stat is not
2777 if [[ $n != $s ]]; then
2778 echo "size seen is $n != $s"
2781 echo "size seen is right: $n == $s"
2783 st=$(get_hsm_flags $f)
2787 if [[ $cpt -lt 10 ]]; then
2790 echo " restore is too long"
2791 wait_request_state $fid RESTORE SUCCEED
2797 # test needs a running copytool
2802 make_archive $tdir/$tfile
2803 local f=$DIR/$tdir/$tfile
2804 import_file $tdir/$tfile $f
2805 local fid=$($LFS path2fid $f)
2806 HSM_ARCHIVE_PURGE=false copytool_setup
2808 restore_and_check_size $f $fid
2811 [[ $err -eq 0 ]] || error "File size changed during restore"
2815 run_test 31a "Import a large file and check size during restore"
2819 # test needs a running copytool
2824 local f=$DIR/$tdir/$tfile
2826 fid=$(make_large_for_progress $f)
2827 [ $? != 0 ] && skip "not enough free space" && return
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2830 wait_request_state $fid ARCHIVE SUCCEED
2833 restore_and_check_size $f $fid
2836 [[ $err -eq 0 ]] || error "File size changed during restore"
2840 run_test 31b "Restore a large unaligned file and check size during restore"
2843 # test needs a running copytool
2848 local f=$DIR/$tdir/$tfile
2850 fid=$(make_large_for_progress_aligned $f)
2851 [ $? != 0 ] && skip "not enough free space" && return
2853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2854 wait_request_state $fid ARCHIVE SUCCEED
2857 restore_and_check_size $f $fid
2860 [[ $err -eq 0 ]] || error "File size changed during restore"
2864 run_test 31c "Restore a large aligned file and check size during restore"
2867 # test needs a running copytool
2872 local f=$DIR/$tdir/$tfile
2874 fid=$(make_large_for_progress $f)
2875 [ $? != 0 ] && skip "not enough free space" && return
2877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2878 wait_request_state $fid ARCHIVE SUCCEED
2881 # to be sure wait_all_done will not be mislead by previous tests
2884 wait_for_grace_delay
2885 # Also raise grace_delay significantly so the Canceled
2886 # Restore action will stay enough long avail.
2887 local old_grace=$(get_hsm_param grace_delay)
2888 set_hsm_param grace_delay 100
2890 md5sum $f >/dev/null &
2892 wait_request_state $fid RESTORE STARTED
2897 # Check restore trigger process was killed
2898 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2902 # instead of waiting+checking both Restore and Cancel ops
2903 # sequentially, wait for both to be finished and then check
2905 wait_all_done 100 $fid
2906 local rstate=$(get_request_state $fid RESTORE)
2907 local cstate=$(get_request_state $fid CANCEL)
2909 # restore orig grace_delay.
2910 set_hsm_param grace_delay $old_grace
2912 if [[ "$rstate" == "CANCELED" ]] ; then
2913 [[ "$cstate" == "SUCCEED" ]] ||
2914 error "Restore state is CANCELED and Cancel state " \
2915 "is not SUCCEED but $cstate"
2916 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2917 elif [[ "$rstate" == "SUCCEED" ]] ; then
2918 [[ "$cstate" == "FAILED" ]] ||
2919 error "Restore state is SUCCEED and Cancel state " \
2920 "is not FAILED but $cstate"
2921 echo "Restore state is SUCCEED, Cancel state is FAILED"
2923 error "Restore state is $rstate and Cancel state is $cstate"
2927 error "Cannot kill process waiting for restore ($killed)"
2931 run_test 33 "Kill a restore waiting process"
2934 # test needs a running copytool
2939 local f=$DIR/$tdir/$tfile
2941 fid=$(make_large_for_progress $f)
2942 [ $? != 0 ] && skip "not enough free space" && return
2944 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2945 wait_request_state $fid ARCHIVE SUCCEED
2948 md5sum $f >/dev/null &
2950 wait_request_state $fid RESTORE STARTED
2952 rm $f || error "rm $f failed"
2953 # rm must not block during restore
2954 wait_request_state $fid RESTORE STARTED
2956 wait_request_state $fid RESTORE SUCCEED
2957 # check md5sum pgm finished
2958 local there=$(ps -o pid,comm hp $pid >/dev/null)
2959 [[ -z $there ]] || error "Restore initiator does not exit"
2961 local rc=$(wait $pid)
2962 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2966 run_test 34 "Remove file during restore"
2969 # test needs a running copytool
2974 local f=$DIR/$tdir/$tfile
2975 local f1=$DIR/$tdir/$tfile-1
2977 fid=$(make_large_for_progress $f)
2978 [ $? != 0 ] && skip "not enough free space" && return
2980 local fid1=$(copy_file /etc/passwd $f1)
2981 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2982 wait_request_state $fid ARCHIVE SUCCEED
2985 md5sum $f >/dev/null &
2987 wait_request_state $fid RESTORE STARTED
2989 mv $f1 $f || error "mv $f1 $f failed"
2990 # mv must not block during restore
2991 wait_request_state $fid RESTORE STARTED
2993 wait_request_state $fid RESTORE SUCCEED
2994 # check md5sum pgm finished
2995 local there=$(ps -o pid,comm hp $pid >/dev/null)
2996 [[ -z $there ]] || error "Restore initiator does not exit"
2998 local rc=$(wait $pid)
2999 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
3002 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3006 run_test 35 "Overwrite file during restore"
3009 # test needs a running copytool
3014 local f=$DIR/$tdir/$tfile
3016 fid=$(make_large_for_progress $f)
3017 [ $? != 0 ] && skip "not enough free space" && return
3019 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3020 wait_request_state $fid ARCHIVE SUCCEED
3023 md5sum $f >/dev/null &
3025 wait_request_state $fid RESTORE STARTED
3028 # rm must not block during restore
3029 wait_request_state $fid RESTORE STARTED
3031 wait_request_state $fid RESTORE SUCCEED
3032 # check md5sum pgm finished
3033 local there=$(ps -o pid,comm hp $pid >/dev/null)
3035 error "Restore initiator does not exit"
3037 local rc=$(wait $pid)
3039 error "Restore initiator failed with $rc"
3043 run_test 36 "Move file during restore"
3046 # LU-5683: check that an archived dirty file can be rearchived.
3048 copytool_setup $SINGLEAGT $MOUNT2
3051 local f=$DIR/$tdir/$tfile
3054 fid=$(make_small $f) || error "cannot create small file"
3056 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3057 wait_request_state $fid ARCHIVE SUCCEED
3058 $LFS hsm_release $f || error "cannot release $f"
3061 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3063 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3064 wait_request_state $fid ARCHIVE SUCCEED
3068 run_test 37 "re-archive a dirty file"
3075 for n in $(seq 1 $count); do
3076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3078 echo "$count archive requests submitted"
3082 local stream_count=4
3083 local file_count=100
3085 local f=$DIR/$tdir/$tfile
3090 for i in $(seq 1 $file_count); do
3091 for p in $(seq 1 $stream_count); do
3092 fid=$(copy_file /etc/hosts $f.$p.$i)
3095 # force copytool to use a local/temp archive dir to ensure best
3096 # performance vs remote/NFS mounts used in auto-tests
3097 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3100 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3102 # to be sure wait_all_done will not be mislead by previous tests
3104 wait_for_grace_delay
3106 # start archive streams in background (archive files in parallel)
3107 for p in $(seq 1 $stream_count); do
3108 multi_archive $f.$p $file_count &
3111 echo -n "Wait for all requests being enqueued..."
3117 run_test 40 "Parallel archive requests"
3120 # test needs a running copytool
3124 local f=$DIR/$tdir/$tfile
3125 local fid=$(copy_file /etc/motd $f 1)
3127 $LFS hsm_archive $f || error "could not archive file"
3128 wait_request_state $fid ARCHIVE SUCCEED
3129 check_hsm_flags $f "0x00000009"
3131 multiop_bg_pause $f O_c || error "multiop failed"
3135 client_up || client_up || true
3137 kill -USR1 $MULTIPID
3138 wait $MULTIPID || error "multiop close failed"
3140 check_hsm_flags $f "0x0000000b"
3144 run_test 52 "Opened for write file on an evicted client should be set dirty"
3147 # test needs a running copytool
3151 local f=$DIR/$tdir/$tfile
3152 local fid=$(copy_file /etc/motd $f 1)
3154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3155 error "could not archive file"
3156 wait_request_state $fid ARCHIVE SUCCEED
3157 check_hsm_flags $f "0x00000009"
3159 multiop_bg_pause $f o_c || error "multiop failed"
3163 client_up || client_up || true
3165 kill -USR1 $MULTIPID
3166 wait $MULTIPID || error "multiop close failed"
3168 check_hsm_flags $f "0x00000009"
3172 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3175 # test needs a running copytool
3179 local f=$DIR/$tdir/$tfile
3180 local fid=$(make_large_for_progress $f)
3182 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3183 error "could not archive file"
3184 wait_request_state $fid ARCHIVE STARTED
3186 check_hsm_flags $f "0x00000001"
3188 # Avoid coordinator resending this request as soon it has failed.
3193 wait_request_state $fid ARCHIVE FAILED
3195 check_hsm_flags $f "0x00000003"
3200 run_test 54 "Write during an archive cancels it"
3203 # test needs a running copytool
3207 local f=$DIR/$tdir/$tfile
3208 local fid=$(make_large_for_progress $f)
3210 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3211 error "could not archive file"
3212 wait_request_state $fid ARCHIVE STARTED
3214 check_hsm_flags $f "0x00000001"
3216 # Avoid coordinator resending this request as soon it has failed.
3219 $TRUNCATE $f 1024 || error "truncate failed"
3221 wait_request_state $fid ARCHIVE FAILED
3223 check_hsm_flags $f "0x00000003"
3228 run_test 55 "Truncate during an archive cancels it"
3231 # test needs a running copytool
3235 local f=$DIR/$tdir/$tfile
3237 fid=$(make_large_for_progress $f)
3238 [ $? != 0 ] && skip "not enough free space" && return
3240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3241 error "could not archive file"
3242 wait_request_state $fid ARCHIVE STARTED
3244 check_hsm_flags $f "0x00000001"
3246 # Change metadata and sync to be sure we are not changing only
3251 wait_request_state $fid ARCHIVE SUCCEED
3253 check_hsm_flags $f "0x00000009"
3257 run_test 56 "Setattr during an archive is ok"
3260 # Need one client for I/O, one for request
3261 needclients 2 || return 0
3263 # test needs a running copytool
3267 local f=$DIR/$tdir/test_archive_remote
3268 # Create a file on a remote node
3269 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3270 "count=2 conv=fsync"
3273 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3274 error "hsm_archive failed"
3275 local fid=$(path2fid $f)
3276 wait_request_state $fid ARCHIVE SUCCEED
3278 # Release and implicit restore it
3279 do_node $CLIENT2 "$LFS hsm_release $f" ||
3280 error "hsm_release failed"
3281 do_node $CLIENT2 "md5sum $f" ||
3282 error "hsm_restore failed"
3284 wait_request_state $fid RESTORE SUCCEED
3288 run_test 57 "Archive a file with dirty cache on another node"
3290 truncate_released_file() {
3294 local sz=$(stat -c %s $src_file)
3295 local f=$DIR/$tdir/$tfile
3296 local fid=$(copy_file $1 $f)
3300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3301 error "could not archive file"
3302 wait_request_state $fid ARCHIVE SUCCEED
3304 $LFS hsm_release $f || error "could not release file"
3306 $TRUNCATE $f $trunc_to || error "truncate failed"
3309 local sz1=$(stat -c %s $f)
3310 [[ $sz1 == $trunc_to ]] ||
3311 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3314 check_hsm_flags $f "0x0000000b"
3316 local state=$(get_request_state $fid RESTORE)
3317 [[ "$state" == "SUCCEED" ]] ||
3318 error "truncate $sz does not trig restore, state = $state"
3320 $TRUNCATE $ref $trunc_to
3321 cmp $ref $f || error "file data wrong after truncate"
3327 # test needs a running copytool
3332 local sz=$(stat -c %s /etc/passwd)
3334 echo "truncate up from $sz to $((sz*2))"
3335 truncate_released_file /etc/passwd $((sz*2))
3337 echo "truncate down from $sz to $((sz/2))"
3338 truncate_released_file /etc/passwd $((sz/2))
3340 echo "truncate to 0"
3341 truncate_released_file /etc/passwd 0
3345 run_test 58 "Truncate a released file will trigger restore"
3349 local server_version=$(lustre_version_code $SINGLEMDS)
3350 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3351 skip "Need MDS version at least 2.7.63" && return
3354 $MCREATE $DIR/$tfile || error "mcreate failed"
3355 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3356 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3357 fid=$(path2fid $DIR/$tfile)
3358 wait_request_state $fid ARCHIVE SUCCEED
3359 $LFS hsm_release $DIR/$tfile || error "release failed"
3362 run_test 59 "Release stripeless file with non-zero size"
3365 # This test validates the fix for LU-4512. Ensure that the -u
3366 # option changes the progress reporting interval from the
3367 # default (30 seconds) to the user-specified interval.
3369 local progress_timeout=$((interval * 4))
3371 # test needs a new running copytool
3373 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3376 local f=$DIR/$tdir/$tfile
3378 fid=$(make_large_for_progress $f)
3379 [ $? != 0 ] && skip "not enough free space" && return
3382 local mdt=${MDT_PREFIX}${mdtidx}
3383 local mds=mds$((mdtidx + 1))
3385 # Wait for copytool to register
3386 wait_update_facet $mds \
3387 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3388 uuid 100 || error "coyptool failed to register with $mdt"
3390 local start_at=$(date +%s)
3391 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3392 error "could not archive file"
3394 local agent=$(facet_active_host $SINGLEAGT)
3395 local prefix=$TESTLOG_PREFIX
3396 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3397 local copytool_log=$prefix.copytool_log.$agent.log
3400 wait_update $agent \
3401 "grep -o start.copy $copytool_log" "start copy" 100 ||
3402 error "copytool failed to start"
3404 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3405 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3411 echo -n "Expecting a progress update within $progress_timeout seconds... "
3413 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3414 if [ $RESULT -gt 0 ]; then
3415 echo "$RESULT bytes copied in $WAIT seconds."
3417 elif [ $WAIT -ge $progress_timeout ]; then
3418 error "Timed out waiting for progress update!"
3421 WAIT=$((WAIT + sleep))
3425 local finish_at=$(date +%s)
3426 local elapsed=$((finish_at - start_at))
3428 # Ensure that the progress update occurred within the expected window.
3429 if [ $elapsed -lt $((interval - 1)) ]; then
3430 error "Expected progress update after at least $interval seconds"
3436 run_test 60 "Changing progress update interval from default"
3439 # test needs a new running copytool
3441 copytool_monitor_setup
3442 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3444 # Just start and stop the copytool to generate events.
3447 # Wait for the copytool to register.
3448 wait_update --verbose $(facet_active_host mds1) \
3449 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3451 error "copytool failed to register with MDT0000"
3455 local REGISTER_EVENT
3456 local UNREGISTER_EVENT
3457 while read event; do
3458 local parsed=$(parse_json_event "$event")
3459 if [ -z "$parsed" ]; then
3460 error "Copytool sent malformed event: $event"
3464 if [ $event_type == "REGISTER" ]; then
3465 REGISTER_EVENT=$event
3466 elif [ $event_type == "UNREGISTER" ]; then
3467 UNREGISTER_EVENT=$event
3469 done < <(echo $"$(get_copytool_event_log)")
3471 if [ -z "$REGISTER_EVENT" ]; then
3472 error "Copytool failed to send register event to FIFO"
3475 if [ -z "$UNREGISTER_EVENT" ]; then
3476 error "Copytool failed to send unregister event to FIFO"
3479 copytool_monitor_cleanup
3480 echo "Register/Unregister events look OK."
3482 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3485 # Bump progress interval for livelier events.
3488 # test needs a new running copytool
3490 copytool_monitor_setup
3491 HSMTOOL_UPDATE_INTERVAL=$interval \
3492 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3495 local f=$DIR/$tdir/$tfile
3497 fid=$(make_large_for_progress $f)
3498 [ $? != 0 ] && skip "not enough free space" && return
3500 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3501 error "could not archive file"
3502 wait_request_state $fid ARCHIVE SUCCEED
3504 local expected_fields="event_time data_fid source_fid"
3505 expected_fields+=" total_bytes current_bytes"
3509 while read event; do
3510 # Make sure we're not getting anything from previous events.
3511 for field in $expected_fields; do
3515 local parsed=$(parse_json_event "$event")
3516 if [ -z "$parsed" ]; then
3517 error "Copytool sent malformed event: $event"
3521 if [ $event_type == "ARCHIVE_START" ]; then
3524 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3527 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3531 # Do some simple checking of the progress update events.
3532 for expected_field in $expected_fields; do
3533 if [ -z ${!expected_field+x} ]; then
3534 error "Missing $expected_field field in event"
3538 if [ $total_bytes -eq 0 ]; then
3539 error "Expected total_bytes to be > 0"
3542 # These should be identical throughout an archive
3544 if [ $source_fid != $data_fid ]; then
3545 error "Expected source_fid to equal data_fid"
3547 done < <(echo $"$(get_copytool_event_log)")
3549 if [ -z "$START_EVENT" ]; then
3550 error "Copytool failed to send archive start event to FIFO"
3553 if [ -z "$FINISH_EVENT" ]; then
3554 error "Copytool failed to send archive finish event to FIFO"
3557 echo "Archive events look OK."
3561 copytool_monitor_cleanup
3563 run_test 71 "Copytool logs JSON archive events to FIFO"
3566 # Bump progress interval for livelier events.
3569 # test needs a new running copytool
3571 copytool_monitor_setup
3572 HSMTOOL_UPDATE_INTERVAL=$interval \
3573 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3574 local test_file=$HSMTOOL_MONITOR_DIR/file
3576 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3578 do_facet $SINGLEAGT "$cmd" ||
3579 error "cannot create $test_file on $SINGLEAGT"
3580 copy2archive $test_file $tdir/$tfile
3583 local f=$DIR/$tdir/$tfile
3584 import_file $tdir/$tfile $f
3585 f=$DIR2/$tdir/$tfile
3586 echo "Verifying released state: "
3587 check_hsm_flags $f "0x0000000d"
3589 local fid=$(path2fid $f)
3591 wait_request_state $fid RESTORE SUCCEED
3593 local expected_fields="event_time data_fid source_fid"
3594 expected_fields+=" total_bytes current_bytes"
3598 while read event; do
3599 # Make sure we're not getting anything from previous events.
3600 for field in $expected_fields; do
3604 local parsed=$(parse_json_event "$event")
3605 if [ -z "$parsed" ]; then
3606 error "Copytool sent malformed event: $event"
3610 if [ $event_type == "RESTORE_START" ]; then
3612 if [ $source_fid != $data_fid ]; then
3613 error "source_fid should == data_fid at start"
3616 elif [ $event_type == "RESTORE_FINISH" ]; then
3618 if [ $source_fid != $data_fid ]; then
3619 error "source_fid should == data_fid at finish"
3622 elif [ $event_type != "RESTORE_RUNNING" ]; then
3626 # Do some simple checking of the progress update events.
3627 for expected_field in $expected_fields; do
3628 if [ -z ${!expected_field+x} ]; then
3629 error "Missing $expected_field field in event"
3633 if [ $total_bytes -eq 0 ]; then
3634 error "Expected total_bytes to be > 0"
3637 # When a restore starts out, the data fid is the same as the
3638 # source fid. After the restore has gotten going, we learn
3639 # the new data fid. Once the restore has finished, the source
3640 # fid is set to the new data fid.
3642 # We test this because some monitoring software may depend on
3643 # this behavior. If it changes, then the consumers of these
3644 # events may need to be modified.
3645 if [ $source_fid == $data_fid ]; then
3646 error "source_fid should != data_fid during restore"
3648 done < <(echo $"$(get_copytool_event_log)")
3650 if [ -z "$START_EVENT" ]; then
3651 error "Copytool failed to send restore start event to FIFO"
3654 if [ -z "$FINISH_EVENT" ]; then
3655 error "Copytool failed to send restore finish event to FIFO"
3658 echo "Restore events look OK."
3662 copytool_monitor_cleanup
3666 run_test 72 "Copytool logs JSON restore events to FIFO"
3669 file_count=51 # Max number of files constrained by LNET message size
3670 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3671 local f=$DIR/$tdir/$tfile
3672 local FILELIST=/tmp/filelist.txt
3676 for i in $(seq 1 $file_count); do
3677 fid=$(copy_file /etc/hosts $f.$i)
3678 echo $f.$i >> $FILELIST
3680 # force copytool to use a local/temp archive dir to ensure best
3681 # performance vs remote/NFS mounts used in auto-tests
3682 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3685 local dai=$(get_hsm_param default_archive_id)
3686 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3688 # to be sure wait_all_done will not be mislead by previous tests
3690 wait_for_grace_delay
3691 $LFS hsm_archive --filelist $FILELIST ||
3692 error "cannot archive a file list"
3694 $LFS hsm_release --filelist $FILELIST ||
3695 error "cannot release a file list"
3696 $LFS hsm_restore --filelist $FILELIST ||
3697 error "cannot restore a file list"
3701 run_test 90 "Archive/restore a file list"
3703 double_verify_reset_hsm_param() {
3705 echo "Testing $HSM_PARAM.$p"
3706 local val=$(get_hsm_param $p)
3708 local val2=$(($val * 2))
3709 set_hsm_param $p $val2
3710 val=$(get_hsm_param $p)
3711 [[ $val == $val2 ]] ||
3712 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3713 echo "Set $p to 0 must failed"
3717 set_hsm_param $p $save
3719 if [[ $rc == 0 ]]; then
3720 error "we must not be able to set $HSM_PARAM.$p to 0"
3725 double_verify_reset_hsm_param loop_period
3726 double_verify_reset_hsm_param grace_delay
3727 double_verify_reset_hsm_param active_request_timeout
3728 double_verify_reset_hsm_param max_requests
3729 double_verify_reset_hsm_param default_archive_id
3731 run_test 100 "Set coordinator /proc tunables"
3738 run_test 102 "Verify coordinator control"
3741 # test needs a running copytool
3748 for i in $(seq 1 20); do
3749 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3755 echo "Current requests"
3756 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3757 $HSM_PARAM.actions |\
3758 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3760 [[ -z "$res" ]] || error "Some request have not been canceled"
3764 run_test 103 "Purge all requests"
3769 # test needs a running copytool
3773 local f=$DIR/$tdir/$tfile
3775 fid=$(make_large_for_progress $f)
3776 [ $? != 0 ] && skip "not enough free space" && return
3778 # if cdt is on, it can serve too quickly the request
3780 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3781 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3782 $HSM_PARAM.actions |\
3783 grep $fid | cut -f16 -d=")
3786 [[ "$data1" == "$DATAHEX" ]] ||
3787 error "Data field in records is ($data1) and not ($DATAHEX)"
3791 run_test 104 "Copy tool data field"
3798 for i in $(seq -w 1 10); do
3799 cp /etc/passwd $DIR/$tdir/$i
3800 $LFS hsm_archive $DIR/$tdir/$i
3802 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3803 $HSM_PARAM.actions |\
3804 grep WAITING | wc -l")
3807 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3808 $HSM_PARAM.actions |\
3809 grep WAITING | wc -l")
3812 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3813 error "Requests count after shutdown $reqcnt2 != "\
3814 "before shutdown $reqcnt1"
3816 run_test 105 "Restart of coordinator"
3818 get_agent_by_uuid_mdt() {
3821 local mds=mds$(($mdtidx + 1))
3822 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3826 check_agent_registered_by_mdt() {
3829 local mds=mds$(($mdtidx + 1))
3830 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3831 if [[ ! -z "$agent" ]]; then
3832 echo "found agent $agent on $mds"
3834 error "uuid $uuid not found in agent list on $mds"
3838 check_agent_unregistered_by_mdt() {
3841 local mds=mds$(($mdtidx + 1))
3842 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3843 if [[ -z "$agent" ]]; then
3844 echo "uuid not found in agent list on $mds"
3846 error "uuid found in agent list on $mds: $agent"
3850 check_agent_registered() {
3853 for mdsno in $(seq 1 $MDSCOUNT); do
3854 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3858 check_agent_unregistered() {
3861 for mdsno in $(seq 1 $MDSCOUNT); do
3862 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3867 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3869 # Lustre mount-point is mandatory and last parameter on
3870 # copytool cmd-line.
3871 local mntpnt=$(do_rpc_nodes $agent pgrep -fl $HSMTOOL_BASE |
3872 grep -v pgrep | awk '{print $NF}')
3873 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3875 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3879 # test needs a running copytool
3882 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3884 check_agent_registered $uuid
3886 search_copytools || error "No copytool found"
3889 check_agent_unregistered $uuid
3892 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3893 check_agent_registered $uuid
3897 run_test 106 "Copytool register/unregister"
3900 # test needs a running copytool
3902 # create and archive file
3904 local f1=$DIR/$tdir/$tfile
3905 local fid=$(copy_file /etc/passwd $f1)
3906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3907 wait_request_state $fid ARCHIVE SUCCEED
3908 # shutdown and restart MDS
3910 # check the copytool still gets messages from MDT
3911 local f2=$DIR/$tdir/2
3912 local fid=$(copy_file /etc/passwd $f2)
3913 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3914 # main check of this sanity: this request MUST succeed
3915 wait_request_state $fid ARCHIVE SUCCEED
3918 run_test 107 "Copytool re-register after MDS restart"
3920 policy_set_and_test()
3924 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3925 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3926 [[ "$policy" == "$target" ]] ||
3927 error "Wrong policy after '$change': '$policy' != '$target'"
3931 # to force default policy setting if error
3932 CDT_POLICY_HAD_CHANGED=true
3934 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3935 local default="NonBlockingRestore [NoRetryAction]"
3936 [[ "$policy" == "$default" ]] ||
3937 error "default policy has changed,"\
3938 " '$policy' != '$default' update the test"
3939 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3940 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3941 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3942 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3943 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3944 # useless bacause we know but safer for futur changes to use real value
3945 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3946 echo "Next set_param must failed"
3947 policy_set_and_test "wrong" "$policy"
3950 echo "Back to default policy"
3951 cdt_set_sanity_policy
3953 run_test 109 "Policy display/change"
3956 # test needs a running copytool
3961 copy2archive /etc/passwd $tdir/$tfile
3963 local f=$DIR/$tdir/$tfile
3964 import_file $tdir/$tfile $f
3965 local fid=$(path2fid $f)
3967 cdt_set_non_blocking_restore
3972 wait_request_state $fid RESTORE SUCCEED
3973 cdt_clear_non_blocking_restore
3977 error "md5sum returns $st != 1, "\
3978 "should also perror ENODATA (No data available)"
3982 run_test 110a "Non blocking restore policy (import case)"
3985 # test needs a running copytool
3989 local f=$DIR/$tdir/$tfile
3990 local fid=$(copy_file /etc/passwd $f)
3991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3992 wait_request_state $fid ARCHIVE SUCCEED
3995 cdt_set_non_blocking_restore
4000 wait_request_state $fid RESTORE SUCCEED
4001 cdt_clear_non_blocking_restore
4005 error "md5sum returns $st != 1, "\
4006 "should also perror ENODATA (No data available)"
4010 run_test 110b "Non blocking restore policy (release case)"
4013 # test needs a running copytool
4017 copy2archive /etc/passwd $tdir/$tfile
4019 local f=$DIR/$tdir/$tfile
4021 import_file $tdir/$tfile $f
4022 local fid=$(path2fid $f)
4026 copytool_remove_backend $fid
4029 wait_request_state $fid RESTORE FAILED
4036 [[ $st == 0 ]] || error "Restore does not failed"
4040 run_test 111a "No retry policy (import case), restore will error"\
4041 " (No such file or directory)"
4044 # test needs a running copytool
4048 local f=$DIR/$tdir/$tfile
4049 local fid=$(copy_file /etc/passwd $f)
4051 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4052 wait_request_state $fid ARCHIVE SUCCEED
4055 copytool_remove_backend $fid
4058 wait_request_state $fid RESTORE FAILED
4065 [[ $st == 0 ]] || error "Restore does not failed"
4069 run_test 111b "No retry policy (release case), restore will error"\
4070 " (No such file or directory)"
4073 # test needs a running copytool
4077 local f=$DIR/$tdir/$tfile
4078 local fid=$(copy_file /etc/passwd $f)
4080 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4081 local l=$($LFS hsm_action $f)
4083 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4087 wait_request_state $fid ARCHIVE SUCCEED
4090 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4094 run_test 112 "State of recorded request"
4097 # test needs a running copytool
4101 local f=$DIR/$tdir/$tfile
4103 fid=$(make_large_for_cancel $f)
4104 [ $? != 0 ] && skip "not enough free space" && return
4106 # test with cdt on is made in test_221
4108 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4109 # wait archive to register at CDT
4110 wait_request_state $fid ARCHIVE WAITING
4113 wait_request_state $fid ARCHIVE CANCELED
4114 wait_request_state $fid CANCEL SUCCEED
4118 run_test 200 "Register/Cancel archive"
4121 # test needs a running copytool
4125 local f=$DIR/$tdir/$tfile
4126 make_archive $tdir/$tfile
4127 import_file $tdir/$tfile $f
4128 local fid=$(path2fid $f)
4130 # test with cdt on is made in test_222
4133 # wait restore to register at CDT
4134 wait_request_state $fid RESTORE WAITING
4137 wait_request_state $fid RESTORE CANCELED
4138 wait_request_state $fid CANCEL SUCCEED
4142 run_test 201 "Register/Cancel restore"
4145 # test needs a running copytool
4149 local f=$DIR/$tdir/$tfile
4151 fid=$(make_large_for_progress $f)
4152 [ $? != 0 ] && skip "not enough free space" && return
4154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4155 wait_request_state $fid ARCHIVE SUCCEED
4159 # wait remove to register at CDT
4160 wait_request_state $fid REMOVE WAITING
4163 wait_request_state $fid REMOVE CANCELED
4167 run_test 202 "Register/Cancel remove"
4170 # test needs a running copytool
4175 local f=$DIR/$tdir/$tfile
4176 local fid=$(copy_file /etc/passwd $f)
4180 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4181 wait_request_state $fid ARCHIVE SUCCEED
4183 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4187 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4191 run_test 220 "Changelog for archive"
4194 # test needs a running copytool
4199 local f=$DIR/$tdir/$tfile
4201 fid=$(make_large_for_cancel $f)
4202 [ $? != 0 ] && skip "not enough free space" && return
4206 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4207 wait_request_state $fid ARCHIVE STARTED
4209 wait_request_state $fid ARCHIVE CANCELED
4210 wait_request_state $fid CANCEL SUCCEED
4212 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4215 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4219 run_test 221 "Changelog for archive canceled"
4222 # test needs a running copytool
4226 copy2archive /etc/passwd $tdir/$tfile
4228 local f=$DIR/$tdir/$tfile
4229 import_file $tdir/$tfile $f
4230 local fid=$(path2fid $f)
4235 wait_request_state $fid RESTORE SUCCEED
4237 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4240 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4244 run_test 222a "Changelog for explicit restore"
4247 # test needs a running copytool
4251 local f=$DIR/$tdir/$tfile
4252 local fid=$(copy_file /etc/passwd $f)
4255 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4256 wait_request_state $fid ARCHIVE SUCCEED
4261 wait_request_state $fid RESTORE SUCCEED
4263 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4266 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4270 run_test 222b "Changelog for implicit restore"
4273 # test needs a running copytool
4278 local f=$DIR/$tdir/$tfile
4279 make_archive $tdir/$tfile
4283 import_file $tdir/$tfile $f
4284 local fid=$(path2fid $f)
4287 wait_request_state $fid RESTORE STARTED
4289 wait_request_state $fid RESTORE CANCELED
4290 wait_request_state $fid CANCEL SUCCEED
4292 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4295 [[ $flags == $target ]] ||
4296 error "Changelog flag is $flags not $target"
4300 run_test 223a "Changelog for restore canceled (import case)"
4303 # test needs a running copytool
4308 local f=$DIR/$tdir/$tfile
4310 fid=$(make_large_for_progress $f)
4311 [ $? != 0 ] && skip "not enough free space" && return
4314 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4315 wait_request_state $fid ARCHIVE SUCCEED
4318 wait_request_state $fid RESTORE STARTED
4320 wait_request_state $fid RESTORE CANCELED
4321 wait_request_state $fid CANCEL SUCCEED
4323 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4326 [[ $flags == $target ]] ||
4327 error "Changelog flag is $flags not $target"
4331 run_test 223b "Changelog for restore canceled (release case)"
4334 # test needs a running copytool
4339 local f=$DIR/$tdir/$tfile
4340 local fid=$(copy_file /etc/passwd $f)
4343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4344 wait_request_state $fid ARCHIVE SUCCEED
4347 wait_request_state $fid REMOVE SUCCEED
4349 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4352 [[ $flags == $target ]] ||
4353 error "Changelog flag is $flags not $target"
4357 run_test 224 "Changelog for remove"
4360 # test needs a running copytool
4363 # test is not usable because remove request is too fast
4364 # so it is always finished before cancel can be done ...
4365 echo "Test disabled"
4370 local f=$DIR/$tdir/$tfile
4372 fid=$(make_large_for_progress $f)
4373 [ $? != 0 ] && skip "not enough free space" && return
4376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4377 wait_request_state $fid ARCHIVE SUCCEED
4379 # if cdt is on, it can serve too quickly the request
4384 wait_request_state $fid REMOVE CANCELED
4385 wait_request_state $fid CANCEL SUCCEED
4387 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4388 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4389 tail -n 1 | awk '{print $5}')
4392 [[ $flags == $target ]] ||
4393 error "Changelog flag is $flags not $target"
4397 run_test 225 "Changelog for remove canceled"
4400 # test needs a running copytool
4405 local f1=$DIR/$tdir/$tfile-1
4406 local f2=$DIR/$tdir/$tfile-2
4407 local f3=$DIR/$tdir/$tfile-3
4408 local fid1=$(copy_file /etc/passwd $f1)
4409 local fid2=$(copy_file /etc/passwd $f2)
4410 copy_file /etc/passwd $f3
4413 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4414 wait_request_state $fid1 ARCHIVE SUCCEED
4416 $LFS hsm_archive $f2
4417 wait_request_state $fid2 ARCHIVE SUCCEED
4419 rm $f1 || error "rm $f1 failed"
4421 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4424 [[ $flags == $target ]] ||
4425 error "Changelog flag is $flags not $target"
4427 mv $f3 $f2 || error "mv $f3 $f2 failed"
4429 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4432 [[ $flags == $target ]] ||
4433 error "Changelog flag is $flags not $target"
4437 run_test 226 "changelog for last rm/mv with exiting archive"
4439 check_flags_changes() {
4447 $LFS hsm_set --$hsm_flag $f ||
4448 error "Cannot set $hsm_flag on $f"
4449 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4450 local seen=${#flags[*]}
4452 [[ $seen == $cnt ]] ||
4453 error "set $hsm_flag: Changelog events $seen != $cnt"
4454 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4455 error "set $hsm_flag: Changelog flags are "\
4456 "${flags[$((cnt - 1))]} not $target"
4458 $LFS hsm_clear --$hsm_flag $f ||
4459 error "Cannot clear $hsm_flag on $f"
4460 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4463 [[ $cnt == $seen ]] ||
4464 error "clear $hsm_flag: Changelog events $seen != $cnt"
4466 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4467 error "clear $hsm_flag: Changelog flag is "\
4468 "${flags[$((cnt - 1))]} not $target"
4472 # test needs a running copytool
4479 for i in norelease noarchive exists archived
4481 local f=$DIR/$tdir/$tfile-$i
4482 local fid=$(copy_file /etc/passwd $f)
4483 check_flags_changes $f $fid $i 0 1
4486 f=$DIR/$tdir/$tfile---lost
4487 fid=$(copy_file /etc/passwd $f)
4488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4489 wait_request_state $fid ARCHIVE SUCCEED
4490 check_flags_changes $f $fid lost 3 1
4494 run_test 227 "changelog when explicit setting of HSM flags"
4497 # test needs a running copytool
4500 local fid=$(make_small_sync $DIR/$tfile)
4501 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4502 wait_request_state $fid ARCHIVE SUCCEED
4504 $LFS hsm_release $DIR/$tfile
4505 check_hsm_flags $DIR/$tfile "0x0000000d"
4507 filefrag $DIR/$tfile | grep " 1 extent found" ||
4508 error "filefrag on released file must return only one extent"
4510 # only newer versions of cp detect sparse files by stat/FIEMAP
4512 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4513 error "copying $DIR/$tfile"
4514 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4516 $LFS hsm_release $DIR/$tfile
4517 check_hsm_flags $DIR/$tfile "0x0000000d"
4519 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4521 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4523 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4524 error "comparing untarred $DIR/$tfile"
4526 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4527 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4530 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4533 # test needs a running copytool
4537 local maxrequest=$(get_hsm_param max_requests)
4538 local rqcnt=$(($maxrequest * 3))
4542 for i in $(seq -w 1 $rqcnt); do
4544 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4546 # we do it in 2 steps, so all requests arrive at the same time
4547 for i in $(seq -w 1 $rqcnt); do
4548 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4553 while [[ $cnt != 0 || $wt != 0 ]]; do
4555 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4556 $HSM_PARAM.actions |\
4557 grep STARTED | grep -v CANCEL | wc -l")
4558 [[ $cnt -le $maxrequest ]] ||
4559 error "$cnt > $maxrequest too many started requests"
4560 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4561 $HSM_PARAM.actions |\
4562 grep WAITING | wc -l")
4563 echo "max=$maxrequest started=$cnt waiting=$wt"
4568 run_test 250 "Coordinator max request"
4571 # test needs a running copytool
4575 local f=$DIR/$tdir/$tfile
4577 fid=$(make_large_for_cancel $f)
4578 [ $? != 0 ] && skip "not enough free space" && return
4581 # to have a short test
4582 local old_to=$(get_hsm_param active_request_timeout)
4583 set_hsm_param active_request_timeout 4
4584 # to be sure the cdt will wake up frequently so
4585 # it will be able to cancel the "old" request
4586 local old_loop=$(get_hsm_param loop_period)
4587 set_hsm_param loop_period 2
4590 # clear locks to avoid extra delay caused by flush/cancel
4591 # and thus prevent early copytool death to timeout.
4592 cancel_lru_locks osc
4594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4595 wait_request_state $fid ARCHIVE STARTED
4597 wait_request_state $fid ARCHIVE CANCELED
4599 set_hsm_param active_request_timeout $old_to
4600 set_hsm_param loop_period $old_loop
4604 run_test 251 "Coordinator request timeout"
4607 # the only way to test ondisk conf is to restart MDS ...
4608 echo "Stop coordinator and remove coordinator state at mount"
4611 # clean on disk conf set by default
4612 cdt_clear_mount_state
4613 cdt_check_state stopped
4615 # check cdt still off after umount/remount
4617 cdt_check_state stopped
4619 echo "Set coordinator start at mount, and start coordinator"
4620 cdt_set_mount_state enabled
4623 cdt_check_state enabled
4625 # check cdt still on after umount/remount
4627 cdt_check_state enabled
4629 # we are back to original state (cdt started at mount)
4631 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4634 local ai=$(get_hsm_param default_archive_id)
4635 local new=$((ai + 1))
4637 set_hsm_param default_archive_id $new -P
4639 local res=$(get_hsm_param default_archive_id)
4642 set_hsm_param default_archive_id "" "-P -d"
4644 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4646 run_test 301 "HSM tunnable are persistent"
4649 local ai=$(get_hsm_param default_archive_id)
4650 local new=$((ai + 1))
4655 set_hsm_param default_archive_id $new -P
4658 for mdtno in $(seq 1 $MDSCOUNT); do
4663 cdt_check_state enabled
4665 local res=$(get_hsm_param default_archive_id)
4668 set_hsm_param default_archive_id "" "-P -d"
4670 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4672 run_test 302 "HSM tunnable are persistent when CDT is off"
4675 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4681 local dir_mdt0=$DIR/$tdir/mdt0
4682 local dir_mdt1=$DIR/$tdir/mdt1
4684 # create 1 dir per MDT
4685 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4686 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4688 # create 1 file in each MDT
4689 local fid1=$(make_small $dir_mdt0/$tfile)
4690 local fid2=$(make_small $dir_mdt1/$tfile)
4692 # check that hsm request on mdt0 is sent to the right MDS
4693 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4694 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4695 echo "archive successful on mdt0"
4697 # check that hsm request on mdt1 is sent to the right MDS
4698 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4699 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4700 echo "archive successful on mdt1"
4703 # clean test files and directories
4704 rm -rf $dir_mdt0 $dir_mdt1
4706 run_test 400 "Single request is sent to the right MDT"
4709 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4715 local dir_mdt0=$DIR/$tdir/mdt0
4716 local dir_mdt1=$DIR/$tdir/mdt1
4718 # create 1 dir per MDT
4719 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4720 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4722 # create 1 file in each MDT
4723 local fid1=$(make_small $dir_mdt0/$tfile)
4724 local fid2=$(make_small $dir_mdt1/$tfile)
4726 # check that compound requests are shunt to the rights MDTs
4727 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4728 error "lfs hsm_archive"
4729 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4730 echo "archive successful on mdt0"
4731 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4732 echo "archive successful on mdt1"
4735 # clean test files and directories
4736 rm -rf $dir_mdt0 $dir_mdt1
4738 run_test 401 "Compound requests split and sent to their respective MDTs"
4740 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4745 local node=$(facet_active_host $facet)
4747 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4748 awk '{print $4}'); do
4749 echo "$3 $mdc on $node"
4750 do_facet $facet "$LCTL --device $mdc $state" || return 1
4755 # make sure there is no running copytool
4758 # deactivate all mdc on agent1
4759 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4761 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4763 check_agent_unregistered "uuid" # match any agent
4765 # no expected running copytool
4766 search_copytools $agent && error "Copytool start should have failed"
4769 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4771 run_test 402 "Copytool start fails if all MDTs are inactive"
4774 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4776 # make sure there is no running copytool
4779 local agent=$(facet_active_host $SINGLEAGT)
4781 # deactivate all mdc for MDT0001
4782 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4785 local uuid=$(get_agent_uuid $agent)
4786 # check the agent is registered on MDT0000, and not on MDT0001
4787 check_agent_registered_by_mdt $uuid 0
4788 check_agent_unregistered_by_mdt $uuid 1
4790 # check running copytool process
4791 search_copytools $agent || error "No running copytools on $agent"
4793 # reactivate all mdc for MDT0001
4794 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4796 # make sure the copytool is now registered to all MDTs
4797 check_agent_registered $uuid
4801 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4804 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4808 # create files on both MDT0000 and MDT0001
4811 local dir_mdt0=$DIR/$tdir/mdt0
4812 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4814 # create 1 file on mdt0
4815 local fid1=$(make_small $dir_mdt0/$tfile)
4817 # deactivate all mdc for MDT0001
4818 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4820 # send an HSM request for files in MDT0000
4821 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4823 # check for completion of files in MDT0000
4824 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4825 echo "archive successful on mdt0"
4827 # reactivate all mdc for MDT0001
4828 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4831 # clean test files and directories
4834 run_test 404 "Inactive MDT does not block requests for active MDTs"
4837 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4843 local striped_dir=$DIR/$tdir/striped_dir
4845 # create striped dir on all of MDTs
4846 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4848 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4849 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4850 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4851 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4853 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4854 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4855 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4856 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4858 # check that compound requests are shunt to the rights MDTs
4859 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4860 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4861 error "lfs hsm_archive"
4863 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4864 echo "archive successful on $fid1"
4865 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4866 echo "archive successful on $fid2"
4867 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4868 echo "archive successful on $fid3"
4869 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4870 echo "archive successful on $fid4"
4872 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4873 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4874 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4875 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4877 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4878 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4879 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4880 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4884 run_test 405 "archive and release under striped directory"
4887 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4889 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4890 skip "need MDS version at least 2.7.64" && return 0
4897 fid=$(make_small $DIR/$tdir/$tfile)
4900 $LFS hsm_archive $DIR/$tdir/$tfile
4901 wait_request_state "$fid" ARCHIVE SUCCEED
4902 $LFS hsm_release $DIR/$tdir/$tfile
4904 # Should migrate $tdir but not $tfile.
4905 $LFS mv -M1 $DIR/$tdir &&
4906 error "migrating HSM an archived file should fail"
4908 $LFS hsm_restore $DIR/$tdir/$tfile
4909 wait_request_state "$fid" RESTORE SUCCEED
4911 $LFS hsm_remove $DIR/$tdir/$tfile
4912 wait_request_state "$fid" REMOVE SUCCEED
4914 cat $DIR/$tdir/$tfile > /dev/null ||
4915 error "cannot read $DIR/$tdir/$tfile"
4917 $LFS mv -M1 $DIR/$tdir ||
4918 error "cannot complete migration after HSM remove"
4920 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4921 if ((mdt_index != 1)); then
4922 error "expected MDT index 1, got $mdt_index"
4925 # Refresh fid after migration.
4926 fid=$(path2fid $DIR/$tdir/$tfile)
4929 $LFS hsm_archive $DIR/$tdir/$tfile
4930 wait_request_state "$fid" ARCHIVE SUCCEED 1
4932 lctl set_param debug=+trace
4933 $LFS hsm_release $DIR/$tdir/$tfile ||
4934 error "cannot release $DIR/$tdir/$tfile"
4936 $LFS hsm_restore $DIR/$tdir/$tfile
4937 wait_request_state "$fid" RESTORE SUCCEED 1
4939 cat $DIR/$tdir/$tfile > /dev/null ||
4940 error "cannot read $DIR/$tdir/$tfile"
4944 run_test 406 "attempting to migrate HSM archived files is safe"
4948 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4949 skip "HSM migrate is not supported" && return
4951 # Stop the existing copytool
4954 test_mkdir -p $DIR/$tdir
4955 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4957 run_test 500 "various LLAPI HSM tests"
4962 check_and_cleanup_lustre