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_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
174 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
184 # try to dump Copytool's stack
185 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
186 "echo t >/proc/sysrq-trigger"
188 echo "copytools failed to stop in ${wait_timeout}s"
193 copytool_monitor_setup() {
194 local facet=${1:-$SINGLEAGT}
195 local agent=$(facet_active_host $facet)
197 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
198 local test_dir=$(do_node $agent "$cmd") ||
199 error "Failed to create tempdir on $agent"
200 export HSMTOOL_MONITOR_DIR=$test_dir
202 # Create the fifo and a monitor (cat dies when copytool dies)
203 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
204 error "failed to create copytool fifo on $agent"
205 cmd="cat $test_dir/fifo > $test_dir/events &"
206 cmd+=" echo \\\$! > $test_dir/monitor_pid"
208 if [[ $PDSH == *Rmrsh* ]]; then
209 # This is required for pdsh -Rmrsh and its handling of remote
211 # Regular ssh and pdsh -Rssh work fine without this
212 # backgrounded subshell nonsense.
213 (do_node $agent "$cmd") &
214 export HSMTOOL_MONITOR_PDSH=$!
216 # Slightly racy, but just making a best-effort to catch obvious
219 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
220 error "Failed to start copytool monitor on $agent"
222 do_node $agent "$cmd"
224 error "Failed to start copytool monitor on $agent"
229 copytool_monitor_cleanup() {
230 local facet=${1:-$SINGLEAGT}
231 local agent=$(facet_active_host $facet)
233 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
234 # Should die when the copytool dies, but just in case.
235 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
236 cmd+=" 2>/dev/null || true"
237 do_node $agent "$cmd"
238 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
239 export HSMTOOL_MONITOR_DIR=
242 # The pdsh should die on its own when the monitor dies. Just
243 # in case, though, try to clean up to avoid any cruft.
244 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
245 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
246 export HSMTOOL_MONITOR_PDSH=
251 local facet=${1:-$SINGLEAGT}
252 # Use MOUNT2 by default if defined
253 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
255 local hsm_root=${4:-$(copytool_device $facet)}
257 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
259 local agent=$(facet_active_host $facet)
261 if [[ -z "$arc_id" ]] &&
262 do_facet $facet "pkill -CONT -x $HSMTOOL_BASE"; then
263 echo "Only wakeup running copytool $facet on $agent"
267 if $HSM_ARCHIVE_PURGE; then
268 echo "Purging archive on $agent"
269 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
272 echo "Starting copytool $facet on $agent"
273 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
274 error "mkdir '$hsm_root/$HSMTMP' failed"
275 # bandwidth is limited to 1MB/s so the copy time is known and
276 # independent of hardware
277 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
278 cmd+=" --hsm-root $hsm_root/$HSMTMP"
279 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
280 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
281 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
282 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
283 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
284 cmd+=" --bandwidth 1 $lustre_mntpnt"
286 # Redirect the standard output and error to a log file which
287 # can be uploaded to Maloo.
288 local prefix=$TESTLOG_PREFIX
289 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
290 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
292 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
293 if [[ $? != 0 ]]; then
294 [[ $HSMTOOL_NOERROR == true ]] ||
295 error "start copytool $facet on $agent failed"
296 echo "start copytool $facet on $agent failed"
302 get_copytool_event_log() {
303 local facet=${1:-$SINGLEAGT}
304 local agent=$(facet_active_host $facet)
306 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
307 error "Can't get event log: No monitor directory!"
309 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
310 error "Could not collect event log from $agent"
315 local agt_facet=$SINGLEAGT
316 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
317 local hsm_root=$(copytool_device $agt_facet)
319 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
326 kill_copytools $agt_hosts
327 wait_copytools $agt_hosts || error "copytools failed to stop"
329 # Clean all CDTs orphans requests from previous tests that
330 # would otherwise need to timeout to clear.
331 for ((i = 0; i < MDSCOUNT; i++)); do
333 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
334 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
336 # Skip already stopping or stopped CDTs.
337 [[ "${state[$i]}" =~ ^stop ]] && continue
339 do_facet $facet "$LCTL set_param $param=shutdown"
342 for ((i = 0; i < MDSCOUNT; i++)); do
343 # Only check and restore CDTs that we stopped in the first loop.
344 [[ "${state[$i]}" =~ ^stop ]] && continue
347 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
349 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
350 error "$facet CDT state is not stopped"
352 # Restore old CDT state.
353 do_facet $facet "$LCTL set_param $param=${state[$i]}"
356 for ((i = 0; i < MDSCOUNT; i++)); do
357 # Only check CDTs that we stopped in the first loop.
358 [[ "${state[$i]}" =~ ^stop ]] && continue
361 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
363 # Check that the old CDT state was restored.
364 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
365 20 || error "$facet CDT state is not '${state[$i]}'"
368 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
369 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
374 local agents=${1:-$(facet_active_host $SINGLEAGT)}
376 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
377 echo "Copytool is suspended on $agents"
380 copytool_remove_backend() {
382 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
383 echo "Remove from backend: $fid = $be"
384 do_facet $SINGLEAGT rm -f $be
388 do_facet $SINGLEAGT \
389 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
390 --import $1 $2 $MOUNT" ||
391 error "import of $1 to $2 failed"
395 local file=$HSM_ARCHIVE/$1
396 do_facet $SINGLEAGT mkdir -p $(dirname $file)
397 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
398 file_creation_failure dd $file $?
402 local file=$HSM_ARCHIVE/$2
403 do_facet $SINGLEAGT mkdir -p $(dirname $file)
404 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
413 if [[ "$value" != "" ]]; then
416 for mdtno in $(seq 1 $MDSCOUNT); do
417 local idx=$(($mdtno - 1))
418 local facet=mds${mdtno}
419 # if $arg include -P option, run 1 set_param per MDT on the MGS
420 # else, run set_param on each MDT
421 [[ $arg = *"-P"* ]] && facet=mgs
422 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
423 [[ $? != 0 ]] && rc=1
433 for mdtno in $(seq 1 $MDSCOUNT); do
434 local idx=$(($mdtno - 1))
435 wait_result mds${mdtno} \
436 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
438 error "$key state is not '$target' on mds${mdtno}"
445 for mdtno in $(seq 1 $MDSCOUNT); do
446 local idx=$(($mdtno - 1))
447 local cl_user=$(do_facet mds${mdtno} $LCTL \
448 --device ${MDT[$idx]} \
449 changelog_register -n)
451 do_facet mds${mdtno} lctl set_param \
452 mdd.${MDT[$idx]}.changelog_mask="+hsm"
453 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
457 changelog_cleanup() {
459 for mdtno in $(seq 1 $MDSCOUNT); do
460 local idx=$(($mdtno - 1))
461 [[ -z ${CL_USERS[$idx]} ]] && continue
462 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
463 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
464 changelog_deregister ${CL_USERS[$idx]}
469 changelog_get_flags() {
474 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
479 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
487 mdts_set_param "$opt -n" "hsm.$param" "$value"
494 mdts_set_param "" hsm_control "$cmd"
495 mdts_check_param hsm_control "$target" 10
498 cdt_set_sanity_policy() {
499 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
502 mdts_set_param "" hsm.policy "+NRA"
503 mdts_set_param "" hsm.policy "-NBR"
504 CDT_POLICY_HAD_CHANGED=
509 mdts_set_param "" hsm.policy "+NRA"
510 CDT_POLICY_HAD_CHANGED=true
513 cdt_clear_no_retry() {
514 mdts_set_param "" hsm.policy "-NRA"
515 CDT_POLICY_HAD_CHANGED=true
518 cdt_set_non_blocking_restore() {
519 mdts_set_param "" hsm.policy "+NBR"
520 CDT_POLICY_HAD_CHANGED=true
523 cdt_clear_non_blocking_restore() {
524 mdts_set_param "" hsm.policy "-NBR"
525 CDT_POLICY_HAD_CHANGED=true
528 cdt_clear_mount_state() {
529 mdts_set_param "-P -d" hsm_control ""
532 cdt_set_mount_state() {
533 mdts_set_param "-P" hsm_control "$1"
534 # set_param -P is asynchronous operation and could race with set_param.
535 # In such case configs could be retrieved and applied at mgc after
536 # set_param -P completion. Sleep here to avoid race with set_param.
537 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
538 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
539 # and 10 seconds to retrieve config from server.
544 mdts_check_param hsm_control "$1" 20
548 set_test_state disabled disabled
552 set_test_state enabled enabled
556 set_test_state shutdown stopped
560 set_test_state purge enabled
566 cdt_set_sanity_policy
570 local client_count=$1
571 if [[ $CLIENTCOUNT -lt $client_count ]]; then
572 skip "Need $client_count or more clients, have $CLIENTCOUNT"
579 $LFS path2fid $1 | tr -d '[]'
580 return ${PIPESTATUS[0]}
588 if [[ $u == "user" ]]; then
589 st=$($RUNAS $LFS hsm_state $f)
592 st=$($LFS hsm_state $f)
595 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
597 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
601 get_hsm_archive_id() {
604 st=$($LFS hsm_state $f)
605 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
607 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
616 local st=$(get_hsm_flags $f)
617 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
620 check_hsm_flags_user() {
624 local st=$(get_hsm_flags $f user)
625 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
628 file_creation_failure() {
633 df $MOUNT $MOUNT2 >&2
634 error "cannot create $f with $cmd, status=$err"
646 if [[ "$3" != 1 ]]; then
650 cp $1 $f || file_creation_failure cp $f $?
652 path2fid $f || error "cannot get fid on $f"
656 local file2=${1/$DIR/$DIR2}
657 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
658 file_creation_failure dd $file2 $?
660 path2fid $1 || error "cannot get fid on $1"
664 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
665 file_creation_failure dd $1 $?
666 path2fid $1 || error "cannot get fid on $1"
669 cleanup_large_files() {
670 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
672 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
675 check_enough_free_space() {
678 local need=$((nb * unit /1024))
679 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
680 (( $need >= $free )) && return 1
684 make_large_for_striping() {
685 local file2=${1/$DIR/$DIR2}
686 local sz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
690 check_enough_free_space 5 $sz
691 [ $? != 0 ] && return $?
693 dd if=/dev/urandom of=$file2 count=5 bs=$sz conv=fsync ||
694 file_creation_failure dd $file2 $?
696 path2fid $1 || error "cannot get fid on $1"
699 make_large_for_progress() {
700 local file2=${1/$DIR/$DIR2}
704 check_enough_free_space 39 1000000
705 [ $? != 0 ] && return $?
707 # big file is large enough, so copy time is > 30s
708 # so copytool make 1 progress
709 # size is not a multiple of 1M to avoid stripe
711 dd if=/dev/urandom of=$file2 count=39 bs=1000000 conv=fsync ||
712 file_creation_failure dd $file2 $?
714 path2fid $1 || error "cannot get fid on $1"
717 make_large_for_progress_aligned() {
718 local file2=${1/$DIR/$DIR2}
722 check_enough_free_space 33 1048576
723 [ $? != 0 ] && return $?
725 # big file is large enough, so copy time is > 30s
726 # so copytool make 1 progress
727 # size is a multiple of 1M to have stripe
729 dd if=/dev/urandom of=$file2 count=33 bs=1M conv=fsync ||
730 file_creation_failure dd $file2 $?
731 path2fid $1 || error "cannot get fid on $1"
734 make_large_for_cancel() {
735 local file2=${1/$DIR/$DIR2}
739 check_enough_free_space 103 1048576
740 [ $? != 0 ] && return $?
742 # Copy timeout is 100s. 105MB => 105s
743 dd if=/dev/urandom of=$file2 count=103 bs=1M conv=fsync ||
744 file_creation_failure dd $file2 $?
745 path2fid $1 || error "cannot get fid on $1"
751 wait_update --verbose $(facet_active_host $facet) "$@"
754 wait_request_state() {
758 # 4th arg (mdt index) is optional
760 local mds=mds$(($mdtidx + 1))
762 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
763 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
765 wait_result $mds "$cmd" $state 200 ||
766 error "request on $fid is not $state on $mds"
769 get_request_state() {
773 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
774 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
777 get_request_count() {
781 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
782 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
789 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
790 [[ -n $fid ]] && cmd+=" | grep '$fid'"
791 cmd+=" | egrep 'WAITING|STARTED'"
793 wait_result $SINGLEMDS "$cmd" "" $timeout ||
794 error "requests did not complete"
797 wait_for_grace_delay() {
798 local val=$(get_hsm_param grace_delay)
805 # python2.6 in EL6 includes an internal json module
806 local json_parser='import json; import fileinput;'
807 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
808 json_parser+='json.loads([line for line in '
809 json_parser+='fileinput.input()][0]).items()])'
811 echo $raw_event | python -c "$json_parser"
817 # populate MDT device array
820 # cleanup from previous bad setup
823 # for recovery tests, coordinator needs to be started at mount
825 # the lustre conf must be without hsm on (like for sanity.sh)
826 echo "Set HSM on and start"
827 cdt_set_mount_state enabled
828 cdt_check_state enabled
830 echo "Start copytool"
833 echo "Set sanity-hsm HSM policy"
834 cdt_set_sanity_policy
836 # finished requests are quickly removed from list
837 set_hsm_param grace_delay 10
843 local f=$DIR/$tdir/$tfile
847 check_hsm_flags_user $f "0x00000000"
849 $RUNAS $LFS hsm_set --norelease $f ||
850 error "user could not change hsm flags"
851 check_hsm_flags_user $f "0x00000010"
853 $RUNAS $LFS hsm_clear --norelease $f ||
854 error "user could not clear hsm flags"
855 check_hsm_flags_user $f "0x00000000"
857 # User could not change those flags...
858 $RUNAS $LFS hsm_set --exists $f &&
859 error "user should not set this flag"
860 check_hsm_flags_user $f "0x00000000"
863 $LFS hsm_set --exists $f ||
864 error "root could not change hsm flags"
865 check_hsm_flags_user $f "0x00000001"
867 $LFS hsm_clear --exists $f ||
868 error "root could not clear hsm state"
869 check_hsm_flags_user $f "0x00000000"
872 run_test 1 "lfs hsm flags root/non-root access"
876 local f=$DIR/$tdir/$tfile
877 local fid=$(make_small $f)
879 $LFS hsm_archive $f || error "could not archive file"
880 wait_request_state $fid ARCHIVE SUCCEED
882 # Release and check states
883 $LFS hsm_release $f || error "could not release file"
884 echo -n "Verifying released state: "
885 check_hsm_flags $f "0x0000000d"
887 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
889 run_test 1a "mmap & cat a HSM released file"
893 local f=$DIR/$tdir/$tfile
895 # New files are not dirty
896 check_hsm_flags $f "0x00000000"
898 # For test, we simulate an archived file.
899 $LFS hsm_set --exists $f || error "user could not change hsm flags"
900 check_hsm_flags $f "0x00000001"
902 # chmod do not put the file dirty
903 chmod 600 $f || error "could not chmod test file"
904 check_hsm_flags $f "0x00000001"
906 # chown do not put the file dirty
907 chown $RUNAS_ID $f || error "could not chown test file"
908 check_hsm_flags $f "0x00000001"
910 # truncate put the file dirty
911 $TRUNCATE $f 1 || error "could not truncate test file"
912 check_hsm_flags $f "0x00000003"
914 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
915 check_hsm_flags $f "0x00000001"
917 run_test 2 "Check file dirtyness when doing setattr"
923 # New files are not dirty
925 check_hsm_flags $f "0x00000000"
927 # For test, we simulate an archived file.
928 $LFS hsm_set --exists $f ||
929 error "user could not change hsm flags"
930 check_hsm_flags $f "0x00000001"
932 # Reading a file, does not set dirty
933 cat $f > /dev/null || error "could not read file"
934 check_hsm_flags $f "0x00000001"
936 # Open for write without modifying data, does not set dirty
937 openfile -f O_WRONLY $f || error "could not open test file"
938 check_hsm_flags $f "0x00000001"
940 # Append to a file sets it dirty
941 cp -p /etc/passwd $f.append || error "could not create file"
942 $LFS hsm_set --exists $f.append ||
943 error "user could not change hsm flags"
944 dd if=/etc/passwd of=$f.append bs=1 count=3\
945 conv=notrunc oflag=append status=noxfer ||
946 file_creation_failure dd $f.append $?
947 check_hsm_flags $f.append "0x00000003"
949 # Modify a file sets it dirty
950 cp -p /etc/passwd $f.modify || error "could not create file"
951 $LFS hsm_set --exists $f.modify ||
952 error "user could not change hsm flags"
953 dd if=/dev/zero of=$f.modify bs=1 count=3\
954 conv=notrunc status=noxfer ||
955 file_creation_failure dd $f.modify $?
956 check_hsm_flags $f.modify "0x00000003"
958 # Open O_TRUNC sets dirty
959 cp -p /etc/passwd $f.trunc || error "could not create file"
960 $LFS hsm_set --exists $f.trunc ||
961 error "user could not change hsm flags"
962 cp /etc/group $f.trunc || error "could not override a file"
963 check_hsm_flags $f.trunc "0x00000003"
965 # Mmapped a file sets dirty
966 cp -p /etc/passwd $f.mmap || error "could not create file"
967 $LFS hsm_set --exists $f.mmap ||
968 error "user could not change hsm flags"
969 multiop $f.mmap OSMWUc || error "could not mmap a file"
970 check_hsm_flags $f.mmap "0x00000003"
972 run_test 3 "Check file dirtyness when opening for write"
976 local f=$DIR/$tdir/$tfile
977 local fid=$(make_small $f)
980 local st=$(get_request_state $fid CANCEL)
981 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
983 run_test 4 "Useless cancel must not be registered"
986 # test needs a running copytool
990 local f=$DIR/$tdir/$tfile
991 local fid=$(copy_file /etc/passwd $f)
993 wait_request_state $fid ARCHIVE SUCCEED
995 check_hsm_flags $f "0x00000009"
999 run_test 8 "Test default archive number"
1003 local f=$DIR/$tdir/$tfile
1004 local fid=$(copy_file /etc/passwd $f)
1005 # we do not use the default one to be sure
1006 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1008 copytool_setup $SINGLEAGT $MOUNT $new_an
1009 $LFS hsm_archive --archive $new_an $f
1010 wait_request_state $fid ARCHIVE SUCCEED
1012 check_hsm_flags $f "0x00000009"
1016 run_test 9 "Use of explicit archive number, with dedicated copytool"
1019 needclients 3 || return 0
1025 copytool_cleanup $(comma_list $(agts_nodes))
1027 # start all of the copytools
1028 for n in $(seq $AGTCOUNT); do
1029 copytool_setup agt$n
1032 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1035 for n in $(seq $AGTCOUNT); do
1036 file=$DIR/$tdir/$tfile.$n
1037 fid=$(make_small $file)
1039 $LFS hsm_archive $file || error "could not archive file $file"
1040 wait_request_state $fid ARCHIVE SUCCEED
1041 check_hsm_flags $file "0x00000009"
1045 copytool_cleanup $(comma_list $(agts_nodes))
1047 run_test 9a "Multiple remote agents"
1050 # test needs a running copytool
1053 mkdir -p $DIR/$tdir/d1
1054 local f=$DIR/$tdir/$tfile
1055 local fid=$(copy_file /etc/hosts $f)
1056 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1057 error "hsm_archive failed"
1058 wait_request_state $fid ARCHIVE SUCCEED
1060 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1061 error "fid $fid not in archive $HSM_ARCHIVE"
1062 echo "Verifying content"
1063 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1064 echo "Verifying hsm state "
1065 check_hsm_flags $f "0x00000009"
1067 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1068 local st=$(get_hsm_archive_id $f)
1069 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1070 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1075 run_test 10a "Archive a file"
1078 # test needs a running copytool
1082 local f=$DIR/$tdir/$tfile
1083 local fid=$(copy_file /etc/hosts $f)
1084 $LFS hsm_archive $f || error "archive request failed"
1085 wait_request_state $fid ARCHIVE SUCCEED
1087 $LFS hsm_archive $f || error "archive of non dirty file failed"
1088 local cnt=$(get_request_count $fid ARCHIVE)
1089 [[ "$cnt" == "1" ]] ||
1090 error "archive of non dirty file must not make a request"
1094 run_test 10b "Archive of non dirty file must work without doing request"
1097 # test needs a running copytool
1101 local f=$DIR/$tdir/$tfile
1102 local fid=$(copy_file /etc/hosts $f)
1103 $LFS hsm_set --noarchive $f
1104 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1108 run_test 10c "Check forbidden archive"
1111 # test needs a running copytool
1115 local f=$DIR/$tdir/$tfile
1116 local fid=$(copy_file /etc/hosts $f)
1117 $LFS hsm_archive $f || error "cannot archive $f"
1118 wait_request_state $fid ARCHIVE SUCCEED
1120 local ar=$(get_hsm_archive_id $f)
1121 local dflt=$(get_hsm_param default_archive_id)
1122 [[ $ar == $dflt ]] ||
1123 error "archived file is not on default archive: $ar != $dflt"
1127 run_test 10d "Archive a file on the default archive id"
1131 copy2archive /etc/hosts $tdir/$tfile
1132 local f=$DIR/$tdir/$tfile
1134 import_file $tdir/$tfile $f
1135 echo -n "Verifying released state: "
1136 check_hsm_flags $f "0x0000000d"
1138 local LSZ=$(stat -c "%s" $f)
1139 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1141 echo "Verifying imported size $LSZ=$ASZ"
1142 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1143 echo -n "Verifying released pattern: "
1144 local PTRN=$($GETSTRIPE -L $f)
1146 [[ $PTRN == 80000001 ]] || error "Is not released"
1147 local fid=$(path2fid $f)
1148 echo "Verifying new fid $fid in archive"
1150 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1151 error "fid $fid not in archive $HSM_ARCHIVE"
1153 run_test 11a "Import a file"
1156 # test needs a running copytool
1160 local f=$DIR/$tdir/$tfile
1161 local fid=$(copy_file /etc/hosts $f)
1162 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1163 error "hsm_archive failed"
1164 wait_request_state $fid ARCHIVE SUCCEED
1166 local FILE_HASH=$(md5sum $f)
1171 echo "$FILE_HASH" | md5sum -c
1173 [[ $? -eq 0 ]] || error "Restored file differs"
1177 run_test 11b "Import a deleted file using its FID"
1180 # test needs a running copytool
1184 copy2archive /etc/hosts $tdir/$tfile
1186 local f=$DIR/$tdir/$tfile
1187 import_file $tdir/$tfile $f
1188 local f2=$DIR2/$tdir/$tfile
1189 echo "Verifying released state: "
1190 check_hsm_flags $f2 "0x0000000d"
1192 local fid=$(path2fid $f2)
1193 $LFS hsm_restore $f2
1194 wait_request_state $fid RESTORE SUCCEED
1196 echo "Verifying file state: "
1197 check_hsm_flags $f2 "0x00000009"
1199 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1201 [[ $? -eq 0 ]] || error "Restored file differs"
1205 run_test 12a "Restore an imported file explicitly"
1208 # test needs a running copytool
1212 copy2archive /etc/hosts $tdir/$tfile
1214 local f=$DIR/$tdir/$tfile
1215 import_file $tdir/$tfile $f
1216 echo "Verifying released state: "
1217 check_hsm_flags $f "0x0000000d"
1219 cat $f > /dev/null || error "File read failed"
1221 echo "Verifying file state after restore: "
1222 check_hsm_flags $f "0x00000009"
1224 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1226 [[ $? -eq 0 ]] || error "Restored file differs"
1230 run_test 12b "Restore an imported file implicitly"
1233 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1235 # test needs a running copytool
1239 local f=$DIR/$tdir/$tfile
1240 $LFS setstripe -c 2 $f
1242 fid=$(make_large_for_striping $f)
1243 [ $? != 0 ] && skip "not enough free space" && return
1245 local FILE_CRC=$(md5sum $f)
1247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1248 wait_request_state $fid ARCHIVE SUCCEED
1249 $LFS hsm_release $f || error "release $f failed"
1251 echo "$FILE_CRC" | md5sum -c
1253 [[ $? -eq 0 ]] || error "Restored file differs"
1257 run_test 12c "Restore a file with stripe of 2"
1260 # test needs a running copytool
1265 local f=$DIR/$tdir/$tfile
1266 local fid=$(copy_file /etc/hosts $f)
1267 $LFS hsm_restore $f || error "restore of non archived file failed"
1268 local cnt=$(get_request_count $fid RESTORE)
1269 [[ "$cnt" == "0" ]] ||
1270 error "restore non archived must not make a request"
1271 $LFS hsm_archive $f ||
1272 error "archive request failed"
1273 wait_request_state $fid ARCHIVE SUCCEED
1274 $LFS hsm_restore $f ||
1275 error "restore of non released file failed"
1276 local cnt=$(get_request_count $fid RESTORE)
1277 [[ "$cnt" == "0" ]] ||
1278 error "restore a non dirty file must not make a request"
1282 run_test 12d "Restore of a non archived, non released file must work"\
1283 " without doing request"
1286 # test needs a running copytool
1289 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1290 local f=$DIR/$tdir/$tfile
1291 local fid=$(copy_file /etc/hosts $f)
1292 $LFS hsm_archive $f || error "archive request failed"
1293 wait_request_state $fid ARCHIVE SUCCEED
1296 cat /etc/hosts >> $f
1300 $LFS hsm_restore $f && error "restore a dirty file must fail"
1304 run_test 12e "Check forbidden restore"
1307 # test needs a running copytool
1311 local f=$DIR/$tdir/$tfile
1312 local fid=$(copy_file /etc/hosts $f)
1314 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1315 wait_request_state $fid ARCHIVE SUCCEED
1316 $LFS hsm_release $f || error "release of $f failed"
1318 wait_request_state $fid RESTORE SUCCEED
1320 echo -n "Verifying file state: "
1321 check_hsm_flags $f "0x00000009"
1323 diff -q /etc/hosts $f
1325 [[ $? -eq 0 ]] || error "Restored file differs"
1329 run_test 12f "Restore a released file explicitly"
1332 # test needs a running copytool
1336 local f=$DIR/$tdir/$tfile
1337 local fid=$(copy_file /etc/hosts $f)
1339 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1340 wait_request_state $fid ARCHIVE SUCCEED
1341 $LFS hsm_release $f || error "release of $f failed"
1343 diff -q /etc/hosts $f
1346 # we check we had a restore done
1347 wait_request_state $fid RESTORE SUCCEED
1349 [[ $st -eq 0 ]] || error "Restored file differs"
1353 run_test 12g "Restore a released file implicitly"
1356 needclients 2 || return 0
1358 # test needs a running copytool
1362 local f=$DIR/$tdir/$tfile
1363 local fid=$(copy_file /etc/hosts $f)
1365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1366 wait_request_state $fid ARCHIVE SUCCEED
1367 $LFS hsm_release $f || error "release of $f failed"
1369 do_node $CLIENT2 diff -q /etc/hosts $f
1372 # we check we had a restore done
1373 wait_request_state $fid RESTORE SUCCEED
1375 [[ $st -eq 0 ]] || error "Restored file differs"
1379 run_test 12h "Restore a released file implicitly from a second node"
1382 # test needs a running copytool
1386 local f=$DIR/$tdir/$tfile
1387 local fid=$(copy_file /etc/passwd $f)
1388 $LFS hsm_archive $f || error "archive of $f failed"
1389 wait_request_state $fid ARCHIVE SUCCEED
1391 $LFS hsm_release $f || error "release of $f failed"
1395 [[ $? -eq 0 ]] || error "Restored file differs"
1399 run_test 12m "Archive/release/implicit restore"
1402 # test needs a running copytool
1406 copy2archive /etc/hosts $tdir/$tfile
1408 local f=$DIR/$tdir/$tfile
1409 import_file $tdir/$tfile $f
1411 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1412 error "Restored file differs"
1414 $LFS hsm_release $f || error "release of $f failed"
1418 run_test 12n "Import/implicit restore/release"
1421 # test needs a running copytool
1425 local f=$DIR/$tdir/$tfile
1426 local fid=$(copy_file /etc/hosts $f)
1428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1429 wait_request_state $fid ARCHIVE SUCCEED
1430 $LFS hsm_release $f || error "release of $f failed"
1432 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1433 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1435 # set no retry action mode
1438 diff -q /etc/hosts $f
1441 # we check we had a restore failure
1442 wait_request_state $fid RESTORE FAILED
1444 [[ $st -eq 0 ]] && error "Restore must fail"
1446 # remove no retry action mode
1449 # check file is still released
1450 check_hsm_flags $f "0x0000000d"
1452 # retry w/o failure injection
1453 do_facet $SINGLEMDS lctl set_param fail_loc=0
1455 # to be sure previous RESTORE result is gone
1457 wait_for_grace_delay
1459 diff -q /etc/hosts $f
1462 # we check we had a restore done
1463 wait_request_state $fid RESTORE SUCCEED
1465 [[ $st -eq 0 ]] || error "Restored file differs"
1469 run_test 12o "Layout-swap failure during Restore leaves file released"
1472 # test needs a running copytool
1476 local f=$DIR/$tdir/$tfile
1477 local fid=$(copy_file /etc/hosts $f)
1479 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1480 wait_request_state $fid ARCHIVE SUCCEED
1481 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1482 $LFS hsm_release $f || error "cannot release $f"
1483 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1484 $LFS hsm_release $f || error "cannot release $f"
1485 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1489 run_test 12p "implicit restore of a file on copytool mount point"
1491 cleanup_test_12q() {
1493 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1494 error "cannot umount $MOUNT3 on $SINGLEAGT"
1498 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1499 skip "need MDS version at least 2.7.58" && return 0
1501 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1502 error "cannot mount $MOUNT3 on $SINGLEAGT"
1504 trap cleanup_test_12q EXIT
1506 # test needs a running copytool
1507 copytool_setup $SINGLEAGT $MOUNT3
1510 local f=$DIR/$tdir/$tfile
1511 local f2=$DIR2/$tdir/$tfile
1512 local fid=$(make_small $f)
1513 local orig_size=$(stat -c "%s" $f)
1515 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1516 wait_request_state $fid ARCHIVE SUCCEED
1518 $LFS hsm_release $f || error "could not release file"
1519 check_hsm_flags $f "0x0000000d"
1522 wait_copytools || error "copytool failed to stop"
1524 cat $f > /dev/null &
1526 # wait a bit to allow implicit restore request to be handled.
1527 # if not, next stat would also block on layout-lock.
1530 local size=$(stat -c "%s" $f2)
1531 [ $size -eq $orig_size ] ||
1532 error "$f2: wrong size after archive: $size != $orig_size"
1534 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1538 size=$(stat -c "%s" $f)
1539 [ $size -eq $orig_size ] ||
1540 error "$f: wrong size after restore: $size != $orig_size"
1542 size=$(stat -c "%s" $f2)
1543 [ $size -eq $orig_size ] ||
1544 error "$f2: wrong size after restore: $size != $orig_size"
1548 size=$(stat -c "%s" $f)
1550 error "$f: wrong size after overwrite: $size != 0"
1552 size=$(stat -c "%s" $f2)
1554 error "$f2: wrong size after overwrite: $size != 0"
1557 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1558 error "cannot umount $MOUNT3 on $SINGLEAGT"
1560 run_test 12q "file attributes are refreshed after restore"
1563 # test needs a running copytool
1566 local ARC_SUBDIR="import.orig"
1570 # populate directory to be imported
1571 for d in $(seq 1 10); do
1572 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1573 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1574 for f in $(seq 1 10); do
1575 CURR_FILE="$CURR_DIR/$tfile.$f"
1576 # write file-specific data
1577 do_facet $SINGLEAGT \
1578 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1579 "file=$CURR_FILE > $CURR_FILE"
1583 import_file "$ARC_SUBDIR" $DIR/$tdir
1584 # diff lustre content and origin (triggers file restoration)
1585 # there must be 10x10 identical files, and no difference
1586 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1587 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1588 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1589 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1591 [ $cnt_diff -eq 0 ] ||
1592 error "$cnt_diff imported files differ from read data"
1593 [ $cnt_ok -eq 100 ] ||
1594 error "not enough identical files ($cnt_ok != 100)"
1598 run_test 13 "Recursively import and restore a directory"
1601 # test needs a running copytool
1606 local f=$DIR/$tdir/$tfile
1607 local fid=$(make_small $f)
1608 local sum=$(md5sum $f | awk '{print $1}')
1609 $LFS hsm_archive $f || error "could not archive file"
1610 wait_request_state $fid ARCHIVE SUCCEED
1614 # create released file (simulate llapi_hsm_import call)
1616 local fid2=$(path2fid $f)
1617 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1618 $LFS hsm_release $f || error "could not release file"
1620 # rebind the archive to the newly created file
1621 echo "rebind $fid to $fid2"
1623 do_facet $SINGLEAGT \
1624 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1625 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1627 # restore file and compare md5sum
1628 local sum2=$(md5sum $f | awk '{print $1}')
1630 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1634 run_test 14 "Rebind archived file to a new fid"
1637 # test needs a running copytool
1642 local f=$DIR/$tdir/$tfile
1644 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1648 for i in $(seq 1 $count); do
1649 fids[$i]=$(make_small $f.$i)
1650 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1651 $LFS hsm_archive $f.$i || error "could not archive file"
1653 wait_all_done $(($count*60))
1657 for i in $(seq 1 $count); do
1660 local fid2=$(path2fid $f.$i)
1661 # add the rebind operation to the list
1662 echo ${fids[$i]} $fid2 >> $tmpfile
1664 # set it released (simulate llapi_hsm_import call)
1665 $LFS hsm_set --archived --exists $f.$i ||
1666 error "could not force hsm flags"
1667 $LFS hsm_release $f.$i || error "could not release file"
1669 nl=$(wc -l < $tmpfile)
1670 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1672 echo "rebind list of files"
1673 do_facet $SINGLEAGT \
1674 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1675 --rebind $tmpfile $DIR" || error "could not rebind file list"
1677 # restore files and compare md5sum
1678 for i in $(seq 1 $count); do
1679 local sum2=$(md5sum $f.$i | awk '{print $1}')
1680 [[ $sum2 == ${sums[$i]} ]] ||
1681 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1687 run_test 15 "Rebind a list of files"
1690 # test needs a running copytool
1694 # create a known size file so we can verify transfer speed
1697 dd if=/dev/zero of=$ref bs=1M count=20
1700 local f=$DIR/$tdir/$tfile
1701 local fid=$(copy_file $ref $f)
1703 local start=$(date +%s)
1705 wait_request_state $fid ARCHIVE SUCCEED
1706 local end=$(date +%s)
1707 local duration=$((end - start))
1709 [[ $duration -ge $goal ]] ||
1710 error "Transfer is too fast $duration < $goal"
1714 run_test 16 "Test CT bandwith control option"
1719 local f=$DIR/$tdir/$tfile
1720 touch $f || error "touch $f failed"
1722 # Could not release a non-archived file
1723 $LFS hsm_release $f && error "release should not succeed"
1725 # For following tests, we must test them with HS_ARCHIVED set
1726 $LFS hsm_set --exists --archived $f || error "could not add flag"
1728 # Could not release a file if no-release is set
1729 $LFS hsm_set --norelease $f || error "could not add flag"
1730 $LFS hsm_release $f && error "release should not succeed"
1731 $LFS hsm_clear --norelease $f || error "could not remove flag"
1733 # Could not release a file if lost
1734 $LFS hsm_set --lost $f || error "could not add flag"
1735 $LFS hsm_release $f && error "release should not succeed"
1736 $LFS hsm_clear --lost $f || error "could not remove flag"
1738 # Could not release a file if dirty
1739 $LFS hsm_set --dirty $f || error "could not add flag"
1740 $LFS hsm_release $f && error "release should not succeed"
1741 $LFS hsm_clear --dirty $f || error "could not remove flag"
1743 run_test 20 "Release is not permitted"
1746 # test needs a running copytool
1750 local f=$DIR/$tdir/test_release
1752 # Create a file and check its states
1753 local fid=$(make_small $f)
1754 check_hsm_flags $f "0x00000000"
1756 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1757 # used until file is flushed to disk
1758 if [ $(facet_fstype ost1) == "zfs" ]; then
1759 # this causes an OST_SYNC rpc to be sent
1760 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1761 # clear locks to reread file data
1762 cancel_lru_locks osc
1765 local orig_size=$(stat -c "%s" $f)
1766 local orig_blocks=$(stat -c "%b" $f)
1768 start_full_debug_logging
1770 $LFS hsm_archive $f || error "could not archive file"
1771 wait_request_state $fid ARCHIVE SUCCEED
1773 local blocks=$(stat -c "%b" $f)
1774 [ $blocks -eq $orig_blocks ] ||
1775 error "$f: wrong block number after archive: " \
1776 "$blocks != $orig_blocks"
1777 local size=$(stat -c "%s" $f)
1778 [ $size -eq $orig_size ] ||
1779 error "$f: wrong size after archive: $size != $orig_size"
1781 # Release and check states
1782 $LFS hsm_release $f || error "could not release file"
1783 check_hsm_flags $f "0x0000000d"
1785 blocks=$(stat -c "%b" $f)
1786 [ $blocks -gt 5 ] &&
1787 error "$f: too many blocks after release: $blocks > 5"
1788 size=$(stat -c "%s" $f)
1789 [ $size -ne $orig_size ] &&
1790 error "$f: wrong size after release: $size != $orig_size"
1792 # Check we can release an file without stripe info
1796 check_hsm_flags $f "0x00000000"
1797 $LFS hsm_archive $f || error "could not archive file"
1798 wait_request_state $fid ARCHIVE SUCCEED
1800 # Release and check states
1801 $LFS hsm_release $f || error "could not release file"
1802 check_hsm_flags $f "0x0000000d"
1804 # Release again a file that is already released is OK
1805 $LFS hsm_release $f || fail "second release should succeed"
1806 check_hsm_flags $f "0x0000000d"
1808 stop_full_debug_logging
1812 run_test 21 "Simple release tests"
1815 # test needs a running copytool
1820 local f=$DIR/$tdir/test_release
1821 local swap=$DIR/$tdir/test_swap
1823 # Create a file and check its states
1824 local fid=$(make_small $f)
1825 check_hsm_flags $f "0x00000000"
1827 $LFS hsm_archive $f || error "could not archive file"
1828 wait_request_state $fid ARCHIVE SUCCEED
1830 # Release and check states
1831 $LFS hsm_release $f || error "could not release file"
1832 check_hsm_flags $f "0x0000000d"
1835 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1840 run_test 22 "Could not swap a release file"
1843 # test needs a running copytool
1848 local f=$DIR/$tdir/test_mtime
1850 # Create a file and check its states
1851 local fid=$(make_small $f)
1852 check_hsm_flags $f "0x00000000"
1854 $LFS hsm_archive $f || error "could not archive file"
1855 wait_request_state $fid ARCHIVE SUCCEED
1857 # Set modification time in the past
1858 touch -m -a -d @978261179 $f
1860 # Release and check states
1861 $LFS hsm_release $f || error "could not release file"
1862 check_hsm_flags $f "0x0000000d"
1864 local MTIME=$(stat -c "%Y" $f)
1865 local ATIME=$(stat -c "%X" $f)
1866 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1867 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1871 run_test 23 "Release does not change a/mtime (utime)"
1874 local file=$DIR/$tdir/$tfile
1883 # test needs a running copytool
1888 fid=$(make_small $file)
1890 # Create a file and check its states
1891 check_hsm_flags $file "0x00000000"
1893 # Ensure atime is less than mtime and ctime.
1897 atime0=$(stat -c "%X" $file)
1898 mtime0=$(stat -c "%Y" $file)
1899 ctime0=$(stat -c "%Z" $file)
1901 [ $atime0 -lt $mtime0 ] ||
1902 error "atime $atime0 is not less than mtime $mtime0"
1904 [ $atime0 -lt $ctime0 ] ||
1905 error "atime $atime0 is not less than ctime $ctime0"
1907 # Archive should not change any timestamps.
1908 $LFS hsm_archive $file || error "cannot archive '$file'"
1909 wait_request_state $fid ARCHIVE SUCCEED
1911 atime1=$(stat -c "%X" $file)
1912 mtime1=$(stat -c "%Y" $file)
1913 ctime1=$(stat -c "%Z" $file)
1915 [ $atime0 -eq $atime1 ] ||
1916 error "archive changed atime from $atime0 to $atime1"
1918 [ $mtime0 -eq $mtime1 ] ||
1919 error "archive changed mtime from $mtime0 to $mtime1"
1921 [ $ctime0 -eq $ctime1 ] ||
1922 error "archive changed ctime from $ctime0 to $ctime1"
1924 # Release should not change any timestamps.
1925 $LFS hsm_release $file || error "cannot release '$file'"
1926 check_hsm_flags $file "0x0000000d"
1928 atime1=$(stat -c "%X" $file)
1929 mtime1=$(stat -c "%Y" $file)
1930 ctime1=$(stat -c "%Z" $file)
1932 [ $atime0 -eq $atime1 ] ||
1933 error "release changed atime from $atime0 to $atime1"
1935 [ $mtime0 -eq $mtime1 ] ||
1936 error "release changed mtime from $mtime0 to $mtime1"
1938 [ $ctime0 -eq $ctime1 ] ||
1939 error "release changed ctime from $ctime0 to $ctime1"
1941 # Restore should not change any timestamps.
1942 $LFS hsm_restore $file
1943 wait_request_state $fid RESTORE SUCCEED
1945 atime1=$(stat -c "%X" $file)
1946 mtime1=$(stat -c "%Y" $file)
1947 ctime1=$(stat -c "%Z" $file)
1949 [ $atime0 -eq $atime1 ] ||
1950 error "restore changed atime from $atime0 to $atime1"
1952 [ $mtime0 -eq $mtime1 ] ||
1953 error "restore changed mtime from $mtime0 to $mtime1"
1955 [ $ctime0 -eq $ctime1 ] ||
1956 error "restore changed ctime from $ctime0 to $ctime1"
1960 # Once more, after unmount and mount.
1961 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1962 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1964 atime1=$(stat -c "%X" $file)
1965 mtime1=$(stat -c "%Y" $file)
1966 ctime1=$(stat -c "%Z" $file)
1968 [ $atime0 -eq $atime1 ] ||
1969 error "remount changed atime from $atime0 to $atime1"
1971 [ $mtime0 -eq $mtime1 ] ||
1972 error "remount changed mtime from $mtime0 to $mtime1"
1974 [ $ctime0 -eq $ctime1 ] ||
1975 error "remount changed ctime from $ctime0 to $ctime1"
1977 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1980 local file=$DIR/$tdir/$tfile
1986 # Test needs a running copytool.
1990 # Check that root can do HSM actions on a regular user's file.
1992 fid=$(make_small $file)
1993 sum0=$(md5sum $file)
1995 chown $RUNAS_ID:$RUNAS_GID $file ||
1996 error "cannot chown '$file' to '$RUNAS_ID'"
1998 chmod ugo-w $DIR/$tdir ||
1999 error "cannot chmod '$DIR/$tdir'"
2001 $LFS hsm_archive $file
2002 wait_request_state $fid ARCHIVE SUCCEED
2004 $LFS hsm_release $file
2005 check_hsm_flags $file "0x0000000d"
2007 $LFS hsm_restore $file
2008 wait_request_state $fid RESTORE SUCCEED
2010 # Check that ordinary user can get HSM state.
2011 $RUNAS $LFS hsm_state $file ||
2012 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2014 $LFS hsm_release $file
2015 check_hsm_flags $file "0x0000000d"
2017 # Check that ordinary user can accessed released file.
2018 sum1=$($RUNAS md5sum $file) ||
2019 error "user '$RUNAS_ID' cannot read '$file'"
2021 [ "$sum0" == "$sum1" ] ||
2022 error "md5sum mismatch for '$file'"
2026 run_test 24b "root can archive, release, and restore user files"
2028 cleanup_test_24c() {
2030 set_hsm_param user_request_mask RESTORE
2031 set_hsm_param group_request_mask RESTORE
2032 set_hsm_param other_request_mask RESTORE
2036 local file=$DIR/$tdir/$tfile
2037 local action=archive
2042 # test needs a running copytool
2047 # Save the default masks and check that cleanup_24c will
2048 # restore the request masks correctly.
2049 user_save=$(get_hsm_param user_request_mask)
2050 group_save=$(get_hsm_param group_request_mask)
2051 other_save=$(get_hsm_param other_request_mask)
2053 [ "$user_save" == RESTORE ] ||
2054 error "user_request_mask is '$user_save' expected 'RESTORE'"
2055 [ "$group_save" == RESTORE ] ||
2056 error "group_request_mask is '$group_save' expected 'RESTORE'"
2057 [ "$other_save" == RESTORE ] ||
2058 error "other_request_mask is '$other_save' expected 'RESTORE'"
2060 trap cleanup_test_24c EXIT
2065 chown $RUNAS_ID:nobody $file ||
2066 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2068 set_hsm_param user_request_mask ""
2069 $RUNAS $LFS hsm_$action $file &&
2070 error "$action by user should fail"
2072 set_hsm_param user_request_mask $action
2073 $RUNAS $LFS hsm_$action $file ||
2074 error "$action by user should succeed"
2079 chown nobody:$RUNAS_GID $file ||
2080 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2082 set_hsm_param group_request_mask ""
2083 $RUNAS $LFS hsm_$action $file &&
2084 error "$action by group should fail"
2086 set_hsm_param group_request_mask $action
2087 $RUNAS $LFS hsm_$action $file ||
2088 error "$action by group should succeed"
2093 chown nobody:nobody $file ||
2094 error "cannot chown '$file' to 'nobody:nobody'"
2096 set_hsm_param other_request_mask ""
2097 $RUNAS $LFS hsm_$action $file &&
2098 error "$action by other should fail"
2100 set_hsm_param other_request_mask $action
2101 $RUNAS $LFS hsm_$action $file ||
2102 error "$action by other should succeed"
2107 run_test 24c "check that user,group,other request masks work"
2109 cleanup_test_24d() {
2111 mount -o remount,rw $MOUNT2
2115 local file1=$DIR/$tdir/$tfile
2116 local file2=$DIR2/$tdir/$tfile
2124 fid1=$(make_small $file1)
2126 trap cleanup_test_24d EXIT
2128 mount -o remount,ro $MOUNT2
2130 fid2=$(path2fid $file2)
2131 [ "$fid1" == "$fid2" ] ||
2132 error "FID mismatch '$fid1' != '$fid2'"
2134 $LFS hsm_archive $file2 &&
2135 error "archive should fail on read-only mount"
2136 check_hsm_flags $file1 "0x00000000"
2138 $LFS hsm_archive $file1
2139 wait_request_state $fid1 ARCHIVE SUCCEED
2141 $LFS hsm_release $file1
2142 $LFS hsm_restore $file2
2143 wait_request_state $fid1 RESTORE SUCCEED
2145 $LFS hsm_release $file1 || error "cannot release '$file1'"
2146 dd if=$file2 of=/dev/null bs=1M || "cannot read '$file2'"
2148 $LFS hsm_release $file2 &&
2149 error "release should fail on read-only mount"
2154 run_test 24d "check that read-only mounts are respected"
2161 local f=$DIR/$tdir/$tfile
2164 fid=$(make_small $f) || error "cannot create $f"
2165 $LFS hsm_archive $f || error "cannot archive $f"
2166 wait_request_state $fid ARCHIVE SUCCEED
2167 $LFS hsm_release $f || error "cannot release $f"
2168 while ! $LFS hsm_state $f | grep released; do
2172 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2176 run_test 24e "tar succeeds on HSM released files" # LU-6213
2180 # test needs a running copytool
2183 mkdir -p $DIR/$tdir/d1
2184 local f=$DIR/$tdir/$tfile
2185 local fid=$(copy_file /etc/hosts $f)
2188 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2189 error "hsm_archive failed"
2190 wait_request_state $fid ARCHIVE SUCCEED
2191 $LFS hsm_release $f || error "cannot release $f"
2192 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2195 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2196 error "Can not recover the tar contents"
2198 echo "Sum0 = $sum0, sum1 = $sum1"
2199 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2203 run_test 24f "root can archive, release, and restore tar files"
2206 # test needs a running copytool
2210 copy2archive /etc/hosts $tdir/$tfile
2212 local f=$DIR/$tdir/$tfile
2214 import_file $tdir/$tfile $f
2216 $LFS hsm_set --lost $f
2221 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2225 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2226 " (Operation not permitted)"
2229 # test needs a running copytool
2234 local f=$DIR/$tdir/$tfile
2235 local fid=$(copy_file /etc/passwd $f)
2237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2238 wait_request_state $fid ARCHIVE SUCCEED
2241 $LFS hsm_set --lost $f
2245 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2249 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2250 " (Operation not permitted)"
2253 # test needs a running copytool
2257 local f=$DIR/$tdir/$tfile
2259 fid=$(make_large_for_progress $f)
2260 [ $? != 0 ] && skip "not enough free space" && return
2262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2263 wait_request_state $fid ARCHIVE SUCCEED
2266 wait_request_state $fid REMOVE SUCCEED
2268 check_hsm_flags $f "0x00000000"
2272 run_test 26 "Remove the archive of a valid file"
2275 # test needs a running copytool
2279 make_archive $tdir/$tfile
2280 local f=$DIR/$tdir/$tfile
2281 import_file $tdir/$tfile $f
2282 local fid=$(path2fid $f)
2286 [[ $? != 0 ]] || error "Remove of a released file should fail"
2290 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2293 # test needs a running copytool
2297 local f=$DIR/$tdir/$tfile
2299 fid=$(make_large_for_progress $f)
2300 [ $? != 0 ] && skip "not enough free space" && return
2302 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2303 wait_request_state $fid ARCHIVE SUCCEED
2308 [[ $? != 0 ]] || error "Remove of a released file should fail"
2312 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2315 # test needs a running copytool
2319 local f=$DIR/$tdir/$tfile
2321 fid=$(make_large_for_progress $f)
2322 [ $? != 0 ] && skip "not enough free space" && return
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2325 wait_request_state $fid ARCHIVE SUCCEED
2334 wait_request_state $fid REMOVE SUCCEED
2338 run_test 28 "Concurrent archive/file remove"
2341 # Tests --mntpath and --archive options
2344 copytool_setup $SINGLEAGT $MOUNT $archive_id
2346 # Bad archive number
2347 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2348 grep "Invalid argument" ||
2349 error "unexpected hsm_remove failure (1)"
2351 # mntpath is present but file is given
2352 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2353 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2354 error "unexpected hsm_remove failure (2)"
2358 run_test 29a "Tests --mntpath and --archive options"
2361 # test needs a running copytool
2365 local f=$DIR/$tdir/$tfile
2366 local fid=$(make_small $f)
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2369 wait_request_state $fid ARCHIVE SUCCEED
2373 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2374 wait_request_state $fid REMOVE SUCCEED
2378 run_test 29b "Archive/delete/remove by FID from the archive."
2381 # test needs a running copytool
2385 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2386 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2387 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2389 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2390 wait_request_state $fid1 ARCHIVE SUCCEED
2391 wait_request_state $fid2 ARCHIVE SUCCEED
2392 wait_request_state $fid3 ARCHIVE SUCCEED
2394 rm -f $DIR/$tdir/$tfile-[1-3]
2396 echo $fid1 > $DIR/$tdir/list
2397 echo $fid2 >> $DIR/$tdir/list
2398 echo $fid3 >> $DIR/$tdir/list
2400 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2401 --filelist $DIR/$tdir/list
2402 wait_request_state $fid1 REMOVE SUCCEED
2403 wait_request_state $fid2 REMOVE SUCCEED
2404 wait_request_state $fid3 REMOVE SUCCEED
2408 run_test 29c "Archive/delete/remove by FID, using a file list."
2411 # restore at exec cannot work on agent node (because of Linux kernel
2412 # protection of executables)
2413 needclients 2 || return 0
2415 # test needs a running copytool
2419 copy2archive /bin/true $tdir/$tfile
2421 local f=$DIR/$tdir/true
2422 import_file $tdir/$tfile $f
2424 local fid=$(path2fid $f)
2426 # set no retry action mode
2432 # remove no try action mode
2436 [[ $st == 0 ]] || error "Failed to exec a released file"
2440 run_test 30a "Restore at exec (import case)"
2443 # restore at exec cannot work on agent node (because of Linux kernel
2444 # protection of executables)
2445 needclients 2 || return 0
2447 # test needs a running copytool
2451 local f=$DIR/$tdir/true
2452 local fid=$(copy_file /bin/true $f)
2454 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2455 wait_request_state $fid ARCHIVE SUCCEED
2458 # set no retry action mode
2464 # remove no try action mode
2468 [[ $st == 0 ]] || error "Failed to exec a released file"
2472 run_test 30b "Restore at exec (release case)"
2475 needclients 2 || return 0
2477 # test needs a running copytool
2481 local f=$DIR/$tdir/SLEEP
2482 local slp_sum1=$(md5sum /bin/sleep)
2483 local fid=$(copy_file /bin/sleep $f)
2485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2486 wait_request_state $fid ARCHIVE SUCCEED
2488 check_hsm_flags $f "0x0000000d"
2489 # set no retry action mode
2491 do_node $CLIENT2 "$f 10" &
2495 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2497 [[ $? == 0 ]] || error "Execution failed during run"
2499 if [[ $? != 0 ]]; then
2500 local slp_sum2=$(md5sum /bin/sleep)
2501 # in case sleep file is modified during the test
2502 [[ $slp_sum1 == $slp_sum2 ]] &&
2503 error "Binary overwritten during exec"
2507 # remove no try action mode
2509 check_hsm_flags $f "0x00000009"
2513 run_test 30c "Update during exec of released file must fail"
2515 restore_and_check_size() {
2518 local s=$(stat -c "%s" $f)
2520 local st=$(get_hsm_flags $f)
2524 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2526 n=$(stat -c "%s" $f)
2527 # we echo in both cases to show stat is not
2529 if [[ $n != $s ]]; then
2530 echo "size seen is $n != $s"
2533 echo "size seen is right: $n == $s"
2535 st=$(get_hsm_flags $f)
2539 if [[ $cpt -lt 10 ]]; then
2542 echo " restore is too long"
2543 wait_request_state $fid RESTORE SUCCEED
2549 # test needs a running copytool
2554 make_archive $tdir/$tfile
2555 local f=$DIR/$tdir/$tfile
2556 import_file $tdir/$tfile $f
2557 local fid=$($LFS path2fid $f)
2558 HSM_ARCHIVE_PURGE=false copytool_setup
2560 restore_and_check_size $f $fid
2563 [[ $err -eq 0 ]] || error "File size changed during restore"
2567 run_test 31a "Import a large file and check size during restore"
2571 # test needs a running copytool
2576 local f=$DIR/$tdir/$tfile
2578 fid=$(make_large_for_progress $f)
2579 [ $? != 0 ] && skip "not enough free space" && return
2581 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2582 wait_request_state $fid ARCHIVE SUCCEED
2585 restore_and_check_size $f $fid
2588 [[ $err -eq 0 ]] || error "File size changed during restore"
2592 run_test 31b "Restore a large unaligned file and check size during restore"
2595 # test needs a running copytool
2600 local f=$DIR/$tdir/$tfile
2602 fid=$(make_large_for_progress_aligned $f)
2603 [ $? != 0 ] && skip "not enough free space" && return
2605 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2606 wait_request_state $fid ARCHIVE SUCCEED
2609 restore_and_check_size $f $fid
2612 [[ $err -eq 0 ]] || error "File size changed during restore"
2616 run_test 31c "Restore a large aligned file and check size during restore"
2619 # test needs a running copytool
2624 local f=$DIR/$tdir/$tfile
2626 fid=$(make_large_for_progress $f)
2627 [ $? != 0 ] && skip "not enough free space" && return
2629 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2630 wait_request_state $fid ARCHIVE SUCCEED
2633 # to be sure wait_all_done will not be mislead by previous tests
2636 wait_for_grace_delay
2637 # Also raise grace_delay significantly so the Canceled
2638 # Restore action will stay enough long avail.
2639 local old_grace=$(get_hsm_param grace_delay)
2640 set_hsm_param grace_delay 100
2642 md5sum $f >/dev/null &
2644 wait_request_state $fid RESTORE STARTED
2649 # Check restore trigger process was killed
2650 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2654 # instead of waiting+checking both Restore and Cancel ops
2655 # sequentially, wait for both to be finished and then check
2657 wait_all_done 100 $fid
2658 local rstate=$(get_request_state $fid RESTORE)
2659 local cstate=$(get_request_state $fid CANCEL)
2661 # restore orig grace_delay.
2662 set_hsm_param grace_delay $old_grace
2664 if [[ "$rstate" == "CANCELED" ]] ; then
2665 [[ "$cstate" == "SUCCEED" ]] ||
2666 error "Restore state is CANCELED and Cancel state " \
2667 "is not SUCCEED but $cstate"
2668 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2669 elif [[ "$rstate" == "SUCCEED" ]] ; then
2670 [[ "$cstate" == "FAILED" ]] ||
2671 error "Restore state is SUCCEED and Cancel state " \
2672 "is not FAILED but $cstate"
2673 echo "Restore state is SUCCEED, Cancel state is FAILED"
2675 error "Restore state is $rstate and Cancel state is $cstate"
2679 error "Cannot kill process waiting for restore ($killed)"
2683 run_test 33 "Kill a restore waiting process"
2686 # test needs a running copytool
2691 local f=$DIR/$tdir/$tfile
2693 fid=$(make_large_for_progress $f)
2694 [ $? != 0 ] && skip "not enough free space" && return
2696 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2697 wait_request_state $fid ARCHIVE SUCCEED
2700 md5sum $f >/dev/null &
2702 wait_request_state $fid RESTORE STARTED
2704 rm $f || error "rm $f failed"
2705 # rm must not block during restore
2706 wait_request_state $fid RESTORE STARTED
2708 wait_request_state $fid RESTORE SUCCEED
2709 # check md5sum pgm finished
2710 local there=$(ps -o pid,comm hp $pid >/dev/null)
2711 [[ -z $there ]] || error "Restore initiator does not exit"
2713 local rc=$(wait $pid)
2714 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2718 run_test 34 "Remove file during restore"
2721 # test needs a running copytool
2726 local f=$DIR/$tdir/$tfile
2727 local f1=$DIR/$tdir/$tfile-1
2729 fid=$(make_large_for_progress $f)
2730 [ $? != 0 ] && skip "not enough free space" && return
2732 local fid1=$(copy_file /etc/passwd $f1)
2733 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2734 wait_request_state $fid ARCHIVE SUCCEED
2737 md5sum $f >/dev/null &
2739 wait_request_state $fid RESTORE STARTED
2741 mv $f1 $f || error "mv $f1 $f failed"
2742 # mv must not block during restore
2743 wait_request_state $fid RESTORE STARTED
2745 wait_request_state $fid RESTORE SUCCEED
2746 # check md5sum pgm finished
2747 local there=$(ps -o pid,comm hp $pid >/dev/null)
2748 [[ -z $there ]] || error "Restore initiator does not exit"
2750 local rc=$(wait $pid)
2751 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2754 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2758 run_test 35 "Overwrite file during restore"
2761 # test needs a running copytool
2766 local f=$DIR/$tdir/$tfile
2768 fid=$(make_large_for_progress $f)
2769 [ $? != 0 ] && skip "not enough free space" && return
2771 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2772 wait_request_state $fid ARCHIVE SUCCEED
2775 md5sum $f >/dev/null &
2777 wait_request_state $fid RESTORE STARTED
2780 # rm must not block during restore
2781 wait_request_state $fid RESTORE STARTED
2783 wait_request_state $fid RESTORE SUCCEED
2784 # check md5sum pgm finished
2785 local there=$(ps -o pid,comm hp $pid >/dev/null)
2787 error "Restore initiator does not exit"
2789 local rc=$(wait $pid)
2791 error "Restore initiator failed with $rc"
2795 run_test 36 "Move file during restore"
2798 # LU-5683: check that an archived dirty file can be rearchived.
2800 copytool_setup $SINGLEAGT $MOUNT2
2803 local f=$DIR/$tdir/$tfile
2806 fid=$(make_small $f) || error "cannot create small file"
2808 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2809 wait_request_state $fid ARCHIVE SUCCEED
2810 $LFS hsm_release $f || error "cannot release $f"
2813 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2815 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2816 wait_request_state $fid ARCHIVE SUCCEED
2820 run_test 37 "re-archive a dirty file"
2827 for n in $(seq 1 $count); do
2828 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2830 echo "$count archive requests submitted"
2834 local stream_count=4
2835 local file_count=100
2837 local f=$DIR/$tdir/$tfile
2842 for i in $(seq 1 $file_count); do
2843 for p in $(seq 1 $stream_count); do
2844 fid=$(copy_file /etc/hosts $f.$p.$i)
2847 # force copytool to use a local/temp archive dir to ensure best
2848 # performance vs remote/NFS mounts used in auto-tests
2849 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2852 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2854 # to be sure wait_all_done will not be mislead by previous tests
2856 wait_for_grace_delay
2858 # start archive streams in background (archive files in parallel)
2859 for p in $(seq 1 $stream_count); do
2860 multi_archive $f.$p $file_count &
2863 echo -n "Wait for all requests being enqueued..."
2869 run_test 40 "Parallel archive requests"
2872 # test needs a running copytool
2876 local f=$DIR/$tdir/$tfile
2877 local fid=$(copy_file /etc/motd $f 1)
2879 $LFS hsm_archive $f || error "could not archive file"
2880 wait_request_state $fid ARCHIVE SUCCEED
2881 check_hsm_flags $f "0x00000009"
2883 multiop_bg_pause $f O_c || error "multiop failed"
2887 client_up || client_up || true
2889 kill -USR1 $MULTIPID
2890 wait $MULTIPID || error "multiop close failed"
2892 check_hsm_flags $f "0x0000000b"
2896 run_test 52 "Opened for write file on an evicted client should be set dirty"
2899 # test needs a running copytool
2903 local f=$DIR/$tdir/$tfile
2904 local fid=$(copy_file /etc/motd $f 1)
2906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2907 error "could not archive file"
2908 wait_request_state $fid ARCHIVE SUCCEED
2909 check_hsm_flags $f "0x00000009"
2911 multiop_bg_pause $f o_c || error "multiop failed"
2915 client_up || client_up || true
2917 kill -USR1 $MULTIPID
2918 wait $MULTIPID || error "multiop close failed"
2920 check_hsm_flags $f "0x00000009"
2924 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2927 # test needs a running copytool
2931 local f=$DIR/$tdir/$tfile
2932 local fid=$(make_large_for_progress $f)
2934 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2935 error "could not archive file"
2936 wait_request_state $fid ARCHIVE STARTED
2938 check_hsm_flags $f "0x00000001"
2940 # Avoid coordinator resending this request as soon it has failed.
2945 wait_request_state $fid ARCHIVE FAILED
2947 check_hsm_flags $f "0x00000003"
2952 run_test 54 "Write during an archive cancels it"
2955 # test needs a running copytool
2959 local f=$DIR/$tdir/$tfile
2960 local fid=$(make_large_for_progress $f)
2962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2963 error "could not archive file"
2964 wait_request_state $fid ARCHIVE STARTED
2966 check_hsm_flags $f "0x00000001"
2968 # Avoid coordinator resending this request as soon it has failed.
2971 $TRUNCATE $f 1024 || error "truncate failed"
2973 wait_request_state $fid ARCHIVE FAILED
2975 check_hsm_flags $f "0x00000003"
2980 run_test 55 "Truncate during an archive cancels it"
2983 # test needs a running copytool
2987 local f=$DIR/$tdir/$tfile
2989 fid=$(make_large_for_progress $f)
2990 [ $? != 0 ] && skip "not enough free space" && return
2992 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2993 error "could not archive file"
2994 wait_request_state $fid ARCHIVE STARTED
2996 check_hsm_flags $f "0x00000001"
2998 # Change metadata and sync to be sure we are not changing only
3003 wait_request_state $fid ARCHIVE SUCCEED
3005 check_hsm_flags $f "0x00000009"
3009 run_test 56 "Setattr during an archive is ok"
3012 # Need one client for I/O, one for request
3013 needclients 2 || return 0
3015 # test needs a running copytool
3019 local f=$DIR/$tdir/test_archive_remote
3020 # Create a file on a remote node
3021 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3022 "count=2 conv=fsync"
3025 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3026 error "hsm_archive failed"
3027 local fid=$(path2fid $f)
3028 wait_request_state $fid ARCHIVE SUCCEED
3030 # Release and implicit restore it
3031 do_node $CLIENT2 "$LFS hsm_release $f" ||
3032 error "hsm_release failed"
3033 do_node $CLIENT2 "md5sum $f" ||
3034 error "hsm_restore failed"
3036 wait_request_state $fid RESTORE SUCCEED
3040 run_test 57 "Archive a file with dirty cache on another node"
3042 truncate_released_file() {
3046 local sz=$(stat -c %s $src_file)
3047 local f=$DIR/$tdir/$tfile
3048 local fid=$(copy_file $1 $f)
3052 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3053 error "could not archive file"
3054 wait_request_state $fid ARCHIVE SUCCEED
3056 $LFS hsm_release $f || error "could not release file"
3058 $TRUNCATE $f $trunc_to || error "truncate failed"
3061 local sz1=$(stat -c %s $f)
3062 [[ $sz1 == $trunc_to ]] ||
3063 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3066 check_hsm_flags $f "0x0000000b"
3068 local state=$(get_request_state $fid RESTORE)
3069 [[ "$state" == "SUCCEED" ]] ||
3070 error "truncate $sz does not trig restore, state = $state"
3072 $TRUNCATE $ref $trunc_to
3073 cmp $ref $f || error "file data wrong after truncate"
3079 # test needs a running copytool
3084 local sz=$(stat -c %s /etc/passwd)
3086 echo "truncate up from $sz to $((sz*2))"
3087 truncate_released_file /etc/passwd $((sz*2))
3089 echo "truncate down from $sz to $((sz/2))"
3090 truncate_released_file /etc/passwd $((sz/2))
3092 echo "truncate to 0"
3093 truncate_released_file /etc/passwd 0
3097 run_test 58 "Truncate a released file will trigger restore"
3101 local server_version=$(lustre_version_code $SINGLEMDS)
3102 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3103 skip "Need MDS version at least 2.7.63" && return
3106 $MCREATE $DIR/$tfile || error "mcreate failed"
3107 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3108 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3109 fid=$(path2fid $DIR/$tfile)
3110 wait_request_state $fid ARCHIVE SUCCEED
3111 $LFS hsm_release $DIR/$tfile || error "release failed"
3114 run_test 59 "Release stripeless file with non-zero size"
3117 # This test validates the fix for LU-4512. Ensure that the -u
3118 # option changes the progress reporting interval from the
3119 # default (30 seconds) to the user-specified interval.
3121 local progress_timeout=$((interval * 4))
3123 # test needs a new running copytool
3125 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3128 local f=$DIR/$tdir/$tfile
3130 fid=$(make_large_for_progress $f)
3131 [ $? != 0 ] && skip "not enough free space" && return
3134 local mdt=${MDT_PREFIX}${mdtidx}
3135 local mds=mds$((mdtidx + 1))
3137 # Wait for copytool to register
3138 wait_update_facet $mds \
3139 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3140 uuid 100 || error "coyptool failed to register with $mdt"
3142 local start_at=$(date +%s)
3143 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3144 error "could not archive file"
3146 local agent=$(facet_active_host $SINGLEAGT)
3147 local prefix=$TESTLOG_PREFIX
3148 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3149 local copytool_log=$prefix.copytool_log.$agent.log
3152 wait_update $agent \
3153 "grep -o start.copy $copytool_log" "start copy" 100 ||
3154 error "copytool failed to start"
3156 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3157 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3163 echo -n "Expecting a progress update within $progress_timeout seconds... "
3165 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3166 if [ $RESULT -gt 0 ]; then
3167 echo "$RESULT bytes copied in $WAIT seconds."
3169 elif [ $WAIT -ge $progress_timeout ]; then
3170 error "Timed out waiting for progress update!"
3173 WAIT=$((WAIT + sleep))
3177 local finish_at=$(date +%s)
3178 local elapsed=$((finish_at - start_at))
3180 # Ensure that the progress update occurred within the expected window.
3181 if [ $elapsed -lt $((interval - 1)) ]; then
3182 error "Expected progress update after at least $interval seconds"
3188 run_test 60 "Changing progress update interval from default"
3191 # test needs a new running copytool
3193 copytool_monitor_setup
3194 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3196 # Just start and stop the copytool to generate events.
3199 # Wait for the copytool to register.
3200 wait_update --verbose $(facet_active_host mds1) \
3201 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3203 error "copytool failed to register with MDT0000"
3207 local REGISTER_EVENT
3208 local UNREGISTER_EVENT
3209 while read event; do
3210 local parsed=$(parse_json_event "$event")
3211 if [ -z "$parsed" ]; then
3212 error "Copytool sent malformed event: $event"
3216 if [ $event_type == "REGISTER" ]; then
3217 REGISTER_EVENT=$event
3218 elif [ $event_type == "UNREGISTER" ]; then
3219 UNREGISTER_EVENT=$event
3221 done < <(echo $"$(get_copytool_event_log)")
3223 if [ -z "$REGISTER_EVENT" ]; then
3224 error "Copytool failed to send register event to FIFO"
3227 if [ -z "$UNREGISTER_EVENT" ]; then
3228 error "Copytool failed to send unregister event to FIFO"
3231 copytool_monitor_cleanup
3232 echo "Register/Unregister events look OK."
3234 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3237 # Bump progress interval for livelier events.
3240 # test needs a new running copytool
3242 copytool_monitor_setup
3243 HSMTOOL_UPDATE_INTERVAL=$interval \
3244 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3247 local f=$DIR/$tdir/$tfile
3249 fid=$(make_large_for_progress $f)
3250 [ $? != 0 ] && skip "not enough free space" && return
3252 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3253 error "could not archive file"
3254 wait_request_state $fid ARCHIVE SUCCEED
3256 local expected_fields="event_time data_fid source_fid"
3257 expected_fields+=" total_bytes current_bytes"
3261 while read event; do
3262 # Make sure we're not getting anything from previous events.
3263 for field in $expected_fields; do
3267 local parsed=$(parse_json_event "$event")
3268 if [ -z "$parsed" ]; then
3269 error "Copytool sent malformed event: $event"
3273 if [ $event_type == "ARCHIVE_START" ]; then
3276 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3279 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3283 # Do some simple checking of the progress update events.
3284 for expected_field in $expected_fields; do
3285 if [ -z ${!expected_field+x} ]; then
3286 error "Missing $expected_field field in event"
3290 if [ $total_bytes -eq 0 ]; then
3291 error "Expected total_bytes to be > 0"
3294 # These should be identical throughout an archive
3296 if [ $source_fid != $data_fid ]; then
3297 error "Expected source_fid to equal data_fid"
3299 done < <(echo $"$(get_copytool_event_log)")
3301 if [ -z "$START_EVENT" ]; then
3302 error "Copytool failed to send archive start event to FIFO"
3305 if [ -z "$FINISH_EVENT" ]; then
3306 error "Copytool failed to send archive finish event to FIFO"
3309 echo "Archive events look OK."
3313 copytool_monitor_cleanup
3315 run_test 71 "Copytool logs JSON archive events to FIFO"
3318 # Bump progress interval for livelier events.
3321 # test needs a new running copytool
3323 copytool_monitor_setup
3324 HSMTOOL_UPDATE_INTERVAL=$interval \
3325 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3326 local test_file=$HSMTOOL_MONITOR_DIR/file
3328 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3330 do_facet $SINGLEAGT "$cmd" ||
3331 error "cannot create $test_file on $SINGLEAGT"
3332 copy2archive $test_file $tdir/$tfile
3335 local f=$DIR/$tdir/$tfile
3336 import_file $tdir/$tfile $f
3337 f=$DIR2/$tdir/$tfile
3338 echo "Verifying released state: "
3339 check_hsm_flags $f "0x0000000d"
3341 local fid=$(path2fid $f)
3343 wait_request_state $fid RESTORE SUCCEED
3345 local expected_fields="event_time data_fid source_fid"
3346 expected_fields+=" total_bytes current_bytes"
3350 while read event; do
3351 # Make sure we're not getting anything from previous events.
3352 for field in $expected_fields; do
3356 local parsed=$(parse_json_event "$event")
3357 if [ -z "$parsed" ]; then
3358 error "Copytool sent malformed event: $event"
3362 if [ $event_type == "RESTORE_START" ]; then
3364 if [ $source_fid != $data_fid ]; then
3365 error "source_fid should == data_fid at start"
3368 elif [ $event_type == "RESTORE_FINISH" ]; then
3370 if [ $source_fid != $data_fid ]; then
3371 error "source_fid should == data_fid at finish"
3374 elif [ $event_type != "RESTORE_RUNNING" ]; then
3378 # Do some simple checking of the progress update events.
3379 for expected_field in $expected_fields; do
3380 if [ -z ${!expected_field+x} ]; then
3381 error "Missing $expected_field field in event"
3385 if [ $total_bytes -eq 0 ]; then
3386 error "Expected total_bytes to be > 0"
3389 # When a restore starts out, the data fid is the same as the
3390 # source fid. After the restore has gotten going, we learn
3391 # the new data fid. Once the restore has finished, the source
3392 # fid is set to the new data fid.
3394 # We test this because some monitoring software may depend on
3395 # this behavior. If it changes, then the consumers of these
3396 # events may need to be modified.
3397 if [ $source_fid == $data_fid ]; then
3398 error "source_fid should != data_fid during restore"
3400 done < <(echo $"$(get_copytool_event_log)")
3402 if [ -z "$START_EVENT" ]; then
3403 error "Copytool failed to send restore start event to FIFO"
3406 if [ -z "$FINISH_EVENT" ]; then
3407 error "Copytool failed to send restore finish event to FIFO"
3410 echo "Restore events look OK."
3414 copytool_monitor_cleanup
3418 run_test 72 "Copytool logs JSON restore events to FIFO"
3421 file_count=51 # Max number of files constrained by LNET message size
3422 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3423 local f=$DIR/$tdir/$tfile
3424 local FILELIST=/tmp/filelist.txt
3428 for i in $(seq 1 $file_count); do
3429 fid=$(copy_file /etc/hosts $f.$i)
3430 echo $f.$i >> $FILELIST
3432 # force copytool to use a local/temp archive dir to ensure best
3433 # performance vs remote/NFS mounts used in auto-tests
3434 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3437 local dai=$(get_hsm_param default_archive_id)
3438 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3440 # to be sure wait_all_done will not be mislead by previous tests
3442 wait_for_grace_delay
3443 $LFS hsm_archive --filelist $FILELIST ||
3444 error "cannot archive a file list"
3446 $LFS hsm_release --filelist $FILELIST ||
3447 error "cannot release a file list"
3448 $LFS hsm_restore --filelist $FILELIST ||
3449 error "cannot restore a file list"
3453 run_test 90 "Archive/restore a file list"
3455 double_verify_reset_hsm_param() {
3457 echo "Testing $HSM_PARAM.$p"
3458 local val=$(get_hsm_param $p)
3460 local val2=$(($val * 2))
3461 set_hsm_param $p $val2
3462 val=$(get_hsm_param $p)
3463 [[ $val == $val2 ]] ||
3464 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3465 echo "Set $p to 0 must failed"
3469 set_hsm_param $p $save
3471 if [[ $rc == 0 ]]; then
3472 error "we must not be able to set $HSM_PARAM.$p to 0"
3477 double_verify_reset_hsm_param loop_period
3478 double_verify_reset_hsm_param grace_delay
3479 double_verify_reset_hsm_param active_request_timeout
3480 double_verify_reset_hsm_param max_requests
3481 double_verify_reset_hsm_param default_archive_id
3483 run_test 100 "Set coordinator /proc tunables"
3490 run_test 102 "Verify coordinator control"
3493 # test needs a running copytool
3500 for i in $(seq 1 20); do
3501 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3503 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3507 echo "Current requests"
3508 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3509 $HSM_PARAM.actions |\
3510 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3512 [[ -z "$res" ]] || error "Some request have not been canceled"
3516 run_test 103 "Purge all requests"
3521 # test needs a running copytool
3525 local f=$DIR/$tdir/$tfile
3527 fid=$(make_large_for_progress $f)
3528 [ $? != 0 ] && skip "not enough free space" && return
3530 # if cdt is on, it can serve too quickly the request
3532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3533 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3534 $HSM_PARAM.actions |\
3535 grep $fid | cut -f16 -d=")
3538 [[ "$data1" == "$DATAHEX" ]] ||
3539 error "Data field in records is ($data1) and not ($DATAHEX)"
3543 run_test 104 "Copy tool data field"
3550 for i in $(seq -w 1 10); do
3551 cp /etc/passwd $DIR/$tdir/$i
3552 $LFS hsm_archive $DIR/$tdir/$i
3554 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3555 $HSM_PARAM.actions |\
3556 grep WAITING | wc -l")
3559 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3560 $HSM_PARAM.actions |\
3561 grep WAITING | wc -l")
3564 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3565 error "Requests count after shutdown $reqcnt2 != "\
3566 "before shutdown $reqcnt1"
3568 run_test 105 "Restart of coordinator"
3570 get_agent_by_uuid_mdt() {
3573 local mds=mds$(($mdtidx + 1))
3574 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
3578 check_agent_registered_by_mdt() {
3581 local mds=mds$(($mdtidx + 1))
3582 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3583 if [[ ! -z "$agent" ]]; then
3584 echo "found agent $agent on $mds"
3586 error "uuid $uuid not found in agent list on $mds"
3590 check_agent_unregistered_by_mdt() {
3593 local mds=mds$(($mdtidx + 1))
3594 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
3595 if [[ -z "$agent" ]]; then
3596 echo "uuid not found in agent list on $mds"
3598 error "uuid found in agent list on $mds: $agent"
3602 check_agent_registered() {
3605 for mdsno in $(seq 1 $MDSCOUNT); do
3606 check_agent_registered_by_mdt $uuid $((mdsno - 1))
3610 check_agent_unregistered() {
3613 for mdsno in $(seq 1 $MDSCOUNT); do
3614 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
3619 local agent=${1:-$(facet_active_host $SINGLEAGT)}
3621 # Lustre mount-point is mandatory and last parameter on
3622 # copytool cmd-line.
3623 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
3625 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
3627 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
3631 # test needs a running copytool
3634 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3636 check_agent_registered $uuid
3638 search_copytools || error "No copytool found"
3641 check_agent_unregistered $uuid
3644 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3645 check_agent_registered $uuid
3649 run_test 106 "Copytool register/unregister"
3652 # test needs a running copytool
3654 # create and archive file
3656 local f1=$DIR/$tdir/$tfile
3657 local fid=$(copy_file /etc/passwd $f1)
3658 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3659 wait_request_state $fid ARCHIVE SUCCEED
3660 # shutdown and restart MDS
3662 # check the copytool still gets messages from MDT
3663 local f2=$DIR/$tdir/2
3664 local fid=$(copy_file /etc/passwd $f2)
3665 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3666 # main check of this sanity: this request MUST succeed
3667 wait_request_state $fid ARCHIVE SUCCEED
3670 run_test 107 "Copytool re-register after MDS restart"
3672 policy_set_and_test()
3676 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3677 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3678 [[ "$policy" == "$target" ]] ||
3679 error "Wrong policy after '$change': '$policy' != '$target'"
3683 # to force default policy setting if error
3684 CDT_POLICY_HAD_CHANGED=true
3686 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3687 local default="NonBlockingRestore [NoRetryAction]"
3688 [[ "$policy" == "$default" ]] ||
3689 error "default policy has changed,"\
3690 " '$policy' != '$default' update the test"
3691 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3692 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3693 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3694 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3695 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3696 # useless bacause we know but safer for futur changes to use real value
3697 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3698 echo "Next set_param must failed"
3699 policy_set_and_test "wrong" "$policy"
3702 echo "Back to default policy"
3703 cdt_set_sanity_policy
3705 run_test 109 "Policy display/change"
3708 # test needs a running copytool
3713 copy2archive /etc/passwd $tdir/$tfile
3715 local f=$DIR/$tdir/$tfile
3716 import_file $tdir/$tfile $f
3717 local fid=$(path2fid $f)
3719 cdt_set_non_blocking_restore
3724 wait_request_state $fid RESTORE SUCCEED
3725 cdt_clear_non_blocking_restore
3729 error "md5sum returns $st != 1, "\
3730 "should also perror ENODATA (No data available)"
3734 run_test 110a "Non blocking restore policy (import case)"
3737 # test needs a running copytool
3741 local f=$DIR/$tdir/$tfile
3742 local fid=$(copy_file /etc/passwd $f)
3743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3744 wait_request_state $fid ARCHIVE SUCCEED
3747 cdt_set_non_blocking_restore
3752 wait_request_state $fid RESTORE SUCCEED
3753 cdt_clear_non_blocking_restore
3757 error "md5sum returns $st != 1, "\
3758 "should also perror ENODATA (No data available)"
3762 run_test 110b "Non blocking restore policy (release case)"
3765 # test needs a running copytool
3769 copy2archive /etc/passwd $tdir/$tfile
3771 local f=$DIR/$tdir/$tfile
3773 import_file $tdir/$tfile $f
3774 local fid=$(path2fid $f)
3778 copytool_remove_backend $fid
3781 wait_request_state $fid RESTORE FAILED
3788 [[ $st == 0 ]] || error "Restore does not failed"
3792 run_test 111a "No retry policy (import case), restore will error"\
3793 " (No such file or directory)"
3796 # test needs a running copytool
3800 local f=$DIR/$tdir/$tfile
3801 local fid=$(copy_file /etc/passwd $f)
3803 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3804 wait_request_state $fid ARCHIVE SUCCEED
3807 copytool_remove_backend $fid
3810 wait_request_state $fid RESTORE FAILED
3817 [[ $st == 0 ]] || error "Restore does not failed"
3821 run_test 111b "No retry policy (release case), restore will error"\
3822 " (No such file or directory)"
3825 # test needs a running copytool
3829 local f=$DIR/$tdir/$tfile
3830 local fid=$(copy_file /etc/passwd $f)
3832 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3833 local l=$($LFS hsm_action $f)
3835 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3839 wait_request_state $fid ARCHIVE SUCCEED
3842 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3846 run_test 112 "State of recorded request"
3849 # test needs a running copytool
3853 local f=$DIR/$tdir/$tfile
3855 fid=$(make_large_for_cancel $f)
3856 [ $? != 0 ] && skip "not enough free space" && return
3858 # test with cdt on is made in test_221
3860 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3861 # wait archive to register at CDT
3862 wait_request_state $fid ARCHIVE WAITING
3865 wait_request_state $fid ARCHIVE CANCELED
3866 wait_request_state $fid CANCEL SUCCEED
3870 run_test 200 "Register/Cancel archive"
3873 # test needs a running copytool
3877 local f=$DIR/$tdir/$tfile
3878 make_archive $tdir/$tfile
3879 import_file $tdir/$tfile $f
3880 local fid=$(path2fid $f)
3882 # test with cdt on is made in test_222
3885 # wait restore to register at CDT
3886 wait_request_state $fid RESTORE WAITING
3889 wait_request_state $fid RESTORE CANCELED
3890 wait_request_state $fid CANCEL SUCCEED
3894 run_test 201 "Register/Cancel restore"
3897 # test needs a running copytool
3901 local f=$DIR/$tdir/$tfile
3903 fid=$(make_large_for_progress $f)
3904 [ $? != 0 ] && skip "not enough free space" && return
3906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3907 wait_request_state $fid ARCHIVE SUCCEED
3911 # wait remove to register at CDT
3912 wait_request_state $fid REMOVE WAITING
3915 wait_request_state $fid REMOVE CANCELED
3919 run_test 202 "Register/Cancel remove"
3922 # test needs a running copytool
3927 local f=$DIR/$tdir/$tfile
3928 local fid=$(copy_file /etc/passwd $f)
3932 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3933 wait_request_state $fid ARCHIVE SUCCEED
3935 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3939 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3943 run_test 220 "Changelog for archive"
3946 # test needs a running copytool
3951 local f=$DIR/$tdir/$tfile
3953 fid=$(make_large_for_cancel $f)
3954 [ $? != 0 ] && skip "not enough free space" && return
3958 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3959 wait_request_state $fid ARCHIVE STARTED
3961 wait_request_state $fid ARCHIVE CANCELED
3962 wait_request_state $fid CANCEL SUCCEED
3964 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3967 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3971 run_test 221 "Changelog for archive canceled"
3974 # test needs a running copytool
3978 copy2archive /etc/passwd $tdir/$tfile
3980 local f=$DIR/$tdir/$tfile
3981 import_file $tdir/$tfile $f
3982 local fid=$(path2fid $f)
3987 wait_request_state $fid RESTORE SUCCEED
3989 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3992 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3996 run_test 222a "Changelog for explicit restore"
3999 # test needs a running copytool
4003 local f=$DIR/$tdir/$tfile
4004 local fid=$(copy_file /etc/passwd $f)
4007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4008 wait_request_state $fid ARCHIVE SUCCEED
4013 wait_request_state $fid RESTORE SUCCEED
4015 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4018 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4022 run_test 222b "Changelog for implicit restore"
4025 # test needs a running copytool
4030 local f=$DIR/$tdir/$tfile
4031 make_archive $tdir/$tfile
4035 import_file $tdir/$tfile $f
4036 local fid=$(path2fid $f)
4039 wait_request_state $fid RESTORE STARTED
4041 wait_request_state $fid RESTORE CANCELED
4042 wait_request_state $fid CANCEL SUCCEED
4044 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4047 [[ $flags == $target ]] ||
4048 error "Changelog flag is $flags not $target"
4052 run_test 223a "Changelog for restore canceled (import case)"
4055 # test needs a running copytool
4060 local f=$DIR/$tdir/$tfile
4062 fid=$(make_large_for_progress $f)
4063 [ $? != 0 ] && skip "not enough free space" && return
4066 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4067 wait_request_state $fid ARCHIVE SUCCEED
4070 wait_request_state $fid RESTORE STARTED
4072 wait_request_state $fid RESTORE CANCELED
4073 wait_request_state $fid CANCEL SUCCEED
4075 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4078 [[ $flags == $target ]] ||
4079 error "Changelog flag is $flags not $target"
4083 run_test 223b "Changelog for restore canceled (release case)"
4086 # test needs a running copytool
4091 local f=$DIR/$tdir/$tfile
4092 local fid=$(copy_file /etc/passwd $f)
4095 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4096 wait_request_state $fid ARCHIVE SUCCEED
4099 wait_request_state $fid REMOVE SUCCEED
4101 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4104 [[ $flags == $target ]] ||
4105 error "Changelog flag is $flags not $target"
4109 run_test 224 "Changelog for remove"
4112 # test needs a running copytool
4115 # test is not usable because remove request is too fast
4116 # so it is always finished before cancel can be done ...
4117 echo "Test disabled"
4122 local f=$DIR/$tdir/$tfile
4124 fid=$(make_large_for_progress $f)
4125 [ $? != 0 ] && skip "not enough free space" && return
4128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4129 wait_request_state $fid ARCHIVE SUCCEED
4131 # if cdt is on, it can serve too quickly the request
4136 wait_request_state $fid REMOVE CANCELED
4137 wait_request_state $fid CANCEL SUCCEED
4139 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4140 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4141 tail -n 1 | awk '{print $5}')
4144 [[ $flags == $target ]] ||
4145 error "Changelog flag is $flags not $target"
4149 run_test 225 "Changelog for remove canceled"
4152 # test needs a running copytool
4157 local f1=$DIR/$tdir/$tfile-1
4158 local f2=$DIR/$tdir/$tfile-2
4159 local f3=$DIR/$tdir/$tfile-3
4160 local fid1=$(copy_file /etc/passwd $f1)
4161 local fid2=$(copy_file /etc/passwd $f2)
4162 copy_file /etc/passwd $f3
4165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4166 wait_request_state $fid1 ARCHIVE SUCCEED
4168 $LFS hsm_archive $f2
4169 wait_request_state $fid2 ARCHIVE SUCCEED
4171 rm $f1 || error "rm $f1 failed"
4173 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4176 [[ $flags == $target ]] ||
4177 error "Changelog flag is $flags not $target"
4179 mv $f3 $f2 || error "mv $f3 $f2 failed"
4181 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4184 [[ $flags == $target ]] ||
4185 error "Changelog flag is $flags not $target"
4189 run_test 226 "changelog for last rm/mv with exiting archive"
4191 check_flags_changes() {
4199 $LFS hsm_set --$hsm_flag $f ||
4200 error "Cannot set $hsm_flag on $f"
4201 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4202 local seen=${#flags[*]}
4204 [[ $seen == $cnt ]] ||
4205 error "set $hsm_flag: Changelog events $seen != $cnt"
4206 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4207 error "set $hsm_flag: Changelog flags are "\
4208 "${flags[$((cnt - 1))]} not $target"
4210 $LFS hsm_clear --$hsm_flag $f ||
4211 error "Cannot clear $hsm_flag on $f"
4212 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4215 [[ $cnt == $seen ]] ||
4216 error "clear $hsm_flag: Changelog events $seen != $cnt"
4218 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4219 error "clear $hsm_flag: Changelog flag is "\
4220 "${flags[$((cnt - 1))]} not $target"
4224 # test needs a running copytool
4231 for i in norelease noarchive exists archived
4233 local f=$DIR/$tdir/$tfile-$i
4234 local fid=$(copy_file /etc/passwd $f)
4235 check_flags_changes $f $fid $i 0 1
4238 f=$DIR/$tdir/$tfile---lost
4239 fid=$(copy_file /etc/passwd $f)
4240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4241 wait_request_state $fid ARCHIVE SUCCEED
4242 check_flags_changes $f $fid lost 3 1
4246 run_test 227 "changelog when explicit setting of HSM flags"
4249 # test needs a running copytool
4252 local fid=$(make_small_sync $DIR/$tfile)
4253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4254 wait_request_state $fid ARCHIVE SUCCEED
4256 $LFS hsm_release $DIR/$tfile
4257 check_hsm_flags $DIR/$tfile "0x0000000d"
4259 filefrag $DIR/$tfile | grep " 1 extent found" ||
4260 error "filefrag on released file must return only one extent"
4262 # only newer versions of cp detect sparse files by stat/FIEMAP
4264 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4265 error "copying $DIR/$tfile"
4266 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4268 $LFS hsm_release $DIR/$tfile
4269 check_hsm_flags $DIR/$tfile "0x0000000d"
4271 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4273 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4275 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4276 error "comparing untarred $DIR/$tfile"
4278 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4279 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4282 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4285 # test needs a running copytool
4289 local maxrequest=$(get_hsm_param max_requests)
4290 local rqcnt=$(($maxrequest * 3))
4294 for i in $(seq -w 1 $rqcnt); do
4296 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4298 # we do it in 2 steps, so all requests arrive at the same time
4299 for i in $(seq -w 1 $rqcnt); do
4300 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4305 while [[ $cnt != 0 || $wt != 0 ]]; do
4307 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4308 $HSM_PARAM.actions |\
4309 grep STARTED | grep -v CANCEL | wc -l")
4310 [[ $cnt -le $maxrequest ]] ||
4311 error "$cnt > $maxrequest too many started requests"
4312 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4313 $HSM_PARAM.actions |\
4314 grep WAITING | wc -l")
4315 echo "max=$maxrequest started=$cnt waiting=$wt"
4320 run_test 250 "Coordinator max request"
4323 # test needs a running copytool
4327 local f=$DIR/$tdir/$tfile
4329 fid=$(make_large_for_cancel $f)
4330 [ $? != 0 ] && skip "not enough free space" && return
4333 # to have a short test
4334 local old_to=$(get_hsm_param active_request_timeout)
4335 set_hsm_param active_request_timeout 4
4336 # to be sure the cdt will wake up frequently so
4337 # it will be able to cancel the "old" request
4338 local old_loop=$(get_hsm_param loop_period)
4339 set_hsm_param loop_period 2
4342 # clear locks to avoid extra delay caused by flush/cancel
4343 # and thus prevent early copytool death to timeout.
4344 cancel_lru_locks osc
4346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4347 wait_request_state $fid ARCHIVE STARTED
4349 wait_request_state $fid ARCHIVE CANCELED
4351 set_hsm_param active_request_timeout $old_to
4352 set_hsm_param loop_period $old_loop
4356 run_test 251 "Coordinator request timeout"
4359 # the only way to test ondisk conf is to restart MDS ...
4360 echo "Stop coordinator and remove coordinator state at mount"
4363 # clean on disk conf set by default
4364 cdt_clear_mount_state
4365 cdt_check_state stopped
4367 # check cdt still off after umount/remount
4369 cdt_check_state stopped
4371 echo "Set coordinator start at mount, and start coordinator"
4372 cdt_set_mount_state enabled
4375 cdt_check_state enabled
4377 # check cdt still on after umount/remount
4379 cdt_check_state enabled
4381 # we are back to original state (cdt started at mount)
4383 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4386 local ai=$(get_hsm_param default_archive_id)
4387 local new=$((ai + 1))
4389 set_hsm_param default_archive_id $new -P
4391 local res=$(get_hsm_param default_archive_id)
4394 set_hsm_param default_archive_id "" "-P -d"
4396 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4398 run_test 301 "HSM tunnable are persistent"
4401 local ai=$(get_hsm_param default_archive_id)
4402 local new=$((ai + 1))
4407 set_hsm_param default_archive_id $new -P
4410 for mdtno in $(seq 1 $MDSCOUNT); do
4415 cdt_check_state enabled
4417 local res=$(get_hsm_param default_archive_id)
4420 set_hsm_param default_archive_id "" "-P -d"
4422 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4424 run_test 302 "HSM tunnable are persistent when CDT is off"
4427 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4433 local dir_mdt0=$DIR/$tdir/mdt0
4434 local dir_mdt1=$DIR/$tdir/mdt1
4436 # create 1 dir per MDT
4437 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4438 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4440 # create 1 file in each MDT
4441 local fid1=$(make_small $dir_mdt0/$tfile)
4442 local fid2=$(make_small $dir_mdt1/$tfile)
4444 # check that hsm request on mdt0 is sent to the right MDS
4445 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4446 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4447 echo "archive successful on mdt0"
4449 # check that hsm request on mdt1 is sent to the right MDS
4450 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4451 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4452 echo "archive successful on mdt1"
4455 # clean test files and directories
4456 rm -rf $dir_mdt0 $dir_mdt1
4458 run_test 400 "Single request is sent to the right MDT"
4461 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4467 local dir_mdt0=$DIR/$tdir/mdt0
4468 local dir_mdt1=$DIR/$tdir/mdt1
4470 # create 1 dir per MDT
4471 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4472 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4474 # create 1 file in each MDT
4475 local fid1=$(make_small $dir_mdt0/$tfile)
4476 local fid2=$(make_small $dir_mdt1/$tfile)
4478 # check that compound requests are shunt to the rights MDTs
4479 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4480 error "lfs hsm_archive"
4481 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4482 echo "archive successful on mdt0"
4483 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4484 echo "archive successful on mdt1"
4487 # clean test files and directories
4488 rm -rf $dir_mdt0 $dir_mdt1
4490 run_test 401 "Compound requests split and sent to their respective MDTs"
4492 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4497 local node=$(facet_active_host $facet)
4499 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4500 awk '{print $4}'); do
4501 echo "$3 $mdc on $node"
4502 do_facet $facet "$LCTL --device $mdc $state" || return 1
4507 # make sure there is no running copytool
4510 # deactivate all mdc on agent1
4511 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4513 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4515 check_agent_unregistered "uuid" # match any agent
4517 # no expected running copytool
4518 search_copytools $agent && error "Copytool start should have failed"
4521 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4523 run_test 402 "Copytool start fails if all MDTs are inactive"
4526 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4528 # make sure there is no running copytool
4531 local agent=$(facet_active_host $SINGLEAGT)
4533 # deactivate all mdc for MDT0001
4534 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4537 local uuid=$(get_agent_uuid $agent)
4538 # check the agent is registered on MDT0000, and not on MDT0001
4539 check_agent_registered_by_mdt $uuid 0
4540 check_agent_unregistered_by_mdt $uuid 1
4542 # check running copytool process
4543 search_copytools $agent || error "No running copytools on $agent"
4545 # reactivate all mdc for MDT0001
4546 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4548 # make sure the copytool is now registered to all MDTs
4549 check_agent_registered $uuid
4553 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4556 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4560 # create files on both MDT0000 and MDT0001
4563 local dir_mdt0=$DIR/$tdir/mdt0
4564 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4566 # create 1 file on mdt0
4567 local fid1=$(make_small $dir_mdt0/$tfile)
4569 # deactivate all mdc for MDT0001
4570 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4572 # send an HSM request for files in MDT0000
4573 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4575 # check for completion of files in MDT0000
4576 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4577 echo "archive successful on mdt0"
4579 # reactivate all mdc for MDT0001
4580 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4583 # clean test files and directories
4586 run_test 404 "Inactive MDT does not block requests for active MDTs"
4589 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4595 local striped_dir=$DIR/$tdir/striped_dir
4597 # create striped dir on all of MDTs
4598 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4600 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4601 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4602 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4603 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4605 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4606 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4607 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4608 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4610 # check that compound requests are shunt to the rights MDTs
4611 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4612 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4613 error "lfs hsm_archive"
4615 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4616 echo "archive successful on $fid1"
4617 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4618 echo "archive successful on $fid2"
4619 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4620 echo "archive successful on $fid3"
4621 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4622 echo "archive successful on $fid4"
4624 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4625 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4626 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4627 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4629 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4630 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4631 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4632 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4636 run_test 405 "archive and release under striped directory"
4639 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4641 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4642 skip "need MDS version at least 2.7.64" && return 0
4649 fid=$(make_small $DIR/$tdir/$tfile)
4652 $LFS hsm_archive $DIR/$tdir/$tfile
4653 wait_request_state "$fid" ARCHIVE SUCCEED
4654 $LFS hsm_release $DIR/$tdir/$tfile
4656 # Should migrate $tdir but not $tfile.
4657 $LFS mv -M1 $DIR/$tdir &&
4658 error "migrating HSM an archived file should fail"
4660 $LFS hsm_restore $DIR/$tdir/$tfile
4661 wait_request_state "$fid" RESTORE SUCCEED
4663 $LFS hsm_remove $DIR/$tdir/$tfile
4664 wait_request_state "$fid" REMOVE SUCCEED
4666 cat $DIR/$tdir/$tfile > /dev/null ||
4667 error "cannot read $DIR/$tdir/$tfile"
4669 $LFS mv -M1 $DIR/$tdir ||
4670 error "cannot complete migration after HSM remove"
4672 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4673 if ((mdt_index != 1)); then
4674 error "expected MDT index 1, got $mdt_index"
4677 # Refresh fid after migration.
4678 fid=$(path2fid $DIR/$tdir/$tfile)
4681 $LFS hsm_archive $DIR/$tdir/$tfile
4682 wait_request_state "$fid" ARCHIVE SUCCEED 1
4684 lctl set_param debug=+trace
4685 $LFS hsm_release $DIR/$tdir/$tfile ||
4686 error "cannot release $DIR/$tdir/$tfile"
4688 $LFS hsm_restore $DIR/$tdir/$tfile
4689 wait_request_state "$fid" RESTORE SUCCEED 1
4691 cat $DIR/$tdir/$tfile > /dev/null ||
4692 error "cannot read $DIR/$tdir/$tfile"
4696 run_test 406 "attempting to migrate HSM archived files is safe"
4700 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4701 skip "HSM migrate is not supported" && return
4703 # Stop the existing copytool
4706 test_mkdir -p $DIR/$tdir
4707 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4709 run_test 500 "various LLAPI HSM tests"
4714 check_and_cleanup_lustre