3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
49 # if there is no CLIENT1 defined, some tests can be ran on localhost
50 CLIENT1=${CLIENT1:-$HOSTNAME}
51 # if CLIENT2 doesn't exist then use CLIENT1 instead
52 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
54 # Exception is the test which need two separate nodes
55 CLIENT2=${CLIENT2:-$CLIENT1}
58 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
59 # the following associated variables are added:
61 # AGTCOUNT: number of agents
62 # AGTDEV{N}: target HSM mount point (root path of the backend)
63 # agt{N}_HOST: hostname of the agent agt{N}
64 # SINGLEAGT: facet of the single agent
66 # The number of agents is initialized as the number of remote client nodes.
67 # By default, only single copytool is started on a remote client/agent. If there
68 # was no remote client, then the copytool will be started on the local client.
74 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
75 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
77 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
78 if [[ $CLIENTCOUNT -gt 1 ]] &&
79 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
80 skip_env "SHARED_DIRECTORY should be accessible"\
85 # We used to put the HSM archive in $SHARED_DIRECTORY but that
86 # meant NFS issues could hose sanity-hsm sessions. So now we
88 for n in $(seq $AGTCOUNT); do
89 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
90 agent=CLIENT$((n + 1))
91 if [[ -z "${!agent}" ]]; then
92 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
95 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
98 export SINGLEAGT=${SINGLEAGT:-agt1}
100 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
101 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
102 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
103 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
104 export HSMTOOL_TESTDIR
105 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
106 # $hsm_root/$HSMTMP Makes $hsm_root dir path less generic to ensure
107 # rm -rf $hsm_root/* is safe even if $hsm_root becomes unset to avoid
108 # deleting everything in filesystem, independent of any copytool.
109 export HSMTMP=${HSMTMP:-"shsm"}
111 HSM_ARCHIVE=$(copytool_device $SINGLEAGT)
113 [ -z "${HSM_ARCHIVE// /}" ] && error "HSM_ARCHIVE is empty!"
114 HSM_ARCHIVE=$HSM_ARCHIVE/$HSMTMP
118 # The test only support up to 10 MDTs
119 MDT_PREFIX="mdt.$FSNAME-MDT000"
120 HSM_PARAM="${MDT_PREFIX}0.hsm"
122 # archive is purged at copytool setup
123 HSM_ARCHIVE_PURGE=true
125 # Don't allow copytool error upon start/setup
126 HSMTOOL_NOERROR=false
129 # Get the backend root path for the given agent facet.
132 local dev=AGTDEV$(facet_number $facet)
137 # Stop copytool and unregister an existing changelog user.
139 copytool_monitor_cleanup
142 cdt_set_sanity_policy
147 # get MDT device for each mdc
148 for mdtno in $(seq 1 $MDSCOUNT); do
149 local idx=$(($mdtno - 1))
150 MDT[$idx]=$($LCTL get_param -n \
151 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
152 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
158 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
162 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
164 echo "Killing existing copytools on $hosts"
165 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
169 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
170 local wait_timeout=200
171 local wait_start=$SECONDS
172 local wait_end=$((wait_start + wait_timeout))
173 local sleep_time=100000 # 0.1 second
175 while ((SECONDS < wait_end)); do
176 if ! search_copytools $hosts; then
177 echo "copytools stopped in $((SECONDS - wait_start))s"
181 echo "copytools still running on $hosts"
183 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
184 sleep_time=$(bc <<< "$sleep_time * 2")
187 # try to dump Copytool's stack
188 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
189 "echo t >/proc/sysrq-trigger"
191 echo "copytools failed to stop in ${wait_timeout}s"
196 copytool_monitor_setup() {
197 local facet=${1:-$SINGLEAGT}
198 local agent=$(facet_active_host $facet)
200 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
201 local test_dir=$(do_node $agent "$cmd") ||
202 error "Failed to create tempdir on $agent"
203 export HSMTOOL_MONITOR_DIR=$test_dir
205 # Create the fifo and a monitor (cat dies when copytool dies)
206 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
207 error "failed to create copytool fifo on $agent"
208 cmd="cat $test_dir/fifo > $test_dir/events &"
209 cmd+=" echo \\\$! > $test_dir/monitor_pid"
211 if [[ $PDSH == *Rmrsh* ]]; then
212 # This is required for pdsh -Rmrsh and its handling of remote
214 # Regular ssh and pdsh -Rssh work fine without this
215 # backgrounded subshell nonsense.
216 (do_node $agent "$cmd") &
217 export HSMTOOL_MONITOR_PDSH=$!
219 # Slightly racy, but just making a best-effort to catch obvious
222 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
223 error "Failed to start copytool monitor on $agent"
225 do_node $agent "$cmd"
227 error "Failed to start copytool monitor on $agent"
232 copytool_monitor_cleanup() {
233 local facet=${1:-$SINGLEAGT}
234 local agent=$(facet_active_host $facet)
236 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
237 # Should die when the copytool dies, but just in case.
238 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
239 cmd+=" 2>/dev/null || true"
240 do_node $agent "$cmd"
241 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
242 export HSMTOOL_MONITOR_DIR=
245 # The pdsh should die on its own when the monitor dies. Just
246 # in case, though, try to clean up to avoid any cruft.
247 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
248 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null
249 export HSMTOOL_MONITOR_PDSH=
254 local facet=${1:-$SINGLEAGT}
255 # Use MOUNT2 by default if defined
256 local lustre_mntpnt=${2:-${MOUNT2:-$MOUNT}}
258 local hsm_root=${4:-$(copytool_device $facet)}
260 [ -z "${hsm_root// /}" ] && error "copytool_setup: hsm_root empty!"
262 local agent=$(facet_active_host $facet)
264 if $HSM_ARCHIVE_PURGE; then
265 echo "Purging archive on $agent"
266 do_facet $facet "rm -rf $hsm_root/$HSMTMP/*"
269 echo "Starting copytool $facet on $agent"
270 do_facet $facet "mkdir -p $hsm_root/$HSMTMP/" ||
271 error "mkdir '$hsm_root/$HSMTMP' failed"
272 # bandwidth is limited to 1MB/s so the copy time is known and
273 # independent of hardware
274 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon"
275 cmd+=" --hsm-root $hsm_root/$HSMTMP"
276 [[ -z "$arc_id" ]] || cmd+=" --archive $arc_id"
277 [[ -z "$HSMTOOL_UPDATE_INTERVAL" ]] ||
278 cmd+=" --update-interval $HSMTOOL_UPDATE_INTERVAL"
279 [[ -z "$HSMTOOL_EVENT_FIFO" ]] ||
280 cmd+=" --event-fifo $HSMTOOL_EVENT_FIFO"
281 cmd+=" --bandwidth 1 $lustre_mntpnt"
283 # Redirect the standard output and error to a log file which
284 # can be uploaded to Maloo.
285 local prefix=$TESTLOG_PREFIX
286 [[ -z "$TESTNAME" ]] || prefix=$prefix.$TESTNAME
287 local copytool_log=$prefix.copytool${arc_id}_log.$agent.log
289 do_facet $facet "$cmd < /dev/null > $copytool_log 2>&1"
290 if [[ $? != 0 ]]; then
291 [[ $HSMTOOL_NOERROR == true ]] ||
292 error "start copytool $facet on $agent failed"
293 echo "start copytool $facet on $agent failed"
299 get_copytool_event_log() {
300 local facet=${1:-$SINGLEAGT}
301 local agent=$(facet_active_host $facet)
303 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
304 error "Can't get event log: No monitor directory!"
306 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
307 error "Could not collect event log from $agent"
312 local agt_facet=$SINGLEAGT
313 local agt_hosts=${1:-$(facet_active_host $agt_facet)}
314 local hsm_root=$(copytool_device $agt_facet)
316 [ -z "${hsm_root// /}" ] && error "copytool_cleanup: hsm_root empty!"
323 kill_copytools $agt_hosts
324 wait_copytools $agt_hosts || error "copytools failed to stop"
326 # Clean all CDTs orphans requests from previous tests that
327 # would otherwise need to timeout to clear.
328 for ((i = 0; i < MDSCOUNT; i++)); do
330 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
331 state[$i]=$(do_facet $facet "$LCTL get_param -n $param")
333 # Skip already stopping or stopped CDTs.
334 [[ "${state[$i]}" =~ ^stop ]] && continue
336 do_facet $facet "$LCTL set_param $param=shutdown"
339 for ((i = 0; i < MDSCOUNT; i++)); do
340 # Only check and restore CDTs that we stopped in the first loop.
341 [[ "${state[$i]}" =~ ^stop ]] && continue
344 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
346 wait_result $facet "$LCTL get_param -n $param" stopped 20 ||
347 error "$facet CDT state is not stopped"
349 # Restore old CDT state.
350 do_facet $facet "$LCTL set_param $param=${state[$i]}"
353 for ((i = 0; i < MDSCOUNT; i++)); do
354 # Only check CDTs that we stopped in the first loop.
355 [[ "${state[$i]}" =~ ^stop ]] && continue
358 param=$(printf 'mdt.%s-MDT%04x.hsm_control' $FSNAME $i)
360 # Check that the old CDT state was restored.
361 wait_result $facet "$LCTL get_param -n $param" "${state[$i]}" \
362 20 || error "$facet CDT state is not '${state[$i]}'"
365 if do_facet $agt_facet "df $hsm_root" >/dev/null 2>&1 ; then
366 do_facet $agt_facet "rm -rf $hsm_root/$HSMTMP/*"
371 local agents=${1:-$(facet_active_host $SINGLEAGT)}
373 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
374 echo "Copytool is suspended on $agents"
377 copytool_continue() {
378 local agents=${1:-$(facet_active_host $SINGLEAGT)}
380 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
381 echo "Copytool is continued on $agents"
384 copytool_remove_backend() {
386 local be=$(do_facet $SINGLEAGT find $HSM_ARCHIVE -name $fid)
387 echo "Remove from backend: $fid = $be"
388 do_facet $SINGLEAGT rm -f $be
392 do_facet $SINGLEAGT \
393 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
394 --import $1 $2 $MOUNT" ||
395 error "import of $1 to $2 failed"
399 local file=$HSM_ARCHIVE/$1
400 do_facet $SINGLEAGT mkdir -p $(dirname $file)
401 do_facet $SINGLEAGT dd if=/dev/urandom of=$file count=32 bs=1000000 ||
402 file_creation_failure dd $file $?
406 local file=$HSM_ARCHIVE/$2
407 do_facet $SINGLEAGT mkdir -p $(dirname $file)
408 do_facet $SINGLEAGT cp -p $1 $file || error "cannot copy $1 to $file"
417 if [[ "$value" != "" ]]; then
420 for mdtno in $(seq 1 $MDSCOUNT); do
421 local idx=$(($mdtno - 1))
422 local facet=mds${mdtno}
423 # if $arg include -P option, run 1 set_param per MDT on the MGS
424 # else, run set_param on each MDT
425 [[ $arg = *"-P"* ]] && facet=mgs
426 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
427 [[ $? != 0 ]] && rc=1
437 for mdtno in $(seq 1 $MDSCOUNT); do
438 local idx=$(($mdtno - 1))
439 wait_result mds${mdtno} \
440 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
442 error "$key state is not '$target' on mds${mdtno}"
449 for mdtno in $(seq 1 $MDSCOUNT); do
450 local idx=$(($mdtno - 1))
451 local cl_user=$(do_facet mds${mdtno} $LCTL \
452 --device ${MDT[$idx]} \
453 changelog_register -n)
455 do_facet mds${mdtno} lctl set_param \
456 mdd.${MDT[$idx]}.changelog_mask="+hsm"
457 $LFS changelog_clear ${MDT[$idx]} $cl_user 0
461 changelog_cleanup() {
463 for mdtno in $(seq 1 $MDSCOUNT); do
464 local idx=$(($mdtno - 1))
465 [[ -z ${CL_USERS[$idx]} ]] && continue
466 $LFS changelog_clear ${MDT[$idx]} ${CL_USERS[$idx]} 0
467 do_facet mds${mdtno} lctl --device ${MDT[$idx]} \
468 changelog_deregister ${CL_USERS[$idx]}
473 changelog_get_flags() {
478 $LFS changelog $mdt | awk "/$cltype/ && /t=\[$fid\]/ {print \$5}"
483 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
491 mdts_set_param "$opt -n" "hsm.$param" "$value"
498 mdts_set_param "" hsm_control "$cmd"
499 mdts_check_param hsm_control "$target" 10
502 cdt_set_sanity_policy() {
503 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
506 mdts_set_param "" hsm.policy "+NRA"
507 mdts_set_param "" hsm.policy "-NBR"
508 CDT_POLICY_HAD_CHANGED=
513 mdts_set_param "" hsm.policy "+NRA"
514 CDT_POLICY_HAD_CHANGED=true
517 cdt_clear_no_retry() {
518 mdts_set_param "" hsm.policy "-NRA"
519 CDT_POLICY_HAD_CHANGED=true
522 cdt_set_non_blocking_restore() {
523 mdts_set_param "" hsm.policy "+NBR"
524 CDT_POLICY_HAD_CHANGED=true
527 cdt_clear_non_blocking_restore() {
528 mdts_set_param "" hsm.policy "-NBR"
529 CDT_POLICY_HAD_CHANGED=true
532 cdt_clear_mount_state() {
533 mdts_set_param "-P -d" hsm_control ""
536 cdt_set_mount_state() {
537 mdts_set_param "-P" hsm_control "$1"
538 # set_param -P is asynchronous operation and could race with set_param.
539 # In such case configs could be retrieved and applied at mgc after
540 # set_param -P completion. Sleep here to avoid race with set_param.
541 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
542 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
543 # and 10 seconds to retrieve config from server.
548 mdts_check_param hsm_control "$1" 20
552 set_test_state disabled disabled
556 set_test_state enabled enabled
560 set_test_state shutdown stopped
564 set_test_state purge enabled
570 cdt_set_sanity_policy
574 local client_count=$1
575 if [[ $CLIENTCOUNT -lt $client_count ]]; then
576 skip "Need $client_count or more clients, have $CLIENTCOUNT"
583 $LFS path2fid $1 | tr -d '[]'
584 return ${PIPESTATUS[0]}
592 if [[ $u == "user" ]]; then
593 st=$($RUNAS $LFS hsm_state $f)
596 st=$($LFS hsm_state $f)
599 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
601 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
605 get_hsm_archive_id() {
608 st=$($LFS hsm_state $f)
609 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
611 local ar=$(echo $st | grep "archive_id" | cut -f5 -d" " |
620 local st=$(get_hsm_flags $f)
621 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
624 check_hsm_flags_user() {
628 local st=$(get_hsm_flags $f user)
629 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
632 file_creation_failure() {
637 df $MOUNT $MOUNT2 >&2
638 error "cannot create $f with $cmd, status=$err"
650 if [[ "$3" != 1 ]]; then
654 cp $1 $f || file_creation_failure cp $f $?
656 path2fid $f || error "cannot get fid on $f"
660 local file2=${1/$DIR/$DIR2}
661 dd if=/dev/urandom of=$file2 count=2 bs=1M conv=fsync ||
662 file_creation_failure dd $file2 $?
664 path2fid $1 || error "cannot get fid on $1"
668 dd if=/dev/urandom of=$1 count=1 bs=1M conv=sync ||
669 file_creation_failure dd $1 $?
670 path2fid $1 || error "cannot get fid on $1"
673 cleanup_large_files() {
674 local ratio=$(df -P $MOUNT | tail -1 | awk '{print $5}' |
676 [ $ratio -gt 50 ] && find $MOUNT -size +10M -exec rm -f {} \;
679 check_enough_free_space() {
682 local need=$((nb * unit /1024))
683 local free=$(df -kP $MOUNT | tail -1 | awk '{print $4}')
684 (( $need >= $free )) && return 1
688 make_custom_file_for_progress() {
689 local file2=${1/$DIR/$DIR2}
690 local fsize=${2:-"39"}
691 local blksz=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
694 [[ $fsize -gt 0 ]] || error "Invalid file size"
695 [[ $blksz -gt 0 ]] || error "Invalid stripe size"
698 check_enough_free_space $fsize $blksz || return $?
699 dd if=/dev/zero of=$file2 count=$fsize bs=$blksz conv=fsync ||
700 file_creation_failure dd $file2 $?
701 path2fid $1 || error "cannot get fid on $1"
707 wait_update --verbose $(facet_active_host $facet) "$@"
710 wait_request_state() {
714 # 4th arg (mdt index) is optional
716 local mds=mds$(($mdtidx + 1))
718 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
719 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
721 wait_result $mds "$cmd" $state 200 ||
722 error "request on $fid is not $state on $mds"
725 get_request_state() {
729 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
730 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
733 get_request_count() {
737 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
738 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
741 # Ensure the number of HSM request for a given FID is correct
742 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
743 assert_request_count() {
744 local request_count=$(get_request_count $1 $2)
745 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
747 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
754 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
755 [[ -n $fid ]] && cmd+=" | grep '$fid'"
756 cmd+=" | egrep 'WAITING|STARTED'"
758 wait_result $SINGLEMDS "$cmd" "" $timeout ||
759 error "requests did not complete"
762 wait_for_grace_delay() {
763 local val=$(get_hsm_param grace_delay)
767 wait_for_loop_period() {
768 local val=$(get_hsm_param loop_period)
775 # python2.6 in EL6 includes an internal json module
776 local json_parser='import json; import fileinput;'
777 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
778 json_parser+='json.loads([line for line in '
779 json_parser+='fileinput.input()][0]).items()])'
781 echo $raw_event | python -c "$json_parser"
784 get_agent_by_uuid_mdt() {
787 local mds=mds$(($mdtidx + 1))
788 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
792 check_agent_registered_by_mdt() {
795 local mds=mds$(($mdtidx + 1))
796 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
797 if [[ ! -z "$agent" ]]; then
798 echo "found agent $agent on $mds"
800 error "uuid $uuid not found in agent list on $mds"
804 check_agent_unregistered_by_mdt() {
807 local mds=mds$(($mdtidx + 1))
808 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
809 if [[ -z "$agent" ]]; then
810 echo "uuid not found in agent list on $mds"
812 error "uuid found in agent list on $mds: $agent"
816 check_agent_registered() {
819 for mdsno in $(seq 1 $MDSCOUNT); do
820 check_agent_registered_by_mdt $uuid $((mdsno - 1))
824 check_agent_unregistered() {
827 for mdsno in $(seq 1 $MDSCOUNT); do
828 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
833 local agent=${1:-$(facet_active_host $SINGLEAGT)}
835 # Lustre mount-point is mandatory and last parameter on
837 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
839 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
841 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
847 # populate MDT device array
850 # cleanup from previous bad setup
853 # for recovery tests, coordinator needs to be started at mount
855 # the lustre conf must be without hsm on (like for sanity.sh)
856 echo "Set HSM on and start"
857 cdt_set_mount_state enabled
858 cdt_check_state enabled
860 echo "Set sanity-hsm HSM policy"
861 cdt_set_sanity_policy
863 # finished requests are quickly removed from list
864 set_hsm_param grace_delay 10
870 local f=$DIR/$tdir/$tfile
874 check_hsm_flags_user $f "0x00000000"
876 $RUNAS $LFS hsm_set --norelease $f ||
877 error "user could not change hsm flags"
878 check_hsm_flags_user $f "0x00000010"
880 $RUNAS $LFS hsm_clear --norelease $f ||
881 error "user could not clear hsm flags"
882 check_hsm_flags_user $f "0x00000000"
884 # User could not change those flags...
885 $RUNAS $LFS hsm_set --exists $f &&
886 error "user should not set this flag"
887 check_hsm_flags_user $f "0x00000000"
890 $LFS hsm_set --exists $f ||
891 error "root could not change hsm flags"
892 check_hsm_flags_user $f "0x00000001"
894 $LFS hsm_clear --exists $f ||
895 error "root could not clear hsm state"
896 check_hsm_flags_user $f "0x00000000"
899 run_test 1 "lfs hsm flags root/non-root access"
903 local f=$DIR/$tdir/$tfile
904 local fid=$(make_small $f)
908 $LFS hsm_archive $f || error "could not archive file"
909 wait_request_state $fid ARCHIVE SUCCEED
911 # Release and check states
912 $LFS hsm_release $f || error "could not release file"
913 echo -n "Verifying released state: "
914 check_hsm_flags $f "0x0000000d"
916 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
920 run_test 1a "mmap & cat a HSM released file"
924 $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
925 error "failed to set default stripe"
926 local f=$DIR/$tdir/$tfile
929 dd if=/dev/random of=$f bs=1M count=1 conv=sync ||
930 error "failed to create file"
931 local fid=$(path2fid $f)
936 $LFS hsm_archive $f || error "could not archive file"
937 wait_request_state $fid ARCHIVE SUCCEED
940 $LFS hsm_release $f || error "could not release file"
941 echo "verify released state: "
942 check_hsm_flags $f "0x0000000d" && echo "pass"
945 $LFS hsm_restore $f || error "could not restore file"
946 wait_request_state $fid RESTORE SUCCEED
947 echo "verify restored state: "
948 check_hsm_flags $f "0x00000009" && echo "pass"
952 run_test 1b "Archive, Release & Restore composite file"
956 local f=$DIR/$tdir/$tfile
958 # New files are not dirty
959 check_hsm_flags $f "0x00000000"
961 # For test, we simulate an archived file.
962 $LFS hsm_set --exists $f || error "user could not change hsm flags"
963 check_hsm_flags $f "0x00000001"
965 # chmod do not put the file dirty
966 chmod 600 $f || error "could not chmod test file"
967 check_hsm_flags $f "0x00000001"
969 # chown do not put the file dirty
970 chown $RUNAS_ID $f || error "could not chown test file"
971 check_hsm_flags $f "0x00000001"
973 # truncate put the file dirty
974 $TRUNCATE $f 1 || error "could not truncate test file"
975 check_hsm_flags $f "0x00000003"
977 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
978 check_hsm_flags $f "0x00000001"
980 run_test 2 "Check file dirtyness when doing setattr"
986 # New files are not dirty
988 check_hsm_flags $f "0x00000000"
990 # For test, we simulate an archived file.
991 $LFS hsm_set --exists $f ||
992 error "user could not change hsm flags"
993 check_hsm_flags $f "0x00000001"
995 # Reading a file, does not set dirty
996 cat $f > /dev/null || error "could not read file"
997 check_hsm_flags $f "0x00000001"
999 # Open for write without modifying data, does not set dirty
1000 openfile -f O_WRONLY $f || error "could not open test file"
1001 check_hsm_flags $f "0x00000001"
1003 # Append to a file sets it dirty
1004 cp -p /etc/passwd $f.append || error "could not create file"
1005 $LFS hsm_set --exists $f.append ||
1006 error "user could not change hsm flags"
1007 dd if=/etc/passwd of=$f.append bs=1 count=3\
1008 conv=notrunc oflag=append status=noxfer ||
1009 file_creation_failure dd $f.append $?
1010 check_hsm_flags $f.append "0x00000003"
1012 # Modify a file sets it dirty
1013 cp -p /etc/passwd $f.modify || error "could not create file"
1014 $LFS hsm_set --exists $f.modify ||
1015 error "user could not change hsm flags"
1016 dd if=/dev/zero of=$f.modify bs=1 count=3\
1017 conv=notrunc status=noxfer ||
1018 file_creation_failure dd $f.modify $?
1019 check_hsm_flags $f.modify "0x00000003"
1021 # Open O_TRUNC sets dirty
1022 cp -p /etc/passwd $f.trunc || error "could not create file"
1023 $LFS hsm_set --exists $f.trunc ||
1024 error "user could not change hsm flags"
1025 cp /etc/group $f.trunc || error "could not override a file"
1026 check_hsm_flags $f.trunc "0x00000003"
1028 # Mmapped a file sets dirty
1029 cp -p /etc/passwd $f.mmap || error "could not create file"
1030 $LFS hsm_set --exists $f.mmap ||
1031 error "user could not change hsm flags"
1032 multiop $f.mmap OSMWUc || error "could not mmap a file"
1033 check_hsm_flags $f.mmap "0x00000003"
1035 run_test 3 "Check file dirtyness when opening for write"
1039 local f=$DIR/$tdir/$tfile
1040 local fid=$(make_small $f)
1043 local st=$(get_request_state $fid CANCEL)
1044 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1046 run_test 4 "Useless cancel must not be registered"
1049 # test needs a running copytool
1053 local f=$DIR/$tdir/$tfile
1054 local fid=$(copy_file /etc/passwd $f)
1056 wait_request_state $fid ARCHIVE SUCCEED
1058 check_hsm_flags $f "0x00000009"
1062 run_test 8 "Test default archive number"
1065 # we do not use the default one to be sure
1066 local new_an=$((HSM_ARCHIVE_NUMBER + 1))
1068 copytool_setup $SINGLEAGT $MOUNT $new_an
1070 # give time for CT to register with MDTs
1071 sleep $(($MDSCOUNT*2))
1072 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1073 check_agent_registered $uuid
1076 local f=$DIR/$tdir/$tfile
1077 local fid=$(copy_file /etc/passwd $f)
1078 $LFS hsm_archive --archive $new_an $f
1079 wait_request_state $fid ARCHIVE SUCCEED
1081 check_hsm_flags $f "0x00000009"
1085 run_test 9 "Use of explicit archive number, with dedicated copytool"
1088 needclients 3 || return 0
1094 copytool_cleanup $(comma_list $(agts_nodes))
1096 # start all of the copytools
1097 for n in $(seq $AGTCOUNT); do
1098 copytool_setup agt$n
1101 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
1104 for n in $(seq $AGTCOUNT); do
1105 file=$DIR/$tdir/$tfile.$n
1106 fid=$(make_small $file)
1108 $LFS hsm_archive $file || error "could not archive file $file"
1109 wait_request_state $fid ARCHIVE SUCCEED
1110 check_hsm_flags $file "0x00000009"
1114 copytool_cleanup $(comma_list $(agts_nodes))
1116 run_test 9a "Multiple remote agents"
1119 # test needs a running copytool
1122 mkdir -p $DIR/$tdir/d1
1123 local f=$DIR/$tdir/$tfile
1124 local fid=$(copy_file /etc/hosts $f)
1125 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1126 error "hsm_archive failed"
1127 wait_request_state $fid ARCHIVE SUCCEED
1129 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1130 error "fid $fid not in archive $HSM_ARCHIVE"
1131 echo "Verifying content"
1132 do_facet $SINGLEAGT diff $f $AFILE || error "archived file differs"
1133 echo "Verifying hsm state "
1134 check_hsm_flags $f "0x00000009"
1136 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1137 local st=$(get_hsm_archive_id $f)
1138 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1139 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1144 run_test 10a "Archive a file"
1147 # test needs a running copytool
1151 local f=$DIR/$tdir/$tfile
1152 local fid=$(copy_file /etc/hosts $f)
1153 $LFS hsm_archive $f || error "archive request failed"
1154 wait_request_state $fid ARCHIVE SUCCEED
1156 $LFS hsm_archive $f || error "archive of non dirty file failed"
1157 local cnt=$(get_request_count $fid ARCHIVE)
1158 [[ "$cnt" == "1" ]] ||
1159 error "archive of non dirty file must not make a request"
1163 run_test 10b "Archive of non dirty file must work without doing request"
1166 # test needs a running copytool
1170 local f=$DIR/$tdir/$tfile
1171 local fid=$(copy_file /etc/hosts $f)
1172 $LFS hsm_set --noarchive $f
1173 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1177 run_test 10c "Check forbidden archive"
1180 # test needs a running copytool
1184 local f=$DIR/$tdir/$tfile
1185 local fid=$(copy_file /etc/hosts $f)
1186 $LFS hsm_archive $f || error "cannot archive $f"
1187 wait_request_state $fid ARCHIVE SUCCEED
1189 local ar=$(get_hsm_archive_id $f)
1190 local dflt=$(get_hsm_param default_archive_id)
1191 [[ $ar == $dflt ]] ||
1192 error "archived file is not on default archive: $ar != $dflt"
1196 run_test 10d "Archive a file on the default archive id"
1200 copy2archive /etc/hosts $tdir/$tfile
1201 local f=$DIR/$tdir/$tfile
1203 import_file $tdir/$tfile $f
1204 echo -n "Verifying released state: "
1205 check_hsm_flags $f "0x0000000d"
1207 local LSZ=$(stat -c "%s" $f)
1208 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" $HSM_ARCHIVE/$tdir/$tfile)
1210 echo "Verifying imported size $LSZ=$ASZ"
1211 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1212 echo -n "Verifying released pattern: "
1213 local PTRN=$($GETSTRIPE -L $f)
1215 [[ $PTRN == 80000001 ]] || error "Is not released"
1216 local fid=$(path2fid $f)
1217 echo "Verifying new fid $fid in archive"
1219 local AFILE=$(do_facet $SINGLEAGT ls $HSM_ARCHIVE'/*/*/*/*/*/*/'$fid) ||
1220 error "fid $fid not in archive $HSM_ARCHIVE"
1222 run_test 11a "Import a file"
1225 # test needs a running copytool
1229 local f=$DIR/$tdir/$tfile
1230 local fid=$(copy_file /etc/hosts $f)
1231 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1232 error "hsm_archive failed"
1233 wait_request_state $fid ARCHIVE SUCCEED
1235 local FILE_HASH=$(md5sum $f)
1240 echo "$FILE_HASH" | md5sum -c
1242 [[ $? -eq 0 ]] || error "Restored file differs"
1246 run_test 11b "Import a deleted file using its FID"
1249 # test needs a running copytool
1253 copy2archive /etc/hosts $tdir/$tfile
1255 local f=$DIR/$tdir/$tfile
1256 import_file $tdir/$tfile $f
1257 local f2=$DIR2/$tdir/$tfile
1258 echo "Verifying released state: "
1259 check_hsm_flags $f2 "0x0000000d"
1261 local fid=$(path2fid $f2)
1262 $LFS hsm_restore $f2
1263 wait_request_state $fid RESTORE SUCCEED
1265 echo "Verifying file state: "
1266 check_hsm_flags $f2 "0x00000009"
1268 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1270 [[ $? -eq 0 ]] || error "Restored file differs"
1274 run_test 12a "Restore an imported file explicitly"
1277 # test needs a running copytool
1281 copy2archive /etc/hosts $tdir/$tfile
1283 local f=$DIR/$tdir/$tfile
1284 import_file $tdir/$tfile $f
1285 echo "Verifying released state: "
1286 check_hsm_flags $f "0x0000000d"
1288 cat $f > /dev/null || error "File read failed"
1290 echo "Verifying file state after restore: "
1291 check_hsm_flags $f "0x00000009"
1293 do_facet $SINGLEAGT diff -q $HSM_ARCHIVE/$tdir/$tfile $f
1295 [[ $? -eq 0 ]] || error "Restored file differs"
1299 run_test 12b "Restore an imported file implicitly"
1302 [ "$OSTCOUNT" -lt "2" ] && skip_env "skipping 2-stripe test" && return
1304 # test needs a running copytool
1308 local f=$DIR/$tdir/$tfile
1309 $LFS setstripe -c 2 $f
1311 fid=$(make_custom_file_for_progress $f 5)
1312 [ $? != 0 ] && skip "not enough free space" && return
1314 local FILE_CRC=$(md5sum $f)
1316 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1317 wait_request_state $fid ARCHIVE SUCCEED
1318 $LFS hsm_release $f || error "release $f failed"
1320 echo "$FILE_CRC" | md5sum -c
1322 [[ $? -eq 0 ]] || error "Restored file differs"
1326 run_test 12c "Restore a file with stripe of 2"
1329 # test needs a running copytool
1334 local f=$DIR/$tdir/$tfile
1335 local fid=$(copy_file /etc/hosts $f)
1336 $LFS hsm_restore $f || error "restore of non archived file failed"
1337 local cnt=$(get_request_count $fid RESTORE)
1338 [[ "$cnt" == "0" ]] ||
1339 error "restore non archived must not make a request"
1340 $LFS hsm_archive $f ||
1341 error "archive request failed"
1342 wait_request_state $fid ARCHIVE SUCCEED
1343 $LFS hsm_restore $f ||
1344 error "restore of non released file failed"
1345 local cnt=$(get_request_count $fid RESTORE)
1346 [[ "$cnt" == "0" ]] ||
1347 error "restore a non dirty file must not make a request"
1351 run_test 12d "Restore of a non archived, non released file must work"\
1352 " without doing request"
1355 # test needs a running copytool
1358 mkdir -p $DIR/$tdir $HSM_ARCHIVE/$tdir
1359 local f=$DIR/$tdir/$tfile
1360 local fid=$(copy_file /etc/hosts $f)
1361 $LFS hsm_archive $f || error "archive request failed"
1362 wait_request_state $fid ARCHIVE SUCCEED
1365 cat /etc/hosts >> $f
1369 $LFS hsm_restore $f && error "restore a dirty file must fail"
1373 run_test 12e "Check forbidden restore"
1376 # test needs a running copytool
1380 local f=$DIR/$tdir/$tfile
1381 local fid=$(copy_file /etc/hosts $f)
1383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1384 wait_request_state $fid ARCHIVE SUCCEED
1385 $LFS hsm_release $f || error "release of $f failed"
1387 wait_request_state $fid RESTORE SUCCEED
1389 echo -n "Verifying file state: "
1390 check_hsm_flags $f "0x00000009"
1392 diff -q /etc/hosts $f
1394 [[ $? -eq 0 ]] || error "Restored file differs"
1398 run_test 12f "Restore a released file explicitly"
1401 # test needs a running copytool
1405 local f=$DIR/$tdir/$tfile
1406 local fid=$(copy_file /etc/hosts $f)
1408 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1409 wait_request_state $fid ARCHIVE SUCCEED
1410 $LFS hsm_release $f || error "release of $f failed"
1412 diff -q /etc/hosts $f
1415 # we check we had a restore done
1416 wait_request_state $fid RESTORE SUCCEED
1418 [[ $st -eq 0 ]] || error "Restored file differs"
1422 run_test 12g "Restore a released file implicitly"
1425 needclients 2 || return 0
1427 # test needs a running copytool
1431 local f=$DIR/$tdir/$tfile
1432 local fid=$(copy_file /etc/hosts $f)
1434 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1435 wait_request_state $fid ARCHIVE SUCCEED
1436 $LFS hsm_release $f || error "release of $f failed"
1438 do_node $CLIENT2 diff -q /etc/hosts $f
1441 # we check we had a restore done
1442 wait_request_state $fid RESTORE SUCCEED
1444 [[ $st -eq 0 ]] || error "Restored file differs"
1448 run_test 12h "Restore a released file implicitly from a second node"
1451 # test needs a running copytool
1455 local f=$DIR/$tdir/$tfile
1456 local fid=$(copy_file /etc/passwd $f)
1457 $LFS hsm_archive $f || error "archive of $f failed"
1458 wait_request_state $fid ARCHIVE SUCCEED
1460 $LFS hsm_release $f || error "release of $f failed"
1464 [[ $? -eq 0 ]] || error "Restored file differs"
1468 run_test 12m "Archive/release/implicit restore"
1471 # test needs a running copytool
1475 copy2archive /etc/hosts $tdir/$tfile
1477 local f=$DIR/$tdir/$tfile
1478 import_file $tdir/$tfile $f
1480 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1481 error "Restored file differs"
1483 $LFS hsm_release $f || error "release of $f failed"
1487 run_test 12n "Import/implicit restore/release"
1490 # test needs a running copytool
1494 local f=$DIR/$tdir/$tfile
1495 local fid=$(copy_file /etc/hosts $f)
1497 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1498 wait_request_state $fid ARCHIVE SUCCEED
1499 $LFS hsm_release $f || error "release of $f failed"
1501 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1502 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1504 # set no retry action mode
1507 diff -q /etc/hosts $f
1510 # we check we had a restore failure
1511 wait_request_state $fid RESTORE FAILED
1513 [[ $st -eq 0 ]] && error "Restore must fail"
1515 # remove no retry action mode
1518 # check file is still released
1519 check_hsm_flags $f "0x0000000d"
1521 # retry w/o failure injection
1522 do_facet $SINGLEMDS lctl set_param fail_loc=0
1524 # to be sure previous RESTORE result is gone
1526 wait_for_grace_delay
1528 diff -q /etc/hosts $f
1531 # we check we had a restore done
1532 wait_request_state $fid RESTORE SUCCEED
1534 [[ $st -eq 0 ]] || error "Restored file differs"
1538 run_test 12o "Layout-swap failure during Restore leaves file released"
1541 # test needs a running copytool
1545 local f=$DIR/$tdir/$tfile
1546 local fid=$(copy_file /etc/hosts $f)
1548 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1549 wait_request_state $fid ARCHIVE SUCCEED
1550 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1551 $LFS hsm_release $f || error "cannot release $f"
1552 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1553 $LFS hsm_release $f || error "cannot release $f"
1554 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1558 run_test 12p "implicit restore of a file on copytool mount point"
1560 cleanup_test_12q() {
1562 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1563 error "cannot umount $MOUNT3 on $SINGLEAGT"
1567 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1568 skip "need MDS version at least 2.7.58" && return 0
1570 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1571 error "cannot mount $MOUNT3 on $SINGLEAGT"
1573 trap cleanup_test_12q EXIT
1575 # test needs a running copytool
1576 copytool_setup $SINGLEAGT $MOUNT3
1579 local f=$DIR/$tdir/$tfile
1580 local f2=$DIR2/$tdir/$tfile
1581 local fid=$(make_small $f)
1582 local orig_size=$(stat -c "%s" $f)
1584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1585 wait_request_state $fid ARCHIVE SUCCEED
1587 $LFS hsm_release $f || error "could not release file"
1588 check_hsm_flags $f "0x0000000d"
1591 wait_copytools || error "copytool failed to stop"
1593 cat $f > /dev/null &
1595 # wait a bit to allow implicit restore request to be handled.
1596 # if not, next stat would also block on layout-lock.
1599 local size=$(stat -c "%s" $f2)
1600 [ $size -eq $orig_size ] ||
1601 error "$f2: wrong size after archive: $size != $orig_size"
1603 HSM_ARCHIVE_PURGE=false copytool_setup $SINGLEAGT /mnt/lustre3
1607 size=$(stat -c "%s" $f)
1608 [ $size -eq $orig_size ] ||
1609 error "$f: wrong size after restore: $size != $orig_size"
1611 size=$(stat -c "%s" $f2)
1612 [ $size -eq $orig_size ] ||
1613 error "$f2: wrong size after restore: $size != $orig_size"
1617 size=$(stat -c "%s" $f)
1619 error "$f: wrong size after overwrite: $size != 0"
1621 size=$(stat -c "%s" $f2)
1623 error "$f2: wrong size after overwrite: $size != 0"
1626 zconf_umount $(facet_host $SINGLEAGT) $MOUNT3 ||
1627 error "cannot umount $MOUNT3 on $SINGLEAGT"
1629 run_test 12q "file attributes are refreshed after restore"
1632 # test needs a running copytool
1635 local ARC_SUBDIR="import.orig"
1639 # populate directory to be imported
1640 for d in $(seq 1 10); do
1641 local CURR_DIR="$HSM_ARCHIVE/$ARC_SUBDIR/dir.$d"
1642 do_facet $SINGLEAGT mkdir -p "$CURR_DIR"
1643 for f in $(seq 1 10); do
1644 CURR_FILE="$CURR_DIR/$tfile.$f"
1645 # write file-specific data
1646 do_facet $SINGLEAGT \
1647 "echo d=$d, f=$f, dir=$CURR_DIR, "\
1648 "file=$CURR_FILE > $CURR_FILE"
1652 import_file "$ARC_SUBDIR" $DIR/$tdir
1653 # diff lustre content and origin (triggers file restoration)
1654 # there must be 10x10 identical files, and no difference
1655 local cnt_ok=$(do_facet $SINGLEAGT diff -rs $HSM_ARCHIVE/$ARC_SUBDIR \
1656 $DIR/$tdir/$ARC_SUBDIR | grep identical | wc -l)
1657 local cnt_diff=$(do_facet $SINGLEAGT diff -r $HSM_ARCHIVE/$ARC_SUBDIR \
1658 $DIR/$tdir/$ARC_SUBDIR | wc -l)
1660 [ $cnt_diff -eq 0 ] ||
1661 error "$cnt_diff imported files differ from read data"
1662 [ $cnt_ok -eq 100 ] ||
1663 error "not enough identical files ($cnt_ok != 100)"
1667 run_test 13 "Recursively import and restore a directory"
1670 # test needs a running copytool
1675 local f=$DIR/$tdir/$tfile
1676 local fid=$(make_small $f)
1677 local sum=$(md5sum $f | awk '{print $1}')
1678 $LFS hsm_archive $f || error "could not archive file"
1679 wait_request_state $fid ARCHIVE SUCCEED
1683 # create released file (simulate llapi_hsm_import call)
1685 local fid2=$(path2fid $f)
1686 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1687 $LFS hsm_release $f || error "could not release file"
1689 # rebind the archive to the newly created file
1690 echo "rebind $fid to $fid2"
1692 do_facet $SINGLEAGT \
1693 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1694 --rebind $fid $fid2 $DIR" || error "could not rebind file"
1696 # restore file and compare md5sum
1697 local sum2=$(md5sum $f | awk '{print $1}')
1699 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1703 run_test 14 "Rebind archived file to a new fid"
1706 # test needs a running copytool
1711 local f=$DIR/$tdir/$tfile
1713 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1717 for i in $(seq 1 $count); do
1718 fids[$i]=$(make_small $f.$i)
1719 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1720 $LFS hsm_archive $f.$i || error "could not archive file"
1722 wait_all_done $(($count*60))
1726 for i in $(seq 1 $count); do
1729 local fid2=$(path2fid $f.$i)
1730 # add the rebind operation to the list
1731 echo ${fids[$i]} $fid2 >> $tmpfile
1733 # set it released (simulate llapi_hsm_import call)
1734 $LFS hsm_set --archived --exists $f.$i ||
1735 error "could not force hsm flags"
1736 $LFS hsm_release $f.$i || error "could not release file"
1738 nl=$(wc -l < $tmpfile)
1739 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1741 echo "rebind list of files"
1742 do_facet $SINGLEAGT \
1743 "$HSMTOOL --archive $HSM_ARCHIVE_NUMBER --hsm-root $HSM_ARCHIVE\
1744 --rebind $tmpfile $DIR" || error "could not rebind file list"
1746 # restore files and compare md5sum
1747 for i in $(seq 1 $count); do
1748 local sum2=$(md5sum $f.$i | awk '{print $1}')
1749 [[ $sum2 == ${sums[$i]} ]] ||
1750 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1756 run_test 15 "Rebind a list of files"
1759 # test needs a running copytool
1763 # create a known size file so we can verify transfer speed
1766 dd if=/dev/zero of=$ref bs=1M count=20
1769 local f=$DIR/$tdir/$tfile
1770 local fid=$(copy_file $ref $f)
1772 local start=$(date +%s)
1774 wait_request_state $fid ARCHIVE SUCCEED
1775 local end=$(date +%s)
1776 # Add 1 to account for rounding errors between start and end (LU-8155)
1777 local duration=$((end - start + 1))
1779 [[ $duration -ge $((goal - 1)) ]] ||
1780 error "Transfer is too fast $duration < $goal"
1784 run_test 16 "Test CT bandwith control option"
1789 local f=$DIR/$tdir/$tfile
1790 touch $f || error "touch $f failed"
1792 # Could not release a non-archived file
1793 $LFS hsm_release $f && error "release should not succeed"
1795 # For following tests, we must test them with HS_ARCHIVED set
1796 $LFS hsm_set --exists --archived $f || error "could not add flag"
1798 # Could not release a file if no-release is set
1799 $LFS hsm_set --norelease $f || error "could not add flag"
1800 $LFS hsm_release $f && error "release should not succeed"
1801 $LFS hsm_clear --norelease $f || error "could not remove flag"
1803 # Could not release a file if lost
1804 $LFS hsm_set --lost $f || error "could not add flag"
1805 $LFS hsm_release $f && error "release should not succeed"
1806 $LFS hsm_clear --lost $f || error "could not remove flag"
1808 # Could not release a file if dirty
1809 $LFS hsm_set --dirty $f || error "could not add flag"
1810 $LFS hsm_release $f && error "release should not succeed"
1811 $LFS hsm_clear --dirty $f || error "could not remove flag"
1813 run_test 20 "Release is not permitted"
1816 # test needs a running copytool
1820 local f=$DIR/$tdir/test_release
1822 # Create a file and check its states
1823 local fid=$(make_small $f)
1824 check_hsm_flags $f "0x00000000"
1826 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1827 # used until file is flushed to disk
1828 if [ $(facet_fstype ost1) == "zfs" ]; then
1829 # this causes an OST_SYNC rpc to be sent
1830 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1831 # clear locks to reread file data
1832 cancel_lru_locks osc
1835 local orig_size=$(stat -c "%s" $f)
1836 local orig_blocks=$(stat -c "%b" $f)
1838 start_full_debug_logging
1840 $LFS hsm_archive $f || error "could not archive file"
1841 wait_request_state $fid ARCHIVE SUCCEED
1843 local blocks=$(stat -c "%b" $f)
1844 [ $blocks -eq $orig_blocks ] ||
1845 error "$f: wrong block number after archive: " \
1846 "$blocks != $orig_blocks"
1847 local size=$(stat -c "%s" $f)
1848 [ $size -eq $orig_size ] ||
1849 error "$f: wrong size after archive: $size != $orig_size"
1851 # Release and check states
1852 $LFS hsm_release $f || error "could not release file"
1853 check_hsm_flags $f "0x0000000d"
1855 blocks=$(stat -c "%b" $f)
1856 [ $blocks -gt 5 ] &&
1857 error "$f: too many blocks after release: $blocks > 5"
1858 size=$(stat -c "%s" $f)
1859 [ $size -ne $orig_size ] &&
1860 error "$f: wrong size after release: $size != $orig_size"
1862 # Check we can release an file without stripe info
1866 check_hsm_flags $f "0x00000000"
1867 $LFS hsm_archive $f || error "could not archive file"
1868 wait_request_state $fid ARCHIVE SUCCEED
1870 # Release and check states
1871 $LFS hsm_release $f || error "could not release file"
1872 check_hsm_flags $f "0x0000000d"
1874 # Release again a file that is already released is OK
1875 $LFS hsm_release $f || fail "second release should succeed"
1876 check_hsm_flags $f "0x0000000d"
1878 stop_full_debug_logging
1882 run_test 21 "Simple release tests"
1885 # test needs a running copytool
1890 local f=$DIR/$tdir/test_release
1891 local swap=$DIR/$tdir/test_swap
1893 # Create a file and check its states
1894 local fid=$(make_small $f)
1895 check_hsm_flags $f "0x00000000"
1897 $LFS hsm_archive $f || error "could not archive file"
1898 wait_request_state $fid ARCHIVE SUCCEED
1900 # Release and check states
1901 $LFS hsm_release $f || error "could not release file"
1902 check_hsm_flags $f "0x0000000d"
1905 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1910 run_test 22 "Could not swap a release file"
1913 # test needs a running copytool
1918 local f=$DIR/$tdir/test_mtime
1920 # Create a file and check its states
1921 local fid=$(make_small $f)
1922 check_hsm_flags $f "0x00000000"
1924 $LFS hsm_archive $f || error "could not archive file"
1925 wait_request_state $fid ARCHIVE SUCCEED
1927 # Set modification time in the past
1928 touch -m -a -d @978261179 $f
1930 # Release and check states
1931 $LFS hsm_release $f || error "could not release file"
1932 check_hsm_flags $f "0x0000000d"
1934 local MTIME=$(stat -c "%Y" $f)
1935 local ATIME=$(stat -c "%X" $f)
1936 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1937 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1941 run_test 23 "Release does not change a/mtime (utime)"
1944 local file=$DIR/$tdir/$tfile
1953 # test needs a running copytool
1958 fid=$(make_small $file)
1960 # Create a file and check its states
1961 check_hsm_flags $file "0x00000000"
1963 # Ensure atime is less than mtime and ctime.
1967 atime0=$(stat -c "%X" $file)
1968 mtime0=$(stat -c "%Y" $file)
1969 ctime0=$(stat -c "%Z" $file)
1971 [ $atime0 -lt $mtime0 ] ||
1972 error "atime $atime0 is not less than mtime $mtime0"
1974 [ $atime0 -lt $ctime0 ] ||
1975 error "atime $atime0 is not less than ctime $ctime0"
1977 # Archive should not change any timestamps.
1978 $LFS hsm_archive $file || error "cannot archive '$file'"
1979 wait_request_state $fid ARCHIVE SUCCEED
1981 atime1=$(stat -c "%X" $file)
1982 mtime1=$(stat -c "%Y" $file)
1983 ctime1=$(stat -c "%Z" $file)
1985 [ $atime0 -eq $atime1 ] ||
1986 error "archive changed atime from $atime0 to $atime1"
1988 [ $mtime0 -eq $mtime1 ] ||
1989 error "archive changed mtime from $mtime0 to $mtime1"
1991 [ $ctime0 -eq $ctime1 ] ||
1992 error "archive changed ctime from $ctime0 to $ctime1"
1994 # Release should not change any timestamps.
1995 $LFS hsm_release $file || error "cannot release '$file'"
1996 check_hsm_flags $file "0x0000000d"
1998 atime1=$(stat -c "%X" $file)
1999 mtime1=$(stat -c "%Y" $file)
2000 ctime1=$(stat -c "%Z" $file)
2002 [ $atime0 -eq $atime1 ] ||
2003 error "release changed atime from $atime0 to $atime1"
2005 [ $mtime0 -eq $mtime1 ] ||
2006 error "release changed mtime from $mtime0 to $mtime1"
2008 [ $ctime0 -eq $ctime1 ] ||
2009 error "release changed ctime from $ctime0 to $ctime1"
2011 # Restore should not change any timestamps.
2012 $LFS hsm_restore $file
2013 wait_request_state $fid RESTORE SUCCEED
2015 atime1=$(stat -c "%X" $file)
2016 mtime1=$(stat -c "%Y" $file)
2017 ctime1=$(stat -c "%Z" $file)
2019 [ $atime0 -eq $atime1 ] ||
2020 error "restore changed atime from $atime0 to $atime1"
2022 [ $mtime0 -eq $mtime1 ] ||
2023 error "restore changed mtime from $mtime0 to $mtime1"
2025 [ $ctime0 -eq $ctime1 ] ||
2026 error "restore changed ctime from $ctime0 to $ctime1"
2030 # Once more, after unmount and mount.
2031 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2032 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2034 atime1=$(stat -c "%X" $file)
2035 mtime1=$(stat -c "%Y" $file)
2036 ctime1=$(stat -c "%Z" $file)
2038 [ $atime0 -eq $atime1 ] ||
2039 error "remount changed atime from $atime0 to $atime1"
2041 [ $mtime0 -eq $mtime1 ] ||
2042 error "remount changed mtime from $mtime0 to $mtime1"
2044 [ $ctime0 -eq $ctime1 ] ||
2045 error "remount changed ctime from $ctime0 to $ctime1"
2047 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2050 local file=$DIR/$tdir/$tfile
2056 # Test needs a running copytool.
2060 # Check that root can do HSM actions on a regular user's file.
2062 fid=$(make_small $file)
2063 sum0=$(md5sum $file)
2065 chown $RUNAS_ID:$RUNAS_GID $file ||
2066 error "cannot chown '$file' to '$RUNAS_ID'"
2068 chmod ugo-w $DIR/$tdir ||
2069 error "cannot chmod '$DIR/$tdir'"
2071 $LFS hsm_archive $file
2072 wait_request_state $fid ARCHIVE SUCCEED
2074 $LFS hsm_release $file
2075 check_hsm_flags $file "0x0000000d"
2077 $LFS hsm_restore $file
2078 wait_request_state $fid RESTORE SUCCEED
2080 # Check that ordinary user can get HSM state.
2081 $RUNAS $LFS hsm_state $file ||
2082 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2084 $LFS hsm_release $file
2085 check_hsm_flags $file "0x0000000d"
2087 # Check that ordinary user can accessed released file.
2088 sum1=$($RUNAS md5sum $file) ||
2089 error "user '$RUNAS_ID' cannot read '$file'"
2091 [ "$sum0" == "$sum1" ] ||
2092 error "md5sum mismatch for '$file'"
2096 run_test 24b "root can archive, release, and restore user files"
2098 cleanup_test_24c() {
2100 set_hsm_param user_request_mask RESTORE
2101 set_hsm_param group_request_mask RESTORE
2102 set_hsm_param other_request_mask RESTORE
2106 local file=$DIR/$tdir/$tfile
2107 local action=archive
2112 # test needs a running copytool
2117 # Save the default masks and check that cleanup_24c will
2118 # restore the request masks correctly.
2119 user_save=$(get_hsm_param user_request_mask)
2120 group_save=$(get_hsm_param group_request_mask)
2121 other_save=$(get_hsm_param other_request_mask)
2123 [ "$user_save" == RESTORE ] ||
2124 error "user_request_mask is '$user_save' expected 'RESTORE'"
2125 [ "$group_save" == RESTORE ] ||
2126 error "group_request_mask is '$group_save' expected 'RESTORE'"
2127 [ "$other_save" == RESTORE ] ||
2128 error "other_request_mask is '$other_save' expected 'RESTORE'"
2130 trap cleanup_test_24c EXIT
2135 chown $RUNAS_ID:nobody $file ||
2136 error "cannot chown '$file' to '$RUNAS_ID:nobody'"
2138 $RUNAS $LFS hsm_$action $file &&
2139 error "$action by user should fail"
2141 set_hsm_param user_request_mask $action
2142 $RUNAS $LFS hsm_$action $file ||
2143 error "$action by user should succeed"
2148 chown nobody:$RUNAS_GID $file ||
2149 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2151 $RUNAS $LFS hsm_$action $file &&
2152 error "$action by group should fail"
2154 set_hsm_param group_request_mask $action
2155 $RUNAS $LFS hsm_$action $file ||
2156 error "$action by group should succeed"
2161 chown nobody:nobody $file ||
2162 error "cannot chown '$file' to 'nobody:nobody'"
2164 $RUNAS $LFS hsm_$action $file &&
2165 error "$action by other should fail"
2167 set_hsm_param other_request_mask $action
2168 $RUNAS $LFS hsm_$action $file ||
2169 error "$action by other should succeed"
2174 run_test 24c "check that user,group,other request masks work"
2176 cleanup_test_24d() {
2178 mount -o remount,rw $MOUNT2
2179 zconf_umount $(facet_host $SINGLEAGT) "$MOUNT3"
2183 local file1=$DIR/$tdir/$tfile
2184 local file2=$DIR2/$tdir/$tfile
2190 fid1=$(make_small $file1)
2193 $LFS getstripe $file1
2195 trap cleanup_test_24d EXIT
2196 zconf_mount $(facet_host $SINGLEAGT) "$MOUNT3" ||
2197 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2198 copytool_setup $SINGLEAGT "$MOUNT3" ||
2199 error "unable to setup a copytool for the test"
2201 mount -o remount,ro $MOUNT2
2203 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2204 start_full_debug_logging
2206 fid2=$(path2fid $file2)
2207 [ "$fid1" == "$fid2" ] ||
2208 error "FID mismatch '$fid1' != '$fid2'"
2210 $LFS hsm_archive $file2 &&
2211 error "archive should fail on read-only mount"
2212 check_hsm_flags $file1 "0x00000000"
2214 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2215 wait_request_state $fid1 ARCHIVE SUCCEED
2217 stop_full_debug_logging
2219 $LFS hsm_release $file1
2220 $LFS hsm_restore $file2
2221 wait_request_state $fid1 RESTORE SUCCEED
2223 $LFS hsm_release $file1 || error "cannot release '$file1'"
2224 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2226 $LFS hsm_release $file2 &&
2227 error "release should fail on read-only mount"
2232 run_test 24d "check that read-only mounts are respected"
2239 local f=$DIR/$tdir/$tfile
2242 fid=$(make_small $f) || error "cannot create $f"
2243 $LFS hsm_archive $f || error "cannot archive $f"
2244 wait_request_state $fid ARCHIVE SUCCEED
2245 $LFS hsm_release $f || error "cannot release $f"
2246 while ! $LFS hsm_state $f | grep released; do
2250 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2254 run_test 24e "tar succeeds on HSM released files" # LU-6213
2258 # test needs a running copytool
2261 mkdir -p $DIR/$tdir/d1
2262 local f=$DIR/$tdir/$tfile
2263 local fid=$(copy_file /etc/hosts $f)
2266 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
2267 error "hsm_archive failed"
2268 wait_request_state $fid ARCHIVE SUCCEED
2269 $LFS hsm_release $f || error "cannot release $f"
2270 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2273 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2274 error "Can not recover the tar contents"
2276 echo "Sum0 = $sum0, sum1 = $sum1"
2277 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2281 run_test 24f "root can archive, release, and restore tar files"
2284 # test needs a running copytool
2288 copy2archive /etc/hosts $tdir/$tfile
2290 local f=$DIR/$tdir/$tfile
2292 import_file $tdir/$tfile $f
2294 $LFS hsm_set --lost $f
2299 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2303 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2304 " (Operation not permitted)"
2307 # test needs a running copytool
2312 local f=$DIR/$tdir/$tfile
2313 local fid=$(copy_file /etc/passwd $f)
2315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2316 wait_request_state $fid ARCHIVE SUCCEED
2319 $LFS hsm_set --lost $f
2323 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2327 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2328 " (Operation not permitted)"
2331 # test needs a running copytool
2335 local f=$DIR/$tdir/$tfile
2337 fid=$(make_custom_file_for_progress $f 39 1000000)
2338 [ $? != 0 ] && skip "not enough free space" && return
2340 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2341 wait_request_state $fid ARCHIVE SUCCEED
2344 wait_request_state $fid REMOVE SUCCEED
2346 check_hsm_flags $f "0x00000000"
2350 run_test 26 "Remove the archive of a valid file"
2352 cleanup_test_26a() {
2354 set_hsm_param remove_archive_on_last_unlink 0
2355 set_hsm_param loop_period $orig_loop_period
2356 set_hsm_param grace_delay $orig_grace_delay
2361 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2362 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2364 # test needs a running copytool
2368 local f=$DIR/$tdir/$tfile
2369 local fid=$(copy_file /etc/passwd $f)
2371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2372 wait_request_state $fid ARCHIVE SUCCEED
2374 local f2=$DIR/$tdir/${tfile}_2
2375 local fid2=$(copy_file /etc/passwd $f2)
2377 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2378 wait_request_state $fid2 ARCHIVE SUCCEED
2380 local f3=$DIR/$tdir/${tfile}_3
2381 local fid3=$(copy_file /etc/passwd $f3)
2383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2384 wait_request_state $fid3 ARCHIVE SUCCEED
2386 trap cleanup_test_26a EXIT
2388 # set a long grace_delay vs short loop_period
2389 local orig_loop_period=$(get_hsm_param loop_period)
2390 local orig_grace_delay=$(get_hsm_param grace_delay)
2391 set_hsm_param loop_period 10
2392 set_hsm_param grace_delay 100
2396 set_hsm_param remove_archive_on_last_unlink 1
2398 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2403 set_hsm_param remove_archive_on_last_unlink 0
2405 wait_request_state $fid2 REMOVE SUCCEED
2407 assert_request_count $fid REMOVE 0 \
2408 "Unexpected archived data remove request for $f"
2409 assert_request_count $fid3 REMOVE 0 \
2410 "Unexpected archived data remove request for $f3"
2414 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2416 cleanup_test_26b() {
2418 set_hsm_param remove_archive_on_last_unlink 0
2424 # test needs a running copytool
2428 local f=$DIR/$tdir/$tfile
2429 local fid=$(copy_file /etc/passwd $f)
2431 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2432 wait_request_state $fid ARCHIVE SUCCEED
2434 trap cleanup_test_26b EXIT
2436 set_hsm_param remove_archive_on_last_unlink 1
2439 cdt_check_state stopped
2443 set_hsm_param remove_archive_on_last_unlink 0
2445 wait_request_state $fid REMOVE WAITING
2448 # copytool must re-register
2450 wait_copytools || error "copytool failed to stop"
2451 HSM_ARCHIVE_PURGE=false copytool_setup
2453 wait_request_state $fid REMOVE SUCCEED
2457 run_test 26b "RAoLU policy when CDT off"
2459 cleanup_test_26c() {
2461 set_hsm_param remove_archive_on_last_unlink 0
2462 set_hsm_param loop_period $orig_loop_period
2463 set_hsm_param grace_delay $orig_grace_delay
2469 # test needs a running copytool
2473 local f=$DIR/$tdir/$tfile
2474 local fid=$(copy_file /etc/passwd $f)
2476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2477 wait_request_state $fid ARCHIVE SUCCEED
2479 local f2=$DIR/$tdir/${tfile}_2
2480 local fid2=$(copy_file /etc/passwd $f2)
2482 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2483 wait_request_state $fid2 ARCHIVE SUCCEED
2485 trap cleanup_test_26c EXIT
2487 # set a long grace_delay vs short loop_period
2488 local orig_loop_period=$(get_hsm_param loop_period)
2489 local orig_grace_delay=$(get_hsm_param grace_delay)
2490 set_hsm_param loop_period 10
2491 set_hsm_param grace_delay 100
2493 set_hsm_param remove_archive_on_last_unlink 1
2495 multiop_bg_pause $f O_c || error "open $f failed"
2501 wait_request_state $fid2 REMOVE SUCCEED
2502 assert_request_count $fid REMOVE 0 \
2503 "Unexpected archived data remove request for $f"
2505 kill -USR1 $pid || error "multiop early exit"
2506 # should reach autotest timeout if multiop fails to trap
2507 # signal, close file, and exit ...
2510 set_hsm_param remove_archive_on_last_unlink 0
2512 wait_request_state $fid REMOVE SUCCEED
2516 run_test 26c "RAoLU effective when file closed"
2518 cleanup_test_26d() {
2520 set_hsm_param remove_archive_on_last_unlink 0
2521 set_hsm_param loop_period $orig_loop_period
2522 set_hsm_param grace_delay $orig_grace_delay
2528 # test needs a running copytool
2532 local f=$DIR/$tdir/$tfile
2533 local fid=$(copy_file /etc/motd $f 1)
2535 $LFS hsm_archive $f || error "could not archive file"
2536 wait_request_state $fid ARCHIVE SUCCEED
2538 trap cleanup_test_26d EXIT
2540 # set a long grace_delay vs short loop_period
2541 local orig_loop_period=$(get_hsm_param loop_period)
2542 local orig_grace_delay=$(get_hsm_param grace_delay)
2543 set_hsm_param loop_period 10
2544 set_hsm_param grace_delay 100
2546 set_hsm_param remove_archive_on_last_unlink 1
2548 multiop_bg_pause $f O_c || error "multiop failed"
2555 set_hsm_param remove_archive_on_last_unlink 0
2557 wait_request_state $fid REMOVE SUCCEED
2559 client_up || client_up || true
2561 kill -USR1 $MULTIPID
2562 wait $MULTIPID || error "multiop close failed"
2566 run_test 26d "RAoLU when Client eviction"
2569 # test needs a running copytool
2573 make_archive $tdir/$tfile
2574 local f=$DIR/$tdir/$tfile
2575 import_file $tdir/$tfile $f
2576 local fid=$(path2fid $f)
2580 [[ $? != 0 ]] || error "Remove of a released file should fail"
2584 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2587 # test needs a running copytool
2591 local f=$DIR/$tdir/$tfile
2593 fid=$(make_custom_file_for_progress $f 39 1000000)
2594 [ $? != 0 ] && skip "not enough free space" && return
2596 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2597 wait_request_state $fid ARCHIVE SUCCEED
2602 [[ $? != 0 ]] || error "Remove of a released file should fail"
2606 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2609 # test needs a running copytool
2613 local f=$DIR/$tdir/$tfile
2615 fid=$(make_custom_file_for_progress $f 39 1000000)
2616 [ $? != 0 ] && skip "not enough free space" && return
2618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2619 wait_request_state $fid ARCHIVE SUCCEED
2628 wait_request_state $fid REMOVE SUCCEED
2632 run_test 28 "Concurrent archive/file remove"
2635 # Tests --mntpath and --archive options
2638 copytool_setup $SINGLEAGT $MOUNT $archive_id
2640 # Bad archive number
2641 $LFS hsm_remove -m $MOUNT -a 33 0x857765760:0x8:0x2 2>&1 |
2642 grep "Invalid argument" ||
2643 error "unexpected hsm_remove failure (1)"
2645 # mntpath is present but file is given
2646 $LFS hsm_remove --mntpath $MOUNT --archive 30 /qwerty/uyt 2>&1 |
2647 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2648 error "unexpected hsm_remove failure (2)"
2652 run_test 29a "Tests --mntpath and --archive options"
2655 # test needs a running copytool
2659 local f=$DIR/$tdir/$tfile
2660 local fid=$(make_small $f)
2662 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2663 wait_request_state $fid ARCHIVE SUCCEED
2667 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2668 wait_request_state $fid REMOVE SUCCEED
2672 run_test 29b "Archive/delete/remove by FID from the archive."
2675 # test needs a running copytool
2679 local fid1=$(make_small $DIR/$tdir/$tfile-1)
2680 local fid2=$(make_small $DIR/$tdir/$tfile-2)
2681 local fid3=$(make_small $DIR/$tdir/$tfile-3)
2683 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2684 wait_request_state $fid1 ARCHIVE SUCCEED
2685 wait_request_state $fid2 ARCHIVE SUCCEED
2686 wait_request_state $fid3 ARCHIVE SUCCEED
2688 rm -f $DIR/$tdir/$tfile-[1-3]
2690 echo $fid1 > $DIR/$tdir/list
2691 echo $fid2 >> $DIR/$tdir/list
2692 echo $fid3 >> $DIR/$tdir/list
2694 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2695 --filelist $DIR/$tdir/list
2696 wait_request_state $fid1 REMOVE SUCCEED
2697 wait_request_state $fid2 REMOVE SUCCEED
2698 wait_request_state $fid3 REMOVE SUCCEED
2702 run_test 29c "Archive/delete/remove by FID, using a file list."
2705 # test needs more than one CT
2706 needclients 3 || return 0
2712 copytool_cleanup $(comma_list $(agts_nodes))
2714 # start all of the copytools
2715 for n in $(seq $AGTCOUNT); do
2716 copytool_setup agt$n $MOUNT2 $n
2719 trap "copytool_cleanup $(comma_list $(agts_nodes))" EXIT
2722 file=$DIR/$tdir/$tfile
2723 fid=$(make_small $file)
2725 $LFS hsm_archive $file
2726 wait_request_state $fid ARCHIVE SUCCEED
2727 check_hsm_flags $file "0x00000009"
2731 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2732 error "cannot hsm_remove '$fid'"
2734 # give time for CDT to handle remove request and create broadcasted
2737 # remove request has been broadcasted ?
2738 local cnt=$(get_request_count $fid REMOVE)
2739 # broadcasted requests + original
2740 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2741 error "remove not broadcasted to all CTs"
2743 # give time for CDT and CTs to handle broadcasted
2744 wait_for_loop_period
2746 # each agent serves one different archive_id, so broadcasted
2747 # hsm_remove request should only succeed once and fail at all others
2751 for n in $(seq $AGTCOUNT); do
2752 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2753 $HSM_PARAM.actions | awk \
2754 '/'$fid'.*action=REMOVE archive#='$n'/ \
2755 {print \\\$13}' | cut -f2 -d=")
2756 if [[ "$res" == "SUCCEED" ]]; then
2758 elif [[ "$res" == "FAILED" ]]; then
2763 [[ $scnt -ne 1 ]] &&
2764 error "one and only CT should have removed successfully"
2766 [[ $AGTCOUNT -ne $((scnt + fcnt)) ]] &&
2767 error "all but one CT should have failed to remove"
2770 copytool_cleanup $(comma_list $(agts_nodes))
2773 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2774 "request to be sent once for each registered archive_id"
2777 # restore at exec cannot work on agent node (because of Linux kernel
2778 # protection of executables)
2779 needclients 2 || return 0
2781 # test needs a running copytool
2785 copy2archive /bin/true $tdir/$tfile
2787 local f=$DIR/$tdir/true
2788 import_file $tdir/$tfile $f
2790 local fid=$(path2fid $f)
2792 # set no retry action mode
2798 # remove no try action mode
2802 [[ $st == 0 ]] || error "Failed to exec a released file"
2806 run_test 30a "Restore at exec (import case)"
2809 # restore at exec cannot work on agent node (because of Linux kernel
2810 # protection of executables)
2811 needclients 2 || return 0
2813 # test needs a running copytool
2817 local f=$DIR/$tdir/true
2818 local fid=$(copy_file /bin/true $f)
2820 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2821 wait_request_state $fid ARCHIVE SUCCEED
2824 # set no retry action mode
2830 # remove no try action mode
2834 [[ $st == 0 ]] || error "Failed to exec a released file"
2838 run_test 30b "Restore at exec (release case)"
2841 needclients 2 || return 0
2843 # test needs a running copytool
2847 local f=$DIR/$tdir/SLEEP
2848 local slp_sum1=$(md5sum /bin/sleep)
2849 local fid=$(copy_file /bin/sleep $f)
2851 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2852 wait_request_state $fid ARCHIVE SUCCEED
2854 check_hsm_flags $f "0x0000000d"
2855 # set no retry action mode
2857 do_node $CLIENT2 "$f 10" &
2861 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2863 [[ $? == 0 ]] || error "Execution failed during run"
2865 if [[ $? != 0 ]]; then
2866 local slp_sum2=$(md5sum /bin/sleep)
2867 # in case sleep file is modified during the test
2868 [[ $slp_sum1 == $slp_sum2 ]] &&
2869 error "Binary overwritten during exec"
2873 # remove no try action mode
2875 check_hsm_flags $f "0x00000009"
2879 run_test 30c "Update during exec of released file must fail"
2881 restore_and_check_size() {
2884 local s=$(stat -c "%s" $f)
2886 local st=$(get_hsm_flags $f)
2890 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2892 n=$(stat -c "%s" $f)
2893 # we echo in both cases to show stat is not hang
2894 if [[ $n != $s ]]; then
2895 echo "size seen is $n != $s"
2898 echo "size seen is right: $n == $s"
2902 st=$(get_hsm_flags $f)
2904 if [[ "$st" = "0x00000009" ]]; then
2907 echo " restore is too long"
2908 wait_request_state $fid RESTORE SUCCEED
2914 # test needs a running copytool
2919 make_archive $tdir/$tfile
2920 local f=$DIR/$tdir/$tfile
2921 import_file $tdir/$tfile $f
2922 local fid=$($LFS path2fid $f)
2923 HSM_ARCHIVE_PURGE=false copytool_setup
2925 restore_and_check_size $f $fid
2928 [[ $err -eq 0 ]] || error "File size changed during restore"
2932 run_test 31a "Import a large file and check size during restore"
2936 # test needs a running copytool
2941 local f=$DIR/$tdir/$tfile
2943 fid=$(make_custom_file_for_progress $f 39 1000000)
2944 [ $? != 0 ] && skip "not enough free space" && return
2946 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2947 wait_request_state $fid ARCHIVE SUCCEED
2950 restore_and_check_size $f $fid
2953 [[ $err -eq 0 ]] || error "File size changed during restore"
2957 run_test 31b "Restore a large unaligned file and check size during restore"
2960 # test needs a running copytool
2965 local f=$DIR/$tdir/$tfile
2967 fid=$(make_custom_file_for_progress $f 33 1048576)
2968 [ $? != 0 ] && skip "not enough free space" && return
2970 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2971 wait_request_state $fid ARCHIVE SUCCEED
2974 restore_and_check_size $f $fid
2977 [[ $err -eq 0 ]] || error "File size changed during restore"
2981 run_test 31c "Restore a large aligned file and check size during restore"
2984 # test needs a running copytool
2989 local f=$DIR/$tdir/$tfile
2991 fid=$(make_custom_file_for_progress $f 39 1000000)
2992 [ $? != 0 ] && skip "not enough free space" && return
2994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2995 wait_request_state $fid ARCHIVE SUCCEED
2998 # to be sure wait_all_done will not be mislead by previous tests
3001 wait_for_grace_delay
3002 # Also raise grace_delay significantly so the Canceled
3003 # Restore action will stay enough long avail.
3004 local old_grace=$(get_hsm_param grace_delay)
3005 set_hsm_param grace_delay 100
3007 md5sum $f >/dev/null &
3009 wait_request_state $fid RESTORE STARTED
3014 # Check restore trigger process was killed
3015 local killed=$(ps -o pid,comm hp $pid >/dev/null)
3019 # instead of waiting+checking both Restore and Cancel ops
3020 # sequentially, wait for both to be finished and then check
3022 wait_all_done 100 $fid
3023 local rstate=$(get_request_state $fid RESTORE)
3024 local cstate=$(get_request_state $fid CANCEL)
3026 # restore orig grace_delay.
3027 set_hsm_param grace_delay $old_grace
3029 if [[ "$rstate" == "CANCELED" ]] ; then
3030 [[ "$cstate" == "SUCCEED" ]] ||
3031 error "Restore state is CANCELED and Cancel state " \
3032 "is not SUCCEED but $cstate"
3033 echo "Restore state is CANCELED, Cancel state is SUCCEED"
3034 elif [[ "$rstate" == "SUCCEED" ]] ; then
3035 [[ "$cstate" == "FAILED" ]] ||
3036 error "Restore state is SUCCEED and Cancel state " \
3037 "is not FAILED but $cstate"
3038 echo "Restore state is SUCCEED, Cancel state is FAILED"
3040 error "Restore state is $rstate and Cancel state is $cstate"
3044 error "Cannot kill process waiting for restore ($killed)"
3048 run_test 33 "Kill a restore waiting process"
3051 # test needs a running copytool
3056 local f=$DIR/$tdir/$tfile
3058 fid=$(make_custom_file_for_progress $f 39 1000000)
3059 [ $? != 0 ] && skip "not enough free space" && return
3061 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3062 wait_request_state $fid ARCHIVE SUCCEED
3065 md5sum $f >/dev/null &
3067 wait_request_state $fid RESTORE STARTED
3069 rm $f || error "rm $f failed"
3070 # rm must not block during restore
3071 wait_request_state $fid RESTORE STARTED
3073 wait_request_state $fid RESTORE SUCCEED
3074 # check md5sum pgm finished
3075 local there=$(ps -o pid,comm hp $pid >/dev/null)
3076 [[ -z $there ]] || error "Restore initiator does not exit"
3078 local rc=$(wait $pid)
3079 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
3083 run_test 34 "Remove file during restore"
3086 # test needs a running copytool
3091 local f=$DIR/$tdir/$tfile
3092 local f1=$DIR/$tdir/$tfile-1
3094 fid=$(make_custom_file_for_progress $f 39 1000000)
3095 [ $? != 0 ] && skip "not enough free space" && return
3097 local fid1=$(copy_file /etc/passwd $f1)
3098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3099 wait_request_state $fid ARCHIVE SUCCEED
3102 md5sum $f >/dev/null &
3104 wait_request_state $fid RESTORE STARTED
3106 mv $f1 $f || error "mv $f1 $f failed"
3107 # mv must not block during restore
3108 wait_request_state $fid RESTORE STARTED
3110 wait_request_state $fid RESTORE SUCCEED
3111 # check md5sum pgm finished
3112 local there=$(ps -o pid,comm hp $pid >/dev/null)
3113 [[ -z $there ]] || error "Restore initiator does not exit"
3115 local rc=$(wait $pid)
3116 [[ $rc -eq 0 ]] || error "Restore initiator failed with $rc"
3119 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
3123 run_test 35 "Overwrite file during restore"
3126 # test needs a running copytool
3131 local f=$DIR/$tdir/$tfile
3133 fid=$(make_custom_file_for_progress $f 39 1000000)
3134 [ $? != 0 ] && skip "not enough free space" && return
3136 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3137 wait_request_state $fid ARCHIVE SUCCEED
3140 md5sum $f >/dev/null &
3142 wait_request_state $fid RESTORE STARTED
3145 # rm must not block during restore
3146 wait_request_state $fid RESTORE STARTED
3148 wait_request_state $fid RESTORE SUCCEED
3149 # check md5sum pgm finished
3150 local there=$(ps -o pid,comm hp $pid >/dev/null)
3152 error "Restore initiator does not exit"
3154 local rc=$(wait $pid)
3156 error "Restore initiator failed with $rc"
3160 run_test 36 "Move file during restore"
3163 # LU-5683: check that an archived dirty file can be rearchived.
3165 copytool_setup $SINGLEAGT $MOUNT2
3168 local f=$DIR/$tdir/$tfile
3171 fid=$(make_small $f) || error "cannot create small file"
3173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3174 wait_request_state $fid ARCHIVE SUCCEED
3175 $LFS hsm_release $f || error "cannot release $f"
3177 # Allow previous archive request to expire from the actions log.
3178 wait_for_grace_delay
3181 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3183 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3184 wait_request_state $fid ARCHIVE SUCCEED
3188 run_test 37 "re-archive a dirty file"
3195 for n in $(seq 1 $count); do
3196 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3198 echo "$count archive requests submitted"
3203 set_hsm_param max_requests $max_requests
3208 local stream_count=4
3209 local file_count=100
3211 local f=$DIR/$tdir/$tfile
3215 local max_requests=$(get_hsm_param max_requests)
3217 # Increase the number of HSM request that can be performed in
3218 # parallel. With the coordinator running once per second, this
3219 # also limits the number of requests per seconds that can be
3220 # performed, so we pick a decent number. But we also need to keep
3221 # that number low because the copytool has no rate limit and will
3222 # fail some requests if if gets too many at once.
3223 set_hsm_param max_requests 300
3225 trap cleanup_test_40 EXIT
3227 for i in $(seq 1 $file_count); do
3228 for p in $(seq 1 $stream_count); do
3229 fid=$(copy_file /etc/hosts $f.$p.$i)
3232 # force copytool to use a local/temp archive dir to ensure best
3233 # performance vs remote/NFS mounts used in auto-tests
3234 if do_facet $SINGLEAGT "df --local $HSM_ARCHIVE" >/dev/null 2>&1 ; then
3237 copytool_setup $SINGLEAGT $MOUNT $HSM_ARCHIVE_NUMBER $TMP/$tdir
3239 # to be sure wait_all_done will not be mislead by previous tests
3241 wait_for_grace_delay
3243 # start archive streams in background (archive files in parallel)
3244 for p in $(seq 1 $stream_count); do
3245 multi_archive $f.$p $file_count &
3248 echo -n "Wait for all requests being enqueued..."
3255 run_test 40 "Parallel archive requests"
3258 # test needs a running copytool
3262 local f=$DIR/$tdir/$tfile
3263 local fid=$(copy_file /etc/motd $f 1)
3265 $LFS hsm_archive $f || error "could not archive file"
3266 wait_request_state $fid ARCHIVE SUCCEED
3267 check_hsm_flags $f "0x00000009"
3269 multiop_bg_pause $f O_c || error "multiop failed"
3273 client_up || client_up || true
3275 kill -USR1 $MULTIPID
3276 wait $MULTIPID || error "multiop close failed"
3278 check_hsm_flags $f "0x0000000b"
3282 run_test 52 "Opened for write file on an evicted client should be set dirty"
3285 # test needs a running copytool
3289 local f=$DIR/$tdir/$tfile
3290 local fid=$(copy_file /etc/motd $f 1)
3292 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3293 error "could not archive file"
3294 wait_request_state $fid ARCHIVE SUCCEED
3295 check_hsm_flags $f "0x00000009"
3297 multiop_bg_pause $f o_c || error "multiop failed"
3301 client_up || client_up || true
3303 kill -USR1 $MULTIPID
3304 wait $MULTIPID || error "multiop close failed"
3306 check_hsm_flags $f "0x00000009"
3310 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3313 # test needs a running copytool
3317 local f=$DIR/$tdir/$tfile
3318 local fid=$(make_custom_file_for_progress $f 39 1000000)
3320 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3321 error "could not archive file"
3322 wait_request_state $fid ARCHIVE STARTED
3324 check_hsm_flags $f "0x00000001"
3326 # Avoid coordinator resending this request as soon it has failed.
3331 wait_request_state $fid ARCHIVE FAILED
3333 check_hsm_flags $f "0x00000003"
3338 run_test 54 "Write during an archive cancels it"
3341 # test needs a running copytool
3345 local f=$DIR/$tdir/$tfile
3346 local fid=$(make_custom_file_for_progress $f 39 1000000)
3348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3349 error "could not archive file"
3350 wait_request_state $fid ARCHIVE STARTED
3352 check_hsm_flags $f "0x00000001"
3354 # Avoid coordinator resending this request as soon it has failed.
3357 $TRUNCATE $f 1024 || error "truncate failed"
3359 wait_request_state $fid ARCHIVE FAILED
3361 check_hsm_flags $f "0x00000003"
3366 run_test 55 "Truncate during an archive cancels it"
3369 # test needs a running copytool
3373 local f=$DIR/$tdir/$tfile
3375 fid=$(make_custom_file_for_progress $f 39 1000000)
3376 [ $? != 0 ] && skip "not enough free space" && return
3378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3379 error "could not archive file"
3380 wait_request_state $fid ARCHIVE STARTED
3382 check_hsm_flags $f "0x00000001"
3384 # Change metadata and sync to be sure we are not changing only
3389 wait_request_state $fid ARCHIVE SUCCEED
3391 check_hsm_flags $f "0x00000009"
3395 run_test 56 "Setattr during an archive is ok"
3398 # Need one client for I/O, one for request
3399 needclients 2 || return 0
3401 # test needs a running copytool
3405 local f=$DIR/$tdir/test_archive_remote
3406 # Create a file on a remote node
3407 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3408 "count=2 conv=fsync"
3411 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3412 error "hsm_archive failed"
3413 local fid=$(path2fid $f)
3414 wait_request_state $fid ARCHIVE SUCCEED
3416 # Release and implicit restore it
3417 do_node $CLIENT2 "$LFS hsm_release $f" ||
3418 error "hsm_release failed"
3419 do_node $CLIENT2 "md5sum $f" ||
3420 error "hsm_restore failed"
3422 wait_request_state $fid RESTORE SUCCEED
3426 run_test 57 "Archive a file with dirty cache on another node"
3428 truncate_released_file() {
3432 local sz=$(stat -c %s $src_file)
3433 local f=$DIR/$tdir/$tfile
3434 local fid=$(copy_file $1 $f)
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3439 error "could not archive file"
3440 wait_request_state $fid ARCHIVE SUCCEED
3442 $LFS hsm_release $f || error "could not release file"
3444 $TRUNCATE $f $trunc_to || error "truncate failed"
3447 local sz1=$(stat -c %s $f)
3448 [[ $sz1 == $trunc_to ]] ||
3449 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3452 check_hsm_flags $f "0x0000000b"
3454 local state=$(get_request_state $fid RESTORE)
3455 [[ "$state" == "SUCCEED" ]] ||
3456 error "truncate $sz does not trig restore, state = $state"
3458 $TRUNCATE $ref $trunc_to
3459 cmp $ref $f || error "file data wrong after truncate"
3465 # test needs a running copytool
3470 local sz=$(stat -c %s /etc/passwd)
3472 echo "truncate up from $sz to $((sz*2))"
3473 truncate_released_file /etc/passwd $((sz*2))
3475 echo "truncate down from $sz to $((sz/2))"
3476 truncate_released_file /etc/passwd $((sz/2))
3478 echo "truncate to 0"
3479 truncate_released_file /etc/passwd 0
3483 run_test 58 "Truncate a released file will trigger restore"
3487 local server_version=$(lustre_version_code $SINGLEMDS)
3488 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3489 skip "Need MDS version at least 2.7.63" && return
3492 $MCREATE $DIR/$tfile || error "mcreate failed"
3493 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3494 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3495 fid=$(path2fid $DIR/$tfile)
3496 wait_request_state $fid ARCHIVE SUCCEED
3497 $LFS hsm_release $DIR/$tfile || error "release failed"
3500 run_test 59 "Release stripeless file with non-zero size"
3503 # This test validates the fix for LU-4512. Ensure that the -u
3504 # option changes the progress reporting interval from the
3505 # default (30 seconds) to the user-specified interval.