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 || return $?
702 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
703 file_creation_failure dd $file2 $?
704 path2fid $1 || error "cannot get fid on $1"
710 wait_update --verbose $(facet_active_host $facet) "$@"
713 wait_request_state() {
717 # 4th arg (mdt index) is optional
719 local mds=mds$(($mdtidx + 1))
721 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
722 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
724 wait_result $mds "$cmd" $state 200 ||
725 error "request on $fid is not $state on $mds"
728 get_request_state() {
732 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
733 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
736 get_request_count() {
740 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
741 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
748 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
749 [[ -n $fid ]] && cmd+=" | grep '$fid'"
750 cmd+=" | egrep 'WAITING|STARTED'"
752 wait_result $SINGLEMDS "$cmd" "" $timeout ||
753 error "requests did not complete"
756 wait_for_grace_delay() {
757 local val=$(get_hsm_param grace_delay)
761 wait_for_loop_period() {
762 local val=$(get_hsm_param loop_period)
769 # python2.6 in EL6 includes an internal json module
770 local json_parser='import json; import fileinput;'
771 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
772 json_parser+='json.loads([line for line in '
773 json_parser+='fileinput.input()][0]).items()])'
775 echo $raw_event | python -c "$json_parser"
778 get_agent_by_uuid_mdt() {
781 local mds=mds$(($mdtidx + 1))
782 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
786 check_agent_registered_by_mdt() {
789 local mds=mds$(($mdtidx + 1))
790 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
791 if [[ ! -z "$agent" ]]; then
792 echo "found agent $agent on $mds"
794 error "uuid $uuid not found in agent list on $mds"
798 check_agent_unregistered_by_mdt() {
801 local mds=mds$(($mdtidx + 1))
802 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
803 if [[ -z "$agent" ]]; then
804 echo "uuid not found in agent list on $mds"
806 error "uuid found in agent list on $mds: $agent"
810 check_agent_registered() {
813 for mdsno in $(seq 1 $MDSCOUNT); do
814 check_agent_registered_by_mdt $uuid $((mdsno - 1))
818 check_agent_unregistered() {
821 for mdsno in $(seq 1 $MDSCOUNT); do
822 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
827 local agent=${1:-$(facet_active_host $SINGLEAGT)}
829 # Lustre mount-point is mandatory and last parameter on
831 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
833 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
835 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
841 # populate MDT device array
844 # cleanup from previous bad setup
847 # for recovery tests, coordinator needs to be started at mount
849 # the lustre conf must be without hsm on (like for sanity.sh)
850 echo "Set HSM on and start"
851 cdt_set_mount_state enabled
852 cdt_check_state enabled
854 echo "Start copytool"
857 echo "Set sanity-hsm HSM policy"
858 cdt_set_sanity_policy
860 # finished requests are quickly removed from list
861 set_hsm_param grace_delay 10
867 local f=$DIR/$tdir/$tfile
871 check_hsm_flags_user $f "0x00000000"
873 $RUNAS $LFS hsm_set --norelease $f ||
874 error "user could not change hsm flags"
875 check_hsm_flags_user $f "0x00000010"
877 $RUNAS $LFS hsm_clear --norelease $f ||
878 error "user could not clear hsm flags"
879 check_hsm_flags_user $f "0x00000000"
881 # User could not change those flags...
882 $RUNAS $LFS hsm_set --exists $f &&
883 error "user should not set this flag"
884 check_hsm_flags_user $f "0x00000000"
887 $LFS hsm_set --exists $f ||
888 error "root could not change hsm flags"
889 check_hsm_flags_user $f "0x00000001"
891 $LFS hsm_clear --exists $f ||
892 error "root could not clear hsm state"
893 check_hsm_flags_user $f "0x00000000"
896 run_test 1 "lfs hsm flags root/non-root access"
900 local f=$DIR/$tdir/$tfile
901 local fid=$(make_small $f)
903 $LFS hsm_archive $f || error "could not archive file"
904 wait_request_state $fid ARCHIVE SUCCEED
906 # Release and check states
907 $LFS hsm_release $f || error "could not release file"
908 echo -n "Verifying released state: "
909 check_hsm_flags $f "0x0000000d"
911 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
913 run_test 1a "mmap & cat a HSM released file"
917 local f=$DIR/$tdir/$tfile
919 # New files are not dirty
920 check_hsm_flags $f "0x00000000"
922 # For test, we simulate an archived file.
923 $LFS hsm_set --exists $f || error "user could not change hsm flags"
924 check_hsm_flags $f "0x00000001"
926 # chmod do not put the file dirty
927 chmod 600 $f || error "could not chmod test file"
928 check_hsm_flags $f "0x00000001"
930 # chown do not put the file dirty
931 chown $RUNAS_ID $f || error "could not chown test file"
932 check_hsm_flags $f "0x00000001"
934 # truncate put the file dirty
935 $TRUNCATE $f 1 || error "could not truncate test file"
936 check_hsm_flags $f "0x00000003"
938 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
939 check_hsm_flags $f "0x00000001"
941 run_test 2 "Check file dirtyness when doing setattr"
947 # New files are not dirty
949 check_hsm_flags $f "0x00000000"
951 # For test, we simulate an archived file.
952 $LFS hsm_set --exists $f ||
953 error "user could not change hsm flags"
954 check_hsm_flags $f "0x00000001"
956 # Reading a file, does not set dirty
957 cat $f > /dev/null || error "could not read file"
958 check_hsm_flags $f "0x00000001"
960 # Open for write without modifying data, does not set dirty
961 openfile -f O_WRONLY $f || error "could not open test file"
962 check_hsm_flags $f "0x00000001"
964 # Append to a file sets it dirty
965 cp -p /etc/passwd $f.append || error "could not create file"
966 $LFS hsm_set --exists $f.append ||
967 error "user could not change hsm flags"
968 dd if=/etc/passwd of=$f.append bs=1 count=3\
969 conv=notrunc oflag=append status=noxfer ||
970 file_creation_failure dd $f.append $?
971 check_hsm_flags $f.append "0x00000003"
973 # Modify a file sets it dirty
974 cp -p /etc/passwd $f.modify || error "could not create file"
975 $LFS hsm_set --exists $f.modify ||
976 error "user could not change hsm flags"
977 dd if=/dev/zero of=$f.modify bs=1 count=3\
978 conv=notrunc status=noxfer ||
979 file_creation_failure dd $f.modify $?
980 check_hsm_flags $f.modify "0x00000003"
982 # Open O_TRUNC sets dirty
983 cp -p /etc/passwd $f.trunc || error "could not create file"
984 $LFS hsm_set --exists $f.trunc ||
985 error "user could not change hsm flags"
986 cp /etc/group $f.trunc || error "could not override a file"
987 check_hsm_flags $f.trunc "0x00000003"
989 # Mmapped a file sets dirty
990 cp -p /etc/passwd $f.mmap || error "could not create file"
991 $LFS hsm_set --exists $f.mmap ||
992 error "user could not change hsm flags"
993 multiop $f.mmap OSMWUc || error "could not mmap a file"
994 check_hsm_flags $f.mmap "0x00000003"
996 run_test 3 "Check file dirtyness when opening for write"
1000 local f=$DIR/$tdir/$tfile
1001 local fid=$(make_small $f)
1004 local st=$(get_request_state $fid CANCEL)
1005 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1007 run_test 4 "Useless cancel must not be registered"
1010 # test needs a running copytool
1014 local f=$DIR/$tdir/$tfile
1015 local fid=$(copy_file /etc/passwd $f)
1017 wait_request_state $fid ARCHIVE SUCCEED
1019 check_hsm_flags $f "0x00000009"
1023 run_test 8 "Test default archive number"
1026 # we do not use the default one to be sure
1027 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1029 copytool_setup $SINGLEAGT $MOUNT $new_an
1031 # give time for CT to register with MDTs
1032 sleep $(($MDSCOUNT*2))
1033 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1034 check_agent_registered $uuid
1037 local f=$DIR/$tdir/$tfile
1038 local fid=$(copy_file /etc/passwd $f)
1039 $LFS hsm_archive --archive $new_an $f
1040 wait_request_state $fid ARCHIVE SUCCEED
1042 check_hsm_flags $f "0x00000009"
1046 run_test 9 "Use of explicit archive number, with dedicated copytool"
1049 needclients 3 || return 0
1055 copytool_cleanup $(comma_list $(agts_nodes))
1057 # start all of the copytools
1058 for n in $(seq $AGTCOUNT); do
1059 copytool_setup agt$n
1062 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1065 for n in $(seq $AGTCOUNT); do
1066 file=$DIR/$tdir/$tfile.$n
1067 fid=$(make_small $file)
1069 $LFS hsm_archive $file || error "could not archive file $file"
1070 wait_request_state $fid ARCHIVE SUCCEED
1071 check_hsm_flags $file "0x00000009"
1075 copytool_cleanup $(comma_list $(agts_nodes))
1077 run_test 9a "Multiple remote agents"
1080 # test needs a running copytool
1083 mkdir -p $DIR/$tdir/d1
1084 local f=$DIR/$tdir/$tfile
1085 local fid=$(copy_file /etc/hosts $f)
1086 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1087 error "hsm_archive failed"
1088 wait_request_state $fid ARCHIVE SUCCEED
1090 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1091 error "fid $fid not in archive $HSM_ARCHIVE"
1092 echo "Verifying content"
1093 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1094 echo "Verifying hsm state "
1095 check_hsm_flags $f "0x00000009"
1097 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1098 local st=$(get_hsm_archive_id $f)
1099 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1100 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1105 run_test 10a "Archive a file"
1108 # test needs a running copytool
1112 local f=$DIR/$tdir/$tfile
1113 local fid=$(copy_file /etc/hosts $f)
1114 $LFS hsm_archive $f || error "archive request failed"
1115 wait_request_state $fid ARCHIVE SUCCEED
1117 $LFS hsm_archive $f || error "archive of non dirty file failed"
1118 local cnt=$(get_request_count $fid ARCHIVE)
1119 [[ "$cnt" == "1" ]] ||
1120 error "archive of non dirty file must not make a request"
1124 run_test 10b "Archive of non dirty file must work without doing request"
1127 # test needs a running copytool
1131 local f=$DIR/$tdir/$tfile
1132 local fid=$(copy_file /etc/hosts $f)
1133 $LFS hsm_set --noarchive $f
1134 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1138 run_test 10c "Check forbidden archive"
1141 # test needs a running copytool
1145 local f=$DIR/$tdir/$tfile
1146 local fid=$(copy_file /etc/hosts $f)
1147 $LFS hsm_archive $f || error "cannot archive $f"
1148 wait_request_state $fid ARCHIVE SUCCEED
1150 local ar=$(get_hsm_archive_id $f)
1151 local dflt=$(get_hsm_param default_archive_id)
1152 [[ $ar == $dflt ]] ||
1153 error "archived file is not on default archive: $ar != $dflt"
1157 run_test 10d "Archive a file on the default archive id"
1161 copy2archive /etc/hosts $tdir/$tfile
1162 local f=$DIR/$tdir/$tfile
1164 import_file $tdir/$tfile $f
1165 echo -n "Verifying released state: "
1166 check_hsm_flags $f "0x0000000d"
1168 local LSZ=$(stat -c "%s" $f)
1169 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1171 echo "Verifying imported size $LSZ=$ASZ"
1172 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1173 echo -n "Verifying released pattern: "
1174 local PTRN=$($GETSTRIPE -L $f)
1176 [[ $PTRN == 80000001 ]] || error "Is not released"
1177 local fid=$(path2fid $f)
1178 echo "Verifying new fid $fid in archive"
1180 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1181 error "fid $fid not in archive $HSM_ARCHIVE"
1183 run_test 11a "Import a file"
1186 # test needs a running copytool
1190 local f=$DIR/$tdir/$tfile
1191 local fid=$(copy_file /etc/hosts $f)
1192 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1193 error "hsm_archive failed"
1194 wait_request_state $fid ARCHIVE SUCCEED
1196 local FILE_HASH=$(md5sum $f)
1201 echo "$FILE_HASH" | md5sum -c
1203 [[ $? -eq 0 ]] || error "Restored file differs"
1207 run_test 11b "Import a deleted file using its FID"
1210 # test needs a running copytool
1214 copy2archive /etc/hosts $tdir/$tfile
1216 local f=$DIR/$tdir/$tfile
1217 import_file $tdir/$tfile $f
1218 local f2=$DIR2/$tdir/$tfile
1219 echo "Verifying released state: "
1220 check_hsm_flags $f2 "0x0000000d"
1222 local fid=$(path2fid $f2)
1223 $LFS hsm_restore $f2
1224 wait_request_state $fid RESTORE SUCCEED
1226 echo "Verifying file state: "
1227 check_hsm_flags $f2 "0x00000009"
1229 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1231 [[ $? -eq 0 ]] || error "Restored file differs"
1235 run_test 12a "Restore an imported file explicitly"
1238 # test needs a running copytool
1242 copy2archive /etc/hosts $tdir/$tfile
1244 local f=$DIR/$tdir/$tfile
1245 import_file $tdir/$tfile $f
1246 echo "Verifying released state: "
1247 check_hsm_flags $f "0x0000000d"
1249 cat $f > /dev/null || error "File read failed"
1251 echo "Verifying file state after restore: "
1252 check_hsm_flags $f "0x00000009"
1254 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1256 [[ $? -eq 0 ]] || error "Restored file differs"
1260 run_test 12b "Restore an imported file implicitly"
1263 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1265 # test needs a running copytool
1269 local f=$DIR/$tdir/$tfile
1270 $LFS setstripe -c 2 $f
1272 fid=$(make_custom_file_for_progress $f 5)
1273 [ $? != 0 ] && skip "not enough free space" && return
1275 local FILE_CRC=$(md5sum $f)
1277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1278 wait_request_state $fid ARCHIVE SUCCEED
1279 $LFS hsm_release $f || error "release $f failed"
1281 echo "$FILE_CRC" | md5sum -c
1283 [[ $? -eq 0 ]] || error "Restored file differs"
1287 run_test 12c "Restore a file with stripe of 2"
1290 # test needs a running copytool
1295 local f=$DIR/$tdir/$tfile
1296 local fid=$(copy_file /etc/hosts $f)
1297 $LFS hsm_restore $f || error "restore of non archived file failed"
1298 local cnt=$(get_request_count $fid RESTORE)
1299 [[ "$cnt" == "0" ]] ||
1300 error "restore non archived must not make a request"
1301 $LFS hsm_archive $f ||
1302 error "archive request failed"
1303 wait_request_state $fid ARCHIVE SUCCEED
1304 $LFS hsm_restore $f ||
1305 error "restore of non released file failed"
1306 local cnt=$(get_request_count $fid RESTORE)
1307 [[ "$cnt" == "0" ]] ||
1308 error "restore a non dirty file must not make a request"
1312 run_test 12d "Restore of a non archived, non released file must work"\
1313 " without doing request"
1316 # test needs a running copytool
1319 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1320 local f=$DIR/$tdir/$tfile
1321 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive $f || error "archive request failed"
1323 wait_request_state $fid ARCHIVE SUCCEED
1326 cat /etc/hosts >> $f
1330 $LFS hsm_restore $f && error "restore a dirty file must fail"
1334 run_test 12e "Check forbidden restore"
1337 # test needs a running copytool
1341 local f=$DIR/$tdir/$tfile
1342 local fid=$(copy_file /etc/hosts $f)
1344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1345 wait_request_state $fid ARCHIVE SUCCEED
1346 $LFS hsm_release $f || error "release of $f failed"
1348 wait_request_state $fid RESTORE SUCCEED
1350 echo -n "Verifying file state: "
1351 check_hsm_flags $f "0x00000009"
1353 diff -q /etc/hosts $f
1355 [[ $? -eq 0 ]] || error "Restored file differs"
1359 run_test 12f "Restore a released file explicitly"
1362 # test needs a running copytool
1366 local f=$DIR/$tdir/$tfile
1367 local fid=$(copy_file /etc/hosts $f)
1369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1370 wait_request_state $fid ARCHIVE SUCCEED
1371 $LFS hsm_release $f || error "release of $f failed"
1373 diff -q /etc/hosts $f
1376 # we check we had a restore done
1377 wait_request_state $fid RESTORE SUCCEED
1379 [[ $st -eq 0 ]] || error "Restored file differs"
1383 run_test 12g "Restore a released file implicitly"
1386 needclients 2 || return 0
1388 # test needs a running copytool
1392 local f=$DIR/$tdir/$tfile
1393 local fid=$(copy_file /etc/hosts $f)
1395 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1396 wait_request_state $fid ARCHIVE SUCCEED
1397 $LFS hsm_release $f || error "release of $f failed"
1399 do_node $CLIENT2 diff -q /etc/hosts $f
1402 # we check we had a restore done
1403 wait_request_state $fid RESTORE SUCCEED
1405 [[ $st -eq 0 ]] || error "Restored file differs"
1409 run_test 12h "Restore a released file implicitly from a second node"
1412 # test needs a running copytool
1416 local f=$DIR/$tdir/$tfile
1417 local fid=$(copy_file /etc/passwd $f)
1418 $LFS hsm_archive $f || error "archive of $f failed"
1419 wait_request_state $fid ARCHIVE SUCCEED
1421 $LFS hsm_release $f || error "release of $f failed"
1425 [[ $? -eq 0 ]] || error "Restored file differs"
1429 run_test 12m "Archive/release/implicit restore"
1432 # test needs a running copytool
1436 copy2archive /etc/hosts $tdir/$tfile
1438 local f=$DIR/$tdir/$tfile
1439 import_file $tdir/$tfile $f
1441 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1442 error "Restored file differs"
1444 $LFS hsm_release $f || error "release of $f failed"
1448 run_test 12n "Import/implicit restore/release"
1451 # test needs a running copytool
1455 local f=$DIR/$tdir/$tfile
1456 local fid=$(copy_file /etc/hosts $f)
1458 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1459 wait_request_state $fid ARCHIVE SUCCEED
1460 $LFS hsm_release $f || error "release of $f failed"
1462 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1463 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1465 # set no retry action mode
1468 diff -q /etc/hosts $f
1471 # we check we had a restore failure
1472 wait_request_state $fid RESTORE FAILED
1474 [[ $st -eq 0 ]] && error "Restore must fail"
1476 # remove no retry action mode
1479 # check file is still released
1480 check_hsm_flags $f "0x0000000d"
1482 # retry w/o failure injection
1483 do_facet $SINGLEMDS lctl set_param fail_loc=0
1485 # to be sure previous RESTORE result is gone
1487 wait_for_grace_delay
1489 diff -q /etc/hosts $f
1492 # we check we had a restore done
1493 wait_request_state $fid RESTORE SUCCEED
1495 [[ $st -eq 0 ]] || error "Restored file differs"
1499 run_test 12o "Layout-swap failure during Restore leaves file released"
1502 # test needs a running copytool
1506 local f=$DIR/$tdir/$tfile
1507 local fid=$(copy_file /etc/hosts $f)
1509 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1510 wait_request_state $fid ARCHIVE SUCCEED
1511 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1512 $LFS hsm_release $f || error "cannot release $f"
1513 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1514 $LFS hsm_release $f || error "cannot release $f"
1515 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1519 run_test 12p "implicit restore of a file on copytool mount point"
1521 cleanup_test_12q() {
1523 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1524 error "cannot umount $MOUNT3 on $SINGLEAGT"
1528 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1529 skip "need MDS version at least 2.7.58" && return 0
1531 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1532 error "cannot mount $MOUNT3 on $SINGLEAGT"
1534 trap cleanup_test_12q EXIT
1536 # test needs a running copytool
1537 copytool_setup $SINGLEAGT $MOUNT3
1540 local f=$DIR/$tdir/$tfile
1541 local f2=$DIR2/$tdir/$tfile
1542 local fid=$(make_small $f)
1543 local orig_size=$(stat -c "%s" $f)
1545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1546 wait_request_state $fid ARCHIVE SUCCEED
1548 $LFS hsm_release $f || error "could not release file"
1549 check_hsm_flags $f "0x0000000d"
1552 wait_copytools || error "copytool failed to stop"
1554 cat $f > /dev/null &
1556 # wait a bit to allow implicit restore request to be handled.
1557 # if not, next stat would also block on layout-lock.
1560 local size=$(stat -c "%s" $f2)
1561 [ $size -eq $orig_size ] ||
1562 error "$f2: wrong size after archive: $size != $orig_size"
1564 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1568 size=$(stat -c "%s" $f)
1569 [ $size -eq $orig_size ] ||
1570 error "$f: wrong size after restore: $size != $orig_size"
1572 size=$(stat -c "%s" $f2)
1573 [ $size -eq $orig_size ] ||
1574 error "$f2: wrong size after restore: $size != $orig_size"
1578 size=$(stat -c "%s" $f)
1580 error "$f: wrong size after overwrite: $size != 0"
1582 size=$(stat -c "%s" $f2)
1584 error "$f2: wrong size after overwrite: $size != 0"
1587 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1588 error "cannot umount $MOUNT3 on $SINGLEAGT"
1590 run_test 12q "file attributes are refreshed after restore"
1593 # test needs a running copytool
1596 local ARC_SUBDIR="import.orig"
1600 # populate directory to be imported
1601 for d in $(seq 1 10); do
1602 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1603 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1604 for f in $(seq 1 10); do
1605 CURR_FILE="$CURR_DIR/$tfile.$f"
1606 # write file-specific data
1607 do_facet $SINGLEAGT \
1608 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1609 "file=$CURR_FILE > $CURR_FILE"
1613 import_file "$ARC_SUBDIR" $DIR/$tdir
1614 # diff lustre content and origin (triggers file restoration)
1615 # there must be 10x10 identical files, and no difference
1616 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1617 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1618 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1619 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1621 [ $cnt_diff -eq 0 ] ||
1622 error "$cnt_diff imported files differ from read data"
1623 [ $cnt_ok -eq 100 ] ||
1624 error "not enough identical files ($cnt_ok != 100)"
1628 run_test 13 "Recursively import and restore a directory"
1631 # test needs a running copytool
1636 local f=$DIR/$tdir/$tfile
1637 local fid=$(make_small $f)
1638 local sum=$(md5sum $f | awk '{print $1}')
1639 $LFS hsm_archive $f || error "could not archive file"
1640 wait_request_state $fid ARCHIVE SUCCEED
1644 # create released file (simulate llapi_hsm_import call)
1646 local fid2=$(path2fid $f)
1647 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1648 $LFS hsm_release $f || error "could not release file"
1650 # rebind the archive to the newly created file
1651 echo "rebind $fid to $fid2"
1653 do_facet $SINGLEAGT \
1654 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1655 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1657 # restore file and compare md5sum
1658 local sum2=$(md5sum $f | awk '{print $1}')
1660 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1664 run_test 14 "Rebind archived file to a new fid"
1667 # test needs a running copytool
1672 local f=$DIR/$tdir/$tfile
1674 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1678 for i in $(seq 1 $count); do
1679 fids[$i]=$(make_small $f.$i)
1680 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1681 $LFS hsm_archive $f.$i || error "could not archive file"
1683 wait_all_done $(($count*60))
1687 for i in $(seq 1 $count); do
1690 local fid2=$(path2fid $f.$i)
1691 # add the rebind operation to the list
1692 echo ${fids[$i]} $fid2 >> $tmpfile
1694 # set it released (simulate llapi_hsm_import call)
1695 $LFS hsm_set --archived --exists $f.$i ||
1696 error "could not force hsm flags"
1697 $LFS hsm_release $f.$i || error "could not release file"
1699 nl=$(wc -l < $tmpfile)
1700 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1702 echo "rebind list of files"
1703 do_facet $SINGLEAGT \
1704 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1705 --rebind $tmpfile $DIR" || error "could not rebind file list"
1707 # restore files and compare md5sum
1708 for i in $(seq 1 $count); do
1709 local sum2=$(md5sum $f.$i | awk '{print $1}')
1710 [[ $sum2 == ${sums[$i]} ]] ||
1711 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1717 run_test 15 "Rebind a list of files"
1720 # test needs a running copytool
1724 # create a known size file so we can verify transfer speed
1727 dd if=/dev/zero of=$ref bs=1M count=20
1730 local f=$DIR/$tdir/$tfile
1731 local fid=$(copy_file $ref $f)
1733 local start=$(date +%s)
1735 wait_request_state $fid ARCHIVE SUCCEED
1736 local end=$(date +%s)
1737 # Add 1 to account for rounding errors between start and end (LU-8155)
1738 local duration=$((end - start + 1))
1740 [[ $duration -ge $((goal - 1)) ]] ||
1741 error "Transfer is too fast $duration < $goal"
1745 run_test 16 "Test CT bandwith control option"
1750 local f=$DIR/$tdir/$tfile
1751 touch $f || error "touch $f failed"
1753 # Could not release a non-archived file
1754 $LFS hsm_release $f && error "release should not succeed"
1756 # For following tests, we must test them with HS_ARCHIVED set
1757 $LFS hsm_set --exists --archived $f || error "could not add flag"
1759 # Could not release a file if no-release is set
1760 $LFS hsm_set --norelease $f || error "could not add flag"
1761 $LFS hsm_release $f && error "release should not succeed"
1762 $LFS hsm_clear --norelease $f || error "could not remove flag"
1764 # Could not release a file if lost
1765 $LFS hsm_set --lost $f || error "could not add flag"
1766 $LFS hsm_release $f && error "release should not succeed"
1767 $LFS hsm_clear --lost $f || error "could not remove flag"
1769 # Could not release a file if dirty
1770 $LFS hsm_set --dirty $f || error "could not add flag"
1771 $LFS hsm_release $f && error "release should not succeed"
1772 $LFS hsm_clear --dirty $f || error "could not remove flag"
1774 run_test 20 "Release is not permitted"
1777 # test needs a running copytool
1781 local f=$DIR/$tdir/test_release
1783 # Create a file and check its states
1784 local fid=$(make_small $f)
1785 check_hsm_flags $f "0x00000000"
1787 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1788 # used until file is flushed to disk
1789 if [ $(facet_fstype ost1) == "zfs" ]; then
1790 # this causes an OST_SYNC rpc to be sent
1791 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1792 # clear locks to reread file data
1793 cancel_lru_locks osc
1796 local orig_size=$(stat -c "%s" $f)
1797 local orig_blocks=$(stat -c "%b" $f)
1799 start_full_debug_logging
1801 $LFS hsm_archive $f || error "could not archive file"
1802 wait_request_state $fid ARCHIVE SUCCEED
1804 local blocks=$(stat -c "%b" $f)
1805 [ $blocks -eq $orig_blocks ] ||
1806 error "$f: wrong block number after archive: " \
1807 "$blocks != $orig_blocks"
1808 local size=$(stat -c "%s" $f)
1809 [ $size -eq $orig_size ] ||
1810 error "$f: wrong size after archive: $size != $orig_size"
1812 # Release and check states
1813 $LFS hsm_release $f || error "could not release file"
1814 check_hsm_flags $f "0x0000000d"
1816 blocks=$(stat -c "%b" $f)
1817 [ $blocks -gt 5 ] &&
1818 error "$f: too many blocks after release: $blocks > 5"
1819 size=$(stat -c "%s" $f)
1820 [ $size -ne $orig_size ] &&
1821 error "$f: wrong size after release: $size != $orig_size"
1823 # Check we can release an file without stripe info
1827 check_hsm_flags $f "0x00000000"
1828 $LFS hsm_archive $f || error "could not archive file"
1829 wait_request_state $fid ARCHIVE SUCCEED
1831 # Release and check states
1832 $LFS hsm_release $f || error "could not release file"
1833 check_hsm_flags $f "0x0000000d"
1835 # Release again a file that is already released is OK
1836 $LFS hsm_release $f || fail "second release should succeed"
1837 check_hsm_flags $f "0x0000000d"
1839 stop_full_debug_logging
1843 run_test 21 "Simple release tests"
1846 # test needs a running copytool
1851 local f=$DIR/$tdir/test_release
1852 local swap=$DIR/$tdir/test_swap
1854 # Create a file and check its states
1855 local fid=$(make_small $f)
1856 check_hsm_flags $f "0x00000000"
1858 $LFS hsm_archive $f || error "could not archive file"
1859 wait_request_state $fid ARCHIVE SUCCEED
1861 # Release and check states
1862 $LFS hsm_release $f || error "could not release file"
1863 check_hsm_flags $f "0x0000000d"
1866 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1871 run_test 22 "Could not swap a release file"
1874 # test needs a running copytool
1879 local f=$DIR/$tdir/test_mtime
1881 # Create a file and check its states
1882 local fid=$(make_small $f)
1883 check_hsm_flags $f "0x00000000"
1885 $LFS hsm_archive $f || error "could not archive file"
1886 wait_request_state $fid ARCHIVE SUCCEED
1888 # Set modification time in the past
1889 touch -m -a -d @978261179 $f
1891 # Release and check states
1892 $LFS hsm_release $f || error "could not release file"
1893 check_hsm_flags $f "0x0000000d"
1895 local MTIME=$(stat -c "%Y" $f)
1896 local ATIME=$(stat -c "%X" $f)
1897 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1898 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1902 run_test 23 "Release does not change a/mtime (utime)"
1905 local file=$DIR/$tdir/$tfile
1914 # test needs a running copytool
1919 fid=$(make_small $file)
1921 # Create a file and check its states
1922 check_hsm_flags $file "0x00000000"
1924 # Ensure atime is less than mtime and ctime.
1928 atime0=$(stat -c "%X" $file)
1929 mtime0=$(stat -c "%Y" $file)
1930 ctime0=$(stat -c "%Z" $file)
1932 [ $atime0 -lt $mtime0 ] ||
1933 error "atime $atime0 is not less than mtime $mtime0"
1935 [ $atime0 -lt $ctime0 ] ||
1936 error "atime $atime0 is not less than ctime $ctime0"
1938 # Archive should not change any timestamps.
1939 $LFS hsm_archive $file || error "cannot archive '$file'"
1940 wait_request_state $fid ARCHIVE SUCCEED
1942 atime1=$(stat -c "%X" $file)
1943 mtime1=$(stat -c "%Y" $file)
1944 ctime1=$(stat -c "%Z" $file)
1946 [ $atime0 -eq $atime1 ] ||
1947 error "archive changed atime from $atime0 to $atime1"
1949 [ $mtime0 -eq $mtime1 ] ||
1950 error "archive changed mtime from $mtime0 to $mtime1"
1952 [ $ctime0 -eq $ctime1 ] ||
1953 error "archive changed ctime from $ctime0 to $ctime1"
1955 # Release should not change any timestamps.
1956 $LFS hsm_release $file || error "cannot release '$file'"
1957 check_hsm_flags $file "0x0000000d"
1959 atime1=$(stat -c "%X" $file)
1960 mtime1=$(stat -c "%Y" $file)
1961 ctime1=$(stat -c "%Z" $file)
1963 [ $atime0 -eq $atime1 ] ||
1964 error "release changed atime from $atime0 to $atime1"
1966 [ $mtime0 -eq $mtime1 ] ||
1967 error "release changed mtime from $mtime0 to $mtime1"
1969 [ $ctime0 -eq $ctime1 ] ||
1970 error "release changed ctime from $ctime0 to $ctime1"
1972 # Restore should not change any timestamps.
1973 $LFS hsm_restore $file
1974 wait_request_state $fid RESTORE SUCCEED
1976 atime1=$(stat -c "%X" $file)
1977 mtime1=$(stat -c "%Y" $file)
1978 ctime1=$(stat -c "%Z" $file)
1980 [ $atime0 -eq $atime1 ] ||
1981 error "restore changed atime from $atime0 to $atime1"
1983 [ $mtime0 -eq $mtime1 ] ||
1984 error "restore changed mtime from $mtime0 to $mtime1"
1986 [ $ctime0 -eq $ctime1 ] ||
1987 error "restore changed ctime from $ctime0 to $ctime1"
1991 # Once more, after unmount and mount.
1992 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1993 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1995 atime1=$(stat -c "%X" $file)
1996 mtime1=$(stat -c "%Y" $file)
1997 ctime1=$(stat -c "%Z" $file)
1999 [ $atime0 -eq $atime1 ] ||
2000 error "remount changed atime from $atime0 to $atime1"
2002 [ $mtime0 -eq $mtime1 ] ||
2003 error "remount changed mtime from $mtime0 to $mtime1"
2005 [ $ctime0 -eq $ctime1 ] ||
2006 error "remount changed ctime from $ctime0 to $ctime1"
2008 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2011 local file=$DIR/$tdir/$tfile
2017 # Test needs a running copytool.
2021 # Check that root can do HSM actions on a regular user's file.
2023 fid=$(make_small $file)
2024 sum0=$(md5sum $file)
2026 chown $RUNAS_ID:$RUNAS_GID $file ||
2027 error "cannot chown '$file' to '$RUNAS_ID'"
2029 chmod ugo-w $DIR/$tdir ||
2030 error "cannot chmod '$DIR/$tdir'"
2032 $LFS hsm_archive $file
2033 wait_request_state $fid ARCHIVE SUCCEED
2035 $LFS hsm_release $file
2036 check_hsm_flags $file "0x0000000d"
2038 $LFS hsm_restore $file
2039 wait_request_state $fid RESTORE SUCCEED
2041 # Check that ordinary user can get HSM state.
2042 $RUNAS $LFS hsm_state $file ||
2043 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2045 $LFS hsm_release $file
2046 check_hsm_flags $file "0x0000000d"
2048 # Check that ordinary user can accessed released file.
2049 sum1=$($RUNAS md5sum $file) ||
2050 error "user '$RUNAS_ID' cannot read '$file'"
2052 [ "$sum0" == "$sum1" ] ||
2053 error "md5sum mismatch for '$file'"
2057 run_test 24b "root can archive, release, and restore user files"
2059 cleanup_test_24c() {
2061 set_hsm_param user_request_mask RESTORE
2062 set_hsm_param group_request_mask RESTORE
2063 set_hsm_param other_request_mask RESTORE
2067 local file=$DIR/$tdir/$tfile
2068 local action=archive
2073 # test needs a running copytool
2078 # Save the default masks and check that cleanup_24c will
2079 # restore the request masks correctly.
2080 user_save=$(get_hsm_param user_request_mask)
2081 group_save=$(get_hsm_param group_request_mask)
2082 other_save=$(get_hsm_param other_request_mask)
2084 [ "$user_save" == RESTORE ] ||
2085 error "user_request_mask is '$user_save' expected 'RESTORE'"
2086 [ "$group_save" == RESTORE ] ||
2087 error "group_request_mask is '$group_save' expected 'RESTORE'"
2088 [ "$other_save" == RESTORE ] ||
2089 error "other_request_mask is '$other_save' expected 'RESTORE'"
2091 trap cleanup_test_24c EXIT
2096 chown $RUNAS_ID:nobody $file ||
2097 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2099 $RUNAS $LFS hsm_$action $file &&
2100 error "$action by user should fail"
2102 set_hsm_param user_request_mask $action
2103 $RUNAS $LFS hsm_$action $file ||
2104 error "$action by user should succeed"
2109 chown nobody:$RUNAS_GID $file ||
2110 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2112 $RUNAS $LFS hsm_$action $file &&
2113 error "$action by group should fail"
2115 set_hsm_param group_request_mask $action
2116 $RUNAS $LFS hsm_$action $file ||
2117 error "$action by group should succeed"
2122 chown nobody:nobody $file ||
2123 error "cannot chown '$file' to 'nobody:nobody'"
2125 $RUNAS $LFS hsm_$action $file &&
2126 error "$action by other should fail"
2128 set_hsm_param other_request_mask $action
2129 $RUNAS $LFS hsm_$action $file ||
2130 error "$action by other should succeed"
2135 run_test 24c "check that user,group,other request masks work"
2137 cleanup_test_24d() {
2139 mount -o remount,rw $MOUNT2
2143 local file1=$DIR/$tdir/$tfile
2144 local file2=$DIR2/$tdir/$tfile
2152 fid1=$(make_small $file1)
2154 trap cleanup_test_24d EXIT
2156 mount -o remount,ro $MOUNT2
2158 fid2=$(path2fid $file2)
2159 [ "$fid1" == "$fid2" ] ||
2160 error "FID mismatch '$fid1' != '$fid2'"
2162 $LFS hsm_archive $file2 &&
2163 error "archive should fail on read-only mount"
2164 check_hsm_flags $file1 "0x00000000"
2166 $LFS hsm_archive $file1
2167 wait_request_state $fid1 ARCHIVE SUCCEED
2169 $LFS hsm_release $file1
2170 $LFS hsm_restore $file2
2171 wait_request_state $fid1 RESTORE SUCCEED
2173 $LFS hsm_release $file1 || error "cannot release '$file1'"
2174 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2176 $LFS hsm_release $file2 &&
2177 error "release should fail on read-only mount"
2182 run_test 24d "check that read-only mounts are respected"
2189 local f=$DIR/$tdir/$tfile
2192 fid=$(make_small $f) || error "cannot create $f"
2193 $LFS hsm_archive $f || error "cannot archive $f"
2194 wait_request_state $fid ARCHIVE SUCCEED
2195 $LFS hsm_release $f || error "cannot release $f"
2196 while ! $LFS hsm_state $f | grep released; do
2200 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2204 run_test 24e "tar succeeds on HSM released files" # LU-6213
2208 # test needs a running copytool
2211 mkdir -p $DIR/$tdir/d1
2212 local f=$DIR/$tdir/$tfile
2213 local fid=$(copy_file /etc/hosts $f)
2216 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2217 error "hsm_archive failed"
2218 wait_request_state $fid ARCHIVE SUCCEED
2219 $LFS hsm_release $f || error "cannot release $f"
2220 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2223 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2224 error "Can not recover the tar contents"
2226 echo "Sum0 = $sum0, sum1 = $sum1"
2227 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2231 run_test 24f "root can archive, release, and restore tar files"
2234 # test needs a running copytool
2238 copy2archive /etc/hosts $tdir/$tfile
2240 local f=$DIR/$tdir/$tfile
2242 import_file $tdir/$tfile $f
2244 $LFS hsm_set --lost $f
2249 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2253 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2254 " (Operation not permitted)"
2257 # test needs a running copytool
2262 local f=$DIR/$tdir/$tfile
2263 local fid=$(copy_file /etc/passwd $f)
2265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2266 wait_request_state $fid ARCHIVE SUCCEED
2269 $LFS hsm_set --lost $f
2273 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2277 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2278 " (Operation not permitted)"
2281 # test needs a running copytool
2285 local f=$DIR/$tdir/$tfile
2287 fid=$(make_custom_file_for_progress $f 39 1000000)
2288 [ $? != 0 ] && skip "not enough free space" && return
2290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2291 wait_request_state $fid ARCHIVE SUCCEED
2294 wait_request_state $fid REMOVE SUCCEED
2296 check_hsm_flags $f "0x00000000"
2300 run_test 26 "Remove the archive of a valid file"
2303 # test needs a running copytool
2307 make_archive $tdir/$tfile
2308 local f=$DIR/$tdir/$tfile
2309 import_file $tdir/$tfile $f
2310 local fid=$(path2fid $f)
2314 [[ $? != 0 ]] || error "Remove of a released file should fail"
2318 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2321 # test needs a running copytool
2325 local f=$DIR/$tdir/$tfile
2327 fid=$(make_custom_file_for_progress $f 39 1000000)
2328 [ $? != 0 ] && skip "not enough free space" && return
2330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2331 wait_request_state $fid ARCHIVE SUCCEED
2336 [[ $? != 0 ]] || error "Remove of a released file should fail"
2340 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2343 # test needs a running copytool
2347 local f=$DIR/$tdir/$tfile
2349 fid=$(make_custom_file_for_progress $f 39 1000000)
2350 [ $? != 0 ] && skip "not enough free space" && return
2352 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2353 wait_request_state $fid ARCHIVE SUCCEED
2362 wait_request_state $fid REMOVE SUCCEED
2366 run_test 28 "Concurrent archive/file remove"
2369 # Tests --mntpath and --archive options
2372 copytool_setup $SINGLEAGT $MOUNT $archive_id
2374 # Bad archive number
2375 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2376 grep "Invalid argument" ||
2377 error "unexpected hsm_remove failure (1)"
2379 # mntpath is present but file is given
2380 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2381 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2382 error "unexpected hsm_remove failure (2)"
2386 run_test 29a "Tests --mntpath and --archive options"
2389 # test needs a running copytool
2393 local f=$DIR/$tdir/$tfile
2394 local fid=$(make_small $f)
2396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2397 wait_request_state $fid ARCHIVE SUCCEED
2401 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2402 wait_request_state $fid REMOVE SUCCEED
2406 run_test 29b "Archive/delete/remove by FID from the archive."
2409 # test needs a running copytool
2413 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2414 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2415 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2417 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2418 wait_request_state $fid1 ARCHIVE SUCCEED
2419 wait_request_state $fid2 ARCHIVE SUCCEED
2420 wait_request_state $fid3 ARCHIVE SUCCEED
2422 rm -f $DIR/$tdir/$tfile-[1-3]
2424 echo $fid1 > $DIR/$tdir/list
2425 echo $fid2 >> $DIR/$tdir/list
2426 echo $fid3 >> $DIR/$tdir/list
2428 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2429 --filelist $DIR/$tdir/list
2430 wait_request_state $fid1 REMOVE SUCCEED
2431 wait_request_state $fid2 REMOVE SUCCEED
2432 wait_request_state $fid3 REMOVE SUCCEED
2436 run_test 29c "Archive/delete/remove by FID, using a file list."
2439 # test needs more than one CT
2440 needclients 3 || return 0
2446 copytool_cleanup $(comma_list $(agts_nodes))
2448 # start all of the copytools
2449 for n in $(seq $AGTCOUNT); do
2450 copytool_setup agt$n $MOUNT2 $n
2453 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2456 file=$DIR/$tdir/$tfile
2457 fid=$(make_small $file)
2459 $LFS hsm_archive $file
2460 wait_request_state $fid ARCHIVE SUCCEED
2461 check_hsm_flags $file "0x00000009"
2465 $LFS hsm_remove -a 0 $fid
2467 # give time for CDT to handle remove request and create broadcasted
2470 # remove request has been broadcasted ?
2471 local cnt=$(get_request_count $fid REMOVE)
2472 # broadcasted requests + original
2473 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2474 error "remove not broadcasted to all CTs"
2476 # give time for CDT and CTs to handle broadcasted
2477 wait_for_loop_period
2479 # each agent serves one different archive_id, so broadcasted
2480 # hsm_remove request should only succeed once and fail at all others
2484 for n in $(seq $AGTCOUNT); do
2485 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2486 $HSM_PARAM.actions | awk \
2487 '/'$fid'.*action=REMOVE archive#='$n'/ \
2488 {print \\\$13}' | cut -f2 -d=")
2489 if [[ "$res" == "SUCCEED" ]]; then
2491 elif [[ "$res" == "FAILED" ]]; then
2496 [[ $scnt -ne 1 ]] &&
2497 error "one and only CT should have removed successfully"
2499 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2500 error "all but one CT should have failed to remove"
2503 copytool_cleanup $(comma_list $(agts_nodes))
2506 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2507 "request to be sent once for each registered archive_id"
2510 # restore at exec cannot work on agent node (because of Linux kernel
2511 # protection of executables)
2512 needclients 2 || return 0
2514 # test needs a running copytool
2518 copy2archive /bin/true $tdir/$tfile
2520 local f=$DIR/$tdir/true
2521 import_file $tdir/$tfile $f
2523 local fid=$(path2fid $f)
2525 # set no retry action mode
2531 # remove no try action mode
2535 [[ $st == 0 ]] || error "Failed to exec a released file"
2539 run_test 30a "Restore at exec (import case)"
2542 # restore at exec cannot work on agent node (because of Linux kernel
2543 # protection of executables)
2544 needclients 2 || return 0
2546 # test needs a running copytool
2550 local f=$DIR/$tdir/true
2551 local fid=$(copy_file /bin/true $f)
2553 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2554 wait_request_state $fid ARCHIVE SUCCEED
2557 # set no retry action mode
2563 # remove no try action mode
2567 [[ $st == 0 ]] || error "Failed to exec a released file"
2571 run_test 30b "Restore at exec (release case)"
2574 needclients 2 || return 0
2576 # test needs a running copytool
2580 local f=$DIR/$tdir/SLEEP
2581 local slp_sum1=$(md5sum /bin/sleep)
2582 local fid=$(copy_file /bin/sleep $f)
2584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2585 wait_request_state $fid ARCHIVE SUCCEED
2587 check_hsm_flags $f "0x0000000d"
2588 # set no retry action mode
2590 do_node $CLIENT2 "$f 10" &
2594 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2596 [[ $? == 0 ]] || error "Execution failed during run"
2598 if [[ $? != 0 ]]; then
2599 local slp_sum2=$(md5sum /bin/sleep)
2600 # in case sleep file is modified during the test
2601 [[ $slp_sum1 == $slp_sum2 ]] &&
2602 error "Binary overwritten during exec"
2606 # remove no try action mode
2608 check_hsm_flags $f "0x00000009"
2612 run_test 30c "Update during exec of released file must fail"
2614 restore_and_check_size() {
2617 local s=$(stat -c "%s" $f)
2619 local st=$(get_hsm_flags $f)
2623 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2625 n=$(stat -c "%s" $f)
2626 # we echo in both cases to show stat is not hang
2627 if [[ $n != $s ]]; then
2628 echo "size seen is $n != $s"
2631 echo "size seen is right: $n == $s"
2635 st=$(get_hsm_flags $f)
2637 if [[ "$st" = "0x00000009" ]]; then
2640 echo " restore is too long"
2641 wait_request_state $fid RESTORE SUCCEED
2647 # test needs a running copytool
2652 make_archive $tdir/$tfile
2653 local f=$DIR/$tdir/$tfile
2654 import_file $tdir/$tfile $f
2655 local fid=$($LFS path2fid $f)
2656 HSM_ARCHIVE_PURGE=false copytool_setup
2658 restore_and_check_size $f $fid
2661 [[ $err -eq 0 ]] || error "File size changed during restore"
2665 run_test 31a "Import a large file and check size during restore"
2669 # test needs a running copytool
2674 local f=$DIR/$tdir/$tfile
2676 fid=$(make_custom_file_for_progress $f 39 1000000)
2677 [ $? != 0 ] && skip "not enough free space" && return
2679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2680 wait_request_state $fid ARCHIVE SUCCEED
2683 restore_and_check_size $f $fid
2686 [[ $err -eq 0 ]] || error "File size changed during restore"
2690 run_test 31b "Restore a large unaligned file and check size during restore"
2693 # test needs a running copytool
2698 local f=$DIR/$tdir/$tfile
2700 fid=$(make_custom_file_for_progress $f 33 1048576)
2701 [ $? != 0 ] && skip "not enough free space" && return
2703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2704 wait_request_state $fid ARCHIVE SUCCEED
2707 restore_and_check_size $f $fid
2710 [[ $err -eq 0 ]] || error "File size changed during restore"
2714 run_test 31c "Restore a large aligned file and check size during restore"
2717 # test needs a running copytool
2722 local f=$DIR/$tdir/$tfile
2724 fid=$(make_custom_file_for_progress $f 39 1000000)
2725 [ $? != 0 ] && skip "not enough free space" && return
2727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2728 wait_request_state $fid ARCHIVE SUCCEED
2731 # to be sure wait_all_done will not be mislead by previous tests
2734 wait_for_grace_delay
2735 # Also raise grace_delay significantly so the Canceled
2736 # Restore action will stay enough long avail.
2737 local old_grace=$(get_hsm_param grace_delay)
2738 set_hsm_param grace_delay 100
2740 md5sum $f >/dev/null &
2742 wait_request_state $fid RESTORE STARTED
2747 # Check restore trigger process was killed
2748 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2752 # instead of waiting+checking both Restore and Cancel ops
2753 # sequentially, wait for both to be finished and then check
2755 wait_all_done 100 $fid
2756 local rstate=$(get_request_state $fid RESTORE)
2757 local cstate=$(get_request_state $fid CANCEL)
2759 # restore orig grace_delay.
2760 set_hsm_param grace_delay $old_grace
2762 if [[ "$rstate" == "CANCELED" ]] ; then
2763 [[ "$cstate" == "SUCCEED" ]] ||
2764 error "Restore state is CANCELED and Cancel state " \
2765 "is not SUCCEED but $cstate"
2766 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2767 elif [[ "$rstate" == "SUCCEED" ]] ; then
2768 [[ "$cstate" == "FAILED" ]] ||
2769 error "Restore state is SUCCEED and Cancel state " \
2770 "is not FAILED but $cstate"
2771 echo "Restore state is SUCCEED, Cancel state is FAILED"
2773 error "Restore state is $rstate and Cancel state is $cstate"
2777 error "Cannot kill process waiting for restore ($killed)"
2781 run_test 33 "Kill a restore waiting process"
2784 # test needs a running copytool
2789 local f=$DIR/$tdir/$tfile
2791 fid=$(make_custom_file_for_progress $f 39 1000000)
2792 [ $? != 0 ] && skip "not enough free space" && return
2794 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2795 wait_request_state $fid ARCHIVE SUCCEED
2798 md5sum $f >/dev/null &
2800 wait_request_state $fid RESTORE STARTED
2802 rm $f || error "rm $f failed"
2803 # rm must not block during restore
2804 wait_request_state $fid RESTORE STARTED
2806 wait_request_state $fid RESTORE SUCCEED
2807 # check md5sum pgm finished
2808 local there=$(ps -o pid,comm hp $pid >/dev/null)
2809 [[ -z $there ]] || error "Restore initiator does not exit"
2811 local rc=$(wait $pid)
2812 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2816 run_test 34 "Remove file during restore"
2819 # test needs a running copytool
2824 local f=$DIR/$tdir/$tfile
2825 local f1=$DIR/$tdir/$tfile-1
2827 fid=$(make_custom_file_for_progress $f 39 1000000)
2828 [ $? != 0 ] && skip "not enough free space" && return
2830 local fid1=$(copy_file /etc/passwd $f1)
2831 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2832 wait_request_state $fid ARCHIVE SUCCEED
2835 md5sum $f >/dev/null &
2837 wait_request_state $fid RESTORE STARTED
2839 mv $f1 $f || error "mv $f1 $f failed"
2840 # mv must not block during restore
2841 wait_request_state $fid RESTORE STARTED
2843 wait_request_state $fid RESTORE SUCCEED
2844 # check md5sum pgm finished
2845 local there=$(ps -o pid,comm hp $pid >/dev/null)
2846 [[ -z $there ]] || error "Restore initiator does not exit"
2848 local rc=$(wait $pid)
2849 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2852 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2856 run_test 35 "Overwrite file during restore"
2859 # test needs a running copytool
2864 local f=$DIR/$tdir/$tfile
2866 fid=$(make_custom_file_for_progress $f 39 1000000)
2867 [ $? != 0 ] && skip "not enough free space" && return
2869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2870 wait_request_state $fid ARCHIVE SUCCEED
2873 md5sum $f >/dev/null &
2875 wait_request_state $fid RESTORE STARTED
2878 # rm must not block during restore
2879 wait_request_state $fid RESTORE STARTED
2881 wait_request_state $fid RESTORE SUCCEED
2882 # check md5sum pgm finished
2883 local there=$(ps -o pid,comm hp $pid >/dev/null)
2885 error "Restore initiator does not exit"
2887 local rc=$(wait $pid)
2889 error "Restore initiator failed with $rc"
2893 run_test 36 "Move file during restore"
2896 # LU-5683: check that an archived dirty file can be rearchived.
2898 copytool_setup $SINGLEAGT $MOUNT2
2901 local f=$DIR/$tdir/$tfile
2904 fid=$(make_small $f) || error "cannot create small file"
2906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2907 wait_request_state $fid ARCHIVE SUCCEED
2908 $LFS hsm_release $f || error "cannot release $f"
2910 # Allow previous archive request to expire from the actions log.
2911 wait_for_grace_delay
2914 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2916 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2917 wait_request_state $fid ARCHIVE SUCCEED
2921 run_test 37 "re-archive a dirty file"
2928 for n in $(seq 1 $count); do
2929 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2931 echo "$count archive requests submitted"
2935 local stream_count=4
2936 local file_count=100
2938 local f=$DIR/$tdir/$tfile
2943 for i in $(seq 1 $file_count); do
2944 for p in $(seq 1 $stream_count); do
2945 fid=$(copy_file /etc/hosts $f.$p.$i)
2948 # force copytool to use a local/temp archive dir to ensure best
2949 # performance vs remote/NFS mounts used in auto-tests
2950 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2953 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2955 # to be sure wait_all_done will not be mislead by previous tests
2957 wait_for_grace_delay
2959 # start archive streams in background (archive files in parallel)
2960 for p in $(seq 1 $stream_count); do
2961 multi_archive $f.$p $file_count &
2964 echo -n "Wait for all requests being enqueued..."
2970 run_test 40 "Parallel archive requests"
2973 # test needs a running copytool
2977 local f=$DIR/$tdir/$tfile
2978 local fid=$(copy_file /etc/motd $f 1)
2980 $LFS hsm_archive $f || error "could not archive file"
2981 wait_request_state $fid ARCHIVE SUCCEED
2982 check_hsm_flags $f "0x00000009"
2984 multiop_bg_pause $f O_c || error "multiop failed"
2988 client_up || client_up || true
2990 kill -USR1 $MULTIPID
2991 wait $MULTIPID || error "multiop close failed"
2993 check_hsm_flags $f "0x0000000b"
2997 run_test 52 "Opened for write file on an evicted client should be set dirty"
3000 # test needs a running copytool
3004 local f=$DIR/$tdir/$tfile
3005 local fid=$(copy_file /etc/motd $f 1)
3007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3008 error "could not archive file"
3009 wait_request_state $fid ARCHIVE SUCCEED
3010 check_hsm_flags $f "0x00000009"
3012 multiop_bg_pause $f o_c || error "multiop failed"
3016 client_up || client_up || true
3018 kill -USR1 $MULTIPID
3019 wait $MULTIPID || error "multiop close failed"
3021 check_hsm_flags $f "0x00000009"
3025 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3028 # test needs a running copytool
3032 local f=$DIR/$tdir/$tfile
3033 local fid=$(make_custom_file_for_progress $f 39 1000000)
3035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3036 error "could not archive file"
3037 wait_request_state $fid ARCHIVE STARTED
3039 check_hsm_flags $f "0x00000001"
3041 # Avoid coordinator resending this request as soon it has failed.
3046 wait_request_state $fid ARCHIVE FAILED
3048 check_hsm_flags $f "0x00000003"
3053 run_test 54 "Write during an archive cancels it"
3056 # test needs a running copytool
3060 local f=$DIR/$tdir/$tfile
3061 local fid=$(make_custom_file_for_progress $f 39 1000000)
3063 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3064 error "could not archive file"
3065 wait_request_state $fid ARCHIVE STARTED
3067 check_hsm_flags $f "0x00000001"
3069 # Avoid coordinator resending this request as soon it has failed.
3072 $TRUNCATE $f 1024 || error "truncate failed"
3074 wait_request_state $fid ARCHIVE FAILED
3076 check_hsm_flags $f "0x00000003"
3081 run_test 55 "Truncate during an archive cancels it"
3084 # test needs a running copytool
3088 local f=$DIR/$tdir/$tfile
3090 fid=$(make_custom_file_for_progress $f 39 1000000)
3091 [ $? != 0 ] && skip "not enough free space" && return
3093 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3094 error "could not archive file"
3095 wait_request_state $fid ARCHIVE STARTED
3097 check_hsm_flags $f "0x00000001"
3099 # Change metadata and sync to be sure we are not changing only
3104 wait_request_state $fid ARCHIVE SUCCEED
3106 check_hsm_flags $f "0x00000009"
3110 run_test 56 "Setattr during an archive is ok"
3113 # Need one client for I/O, one for request
3114 needclients 2 || return 0
3116 # test needs a running copytool
3120 local f=$DIR/$tdir/test_archive_remote
3121 # Create a file on a remote node
3122 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3123 "count=2 conv=fsync"
3126 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3127 error "hsm_archive failed"
3128 local fid=$(path2fid $f)
3129 wait_request_state $fid ARCHIVE SUCCEED
3131 # Release and implicit restore it
3132 do_node $CLIENT2 "$LFS hsm_release $f" ||
3133 error "hsm_release failed"
3134 do_node $CLIENT2 "md5sum $f" ||
3135 error "hsm_restore failed"
3137 wait_request_state $fid RESTORE SUCCEED
3141 run_test 57 "Archive a file with dirty cache on another node"
3143 truncate_released_file() {
3147 local sz=$(stat -c %s $src_file)
3148 local f=$DIR/$tdir/$tfile
3149 local fid=$(copy_file $1 $f)
3153 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3154 error "could not archive file"
3155 wait_request_state $fid ARCHIVE SUCCEED
3157 $LFS hsm_release $f || error "could not release file"
3159 $TRUNCATE $f $trunc_to || error "truncate failed"
3162 local sz1=$(stat -c %s $f)
3163 [[ $sz1 == $trunc_to ]] ||
3164 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3167 check_hsm_flags $f "0x0000000b"
3169 local state=$(get_request_state $fid RESTORE)
3170 [[ "$state" == "SUCCEED" ]] ||
3171 error "truncate $sz does not trig restore, state = $state"
3173 $TRUNCATE $ref $trunc_to
3174 cmp $ref $f || error "file data wrong after truncate"
3180 # test needs a running copytool
3185 local sz=$(stat -c %s /etc/passwd)
3187 echo "truncate up from $sz to $((sz*2))"
3188 truncate_released_file /etc/passwd $((sz*2))
3190 echo "truncate down from $sz to $((sz/2))"
3191 truncate_released_file /etc/passwd $((sz/2))
3193 echo "truncate to 0"
3194 truncate_released_file /etc/passwd 0
3198 run_test 58 "Truncate a released file will trigger restore"
3202 local server_version=$(lustre_version_code $SINGLEMDS)
3203 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3204 skip "Need MDS version at least 2.7.63" && return
3207 $MCREATE $DIR/$tfile || error "mcreate failed"
3208 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3209 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3210 fid=$(path2fid $DIR/$tfile)
3211 wait_request_state $fid ARCHIVE SUCCEED
3212 $LFS hsm_release $DIR/$tfile || error "release failed"
3215 run_test 59 "Release stripeless file with non-zero size"
3218 # This test validates the fix for LU-4512. Ensure that the -u
3219 # option changes the progress reporting interval from the
3220 # default (30 seconds) to the user-specified interval.
3222 local progress_timeout=$((interval * 4))
3224 # test needs a new running copytool
3226 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3229 local f=$DIR/$tdir/$tfile
3231 fid=$(make_custom_file_for_progress $f 10)
3232 [ $? != 0 ] && skip "not enough free space" && return
3235 local mdt=${MDT_PREFIX}${mdtidx}
3236 local mds=mds$((mdtidx + 1))
3238 # Wait for copytool to register
3239 wait_update_facet $mds \
3240 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3241 uuid 100 || error "coyptool failed to register with $mdt"
3243 local start_at=$(date +%s)
3244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3245 error "could not archive file"
3247 local agent=$(facet_active_host $SINGLEAGT)
3248 local prefix=$TESTLOG_PREFIX
3249 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3250 local copytool_log=$prefix.copytool_log.$agent.log
3253 wait_update $agent \
3254 "grep -o start.copy $copytool_log" "start copy" 100 ||
3255 error "copytool failed to start"
3257 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3258 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3264 echo -n "Expecting a progress update within $progress_timeout seconds... "
3266 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3267 if [ $RESULT -gt 0 ]; then
3268 echo "$RESULT bytes copied in $WAIT seconds."
3270 elif [ $WAIT -ge $progress_timeout ]; then
3271 error "Timed out waiting for progress update!"
3274 WAIT=$((WAIT + sleep))
3278 local finish_at=$(date +%s)
3279 local elapsed=$((finish_at - start_at))
3281 # Ensure that the progress update occurred within the expected window.
3282 if [ $elapsed -lt $((interval - 1)) ]; then
3283 error "Expected progress update after at least $interval seconds"
3286 echo "Wait for on going archive hsm action to complete"
3287 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3288 echo "File archiving not completed even after 10 secs"
3293 run_test 60 "Changing progress update interval from default"
3296 # test needs a new running copytool
3298 copytool_monitor_setup
3299 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3301 # Just start and stop the copytool to generate events.
3304 # Wait for the copytool to register.
3305 wait_update --verbose $(facet_active_host mds1) \
3306 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3308 error "copytool failed to register with MDT0000"
3312 local REGISTER_EVENT
3313 local UNREGISTER_EVENT
3314 while read event; do
3315 local parsed=$(parse_json_event "$event")
3316 if [ -z "$parsed" ]; then
3317 error "Copytool sent malformed event: $event"
3321 if [ $event_type == "REGISTER" ]; then
3322 REGISTER_EVENT=$event
3323 elif [ $event_type == "UNREGISTER" ]; then
3324 UNREGISTER_EVENT=$event
3326 done < <(echo $"$(get_copytool_event_log)")
3328 if [ -z "$REGISTER_EVENT" ]; then
3329 error "Copytool failed to send register event to FIFO"
3332 if [ -z "$UNREGISTER_EVENT" ]; then
3333 error "Copytool failed to send unregister event to FIFO"
3336 copytool_monitor_cleanup
3337 echo "Register/Unregister events look OK."
3339 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3342 # Bump progress interval for livelier events.
3345 # test needs a new running copytool
3347 copytool_monitor_setup
3348 HSMTOOL_UPDATE_INTERVAL=$interval \
3349 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3352 local f=$DIR/$tdir/$tfile
3354 fid=$(make_custom_file_for_progress $f 39 1000000)
3355 [ $? != 0 ] && skip "not enough free space" && return
3357 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3358 error "could not archive file"
3359 wait_request_state $fid ARCHIVE SUCCEED
3361 local expected_fields="event_time data_fid source_fid"
3362 expected_fields+=" total_bytes current_bytes"
3366 while read event; do
3367 # Make sure we're not getting anything from previous events.
3368 for field in $expected_fields; do
3372 local parsed=$(parse_json_event "$event")
3373 if [ -z "$parsed" ]; then
3374 error "Copytool sent malformed event: $event"
3378 if [ $event_type == "ARCHIVE_START" ]; then
3381 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3384 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3388 # Do some simple checking of the progress update events.
3389 for expected_field in $expected_fields; do
3390 if [ -z ${!expected_field+x} ]; then
3391 error "Missing $expected_field field in event"
3395 if [ $total_bytes -eq 0 ]; then
3396 error "Expected total_bytes to be > 0"
3399 # These should be identical throughout an archive
3401 if [ $source_fid != $data_fid ]; then
3402 error "Expected source_fid to equal data_fid"
3404 done < <(echo $"$(get_copytool_event_log)")
3406 if [ -z "$START_EVENT" ]; then
3407 error "Copytool failed to send archive start event to FIFO"
3410 if [ -z "$FINISH_EVENT" ]; then
3411 error "Copytool failed to send archive finish event to FIFO"
3414 echo "Archive events look OK."
3418 copytool_monitor_cleanup
3420 run_test 71 "Copytool logs JSON archive events to FIFO"
3423 # Bump progress interval for livelier events.
3426 # test needs a new running copytool
3428 copytool_monitor_setup
3429 HSMTOOL_UPDATE_INTERVAL=$interval \
3430 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3431 local test_file=$HSMTOOL_MONITOR_DIR/file
3433 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3435 do_facet $SINGLEAGT "$cmd" ||
3436 error "cannot create $test_file on $SINGLEAGT"
3437 copy2archive $test_file $tdir/$tfile
3440 local f=$DIR/$tdir/$tfile
3441 import_file $tdir/$tfile $f
3442 f=$DIR2/$tdir/$tfile
3443 echo "Verifying released state: "
3444 check_hsm_flags $f "0x0000000d"
3446 local fid=$(path2fid $f)
3448 wait_request_state $fid RESTORE SUCCEED
3450 local expected_fields="event_time data_fid source_fid"
3451 expected_fields+=" total_bytes current_bytes"
3455 while read event; do
3456 # Make sure we're not getting anything from previous events.
3457 for field in $expected_fields; do
3461 local parsed=$(parse_json_event "$event")
3462 if [ -z "$parsed" ]; then
3463 error "Copytool sent malformed event: $event"
3467 if [ $event_type == "RESTORE_START" ]; then
3469 if [ $source_fid != $data_fid ]; then
3470 error "source_fid should == data_fid at start"
3473 elif [ $event_type == "RESTORE_FINISH" ]; then
3475 if [ $source_fid != $data_fid ]; then
3476 error "source_fid should == data_fid at finish"
3479 elif [ $event_type != "RESTORE_RUNNING" ]; then
3483 # Do some simple checking of the progress update events.
3484 for expected_field in $expected_fields; do
3485 if [ -z ${!expected_field+x} ]; then
3486 error "Missing $expected_field field in event"
3490 if [ $total_bytes -eq 0 ]; then
3491 error "Expected total_bytes to be > 0"
3494 # When a restore starts out, the data fid is the same as the
3495 # source fid. After the restore has gotten going, we learn
3496 # the new data fid. Once the restore has finished, the source
3497 # fid is set to the new data fid.
3499 # We test this because some monitoring software may depend on
3500 # this behavior. If it changes, then the consumers of these
3501 # events may need to be modified.
3502 if [ $source_fid == $data_fid ]; then
3503 error "source_fid should != data_fid during restore"
3505 done < <(echo $"$(get_copytool_event_log)")
3507 if [ -z "$START_EVENT" ]; then
3508 error "Copytool failed to send restore start event to FIFO"
3511 if [ -z "$FINISH_EVENT" ]; then
3512 error "Copytool failed to send restore finish event to FIFO"
3515 echo "Restore events look OK."
3519 copytool_monitor_cleanup
3523 run_test 72 "Copytool logs JSON restore events to FIFO"
3526 file_count=51 # Max number of files constrained by LNET message size
3527 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3528 local f=$DIR/$tdir/$tfile
3529 local FILELIST=/tmp/filelist.txt
3533 for i in $(seq 1 $file_count); do
3534 fid=$(copy_file /etc/hosts $f.$i)
3535 echo $f.$i >> $FILELIST
3537 # force copytool to use a local/temp archive dir to ensure best
3538 # performance vs remote/NFS mounts used in auto-tests
3539 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3542 local dai=$(get_hsm_param default_archive_id)
3543 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3545 # to be sure wait_all_done will not be mislead by previous tests
3547 wait_for_grace_delay
3548 $LFS hsm_archive --filelist $FILELIST ||
3549 error "cannot archive a file list"
3551 $LFS hsm_release --filelist $FILELIST ||
3552 error "cannot release a file list"
3553 $LFS hsm_restore --filelist $FILELIST ||
3554 error "cannot restore a file list"
3558 run_test 90 "Archive/restore a file list"
3560 double_verify_reset_hsm_param() {
3562 echo "Testing $HSM_PARAM.$p"
3563 local val=$(get_hsm_param $p)
3565 local val2=$(($val * 2))
3566 set_hsm_param $p $val2
3567 val=$(get_hsm_param $p)
3568 [[ $val == $val2 ]] ||
3569 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3570 echo "Set $p to 0 must failed"
3574 set_hsm_param $p $save
3576 if [[ $rc == 0 ]]; then
3577 error "we must not be able to set $HSM_PARAM.$p to 0"
3582 double_verify_reset_hsm_param loop_period
3583 double_verify_reset_hsm_param grace_delay
3584 double_verify_reset_hsm_param active_request_timeout
3585 double_verify_reset_hsm_param max_requests
3586 double_verify_reset_hsm_param default_archive_id
3588 run_test 100 "Set coordinator /proc tunables"
3595 run_test 102 "Verify coordinator control"
3598 # test needs a running copytool
3605 for i in $(seq 1 20); do
3606 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3608 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3612 echo "Current requests"
3613 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3614 $HSM_PARAM.actions |\
3615 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3617 [[ -z "$res" ]] || error "Some request have not been canceled"
3621 run_test 103 "Purge all requests"
3626 # test needs a running copytool
3630 local f=$DIR/$tdir/$tfile
3632 fid=$(make_custom_file_for_progress $f 39 1000000)
3633 [ $? != 0 ] && skip "not enough free space" && return
3635 # if cdt is on, it can serve too quickly the request
3637 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3638 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3639 $HSM_PARAM.actions |\
3640 grep $fid | cut -f16 -d=")
3643 [[ "$data1" == "$DATAHEX" ]] ||
3644 error "Data field in records is ($data1) and not ($DATAHEX)"
3648 run_test 104 "Copy tool data field"
3655 for i in $(seq -w 1 10); do
3656 cp /etc/passwd $DIR/$tdir/$i
3657 $LFS hsm_archive $DIR/$tdir/$i
3659 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3660 $HSM_PARAM.actions |\
3661 grep WAITING | wc -l")
3664 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3665 $HSM_PARAM.actions |\
3666 grep WAITING | wc -l")
3669 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3670 error "Requests count after shutdown $reqcnt2 != "\
3671 "before shutdown $reqcnt1"
3673 run_test 105 "Restart of coordinator"
3676 # test needs a running copytool
3679 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3681 check_agent_registered $uuid
3683 search_copytools || error "No copytool found"
3686 check_agent_unregistered $uuid
3689 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3690 check_agent_registered $uuid
3694 run_test 106 "Copytool register/unregister"
3697 # test needs a running copytool
3699 # create and archive file
3701 local f1=$DIR/$tdir/$tfile
3702 local fid=$(copy_file /etc/passwd $f1)
3703 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3704 wait_request_state $fid ARCHIVE SUCCEED
3705 # shutdown and restart MDS
3707 # check the copytool still gets messages from MDT
3708 local f2=$DIR/$tdir/2
3709 local fid=$(copy_file /etc/passwd $f2)
3710 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3711 # main check of this sanity: this request MUST succeed
3712 wait_request_state $fid ARCHIVE SUCCEED
3715 run_test 107 "Copytool re-register after MDS restart"
3717 policy_set_and_test()
3721 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3722 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3723 [[ "$policy" == "$target" ]] ||
3724 error "Wrong policy after '$change': '$policy' != '$target'"
3728 # to force default policy setting if error
3729 CDT_POLICY_HAD_CHANGED=true
3731 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3732 local default="NonBlockingRestore [NoRetryAction]"
3733 [[ "$policy" == "$default" ]] ||
3734 error "default policy has changed,"\
3735 " '$policy' != '$default' update the test"
3736 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3737 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3738 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3739 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3740 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3741 # useless bacause we know but safer for futur changes to use real value
3742 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3743 echo "Next set_param must failed"
3744 policy_set_and_test "wrong" "$policy"
3747 echo "Back to default policy"
3748 cdt_set_sanity_policy
3750 run_test 109 "Policy display/change"
3753 # test needs a running copytool
3758 copy2archive /etc/passwd $tdir/$tfile
3760 local f=$DIR/$tdir/$tfile
3761 import_file $tdir/$tfile $f
3762 local fid=$(path2fid $f)
3764 cdt_set_non_blocking_restore
3769 wait_request_state $fid RESTORE SUCCEED
3770 cdt_clear_non_blocking_restore
3774 error "md5sum returns $st != 1, "\
3775 "should also perror ENODATA (No data available)"
3779 run_test 110a "Non blocking restore policy (import case)"
3782 # test needs a running copytool
3786 local f=$DIR/$tdir/$tfile
3787 local fid=$(copy_file /etc/passwd $f)
3788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3789 wait_request_state $fid ARCHIVE SUCCEED
3792 cdt_set_non_blocking_restore
3797 wait_request_state $fid RESTORE SUCCEED
3798 cdt_clear_non_blocking_restore
3802 error "md5sum returns $st != 1, "\
3803 "should also perror ENODATA (No data available)"
3807 run_test 110b "Non blocking restore policy (release case)"
3810 # test needs a running copytool
3814 copy2archive /etc/passwd $tdir/$tfile
3816 local f=$DIR/$tdir/$tfile
3818 import_file $tdir/$tfile $f
3819 local fid=$(path2fid $f)
3823 copytool_remove_backend $fid
3826 wait_request_state $fid RESTORE FAILED
3833 [[ $st == 0 ]] || error "Restore does not failed"
3837 run_test 111a "No retry policy (import case), restore will error"\
3838 " (No such file or directory)"
3841 # test needs a running copytool
3845 local f=$DIR/$tdir/$tfile
3846 local fid=$(copy_file /etc/passwd $f)
3848 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3849 wait_request_state $fid ARCHIVE SUCCEED
3852 copytool_remove_backend $fid
3855 wait_request_state $fid RESTORE FAILED
3862 [[ $st == 0 ]] || error "Restore does not failed"
3866 run_test 111b "No retry policy (release case), restore will error"\
3867 " (No such file or directory)"
3870 # test needs a running copytool
3874 local f=$DIR/$tdir/$tfile
3875 local fid=$(copy_file /etc/passwd $f)
3877 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3878 local l=$($LFS hsm_action $f)
3880 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3884 wait_request_state $fid ARCHIVE SUCCEED
3887 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3891 run_test 112 "State of recorded request"
3894 # test needs a running copytool
3898 local f=$DIR/$tdir/$tfile
3900 fid=$(make_custom_file_for_progress $f 103 1048576)
3901 [ $? != 0 ] && skip "not enough free space" && return
3903 # test with cdt on is made in test_221
3905 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3906 # wait archive to register at CDT
3907 wait_request_state $fid ARCHIVE WAITING
3910 wait_request_state $fid ARCHIVE CANCELED
3911 wait_request_state $fid CANCEL SUCCEED
3915 run_test 200 "Register/Cancel archive"
3918 # test needs a running copytool
3922 local f=$DIR/$tdir/$tfile
3923 make_archive $tdir/$tfile
3924 import_file $tdir/$tfile $f
3925 local fid=$(path2fid $f)
3927 # test with cdt on is made in test_222
3930 # wait restore to register at CDT
3931 wait_request_state $fid RESTORE WAITING
3934 wait_request_state $fid RESTORE CANCELED
3935 wait_request_state $fid CANCEL SUCCEED
3939 run_test 201 "Register/Cancel restore"
3942 # test needs a running copytool
3946 local f=$DIR/$tdir/$tfile
3948 fid=$(make_custom_file_for_progress $f 39 1000000)
3949 [ $? != 0 ] && skip "not enough free space" && return
3951 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3952 wait_request_state $fid ARCHIVE SUCCEED
3956 # wait remove to register at CDT
3957 wait_request_state $fid REMOVE WAITING
3960 wait_request_state $fid REMOVE CANCELED
3964 run_test 202 "Register/Cancel remove"
3967 # test needs a running copytool
3972 local f=$DIR/$tdir/$tfile
3973 local fid=$(copy_file /etc/passwd $f)
3977 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3978 wait_request_state $fid ARCHIVE SUCCEED
3980 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
3984 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
3988 run_test 220 "Changelog for archive"
3991 # test needs a running copytool
3996 local f=$DIR/$tdir/$tfile
3997 local fid=$(copy_file /etc/passwd $f)
4001 # block copytool operations to allow for HSM request to be
4002 # submitted and file be unlinked (CDT will find object removed)
4005 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4011 wait_request_state $fid ARCHIVE FAILED
4013 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4018 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4022 run_test 220a "Changelog for failed archive"
4025 # test needs a running copytool
4030 local f=$DIR/$tdir/$tfile
4032 fid=$(make_custom_file_for_progress $f 103 1048576)
4033 [ $? != 0 ] && skip "not enough free space" && return
4037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4038 wait_request_state $fid ARCHIVE STARTED
4040 wait_request_state $fid ARCHIVE CANCELED
4041 wait_request_state $fid CANCEL SUCCEED
4043 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4046 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4050 run_test 221 "Changelog for archive canceled"
4053 # test needs a running copytool
4057 copy2archive /etc/passwd $tdir/$tfile
4059 local f=$DIR/$tdir/$tfile
4060 import_file $tdir/$tfile $f
4061 local fid=$(path2fid $f)
4066 wait_request_state $fid RESTORE SUCCEED
4068 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4071 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4075 run_test 222a "Changelog for explicit restore"
4078 # test needs a running copytool
4082 local f=$DIR/$tdir/$tfile
4083 local fid=$(copy_file /etc/passwd $f)
4086 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4087 wait_request_state $fid ARCHIVE SUCCEED
4092 wait_request_state $fid RESTORE SUCCEED
4094 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4097 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4101 run_test 222b "Changelog for implicit restore"
4104 # test needs a running copytool
4108 copy2archive /etc/passwd $tdir/$tfile
4110 local f=$DIR/$tdir/$tfile
4111 import_file $tdir/$tfile $f
4112 local fid=$(path2fid $f)
4116 # block copytool operations to allow for HSM request to be
4117 # submitted and file be unlinked (CDT will find object removed)
4125 wait_request_state $fid RESTORE FAILED
4127 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4131 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4135 run_test 222c "Changelog for failed explicit restore"
4138 # test needs a running copytool
4142 local f=$DIR/$tdir/$tfile
4143 local fid=$(copy_file /etc/passwd $f)
4146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4147 wait_request_state $fid ARCHIVE SUCCEED
4150 copytool_remove_backend $fid
4153 wait_request_state $fid RESTORE FAILED
4155 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4159 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4163 run_test 222d "Changelog for failed implicit restore"
4166 # test needs a running copytool
4171 local f=$DIR/$tdir/$tfile
4172 make_archive $tdir/$tfile
4176 import_file $tdir/$tfile $f
4177 local fid=$(path2fid $f)
4180 wait_request_state $fid RESTORE STARTED
4182 wait_request_state $fid RESTORE CANCELED
4183 wait_request_state $fid CANCEL SUCCEED
4185 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4188 [[ $flags == $target ]] ||
4189 error "Changelog flag is $flags not $target"
4193 run_test 223a "Changelog for restore canceled (import case)"
4196 # test needs a running copytool
4201 local f=$DIR/$tdir/$tfile
4203 fid=$(make_custom_file_for_progress $f 39 1000000)
4204 [ $? != 0 ] && skip "not enough free space" && return
4207 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4208 wait_request_state $fid ARCHIVE SUCCEED
4211 wait_request_state $fid RESTORE STARTED
4213 wait_request_state $fid RESTORE CANCELED
4214 wait_request_state $fid CANCEL SUCCEED
4216 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4219 [[ $flags == $target ]] ||
4220 error "Changelog flag is $flags not $target"
4224 run_test 223b "Changelog for restore canceled (release case)"
4227 # test needs a running copytool
4232 local f=$DIR/$tdir/$tfile
4233 local fid=$(copy_file /etc/passwd $f)
4236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4237 wait_request_state $fid ARCHIVE SUCCEED
4240 wait_request_state $fid REMOVE SUCCEED
4242 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4245 [[ $flags == $target ]] ||
4246 error "Changelog flag is $flags not $target"
4250 run_test 224 "Changelog for remove"
4253 # test needs a running copytool
4258 local f=$DIR/$tdir/$tfile
4259 local fid=$(copy_file /etc/passwd $f)
4262 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4263 wait_request_state $fid ARCHIVE SUCCEED
4265 copytool_remove_backend $fid
4267 # block copytool operations to allow for HSM request to be
4268 # submitted and file be unlinked (CDT will find object removed)
4276 wait_request_state $fid REMOVE FAILED
4278 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4282 [[ $flags == $target ]] ||
4283 error "Changelog flag is $flags not $target"
4287 run_test 224a "Changelog for failed remove"
4290 # test needs a running copytool
4293 # test is not usable because remove request is too fast
4294 # so it is always finished before cancel can be done ...
4295 echo "Test disabled"
4300 local f=$DIR/$tdir/$tfile
4302 fid=$(make_custom_file_for_progress $f 39 1000000)
4303 [ $? != 0 ] && skip "not enough free space" && return
4306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4307 wait_request_state $fid ARCHIVE SUCCEED
4309 # if cdt is on, it can serve too quickly the request
4314 wait_request_state $fid REMOVE CANCELED
4315 wait_request_state $fid CANCEL SUCCEED
4317 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4318 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4319 tail -n 1 | awk '{print $5}')
4322 [[ $flags == $target ]] ||
4323 error "Changelog flag is $flags not $target"
4327 run_test 225 "Changelog for remove canceled"
4330 # test needs a running copytool
4335 local f1=$DIR/$tdir/$tfile-1
4336 local f2=$DIR/$tdir/$tfile-2
4337 local f3=$DIR/$tdir/$tfile-3
4338 local fid1=$(copy_file /etc/passwd $f1)
4339 local fid2=$(copy_file /etc/passwd $f2)
4340 copy_file /etc/passwd $f3
4343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4344 wait_request_state $fid1 ARCHIVE SUCCEED
4346 $LFS hsm_archive $f2
4347 wait_request_state $fid2 ARCHIVE SUCCEED
4349 rm $f1 || error "rm $f1 failed"
4351 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4354 [[ $flags == $target ]] ||
4355 error "Changelog flag is $flags not $target"
4357 mv $f3 $f2 || error "mv $f3 $f2 failed"
4359 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4362 [[ $flags == $target ]] ||
4363 error "Changelog flag is $flags not $target"
4367 run_test 226 "changelog for last rm/mv with exiting archive"
4369 check_flags_changes() {
4377 $LFS hsm_set --$hsm_flag $f ||
4378 error "Cannot set $hsm_flag on $f"
4379 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4380 local seen=${#flags[*]}
4382 [[ $seen == $cnt ]] ||
4383 error "set $hsm_flag: Changelog events $seen != $cnt"
4384 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4385 error "set $hsm_flag: Changelog flags are "\
4386 "${flags[$((cnt - 1))]} not $target"
4388 $LFS hsm_clear --$hsm_flag $f ||
4389 error "Cannot clear $hsm_flag on $f"
4390 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4393 [[ $cnt == $seen ]] ||
4394 error "clear $hsm_flag: Changelog events $seen != $cnt"
4396 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4397 error "clear $hsm_flag: Changelog flag is "\
4398 "${flags[$((cnt - 1))]} not $target"
4402 # test needs a running copytool
4409 for i in norelease noarchive exists archived
4411 local f=$DIR/$tdir/$tfile-$i
4412 local fid=$(copy_file /etc/passwd $f)
4413 check_flags_changes $f $fid $i 0 1
4416 f=$DIR/$tdir/$tfile---lost
4417 fid=$(copy_file /etc/passwd $f)
4418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4419 wait_request_state $fid ARCHIVE SUCCEED
4420 check_flags_changes $f $fid lost 3 1
4424 run_test 227 "changelog when explicit setting of HSM flags"
4427 # test needs a running copytool
4430 local fid=$(make_small_sync $DIR/$tfile)
4431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4432 wait_request_state $fid ARCHIVE SUCCEED
4434 $LFS hsm_release $DIR/$tfile
4435 check_hsm_flags $DIR/$tfile "0x0000000d"
4437 filefrag $DIR/$tfile | grep " 1 extent found" ||
4438 error "filefrag on released file must return only one extent"
4440 # only newer versions of cp detect sparse files by stat/FIEMAP
4442 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4443 error "copying $DIR/$tfile"
4444 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4446 $LFS hsm_release $DIR/$tfile
4447 check_hsm_flags $DIR/$tfile "0x0000000d"
4449 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4451 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4453 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4454 error "comparing untarred $DIR/$tfile"
4456 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4457 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4460 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4463 # test needs a running copytool
4467 local maxrequest=$(get_hsm_param max_requests)
4468 local rqcnt=$(($maxrequest * 3))
4472 for i in $(seq -w 1 $rqcnt); do
4474 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4476 # we do it in 2 steps, so all requests arrive at the same time
4477 for i in $(seq -w 1 $rqcnt); do
4478 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4483 while [[ $cnt != 0 || $wt != 0 ]]; do
4485 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4486 $HSM_PARAM.actions |\
4487 grep STARTED | grep -v CANCEL | wc -l")
4488 [[ $cnt -le $maxrequest ]] ||
4489 error "$cnt > $maxrequest too many started requests"
4490 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4491 $HSM_PARAM.actions |\
4492 grep WAITING | wc -l")
4493 echo "max=$maxrequest started=$cnt waiting=$wt"
4498 run_test 250 "Coordinator max request"
4501 # test needs a running copytool
4505 local f=$DIR/$tdir/$tfile
4507 fid=$(make_custom_file_for_progress $f 103 1048576)
4508 [ $? != 0 ] && skip "not enough free space" && return
4511 # to have a short test
4512 local old_to=$(get_hsm_param active_request_timeout)
4513 set_hsm_param active_request_timeout 4
4514 # to be sure the cdt will wake up frequently so
4515 # it will be able to cancel the "old" request
4516 local old_loop=$(get_hsm_param loop_period)
4517 set_hsm_param loop_period 2
4520 # clear locks to avoid extra delay caused by flush/cancel
4521 # and thus prevent early copytool death to timeout.
4522 cancel_lru_locks osc
4524 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4525 wait_request_state $fid ARCHIVE STARTED
4527 wait_request_state $fid ARCHIVE CANCELED
4529 set_hsm_param active_request_timeout $old_to
4530 set_hsm_param loop_period $old_loop
4534 run_test 251 "Coordinator request timeout"
4537 # the only way to test ondisk conf is to restart MDS ...
4538 echo "Stop coordinator and remove coordinator state at mount"
4541 # clean on disk conf set by default
4542 cdt_clear_mount_state
4543 cdt_check_state stopped
4545 # check cdt still off after umount/remount
4547 cdt_check_state stopped
4549 echo "Set coordinator start at mount, and start coordinator"
4550 cdt_set_mount_state enabled
4553 cdt_check_state enabled
4555 # check cdt still on after umount/remount
4557 cdt_check_state enabled
4559 # we are back to original state (cdt started at mount)
4561 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4564 local ai=$(get_hsm_param default_archive_id)
4565 local new=$((ai + 1))
4567 set_hsm_param default_archive_id $new -P
4569 local res=$(get_hsm_param default_archive_id)
4572 set_hsm_param default_archive_id "" "-P -d"
4574 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4576 run_test 301 "HSM tunnable are persistent"
4579 local ai=$(get_hsm_param default_archive_id)
4580 local new=$((ai + 1))
4585 set_hsm_param default_archive_id $new -P
4588 for mdtno in $(seq 1 $MDSCOUNT); do
4593 cdt_check_state enabled
4595 local res=$(get_hsm_param default_archive_id)
4598 set_hsm_param default_archive_id "" "-P -d"
4600 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4602 run_test 302 "HSM tunnable are persistent when CDT is off"
4605 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4611 local dir_mdt0=$DIR/$tdir/mdt0
4612 local dir_mdt1=$DIR/$tdir/mdt1
4614 # create 1 dir per MDT
4615 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4616 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4618 # create 1 file in each MDT
4619 local fid1=$(make_small $dir_mdt0/$tfile)
4620 local fid2=$(make_small $dir_mdt1/$tfile)
4622 # check that hsm request on mdt0 is sent to the right MDS
4623 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4624 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4625 echo "archive successful on mdt0"
4627 # check that hsm request on mdt1 is sent to the right MDS
4628 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4629 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4630 echo "archive successful on mdt1"
4633 # clean test files and directories
4634 rm -rf $dir_mdt0 $dir_mdt1
4636 run_test 400 "Single request is sent to the right MDT"
4639 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4645 local dir_mdt0=$DIR/$tdir/mdt0
4646 local dir_mdt1=$DIR/$tdir/mdt1
4648 # create 1 dir per MDT
4649 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4650 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4652 # create 1 file in each MDT
4653 local fid1=$(make_small $dir_mdt0/$tfile)
4654 local fid2=$(make_small $dir_mdt1/$tfile)
4656 # check that compound requests are shunt to the rights MDTs
4657 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4658 error "lfs hsm_archive"
4659 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4660 echo "archive successful on mdt0"
4661 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4662 echo "archive successful on mdt1"
4665 # clean test files and directories
4666 rm -rf $dir_mdt0 $dir_mdt1
4668 run_test 401 "Compound requests split and sent to their respective MDTs"
4670 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4675 local node=$(facet_active_host $facet)
4677 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4678 awk '{print $4}'); do
4679 echo "$3 $mdc on $node"
4680 do_facet $facet "$LCTL --device $mdc $state" || return 1
4685 # make sure there is no running copytool
4688 # deactivate all mdc on agent1
4689 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4691 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4693 check_agent_unregistered "uuid" # match any agent
4695 # no expected running copytool
4696 search_copytools $agent && error "Copytool start should have failed"
4699 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4701 run_test 402 "Copytool start fails if all MDTs are inactive"
4704 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4706 # make sure there is no running copytool
4709 local agent=$(facet_active_host $SINGLEAGT)
4711 # deactivate all mdc for MDT0001
4712 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4715 local uuid=$(get_agent_uuid $agent)
4716 # check the agent is registered on MDT0000, and not on MDT0001
4717 check_agent_registered_by_mdt $uuid 0
4718 check_agent_unregistered_by_mdt $uuid 1
4720 # check running copytool process
4721 search_copytools $agent || error "No running copytools on $agent"
4723 # reactivate all mdc for MDT0001
4724 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4726 # make sure the copytool is now registered to all MDTs
4727 check_agent_registered $uuid
4731 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4734 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4738 # create files on both MDT0000 and MDT0001
4741 local dir_mdt0=$DIR/$tdir/mdt0
4742 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4744 # create 1 file on mdt0
4745 local fid1=$(make_small $dir_mdt0/$tfile)
4747 # deactivate all mdc for MDT0001
4748 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4750 # send an HSM request for files in MDT0000
4751 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4753 # check for completion of files in MDT0000
4754 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4755 echo "archive successful on mdt0"
4757 # reactivate all mdc for MDT0001
4758 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4761 # clean test files and directories
4764 run_test 404 "Inactive MDT does not block requests for active MDTs"
4767 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4773 local striped_dir=$DIR/$tdir/striped_dir
4775 # create striped dir on all of MDTs
4776 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4778 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4779 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4780 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4781 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4783 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4784 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4785 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4786 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4788 # check that compound requests are shunt to the rights MDTs
4789 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4790 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4791 error "lfs hsm_archive"
4793 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4794 echo "archive successful on $fid1"
4795 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4796 echo "archive successful on $fid2"
4797 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4798 echo "archive successful on $fid3"
4799 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4800 echo "archive successful on $fid4"
4802 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4803 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4804 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4805 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4807 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4808 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4809 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4810 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4814 run_test 405 "archive and release under striped directory"
4817 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4819 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4820 skip "need MDS version at least 2.7.64" && return 0
4827 fid=$(make_small $DIR/$tdir/$tfile)
4830 $LFS hsm_archive $DIR/$tdir/$tfile
4831 wait_request_state "$fid" ARCHIVE SUCCEED
4832 $LFS hsm_release $DIR/$tdir/$tfile
4834 # Should migrate $tdir but not $tfile.
4835 $LFS mv -M1 $DIR/$tdir &&
4836 error "migrating HSM an archived file should fail"
4838 $LFS hsm_restore $DIR/$tdir/$tfile
4839 wait_request_state "$fid" RESTORE SUCCEED
4841 $LFS hsm_remove $DIR/$tdir/$tfile
4842 wait_request_state "$fid" REMOVE SUCCEED
4844 cat $DIR/$tdir/$tfile > /dev/null ||
4845 error "cannot read $DIR/$tdir/$tfile"
4847 $LFS mv -M1 $DIR/$tdir ||
4848 error "cannot complete migration after HSM remove"
4850 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4851 if ((mdt_index != 1)); then
4852 error "expected MDT index 1, got $mdt_index"
4855 # Refresh fid after migration.
4856 fid=$(path2fid $DIR/$tdir/$tfile)
4859 $LFS hsm_archive $DIR/$tdir/$tfile
4860 wait_request_state "$fid" ARCHIVE SUCCEED 1
4862 lctl set_param debug=+trace
4863 $LFS hsm_release $DIR/$tdir/$tfile ||
4864 error "cannot release $DIR/$tdir/$tfile"
4866 $LFS hsm_restore $DIR/$tdir/$tfile
4867 wait_request_state "$fid" RESTORE SUCCEED 1
4869 cat $DIR/$tdir/$tfile > /dev/null ||
4870 error "cannot read $DIR/$tdir/$tfile"
4874 run_test 406 "attempting to migrate HSM archived files is safe"
4878 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
4879 skip "HSM migrate is not supported" && return
4881 # Stop the existing copytool
4884 test_mkdir -p $DIR/$tdir
4885 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
4887 run_test 500 "various LLAPI HSM tests"
4892 check_and_cleanup_lustre