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))
173 local sleep_time=100000 # 0.1 second
175 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"
183 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
184 sleep_time=$(bc <<< "$sleep_time * 2")
187 # try to dump Copytool's stack
188 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
189 "echo t >/proc/sysrq-trigger"
191 echo "copytools failed to stop in ${wait_timeout}s"
196 copytool_monitor_setup() {
197 local facet=${1:-$SINGLEAGT}
198 local agent=$(facet_active_host $facet)
200 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
201 local test_dir=$(do_node $agent "$cmd") ||
202 error "Failed to create tempdir on $agent"
203 export HSMTOOL_MONITOR_DIR=$test_dir
205 # Create the fifo and a monitor (cat dies when copytool dies)
206 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
207 error "failed to create copytool fifo on $agent"
208 cmd="cat $test_dir/fifo > $test_dir/events &"
209 cmd+=" echo \\\$! > $test_dir/monitor_pid"
211 if [[ $PDSH == *Rmrsh* ]]; then
212 # This is required for pdsh -Rmrsh and its handling of remote
214 # Regular ssh and pdsh -Rssh work fine without this
215 # backgrounded subshell nonsense.
216 (do_node $agent "$cmd") &
217 export HSMTOOL_MONITOR_PDSH=$!
219 # Slightly racy, but just making a best-effort to catch obvious
222 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
223 error "Failed to start copytool monitor on $agent"
225 do_node $agent "$cmd"
227 error "Failed to start copytool monitor on $agent"
232 copytool_monitor_cleanup() {
233 local facet=${1:-$SINGLEAGT}
234 local agent=$(facet_active_host $facet)
236 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
237 # Should die when the copytool dies, but just in case.
238 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
239 cmd+=" 2>/dev/null || true"
240 do_node $agent "$cmd"
241 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
242 export HSMTOOL_MONITOR_DIR=
245 # The pdsh should die on its own when the monitor dies. Just
246 # in case, though, try to clean up to avoid any cruft.
247 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
248 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
249 export HSMTOOL_MONITOR_PDSH=
254 local facet=${1:-$SINGLEAGT}
255 # Use MOUNT2 by default if defined
256 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
258 local hsm_root=${4:-$(copytool_device $facet)}
260 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
262 local agent=$(facet_active_host $facet)
264 if $HSM_ARCHIVE_PURGE; then
265 echo "Purging archive on $agent"
266 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
269 echo "Starting copytool $facet on $agent"
270 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
271 error "mkdir '$hsm_root/$HSMTMP' failed"
272 # bandwidth is limited to 1MB/s so the copy time is known and
273 # independent of hardware
274 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
275 cmd+=" --hsm-root $hsm_root/$HSMTMP"
276 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
277 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
278 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
279 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
280 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
281 cmd+=" --bandwidth 1 $lustre_mntpnt"
283 # Redirect the standard output and error to a log file which
284 # can be uploaded to Maloo.
285 local prefix=$TESTLOG_PREFIX
286 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
287 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
289 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
290 if [[ $? != 0 ]]; then
291 [[ $HSMTOOL_NOERROR == true ]] ||
292 error "start copytool $facet on $agent failed"
293 echo "start copytool $facet on $agent failed"
299 get_copytool_event_log() {
300 local facet=${1:-$SINGLEAGT}
301 local agent=$(facet_active_host $facet)
303 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
304 error "Can't get event log: No monitor directory!"
306 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
307 error "Could not collect event log from $agent"
312 local agt_facet=$SINGLEAGT
313 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
314 local hsm_root=$(copytool_device $agt_facet)
316 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
323 kill_copytools $agt_hosts
324 wait_copytools $agt_hosts || error "copytools failed to stop"
326 # Clean all CDTs orphans requests from previous tests that
327 # would otherwise need to timeout to clear.
328 for ((i = 0; i < MDSCOUNT; i++)); do
330 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
331 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
333 # Skip already stopping or stopped CDTs.
334 [[ "${state[$i]}" =~ ^stop ]] && continue
336 do_facet $facet "$LCTL set_param $param=shutdown"
339 for ((i = 0; i < MDSCOUNT; i++)); do
340 # Only check and restore CDTs that we stopped in the first loop.
341 [[ "${state[$i]}" =~ ^stop ]] && continue
344 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
346 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
347 error "$facet CDT state is not stopped"
349 # Restore old CDT state.
350 do_facet $facet "$LCTL set_param $param=${state[$i]}"
353 for ((i = 0; i < MDSCOUNT; i++)); do
354 # Only check CDTs that we stopped in the first loop.
355 [[ "${state[$i]}" =~ ^stop ]] && continue
358 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
360 # Check that the old CDT state was restored.
361 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
362 20 || error "$facet CDT state is not '${state[$i]}'"
365 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
366 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
371 local agents=${1:-$(facet_active_host $SINGLEAGT)}
373 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
374 echo "Copytool is suspended on $agents"
377 copytool_continue() {
378 local agents=${1:-$(facet_active_host $SINGLEAGT)}
380 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
381 echo "Copytool is continued on $agents"
384 copytool_remove_backend() {
386 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
387 echo "Remove from backend: $fid = $be"
388 do_facet $SINGLEAGT rm -f $be
392 do_facet $SINGLEAGT \
393 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
394 --import $1 $2 $MOUNT" ||
395 error "import of $1 to $2 failed"
399 local file=$HSM_ARCHIVE/$1
400 do_facet $SINGLEAGT mkdir -p $(dirname $file)
401 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
402 file_creation_failure dd $file $?
406 local file=$HSM_ARCHIVE/$2
407 do_facet $SINGLEAGT mkdir -p $(dirname $file)
408 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
417 if [[ "$value" != "" ]]; then
420 for mdtno in $(seq 1 $MDSCOUNT); do
421 local idx=$(($mdtno - 1))
422 local facet=mds${mdtno}
423 # if $arg include -P option, run 1 set_param per MDT on the MGS
424 # else, run set_param on each MDT
425 [[ $arg = *"-P"* ]] && facet=mgs
426 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
427 [[ $? != 0 ]] && rc=1
437 for mdtno in $(seq 1 $MDSCOUNT); do
438 local idx=$(($mdtno - 1))
439 wait_result mds${mdtno} \
440 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
442 error "$key state is not '$target' on mds${mdtno}"
449 for mdtno in $(seq 1 $MDSCOUNT); do
450 local idx=$(($mdtno - 1))
451 local cl_user=$(do_facet mds${mdtno} $LCTL \
452 --device ${MDT[$idx]} \
453 changelog_register -n)
455 do_facet mds${mdtno} lctl set_param \
456 mdd.${MDT[$idx]}.changelog_mask="+hsm"
457 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
461 changelog_cleanup() {
463 for mdtno in $(seq 1 $MDSCOUNT); do
464 local idx=$(($mdtno - 1))
465 [[ -z ${CL_USERS[$idx]} ]] && continue
466 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
467 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
468 changelog_deregister ${CL_USERS[$idx]}
473 changelog_get_flags() {
478 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
483 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
491 mdts_set_param "$opt -n" "hsm.$param" "$value"
498 mdts_set_param "" hsm_control "$cmd"
499 mdts_check_param hsm_control "$target" 10
502 cdt_set_sanity_policy() {
503 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
506 mdts_set_param "" hsm.policy "+NRA"
507 mdts_set_param "" hsm.policy "-NBR"
508 CDT_POLICY_HAD_CHANGED=
513 mdts_set_param "" hsm.policy "+NRA"
514 CDT_POLICY_HAD_CHANGED=true
517 cdt_clear_no_retry() {
518 mdts_set_param "" hsm.policy "-NRA"
519 CDT_POLICY_HAD_CHANGED=true
522 cdt_set_non_blocking_restore() {
523 mdts_set_param "" hsm.policy "+NBR"
524 CDT_POLICY_HAD_CHANGED=true
527 cdt_clear_non_blocking_restore() {
528 mdts_set_param "" hsm.policy "-NBR"
529 CDT_POLICY_HAD_CHANGED=true
532 cdt_clear_mount_state() {
533 mdts_set_param "-P -d" hsm_control ""
536 cdt_set_mount_state() {
537 mdts_set_param "-P" hsm_control "$1"
538 # set_param -P is asynchronous operation and could race with set_param.
539 # In such case configs could be retrieved and applied at mgc after
540 # set_param -P completion. Sleep here to avoid race with set_param.
541 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
542 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
543 # and 10 seconds to retrieve config from server.
548 mdts_check_param hsm_control "$1" 20
552 set_test_state disabled disabled
556 set_test_state enabled enabled
560 set_test_state shutdown stopped
564 set_test_state purge enabled
570 cdt_set_sanity_policy
574 local client_count=$1
575 if [[ $CLIENTCOUNT -lt $client_count ]]; then
576 skip "Need $client_count or more clients, have $CLIENTCOUNT"
583 $LFS path2fid $1 | tr -d '[]'
584 return ${PIPESTATUS[0]}
592 if [[ $u == "user" ]]; then
593 st=$($RUNAS $LFS hsm_state $f)
596 st=$($LFS hsm_state $f)
599 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
601 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
605 get_hsm_archive_id() {
608 st=$($LFS hsm_state $f)
609 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
611 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
620 local st=$(get_hsm_flags $f)
621 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
624 check_hsm_flags_user() {
628 local st=$(get_hsm_flags $f user)
629 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
632 file_creation_failure() {
637 df $MOUNT $MOUNT2 >&2
638 error "cannot create $f with $cmd, status=$err"
650 if [[ "$3" != 1 ]]; then
654 cp $1 $f || file_creation_failure cp $f $?
656 path2fid $f || error "cannot get fid on $f"
660 local file2=${1/$DIR/$DIR2}
661 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
662 file_creation_failure dd $file2 $?
664 path2fid $1 || error "cannot get fid on $1"
668 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
669 file_creation_failure dd $1 $?
670 path2fid $1 || error "cannot get fid on $1"
673 cleanup_large_files() {
674 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
676 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
679 check_enough_free_space() {
682 local need=$((nb * unit /1024))
683 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
684 (( $need >= $free )) && return 1
688 make_custom_file_for_progress() {
689 local file2=${1/$DIR/$DIR2}
690 local fsize=${2:-"39"}
691 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
694 [[ $fsize -gt 0 ]] || error "Invalid file size"
695 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
698 check_enough_free_space $fsize $blksz || return $?
699 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
700 file_creation_failure dd $file2 $?
701 path2fid $1 || error "cannot get fid on $1"
707 wait_update --verbose $(facet_active_host $facet) "$@"
710 wait_request_state() {
714 # 4th arg (mdt index) is optional
716 local mds=mds$(($mdtidx + 1))
718 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
719 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
721 wait_result $mds "$cmd" $state 200 ||
722 error "request on $fid is not $state on $mds"
725 get_request_state() {
729 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
730 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
733 get_request_count() {
737 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
738 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
745 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
746 [[ -n $fid ]] && cmd+=" | grep '$fid'"
747 cmd+=" | egrep 'WAITING|STARTED'"
749 wait_result $SINGLEMDS "$cmd" "" $timeout ||
750 error "requests did not complete"
753 wait_for_grace_delay() {
754 local val=$(get_hsm_param grace_delay)
758 wait_for_loop_period() {
759 local val=$(get_hsm_param loop_period)
766 # python2.6 in EL6 includes an internal json module
767 local json_parser='import json; import fileinput;'
768 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
769 json_parser+='json.loads([line for line in '
770 json_parser+='fileinput.input()][0]).items()])'
772 echo $raw_event | python -c "$json_parser"
775 get_agent_by_uuid_mdt() {
778 local mds=mds$(($mdtidx + 1))
779 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
783 check_agent_registered_by_mdt() {
786 local mds=mds$(($mdtidx + 1))
787 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
788 if [[ ! -z "$agent" ]]; then
789 echo "found agent $agent on $mds"
791 error "uuid $uuid not found in agent list on $mds"
795 check_agent_unregistered_by_mdt() {
798 local mds=mds$(($mdtidx + 1))
799 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
800 if [[ -z "$agent" ]]; then
801 echo "uuid not found in agent list on $mds"
803 error "uuid found in agent list on $mds: $agent"
807 check_agent_registered() {
810 for mdsno in $(seq 1 $MDSCOUNT); do
811 check_agent_registered_by_mdt $uuid $((mdsno - 1))
815 check_agent_unregistered() {
818 for mdsno in $(seq 1 $MDSCOUNT); do
819 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
824 local agent=${1:-$(facet_active_host $SINGLEAGT)}
826 # Lustre mount-point is mandatory and last parameter on
828 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
830 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
832 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
838 # populate MDT device array
841 # cleanup from previous bad setup
844 # for recovery tests, coordinator needs to be started at mount
846 # the lustre conf must be without hsm on (like for sanity.sh)
847 echo "Set HSM on and start"
848 cdt_set_mount_state enabled
849 cdt_check_state enabled
851 echo "Set sanity-hsm HSM policy"
852 cdt_set_sanity_policy
854 # finished requests are quickly removed from list
855 set_hsm_param grace_delay 10
861 local f=$DIR/$tdir/$tfile
865 check_hsm_flags_user $f "0x00000000"
867 $RUNAS $LFS hsm_set --norelease $f ||
868 error "user could not change hsm flags"
869 check_hsm_flags_user $f "0x00000010"
871 $RUNAS $LFS hsm_clear --norelease $f ||
872 error "user could not clear hsm flags"
873 check_hsm_flags_user $f "0x00000000"
875 # User could not change those flags...
876 $RUNAS $LFS hsm_set --exists $f &&
877 error "user should not set this flag"
878 check_hsm_flags_user $f "0x00000000"
881 $LFS hsm_set --exists $f ||
882 error "root could not change hsm flags"
883 check_hsm_flags_user $f "0x00000001"
885 $LFS hsm_clear --exists $f ||
886 error "root could not clear hsm state"
887 check_hsm_flags_user $f "0x00000000"
890 run_test 1 "lfs hsm flags root/non-root access"
894 local f=$DIR/$tdir/$tfile
895 local fid=$(make_small $f)
899 $LFS hsm_archive $f || error "could not archive file"
900 wait_request_state $fid ARCHIVE SUCCEED
902 # Release and check states
903 $LFS hsm_release $f || error "could not release file"
904 echo -n "Verifying released state: "
905 check_hsm_flags $f "0x0000000d"
907 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
911 run_test 1a "mmap & cat a HSM released file"
915 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
916 error "failed to set default stripe"
917 local f=$DIR/$tdir/$tfile
920 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
921 error "failed to create file"
922 local fid=$(path2fid $f)
927 $LFS hsm_archive $f || error "could not archive file"
928 wait_request_state $fid ARCHIVE SUCCEED
931 $LFS hsm_release $f || error "could not release file"
932 echo "verify released state: "
933 check_hsm_flags $f "0x0000000d" && echo "pass"
936 $LFS hsm_restore $f || error "could not restore file"
937 wait_request_state $fid RESTORE SUCCEED
938 echo "verify restored state: "
939 check_hsm_flags $f "0x00000009" && echo "pass"
943 run_test 1b "Archive, Release & Restore composite file"
947 local f=$DIR/$tdir/$tfile
949 # New files are not dirty
950 check_hsm_flags $f "0x00000000"
952 # For test, we simulate an archived file.
953 $LFS hsm_set --exists $f || error "user could not change hsm flags"
954 check_hsm_flags $f "0x00000001"
956 # chmod do not put the file dirty
957 chmod 600 $f || error "could not chmod test file"
958 check_hsm_flags $f "0x00000001"
960 # chown do not put the file dirty
961 chown $RUNAS_ID $f || error "could not chown test file"
962 check_hsm_flags $f "0x00000001"
964 # truncate put the file dirty
965 $TRUNCATE $f 1 || error "could not truncate test file"
966 check_hsm_flags $f "0x00000003"
968 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
969 check_hsm_flags $f "0x00000001"
971 run_test 2 "Check file dirtyness when doing setattr"
977 # New files are not dirty
979 check_hsm_flags $f "0x00000000"
981 # For test, we simulate an archived file.
982 $LFS hsm_set --exists $f ||
983 error "user could not change hsm flags"
984 check_hsm_flags $f "0x00000001"
986 # Reading a file, does not set dirty
987 cat $f > /dev/null || error "could not read file"
988 check_hsm_flags $f "0x00000001"
990 # Open for write without modifying data, does not set dirty
991 openfile -f O_WRONLY $f || error "could not open test file"
992 check_hsm_flags $f "0x00000001"
994 # Append to a file sets it dirty
995 cp -p /etc/passwd $f.append || error "could not create file"
996 $LFS hsm_set --exists $f.append ||
997 error "user could not change hsm flags"
998 dd if=/etc/passwd of=$f.append bs=1 count=3\
999 conv=notrunc oflag=append status=noxfer ||
1000 file_creation_failure dd $f.append $?
1001 check_hsm_flags $f.append "0x00000003"
1003 # Modify a file sets it dirty
1004 cp -p /etc/passwd $f.modify || error "could not create file"
1005 $LFS hsm_set --exists $f.modify ||
1006 error "user could not change hsm flags"
1007 dd if=/dev/zero of=$f.modify bs=1 count=3\
1008 conv=notrunc status=noxfer ||
1009 file_creation_failure dd $f.modify $?
1010 check_hsm_flags $f.modify "0x00000003"
1012 # Open O_TRUNC sets dirty
1013 cp -p /etc/passwd $f.trunc || error "could not create file"
1014 $LFS hsm_set --exists $f.trunc ||
1015 error "user could not change hsm flags"
1016 cp /etc/group $f.trunc || error "could not override a file"
1017 check_hsm_flags $f.trunc "0x00000003"
1019 # Mmapped a file sets dirty
1020 cp -p /etc/passwd $f.mmap || error "could not create file"
1021 $LFS hsm_set --exists $f.mmap ||
1022 error "user could not change hsm flags"
1023 multiop $f.mmap OSMWUc || error "could not mmap a file"
1024 check_hsm_flags $f.mmap "0x00000003"
1026 run_test 3 "Check file dirtyness when opening for write"
1030 local f=$DIR/$tdir/$tfile
1031 local fid=$(make_small $f)
1034 local st=$(get_request_state $fid CANCEL)
1035 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1037 run_test 4 "Useless cancel must not be registered"
1040 # test needs a running copytool
1044 local f=$DIR/$tdir/$tfile
1045 local fid=$(copy_file /etc/passwd $f)
1047 wait_request_state $fid ARCHIVE SUCCEED
1049 check_hsm_flags $f "0x00000009"
1053 run_test 8 "Test default archive number"
1056 # we do not use the default one to be sure
1057 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1059 copytool_setup $SINGLEAGT $MOUNT $new_an
1061 # give time for CT to register with MDTs
1062 sleep $(($MDSCOUNT*2))
1063 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1064 check_agent_registered $uuid
1067 local f=$DIR/$tdir/$tfile
1068 local fid=$(copy_file /etc/passwd $f)
1069 $LFS hsm_archive --archive $new_an $f
1070 wait_request_state $fid ARCHIVE SUCCEED
1072 check_hsm_flags $f "0x00000009"
1076 run_test 9 "Use of explicit archive number, with dedicated copytool"
1079 needclients 3 || return 0
1085 copytool_cleanup $(comma_list $(agts_nodes))
1087 # start all of the copytools
1088 for n in $(seq $AGTCOUNT); do
1089 copytool_setup agt$n
1092 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1095 for n in $(seq $AGTCOUNT); do
1096 file=$DIR/$tdir/$tfile.$n
1097 fid=$(make_small $file)
1099 $LFS hsm_archive $file || error "could not archive file $file"
1100 wait_request_state $fid ARCHIVE SUCCEED
1101 check_hsm_flags $file "0x00000009"
1105 copytool_cleanup $(comma_list $(agts_nodes))
1107 run_test 9a "Multiple remote agents"
1110 # test needs a running copytool
1113 mkdir -p $DIR/$tdir/d1
1114 local f=$DIR/$tdir/$tfile
1115 local fid=$(copy_file /etc/hosts $f)
1116 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1117 error "hsm_archive failed"
1118 wait_request_state $fid ARCHIVE SUCCEED
1120 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1121 error "fid $fid not in archive $HSM_ARCHIVE"
1122 echo "Verifying content"
1123 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1124 echo "Verifying hsm state "
1125 check_hsm_flags $f "0x00000009"
1127 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1128 local st=$(get_hsm_archive_id $f)
1129 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1130 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1135 run_test 10a "Archive a file"
1138 # test needs a running copytool
1142 local f=$DIR/$tdir/$tfile
1143 local fid=$(copy_file /etc/hosts $f)
1144 $LFS hsm_archive $f || error "archive request failed"
1145 wait_request_state $fid ARCHIVE SUCCEED
1147 $LFS hsm_archive $f || error "archive of non dirty file failed"
1148 local cnt=$(get_request_count $fid ARCHIVE)
1149 [[ "$cnt" == "1" ]] ||
1150 error "archive of non dirty file must not make a request"
1154 run_test 10b "Archive of non dirty file must work without doing request"
1157 # test needs a running copytool
1161 local f=$DIR/$tdir/$tfile
1162 local fid=$(copy_file /etc/hosts $f)
1163 $LFS hsm_set --noarchive $f
1164 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1168 run_test 10c "Check forbidden archive"
1171 # test needs a running copytool
1175 local f=$DIR/$tdir/$tfile
1176 local fid=$(copy_file /etc/hosts $f)
1177 $LFS hsm_archive $f || error "cannot archive $f"
1178 wait_request_state $fid ARCHIVE SUCCEED
1180 local ar=$(get_hsm_archive_id $f)
1181 local dflt=$(get_hsm_param default_archive_id)
1182 [[ $ar == $dflt ]] ||
1183 error "archived file is not on default archive: $ar != $dflt"
1187 run_test 10d "Archive a file on the default archive id"
1191 copy2archive /etc/hosts $tdir/$tfile
1192 local f=$DIR/$tdir/$tfile
1194 import_file $tdir/$tfile $f
1195 echo -n "Verifying released state: "
1196 check_hsm_flags $f "0x0000000d"
1198 local LSZ=$(stat -c "%s" $f)
1199 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1201 echo "Verifying imported size $LSZ=$ASZ"
1202 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1203 echo -n "Verifying released pattern: "
1204 local PTRN=$($GETSTRIPE -L $f)
1206 [[ $PTRN == 80000001 ]] || error "Is not released"
1207 local fid=$(path2fid $f)
1208 echo "Verifying new fid $fid in archive"
1210 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1211 error "fid $fid not in archive $HSM_ARCHIVE"
1213 run_test 11a "Import a file"
1216 # test needs a running copytool
1220 local f=$DIR/$tdir/$tfile
1221 local fid=$(copy_file /etc/hosts $f)
1222 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1223 error "hsm_archive failed"
1224 wait_request_state $fid ARCHIVE SUCCEED
1226 local FILE_HASH=$(md5sum $f)
1231 echo "$FILE_HASH" | md5sum -c
1233 [[ $? -eq 0 ]] || error "Restored file differs"
1237 run_test 11b "Import a deleted file using its FID"
1240 # test needs a running copytool
1244 copy2archive /etc/hosts $tdir/$tfile
1246 local f=$DIR/$tdir/$tfile
1247 import_file $tdir/$tfile $f
1248 local f2=$DIR2/$tdir/$tfile
1249 echo "Verifying released state: "
1250 check_hsm_flags $f2 "0x0000000d"
1252 local fid=$(path2fid $f2)
1253 $LFS hsm_restore $f2
1254 wait_request_state $fid RESTORE SUCCEED
1256 echo "Verifying file state: "
1257 check_hsm_flags $f2 "0x00000009"
1259 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1261 [[ $? -eq 0 ]] || error "Restored file differs"
1265 run_test 12a "Restore an imported file explicitly"
1268 # test needs a running copytool
1272 copy2archive /etc/hosts $tdir/$tfile
1274 local f=$DIR/$tdir/$tfile
1275 import_file $tdir/$tfile $f
1276 echo "Verifying released state: "
1277 check_hsm_flags $f "0x0000000d"
1279 cat $f > /dev/null || error "File read failed"
1281 echo "Verifying file state after restore: "
1282 check_hsm_flags $f "0x00000009"
1284 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1286 [[ $? -eq 0 ]] || error "Restored file differs"
1290 run_test 12b "Restore an imported file implicitly"
1293 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1295 # test needs a running copytool
1299 local f=$DIR/$tdir/$tfile
1300 $LFS setstripe -c 2 $f
1302 fid=$(make_custom_file_for_progress $f 5)
1303 [ $? != 0 ] && skip "not enough free space" && return
1305 local FILE_CRC=$(md5sum $f)
1307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1308 wait_request_state $fid ARCHIVE SUCCEED
1309 $LFS hsm_release $f || error "release $f failed"
1311 echo "$FILE_CRC" | md5sum -c
1313 [[ $? -eq 0 ]] || error "Restored file differs"
1317 run_test 12c "Restore a file with stripe of 2"
1320 # test needs a running copytool
1325 local f=$DIR/$tdir/$tfile
1326 local fid=$(copy_file /etc/hosts $f)
1327 $LFS hsm_restore $f || error "restore of non archived file failed"
1328 local cnt=$(get_request_count $fid RESTORE)
1329 [[ "$cnt" == "0" ]] ||
1330 error "restore non archived must not make a request"
1331 $LFS hsm_archive $f ||
1332 error "archive request failed"
1333 wait_request_state $fid ARCHIVE SUCCEED
1334 $LFS hsm_restore $f ||
1335 error "restore of non released file failed"
1336 local cnt=$(get_request_count $fid RESTORE)
1337 [[ "$cnt" == "0" ]] ||
1338 error "restore a non dirty file must not make a request"
1342 run_test 12d "Restore of a non archived, non released file must work"\
1343 " without doing request"
1346 # test needs a running copytool
1349 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1350 local f=$DIR/$tdir/$tfile
1351 local fid=$(copy_file /etc/hosts $f)
1352 $LFS hsm_archive $f || error "archive request failed"
1353 wait_request_state $fid ARCHIVE SUCCEED
1356 cat /etc/hosts >> $f
1360 $LFS hsm_restore $f && error "restore a dirty file must fail"
1364 run_test 12e "Check forbidden restore"
1367 # test needs a running copytool
1371 local f=$DIR/$tdir/$tfile
1372 local fid=$(copy_file /etc/hosts $f)
1374 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1375 wait_request_state $fid ARCHIVE SUCCEED
1376 $LFS hsm_release $f || error "release of $f failed"
1378 wait_request_state $fid RESTORE SUCCEED
1380 echo -n "Verifying file state: "
1381 check_hsm_flags $f "0x00000009"
1383 diff -q /etc/hosts $f
1385 [[ $? -eq 0 ]] || error "Restored file differs"
1389 run_test 12f "Restore a released file explicitly"
1392 # test needs a running copytool
1396 local f=$DIR/$tdir/$tfile
1397 local fid=$(copy_file /etc/hosts $f)
1399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1400 wait_request_state $fid ARCHIVE SUCCEED
1401 $LFS hsm_release $f || error "release of $f failed"
1403 diff -q /etc/hosts $f
1406 # we check we had a restore done
1407 wait_request_state $fid RESTORE SUCCEED
1409 [[ $st -eq 0 ]] || error "Restored file differs"
1413 run_test 12g "Restore a released file implicitly"
1416 needclients 2 || return 0
1418 # test needs a running copytool
1422 local f=$DIR/$tdir/$tfile
1423 local fid=$(copy_file /etc/hosts $f)
1425 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1426 wait_request_state $fid ARCHIVE SUCCEED
1427 $LFS hsm_release $f || error "release of $f failed"
1429 do_node $CLIENT2 diff -q /etc/hosts $f
1432 # we check we had a restore done
1433 wait_request_state $fid RESTORE SUCCEED
1435 [[ $st -eq 0 ]] || error "Restored file differs"
1439 run_test 12h "Restore a released file implicitly from a second node"
1442 # test needs a running copytool
1446 local f=$DIR/$tdir/$tfile
1447 local fid=$(copy_file /etc/passwd $f)
1448 $LFS hsm_archive $f || error "archive of $f failed"
1449 wait_request_state $fid ARCHIVE SUCCEED
1451 $LFS hsm_release $f || error "release of $f failed"
1455 [[ $? -eq 0 ]] || error "Restored file differs"
1459 run_test 12m "Archive/release/implicit restore"
1462 # test needs a running copytool
1466 copy2archive /etc/hosts $tdir/$tfile
1468 local f=$DIR/$tdir/$tfile
1469 import_file $tdir/$tfile $f
1471 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1472 error "Restored file differs"
1474 $LFS hsm_release $f || error "release of $f failed"
1478 run_test 12n "Import/implicit restore/release"
1481 # test needs a running copytool
1485 local f=$DIR/$tdir/$tfile
1486 local fid=$(copy_file /etc/hosts $f)
1488 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1489 wait_request_state $fid ARCHIVE SUCCEED
1490 $LFS hsm_release $f || error "release of $f failed"
1492 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1493 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1495 # set no retry action mode
1498 diff -q /etc/hosts $f
1501 # we check we had a restore failure
1502 wait_request_state $fid RESTORE FAILED
1504 [[ $st -eq 0 ]] && error "Restore must fail"
1506 # remove no retry action mode
1509 # check file is still released
1510 check_hsm_flags $f "0x0000000d"
1512 # retry w/o failure injection
1513 do_facet $SINGLEMDS lctl set_param fail_loc=0
1515 # to be sure previous RESTORE result is gone
1517 wait_for_grace_delay
1519 diff -q /etc/hosts $f
1522 # we check we had a restore done
1523 wait_request_state $fid RESTORE SUCCEED
1525 [[ $st -eq 0 ]] || error "Restored file differs"
1529 run_test 12o "Layout-swap failure during Restore leaves file released"
1532 # test needs a running copytool
1536 local f=$DIR/$tdir/$tfile
1537 local fid=$(copy_file /etc/hosts $f)
1539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1540 wait_request_state $fid ARCHIVE SUCCEED
1541 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1542 $LFS hsm_release $f || error "cannot release $f"
1543 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1544 $LFS hsm_release $f || error "cannot release $f"
1545 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1549 run_test 12p "implicit restore of a file on copytool mount point"
1551 cleanup_test_12q() {
1553 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1554 error "cannot umount $MOUNT3 on $SINGLEAGT"
1558 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1559 skip "need MDS version at least 2.7.58" && return 0
1561 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1562 error "cannot mount $MOUNT3 on $SINGLEAGT"
1564 trap cleanup_test_12q EXIT
1566 # test needs a running copytool
1567 copytool_setup $SINGLEAGT $MOUNT3
1570 local f=$DIR/$tdir/$tfile
1571 local f2=$DIR2/$tdir/$tfile
1572 local fid=$(make_small $f)
1573 local orig_size=$(stat -c "%s" $f)
1575 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1576 wait_request_state $fid ARCHIVE SUCCEED
1578 $LFS hsm_release $f || error "could not release file"
1579 check_hsm_flags $f "0x0000000d"
1582 wait_copytools || error "copytool failed to stop"
1584 cat $f > /dev/null &
1586 # wait a bit to allow implicit restore request to be handled.
1587 # if not, next stat would also block on layout-lock.
1590 local size=$(stat -c "%s" $f2)
1591 [ $size -eq $orig_size ] ||
1592 error "$f2: wrong size after archive: $size != $orig_size"
1594 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1598 size=$(stat -c "%s" $f)
1599 [ $size -eq $orig_size ] ||
1600 error "$f: wrong size after restore: $size != $orig_size"
1602 size=$(stat -c "%s" $f2)
1603 [ $size -eq $orig_size ] ||
1604 error "$f2: wrong size after restore: $size != $orig_size"
1608 size=$(stat -c "%s" $f)
1610 error "$f: wrong size after overwrite: $size != 0"
1612 size=$(stat -c "%s" $f2)
1614 error "$f2: wrong size after overwrite: $size != 0"
1617 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1618 error "cannot umount $MOUNT3 on $SINGLEAGT"
1620 run_test 12q "file attributes are refreshed after restore"
1623 # test needs a running copytool
1626 local ARC_SUBDIR="import.orig"
1630 # populate directory to be imported
1631 for d in $(seq 1 10); do
1632 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1633 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1634 for f in $(seq 1 10); do
1635 CURR_FILE="$CURR_DIR/$tfile.$f"
1636 # write file-specific data
1637 do_facet $SINGLEAGT \
1638 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1639 "file=$CURR_FILE > $CURR_FILE"
1643 import_file "$ARC_SUBDIR" $DIR/$tdir
1644 # diff lustre content and origin (triggers file restoration)
1645 # there must be 10x10 identical files, and no difference
1646 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1647 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1648 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1649 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1651 [ $cnt_diff -eq 0 ] ||
1652 error "$cnt_diff imported files differ from read data"
1653 [ $cnt_ok -eq 100 ] ||
1654 error "not enough identical files ($cnt_ok != 100)"
1658 run_test 13 "Recursively import and restore a directory"
1661 # test needs a running copytool
1666 local f=$DIR/$tdir/$tfile
1667 local fid=$(make_small $f)
1668 local sum=$(md5sum $f | awk '{print $1}')
1669 $LFS hsm_archive $f || error "could not archive file"
1670 wait_request_state $fid ARCHIVE SUCCEED
1674 # create released file (simulate llapi_hsm_import call)
1676 local fid2=$(path2fid $f)
1677 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1678 $LFS hsm_release $f || error "could not release file"
1680 # rebind the archive to the newly created file
1681 echo "rebind $fid to $fid2"
1683 do_facet $SINGLEAGT \
1684 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1685 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1687 # restore file and compare md5sum
1688 local sum2=$(md5sum $f | awk '{print $1}')
1690 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1694 run_test 14 "Rebind archived file to a new fid"
1697 # test needs a running copytool
1702 local f=$DIR/$tdir/$tfile
1704 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1708 for i in $(seq 1 $count); do
1709 fids[$i]=$(make_small $f.$i)
1710 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1711 $LFS hsm_archive $f.$i || error "could not archive file"
1713 wait_all_done $(($count*60))
1717 for i in $(seq 1 $count); do
1720 local fid2=$(path2fid $f.$i)
1721 # add the rebind operation to the list
1722 echo ${fids[$i]} $fid2 >> $tmpfile
1724 # set it released (simulate llapi_hsm_import call)
1725 $LFS hsm_set --archived --exists $f.$i ||
1726 error "could not force hsm flags"
1727 $LFS hsm_release $f.$i || error "could not release file"
1729 nl=$(wc -l < $tmpfile)
1730 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1732 echo "rebind list of files"
1733 do_facet $SINGLEAGT \
1734 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1735 --rebind $tmpfile $DIR" || error "could not rebind file list"
1737 # restore files and compare md5sum
1738 for i in $(seq 1 $count); do
1739 local sum2=$(md5sum $f.$i | awk '{print $1}')
1740 [[ $sum2 == ${sums[$i]} ]] ||
1741 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1747 run_test 15 "Rebind a list of files"
1750 # test needs a running copytool
1754 # create a known size file so we can verify transfer speed
1757 dd if=/dev/zero of=$ref bs=1M count=20
1760 local f=$DIR/$tdir/$tfile
1761 local fid=$(copy_file $ref $f)
1763 local start=$(date +%s)
1765 wait_request_state $fid ARCHIVE SUCCEED
1766 local end=$(date +%s)
1767 # Add 1 to account for rounding errors between start and end (LU-8155)
1768 local duration=$((end - start + 1))
1770 [[ $duration -ge $((goal - 1)) ]] ||
1771 error "Transfer is too fast $duration < $goal"
1775 run_test 16 "Test CT bandwith control option"
1780 local f=$DIR/$tdir/$tfile
1781 touch $f || error "touch $f failed"
1783 # Could not release a non-archived file
1784 $LFS hsm_release $f && error "release should not succeed"
1786 # For following tests, we must test them with HS_ARCHIVED set
1787 $LFS hsm_set --exists --archived $f || error "could not add flag"
1789 # Could not release a file if no-release is set
1790 $LFS hsm_set --norelease $f || error "could not add flag"
1791 $LFS hsm_release $f && error "release should not succeed"
1792 $LFS hsm_clear --norelease $f || error "could not remove flag"
1794 # Could not release a file if lost
1795 $LFS hsm_set --lost $f || error "could not add flag"
1796 $LFS hsm_release $f && error "release should not succeed"
1797 $LFS hsm_clear --lost $f || error "could not remove flag"
1799 # Could not release a file if dirty
1800 $LFS hsm_set --dirty $f || error "could not add flag"
1801 $LFS hsm_release $f && error "release should not succeed"
1802 $LFS hsm_clear --dirty $f || error "could not remove flag"
1804 run_test 20 "Release is not permitted"
1807 # test needs a running copytool
1811 local f=$DIR/$tdir/test_release
1813 # Create a file and check its states
1814 local fid=$(make_small $f)
1815 check_hsm_flags $f "0x00000000"
1817 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1818 # used until file is flushed to disk
1819 if [ $(facet_fstype ost1) == "zfs" ]; then
1820 # this causes an OST_SYNC rpc to be sent
1821 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1822 # clear locks to reread file data
1823 cancel_lru_locks osc
1826 local orig_size=$(stat -c "%s" $f)
1827 local orig_blocks=$(stat -c "%b" $f)
1829 start_full_debug_logging
1831 $LFS hsm_archive $f || error "could not archive file"
1832 wait_request_state $fid ARCHIVE SUCCEED
1834 local blocks=$(stat -c "%b" $f)
1835 [ $blocks -eq $orig_blocks ] ||
1836 error "$f: wrong block number after archive: " \
1837 "$blocks != $orig_blocks"
1838 local size=$(stat -c "%s" $f)
1839 [ $size -eq $orig_size ] ||
1840 error "$f: wrong size after archive: $size != $orig_size"
1842 # Release and check states
1843 $LFS hsm_release $f || error "could not release file"
1844 check_hsm_flags $f "0x0000000d"
1846 blocks=$(stat -c "%b" $f)
1847 [ $blocks -gt 5 ] &&
1848 error "$f: too many blocks after release: $blocks > 5"
1849 size=$(stat -c "%s" $f)
1850 [ $size -ne $orig_size ] &&
1851 error "$f: wrong size after release: $size != $orig_size"
1853 # Check we can release an file without stripe info
1857 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"
1865 # Release again a file that is already released is OK
1866 $LFS hsm_release $f || fail "second release should succeed"
1867 check_hsm_flags $f "0x0000000d"
1869 stop_full_debug_logging
1873 run_test 21 "Simple release tests"
1876 # test needs a running copytool
1881 local f=$DIR/$tdir/test_release
1882 local swap=$DIR/$tdir/test_swap
1884 # Create a file and check its states
1885 local fid=$(make_small $f)
1886 check_hsm_flags $f "0x00000000"
1888 $LFS hsm_archive $f || error "could not archive file"
1889 wait_request_state $fid ARCHIVE SUCCEED
1891 # Release and check states
1892 $LFS hsm_release $f || error "could not release file"
1893 check_hsm_flags $f "0x0000000d"
1896 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1901 run_test 22 "Could not swap a release file"
1904 # test needs a running copytool
1909 local f=$DIR/$tdir/test_mtime
1911 # Create a file and check its states
1912 local fid=$(make_small $f)
1913 check_hsm_flags $f "0x00000000"
1915 $LFS hsm_archive $f || error "could not archive file"
1916 wait_request_state $fid ARCHIVE SUCCEED
1918 # Set modification time in the past
1919 touch -m -a -d @978261179 $f
1921 # Release and check states
1922 $LFS hsm_release $f || error "could not release file"
1923 check_hsm_flags $f "0x0000000d"
1925 local MTIME=$(stat -c "%Y" $f)
1926 local ATIME=$(stat -c "%X" $f)
1927 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1928 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1932 run_test 23 "Release does not change a/mtime (utime)"
1935 local file=$DIR/$tdir/$tfile
1944 # test needs a running copytool
1949 fid=$(make_small $file)
1951 # Create a file and check its states
1952 check_hsm_flags $file "0x00000000"
1954 # Ensure atime is less than mtime and ctime.
1958 atime0=$(stat -c "%X" $file)
1959 mtime0=$(stat -c "%Y" $file)
1960 ctime0=$(stat -c "%Z" $file)
1962 [ $atime0 -lt $mtime0 ] ||
1963 error "atime $atime0 is not less than mtime $mtime0"
1965 [ $atime0 -lt $ctime0 ] ||
1966 error "atime $atime0 is not less than ctime $ctime0"
1968 # Archive should not change any timestamps.
1969 $LFS hsm_archive $file || error "cannot archive '$file'"
1970 wait_request_state $fid ARCHIVE SUCCEED
1972 atime1=$(stat -c "%X" $file)
1973 mtime1=$(stat -c "%Y" $file)
1974 ctime1=$(stat -c "%Z" $file)
1976 [ $atime0 -eq $atime1 ] ||
1977 error "archive changed atime from $atime0 to $atime1"
1979 [ $mtime0 -eq $mtime1 ] ||
1980 error "archive changed mtime from $mtime0 to $mtime1"
1982 [ $ctime0 -eq $ctime1 ] ||
1983 error "archive changed ctime from $ctime0 to $ctime1"
1985 # Release should not change any timestamps.
1986 $LFS hsm_release $file || error "cannot release '$file'"
1987 check_hsm_flags $file "0x0000000d"
1989 atime1=$(stat -c "%X" $file)
1990 mtime1=$(stat -c "%Y" $file)
1991 ctime1=$(stat -c "%Z" $file)
1993 [ $atime0 -eq $atime1 ] ||
1994 error "release changed atime from $atime0 to $atime1"
1996 [ $mtime0 -eq $mtime1 ] ||
1997 error "release changed mtime from $mtime0 to $mtime1"
1999 [ $ctime0 -eq $ctime1 ] ||
2000 error "release changed ctime from $ctime0 to $ctime1"
2002 # Restore should not change any timestamps.
2003 $LFS hsm_restore $file
2004 wait_request_state $fid RESTORE SUCCEED
2006 atime1=$(stat -c "%X" $file)
2007 mtime1=$(stat -c "%Y" $file)
2008 ctime1=$(stat -c "%Z" $file)
2010 [ $atime0 -eq $atime1 ] ||
2011 error "restore changed atime from $atime0 to $atime1"
2013 [ $mtime0 -eq $mtime1 ] ||
2014 error "restore changed mtime from $mtime0 to $mtime1"
2016 [ $ctime0 -eq $ctime1 ] ||
2017 error "restore changed ctime from $ctime0 to $ctime1"
2021 # Once more, after unmount and mount.
2022 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2023 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2025 atime1=$(stat -c "%X" $file)
2026 mtime1=$(stat -c "%Y" $file)
2027 ctime1=$(stat -c "%Z" $file)
2029 [ $atime0 -eq $atime1 ] ||
2030 error "remount changed atime from $atime0 to $atime1"
2032 [ $mtime0 -eq $mtime1 ] ||
2033 error "remount changed mtime from $mtime0 to $mtime1"
2035 [ $ctime0 -eq $ctime1 ] ||
2036 error "remount changed ctime from $ctime0 to $ctime1"
2038 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2041 local file=$DIR/$tdir/$tfile
2047 # Test needs a running copytool.
2051 # Check that root can do HSM actions on a regular user's file.
2053 fid=$(make_small $file)
2054 sum0=$(md5sum $file)
2056 chown $RUNAS_ID:$RUNAS_GID $file ||
2057 error "cannot chown '$file' to '$RUNAS_ID'"
2059 chmod ugo-w $DIR/$tdir ||
2060 error "cannot chmod '$DIR/$tdir'"
2062 $LFS hsm_archive $file
2063 wait_request_state $fid ARCHIVE SUCCEED
2065 $LFS hsm_release $file
2066 check_hsm_flags $file "0x0000000d"
2068 $LFS hsm_restore $file
2069 wait_request_state $fid RESTORE SUCCEED
2071 # Check that ordinary user can get HSM state.
2072 $RUNAS $LFS hsm_state $file ||
2073 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2075 $LFS hsm_release $file
2076 check_hsm_flags $file "0x0000000d"
2078 # Check that ordinary user can accessed released file.
2079 sum1=$($RUNAS md5sum $file) ||
2080 error "user '$RUNAS_ID' cannot read '$file'"
2082 [ "$sum0" == "$sum1" ] ||
2083 error "md5sum mismatch for '$file'"
2087 run_test 24b "root can archive, release, and restore user files"
2089 cleanup_test_24c() {
2091 set_hsm_param user_request_mask RESTORE
2092 set_hsm_param group_request_mask RESTORE
2093 set_hsm_param other_request_mask RESTORE
2097 local file=$DIR/$tdir/$tfile
2098 local action=archive
2103 # test needs a running copytool
2108 # Save the default masks and check that cleanup_24c will
2109 # restore the request masks correctly.
2110 user_save=$(get_hsm_param user_request_mask)
2111 group_save=$(get_hsm_param group_request_mask)
2112 other_save=$(get_hsm_param other_request_mask)
2114 [ "$user_save" == RESTORE ] ||
2115 error "user_request_mask is '$user_save' expected 'RESTORE'"
2116 [ "$group_save" == RESTORE ] ||
2117 error "group_request_mask is '$group_save' expected 'RESTORE'"
2118 [ "$other_save" == RESTORE ] ||
2119 error "other_request_mask is '$other_save' expected 'RESTORE'"
2121 trap cleanup_test_24c EXIT
2126 chown $RUNAS_ID:nobody $file ||
2127 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2129 $RUNAS $LFS hsm_$action $file &&
2130 error "$action by user should fail"
2132 set_hsm_param user_request_mask $action
2133 $RUNAS $LFS hsm_$action $file ||
2134 error "$action by user should succeed"
2139 chown nobody:$RUNAS_GID $file ||
2140 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2142 $RUNAS $LFS hsm_$action $file &&
2143 error "$action by group should fail"
2145 set_hsm_param group_request_mask $action
2146 $RUNAS $LFS hsm_$action $file ||
2147 error "$action by group should succeed"
2152 chown nobody:nobody $file ||
2153 error "cannot chown '$file' to 'nobody:nobody'"
2155 $RUNAS $LFS hsm_$action $file &&
2156 error "$action by other should fail"
2158 set_hsm_param other_request_mask $action
2159 $RUNAS $LFS hsm_$action $file ||
2160 error "$action by other should succeed"
2165 run_test 24c "check that user,group,other request masks work"
2167 cleanup_test_24d() {
2169 mount -o remount,rw $MOUNT2
2170 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2174 local file1=$DIR/$tdir/$tfile
2175 local file2=$DIR2/$tdir/$tfile
2181 fid1=$(make_small $file1)
2184 $LFS getstripe $file1
2186 trap cleanup_test_24d EXIT
2187 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2188 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2189 copytool_setup $SINGLEAGT "$MOUNT3" ||
2190 error "unable to setup a copytool for the test"
2192 mount -o remount,ro $MOUNT2
2194 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2195 start_full_debug_logging
2197 fid2=$(path2fid $file2)
2198 [ "$fid1" == "$fid2" ] ||
2199 error "FID mismatch '$fid1' != '$fid2'"
2201 $LFS hsm_archive $file2 &&
2202 error "archive should fail on read-only mount"
2203 check_hsm_flags $file1 "0x00000000"
2205 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2206 wait_request_state $fid1 ARCHIVE SUCCEED
2208 stop_full_debug_logging
2210 $LFS hsm_release $file1
2211 $LFS hsm_restore $file2
2212 wait_request_state $fid1 RESTORE SUCCEED
2214 $LFS hsm_release $file1 || error "cannot release '$file1'"
2215 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2217 $LFS hsm_release $file2 &&
2218 error "release should fail on read-only mount"
2223 run_test 24d "check that read-only mounts are respected"
2230 local f=$DIR/$tdir/$tfile
2233 fid=$(make_small $f) || error "cannot create $f"
2234 $LFS hsm_archive $f || error "cannot archive $f"
2235 wait_request_state $fid ARCHIVE SUCCEED
2236 $LFS hsm_release $f || error "cannot release $f"
2237 while ! $LFS hsm_state $f | grep released; do
2241 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2245 run_test 24e "tar succeeds on HSM released files" # LU-6213
2249 # test needs a running copytool
2252 mkdir -p $DIR/$tdir/d1
2253 local f=$DIR/$tdir/$tfile
2254 local fid=$(copy_file /etc/hosts $f)
2257 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2258 error "hsm_archive failed"
2259 wait_request_state $fid ARCHIVE SUCCEED
2260 $LFS hsm_release $f || error "cannot release $f"
2261 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2264 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2265 error "Can not recover the tar contents"
2267 echo "Sum0 = $sum0, sum1 = $sum1"
2268 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2272 run_test 24f "root can archive, release, and restore tar files"
2275 # test needs a running copytool
2279 copy2archive /etc/hosts $tdir/$tfile
2281 local f=$DIR/$tdir/$tfile
2283 import_file $tdir/$tfile $f
2285 $LFS hsm_set --lost $f
2290 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2294 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2295 " (Operation not permitted)"
2298 # test needs a running copytool
2303 local f=$DIR/$tdir/$tfile
2304 local fid=$(copy_file /etc/passwd $f)
2306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2307 wait_request_state $fid ARCHIVE SUCCEED
2310 $LFS hsm_set --lost $f
2314 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2318 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2319 " (Operation not permitted)"
2322 # test needs a running copytool
2326 local f=$DIR/$tdir/$tfile
2328 fid=$(make_custom_file_for_progress $f 39 1000000)
2329 [ $? != 0 ] && skip "not enough free space" && return
2331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2332 wait_request_state $fid ARCHIVE SUCCEED
2335 wait_request_state $fid REMOVE SUCCEED
2337 check_hsm_flags $f "0x00000000"
2341 run_test 26 "Remove the archive of a valid file"
2344 # test needs a running copytool
2348 make_archive $tdir/$tfile
2349 local f=$DIR/$tdir/$tfile
2350 import_file $tdir/$tfile $f
2351 local fid=$(path2fid $f)
2355 [[ $? != 0 ]] || error "Remove of a released file should fail"
2359 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2362 # test needs a running copytool
2366 local f=$DIR/$tdir/$tfile
2368 fid=$(make_custom_file_for_progress $f 39 1000000)
2369 [ $? != 0 ] && skip "not enough free space" && return
2371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2372 wait_request_state $fid ARCHIVE SUCCEED
2377 [[ $? != 0 ]] || error "Remove of a released file should fail"
2381 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2384 # test needs a running copytool
2388 local f=$DIR/$tdir/$tfile
2390 fid=$(make_custom_file_for_progress $f 39 1000000)
2391 [ $? != 0 ] && skip "not enough free space" && return
2393 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2394 wait_request_state $fid ARCHIVE SUCCEED
2403 wait_request_state $fid REMOVE SUCCEED
2407 run_test 28 "Concurrent archive/file remove"
2410 # Tests --mntpath and --archive options
2413 copytool_setup $SINGLEAGT $MOUNT $archive_id
2415 # Bad archive number
2416 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2417 grep "Invalid argument" ||
2418 error "unexpected hsm_remove failure (1)"
2420 # mntpath is present but file is given
2421 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2422 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2423 error "unexpected hsm_remove failure (2)"
2427 run_test 29a "Tests --mntpath and --archive options"
2430 # test needs a running copytool
2434 local f=$DIR/$tdir/$tfile
2435 local fid=$(make_small $f)
2437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2438 wait_request_state $fid ARCHIVE SUCCEED
2442 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2443 wait_request_state $fid REMOVE SUCCEED
2447 run_test 29b "Archive/delete/remove by FID from the archive."
2450 # test needs a running copytool
2454 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2455 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2456 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2458 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2459 wait_request_state $fid1 ARCHIVE SUCCEED
2460 wait_request_state $fid2 ARCHIVE SUCCEED
2461 wait_request_state $fid3 ARCHIVE SUCCEED
2463 rm -f $DIR/$tdir/$tfile-[1-3]
2465 echo $fid1 > $DIR/$tdir/list
2466 echo $fid2 >> $DIR/$tdir/list
2467 echo $fid3 >> $DIR/$tdir/list
2469 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2470 --filelist $DIR/$tdir/list
2471 wait_request_state $fid1 REMOVE SUCCEED
2472 wait_request_state $fid2 REMOVE SUCCEED
2473 wait_request_state $fid3 REMOVE SUCCEED
2477 run_test 29c "Archive/delete/remove by FID, using a file list."
2480 # test needs more than one CT
2481 needclients 3 || return 0
2487 copytool_cleanup $(comma_list $(agts_nodes))
2489 # start all of the copytools
2490 for n in $(seq $AGTCOUNT); do
2491 copytool_setup agt$n $MOUNT2 $n
2494 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2497 file=$DIR/$tdir/$tfile
2498 fid=$(make_small $file)
2500 $LFS hsm_archive $file
2501 wait_request_state $fid ARCHIVE SUCCEED
2502 check_hsm_flags $file "0x00000009"
2506 $LFS hsm_remove -a 0 $fid
2508 # give time for CDT to handle remove request and create broadcasted
2511 # remove request has been broadcasted ?
2512 local cnt=$(get_request_count $fid REMOVE)
2513 # broadcasted requests + original
2514 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2515 error "remove not broadcasted to all CTs"
2517 # give time for CDT and CTs to handle broadcasted
2518 wait_for_loop_period
2520 # each agent serves one different archive_id, so broadcasted
2521 # hsm_remove request should only succeed once and fail at all others
2525 for n in $(seq $AGTCOUNT); do
2526 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2527 $HSM_PARAM.actions | awk \
2528 '/'$fid'.*action=REMOVE archive#='$n'/ \
2529 {print \\\$13}' | cut -f2 -d=")
2530 if [[ "$res" == "SUCCEED" ]]; then
2532 elif [[ "$res" == "FAILED" ]]; then
2537 [[ $scnt -ne 1 ]] &&
2538 error "one and only CT should have removed successfully"
2540 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2541 error "all but one CT should have failed to remove"
2544 copytool_cleanup $(comma_list $(agts_nodes))
2547 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2548 "request to be sent once for each registered archive_id"
2551 # restore at exec cannot work on agent node (because of Linux kernel
2552 # protection of executables)
2553 needclients 2 || return 0
2555 # test needs a running copytool
2559 copy2archive /bin/true $tdir/$tfile
2561 local f=$DIR/$tdir/true
2562 import_file $tdir/$tfile $f
2564 local fid=$(path2fid $f)
2566 # set no retry action mode
2572 # remove no try action mode
2576 [[ $st == 0 ]] || error "Failed to exec a released file"
2580 run_test 30a "Restore at exec (import case)"
2583 # restore at exec cannot work on agent node (because of Linux kernel
2584 # protection of executables)
2585 needclients 2 || return 0
2587 # test needs a running copytool
2591 local f=$DIR/$tdir/true
2592 local fid=$(copy_file /bin/true $f)
2594 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2595 wait_request_state $fid ARCHIVE SUCCEED
2598 # set no retry action mode
2604 # remove no try action mode
2608 [[ $st == 0 ]] || error "Failed to exec a released file"
2612 run_test 30b "Restore at exec (release case)"
2615 needclients 2 || return 0
2617 # test needs a running copytool
2621 local f=$DIR/$tdir/SLEEP
2622 local slp_sum1=$(md5sum /bin/sleep)
2623 local fid=$(copy_file /bin/sleep $f)
2625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2626 wait_request_state $fid ARCHIVE SUCCEED
2628 check_hsm_flags $f "0x0000000d"
2629 # set no retry action mode
2631 do_node $CLIENT2 "$f 10" &
2635 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2637 [[ $? == 0 ]] || error "Execution failed during run"
2639 if [[ $? != 0 ]]; then
2640 local slp_sum2=$(md5sum /bin/sleep)
2641 # in case sleep file is modified during the test
2642 [[ $slp_sum1 == $slp_sum2 ]] &&
2643 error "Binary overwritten during exec"
2647 # remove no try action mode
2649 check_hsm_flags $f "0x00000009"
2653 run_test 30c "Update during exec of released file must fail"
2655 restore_and_check_size() {
2658 local s=$(stat -c "%s" $f)
2660 local st=$(get_hsm_flags $f)
2664 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2666 n=$(stat -c "%s" $f)
2667 # we echo in both cases to show stat is not hang
2668 if [[ $n != $s ]]; then
2669 echo "size seen is $n != $s"
2672 echo "size seen is right: $n == $s"
2676 st=$(get_hsm_flags $f)
2678 if [[ "$st" = "0x00000009" ]]; then
2681 echo " restore is too long"
2682 wait_request_state $fid RESTORE SUCCEED
2688 # test needs a running copytool
2693 make_archive $tdir/$tfile
2694 local f=$DIR/$tdir/$tfile
2695 import_file $tdir/$tfile $f
2696 local fid=$($LFS path2fid $f)
2697 HSM_ARCHIVE_PURGE=false copytool_setup
2699 restore_and_check_size $f $fid
2702 [[ $err -eq 0 ]] || error "File size changed during restore"
2706 run_test 31a "Import a large file and check size during restore"
2710 # test needs a running copytool
2715 local f=$DIR/$tdir/$tfile
2717 fid=$(make_custom_file_for_progress $f 39 1000000)
2718 [ $? != 0 ] && skip "not enough free space" && return
2720 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2721 wait_request_state $fid ARCHIVE SUCCEED
2724 restore_and_check_size $f $fid
2727 [[ $err -eq 0 ]] || error "File size changed during restore"
2731 run_test 31b "Restore a large unaligned file and check size during restore"
2734 # test needs a running copytool
2739 local f=$DIR/$tdir/$tfile
2741 fid=$(make_custom_file_for_progress $f 33 1048576)
2742 [ $? != 0 ] && skip "not enough free space" && return
2744 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2745 wait_request_state $fid ARCHIVE SUCCEED
2748 restore_and_check_size $f $fid
2751 [[ $err -eq 0 ]] || error "File size changed during restore"
2755 run_test 31c "Restore a large aligned file and check size during restore"
2758 # test needs a running copytool
2763 local f=$DIR/$tdir/$tfile
2765 fid=$(make_custom_file_for_progress $f 39 1000000)
2766 [ $? != 0 ] && skip "not enough free space" && return
2768 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2769 wait_request_state $fid ARCHIVE SUCCEED
2772 # to be sure wait_all_done will not be mislead by previous tests
2775 wait_for_grace_delay
2776 # Also raise grace_delay significantly so the Canceled
2777 # Restore action will stay enough long avail.
2778 local old_grace=$(get_hsm_param grace_delay)
2779 set_hsm_param grace_delay 100
2781 md5sum $f >/dev/null &
2783 wait_request_state $fid RESTORE STARTED
2788 # Check restore trigger process was killed
2789 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2793 # instead of waiting+checking both Restore and Cancel ops
2794 # sequentially, wait for both to be finished and then check
2796 wait_all_done 100 $fid
2797 local rstate=$(get_request_state $fid RESTORE)
2798 local cstate=$(get_request_state $fid CANCEL)
2800 # restore orig grace_delay.
2801 set_hsm_param grace_delay $old_grace
2803 if [[ "$rstate" == "CANCELED" ]] ; then
2804 [[ "$cstate" == "SUCCEED" ]] ||
2805 error "Restore state is CANCELED and Cancel state " \
2806 "is not SUCCEED but $cstate"
2807 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2808 elif [[ "$rstate" == "SUCCEED" ]] ; then
2809 [[ "$cstate" == "FAILED" ]] ||
2810 error "Restore state is SUCCEED and Cancel state " \
2811 "is not FAILED but $cstate"
2812 echo "Restore state is SUCCEED, Cancel state is FAILED"
2814 error "Restore state is $rstate and Cancel state is $cstate"
2818 error "Cannot kill process waiting for restore ($killed)"
2822 run_test 33 "Kill a restore waiting process"
2825 # test needs a running copytool
2830 local f=$DIR/$tdir/$tfile
2832 fid=$(make_custom_file_for_progress $f 39 1000000)
2833 [ $? != 0 ] && skip "not enough free space" && return
2835 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2836 wait_request_state $fid ARCHIVE SUCCEED
2839 md5sum $f >/dev/null &
2841 wait_request_state $fid RESTORE STARTED
2843 rm $f || error "rm $f failed"
2844 # rm must not block during restore
2845 wait_request_state $fid RESTORE STARTED
2847 wait_request_state $fid RESTORE SUCCEED
2848 # check md5sum pgm finished
2849 local there=$(ps -o pid,comm hp $pid >/dev/null)
2850 [[ -z $there ]] || error "Restore initiator does not exit"
2852 local rc=$(wait $pid)
2853 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2857 run_test 34 "Remove file during restore"
2860 # test needs a running copytool
2865 local f=$DIR/$tdir/$tfile
2866 local f1=$DIR/$tdir/$tfile-1
2868 fid=$(make_custom_file_for_progress $f 39 1000000)
2869 [ $? != 0 ] && skip "not enough free space" && return
2871 local fid1=$(copy_file /etc/passwd $f1)
2872 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2873 wait_request_state $fid ARCHIVE SUCCEED
2876 md5sum $f >/dev/null &
2878 wait_request_state $fid RESTORE STARTED
2880 mv $f1 $f || error "mv $f1 $f failed"
2881 # mv must not block during restore
2882 wait_request_state $fid RESTORE STARTED
2884 wait_request_state $fid RESTORE SUCCEED
2885 # check md5sum pgm finished
2886 local there=$(ps -o pid,comm hp $pid >/dev/null)
2887 [[ -z $there ]] || error "Restore initiator does not exit"
2889 local rc=$(wait $pid)
2890 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
2893 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2897 run_test 35 "Overwrite file during restore"
2900 # test needs a running copytool
2905 local f=$DIR/$tdir/$tfile
2907 fid=$(make_custom_file_for_progress $f 39 1000000)
2908 [ $? != 0 ] && skip "not enough free space" && return
2910 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2911 wait_request_state $fid ARCHIVE SUCCEED
2914 md5sum $f >/dev/null &
2916 wait_request_state $fid RESTORE STARTED
2919 # rm must not block during restore
2920 wait_request_state $fid RESTORE STARTED
2922 wait_request_state $fid RESTORE SUCCEED
2923 # check md5sum pgm finished
2924 local there=$(ps -o pid,comm hp $pid >/dev/null)
2926 error "Restore initiator does not exit"
2928 local rc=$(wait $pid)
2930 error "Restore initiator failed with $rc"
2934 run_test 36 "Move file during restore"
2937 # LU-5683: check that an archived dirty file can be rearchived.
2939 copytool_setup $SINGLEAGT $MOUNT2
2942 local f=$DIR/$tdir/$tfile
2945 fid=$(make_small $f) || error "cannot create small file"
2947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2948 wait_request_state $fid ARCHIVE SUCCEED
2949 $LFS hsm_release $f || error "cannot release $f"
2951 # Allow previous archive request to expire from the actions log.
2952 wait_for_grace_delay
2955 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2957 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2958 wait_request_state $fid ARCHIVE SUCCEED
2962 run_test 37 "re-archive a dirty file"
2969 for n in $(seq 1 $count); do
2970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2972 echo "$count archive requests submitted"
2976 local stream_count=4
2977 local file_count=100
2979 local f=$DIR/$tdir/$tfile
2984 for i in $(seq 1 $file_count); do
2985 for p in $(seq 1 $stream_count); do
2986 fid=$(copy_file /etc/hosts $f.$p.$i)
2989 # force copytool to use a local/temp archive dir to ensure best
2990 # performance vs remote/NFS mounts used in auto-tests
2991 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
2994 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
2996 # to be sure wait_all_done will not be mislead by previous tests
2998 wait_for_grace_delay
3000 # start archive streams in background (archive files in parallel)
3001 for p in $(seq 1 $stream_count); do
3002 multi_archive $f.$p $file_count &
3005 echo -n "Wait for all requests being enqueued..."
3011 run_test 40 "Parallel archive requests"
3014 # test needs a running copytool
3018 local f=$DIR/$tdir/$tfile
3019 local fid=$(copy_file /etc/motd $f 1)
3021 $LFS hsm_archive $f || error "could not archive file"
3022 wait_request_state $fid ARCHIVE SUCCEED
3023 check_hsm_flags $f "0x00000009"
3025 multiop_bg_pause $f O_c || error "multiop failed"
3029 client_up || client_up || true
3031 kill -USR1 $MULTIPID
3032 wait $MULTIPID || error "multiop close failed"
3034 check_hsm_flags $f "0x0000000b"
3038 run_test 52 "Opened for write file on an evicted client should be set dirty"
3041 # test needs a running copytool
3045 local f=$DIR/$tdir/$tfile
3046 local fid=$(copy_file /etc/motd $f 1)
3048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3049 error "could not archive file"
3050 wait_request_state $fid ARCHIVE SUCCEED
3051 check_hsm_flags $f "0x00000009"
3053 multiop_bg_pause $f o_c || error "multiop failed"
3057 client_up || client_up || true
3059 kill -USR1 $MULTIPID
3060 wait $MULTIPID || error "multiop close failed"
3062 check_hsm_flags $f "0x00000009"
3066 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3069 # test needs a running copytool
3073 local f=$DIR/$tdir/$tfile
3074 local fid=$(make_custom_file_for_progress $f 39 1000000)
3076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3077 error "could not archive file"
3078 wait_request_state $fid ARCHIVE STARTED
3080 check_hsm_flags $f "0x00000001"
3082 # Avoid coordinator resending this request as soon it has failed.
3087 wait_request_state $fid ARCHIVE FAILED
3089 check_hsm_flags $f "0x00000003"
3094 run_test 54 "Write during an archive cancels it"
3097 # test needs a running copytool
3101 local f=$DIR/$tdir/$tfile
3102 local fid=$(make_custom_file_for_progress $f 39 1000000)
3104 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3105 error "could not archive file"
3106 wait_request_state $fid ARCHIVE STARTED
3108 check_hsm_flags $f "0x00000001"
3110 # Avoid coordinator resending this request as soon it has failed.
3113 $TRUNCATE $f 1024 || error "truncate failed"
3115 wait_request_state $fid ARCHIVE FAILED
3117 check_hsm_flags $f "0x00000003"
3122 run_test 55 "Truncate during an archive cancels it"
3125 # test needs a running copytool
3129 local f=$DIR/$tdir/$tfile
3131 fid=$(make_custom_file_for_progress $f 39 1000000)
3132 [ $? != 0 ] && skip "not enough free space" && return
3134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3135 error "could not archive file"
3136 wait_request_state $fid ARCHIVE STARTED
3138 check_hsm_flags $f "0x00000001"
3140 # Change metadata and sync to be sure we are not changing only
3145 wait_request_state $fid ARCHIVE SUCCEED
3147 check_hsm_flags $f "0x00000009"
3151 run_test 56 "Setattr during an archive is ok"
3154 # Need one client for I/O, one for request
3155 needclients 2 || return 0
3157 # test needs a running copytool
3161 local f=$DIR/$tdir/test_archive_remote
3162 # Create a file on a remote node
3163 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3164 "count=2 conv=fsync"
3167 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3168 error "hsm_archive failed"
3169 local fid=$(path2fid $f)
3170 wait_request_state $fid ARCHIVE SUCCEED
3172 # Release and implicit restore it
3173 do_node $CLIENT2 "$LFS hsm_release $f" ||
3174 error "hsm_release failed"
3175 do_node $CLIENT2 "md5sum $f" ||
3176 error "hsm_restore failed"
3178 wait_request_state $fid RESTORE SUCCEED
3182 run_test 57 "Archive a file with dirty cache on another node"
3184 truncate_released_file() {
3188 local sz=$(stat -c %s $src_file)
3189 local f=$DIR/$tdir/$tfile
3190 local fid=$(copy_file $1 $f)
3194 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3195 error "could not archive file"
3196 wait_request_state $fid ARCHIVE SUCCEED
3198 $LFS hsm_release $f || error "could not release file"
3200 $TRUNCATE $f $trunc_to || error "truncate failed"
3203 local sz1=$(stat -c %s $f)
3204 [[ $sz1 == $trunc_to ]] ||
3205 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3208 check_hsm_flags $f "0x0000000b"
3210 local state=$(get_request_state $fid RESTORE)
3211 [[ "$state" == "SUCCEED" ]] ||
3212 error "truncate $sz does not trig restore, state = $state"
3214 $TRUNCATE $ref $trunc_to
3215 cmp $ref $f || error "file data wrong after truncate"
3221 # test needs a running copytool
3226 local sz=$(stat -c %s /etc/passwd)
3228 echo "truncate up from $sz to $((sz*2))"
3229 truncate_released_file /etc/passwd $((sz*2))
3231 echo "truncate down from $sz to $((sz/2))"
3232 truncate_released_file /etc/passwd $((sz/2))
3234 echo "truncate to 0"
3235 truncate_released_file /etc/passwd 0
3239 run_test 58 "Truncate a released file will trigger restore"
3243 local server_version=$(lustre_version_code $SINGLEMDS)
3244 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3245 skip "Need MDS version at least 2.7.63" && return
3248 $MCREATE $DIR/$tfile || error "mcreate failed"
3249 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3250 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3251 fid=$(path2fid $DIR/$tfile)
3252 wait_request_state $fid ARCHIVE SUCCEED
3253 $LFS hsm_release $DIR/$tfile || error "release failed"
3256 run_test 59 "Release stripeless file with non-zero size"
3259 # This test validates the fix for LU-4512. Ensure that the -u
3260 # option changes the progress reporting interval from the
3261 # default (30 seconds) to the user-specified interval.
3263 local progress_timeout=$((interval * 4))
3265 # test needs a new running copytool
3267 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3270 local f=$DIR/$tdir/$tfile
3272 fid=$(make_custom_file_for_progress $f 10)
3273 [ $? != 0 ] && skip "not enough free space" && return
3276 local mdt=${MDT_PREFIX}${mdtidx}
3277 local mds=mds$((mdtidx + 1))
3279 # Wait for copytool to register
3280 wait_update_facet $mds \
3281 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3282 uuid 100 || error "coyptool failed to register with $mdt"
3284 local start_at=$(date +%s)
3285 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3286 error "could not archive file"
3288 local agent=$(facet_active_host $SINGLEAGT)
3289 local prefix=$TESTLOG_PREFIX
3290 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3291 local copytool_log=$prefix.copytool_log.$agent.log
3294 wait_update $agent \
3295 "grep -o start.copy $copytool_log" "start copy" 100 ||
3296 error "copytool failed to start"
3298 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3299 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3305 echo -n "Expecting a progress update within $progress_timeout seconds... "
3307 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3308 if [ $RESULT -gt 0 ]; then
3309 echo "$RESULT bytes copied in $WAIT seconds."
3311 elif [ $WAIT -ge $progress_timeout ]; then
3312 error "Timed out waiting for progress update!"
3315 WAIT=$((WAIT + sleep))
3319 local finish_at=$(date +%s)
3320 local elapsed=$((finish_at - start_at))
3322 # Ensure that the progress update occurred within the expected window.
3323 if [ $elapsed -lt $((interval - 1)) ]; then
3324 error "Expected progress update after at least $interval seconds"
3327 echo "Wait for on going archive hsm action to complete"
3328 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3329 echo "File archiving not completed even after 10 secs"
3334 run_test 60 "Changing progress update interval from default"
3337 # test needs a running copytool
3341 local f=$DIR/$tdir/$tfile
3342 local fid=$(copy_file /etc/passwd $f)
3344 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3347 wait_request_state $fid ARCHIVE FAILED
3351 run_test 61 "Waiting archive of a removed file should fail"
3354 # test needs a new running copytool
3356 copytool_monitor_setup
3357 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3359 # Just start and stop the copytool to generate events.
3362 # Wait for the copytool to register.
3363 wait_update --verbose $(facet_active_host mds1) \
3364 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3366 error "copytool failed to register with MDT0000"
3370 local REGISTER_EVENT
3371 local UNREGISTER_EVENT
3372 while read event; do
3373 local parsed=$(parse_json_event "$event")
3374 if [ -z "$parsed" ]; then
3375 error "Copytool sent malformed event: $event"
3379 if [ $event_type == "REGISTER" ]; then
3380 REGISTER_EVENT=$event
3381 elif [ $event_type == "UNREGISTER" ]; then
3382 UNREGISTER_EVENT=$event
3384 done < <(echo $"$(get_copytool_event_log)")
3386 if [ -z "$REGISTER_EVENT" ]; then
3387 error "Copytool failed to send register event to FIFO"
3390 if [ -z "$UNREGISTER_EVENT" ]; then
3391 error "Copytool failed to send unregister event to FIFO"
3394 copytool_monitor_cleanup
3395 echo "Register/Unregister events look OK."
3397 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3400 # Bump progress interval for livelier events.
3403 # test needs a new running copytool
3405 copytool_monitor_setup
3406 HSMTOOL_UPDATE_INTERVAL=$interval \
3407 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3410 local f=$DIR/$tdir/$tfile
3412 fid=$(make_custom_file_for_progress $f 39 1000000)
3413 [ $? != 0 ] && skip "not enough free space" && return
3415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3416 error "could not archive file"
3417 wait_request_state $fid ARCHIVE SUCCEED
3419 local expected_fields="event_time data_fid source_fid"
3420 expected_fields+=" total_bytes current_bytes"
3424 while read event; do
3425 # Make sure we're not getting anything from previous events.
3426 for field in $expected_fields; do
3430 local parsed=$(parse_json_event "$event")
3431 if [ -z "$parsed" ]; then
3432 error "Copytool sent malformed event: $event"
3436 if [ $event_type == "ARCHIVE_START" ]; then
3439 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3442 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3446 # Do some simple checking of the progress update events.
3447 for expected_field in $expected_fields; do
3448 if [ -z ${!expected_field+x} ]; then
3449 error "Missing $expected_field field in event"
3453 if [ $total_bytes -eq 0 ]; then
3454 error "Expected total_bytes to be > 0"
3457 # These should be identical throughout an archive
3459 if [ $source_fid != $data_fid ]; then
3460 error "Expected source_fid to equal data_fid"
3462 done < <(echo $"$(get_copytool_event_log)")
3464 if [ -z "$START_EVENT" ]; then
3465 error "Copytool failed to send archive start event to FIFO"
3468 if [ -z "$FINISH_EVENT" ]; then
3469 error "Copytool failed to send archive finish event to FIFO"
3472 echo "Archive events look OK."
3476 copytool_monitor_cleanup
3478 run_test 71 "Copytool logs JSON archive events to FIFO"
3481 # Bump progress interval for livelier events.
3484 # test needs a new running copytool
3486 copytool_monitor_setup
3487 HSMTOOL_UPDATE_INTERVAL=$interval \
3488 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3489 local test_file=$HSMTOOL_MONITOR_DIR/file
3491 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3493 do_facet $SINGLEAGT "$cmd" ||
3494 error "cannot create $test_file on $SINGLEAGT"
3495 copy2archive $test_file $tdir/$tfile
3498 local f=$DIR/$tdir/$tfile
3499 import_file $tdir/$tfile $f
3500 f=$DIR2/$tdir/$tfile
3501 echo "Verifying released state: "
3502 check_hsm_flags $f "0x0000000d"
3504 local fid=$(path2fid $f)
3506 wait_request_state $fid RESTORE SUCCEED
3508 local expected_fields="event_time data_fid source_fid"
3509 expected_fields+=" total_bytes current_bytes"
3513 while read event; do
3514 # Make sure we're not getting anything from previous events.
3515 for field in $expected_fields; do
3519 local parsed=$(parse_json_event "$event")
3520 if [ -z "$parsed" ]; then
3521 error "Copytool sent malformed event: $event"
3525 if [ $event_type == "RESTORE_START" ]; then
3527 if [ $source_fid != $data_fid ]; then
3528 error "source_fid should == data_fid at start"
3531 elif [ $event_type == "RESTORE_FINISH" ]; then
3533 if [ $source_fid != $data_fid ]; then
3534 error "source_fid should == data_fid at finish"
3537 elif [ $event_type != "RESTORE_RUNNING" ]; then
3541 # Do some simple checking of the progress update events.
3542 for expected_field in $expected_fields; do
3543 if [ -z ${!expected_field+x} ]; then
3544 error "Missing $expected_field field in event"
3548 if [ $total_bytes -eq 0 ]; then
3549 error "Expected total_bytes to be > 0"
3552 # When a restore starts out, the data fid is the same as the
3553 # source fid. After the restore has gotten going, we learn
3554 # the new data fid. Once the restore has finished, the source
3555 # fid is set to the new data fid.
3557 # We test this because some monitoring software may depend on
3558 # this behavior. If it changes, then the consumers of these
3559 # events may need to be modified.
3560 if [ $source_fid == $data_fid ]; then
3561 error "source_fid should != data_fid during restore"
3563 done < <(echo $"$(get_copytool_event_log)")
3565 if [ -z "$START_EVENT" ]; then
3566 error "Copytool failed to send restore start event to FIFO"
3569 if [ -z "$FINISH_EVENT" ]; then
3570 error "Copytool failed to send restore finish event to FIFO"
3573 echo "Restore events look OK."
3577 copytool_monitor_cleanup
3581 run_test 72 "Copytool logs JSON restore events to FIFO"
3584 file_count=51 # Max number of files constrained by LNET message size
3585 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3586 local f=$DIR/$tdir/$tfile
3587 local FILELIST=/tmp/filelist.txt
3591 for i in $(seq 1 $file_count); do
3592 fid=$(copy_file /etc/hosts $f.$i)
3593 echo $f.$i >> $FILELIST
3595 # force copytool to use a local/temp archive dir to ensure best
3596 # performance vs remote/NFS mounts used in auto-tests
3597 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3600 local dai=$(get_hsm_param default_archive_id)
3601 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3603 # to be sure wait_all_done will not be mislead by previous tests
3605 wait_for_grace_delay
3606 $LFS hsm_archive --filelist $FILELIST ||
3607 error "cannot archive a file list"
3609 $LFS hsm_release --filelist $FILELIST ||
3610 error "cannot release a file list"
3611 $LFS hsm_restore --filelist $FILELIST ||
3612 error "cannot restore a file list"
3616 run_test 90 "Archive/restore a file list"
3618 double_verify_reset_hsm_param() {
3620 echo "Testing $HSM_PARAM.$p"
3621 local val=$(get_hsm_param $p)
3623 local val2=$(($val * 2))
3624 set_hsm_param $p $val2
3625 val=$(get_hsm_param $p)
3626 [[ $val == $val2 ]] ||
3627 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3628 echo "Set $p to 0 must failed"
3632 set_hsm_param $p $save
3634 if [[ $rc == 0 ]]; then
3635 error "we must not be able to set $HSM_PARAM.$p to 0"
3640 double_verify_reset_hsm_param loop_period
3641 double_verify_reset_hsm_param grace_delay
3642 double_verify_reset_hsm_param active_request_timeout
3643 double_verify_reset_hsm_param max_requests
3644 double_verify_reset_hsm_param default_archive_id
3646 run_test 100 "Set coordinator /proc tunables"
3653 run_test 102 "Verify coordinator control"
3656 # test needs a running copytool
3663 for i in $(seq 1 20); do
3664 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3666 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3670 echo "Current requests"
3671 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3672 $HSM_PARAM.actions |\
3673 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3675 [[ -z "$res" ]] || error "Some request have not been canceled"
3679 run_test 103 "Purge all requests"
3684 # test needs a running copytool
3688 local f=$DIR/$tdir/$tfile
3690 fid=$(make_custom_file_for_progress $f 39 1000000)
3691 [ $? != 0 ] && skip "not enough free space" && return
3693 # if cdt is on, it can serve too quickly the request
3695 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3696 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3697 $HSM_PARAM.actions |\
3698 grep $fid | cut -f16 -d=")
3701 [[ "$data1" == "$DATAHEX" ]] ||
3702 error "Data field in records is ($data1) and not ($DATAHEX)"
3706 run_test 104 "Copy tool data field"
3713 for i in $(seq -w 1 10); do
3714 cp /etc/passwd $DIR/$tdir/$i
3715 $LFS hsm_archive $DIR/$tdir/$i
3717 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3718 $HSM_PARAM.actions |\
3719 grep WAITING | wc -l")
3722 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3723 $HSM_PARAM.actions |\
3724 grep WAITING | wc -l")
3727 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3728 error "Requests count after shutdown $reqcnt2 != "\
3729 "before shutdown $reqcnt1"
3731 run_test 105 "Restart of coordinator"
3734 # test needs a running copytool
3737 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3739 check_agent_registered $uuid
3741 search_copytools || error "No copytool found"
3744 check_agent_unregistered $uuid
3747 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3748 check_agent_registered $uuid
3752 run_test 106 "Copytool register/unregister"
3755 # test needs a running copytool
3757 # create and archive file
3759 local f1=$DIR/$tdir/$tfile
3760 local fid=$(copy_file /etc/passwd $f1)
3761 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3762 wait_request_state $fid ARCHIVE SUCCEED
3763 # shutdown and restart MDS
3765 # check the copytool still gets messages from MDT
3766 local f2=$DIR/$tdir/2
3767 local fid=$(copy_file /etc/passwd $f2)
3768 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3769 # main check of this sanity: this request MUST succeed
3770 wait_request_state $fid ARCHIVE SUCCEED
3773 run_test 107 "Copytool re-register after MDS restart"
3775 policy_set_and_test()
3779 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3780 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3781 [[ "$policy" == "$target" ]] ||
3782 error "Wrong policy after '$change': '$policy' != '$target'"
3786 # to force default policy setting if error
3787 CDT_POLICY_HAD_CHANGED=true
3789 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3790 local default="NonBlockingRestore [NoRetryAction]"
3791 [[ "$policy" == "$default" ]] ||
3792 error "default policy has changed,"\
3793 " '$policy' != '$default' update the test"
3794 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3795 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3796 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3797 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3798 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3799 # useless bacause we know but safer for futur changes to use real value
3800 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3801 echo "Next set_param must failed"
3802 policy_set_and_test "wrong" "$policy"
3805 echo "Back to default policy"
3806 cdt_set_sanity_policy
3808 run_test 109 "Policy display/change"
3811 # test needs a running copytool
3816 copy2archive /etc/passwd $tdir/$tfile
3818 local f=$DIR/$tdir/$tfile
3819 import_file $tdir/$tfile $f
3820 local fid=$(path2fid $f)
3822 cdt_set_non_blocking_restore
3827 wait_request_state $fid RESTORE SUCCEED
3828 cdt_clear_non_blocking_restore
3832 error "md5sum returns $st != 1, "\
3833 "should also perror ENODATA (No data available)"
3837 run_test 110a "Non blocking restore policy (import case)"
3840 # test needs a running copytool
3844 local f=$DIR/$tdir/$tfile
3845 local fid=$(copy_file /etc/passwd $f)
3846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3847 wait_request_state $fid ARCHIVE SUCCEED
3850 cdt_set_non_blocking_restore
3855 wait_request_state $fid RESTORE SUCCEED
3856 cdt_clear_non_blocking_restore
3860 error "md5sum returns $st != 1, "\
3861 "should also perror ENODATA (No data available)"
3865 run_test 110b "Non blocking restore policy (release case)"
3868 # test needs a running copytool
3872 copy2archive /etc/passwd $tdir/$tfile
3874 local f=$DIR/$tdir/$tfile
3876 import_file $tdir/$tfile $f
3877 local fid=$(path2fid $f)
3881 copytool_remove_backend $fid
3884 wait_request_state $fid RESTORE FAILED
3891 [[ $st == 0 ]] || error "Restore does not failed"
3895 run_test 111a "No retry policy (import case), restore will error"\
3896 " (No such file or directory)"
3899 # test needs a running copytool
3903 local f=$DIR/$tdir/$tfile
3904 local fid=$(copy_file /etc/passwd $f)
3906 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3907 wait_request_state $fid ARCHIVE SUCCEED
3910 copytool_remove_backend $fid
3913 wait_request_state $fid RESTORE FAILED
3920 [[ $st == 0 ]] || error "Restore does not failed"
3924 run_test 111b "No retry policy (release case), restore will error"\
3925 " (No such file or directory)"
3928 # test needs a running copytool
3932 local f=$DIR/$tdir/$tfile
3933 local fid=$(copy_file /etc/passwd $f)
3935 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3936 local l=$($LFS hsm_action $f)
3938 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3942 wait_request_state $fid ARCHIVE SUCCEED
3945 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3949 run_test 112 "State of recorded request"
3952 # test needs a running copytool
3956 local f=$DIR/$tdir/$tfile
3958 fid=$(make_custom_file_for_progress $f 103 1048576)
3959 [ $? != 0 ] && skip "not enough free space" && return
3961 # test with cdt on is made in test_221
3963 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3964 # wait archive to register at CDT
3965 wait_request_state $fid ARCHIVE WAITING
3968 wait_request_state $fid ARCHIVE CANCELED
3969 wait_request_state $fid CANCEL SUCCEED
3973 run_test 200 "Register/Cancel archive"
3976 # test needs a running copytool
3980 local f=$DIR/$tdir/$tfile
3981 make_archive $tdir/$tfile
3982 import_file $tdir/$tfile $f
3983 local fid=$(path2fid $f)
3985 # test with cdt on is made in test_222
3988 # wait restore to register at CDT
3989 wait_request_state $fid RESTORE WAITING
3992 wait_request_state $fid RESTORE CANCELED
3993 wait_request_state $fid CANCEL SUCCEED
3997 run_test 201 "Register/Cancel restore"
4000 # test needs a running copytool
4004 local f=$DIR/$tdir/$tfile
4006 fid=$(make_custom_file_for_progress $f 39 1000000)
4007 [ $? != 0 ] && skip "not enough free space" && return
4009 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4010 wait_request_state $fid ARCHIVE SUCCEED
4014 # wait remove to register at CDT
4015 wait_request_state $fid REMOVE WAITING
4018 wait_request_state $fid REMOVE CANCELED
4022 run_test 202 "Register/Cancel remove"
4025 # test needs a running copytool
4030 local f=$DIR/$tdir/$tfile
4031 local fid=$(copy_file /etc/passwd $f)
4035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4036 wait_request_state $fid ARCHIVE SUCCEED
4038 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4042 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4046 run_test 220 "Changelog for archive"
4049 # test needs a running copytool
4054 local f=$DIR/$tdir/$tfile
4055 local fid=$(copy_file /etc/passwd $f)
4059 # block copytool operations to allow for HSM request to be
4060 # submitted and file be unlinked (CDT will find object removed)
4063 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4069 wait_request_state $fid ARCHIVE FAILED
4071 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4076 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4080 run_test 220a "Changelog for failed archive"
4083 # test needs a running copytool
4088 local f=$DIR/$tdir/$tfile
4090 fid=$(make_custom_file_for_progress $f 103 1048576)
4091 [ $? != 0 ] && skip "not enough free space" && return
4095 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4096 wait_request_state $fid ARCHIVE STARTED
4098 wait_request_state $fid ARCHIVE CANCELED
4099 wait_request_state $fid CANCEL SUCCEED
4101 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4104 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4108 run_test 221 "Changelog for archive canceled"
4111 # test needs a running copytool
4115 copy2archive /etc/passwd $tdir/$tfile
4117 local f=$DIR/$tdir/$tfile
4118 import_file $tdir/$tfile $f
4119 local fid=$(path2fid $f)
4124 wait_request_state $fid RESTORE SUCCEED
4126 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4129 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4133 run_test 222a "Changelog for explicit restore"
4136 # test needs a running copytool
4140 local f=$DIR/$tdir/$tfile
4141 local fid=$(copy_file /etc/passwd $f)
4144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4145 wait_request_state $fid ARCHIVE SUCCEED
4150 wait_request_state $fid RESTORE SUCCEED
4152 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4155 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4159 run_test 222b "Changelog for implicit restore"
4162 # test needs a running copytool
4166 copy2archive /etc/passwd $tdir/$tfile
4168 local f=$DIR/$tdir/$tfile
4169 import_file $tdir/$tfile $f
4170 local fid=$(path2fid $f)
4174 # block copytool operations to allow for HSM request to be
4175 # submitted and file be unlinked (CDT will find object removed)
4183 wait_request_state $fid RESTORE FAILED
4185 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4189 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4193 run_test 222c "Changelog for failed explicit restore"
4196 # test needs a running copytool
4200 local f=$DIR/$tdir/$tfile
4201 local fid=$(copy_file /etc/passwd $f)
4204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4205 wait_request_state $fid ARCHIVE SUCCEED
4208 copytool_remove_backend $fid
4211 wait_request_state $fid RESTORE FAILED
4213 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4217 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4221 run_test 222d "Changelog for failed implicit restore"
4224 # test needs a running copytool
4229 local f=$DIR/$tdir/$tfile
4230 make_archive $tdir/$tfile
4234 import_file $tdir/$tfile $f
4235 local fid=$(path2fid $f)
4238 wait_request_state $fid RESTORE STARTED
4240 wait_request_state $fid RESTORE CANCELED
4241 wait_request_state $fid CANCEL SUCCEED
4243 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4246 [[ $flags == $target ]] ||
4247 error "Changelog flag is $flags not $target"
4251 run_test 223a "Changelog for restore canceled (import case)"
4254 # test needs a running copytool
4259 local f=$DIR/$tdir/$tfile
4261 fid=$(make_custom_file_for_progress $f 39 1000000)
4262 [ $? != 0 ] && skip "not enough free space" && return
4265 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4266 wait_request_state $fid ARCHIVE SUCCEED
4269 wait_request_state $fid RESTORE STARTED
4271 wait_request_state $fid RESTORE CANCELED
4272 wait_request_state $fid CANCEL SUCCEED
4274 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4277 [[ $flags == $target ]] ||
4278 error "Changelog flag is $flags not $target"
4282 run_test 223b "Changelog for restore canceled (release case)"
4285 # test needs a running copytool
4290 local f=$DIR/$tdir/$tfile
4291 local fid=$(copy_file /etc/passwd $f)
4294 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4295 wait_request_state $fid ARCHIVE SUCCEED
4298 wait_request_state $fid REMOVE SUCCEED
4300 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4303 [[ $flags == $target ]] ||
4304 error "Changelog flag is $flags not $target"
4308 run_test 224 "Changelog for remove"
4311 # test needs a running copytool
4316 local f=$DIR/$tdir/$tfile
4317 local fid=$(copy_file /etc/passwd $f)
4320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4321 wait_request_state $fid ARCHIVE SUCCEED
4323 copytool_remove_backend $fid
4325 # block copytool operations to allow for HSM request to be
4326 # submitted and file be unlinked (CDT will find object removed)
4334 wait_request_state $fid REMOVE FAILED
4336 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4340 [[ $flags == $target ]] ||
4341 error "Changelog flag is $flags not $target"
4345 run_test 224a "Changelog for failed remove"
4348 # test needs a running copytool
4351 # test is not usable because remove request is too fast
4352 # so it is always finished before cancel can be done ...
4353 echo "Test disabled"
4358 local f=$DIR/$tdir/$tfile
4360 fid=$(make_custom_file_for_progress $f 39 1000000)
4361 [ $? != 0 ] && skip "not enough free space" && return
4364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4365 wait_request_state $fid ARCHIVE SUCCEED
4367 # if cdt is on, it can serve too quickly the request
4372 wait_request_state $fid REMOVE CANCELED
4373 wait_request_state $fid CANCEL SUCCEED
4375 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4376 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4377 tail -n 1 | awk '{print $5}')
4380 [[ $flags == $target ]] ||
4381 error "Changelog flag is $flags not $target"
4385 run_test 225 "Changelog for remove canceled"
4388 # test needs a running copytool
4393 local f1=$DIR/$tdir/$tfile-1
4394 local f2=$DIR/$tdir/$tfile-2
4395 local f3=$DIR/$tdir/$tfile-3
4396 local fid1=$(copy_file /etc/passwd $f1)
4397 local fid2=$(copy_file /etc/passwd $f2)
4398 copy_file /etc/passwd $f3
4401 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4402 wait_request_state $fid1 ARCHIVE SUCCEED
4404 $LFS hsm_archive $f2
4405 wait_request_state $fid2 ARCHIVE SUCCEED
4407 rm $f1 || error "rm $f1 failed"
4409 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4412 [[ $flags == $target ]] ||
4413 error "Changelog flag is $flags not $target"
4415 mv $f3 $f2 || error "mv $f3 $f2 failed"
4417 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4420 [[ $flags == $target ]] ||
4421 error "Changelog flag is $flags not $target"
4425 run_test 226 "changelog for last rm/mv with exiting archive"
4427 check_flags_changes() {
4435 $LFS hsm_set --$hsm_flag $f ||
4436 error "Cannot set $hsm_flag on $f"
4437 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4438 local seen=${#flags[*]}
4440 [[ $seen == $cnt ]] ||
4441 error "set $hsm_flag: Changelog events $seen != $cnt"
4442 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4443 error "set $hsm_flag: Changelog flags are "\
4444 "${flags[$((cnt - 1))]} not $target"
4446 $LFS hsm_clear --$hsm_flag $f ||
4447 error "Cannot clear $hsm_flag on $f"
4448 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4451 [[ $cnt == $seen ]] ||
4452 error "clear $hsm_flag: Changelog events $seen != $cnt"
4454 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4455 error "clear $hsm_flag: Changelog flag is "\
4456 "${flags[$((cnt - 1))]} not $target"
4460 # test needs a running copytool
4467 for i in norelease noarchive exists archived
4469 local f=$DIR/$tdir/$tfile-$i
4470 local fid=$(copy_file /etc/passwd $f)
4471 check_flags_changes $f $fid $i 0 1
4474 f=$DIR/$tdir/$tfile---lost
4475 fid=$(copy_file /etc/passwd $f)
4476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4477 wait_request_state $fid ARCHIVE SUCCEED
4478 check_flags_changes $f $fid lost 3 1
4482 run_test 227 "changelog when explicit setting of HSM flags"
4485 # test needs a running copytool
4488 local fid=$(make_small_sync $DIR/$tfile)
4489 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4490 wait_request_state $fid ARCHIVE SUCCEED
4492 $LFS hsm_release $DIR/$tfile
4493 check_hsm_flags $DIR/$tfile "0x0000000d"
4495 filefrag $DIR/$tfile | grep " 1 extent found" ||
4496 error "filefrag on released file must return only one extent"
4498 # only newer versions of cp detect sparse files by stat/FIEMAP
4500 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4501 error "copying $DIR/$tfile"
4502 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4504 $LFS hsm_release $DIR/$tfile
4505 check_hsm_flags $DIR/$tfile "0x0000000d"
4507 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4509 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4511 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4512 error "comparing untarred $DIR/$tfile"
4514 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4515 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4518 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4521 # test needs a running copytool
4525 local maxrequest=$(get_hsm_param max_requests)
4526 local rqcnt=$(($maxrequest * 3))
4530 for i in $(seq -w 1 $rqcnt); do
4532 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4534 # we do it in 2 steps, so all requests arrive at the same time
4535 for i in $(seq -w 1 $rqcnt); do
4536 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4541 while [[ $cnt != 0 || $wt != 0 ]]; do
4543 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4544 $HSM_PARAM.actions |\
4545 grep STARTED | grep -v CANCEL | wc -l")
4546 [[ $cnt -le $maxrequest ]] ||
4547 error "$cnt > $maxrequest too many started requests"
4548 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4549 $HSM_PARAM.actions |\
4550 grep WAITING | wc -l")
4551 echo "max=$maxrequest started=$cnt waiting=$wt"
4556 run_test 250 "Coordinator max request"
4559 # test needs a running copytool
4563 local f=$DIR/$tdir/$tfile
4565 fid=$(make_custom_file_for_progress $f 103 1048576)
4566 [ $? != 0 ] && skip "not enough free space" && return
4569 # to have a short test
4570 local old_to=$(get_hsm_param active_request_timeout)
4571 set_hsm_param active_request_timeout 4
4572 # to be sure the cdt will wake up frequently so
4573 # it will be able to cancel the "old" request
4574 local old_loop=$(get_hsm_param loop_period)
4575 set_hsm_param loop_period 2
4578 # clear locks to avoid extra delay caused by flush/cancel
4579 # and thus prevent early copytool death to timeout.
4580 cancel_lru_locks osc
4582 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4583 wait_request_state $fid ARCHIVE STARTED
4585 wait_request_state $fid ARCHIVE CANCELED
4587 set_hsm_param active_request_timeout $old_to
4588 set_hsm_param loop_period $old_loop
4592 run_test 251 "Coordinator request timeout"
4595 # test needs a running copytool
4599 local f=$DIR/$tdir/$tfile
4600 local fid=$(make_custom_file_for_progress $f 103 1048576)
4603 # to have a short test
4604 local old_to=$(get_hsm_param active_request_timeout)
4605 set_hsm_param active_request_timeout 20
4606 # to be sure the cdt will wake up frequently so
4607 # it will be able to cancel the "old" request
4608 local old_loop=$(get_hsm_param loop_period)
4609 set_hsm_param loop_period 2
4612 # clear locks to avoid extra delay caused by flush/cancel
4613 # and thus prevent early copytool death to timeout.
4614 cancel_lru_locks osc
4616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4617 wait_request_state $fid ARCHIVE STARTED
4620 # wait but less than active_request_timeout+grace_delay
4622 wait_request_state $fid ARCHIVE CANCELED
4624 set_hsm_param active_request_timeout $old_to
4625 set_hsm_param loop_period $old_loop
4629 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4632 # the only way to test ondisk conf is to restart MDS ...
4633 echo "Stop coordinator and remove coordinator state at mount"
4636 # clean on disk conf set by default
4637 cdt_clear_mount_state
4638 cdt_check_state stopped
4640 # check cdt still off after umount/remount
4642 cdt_check_state stopped
4644 echo "Set coordinator start at mount, and start coordinator"
4645 cdt_set_mount_state enabled
4648 cdt_check_state enabled
4650 # check cdt still on after umount/remount
4652 cdt_check_state enabled
4654 # we are back to original state (cdt started at mount)
4656 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4659 local ai=$(get_hsm_param default_archive_id)
4660 local new=$((ai + 1))
4662 set_hsm_param default_archive_id $new -P
4664 local res=$(get_hsm_param default_archive_id)
4667 set_hsm_param default_archive_id "" "-P -d"
4669 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4671 run_test 301 "HSM tunnable are persistent"
4674 local ai=$(get_hsm_param default_archive_id)
4675 local new=$((ai + 1))
4680 set_hsm_param default_archive_id $new -P
4683 for mdtno in $(seq 1 $MDSCOUNT); do
4688 cdt_check_state enabled
4690 local res=$(get_hsm_param default_archive_id)
4693 set_hsm_param default_archive_id "" "-P -d"
4695 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4697 run_test 302 "HSM tunnable are persistent when CDT is off"
4700 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4706 local dir_mdt0=$DIR/$tdir/mdt0
4707 local dir_mdt1=$DIR/$tdir/mdt1
4709 # create 1 dir per MDT
4710 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4711 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4713 # create 1 file in each MDT
4714 local fid1=$(make_small $dir_mdt0/$tfile)
4715 local fid2=$(make_small $dir_mdt1/$tfile)
4717 # check that hsm request on mdt0 is sent to the right MDS
4718 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4719 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4720 echo "archive successful on mdt0"
4722 # check that hsm request on mdt1 is sent to the right MDS
4723 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4724 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4725 echo "archive successful on mdt1"
4728 # clean test files and directories
4729 rm -rf $dir_mdt0 $dir_mdt1
4731 run_test 400 "Single request is sent to the right MDT"
4734 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4740 local dir_mdt0=$DIR/$tdir/mdt0
4741 local dir_mdt1=$DIR/$tdir/mdt1
4743 # create 1 dir per MDT
4744 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4745 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4747 # create 1 file in each MDT
4748 local fid1=$(make_small $dir_mdt0/$tfile)
4749 local fid2=$(make_small $dir_mdt1/$tfile)
4751 # check that compound requests are shunt to the rights MDTs
4752 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4753 error "lfs hsm_archive"
4754 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4755 echo "archive successful on mdt0"
4756 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4757 echo "archive successful on mdt1"
4760 # clean test files and directories
4761 rm -rf $dir_mdt0 $dir_mdt1
4763 run_test 401 "Compound requests split and sent to their respective MDTs"
4765 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4770 local node=$(facet_active_host $facet)
4772 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4773 awk '{print $4}'); do
4774 echo "$3 $mdc on $node"
4775 do_facet $facet "$LCTL --device $mdc $state" || return 1
4780 # make sure there is no running copytool
4783 # deactivate all mdc on agent1
4784 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4786 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
4788 check_agent_unregistered "uuid" # match any agent
4790 # no expected running copytool
4791 search_copytools $agent && error "Copytool start should have failed"
4794 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4796 run_test 402a "Copytool start fails if all MDTs are inactive"
4803 local f=$DIR/$tdir/$tfile
4804 touch $f || error "touch $f failed"
4805 local fid=$(path2fid $f)
4807 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4808 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4809 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4811 # give time for CDT to send request and to keep it for retry
4812 wait_for_loop_period
4814 wait_request_state $fid ARCHIVE WAITING
4816 do_facet $SINGLEAGT lctl set_param fail_loc=0
4818 # request should succeed now
4819 wait_request_state $fid ARCHIVE SUCCEED
4823 run_test 402b "CDT must retry request upon slow start of CT"
4826 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4828 # make sure there is no running copytool
4831 local agent=$(facet_active_host $SINGLEAGT)
4833 # deactivate all mdc for MDT0001
4834 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4837 local uuid=$(get_agent_uuid $agent)
4838 # check the agent is registered on MDT0000, and not on MDT0001
4839 check_agent_registered_by_mdt $uuid 0
4840 check_agent_unregistered_by_mdt $uuid 1
4842 # check running copytool process
4843 search_copytools $agent || error "No running copytools on $agent"
4845 # reactivate all mdc for MDT0001
4846 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4848 # make sure the copytool is now registered to all MDTs
4849 check_agent_registered $uuid
4853 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4856 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4860 # create files on both MDT0000 and MDT0001
4863 local dir_mdt0=$DIR/$tdir/mdt0
4864 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4866 # create 1 file on mdt0
4867 local fid1=$(make_small $dir_mdt0/$tfile)
4869 # deactivate all mdc for MDT0001
4870 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4872 # send an HSM request for files in MDT0000
4873 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4875 # check for completion of files in MDT0000
4876 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4877 echo "archive successful on mdt0"
4879 # reactivate all mdc for MDT0001
4880 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4883 # clean test files and directories
4886 run_test 404 "Inactive MDT does not block requests for active MDTs"
4889 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4895 local striped_dir=$DIR/$tdir/striped_dir
4897 # create striped dir on all of MDTs
4898 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4900 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
4901 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
4902 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
4903 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
4905 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
4906 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
4907 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
4908 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
4910 # check that compound requests are shunt to the rights MDTs
4911 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4912 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4913 error "lfs hsm_archive"
4915 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4916 echo "archive successful on $fid1"
4917 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4918 echo "archive successful on $fid2"
4919 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4920 echo "archive successful on $fid3"
4921 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4922 echo "archive successful on $fid4"
4924 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4925 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4926 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4927 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4929 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4930 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4931 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4932 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4936 run_test 405 "archive and release under striped directory"
4939 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4941 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4942 skip "need MDS version at least 2.7.64" && return 0
4949 fid=$(make_small $DIR/$tdir/$tfile)
4952 $LFS hsm_archive $DIR/$tdir/$tfile
4953 wait_request_state "$fid" ARCHIVE SUCCEED
4954 $LFS hsm_release $DIR/$tdir/$tfile
4956 # Should migrate $tdir but not $tfile.
4957 $LFS mv -M1 $DIR/$tdir &&
4958 error "migrating HSM an archived file should fail"
4960 $LFS hsm_restore $DIR/$tdir/$tfile
4961 wait_request_state "$fid" RESTORE SUCCEED
4963 $LFS hsm_remove $DIR/$tdir/$tfile
4964 wait_request_state "$fid" REMOVE SUCCEED
4966 cat $DIR/$tdir/$tfile > /dev/null ||
4967 error "cannot read $DIR/$tdir/$tfile"
4969 $LFS mv -M1 $DIR/$tdir ||
4970 error "cannot complete migration after HSM remove"
4972 mdt_index=$($LFS getstripe -M $DIR/$tdir)
4973 if ((mdt_index != 1)); then
4974 error "expected MDT index 1, got $mdt_index"
4977 # Refresh fid after migration.
4978 fid=$(path2fid $DIR/$tdir/$tfile)
4981 $LFS hsm_archive $DIR/$tdir/$tfile
4982 wait_request_state "$fid" ARCHIVE SUCCEED 1
4984 lctl set_param debug=+trace
4985 $LFS hsm_release $DIR/$tdir/$tfile ||
4986 error "cannot release $DIR/$tdir/$tfile"
4988 $LFS hsm_restore $DIR/$tdir/$tfile
4989 wait_request_state "$fid" RESTORE SUCCEED 1
4991 cat $DIR/$tdir/$tfile > /dev/null ||
4992 error "cannot read $DIR/$tdir/$tfile"
4996 run_test 406 "attempting to migrate HSM archived files is safe"
5000 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5001 skip "HSM migrate is not supported" && return
5003 # Stop the existing copytool
5006 test_mkdir -p $DIR/$tdir
5007 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5009 run_test 500 "various LLAPI HSM tests"
5014 check_and_cleanup_lustre