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:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
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_continue() {
381 local agents=${1:-$(facet_active_host $SINGLEAGT)}
383 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
384 echo "Copytool is continued on $agents"
387 copytool_remove_backend() {
389 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
390 echo "Remove from backend: $fid = $be"
391 do_facet $SINGLEAGT rm -f $be
395 do_facet $SINGLEAGT \
396 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
397 --import $1 $2 $MOUNT" ||
398 error "import of $1 to $2 failed"
402 local file=$HSM_ARCHIVE/$1
403 do_facet $SINGLEAGT mkdir -p $(dirname $file)
404 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
405 file_creation_failure dd $file $?
409 local file=$HSM_ARCHIVE/$2
410 do_facet $SINGLEAGT mkdir -p $(dirname $file)
411 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
420 if [[ "$value" != "" ]]; then
423 for mdtno in $(seq 1 $MDSCOUNT); do
424 local idx=$(($mdtno - 1))
425 local facet=mds${mdtno}
426 # if $arg include -P option, run 1 set_param per MDT on the MGS
427 # else, run set_param on each MDT
428 [[ $arg = *"-P"* ]] && facet=mgs
429 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
430 [[ $? != 0 ]] && rc=1
440 for mdtno in $(seq 1 $MDSCOUNT); do
441 local idx=$(($mdtno - 1))
442 wait_result mds${mdtno} \
443 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
445 error "$key state is not '$target' on mds${mdtno}"
452 for mdtno in $(seq 1 $MDSCOUNT); do
453 local idx=$(($mdtno - 1))
454 local cl_user=$(do_facet mds${mdtno} $LCTL \
455 --device ${MDT[$idx]} \
456 changelog_register -n)
458 do_facet mds${mdtno} lctl set_param \
459 mdd.${MDT[$idx]}.changelog_mask="+hsm"
460 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
464 changelog_cleanup() {
466 for mdtno in $(seq 1 $MDSCOUNT); do
467 local idx=$(($mdtno - 1))
468 [[ -z ${CL_USERS[$idx]} ]] && continue
469 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
470 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
471 changelog_deregister ${CL_USERS[$idx]}
476 changelog_get_flags() {
481 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
486 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
494 mdts_set_param "$opt -n" "hsm.$param" "$value"
501 mdts_set_param "" hsm_control "$cmd"
502 mdts_check_param hsm_control "$target" 10
505 cdt_set_sanity_policy() {
506 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
509 mdts_set_param "" hsm.policy "+NRA"
510 mdts_set_param "" hsm.policy "-NBR"
511 CDT_POLICY_HAD_CHANGED=
516 mdts_set_param "" hsm.policy "+NRA"
517 CDT_POLICY_HAD_CHANGED=true
520 cdt_clear_no_retry() {
521 mdts_set_param "" hsm.policy "-NRA"
522 CDT_POLICY_HAD_CHANGED=true
525 cdt_set_non_blocking_restore() {
526 mdts_set_param "" hsm.policy "+NBR"
527 CDT_POLICY_HAD_CHANGED=true
530 cdt_clear_non_blocking_restore() {
531 mdts_set_param "" hsm.policy "-NBR"
532 CDT_POLICY_HAD_CHANGED=true
535 cdt_clear_mount_state() {
536 mdts_set_param "-P -d" hsm_control ""
539 cdt_set_mount_state() {
540 mdts_set_param "-P" hsm_control "$1"
541 # set_param -P is asynchronous operation and could race with set_param.
542 # In such case configs could be retrieved and applied at mgc after
543 # set_param -P completion. Sleep here to avoid race with set_param.
544 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
545 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
546 # and 10 seconds to retrieve config from server.
551 mdts_check_param hsm_control "$1" 20
555 set_test_state disabled disabled
559 set_test_state enabled enabled
563 set_test_state shutdown stopped
567 set_test_state purge enabled
573 cdt_set_sanity_policy
577 local client_count=$1
578 if [[ $CLIENTCOUNT -lt $client_count ]]; then
579 skip "Need $client_count or more clients, have $CLIENTCOUNT"
586 $LFS path2fid $1 | tr -d '[]'
587 return ${PIPESTATUS[0]}
595 if [[ $u == "user" ]]; then
596 st=$($RUNAS $LFS hsm_state $f)
599 st=$($LFS hsm_state $f)
602 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
604 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
608 get_hsm_archive_id() {
611 st=$($LFS hsm_state $f)
612 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
614 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
623 local st=$(get_hsm_flags $f)
624 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
627 check_hsm_flags_user() {
631 local st=$(get_hsm_flags $f user)
632 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
635 file_creation_failure() {
640 df $MOUNT $MOUNT2 >&2
641 error "cannot create $f with $cmd, status=$err"
653 if [[ "$3" != 1 ]]; then
657 cp $1 $f || file_creation_failure cp $f $?
659 path2fid $f || error "cannot get fid on $f"
663 local file2=${1/$DIR/$DIR2}
664 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
665 file_creation_failure dd $file2 $?
667 path2fid $1 || error "cannot get fid on $1"
671 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
672 file_creation_failure dd $1 $?
673 path2fid $1 || error "cannot get fid on $1"
676 cleanup_large_files() {
677 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
679 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
682 check_enough_free_space() {
685 local need=$((nb * unit /1024))
686 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
687 (( $need >= $free )) && return 1
691 make_custom_file_for_progress() {
692 local file2=${1/$DIR/$DIR2}
693 local fsize=${2:-"39"}
694 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
697 [[ $fsize -gt 0 ]] || error "Invalid file size"
698 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
701 check_enough_free_space $fsize $blksz
702 [ $? != 0 ] && return $?
703 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
704 file_creation_failure dd $file2 $?
705 path2fid $1 || error "cannot get fid on $1"
711 wait_update --verbose $(facet_active_host $facet) "$@"
714 wait_request_state() {
718 # 4th arg (mdt index) is optional
720 local mds=mds$(($mdtidx + 1))
722 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
723 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
725 wait_result $mds "$cmd" $state 200 ||
726 error "request on $fid is not $state on $mds"
729 get_request_state() {
733 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
734 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
737 get_request_count() {
741 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
742 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
749 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
750 [[ -n $fid ]] && cmd+=" | grep '$fid'"
751 cmd+=" | egrep 'WAITING|STARTED'"
753 wait_result $SINGLEMDS "$cmd" "" $timeout ||
754 error "requests did not complete"
757 wait_for_grace_delay() {
758 local val=$(get_hsm_param grace_delay)
762 wait_for_loop_period() {
763 local val=$(get_hsm_param loop_period)
770 # python2.6 in EL6 includes an internal json module
771 local json_parser='import json; import fileinput;'
772 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
773 json_parser+='json.loads([line for line in '
774 json_parser+='fileinput.input()][0]).items()])'
776 echo $raw_event | python -c "$json_parser"
779 get_agent_by_uuid_mdt() {
782 local mds=mds$(($mdtidx + 1))
783 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
787 check_agent_registered_by_mdt() {
790 local mds=mds$(($mdtidx + 1))
791 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
792 if [[ ! -z "$agent" ]]; then
793 echo "found agent $agent on $mds"
795 error "uuid $uuid not found in agent list on $mds"
799 check_agent_unregistered_by_mdt() {
802 local mds=mds$(($mdtidx + 1))
803 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
804 if [[ -z "$agent" ]]; then
805 echo "uuid not found in agent list on $mds"
807 error "uuid found in agent list on $mds: $agent"
811 check_agent_registered() {
814 for mdsno in $(seq 1 $MDSCOUNT); do
815 check_agent_registered_by_mdt $uuid $((mdsno - 1))
819 check_agent_unregistered() {
822 for mdsno in $(seq 1 $MDSCOUNT); do
823 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
828 local agent=${1:-$(facet_active_host $SINGLEAGT)}
830 # Lustre mount-point is mandatory and last parameter on
832 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
834 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
836 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
842 # populate MDT device array
845 # cleanup from previous bad setup
848 # for recovery tests, coordinator needs to be started at mount
850 # the lustre conf must be without hsm on (like for sanity.sh)
851 echo "Set HSM on and start"
852 cdt_set_mount_state enabled
853 cdt_check_state enabled
855 echo "Start copytool"
858 echo "Set sanity-hsm HSM policy"
859 cdt_set_sanity_policy
861 # finished requests are quickly removed from list
862 set_hsm_param grace_delay 10
868 local f=$DIR/$tdir/$tfile
872 check_hsm_flags_user $f "0x00000000"
874 $RUNAS $LFS hsm_set --norelease $f ||
875 error "user could not change hsm flags"
876 check_hsm_flags_user $f "0x00000010"
878 $RUNAS $LFS hsm_clear --norelease $f ||
879 error "user could not clear hsm flags"
880 check_hsm_flags_user $f "0x00000000"
882 # User could not change those flags...
883 $RUNAS $LFS hsm_set --exists $f &&
884 error "user should not set this flag"
885 check_hsm_flags_user $f "0x00000000"
888 $LFS hsm_set --exists $f ||
889 error "root could not change hsm flags"
890 check_hsm_flags_user $f "0x00000001"
892 $LFS hsm_clear --exists $f ||
893 error "root could not clear hsm state"
894 check_hsm_flags_user $f "0x00000000"
897 run_test 1 "lfs hsm flags root/non-root access"
901 local f=$DIR/$tdir/$tfile
902 local fid=$(make_small $f)
904 $LFS hsm_archive $f || error "could not archive file"
905 wait_request_state $fid ARCHIVE SUCCEED
907 # Release and check states
908 $LFS hsm_release $f || error "could not release file"
909 echo -n "Verifying released state: "
910 check_hsm_flags $f "0x0000000d"
912 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
914 run_test 1a "mmap & cat a HSM released file"
918 local f=$DIR/$tdir/$tfile
920 # New files are not dirty
921 check_hsm_flags $f "0x00000000"
923 # For test, we simulate an archived file.
924 $LFS hsm_set --exists $f || error "user could not change hsm flags"
925 check_hsm_flags $f "0x00000001"
927 # chmod do not put the file dirty
928 chmod 600 $f || error "could not chmod test file"
929 check_hsm_flags $f "0x00000001"
931 # chown do not put the file dirty
932 chown $RUNAS_ID $f || error "could not chown test file"
933 check_hsm_flags $f "0x00000001"
935 # truncate put the file dirty
936 $TRUNCATE $f 1 || error "could not truncate test file"
937 check_hsm_flags $f "0x00000003"
939 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
940 check_hsm_flags $f "0x00000001"
942 run_test 2 "Check file dirtyness when doing setattr"
948 # New files are not dirty
950 check_hsm_flags $f "0x00000000"
952 # For test, we simulate an archived file.
953 $LFS hsm_set --exists $f ||
954 error "user could not change hsm flags"
955 check_hsm_flags $f "0x00000001"
957 # Reading a file, does not set dirty
958 cat $f > /dev/null || error "could not read file"
959 check_hsm_flags $f "0x00000001"
961 # Open for write without modifying data, does not set dirty
962 openfile -f O_WRONLY $f || error "could not open test file"
963 check_hsm_flags $f "0x00000001"
965 # Append to a file sets it dirty
966 cp -p /etc/passwd $f.append || error "could not create file"
967 $LFS hsm_set --exists $f.append ||
968 error "user could not change hsm flags"
969 dd if=/etc/passwd of=$f.append bs=1 count=3\
970 conv=notrunc oflag=append status=noxfer ||
971 file_creation_failure dd $f.append $?
972 check_hsm_flags $f.append "0x00000003"
974 # Modify a file sets it dirty
975 cp -p /etc/passwd $f.modify || error "could not create file"
976 $LFS hsm_set --exists $f.modify ||
977 error "user could not change hsm flags"
978 dd if=/dev/zero of=$f.modify bs=1 count=3\
979 conv=notrunc status=noxfer ||
980 file_creation_failure dd $f.modify $?
981 check_hsm_flags $f.modify "0x00000003"
983 # Open O_TRUNC sets dirty
984 cp -p /etc/passwd $f.trunc || error "could not create file"
985 $LFS hsm_set --exists $f.trunc ||
986 error "user could not change hsm flags"
987 cp /etc/group $f.trunc || error "could not override a file"
988 check_hsm_flags $f.trunc "0x00000003"
990 # Mmapped a file sets dirty
991 cp -p /etc/passwd $f.mmap || error "could not create file"
992 $LFS hsm_set --exists $f.mmap ||
993 error "user could not change hsm flags"
994 multiop $f.mmap OSMWUc || error "could not mmap a file"
995 check_hsm_flags $f.mmap "0x00000003"
997 run_test 3 "Check file dirtyness when opening for write"
1001 local f=$DIR/$tdir/$tfile
1002 local fid=$(make_small $f)
1005 local st=$(get_request_state $fid CANCEL)
1006 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1008 run_test 4 "Useless cancel must not be registered"
1011 # test needs a running copytool
1015 local f=$DIR/$tdir/$tfile
1016 local fid=$(copy_file /etc/passwd $f)
1018 wait_request_state $fid ARCHIVE SUCCEED
1020 check_hsm_flags $f "0x00000009"
1024 run_test 8 "Test default archive number"
1027 # we do not use the default one to be sure
1028 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1030 copytool_setup $SINGLEAGT $MOUNT $new_an
1032 # give time for CT to register with MDTs
1033 sleep $(($MDSCOUNT*2))
1034 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1035 check_agent_registered $uuid
1038 local f=$DIR/$tdir/$tfile
1039 local fid=$(copy_file /etc/passwd $f)
1040 $LFS hsm_archive --archive $new_an $f
1041 wait_request_state $fid ARCHIVE SUCCEED
1043 check_hsm_flags $f "0x00000009"
1047 run_test 9 "Use of explicit archive number, with dedicated copytool"
1050 needclients 3 || return 0
1056 copytool_cleanup $(comma_list $(agts_nodes))
1058 # start all of the copytools
1059 for n in $(seq $AGTCOUNT); do
1060 copytool_setup agt$n
1063 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1066 for n in $(seq $AGTCOUNT); do
1067 file=$DIR/$tdir/$tfile.$n
1068 fid=$(make_small $file)
1070 $LFS hsm_archive $file || error "could not archive file $file"
1071 wait_request_state $fid ARCHIVE SUCCEED
1072 check_hsm_flags $file "0x00000009"
1076 copytool_cleanup $(comma_list $(agts_nodes))
1078 run_test 9a "Multiple remote agents"
1081 # test needs a running copytool
1084 mkdir -p $DIR/$tdir/d1
1085 local f=$DIR/$tdir/$tfile
1086 local fid=$(copy_file /etc/hosts $f)
1087 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1088 error "hsm_archive failed"
1089 wait_request_state $fid ARCHIVE SUCCEED
1091 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1092 error "fid $fid not in archive $HSM_ARCHIVE"
1093 echo "Verifying content"
1094 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1095 echo "Verifying hsm state "
1096 check_hsm_flags $f "0x00000009"
1098 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1099 local st=$(get_hsm_archive_id $f)
1100 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1101 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1106 run_test 10a "Archive a file"
1109 # test needs a running copytool
1113 local f=$DIR/$tdir/$tfile
1114 local fid=$(copy_file /etc/hosts $f)
1115 $LFS hsm_archive $f || error "archive request failed"
1116 wait_request_state $fid ARCHIVE SUCCEED
1118 $LFS hsm_archive $f || error "archive of non dirty file failed"
1119 local cnt=$(get_request_count $fid ARCHIVE)
1120 [[ "$cnt" == "1" ]] ||
1121 error "archive of non dirty file must not make a request"
1125 run_test 10b "Archive of non dirty file must work without doing request"
1128 # test needs a running copytool
1132 local f=$DIR/$tdir/$tfile
1133 local fid=$(copy_file /etc/hosts $f)
1134 $LFS hsm_set --noarchive $f
1135 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1139 run_test 10c "Check forbidden archive"
1142 # test needs a running copytool
1146 local f=$DIR/$tdir/$tfile
1147 local fid=$(copy_file /etc/hosts $f)
1148 $LFS hsm_archive $f || error "cannot archive $f"
1149 wait_request_state $fid ARCHIVE SUCCEED
1151 local ar=$(get_hsm_archive_id $f)
1152 local dflt=$(get_hsm_param default_archive_id)
1153 [[ $ar == $dflt ]] ||
1154 error "archived file is not on default archive: $ar != $dflt"
1158 run_test 10d "Archive a file on the default archive id"
1162 copy2archive /etc/hosts $tdir/$tfile
1163 local f=$DIR/$tdir/$tfile
1165 import_file $tdir/$tfile $f
1166 echo -n "Verifying released state: "
1167 check_hsm_flags $f "0x0000000d"
1169 local LSZ=$(stat -c "%s" $f)
1170 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1172 echo "Verifying imported size $LSZ=$ASZ"
1173 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1174 echo -n "Verifying released pattern: "
1175 local PTRN=$($GETSTRIPE -L $f)
1177 [[ $PTRN == 80000001 ]] || error "Is not released"
1178 local fid=$(path2fid $f)
1179 echo "Verifying new fid $fid in archive"
1181 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1182 error "fid $fid not in archive $HSM_ARCHIVE"
1184 run_test 11a "Import a file"
1187 # test needs a running copytool
1191 local f=$DIR/$tdir/$tfile
1192 local fid=$(copy_file /etc/hosts $f)
1193 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1194 error "hsm_archive failed"
1195 wait_request_state $fid ARCHIVE SUCCEED
1197 local FILE_HASH=$(md5sum $f)
1202 echo "$FILE_HASH" | md5sum -c
1204 [[ $? -eq 0 ]] || error "Restored file differs"
1208 run_test 11b "Import a deleted file using its FID"
1211 # test needs a running copytool
1215 copy2archive /etc/hosts $tdir/$tfile
1217 local f=$DIR/$tdir/$tfile
1218 import_file $tdir/$tfile $f
1219 local f2=$DIR2/$tdir/$tfile
1220 echo "Verifying released state: "
1221 check_hsm_flags $f2 "0x0000000d"
1223 local fid=$(path2fid $f2)
1224 $LFS hsm_restore $f2
1225 wait_request_state $fid RESTORE SUCCEED
1227 echo "Verifying file state: "
1228 check_hsm_flags $f2 "0x00000009"
1230 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1232 [[ $? -eq 0 ]] || error "Restored file differs"
1236 run_test 12a "Restore an imported file explicitly"
1239 # test needs a running copytool
1243 copy2archive /etc/hosts $tdir/$tfile
1245 local f=$DIR/$tdir/$tfile
1246 import_file $tdir/$tfile $f
1247 echo "Verifying released state: "
1248 check_hsm_flags $f "0x0000000d"
1250 cat $f > /dev/null || error "File read failed"
1252 echo "Verifying file state after restore: "
1253 check_hsm_flags $f "0x00000009"
1255 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1257 [[ $? -eq 0 ]] || error "Restored file differs"
1261 run_test 12b "Restore an imported file implicitly"
1264 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1266 # test needs a running copytool
1270 local f=$DIR/$tdir/$tfile
1271 $LFS setstripe -c 2 $f
1273 fid=$(make_custom_file_for_progress $f 5)
1274 [ $? != 0 ] && skip "not enough free space" && return
1276 local FILE_CRC=$(md5sum $f)
1278 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1279 wait_request_state $fid ARCHIVE SUCCEED
1280 $LFS hsm_release $f || error "release $f failed"
1282 echo "$FILE_CRC" | md5sum -c
1284 [[ $? -eq 0 ]] || error "Restored file differs"
1288 run_test 12c "Restore a file with stripe of 2"
1291 # test needs a running copytool
1296 local f=$DIR/$tdir/$tfile
1297 local fid=$(copy_file /etc/hosts $f)
1298 $LFS hsm_restore $f || error "restore of non archived file failed"
1299 local cnt=$(get_request_count $fid RESTORE)
1300 [[ "$cnt" == "0" ]] ||
1301 error "restore non archived must not make a request"
1302 $LFS hsm_archive $f ||
1303 error "archive request failed"
1304 wait_request_state $fid ARCHIVE SUCCEED
1305 $LFS hsm_restore $f ||
1306 error "restore of non released file failed"
1307 local cnt=$(get_request_count $fid RESTORE)
1308 [[ "$cnt" == "0" ]] ||
1309 error "restore a non dirty file must not make a request"
1313 run_test 12d "Restore of a non archived, non released file must work"\
1314 " without doing request"
1317 # test needs a running copytool
1320 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1321 local f=$DIR/$tdir/$tfile
1322 local fid=$(copy_file /etc/hosts $f)
1323 $LFS hsm_archive $f || error "archive request failed"
1324 wait_request_state $fid ARCHIVE SUCCEED
1327 cat /etc/hosts >> $f
1331 $LFS hsm_restore $f && error "restore a dirty file must fail"
1335 run_test 12e "Check forbidden restore"
1338 # test needs a running copytool
1342 local f=$DIR/$tdir/$tfile
1343 local fid=$(copy_file /etc/hosts $f)
1345 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1346 wait_request_state $fid ARCHIVE SUCCEED
1347 $LFS hsm_release $f || error "release of $f failed"
1349 wait_request_state $fid RESTORE SUCCEED
1351 echo -n "Verifying file state: "
1352 check_hsm_flags $f "0x00000009"
1354 diff -q /etc/hosts $f
1356 [[ $? -eq 0 ]] || error "Restored file differs"
1360 run_test 12f "Restore a released file explicitly"
1363 # test needs a running copytool
1367 local f=$DIR/$tdir/$tfile
1368 local fid=$(copy_file /etc/hosts $f)
1370 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1371 wait_request_state $fid ARCHIVE SUCCEED
1372 $LFS hsm_release $f || error "release of $f failed"
1374 diff -q /etc/hosts $f
1377 # we check we had a restore done
1378 wait_request_state $fid RESTORE SUCCEED
1380 [[ $st -eq 0 ]] || error "Restored file differs"
1384 run_test 12g "Restore a released file implicitly"
1387 needclients 2 || return 0
1389 # test needs a running copytool
1393 local f=$DIR/$tdir/$tfile
1394 local fid=$(copy_file /etc/hosts $f)
1396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1397 wait_request_state $fid ARCHIVE SUCCEED
1398 $LFS hsm_release $f || error "release of $f failed"
1400 do_node $CLIENT2 diff -q /etc/hosts $f
1403 # we check we had a restore done
1404 wait_request_state $fid RESTORE SUCCEED
1406 [[ $st -eq 0 ]] || error "Restored file differs"
1410 run_test 12h "Restore a released file implicitly from a second node"
1413 # test needs a running copytool
1417 local f=$DIR/$tdir/$tfile
1418 local fid=$(copy_file /etc/passwd $f)
1419 $LFS hsm_archive $f || error "archive of $f failed"
1420 wait_request_state $fid ARCHIVE SUCCEED
1422 $LFS hsm_release $f || error "release of $f failed"
1426 [[ $? -eq 0 ]] || error "Restored file differs"
1430 run_test 12m "Archive/release/implicit restore"
1433 # test needs a running copytool
1437 copy2archive /etc/hosts $tdir/$tfile
1439 local f=$DIR/$tdir/$tfile
1440 import_file $tdir/$tfile $f
1442 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1443 error "Restored file differs"
1445 $LFS hsm_release $f || error "release of $f failed"
1449 run_test 12n "Import/implicit restore/release"
1452 # test needs a running copytool
1456 local f=$DIR/$tdir/$tfile
1457 local fid=$(copy_file /etc/hosts $f)
1459 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1460 wait_request_state $fid ARCHIVE SUCCEED
1461 $LFS hsm_release $f || error "release of $f failed"
1463 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1464 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1466 # set no retry action mode
1469 diff -q /etc/hosts $f
1472 # we check we had a restore failure
1473 wait_request_state $fid RESTORE FAILED
1475 [[ $st -eq 0 ]] && error "Restore must fail"
1477 # remove no retry action mode
1480 # check file is still released
1481 check_hsm_flags $f "0x0000000d"
1483 # retry w/o failure injection
1484 do_facet $SINGLEMDS lctl set_param fail_loc=0
1486 # to be sure previous RESTORE result is gone
1488 wait_for_grace_delay
1490 diff -q /etc/hosts $f
1493 # we check we had a restore done
1494 wait_request_state $fid RESTORE SUCCEED
1496 [[ $st -eq 0 ]] || error "Restored file differs"
1500 run_test 12o "Layout-swap failure during Restore leaves file released"
1503 # test needs a running copytool
1507 local f=$DIR/$tdir/$tfile
1508 local fid=$(copy_file /etc/hosts $f)
1510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1511 wait_request_state $fid ARCHIVE SUCCEED
1512 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1513 $LFS hsm_release $f || error "cannot release $f"
1514 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1515 $LFS hsm_release $f || error "cannot release $f"
1516 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1520 run_test 12p "implicit restore of a file on copytool mount point"
1522 cleanup_test_12q() {
1524 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1525 error "cannot umount $MOUNT3 on $SINGLEAGT"
1529 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1530 skip "need MDS version at least 2.7.58" && return 0
1532 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1533 error "cannot mount $MOUNT3 on $SINGLEAGT"
1535 trap cleanup_test_12q EXIT
1537 # test needs a running copytool
1538 copytool_setup $SINGLEAGT $MOUNT3
1541 local f=$DIR/$tdir/$tfile
1542 local f2=$DIR2/$tdir/$tfile
1543 local fid=$(make_small $f)
1544 local orig_size=$(stat -c "%s" $f)
1546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1547 wait_request_state $fid ARCHIVE SUCCEED
1549 $LFS hsm_release $f || error "could not release file"
1550 check_hsm_flags $f "0x0000000d"
1553 wait_copytools || error "copytool failed to stop"
1555 cat $f > /dev/null &
1557 # wait a bit to allow implicit restore request to be handled.
1558 # if not, next stat would also block on layout-lock.
1561 local size=$(stat -c "%s" $f2)
1562 [ $size -eq $orig_size ] ||
1563 error "$f2: wrong size after archive: $size != $orig_size"
1565 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1569 size=$(stat -c "%s" $f)
1570 [ $size -eq $orig_size ] ||
1571 error "$f: wrong size after restore: $size != $orig_size"
1573 size=$(stat -c "%s" $f2)
1574 [ $size -eq $orig_size ] ||
1575 error "$f2: wrong size after restore: $size != $orig_size"
1579 size=$(stat -c "%s" $f)
1581 error "$f: wrong size after overwrite: $size != 0"
1583 size=$(stat -c "%s" $f2)
1585 error "$f2: wrong size after overwrite: $size != 0"
1588 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1589 error "cannot umount $MOUNT3 on $SINGLEAGT"
1591 run_test 12q "file attributes are refreshed after restore"
1594 # test needs a running copytool
1597 local ARC_SUBDIR="import.orig"
1601 # populate directory to be imported
1602 for d in $(seq 1 10); do
1603 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1604 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1605 for f in $(seq 1 10); do
1606 CURR_FILE="$CURR_DIR/$tfile.$f"
1607 # write file-specific data
1608 do_facet $SINGLEAGT \
1609 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1610 "file=$CURR_FILE > $CURR_FILE"
1614 import_file "$ARC_SUBDIR" $DIR/$tdir
1615 # diff lustre content and origin (triggers file restoration)
1616 # there must be 10x10 identical files, and no difference
1617 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1618 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1619 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1620 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1622 [ $cnt_diff -eq 0 ] ||
1623 error "$cnt_diff imported files differ from read data"
1624 [ $cnt_ok -eq 100 ] ||
1625 error "not enough identical files ($cnt_ok != 100)"
1629 run_test 13 "Recursively import and restore a directory"
1632 # test needs a running copytool
1637 local f=$DIR/$tdir/$tfile
1638 local fid=$(make_small $f)
1639 local sum=$(md5sum $f | awk '{print $1}')
1640 $LFS hsm_archive $f || error "could not archive file"
1641 wait_request_state $fid ARCHIVE SUCCEED
1645 # create released file (simulate llapi_hsm_import call)
1647 local fid2=$(path2fid $f)
1648 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1649 $LFS hsm_release $f || error "could not release file"
1651 # rebind the archive to the newly created file
1652 echo "rebind $fid to $fid2"
1654 do_facet $SINGLEAGT \
1655 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1656 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1658 # restore file and compare md5sum
1659 local sum2=$(md5sum $f | awk '{print $1}')
1661 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1665 run_test 14 "Rebind archived file to a new fid"
1668 # test needs a running copytool
1673 local f=$DIR/$tdir/$tfile
1675 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1679 for i in $(seq 1 $count); do
1680 fids[$i]=$(make_small $f.$i)
1681 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1682 $LFS hsm_archive $f.$i || error "could not archive file"
1684 wait_all_done $(($count*60))
1688 for i in $(seq 1 $count); do
1691 local fid2=$(path2fid $f.$i)
1692 # add the rebind operation to the list
1693 echo ${fids[$i]} $fid2 >> $tmpfile
1695 # set it released (simulate llapi_hsm_import call)
1696 $LFS hsm_set --archived --exists $f.$i ||
1697 error "could not force hsm flags"
1698 $LFS hsm_release $f.$i || error "could not release file"
1700 nl=$(wc -l < $tmpfile)
1701 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1703 echo "rebind list of files"
1704 do_facet $SINGLEAGT \
1705 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1706 --rebind $tmpfile $DIR" || error "could not rebind file list"
1708 # restore files and compare md5sum
1709 for i in $(seq 1 $count); do
1710 local sum2=$(md5sum $f.$i | awk '{print $1}')
1711 [[ $sum2 == ${sums[$i]} ]] ||
1712 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1718 run_test 15 "Rebind a list of files"
1721 # test needs a running copytool
1725 # create a known size file so we can verify transfer speed
1728 dd if=/dev/zero of=$ref bs=1M count=20
1731 local f=$DIR/$tdir/$tfile
1732 local fid=$(copy_file $ref $f)
1734 local start=$(date +%s)
1736 wait_request_state $fid ARCHIVE SUCCEED
1737 local end=$(date +%s)
1738 # Add 1 to account for rounding errors between start and end (LU-8155)
1739 local duration=$((end - start + 1))
1741 [[ $duration -ge $((goal - 1)) ]] ||
1742 error "Transfer is too fast $duration < $goal"
1746 run_test 16 "Test CT bandwith control option"
1751 local f=$DIR/$tdir/$tfile
1752 touch $f || error "touch $f failed"
1754 # Could not release a non-archived file
1755 $LFS hsm_release $f && error "release should not succeed"
1757 # For following tests, we must test them with HS_ARCHIVED set
1758 $LFS hsm_set --exists --archived $f || error "could not add flag"
1760 # Could not release a file if no-release is set
1761 $LFS hsm_set --norelease $f || error "could not add flag"
1762 $LFS hsm_release $f && error "release should not succeed"
1763 $LFS hsm_clear --norelease $f || error "could not remove flag"
1765 # Could not release a file if lost
1766 $LFS hsm_set --lost $f || error "could not add flag"
1767 $LFS hsm_release $f && error "release should not succeed"
1768 $LFS hsm_clear --lost $f || error "could not remove flag"
1770 # Could not release a file if dirty
1771 $LFS hsm_set --dirty $f || error "could not add flag"
1772 $LFS hsm_release $f && error "release should not succeed"
1773 $LFS hsm_clear --dirty $f || error "could not remove flag"
1775 run_test 20 "Release is not permitted"
1778 # test needs a running copytool
1782 local f=$DIR/$tdir/test_release
1784 # Create a file and check its states
1785 local fid=$(make_small $f)
1786 check_hsm_flags $f "0x00000000"
1788 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1789 # used until file is flushed to disk
1790 if [ $(facet_fstype ost1) == "zfs" ]; then
1791 # this causes an OST_SYNC rpc to be sent
1792 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1793 # clear locks to reread file data
1794 cancel_lru_locks osc
1797 local orig_size=$(stat -c "%s" $f)
1798 local orig_blocks=$(stat -c "%b" $f)
1800 start_full_debug_logging
1802 $LFS hsm_archive $f || error "could not archive file"
1803 wait_request_state $fid ARCHIVE SUCCEED
1805 local blocks=$(stat -c "%b" $f)
1806 [ $blocks -eq $orig_blocks ] ||
1807 error "$f: wrong block number after archive: " \
1808 "$blocks != $orig_blocks"
1809 local size=$(stat -c "%s" $f)
1810 [ $size -eq $orig_size ] ||
1811 error "$f: wrong size after archive: $size != $orig_size"
1813 # Release and check states
1814 $LFS hsm_release $f || error "could not release file"
1815 check_hsm_flags $f "0x0000000d"
1817 blocks=$(stat -c "%b" $f)
1818 [ $blocks -gt 5 ] &&
1819 error "$f: too many blocks after release: $blocks > 5"
1820 size=$(stat -c "%s" $f)
1821 [ $size -ne $orig_size ] &&
1822 error "$f: wrong size after release: $size != $orig_size"
1824 # Check we can release an file without stripe info
1828 check_hsm_flags $f "0x00000000"
1829 $LFS hsm_archive $f || error "could not archive file"
1830 wait_request_state $fid ARCHIVE SUCCEED
1832 # Release and check states
1833 $LFS hsm_release $f || error "could not release file"
1834 check_hsm_flags $f "0x0000000d"
1836 # Release again a file that is already released is OK
1837 $LFS hsm_release $f || fail "second release should succeed"
1838 check_hsm_flags $f "0x0000000d"
1840 stop_full_debug_logging
1844 run_test 21 "Simple release tests"
1847 # test needs a running copytool
1852 local f=$DIR/$tdir/test_release
1853 local swap=$DIR/$tdir/test_swap
1855 # Create a file and check its states
1856 local fid=$(make_small $f)
1857 check_hsm_flags $f "0x00000000"
1859 $LFS hsm_archive $f || error "could not archive file"
1860 wait_request_state $fid ARCHIVE SUCCEED
1862 # Release and check states
1863 $LFS hsm_release $f || error "could not release file"
1864 check_hsm_flags $f "0x0000000d"
1867 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1872 run_test 22 "Could not swap a release file"
1875 # test needs a running copytool
1880 local f=$DIR/$tdir/test_mtime
1882 # Create a file and check its states
1883 local fid=$(make_small $f)
1884 check_hsm_flags $f "0x00000000"
1886 $LFS hsm_archive $f || error "could not archive file"
1887 wait_request_state $fid ARCHIVE SUCCEED
1889 # Set modification time in the past
1890 touch -m -a -d @978261179 $f
1892 # Release and check states
1893 $LFS hsm_release $f || error "could not release file"
1894 check_hsm_flags $f "0x0000000d"
1896 local MTIME=$(stat -c "%Y" $f)
1897 local ATIME=$(stat -c "%X" $f)
1898 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1899 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1903 run_test 23 "Release does not change a/mtime (utime)"
1906 local file=$DIR/$tdir/$tfile
1915 # test needs a running copytool
1920 fid=$(make_small $file)
1922 # Create a file and check its states
1923 check_hsm_flags $file "0x00000000"
1925 # Ensure atime is less than mtime and ctime.
1929 atime0=$(stat -c "%X" $file)
1930 mtime0=$(stat -c "%Y" $file)
1931 ctime0=$(stat -c "%Z" $file)
1933 [ $atime0 -lt $mtime0 ] ||
1934 error "atime $atime0 is not less than mtime $mtime0"
1936 [ $atime0 -lt $ctime0 ] ||
1937 error "atime $atime0 is not less than ctime $ctime0"
1939 # Archive should not change any timestamps.
1940 $LFS hsm_archive $file || error "cannot archive '$file'"
1941 wait_request_state $fid ARCHIVE SUCCEED
1943 atime1=$(stat -c "%X" $file)
1944 mtime1=$(stat -c "%Y" $file)
1945 ctime1=$(stat -c "%Z" $file)
1947 [ $atime0 -eq $atime1 ] ||
1948 error "archive changed atime from $atime0 to $atime1"
1950 [ $mtime0 -eq $mtime1 ] ||
1951 error "archive changed mtime from $mtime0 to $mtime1"
1953 [ $ctime0 -eq $ctime1 ] ||
1954 error "archive changed ctime from $ctime0 to $ctime1"
1956 # Release should not change any timestamps.
1957 $LFS hsm_release $file || error "cannot release '$file'"
1958 check_hsm_flags $file "0x0000000d"
1960 atime1=$(stat -c "%X" $file)
1961 mtime1=$(stat -c "%Y" $file)
1962 ctime1=$(stat -c "%Z" $file)
1964 [ $atime0 -eq $atime1 ] ||
1965 error "release changed atime from $atime0 to $atime1"
1967 [ $mtime0 -eq $mtime1 ] ||
1968 error "release changed mtime from $mtime0 to $mtime1"
1970 [ $ctime0 -eq $ctime1 ] ||
1971 error "release changed ctime from $ctime0 to $ctime1"
1973 # Restore should not change any timestamps.
1974 $LFS hsm_restore $file
1975 wait_request_state $fid RESTORE SUCCEED
1977 atime1=$(stat -c "%X" $file)
1978 mtime1=$(stat -c "%Y" $file)
1979 ctime1=$(stat -c "%Z" $file)
1981 [ $atime0 -eq $atime1 ] ||
1982 error "restore changed atime from $atime0 to $atime1"
1984 [ $mtime0 -eq $mtime1 ] ||
1985 error "restore changed mtime from $mtime0 to $mtime1"
1987 [ $ctime0 -eq $ctime1 ] ||
1988 error "restore changed ctime from $ctime0 to $ctime1"
1992 # Once more, after unmount and mount.
1993 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1994 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1996 atime1=$(stat -c "%X" $file)
1997 mtime1=$(stat -c "%Y" $file)
1998 ctime1=$(stat -c "%Z" $file)
2000 [ $atime0 -eq $atime1 ] ||
2001 error "remount changed atime from $atime0 to $atime1"
2003 [ $mtime0 -eq $mtime1 ] ||
2004 error "remount changed mtime from $mtime0 to $mtime1"
2006 [ $ctime0 -eq $ctime1 ] ||
2007 error "remount changed ctime from $ctime0 to $ctime1"
2009 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2012 local file=$DIR/$tdir/$tfile
2018 # Test needs a running copytool.
2022 # Check that root can do HSM actions on a regular user's file.
2024 fid=$(make_small $file)
2025 sum0=$(md5sum $file)
2027 chown $RUNAS_ID:$RUNAS_GID $file ||
2028 error "cannot chown '$file' to '$RUNAS_ID'"
2030 chmod ugo-w $DIR/$tdir ||
2031 error "cannot chmod '$DIR/$tdir'"
2033 $LFS hsm_archive $file
2034 wait_request_state $fid ARCHIVE SUCCEED
2036 $LFS hsm_release $file
2037 check_hsm_flags $file "0x0000000d"
2039 $LFS hsm_restore $file
2040 wait_request_state $fid RESTORE SUCCEED
2042 # Check that ordinary user can get HSM state.
2043 $RUNAS $LFS hsm_state $file ||
2044 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2046 $LFS hsm_release $file
2047 check_hsm_flags $file "0x0000000d"
2049 # Check that ordinary user can accessed released file.
2050 sum1=$($RUNAS md5sum $file) ||
2051 error "user '$RUNAS_ID' cannot read '$file'"
2053 [ "$sum0" == "$sum1" ] ||
2054 error "md5sum mismatch for '$file'"
2058 run_test 24b "root can archive, release, and restore user files"
2060 cleanup_test_24c() {
2062 set_hsm_param user_request_mask RESTORE
2063 set_hsm_param group_request_mask RESTORE
2064 set_hsm_param other_request_mask RESTORE
2068 local file=$DIR/$tdir/$tfile
2069 local action=archive
2074 # test needs a running copytool
2079 # Save the default masks and check that cleanup_24c will
2080 # restore the request masks correctly.
2081 user_save=$(get_hsm_param user_request_mask)
2082 group_save=$(get_hsm_param group_request_mask)
2083 other_save=$(get_hsm_param other_request_mask)
2085 [ "$user_save" == RESTORE ] ||
2086 error "user_request_mask is '$user_save' expected 'RESTORE'"
2087 [ "$group_save" == RESTORE ] ||
2088 error "group_request_mask is '$group_save' expected 'RESTORE'"
2089 [ "$other_save" == RESTORE ] ||
2090 error "other_request_mask is '$other_save' expected 'RESTORE'"
2092 trap cleanup_test_24c EXIT
2097 chown $RUNAS_ID:nobody $file ||
2098 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2100 $RUNAS $LFS hsm_$action $file &&
2101 error "$action by user should fail"
2103 set_hsm_param user_request_mask $action
2104 $RUNAS $LFS hsm_$action $file ||
2105 error "$action by user should succeed"
2110 chown nobody:$RUNAS_GID $file ||
2111 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2113 $RUNAS $LFS hsm_$action $file &&
2114 error "$action by group should fail"
2116 set_hsm_param group_request_mask $action
2117 $RUNAS $LFS hsm_$action $file ||
2118 error "$action by group should succeed"
2123 chown nobody:nobody $file ||
2124 error "cannot chown '$file' to 'nobody:nobody'"
2126 $RUNAS $LFS hsm_$action $file &&
2127 error "$action by other should fail"
2129 set_hsm_param other_request_mask $action
2130 $RUNAS $LFS hsm_$action $file ||
2131 error "$action by other should succeed"
2136 run_test 24c "check that user,group,other request masks work"
2138 cleanup_test_24d() {
2140 mount -o remount,rw $MOUNT2
2144 local file1=$DIR/$tdir/$tfile
2145 local file2=$DIR2/$tdir/$tfile
2153 fid1=$(make_small $file1)
2155 trap cleanup_test_24d EXIT
2157 mount -o remount,ro $MOUNT2
2159 fid2=$(path2fid $file2)
2160 [ "$fid1" == "$fid2" ] ||
2161 error "FID mismatch '$fid1' != '$fid2'"
2163 $LFS hsm_archive $file2 &&
2164 error "archive should fail on read-only mount"
2165 check_hsm_flags $file1 "0x00000000"
2167 $LFS hsm_archive $file1
2168 wait_request_state $fid1 ARCHIVE SUCCEED
2170 $LFS hsm_release $file1
2171 $LFS hsm_restore $file2
2172 wait_request_state $fid1 RESTORE SUCCEED
2174 $LFS hsm_release $file1 || error "cannot release '$file1'"
2175 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2177 $LFS hsm_release $file2 &&
2178 error "release should fail on read-only mount"
2183 run_test 24d "check that read-only mounts are respected"
2190 local f=$DIR/$tdir/$tfile
2193 fid=$(make_small $f) || error "cannot create $f"
2194 $LFS hsm_archive $f || error "cannot archive $f"
2195 wait_request_state $fid ARCHIVE SUCCEED
2196 $LFS hsm_release $f || error "cannot release $f"
2197 while ! $LFS hsm_state $f | grep released; do
2201 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2205 run_test 24e "tar succeeds on HSM released files" # LU-6213
2209 # test needs a running copytool
2212 mkdir -p $DIR/$tdir/d1
2213 local f=$DIR/$tdir/$tfile
2214 local fid=$(copy_file /etc/hosts $f)
2217 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2218 error "hsm_archive failed"
2219 wait_request_state $fid ARCHIVE SUCCEED
2220 $LFS hsm_release $f || error "cannot release $f"
2221 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2224 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2225 error "Can not recover the tar contents"
2227 echo "Sum0 = $sum0, sum1 = $sum1"
2228 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2232 run_test 24f "root can archive, release, and restore tar files"
2235 # test needs a running copytool
2239 copy2archive /etc/hosts $tdir/$tfile
2241 local f=$DIR/$tdir/$tfile
2243 import_file $tdir/$tfile $f
2245 $LFS hsm_set --lost $f
2250 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2254 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2255 " (Operation not permitted)"
2258 # test needs a running copytool
2263 local f=$DIR/$tdir/$tfile
2264 local fid=$(copy_file /etc/passwd $f)
2266 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2267 wait_request_state $fid ARCHIVE SUCCEED
2270 $LFS hsm_set --lost $f
2274 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2278 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2279 " (Operation not permitted)"
2282 # test needs a running copytool
2286 local f=$DIR/$tdir/$tfile
2288 fid=$(make_custom_file_for_progress $f 39 1000000)
2289 [ $? != 0 ] && skip "not enough free space" && return
2291 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2292 wait_request_state $fid ARCHIVE SUCCEED
2295 wait_request_state $fid REMOVE SUCCEED
2297 check_hsm_flags $f "0x00000000"
2301 run_test 26 "Remove the archive of a valid file"
2304 # test needs a running copytool
2308 make_archive $tdir/$tfile
2309 local f=$DIR/$tdir/$tfile
2310 import_file $tdir/$tfile $f
2311 local fid=$(path2fid $f)
2315 [[ $? != 0 ]] || error "Remove of a released file should fail"
2319 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2322 # test needs a running copytool
2326 local f=$DIR/$tdir/$tfile
2328 fid=$(make_custom_file_for_progress $f 39 1000000)
2329 [ $? != 0 ] && skip "not enough free space" && return
2331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2332 wait_request_state $fid ARCHIVE SUCCEED
2337 [[ $? != 0 ]] || error "Remove of a released file should fail"
2341 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2344 # test needs a running copytool
2348 local f=$DIR/$tdir/$tfile
2350 fid=$(make_custom_file_for_progress $f 39 1000000)
2351 [ $? != 0 ] && skip "not enough free space" && return
2353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2354 wait_request_state $fid ARCHIVE SUCCEED
2363 wait_request_state $fid REMOVE SUCCEED
2367 run_test 28 "Concurrent archive/file remove"
2370 # Tests --mntpath and --archive options
2373 copytool_setup $SINGLEAGT $MOUNT $archive_id
2375 # Bad archive number
2376 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2377 grep "Invalid argument" ||
2378 error "unexpected hsm_remove failure (1)"
2380 # mntpath is present but file is given
2381 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2382 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2383 error "unexpected hsm_remove failure (2)"
2387 run_test 29a "Tests --mntpath and --archive options"
2390 # test needs a running copytool
2394 local f=$DIR/$tdir/$tfile
2395 local fid=$(make_small $f)
2397 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2398 wait_request_state $fid ARCHIVE SUCCEED
2402 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2403 wait_request_state $fid REMOVE SUCCEED
2407 run_test 29b "Archive/delete/remove by FID from the archive."
2410 # test needs a running copytool
2414 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2415 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2416 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2419 wait_request_state $fid1 ARCHIVE SUCCEED
2420 wait_request_state $fid2 ARCHIVE SUCCEED
2421 wait_request_state $fid3 ARCHIVE SUCCEED
2423 rm -f $DIR/$tdir/$tfile-[1-3]
2425 echo $fid1 > $DIR/$tdir/list
2426 echo $fid2 >> $DIR/$tdir/list
2427 echo $fid3 >> $DIR/$tdir/list
2429 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2430 --filelist $DIR/$tdir/list
2431 wait_request_state $fid1 REMOVE SUCCEED
2432 wait_request_state $fid2 REMOVE SUCCEED
2433 wait_request_state $fid3 REMOVE SUCCEED
2437 run_test 29c "Archive/delete/remove by FID, using a file list."
2440 # test needs more than one CT
2441 needclients 3 || return 0
2447 copytool_cleanup $(comma_list $(agts_nodes))
2449 # start all of the copytools
2450 for n in $(seq $AGTCOUNT); do
2451 copytool_setup agt$n $MOUNT2 $n
2454 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2457 file=$DIR/$tdir/$tfile
2458 fid=$(make_small $file)
2460 $LFS hsm_archive $file
2461 wait_request_state $fid ARCHIVE SUCCEED
2462 check_hsm_flags $file "0x00000009"
2466 $LFS hsm_remove -a 0 $fid
2468 # give time for CDT to handle remove request and create broadcasted
2471 # remove request has been broadcasted ?
2472 local cnt=$(get_request_count $fid REMOVE)
2473 # broadcasted requests + original
2474 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2475 error "remove not broadcasted to all CTs"
2477 # give time for CDT and CTs to handle broadcasted
2478 wait_for_loop_period
2480 # each agent serves one different archive_id, so broadcasted
2481 # hsm_remove request should only succeed once and fail at all others
2485 for n in $(seq $AGTCOUNT); do
2486 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2487 $HSM_PARAM.actions | awk \
2488 '/'$fid'.*action=REMOVE archive#='$n'/ \
2489 {print \\\$13}' | cut -f2 -d=")
2490 if [[ "$res" == "SUCCEED" ]]; then
2492 elif [[ "$res" == "FAILED" ]]; then
2497 [[ $scnt -ne 1 ]] &&
2498 error "one and only CT should have removed successfully"
2500 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2501 error "all but one CT should have failed to remove"
2504 copytool_cleanup $(comma_list $(agts_nodes))
2507 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2508 "request to be sent once for each registered archive_id"
2511 # restore at exec cannot work on agent node (because of Linux kernel
2512 # protection of executables)
2513 needclients 2 || return 0
2515 # test needs a running copytool
2519 copy2archive /bin/true $tdir/$tfile
2521 local f=$DIR/$tdir/true
2522 import_file $tdir/$tfile $f
2524 local fid=$(path2fid $f)
2526 # set no retry action mode
2532 # remove no try action mode
2536 [[ $st == 0 ]] || error "Failed to exec a released file"
2540 run_test 30a "Restore at exec (import case)"
2543 # restore at exec cannot work on agent node (because of Linux kernel
2544 # protection of executables)
2545 needclients 2 || return 0
2547 # test needs a running copytool
2551 local f=$DIR/$tdir/true
2552 local fid=$(copy_file /bin/true $f)
2554 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2555 wait_request_state $fid ARCHIVE SUCCEED
2558 # set no retry action mode
2564 # remove no try action mode
2568 [[ $st == 0 ]] || error "Failed to exec a released file"
2572 run_test 30b "Restore at exec (release case)"
2575 needclients 2 || return 0
2577 # test needs a running copytool
2581 local f=$DIR/$tdir/SLEEP
2582 local slp_sum1=$(md5sum /bin/sleep)
2583 local fid=$(copy_file /bin/sleep $f)
2585 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2586 wait_request_state $fid ARCHIVE SUCCEED
2588 check_hsm_flags $f "0x0000000d"
2589 # set no retry action mode
2591 do_node $CLIENT2 "$f 10" &
2595 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2597 [[ $? == 0 ]] || error "Execution failed during run"
2599 if [[ $? != 0 ]]; then
2600 local slp_sum2=$(md5sum /bin/sleep)
2601 # in case sleep file is modified during the test
2602 [[ $slp_sum1 == $slp_sum2 ]] &&
2603 error "Binary overwritten during exec"
2607 # remove no try action mode
2609 check_hsm_flags $f "0x00000009"
2613 run_test 30c "Update during exec of released file must fail"
2615 restore_and_check_size() {
2618 local s=$(stat -c "%s" $f)
2620 local st=$(get_hsm_flags $f)
2624 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2626 n=$(stat -c "%s" $f)
2627 # we echo in both cases to show stat is not hang
2628 if [[ $n != $s ]]; then
2629 echo "size seen is $n != $s"
2632 echo "size seen is right: $n == $s"
2636 st=$(get_hsm_flags $f)
2638 if [[ "$st" = "0x00000009" ]]; then
2641 echo " restore is too long"
2642 wait_request_state $fid RESTORE SUCCEED
2648 # test needs a running copytool
2653 make_archive $tdir/$tfile
2654 local f=$DIR/$tdir/$tfile
2655 import_file $tdir/$tfile $f
2656 local fid=$($LFS path2fid $f)
2657 HSM_ARCHIVE_PURGE=false copytool_setup
2659 restore_and_check_size $f $fid
2662 [[ $err -eq 0 ]] || error "File size changed during restore"
2666 run_test 31a "Import a large file and check size during restore"
2670 # test needs a running copytool
2675 local f=$DIR/$tdir/$tfile
2677 fid=$(make_custom_file_for_progress $f 39 1000000)
2678 [ $? != 0 ] && skip "not enough free space" && return
2680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2681 wait_request_state $fid ARCHIVE SUCCEED
2684 restore_and_check_size $f $fid
2687 [[ $err -eq 0 ]] || error "File size changed during restore"
2691 run_test 31b "Restore a large unaligned file and check size during restore"
2694 # test needs a running copytool
2699 local f=$DIR/$tdir/$tfile
2701 fid=$(make_custom_file_for_progress $f 33 1048576)
2702 [ $? != 0 ] && skip "not enough free space" && return
2704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2705 wait_request_state $fid ARCHIVE SUCCEED
2708 restore_and_check_size $f $fid
2711 [[ $err -eq 0 ]] || error "File size changed during restore"
2715 run_test 31c "Restore a large aligned file and check size during restore"
2718 # test needs a running copytool
2723 local f=$DIR/$tdir/$tfile
2725 fid=$(make_custom_file_for_progress $f 39 1000000)
2726 [ $? != 0 ] && skip "not enough free space" && return
2728 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2729 wait_request_state $fid ARCHIVE SUCCEED
2732 # to be sure wait_all_done will not be mislead by previous tests
2735 wait_for_grace_delay
2736 # Also raise grace_delay significantly so the Canceled
2737 # Restore action will stay enough long avail.
2738 local old_grace=$(get_hsm_param grace_delay)
2739 set_hsm_param grace_delay 100
2741 md5sum $f >/dev/null &
2743 wait_request_state $fid RESTORE STARTED
2748 # Check restore trigger process was killed
2749 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2753 # instead of waiting+checking both Restore and Cancel ops
2754 # sequentially, wait for both to be finished and then check
2756 wait_all_done 100 $fid
2757 local rstate=$(get_request_state $fid RESTORE)
2758 local cstate=$(get_request_state $fid CANCEL)
2760 # restore orig grace_delay.
2761 set_hsm_param grace_delay $old_grace
2763 if [[ "$rstate" == "CANCELED" ]] ; then
2764 [[ "$cstate" == "SUCCEED" ]] ||
2765 error "Restore state is CANCELED and Cancel state " \
2766 "is not SUCCEED but $cstate"
2767 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2768 elif [[ "$rstate" == "SUCCEED" ]] ; then
2769 [[ "$cstate" == "FAILED" ]] ||
2770 error "Restore state is SUCCEED and Cancel state " \
2771 "is not FAILED but $cstate"
2772 echo "Restore state is SUCCEED, Cancel state is FAILED"
2774 error "Restore state is $rstate and Cancel state is $cstate"
2778 error "Cannot kill process waiting for restore ($killed)"
2782 run_test 33 "Kill a restore waiting process"
2785 # test needs a running copytool
2790 local f=$DIR/$tdir/$tfile
2792 fid=$(make_custom_file_for_progress $f 39 1000000)
2793 [ $? != 0 ] && skip "not enough free space" && return
2795 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2796 wait_request_state $fid ARCHIVE SUCCEED
2799 md5sum $f >/dev/null &
2801 wait_request_state $fid RESTORE STARTED
2803 rm $f || error "rm $f failed"
2804 # rm must not block during restore
2805 wait_request_state $fid RESTORE STARTED
2807 wait_request_state $fid RESTORE SUCCEED
2808 # check md5sum pgm finished
2809 local there=$(ps -o pid,comm hp $pid >/dev/null)
2810 [[ -z $there ]] || error "Restore initiator does not exit"
2812 local rc=$(wait $pid)
2813 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2817 run_test 34 "Remove file during restore"
2820 # test needs a running copytool
2825 local f=$DIR/$tdir/$tfile
2826 local f1=$DIR/$tdir/$tfile-1
2828 fid=$(make_custom_file_for_progress $f 39 1000000)
2829 [ $? != 0 ] && skip "not enough free space" && return
2831 local fid1=$(copy_file /etc/passwd $f1)
2832 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2833 wait_request_state $fid ARCHIVE SUCCEED
2836 md5sum $f >/dev/null &
2838 wait_request_state $fid RESTORE STARTED
2840 mv $f1 $f || error "mv $f1 $f failed"
2841 # mv must not block during restore
2842 wait_request_state $fid RESTORE STARTED
2844 wait_request_state $fid RESTORE SUCCEED
2845 # check md5sum pgm finished
2846 local there=$(ps -o pid,comm hp $pid >/dev/null)
2847 [[ -z $there ]] || error "Restore initiator does not exit"
2849 local rc=$(wait $pid)
2850 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2853 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2857 run_test 35 "Overwrite file during restore"
2860 # test needs a running copytool
2865 local f=$DIR/$tdir/$tfile
2867 fid=$(make_custom_file_for_progress $f 39 1000000)
2868 [ $? != 0 ] && skip "not enough free space" && return
2870 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2871 wait_request_state $fid ARCHIVE SUCCEED
2874 md5sum $f >/dev/null &
2876 wait_request_state $fid RESTORE STARTED
2879 # rm must not block during restore
2880 wait_request_state $fid RESTORE STARTED
2882 wait_request_state $fid RESTORE SUCCEED
2883 # check md5sum pgm finished
2884 local there=$(ps -o pid,comm hp $pid >/dev/null)
2886 error "Restore initiator does not exit"
2888 local rc=$(wait $pid)
2890 error "Restore initiator failed with $rc"
2894 run_test 36 "Move file during restore"
2897 # LU-5683: check that an archived dirty file can be rearchived.
2899 copytool_setup $SINGLEAGT $MOUNT2
2902 local f=$DIR/$tdir/$tfile
2905 fid=$(make_small $f) || error "cannot create small file"
2907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2908 wait_request_state $fid ARCHIVE SUCCEED
2909 $LFS hsm_release $f || error "cannot release $f"
2911 # Allow previous archive request to expire from the actions log.
2912 wait_for_grace_delay
2915 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2917 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2918 wait_request_state $fid ARCHIVE SUCCEED
2922 run_test 37 "re-archive a dirty file"
2929 for n in $(seq 1 $count); do
2930 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2932 echo "$count archive requests submitted"
2936 local stream_count=4
2937 local file_count=100
2939 local f=$DIR/$tdir/$tfile
2944 for i in $(seq 1 $file_count); do
2945 for p in $(seq 1 $stream_count); do
2946 fid=$(copy_file /etc/hosts $f.$p.$i)
2949 # force copytool to use a local/temp archive dir to ensure best
2950 # performance vs remote/NFS mounts used in auto-tests
2951 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2954 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2956 # to be sure wait_all_done will not be mislead by previous tests
2958 wait_for_grace_delay
2960 # start archive streams in background (archive files in parallel)
2961 for p in $(seq 1 $stream_count); do
2962 multi_archive $f.$p $file_count &
2965 echo -n "Wait for all requests being enqueued..."
2971 run_test 40 "Parallel archive requests"
2974 # test needs a running copytool
2978 local f=$DIR/$tdir/$tfile
2979 local fid=$(copy_file /etc/motd $f 1)
2981 $LFS hsm_archive $f || error "could not archive file"
2982 wait_request_state $fid ARCHIVE SUCCEED
2983 check_hsm_flags $f "0x00000009"
2985 multiop_bg_pause $f O_c || error "multiop failed"
2989 client_up || client_up || true
2991 kill -USR1 $MULTIPID
2992 wait $MULTIPID || error "multiop close failed"
2994 check_hsm_flags $f "0x0000000b"
2998 run_test 52 "Opened for write file on an evicted client should be set dirty"
3001 # test needs a running copytool
3005 local f=$DIR/$tdir/$tfile
3006 local fid=$(copy_file /etc/motd $f 1)
3008 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3009 error "could not archive file"
3010 wait_request_state $fid ARCHIVE SUCCEED
3011 check_hsm_flags $f "0x00000009"
3013 multiop_bg_pause $f o_c || error "multiop failed"
3017 client_up || client_up || true
3019 kill -USR1 $MULTIPID
3020 wait $MULTIPID || error "multiop close failed"
3022 check_hsm_flags $f "0x00000009"
3026 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3029 # test needs a running copytool
3033 local f=$DIR/$tdir/$tfile
3034 local fid=$(make_custom_file_for_progress $f 39 1000000)
3036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3037 error "could not archive file"
3038 wait_request_state $fid ARCHIVE STARTED
3040 check_hsm_flags $f "0x00000001"
3042 # Avoid coordinator resending this request as soon it has failed.
3047 wait_request_state $fid ARCHIVE FAILED
3049 check_hsm_flags $f "0x00000003"
3054 run_test 54 "Write during an archive cancels it"
3057 # test needs a running copytool
3061 local f=$DIR/$tdir/$tfile
3062 local fid=$(make_custom_file_for_progress $f 39 1000000)
3064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3065 error "could not archive file"
3066 wait_request_state $fid ARCHIVE STARTED
3068 check_hsm_flags $f "0x00000001"
3070 # Avoid coordinator resending this request as soon it has failed.
3073 $TRUNCATE $f 1024 || error "truncate failed"
3075 wait_request_state $fid ARCHIVE FAILED
3077 check_hsm_flags $f "0x00000003"
3082 run_test 55 "Truncate during an archive cancels it"
3085 # test needs a running copytool
3089 local f=$DIR/$tdir/$tfile
3091 fid=$(make_custom_file_for_progress $f 39 1000000)
3092 [ $? != 0 ] && skip "not enough free space" && return
3094 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3095 error "could not archive file"
3096 wait_request_state $fid ARCHIVE STARTED
3098 check_hsm_flags $f "0x00000001"
3100 # Change metadata and sync to be sure we are not changing only
3105 wait_request_state $fid ARCHIVE SUCCEED
3107 check_hsm_flags $f "0x00000009"
3111 run_test 56 "Setattr during an archive is ok"
3114 # Need one client for I/O, one for request
3115 needclients 2 || return 0
3117 # test needs a running copytool
3121 local f=$DIR/$tdir/test_archive_remote
3122 # Create a file on a remote node
3123 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3124 "count=2 conv=fsync"
3127 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3128 error "hsm_archive failed"
3129 local fid=$(path2fid $f)
3130 wait_request_state $fid ARCHIVE SUCCEED
3132 # Release and implicit restore it
3133 do_node $CLIENT2 "$LFS hsm_release $f" ||
3134 error "hsm_release failed"
3135 do_node $CLIENT2 "md5sum $f" ||
3136 error "hsm_restore failed"
3138 wait_request_state $fid RESTORE SUCCEED
3142 run_test 57 "Archive a file with dirty cache on another node"
3144 truncate_released_file() {
3148 local sz=$(stat -c %s $src_file)
3149 local f=$DIR/$tdir/$tfile
3150 local fid=$(copy_file $1 $f)
3154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3155 error "could not archive file"
3156 wait_request_state $fid ARCHIVE SUCCEED
3158 $LFS hsm_release $f || error "could not release file"
3160 $TRUNCATE $f $trunc_to || error "truncate failed"
3163 local sz1=$(stat -c %s $f)
3164 [[ $sz1 == $trunc_to ]] ||
3165 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3168 check_hsm_flags $f "0x0000000b"
3170 local state=$(get_request_state $fid RESTORE)
3171 [[ "$state" == "SUCCEED" ]] ||
3172 error "truncate $sz does not trig restore, state = $state"
3174 $TRUNCATE $ref $trunc_to
3175 cmp $ref $f || error "file data wrong after truncate"
3181 # test needs a running copytool
3186 local sz=$(stat -c %s /etc/passwd)
3188 echo "truncate up from $sz to $((sz*2))"
3189 truncate_released_file /etc/passwd $((sz*2))
3191 echo "truncate down from $sz to $((sz/2))"
3192 truncate_released_file /etc/passwd $((sz/2))
3194 echo "truncate to 0"
3195 truncate_released_file /etc/passwd 0
3199 run_test 58 "Truncate a released file will trigger restore"
3203 local server_version=$(lustre_version_code $SINGLEMDS)
3204 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3205 skip "Need MDS version at least 2.7.63" && return
3208 $MCREATE $DIR/$tfile || error "mcreate failed"
3209 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3210 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3211 fid=$(path2fid $DIR/$tfile)
3212 wait_request_state $fid ARCHIVE SUCCEED
3213 $LFS hsm_release $DIR/$tfile || error "release failed"
3216 run_test 59 "Release stripeless file with non-zero size"
3219 # This test validates the fix for LU-4512. Ensure that the -u
3220 # option changes the progress reporting interval from the
3221 # default (30 seconds) to the user-specified interval.
3223 local progress_timeout=$((interval * 4))
3225 # test needs a new running copytool
3227 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3230 local f=$DIR/$tdir/$tfile
3232 fid=$(make_custom_file_for_progress $f 10)
3233 [ $? != 0 ] && skip "not enough free space" && return
3236 local mdt=${MDT_PREFIX}${mdtidx}
3237 local mds=mds$((mdtidx + 1))
3239 # Wait for copytool to register
3240 wait_update_facet $mds \
3241 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3242 uuid 100 || error "coyptool failed to register with $mdt"
3244 local start_at=$(date +%s)
3245 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3246 error "could not archive file"
3248 local agent=$(facet_active_host $SINGLEAGT)
3249 local prefix=$TESTLOG_PREFIX
3250 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3251 local copytool_log=$prefix.copytool_log.$agent.log
3254 wait_update $agent \
3255 "grep -o start.copy $copytool_log" "start copy" 100 ||
3256 error "copytool failed to start"
3258 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3259 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3265 echo -n "Expecting a progress update within $progress_timeout seconds... "
3267 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3268 if [ $RESULT -gt 0 ]; then
3269 echo "$RESULT bytes copied in $WAIT seconds."
3271 elif [ $WAIT -ge $progress_timeout ]; then
3272 error "Timed out waiting for progress update!"
3275 WAIT=$((WAIT + sleep))
3279 local finish_at=$(date +%s)
3280 local elapsed=$((finish_at - start_at))
3282 # Ensure that the progress update occurred within the expected window.
3283 if [ $elapsed -lt $((interval - 1)) ]; then
3284 error "Expected progress update after at least $interval seconds"
3287 echo "Wait for on going archive hsm action to complete"
3288 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3289 echo "File archiving not completed even after 10 secs"
3294 run_test 60 "Changing progress update interval from default"
3297 # test needs a new running copytool
3299 copytool_monitor_setup
3300 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3302 # Just start and stop the copytool to generate events.
3305 # Wait for the copytool to register.
3306 wait_update --verbose $(facet_active_host mds1) \
3307 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3309 error "copytool failed to register with MDT0000"
3313 local REGISTER_EVENT
3314 local UNREGISTER_EVENT
3315 while read event; do
3316 local parsed=$(parse_json_event "$event")
3317 if [ -z "$parsed" ]; then
3318 error "Copytool sent malformed event: $event"
3322 if [ $event_type == "REGISTER" ]; then
3323 REGISTER_EVENT=$event
3324 elif [ $event_type == "UNREGISTER" ]; then
3325 UNREGISTER_EVENT=$event
3327 done < <(echo $"$(get_copytool_event_log)")
3329 if [ -z "$REGISTER_EVENT" ]; then
3330 error "Copytool failed to send register event to FIFO"
3333 if [ -z "$UNREGISTER_EVENT" ]; then
3334 error "Copytool failed to send unregister event to FIFO"
3337 copytool_monitor_cleanup
3338 echo "Register/Unregister events look OK."
3340 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3343 # Bump progress interval for livelier events.
3346 # test needs a new running copytool
3348 copytool_monitor_setup
3349 HSMTOOL_UPDATE_INTERVAL=$interval \
3350 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3353 local f=$DIR/$tdir/$tfile
3355 fid=$(make_custom_file_for_progress $f 39 1000000)
3356 [ $? != 0 ] && skip "not enough free space" && return
3358 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3359 error "could not archive file"
3360 wait_request_state $fid ARCHIVE SUCCEED
3362 local expected_fields="event_time data_fid source_fid"
3363 expected_fields+=" total_bytes current_bytes"
3367 while read event; do
3368 # Make sure we're not getting anything from previous events.
3369 for field in $expected_fields; do
3373 local parsed=$(parse_json_event "$event")
3374 if [ -z "$parsed" ]; then
3375 error "Copytool sent malformed event: $event"
3379 if [ $event_type == "ARCHIVE_START" ]; then
3382 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3385 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3389 # Do some simple checking of the progress update events.
3390 for expected_field in $expected_fields; do
3391 if [ -z ${!expected_field+x} ]; then
3392 error "Missing $expected_field field in event"
3396 if [ $total_bytes -eq 0 ]; then
3397 error "Expected total_bytes to be > 0"
3400 # These should be identical throughout an archive
3402 if [ $source_fid != $data_fid ]; then
3403 error "Expected source_fid to equal data_fid"
3405 done < <(echo $"$(get_copytool_event_log)")
3407 if [ -z "$START_EVENT" ]; then
3408 error "Copytool failed to send archive start event to FIFO"
3411 if [ -z "$FINISH_EVENT" ]; then
3412 error "Copytool failed to send archive finish event to FIFO"
3415 echo "Archive events look OK."
3419 copytool_monitor_cleanup
3421 run_test 71 "Copytool logs JSON archive events to FIFO"
3424 # Bump progress interval for livelier events.
3427 # test needs a new running copytool
3429 copytool_monitor_setup
3430 HSMTOOL_UPDATE_INTERVAL=$interval \
3431 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3432 local test_file=$HSMTOOL_MONITOR_DIR/file
3434 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3436 do_facet $SINGLEAGT "$cmd" ||
3437 error "cannot create $test_file on $SINGLEAGT"
3438 copy2archive $test_file $tdir/$tfile
3441 local f=$DIR/$tdir/$tfile
3442 import_file $tdir/$tfile $f
3443 f=$DIR2/$tdir/$tfile
3444 echo "Verifying released state: "
3445 check_hsm_flags $f "0x0000000d"
3447 local fid=$(path2fid $f)
3449 wait_request_state $fid RESTORE SUCCEED
3451 local expected_fields="event_time data_fid source_fid"
3452 expected_fields+=" total_bytes current_bytes"
3456 while read event; do
3457 # Make sure we're not getting anything from previous events.
3458 for field in $expected_fields; do
3462 local parsed=$(parse_json_event "$event")
3463 if [ -z "$parsed" ]; then
3464 error "Copytool sent malformed event: $event"
3468 if [ $event_type == "RESTORE_START" ]; then
3470 if [ $source_fid != $data_fid ]; then
3471 error "source_fid should == data_fid at start"
3474 elif [ $event_type == "RESTORE_FINISH" ]; then
3476 if [ $source_fid != $data_fid ]; then
3477 error "source_fid should == data_fid at finish"
3480 elif [ $event_type != "RESTORE_RUNNING" ]; then
3484 # Do some simple checking of the progress update events.
3485 for expected_field in $expected_fields; do
3486 if [ -z ${!expected_field+x} ]; then
3487 error "Missing $expected_field field in event"
3491 if [ $total_bytes -eq 0 ]; then
3492 error "Expected total_bytes to be > 0"
3495 # When a restore starts out, the data fid is the same as the
3496 # source fid. After the restore has gotten going, we learn
3497 # the new data fid. Once the restore has finished, the source
3498 # fid is set to the new data fid.
3500 # We test this because some monitoring software may depend on
3501 # this behavior. If it changes, then the consumers of these
3502 # events may need to be modified.
3503 if [ $source_fid == $data_fid ]; then
3504 error "source_fid should != data_fid during restore"
3506 done < <(echo $"$(get_copytool_event_log)")
3508 if [ -z "$START_EVENT" ]; then
3509 error "Copytool failed to send restore start event to FIFO"
3512 if [ -z "$FINISH_EVENT" ]; then
3513 error "Copytool failed to send restore finish event to FIFO"
3516 echo "Restore events look OK."
3520 copytool_monitor_cleanup
3524 run_test 72 "Copytool logs JSON restore events to FIFO"
3527 file_count=51 # Max number of files constrained by LNET message size
3528 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3529 local f=$DIR/$tdir/$tfile
3530 local FILELIST=/tmp/filelist.txt
3534 for i in $(seq 1 $file_count); do
3535 fid=$(copy_file /etc/hosts $f.$i)
3536 echo $f.$i >> $FILELIST
3538 # force copytool to use a local/temp archive dir to ensure best
3539 # performance vs remote/NFS mounts used in auto-tests
3540 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3543 local dai=$(get_hsm_param default_archive_id)
3544 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3546 # to be sure wait_all_done will not be mislead by previous tests
3548 wait_for_grace_delay
3549 $LFS hsm_archive --filelist $FILELIST ||
3550 error "cannot archive a file list"
3552 $LFS hsm_release --filelist $FILELIST ||
3553 error "cannot release a file list"
3554 $LFS hsm_restore --filelist $FILELIST ||
3555 error "cannot restore a file list"
3559 run_test 90 "Archive/restore a file list"
3561 double_verify_reset_hsm_param() {
3563 echo "Testing $HSM_PARAM.$p"
3564 local val=$(get_hsm_param $p)
3566 local val2=$(($val * 2))
3567 set_hsm_param $p $val2
3568 val=$(get_hsm_param $p)
3569 [[ $val == $val2 ]] ||
3570 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3571 echo "Set $p to 0 must failed"
3575 set_hsm_param $p $save
3577 if [[ $rc == 0 ]]; then
3578 error "we must not be able to set $HSM_PARAM.$p to 0"
3583 double_verify_reset_hsm_param loop_period
3584 double_verify_reset_hsm_param grace_delay
3585 double_verify_reset_hsm_param active_request_timeout
3586 double_verify_reset_hsm_param max_requests
3587 double_verify_reset_hsm_param default_archive_id
3589 run_test 100 "Set coordinator /proc tunables"
3596 run_test 102 "Verify coordinator control"
3599 # test needs a running copytool
3606 for i in $(seq 1 20); do
3607 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3609 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3613 echo "Current requests"
3614 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3615 $HSM_PARAM.actions |\
3616 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3618 [[ -z "$res" ]] || error "Some request have not been canceled"
3622 run_test 103 "Purge all requests"
3627 # test needs a running copytool
3631 local f=$DIR/$tdir/$tfile
3633 fid=$(make_custom_file_for_progress $f 39 1000000)
3634 [ $? != 0 ] && skip "not enough free space" && return
3636 # if cdt is on, it can serve too quickly the request
3638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3639 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3640 $HSM_PARAM.actions |\
3641 grep $fid | cut -f16 -d=")
3644 [[ "$data1" == "$DATAHEX" ]] ||
3645 error "Data field in records is ($data1) and not ($DATAHEX)"
3649 run_test 104 "Copy tool data field"
3656 for i in $(seq -w 1 10); do
3657 cp /etc/passwd $DIR/$tdir/$i
3658 $LFS hsm_archive $DIR/$tdir/$i
3660 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3661 $HSM_PARAM.actions |\
3662 grep WAITING | wc -l")
3665 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3666 $HSM_PARAM.actions |\
3667 grep WAITING | wc -l")
3670 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3671 error "Requests count after shutdown $reqcnt2 != "\
3672 "before shutdown $reqcnt1"
3674 run_test 105 "Restart of coordinator"
3677 # test needs a running copytool
3680 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3682 check_agent_registered $uuid
3684 search_copytools || error "No copytool found"
3687 check_agent_unregistered $uuid
3690 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3691 check_agent_registered $uuid
3695 run_test 106 "Copytool register/unregister"
3698 # test needs a running copytool
3700 # create and archive file
3702 local f1=$DIR/$tdir/$tfile
3703 local fid=$(copy_file /etc/passwd $f1)
3704 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3705 wait_request_state $fid ARCHIVE SUCCEED
3706 # shutdown and restart MDS
3708 # check the copytool still gets messages from MDT
3709 local f2=$DIR/$tdir/2
3710 local fid=$(copy_file /etc/passwd $f2)
3711 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3712 # main check of this sanity: this request MUST succeed
3713 wait_request_state $fid ARCHIVE SUCCEED
3716 run_test 107 "Copytool re-register after MDS restart"
3718 policy_set_and_test()
3722 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3723 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3724 [[ "$policy" == "$target" ]] ||
3725 error "Wrong policy after '$change': '$policy' != '$target'"
3729 # to force default policy setting if error
3730 CDT_POLICY_HAD_CHANGED=true
3732 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3733 local default="NonBlockingRestore [NoRetryAction]"
3734 [[ "$policy" == "$default" ]] ||
3735 error "default policy has changed,"\
3736 " '$policy' != '$default' update the test"
3737 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3738 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3739 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3740 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3741 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3742 # useless bacause we know but safer for futur changes to use real value
3743 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3744 echo "Next set_param must failed"
3745 policy_set_and_test "wrong" "$policy"
3748 echo "Back to default policy"
3749 cdt_set_sanity_policy
3751 run_test 109 "Policy display/change"
3754 # test needs a running copytool
3759 copy2archive /etc/passwd $tdir/$tfile
3761 local f=$DIR/$tdir/$tfile
3762 import_file $tdir/$tfile $f
3763 local fid=$(path2fid $f)
3765 cdt_set_non_blocking_restore
3770 wait_request_state $fid RESTORE SUCCEED
3771 cdt_clear_non_blocking_restore
3775 error "md5sum returns $st != 1, "\
3776 "should also perror ENODATA (No data available)"
3780 run_test 110a "Non blocking restore policy (import case)"
3783 # test needs a running copytool
3787 local f=$DIR/$tdir/$tfile
3788 local fid=$(copy_file /etc/passwd $f)
3789 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3790 wait_request_state $fid ARCHIVE SUCCEED
3793 cdt_set_non_blocking_restore
3798 wait_request_state $fid RESTORE SUCCEED
3799 cdt_clear_non_blocking_restore
3803 error "md5sum returns $st != 1, "\
3804 "should also perror ENODATA (No data available)"
3808 run_test 110b "Non blocking restore policy (release case)"
3811 # test needs a running copytool
3815 copy2archive /etc/passwd $tdir/$tfile
3817 local f=$DIR/$tdir/$tfile
3819 import_file $tdir/$tfile $f
3820 local fid=$(path2fid $f)
3824 copytool_remove_backend $fid
3827 wait_request_state $fid RESTORE FAILED
3834 [[ $st == 0 ]] || error "Restore does not failed"
3838 run_test 111a "No retry policy (import case), restore will error"\
3839 " (No such file or directory)"
3842 # test needs a running copytool
3846 local f=$DIR/$tdir/$tfile
3847 local fid=$(copy_file /etc/passwd $f)
3849 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3850 wait_request_state $fid ARCHIVE SUCCEED
3853 copytool_remove_backend $fid
3856 wait_request_state $fid RESTORE FAILED
3863 [[ $st == 0 ]] || error "Restore does not failed"
3867 run_test 111b "No retry policy (release case), restore will error"\
3868 " (No such file or directory)"
3871 # test needs a running copytool
3875 local f=$DIR/$tdir/$tfile
3876 local fid=$(copy_file /etc/passwd $f)
3878 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3879 local l=$($LFS hsm_action $f)
3881 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3885 wait_request_state $fid ARCHIVE SUCCEED
3888 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3892 run_test 112 "State of recorded request"
3895 # test needs a running copytool
3899 local f=$DIR/$tdir/$tfile
3901 fid=$(make_custom_file_for_progress $f 103 1048576)
3902 [ $? != 0 ] && skip "not enough free space" && return
3904 # test with cdt on is made in test_221
3906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3907 # wait archive to register at CDT
3908 wait_request_state $fid ARCHIVE WAITING
3911 wait_request_state $fid ARCHIVE CANCELED
3912 wait_request_state $fid CANCEL SUCCEED
3916 run_test 200 "Register/Cancel archive"
3919 # test needs a running copytool
3923 local f=$DIR/$tdir/$tfile
3924 make_archive $tdir/$tfile
3925 import_file $tdir/$tfile $f
3926 local fid=$(path2fid $f)
3928 # test with cdt on is made in test_222
3931 # wait restore to register at CDT
3932 wait_request_state $fid RESTORE WAITING
3935 wait_request_state $fid RESTORE CANCELED
3936 wait_request_state $fid CANCEL SUCCEED
3940 run_test 201 "Register/Cancel restore"
3943 # test needs a running copytool
3947 local f=$DIR/$tdir/$tfile
3949 fid=$(make_custom_file_for_progress $f 39 1000000)
3950 [ $? != 0 ] && skip "not enough free space" && return
3952 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3953 wait_request_state $fid ARCHIVE SUCCEED
3957 # wait remove to register at CDT
3958 wait_request_state $fid REMOVE WAITING
3961 wait_request_state $fid REMOVE CANCELED
3965 run_test 202 "Register/Cancel remove"
3968 # test needs a running copytool
3973 local f=$DIR/$tdir/$tfile
3974 local fid=$(copy_file /etc/passwd $f)
3978 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3979 wait_request_state $fid ARCHIVE SUCCEED
3981 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3985 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3989 run_test 220 "Changelog for archive"
3992 # test needs a running copytool
3997 local f=$DIR/$tdir/$tfile
3998 local fid=$(copy_file /etc/passwd $f)
4002 # block copytool operations to allow for HSM request to be
4003 # submitted and file be unlinked (CDT will find object removed)
4006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4012 wait_request_state $fid ARCHIVE FAILED
4014 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4019 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4023 run_test 220a "Changelog for failed archive"
4026 # test needs a running copytool
4031 local f=$DIR/$tdir/$tfile
4033 fid=$(make_custom_file_for_progress $f 103 1048576)
4034 [ $? != 0 ] && skip "not enough free space" && return
4038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4039 wait_request_state $fid ARCHIVE STARTED
4041 wait_request_state $fid ARCHIVE CANCELED
4042 wait_request_state $fid CANCEL SUCCEED
4044 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4047 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4051 run_test 221 "Changelog for archive canceled"
4054 # test needs a running copytool
4058 copy2archive /etc/passwd $tdir/$tfile
4060 local f=$DIR/$tdir/$tfile
4061 import_file $tdir/$tfile $f
4062 local fid=$(path2fid $f)
4067 wait_request_state $fid RESTORE SUCCEED
4069 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4072 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4076 run_test 222a "Changelog for explicit restore"
4079 # test needs a running copytool
4083 local f=$DIR/$tdir/$tfile
4084 local fid=$(copy_file /etc/passwd $f)
4087 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4088 wait_request_state $fid ARCHIVE SUCCEED
4093 wait_request_state $fid RESTORE SUCCEED
4095 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4098 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4102 run_test 222b "Changelog for implicit restore"
4105 # test needs a running copytool
4109 copy2archive /etc/passwd $tdir/$tfile
4111 local f=$DIR/$tdir/$tfile
4112 import_file $tdir/$tfile $f
4113 local fid=$(path2fid $f)
4117 # block copytool operations to allow for HSM request to be
4118 # submitted and file be unlinked (CDT will find object removed)
4126 wait_request_state $fid RESTORE FAILED
4128 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4132 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4136 run_test 222c "Changelog for failed explicit restore"
4139 # test needs a running copytool
4143 local f=$DIR/$tdir/$tfile
4144 local fid=$(copy_file /etc/passwd $f)
4147 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4148 wait_request_state $fid ARCHIVE SUCCEED
4151 copytool_remove_backend $fid
4154 wait_request_state $fid RESTORE FAILED
4156 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4160 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4164 run_test 222d "Changelog for failed implicit restore"
4167 # test needs a running copytool
4172 local f=$DIR/$tdir/$tfile
4173 make_archive $tdir/$tfile
4177 import_file $tdir/$tfile $f
4178 local fid=$(path2fid $f)
4181 wait_request_state $fid RESTORE STARTED
4183 wait_request_state $fid RESTORE CANCELED
4184 wait_request_state $fid CANCEL SUCCEED
4186 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4189 [[ $flags == $target ]] ||
4190 error "Changelog flag is $flags not $target"
4194 run_test 223a "Changelog for restore canceled (import case)"
4197 # test needs a running copytool
4202 local f=$DIR/$tdir/$tfile
4204 fid=$(make_custom_file_for_progress $f 39 1000000)
4205 [ $? != 0 ] && skip "not enough free space" && return
4208 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4209 wait_request_state $fid ARCHIVE SUCCEED
4212 wait_request_state $fid RESTORE STARTED
4214 wait_request_state $fid RESTORE CANCELED
4215 wait_request_state $fid CANCEL SUCCEED
4217 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4220 [[ $flags == $target ]] ||
4221 error "Changelog flag is $flags not $target"
4225 run_test 223b "Changelog for restore canceled (release case)"
4228 # test needs a running copytool
4233 local f=$DIR/$tdir/$tfile
4234 local fid=$(copy_file /etc/passwd $f)
4237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4238 wait_request_state $fid ARCHIVE SUCCEED
4241 wait_request_state $fid REMOVE SUCCEED
4243 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4246 [[ $flags == $target ]] ||
4247 error "Changelog flag is $flags not $target"
4251 run_test 224 "Changelog for remove"
4254 # test needs a running copytool
4259 local f=$DIR/$tdir/$tfile
4260 local fid=$(copy_file /etc/passwd $f)
4263 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4264 wait_request_state $fid ARCHIVE SUCCEED
4266 copytool_remove_backend $fid
4268 # block copytool operations to allow for HSM request to be
4269 # submitted and file be unlinked (CDT will find object removed)
4277 wait_request_state $fid REMOVE FAILED
4279 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4283 [[ $flags == $target ]] ||
4284 error "Changelog flag is $flags not $target"
4288 run_test 224a "Changelog for failed remove"
4291 # test needs a running copytool
4294 # test is not usable because remove request is too fast
4295 # so it is always finished before cancel can be done ...
4296 echo "Test disabled"
4301 local f=$DIR/$tdir/$tfile
4303 fid=$(make_custom_file_for_progress $f 39 1000000)
4304 [ $? != 0 ] && skip "not enough free space" && return
4307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4308 wait_request_state $fid ARCHIVE SUCCEED
4310 # if cdt is on, it can serve too quickly the request
4315 wait_request_state $fid REMOVE CANCELED
4316 wait_request_state $fid CANCEL SUCCEED
4318 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4319 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4320 tail -n 1 | awk '{print $5}')
4323 [[ $flags == $target ]] ||
4324 error "Changelog flag is $flags not $target"
4328 run_test 225 "Changelog for remove canceled"
4331 # test needs a running copytool
4336 local f1=$DIR/$tdir/$tfile-1
4337 local f2=$DIR/$tdir/$tfile-2
4338 local f3=$DIR/$tdir/$tfile-3
4339 local fid1=$(copy_file /etc/passwd $f1)
4340 local fid2=$(copy_file /etc/passwd $f2)
4341 copy_file /etc/passwd $f3
4344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4345 wait_request_state $fid1 ARCHIVE SUCCEED
4347 $LFS hsm_archive $f2
4348 wait_request_state $fid2 ARCHIVE SUCCEED
4350 rm $f1 || error "rm $f1 failed"
4352 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4355 [[ $flags == $target ]] ||
4356 error "Changelog flag is $flags not $target"
4358 mv $f3 $f2 || error "mv $f3 $f2 failed"
4360 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4363 [[ $flags == $target ]] ||
4364 error "Changelog flag is $flags not $target"
4368 run_test 226 "changelog for last rm/mv with exiting archive"
4370 check_flags_changes() {
4378 $LFS hsm_set --$hsm_flag $f ||
4379 error "Cannot set $hsm_flag on $f"
4380 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4381 local seen=${#flags[*]}
4383 [[ $seen == $cnt ]] ||
4384 error "set $hsm_flag: Changelog events $seen != $cnt"
4385 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4386 error "set $hsm_flag: Changelog flags are "\
4387 "${flags[$((cnt - 1))]} not $target"
4389 $LFS hsm_clear --$hsm_flag $f ||
4390 error "Cannot clear $hsm_flag on $f"
4391 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4394 [[ $cnt == $seen ]] ||
4395 error "clear $hsm_flag: Changelog events $seen != $cnt"
4397 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4398 error "clear $hsm_flag: Changelog flag is "\
4399 "${flags[$((cnt - 1))]} not $target"
4403 # test needs a running copytool
4410 for i in norelease noarchive exists archived
4412 local f=$DIR/$tdir/$tfile-$i
4413 local fid=$(copy_file /etc/passwd $f)
4414 check_flags_changes $f $fid $i 0 1
4417 f=$DIR/$tdir/$tfile---lost
4418 fid=$(copy_file /etc/passwd $f)
4419 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4420 wait_request_state $fid ARCHIVE SUCCEED
4421 check_flags_changes $f $fid lost 3 1
4425 run_test 227 "changelog when explicit setting of HSM flags"
4428 # test needs a running copytool
4431 local fid=$(make_small_sync $DIR/$tfile)
4432 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4433 wait_request_state $fid ARCHIVE SUCCEED
4435 $LFS hsm_release $DIR/$tfile
4436 check_hsm_flags $DIR/$tfile "0x0000000d"
4438 filefrag $DIR/$tfile | grep " 1 extent found" ||
4439 error "filefrag on released file must return only one extent"
4441 # only newer versions of cp detect sparse files by stat/FIEMAP
4443 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4444 error "copying $DIR/$tfile"
4445 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4447 $LFS hsm_release $DIR/$tfile
4448 check_hsm_flags $DIR/$tfile "0x0000000d"
4450 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4452 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4454 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4455 error "comparing untarred $DIR/$tfile"
4457 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4458 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4461 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4464 # test needs a running copytool
4468 local maxrequest=$(get_hsm_param max_requests)
4469 local rqcnt=$(($maxrequest * 3))
4473 for i in $(seq -w 1 $rqcnt); do
4475 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4477 # we do it in 2 steps, so all requests arrive at the same time
4478 for i in $(seq -w 1 $rqcnt); do
4479 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4484 while [[ $cnt != 0 || $wt != 0 ]]; do
4486 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4487 $HSM_PARAM.actions |\
4488 grep STARTED | grep -v CANCEL | wc -l")
4489 [[ $cnt -le $maxrequest ]] ||
4490 error "$cnt > $maxrequest too many started requests"
4491 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4492 $HSM_PARAM.actions |\
4493 grep WAITING | wc -l")
4494 echo "max=$maxrequest started=$cnt waiting=$wt"
4499 run_test 250 "Coordinator max request"
4502 # test needs a running copytool
4506 local f=$DIR/$tdir/$tfile
4508 fid=$(make_custom_file_for_progress $f 103 1048576)
4509 [ $? != 0 ] && skip "not enough free space" && return
4512 # to have a short test
4513 local old_to=$(get_hsm_param active_request_timeout)
4514 set_hsm_param active_request_timeout 4
4515 # to be sure the cdt will wake up frequently so
4516 # it will be able to cancel the "old" request
4517 local old_loop=$(get_hsm_param loop_period)
4518 set_hsm_param loop_period 2
4521 # clear locks to avoid extra delay caused by flush/cancel
4522 # and thus prevent early copytool death to timeout.
4523 cancel_lru_locks osc
4525 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4526 wait_request_state $fid ARCHIVE STARTED
4528 wait_request_state $fid ARCHIVE CANCELED
4530 set_hsm_param active_request_timeout $old_to
4531 set_hsm_param loop_period $old_loop
4535 run_test 251 "Coordinator request timeout"
4538 # the only way to test ondisk conf is to restart MDS ...
4539 echo "Stop coordinator and remove coordinator state at mount"
4542 # clean on disk conf set by default
4543 cdt_clear_mount_state
4544 cdt_check_state stopped
4546 # check cdt still off after umount/remount
4548 cdt_check_state stopped
4550 echo "Set coordinator start at mount, and start coordinator"
4551 cdt_set_mount_state enabled
4554 cdt_check_state enabled
4556 # check cdt still on after umount/remount
4558 cdt_check_state enabled
4560 # we are back to original state (cdt started at mount)
4562 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4565 local ai=$(get_hsm_param default_archive_id)
4566 local new=$((ai + 1))
4568 set_hsm_param default_archive_id $new -P
4570 local res=$(get_hsm_param default_archive_id)
4573 set_hsm_param default_archive_id "" "-P -d"
4575 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4577 run_test 301 "HSM tunnable are persistent"
4580 local ai=$(get_hsm_param default_archive_id)
4581 local new=$((ai + 1))
4586 set_hsm_param default_archive_id $new -P
4589 for mdtno in $(seq 1 $MDSCOUNT); do
4594 cdt_check_state enabled
4596 local res=$(get_hsm_param default_archive_id)
4599 set_hsm_param default_archive_id "" "-P -d"
4601 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4603 run_test 302 "HSM tunnable are persistent when CDT is off"
4606 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4612 local dir_mdt0=$DIR/$tdir/mdt0
4613 local dir_mdt1=$DIR/$tdir/mdt1
4615 # create 1 dir per MDT
4616 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4617 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4619 # create 1 file in each MDT
4620 local fid1=$(make_small $dir_mdt0/$tfile)
4621 local fid2=$(make_small $dir_mdt1/$tfile)
4623 # check that hsm request on mdt0 is sent to the right MDS
4624 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4625 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4626 echo "archive successful on mdt0"
4628 # check that hsm request on mdt1 is sent to the right MDS
4629 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4630 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4631 echo "archive successful on mdt1"
4634 # clean test files and directories
4635 rm -rf $dir_mdt0 $dir_mdt1
4637 run_test 400 "Single request is sent to the right MDT"
4640 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4646 local dir_mdt0=$DIR/$tdir/mdt0
4647 local dir_mdt1=$DIR/$tdir/mdt1
4649 # create 1 dir per MDT
4650 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4651 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4653 # create 1 file in each MDT
4654 local fid1=$(make_small $dir_mdt0/$tfile)
4655 local fid2=$(make_small $dir_mdt1/$tfile)
4657 # check that compound requests are shunt to the rights MDTs
4658 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4659 error "lfs hsm_archive"
4660 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4661 echo "archive successful on mdt0"
4662 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4663 echo "archive successful on mdt1"
4666 # clean test files and directories
4667 rm -rf $dir_mdt0 $dir_mdt1
4669 run_test 401 "Compound requests split and sent to their respective MDTs"
4671 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4676 local node=$(facet_active_host $facet)
4678 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4679 awk '{print $4}'); do
4680 echo "$3 $mdc on $node"
4681 do_facet $facet "$LCTL --device $mdc $state" || return 1
4686 # make sure there is no running copytool
4689 # deactivate all mdc on agent1
4690 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4692 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4694 check_agent_unregistered "uuid" # match any agent
4696 # no expected running copytool
4697 search_copytools $agent && error "Copytool start should have failed"
4700 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4702 run_test 402 "Copytool start fails if all MDTs are inactive"
4705 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4707 # make sure there is no running copytool
4710 local agent=$(facet_active_host $SINGLEAGT)
4712 # deactivate all mdc for MDT0001
4713 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4716 local uuid=$(get_agent_uuid $agent)
4717 # check the agent is registered on MDT0000, and not on MDT0001
4718 check_agent_registered_by_mdt $uuid 0
4719 check_agent_unregistered_by_mdt $uuid 1
4721 # check running copytool process
4722 search_copytools $agent || error "No running copytools on $agent"
4724 # reactivate all mdc for MDT0001
4725 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4727 # make sure the copytool is now registered to all MDTs
4728 check_agent_registered $uuid
4732 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4735 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4739 # create files on both MDT0000 and MDT0001
4742 local dir_mdt0=$DIR/$tdir/mdt0
4743 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4745 # create 1 file on mdt0
4746 local fid1=$(make_small $dir_mdt0/$tfile)
4748 # deactivate all mdc for MDT0001
4749 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4751 # send an HSM request for files in MDT0000
4752 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4754 # check for completion of files in MDT0000
4755 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4756 echo "archive successful on mdt0"
4758 # reactivate all mdc for MDT0001
4759 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4762 # clean test files and directories
4765 run_test 404 "Inactive MDT does not block requests for active MDTs"
4768 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4774 local striped_dir=$DIR/$tdir/striped_dir
4776 # create striped dir on all of MDTs
4777 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4779 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4780 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4781 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4782 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4784 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4785 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4786 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4787 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4789 # check that compound requests are shunt to the rights MDTs
4790 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4791 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4792 error "lfs hsm_archive"
4794 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4795 echo "archive successful on $fid1"
4796 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4797 echo "archive successful on $fid2"
4798 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4799 echo "archive successful on $fid3"
4800 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4801 echo "archive successful on $fid4"
4803 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4804 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4805 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4806 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4808 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4809 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4810 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4811 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4815 run_test 405 "archive and release under striped directory"
4818 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4820 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4821 skip "need MDS version at least 2.7.64" && return 0
4828 fid=$(make_small $DIR/$tdir/$tfile)
4831 $LFS hsm_archive $DIR/$tdir/$tfile
4832 wait_request_state "$fid" ARCHIVE SUCCEED
4833 $LFS hsm_release $DIR/$tdir/$tfile
4835 # Should migrate $tdir but not $tfile.
4836 $LFS mv -M1 $DIR/$tdir &&
4837 error "migrating HSM an archived file should fail"
4839 $LFS hsm_restore $DIR/$tdir/$tfile
4840 wait_request_state "$fid" RESTORE SUCCEED
4842 $LFS hsm_remove $DIR/$tdir/$tfile
4843 wait_request_state "$fid" REMOVE SUCCEED
4845 cat $DIR/$tdir/$tfile > /dev/null ||
4846 error "cannot read $DIR/$tdir/$tfile"
4848 $LFS mv -M1 $DIR/$tdir ||
4849 error "cannot complete migration after HSM remove"
4851 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4852 if ((mdt_index != 1)); then
4853 error "expected MDT index 1, got $mdt_index"
4856 # Refresh fid after migration.
4857 fid=$(path2fid $DIR/$tdir/$tfile)
4860 $LFS hsm_archive $DIR/$tdir/$tfile
4861 wait_request_state "$fid" ARCHIVE SUCCEED 1
4863 lctl set_param debug=+trace
4864 $LFS hsm_release $DIR/$tdir/$tfile ||
4865 error "cannot release $DIR/$tdir/$tfile"
4867 $LFS hsm_restore $DIR/$tdir/$tfile
4868 wait_request_state "$fid" RESTORE SUCCEED 1
4870 cat $DIR/$tdir/$tfile > /dev/null ||
4871 error "cannot read $DIR/$tdir/$tfile"
4875 run_test 406 "attempting to migrate HSM archived files is safe"
4879 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4880 skip "HSM migrate is not supported" && return
4882 # Stop the existing copytool
4885 test_mkdir -p $DIR/$tdir
4886 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4888 run_test 500 "various LLAPI HSM tests"
4893 check_and_cleanup_lustre