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" ")
116 # The test only support up to 10 MDTs
117 MDT_PREFIX="mdt.$FSNAME-MDT000"
118 HSM_PARAM="${MDT_PREFIX}0.hsm"
120 # archive is purged at copytool setup
121 HSM_ARCHIVE_PURGE=true
123 # Don't allow copytool error upon start/setup
124 HSMTOOL_NOERROR=false
127 # Get the backend root path for the given agent facet.
130 local dev=AGTDEV$(facet_number $facet)
137 # get MDT device for each mdc
138 for mdtno in $(seq 1 $MDSCOUNT); do
139 local idx=$(($mdtno - 1))
140 MDT[$idx]=$($LCTL get_param -n \
141 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
142 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
147 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
148 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
152 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
154 echo "Killing existing copytools on $hosts"
155 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
156 copytool_continue "$hosts"
160 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
161 local wait_timeout=200
162 local wait_start=$SECONDS
163 local wait_end=$((wait_start + wait_timeout))
164 local sleep_time=100000 # 0.1 second
166 while ((SECONDS < wait_end)); do
167 if ! search_copytools $hosts; then
168 echo "copytools stopped in $((SECONDS - wait_start))s"
172 echo "copytools still running on $hosts"
174 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
175 sleep_time=$(bc <<< "$sleep_time * 2")
178 # try to dump Copytool's stack
179 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
180 "echo t >/proc/sysrq-trigger"
182 echo "copytools failed to stop in ${wait_timeout}s"
187 copytool_monitor_setup() {
188 local facet=${1:-$SINGLEAGT}
189 local agent=$(facet_active_host $facet)
191 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
192 local test_dir=$(do_node $agent "$cmd") ||
193 error "Failed to create tempdir on $agent"
194 export HSMTOOL_MONITOR_DIR=$test_dir
196 # Create the fifo and a monitor (cat dies when copytool dies)
197 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
198 error "failed to create copytool fifo on $agent"
199 cmd="cat $test_dir/fifo > $test_dir/events &"
200 cmd+=" echo \\\$! > $test_dir/monitor_pid"
202 if [[ $PDSH == *Rmrsh* ]]; then
203 # This is required for pdsh -Rmrsh and its handling of remote
205 # Regular ssh and pdsh -Rssh work fine without this
206 # backgrounded subshell nonsense.
207 (do_node $agent "$cmd") &
208 export HSMTOOL_MONITOR_PDSH=$!
210 # Slightly racy, but just making a best-effort to catch obvious
213 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
214 error "Failed to start copytool monitor on $agent"
216 do_node $agent "$cmd"
218 error "Failed to start copytool monitor on $agent"
223 copytool_monitor_cleanup() {
224 local facet=${1:-$SINGLEAGT}
225 local agent=$(facet_active_host $facet)
227 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
228 # Should die when the copytool dies, but just in case.
229 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
230 cmd+=" 2>/dev/null || true"
231 do_node $agent "$cmd"
232 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
233 export HSMTOOL_MONITOR_DIR=
236 # The pdsh should die on its own when the monitor dies. Just
237 # in case, though, try to clean up to avoid any cruft.
238 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
239 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
240 export HSMTOOL_MONITOR_PDSH=
250 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
257 local host="$(facet_host "$1")"
258 local prefix=$TESTLOG_PREFIX
259 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
261 printf "${prefix}.copytool${archive_id}_log.${host}.log"
266 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
271 mkdir -p "$(dirname "$2")" ||
272 error "cannot create directory '$(dirname "$2")'"
273 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
278 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
279 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
280 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
281 [ ${#misc_options[@]} -gt 0 ] &&
282 cmd+=" $(IFS=" " echo "$@")"
283 cmd+=" \"$mountpoint\""
285 echo "Starting copytool $facet on $(facet_host $facet)"
286 stack_trap "do_facet $facet pkill -x '$HSMTOOL_BASE' || true" EXIT
287 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
291 local facet="${1:-$SINGLEAGT}"
293 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
296 # Main entry point to perform copytool related operations
300 # setup setup a copytool to run in the background, that copytool will be
302 # import import a file from an HSM backend
303 # rebind rebind an archived file to a new fid
305 # Although the semantics might suggest otherwise, one does not need to 'setup'
306 # a copytool before a call to 'copytool import' or 'copytool rebind'.
314 local fail_on_error=true
315 local -a misc_options
316 while [ $# -gt 0 ]; do
324 local mountpoint="$1"
328 local archive_id="$1"
332 local bandwidth="$1" # in MB/s
335 local fail_on_error=false
338 # Uncommon(/copytool dependent) option
345 # Use default values if needed
346 local facet=${facet:-$SINGLEAGT}
347 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
348 local hsm_root="$(hsm_root "$facet")"
350 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
351 do_facet $facet mkdir -p "$hsm_root" ||
352 error "mkdir '$hsm_root' failed"
356 local copytool=lhsmtool
360 __${copytool}_${action} "${misc_options[@]}"
361 if [ $? -ne 0 ]; then
366 local host="$(facet_host $facet)"
367 error_msg="Failed to start copytool $facet on '$host'"
370 local src="${misc_options[0]}"
371 local dest="${misc_options[1]}"
372 error_msg="Failed to import '$src' to '$dest'"
375 error_msg="could not rebind file"
379 $fail_on_error && error "$error_msg" || echo "$error_msg"
383 get_copytool_event_log() {
384 local facet=${1:-$SINGLEAGT}
385 local agent=$(facet_active_host $facet)
387 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
388 error "Can't get event log: No monitor directory!"
390 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
391 error "Could not collect event log from $agent"
395 local agents=${1:-$(facet_active_host $SINGLEAGT)}
398 "do_nodesv $agents pkill -CONT -x '$HSMTOOL_BASE' || true" EXIT
399 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
400 echo "Copytool is suspended on $agents"
403 copytool_continue() {
404 local agents=${1:-$(facet_active_host $SINGLEAGT)}
406 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
407 echo "Copytool is continued on $agents"
410 copytool_remove_backend() {
412 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
413 echo "Remove from backend: $fid = $be"
414 do_facet $SINGLEAGT rm -f $be
417 file_creation_failure() {
424 df $MOUNT $MOUNT2 >&2
425 error "Not enough space to create $file with $cmd"
428 error "cannot create $file with $cmd, status=$err"
433 # Creates a file using dd
439 local source=${5:-/dev/zero}
443 if [ -n "$conv" ]; then
447 # Create the directory in case it does not exist
448 mkdir -p "$(dirname "$file")"
449 # Delete the file in case it already exist
452 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
453 path2fid "$file" || error "cannot get FID of '$file'"
456 echo "cannot create file '$file'" >&2;
457 # Let the caller decide what to do on error
462 create_empty_file() {
463 create_file "${1/$DIR/$DIR2}" 1M 0 ||
464 file_creation_failure dd "${1/$DIR/$DIR2}" $?
467 create_small_file() {
468 local source_file=/dev/urandom
471 local conv=${2:-fsync}
473 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
474 file_creation_failure dd "${1/$DIR/$DIR2}" $?
477 create_small_sync_file() {
478 create_small_file "$1" sync
481 create_archive_file() {
482 local file="$(hsm_root)/$1"
484 local source=/dev/urandom
486 # Create the counterpart directory of the archive
487 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
488 error "cannot create archive directory '$(dirname "$file")'"
490 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
491 error "cannot create archive file '$file'"
495 local hsm_root="$(hsm_root)"
496 local file="$hsm_root/$2"
498 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
499 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
500 error "mkdir '$(dirname "$file")' failed"
501 do_facet $SINGLEAGT cp -p "$1" "$file" ||
502 error "cannot copy '$1' to '$file'"
511 if [[ "$value" != "" ]]; then
514 for mdtno in $(seq 1 $MDSCOUNT); do
515 local idx=$(($mdtno - 1))
516 local facet=mds${mdtno}
517 # if $arg include -P option, run 1 set_param per MDT on the MGS
518 # else, run set_param on each MDT
519 [[ $arg = *"-P"* ]] && facet=mgs
520 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
521 [[ $? != 0 ]] && rc=1
531 for mdtno in $(seq 1 $MDSCOUNT); do
532 local idx=$(($mdtno - 1))
533 wait_result mds${mdtno} \
534 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
536 error "$key state is not '$target' on mds${mdtno}"
542 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
550 mdts_set_param "$opt -n" "hsm.$param" "$value"
557 mdts_set_param "" hsm_control "$cmd"
558 mdts_check_param hsm_control "$target" 10
561 cdt_set_sanity_policy() {
562 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
565 mdts_set_param "" hsm.policy "+NRA"
566 mdts_set_param "" hsm.policy "-NBR"
567 CDT_POLICY_HAD_CHANGED=
572 mdts_set_param "" hsm.policy "+NRA"
573 CDT_POLICY_HAD_CHANGED=true
576 cdt_clear_no_retry() {
577 mdts_set_param "" hsm.policy "-NRA"
578 CDT_POLICY_HAD_CHANGED=true
581 cdt_set_non_blocking_restore() {
582 mdts_set_param "" hsm.policy "+NBR"
583 CDT_POLICY_HAD_CHANGED=true
586 cdt_clear_non_blocking_restore() {
587 mdts_set_param "" hsm.policy "-NBR"
588 CDT_POLICY_HAD_CHANGED=true
591 cdt_clear_mount_state() {
592 mdts_set_param "-P -d" hsm_control ""
595 cdt_set_mount_state() {
596 mdts_set_param "-P" hsm_control "$1"
597 # set_param -P is asynchronous operation and could race with set_param.
598 # In such case configs could be retrieved and applied at mgc after
599 # set_param -P completion. Sleep here to avoid race with set_param.
600 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
601 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
602 # and 10 seconds to retrieve config from server.
607 mdts_check_param hsm_control "$1" 20
611 set_test_state disabled disabled
615 set_test_state enabled enabled
619 set_test_state shutdown stopped
623 set_test_state purge enabled
629 cdt_set_sanity_policy
633 local client_count=$1
634 if [[ $CLIENTCOUNT -lt $client_count ]]; then
635 skip "Need $client_count or more clients, have $CLIENTCOUNT"
642 $LFS path2fid $1 | tr -d '[]'
643 return ${PIPESTATUS[0]}
651 if [[ $u == "user" ]]; then
652 st=$($RUNAS $LFS hsm_state $f)
655 st=$($LFS hsm_state $f)
658 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
660 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
664 get_hsm_archive_id() {
667 st=$($LFS hsm_state $f)
668 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
670 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
678 local st=$(get_hsm_flags $f)
679 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
682 check_hsm_flags_user() {
686 local st=$(get_hsm_flags $f user)
687 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
699 if [[ "$3" != 1 ]]; then
703 cp $1 $f || file_creation_failure cp $f $?
705 path2fid $f || error "cannot get fid on $f"
708 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
710 # Note that this might lead to surprising behaviours such as deleting an
711 # important file for the currently running test
712 delete_large_files() {
713 printf "Deleting large files...\n" >&2
714 find $MOUNT -size +10M -delete
715 wait_delete_completed
721 wait_update --verbose $(facet_active_host $facet) "$@"
724 wait_request_state() {
728 # 4th arg (mdt index) is optional
730 local mds=mds$(($mdtidx + 1))
732 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
733 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
735 wait_result $mds "$cmd" $state 200 ||
736 error "request on $fid is not $state on $mds"
739 get_request_state() {
743 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
744 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
747 get_request_count() {
751 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
752 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
755 # Ensure the number of HSM request for a given FID is correct
756 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
757 assert_request_count() {
758 local request_count=$(get_request_count $1 $2)
759 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
761 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
768 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
769 [[ -n $fid ]] && cmd+=" | grep '$fid'"
770 cmd+=" | egrep 'WAITING|STARTED'"
772 wait_result $SINGLEMDS "$cmd" "" $timeout ||
773 error "requests did not complete"
776 wait_for_grace_delay() {
777 local val=$(get_hsm_param grace_delay)
781 wait_for_loop_period() {
782 local val=$(get_hsm_param loop_period)
789 # python2.6 in EL6 includes an internal json module
790 local json_parser='import json; import fileinput;'
791 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
792 json_parser+='json.loads([line for line in '
793 json_parser+='fileinput.input()][0]).items()])'
795 echo $raw_event | python -c "$json_parser"
798 get_agent_by_uuid_mdt() {
801 local mds=mds$(($mdtidx + 1))
802 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
806 check_agent_registered_by_mdt() {
809 local mds=mds$(($mdtidx + 1))
810 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
811 if [[ ! -z "$agent" ]]; then
812 echo "found agent $agent on $mds"
814 error "uuid $uuid not found in agent list on $mds"
818 check_agent_unregistered_by_mdt() {
821 local mds=mds$(($mdtidx + 1))
822 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
823 if [[ -z "$agent" ]]; then
824 echo "uuid not found in agent list on $mds"
826 error "uuid found in agent list on $mds: $agent"
830 check_agent_registered() {
833 for mdsno in $(seq 1 $MDSCOUNT); do
834 check_agent_registered_by_mdt $uuid $((mdsno - 1))
838 check_agent_unregistered() {
841 for mdsno in $(seq 1 $MDSCOUNT); do
842 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
847 local agent=${1:-$(facet_active_host $SINGLEAGT)}
849 # Lustre mount-point is mandatory and last parameter on
851 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
853 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
855 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
861 # populate MDT device array
864 # cleanup from previous bad setup
867 # for recovery tests, coordinator needs to be started at mount
869 # the lustre conf must be without hsm on (like for sanity.sh)
870 echo "Set HSM on and start"
871 cdt_set_mount_state enabled
872 cdt_check_state enabled
874 echo "Set sanity-hsm HSM policy"
875 cdt_set_sanity_policy
877 # finished requests are quickly removed from list
878 set_hsm_param grace_delay 10
880 CLIENT_NIDS=( $($LCTL list_nids all) )
882 test_1A() { # was test_1
886 local f=$DIR/$tdir/$tfile
890 check_hsm_flags_user $f "0x00000000"
892 $RUNAS $LFS hsm_set --norelease $f ||
893 error "user could not change hsm flags"
894 check_hsm_flags_user $f "0x00000010"
896 $RUNAS $LFS hsm_clear --norelease $f ||
897 error "user could not clear hsm flags"
898 check_hsm_flags_user $f "0x00000000"
900 # User could not change those flags...
901 $RUNAS $LFS hsm_set --exists $f &&
902 error "user should not set this flag"
903 check_hsm_flags_user $f "0x00000000"
906 $LFS hsm_set --exists $f ||
907 error "root could not change hsm flags"
908 check_hsm_flags_user $f "0x00000001"
910 $LFS hsm_clear --exists $f ||
911 error "root could not clear hsm state"
912 check_hsm_flags_user $f "0x00000000"
915 run_test 1A "lfs hsm flags root/non-root access"
918 local f=$DIR/$tdir/$tfile
919 local fid=$(create_small_file $f)
923 $LFS hsm_archive $f || error "could not archive file"
924 wait_request_state $fid ARCHIVE SUCCEED
926 # Release and check states
927 $LFS hsm_release $f || error "could not release file"
928 echo -n "Verifying released state: "
929 check_hsm_flags $f "0x0000000d"
931 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
933 run_test 1a "mmap & cat a HSM released file"
937 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
938 error "failed to set default stripe"
939 local f=$DIR/$tdir/$tfile
942 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
943 error "failed to create file"
944 local fid=$(path2fid $f)
949 $LFS hsm_archive $f || error "could not archive file"
950 wait_request_state $fid ARCHIVE SUCCEED
953 $LFS hsm_release $f || error "could not release file"
954 echo "verify released state: "
955 check_hsm_flags $f "0x0000000d" && echo "pass"
958 $LFS hsm_restore $f || error "could not restore file"
959 wait_request_state $fid RESTORE SUCCEED
960 echo "verify restored state: "
961 check_hsm_flags $f "0x00000009" && echo "pass"
963 run_test 1b "Archive, Release and Restore composite file"
969 local f=$DIR/$tdir/$tfile
972 # Test whether we can set the maximum archive number.
973 local LOCAL_HSM_ARCHIVE_NUMBER=32
974 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
975 error "root could not change hsm flags"
976 check_hsm_flags_user $f "0x00000001"
977 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
978 local st=$(get_hsm_archive_id $f)
979 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
980 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
982 # Test whether setting archive number 0 results in no change.
983 $LFS hsm_set --exists --archive-id 0 $f ||
984 error "root could not change hsm flags"
985 check_hsm_flags_user $f "0x00000001"
986 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
987 st=$(get_hsm_archive_id $f)
988 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
989 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
991 # Test whether setting archive number > 32 results in error.
992 $LFS hsm_set --exists --archive-id 33 $f &&
993 error "archive number is larger than 32"
994 check_hsm_flags_user $f "0x00000001"
996 # Test whether setting archive number 16 and archived flag.
997 LOCAL_HSM_ARCHIVE_NUMBER=16
998 $LFS hsm_set --exists --archived \
999 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1000 error "root could not change hsm flags"
1001 check_hsm_flags_user $f "0x00000009"
1002 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1003 st=$(get_hsm_archive_id $f)
1004 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1005 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1007 run_test 1c "Check setting archive-id in lfs hsm_set"
1011 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1012 error "failed to set default stripe"
1013 local f=$DIR/$tdir/$tfile
1016 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1017 error "failed to create file"
1018 local fid=$(path2fid $f)
1023 $LFS hsm_archive $f || error "could not archive file"
1024 wait_request_state $fid ARCHIVE SUCCEED
1027 $LFS hsm_release $f || error "could not release file"
1028 echo "verify released state: "
1029 check_hsm_flags $f "0x0000000d" && echo "pass"
1032 $LFS hsm_restore $f || error "could not restore file"
1033 wait_request_state $fid RESTORE SUCCEED
1034 echo "verify restored state: "
1035 check_hsm_flags $f "0x00000009" && echo "pass"
1037 run_test 1d "Archive, Release and Restore DoM file"
1040 local f=$DIR/$tdir/$tfile
1042 create_empty_file "$f"
1043 # New files are not dirty
1044 check_hsm_flags $f "0x00000000"
1046 # For test, we simulate an archived file.
1047 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1048 check_hsm_flags $f "0x00000001"
1050 # chmod do not put the file dirty
1051 chmod 600 $f || error "could not chmod test file"
1052 check_hsm_flags $f "0x00000001"
1054 # chown do not put the file dirty
1055 chown $RUNAS_ID $f || error "could not chown test file"
1056 check_hsm_flags $f "0x00000001"
1058 # truncate put the file dirty
1059 $TRUNCATE $f 1 || error "could not truncate test file"
1060 check_hsm_flags $f "0x00000003"
1062 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1063 check_hsm_flags $f "0x00000001"
1065 run_test 2 "Check file dirtyness when doing setattr"
1071 # New files are not dirty
1072 cp -p /etc/passwd $f
1073 check_hsm_flags $f "0x00000000"
1075 # For test, we simulate an archived file.
1076 $LFS hsm_set --exists $f ||
1077 error "user could not change hsm flags"
1078 check_hsm_flags $f "0x00000001"
1080 # Reading a file, does not set dirty
1081 cat $f > /dev/null || error "could not read file"
1082 check_hsm_flags $f "0x00000001"
1084 # Open for write without modifying data, does not set dirty
1085 openfile -f O_WRONLY $f || error "could not open test file"
1086 check_hsm_flags $f "0x00000001"
1088 # Append to a file sets it dirty
1089 cp -p /etc/passwd $f.append || error "could not create file"
1090 $LFS hsm_set --exists $f.append ||
1091 error "user could not change hsm flags"
1092 dd if=/etc/passwd of=$f.append bs=1 count=3\
1093 conv=notrunc oflag=append status=noxfer ||
1094 file_creation_failure dd $f.append $?
1095 check_hsm_flags $f.append "0x00000003"
1097 # Modify a file sets it dirty
1098 cp -p /etc/passwd $f.modify || error "could not create file"
1099 $LFS hsm_set --exists $f.modify ||
1100 error "user could not change hsm flags"
1101 dd if=/dev/zero of=$f.modify bs=1 count=3\
1102 conv=notrunc status=noxfer ||
1103 file_creation_failure dd $f.modify $?
1104 check_hsm_flags $f.modify "0x00000003"
1106 # Open O_TRUNC sets dirty
1107 cp -p /etc/passwd $f.trunc || error "could not create file"
1108 $LFS hsm_set --exists $f.trunc ||
1109 error "user could not change hsm flags"
1110 cp /etc/group $f.trunc || error "could not override a file"
1111 check_hsm_flags $f.trunc "0x00000003"
1113 # Mmapped a file sets dirty
1114 cp -p /etc/passwd $f.mmap || error "could not create file"
1115 $LFS hsm_set --exists $f.mmap ||
1116 error "user could not change hsm flags"
1117 multiop $f.mmap OSMWUc || error "could not mmap a file"
1118 check_hsm_flags $f.mmap "0x00000003"
1120 run_test 3 "Check file dirtyness when opening for write"
1123 local f=$DIR/$tdir/$tfile
1124 local fid=$(create_small_file $f)
1127 local st=$(get_request_state $fid CANCEL)
1128 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1130 run_test 4 "Useless cancel must not be registered"
1133 # test needs a running copytool
1137 local f=$DIR/$tdir/$tfile
1138 local fid=$(copy_file /etc/passwd $f)
1140 wait_request_state $fid ARCHIVE SUCCEED
1142 check_hsm_flags $f "0x00000009"
1144 run_test 8 "Test default archive number"
1146 test_9A() { # was test_9
1147 # we do not use the default one to be sure
1148 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1149 copytool setup --archive-id $archive_id
1151 # give time for CT to register with MDTs
1152 sleep $(($MDSCOUNT*2))
1153 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1154 check_agent_registered $uuid
1157 local f=$DIR/$tdir/$tfile
1158 local fid=$(copy_file /etc/passwd $f)
1159 $LFS hsm_archive --archive $archive_id $f
1160 wait_request_state $fid ARCHIVE SUCCEED
1162 check_hsm_flags $f "0x00000009"
1164 run_test 9A "Use of explicit archive number, with dedicated copytool"
1167 needclients 3 || return 0
1173 # start all of the copytools
1174 for n in $(seq $AGTCOUNT); do
1175 copytool setup --facet agt$n
1179 for n in $(seq $AGTCOUNT); do
1180 file=$DIR/$tdir/$tfile.$n
1181 fid=$(create_small_file $file)
1183 $LFS hsm_archive $file || error "could not archive file $file"
1184 wait_request_state $fid ARCHIVE SUCCEED
1185 check_hsm_flags $file "0x00000009"
1188 run_test 9a "Multiple remote agents"
1191 # test needs a running copytool
1194 mkdir -p $DIR/$tdir/d1
1195 local f=$DIR/$tdir/$tfile
1196 local fid=$(copy_file /etc/hosts $f)
1197 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1198 error "hsm_archive failed"
1199 wait_request_state $fid ARCHIVE SUCCEED
1201 local hsm_root="$(copytool_device $SINGLEAGT)"
1202 local archive="$(do_facet $SINGLEAGT \
1203 find "$hsm_root" -name "$fid" -print0)"
1204 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1206 echo "Verifying content"
1207 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1208 echo "Verifying hsm state "
1209 check_hsm_flags $f "0x00000009"
1211 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1212 local st=$(get_hsm_archive_id $f)
1213 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1214 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1216 run_test 10a "Archive a file"
1219 # test needs a running copytool
1223 local f=$DIR/$tdir/$tfile
1224 local fid=$(copy_file /etc/hosts $f)
1225 $LFS hsm_archive $f || error "archive request failed"
1226 wait_request_state $fid ARCHIVE SUCCEED
1228 $LFS hsm_archive $f || error "archive of non dirty file failed"
1229 local cnt=$(get_request_count $fid ARCHIVE)
1230 [[ "$cnt" == "1" ]] ||
1231 error "archive of non dirty file must not make a request"
1233 run_test 10b "Archive of non dirty file must work without doing request"
1236 # test needs a running copytool
1240 local f=$DIR/$tdir/$tfile
1241 local fid=$(copy_file /etc/hosts $f)
1242 $LFS hsm_set --noarchive $f
1243 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1246 run_test 10c "Check forbidden archive"
1249 # test needs a running copytool
1253 local f=$DIR/$tdir/$tfile
1254 local fid=$(copy_file /etc/hosts $f)
1255 $LFS hsm_archive $f || error "cannot archive $f"
1256 wait_request_state $fid ARCHIVE SUCCEED
1258 local ar=$(get_hsm_archive_id $f)
1259 local dflt=$(get_hsm_param default_archive_id)
1260 [[ $ar == $dflt ]] ||
1261 error "archived file is not on default archive: $ar != $dflt"
1263 run_test 10d "Archive a file on the default archive id"
1267 copy2archive /etc/hosts $tdir/$tfile
1268 local f=$DIR/$tdir/$tfile
1270 copytool import $tdir/$tfile $f
1271 echo -n "Verifying released state: "
1272 check_hsm_flags $f "0x0000000d"
1274 local LSZ=$(stat -c "%s" $f)
1275 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1277 echo "Verifying imported size $LSZ=$ASZ"
1278 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1279 echo -n "Verifying released pattern: "
1280 local PTRN=$($GETSTRIPE -L $f)
1282 [[ $PTRN == released ]] || error "Is not released"
1283 local fid=$(path2fid $f)
1284 echo "Verifying new fid $fid in archive"
1286 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1287 error "No archive for fid $fid"
1289 run_test 11a "Import a file"
1292 # test needs a running copytool
1296 local f=$DIR/$tdir/$tfile
1297 local fid=$(copy_file /etc/hosts $f)
1298 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1299 error "hsm_archive failed"
1300 wait_request_state $fid ARCHIVE SUCCEED
1302 local FILE_HASH=$(md5sum $f)
1305 copytool import $fid $f
1307 echo "$FILE_HASH" | md5sum -c
1309 [[ $? -eq 0 ]] || error "Restored file differs"
1311 run_test 11b "Import a deleted file using its FID"
1314 # test needs a running copytool
1318 copy2archive /etc/hosts $tdir/$tfile
1320 local f=$DIR/$tdir/$tfile
1321 copytool import $tdir/$tfile $f
1322 local f2=$DIR2/$tdir/$tfile
1323 echo "Verifying released state: "
1324 check_hsm_flags $f2 "0x0000000d"
1326 local fid=$(path2fid $f2)
1327 $LFS hsm_restore $f2
1328 wait_request_state $fid RESTORE SUCCEED
1330 echo "Verifying file state: "
1331 check_hsm_flags $f2 "0x00000009"
1333 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1335 [[ $? -eq 0 ]] || error "Restored file differs"
1337 run_test 12a "Restore an imported file explicitly"
1340 # test needs a running copytool
1344 copy2archive /etc/hosts $tdir/$tfile
1346 local f=$DIR/$tdir/$tfile
1347 copytool import $tdir/$tfile $f
1348 echo "Verifying released state: "
1349 check_hsm_flags $f "0x0000000d"
1351 cat $f > /dev/null || error "File read failed"
1353 echo "Verifying file state after restore: "
1354 check_hsm_flags $f "0x00000009"
1356 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1358 [[ $? -eq 0 ]] || error "Restored file differs"
1360 run_test 12b "Restore an imported file implicitly"
1363 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1365 # test needs a running copytool
1368 local f=$DIR/$tdir/$tfile
1370 $LFS setstripe -c 2 "$f"
1371 local fid=$(create_file "$f" 1M 5)
1373 local FILE_CRC=$(md5sum $f)
1375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1376 wait_request_state $fid ARCHIVE SUCCEED
1377 $LFS hsm_release $f || error "release $f failed"
1379 echo "$FILE_CRC" | md5sum -c
1381 [[ $? -eq 0 ]] || error "Restored file differs"
1383 run_test 12c "Restore a file with stripe of 2"
1386 # test needs a running copytool
1391 local f=$DIR/$tdir/$tfile
1392 local fid=$(copy_file /etc/hosts $f)
1393 $LFS hsm_restore $f || error "restore of non archived file failed"
1394 local cnt=$(get_request_count $fid RESTORE)
1395 [[ "$cnt" == "0" ]] ||
1396 error "restore non archived must not make a request"
1397 $LFS hsm_archive $f ||
1398 error "archive request failed"
1399 wait_request_state $fid ARCHIVE SUCCEED
1400 $LFS hsm_restore $f ||
1401 error "restore of non released file failed"
1402 local cnt=$(get_request_count $fid RESTORE)
1403 [[ "$cnt" == "0" ]] ||
1404 error "restore a non dirty file must not make a request"
1406 run_test 12d "Restore of a non archived, non released file must work"\
1407 " without doing request"
1410 # test needs a running copytool
1414 local f=$DIR/$tdir/$tfile
1415 local fid=$(copy_file /etc/hosts $f)
1416 $LFS hsm_archive $f || error "archive request failed"
1417 wait_request_state $fid ARCHIVE SUCCEED
1420 cat /etc/hosts >> $f
1424 $LFS hsm_restore $f && error "restore a dirty file must fail"
1427 run_test 12e "Check forbidden restore"
1430 # test needs a running copytool
1434 local f=$DIR/$tdir/$tfile
1435 local fid=$(copy_file /etc/hosts $f)
1437 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1438 wait_request_state $fid ARCHIVE SUCCEED
1439 $LFS hsm_release $f || error "release of $f failed"
1441 wait_request_state $fid RESTORE SUCCEED
1443 echo -n "Verifying file state: "
1444 check_hsm_flags $f "0x00000009"
1446 diff -q /etc/hosts $f
1448 [[ $? -eq 0 ]] || error "Restored file differs"
1450 run_test 12f "Restore a released file explicitly"
1453 # test needs a running copytool
1457 local f=$DIR/$tdir/$tfile
1458 local fid=$(copy_file /etc/hosts $f)
1460 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1461 wait_request_state $fid ARCHIVE SUCCEED
1462 $LFS hsm_release $f || error "release of $f failed"
1464 diff -q /etc/hosts $f
1467 # we check we had a restore done
1468 wait_request_state $fid RESTORE SUCCEED
1470 [[ $st -eq 0 ]] || error "Restored file differs"
1472 run_test 12g "Restore a released file implicitly"
1475 needclients 2 || return 0
1477 # test needs a running copytool
1481 local f=$DIR/$tdir/$tfile
1482 local fid=$(copy_file /etc/hosts $f)
1484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1485 wait_request_state $fid ARCHIVE SUCCEED
1486 $LFS hsm_release $f || error "release of $f failed"
1488 do_node $CLIENT2 diff -q /etc/hosts $f
1491 # we check we had a restore done
1492 wait_request_state $fid RESTORE SUCCEED
1494 [[ $st -eq 0 ]] || error "Restored file differs"
1496 run_test 12h "Restore a released file implicitly from a second node"
1499 # test needs a running copytool
1503 local f=$DIR/$tdir/$tfile
1504 local fid=$(copy_file /etc/passwd $f)
1505 $LFS hsm_archive $f || error "archive of $f failed"
1506 wait_request_state $fid ARCHIVE SUCCEED
1508 $LFS hsm_release $f || error "release of $f failed"
1512 [[ $? -eq 0 ]] || error "Restored file differs"
1514 run_test 12m "Archive/release/implicit restore"
1517 # test needs a running copytool
1521 copy2archive /etc/hosts $tdir/$tfile
1523 local f=$DIR/$tdir/$tfile
1524 copytool import $tdir/$tfile $f
1526 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1527 error "Restored file differs"
1529 $LFS hsm_release $f || error "release of $f failed"
1531 run_test 12n "Import/implicit restore/release"
1534 # test needs a running copytool
1538 local f=$DIR/$tdir/$tfile
1539 local fid=$(copy_file /etc/hosts $f)
1541 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1542 wait_request_state $fid ARCHIVE SUCCEED
1543 $LFS hsm_release $f || error "release of $f failed"
1545 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1546 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1548 # set no retry action mode
1551 diff -q /etc/hosts $f
1554 # we check we had a restore failure
1555 wait_request_state $fid RESTORE FAILED
1557 [[ $st -eq 0 ]] && error "Restore must fail"
1559 # remove no retry action mode
1562 # check file is still released
1563 check_hsm_flags $f "0x0000000d"
1565 # retry w/o failure injection
1566 do_facet $SINGLEMDS lctl set_param fail_loc=0
1568 # to be sure previous RESTORE result is gone
1570 wait_for_grace_delay
1572 diff -q /etc/hosts $f
1575 # we check we had a restore done
1576 wait_request_state $fid RESTORE SUCCEED
1578 [[ $st -eq 0 ]] || error "Restored file differs"
1580 run_test 12o "Layout-swap failure during Restore leaves file released"
1583 # test needs a running copytool
1587 local f=$DIR/$tdir/$tfile
1588 local fid=$(copy_file /etc/hosts $f)
1590 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1591 wait_request_state $fid ARCHIVE SUCCEED
1592 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1593 $LFS hsm_release $f || error "cannot release $f"
1594 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1595 $LFS hsm_release $f || error "cannot release $f"
1596 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1598 run_test 12p "implicit restore of a file on copytool mount point"
1601 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1602 skip "need MDS version at least 2.7.58" && return 0
1604 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1605 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1606 error "cannot mount $MOUNT3 on $SINGLEAGT"
1608 # test needs a running copytool
1609 copytool setup -m "$MOUNT3"
1611 local f=$DIR/$tdir/$tfile
1612 local f2=$DIR2/$tdir/$tfile
1613 local fid=$(create_small_file $f)
1614 local orig_size=$(stat -c "%s" $f)
1616 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1617 wait_request_state $fid ARCHIVE SUCCEED
1619 $LFS hsm_release $f || error "could not release file"
1620 check_hsm_flags $f "0x0000000d"
1623 wait_copytools || error "copytool failed to stop"
1625 cat $f > /dev/null &
1627 # wait a bit to allow implicit restore request to be handled.
1628 # if not, next stat would also block on layout-lock.
1631 local size=$(stat -c "%s" $f2)
1632 [ $size -eq $orig_size ] ||
1633 error "$f2: wrong size after archive: $size != $orig_size"
1635 copytool setup -m "$MOUNT3"
1639 size=$(stat -c "%s" $f)
1640 [ $size -eq $orig_size ] ||
1641 error "$f: wrong size after restore: $size != $orig_size"
1643 size=$(stat -c "%s" $f2)
1644 [ $size -eq $orig_size ] ||
1645 error "$f2: wrong size after restore: $size != $orig_size"
1649 size=$(stat -c "%s" $f)
1651 error "$f: wrong size after overwrite: $size != 0"
1653 size=$(stat -c "%s" $f2)
1655 error "$f2: wrong size after overwrite: $size != 0"
1657 run_test 12q "file attributes are refreshed after restore"
1661 for i in {1..10}; do
1662 local archive_dir="$(hsm_root)"/subdir/dir.$i
1664 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1665 for j in {1..10}; do
1666 local archive_file="$archive_dir"/file.$j
1668 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1674 copytool import "subdir" "$DIR/$tdir"
1676 # To check the import, the test uses diff with the -r flag
1677 # This is nice, but diff only checks files one by one, and triggering
1678 # an implicit restore for one file at a time will consume as many
1679 # seconds as there are files to compare. To speed this up, a restore
1680 # operation is triggered manually first.
1682 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1684 # Compare the imported data
1685 do_facet $SINGLEAGT \
1686 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1687 error "imported files differ from archived data"
1689 run_test 13 "Recursively import and restore a directory"
1692 # test needs a running copytool
1696 local f=$DIR/$tdir/$tfile
1697 local fid=$(create_small_file $f)
1698 local sum=$(md5sum $f | awk '{print $1}')
1699 $LFS hsm_archive $f || error "could not archive file"
1700 wait_request_state $fid ARCHIVE SUCCEED
1702 # create released file (simulate llapi_hsm_import call)
1703 local fid2=$(create_empty_file "$f")
1704 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1705 $LFS hsm_release $f || error "could not release file"
1707 # rebind the archive to the newly created file
1708 echo "rebind $fid to $fid2"
1710 copytool rebind $fid $fid2
1712 # restore file and compare md5sum
1713 local sum2=$(md5sum $f | awk '{print $1}')
1715 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1717 run_test 14 "Rebind archived file to a new fid"
1720 # test needs a running copytool
1724 local f=$DIR/$tdir/$tfile
1726 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1730 for i in $(seq 1 $count); do
1731 fids[$i]=$(create_small_file $f.$i)
1732 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1733 $LFS hsm_archive $f.$i || error "could not archive file"
1735 wait_all_done $(($count*60))
1737 stack_trap "rm -f $tmpfile" EXIT
1740 for i in $(seq 1 $count); do
1741 local fid2=$(create_empty_file "${f}.${i}")
1742 # add the rebind operation to the list
1743 echo ${fids[$i]} $fid2 >> $tmpfile
1745 # set it released (simulate llapi_hsm_import call)
1746 $LFS hsm_set --archived --exists $f.$i ||
1747 error "could not force hsm flags"
1748 $LFS hsm_release $f.$i || error "could not release file"
1750 nl=$(wc -l < $tmpfile)
1751 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1753 echo "rebind list of files"
1754 copytool rebind "$tmpfile"
1756 # restore files and compare md5sum
1757 for i in $(seq 1 $count); do
1758 local sum2=$(md5sum $f.$i | awk '{print $1}')
1759 [[ $sum2 == ${sums[$i]} ]] ||
1760 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1763 run_test 15 "Rebind a list of files"
1766 # test needs a running copytool
1770 # create a known size file so we can verify transfer speed
1773 dd if=/dev/zero of=$ref bs=1M count=20
1776 local f=$DIR/$tdir/$tfile
1777 local fid=$(copy_file $ref $f)
1779 local start=$(date +%s)
1781 wait_request_state $fid ARCHIVE SUCCEED
1782 local end=$(date +%s)
1783 # Add 1 to account for rounding errors between start and end (LU-8155)
1784 local duration=$((end - start + 1))
1786 [[ $duration -ge $((goal - 1)) ]] ||
1787 error "Transfer is too fast $duration < $goal"
1789 run_test 16 "Test CT bandwith control option"
1792 local f=$DIR/$tdir/$tfile
1793 create_empty_file "$f"
1795 # Could not release a non-archived file
1796 $LFS hsm_release $f && error "release should not succeed"
1798 # For following tests, we must test them with HS_ARCHIVED set
1799 $LFS hsm_set --exists --archived $f || error "could not add flag"
1801 # Could not release a file if no-release is set
1802 $LFS hsm_set --norelease $f || error "could not add flag"
1803 $LFS hsm_release $f && error "release should not succeed"
1804 $LFS hsm_clear --norelease $f || error "could not remove flag"
1806 # Could not release a file if lost
1807 $LFS hsm_set --lost $f || error "could not add flag"
1808 $LFS hsm_release $f && error "release should not succeed"
1809 $LFS hsm_clear --lost $f || error "could not remove flag"
1811 # Could not release a file if dirty
1812 $LFS hsm_set --dirty $f || error "could not add flag"
1813 $LFS hsm_release $f && error "release should not succeed"
1814 $LFS hsm_clear --dirty $f || error "could not remove flag"
1816 run_test 20 "Release is not permitted"
1819 # test needs a running copytool
1822 local f=$DIR/$tdir/test_release
1824 # Create a file and check its states
1825 local fid=$(create_small_file $f)
1826 check_hsm_flags $f "0x00000000"
1828 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1829 # used until file is flushed to disk
1830 if [ $(facet_fstype ost1) == "zfs" ]; then
1831 # this causes an OST_SYNC rpc to be sent
1832 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1833 # clear locks to reread file data
1834 cancel_lru_locks osc
1837 local orig_size=$(stat -c "%s" $f)
1838 local orig_blocks=$(stat -c "%b" $f)
1840 start_full_debug_logging
1842 $LFS hsm_archive $f || error "could not archive file"
1843 wait_request_state $fid ARCHIVE SUCCEED
1845 local blocks=$(stat -c "%b" $f)
1846 [ $blocks -eq $orig_blocks ] ||
1847 error "$f: wrong block number after archive: " \
1848 "$blocks != $orig_blocks"
1849 local size=$(stat -c "%s" $f)
1850 [ $size -eq $orig_size ] ||
1851 error "$f: wrong size after archive: $size != $orig_size"
1853 # Release and check states
1854 $LFS hsm_release $f || error "could not release file"
1855 check_hsm_flags $f "0x0000000d"
1857 blocks=$(stat -c "%b" $f)
1858 [ $blocks -gt 5 ] &&
1859 error "$f: too many blocks after release: $blocks > 5"
1860 size=$(stat -c "%s" $f)
1861 [ $size -ne $orig_size ] &&
1862 error "$f: wrong size after release: $size != $orig_size"
1864 # Check we can release an file without stripe info
1868 check_hsm_flags $f "0x00000000"
1869 $LFS hsm_archive $f || error "could not archive file"
1870 wait_request_state $fid ARCHIVE SUCCEED
1872 # Release and check states
1873 $LFS hsm_release $f || error "could not release file"
1874 check_hsm_flags $f "0x0000000d"
1876 # Release again a file that is already released is OK
1877 $LFS hsm_release $f || fail "second release should succeed"
1878 check_hsm_flags $f "0x0000000d"
1880 stop_full_debug_logging
1882 run_test 21 "Simple release tests"
1885 # test needs a running copytool
1888 local f=$DIR/$tdir/test_release
1889 local swap=$DIR/$tdir/test_swap
1891 # Create a file and check its states
1892 local fid=$(create_small_file $f)
1893 check_hsm_flags $f "0x00000000"
1895 $LFS hsm_archive $f || error "could not archive file"
1896 wait_request_state $fid ARCHIVE SUCCEED
1898 # Release and check states
1899 $LFS hsm_release $f || error "could not release file"
1900 check_hsm_flags $f "0x0000000d"
1902 create_small_file $swap
1903 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1907 run_test 22 "Could not swap a release file"
1910 # test needs a running copytool
1913 local f=$DIR/$tdir/test_mtime
1915 # Create a file and check its states
1916 local fid=$(create_small_file $f)
1917 check_hsm_flags $f "0x00000000"
1919 $LFS hsm_archive $f || error "could not archive file"
1920 wait_request_state $fid ARCHIVE SUCCEED
1922 # Set modification time in the past
1923 touch -m -a -d @978261179 $f
1925 # Release and check states
1926 $LFS hsm_release $f || error "could not release file"
1927 check_hsm_flags $f "0x0000000d"
1929 local MTIME=$(stat -c "%Y" $f)
1930 local ATIME=$(stat -c "%X" $f)
1931 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1932 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1934 run_test 23 "Release does not change a/mtime (utime)"
1937 local file=$DIR/$tdir/$tfile
1946 # test needs a running copytool
1949 fid=$(create_small_file $file)
1951 # Create a file and check its states
1952 check_hsm_flags $file "0x00000000"
1954 # Ensure atime is less than mtime and ctime.
1958 atime0=$(stat -c "%X" $file)
1959 mtime0=$(stat -c "%Y" $file)
1960 ctime0=$(stat -c "%Z" $file)
1962 [ $atime0 -lt $mtime0 ] ||
1963 error "atime $atime0 is not less than mtime $mtime0"
1965 [ $atime0 -lt $ctime0 ] ||
1966 error "atime $atime0 is not less than ctime $ctime0"
1968 # Archive should not change any timestamps.
1969 $LFS hsm_archive $file || error "cannot archive '$file'"
1970 wait_request_state $fid ARCHIVE SUCCEED
1972 atime1=$(stat -c "%X" $file)
1973 mtime1=$(stat -c "%Y" $file)
1974 ctime1=$(stat -c "%Z" $file)
1976 [ $atime0 -eq $atime1 ] ||
1977 error "archive changed atime from $atime0 to $atime1"
1979 [ $mtime0 -eq $mtime1 ] ||
1980 error "archive changed mtime from $mtime0 to $mtime1"
1982 [ $ctime0 -eq $ctime1 ] ||
1983 error "archive changed ctime from $ctime0 to $ctime1"
1985 # Release should not change any timestamps.
1986 $LFS hsm_release $file || error "cannot release '$file'"
1987 check_hsm_flags $file "0x0000000d"
1989 atime1=$(stat -c "%X" $file)
1990 mtime1=$(stat -c "%Y" $file)
1991 ctime1=$(stat -c "%Z" $file)
1993 [ $atime0 -eq $atime1 ] ||
1994 error "release changed atime from $atime0 to $atime1"
1996 [ $mtime0 -eq $mtime1 ] ||
1997 error "release changed mtime from $mtime0 to $mtime1"
1999 [ $ctime0 -eq $ctime1 ] ||
2000 error "release changed ctime from $ctime0 to $ctime1"
2002 # Restore should not change any timestamps.
2003 $LFS hsm_restore $file
2004 wait_request_state $fid RESTORE SUCCEED
2006 atime1=$(stat -c "%X" $file)
2007 mtime1=$(stat -c "%Y" $file)
2008 ctime1=$(stat -c "%Z" $file)
2010 [ $atime0 -eq $atime1 ] ||
2011 error "restore changed atime from $atime0 to $atime1"
2013 [ $mtime0 -eq $mtime1 ] ||
2014 error "restore changed mtime from $mtime0 to $mtime1"
2016 [ $ctime0 -eq $ctime1 ] ||
2017 error "restore changed ctime from $ctime0 to $ctime1"
2020 wait_copytools || error "Copytools failed to stop"
2022 # Once more, after unmount and mount.
2023 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2024 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2026 atime1=$(stat -c "%X" $file)
2027 mtime1=$(stat -c "%Y" $file)
2028 ctime1=$(stat -c "%Z" $file)
2030 [ $atime0 -eq $atime1 ] ||
2031 error "remount changed atime from $atime0 to $atime1"
2033 [ $mtime0 -eq $mtime1 ] ||
2034 error "remount changed mtime from $mtime0 to $mtime1"
2036 [ $ctime0 -eq $ctime1 ] ||
2037 error "remount changed ctime from $ctime0 to $ctime1"
2039 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2042 local file=$DIR/$tdir/$tfile
2048 # Test needs a running copytool.
2051 # Check that root can do HSM actions on a regular user's file.
2052 fid=$(create_small_file $file)
2053 sum0=$(md5sum $file)
2055 chown $RUNAS_ID:$RUNAS_GID $file ||
2056 error "cannot chown '$file' to '$RUNAS_ID'"
2058 chmod ugo-w $DIR/$tdir ||
2059 error "cannot chmod '$DIR/$tdir'"
2061 $LFS hsm_archive $file
2062 wait_request_state $fid ARCHIVE SUCCEED
2064 $LFS hsm_release $file
2065 check_hsm_flags $file "0x0000000d"
2067 $LFS hsm_restore $file
2068 wait_request_state $fid RESTORE SUCCEED
2070 # Check that ordinary user can get HSM state.
2071 $RUNAS $LFS hsm_state $file ||
2072 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2074 $LFS hsm_release $file
2075 check_hsm_flags $file "0x0000000d"
2077 # Check that ordinary user can accessed released file.
2078 sum1=$($RUNAS md5sum $file) ||
2079 error "user '$RUNAS_ID' cannot read '$file'"
2081 [ "$sum0" == "$sum1" ] ||
2082 error "md5sum mismatch for '$file'"
2084 run_test 24b "root can archive, release, and restore user files"
2087 local file=$DIR/$tdir/$tfile
2088 local action=archive
2093 # test needs a running copytool
2098 # Save the default masks and check that cleanup_24c will
2099 # restore the request masks correctly.
2100 user_save=$(get_hsm_param user_request_mask)
2101 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2102 group_save=$(get_hsm_param group_request_mask)
2103 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2104 other_save=$(get_hsm_param other_request_mask)
2105 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2107 [ "$user_save" == RESTORE ] ||
2108 error "user_request_mask is '$user_save' expected 'RESTORE'"
2109 [ "$group_save" == RESTORE ] ||
2110 error "group_request_mask is '$group_save' expected 'RESTORE'"
2111 [ "$other_save" == RESTORE ] ||
2112 error "other_request_mask is '$other_save' expected 'RESTORE'"
2115 create_small_file $file
2116 chown $RUNAS_ID:$GROUP $file ||
2117 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2119 $RUNAS $LFS hsm_$action $file &&
2120 error "$action by user should fail"
2122 set_hsm_param user_request_mask $action
2123 $RUNAS $LFS hsm_$action $file ||
2124 error "$action by user should succeed"
2127 create_small_file $file
2128 chown nobody:$RUNAS_GID $file ||
2129 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2131 $RUNAS $LFS hsm_$action $file &&
2132 error "$action by group should fail"
2134 set_hsm_param group_request_mask $action
2135 $RUNAS $LFS hsm_$action $file ||
2136 error "$action by group should succeed"
2139 create_small_file $file
2140 chown nobody:$GROUP $file ||
2141 error "cannot chown '$file' to 'nobody:$GROUP'"
2143 $RUNAS $LFS hsm_$action $file &&
2144 error "$action by other should fail"
2146 set_hsm_param other_request_mask $action
2147 $RUNAS $LFS hsm_$action $file ||
2148 error "$action by other should succeed"
2150 run_test 24c "check that user,group,other request masks work"
2153 local file1=$DIR/$tdir/$tfile
2154 local file2=$DIR2/$tdir/$tfile
2158 fid1=$(create_small_file $file1)
2161 $LFS getstripe $file1
2163 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2164 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2165 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2167 copytool setup -m "$MOUNT3"
2169 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2170 mount -o remount,ro $MOUNT2
2172 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2174 fid2=$(path2fid $file2)
2175 [ "$fid1" == "$fid2" ] ||
2176 error "FID mismatch '$fid1' != '$fid2'"
2178 $LFS hsm_archive $file2 &&
2179 error "archive should fail on read-only mount"
2180 check_hsm_flags $file1 "0x00000000"
2182 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2183 wait_request_state $fid1 ARCHIVE SUCCEED
2185 $LFS hsm_release $file1
2186 $LFS hsm_restore $file2
2187 wait_request_state $fid1 RESTORE SUCCEED
2189 $LFS hsm_release $file1 || error "cannot release '$file1'"
2190 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2192 $LFS hsm_release $file2 &&
2193 error "release should fail on read-only mount"
2197 run_test 24d "check that read-only mounts are respected"
2202 local f=$DIR/$tdir/$tfile
2205 fid=$(create_small_file $f) || error "cannot create $f"
2206 $LFS hsm_archive $f || error "cannot archive $f"
2207 wait_request_state $fid ARCHIVE SUCCEED
2208 $LFS hsm_release $f || error "cannot release $f"
2209 while ! $LFS hsm_state $f | grep released; do
2213 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2215 run_test 24e "tar succeeds on HSM released files" # LU-6213
2218 # test needs a running copytool
2221 mkdir -p $DIR/$tdir/d1
2222 local f=$DIR/$tdir/$tfile
2223 local fid=$(copy_file /etc/hosts $f)
2226 $LFS hsm_archive $f ||
2227 error "hsm_archive failed"
2228 wait_request_state $fid ARCHIVE SUCCEED
2229 $LFS hsm_release $f || error "cannot release $f"
2230 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2233 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2234 error "Can not recover the tar contents"
2236 echo "Sum0 = $sum0, sum1 = $sum1"
2237 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2239 run_test 24f "root can archive, release, and restore tar files"
2242 local file=$DIR/$tdir/$tfile
2245 echo "RUNAS = '$RUNAS'"
2250 chmod ugo+rwx $DIR/$tdir
2252 echo "Please listen carefully as our options have changed." | tee $file
2253 fid=$(path2fid $file)
2256 $LFS hsm_archive $file
2257 wait_request_state $fid ARCHIVE SUCCEED
2258 check_hsm_flags $file 0x00000009 # exists archived
2260 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2261 check_hsm_flags $file 0x0000000b # exists dirty archived
2263 run_test 24g "write by non-owner still sets dirty" # LU-11369
2266 # test needs a running copytool
2270 copy2archive /etc/hosts $tdir/$tfile
2272 local f=$DIR/$tdir/$tfile
2274 copytool import $tdir/$tfile $f
2276 $LFS hsm_set --lost $f
2281 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2283 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2284 " (Operation not permitted)"
2287 # test needs a running copytool
2292 local f=$DIR/$tdir/$tfile
2293 local fid=$(copy_file /etc/passwd $f)
2295 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2296 wait_request_state $fid ARCHIVE SUCCEED
2299 $LFS hsm_set --lost $f
2303 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2305 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2306 " (Operation not permitted)"
2308 test_26A() { # was test_26
2309 # test needs a running copytool
2312 local f=$DIR/$tdir/$tfile
2313 local fid=$(create_empty_file "$f")
2315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2316 wait_request_state $fid ARCHIVE SUCCEED
2319 wait_request_state $fid REMOVE SUCCEED
2321 check_hsm_flags $f "0x00000000"
2323 run_test 26A "Remove the archive of a valid file"
2326 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2327 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2329 # test needs a running copytool
2333 local f=$DIR/$tdir/$tfile
2334 local fid=$(copy_file /etc/passwd $f)
2336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2337 wait_request_state $fid ARCHIVE SUCCEED
2339 local f2=$DIR/$tdir/${tfile}_2
2340 local fid2=$(copy_file /etc/passwd $f2)
2342 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2343 wait_request_state $fid2 ARCHIVE SUCCEED
2345 local f3=$DIR/$tdir/${tfile}_3
2346 local fid3=$(copy_file /etc/passwd $f3)
2348 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2349 wait_request_state $fid3 ARCHIVE SUCCEED
2351 # set a long grace_delay vs short loop_period
2352 local orig_loop_period=$(get_hsm_param loop_period)
2353 local orig_grace_delay=$(get_hsm_param grace_delay)
2354 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2355 set_hsm_param loop_period 10
2356 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2357 set_hsm_param grace_delay 100
2361 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2362 set_hsm_param remove_archive_on_last_unlink 1
2364 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2369 wait_request_state $fid2 REMOVE SUCCEED
2371 assert_request_count $fid REMOVE 0 \
2372 "Unexpected archived data remove request for $f"
2373 assert_request_count $fid3 REMOVE 0 \
2374 "Unexpected archived data remove request for $f3"
2376 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2379 # test needs a running copytool
2383 local f=$DIR/$tdir/$tfile
2384 local fid=$(copy_file /etc/passwd $f)
2386 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2387 wait_request_state $fid ARCHIVE SUCCEED
2389 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2390 set_hsm_param remove_archive_on_last_unlink 1
2393 cdt_check_state stopped
2397 wait_request_state $fid REMOVE WAITING
2401 # copytool must re-register
2403 wait_copytools || error "copytool failed to stop"
2406 wait_request_state $fid REMOVE SUCCEED
2408 run_test 26b "RAoLU policy when CDT off"
2411 # test needs a running copytool
2415 local f=$DIR/$tdir/$tfile
2416 local fid=$(copy_file /etc/passwd $f)
2418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2419 wait_request_state $fid ARCHIVE SUCCEED
2421 local f2=$DIR/$tdir/${tfile}_2
2422 local fid2=$(copy_file /etc/passwd $f2)
2424 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2425 wait_request_state $fid2 ARCHIVE SUCCEED
2427 # set a long grace_delay vs short loop_period
2428 local orig_loop_period=$(get_hsm_param loop_period)
2429 local orig_grace_delay=$(get_hsm_param grace_delay)
2430 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2431 set_hsm_param loop_period 10
2432 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2433 set_hsm_param grace_delay 100
2435 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2436 set_hsm_param remove_archive_on_last_unlink 1
2438 multiop_bg_pause $f O_c || error "open $f failed"
2444 wait_request_state $fid2 REMOVE SUCCEED
2445 assert_request_count $fid REMOVE 0 \
2446 "Unexpected archived data remove request for $f"
2448 kill -USR1 $pid || error "multiop early exit"
2449 # should reach autotest timeout if multiop fails to trap
2450 # signal, close file, and exit ...
2451 wait $pid || error "wait PID $PID failed"
2453 wait_request_state $fid REMOVE SUCCEED
2455 run_test 26c "RAoLU effective when file closed"
2458 # test needs a running copytool
2462 local f=$DIR/$tdir/$tfile
2463 local fid=$(create_small_file $f)
2465 $LFS hsm_archive $f || error "could not archive file"
2466 wait_request_state $fid ARCHIVE SUCCEED
2468 # set a long grace_delay vs short loop_period
2469 local orig_loop_period=$(get_hsm_param loop_period)
2470 local orig_grace_delay=$(get_hsm_param grace_delay)
2471 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2472 set_hsm_param loop_period 10
2473 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2474 set_hsm_param grace_delay 100
2476 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2477 set_hsm_param remove_archive_on_last_unlink 1
2479 multiop_bg_pause $f O_c || error "multiop failed"
2486 wait_request_state $fid REMOVE SUCCEED
2488 client_up || client_up || true
2490 kill -USR1 $MULTIPID
2491 wait $MULTIPID || error "multiop close failed"
2493 run_test 26d "RAoLU when Client eviction"
2496 # test needs a running copytool
2499 create_archive_file $tdir/$tfile
2500 local f=$DIR/$tdir/$tfile
2501 copytool import $tdir/$tfile $f
2502 local fid=$(path2fid $f)
2506 [[ $? != 0 ]] || error "Remove of a released file should fail"
2508 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2511 # test needs a running copytool
2514 local f=$DIR/$tdir/$tfile
2515 local fid=$(create_empty_file "$f")
2517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2518 wait_request_state $fid ARCHIVE SUCCEED
2523 [[ $? != 0 ]] || error "Remove of a released file should fail"
2525 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2528 # test needs a running copytool
2531 local f=$DIR/$tdir/$tfile
2532 local fid=$(create_empty_file "$f")
2534 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2535 wait_request_state $fid ARCHIVE SUCCEED
2544 wait_request_state $fid REMOVE SUCCEED
2546 run_test 28 "Concurrent archive/file remove"
2549 # Tests --mntpath and --archive options
2552 copytool setup -m "$MOUNT" -a $archive_id
2554 # Bad archive number
2555 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2556 grep "Invalid argument" ||
2557 error "unexpected hsm_remove failure (1)"
2559 # mntpath is present but file is given
2560 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2561 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2562 error "unexpected hsm_remove failure (2)"
2564 run_test 29a "Tests --mntpath and --archive options"
2567 # test needs a running copytool
2570 local f=$DIR/$tdir/$tfile
2571 local fid=$(create_small_file $f)
2573 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2574 wait_request_state $fid ARCHIVE SUCCEED
2578 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2579 wait_request_state $fid REMOVE SUCCEED
2581 run_test 29b "Archive/delete/remove by FID from the archive."
2584 # test needs a running copytool
2587 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2588 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2589 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2591 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2592 wait_request_state $fid1 ARCHIVE SUCCEED
2593 wait_request_state $fid2 ARCHIVE SUCCEED
2594 wait_request_state $fid3 ARCHIVE SUCCEED
2596 rm -f $DIR/$tdir/$tfile-[1-3]
2598 echo $fid1 > $DIR/$tdir/list
2599 echo $fid2 >> $DIR/$tdir/list
2600 echo $fid3 >> $DIR/$tdir/list
2602 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2603 --filelist $DIR/$tdir/list
2604 wait_request_state $fid1 REMOVE SUCCEED
2605 wait_request_state $fid2 REMOVE SUCCEED
2606 wait_request_state $fid3 REMOVE SUCCEED
2608 run_test 29c "Archive/delete/remove by FID, using a file list."
2611 # test needs more than one CT
2612 needclients 3 || return 0
2618 # start all of the copytools
2619 for n in $(seq $AGTCOUNT); do
2620 copytool setup -f agt$n -a $n
2624 file=$DIR/$tdir/$tfile
2625 fid=$(create_small_file $file)
2627 $LFS hsm_archive $file
2628 wait_request_state $fid ARCHIVE SUCCEED
2629 check_hsm_flags $file "0x00000009"
2633 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2634 error "cannot hsm_remove '$fid'"
2636 # give time for CDT to handle remove request and create broadcasted
2639 # remove request has been broadcasted ?
2640 local cnt=$(get_request_count $fid REMOVE)
2641 # broadcasted requests + original
2642 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2643 error "remove not broadcasted to all CTs"
2645 # give time for CDT and CTs to handle broadcasted
2646 wait_for_loop_period
2648 # each agent serves one different archive_id, so broadcasted
2649 # hsm_remove request should only succeed once and fail at all others
2653 for n in $(seq $AGTCOUNT); do
2654 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2655 $HSM_PARAM.actions | awk \
2656 '/'$fid'.*action=REMOVE archive#='$n'/ \
2657 {print \\\$13}' | cut -f2 -d=")
2658 if [[ "$res" == "SUCCEED" ]]; then
2660 elif [[ "$res" == "FAILED" ]]; then
2665 [[ $scnt -eq 1 ]] ||
2666 error "one and only CT should have removed successfully"
2668 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2669 error "all but one CT should have failed to remove"
2671 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2672 "request to be sent once for each registered archive_id"
2675 # restore at exec cannot work on agent node (because of Linux kernel
2676 # protection of executables)
2677 needclients 2 || return 0
2679 # test needs a running copytool
2683 copy2archive /bin/true $tdir/$tfile
2685 local f=$DIR/$tdir/true
2686 copytool import $tdir/$tfile $f
2688 local fid=$(path2fid $f)
2690 stack_trap "cdt_clear_no_retry" EXIT
2691 # set no retry action mode
2698 [[ $st == 0 ]] || error "Failed to exec a released file"
2700 run_test 30a "Restore at exec (import case)"
2703 # restore at exec cannot work on agent node (because of Linux kernel
2704 # protection of executables)
2705 needclients 2 || return 0
2707 # test needs a running copytool
2711 local f=$DIR/$tdir/true
2712 local fid=$(copy_file /bin/true $f)
2714 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2715 wait_request_state $fid ARCHIVE SUCCEED
2719 stack_trap cdt_clear_no_retry EXIT
2720 # set no retry action mode
2728 [[ $st == 0 ]] || error "Failed to exec a released file"
2730 run_test 30b "Restore at exec (release case)"
2733 needclients 2 || return 0
2735 # test needs a running copytool
2739 local f=$DIR/$tdir/SLEEP
2740 local slp_sum1=$(md5sum /bin/sleep)
2741 local fid=$(copy_file /bin/sleep $f)
2743 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2744 wait_request_state $fid ARCHIVE SUCCEED
2746 check_hsm_flags $f "0x0000000d"
2748 stack_trap cdt_clear_no_retry EXIT
2749 # set no retry action mode
2752 do_node $CLIENT2 "$f 10" &
2756 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2758 [[ $? == 0 ]] || error "Execution failed during run"
2760 if [[ $? != 0 ]]; then
2761 local slp_sum2=$(md5sum /bin/sleep)
2762 # in case sleep file is modified during the test
2763 [[ $slp_sum1 == $slp_sum2 ]] &&
2764 error "Binary overwritten during exec"
2767 check_hsm_flags $f "0x00000009"
2769 run_test 30c "Update during exec of released file must fail"
2771 restore_and_check_size() {
2774 local s=$(stat -c "%s" $f)
2776 local st=$(get_hsm_flags $f)
2780 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2782 n=$(stat -c "%s" $f)
2783 # we echo in both cases to show stat is not hang
2784 if [[ $n != $s ]]; then
2785 echo "size seen is $n != $s"
2788 echo "size seen is right: $n == $s"
2792 st=$(get_hsm_flags $f)
2794 if [[ "$st" = "0x00000009" ]]; then
2797 echo " restore is too long"
2798 wait_request_state $fid RESTORE SUCCEED
2804 # test needs a running copytool
2807 create_archive_file $tdir/$tfile
2808 local f=$DIR/$tdir/$tfile
2809 copytool import $tdir/$tfile $f
2810 local fid=$($LFS path2fid $f)
2813 restore_and_check_size $f $fid
2816 [[ $err -eq 0 ]] || error "File size changed during restore"
2818 run_test 31a "Import a large file and check size during restore"
2822 # test needs a running copytool
2825 local f=$DIR/$tdir/$tfile
2826 local fid=$(create_file "$f" 1MB 39)
2828 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2829 wait_request_state $fid ARCHIVE SUCCEED
2832 restore_and_check_size $f $fid
2835 [[ $err -eq 0 ]] || error "File size changed during restore"
2837 run_test 31b "Restore a large unaligned file and check size during restore"
2840 # test needs a running copytool
2843 local f=$DIR/$tdir/$tfile
2844 local fid=$(create_file "$f" 1M 39)
2846 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2847 wait_request_state $fid ARCHIVE SUCCEED
2850 restore_and_check_size $f $fid
2853 [[ $err -eq 0 ]] || error "File size changed during restore"
2855 run_test 31c "Restore a large aligned file and check size during restore"
2858 local f=$DIR/$tdir/$tfile
2859 local fid=$(create_empty_file "$f")
2863 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2864 wait_request_state $fid ARCHIVE SUCCEED
2867 # Prevent restore from completing
2871 md5sum $f >/dev/null &
2874 wait_request_state $fid RESTORE STARTED
2879 # Check restore trigger process was killed
2881 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2883 run_test 33 "Kill a restore waiting process"
2886 # test needs a running copytool
2889 local f=$DIR/$tdir/$tfile
2890 local fid=$(create_empty_file "$f")
2892 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2893 wait_request_state $fid ARCHIVE SUCCEED
2896 # Prevent restore from completing
2899 md5sum $f >/dev/null &
2902 wait_request_state $fid RESTORE STARTED
2904 # rm must not block during restore
2905 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2908 wait_request_state $fid RESTORE SUCCEED
2910 # Check md5sum pgm finished
2911 kill -0 $pid && error "Restore initiatior still running"
2912 wait $pid || error "Restore initiator failed with $?"
2914 # Check the file was actually deleted
2915 [ ! -f "$f" ] || error "$f was not deleted"
2917 run_test 34 "Remove file during restore"
2920 # test needs a running copytool
2923 local f=$DIR/$tdir/$tfile
2924 local f1=$DIR/$tdir/$tfile-1
2925 local fid=$(create_empty_file "$f")
2926 local fid1=$(copy_file /etc/passwd $f1)
2928 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2929 wait_request_state $fid ARCHIVE SUCCEED
2932 # Prevent restore from completing
2935 md5sum $f >/dev/null &
2938 wait_request_state $fid RESTORE STARTED
2940 # mv must not block during restore
2941 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2944 wait_request_state $fid RESTORE SUCCEED
2946 # Check md5sum pgm finished
2947 kill -0 $pid && error "Restore initiatior still running"
2948 wait $pid || error "Restore initiator failed with $?"
2950 local fid2=$(path2fid $f)
2951 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2953 run_test 35 "Overwrite file during restore"
2956 # test needs a running copytool
2959 local f=$DIR/$tdir/$tfile
2960 local fid=$(create_empty_file "$f")
2962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2963 wait_request_state $fid ARCHIVE SUCCEED
2966 # Prevent restore from completing
2969 md5sum $f >/dev/null &
2972 wait_request_state $fid RESTORE STARTED
2974 # mv must not block during restore
2975 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2976 error "mv '$f' '$f.new' failed with rc=$?"
2979 wait_request_state $fid RESTORE SUCCEED
2981 # Check md5sum pgm finished
2982 kill -0 $pid && error "Restore initiator is still running"
2983 wait $pid || error "Restore initiator failed with $?"
2985 run_test 36 "Move file during restore"
2988 # LU-5683: check that an archived dirty file can be rearchived.
2991 local f=$DIR/$tdir/$tfile
2994 fid=$(create_small_file $f) || error "cannot create small file"
2996 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2997 wait_request_state $fid ARCHIVE SUCCEED
2998 $LFS hsm_release $f || error "cannot release $f"
3000 # Allow previous archive request to expire from the actions log.
3001 wait_for_grace_delay
3004 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3006 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3007 wait_request_state $fid ARCHIVE SUCCEED
3009 run_test 37 "re-archive a dirty file"
3016 for n in $(seq 1 $count); do
3017 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3019 echo "$count archive requests submitted"
3023 local stream_count=4
3024 local file_count=100
3026 local f=$DIR/$tdir/$tfile
3030 local max_requests=$(get_hsm_param max_requests)
3032 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3033 # Increase the number of HSM request that can be performed in
3034 # parallel. With the coordinator running once per second, this
3035 # also limits the number of requests per seconds that can be
3036 # performed, so we pick a decent number. But we also need to keep
3037 # that number low because the copytool has no rate limit and will
3038 # fail some requests if if gets too many at once.
3039 set_hsm_param max_requests 300
3041 for i in $(seq 1 $file_count); do
3042 for p in $(seq 1 $stream_count); do
3043 fid=$(copy_file /etc/hosts $f.$p.$i)
3049 # to be sure wait_all_done will not be mislead by previous tests
3051 wait_for_grace_delay
3053 # start archive streams in background (archive files in parallel)
3054 for p in $(seq 1 $stream_count); do
3055 multi_archive $f.$p $file_count &
3058 echo -n "Wait for all requests being enqueued..."
3063 run_test 40 "Parallel archive requests"
3066 # test needs a running copytool
3070 local f=$DIR/$tdir/$tfile
3071 local fid=$(create_small_file $f)
3073 $LFS hsm_archive $f || error "could not archive file"
3074 wait_request_state $fid ARCHIVE SUCCEED
3075 check_hsm_flags $f "0x00000009"
3077 multiop_bg_pause $f O_c || error "multiop failed"
3081 client_up || client_up || true
3083 kill -USR1 $MULTIPID
3084 wait $MULTIPID || error "multiop close failed"
3086 check_hsm_flags $f "0x0000000b"
3088 run_test 52 "Opened for write file on an evicted client should be set dirty"
3091 # test needs a running copytool
3095 local f=$DIR/$tdir/$tfile
3096 local fid=$(create_small_file $f)
3098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3099 error "could not archive file"
3100 wait_request_state $fid ARCHIVE SUCCEED
3101 check_hsm_flags $f "0x00000009"
3103 multiop_bg_pause $f o_c || error "multiop failed"
3107 client_up || client_up || true
3109 kill -USR1 $MULTIPID
3110 wait $MULTIPID || error "multiop close failed"
3112 check_hsm_flags $f "0x00000009"
3114 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3117 local f=$DIR/$tdir/$tfile
3118 local fid=$(create_file "$f" 1MB 39)
3122 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3123 error "could not archive file"
3124 wait_request_state $fid ARCHIVE STARTED
3126 check_hsm_flags $f "0x00000001"
3128 stack_trap "cdt_clear_no_retry" EXIT
3129 # Avoid coordinator resending this request as soon it has failed.
3134 wait_request_state $fid ARCHIVE FAILED
3136 check_hsm_flags $f "0x00000003"
3138 run_test 54 "Write during an archive cancels it"
3141 local f=$DIR/$tdir/$tfile
3142 local fid=$(create_file "$f" 1MB 39)
3146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3147 error "could not archive file"
3148 wait_request_state $fid ARCHIVE STARTED
3150 check_hsm_flags $f "0x00000001"
3152 stack_trap "cdt_clear_no_retry" EXIT
3153 # Avoid coordinator resending this request as soon it has failed.
3156 $TRUNCATE $f 1024 || error "truncate failed"
3158 wait_request_state $fid ARCHIVE FAILED
3160 check_hsm_flags $f "0x00000003"
3162 run_test 55 "Truncate during an archive cancels it"
3165 local f=$DIR/$tdir/$tfile
3166 local fid=$(create_file "$f" 1MB 39)
3170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3171 error "could not archive file"
3172 wait_request_state $fid ARCHIVE STARTED
3174 check_hsm_flags $f "0x00000001"
3176 # Change metadata and sync to be sure we are not changing only
3181 wait_request_state $fid ARCHIVE SUCCEED
3183 check_hsm_flags $f "0x00000009"
3185 run_test 56 "Setattr during an archive is ok"
3188 # Need one client for I/O, one for request
3189 needclients 2 || return 0
3191 # test needs a running copytool
3195 local f=$DIR/$tdir/test_archive_remote
3196 # Create a file on a remote node
3197 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3198 "count=2 conv=fsync"
3201 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3202 error "hsm_archive failed"
3203 local fid=$(path2fid $f)
3204 wait_request_state $fid ARCHIVE SUCCEED
3206 # Release and implicit restore it
3207 do_node $CLIENT2 "$LFS hsm_release $f" ||
3208 error "hsm_release failed"
3209 do_node $CLIENT2 "md5sum $f" ||
3210 error "hsm_restore failed"
3212 wait_request_state $fid RESTORE SUCCEED
3214 run_test 57 "Archive a file with dirty cache on another node"
3216 truncate_released_file() {
3220 local sz=$(stat -c %s $src_file)
3221 local f=$DIR/$tdir/$tfile
3222 local fid=$(copy_file $1 $f)
3226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3227 error "could not archive file"
3228 wait_request_state $fid ARCHIVE SUCCEED
3230 $LFS hsm_release $f || error "could not release file"
3232 $TRUNCATE $f $trunc_to || error "truncate failed"
3235 local sz1=$(stat -c %s $f)
3236 [[ $sz1 == $trunc_to ]] ||
3237 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3240 check_hsm_flags $f "0x0000000b"
3242 local state=$(get_request_state $fid RESTORE)
3243 [[ "$state" == "SUCCEED" ]] ||
3244 error "truncate $sz does not trig restore, state = $state"
3246 $TRUNCATE $ref $trunc_to
3247 cmp $ref $f || error "file data wrong after truncate"
3253 # test needs a running copytool
3258 local sz=$(stat -c %s /etc/passwd)
3260 echo "truncate up from $sz to $((sz*2))"
3261 truncate_released_file /etc/passwd $((sz*2))
3263 echo "truncate down from $sz to $((sz/2))"
3264 truncate_released_file /etc/passwd $((sz/2))
3266 echo "truncate to 0"
3267 truncate_released_file /etc/passwd 0
3269 run_test 58 "Truncate a released file will trigger restore"
3273 local server_version=$(lustre_version_code $SINGLEMDS)
3274 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3275 skip "Need MDS version at least 2.7.63" && return
3278 $MCREATE $DIR/$tfile || error "mcreate failed"
3279 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3280 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3281 fid=$(path2fid $DIR/$tfile)
3282 wait_request_state $fid ARCHIVE SUCCEED
3283 $LFS hsm_release $DIR/$tfile || error "release failed"
3285 run_test 59 "Release stripeless file with non-zero size"
3288 # This test validates the fix for LU-4512. Ensure that the -u
3289 # option changes the progress reporting interval from the
3290 # default (30 seconds) to the user-specified interval.
3291 local f=$DIR/$tdir/$tfile
3292 local fid=$(create_file "$f" 1M 10)
3295 local progress_timeout=$((interval * 4))
3296 copytool setup -b 1 --update-interval $interval
3299 local mdt=${MDT_PREFIX}${mdtidx}
3300 local mds=mds$((mdtidx + 1))
3302 # Wait for copytool to register
3303 wait_update_facet $mds \
3304 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3305 uuid 100 || error "coyptool failed to register with $mdt"
3307 local start_at=$(date +%s)
3308 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3309 error "could not archive file"
3311 local agent=$(facet_active_host $SINGLEAGT)
3312 local logfile=$(copytool_logfile $SINGLEAGT)
3314 wait_update $agent \
3315 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3316 error "copytool failed to start"
3318 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3319 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3325 echo -n "Expecting a progress update within $progress_timeout seconds... "
3327 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3328 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3329 echo "$RESULT bytes copied in $WAIT seconds."
3331 elif [ $WAIT -ge $progress_timeout ]; then
3332 error "Timed out waiting for progress update!"
3335 WAIT=$((WAIT + sleep))
3339 local finish_at=$(date +%s)
3340 local elapsed=$((finish_at - start_at))
3342 # Ensure that the progress update occurred within the expected window.
3343 if [ $elapsed -lt $((interval - 1)) ]; then
3344 error "Expected progress update after at least $interval seconds"
3347 echo "Wait for on going archive hsm action to complete"
3348 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3349 echo "File archiving not completed even after 10 secs"
3351 run_test 60 "Changing progress update interval from default"
3354 # test needs a running copytool
3358 local f=$DIR/$tdir/$tfile
3359 local fid=$(copy_file /etc/passwd $f)
3361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3364 wait_request_state $fid ARCHIVE FAILED
3366 run_test 61 "Waiting archive of a removed file should fail"
3369 # test needs a new running copytool
3370 stack_trap copytool_monitor_cleanup EXIT
3371 copytool_monitor_setup
3372 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3374 # Wait for the copytool to register.
3375 wait_update --verbose $(facet_active_host mds1) \
3376 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3378 error "copytool failed to register with MDT0000"
3381 wait_copytools || error "Copytools failed to stop"
3383 local REGISTER_EVENT
3384 local UNREGISTER_EVENT
3385 while read event; do
3386 local parsed=$(parse_json_event "$event")
3387 if [ -z "$parsed" ]; then
3388 error "Copytool sent malformed event: $event"
3392 if [ $event_type == "REGISTER" ]; then
3393 REGISTER_EVENT=$event
3394 elif [ $event_type == "UNREGISTER" ]; then
3395 UNREGISTER_EVENT=$event
3397 done < <(echo $"$(get_copytool_event_log)")
3399 if [ -z "$REGISTER_EVENT" ]; then
3400 error "Copytool failed to send register event to FIFO"
3403 if [ -z "$UNREGISTER_EVENT" ]; then
3404 error "Copytool failed to send unregister event to FIFO"
3407 echo "Register/Unregister events look OK."
3409 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3412 # Bump progress interval for livelier events.
3415 # test needs a new running copytool
3416 stack_trap copytool_monitor_cleanup EXIT
3417 copytool_monitor_setup
3418 copytool setup --update-interval $interval --event-fifo \
3419 "$HSMTOOL_MONITOR_DIR/fifo"
3421 stack_trap "cdt_clear_no_retry" EXIT
3422 # Just start and stop the copytool to generate events.
3425 local f=$DIR/$tdir/$tfile
3426 local fid=$(create_small_file "$f")
3428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3429 error "could not archive file"
3430 wait_request_state $fid ARCHIVE SUCCEED
3432 local expected_fields="event_time data_fid source_fid"
3433 expected_fields+=" total_bytes current_bytes"
3436 [ARCHIVE_START]=false
3437 [ARCHIVE_FINISH]=false
3438 [ARCHIVE_RUNNING]=false
3440 while read event; do
3441 # Make sure we're not getting anything from previous events.
3442 for field in $expected_fields; do
3446 local parsed=$(parse_json_event "$event")
3447 if [ -z "$parsed" ]; then
3448 error "Copytool sent malformed event: $event"
3452 events["$event_type"]=true
3454 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3456 # Do some simple checking of the progress update events.
3457 for expected_field in $expected_fields; do
3458 if [ -z ${!expected_field+x} ]; then
3459 error "Missing $expected_field field in event"
3463 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3465 # These should be identical throughout an archive operation
3466 [ $source_fid == $data_fid ] ||
3467 error "Expected source_fid to equal data_fid"
3468 done < <(echo $"$(get_copytool_event_log)")
3470 # Check we received every type of events we were expecting
3471 for event in "${!events[@]}"; do
3472 ${events["$event"]} ||
3473 error "Copytool failed to send '$event' event to FIFO"
3476 echo "Archive events look OK."
3478 run_test 71 "Copytool logs JSON archive events to FIFO"
3481 # Bump progress interval for livelier events.
3484 # test needs a new running copytool
3485 stack_trap copytool_monitor_cleanup EXIT
3486 copytool_monitor_setup
3487 copytool setup --update-interval $interval --event-fifo \
3488 "$HSMTOOL_MONITOR_DIR/fifo"
3489 local test_file=$HSMTOOL_MONITOR_DIR/file
3491 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3493 do_facet $SINGLEAGT "$cmd" ||
3494 error "cannot create $test_file on $SINGLEAGT"
3495 copy2archive $test_file $tdir/$tfile
3498 local f=$DIR/$tdir/$tfile
3499 copytool import $tdir/$tfile $f
3500 f=$DIR2/$tdir/$tfile
3501 echo "Verifying released state: "
3502 check_hsm_flags $f "0x0000000d"
3504 local fid=$(path2fid $f)
3506 wait_request_state $fid RESTORE SUCCEED
3508 local expected_fields="event_time data_fid source_fid"
3509 expected_fields+=" total_bytes current_bytes"
3513 while read event; do
3514 # Make sure we're not getting anything from previous events.
3515 for field in $expected_fields; do
3519 local parsed=$(parse_json_event "$event")
3520 if [ -z "$parsed" ]; then
3521 error "Copytool sent malformed event: $event"
3525 if [ $event_type == "RESTORE_START" ]; then
3527 if [ $source_fid != $data_fid ]; then
3528 error "source_fid should == data_fid at start"
3531 elif [ $event_type == "RESTORE_FINISH" ]; then
3533 if [ $source_fid != $data_fid ]; then
3534 error "source_fid should == data_fid at finish"
3537 elif [ $event_type != "RESTORE_RUNNING" ]; then
3541 # Do some simple checking of the progress update events.
3542 for expected_field in $expected_fields; do
3543 if [ -z ${!expected_field+x} ]; then
3544 error "Missing $expected_field field in event"
3548 if [ $total_bytes -eq 0 ]; then
3549 error "Expected total_bytes to be > 0"
3552 # When a restore starts out, the data fid is the same as the
3553 # source fid. After the restore has gotten going, we learn
3554 # the new data fid. Once the restore has finished, the source
3555 # fid is set to the new data fid.
3557 # We test this because some monitoring software may depend on
3558 # this behavior. If it changes, then the consumers of these
3559 # events may need to be modified.
3560 if [ $source_fid == $data_fid ]; then
3561 error "source_fid should != data_fid during restore"
3563 done < <(echo $"$(get_copytool_event_log)")
3565 if [ -z "$START_EVENT" ]; then
3566 error "Copytool failed to send restore start event to FIFO"
3569 if [ -z "$FINISH_EVENT" ]; then
3570 error "Copytool failed to send restore finish event to FIFO"
3573 echo "Restore events look OK."
3575 run_test 72 "Copytool logs JSON restore events to FIFO"
3578 file_count=51 # Max number of files constrained by LNET message size
3579 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3580 local f=$DIR/$tdir/$tfile
3581 local FILELIST=/tmp/filelist.txt
3585 for i in $(seq 1 $file_count); do
3586 fid=$(copy_file /etc/hosts $f.$i)
3587 echo $f.$i >> $FILELIST
3591 # to be sure wait_all_done will not be mislead by previous tests
3593 wait_for_grace_delay
3594 $LFS hsm_archive --filelist $FILELIST ||
3595 error "cannot archive a file list"
3597 $LFS hsm_release --filelist $FILELIST ||
3598 error "cannot release a file list"
3599 $LFS hsm_restore --filelist $FILELIST ||
3600 error "cannot restore a file list"
3603 run_test 90 "Archive/restore a file list"
3605 double_verify_reset_hsm_param() {
3607 echo "Testing $HSM_PARAM.$p"
3608 local val=$(get_hsm_param $p)
3610 local val2=$(($val * 2))
3611 set_hsm_param $p $val2
3612 val=$(get_hsm_param $p)
3613 [[ $val == $val2 ]] ||
3614 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3615 echo "Set $p to 0 must failed"
3619 set_hsm_param $p $save
3621 if [[ $rc == 0 ]]; then
3622 error "we must not be able to set $HSM_PARAM.$p to 0"
3627 double_verify_reset_hsm_param loop_period
3628 double_verify_reset_hsm_param grace_delay
3629 double_verify_reset_hsm_param active_request_timeout
3630 double_verify_reset_hsm_param max_requests
3631 double_verify_reset_hsm_param default_archive_id
3633 run_test 100 "Set coordinator /proc tunables"
3640 run_test 102 "Verify coordinator control"
3643 # test needs a running copytool
3650 for i in $(seq 1 20); do
3651 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3653 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3657 echo "Current requests"
3658 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3659 $HSM_PARAM.actions |\
3660 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3662 [[ -z "$res" ]] || error "Some request have not been canceled"
3664 run_test 103 "Purge all requests"
3669 local f=$DIR/$tdir/$tfile
3670 local fid=$(create_empty_file "$f")
3672 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3673 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3674 $HSM_PARAM.actions |\
3675 grep $fid | cut -f16 -d=")
3677 [[ "$data1" == "$DATAHEX" ]] ||
3678 error "Data field in records is ($data1) and not ($DATAHEX)"
3682 run_test 104 "Copy tool data field"
3685 local max_requests=$(get_hsm_param max_requests)
3689 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3690 set_hsm_param max_requests 300
3693 for i in $(seq -w 1 10); do
3694 cp /etc/passwd $DIR/$tdir/$i
3695 $LFS hsm_archive $DIR/$tdir/$i
3697 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3698 $HSM_PARAM.actions |\
3699 grep WAITING | wc -l")
3703 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3704 $HSM_PARAM.actions |\
3705 grep WAITING | wc -l")
3708 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3709 error "Requests count after shutdown $reqcnt2 != "\
3710 "before shutdown $reqcnt1"
3712 run_test 105 "Restart of coordinator"
3715 # test needs a running copytool
3718 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3720 check_agent_registered $uuid
3722 search_copytools || error "No copytool found"
3725 wait_copytools || error "Copytool failed to stop"
3727 check_agent_unregistered $uuid
3730 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3731 check_agent_registered $uuid
3733 run_test 106 "Copytool register/unregister"
3736 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3738 # test needs a running copytool
3740 # create and archive file
3742 local f1=$DIR/$tdir/$tfile
3743 local fid=$(copy_file /etc/passwd $f1)
3744 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3745 wait_request_state $fid ARCHIVE SUCCEED
3746 # shutdown and restart MDS
3748 # check the copytool still gets messages from MDT
3749 local f2=$DIR/$tdir/2
3750 local fid=$(copy_file /etc/passwd $f2)
3751 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3752 # main check of this sanity: this request MUST succeed
3753 wait_request_state $fid ARCHIVE SUCCEED
3755 run_test 107 "Copytool re-register after MDS restart"
3757 policy_set_and_test()
3761 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3762 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3763 [[ "$policy" == "$target" ]] ||
3764 error "Wrong policy after '$change': '$policy' != '$target'"
3768 # to force default policy setting if error
3769 CDT_POLICY_HAD_CHANGED=true
3771 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3772 local default="NonBlockingRestore [NoRetryAction]"
3773 [[ "$policy" == "$default" ]] ||
3774 error "default policy has changed,"\
3775 " '$policy' != '$default' update the test"
3776 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3777 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3778 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3779 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3780 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3781 # useless bacause we know but safer for futur changes to use real value
3782 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3783 echo "Next set_param must failed"
3784 policy_set_and_test "wrong" "$policy"
3787 echo "Back to default policy"
3788 cdt_set_sanity_policy
3790 run_test 109 "Policy display/change"
3793 # test needs a running copytool
3798 copy2archive /etc/passwd $tdir/$tfile
3800 local f=$DIR/$tdir/$tfile
3801 copytool import $tdir/$tfile $f
3802 local fid=$(path2fid $f)
3804 cdt_set_non_blocking_restore
3809 wait_request_state $fid RESTORE SUCCEED
3810 cdt_clear_non_blocking_restore
3814 error "md5sum returns $st != 1, "\
3815 "should also perror ENODATA (No data available)"
3817 run_test 110a "Non blocking restore policy (import case)"
3820 # test needs a running copytool
3824 local f=$DIR/$tdir/$tfile
3825 local fid=$(copy_file /etc/passwd $f)
3826 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3827 wait_request_state $fid ARCHIVE SUCCEED
3830 cdt_set_non_blocking_restore
3835 wait_request_state $fid RESTORE SUCCEED
3836 cdt_clear_non_blocking_restore
3840 error "md5sum returns $st != 1, "\
3841 "should also perror ENODATA (No data available)"
3843 run_test 110b "Non blocking restore policy (release case)"
3846 # test needs a running copytool
3850 copy2archive /etc/passwd $tdir/$tfile
3852 local f=$DIR/$tdir/$tfile
3854 copytool import $tdir/$tfile $f
3855 local fid=$(path2fid $f)
3859 copytool_remove_backend $fid
3862 wait_request_state $fid RESTORE FAILED
3869 [[ $st == 0 ]] || error "Restore does not failed"
3871 run_test 111a "No retry policy (import case), restore will error"\
3872 " (No such file or directory)"
3875 # test needs a running copytool
3879 local f=$DIR/$tdir/$tfile
3880 local fid=$(copy_file /etc/passwd $f)
3881 stack_trap cdt_clear_no_retry EXIT
3883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3884 wait_request_state $fid ARCHIVE SUCCEED
3887 copytool_remove_backend $fid
3890 wait_request_state $fid RESTORE FAILED
3894 [[ $st == 0 ]] || error "Restore does not failed"
3896 run_test 111b "No retry policy (release case), restore will error"\
3897 " (No such file or directory)"
3900 # test needs a running copytool
3904 local f=$DIR/$tdir/$tfile
3905 local fid=$(copy_file /etc/passwd $f)
3907 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3908 local l=$($LFS hsm_action $f)
3910 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3913 wait_request_state $fid ARCHIVE SUCCEED
3916 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3918 run_test 112 "State of recorded request"
3921 local f=$DIR/$tdir/$tfile
3922 local fid=$(create_empty_file "$f")
3926 # Prevent archive from completing
3929 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3930 # wait archive to register at CDT
3931 wait_request_state $fid ARCHIVE STARTED
3933 # Cancel the archive
3934 $LFS hsm_cancel "$f"
3936 wait_request_state $fid ARCHIVE CANCELED
3939 wait_request_state $fid CANCEL SUCCEED
3941 run_test 200 "Register/Cancel archive"
3944 # test needs a running copytool
3947 local f=$DIR/$tdir/$tfile
3948 create_archive_file $tdir/$tfile
3949 copytool import $tdir/$tfile $f
3950 local fid=$(path2fid $f)
3952 # test with cdt on is made in test_222
3955 # wait restore to register at CDT
3956 wait_request_state $fid RESTORE WAITING
3959 wait_request_state $fid RESTORE CANCELED
3960 wait_request_state $fid CANCEL SUCCEED
3962 run_test 201 "Register/Cancel restore"
3965 local f=$DIR/$tdir/$tfile
3966 local fid=$(create_empty_file "$f")
3968 # test needs a running copytool
3971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3972 wait_request_state $fid ARCHIVE SUCCEED
3976 # wait remove to register at CDT
3977 wait_request_state $fid REMOVE STARTED
3980 wait_request_state $fid REMOVE CANCELED
3982 run_test 202 "Register/Cancel remove"
3984 test_220A() { # was test_220
3985 # test needs a running copytool
3990 local f=$DIR/$tdir/$tfile
3991 local fid=$(copy_file /etc/passwd $f)
3995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3996 wait_request_state $fid ARCHIVE SUCCEED
3998 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3999 error "The expected changelog was not emitted"
4001 run_test 220A "Changelog for archive"
4004 # test needs a running copytool
4009 local f=$DIR/$tdir/$tfile
4010 local fid=$(copy_file /etc/passwd $f)
4014 # block copytool operations to allow for HSM request to be
4015 # submitted and file be unlinked (CDT will find object removed)
4018 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4020 # wait request to reach CT
4021 wait_request_state $fid ARCHIVE STARTED
4027 wait_request_state $fid ARCHIVE FAILED
4030 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4031 error "The expected changelog was not emitted"
4033 run_test 220a "Changelog for failed archive"
4036 local f=$DIR/$tdir/$tfile
4037 local fid=$(create_empty_file "$f")
4042 # Prevent archive from completing
4044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4045 wait_request_state $fid ARCHIVE STARTED
4048 wait_request_state $fid ARCHIVE CANCELED
4051 wait_request_state $fid CANCEL SUCCEED
4053 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4054 error "The expected changelog was not emitted"
4056 run_test 221 "Changelog for archive canceled"
4059 # test needs a running copytool
4063 copy2archive /etc/passwd $tdir/$tfile
4065 local f=$DIR/$tdir/$tfile
4066 copytool import $tdir/$tfile $f
4067 local fid=$(path2fid $f)
4072 wait_request_state $fid RESTORE SUCCEED
4074 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4075 error "The expected changelog was not emitted"
4077 run_test 222a "Changelog for explicit restore"
4080 # test needs a running copytool
4084 local f=$DIR/$tdir/$tfile
4085 local fid=$(copy_file /etc/passwd $f)
4088 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4089 wait_request_state $fid ARCHIVE SUCCEED
4094 wait_request_state $fid RESTORE SUCCEED
4096 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4097 error "The expected changelog was not emitted"
4099 run_test 222b "Changelog for implicit restore"
4102 # test needs a running copytool
4106 copy2archive /etc/passwd $tdir/$tfile
4108 local f=$DIR/$tdir/$tfile
4109 copytool import $tdir/$tfile $f
4110 local fid=$(path2fid $f)
4114 # block copytool operations to allow for HSM request to be
4115 # submitted and file be unlinked (CDT will find object removed)
4120 # wait request to reach CT
4121 wait_request_state $fid RESTORE STARTED
4127 wait_request_state $fid RESTORE FAILED
4130 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4131 error "The expected changelog was not emitted"
4133 run_test 222c "Changelog for failed explicit restore"
4136 # test needs a running copytool
4140 local f=$DIR/$tdir/$tfile
4141 local fid=$(copy_file /etc/passwd $f)
4144 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4145 wait_request_state $fid ARCHIVE SUCCEED
4148 copytool_remove_backend $fid
4151 wait_request_state $fid RESTORE FAILED
4154 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4155 error "The expected changelog was not emitted"
4157 run_test 222d "Changelog for failed implicit restore"
4160 # test needs a running copytool
4163 local f=$DIR/$tdir/$tfile
4164 create_archive_file $tdir/$tfile
4168 copytool import $tdir/$tfile $f
4169 local fid=$(path2fid $f)
4172 wait_request_state $fid RESTORE STARTED
4174 wait_request_state $fid RESTORE CANCELED
4175 wait_request_state $fid CANCEL SUCCEED
4177 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4178 error "The expected changelog was not emitted"
4180 run_test 223a "Changelog for restore canceled (import case)"
4183 local f=$DIR/$tdir/$tfile
4184 local fid=$(create_empty_file "$f")
4189 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4190 wait_request_state $fid ARCHIVE SUCCEED
4193 # Prevent restore from completing
4196 wait_request_state $fid RESTORE STARTED
4199 wait_request_state $fid RESTORE CANCELED
4202 wait_request_state $fid CANCEL SUCCEED
4204 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4205 error "The expected changelog was not emitted"
4207 run_test 223b "Changelog for restore canceled (release case)"
4209 test_224A() { # was test_224
4210 # test needs a running copytool
4215 local f=$DIR/$tdir/$tfile
4216 local fid=$(copy_file /etc/passwd $f)
4219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4220 wait_request_state $fid ARCHIVE SUCCEED
4223 wait_request_state $fid REMOVE SUCCEED
4225 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4226 error "The expected changelog was not emitted"
4228 run_test 224A "Changelog for remove"
4231 # test needs a running copytool
4236 local f=$DIR/$tdir/$tfile
4237 local fid=$(copy_file /etc/passwd $f)
4240 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4241 wait_request_state $fid ARCHIVE SUCCEED
4243 copytool_remove_backend $fid
4245 # block copytool operations to allow for HSM request to be
4246 # submitted and file be unlinked (CDT will find object removed)
4251 # wait for request to reach CT
4252 wait_request_state $fid REMOVE STARTED
4258 wait_request_state $fid REMOVE FAILED
4260 # HE_REMOVE|ENOENT=0x202
4261 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4262 error "The expected changelog was not emitted"
4264 run_test 224a "Changelog for failed remove"
4267 # test is not usable because remove request is too fast
4268 # so it is always finished before cancel can be done ...
4269 echo "Test disabled"
4272 # test needs a running copytool
4275 local f=$DIR/$tdir/$tfile
4276 local fid=$(create_empty_file "$f")
4279 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4280 wait_request_state $fid ARCHIVE SUCCEED
4282 # Prevent restore from completing
4287 wait_request_state $fid REMOVE CANCELED
4290 wait_request_state $fid CANCEL SUCCEED
4292 changelog_find -type HSM -target-fid $fid -flags 0x27d
4293 error "The expected changelog was not emitted"
4295 run_test 225 "Changelog for remove canceled"
4298 # test needs a running copytool
4303 local f1=$DIR/$tdir/$tfile-1
4304 local f2=$DIR/$tdir/$tfile-2
4305 local f3=$DIR/$tdir/$tfile-3
4306 local fid1=$(copy_file /etc/passwd $f1)
4307 local fid2=$(copy_file /etc/passwd $f2)
4308 copy_file /etc/passwd $f3
4311 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4312 wait_request_state $fid1 ARCHIVE SUCCEED
4314 $LFS hsm_archive $f2
4315 wait_request_state $fid2 ARCHIVE SUCCEED
4317 rm $f1 || error "rm $f1 failed"
4320 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4321 error "The expected changelog was not emitted"
4323 mv $f3 $f2 || error "mv $f3 $f2 failed"
4325 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4326 error "The expected changelog was not emitted"
4328 run_test 226 "changelog for last rm/mv with exiting archive"
4330 # This is just a utility function to clarify what test_227 does
4335 "$LFS" "$action" --$flag "$file" ||
4336 error "Cannot ${action#hsm_} $flag on '$file'"
4338 # Only one changelog should be produced
4339 local entries="$(changelog_find -type HSM -target-fid $fid)"
4340 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4341 error "lfs $action --$flag '$file' produced more than one" \
4344 # Parse the last changelog record
4345 local entry="$(tail -n 1 <<< "$entries")"
4346 eval local -A changelog=$(changelog2array $entry)
4348 # Also check the flags match what is expected
4349 [[ ${changelog[flags]} == $target ]] ||
4350 error "Changelog flag is '${changelog[flags]}', not $target"
4354 local file="$DIR/$tdir/$tfile"
4355 local fid=$(create_empty_file "$file")
4360 for flag in norelease noarchive exists archived lost; do
4361 if [ "$flag" == lost ]; then
4362 # The flag "lost" only works on an archived file
4363 "$LFS" hsm_set --archived "$file"
4367 action="hsm_set" __test_227
4368 action="hsm_clear" __test_227
4371 run_test 227 "changelog when explicit setting of HSM flags"
4374 # test needs a running copytool
4377 local fid=$(create_small_sync_file $DIR/$tfile)
4378 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4379 wait_request_state $fid ARCHIVE SUCCEED
4381 $LFS hsm_release $DIR/$tfile
4382 check_hsm_flags $DIR/$tfile "0x0000000d"
4384 filefrag $DIR/$tfile | grep " 1 extent found" ||
4385 error "filefrag on released file must return only one extent"
4387 # only newer versions of cp detect sparse files by stat/FIEMAP
4389 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4390 error "copying $DIR/$tfile"
4391 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4393 $LFS hsm_release $DIR/$tfile
4394 check_hsm_flags $DIR/$tfile "0x0000000d"
4396 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4398 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4400 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4401 error "comparing untarred $DIR/$tfile"
4403 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4404 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4406 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4409 # test needs a running copytool
4413 local maxrequest=$(get_hsm_param max_requests)
4414 local rqcnt=$(($maxrequest * 3))
4418 for i in $(seq -w 1 $rqcnt); do
4420 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4422 # we do it in 2 steps, so all requests arrive at the same time
4423 for i in $(seq -w 1 $rqcnt); do
4424 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4429 while [[ $cnt != 0 || $wt != 0 ]]; do
4431 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4432 $HSM_PARAM.actions |\
4433 grep STARTED | grep -v CANCEL | wc -l")
4434 [[ $cnt -le $maxrequest ]] ||
4435 error "$cnt > $maxrequest too many started requests"
4436 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4437 $HSM_PARAM.actions |\
4438 grep WAITING | wc -l")
4439 echo "max=$maxrequest started=$cnt waiting=$wt"
4442 run_test 250 "Coordinator max request"
4445 local f=$DIR/$tdir/$tfile
4446 local fid=$(create_empty_file "$f")
4449 # to have a short test
4450 local old_to=$(get_hsm_param active_request_timeout)
4451 set_hsm_param active_request_timeout 1
4452 # to be sure the cdt will wake up frequently so
4453 # it will be able to cancel the "old" request
4454 local old_loop=$(get_hsm_param loop_period)
4455 set_hsm_param loop_period 1
4460 # Prevent archive from completing
4462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4463 wait_request_state $fid ARCHIVE STARTED
4465 # Let the request timeout
4466 wait_request_state $fid ARCHIVE CANCELED
4468 set_hsm_param active_request_timeout $old_to
4469 set_hsm_param loop_period $old_loop
4471 run_test 251 "Coordinator request timeout"
4474 local f=$DIR/$tdir/$tfile
4475 local fid=$(create_empty_file "$f")
4477 # to have a short test
4478 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4479 set_hsm_param loop_period 1
4483 # Prevent archive from completing
4485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4486 wait_request_state $fid ARCHIVE STARTED
4489 stack_trap "set_hsm_param active_request_timeout \
4490 $(get_hsm_param active_request_timeout)" EXIT
4491 set_hsm_param active_request_timeout 1
4493 wait_request_state $fid ARCHIVE CANCELED
4496 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4500 # test needs a running copytool
4504 local f=$DIR/$tdir/$tfile
4506 dd if=/dev/zero of=$f bs=1MB count=10
4507 local fid=$(path2fid $f)
4509 $LFS hsm_archive $f || error "could not archive file"
4510 wait_request_state $fid ARCHIVE SUCCEED
4512 # clear locks to discard inode data
4513 cancel_lru_locks osc
4515 #define OBD_FAIL_MDC_MERGE 0x807
4516 $LCTL set_param fail_loc=0x807
4518 #expect error here, instead of release with wrong size
4521 if ((rc == 0)); then
4522 file_size=$(stat -c '%s' $f)
4523 if ((file_size != 10485760)); then
4524 error "Wrong file size after hsm_release"
4527 echo "could not release file"
4530 run_test 253 "Check for wrong file size after release"
4534 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4535 skip "need MDS version at least 2.10.56" && return
4537 # Check that the counters are initialized to 0
4539 for request_type in archive restore remove; do
4540 count="$(get_hsm_param ${request_type}_count)" ||
4541 error "Reading ${request_type}_count failed with $?"
4543 [ "$count" -eq 0 ] ||
4544 error "Expected ${request_type}_count to be " \
4548 run_test 254a "Request counters are initialized to zero"
4552 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4553 skip "need MDS version at least 2.10.56" && return
4555 # The number of request to launch (at least 32)
4556 local request_count=$((RANDOM % 32 + 32))
4557 printf "Will launch %i requests of each type\n" "$request_count"
4559 # Launch a copytool to process requests
4562 # Set hsm.max_requests to allow starting all requests at the same time
4564 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4565 set_hsm_param max_requests "$request_count"
4569 for request_type in archive restore remove; do
4570 printf "Checking %s requests\n" "${request_type}"
4571 # Suspend the copytool to give us time to read the proc files
4574 for ((i = 0; i < $request_count; i++)); do
4575 case $request_type in
4577 create_empty_file "$DIR/$tdir/$tfile-$i" \
4581 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4584 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4587 # Give the coordinator 10 seconds to start every request
4589 while get_hsm_param actions | grep -q WAITING; do
4592 [ $timeout -gt 0 ] ||
4593 error "${request_type^} requests took too " \
4597 count="$(get_hsm_param ${request_type}_count)"
4598 [ "$count" -eq "$request_count" ] ||
4599 error "Expected '$request_count' (!= '$count') " \
4600 "active $request_type requests"
4602 # Let the copytool process the requests
4604 # Give it 10 seconds maximum
4606 while get_hsm_param actions | grep -q STARTED; do
4609 [ $timeout -gt 0 ] ||
4610 error "${request_type^} requests took too " \
4614 count="$(get_hsm_param ${request_type}_count)"
4615 [ "$count" -eq 0 ] ||
4616 error "Expected 0 (!= '$count') " \
4617 "active $request_type requests"
4620 run_test 254b "Request counters are correctly incremented and decremented"
4622 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4623 # break in the future because of that.
4626 local -a files=("$DIR/$tdir/$tfile".{0..15})
4629 for file in "${files[@]}"; do
4630 create_small_file "$file"
4633 # Set a few hsm parameters
4635 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4636 set_hsm_param loop_period 1
4638 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4639 set_hsm_param max_requests 3
4643 "$LFS" hsm_archive "${files[0]}"
4644 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4645 "$LFS" hsm_release "${files[0]}"
4649 wait_copytools || error "copytools failed to stop"
4651 # Send several archive requests
4652 for file in "${files[@]:1}"; do
4653 "$LFS" hsm_archive "$file"
4656 # Send one restore request
4657 "$LFS" hsm_restore "${files[0]}"
4662 # Wait for all the requests to complete
4663 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4664 for file in "${files[@]:1}"; do
4665 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4668 # Collect the actions in the order in which the copytool processed them
4670 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4671 "$(copytool_logfile "$SINGLEAGT")")
4674 printf '%s\n' "${actions[@]}"
4677 for action in "${actions[@]:0:3}"; do
4678 [ "$action" == RESTORE ] && return
4681 error "Too many ARCHIVE requests were run before the RESTORE request"
4683 run_test 260a "Restore request have priority over other requests"
4685 # This test is very much tied to the implementation of the current priorisation
4686 # mechanism in the coordinator. It might not make sense to keep it in the future
4689 local -a files=("$DIR/$tdir/$tfile".{0..15})
4692 for file in "${files[@]}"; do
4693 create_small_file "$file"
4696 # Set a few hsm parameters
4698 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4699 set_hsm_param loop_period 1
4701 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4702 set_hsm_param max_requests 3
4705 copytool setup --archive-id 2
4706 "$LFS" hsm_archive --archive 2 "${files[0]}"
4707 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4708 "$LFS" hsm_release "${files[0]}"
4712 wait_copytools || error "copytools failed to stop"
4714 # Send several archive requests
4715 for file in "${files[@]:1}"; do
4716 "$LFS" hsm_archive "$file"
4719 # Send one restore request
4720 "$LFS" hsm_restore "${files[0]}"
4724 copytool setup --archive-id 2
4726 # Wait for all the requests to complete
4727 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4728 for file in "${files[@]:1}"; do
4729 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4732 # Collect the actions in the order in which the copytool processed them
4734 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4735 "$(copytool_logfile "$SINGLEAGT")")
4738 printf '%s\n' "${actions[@]}"
4741 for action in "${actions[@]:0:3}"; do
4742 [ "$action" == RESTORE ] && return
4745 error "Too many ARCHIVE requests were run before the RESTORE request"
4747 run_test 260b "Restore request have priority over other requests"
4749 # This test is very much tied to the implementation of the current priorisation
4750 # mechanism in the coordinator. It might not make sense to keep it in the future
4753 local -a files=("$DIR/$tdir/$tfile".{0..15})
4756 for file in "${files[@]}"; do
4757 create_small_file "$file"
4760 # Set a few hsm parameters
4762 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4763 set_hsm_param loop_period 10
4765 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4766 set_hsm_param max_requests 3
4769 copytool setup --archive-id 2
4770 "$LFS" hsm_archive --archive 2 "${files[0]}"
4771 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4772 "$LFS" hsm_release "${files[0]}"
4776 wait_copytools || error "copytools failed to stop"
4778 "$LFS" hsm_archive "${files[1]}"
4782 copytool setup --archive-id 2
4784 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4786 # Send several archive requests
4787 for file in "${files[@]:2}"; do
4788 "$LFS" hsm_archive "$file"
4791 # Send one restore request
4792 "$LFS" hsm_restore "${files[0]}"
4794 # Wait for all the requests to complete
4795 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4796 for file in "${files[@]:2}"; do
4797 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4800 # Collect the actions in the order in which the copytool processed them
4802 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4803 "$(copytool_logfile "$SINGLEAGT")")
4806 printf '%s\n' "${actions[@]}"
4809 for action in "${actions[@]:0:3}"; do
4810 [ "$action" == RESTORE ] &&
4811 error "Restore requests should not be prioritised" \
4812 "unless the coordinator is doing housekeeping"
4816 run_test 260c "Restore request have priority over other requests"
4819 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4821 # the only way to test ondisk conf is to restart MDS ...
4822 echo "Stop coordinator and remove coordinator state at mount"
4825 # clean on disk conf set by default
4826 cdt_clear_mount_state
4827 cdt_check_state stopped
4829 # check cdt still off after umount/remount
4831 cdt_check_state stopped
4833 echo "Set coordinator start at mount, and start coordinator"
4834 cdt_set_mount_state enabled
4837 cdt_check_state enabled
4839 # check cdt still on after umount/remount
4841 cdt_check_state enabled
4843 # we are back to original state (cdt started at mount)
4845 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4848 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4850 local ai=$(get_hsm_param default_archive_id)
4851 local new=$((ai + 1))
4853 set_hsm_param default_archive_id $new -P
4855 local res=$(get_hsm_param default_archive_id)
4858 set_hsm_param default_archive_id "" "-P -d"
4860 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4862 run_test 301 "HSM tunnable are persistent"
4865 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4867 local ai=$(get_hsm_param default_archive_id)
4868 local new=$((ai + 1))
4873 set_hsm_param default_archive_id $new -P
4876 for mdtno in $(seq 1 $MDSCOUNT); do
4881 cdt_check_state enabled
4883 local res=$(get_hsm_param default_archive_id)
4886 set_hsm_param default_archive_id "" "-P -d"
4888 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4890 run_test 302 "HSM tunnable are persistent when CDT is off"
4893 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4899 local dir_mdt0=$DIR/$tdir/mdt0
4900 local dir_mdt1=$DIR/$tdir/mdt1
4902 # create 1 dir per MDT
4903 stack_trap "rm -rf $dir_mdt0" EXIT
4904 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4905 stack_trap "rm -rf $dir_mdt1" EXIT
4906 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4908 # create 1 file in each MDT
4909 local fid1=$(create_small_file $dir_mdt0/$tfile)
4910 local fid2=$(create_small_file $dir_mdt1/$tfile)
4912 # check that hsm request on mdt0 is sent to the right MDS
4913 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4914 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4915 echo "archive successful on mdt0"
4917 # check that hsm request on mdt1 is sent to the right MDS
4918 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4919 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4920 echo "archive successful on mdt1"
4922 run_test 400 "Single request is sent to the right MDT"
4925 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4931 local dir_mdt0=$DIR/$tdir/mdt0
4932 local dir_mdt1=$DIR/$tdir/mdt1
4934 # create 1 dir per MDT
4935 stack_trap "rm -rf $dir_mdt0" EXIT
4936 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4937 stack_trap "rm -rf $dir_mdt1" EXIT
4938 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4940 # create 1 file in each MDT
4941 local fid1=$(create_small_file $dir_mdt0/$tfile)
4942 local fid2=$(create_small_file $dir_mdt1/$tfile)
4944 # check that compound requests are shunt to the rights MDTs
4945 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4946 error "lfs hsm_archive"
4947 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4948 echo "archive successful on mdt0"
4949 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4950 echo "archive successful on mdt1"
4952 run_test 401 "Compound requests split and sent to their respective MDTs"
4954 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4959 local node=$(facet_active_host $facet)
4961 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4962 awk '{print $4}'); do
4963 echo "$3 $mdc on $node"
4964 do_facet $facet "$LCTL --device $mdc $state" || return 1
4969 # deactivate all mdc on agent1
4970 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4972 copytool setup --no-fail
4974 check_agent_unregistered "uuid" # match any agent
4976 # no expected running copytool
4977 search_copytools $agent && error "Copytool start should have failed"
4980 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4982 run_test 402a "Copytool start fails if all MDTs are inactive"
4989 local f=$DIR/$tdir/$tfile
4990 touch $f || error "touch $f failed"
4991 local fid=$(path2fid $f)
4993 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4994 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4997 # give time for CDT to send request and to keep it for retry
4998 wait_for_loop_period
5000 wait_request_state $fid ARCHIVE WAITING
5002 do_facet $SINGLEAGT lctl set_param fail_loc=0
5004 # request should succeed now
5005 wait_request_state $fid ARCHIVE SUCCEED
5007 run_test 402b "CDT must retry request upon slow start of CT"
5010 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5012 local agent=$(facet_active_host $SINGLEAGT)
5014 # deactivate all mdc for MDT0001
5015 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5018 local uuid=$(get_agent_uuid $agent)
5019 # check the agent is registered on MDT0000, and not on MDT0001
5020 check_agent_registered_by_mdt $uuid 0
5021 check_agent_unregistered_by_mdt $uuid 1
5023 # check running copytool process
5024 search_copytools $agent || error "No running copytools on $agent"
5026 # reactivate all mdc for MDT0001
5027 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5029 # make sure the copytool is now registered to all MDTs
5030 check_agent_registered $uuid
5032 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5035 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5039 # create files on both MDT0000 and MDT0001
5042 local dir_mdt0=$DIR/$tdir/mdt0
5043 stack_trap "rm -rf $dir_mdt0" EXIT
5044 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5046 # create 1 file on mdt0
5047 local fid1=$(create_small_file $dir_mdt0/$tfile)
5049 # deactivate all mdc for MDT0001
5050 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5052 # send an HSM request for files in MDT0000
5053 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5055 # check for completion of files in MDT0000
5056 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5057 echo "archive successful on mdt0"
5059 # reactivate all mdc for MDT0001
5060 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5062 run_test 404 "Inactive MDT does not block requests for active MDTs"
5065 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5071 local striped_dir=$DIR/$tdir/striped_dir
5073 # create striped dir on all of MDTs
5074 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5076 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5077 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5078 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5079 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5081 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5082 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5083 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5084 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5086 # check that compound requests are shunt to the rights MDTs
5087 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5088 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5089 error "lfs hsm_archive"
5091 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5092 echo "archive successful on $fid1"
5093 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5094 echo "archive successful on $fid2"
5095 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5096 echo "archive successful on $fid3"
5097 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5098 echo "archive successful on $fid4"
5100 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5101 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5102 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5103 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5105 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5106 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5107 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5108 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5110 run_test 405 "archive and release under striped directory"
5113 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5115 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5116 skip "need MDS version at least 2.7.64" && return 0
5121 fid=$(create_small_file $DIR/$tdir/$tfile)
5126 $LFS hsm_archive $DIR/$tdir/$tfile
5127 wait_request_state "$fid" ARCHIVE SUCCEED
5128 $LFS hsm_release $DIR/$tdir/$tfile
5130 # Should migrate $tdir but not $tfile.
5131 $LFS migrate -m1 $DIR/$tdir &&
5132 error "migrating HSM an archived file should fail"
5134 $LFS hsm_restore $DIR/$tdir/$tfile
5135 wait_request_state "$fid" RESTORE SUCCEED
5137 $LFS hsm_remove $DIR/$tdir/$tfile
5138 wait_request_state "$fid" REMOVE SUCCEED
5140 cat $DIR/$tdir/$tfile > /dev/null ||
5141 error "cannot read $DIR/$tdir/$tfile"
5143 $LFS migrate -m1 $DIR/$tdir ||
5144 error "cannot complete migration after HSM remove"
5146 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5147 if ((mdt_index != 1)); then
5148 error "expected MDT index 1, got $mdt_index"
5151 # Refresh fid after migration.
5152 fid=$(path2fid $DIR/$tdir/$tfile)
5155 $LFS hsm_archive $DIR/$tdir/$tfile
5156 wait_request_state "$fid" ARCHIVE SUCCEED 1
5158 lctl set_param debug=+trace
5159 $LFS hsm_release $DIR/$tdir/$tfile ||
5160 error "cannot release $DIR/$tdir/$tfile"
5162 $LFS hsm_restore $DIR/$tdir/$tfile
5163 wait_request_state "$fid" RESTORE SUCCEED 1
5165 cat $DIR/$tdir/$tfile > /dev/null ||
5166 error "cannot read $DIR/$tdir/$tfile"
5168 run_test 406 "attempting to migrate HSM archived files is safe"
5171 local f=$DIR/$tdir/$tfile
5172 local f2=$DIR2/$tdir/$tfile
5173 local fid=$(create_empty_file "$f")
5177 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5178 wait_request_state $fid ARCHIVE SUCCEED
5181 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5182 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5184 # Prevent restore from completing
5188 # 1st request holds layout lock while appropriate
5189 # RESTORE record is still not added to llog
5193 # after umount hsm_actions->O/x/x log shouldn't have
5194 # double RESTORE records like below
5195 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5196 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5198 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5202 wait_request_state $fid RESTORE SUCCEED
5204 run_test 407 "Check for double RESTORE records in llog"
5208 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5209 skip "HSM migrate is not supported" && return
5211 test_mkdir -p $DIR/$tdir
5212 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5214 run_test 500 "various LLAPI HSM tests"
5217 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5218 skip "need MDS version at least 2.10.58" && return 0
5222 local f=$DIR/$tdir/$tfile
5225 # set changelog_mask to ALL
5226 changelog_chmask "ALL"
5228 chmod 777 $DIR/$tdir
5229 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5230 local fid=$(path2fid $f)
5233 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5234 -gid "$RUNAS_GID") ||
5235 error "No matching CREAT entry"
5237 # Parse the changelog
5238 eval local -A changelog=$(changelog2array $entry)
5239 local nid="${changelog[nid]}"
5242 echo "Got NID '$nid'"
5243 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5244 error "nid '$nid' does not match any client NID:" \
5247 run_test 600 "Changelog fields 'u=' and 'nid='"
5250 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5251 skip "need MDS version at least 2.10.58" && return 0
5255 local f=$DIR/$tdir/$tfile
5258 # set changelog_mask to ALL
5259 changelog_chmask "ALL"
5261 touch $f || error "touch $f failed"
5262 local fid=$(path2fid $f)
5265 cat $f || error "cat $f failed"
5267 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5268 error "No matching OPEN entry"
5270 run_test 601 "OPEN Changelog entry"
5273 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5274 skip "need MDS version at least 2.10.58" && return 0
5278 local f=$DIR/$tdir/$tfile
5281 # set changelog_mask to ALL
5282 changelog_chmask "ALL"
5284 touch $f || error "touch $f failed"
5285 local fid=$(path2fid $f)
5288 cat $f || error "cat $f failed"
5290 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5294 echo f > $f || error "write $f failed"
5297 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5299 # remove OPEN from changelog_mask
5300 changelog_chmask "-OPEN"
5304 cat $f || error "cat $f failed"
5307 changelog_find -type CLOSE -target-fid $fid &&
5308 error "There should be no CLOSE entry"
5312 echo f > $f || error "write $f failed"
5315 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5317 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5320 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5321 skip "need MDS version at least 2.10.58" && return 0
5325 local f=$DIR/$tdir/$tfile
5328 # set changelog_mask to ALL
5329 changelog_chmask "ALL"
5331 touch $f || error "touch $f failed"
5332 local fid=$(path2fid $f)
5334 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5337 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5339 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5340 error "No matching GXATR entry"
5342 run_test 603 "GETXATTR Changelog entry"
5345 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5346 skip "need MDS version at least 2.10.58" && return 0
5350 local f=$DIR/$tdir/$tfile
5351 local f2=$DIR2/$tdir/$tfile
5352 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5354 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5355 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5356 do_facet mds1 lctl set_param "$procname=20"
5360 # set changelog_mask to ALL
5361 changelog_chmask "ALL"
5363 touch $f || error "touch $f failed"
5364 local fid=$(path2fid $f)
5370 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5374 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5375 -gid "$RUNAS_GID" -mode "r--") ||
5376 error "No matching NOPEN entry"
5378 # Parse the changelog
5379 eval local -A changelog=$(changelog2array $entry)
5380 local nid="${changelog[nid]}"
5383 echo "Got NID '$nid'"
5384 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5385 error "nid '$nid' does not match any client NID:" \
5390 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5393 changelog_find -type NOPEN -target-fid $fid &&
5394 error "There should be no NOPEN entry"
5396 # Sleep for `changelog_deniednext` seconds
5401 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5404 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5405 -gid "$RUNAS_GID" -mode "r--") ||
5406 error "No matching NOPEN entry"
5408 # Parse the changelog
5409 eval local -A changelog=$(changelog2array $entry)
5410 local nid="${changelog[nid]}"
5413 echo "Got NID '$nid'"
5414 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5415 error "nid '$nid' does not match any client NID:" \
5418 run_test 604 "NOPEN Changelog entry"
5421 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5422 skip "need MDS version at least 2.10.58" && return 0
5426 local f=$DIR/$tdir/$tfile
5427 local f2=$DIR2/$tdir/$tfile
5430 # set changelog_mask to ALL
5431 changelog_chmask "ALL"
5433 touch $f || error "touch $f failed"
5434 local fid=$(path2fid $f)
5438 exec 3<> $f || error "open $f failed"
5442 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5446 exec 4<> $f || error "open $f failed"
5449 changelog_find -type OPEN -target-fid $fid &&
5450 error "There should be no OPEN entry"
5452 exec 4>&- || error "close $f failed"
5455 changelog_find -type CLOSE -target-fid $fid &&
5456 error "There should be no CLOSE entry"
5460 # access in rw, so different access mode should generate entries
5461 cat $f || error "cat $f failed"
5464 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5466 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5470 # same access as first one, should not generate new entries
5471 exec 4<> $f || error "open $f failed"
5474 changelog_find -type OPEN -target-fid $fid &&
5475 error "There should be no OPEN entry"
5477 exec 4>&- || error "close $f failed"
5480 changelog_find -type CLOSE -target-fid $fid &&
5481 error "There should be no CLOSE entry"
5485 # access by different user should generate new entries
5486 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5489 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5491 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5495 exec 3>&- || error "close $f failed"
5498 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5500 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5503 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5504 skip "need MDS version at least 2.10.58" && return 0
5506 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5507 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5508 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5509 skip_env "missing llog_reader" && return
5510 local fstype=$(facet_fstype mds1)
5514 local f=$DIR/$tdir/$tfile
5517 # set changelog_mask to ALL
5518 changelog_chmask "ALL"
5520 chmod 777 $DIR/$tdir
5521 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5522 local fid=$(path2fid $f)
5523 rm $f || error "rm $f failed"
5525 local mntpt=$(facet_mntpt mds1)
5529 #remount mds1 as ldiskfs or zfs type
5530 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5531 stop mds1 || error "stop mds1 failed"
5532 mount_fstype mds1 || error "remount mds1 failed"
5534 for ((i = 0; i < 1; i++)); do
5535 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5536 local cat_file=$(do_facet mds1 $llog_reader \
5537 $mntpt/changelog_catalog | awk \
5538 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5539 [ -n "$cat_file" ] || error "no catalog file"
5541 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5542 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5543 [ -n "$entry" ] || error "no CREAT entry"
5546 local uidgid=$(echo $entry |
5547 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5548 [ -n "$uidgid" ] || error "uidgid is empty"
5549 echo "Got UID/GID $uidgid"
5550 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5551 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5552 local nid=$(echo $entry |
5553 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5554 [ -n "$nid" ] || error "nid is empty"
5556 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5557 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5559 run_test 606 "llog_reader groks changelog fields"
5562 check_and_cleanup_lustre