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
46 if getent group nobody; then
48 elif getent group nogroup; then
51 error "No generic nobody group"
56 # if there is no CLIENT1 defined, some tests can be ran on localhost
57 CLIENT1=${CLIENT1:-$HOSTNAME}
58 # if CLIENT2 doesn't exist then use CLIENT1 instead
59 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # Exception is the test which need two separate nodes
62 CLIENT2=${CLIENT2:-$CLIENT1}
65 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
66 # the following associated variables are added:
68 # AGTCOUNT: number of agents
69 # AGTDEV{N}: target HSM mount point (root path of the backend)
70 # agt{N}_HOST: hostname of the agent agt{N}
71 # SINGLEAGT: facet of the single agent
73 # The number of agents is initialized as the number of remote client nodes.
74 # By default, only single copytool is started on a remote client/agent. If there
75 # was no remote client, then the copytool will be started on the local client.
81 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
82 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
84 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
85 if [[ $CLIENTCOUNT -gt 1 ]] &&
86 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
87 skip_env "SHARED_DIRECTORY should be accessible"\
92 # We used to put the HSM archive in $SHARED_DIRECTORY but that
93 # meant NFS issues could hose sanity-hsm sessions. So now we
95 for n in $(seq $AGTCOUNT); do
96 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
97 agent=CLIENT$((n + 1))
98 if [[ -z "${!agent}" ]]; then
99 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
102 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
105 export SINGLEAGT=${SINGLEAGT:-agt1}
107 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
108 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
109 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
110 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
111 export HSMTOOL_TESTDIR
112 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
113 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
114 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
115 # deleting everything in filesystem, independent of any copytool.
116 export HSMTMP=${HSMTMP:-"shsm"}
118 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
120 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
121 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
125 # The test only support up to 10 MDTs
126 MDT_PREFIX="mdt.$FSNAME-MDT000"
127 HSM_PARAM="${MDT_PREFIX}0.hsm"
129 # archive is purged at copytool setup
130 HSM_ARCHIVE_PURGE=true
132 # Don't allow copytool error upon start/setup
133 HSMTOOL_NOERROR=false
136 # Get the backend root path for the given agent facet.
139 local dev=AGTDEV$(facet_number $facet)
144 # Stop copytool and unregister an existing changelog user.
146 copytool_monitor_cleanup
149 cdt_set_sanity_policy
154 # get MDT device for each mdc
155 for mdtno in $(seq 1 $MDSCOUNT); do
156 local idx=$(($mdtno - 1))
157 MDT[$idx]=$($LCTL get_param -n \
158 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
159 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
164 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
165 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
171 echo "Killing existing copytools on $hosts"
172 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
176 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
177 local wait_timeout=200
178 local wait_start=$SECONDS
179 local wait_end=$((wait_start + wait_timeout))
180 local sleep_time=100000 # 0.1 second
182 while ((SECONDS < wait_end)); do
183 if ! search_copytools $hosts; then
184 echo "copytools stopped in $((SECONDS - wait_start))s"
188 echo "copytools still running on $hosts"
190 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
191 sleep_time=$(bc <<< "$sleep_time * 2")
194 # try to dump Copytool's stack
195 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
196 "echo t >/proc/sysrq-trigger"
198 echo "copytools failed to stop in ${wait_timeout}s"
203 copytool_monitor_setup() {
204 local facet=${1:-$SINGLEAGT}
205 local agent=$(facet_active_host $facet)
207 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
208 local test_dir=$(do_node $agent "$cmd") ||
209 error "Failed to create tempdir on $agent"
210 export HSMTOOL_MONITOR_DIR=$test_dir
212 # Create the fifo and a monitor (cat dies when copytool dies)
213 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
214 error "failed to create copytool fifo on $agent"
215 cmd="cat $test_dir/fifo > $test_dir/events &"
216 cmd+=" echo \\\$! > $test_dir/monitor_pid"
218 if [[ $PDSH == *Rmrsh* ]]; then
219 # This is required for pdsh -Rmrsh and its handling of remote
221 # Regular ssh and pdsh -Rssh work fine without this
222 # backgrounded subshell nonsense.
223 (do_node $agent "$cmd") &
224 export HSMTOOL_MONITOR_PDSH=$!
226 # Slightly racy, but just making a best-effort to catch obvious
229 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
230 error "Failed to start copytool monitor on $agent"
232 do_node $agent "$cmd"
234 error "Failed to start copytool monitor on $agent"
239 copytool_monitor_cleanup() {
240 local facet=${1:-$SINGLEAGT}
241 local agent=$(facet_active_host $facet)
243 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
244 # Should die when the copytool dies, but just in case.
245 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
246 cmd+=" 2>/dev/null || true"
247 do_node $agent "$cmd"
248 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
249 export HSMTOOL_MONITOR_DIR=
252 # The pdsh should die on its own when the monitor dies. Just
253 # in case, though, try to clean up to avoid any cruft.
254 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
255 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
256 export HSMTOOL_MONITOR_PDSH=
261 local facet=${1:-$SINGLEAGT}
262 # Use MOUNT2 by default if defined
263 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
265 local hsm_root=${4:-$(copytool_device $facet)}
267 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
269 local agent=$(facet_active_host $facet)
271 if $HSM_ARCHIVE_PURGE; then
272 echo "Purging archive on $agent"
273 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
276 echo "Starting copytool $facet on $agent"
277 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
278 error "mkdir '$hsm_root/$HSMTMP' failed"
279 # bandwidth is limited to 1MB/s so the copy time is known and
280 # independent of hardware
281 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
282 cmd+=" --hsm-root $hsm_root/$HSMTMP"
283 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
284 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
285 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
286 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
287 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
288 cmd+=" --bandwidth 1 $lustre_mntpnt"
290 # Redirect the standard output and error to a log file which
291 # can be uploaded to Maloo.
292 local prefix=$TESTLOG_PREFIX
293 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
294 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
296 stack_trap cleanup EXIT
297 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
298 if [[ $? != 0 ]]; then
299 [[ $HSMTOOL_NOERROR == true ]] ||
300 error "start copytool $facet on $agent failed"
301 echo "start copytool $facet on $agent failed"
305 get_copytool_event_log() {
306 local facet=${1:-$SINGLEAGT}
307 local agent=$(facet_active_host $facet)
309 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
310 error "Can't get event log: No monitor directory!"
312 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
313 error "Could not collect event log from $agent"
318 local agt_facet=$SINGLEAGT
319 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
320 local hsm_root=$(copytool_device $agt_facet)
322 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
329 kill_copytools $agt_hosts
330 wait_copytools $agt_hosts || error "copytools failed to stop"
332 # Clean all CDTs orphans requests from previous tests that
333 # would otherwise need to timeout to clear.
334 for ((i = 0; i < MDSCOUNT; i++)); do
336 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
337 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
339 # Skip already stopping or stopped CDTs.
340 [[ "${state[$i]}" =~ ^stop ]] && continue
342 do_facet $facet "$LCTL set_param $param=shutdown"
345 for ((i = 0; i < MDSCOUNT; i++)); do
346 # Only check and restore CDTs that we stopped in the first loop.
347 [[ "${state[$i]}" =~ ^stop ]] && continue
350 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
352 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
353 error "$facet CDT state is not stopped"
355 # Restore old CDT state.
356 do_facet $facet "$LCTL set_param $param=${state[$i]}"
359 for ((i = 0; i < MDSCOUNT; i++)); do
360 # Only check CDTs that we stopped in the first loop.
361 [[ "${state[$i]}" =~ ^stop ]] && continue
364 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
366 # Check that the old CDT state was restored.
367 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
368 20 || error "$facet CDT state is not '${state[$i]}'"
371 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
372 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
377 local agents=${1:-$(facet_active_host $SINGLEAGT)}
379 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
380 echo "Copytool is suspended on $agents"
383 copytool_continue() {
384 local agents=${1:-$(facet_active_host $SINGLEAGT)}
386 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
387 echo "Copytool is continued on $agents"
390 copytool_remove_backend() {
392 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
393 echo "Remove from backend: $fid = $be"
394 do_facet $SINGLEAGT rm -f $be
398 do_facet $SINGLEAGT \
399 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
400 --import $1 $2 $MOUNT" ||
401 error "import of $1 to $2 failed"
405 local file=$HSM_ARCHIVE/$1
406 do_facet $SINGLEAGT mkdir -p $(dirname $file)
407 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
408 file_creation_failure dd $file $?
412 local file=$HSM_ARCHIVE/$2
413 do_facet $SINGLEAGT mkdir -p $(dirname $file)
414 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
423 if [[ "$value" != "" ]]; then
426 for mdtno in $(seq 1 $MDSCOUNT); do
427 local idx=$(($mdtno - 1))
428 local facet=mds${mdtno}
429 # if $arg include -P option, run 1 set_param per MDT on the MGS
430 # else, run set_param on each MDT
431 [[ $arg = *"-P"* ]] && facet=mgs
432 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
433 [[ $? != 0 ]] && rc=1
443 for mdtno in $(seq 1 $MDSCOUNT); do
444 local idx=$(($mdtno - 1))
445 wait_result mds${mdtno} \
446 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
448 error "$key state is not '$target' on mds${mdtno}"
455 for mdtno in $(seq 1 $MDSCOUNT); do
456 local idx=$(($mdtno - 1))
457 local cl_user=$(do_facet mds${mdtno} $LCTL \
458 --device ${MDT[$idx]} \
459 changelog_register -n)
461 do_facet mds${mdtno} lctl set_param \
462 mdd.${MDT[$idx]}.changelog_mask="+hsm"
463 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
467 changelog_cleanup() {
469 for mdtno in $(seq 1 $MDSCOUNT); do
470 local idx=$(($mdtno - 1))
471 [[ -z ${CL_USERS[$idx]} ]] && continue
472 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
473 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
474 changelog_deregister ${CL_USERS[$idx]}
479 changelog_get_flags() {
484 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
489 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
497 mdts_set_param "$opt -n" "hsm.$param" "$value"
504 mdts_set_param "" hsm_control "$cmd"
505 mdts_check_param hsm_control "$target" 10
508 cdt_set_sanity_policy() {
509 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
512 mdts_set_param "" hsm.policy "+NRA"
513 mdts_set_param "" hsm.policy "-NBR"
514 CDT_POLICY_HAD_CHANGED=
519 mdts_set_param "" hsm.policy "+NRA"
520 CDT_POLICY_HAD_CHANGED=true
523 cdt_clear_no_retry() {
524 mdts_set_param "" hsm.policy "-NRA"
525 CDT_POLICY_HAD_CHANGED=true
528 cdt_set_non_blocking_restore() {
529 mdts_set_param "" hsm.policy "+NBR"
530 CDT_POLICY_HAD_CHANGED=true
533 cdt_clear_non_blocking_restore() {
534 mdts_set_param "" hsm.policy "-NBR"
535 CDT_POLICY_HAD_CHANGED=true
538 cdt_clear_mount_state() {
539 mdts_set_param "-P -d" hsm_control ""
542 cdt_set_mount_state() {
543 mdts_set_param "-P" hsm_control "$1"
544 # set_param -P is asynchronous operation and could race with set_param.
545 # In such case configs could be retrieved and applied at mgc after
546 # set_param -P completion. Sleep here to avoid race with set_param.
547 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
548 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
549 # and 10 seconds to retrieve config from server.
554 mdts_check_param hsm_control "$1" 20
558 set_test_state disabled disabled
562 set_test_state enabled enabled
566 set_test_state shutdown stopped
570 set_test_state purge enabled
576 cdt_set_sanity_policy
580 local client_count=$1
581 if [[ $CLIENTCOUNT -lt $client_count ]]; then
582 skip "Need $client_count or more clients, have $CLIENTCOUNT"
589 $LFS path2fid $1 | tr -d '[]'
590 return ${PIPESTATUS[0]}
598 if [[ $u == "user" ]]; then
599 st=$($RUNAS $LFS hsm_state $f)
602 st=$($LFS hsm_state $f)
605 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
607 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
611 get_hsm_archive_id() {
614 st=$($LFS hsm_state $f)
615 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
617 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
625 local st=$(get_hsm_flags $f)
626 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
629 check_hsm_flags_user() {
633 local st=$(get_hsm_flags $f user)
634 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
637 file_creation_failure() {
642 df $MOUNT $MOUNT2 >&2
643 error "cannot create $f with $cmd, status=$err"
655 if [[ "$3" != 1 ]]; then
659 cp $1 $f || file_creation_failure cp $f $?
661 path2fid $f || error "cannot get fid on $f"
665 local file2=${1/$DIR/$DIR2}
666 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
667 file_creation_failure dd $file2 $?
669 path2fid $1 || error "cannot get fid on $1"
673 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
674 file_creation_failure dd $1 $?
675 path2fid $1 || error "cannot get fid on $1"
678 cleanup_large_files() {
679 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
681 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
684 check_enough_free_space() {
687 local need=$((nb * unit /1024))
688 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
689 (( $need >= $free )) && return 1
693 make_custom_file_for_progress() {
694 local file2=${1/$DIR/$DIR2}
695 local fsize=${2:-"39"}
696 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
699 [[ $fsize -gt 0 ]] || error "Invalid file size"
700 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
703 check_enough_free_space $fsize $blksz || return $?
704 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
705 file_creation_failure dd $file2 $?
706 path2fid $1 || error "cannot get fid on $1"
712 wait_update --verbose $(facet_active_host $facet) "$@"
715 wait_request_state() {
719 # 4th arg (mdt index) is optional
721 local mds=mds$(($mdtidx + 1))
723 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
724 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
726 wait_result $mds "$cmd" $state 200 ||
727 error "request on $fid is not $state on $mds"
730 get_request_state() {
734 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
735 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
738 get_request_count() {
742 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
743 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
746 # Ensure the number of HSM request for a given FID is correct
747 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
748 assert_request_count() {
749 local request_count=$(get_request_count $1 $2)
750 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
752 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
759 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
760 [[ -n $fid ]] && cmd+=" | grep '$fid'"
761 cmd+=" | egrep 'WAITING|STARTED'"
763 wait_result $SINGLEMDS "$cmd" "" $timeout ||
764 error "requests did not complete"
767 wait_for_grace_delay() {
768 local val=$(get_hsm_param grace_delay)
772 wait_for_loop_period() {
773 local val=$(get_hsm_param loop_period)
780 # python2.6 in EL6 includes an internal json module
781 local json_parser='import json; import fileinput;'
782 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
783 json_parser+='json.loads([line for line in '
784 json_parser+='fileinput.input()][0]).items()])'
786 echo $raw_event | python -c "$json_parser"
789 get_agent_by_uuid_mdt() {
792 local mds=mds$(($mdtidx + 1))
793 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
797 check_agent_registered_by_mdt() {
800 local mds=mds$(($mdtidx + 1))
801 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
802 if [[ ! -z "$agent" ]]; then
803 echo "found agent $agent on $mds"
805 error "uuid $uuid not found in agent list on $mds"
809 check_agent_unregistered_by_mdt() {
812 local mds=mds$(($mdtidx + 1))
813 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
814 if [[ -z "$agent" ]]; then
815 echo "uuid not found in agent list on $mds"
817 error "uuid found in agent list on $mds: $agent"
821 check_agent_registered() {
824 for mdsno in $(seq 1 $MDSCOUNT); do
825 check_agent_registered_by_mdt $uuid $((mdsno - 1))
829 check_agent_unregistered() {
832 for mdsno in $(seq 1 $MDSCOUNT); do
833 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
838 local agent=${1:-$(facet_active_host $SINGLEAGT)}
840 # Lustre mount-point is mandatory and last parameter on
842 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
844 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
846 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
852 # populate MDT device array
855 # cleanup from previous bad setup
858 # for recovery tests, coordinator needs to be started at mount
860 # the lustre conf must be without hsm on (like for sanity.sh)
861 echo "Set HSM on and start"
862 cdt_set_mount_state enabled
863 cdt_check_state enabled
865 echo "Set sanity-hsm HSM policy"
866 cdt_set_sanity_policy
868 # finished requests are quickly removed from list
869 set_hsm_param grace_delay 10
875 local f=$DIR/$tdir/$tfile
879 check_hsm_flags_user $f "0x00000000"
881 $RUNAS $LFS hsm_set --norelease $f ||
882 error "user could not change hsm flags"
883 check_hsm_flags_user $f "0x00000010"
885 $RUNAS $LFS hsm_clear --norelease $f ||
886 error "user could not clear hsm flags"
887 check_hsm_flags_user $f "0x00000000"
889 # User could not change those flags...
890 $RUNAS $LFS hsm_set --exists $f &&
891 error "user should not set this flag"
892 check_hsm_flags_user $f "0x00000000"
895 $LFS hsm_set --exists $f ||
896 error "root could not change hsm flags"
897 check_hsm_flags_user $f "0x00000001"
899 $LFS hsm_clear --exists $f ||
900 error "root could not clear hsm state"
901 check_hsm_flags_user $f "0x00000000"
904 run_test 1 "lfs hsm flags root/non-root access"
908 local f=$DIR/$tdir/$tfile
909 local fid=$(make_small $f)
913 $LFS hsm_archive $f || error "could not archive file"
914 wait_request_state $fid ARCHIVE SUCCEED
916 # Release and check states
917 $LFS hsm_release $f || error "could not release file"
918 echo -n "Verifying released state: "
919 check_hsm_flags $f "0x0000000d"
921 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
925 run_test 1a "mmap & cat a HSM released file"
929 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
930 error "failed to set default stripe"
931 local f=$DIR/$tdir/$tfile
934 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
935 error "failed to create file"
936 local fid=$(path2fid $f)
941 $LFS hsm_archive $f || error "could not archive file"
942 wait_request_state $fid ARCHIVE SUCCEED
945 $LFS hsm_release $f || error "could not release file"
946 echo "verify released state: "
947 check_hsm_flags $f "0x0000000d" && echo "pass"
950 $LFS hsm_restore $f || error "could not restore file"
951 wait_request_state $fid RESTORE SUCCEED
952 echo "verify restored state: "
953 check_hsm_flags $f "0x00000009" && echo "pass"
957 run_test 1b "Archive, Release & Restore composite file"
963 local f=$DIR/$tdir/$tfile
966 # Test whether we can set the maximum archive number.
967 local LOCAL_HSM_ARCHIVE_NUMBER=32
968 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
969 error "root could not change hsm flags"
970 check_hsm_flags_user $f "0x00000001"
971 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
972 local st=$(get_hsm_archive_id $f)
973 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
974 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
976 # Test whether setting archive number 0 results in no change.
977 $LFS hsm_set --exists --archive-id 0 $f ||
978 error "root could not change hsm flags"
979 check_hsm_flags_user $f "0x00000001"
980 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
981 st=$(get_hsm_archive_id $f)
982 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
983 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
985 # Test whether setting archive number > 32 results in error.
986 $LFS hsm_set --exists --archive-id 33 $f &&
987 error "archive number is larger than 32"
988 check_hsm_flags_user $f "0x00000001"
990 # Test whether setting archive number 16 and archived flag.
991 LOCAL_HSM_ARCHIVE_NUMBER=16
992 $LFS hsm_set --exists --archived \
993 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
994 error "root could not change hsm flags"
995 check_hsm_flags_user $f "0x00000009"
996 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
997 st=$(get_hsm_archive_id $f)
998 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
999 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1001 run_test 1c "Check setting archive-id in lfs hsm_set"
1005 local f=$DIR/$tdir/$tfile
1007 # New files are not dirty
1008 check_hsm_flags $f "0x00000000"
1010 # For test, we simulate an archived file.
1011 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1012 check_hsm_flags $f "0x00000001"
1014 # chmod do not put the file dirty
1015 chmod 600 $f || error "could not chmod test file"
1016 check_hsm_flags $f "0x00000001"
1018 # chown do not put the file dirty
1019 chown $RUNAS_ID $f || error "could not chown test file"
1020 check_hsm_flags $f "0x00000001"
1022 # truncate put the file dirty
1023 $TRUNCATE $f 1 || error "could not truncate test file"
1024 check_hsm_flags $f "0x00000003"
1026 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1027 check_hsm_flags $f "0x00000001"
1029 run_test 2 "Check file dirtyness when doing setattr"
1035 # New files are not dirty
1036 cp -p /etc/passwd $f
1037 check_hsm_flags $f "0x00000000"
1039 # For test, we simulate an archived file.
1040 $LFS hsm_set --exists $f ||
1041 error "user could not change hsm flags"
1042 check_hsm_flags $f "0x00000001"
1044 # Reading a file, does not set dirty
1045 cat $f > /dev/null || error "could not read file"
1046 check_hsm_flags $f "0x00000001"
1048 # Open for write without modifying data, does not set dirty
1049 openfile -f O_WRONLY $f || error "could not open test file"
1050 check_hsm_flags $f "0x00000001"
1052 # Append to a file sets it dirty
1053 cp -p /etc/passwd $f.append || error "could not create file"
1054 $LFS hsm_set --exists $f.append ||
1055 error "user could not change hsm flags"
1056 dd if=/etc/passwd of=$f.append bs=1 count=3\
1057 conv=notrunc oflag=append status=noxfer ||
1058 file_creation_failure dd $f.append $?
1059 check_hsm_flags $f.append "0x00000003"
1061 # Modify a file sets it dirty
1062 cp -p /etc/passwd $f.modify || error "could not create file"
1063 $LFS hsm_set --exists $f.modify ||
1064 error "user could not change hsm flags"
1065 dd if=/dev/zero of=$f.modify bs=1 count=3\
1066 conv=notrunc status=noxfer ||
1067 file_creation_failure dd $f.modify $?
1068 check_hsm_flags $f.modify "0x00000003"
1070 # Open O_TRUNC sets dirty
1071 cp -p /etc/passwd $f.trunc || error "could not create file"
1072 $LFS hsm_set --exists $f.trunc ||
1073 error "user could not change hsm flags"
1074 cp /etc/group $f.trunc || error "could not override a file"
1075 check_hsm_flags $f.trunc "0x00000003"
1077 # Mmapped a file sets dirty
1078 cp -p /etc/passwd $f.mmap || error "could not create file"
1079 $LFS hsm_set --exists $f.mmap ||
1080 error "user could not change hsm flags"
1081 multiop $f.mmap OSMWUc || error "could not mmap a file"
1082 check_hsm_flags $f.mmap "0x00000003"
1084 run_test 3 "Check file dirtyness when opening for write"
1088 local f=$DIR/$tdir/$tfile
1089 local fid=$(make_small $f)
1092 local st=$(get_request_state $fid CANCEL)
1093 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1095 run_test 4 "Useless cancel must not be registered"
1098 # test needs a running copytool
1102 local f=$DIR/$tdir/$tfile
1103 local fid=$(copy_file /etc/passwd $f)
1105 wait_request_state $fid ARCHIVE SUCCEED
1107 check_hsm_flags $f "0x00000009"
1111 run_test 8 "Test default archive number"
1114 # we do not use the default one to be sure
1115 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1117 copytool_setup $SINGLEAGT $MOUNT $new_an
1119 # give time for CT to register with MDTs
1120 sleep $(($MDSCOUNT*2))
1121 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1122 check_agent_registered $uuid
1125 local f=$DIR/$tdir/$tfile
1126 local fid=$(copy_file /etc/passwd $f)
1127 $LFS hsm_archive --archive $new_an $f
1128 wait_request_state $fid ARCHIVE SUCCEED
1130 check_hsm_flags $f "0x00000009"
1134 run_test 9 "Use of explicit archive number, with dedicated copytool"
1137 needclients 3 || return 0
1143 copytool_cleanup $(comma_list $(agts_nodes))
1145 # start all of the copytools
1146 for n in $(seq $AGTCOUNT); do
1147 copytool_setup agt$n
1150 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1153 for n in $(seq $AGTCOUNT); do
1154 file=$DIR/$tdir/$tfile.$n
1155 fid=$(make_small $file)
1157 $LFS hsm_archive $file || error "could not archive file $file"
1158 wait_request_state $fid ARCHIVE SUCCEED
1159 check_hsm_flags $file "0x00000009"
1163 copytool_cleanup $(comma_list $(agts_nodes))
1165 run_test 9a "Multiple remote agents"
1168 # test needs a running copytool
1171 mkdir -p $DIR/$tdir/d1
1172 local f=$DIR/$tdir/$tfile
1173 local fid=$(copy_file /etc/hosts $f)
1174 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1175 error "hsm_archive failed"
1176 wait_request_state $fid ARCHIVE SUCCEED
1178 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1179 error "fid $fid not in archive $HSM_ARCHIVE"
1180 echo "Verifying content"
1181 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1182 echo "Verifying hsm state "
1183 check_hsm_flags $f "0x00000009"
1185 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1186 local st=$(get_hsm_archive_id $f)
1187 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1188 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1193 run_test 10a "Archive a file"
1196 # test needs a running copytool
1200 local f=$DIR/$tdir/$tfile
1201 local fid=$(copy_file /etc/hosts $f)
1202 $LFS hsm_archive $f || error "archive request failed"
1203 wait_request_state $fid ARCHIVE SUCCEED
1205 $LFS hsm_archive $f || error "archive of non dirty file failed"
1206 local cnt=$(get_request_count $fid ARCHIVE)
1207 [[ "$cnt" == "1" ]] ||
1208 error "archive of non dirty file must not make a request"
1212 run_test 10b "Archive of non dirty file must work without doing request"
1215 # test needs a running copytool
1219 local f=$DIR/$tdir/$tfile
1220 local fid=$(copy_file /etc/hosts $f)
1221 $LFS hsm_set --noarchive $f
1222 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1226 run_test 10c "Check forbidden archive"
1229 # test needs a running copytool
1233 local f=$DIR/$tdir/$tfile
1234 local fid=$(copy_file /etc/hosts $f)
1235 $LFS hsm_archive $f || error "cannot archive $f"
1236 wait_request_state $fid ARCHIVE SUCCEED
1238 local ar=$(get_hsm_archive_id $f)
1239 local dflt=$(get_hsm_param default_archive_id)
1240 [[ $ar == $dflt ]] ||
1241 error "archived file is not on default archive: $ar != $dflt"
1245 run_test 10d "Archive a file on the default archive id"
1249 copy2archive /etc/hosts $tdir/$tfile
1250 local f=$DIR/$tdir/$tfile
1252 import_file $tdir/$tfile $f
1253 echo -n "Verifying released state: "
1254 check_hsm_flags $f "0x0000000d"
1256 local LSZ=$(stat -c "%s" $f)
1257 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1259 echo "Verifying imported size $LSZ=$ASZ"
1260 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1261 echo -n "Verifying released pattern: "
1262 local PTRN=$($GETSTRIPE -L $f)
1264 [[ $PTRN == 80000001 ]] || error "Is not released"
1265 local fid=$(path2fid $f)
1266 echo "Verifying new fid $fid in archive"
1268 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1269 error "fid $fid not in archive $HSM_ARCHIVE"
1271 run_test 11a "Import a file"
1274 # test needs a running copytool
1278 local f=$DIR/$tdir/$tfile
1279 local fid=$(copy_file /etc/hosts $f)
1280 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1281 error "hsm_archive failed"
1282 wait_request_state $fid ARCHIVE SUCCEED
1284 local FILE_HASH=$(md5sum $f)
1289 echo "$FILE_HASH" | md5sum -c
1291 [[ $? -eq 0 ]] || error "Restored file differs"
1295 run_test 11b "Import a deleted file using its FID"
1298 # test needs a running copytool
1302 copy2archive /etc/hosts $tdir/$tfile
1304 local f=$DIR/$tdir/$tfile
1305 import_file $tdir/$tfile $f
1306 local f2=$DIR2/$tdir/$tfile
1307 echo "Verifying released state: "
1308 check_hsm_flags $f2 "0x0000000d"
1310 local fid=$(path2fid $f2)
1311 $LFS hsm_restore $f2
1312 wait_request_state $fid RESTORE SUCCEED
1314 echo "Verifying file state: "
1315 check_hsm_flags $f2 "0x00000009"
1317 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1319 [[ $? -eq 0 ]] || error "Restored file differs"
1323 run_test 12a "Restore an imported file explicitly"
1326 # test needs a running copytool
1330 copy2archive /etc/hosts $tdir/$tfile
1332 local f=$DIR/$tdir/$tfile
1333 import_file $tdir/$tfile $f
1334 echo "Verifying released state: "
1335 check_hsm_flags $f "0x0000000d"
1337 cat $f > /dev/null || error "File read failed"
1339 echo "Verifying file state after restore: "
1340 check_hsm_flags $f "0x00000009"
1342 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1344 [[ $? -eq 0 ]] || error "Restored file differs"
1348 run_test 12b "Restore an imported file implicitly"
1351 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1353 # test needs a running copytool
1357 local f=$DIR/$tdir/$tfile
1358 $LFS setstripe -c 2 $f
1360 fid=$(make_custom_file_for_progress $f 5)
1361 [ $? != 0 ] && skip "not enough free space" && return
1363 local FILE_CRC=$(md5sum $f)
1365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1366 wait_request_state $fid ARCHIVE SUCCEED
1367 $LFS hsm_release $f || error "release $f failed"
1369 echo "$FILE_CRC" | md5sum -c
1371 [[ $? -eq 0 ]] || error "Restored file differs"
1375 run_test 12c "Restore a file with stripe of 2"
1378 # test needs a running copytool
1383 local f=$DIR/$tdir/$tfile
1384 local fid=$(copy_file /etc/hosts $f)
1385 $LFS hsm_restore $f || error "restore of non archived file failed"
1386 local cnt=$(get_request_count $fid RESTORE)
1387 [[ "$cnt" == "0" ]] ||
1388 error "restore non archived must not make a request"
1389 $LFS hsm_archive $f ||
1390 error "archive request failed"
1391 wait_request_state $fid ARCHIVE SUCCEED
1392 $LFS hsm_restore $f ||
1393 error "restore of non released file failed"
1394 local cnt=$(get_request_count $fid RESTORE)
1395 [[ "$cnt" == "0" ]] ||
1396 error "restore a non dirty file must not make a request"
1400 run_test 12d "Restore of a non archived, non released file must work"\
1401 " without doing request"
1404 # test needs a running copytool
1407 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(copy_file /etc/hosts $f)
1410 $LFS hsm_archive $f || error "archive request failed"
1411 wait_request_state $fid ARCHIVE SUCCEED
1414 cat /etc/hosts >> $f
1418 $LFS hsm_restore $f && error "restore a dirty file must fail"
1422 run_test 12e "Check forbidden restore"
1425 # test needs a running copytool
1429 local f=$DIR/$tdir/$tfile
1430 local fid=$(copy_file /etc/hosts $f)
1432 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1433 wait_request_state $fid ARCHIVE SUCCEED
1434 $LFS hsm_release $f || error "release of $f failed"
1436 wait_request_state $fid RESTORE SUCCEED
1438 echo -n "Verifying file state: "
1439 check_hsm_flags $f "0x00000009"
1441 diff -q /etc/hosts $f
1443 [[ $? -eq 0 ]] || error "Restored file differs"
1447 run_test 12f "Restore a released file explicitly"
1450 # test needs a running copytool
1454 local f=$DIR/$tdir/$tfile
1455 local fid=$(copy_file /etc/hosts $f)
1457 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1458 wait_request_state $fid ARCHIVE SUCCEED
1459 $LFS hsm_release $f || error "release of $f failed"
1461 diff -q /etc/hosts $f
1464 # we check we had a restore done
1465 wait_request_state $fid RESTORE SUCCEED
1467 [[ $st -eq 0 ]] || error "Restored file differs"
1471 run_test 12g "Restore a released file implicitly"
1474 needclients 2 || return 0
1476 # test needs a running copytool
1480 local f=$DIR/$tdir/$tfile
1481 local fid=$(copy_file /etc/hosts $f)
1483 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1484 wait_request_state $fid ARCHIVE SUCCEED
1485 $LFS hsm_release $f || error "release of $f failed"
1487 do_node $CLIENT2 diff -q /etc/hosts $f
1490 # we check we had a restore done
1491 wait_request_state $fid RESTORE SUCCEED
1493 [[ $st -eq 0 ]] || error "Restored file differs"
1497 run_test 12h "Restore a released file implicitly from a second node"
1500 # test needs a running copytool
1504 local f=$DIR/$tdir/$tfile
1505 local fid=$(copy_file /etc/passwd $f)
1506 $LFS hsm_archive $f || error "archive of $f failed"
1507 wait_request_state $fid ARCHIVE SUCCEED
1509 $LFS hsm_release $f || error "release of $f failed"
1513 [[ $? -eq 0 ]] || error "Restored file differs"
1517 run_test 12m "Archive/release/implicit restore"
1520 # test needs a running copytool
1524 copy2archive /etc/hosts $tdir/$tfile
1526 local f=$DIR/$tdir/$tfile
1527 import_file $tdir/$tfile $f
1529 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1530 error "Restored file differs"
1532 $LFS hsm_release $f || error "release of $f failed"
1536 run_test 12n "Import/implicit restore/release"
1539 # test needs a running copytool
1543 local f=$DIR/$tdir/$tfile
1544 local fid=$(copy_file /etc/hosts $f)
1546 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1547 wait_request_state $fid ARCHIVE SUCCEED
1548 $LFS hsm_release $f || error "release of $f failed"
1550 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1551 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1553 # set no retry action mode
1556 diff -q /etc/hosts $f
1559 # we check we had a restore failure
1560 wait_request_state $fid RESTORE FAILED
1562 [[ $st -eq 0 ]] && error "Restore must fail"
1564 # remove no retry action mode
1567 # check file is still released
1568 check_hsm_flags $f "0x0000000d"
1570 # retry w/o failure injection
1571 do_facet $SINGLEMDS lctl set_param fail_loc=0
1573 # to be sure previous RESTORE result is gone
1575 wait_for_grace_delay
1577 diff -q /etc/hosts $f
1580 # we check we had a restore done
1581 wait_request_state $fid RESTORE SUCCEED
1583 [[ $st -eq 0 ]] || error "Restored file differs"
1587 run_test 12o "Layout-swap failure during Restore leaves file released"
1590 # test needs a running copytool
1594 local f=$DIR/$tdir/$tfile
1595 local fid=$(copy_file /etc/hosts $f)
1597 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1598 wait_request_state $fid ARCHIVE SUCCEED
1599 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1600 $LFS hsm_release $f || error "cannot release $f"
1601 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1602 $LFS hsm_release $f || error "cannot release $f"
1603 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1607 run_test 12p "implicit restore of a file on copytool mount point"
1609 cleanup_test_12q() {
1611 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1612 error "cannot umount $MOUNT3 on $SINGLEAGT"
1616 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1617 skip "need MDS version at least 2.7.58" && return 0
1619 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1620 error "cannot mount $MOUNT3 on $SINGLEAGT"
1622 trap cleanup_test_12q EXIT
1624 # test needs a running copytool
1625 copytool_setup $SINGLEAGT $MOUNT3
1628 local f=$DIR/$tdir/$tfile
1629 local f2=$DIR2/$tdir/$tfile
1630 local fid=$(make_small $f)
1631 local orig_size=$(stat -c "%s" $f)
1633 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1634 wait_request_state $fid ARCHIVE SUCCEED
1636 $LFS hsm_release $f || error "could not release file"
1637 check_hsm_flags $f "0x0000000d"
1640 wait_copytools || error "copytool failed to stop"
1642 cat $f > /dev/null &
1644 # wait a bit to allow implicit restore request to be handled.
1645 # if not, next stat would also block on layout-lock.
1648 local size=$(stat -c "%s" $f2)
1649 [ $size -eq $orig_size ] ||
1650 error "$f2: wrong size after archive: $size != $orig_size"
1652 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1656 size=$(stat -c "%s" $f)
1657 [ $size -eq $orig_size ] ||
1658 error "$f: wrong size after restore: $size != $orig_size"
1660 size=$(stat -c "%s" $f2)
1661 [ $size -eq $orig_size ] ||
1662 error "$f2: wrong size after restore: $size != $orig_size"
1666 size=$(stat -c "%s" $f)
1668 error "$f: wrong size after overwrite: $size != 0"
1670 size=$(stat -c "%s" $f2)
1672 error "$f2: wrong size after overwrite: $size != 0"
1675 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1676 error "cannot umount $MOUNT3 on $SINGLEAGT"
1678 run_test 12q "file attributes are refreshed after restore"
1681 # test needs a running copytool
1684 local ARC_SUBDIR="import.orig"
1688 # populate directory to be imported
1689 for d in $(seq 1 10); do
1690 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1691 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1692 for f in $(seq 1 10); do
1693 CURR_FILE="$CURR_DIR/$tfile.$f"
1694 # write file-specific data
1695 do_facet $SINGLEAGT \
1696 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1697 "file=$CURR_FILE > $CURR_FILE"
1701 import_file "$ARC_SUBDIR" $DIR/$tdir
1702 # diff lustre content and origin (triggers file restoration)
1703 # there must be 10x10 identical files, and no difference
1704 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1705 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1706 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1707 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1709 [ $cnt_diff -eq 0 ] ||
1710 error "$cnt_diff imported files differ from read data"
1711 [ $cnt_ok -eq 100 ] ||
1712 error "not enough identical files ($cnt_ok != 100)"
1716 run_test 13 "Recursively import and restore a directory"
1719 # test needs a running copytool
1724 local f=$DIR/$tdir/$tfile
1725 local fid=$(make_small $f)
1726 local sum=$(md5sum $f | awk '{print $1}')
1727 $LFS hsm_archive $f || error "could not archive file"
1728 wait_request_state $fid ARCHIVE SUCCEED
1732 # create released file (simulate llapi_hsm_import call)
1734 local fid2=$(path2fid $f)
1735 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1736 $LFS hsm_release $f || error "could not release file"
1738 # rebind the archive to the newly created file
1739 echo "rebind $fid to $fid2"
1741 do_facet $SINGLEAGT \
1742 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1743 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1745 # restore file and compare md5sum
1746 local sum2=$(md5sum $f | awk '{print $1}')
1748 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1752 run_test 14 "Rebind archived file to a new fid"
1755 # test needs a running copytool
1760 local f=$DIR/$tdir/$tfile
1762 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1766 for i in $(seq 1 $count); do
1767 fids[$i]=$(make_small $f.$i)
1768 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1769 $LFS hsm_archive $f.$i || error "could not archive file"
1771 wait_all_done $(($count*60))
1775 for i in $(seq 1 $count); do
1778 local fid2=$(path2fid $f.$i)
1779 # add the rebind operation to the list
1780 echo ${fids[$i]} $fid2 >> $tmpfile
1782 # set it released (simulate llapi_hsm_import call)
1783 $LFS hsm_set --archived --exists $f.$i ||
1784 error "could not force hsm flags"
1785 $LFS hsm_release $f.$i || error "could not release file"
1787 nl=$(wc -l < $tmpfile)
1788 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1790 echo "rebind list of files"
1791 do_facet $SINGLEAGT \
1792 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1793 --rebind $tmpfile $DIR" || error "could not rebind file list"
1795 # restore files and compare md5sum
1796 for i in $(seq 1 $count); do
1797 local sum2=$(md5sum $f.$i | awk '{print $1}')
1798 [[ $sum2 == ${sums[$i]} ]] ||
1799 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1805 run_test 15 "Rebind a list of files"
1808 # test needs a running copytool
1812 # create a known size file so we can verify transfer speed
1815 dd if=/dev/zero of=$ref bs=1M count=20
1818 local f=$DIR/$tdir/$tfile
1819 local fid=$(copy_file $ref $f)
1821 local start=$(date +%s)
1823 wait_request_state $fid ARCHIVE SUCCEED
1824 local end=$(date +%s)
1825 # Add 1 to account for rounding errors between start and end (LU-8155)
1826 local duration=$((end - start + 1))
1828 [[ $duration -ge $((goal - 1)) ]] ||
1829 error "Transfer is too fast $duration < $goal"
1833 run_test 16 "Test CT bandwith control option"
1838 local f=$DIR/$tdir/$tfile
1839 touch $f || error "touch $f failed"
1841 # Could not release a non-archived file
1842 $LFS hsm_release $f && error "release should not succeed"
1844 # For following tests, we must test them with HS_ARCHIVED set
1845 $LFS hsm_set --exists --archived $f || error "could not add flag"
1847 # Could not release a file if no-release is set
1848 $LFS hsm_set --norelease $f || error "could not add flag"
1849 $LFS hsm_release $f && error "release should not succeed"
1850 $LFS hsm_clear --norelease $f || error "could not remove flag"
1852 # Could not release a file if lost
1853 $LFS hsm_set --lost $f || error "could not add flag"
1854 $LFS hsm_release $f && error "release should not succeed"
1855 $LFS hsm_clear --lost $f || error "could not remove flag"
1857 # Could not release a file if dirty
1858 $LFS hsm_set --dirty $f || error "could not add flag"
1859 $LFS hsm_release $f && error "release should not succeed"
1860 $LFS hsm_clear --dirty $f || error "could not remove flag"
1862 run_test 20 "Release is not permitted"
1865 # test needs a running copytool
1869 local f=$DIR/$tdir/test_release
1871 # Create a file and check its states
1872 local fid=$(make_small $f)
1873 check_hsm_flags $f "0x00000000"
1875 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1876 # used until file is flushed to disk
1877 if [ $(facet_fstype ost1) == "zfs" ]; then
1878 # this causes an OST_SYNC rpc to be sent
1879 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1880 # clear locks to reread file data
1881 cancel_lru_locks osc
1884 local orig_size=$(stat -c "%s" $f)
1885 local orig_blocks=$(stat -c "%b" $f)
1887 start_full_debug_logging
1889 $LFS hsm_archive $f || error "could not archive file"
1890 wait_request_state $fid ARCHIVE SUCCEED
1892 local blocks=$(stat -c "%b" $f)
1893 [ $blocks -eq $orig_blocks ] ||
1894 error "$f: wrong block number after archive: " \
1895 "$blocks != $orig_blocks"
1896 local size=$(stat -c "%s" $f)
1897 [ $size -eq $orig_size ] ||
1898 error "$f: wrong size after archive: $size != $orig_size"
1900 # Release and check states
1901 $LFS hsm_release $f || error "could not release file"
1902 check_hsm_flags $f "0x0000000d"
1904 blocks=$(stat -c "%b" $f)
1905 [ $blocks -gt 5 ] &&
1906 error "$f: too many blocks after release: $blocks > 5"
1907 size=$(stat -c "%s" $f)
1908 [ $size -ne $orig_size ] &&
1909 error "$f: wrong size after release: $size != $orig_size"
1911 # Check we can release an file without stripe info
1915 check_hsm_flags $f "0x00000000"
1916 $LFS hsm_archive $f || error "could not archive file"
1917 wait_request_state $fid ARCHIVE SUCCEED
1919 # Release and check states
1920 $LFS hsm_release $f || error "could not release file"
1921 check_hsm_flags $f "0x0000000d"
1923 # Release again a file that is already released is OK
1924 $LFS hsm_release $f || fail "second release should succeed"
1925 check_hsm_flags $f "0x0000000d"
1927 stop_full_debug_logging
1931 run_test 21 "Simple release tests"
1934 # test needs a running copytool
1939 local f=$DIR/$tdir/test_release
1940 local swap=$DIR/$tdir/test_swap
1942 # Create a file and check its states
1943 local fid=$(make_small $f)
1944 check_hsm_flags $f "0x00000000"
1946 $LFS hsm_archive $f || error "could not archive file"
1947 wait_request_state $fid ARCHIVE SUCCEED
1949 # Release and check states
1950 $LFS hsm_release $f || error "could not release file"
1951 check_hsm_flags $f "0x0000000d"
1954 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1959 run_test 22 "Could not swap a release file"
1962 # test needs a running copytool
1967 local f=$DIR/$tdir/test_mtime
1969 # Create a file and check its states
1970 local fid=$(make_small $f)
1971 check_hsm_flags $f "0x00000000"
1973 $LFS hsm_archive $f || error "could not archive file"
1974 wait_request_state $fid ARCHIVE SUCCEED
1976 # Set modification time in the past
1977 touch -m -a -d @978261179 $f
1979 # Release and check states
1980 $LFS hsm_release $f || error "could not release file"
1981 check_hsm_flags $f "0x0000000d"
1983 local MTIME=$(stat -c "%Y" $f)
1984 local ATIME=$(stat -c "%X" $f)
1985 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1986 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1990 run_test 23 "Release does not change a/mtime (utime)"
1993 local file=$DIR/$tdir/$tfile
2002 # test needs a running copytool
2007 fid=$(make_small $file)
2009 # Create a file and check its states
2010 check_hsm_flags $file "0x00000000"
2012 # Ensure atime is less than mtime and ctime.
2016 atime0=$(stat -c "%X" $file)
2017 mtime0=$(stat -c "%Y" $file)
2018 ctime0=$(stat -c "%Z" $file)
2020 [ $atime0 -lt $mtime0 ] ||
2021 error "atime $atime0 is not less than mtime $mtime0"
2023 [ $atime0 -lt $ctime0 ] ||
2024 error "atime $atime0 is not less than ctime $ctime0"
2026 # Archive should not change any timestamps.
2027 $LFS hsm_archive $file || error "cannot archive '$file'"
2028 wait_request_state $fid ARCHIVE SUCCEED
2030 atime1=$(stat -c "%X" $file)
2031 mtime1=$(stat -c "%Y" $file)
2032 ctime1=$(stat -c "%Z" $file)
2034 [ $atime0 -eq $atime1 ] ||
2035 error "archive changed atime from $atime0 to $atime1"
2037 [ $mtime0 -eq $mtime1 ] ||
2038 error "archive changed mtime from $mtime0 to $mtime1"
2040 [ $ctime0 -eq $ctime1 ] ||
2041 error "archive changed ctime from $ctime0 to $ctime1"
2043 # Release should not change any timestamps.
2044 $LFS hsm_release $file || error "cannot release '$file'"
2045 check_hsm_flags $file "0x0000000d"
2047 atime1=$(stat -c "%X" $file)
2048 mtime1=$(stat -c "%Y" $file)
2049 ctime1=$(stat -c "%Z" $file)
2051 [ $atime0 -eq $atime1 ] ||
2052 error "release changed atime from $atime0 to $atime1"
2054 [ $mtime0 -eq $mtime1 ] ||
2055 error "release changed mtime from $mtime0 to $mtime1"
2057 [ $ctime0 -eq $ctime1 ] ||
2058 error "release changed ctime from $ctime0 to $ctime1"
2060 # Restore should not change any timestamps.
2061 $LFS hsm_restore $file
2062 wait_request_state $fid RESTORE SUCCEED
2064 atime1=$(stat -c "%X" $file)
2065 mtime1=$(stat -c "%Y" $file)
2066 ctime1=$(stat -c "%Z" $file)
2068 [ $atime0 -eq $atime1 ] ||
2069 error "restore changed atime from $atime0 to $atime1"
2071 [ $mtime0 -eq $mtime1 ] ||
2072 error "restore changed mtime from $mtime0 to $mtime1"
2074 [ $ctime0 -eq $ctime1 ] ||
2075 error "restore changed ctime from $ctime0 to $ctime1"
2079 # Once more, after unmount and mount.
2080 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2081 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2083 atime1=$(stat -c "%X" $file)
2084 mtime1=$(stat -c "%Y" $file)
2085 ctime1=$(stat -c "%Z" $file)
2087 [ $atime0 -eq $atime1 ] ||
2088 error "remount changed atime from $atime0 to $atime1"
2090 [ $mtime0 -eq $mtime1 ] ||
2091 error "remount changed mtime from $mtime0 to $mtime1"
2093 [ $ctime0 -eq $ctime1 ] ||
2094 error "remount changed ctime from $ctime0 to $ctime1"
2096 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2099 local file=$DIR/$tdir/$tfile
2105 # Test needs a running copytool.
2109 # Check that root can do HSM actions on a regular user's file.
2111 fid=$(make_small $file)
2112 sum0=$(md5sum $file)
2114 chown $RUNAS_ID:$RUNAS_GID $file ||
2115 error "cannot chown '$file' to '$RUNAS_ID'"
2117 chmod ugo-w $DIR/$tdir ||
2118 error "cannot chmod '$DIR/$tdir'"
2120 $LFS hsm_archive $file
2121 wait_request_state $fid ARCHIVE SUCCEED
2123 $LFS hsm_release $file
2124 check_hsm_flags $file "0x0000000d"
2126 $LFS hsm_restore $file
2127 wait_request_state $fid RESTORE SUCCEED
2129 # Check that ordinary user can get HSM state.
2130 $RUNAS $LFS hsm_state $file ||
2131 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2133 $LFS hsm_release $file
2134 check_hsm_flags $file "0x0000000d"
2136 # Check that ordinary user can accessed released file.
2137 sum1=$($RUNAS md5sum $file) ||
2138 error "user '$RUNAS_ID' cannot read '$file'"
2140 [ "$sum0" == "$sum1" ] ||
2141 error "md5sum mismatch for '$file'"
2145 run_test 24b "root can archive, release, and restore user files"
2147 cleanup_test_24c() {
2149 set_hsm_param user_request_mask RESTORE
2150 set_hsm_param group_request_mask RESTORE
2151 set_hsm_param other_request_mask RESTORE
2155 local file=$DIR/$tdir/$tfile
2156 local action=archive
2161 # test needs a running copytool
2166 # Save the default masks and check that cleanup_24c will
2167 # restore the request masks correctly.
2168 user_save=$(get_hsm_param user_request_mask)
2169 group_save=$(get_hsm_param group_request_mask)
2170 other_save=$(get_hsm_param other_request_mask)
2172 [ "$user_save" == RESTORE ] ||
2173 error "user_request_mask is '$user_save' expected 'RESTORE'"
2174 [ "$group_save" == RESTORE ] ||
2175 error "group_request_mask is '$group_save' expected 'RESTORE'"
2176 [ "$other_save" == RESTORE ] ||
2177 error "other_request_mask is '$other_save' expected 'RESTORE'"
2179 trap cleanup_test_24c EXIT
2184 chown $RUNAS_ID:$GROUP $file ||
2185 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2187 $RUNAS $LFS hsm_$action $file &&
2188 error "$action by user should fail"
2190 set_hsm_param user_request_mask $action
2191 $RUNAS $LFS hsm_$action $file ||
2192 error "$action by user should succeed"
2197 chown nobody:$RUNAS_GID $file ||
2198 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2200 $RUNAS $LFS hsm_$action $file &&
2201 error "$action by group should fail"
2203 set_hsm_param group_request_mask $action
2204 $RUNAS $LFS hsm_$action $file ||
2205 error "$action by group should succeed"
2210 chown nobody:$GROUP $file ||
2211 error "cannot chown '$file' to 'nobody:$GROUP'"
2213 $RUNAS $LFS hsm_$action $file &&
2214 error "$action by other should fail"
2216 set_hsm_param other_request_mask $action
2217 $RUNAS $LFS hsm_$action $file ||
2218 error "$action by other should succeed"
2223 run_test 24c "check that user,group,other request masks work"
2225 cleanup_test_24d() {
2226 mount -o remount,rw $MOUNT2
2227 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2231 local file1=$DIR/$tdir/$tfile
2232 local file2=$DIR2/$tdir/$tfile
2238 fid1=$(make_small $file1)
2241 $LFS getstripe $file1
2243 trap cleanup_test_24d EXIT
2244 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2245 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2246 copytool_setup $SINGLEAGT "$MOUNT3" ||
2247 error "unable to setup a copytool for the test"
2249 mount -o remount,ro $MOUNT2
2251 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2253 fid2=$(path2fid $file2)
2254 [ "$fid1" == "$fid2" ] ||
2255 error "FID mismatch '$fid1' != '$fid2'"
2257 $LFS hsm_archive $file2 &&
2258 error "archive should fail on read-only mount"
2259 check_hsm_flags $file1 "0x00000000"
2261 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2262 wait_request_state $fid1 ARCHIVE SUCCEED
2264 $LFS hsm_release $file1
2265 $LFS hsm_restore $file2
2266 wait_request_state $fid1 RESTORE SUCCEED
2268 $LFS hsm_release $file1 || error "cannot release '$file1'"
2269 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2271 $LFS hsm_release $file2 &&
2272 error "release should fail on read-only mount"
2276 run_test 24d "check that read-only mounts are respected"
2283 local f=$DIR/$tdir/$tfile
2286 fid=$(make_small $f) || error "cannot create $f"
2287 $LFS hsm_archive $f || error "cannot archive $f"
2288 wait_request_state $fid ARCHIVE SUCCEED
2289 $LFS hsm_release $f || error "cannot release $f"
2290 while ! $LFS hsm_state $f | grep released; do
2294 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2298 run_test 24e "tar succeeds on HSM released files" # LU-6213
2302 # test needs a running copytool
2305 mkdir -p $DIR/$tdir/d1
2306 local f=$DIR/$tdir/$tfile
2307 local fid=$(copy_file /etc/hosts $f)
2310 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2311 error "hsm_archive failed"
2312 wait_request_state $fid ARCHIVE SUCCEED
2313 $LFS hsm_release $f || error "cannot release $f"
2314 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2317 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2318 error "Can not recover the tar contents"
2320 echo "Sum0 = $sum0, sum1 = $sum1"
2321 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2325 run_test 24f "root can archive, release, and restore tar files"
2328 # test needs a running copytool
2332 copy2archive /etc/hosts $tdir/$tfile
2334 local f=$DIR/$tdir/$tfile
2336 import_file $tdir/$tfile $f
2338 $LFS hsm_set --lost $f
2343 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2347 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2348 " (Operation not permitted)"
2351 # test needs a running copytool
2356 local f=$DIR/$tdir/$tfile
2357 local fid=$(copy_file /etc/passwd $f)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2360 wait_request_state $fid ARCHIVE SUCCEED
2363 $LFS hsm_set --lost $f
2367 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2371 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2372 " (Operation not permitted)"
2375 # test needs a running copytool
2379 local f=$DIR/$tdir/$tfile
2381 fid=$(make_custom_file_for_progress $f 39 1000000)
2382 [ $? != 0 ] && skip "not enough free space" && return
2384 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2385 wait_request_state $fid ARCHIVE SUCCEED
2388 wait_request_state $fid REMOVE SUCCEED
2390 check_hsm_flags $f "0x00000000"
2394 run_test 26 "Remove the archive of a valid file"
2396 cleanup_test_26a() {
2398 set_hsm_param remove_archive_on_last_unlink 0
2399 set_hsm_param loop_period $orig_loop_period
2400 set_hsm_param grace_delay $orig_grace_delay
2405 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2406 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2408 # test needs a running copytool
2412 local f=$DIR/$tdir/$tfile
2413 local fid=$(copy_file /etc/passwd $f)
2415 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2416 wait_request_state $fid ARCHIVE SUCCEED
2418 local f2=$DIR/$tdir/${tfile}_2
2419 local fid2=$(copy_file /etc/passwd $f2)
2421 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2422 wait_request_state $fid2 ARCHIVE SUCCEED
2424 local f3=$DIR/$tdir/${tfile}_3
2425 local fid3=$(copy_file /etc/passwd $f3)
2427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2428 wait_request_state $fid3 ARCHIVE SUCCEED
2430 trap cleanup_test_26a EXIT
2432 # set a long grace_delay vs short loop_period
2433 local orig_loop_period=$(get_hsm_param loop_period)
2434 local orig_grace_delay=$(get_hsm_param grace_delay)
2435 set_hsm_param loop_period 10
2436 set_hsm_param grace_delay 100
2440 set_hsm_param remove_archive_on_last_unlink 1
2442 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2447 set_hsm_param remove_archive_on_last_unlink 0
2449 wait_request_state $fid2 REMOVE SUCCEED
2451 assert_request_count $fid REMOVE 0 \
2452 "Unexpected archived data remove request for $f"
2453 assert_request_count $fid3 REMOVE 0 \
2454 "Unexpected archived data remove request for $f3"
2458 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2460 cleanup_test_26b() {
2462 set_hsm_param remove_archive_on_last_unlink 0
2468 # test needs a running copytool
2472 local f=$DIR/$tdir/$tfile
2473 local fid=$(copy_file /etc/passwd $f)
2475 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2476 wait_request_state $fid ARCHIVE SUCCEED
2478 trap cleanup_test_26b EXIT
2480 set_hsm_param remove_archive_on_last_unlink 1
2483 cdt_check_state stopped
2487 set_hsm_param remove_archive_on_last_unlink 0
2489 wait_request_state $fid REMOVE WAITING
2492 # copytool must re-register
2494 wait_copytools || error "copytool failed to stop"
2495 HSM_ARCHIVE_PURGE=false copytool_setup
2497 wait_request_state $fid REMOVE SUCCEED
2501 run_test 26b "RAoLU policy when CDT off"
2503 cleanup_test_26c() {
2505 set_hsm_param remove_archive_on_last_unlink 0
2506 set_hsm_param loop_period $orig_loop_period
2507 set_hsm_param grace_delay $orig_grace_delay
2513 # test needs a running copytool
2517 local f=$DIR/$tdir/$tfile
2518 local fid=$(copy_file /etc/passwd $f)
2520 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2521 wait_request_state $fid ARCHIVE SUCCEED
2523 local f2=$DIR/$tdir/${tfile}_2
2524 local fid2=$(copy_file /etc/passwd $f2)
2526 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2527 wait_request_state $fid2 ARCHIVE SUCCEED
2529 trap cleanup_test_26c EXIT
2531 # set a long grace_delay vs short loop_period
2532 local orig_loop_period=$(get_hsm_param loop_period)
2533 local orig_grace_delay=$(get_hsm_param grace_delay)
2534 set_hsm_param loop_period 10
2535 set_hsm_param grace_delay 100
2537 set_hsm_param remove_archive_on_last_unlink 1
2539 multiop_bg_pause $f O_c || error "open $f failed"
2545 wait_request_state $fid2 REMOVE SUCCEED
2546 assert_request_count $fid REMOVE 0 \
2547 "Unexpected archived data remove request for $f"
2549 kill -USR1 $pid || error "multiop early exit"
2550 # should reach autotest timeout if multiop fails to trap
2551 # signal, close file, and exit ...
2554 set_hsm_param remove_archive_on_last_unlink 0
2556 wait_request_state $fid REMOVE SUCCEED
2560 run_test 26c "RAoLU effective when file closed"
2562 cleanup_test_26d() {
2564 set_hsm_param remove_archive_on_last_unlink 0
2565 set_hsm_param loop_period $orig_loop_period
2566 set_hsm_param grace_delay $orig_grace_delay
2572 # test needs a running copytool
2576 local f=$DIR/$tdir/$tfile
2577 local fid=$(copy_file /etc/motd $f 1)
2579 $LFS hsm_archive $f || error "could not archive file"
2580 wait_request_state $fid ARCHIVE SUCCEED
2582 trap cleanup_test_26d EXIT
2584 # set a long grace_delay vs short loop_period
2585 local orig_loop_period=$(get_hsm_param loop_period)
2586 local orig_grace_delay=$(get_hsm_param grace_delay)
2587 set_hsm_param loop_period 10
2588 set_hsm_param grace_delay 100
2590 set_hsm_param remove_archive_on_last_unlink 1
2592 multiop_bg_pause $f O_c || error "multiop failed"
2599 set_hsm_param remove_archive_on_last_unlink 0
2601 wait_request_state $fid REMOVE SUCCEED
2603 client_up || client_up || true
2605 kill -USR1 $MULTIPID
2606 wait $MULTIPID || error "multiop close failed"
2610 run_test 26d "RAoLU when Client eviction"
2613 # test needs a running copytool
2617 make_archive $tdir/$tfile
2618 local f=$DIR/$tdir/$tfile
2619 import_file $tdir/$tfile $f
2620 local fid=$(path2fid $f)
2624 [[ $? != 0 ]] || error "Remove of a released file should fail"
2628 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2631 # test needs a running copytool
2635 local f=$DIR/$tdir/$tfile
2637 fid=$(make_custom_file_for_progress $f 39 1000000)
2638 [ $? != 0 ] && skip "not enough free space" && return
2640 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2641 wait_request_state $fid ARCHIVE SUCCEED
2646 [[ $? != 0 ]] || error "Remove of a released file should fail"
2650 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2653 # test needs a running copytool
2657 local f=$DIR/$tdir/$tfile
2659 fid=$(make_custom_file_for_progress $f 39 1000000)
2660 [ $? != 0 ] && skip "not enough free space" && return
2662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2663 wait_request_state $fid ARCHIVE SUCCEED
2672 wait_request_state $fid REMOVE SUCCEED
2676 run_test 28 "Concurrent archive/file remove"
2679 # Tests --mntpath and --archive options
2682 copytool_setup $SINGLEAGT $MOUNT $archive_id
2684 # Bad archive number
2685 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2686 grep "Invalid argument" ||
2687 error "unexpected hsm_remove failure (1)"
2689 # mntpath is present but file is given
2690 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2691 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2692 error "unexpected hsm_remove failure (2)"
2696 run_test 29a "Tests --mntpath and --archive options"
2699 # test needs a running copytool
2703 local f=$DIR/$tdir/$tfile
2704 local fid=$(make_small $f)
2706 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2707 wait_request_state $fid ARCHIVE SUCCEED
2711 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2712 wait_request_state $fid REMOVE SUCCEED
2716 run_test 29b "Archive/delete/remove by FID from the archive."
2719 # test needs a running copytool
2723 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2724 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2725 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2728 wait_request_state $fid1 ARCHIVE SUCCEED
2729 wait_request_state $fid2 ARCHIVE SUCCEED
2730 wait_request_state $fid3 ARCHIVE SUCCEED
2732 rm -f $DIR/$tdir/$tfile-[1-3]
2734 echo $fid1 > $DIR/$tdir/list
2735 echo $fid2 >> $DIR/$tdir/list
2736 echo $fid3 >> $DIR/$tdir/list
2738 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2739 --filelist $DIR/$tdir/list
2740 wait_request_state $fid1 REMOVE SUCCEED
2741 wait_request_state $fid2 REMOVE SUCCEED
2742 wait_request_state $fid3 REMOVE SUCCEED
2746 run_test 29c "Archive/delete/remove by FID, using a file list."
2749 # test needs more than one CT
2750 needclients 3 || return 0
2756 copytool_cleanup $(comma_list $(agts_nodes))
2758 # start all of the copytools
2759 for n in $(seq $AGTCOUNT); do
2760 copytool_setup agt$n $MOUNT2 $n
2763 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2766 file=$DIR/$tdir/$tfile
2767 fid=$(make_small $file)
2769 $LFS hsm_archive $file
2770 wait_request_state $fid ARCHIVE SUCCEED
2771 check_hsm_flags $file "0x00000009"
2775 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2776 error "cannot hsm_remove '$fid'"
2778 # give time for CDT to handle remove request and create broadcasted
2781 # remove request has been broadcasted ?
2782 local cnt=$(get_request_count $fid REMOVE)
2783 # broadcasted requests + original
2784 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2785 error "remove not broadcasted to all CTs"
2787 # give time for CDT and CTs to handle broadcasted
2788 wait_for_loop_period
2790 # each agent serves one different archive_id, so broadcasted
2791 # hsm_remove request should only succeed once and fail at all others
2795 for n in $(seq $AGTCOUNT); do
2796 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2797 $HSM_PARAM.actions | awk \
2798 '/'$fid'.*action=REMOVE archive#='$n'/ \
2799 {print \\\$13}' | cut -f2 -d=")
2800 if [[ "$res" == "SUCCEED" ]]; then
2802 elif [[ "$res" == "FAILED" ]]; then
2807 [[ $scnt -ne 1 ]] &&
2808 error "one and only CT should have removed successfully"
2810 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2811 error "all but one CT should have failed to remove"
2814 copytool_cleanup $(comma_list $(agts_nodes))
2817 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2818 "request to be sent once for each registered archive_id"
2821 # restore at exec cannot work on agent node (because of Linux kernel
2822 # protection of executables)
2823 needclients 2 || return 0
2825 # test needs a running copytool
2829 copy2archive /bin/true $tdir/$tfile
2831 local f=$DIR/$tdir/true
2832 import_file $tdir/$tfile $f
2834 local fid=$(path2fid $f)
2836 # set no retry action mode
2842 # remove no try action mode
2846 [[ $st == 0 ]] || error "Failed to exec a released file"
2850 run_test 30a "Restore at exec (import case)"
2853 # restore at exec cannot work on agent node (because of Linux kernel
2854 # protection of executables)
2855 needclients 2 || return 0
2857 # test needs a running copytool
2861 local f=$DIR/$tdir/true
2862 local fid=$(copy_file /bin/true $f)
2864 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2865 wait_request_state $fid ARCHIVE SUCCEED
2868 # set no retry action mode
2874 # remove no try action mode
2878 [[ $st == 0 ]] || error "Failed to exec a released file"
2882 run_test 30b "Restore at exec (release case)"
2885 needclients 2 || return 0
2887 # test needs a running copytool
2891 local f=$DIR/$tdir/SLEEP
2892 local slp_sum1=$(md5sum /bin/sleep)
2893 local fid=$(copy_file /bin/sleep $f)
2895 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2896 wait_request_state $fid ARCHIVE SUCCEED
2898 check_hsm_flags $f "0x0000000d"
2899 # set no retry action mode
2901 do_node $CLIENT2 "$f 10" &
2905 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2907 [[ $? == 0 ]] || error "Execution failed during run"
2909 if [[ $? != 0 ]]; then
2910 local slp_sum2=$(md5sum /bin/sleep)
2911 # in case sleep file is modified during the test
2912 [[ $slp_sum1 == $slp_sum2 ]] &&
2913 error "Binary overwritten during exec"
2917 # remove no try action mode
2919 check_hsm_flags $f "0x00000009"
2923 run_test 30c "Update during exec of released file must fail"
2925 restore_and_check_size() {
2928 local s=$(stat -c "%s" $f)
2930 local st=$(get_hsm_flags $f)
2934 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2936 n=$(stat -c "%s" $f)
2937 # we echo in both cases to show stat is not hang
2938 if [[ $n != $s ]]; then
2939 echo "size seen is $n != $s"
2942 echo "size seen is right: $n == $s"
2946 st=$(get_hsm_flags $f)
2948 if [[ "$st" = "0x00000009" ]]; then
2951 echo " restore is too long"
2952 wait_request_state $fid RESTORE SUCCEED
2958 # test needs a running copytool
2963 make_archive $tdir/$tfile
2964 local f=$DIR/$tdir/$tfile
2965 import_file $tdir/$tfile $f
2966 local fid=$($LFS path2fid $f)
2967 HSM_ARCHIVE_PURGE=false copytool_setup
2969 restore_and_check_size $f $fid
2972 [[ $err -eq 0 ]] || error "File size changed during restore"
2976 run_test 31a "Import a large file and check size during restore"
2980 # test needs a running copytool
2985 local f=$DIR/$tdir/$tfile
2987 fid=$(make_custom_file_for_progress $f 39 1000000)
2988 [ $? != 0 ] && skip "not enough free space" && return
2990 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2991 wait_request_state $fid ARCHIVE SUCCEED
2994 restore_and_check_size $f $fid
2997 [[ $err -eq 0 ]] || error "File size changed during restore"
3001 run_test 31b "Restore a large unaligned file and check size during restore"
3004 # test needs a running copytool
3009 local f=$DIR/$tdir/$tfile
3011 fid=$(make_custom_file_for_progress $f 33 1048576)
3012 [ $? != 0 ] && skip "not enough free space" && return
3014 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3015 wait_request_state $fid ARCHIVE SUCCEED
3018 restore_and_check_size $f $fid
3021 [[ $err -eq 0 ]] || error "File size changed during restore"
3025 run_test 31c "Restore a large aligned file and check size during restore"
3028 # test needs a running copytool
3033 local f=$DIR/$tdir/$tfile
3035 fid=$(make_custom_file_for_progress $f 39 1000000)
3036 [ $? != 0 ] && skip "not enough free space" && return
3038 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3039 wait_request_state $fid ARCHIVE SUCCEED
3042 # to be sure wait_all_done will not be mislead by previous tests
3045 wait_for_grace_delay
3046 # Also raise grace_delay significantly so the Canceled
3047 # Restore action will stay enough long avail.
3048 local old_grace=$(get_hsm_param grace_delay)
3049 set_hsm_param grace_delay 100
3051 md5sum $f >/dev/null &
3053 wait_request_state $fid RESTORE STARTED
3058 # Check restore trigger process was killed
3059 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3063 # instead of waiting+checking both Restore and Cancel ops
3064 # sequentially, wait for both to be finished and then check
3066 wait_all_done 100 $fid
3067 local rstate=$(get_request_state $fid RESTORE)
3068 local cstate=$(get_request_state $fid CANCEL)
3070 # restore orig grace_delay.
3071 set_hsm_param grace_delay $old_grace
3073 if [[ "$rstate" == "CANCELED" ]] ; then
3074 [[ "$cstate" == "SUCCEED" ]] ||
3075 error "Restore state is CANCELED and Cancel state " \
3076 "is not SUCCEED but $cstate"
3077 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3078 elif [[ "$rstate" == "SUCCEED" ]] ; then
3079 [[ "$cstate" == "FAILED" ]] ||
3080 error "Restore state is SUCCEED and Cancel state " \
3081 "is not FAILED but $cstate"
3082 echo "Restore state is SUCCEED, Cancel state is FAILED"
3084 error "Restore state is $rstate and Cancel state is $cstate"
3088 error "Cannot kill process waiting for restore ($killed)"
3092 run_test 33 "Kill a restore waiting process"
3095 # test needs a running copytool
3100 local f=$DIR/$tdir/$tfile
3102 fid=$(make_custom_file_for_progress $f 39 1000000)
3103 [ $? != 0 ] && skip "not enough free space" && return
3105 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3106 wait_request_state $fid ARCHIVE SUCCEED
3109 md5sum $f >/dev/null &
3111 wait_request_state $fid RESTORE STARTED
3113 rm $f || error "rm $f failed"
3114 # rm must not block during restore
3115 wait_request_state $fid RESTORE STARTED
3117 wait_request_state $fid RESTORE SUCCEED
3118 # check md5sum pgm finished
3119 local there=$(ps -o pid,comm hp $pid >/dev/null)
3120 [[ -z $there ]] || error "Restore initiator does not exit"
3122 wait $pid || error "Restore initiator failed with $?"
3126 run_test 34 "Remove file during restore"
3129 # test needs a running copytool
3134 local f=$DIR/$tdir/$tfile
3135 local f1=$DIR/$tdir/$tfile-1
3137 fid=$(make_custom_file_for_progress $f 39 1000000)
3138 [ $? != 0 ] && skip "not enough free space" && return
3140 local fid1=$(copy_file /etc/passwd $f1)
3141 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3142 wait_request_state $fid ARCHIVE SUCCEED
3145 md5sum $f >/dev/null &
3147 wait_request_state $fid RESTORE STARTED
3149 mv $f1 $f || error "mv $f1 $f failed"
3150 # mv must not block during restore
3151 wait_request_state $fid RESTORE STARTED
3153 wait_request_state $fid RESTORE SUCCEED
3154 # check md5sum pgm finished
3155 local there=$(ps -o pid,comm hp $pid >/dev/null)
3156 [[ -z $there ]] || error "Restore initiator does not exit"
3158 wait $pid || error "Restore initiator failed with $?"
3161 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3165 run_test 35 "Overwrite file during restore"
3168 # test needs a running copytool
3173 local f=$DIR/$tdir/$tfile
3175 fid=$(make_custom_file_for_progress $f 39 1000000)
3176 [ $? != 0 ] && skip "not enough free space" && return
3178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3179 wait_request_state $fid ARCHIVE SUCCEED
3182 md5sum $f >/dev/null &
3184 wait_request_state $fid RESTORE STARTED
3187 # rm must not block during restore
3188 wait_request_state $fid RESTORE STARTED
3190 wait_request_state $fid RESTORE SUCCEED
3191 # check md5sum pgm finished
3192 local there=$(ps -o pid,comm hp $pid >/dev/null)
3194 error "Restore initiator does not exit"
3196 wait $pid || error "Restore initiator failed with $?"
3200 run_test 36 "Move file during restore"
3203 # LU-5683: check that an archived dirty file can be rearchived.
3205 copytool_setup $SINGLEAGT $MOUNT2
3208 local f=$DIR/$tdir/$tfile
3211 fid=$(make_small $f) || error "cannot create small file"
3213 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3214 wait_request_state $fid ARCHIVE SUCCEED
3215 $LFS hsm_release $f || error "cannot release $f"
3217 # Allow previous archive request to expire from the actions log.
3218 wait_for_grace_delay
3221 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3223 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3224 wait_request_state $fid ARCHIVE SUCCEED
3228 run_test 37 "re-archive a dirty file"
3235 for n in $(seq 1 $count); do
3236 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3238 echo "$count archive requests submitted"
3243 set_hsm_param max_requests $max_requests
3248 local stream_count=4
3249 local file_count=100
3251 local f=$DIR/$tdir/$tfile
3255 local max_requests=$(get_hsm_param max_requests)
3257 # Increase the number of HSM request that can be performed in
3258 # parallel. With the coordinator running once per second, this
3259 # also limits the number of requests per seconds that can be
3260 # performed, so we pick a decent number. But we also need to keep
3261 # that number low because the copytool has no rate limit and will
3262 # fail some requests if if gets too many at once.
3263 set_hsm_param max_requests 300
3265 trap cleanup_test_40 EXIT
3267 for i in $(seq 1 $file_count); do
3268 for p in $(seq 1 $stream_count); do
3269 fid=$(copy_file /etc/hosts $f.$p.$i)
3272 # force copytool to use a local/temp archive dir to ensure best
3273 # performance vs remote/NFS mounts used in auto-tests
3274 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3277 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3279 # to be sure wait_all_done will not be mislead by previous tests
3281 wait_for_grace_delay
3283 # start archive streams in background (archive files in parallel)
3284 for p in $(seq 1 $stream_count); do
3285 multi_archive $f.$p $file_count &
3288 echo -n "Wait for all requests being enqueued..."
3295 run_test 40 "Parallel archive requests"
3298 # test needs a running copytool
3302 local f=$DIR/$tdir/$tfile
3303 local fid=$(copy_file /etc/motd $f 1)
3305 $LFS hsm_archive $f || error "could not archive file"
3306 wait_request_state $fid ARCHIVE SUCCEED
3307 check_hsm_flags $f "0x00000009"
3309 multiop_bg_pause $f O_c || error "multiop failed"
3313 client_up || client_up || true
3315 kill -USR1 $MULTIPID
3316 wait $MULTIPID || error "multiop close failed"
3318 check_hsm_flags $f "0x0000000b"
3322 run_test 52 "Opened for write file on an evicted client should be set dirty"
3325 # test needs a running copytool
3329 local f=$DIR/$tdir/$tfile
3330 local fid=$(copy_file /etc/motd $f 1)
3332 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3333 error "could not archive file"
3334 wait_request_state $fid ARCHIVE SUCCEED
3335 check_hsm_flags $f "0x00000009"
3337 multiop_bg_pause $f o_c || error "multiop failed"
3341 client_up || client_up || true
3343 kill -USR1 $MULTIPID
3344 wait $MULTIPID || error "multiop close failed"
3346 check_hsm_flags $f "0x00000009"
3350 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3353 # test needs a running copytool
3357 local f=$DIR/$tdir/$tfile
3358 local fid=$(make_custom_file_for_progress $f 39 1000000)
3360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3361 error "could not archive file"
3362 wait_request_state $fid ARCHIVE STARTED
3364 check_hsm_flags $f "0x00000001"
3366 # Avoid coordinator resending this request as soon it has failed.
3371 wait_request_state $fid ARCHIVE FAILED
3373 check_hsm_flags $f "0x00000003"
3378 run_test 54 "Write during an archive cancels it"
3381 # test needs a running copytool
3385 local f=$DIR/$tdir/$tfile
3386 local fid=$(make_custom_file_for_progress $f 39 1000000)
3388 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3389 error "could not archive file"
3390 wait_request_state $fid ARCHIVE STARTED
3392 check_hsm_flags $f "0x00000001"
3394 # Avoid coordinator resending this request as soon it has failed.
3397 $TRUNCATE $f 1024 || error "truncate failed"
3399 wait_request_state $fid ARCHIVE FAILED
3401 check_hsm_flags $f "0x00000003"
3406 run_test 55 "Truncate during an archive cancels it"
3409 # test needs a running copytool
3413 local f=$DIR/$tdir/$tfile
3415 fid=$(make_custom_file_for_progress $f 39 1000000)
3416 [ $? != 0 ] && skip "not enough free space" && return
3418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3419 error "could not archive file"
3420 wait_request_state $fid ARCHIVE STARTED
3422 check_hsm_flags $f "0x00000001"
3424 # Change metadata and sync to be sure we are not changing only
3429 wait_request_state $fid ARCHIVE SUCCEED
3431 check_hsm_flags $f "0x00000009"
3435 run_test 56 "Setattr during an archive is ok"
3438 # Need one client for I/O, one for request
3439 needclients 2 || return 0
3441 # test needs a running copytool
3445 local f=$DIR/$tdir/test_archive_remote
3446 # Create a file on a remote node
3447 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3448 "count=2 conv=fsync"
3451 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3452 error "hsm_archive failed"
3453 local fid=$(path2fid $f)
3454 wait_request_state $fid ARCHIVE SUCCEED
3456 # Release and implicit restore it
3457 do_node $CLIENT2 "$LFS hsm_release $f" ||
3458 error "hsm_release failed"
3459 do_node $CLIENT2 "md5sum $f" ||
3460 error "hsm_restore failed"
3462 wait_request_state $fid RESTORE SUCCEED
3466 run_test 57 "Archive a file with dirty cache on another node"
3468 truncate_released_file() {
3472 local sz=$(stat -c %s $src_file)
3473 local f=$DIR/$tdir/$tfile
3474 local fid=$(copy_file $1 $f)
3478 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3479 error "could not archive file"
3480 wait_request_state $fid ARCHIVE SUCCEED
3482 $LFS hsm_release $f || error "could not release file"
3484 $TRUNCATE $f $trunc_to || error "truncate failed"
3487 local sz1=$(stat -c %s $f)
3488 [[ $sz1 == $trunc_to ]] ||
3489 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3492 check_hsm_flags $f "0x0000000b"
3494 local state=$(get_request_state $fid RESTORE)
3495 [[ "$state" == "SUCCEED" ]] ||
3496 error "truncate $sz does not trig restore, state = $state"
3498 $TRUNCATE $ref $trunc_to
3499 cmp $ref $f || error "file data wrong after truncate"
3505 # test needs a running copytool
3510 local sz=$(stat -c %s /etc/passwd)
3512 echo "truncate up from $sz to $((sz*2))"
3513 truncate_released_file /etc/passwd $((sz*2))
3515 echo "truncate down from $sz to $((sz/2))"
3516 truncate_released_file /etc/passwd $((sz/2))
3518 echo "truncate to 0"
3519 truncate_released_file /etc/passwd 0
3523 run_test 58 "Truncate a released file will trigger restore"
3527 local server_version=$(lustre_version_code $SINGLEMDS)
3528 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3529 skip "Need MDS version at least 2.7.63" && return
3532 $MCREATE $DIR/$tfile || error "mcreate failed"
3533 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3534 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3535 fid=$(path2fid $DIR/$tfile)
3536 wait_request_state $fid ARCHIVE SUCCEED
3537 $LFS hsm_release $DIR/$tfile || error "release failed"
3540 run_test 59 "Release stripeless file with non-zero size"
3543 # This test validates the fix for LU-4512. Ensure that the -u
3544 # option changes the progress reporting interval from the
3545 # default (30 seconds) to the user-specified interval.
3547 local progress_timeout=$((interval * 4))
3549 # test needs a new running copytool
3551 HSMTOOL_UPDATE_INTERVAL=$interval copytool_setup
3554 local f=$DIR/$tdir/$tfile
3556 fid=$(make_custom_file_for_progress $f 10)
3557 [ $? != 0 ] && skip "not enough free space" && return
3560 local mdt=${MDT_PREFIX}${mdtidx}
3561 local mds=mds$((mdtidx + 1))
3563 # Wait for copytool to register
3564 wait_update_facet $mds \
3565 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3566 uuid 100 || error "coyptool failed to register with $mdt"
3568 local start_at=$(date +%s)
3569 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3570 error "could not archive file"
3572 local agent=$(facet_active_host $SINGLEAGT)
3573 local prefix=$TESTLOG_PREFIX
3574 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
3575 local copytool_log=$prefix.copytool_log.$agent.log
3578 wait_update $agent \
3579 "grep -o start.copy $copytool_log" "start copy" 100 ||
3580 error "copytool failed to start"
3582 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3583 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3589 echo -n "Expecting a progress update within $progress_timeout seconds... "
3591 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3592 if [ $RESULT -gt 0 ]; then
3593 echo "$RESULT bytes copied in $WAIT seconds."
3595 elif [ $WAIT -ge $progress_timeout ]; then
3596 error "Timed out waiting for progress update!"
3599 WAIT=$((WAIT + sleep))
3603 local finish_at=$(date +%s)
3604 local elapsed=$((finish_at - start_at))
3606 # Ensure that the progress update occurred within the expected window.
3607 if [ $elapsed -lt $((interval - 1)) ]; then
3608 error "Expected progress update after at least $interval seconds"
3611 echo "Wait for on going archive hsm action to complete"
3612 wait_update $agent "grep -o copied $copytool_log" "copied" 10 ||
3613 echo "File archiving not completed even after 10 secs"
3618 run_test 60 "Changing progress update interval from default"
3621 # test needs a running copytool
3625 local f=$DIR/$tdir/$tfile
3626 local fid=$(copy_file /etc/passwd $f)
3628 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3631 wait_request_state $fid ARCHIVE FAILED
3635 run_test 61 "Waiting archive of a removed file should fail"
3638 # test needs a new running copytool
3640 copytool_monitor_setup
3641 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3643 # Just start and stop the copytool to generate events.
3646 # Wait for the copytool to register.
3647 wait_update --verbose $(facet_active_host mds1) \
3648 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3650 error "copytool failed to register with MDT0000"
3654 local REGISTER_EVENT
3655 local UNREGISTER_EVENT
3656 while read event; do
3657 local parsed=$(parse_json_event "$event")
3658 if [ -z "$parsed" ]; then
3659 error "Copytool sent malformed event: $event"
3663 if [ $event_type == "REGISTER" ]; then
3664 REGISTER_EVENT=$event
3665 elif [ $event_type == "UNREGISTER" ]; then
3666 UNREGISTER_EVENT=$event
3668 done < <(echo $"$(get_copytool_event_log)")
3670 if [ -z "$REGISTER_EVENT" ]; then
3671 error "Copytool failed to send register event to FIFO"
3674 if [ -z "$UNREGISTER_EVENT" ]; then
3675 error "Copytool failed to send unregister event to FIFO"
3678 copytool_monitor_cleanup
3679 echo "Register/Unregister events look OK."
3681 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3684 # Bump progress interval for livelier events.
3687 # test needs a new running copytool
3689 copytool_monitor_setup
3690 HSMTOOL_UPDATE_INTERVAL=$interval \
3691 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3694 local f=$DIR/$tdir/$tfile
3696 fid=$(make_custom_file_for_progress $f 39 1000000)
3697 [ $? != 0 ] && skip "not enough free space" && return
3699 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3700 error "could not archive file"
3701 wait_request_state $fid ARCHIVE SUCCEED
3703 local expected_fields="event_time data_fid source_fid"
3704 expected_fields+=" total_bytes current_bytes"
3708 while read event; do
3709 # Make sure we're not getting anything from previous events.
3710 for field in $expected_fields; do
3714 local parsed=$(parse_json_event "$event")
3715 if [ -z "$parsed" ]; then
3716 error "Copytool sent malformed event: $event"
3720 if [ $event_type == "ARCHIVE_START" ]; then
3723 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3726 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3730 # Do some simple checking of the progress update events.
3731 for expected_field in $expected_fields; do
3732 if [ -z ${!expected_field+x} ]; then
3733 error "Missing $expected_field field in event"
3737 if [ $total_bytes -eq 0 ]; then
3738 error "Expected total_bytes to be > 0"
3741 # These should be identical throughout an archive
3743 if [ $source_fid != $data_fid ]; then
3744 error "Expected source_fid to equal data_fid"
3746 done < <(echo $"$(get_copytool_event_log)")
3748 if [ -z "$START_EVENT" ]; then
3749 error "Copytool failed to send archive start event to FIFO"
3752 if [ -z "$FINISH_EVENT" ]; then
3753 error "Copytool failed to send archive finish event to FIFO"
3756 echo "Archive events look OK."
3760 copytool_monitor_cleanup
3762 run_test 71 "Copytool logs JSON archive events to FIFO"
3765 # Bump progress interval for livelier events.
3768 # test needs a new running copytool
3770 copytool_monitor_setup
3771 HSMTOOL_UPDATE_INTERVAL=$interval \
3772 HSMTOOL_EVENT_FIFO=$HSMTOOL_MONITOR_DIR/fifo copytool_setup
3773 local test_file=$HSMTOOL_MONITOR_DIR/file
3775 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3777 do_facet $SINGLEAGT "$cmd" ||
3778 error "cannot create $test_file on $SINGLEAGT"
3779 copy2archive $test_file $tdir/$tfile
3782 local f=$DIR/$tdir/$tfile
3783 import_file $tdir/$tfile $f
3784 f=$DIR2/$tdir/$tfile
3785 echo "Verifying released state: "
3786 check_hsm_flags $f "0x0000000d"
3788 local fid=$(path2fid $f)
3790 wait_request_state $fid RESTORE SUCCEED
3792 local expected_fields="event_time data_fid source_fid"
3793 expected_fields+=" total_bytes current_bytes"
3797 while read event; do
3798 # Make sure we're not getting anything from previous events.
3799 for field in $expected_fields; do
3803 local parsed=$(parse_json_event "$event")
3804 if [ -z "$parsed" ]; then
3805 error "Copytool sent malformed event: $event"
3809 if [ $event_type == "RESTORE_START" ]; then
3811 if [ $source_fid != $data_fid ]; then
3812 error "source_fid should == data_fid at start"
3815 elif [ $event_type == "RESTORE_FINISH" ]; then
3817 if [ $source_fid != $data_fid ]; then
3818 error "source_fid should == data_fid at finish"
3821 elif [ $event_type != "RESTORE_RUNNING" ]; then
3825 # Do some simple checking of the progress update events.
3826 for expected_field in $expected_fields; do
3827 if [ -z ${!expected_field+x} ]; then
3828 error "Missing $expected_field field in event"
3832 if [ $total_bytes -eq 0 ]; then
3833 error "Expected total_bytes to be > 0"
3836 # When a restore starts out, the data fid is the same as the
3837 # source fid. After the restore has gotten going, we learn
3838 # the new data fid. Once the restore has finished, the source
3839 # fid is set to the new data fid.
3841 # We test this because some monitoring software may depend on
3842 # this behavior. If it changes, then the consumers of these
3843 # events may need to be modified.
3844 if [ $source_fid == $data_fid ]; then
3845 error "source_fid should != data_fid during restore"
3847 done < <(echo $"$(get_copytool_event_log)")
3849 if [ -z "$START_EVENT" ]; then
3850 error "Copytool failed to send restore start event to FIFO"
3853 if [ -z "$FINISH_EVENT" ]; then
3854 error "Copytool failed to send restore finish event to FIFO"
3857 echo "Restore events look OK."
3861 copytool_monitor_cleanup
3865 run_test 72 "Copytool logs JSON restore events to FIFO"
3868 file_count=51 # Max number of files constrained by LNET message size
3869 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3870 local f=$DIR/$tdir/$tfile
3871 local FILELIST=/tmp/filelist.txt
3875 for i in $(seq 1 $file_count); do
3876 fid=$(copy_file /etc/hosts $f.$i)
3877 echo $f.$i >> $FILELIST
3879 # force copytool to use a local/temp archive dir to ensure best
3880 # performance vs remote/NFS mounts used in auto-tests
3881 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3884 local dai=$(get_hsm_param default_archive_id)
3885 copytool_setup $SINGLEAGT $MOUNT $dai $TMP/$tdir
3887 # to be sure wait_all_done will not be mislead by previous tests
3889 wait_for_grace_delay
3890 $LFS hsm_archive --filelist $FILELIST ||
3891 error "cannot archive a file list"
3893 $LFS hsm_release --filelist $FILELIST ||
3894 error "cannot release a file list"
3895 $LFS hsm_restore --filelist $FILELIST ||
3896 error "cannot restore a file list"
3900 run_test 90 "Archive/restore a file list"
3902 double_verify_reset_hsm_param() {
3904 echo "Testing $HSM_PARAM.$p"
3905 local val=$(get_hsm_param $p)
3907 local val2=$(($val * 2))
3908 set_hsm_param $p $val2
3909 val=$(get_hsm_param $p)
3910 [[ $val == $val2 ]] ||
3911 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3912 echo "Set $p to 0 must failed"
3916 set_hsm_param $p $save
3918 if [[ $rc == 0 ]]; then
3919 error "we must not be able to set $HSM_PARAM.$p to 0"
3924 double_verify_reset_hsm_param loop_period
3925 double_verify_reset_hsm_param grace_delay
3926 double_verify_reset_hsm_param active_request_timeout
3927 double_verify_reset_hsm_param max_requests
3928 double_verify_reset_hsm_param default_archive_id
3930 run_test 100 "Set coordinator /proc tunables"
3937 run_test 102 "Verify coordinator control"
3940 # test needs a running copytool
3947 for i in $(seq 1 20); do
3948 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3950 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3954 echo "Current requests"
3955 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3956 $HSM_PARAM.actions |\
3957 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3959 [[ -z "$res" ]] || error "Some request have not been canceled"
3963 run_test 103 "Purge all requests"
3970 local f=$DIR/$tdir/$tfile
3972 fid=$(make_custom_file_for_progress $f 39 1000000)
3973 [ $? != 0 ] && skip "not enough free space" && return
3975 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3976 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3977 $HSM_PARAM.actions |\
3978 grep $fid | cut -f16 -d=")
3980 [[ "$data1" == "$DATAHEX" ]] ||
3981 error "Data field in records is ($data1) and not ($DATAHEX)"
3986 wait_request_state $fid ARCHIVE SUCCEED
3990 run_test 104 "Copy tool data field"
3992 cleanup_test_105() {
3994 set_hsm_param max_requests $max_requests
3999 local max_requests=$(get_hsm_param max_requests)
4003 set_hsm_param max_requests 300
4005 trap cleanup_test_105 EXIT
4008 for i in $(seq -w 1 10); do
4009 cp /etc/passwd $DIR/$tdir/$i
4010 $LFS hsm_archive $DIR/$tdir/$i
4012 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4013 $HSM_PARAM.actions |\
4014 grep WAITING | wc -l")
4018 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4019 $HSM_PARAM.actions |\
4020 grep WAITING | wc -l")
4023 [[ "$reqcnt1" == "$reqcnt2" ]] ||
4024 error "Requests count after shutdown $reqcnt2 != "\
4025 "before shutdown $reqcnt1"
4029 run_test 105 "Restart of coordinator"
4032 # test needs a running copytool
4035 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4037 check_agent_registered $uuid
4039 search_copytools || error "No copytool found"
4042 check_agent_unregistered $uuid
4045 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
4046 check_agent_registered $uuid
4050 run_test 106 "Copytool register/unregister"
4053 # test needs a running copytool
4055 # create and archive file
4057 local f1=$DIR/$tdir/$tfile
4058 local fid=$(copy_file /etc/passwd $f1)
4059 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4060 wait_request_state $fid ARCHIVE SUCCEED
4061 # shutdown and restart MDS
4063 # check the copytool still gets messages from MDT
4064 local f2=$DIR/$tdir/2
4065 local fid=$(copy_file /etc/passwd $f2)
4066 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
4067 # main check of this sanity: this request MUST succeed
4068 wait_request_state $fid ARCHIVE SUCCEED
4071 run_test 107 "Copytool re-register after MDS restart"
4073 policy_set_and_test()
4077 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
4078 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4079 [[ "$policy" == "$target" ]] ||
4080 error "Wrong policy after '$change': '$policy' != '$target'"
4084 # to force default policy setting if error
4085 CDT_POLICY_HAD_CHANGED=true
4087 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4088 local default="NonBlockingRestore [NoRetryAction]"
4089 [[ "$policy" == "$default" ]] ||
4090 error "default policy has changed,"\
4091 " '$policy' != '$default' update the test"
4092 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
4093 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
4094 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
4095 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
4096 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
4097 # useless bacause we know but safer for futur changes to use real value
4098 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
4099 echo "Next set_param must failed"
4100 policy_set_and_test "wrong" "$policy"
4103 echo "Back to default policy"
4104 cdt_set_sanity_policy
4106 run_test 109 "Policy display/change"
4109 # test needs a running copytool
4114 copy2archive /etc/passwd $tdir/$tfile
4116 local f=$DIR/$tdir/$tfile
4117 import_file $tdir/$tfile $f
4118 local fid=$(path2fid $f)
4120 cdt_set_non_blocking_restore
4125 wait_request_state $fid RESTORE SUCCEED
4126 cdt_clear_non_blocking_restore
4130 error "md5sum returns $st != 1, "\
4131 "should also perror ENODATA (No data available)"
4135 run_test 110a "Non blocking restore policy (import case)"
4138 # test needs a running copytool
4142 local f=$DIR/$tdir/$tfile
4143 local fid=$(copy_file /etc/passwd $f)
4144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4145 wait_request_state $fid ARCHIVE SUCCEED
4148 cdt_set_non_blocking_restore
4153 wait_request_state $fid RESTORE SUCCEED
4154 cdt_clear_non_blocking_restore
4158 error "md5sum returns $st != 1, "\
4159 "should also perror ENODATA (No data available)"
4163 run_test 110b "Non blocking restore policy (release case)"
4166 # test needs a running copytool
4170 copy2archive /etc/passwd $tdir/$tfile
4172 local f=$DIR/$tdir/$tfile
4174 import_file $tdir/$tfile $f
4175 local fid=$(path2fid $f)
4179 copytool_remove_backend $fid
4182 wait_request_state $fid RESTORE FAILED
4189 [[ $st == 0 ]] || error "Restore does not failed"
4193 run_test 111a "No retry policy (import case), restore will error"\
4194 " (No such file or directory)"
4197 # test needs a running copytool
4201 local f=$DIR/$tdir/$tfile
4202 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
4218 [[ $st == 0 ]] || error "Restore does not failed"
4222 run_test 111b "No retry policy (release case), restore will error"\
4223 " (No such file or directory)"
4226 # test needs a running copytool
4230 local f=$DIR/$tdir/$tfile
4231 local fid=$(copy_file /etc/passwd $f)
4233 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4234 local l=$($LFS hsm_action $f)
4236 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
4240 wait_request_state $fid ARCHIVE SUCCEED
4243 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
4247 run_test 112 "State of recorded request"
4250 # test needs a running copytool
4254 local f=$DIR/$tdir/$tfile
4256 fid=$(make_custom_file_for_progress $f 103 1048576)
4257 [ $? != 0 ] && skip "not enough free space" && return
4259 # test with cdt on is made in test_221
4261 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4262 # wait archive to register at CDT
4263 wait_request_state $fid ARCHIVE WAITING
4266 wait_request_state $fid ARCHIVE CANCELED
4267 wait_request_state $fid CANCEL SUCCEED
4271 run_test 200 "Register/Cancel archive"
4274 # test needs a running copytool
4278 local f=$DIR/$tdir/$tfile
4279 make_archive $tdir/$tfile
4280 import_file $tdir/$tfile $f
4281 local fid=$(path2fid $f)
4283 # test with cdt on is made in test_222
4286 # wait restore to register at CDT
4287 wait_request_state $fid RESTORE WAITING
4290 wait_request_state $fid RESTORE CANCELED
4291 wait_request_state $fid CANCEL SUCCEED
4295 run_test 201 "Register/Cancel restore"
4298 # test needs a running copytool
4302 local f=$DIR/$tdir/$tfile
4304 fid=$(make_custom_file_for_progress $f 39 1000000)
4305 [ $? != 0 ] && skip "not enough free space" && return
4307 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4308 wait_request_state $fid ARCHIVE SUCCEED
4312 # wait remove to register at CDT
4313 wait_request_state $fid REMOVE WAITING
4316 wait_request_state $fid REMOVE CANCELED
4320 run_test 202 "Register/Cancel remove"
4323 # test needs a running copytool
4328 local f=$DIR/$tdir/$tfile
4329 local fid=$(copy_file /etc/passwd $f)
4333 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4334 wait_request_state $fid ARCHIVE SUCCEED
4336 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4340 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4344 run_test 220 "Changelog for archive"
4347 # test needs a running copytool
4352 local f=$DIR/$tdir/$tfile
4353 local fid=$(copy_file /etc/passwd $f)
4357 # block copytool operations to allow for HSM request to be
4358 # submitted and file be unlinked (CDT will find object removed)
4361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4363 # wait request to reach CT
4364 wait_request_state $fid ARCHIVE STARTED
4370 wait_request_state $fid ARCHIVE FAILED
4372 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4377 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4381 run_test 220a "Changelog for failed archive"
4384 # test needs a running copytool
4389 local f=$DIR/$tdir/$tfile
4391 fid=$(make_custom_file_for_progress $f 103 1048576)
4392 [ $? != 0 ] && skip "not enough free space" && return
4396 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4397 wait_request_state $fid ARCHIVE STARTED
4399 wait_request_state $fid ARCHIVE CANCELED
4400 wait_request_state $fid CANCEL SUCCEED
4402 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4405 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4409 run_test 221 "Changelog for archive canceled"
4412 # test needs a running copytool
4416 copy2archive /etc/passwd $tdir/$tfile
4418 local f=$DIR/$tdir/$tfile
4419 import_file $tdir/$tfile $f
4420 local fid=$(path2fid $f)
4425 wait_request_state $fid RESTORE SUCCEED
4427 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4430 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4434 run_test 222a "Changelog for explicit restore"
4437 # test needs a running copytool
4441 local f=$DIR/$tdir/$tfile
4442 local fid=$(copy_file /etc/passwd $f)
4445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4446 wait_request_state $fid ARCHIVE SUCCEED
4451 wait_request_state $fid RESTORE SUCCEED
4453 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4456 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4460 run_test 222b "Changelog for implicit restore"
4463 # test needs a running copytool
4467 copy2archive /etc/passwd $tdir/$tfile
4469 local f=$DIR/$tdir/$tfile
4470 import_file $tdir/$tfile $f
4471 local fid=$(path2fid $f)
4475 # block copytool operations to allow for HSM request to be
4476 # submitted and file be unlinked (CDT will find object removed)
4481 # wait request to reach CT
4482 wait_request_state $fid RESTORE STARTED
4488 wait_request_state $fid RESTORE FAILED
4490 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4494 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4498 run_test 222c "Changelog for failed explicit restore"
4501 # test needs a running copytool
4505 local f=$DIR/$tdir/$tfile
4506 local fid=$(copy_file /etc/passwd $f)
4509 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4510 wait_request_state $fid ARCHIVE SUCCEED
4513 copytool_remove_backend $fid
4516 wait_request_state $fid RESTORE FAILED
4518 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4522 [[ $flags == $target ]] || error "Changelog flag is $flags not $target"
4526 run_test 222d "Changelog for failed implicit restore"
4529 # test needs a running copytool
4534 local f=$DIR/$tdir/$tfile
4535 make_archive $tdir/$tfile
4539 import_file $tdir/$tfile $f
4540 local fid=$(path2fid $f)
4543 wait_request_state $fid RESTORE STARTED
4545 wait_request_state $fid RESTORE CANCELED
4546 wait_request_state $fid CANCEL SUCCEED
4548 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4551 [[ $flags == $target ]] ||
4552 error "Changelog flag is $flags not $target"
4556 run_test 223a "Changelog for restore canceled (import case)"
4559 # test needs a running copytool
4564 local f=$DIR/$tdir/$tfile
4566 fid=$(make_custom_file_for_progress $f 39 1000000)
4567 [ $? != 0 ] && skip "not enough free space" && return
4570 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4571 wait_request_state $fid ARCHIVE SUCCEED
4574 wait_request_state $fid RESTORE STARTED
4576 wait_request_state $fid RESTORE CANCELED
4577 wait_request_state $fid CANCEL SUCCEED
4579 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -1)
4582 [[ $flags == $target ]] ||
4583 error "Changelog flag is $flags not $target"
4587 run_test 223b "Changelog for restore canceled (release case)"
4590 # test needs a running copytool
4595 local f=$DIR/$tdir/$tfile
4596 local fid=$(copy_file /etc/passwd $f)
4599 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4600 wait_request_state $fid ARCHIVE SUCCEED
4603 wait_request_state $fid REMOVE SUCCEED
4605 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4608 [[ $flags == $target ]] ||
4609 error "Changelog flag is $flags not $target"
4613 run_test 224 "Changelog for remove"
4616 # test needs a running copytool
4621 local f=$DIR/$tdir/$tfile
4622 local fid=$(copy_file /etc/passwd $f)
4625 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4626 wait_request_state $fid ARCHIVE SUCCEED
4628 copytool_remove_backend $fid
4630 # block copytool operations to allow for HSM request to be
4631 # submitted and file be unlinked (CDT will find object removed)
4636 # wait for request to reach CT
4637 wait_request_state $fid REMOVE STARTED
4643 wait_request_state $fid REMOVE FAILED
4645 local flags=$(changelog_get_flags ${MDT[0]} HSM $fid | tail -n 1)
4649 [[ $flags == $target ]] ||
4650 error "Changelog flag is $flags not $target"
4654 run_test 224a "Changelog for failed remove"
4657 # test needs a running copytool
4660 # test is not usable because remove request is too fast
4661 # so it is always finished before cancel can be done ...
4662 echo "Test disabled"
4667 local f=$DIR/$tdir/$tfile
4669 fid=$(make_custom_file_for_progress $f 39 1000000)
4670 [ $? != 0 ] && skip "not enough free space" && return
4673 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4674 wait_request_state $fid ARCHIVE SUCCEED
4676 # if cdt is on, it can serve too quickly the request
4681 wait_request_state $fid REMOVE CANCELED
4682 wait_request_state $fid CANCEL SUCCEED
4684 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4685 local flags=$($LFS changelog ${MDT[0]} | grep HSM | grep $fid |
4686 tail -n 1 | awk '{print $5}')
4689 [[ $flags == $target ]] ||
4690 error "Changelog flag is $flags not $target"
4694 run_test 225 "Changelog for remove canceled"
4697 # test needs a running copytool
4702 local f1=$DIR/$tdir/$tfile-1
4703 local f2=$DIR/$tdir/$tfile-2
4704 local f3=$DIR/$tdir/$tfile-3
4705 local fid1=$(copy_file /etc/passwd $f1)
4706 local fid2=$(copy_file /etc/passwd $f2)
4707 copy_file /etc/passwd $f3
4710 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4711 wait_request_state $fid1 ARCHIVE SUCCEED
4713 $LFS hsm_archive $f2
4714 wait_request_state $fid2 ARCHIVE SUCCEED
4716 rm $f1 || error "rm $f1 failed"
4718 local flags=$(changelog_get_flags ${MDT[0]} UNLNK $fid1)
4721 [[ $flags == $target ]] ||
4722 error "Changelog flag is $flags not $target"
4724 mv $f3 $f2 || error "mv $f3 $f2 failed"
4726 flags=$(changelog_get_flags ${MDT[0]} RENME $fid2)
4729 [[ $flags == $target ]] ||
4730 error "Changelog flag is $flags not $target"
4734 run_test 226 "changelog for last rm/mv with exiting archive"
4736 check_flags_changes() {
4744 $LFS hsm_set --$hsm_flag $f ||
4745 error "Cannot set $hsm_flag on $f"
4746 local flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4747 local seen=${#flags[*]}
4749 [[ $seen == $cnt ]] ||
4750 error "set $hsm_flag: Changelog events $seen != $cnt"
4751 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4752 error "set $hsm_flag: Changelog flags are "\
4753 "${flags[$((cnt - 1))]} not $target"
4755 $LFS hsm_clear --$hsm_flag $f ||
4756 error "Cannot clear $hsm_flag on $f"
4757 flags=($(changelog_get_flags ${MDT[0]} HSM $fid))
4760 [[ $cnt == $seen ]] ||
4761 error "clear $hsm_flag: Changelog events $seen != $cnt"
4763 [[ ${flags[$((cnt - 1))]} == $target ]] ||
4764 error "clear $hsm_flag: Changelog flag is "\
4765 "${flags[$((cnt - 1))]} not $target"
4769 # test needs a running copytool
4776 for i in norelease noarchive exists archived
4778 local f=$DIR/$tdir/$tfile-$i
4779 local fid=$(copy_file /etc/passwd $f)
4780 check_flags_changes $f $fid $i 0 1
4783 f=$DIR/$tdir/$tfile---lost
4784 fid=$(copy_file /etc/passwd $f)
4785 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4786 wait_request_state $fid ARCHIVE SUCCEED
4787 check_flags_changes $f $fid lost 3 1
4791 run_test 227 "changelog when explicit setting of HSM flags"
4794 # test needs a running copytool
4797 local fid=$(make_small_sync $DIR/$tfile)
4798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4799 wait_request_state $fid ARCHIVE SUCCEED
4801 $LFS hsm_release $DIR/$tfile
4802 check_hsm_flags $DIR/$tfile "0x0000000d"
4804 filefrag $DIR/$tfile | grep " 1 extent found" ||
4805 error "filefrag on released file must return only one extent"
4807 # only newer versions of cp detect sparse files by stat/FIEMAP
4809 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4810 error "copying $DIR/$tfile"
4811 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4813 $LFS hsm_release $DIR/$tfile
4814 check_hsm_flags $DIR/$tfile "0x0000000d"
4816 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4818 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4820 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4821 error "comparing untarred $DIR/$tfile"
4823 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4824 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4827 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4830 # test needs a running copytool
4834 local maxrequest=$(get_hsm_param max_requests)
4835 local rqcnt=$(($maxrequest * 3))
4839 for i in $(seq -w 1 $rqcnt); do
4841 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4843 # we do it in 2 steps, so all requests arrive at the same time
4844 for i in $(seq -w 1 $rqcnt); do
4845 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4850 while [[ $cnt != 0 || $wt != 0 ]]; do
4852 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4853 $HSM_PARAM.actions |\
4854 grep STARTED | grep -v CANCEL | wc -l")
4855 [[ $cnt -le $maxrequest ]] ||
4856 error "$cnt > $maxrequest too many started requests"
4857 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4858 $HSM_PARAM.actions |\
4859 grep WAITING | wc -l")
4860 echo "max=$maxrequest started=$cnt waiting=$wt"
4865 run_test 250 "Coordinator max request"
4868 # test needs a running copytool
4872 local f=$DIR/$tdir/$tfile
4874 fid=$(make_custom_file_for_progress $f 103 1048576)
4875 [ $? != 0 ] && skip "not enough free space" && return
4878 # to have a short test
4879 local old_to=$(get_hsm_param active_request_timeout)
4880 set_hsm_param active_request_timeout 4
4881 # to be sure the cdt will wake up frequently so
4882 # it will be able to cancel the "old" request
4883 local old_loop=$(get_hsm_param loop_period)
4884 set_hsm_param loop_period 2
4887 # clear locks to avoid extra delay caused by flush/cancel
4888 # and thus prevent early copytool death to timeout.
4889 cancel_lru_locks osc
4891 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4892 wait_request_state $fid ARCHIVE STARTED
4894 wait_request_state $fid ARCHIVE CANCELED
4896 set_hsm_param active_request_timeout $old_to
4897 set_hsm_param loop_period $old_loop
4901 run_test 251 "Coordinator request timeout"
4904 # test needs a running copytool
4908 local f=$DIR/$tdir/$tfile
4909 local fid=$(make_custom_file_for_progress $f 103 1048576)
4912 # to have a short test
4913 local old_to=$(get_hsm_param active_request_timeout)
4914 set_hsm_param active_request_timeout 20
4915 # to be sure the cdt will wake up frequently so
4916 # it will be able to cancel the "old" request
4917 local old_loop=$(get_hsm_param loop_period)
4918 set_hsm_param loop_period 2
4921 # clear locks to avoid extra delay caused by flush/cancel
4922 # and thus prevent early copytool death to timeout.
4923 cancel_lru_locks osc
4925 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4926 wait_request_state $fid ARCHIVE STARTED
4929 # wait but less than active_request_timeout+grace_delay
4931 wait_request_state $fid ARCHIVE CANCELED
4933 set_hsm_param active_request_timeout $old_to
4934 set_hsm_param loop_period $old_loop
4938 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4941 # the only way to test ondisk conf is to restart MDS ...
4942 echo "Stop coordinator and remove coordinator state at mount"
4945 # clean on disk conf set by default
4946 cdt_clear_mount_state
4947 cdt_check_state stopped
4949 # check cdt still off after umount/remount
4951 cdt_check_state stopped
4953 echo "Set coordinator start at mount, and start coordinator"
4954 cdt_set_mount_state enabled
4957 cdt_check_state enabled
4959 # check cdt still on after umount/remount
4961 cdt_check_state enabled
4963 # we are back to original state (cdt started at mount)
4965 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4968 local ai=$(get_hsm_param default_archive_id)
4969 local new=$((ai + 1))
4971 set_hsm_param default_archive_id $new -P
4973 local res=$(get_hsm_param default_archive_id)
4976 set_hsm_param default_archive_id "" "-P -d"
4978 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4980 run_test 301 "HSM tunnable are persistent"
4983 local ai=$(get_hsm_param default_archive_id)
4984 local new=$((ai + 1))
4989 set_hsm_param default_archive_id $new -P
4992 for mdtno in $(seq 1 $MDSCOUNT); do
4997 cdt_check_state enabled
4999 local res=$(get_hsm_param default_archive_id)
5002 set_hsm_param default_archive_id "" "-P -d"
5004 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5006 run_test 302 "HSM tunnable are persistent when CDT is off"
5009 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5015 local dir_mdt0=$DIR/$tdir/mdt0
5016 local dir_mdt1=$DIR/$tdir/mdt1
5018 # create 1 dir per MDT
5019 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5020 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5022 # create 1 file in each MDT
5023 local fid1=$(make_small $dir_mdt0/$tfile)
5024 local fid2=$(make_small $dir_mdt1/$tfile)
5026 # check that hsm request on mdt0 is sent to the right MDS
5027 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5028 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5029 echo "archive successful on mdt0"
5031 # check that hsm request on mdt1 is sent to the right MDS
5032 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5033 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5034 echo "archive successful on mdt1"
5037 # clean test files and directories
5038 rm -rf $dir_mdt0 $dir_mdt1
5040 run_test 400 "Single request is sent to the right MDT"
5043 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5049 local dir_mdt0=$DIR/$tdir/mdt0
5050 local dir_mdt1=$DIR/$tdir/mdt1
5052 # create 1 dir per MDT
5053 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5054 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5056 # create 1 file in each MDT
5057 local fid1=$(make_small $dir_mdt0/$tfile)
5058 local fid2=$(make_small $dir_mdt1/$tfile)
5060 # check that compound requests are shunt to the rights MDTs
5061 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5062 error "lfs hsm_archive"
5063 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5064 echo "archive successful on mdt0"
5065 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5066 echo "archive successful on mdt1"
5069 # clean test files and directories
5070 rm -rf $dir_mdt0 $dir_mdt1
5072 run_test 401 "Compound requests split and sent to their respective MDTs"
5074 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5079 local node=$(facet_active_host $facet)
5081 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5082 awk '{print $4}'); do
5083 echo "$3 $mdc on $node"
5084 do_facet $facet "$LCTL --device $mdc $state" || return 1
5089 # make sure there is no running copytool
5092 # deactivate all mdc on agent1
5093 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5095 HSMTOOL_NOERROR=true copytool_setup $SINGLEAGT
5097 check_agent_unregistered "uuid" # match any agent
5099 # no expected running copytool
5100 search_copytools $agent && error "Copytool start should have failed"
5103 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5105 run_test 402a "Copytool start fails if all MDTs are inactive"
5112 local f=$DIR/$tdir/$tfile
5113 touch $f || error "touch $f failed"
5114 local fid=$(path2fid $f)
5116 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5117 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5118 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5120 # give time for CDT to send request and to keep it for retry
5121 wait_for_loop_period
5123 wait_request_state $fid ARCHIVE WAITING
5125 do_facet $SINGLEAGT lctl set_param fail_loc=0
5127 # request should succeed now
5128 wait_request_state $fid ARCHIVE SUCCEED
5132 run_test 402b "CDT must retry request upon slow start of CT"
5135 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5137 # make sure there is no running copytool
5140 local agent=$(facet_active_host $SINGLEAGT)
5142 # deactivate all mdc for MDT0001
5143 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5146 local uuid=$(get_agent_uuid $agent)
5147 # check the agent is registered on MDT0000, and not on MDT0001
5148 check_agent_registered_by_mdt $uuid 0
5149 check_agent_unregistered_by_mdt $uuid 1
5151 # check running copytool process
5152 search_copytools $agent || error "No running copytools on $agent"
5154 # reactivate all mdc for MDT0001
5155 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5157 # make sure the copytool is now registered to all MDTs
5158 check_agent_registered $uuid
5162 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5165 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5169 # create files on both MDT0000 and MDT0001
5172 local dir_mdt0=$DIR/$tdir/mdt0
5173 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5175 # create 1 file on mdt0
5176 local fid1=$(make_small $dir_mdt0/$tfile)
5178 # deactivate all mdc for MDT0001
5179 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5181 # send an HSM request for files in MDT0000
5182 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5184 # check for completion of files in MDT0000
5185 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5186 echo "archive successful on mdt0"
5188 # reactivate all mdc for MDT0001
5189 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5192 # clean test files and directories
5195 run_test 404 "Inactive MDT does not block requests for active MDTs"
5198 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5204 local striped_dir=$DIR/$tdir/striped_dir
5206 # create striped dir on all of MDTs
5207 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5209 local fid1=$(make_small_sync $striped_dir/${tfile}_0)
5210 local fid2=$(make_small_sync $striped_dir/${tfile}_1)
5211 local fid3=$(make_small_sync $striped_dir/${tfile}_2)
5212 local fid4=$(make_small_sync $striped_dir/${tfile}_3)
5214 local idx1=$($LFS getstripe -M $striped_dir/${tfile}_0)
5215 local idx2=$($LFS getstripe -M $striped_dir/${tfile}_1)
5216 local idx3=$($LFS getstripe -M $striped_dir/${tfile}_2)
5217 local idx4=$($LFS getstripe -M $striped_dir/${tfile}_3)
5219 # check that compound requests are shunt to the rights MDTs
5220 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5221 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5222 error "lfs hsm_archive"
5224 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5225 echo "archive successful on $fid1"
5226 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5227 echo "archive successful on $fid2"
5228 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5229 echo "archive successful on $fid3"
5230 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5231 echo "archive successful on $fid4"
5233 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5234 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5235 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5236 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5238 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5239 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5240 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5241 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5245 run_test 405 "archive and release under striped directory"
5248 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5250 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5251 skip "need MDS version at least 2.7.64" && return 0
5258 fid=$(make_small $DIR/$tdir/$tfile)
5261 $LFS hsm_archive $DIR/$tdir/$tfile
5262 wait_request_state "$fid" ARCHIVE SUCCEED
5263 $LFS hsm_release $DIR/$tdir/$tfile
5265 # Should migrate $tdir but not $tfile.
5266 $LFS mv -M1 $DIR/$tdir &&
5267 error "migrating HSM an archived file should fail"
5269 $LFS hsm_restore $DIR/$tdir/$tfile
5270 wait_request_state "$fid" RESTORE SUCCEED
5272 $LFS hsm_remove $DIR/$tdir/$tfile
5273 wait_request_state "$fid" REMOVE SUCCEED
5275 cat $DIR/$tdir/$tfile > /dev/null ||
5276 error "cannot read $DIR/$tdir/$tfile"
5278 $LFS mv -M1 $DIR/$tdir ||
5279 error "cannot complete migration after HSM remove"
5281 mdt_index=$($LFS getstripe -M $DIR/$tdir)
5282 if ((mdt_index != 1)); then
5283 error "expected MDT index 1, got $mdt_index"
5286 # Refresh fid after migration.
5287 fid=$(path2fid $DIR/$tdir/$tfile)
5290 $LFS hsm_archive $DIR/$tdir/$tfile
5291 wait_request_state "$fid" ARCHIVE SUCCEED 1
5293 lctl set_param debug=+trace
5294 $LFS hsm_release $DIR/$tdir/$tfile ||
5295 error "cannot release $DIR/$tdir/$tfile"
5297 $LFS hsm_restore $DIR/$tdir/$tfile
5298 wait_request_state "$fid" RESTORE SUCCEED 1
5300 cat $DIR/$tdir/$tfile > /dev/null ||
5301 error "cannot read $DIR/$tdir/$tfile"
5305 run_test 406 "attempting to migrate HSM archived files is safe"
5308 needclients 2 || return 0
5309 # test needs a running copytool
5314 local f=$DIR/$tdir/$tfile
5315 local f2=$DIR2/$tdir/$tfile
5317 fid=$(make_custom_file_for_progress $f 39 1000000)
5318 [ $? != 0 ] && skip "not enough free space" && return
5320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5321 wait_request_state $fid ARCHIVE SUCCEED
5324 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5325 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5328 # 1st request holds layout lock while appropriate
5329 # RESTORE record is still not added to llog
5333 # after umount hsm_actions->O/x/x log shouldn't have
5334 # double RESTORE records like below
5335 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5336 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5338 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5341 wait_request_state $fid RESTORE SUCCEED
5344 run_test 407 "Check for double RESTORE records in llog"
5348 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5349 skip "HSM migrate is not supported" && return
5351 # Stop the existing copytool
5354 test_mkdir -p $DIR/$tdir
5355 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5357 run_test 500 "various LLAPI HSM tests"
5362 check_and_cleanup_lustre