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 # test needs a running copytool
2246 copy2archive /etc/hosts $tdir/$tfile
2248 local f=$DIR/$tdir/$tfile
2250 copytool import $tdir/$tfile $f
2252 $LFS hsm_set --lost $f
2257 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2259 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2260 " (Operation not permitted)"
2263 # test needs a running copytool
2268 local f=$DIR/$tdir/$tfile
2269 local fid=$(copy_file /etc/passwd $f)
2271 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2272 wait_request_state $fid ARCHIVE SUCCEED
2275 $LFS hsm_set --lost $f
2279 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2281 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2282 " (Operation not permitted)"
2284 test_26A() { # was test_26
2285 # test needs a running copytool
2288 local f=$DIR/$tdir/$tfile
2289 local fid=$(create_empty_file "$f")
2291 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2292 wait_request_state $fid ARCHIVE SUCCEED
2295 wait_request_state $fid REMOVE SUCCEED
2297 check_hsm_flags $f "0x00000000"
2299 run_test 26A "Remove the archive of a valid file"
2302 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2303 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2305 # test needs a running copytool
2309 local f=$DIR/$tdir/$tfile
2310 local fid=$(copy_file /etc/passwd $f)
2312 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2313 wait_request_state $fid ARCHIVE SUCCEED
2315 local f2=$DIR/$tdir/${tfile}_2
2316 local fid2=$(copy_file /etc/passwd $f2)
2318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2319 wait_request_state $fid2 ARCHIVE SUCCEED
2321 local f3=$DIR/$tdir/${tfile}_3
2322 local fid3=$(copy_file /etc/passwd $f3)
2324 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2325 wait_request_state $fid3 ARCHIVE SUCCEED
2327 # set a long grace_delay vs short loop_period
2328 local orig_loop_period=$(get_hsm_param loop_period)
2329 local orig_grace_delay=$(get_hsm_param grace_delay)
2330 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2331 set_hsm_param loop_period 10
2332 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2333 set_hsm_param grace_delay 100
2337 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2338 set_hsm_param remove_archive_on_last_unlink 1
2340 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2345 wait_request_state $fid2 REMOVE SUCCEED
2347 assert_request_count $fid REMOVE 0 \
2348 "Unexpected archived data remove request for $f"
2349 assert_request_count $fid3 REMOVE 0 \
2350 "Unexpected archived data remove request for $f3"
2352 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2355 # test needs a running copytool
2359 local f=$DIR/$tdir/$tfile
2360 local fid=$(copy_file /etc/passwd $f)
2362 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2363 wait_request_state $fid ARCHIVE SUCCEED
2365 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2366 set_hsm_param remove_archive_on_last_unlink 1
2369 cdt_check_state stopped
2373 wait_request_state $fid REMOVE WAITING
2377 # copytool must re-register
2379 wait_copytools || error "copytool failed to stop"
2382 wait_request_state $fid REMOVE SUCCEED
2384 run_test 26b "RAoLU policy when CDT off"
2387 # test needs a running copytool
2391 local f=$DIR/$tdir/$tfile
2392 local fid=$(copy_file /etc/passwd $f)
2394 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2395 wait_request_state $fid ARCHIVE SUCCEED
2397 local f2=$DIR/$tdir/${tfile}_2
2398 local fid2=$(copy_file /etc/passwd $f2)
2400 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2401 wait_request_state $fid2 ARCHIVE SUCCEED
2403 # set a long grace_delay vs short loop_period
2404 local orig_loop_period=$(get_hsm_param loop_period)
2405 local orig_grace_delay=$(get_hsm_param grace_delay)
2406 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2407 set_hsm_param loop_period 10
2408 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2409 set_hsm_param grace_delay 100
2411 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2412 set_hsm_param remove_archive_on_last_unlink 1
2414 multiop_bg_pause $f O_c || error "open $f failed"
2420 wait_request_state $fid2 REMOVE SUCCEED
2421 assert_request_count $fid REMOVE 0 \
2422 "Unexpected archived data remove request for $f"
2424 kill -USR1 $pid || error "multiop early exit"
2425 # should reach autotest timeout if multiop fails to trap
2426 # signal, close file, and exit ...
2427 wait $pid || error "wait PID $PID failed"
2429 wait_request_state $fid REMOVE SUCCEED
2431 run_test 26c "RAoLU effective when file closed"
2434 # test needs a running copytool
2438 local f=$DIR/$tdir/$tfile
2439 local fid=$(create_small_file $f)
2441 $LFS hsm_archive $f || error "could not archive file"
2442 wait_request_state $fid ARCHIVE SUCCEED
2444 # set a long grace_delay vs short loop_period
2445 local orig_loop_period=$(get_hsm_param loop_period)
2446 local orig_grace_delay=$(get_hsm_param grace_delay)
2447 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2448 set_hsm_param loop_period 10
2449 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2450 set_hsm_param grace_delay 100
2452 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2453 set_hsm_param remove_archive_on_last_unlink 1
2455 multiop_bg_pause $f O_c || error "multiop failed"
2462 wait_request_state $fid REMOVE SUCCEED
2464 client_up || client_up || true
2466 kill -USR1 $MULTIPID
2467 wait $MULTIPID || error "multiop close failed"
2469 run_test 26d "RAoLU when Client eviction"
2472 # test needs a running copytool
2475 create_archive_file $tdir/$tfile
2476 local f=$DIR/$tdir/$tfile
2477 copytool import $tdir/$tfile $f
2478 local fid=$(path2fid $f)
2482 [[ $? != 0 ]] || error "Remove of a released file should fail"
2484 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2487 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(create_empty_file "$f")
2493 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2494 wait_request_state $fid ARCHIVE SUCCEED
2499 [[ $? != 0 ]] || error "Remove of a released file should fail"
2501 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2504 # test needs a running copytool
2507 local f=$DIR/$tdir/$tfile
2508 local fid=$(create_empty_file "$f")
2510 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2511 wait_request_state $fid ARCHIVE SUCCEED
2520 wait_request_state $fid REMOVE SUCCEED
2522 run_test 28 "Concurrent archive/file remove"
2525 # Tests --mntpath and --archive options
2528 copytool setup -m "$MOUNT" -a $archive_id
2530 # Bad archive number
2531 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2532 grep "Invalid argument" ||
2533 error "unexpected hsm_remove failure (1)"
2535 # mntpath is present but file is given
2536 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2537 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2538 error "unexpected hsm_remove failure (2)"
2540 run_test 29a "Tests --mntpath and --archive options"
2543 # test needs a running copytool
2546 local f=$DIR/$tdir/$tfile
2547 local fid=$(create_small_file $f)
2549 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2550 wait_request_state $fid ARCHIVE SUCCEED
2554 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2555 wait_request_state $fid REMOVE SUCCEED
2557 run_test 29b "Archive/delete/remove by FID from the archive."
2560 # test needs a running copytool
2563 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2564 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2565 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2567 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2568 wait_request_state $fid1 ARCHIVE SUCCEED
2569 wait_request_state $fid2 ARCHIVE SUCCEED
2570 wait_request_state $fid3 ARCHIVE SUCCEED
2572 rm -f $DIR/$tdir/$tfile-[1-3]
2574 echo $fid1 > $DIR/$tdir/list
2575 echo $fid2 >> $DIR/$tdir/list
2576 echo $fid3 >> $DIR/$tdir/list
2578 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2579 --filelist $DIR/$tdir/list
2580 wait_request_state $fid1 REMOVE SUCCEED
2581 wait_request_state $fid2 REMOVE SUCCEED
2582 wait_request_state $fid3 REMOVE SUCCEED
2584 run_test 29c "Archive/delete/remove by FID, using a file list."
2587 # test needs more than one CT
2588 needclients 3 || return 0
2594 # start all of the copytools
2595 for n in $(seq $AGTCOUNT); do
2596 copytool setup -f agt$n -a $n
2600 file=$DIR/$tdir/$tfile
2601 fid=$(create_small_file $file)
2603 $LFS hsm_archive $file
2604 wait_request_state $fid ARCHIVE SUCCEED
2605 check_hsm_flags $file "0x00000009"
2609 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2610 error "cannot hsm_remove '$fid'"
2612 # give time for CDT to handle remove request and create broadcasted
2615 # remove request has been broadcasted ?
2616 local cnt=$(get_request_count $fid REMOVE)
2617 # broadcasted requests + original
2618 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2619 error "remove not broadcasted to all CTs"
2621 # give time for CDT and CTs to handle broadcasted
2622 wait_for_loop_period
2624 # each agent serves one different archive_id, so broadcasted
2625 # hsm_remove request should only succeed once and fail at all others
2629 for n in $(seq $AGTCOUNT); do
2630 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2631 $HSM_PARAM.actions | awk \
2632 '/'$fid'.*action=REMOVE archive#='$n'/ \
2633 {print \\\$13}' | cut -f2 -d=")
2634 if [[ "$res" == "SUCCEED" ]]; then
2636 elif [[ "$res" == "FAILED" ]]; then
2641 [[ $scnt -eq 1 ]] ||
2642 error "one and only CT should have removed successfully"
2644 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2645 error "all but one CT should have failed to remove"
2647 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2648 "request to be sent once for each registered archive_id"
2651 # restore at exec cannot work on agent node (because of Linux kernel
2652 # protection of executables)
2653 needclients 2 || return 0
2655 # test needs a running copytool
2659 copy2archive /bin/true $tdir/$tfile
2661 local f=$DIR/$tdir/true
2662 copytool import $tdir/$tfile $f
2664 local fid=$(path2fid $f)
2666 stack_trap "cdt_clear_no_retry" EXIT
2667 # set no retry action mode
2674 [[ $st == 0 ]] || error "Failed to exec a released file"
2676 run_test 30a "Restore at exec (import case)"
2679 # restore at exec cannot work on agent node (because of Linux kernel
2680 # protection of executables)
2681 needclients 2 || return 0
2683 # test needs a running copytool
2687 local f=$DIR/$tdir/true
2688 local fid=$(copy_file /bin/true $f)
2690 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2691 wait_request_state $fid ARCHIVE SUCCEED
2695 stack_trap cdt_clear_no_retry EXIT
2696 # set no retry action mode
2704 [[ $st == 0 ]] || error "Failed to exec a released file"
2706 run_test 30b "Restore at exec (release case)"
2709 needclients 2 || return 0
2711 # test needs a running copytool
2715 local f=$DIR/$tdir/SLEEP
2716 local slp_sum1=$(md5sum /bin/sleep)
2717 local fid=$(copy_file /bin/sleep $f)
2719 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2720 wait_request_state $fid ARCHIVE SUCCEED
2722 check_hsm_flags $f "0x0000000d"
2724 stack_trap cdt_clear_no_retry EXIT
2725 # set no retry action mode
2728 do_node $CLIENT2 "$f 10" &
2732 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2734 [[ $? == 0 ]] || error "Execution failed during run"
2736 if [[ $? != 0 ]]; then
2737 local slp_sum2=$(md5sum /bin/sleep)
2738 # in case sleep file is modified during the test
2739 [[ $slp_sum1 == $slp_sum2 ]] &&
2740 error "Binary overwritten during exec"
2743 check_hsm_flags $f "0x00000009"
2745 run_test 30c "Update during exec of released file must fail"
2747 restore_and_check_size() {
2750 local s=$(stat -c "%s" $f)
2752 local st=$(get_hsm_flags $f)
2756 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2758 n=$(stat -c "%s" $f)
2759 # we echo in both cases to show stat is not hang
2760 if [[ $n != $s ]]; then
2761 echo "size seen is $n != $s"
2764 echo "size seen is right: $n == $s"
2768 st=$(get_hsm_flags $f)
2770 if [[ "$st" = "0x00000009" ]]; then
2773 echo " restore is too long"
2774 wait_request_state $fid RESTORE SUCCEED
2780 # test needs a running copytool
2783 create_archive_file $tdir/$tfile
2784 local f=$DIR/$tdir/$tfile
2785 copytool import $tdir/$tfile $f
2786 local fid=$($LFS path2fid $f)
2789 restore_and_check_size $f $fid
2792 [[ $err -eq 0 ]] || error "File size changed during restore"
2794 run_test 31a "Import a large file and check size during restore"
2798 # test needs a running copytool
2801 local f=$DIR/$tdir/$tfile
2802 local fid=$(create_file "$f" 1MB 39)
2804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2805 wait_request_state $fid ARCHIVE SUCCEED
2808 restore_and_check_size $f $fid
2811 [[ $err -eq 0 ]] || error "File size changed during restore"
2813 run_test 31b "Restore a large unaligned file and check size during restore"
2816 # test needs a running copytool
2819 local f=$DIR/$tdir/$tfile
2820 local fid=$(create_file "$f" 1M 39)
2822 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2823 wait_request_state $fid ARCHIVE SUCCEED
2826 restore_and_check_size $f $fid
2829 [[ $err -eq 0 ]] || error "File size changed during restore"
2831 run_test 31c "Restore a large aligned file and check size during restore"
2834 local f=$DIR/$tdir/$tfile
2835 local fid=$(create_empty_file "$f")
2839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2840 wait_request_state $fid ARCHIVE SUCCEED
2843 # Prevent restore from completing
2847 md5sum $f >/dev/null &
2850 wait_request_state $fid RESTORE STARTED
2855 # Check restore trigger process was killed
2857 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2859 run_test 33 "Kill a restore waiting process"
2862 # test needs a running copytool
2865 local f=$DIR/$tdir/$tfile
2866 local fid=$(create_empty_file "$f")
2868 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2869 wait_request_state $fid ARCHIVE SUCCEED
2872 # Prevent restore from completing
2875 md5sum $f >/dev/null &
2878 wait_request_state $fid RESTORE STARTED
2880 # rm must not block during restore
2881 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2884 wait_request_state $fid RESTORE SUCCEED
2886 # Check md5sum pgm finished
2887 kill -0 $pid && error "Restore initiatior still running"
2888 wait $pid || error "Restore initiator failed with $?"
2890 # Check the file was actually deleted
2891 [ ! -f "$f" ] || error "$f was not deleted"
2893 run_test 34 "Remove file during restore"
2896 # test needs a running copytool
2899 local f=$DIR/$tdir/$tfile
2900 local f1=$DIR/$tdir/$tfile-1
2901 local fid=$(create_empty_file "$f")
2902 local fid1=$(copy_file /etc/passwd $f1)
2904 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2905 wait_request_state $fid ARCHIVE SUCCEED
2908 # Prevent restore from completing
2911 md5sum $f >/dev/null &
2914 wait_request_state $fid RESTORE STARTED
2916 # mv must not block during restore
2917 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2920 wait_request_state $fid RESTORE SUCCEED
2922 # Check md5sum pgm finished
2923 kill -0 $pid && error "Restore initiatior still running"
2924 wait $pid || error "Restore initiator failed with $?"
2926 local fid2=$(path2fid $f)
2927 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2929 run_test 35 "Overwrite file during restore"
2932 # test needs a running copytool
2935 local f=$DIR/$tdir/$tfile
2936 local fid=$(create_empty_file "$f")
2938 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2939 wait_request_state $fid ARCHIVE SUCCEED
2942 # Prevent restore from completing
2945 md5sum $f >/dev/null &
2948 wait_request_state $fid RESTORE STARTED
2950 # mv must not block during restore
2951 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2952 error "mv '$f' '$f.new' failed with rc=$?"
2955 wait_request_state $fid RESTORE SUCCEED
2957 # Check md5sum pgm finished
2958 kill -0 $pid && error "Restore initiator is still running"
2959 wait $pid || error "Restore initiator failed with $?"
2961 run_test 36 "Move file during restore"
2964 # LU-5683: check that an archived dirty file can be rearchived.
2967 local f=$DIR/$tdir/$tfile
2970 fid=$(create_small_file $f) || error "cannot create small file"
2972 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2973 wait_request_state $fid ARCHIVE SUCCEED
2974 $LFS hsm_release $f || error "cannot release $f"
2976 # Allow previous archive request to expire from the actions log.
2977 wait_for_grace_delay
2980 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2982 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2983 wait_request_state $fid ARCHIVE SUCCEED
2985 run_test 37 "re-archive a dirty file"
2992 for n in $(seq 1 $count); do
2993 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2995 echo "$count archive requests submitted"
2999 local stream_count=4
3000 local file_count=100
3002 local f=$DIR/$tdir/$tfile
3006 local max_requests=$(get_hsm_param max_requests)
3008 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3009 # Increase the number of HSM request that can be performed in
3010 # parallel. With the coordinator running once per second, this
3011 # also limits the number of requests per seconds that can be
3012 # performed, so we pick a decent number. But we also need to keep
3013 # that number low because the copytool has no rate limit and will
3014 # fail some requests if if gets too many at once.
3015 set_hsm_param max_requests 300
3017 for i in $(seq 1 $file_count); do
3018 for p in $(seq 1 $stream_count); do
3019 fid=$(copy_file /etc/hosts $f.$p.$i)
3025 # to be sure wait_all_done will not be mislead by previous tests
3027 wait_for_grace_delay
3029 # start archive streams in background (archive files in parallel)
3030 for p in $(seq 1 $stream_count); do
3031 multi_archive $f.$p $file_count &
3034 echo -n "Wait for all requests being enqueued..."
3039 run_test 40 "Parallel archive requests"
3042 # test needs a running copytool
3046 local f=$DIR/$tdir/$tfile
3047 local fid=$(create_small_file $f)
3049 $LFS hsm_archive $f || error "could not archive file"
3050 wait_request_state $fid ARCHIVE SUCCEED
3051 check_hsm_flags $f "0x00000009"
3053 multiop_bg_pause $f O_c || error "multiop failed"
3057 client_up || client_up || true
3059 kill -USR1 $MULTIPID
3060 wait $MULTIPID || error "multiop close failed"
3062 check_hsm_flags $f "0x0000000b"
3064 run_test 52 "Opened for write file on an evicted client should be set dirty"
3067 # test needs a running copytool
3071 local f=$DIR/$tdir/$tfile
3072 local fid=$(create_small_file $f)
3074 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3075 error "could not archive file"
3076 wait_request_state $fid ARCHIVE SUCCEED
3077 check_hsm_flags $f "0x00000009"
3079 multiop_bg_pause $f o_c || error "multiop failed"
3083 client_up || client_up || true
3085 kill -USR1 $MULTIPID
3086 wait $MULTIPID || error "multiop close failed"
3088 check_hsm_flags $f "0x00000009"
3090 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3093 local f=$DIR/$tdir/$tfile
3094 local fid=$(create_file "$f" 1MB 39)
3098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3099 error "could not archive file"
3100 wait_request_state $fid ARCHIVE STARTED
3102 check_hsm_flags $f "0x00000001"
3104 stack_trap "cdt_clear_no_retry" EXIT
3105 # Avoid coordinator resending this request as soon it has failed.
3110 wait_request_state $fid ARCHIVE FAILED
3112 check_hsm_flags $f "0x00000003"
3114 run_test 54 "Write during an archive cancels it"
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.
3132 $TRUNCATE $f 1024 || error "truncate failed"
3134 wait_request_state $fid ARCHIVE FAILED
3136 check_hsm_flags $f "0x00000003"
3138 run_test 55 "Truncate 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 # Change metadata and sync to be sure we are not changing only
3157 wait_request_state $fid ARCHIVE SUCCEED
3159 check_hsm_flags $f "0x00000009"
3161 run_test 56 "Setattr during an archive is ok"
3164 # Need one client for I/O, one for request
3165 needclients 2 || return 0
3167 # test needs a running copytool
3171 local f=$DIR/$tdir/test_archive_remote
3172 # Create a file on a remote node
3173 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3174 "count=2 conv=fsync"
3177 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3178 error "hsm_archive failed"
3179 local fid=$(path2fid $f)
3180 wait_request_state $fid ARCHIVE SUCCEED
3182 # Release and implicit restore it
3183 do_node $CLIENT2 "$LFS hsm_release $f" ||
3184 error "hsm_release failed"
3185 do_node $CLIENT2 "md5sum $f" ||
3186 error "hsm_restore failed"
3188 wait_request_state $fid RESTORE SUCCEED
3190 run_test 57 "Archive a file with dirty cache on another node"
3192 truncate_released_file() {
3196 local sz=$(stat -c %s $src_file)
3197 local f=$DIR/$tdir/$tfile
3198 local fid=$(copy_file $1 $f)
3202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3203 error "could not archive file"
3204 wait_request_state $fid ARCHIVE SUCCEED
3206 $LFS hsm_release $f || error "could not release file"
3208 $TRUNCATE $f $trunc_to || error "truncate failed"
3211 local sz1=$(stat -c %s $f)
3212 [[ $sz1 == $trunc_to ]] ||
3213 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3216 check_hsm_flags $f "0x0000000b"
3218 local state=$(get_request_state $fid RESTORE)
3219 [[ "$state" == "SUCCEED" ]] ||
3220 error "truncate $sz does not trig restore, state = $state"
3222 $TRUNCATE $ref $trunc_to
3223 cmp $ref $f || error "file data wrong after truncate"
3229 # test needs a running copytool
3234 local sz=$(stat -c %s /etc/passwd)
3236 echo "truncate up from $sz to $((sz*2))"
3237 truncate_released_file /etc/passwd $((sz*2))
3239 echo "truncate down from $sz to $((sz/2))"
3240 truncate_released_file /etc/passwd $((sz/2))
3242 echo "truncate to 0"
3243 truncate_released_file /etc/passwd 0
3245 run_test 58 "Truncate a released file will trigger restore"
3249 local server_version=$(lustre_version_code $SINGLEMDS)
3250 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3251 skip "Need MDS version at least 2.7.63" && return
3254 $MCREATE $DIR/$tfile || error "mcreate failed"
3255 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3256 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3257 fid=$(path2fid $DIR/$tfile)
3258 wait_request_state $fid ARCHIVE SUCCEED
3259 $LFS hsm_release $DIR/$tfile || error "release failed"
3261 run_test 59 "Release stripeless file with non-zero size"
3264 # This test validates the fix for LU-4512. Ensure that the -u
3265 # option changes the progress reporting interval from the
3266 # default (30 seconds) to the user-specified interval.
3267 local f=$DIR/$tdir/$tfile
3268 local fid=$(create_file "$f" 1M 10)
3271 local progress_timeout=$((interval * 4))
3272 copytool setup -b 1 --update-interval $interval
3275 local mdt=${MDT_PREFIX}${mdtidx}
3276 local mds=mds$((mdtidx + 1))
3278 # Wait for copytool to register
3279 wait_update_facet $mds \
3280 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3281 uuid 100 || error "coyptool failed to register with $mdt"
3283 local start_at=$(date +%s)
3284 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3285 error "could not archive file"
3287 local agent=$(facet_active_host $SINGLEAGT)
3288 local logfile=$(copytool_logfile $SINGLEAGT)
3290 wait_update $agent \
3291 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3292 error "copytool failed to start"
3294 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3295 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3301 echo -n "Expecting a progress update within $progress_timeout seconds... "
3303 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3304 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3305 echo "$RESULT bytes copied in $WAIT seconds."
3307 elif [ $WAIT -ge $progress_timeout ]; then
3308 error "Timed out waiting for progress update!"
3311 WAIT=$((WAIT + sleep))
3315 local finish_at=$(date +%s)
3316 local elapsed=$((finish_at - start_at))
3318 # Ensure that the progress update occurred within the expected window.
3319 if [ $elapsed -lt $((interval - 1)) ]; then
3320 error "Expected progress update after at least $interval seconds"
3323 echo "Wait for on going archive hsm action to complete"
3324 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3325 echo "File archiving not completed even after 10 secs"
3327 run_test 60 "Changing progress update interval from default"
3330 # test needs a running copytool
3334 local f=$DIR/$tdir/$tfile
3335 local fid=$(copy_file /etc/passwd $f)
3337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3340 wait_request_state $fid ARCHIVE FAILED
3342 run_test 61 "Waiting archive of a removed file should fail"
3345 # test needs a new running copytool
3346 stack_trap copytool_monitor_cleanup EXIT
3347 copytool_monitor_setup
3348 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3350 # Wait for the copytool to register.
3351 wait_update --verbose $(facet_active_host mds1) \
3352 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3354 error "copytool failed to register with MDT0000"
3357 wait_copytools || error "Copytools failed to stop"
3359 local REGISTER_EVENT
3360 local UNREGISTER_EVENT
3361 while read event; do
3362 local parsed=$(parse_json_event "$event")
3363 if [ -z "$parsed" ]; then
3364 error "Copytool sent malformed event: $event"
3368 if [ $event_type == "REGISTER" ]; then
3369 REGISTER_EVENT=$event
3370 elif [ $event_type == "UNREGISTER" ]; then
3371 UNREGISTER_EVENT=$event
3373 done < <(echo $"$(get_copytool_event_log)")
3375 if [ -z "$REGISTER_EVENT" ]; then
3376 error "Copytool failed to send register event to FIFO"
3379 if [ -z "$UNREGISTER_EVENT" ]; then
3380 error "Copytool failed to send unregister event to FIFO"
3383 echo "Register/Unregister events look OK."
3385 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3388 # Bump progress interval for livelier events.
3391 # test needs a new running copytool
3392 stack_trap copytool_monitor_cleanup EXIT
3393 copytool_monitor_setup
3394 copytool setup --update-interval $interval --event-fifo \
3395 "$HSMTOOL_MONITOR_DIR/fifo"
3397 stack_trap "cdt_clear_no_retry" EXIT
3398 # Just start and stop the copytool to generate events.
3401 local f=$DIR/$tdir/$tfile
3402 local fid=$(create_small_file "$f")
3404 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3405 error "could not archive file"
3406 wait_request_state $fid ARCHIVE SUCCEED
3408 local expected_fields="event_time data_fid source_fid"
3409 expected_fields+=" total_bytes current_bytes"
3412 [ARCHIVE_START]=false
3413 [ARCHIVE_FINISH]=false
3414 [ARCHIVE_RUNNING]=false
3416 while read event; do
3417 # Make sure we're not getting anything from previous events.
3418 for field in $expected_fields; do
3422 local parsed=$(parse_json_event "$event")
3423 if [ -z "$parsed" ]; then
3424 error "Copytool sent malformed event: $event"
3428 events["$event_type"]=true
3430 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3432 # Do some simple checking of the progress update events.
3433 for expected_field in $expected_fields; do
3434 if [ -z ${!expected_field+x} ]; then
3435 error "Missing $expected_field field in event"
3439 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3441 # These should be identical throughout an archive operation
3442 [ $source_fid == $data_fid ] ||
3443 error "Expected source_fid to equal data_fid"
3444 done < <(echo $"$(get_copytool_event_log)")
3446 # Check we received every type of events we were expecting
3447 for event in "${!events[@]}"; do
3448 ${events["$event"]} ||
3449 error "Copytool failed to send '$event' event to FIFO"
3452 echo "Archive events look OK."
3454 run_test 71 "Copytool logs JSON archive events to FIFO"
3457 # Bump progress interval for livelier events.
3460 # test needs a new running copytool
3461 stack_trap copytool_monitor_cleanup EXIT
3462 copytool_monitor_setup
3463 copytool setup --update-interval $interval --event-fifo \
3464 "$HSMTOOL_MONITOR_DIR/fifo"
3465 local test_file=$HSMTOOL_MONITOR_DIR/file
3467 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3469 do_facet $SINGLEAGT "$cmd" ||
3470 error "cannot create $test_file on $SINGLEAGT"
3471 copy2archive $test_file $tdir/$tfile
3474 local f=$DIR/$tdir/$tfile
3475 copytool import $tdir/$tfile $f
3476 f=$DIR2/$tdir/$tfile
3477 echo "Verifying released state: "
3478 check_hsm_flags $f "0x0000000d"
3480 local fid=$(path2fid $f)
3482 wait_request_state $fid RESTORE SUCCEED
3484 local expected_fields="event_time data_fid source_fid"
3485 expected_fields+=" total_bytes current_bytes"
3489 while read event; do
3490 # Make sure we're not getting anything from previous events.
3491 for field in $expected_fields; do
3495 local parsed=$(parse_json_event "$event")
3496 if [ -z "$parsed" ]; then
3497 error "Copytool sent malformed event: $event"
3501 if [ $event_type == "RESTORE_START" ]; then
3503 if [ $source_fid != $data_fid ]; then
3504 error "source_fid should == data_fid at start"
3507 elif [ $event_type == "RESTORE_FINISH" ]; then
3509 if [ $source_fid != $data_fid ]; then
3510 error "source_fid should == data_fid at finish"
3513 elif [ $event_type != "RESTORE_RUNNING" ]; then
3517 # Do some simple checking of the progress update events.
3518 for expected_field in $expected_fields; do
3519 if [ -z ${!expected_field+x} ]; then
3520 error "Missing $expected_field field in event"
3524 if [ $total_bytes -eq 0 ]; then
3525 error "Expected total_bytes to be > 0"
3528 # When a restore starts out, the data fid is the same as the
3529 # source fid. After the restore has gotten going, we learn
3530 # the new data fid. Once the restore has finished, the source
3531 # fid is set to the new data fid.
3533 # We test this because some monitoring software may depend on
3534 # this behavior. If it changes, then the consumers of these
3535 # events may need to be modified.
3536 if [ $source_fid == $data_fid ]; then
3537 error "source_fid should != data_fid during restore"
3539 done < <(echo $"$(get_copytool_event_log)")
3541 if [ -z "$START_EVENT" ]; then
3542 error "Copytool failed to send restore start event to FIFO"
3545 if [ -z "$FINISH_EVENT" ]; then
3546 error "Copytool failed to send restore finish event to FIFO"
3549 echo "Restore events look OK."
3551 run_test 72 "Copytool logs JSON restore events to FIFO"
3554 file_count=51 # Max number of files constrained by LNET message size
3555 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3556 local f=$DIR/$tdir/$tfile
3557 local FILELIST=/tmp/filelist.txt
3561 for i in $(seq 1 $file_count); do
3562 fid=$(copy_file /etc/hosts $f.$i)
3563 echo $f.$i >> $FILELIST
3567 # to be sure wait_all_done will not be mislead by previous tests
3569 wait_for_grace_delay
3570 $LFS hsm_archive --filelist $FILELIST ||
3571 error "cannot archive a file list"
3573 $LFS hsm_release --filelist $FILELIST ||
3574 error "cannot release a file list"
3575 $LFS hsm_restore --filelist $FILELIST ||
3576 error "cannot restore a file list"
3579 run_test 90 "Archive/restore a file list"
3581 double_verify_reset_hsm_param() {
3583 echo "Testing $HSM_PARAM.$p"
3584 local val=$(get_hsm_param $p)
3586 local val2=$(($val * 2))
3587 set_hsm_param $p $val2
3588 val=$(get_hsm_param $p)
3589 [[ $val == $val2 ]] ||
3590 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3591 echo "Set $p to 0 must failed"
3595 set_hsm_param $p $save
3597 if [[ $rc == 0 ]]; then
3598 error "we must not be able to set $HSM_PARAM.$p to 0"
3603 double_verify_reset_hsm_param loop_period
3604 double_verify_reset_hsm_param grace_delay
3605 double_verify_reset_hsm_param active_request_timeout
3606 double_verify_reset_hsm_param max_requests
3607 double_verify_reset_hsm_param default_archive_id
3609 run_test 100 "Set coordinator /proc tunables"
3616 run_test 102 "Verify coordinator control"
3619 # test needs a running copytool
3626 for i in $(seq 1 20); do
3627 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3629 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3633 echo "Current requests"
3634 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3635 $HSM_PARAM.actions |\
3636 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3638 [[ -z "$res" ]] || error "Some request have not been canceled"
3640 run_test 103 "Purge all requests"
3645 local f=$DIR/$tdir/$tfile
3646 local fid=$(create_empty_file "$f")
3648 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3649 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3650 $HSM_PARAM.actions |\
3651 grep $fid | cut -f16 -d=")
3653 [[ "$data1" == "$DATAHEX" ]] ||
3654 error "Data field in records is ($data1) and not ($DATAHEX)"
3658 run_test 104 "Copy tool data field"
3661 local max_requests=$(get_hsm_param max_requests)
3665 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3666 set_hsm_param max_requests 300
3669 for i in $(seq -w 1 10); do
3670 cp /etc/passwd $DIR/$tdir/$i
3671 $LFS hsm_archive $DIR/$tdir/$i
3673 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3674 $HSM_PARAM.actions |\
3675 grep WAITING | wc -l")
3679 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3680 $HSM_PARAM.actions |\
3681 grep WAITING | wc -l")
3684 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3685 error "Requests count after shutdown $reqcnt2 != "\
3686 "before shutdown $reqcnt1"
3688 run_test 105 "Restart of coordinator"
3691 # test needs a running copytool
3694 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3696 check_agent_registered $uuid
3698 search_copytools || error "No copytool found"
3701 wait_copytools || error "Copytool failed to stop"
3703 check_agent_unregistered $uuid
3706 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3707 check_agent_registered $uuid
3709 run_test 106 "Copytool register/unregister"
3712 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3714 # test needs a running copytool
3716 # create and archive file
3718 local f1=$DIR/$tdir/$tfile
3719 local fid=$(copy_file /etc/passwd $f1)
3720 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3721 wait_request_state $fid ARCHIVE SUCCEED
3722 # shutdown and restart MDS
3724 # check the copytool still gets messages from MDT
3725 local f2=$DIR/$tdir/2
3726 local fid=$(copy_file /etc/passwd $f2)
3727 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3728 # main check of this sanity: this request MUST succeed
3729 wait_request_state $fid ARCHIVE SUCCEED
3731 run_test 107 "Copytool re-register after MDS restart"
3733 policy_set_and_test()
3737 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3738 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3739 [[ "$policy" == "$target" ]] ||
3740 error "Wrong policy after '$change': '$policy' != '$target'"
3744 # to force default policy setting if error
3745 CDT_POLICY_HAD_CHANGED=true
3747 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3748 local default="NonBlockingRestore [NoRetryAction]"
3749 [[ "$policy" == "$default" ]] ||
3750 error "default policy has changed,"\
3751 " '$policy' != '$default' update the test"
3752 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3753 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3754 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3755 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3756 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3757 # useless bacause we know but safer for futur changes to use real value
3758 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3759 echo "Next set_param must failed"
3760 policy_set_and_test "wrong" "$policy"
3763 echo "Back to default policy"
3764 cdt_set_sanity_policy
3766 run_test 109 "Policy display/change"
3769 # test needs a running copytool
3774 copy2archive /etc/passwd $tdir/$tfile
3776 local f=$DIR/$tdir/$tfile
3777 copytool import $tdir/$tfile $f
3778 local fid=$(path2fid $f)
3780 cdt_set_non_blocking_restore
3785 wait_request_state $fid RESTORE SUCCEED
3786 cdt_clear_non_blocking_restore
3790 error "md5sum returns $st != 1, "\
3791 "should also perror ENODATA (No data available)"
3793 run_test 110a "Non blocking restore policy (import case)"
3796 # test needs a running copytool
3800 local f=$DIR/$tdir/$tfile
3801 local fid=$(copy_file /etc/passwd $f)
3802 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3803 wait_request_state $fid ARCHIVE SUCCEED
3806 cdt_set_non_blocking_restore
3811 wait_request_state $fid RESTORE SUCCEED
3812 cdt_clear_non_blocking_restore
3816 error "md5sum returns $st != 1, "\
3817 "should also perror ENODATA (No data available)"
3819 run_test 110b "Non blocking restore policy (release case)"
3822 # test needs a running copytool
3826 copy2archive /etc/passwd $tdir/$tfile
3828 local f=$DIR/$tdir/$tfile
3830 copytool import $tdir/$tfile $f
3831 local fid=$(path2fid $f)
3835 copytool_remove_backend $fid
3838 wait_request_state $fid RESTORE FAILED
3845 [[ $st == 0 ]] || error "Restore does not failed"
3847 run_test 111a "No retry policy (import case), restore will error"\
3848 " (No such file or directory)"
3851 # test needs a running copytool
3855 local f=$DIR/$tdir/$tfile
3856 local fid=$(copy_file /etc/passwd $f)
3857 stack_trap cdt_clear_no_retry EXIT
3859 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3860 wait_request_state $fid ARCHIVE SUCCEED
3863 copytool_remove_backend $fid
3866 wait_request_state $fid RESTORE FAILED
3870 [[ $st == 0 ]] || error "Restore does not failed"
3872 run_test 111b "No retry policy (release case), restore will error"\
3873 " (No such file or directory)"
3876 # test needs a running copytool
3880 local f=$DIR/$tdir/$tfile
3881 local fid=$(copy_file /etc/passwd $f)
3883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3884 local l=$($LFS hsm_action $f)
3886 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3889 wait_request_state $fid ARCHIVE SUCCEED
3892 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3894 run_test 112 "State of recorded request"
3897 local f=$DIR/$tdir/$tfile
3898 local fid=$(create_empty_file "$f")
3902 # Prevent archive from completing
3905 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3906 # wait archive to register at CDT
3907 wait_request_state $fid ARCHIVE STARTED
3909 # Cancel the archive
3910 $LFS hsm_cancel "$f"
3912 wait_request_state $fid ARCHIVE CANCELED
3915 wait_request_state $fid CANCEL SUCCEED
3917 run_test 200 "Register/Cancel archive"
3920 # test needs a running copytool
3923 local f=$DIR/$tdir/$tfile
3924 create_archive_file $tdir/$tfile
3925 copytool import $tdir/$tfile $f
3926 local fid=$(path2fid $f)
3928 # test with cdt on is made in test_222
3931 # wait restore to register at CDT
3932 wait_request_state $fid RESTORE WAITING
3935 wait_request_state $fid RESTORE CANCELED
3936 wait_request_state $fid CANCEL SUCCEED
3938 run_test 201 "Register/Cancel restore"
3941 local f=$DIR/$tdir/$tfile
3942 local fid=$(create_empty_file "$f")
3944 # test needs a running copytool
3947 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3948 wait_request_state $fid ARCHIVE SUCCEED
3952 # wait remove to register at CDT
3953 wait_request_state $fid REMOVE STARTED
3956 wait_request_state $fid REMOVE CANCELED
3958 run_test 202 "Register/Cancel remove"
3960 test_220A() { # was test_220
3961 # test needs a running copytool
3966 local f=$DIR/$tdir/$tfile
3967 local fid=$(copy_file /etc/passwd $f)
3971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3972 wait_request_state $fid ARCHIVE SUCCEED
3974 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3975 error "The expected changelog was not emitted"
3977 run_test 220A "Changelog for archive"
3980 # test needs a running copytool
3985 local f=$DIR/$tdir/$tfile
3986 local fid=$(copy_file /etc/passwd $f)
3990 # block copytool operations to allow for HSM request to be
3991 # submitted and file be unlinked (CDT will find object removed)
3994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3996 # wait request to reach CT
3997 wait_request_state $fid ARCHIVE STARTED
4003 wait_request_state $fid ARCHIVE FAILED
4006 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4007 error "The expected changelog was not emitted"
4009 run_test 220a "Changelog for failed archive"
4012 local f=$DIR/$tdir/$tfile
4013 local fid=$(create_empty_file "$f")
4018 # Prevent archive from completing
4020 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4021 wait_request_state $fid ARCHIVE STARTED
4024 wait_request_state $fid ARCHIVE CANCELED
4027 wait_request_state $fid CANCEL SUCCEED
4029 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4030 error "The expected changelog was not emitted"
4032 run_test 221 "Changelog for archive canceled"
4035 # test needs a running copytool
4039 copy2archive /etc/passwd $tdir/$tfile
4041 local f=$DIR/$tdir/$tfile
4042 copytool import $tdir/$tfile $f
4043 local fid=$(path2fid $f)
4048 wait_request_state $fid RESTORE SUCCEED
4050 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4051 error "The expected changelog was not emitted"
4053 run_test 222a "Changelog for explicit restore"
4056 # test needs a running copytool
4060 local f=$DIR/$tdir/$tfile
4061 local fid=$(copy_file /etc/passwd $f)
4064 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4065 wait_request_state $fid ARCHIVE SUCCEED
4070 wait_request_state $fid RESTORE SUCCEED
4072 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4073 error "The expected changelog was not emitted"
4075 run_test 222b "Changelog for implicit restore"
4078 # test needs a running copytool
4082 copy2archive /etc/passwd $tdir/$tfile
4084 local f=$DIR/$tdir/$tfile
4085 copytool import $tdir/$tfile $f
4086 local fid=$(path2fid $f)
4090 # block copytool operations to allow for HSM request to be
4091 # submitted and file be unlinked (CDT will find object removed)
4096 # wait request to reach CT
4097 wait_request_state $fid RESTORE STARTED
4103 wait_request_state $fid RESTORE FAILED
4106 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4107 error "The expected changelog was not emitted"
4109 run_test 222c "Changelog for failed explicit restore"
4112 # test needs a running copytool
4116 local f=$DIR/$tdir/$tfile
4117 local fid=$(copy_file /etc/passwd $f)
4120 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4121 wait_request_state $fid ARCHIVE SUCCEED
4124 copytool_remove_backend $fid
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 222d "Changelog for failed implicit restore"
4136 # test needs a running copytool
4139 local f=$DIR/$tdir/$tfile
4140 create_archive_file $tdir/$tfile
4144 copytool import $tdir/$tfile $f
4145 local fid=$(path2fid $f)
4148 wait_request_state $fid RESTORE STARTED
4150 wait_request_state $fid RESTORE CANCELED
4151 wait_request_state $fid CANCEL SUCCEED
4153 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4154 error "The expected changelog was not emitted"
4156 run_test 223a "Changelog for restore canceled (import case)"
4159 local f=$DIR/$tdir/$tfile
4160 local fid=$(create_empty_file "$f")
4165 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4166 wait_request_state $fid ARCHIVE SUCCEED
4169 # Prevent restore from completing
4172 wait_request_state $fid RESTORE STARTED
4175 wait_request_state $fid RESTORE CANCELED
4178 wait_request_state $fid CANCEL SUCCEED
4180 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4181 error "The expected changelog was not emitted"
4183 run_test 223b "Changelog for restore canceled (release case)"
4185 test_224A() { # was test_224
4186 # test needs a running copytool
4191 local f=$DIR/$tdir/$tfile
4192 local fid=$(copy_file /etc/passwd $f)
4195 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4196 wait_request_state $fid ARCHIVE SUCCEED
4199 wait_request_state $fid REMOVE SUCCEED
4201 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4202 error "The expected changelog was not emitted"
4204 run_test 224A "Changelog for remove"
4207 # test needs a running copytool
4212 local f=$DIR/$tdir/$tfile
4213 local fid=$(copy_file /etc/passwd $f)
4216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4217 wait_request_state $fid ARCHIVE SUCCEED
4219 copytool_remove_backend $fid
4221 # block copytool operations to allow for HSM request to be
4222 # submitted and file be unlinked (CDT will find object removed)
4227 # wait for request to reach CT
4228 wait_request_state $fid REMOVE STARTED
4234 wait_request_state $fid REMOVE FAILED
4236 # HE_REMOVE|ENOENT=0x202
4237 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4238 error "The expected changelog was not emitted"
4240 run_test 224a "Changelog for failed remove"
4243 # test is not usable because remove request is too fast
4244 # so it is always finished before cancel can be done ...
4245 echo "Test disabled"
4248 # test needs a running copytool
4251 local f=$DIR/$tdir/$tfile
4252 local fid=$(create_empty_file "$f")
4255 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4256 wait_request_state $fid ARCHIVE SUCCEED
4258 # Prevent restore from completing
4263 wait_request_state $fid REMOVE CANCELED
4266 wait_request_state $fid CANCEL SUCCEED
4268 changelog_find -type HSM -target-fid $fid -flags 0x27d
4269 error "The expected changelog was not emitted"
4271 run_test 225 "Changelog for remove canceled"
4274 # test needs a running copytool
4279 local f1=$DIR/$tdir/$tfile-1
4280 local f2=$DIR/$tdir/$tfile-2
4281 local f3=$DIR/$tdir/$tfile-3
4282 local fid1=$(copy_file /etc/passwd $f1)
4283 local fid2=$(copy_file /etc/passwd $f2)
4284 copy_file /etc/passwd $f3
4287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4288 wait_request_state $fid1 ARCHIVE SUCCEED
4290 $LFS hsm_archive $f2
4291 wait_request_state $fid2 ARCHIVE SUCCEED
4293 rm $f1 || error "rm $f1 failed"
4296 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4297 error "The expected changelog was not emitted"
4299 mv $f3 $f2 || error "mv $f3 $f2 failed"
4301 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4302 error "The expected changelog was not emitted"
4304 run_test 226 "changelog for last rm/mv with exiting archive"
4306 # This is just a utility function to clarify what test_227 does
4311 "$LFS" "$action" --$flag "$file" ||
4312 error "Cannot ${action#hsm_} $flag on '$file'"
4314 # Only one changelog should be produced
4315 local entries="$(changelog_find -type HSM -target-fid $fid)"
4316 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4317 error "lfs $action --$flag '$file' produced more than one" \
4320 # Parse the last changelog record
4321 local entry="$(tail -n 1 <<< "$entries")"
4322 eval local -A changelog=$(changelog2array $entry)
4324 # Also check the flags match what is expected
4325 [[ ${changelog[flags]} == $target ]] ||
4326 error "Changelog flag is '${changelog[flags]}', not $target"
4330 local file="$DIR/$tdir/$tfile"
4331 local fid=$(create_empty_file "$file")
4336 for flag in norelease noarchive exists archived lost; do
4337 if [ "$flag" == lost ]; then
4338 # The flag "lost" only works on an archived file
4339 "$LFS" hsm_set --archived "$file"
4343 action="hsm_set" __test_227
4344 action="hsm_clear" __test_227
4347 run_test 227 "changelog when explicit setting of HSM flags"
4350 # test needs a running copytool
4353 local fid=$(create_small_sync_file $DIR/$tfile)
4354 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4355 wait_request_state $fid ARCHIVE SUCCEED
4357 $LFS hsm_release $DIR/$tfile
4358 check_hsm_flags $DIR/$tfile "0x0000000d"
4360 filefrag $DIR/$tfile | grep " 1 extent found" ||
4361 error "filefrag on released file must return only one extent"
4363 # only newer versions of cp detect sparse files by stat/FIEMAP
4365 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4366 error "copying $DIR/$tfile"
4367 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4369 $LFS hsm_release $DIR/$tfile
4370 check_hsm_flags $DIR/$tfile "0x0000000d"
4372 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4374 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4376 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4377 error "comparing untarred $DIR/$tfile"
4379 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4380 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4382 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4385 # test needs a running copytool
4389 local maxrequest=$(get_hsm_param max_requests)
4390 local rqcnt=$(($maxrequest * 3))
4394 for i in $(seq -w 1 $rqcnt); do
4396 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4398 # we do it in 2 steps, so all requests arrive at the same time
4399 for i in $(seq -w 1 $rqcnt); do
4400 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4405 while [[ $cnt != 0 || $wt != 0 ]]; do
4407 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4408 $HSM_PARAM.actions |\
4409 grep STARTED | grep -v CANCEL | wc -l")
4410 [[ $cnt -le $maxrequest ]] ||
4411 error "$cnt > $maxrequest too many started requests"
4412 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4413 $HSM_PARAM.actions |\
4414 grep WAITING | wc -l")
4415 echo "max=$maxrequest started=$cnt waiting=$wt"
4418 run_test 250 "Coordinator max request"
4421 local f=$DIR/$tdir/$tfile
4422 local fid=$(create_empty_file "$f")
4425 # to have a short test
4426 local old_to=$(get_hsm_param active_request_timeout)
4427 set_hsm_param active_request_timeout 1
4428 # to be sure the cdt will wake up frequently so
4429 # it will be able to cancel the "old" request
4430 local old_loop=$(get_hsm_param loop_period)
4431 set_hsm_param loop_period 1
4436 # Prevent archive from completing
4438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4439 wait_request_state $fid ARCHIVE STARTED
4441 # Let the request timeout
4442 wait_request_state $fid ARCHIVE CANCELED
4444 set_hsm_param active_request_timeout $old_to
4445 set_hsm_param loop_period $old_loop
4447 run_test 251 "Coordinator request timeout"
4450 local f=$DIR/$tdir/$tfile
4451 local fid=$(create_empty_file "$f")
4453 # to have a short test
4454 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4455 set_hsm_param loop_period 1
4459 # Prevent archive from completing
4461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4462 wait_request_state $fid ARCHIVE STARTED
4465 stack_trap "set_hsm_param active_request_timeout \
4466 $(get_hsm_param active_request_timeout)" EXIT
4467 set_hsm_param active_request_timeout 1
4469 wait_request_state $fid ARCHIVE CANCELED
4472 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4476 # test needs a running copytool
4480 local f=$DIR/$tdir/$tfile
4482 dd if=/dev/zero of=$f bs=1MB count=10
4483 local fid=$(path2fid $f)
4485 $LFS hsm_archive $f || error "could not archive file"
4486 wait_request_state $fid ARCHIVE SUCCEED
4488 # clear locks to discard inode data
4489 cancel_lru_locks osc
4491 #define OBD_FAIL_MDC_MERGE 0x807
4492 $LCTL set_param fail_loc=0x807
4494 #expect error here, instead of release with wrong size
4497 if ((rc == 0)); then
4498 file_size=$(stat -c '%s' $f)
4499 if ((file_size != 10485760)); then
4500 error "Wrong file size after hsm_release"
4503 echo "could not release file"
4506 run_test 253 "Check for wrong file size after release"
4510 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4511 skip "need MDS version at least 2.10.56" && return
4513 # Check that the counters are initialized to 0
4515 for request_type in archive restore remove; do
4516 count="$(get_hsm_param ${request_type}_count)" ||
4517 error "Reading ${request_type}_count failed with $?"
4519 [ "$count" -eq 0 ] ||
4520 error "Expected ${request_type}_count to be " \
4524 run_test 254a "Request counters are initialized to zero"
4528 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4529 skip "need MDS version at least 2.10.56" && return
4531 # The number of request to launch (at least 32)
4532 local request_count=$((RANDOM % 32 + 32))
4533 printf "Will launch %i requests of each type\n" "$request_count"
4535 # Launch a copytool to process requests
4538 # Set hsm.max_requests to allow starting all requests at the same time
4540 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4541 set_hsm_param max_requests "$request_count"
4545 for request_type in archive restore remove; do
4546 printf "Checking %s requests\n" "${request_type}"
4547 # Suspend the copytool to give us time to read the proc files
4550 for ((i = 0; i < $request_count; i++)); do
4551 case $request_type in
4553 create_empty_file "$DIR/$tdir/$tfile-$i" \
4557 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4560 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4563 # Give the coordinator 10 seconds to start every request
4565 while get_hsm_param actions | grep -q WAITING; do
4568 [ $timeout -gt 0 ] ||
4569 error "${request_type^} requests took too " \
4573 count="$(get_hsm_param ${request_type}_count)"
4574 [ "$count" -eq "$request_count" ] ||
4575 error "Expected '$request_count' (!= '$count') " \
4576 "active $request_type requests"
4578 # Let the copytool process the requests
4580 # Give it 10 seconds maximum
4582 while get_hsm_param actions | grep -q STARTED; do
4585 [ $timeout -gt 0 ] ||
4586 error "${request_type^} requests took too " \
4590 count="$(get_hsm_param ${request_type}_count)"
4591 [ "$count" -eq 0 ] ||
4592 error "Expected 0 (!= '$count') " \
4593 "active $request_type requests"
4596 run_test 254b "Request counters are correctly incremented and decremented"
4598 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4599 # break in the future because of that.
4602 local -a files=("$DIR/$tdir/$tfile".{0..15})
4605 for file in "${files[@]}"; do
4606 create_small_file "$file"
4609 # Set a few hsm parameters
4611 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4612 set_hsm_param loop_period 1
4614 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4615 set_hsm_param max_requests 3
4619 "$LFS" hsm_archive "${files[0]}"
4620 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4621 "$LFS" hsm_release "${files[0]}"
4625 wait_copytools || error "copytools failed to stop"
4627 # Send several archive requests
4628 for file in "${files[@]:1}"; do
4629 "$LFS" hsm_archive "$file"
4632 # Send one restore request
4633 "$LFS" hsm_restore "${files[0]}"
4638 # Wait for all the requests to complete
4639 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4640 for file in "${files[@]:1}"; do
4641 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4644 # Collect the actions in the order in which the copytool processed them
4646 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4647 "$(copytool_logfile "$SINGLEAGT")")
4650 printf '%s\n' "${actions[@]}"
4653 for action in "${actions[@]:0:3}"; do
4654 [ "$action" == RESTORE ] && return
4657 error "Too many ARCHIVE requests were run before the RESTORE request"
4659 run_test 260a "Restore request have priority over other requests"
4661 # This test is very much tied to the implementation of the current priorisation
4662 # mechanism in the coordinator. It might not make sense to keep it in the future
4665 local -a files=("$DIR/$tdir/$tfile".{0..15})
4668 for file in "${files[@]}"; do
4669 create_small_file "$file"
4672 # Set a few hsm parameters
4674 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4675 set_hsm_param loop_period 1
4677 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4678 set_hsm_param max_requests 3
4681 copytool setup --archive-id 2
4682 "$LFS" hsm_archive --archive 2 "${files[0]}"
4683 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4684 "$LFS" hsm_release "${files[0]}"
4688 wait_copytools || error "copytools failed to stop"
4690 # Send several archive requests
4691 for file in "${files[@]:1}"; do
4692 "$LFS" hsm_archive "$file"
4695 # Send one restore request
4696 "$LFS" hsm_restore "${files[0]}"
4700 copytool setup --archive-id 2
4702 # Wait for all the requests to complete
4703 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4704 for file in "${files[@]:1}"; do
4705 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4708 # Collect the actions in the order in which the copytool processed them
4710 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4711 "$(copytool_logfile "$SINGLEAGT")")
4714 printf '%s\n' "${actions[@]}"
4717 for action in "${actions[@]:0:3}"; do
4718 [ "$action" == RESTORE ] && return
4721 error "Too many ARCHIVE requests were run before the RESTORE request"
4723 run_test 260b "Restore request have priority over other requests"
4725 # This test is very much tied to the implementation of the current priorisation
4726 # mechanism in the coordinator. It might not make sense to keep it in the future
4729 local -a files=("$DIR/$tdir/$tfile".{0..15})
4732 for file in "${files[@]}"; do
4733 create_small_file "$file"
4736 # Set a few hsm parameters
4738 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4739 set_hsm_param loop_period 10
4741 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4742 set_hsm_param max_requests 3
4745 copytool setup --archive-id 2
4746 "$LFS" hsm_archive --archive 2 "${files[0]}"
4747 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4748 "$LFS" hsm_release "${files[0]}"
4752 wait_copytools || error "copytools failed to stop"
4754 "$LFS" hsm_archive "${files[1]}"
4758 copytool setup --archive-id 2
4760 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4762 # Send several archive requests
4763 for file in "${files[@]:2}"; do
4764 "$LFS" hsm_archive "$file"
4767 # Send one restore request
4768 "$LFS" hsm_restore "${files[0]}"
4770 # Wait for all the requests to complete
4771 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4772 for file in "${files[@]:2}"; do
4773 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4776 # Collect the actions in the order in which the copytool processed them
4778 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4779 "$(copytool_logfile "$SINGLEAGT")")
4782 printf '%s\n' "${actions[@]}"
4785 for action in "${actions[@]:0:3}"; do
4786 [ "$action" == RESTORE ] &&
4787 error "Restore requests should not be prioritised" \
4788 "unless the coordinator is doing housekeeping"
4792 run_test 260c "Restore request have priority over other requests"
4795 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4797 # the only way to test ondisk conf is to restart MDS ...
4798 echo "Stop coordinator and remove coordinator state at mount"
4801 # clean on disk conf set by default
4802 cdt_clear_mount_state
4803 cdt_check_state stopped
4805 # check cdt still off after umount/remount
4807 cdt_check_state stopped
4809 echo "Set coordinator start at mount, and start coordinator"
4810 cdt_set_mount_state enabled
4813 cdt_check_state enabled
4815 # check cdt still on after umount/remount
4817 cdt_check_state enabled
4819 # we are back to original state (cdt started at mount)
4821 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4824 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4826 local ai=$(get_hsm_param default_archive_id)
4827 local new=$((ai + 1))
4829 set_hsm_param default_archive_id $new -P
4831 local res=$(get_hsm_param default_archive_id)
4834 set_hsm_param default_archive_id "" "-P -d"
4836 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4838 run_test 301 "HSM tunnable are persistent"
4841 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4843 local ai=$(get_hsm_param default_archive_id)
4844 local new=$((ai + 1))
4849 set_hsm_param default_archive_id $new -P
4852 for mdtno in $(seq 1 $MDSCOUNT); do
4857 cdt_check_state enabled
4859 local res=$(get_hsm_param default_archive_id)
4862 set_hsm_param default_archive_id "" "-P -d"
4864 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4866 run_test 302 "HSM tunnable are persistent when CDT is off"
4869 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4875 local dir_mdt0=$DIR/$tdir/mdt0
4876 local dir_mdt1=$DIR/$tdir/mdt1
4878 # create 1 dir per MDT
4879 stack_trap "rm -rf $dir_mdt0" EXIT
4880 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4881 stack_trap "rm -rf $dir_mdt1" EXIT
4882 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4884 # create 1 file in each MDT
4885 local fid1=$(create_small_file $dir_mdt0/$tfile)
4886 local fid2=$(create_small_file $dir_mdt1/$tfile)
4888 # check that hsm request on mdt0 is sent to the right MDS
4889 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4890 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4891 echo "archive successful on mdt0"
4893 # check that hsm request on mdt1 is sent to the right MDS
4894 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4895 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4896 echo "archive successful on mdt1"
4898 run_test 400 "Single request is sent to the right MDT"
4901 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4907 local dir_mdt0=$DIR/$tdir/mdt0
4908 local dir_mdt1=$DIR/$tdir/mdt1
4910 # create 1 dir per MDT
4911 stack_trap "rm -rf $dir_mdt0" EXIT
4912 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4913 stack_trap "rm -rf $dir_mdt1" EXIT
4914 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4916 # create 1 file in each MDT
4917 local fid1=$(create_small_file $dir_mdt0/$tfile)
4918 local fid2=$(create_small_file $dir_mdt1/$tfile)
4920 # check that compound requests are shunt to the rights MDTs
4921 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4922 error "lfs hsm_archive"
4923 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4924 echo "archive successful on mdt0"
4925 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4926 echo "archive successful on mdt1"
4928 run_test 401 "Compound requests split and sent to their respective MDTs"
4930 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4935 local node=$(facet_active_host $facet)
4937 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4938 awk '{print $4}'); do
4939 echo "$3 $mdc on $node"
4940 do_facet $facet "$LCTL --device $mdc $state" || return 1
4945 # deactivate all mdc on agent1
4946 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4948 copytool setup --no-fail
4950 check_agent_unregistered "uuid" # match any agent
4952 # no expected running copytool
4953 search_copytools $agent && error "Copytool start should have failed"
4956 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4958 run_test 402a "Copytool start fails if all MDTs are inactive"
4965 local f=$DIR/$tdir/$tfile
4966 touch $f || error "touch $f failed"
4967 local fid=$(path2fid $f)
4969 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4970 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4973 # give time for CDT to send request and to keep it for retry
4974 wait_for_loop_period
4976 wait_request_state $fid ARCHIVE WAITING
4978 do_facet $SINGLEAGT lctl set_param fail_loc=0
4980 # request should succeed now
4981 wait_request_state $fid ARCHIVE SUCCEED
4983 run_test 402b "CDT must retry request upon slow start of CT"
4986 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4988 local agent=$(facet_active_host $SINGLEAGT)
4990 # deactivate all mdc for MDT0001
4991 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4994 local uuid=$(get_agent_uuid $agent)
4995 # check the agent is registered on MDT0000, and not on MDT0001
4996 check_agent_registered_by_mdt $uuid 0
4997 check_agent_unregistered_by_mdt $uuid 1
4999 # check running copytool process
5000 search_copytools $agent || error "No running copytools on $agent"
5002 # reactivate all mdc for MDT0001
5003 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5005 # make sure the copytool is now registered to all MDTs
5006 check_agent_registered $uuid
5008 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5011 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5015 # create files on both MDT0000 and MDT0001
5018 local dir_mdt0=$DIR/$tdir/mdt0
5019 stack_trap "rm -rf $dir_mdt0" EXIT
5020 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5022 # create 1 file on mdt0
5023 local fid1=$(create_small_file $dir_mdt0/$tfile)
5025 # deactivate all mdc for MDT0001
5026 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5028 # send an HSM request for files in MDT0000
5029 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5031 # check for completion of files in MDT0000
5032 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5033 echo "archive successful on mdt0"
5035 # reactivate all mdc for MDT0001
5036 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5038 run_test 404 "Inactive MDT does not block requests for active MDTs"
5041 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5047 local striped_dir=$DIR/$tdir/striped_dir
5049 # create striped dir on all of MDTs
5050 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5052 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5053 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5054 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5055 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5057 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5058 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5059 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5060 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5062 # check that compound requests are shunt to the rights MDTs
5063 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5064 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5065 error "lfs hsm_archive"
5067 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5068 echo "archive successful on $fid1"
5069 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5070 echo "archive successful on $fid2"
5071 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5072 echo "archive successful on $fid3"
5073 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5074 echo "archive successful on $fid4"
5076 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5077 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5078 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5079 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5081 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5082 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5083 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5084 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5086 run_test 405 "archive and release under striped directory"
5089 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5091 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
5092 skip "need MDS version at least 2.7.64" && return 0
5097 fid=$(create_small_file $DIR/$tdir/$tfile)
5102 $LFS hsm_archive $DIR/$tdir/$tfile
5103 wait_request_state "$fid" ARCHIVE SUCCEED
5104 $LFS hsm_release $DIR/$tdir/$tfile
5106 # Should migrate $tdir but not $tfile.
5107 $LFS migrate -m1 $DIR/$tdir &&
5108 error "migrating HSM an archived file should fail"
5110 $LFS hsm_restore $DIR/$tdir/$tfile
5111 wait_request_state "$fid" RESTORE SUCCEED
5113 $LFS hsm_remove $DIR/$tdir/$tfile
5114 wait_request_state "$fid" REMOVE SUCCEED
5116 cat $DIR/$tdir/$tfile > /dev/null ||
5117 error "cannot read $DIR/$tdir/$tfile"
5119 $LFS migrate -m1 $DIR/$tdir ||
5120 error "cannot complete migration after HSM remove"
5122 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5123 if ((mdt_index != 1)); then
5124 error "expected MDT index 1, got $mdt_index"
5127 # Refresh fid after migration.
5128 fid=$(path2fid $DIR/$tdir/$tfile)
5131 $LFS hsm_archive $DIR/$tdir/$tfile
5132 wait_request_state "$fid" ARCHIVE SUCCEED 1
5134 lctl set_param debug=+trace
5135 $LFS hsm_release $DIR/$tdir/$tfile ||
5136 error "cannot release $DIR/$tdir/$tfile"
5138 $LFS hsm_restore $DIR/$tdir/$tfile
5139 wait_request_state "$fid" RESTORE SUCCEED 1
5141 cat $DIR/$tdir/$tfile > /dev/null ||
5142 error "cannot read $DIR/$tdir/$tfile"
5144 run_test 406 "attempting to migrate HSM archived files is safe"
5147 local f=$DIR/$tdir/$tfile
5148 local f2=$DIR2/$tdir/$tfile
5149 local fid=$(create_empty_file "$f")
5153 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5154 wait_request_state $fid ARCHIVE SUCCEED
5157 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5158 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5160 # Prevent restore from completing
5164 # 1st request holds layout lock while appropriate
5165 # RESTORE record is still not added to llog
5169 # after umount hsm_actions->O/x/x log shouldn't have
5170 # double RESTORE records like below
5171 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5172 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5174 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5178 wait_request_state $fid RESTORE SUCCEED
5180 run_test 407 "Check for double RESTORE records in llog"
5184 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5185 skip "HSM migrate is not supported" && return
5187 test_mkdir -p $DIR/$tdir
5188 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5190 run_test 500 "various LLAPI HSM tests"
5193 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5194 skip "need MDS version at least 2.10.58" && return 0
5198 local f=$DIR/$tdir/$tfile
5201 # set changelog_mask to ALL
5202 changelog_chmask "ALL"
5204 chmod 777 $DIR/$tdir
5205 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5206 local fid=$(path2fid $f)
5209 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5210 -gid "$RUNAS_GID") ||
5211 error "No matching CREAT entry"
5213 # Parse the changelog
5214 eval local -A changelog=$(changelog2array $entry)
5215 local nid="${changelog[nid]}"
5218 echo "Got NID '$nid'"
5219 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5220 error "nid '$nid' does not match any client NID:" \
5223 run_test 600 "Changelog fields 'u=' and 'nid='"
5226 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5227 skip "need MDS version at least 2.10.58" && return 0
5231 local f=$DIR/$tdir/$tfile
5234 # set changelog_mask to ALL
5235 changelog_chmask "ALL"
5237 touch $f || error "touch $f failed"
5238 local fid=$(path2fid $f)
5241 cat $f || error "cat $f failed"
5243 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5244 error "No matching OPEN entry"
5246 run_test 601 "OPEN Changelog entry"
5249 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5250 skip "need MDS version at least 2.10.58" && return 0
5254 local f=$DIR/$tdir/$tfile
5257 # set changelog_mask to ALL
5258 changelog_chmask "ALL"
5260 touch $f || error "touch $f failed"
5261 local fid=$(path2fid $f)
5264 cat $f || error "cat $f failed"
5266 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5270 echo f > $f || error "write $f failed"
5273 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5275 # remove OPEN from changelog_mask
5276 changelog_chmask "-OPEN"
5280 cat $f || error "cat $f failed"
5283 changelog_find -type CLOSE -target-fid $fid &&
5284 error "There should be no CLOSE entry"
5288 echo f > $f || error "write $f failed"
5291 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5293 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5296 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5297 skip "need MDS version at least 2.10.58" && return 0
5301 local f=$DIR/$tdir/$tfile
5304 # set changelog_mask to ALL
5305 changelog_chmask "ALL"
5307 touch $f || error "touch $f failed"
5308 local fid=$(path2fid $f)
5310 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5313 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5315 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5316 error "No matching GXATR entry"
5318 run_test 603 "GETXATTR Changelog entry"
5321 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5322 skip "need MDS version at least 2.10.58" && return 0
5326 local f=$DIR/$tdir/$tfile
5327 local f2=$DIR2/$tdir/$tfile
5328 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5330 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5331 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5332 do_facet mds1 lctl set_param "$procname=20"
5336 # set changelog_mask to ALL
5337 changelog_chmask "ALL"
5339 touch $f || error "touch $f failed"
5340 local fid=$(path2fid $f)
5346 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5350 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5351 -gid "$RUNAS_GID" -mode "r--") ||
5352 error "No matching NOPEN entry"
5354 # Parse the changelog
5355 eval local -A changelog=$(changelog2array $entry)
5356 local nid="${changelog[nid]}"
5359 echo "Got NID '$nid'"
5360 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5361 error "nid '$nid' does not match any client NID:" \
5366 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5369 changelog_find -type NOPEN -target-fid $fid &&
5370 error "There should be no NOPEN entry"
5372 # Sleep for `changelog_deniednext` seconds
5377 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5380 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5381 -gid "$RUNAS_GID" -mode "r--") ||
5382 error "No matching NOPEN entry"
5384 # Parse the changelog
5385 eval local -A changelog=$(changelog2array $entry)
5386 local nid="${changelog[nid]}"
5389 echo "Got NID '$nid'"
5390 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5391 error "nid '$nid' does not match any client NID:" \
5394 run_test 604 "NOPEN Changelog entry"
5397 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5398 skip "need MDS version at least 2.10.58" && return 0
5402 local f=$DIR/$tdir/$tfile
5403 local f2=$DIR2/$tdir/$tfile
5406 # set changelog_mask to ALL
5407 changelog_chmask "ALL"
5409 touch $f || error "touch $f failed"
5410 local fid=$(path2fid $f)
5414 exec 3<> $f || error "open $f failed"
5418 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5422 exec 4<> $f || error "open $f failed"
5425 changelog_find -type OPEN -target-fid $fid &&
5426 error "There should be no OPEN entry"
5428 exec 4>&- || error "close $f failed"
5431 changelog_find -type CLOSE -target-fid $fid &&
5432 error "There should be no CLOSE entry"
5436 # access in rw, so different access mode should generate entries
5437 cat $f || error "cat $f failed"
5440 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5442 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5446 # same access as first one, should not generate new entries
5447 exec 4<> $f || error "open $f failed"
5450 changelog_find -type OPEN -target-fid $fid &&
5451 error "There should be no OPEN entry"
5453 exec 4>&- || error "close $f failed"
5456 changelog_find -type CLOSE -target-fid $fid &&
5457 error "There should be no CLOSE entry"
5461 # access by different user should generate new entries
5462 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5465 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5467 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5471 exec 3>&- || error "close $f failed"
5474 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5476 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5479 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5480 skip "need MDS version at least 2.10.58" && return 0
5482 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5483 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5484 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5485 skip_env "missing llog_reader" && return
5486 local fstype=$(facet_fstype mds1)
5490 local f=$DIR/$tdir/$tfile
5493 # set changelog_mask to ALL
5494 changelog_chmask "ALL"
5496 chmod 777 $DIR/$tdir
5497 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5498 local fid=$(path2fid $f)
5499 rm $f || error "rm $f failed"
5501 local mntpt=$(facet_mntpt mds1)
5505 #remount mds1 as ldiskfs or zfs type
5506 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5507 stop mds1 || error "stop mds1 failed"
5508 mount_fstype mds1 || error "remount mds1 failed"
5510 for ((i = 0; i < 1; i++)); do
5511 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5512 local cat_file=$(do_facet mds1 $llog_reader \
5513 $mntpt/changelog_catalog | awk \
5514 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5515 [ -n "$cat_file" ] || error "no catalog file"
5517 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5518 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5519 [ -n "$entry" ] || error "no CREAT entry"
5522 local uidgid=$(echo $entry |
5523 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5524 [ -n "$uidgid" ] || error "uidgid is empty"
5525 echo "Got UID/GID $uidgid"
5526 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5527 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5528 local nid=$(echo $entry |
5529 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5530 [ -n "$nid" ] || error "nid is empty"
5532 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5533 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5535 run_test 606 "llog_reader groks changelog fields"
5538 check_and_cleanup_lustre