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 # bug number for skipped tests: LU-9795 LU-9795
19 ALWAYS_EXCEPT=" 13 402b $ALWAYS_EXCEPT"
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 MULTIOP=${MULTIOP:-multiop}
31 OPENFILE=${OPENFILE:-openfile}
32 MMAP_CAT=${MMAP_CAT:-mmap_cat}
33 MOUNT_2=${MOUNT_2:-"yes"}
35 MDS_VERSION_CODE=$(lustre_version_code $SINGLEMDS)
37 # script only handles up to 10 MDTs (because of MDT_PREFIX)
38 [ $MDSCOUNT -gt 9 ] &&
39 error "script cannot handle more than 9 MDTs, please fix" && exit
41 check_and_setup_lustre
43 if [[ $MDS_VERSION_CODE -lt $(version_code 2.4.53) ]]; then
44 skip_env "Need MDS version at least 2.4.53"
47 # $RUNAS_ID may get set incorrectly somewhere else
48 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
49 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
51 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 if getent group nobody; then
54 elif getent group nogroup; then
57 error "No generic nobody group"
62 # if there is no CLIENT1 defined, some tests can be ran on localhost
63 CLIENT1=${CLIENT1:-$HOSTNAME}
64 # if CLIENT2 doesn't exist then use CLIENT1 instead
65 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
67 # Exception is the test which need two separate nodes
68 CLIENT2=${CLIENT2:-$CLIENT1}
71 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
72 # the following associated variables are added:
74 # AGTCOUNT: number of agents
75 # AGTDEV{N}: target HSM mount point (root path of the backend)
76 # agt{N}_HOST: hostname of the agent agt{N}
77 # SINGLEAGT: facet of the single agent
79 # The number of agents is initialized as the number of remote client nodes.
80 # By default, only single copytool is started on a remote client/agent. If there
81 # was no remote client, then the copytool will be started on the local client.
87 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
88 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
90 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
91 if [[ $CLIENTCOUNT -gt 1 ]] &&
92 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
93 skip_env "SHARED_DIRECTORY should be accessible"\
98 # We used to put the HSM archive in $SHARED_DIRECTORY but that
99 # meant NFS issues could hose sanity-hsm sessions. So now we
101 for n in $(seq $AGTCOUNT); do
102 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
103 agent=CLIENT$((n + 1))
104 if [[ -z "${!agent}" ]]; then
105 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
108 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
111 export SINGLEAGT=${SINGLEAGT:-agt1}
113 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
114 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
115 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
116 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
117 export HSMTOOL_TESTDIR
118 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
122 # The test only support up to 10 MDTs
123 MDT_PREFIX="mdt.$FSNAME-MDT000"
124 HSM_PARAM="${MDT_PREFIX}0.hsm"
126 # archive is purged at copytool setup
127 HSM_ARCHIVE_PURGE=true
129 # Don't allow copytool error upon start/setup
130 HSMTOOL_NOERROR=false
133 # Get the backend root path for the given agent facet.
136 local dev=AGTDEV$(facet_number $facet)
143 # get MDT device for each mdc
144 for mdtno in $(seq 1 $MDSCOUNT); do
145 local idx=$(($mdtno - 1))
146 MDT[$idx]=$($LCTL get_param -n \
147 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
148 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
153 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
154 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
158 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
160 echo "Killing existing copytools on $hosts"
161 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
162 copytool_continue "$hosts"
166 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
167 local wait_timeout=200
168 local wait_start=$SECONDS
169 local wait_end=$((wait_start + wait_timeout))
170 local sleep_time=100000 # 0.1 second
172 while ((SECONDS < wait_end)); do
173 if ! search_copytools $hosts; then
174 echo "copytools stopped in $((SECONDS - wait_start))s"
178 echo "copytools still running on $hosts"
180 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
181 sleep_time=$(bc <<< "$sleep_time * 2")
184 # try to dump Copytool's stack
185 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
186 "echo t >/proc/sysrq-trigger"
188 echo "copytools failed to stop in ${wait_timeout}s"
193 copytool_monitor_setup() {
194 local facet=${1:-$SINGLEAGT}
195 local agent=$(facet_active_host $facet)
197 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
198 local test_dir=$(do_node $agent "$cmd") ||
199 error "Failed to create tempdir on $agent"
200 export HSMTOOL_MONITOR_DIR=$test_dir
202 # Create the fifo and a monitor (cat dies when copytool dies)
203 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
204 error "failed to create copytool fifo on $agent"
205 cmd="cat $test_dir/fifo > $test_dir/events &"
206 cmd+=" echo \\\$! > $test_dir/monitor_pid"
208 if [[ $PDSH == *Rmrsh* ]]; then
209 # This is required for pdsh -Rmrsh and its handling of remote
211 # Regular ssh and pdsh -Rssh work fine without this
212 # backgrounded subshell nonsense.
213 (do_node $agent "$cmd") &
214 export HSMTOOL_MONITOR_PDSH=$!
216 # Slightly racy, but just making a best-effort to catch obvious
219 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
220 error "Failed to start copytool monitor on $agent"
222 do_node $agent "$cmd"
224 error "Failed to start copytool monitor on $agent"
229 copytool_monitor_cleanup() {
230 local facet=${1:-$SINGLEAGT}
231 local agent=$(facet_active_host $facet)
233 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
234 # Should die when the copytool dies, but just in case.
235 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
236 cmd+=" 2>/dev/null || true"
237 do_node $agent "$cmd"
238 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
239 export HSMTOOL_MONITOR_DIR=
242 # The pdsh should die on its own when the monitor dies. Just
243 # in case, though, try to clean up to avoid any cruft.
244 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
245 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
246 export HSMTOOL_MONITOR_PDSH=
256 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
263 local host="$(facet_host "$1")"
264 local prefix=$TESTLOG_PREFIX
265 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
267 printf "${prefix}.copytool${archive_id}_log.${host}.log"
272 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
277 mkdir -p "$(dirname "$2")" ||
278 error "cannot create directory '$(dirname "$2")'"
279 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
284 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
285 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
286 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
287 [ ${#misc_options[@]} -gt 0 ] &&
288 cmd+=" $(IFS=" " echo "$@")"
289 cmd+=" \"$mountpoint\""
291 echo "Starting copytool $facet on $(facet_host $facet)"
292 stack_trap "do_facet $facet pkill -x '$HSMTOOL_BASE' || true" EXIT
293 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
297 local facet="${1:-$SINGLEAGT}"
299 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
302 # Main entry point to perform copytool related operations
306 # setup setup a copytool to run in the background, that copytool will be
308 # import import a file from an HSM backend
309 # rebind rebind an archived file to a new fid
311 # Although the semantics might suggest otherwise, one does not need to 'setup'
312 # a copytool before a call to 'copytool import' or 'copytool rebind'.
320 local fail_on_error=true
321 local -a misc_options
322 while [ $# -gt 0 ]; do
330 local mountpoint="$1"
334 local archive_id="$1"
338 local bandwidth="$1" # in MB/s
341 local fail_on_error=false
344 # Uncommon(/copytool dependent) option
351 # Use default values if needed
352 local facet=${facet:-$SINGLEAGT}
353 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
354 local hsm_root="$(hsm_root "$facet")"
356 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
357 do_facet $facet mkdir -p "$hsm_root" ||
358 error "mkdir '$hsm_root' failed"
362 local copytool=lhsmtool
366 __${copytool}_${action} "${misc_options[@]}"
367 if [ $? -ne 0 ]; then
372 local host="$(facet_host $facet)"
373 error_msg="Failed to start copytool $facet on '$host'"
376 local src="${misc_options[0]}"
377 local dest="${misc_options[1]}"
378 error_msg="Failed to import '$src' to '$dest'"
381 error_msg="could not rebind file"
385 $fail_on_error && error "$error_msg" || echo "$error_msg"
389 get_copytool_event_log() {
390 local facet=${1:-$SINGLEAGT}
391 local agent=$(facet_active_host $facet)
393 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
394 error "Can't get event log: No monitor directory!"
396 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
397 error "Could not collect event log from $agent"
401 local agents=${1:-$(facet_active_host $SINGLEAGT)}
404 "do_nodesv $agents pkill -CONT -x '$HSMTOOL_BASE' || true" EXIT
405 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
406 echo "Copytool is suspended on $agents"
409 copytool_continue() {
410 local agents=${1:-$(facet_active_host $SINGLEAGT)}
412 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
413 echo "Copytool is continued on $agents"
416 copytool_remove_backend() {
418 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
419 echo "Remove from backend: $fid = $be"
420 do_facet $SINGLEAGT rm -f $be
423 file_creation_failure() {
430 df $MOUNT $MOUNT2 >&2
431 error "Not enough space to create $file with $cmd"
434 error "cannot create $file with $cmd, status=$err"
439 # Creates a file using dd
445 local source=${5:-/dev/zero}
449 if [ -n "$conv" ]; then
453 # Create the directory in case it does not exist
454 mkdir -p "$(dirname "$file")"
455 # Delete the file in case it already exist
458 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
459 path2fid "$file" || error "cannot get FID of '$file'"
462 echo "cannot create file '$file'" >&2;
463 # Let the caller decide what to do on error
468 create_empty_file() {
469 create_file "${1/$DIR/$DIR2}" 1M 0 ||
470 file_creation_failure dd "${1/$DIR/$DIR2}" $?
473 create_small_file() {
474 local source_file=/dev/urandom
477 local conv=${2:-fsync}
479 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
480 file_creation_failure dd "${1/$DIR/$DIR2}" $?
483 create_small_sync_file() {
484 create_small_file "$1" sync
487 create_archive_file() {
488 local file="$(hsm_root)/$1"
490 local source=/dev/urandom
492 # Create the counterpart directory of the archive
493 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
494 error "cannot create archive directory '$(dirname "$file")'"
496 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
497 error "cannot create archive file '$file'"
501 local hsm_root="$(hsm_root)"
502 local file="$hsm_root/$2"
504 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
505 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
506 error "mkdir '$(dirname "$file")' failed"
507 do_facet $SINGLEAGT cp -p "$1" "$file" ||
508 error "cannot copy '$1' to '$file'"
517 if [[ "$value" != "" ]]; then
520 for mdtno in $(seq 1 $MDSCOUNT); do
521 local idx=$(($mdtno - 1))
522 local facet=mds${mdtno}
523 # if $arg include -P option, run 1 set_param per MDT on the MGS
524 # else, run set_param on each MDT
525 [[ $arg = *"-P"* ]] && facet=mgs
526 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
527 [[ $? != 0 ]] && rc=1
537 for mdtno in $(seq 1 $MDSCOUNT); do
538 local idx=$(($mdtno - 1))
539 wait_result mds${mdtno} \
540 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
542 error "$key state is not '$target' on mds${mdtno}"
548 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
556 mdts_set_param "$opt -n" "hsm.$param" "$value"
563 mdts_set_param "" hsm_control "$cmd"
564 mdts_check_param hsm_control "$target" 10
567 cdt_set_sanity_policy() {
568 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
571 mdts_set_param "" hsm.policy "+NRA"
572 mdts_set_param "" hsm.policy "-NBR"
573 CDT_POLICY_HAD_CHANGED=
578 mdts_set_param "" hsm.policy "+NRA"
579 CDT_POLICY_HAD_CHANGED=true
582 cdt_clear_no_retry() {
583 mdts_set_param "" hsm.policy "-NRA"
584 CDT_POLICY_HAD_CHANGED=true
587 cdt_set_non_blocking_restore() {
588 mdts_set_param "" hsm.policy "+NBR"
589 CDT_POLICY_HAD_CHANGED=true
592 cdt_clear_non_blocking_restore() {
593 mdts_set_param "" hsm.policy "-NBR"
594 CDT_POLICY_HAD_CHANGED=true
597 cdt_clear_mount_state() {
598 mdts_set_param "-P -d" hsm_control ""
601 cdt_set_mount_state() {
602 mdts_set_param "-P" hsm_control "$1"
603 # set_param -P is asynchronous operation and could race with set_param.
604 # In such case configs could be retrieved and applied at mgc after
605 # set_param -P completion. Sleep here to avoid race with set_param.
606 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
607 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
608 # and 10 seconds to retrieve config from server.
613 mdts_check_param hsm_control "$1" 20
617 set_test_state disabled disabled
621 set_test_state enabled enabled
625 set_test_state shutdown stopped
629 set_test_state purge enabled
635 cdt_set_sanity_policy
639 local client_count=$1
640 if [[ $CLIENTCOUNT -lt $client_count ]]; then
641 skip "Need $client_count or more clients, have $CLIENTCOUNT"
648 $LFS path2fid $1 | tr -d '[]'
649 return ${PIPESTATUS[0]}
657 if [[ $u == "user" ]]; then
658 st=$($RUNAS $LFS hsm_state $f)
661 st=$($LFS hsm_state $f)
664 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
666 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
670 get_hsm_archive_id() {
673 st=$($LFS hsm_state $f)
674 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
676 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
684 local st=$(get_hsm_flags $f)
685 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
688 check_hsm_flags_user() {
692 local st=$(get_hsm_flags $f user)
693 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
705 if [[ "$3" != 1 ]]; then
709 cp $1 $f || file_creation_failure cp $f $?
711 path2fid $f || error "cannot get fid on $f"
714 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
716 # Note that this might lead to surprising behaviours such as deleting an
717 # important file for the currently running test
718 delete_large_files() {
719 printf "Deleting large files...\n" >&2
720 find $MOUNT -size +10M -delete
721 wait_delete_completed
727 wait_update --verbose $(facet_active_host $facet) "$@"
730 wait_request_state() {
734 # 4th arg (mdt index) is optional
736 local mds=mds$(($mdtidx + 1))
738 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
739 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
741 wait_result $mds "$cmd" "$state" 200 ||
742 error "request on $fid is not $state on $mds"
745 get_request_state() {
749 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
750 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
753 get_request_count() {
757 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
758 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
761 # Ensure the number of HSM request for a given FID is correct
762 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
763 assert_request_count() {
764 local request_count=$(get_request_count $1 $2)
765 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
767 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
774 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
775 [[ -n $fid ]] && cmd+=" | grep '$fid'"
776 cmd+=" | egrep 'WAITING|STARTED'"
778 wait_result $SINGLEMDS "$cmd" "" $timeout ||
779 error "requests did not complete"
782 wait_for_grace_delay() {
783 local val=$(get_hsm_param grace_delay)
787 wait_for_loop_period() {
788 local val=$(get_hsm_param loop_period)
795 # python2.6 in EL6 includes an internal json module
796 local json_parser='import json; import fileinput;'
797 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
798 json_parser+='json.loads([line for line in '
799 json_parser+='fileinput.input()][0]).items()])'
801 echo $raw_event | python -c "$json_parser"
804 get_agent_by_uuid_mdt() {
807 local mds=mds$(($mdtidx + 1))
808 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
812 check_agent_registered_by_mdt() {
815 local mds=mds$(($mdtidx + 1))
816 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
817 if [[ ! -z "$agent" ]]; then
818 echo "found agent $agent on $mds"
820 error "uuid $uuid not found in agent list on $mds"
824 check_agent_unregistered_by_mdt() {
827 local mds=mds$(($mdtidx + 1))
828 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
829 if [[ -z "$agent" ]]; then
830 echo "uuid not found in agent list on $mds"
832 error "uuid found in agent list on $mds: $agent"
836 check_agent_registered() {
839 for mdsno in $(seq 1 $MDSCOUNT); do
840 check_agent_registered_by_mdt $uuid $((mdsno - 1))
844 check_agent_unregistered() {
847 for mdsno in $(seq 1 $MDSCOUNT); do
848 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
853 local agent=${1:-$(facet_active_host $SINGLEAGT)}
855 # Lustre mount-point is mandatory and last parameter on
857 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
859 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
861 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
867 # populate MDT device array
870 # cleanup from previous bad setup
873 # for recovery tests, coordinator needs to be started at mount
875 # the lustre conf must be without hsm on (like for sanity.sh)
876 echo "Set HSM on and start"
877 cdt_set_mount_state enabled
878 cdt_check_state enabled
880 echo "Set sanity-hsm HSM policy"
881 cdt_set_sanity_policy
883 # finished requests are quickly removed from list
884 set_hsm_param grace_delay 10
886 CLIENT_NIDS=( $($LCTL list_nids all) )
888 test_1A() { # was test_1
892 local f=$DIR/$tdir/$tfile
896 check_hsm_flags_user $f "0x00000000"
898 $RUNAS $LFS hsm_set --norelease $f ||
899 error "user could not change hsm flags"
900 check_hsm_flags_user $f "0x00000010"
902 $RUNAS $LFS hsm_clear --norelease $f ||
903 error "user could not clear hsm flags"
904 check_hsm_flags_user $f "0x00000000"
906 # User could not change those flags...
907 $RUNAS $LFS hsm_set --exists $f &&
908 error "user should not set this flag"
909 check_hsm_flags_user $f "0x00000000"
912 $LFS hsm_set --exists $f ||
913 error "root could not change hsm flags"
914 check_hsm_flags_user $f "0x00000001"
916 $LFS hsm_clear --exists $f ||
917 error "root could not clear hsm state"
918 check_hsm_flags_user $f "0x00000000"
921 run_test 1A "lfs hsm flags root/non-root access"
924 local f=$DIR/$tdir/$tfile
925 local fid=$(create_small_file $f)
929 $LFS hsm_archive $f || error "could not archive file"
930 wait_request_state $fid ARCHIVE SUCCEED
932 # Release and check states
933 $LFS hsm_release $f || error "could not release file"
934 echo -n "Verifying released state: "
935 check_hsm_flags $f "0x0000000d"
937 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
939 run_test 1a "mmap & cat a HSM released file"
943 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
944 error "failed to set default stripe"
945 local f=$DIR/$tdir/$tfile
948 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
949 error "failed to create file"
950 local fid=$(path2fid $f)
955 $LFS hsm_archive $f || error "could not archive file"
956 wait_request_state $fid ARCHIVE SUCCEED
959 $LFS hsm_release $f || error "could not release file"
960 echo "verify released state: "
961 check_hsm_flags $f "0x0000000d" && echo "pass"
964 $LFS hsm_restore $f || error "could not restore file"
965 wait_request_state $fid RESTORE SUCCEED
966 echo "verify restored state: "
967 check_hsm_flags $f "0x00000009" && echo "pass"
969 run_test 1b "Archive, Release and Restore composite file"
975 local f=$DIR/$tdir/$tfile
978 # Test whether we can set the maximum archive number.
979 local LOCAL_HSM_ARCHIVE_NUMBER=32
980 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
981 error "root could not change hsm flags"
982 check_hsm_flags_user $f "0x00000001"
983 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
984 local st=$(get_hsm_archive_id $f)
985 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
986 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
988 # Test whether setting archive number 0 results in no change.
989 $LFS hsm_set --exists --archive-id 0 $f ||
990 error "root could not change hsm flags"
991 check_hsm_flags_user $f "0x00000001"
992 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
993 st=$(get_hsm_archive_id $f)
994 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
995 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
997 LOCAL_HSM_ARCHIVE_NUMBER=33
998 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
999 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
1000 # lustre in the new version supports unlimited archiveID.
1001 # Test whether setting archive number > 32 is supported
1002 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1003 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
1004 check_hsm_flags_user $f "0x00000001"
1006 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1007 st=$(get_hsm_archive_id $f)
1008 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1009 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1011 # old client or old mds can only support at most 32 archiveID
1012 # test whether setting archive number > 32 results in error.
1013 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
1014 error "bitmap archive number is larger than 32"
1015 check_hsm_flags_user $f "0x00000001"
1018 # Test whether setting archive number 16 and archived flag.
1019 LOCAL_HSM_ARCHIVE_NUMBER=16
1020 $LFS hsm_set --exists --archived \
1021 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1022 error "root could not change hsm flags"
1023 check_hsm_flags_user $f "0x00000009"
1024 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1025 st=$(get_hsm_archive_id $f)
1026 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1027 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1029 run_test 1c "Check setting archive-id in lfs hsm_set"
1032 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1033 skip "need MDS version at least 2.10.59"
1036 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1037 error "failed to set default stripe"
1038 local f=$DIR/$tdir/$tfile
1041 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1042 error "failed to create file"
1043 local fid=$(path2fid $f)
1048 $LFS hsm_archive $f || error "could not archive file"
1049 wait_request_state $fid ARCHIVE SUCCEED
1052 $LFS hsm_release $f || error "could not release file"
1053 echo "verify released state: "
1054 check_hsm_flags $f "0x0000000d" && echo "pass"
1057 $LFS hsm_restore $f || error "could not restore file"
1058 wait_request_state $fid RESTORE SUCCEED
1059 echo "verify restored state: "
1060 check_hsm_flags $f "0x00000009" && echo "pass"
1062 run_test 1d "Archive, Release and Restore DoM file"
1065 local f=$DIR/$tdir/$tfile
1067 create_empty_file "$f"
1068 # New files are not dirty
1069 check_hsm_flags $f "0x00000000"
1071 # For test, we simulate an archived file.
1072 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1073 check_hsm_flags $f "0x00000001"
1075 # chmod do not put the file dirty
1076 chmod 600 $f || error "could not chmod test file"
1077 check_hsm_flags $f "0x00000001"
1079 # chown do not put the file dirty
1080 chown $RUNAS_ID $f || error "could not chown test file"
1081 check_hsm_flags $f "0x00000001"
1083 # truncate put the file dirty
1084 $TRUNCATE $f 1 || error "could not truncate test file"
1085 check_hsm_flags $f "0x00000003"
1087 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1088 check_hsm_flags $f "0x00000001"
1090 run_test 2 "Check file dirtyness when doing setattr"
1096 # New files are not dirty
1097 cp -p /etc/passwd $f
1098 check_hsm_flags $f "0x00000000"
1100 # For test, we simulate an archived file.
1101 $LFS hsm_set --exists $f ||
1102 error "user could not change hsm flags"
1103 check_hsm_flags $f "0x00000001"
1105 # Reading a file, does not set dirty
1106 cat $f > /dev/null || error "could not read file"
1107 check_hsm_flags $f "0x00000001"
1109 # Open for write without modifying data, does not set dirty
1110 openfile -f O_WRONLY $f || error "could not open test file"
1111 check_hsm_flags $f "0x00000001"
1113 # Append to a file sets it dirty
1114 cp -p /etc/passwd $f.append || error "could not create file"
1115 $LFS hsm_set --exists $f.append ||
1116 error "user could not change hsm flags"
1117 dd if=/etc/passwd of=$f.append bs=1 count=3\
1118 conv=notrunc oflag=append status=noxfer ||
1119 file_creation_failure dd $f.append $?
1120 check_hsm_flags $f.append "0x00000003"
1122 # Modify a file sets it dirty
1123 cp -p /etc/passwd $f.modify || error "could not create file"
1124 $LFS hsm_set --exists $f.modify ||
1125 error "user could not change hsm flags"
1126 dd if=/dev/zero of=$f.modify bs=1 count=3\
1127 conv=notrunc status=noxfer ||
1128 file_creation_failure dd $f.modify $?
1129 check_hsm_flags $f.modify "0x00000003"
1131 # Open O_TRUNC sets dirty
1132 cp -p /etc/passwd $f.trunc || error "could not create file"
1133 $LFS hsm_set --exists $f.trunc ||
1134 error "user could not change hsm flags"
1135 cp /etc/group $f.trunc || error "could not override a file"
1136 check_hsm_flags $f.trunc "0x00000003"
1138 # Mmapped a file sets dirty
1139 cp -p /etc/passwd $f.mmap || error "could not create file"
1140 $LFS hsm_set --exists $f.mmap ||
1141 error "user could not change hsm flags"
1142 multiop $f.mmap OSMWUc || error "could not mmap a file"
1143 check_hsm_flags $f.mmap "0x00000003"
1145 run_test 3 "Check file dirtyness when opening for write"
1148 local f=$DIR/$tdir/$tfile
1149 local fid=$(create_small_file $f)
1152 local st=$(get_request_state $fid CANCEL)
1153 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1155 run_test 4 "Useless cancel must not be registered"
1158 # test needs a running copytool
1162 local f=$DIR/$tdir/$tfile
1163 local fid=$(copy_file /etc/passwd $f)
1165 wait_request_state $fid ARCHIVE SUCCEED
1167 check_hsm_flags $f "0x00000009"
1169 run_test 8 "Test default archive number"
1171 test_9A() { # was test_9
1172 # we do not use the default one to be sure
1173 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1174 copytool setup --archive-id $archive_id
1176 # give time for CT to register with MDTs
1177 sleep $(($MDSCOUNT*2))
1178 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1179 check_agent_registered $uuid
1182 local f=$DIR/$tdir/$tfile
1183 local fid=$(copy_file /etc/passwd $f)
1184 $LFS hsm_archive --archive $archive_id $f
1185 wait_request_state $fid ARCHIVE SUCCEED
1187 check_hsm_flags $f "0x00000009"
1189 run_test 9A "Use of explicit archive number, with dedicated copytool"
1192 needclients 3 || return 0
1198 # start all of the copytools
1199 for n in $(seq $AGTCOUNT); do
1200 copytool setup --facet agt$n
1204 for n in $(seq $AGTCOUNT); do
1205 file=$DIR/$tdir/$tfile.$n
1206 fid=$(create_small_file $file)
1208 $LFS hsm_archive $file || error "could not archive file $file"
1209 wait_request_state $fid ARCHIVE SUCCEED
1210 check_hsm_flags $file "0x00000009"
1213 run_test 9a "Multiple remote agents"
1216 # test needs a running copytool
1219 mkdir -p $DIR/$tdir/d1
1220 local f=$DIR/$tdir/$tfile
1221 local fid=$(copy_file /etc/hosts $f)
1222 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1223 error "hsm_archive failed"
1224 wait_request_state $fid ARCHIVE SUCCEED
1226 local hsm_root="$(copytool_device $SINGLEAGT)"
1227 local archive="$(do_facet $SINGLEAGT \
1228 find "$hsm_root" -name "$fid" -print0)"
1229 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1231 echo "Verifying content"
1232 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1233 echo "Verifying hsm state "
1234 check_hsm_flags $f "0x00000009"
1236 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1237 local st=$(get_hsm_archive_id $f)
1238 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1239 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1241 run_test 10a "Archive a file"
1244 # test needs a running copytool
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_archive $f || error "archive request failed"
1251 wait_request_state $fid ARCHIVE SUCCEED
1253 $LFS hsm_archive $f || error "archive of non dirty file failed"
1254 local cnt=$(get_request_count $fid ARCHIVE)
1255 [[ "$cnt" == "1" ]] ||
1256 error "archive of non dirty file must not make a request"
1258 run_test 10b "Archive of non dirty file must work without doing request"
1261 # test needs a running copytool
1265 local f=$DIR/$tdir/$tfile
1266 local fid=$(copy_file /etc/hosts $f)
1267 $LFS hsm_set --noarchive $f
1268 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1271 run_test 10c "Check forbidden archive"
1274 # test needs a running copytool
1278 local f=$DIR/$tdir/$tfile
1279 local fid=$(copy_file /etc/hosts $f)
1280 $LFS hsm_archive $f || error "cannot archive $f"
1281 wait_request_state $fid ARCHIVE SUCCEED
1283 local ar=$(get_hsm_archive_id $f)
1284 local dflt=$(get_hsm_param default_archive_id)
1285 [[ $ar == $dflt ]] ||
1286 error "archived file is not on default archive: $ar != $dflt"
1288 run_test 10d "Archive a file on the default archive id"
1292 copy2archive /etc/hosts $tdir/$tfile
1293 local f=$DIR/$tdir/$tfile
1295 copytool import $tdir/$tfile $f
1296 echo -n "Verifying released state: "
1297 check_hsm_flags $f "0x0000000d"
1299 local LSZ=$(stat -c "%s" $f)
1300 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1302 echo "Verifying imported size $LSZ=$ASZ"
1303 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1304 echo -n "Verifying released pattern: "
1305 local PTRN=$($GETSTRIPE -L $f)
1307 [[ $PTRN == released ]] || error "Is not released"
1308 local fid=$(path2fid $f)
1309 echo "Verifying new fid $fid in archive"
1311 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1312 error "No archive for fid $fid"
1314 run_test 11a "Import a file"
1317 # test needs a running copytool
1321 local f=$DIR/$tdir/$tfile
1322 local fid=$(copy_file /etc/hosts $f)
1323 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1324 error "hsm_archive failed"
1325 wait_request_state $fid ARCHIVE SUCCEED
1327 local FILE_HASH=$(md5sum $f)
1330 copytool import $fid $f
1332 echo "$FILE_HASH" | md5sum -c
1334 [[ $? -eq 0 ]] || error "Restored file differs"
1336 run_test 11b "Import a deleted file using its FID"
1339 # test needs a running copytool
1343 copy2archive /etc/hosts $tdir/$tfile
1345 local f=$DIR/$tdir/$tfile
1346 copytool import $tdir/$tfile $f
1347 local f2=$DIR2/$tdir/$tfile
1348 echo "Verifying released state: "
1349 check_hsm_flags $f2 "0x0000000d"
1351 local fid=$(path2fid $f2)
1352 $LFS hsm_restore $f2
1353 wait_request_state $fid RESTORE SUCCEED
1355 echo "Verifying file state: "
1356 check_hsm_flags $f2 "0x00000009"
1358 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1360 [[ $? -eq 0 ]] || error "Restored file differs"
1362 run_test 12a "Restore an imported file explicitly"
1365 # test needs a running copytool
1369 copy2archive /etc/hosts $tdir/$tfile
1371 local f=$DIR/$tdir/$tfile
1372 copytool import $tdir/$tfile $f
1373 echo "Verifying released state: "
1374 check_hsm_flags $f "0x0000000d"
1376 cat $f > /dev/null || error "File read failed"
1378 echo "Verifying file state after restore: "
1379 check_hsm_flags $f "0x00000009"
1381 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1383 [[ $? -eq 0 ]] || error "Restored file differs"
1385 run_test 12b "Restore an imported file implicitly"
1388 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1390 # test needs a running copytool
1393 local f=$DIR/$tdir/$tfile
1395 $LFS setstripe -c 2 "$f"
1396 local fid=$(create_file "$f" 1M 5)
1398 local FILE_CRC=$(md5sum $f)
1400 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1401 wait_request_state $fid ARCHIVE SUCCEED
1402 $LFS hsm_release $f || error "release $f failed"
1404 echo "$FILE_CRC" | md5sum -c
1406 [[ $? -eq 0 ]] || error "Restored file differs"
1408 run_test 12c "Restore a file with stripe of 2"
1411 # test needs a running copytool
1416 local f=$DIR/$tdir/$tfile
1417 local fid=$(copy_file /etc/hosts $f)
1418 $LFS hsm_restore $f || error "restore of non archived file failed"
1419 local cnt=$(get_request_count $fid RESTORE)
1420 [[ "$cnt" == "0" ]] ||
1421 error "restore non archived must not make a request"
1422 $LFS hsm_archive $f ||
1423 error "archive request failed"
1424 wait_request_state $fid ARCHIVE SUCCEED
1425 $LFS hsm_restore $f ||
1426 error "restore of non released file failed"
1427 local cnt=$(get_request_count $fid RESTORE)
1428 [[ "$cnt" == "0" ]] ||
1429 error "restore a non dirty file must not make a request"
1431 run_test 12d "Restore of a non archived, non released file must work"\
1432 " without doing request"
1435 # test needs a running copytool
1439 local f=$DIR/$tdir/$tfile
1440 local fid=$(copy_file /etc/hosts $f)
1441 $LFS hsm_archive $f || error "archive request failed"
1442 wait_request_state $fid ARCHIVE SUCCEED
1445 cat /etc/hosts >> $f
1449 $LFS hsm_restore $f && error "restore a dirty file must fail"
1452 run_test 12e "Check forbidden restore"
1455 # test needs a running copytool
1459 local f=$DIR/$tdir/$tfile
1460 local fid=$(copy_file /etc/hosts $f)
1462 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1463 wait_request_state $fid ARCHIVE SUCCEED
1464 $LFS hsm_release $f || error "release of $f failed"
1466 wait_request_state $fid RESTORE SUCCEED
1468 echo -n "Verifying file state: "
1469 check_hsm_flags $f "0x00000009"
1471 diff -q /etc/hosts $f
1473 [[ $? -eq 0 ]] || error "Restored file differs"
1475 run_test 12f "Restore a released file explicitly"
1478 # test needs a running copytool
1482 local f=$DIR/$tdir/$tfile
1483 local fid=$(copy_file /etc/hosts $f)
1485 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1486 wait_request_state $fid ARCHIVE SUCCEED
1487 $LFS hsm_release $f || error "release of $f failed"
1489 diff -q /etc/hosts $f
1492 # we check we had a restore done
1493 wait_request_state $fid RESTORE SUCCEED
1495 [[ $st -eq 0 ]] || error "Restored file differs"
1497 run_test 12g "Restore a released file implicitly"
1500 needclients 2 || return 0
1502 # test needs a running copytool
1506 local f=$DIR/$tdir/$tfile
1507 local fid=$(copy_file /etc/hosts $f)
1509 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1510 wait_request_state $fid ARCHIVE SUCCEED
1511 $LFS hsm_release $f || error "release of $f failed"
1513 do_node $CLIENT2 diff -q /etc/hosts $f
1516 # we check we had a restore done
1517 wait_request_state $fid RESTORE SUCCEED
1519 [[ $st -eq 0 ]] || error "Restored file differs"
1521 run_test 12h "Restore a released file implicitly from a second node"
1524 # test needs a running copytool
1528 local f=$DIR/$tdir/$tfile
1529 local fid=$(copy_file /etc/passwd $f)
1530 $LFS hsm_archive $f || error "archive of $f failed"
1531 wait_request_state $fid ARCHIVE SUCCEED
1533 $LFS hsm_release $f || error "release of $f failed"
1537 [[ $? -eq 0 ]] || error "Restored file differs"
1539 run_test 12m "Archive/release/implicit restore"
1542 # test needs a running copytool
1546 copy2archive /etc/hosts $tdir/$tfile
1548 local f=$DIR/$tdir/$tfile
1549 copytool import $tdir/$tfile $f
1551 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1552 error "Restored file differs"
1554 $LFS hsm_release $f || error "release of $f failed"
1556 run_test 12n "Import/implicit restore/release"
1559 # test needs a running copytool
1563 local f=$DIR/$tdir/$tfile
1564 local fid=$(copy_file /etc/hosts $f)
1566 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1567 wait_request_state $fid ARCHIVE SUCCEED
1568 $LFS hsm_release $f || error "release of $f failed"
1570 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1571 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1573 # set no retry action mode
1576 diff -q /etc/hosts $f
1579 # we check we had a restore failure
1580 wait_request_state $fid RESTORE FAILED
1582 [[ $st -eq 0 ]] && error "Restore must fail"
1584 # remove no retry action mode
1587 # check file is still released
1588 check_hsm_flags $f "0x0000000d"
1590 # retry w/o failure injection
1591 do_facet $SINGLEMDS lctl set_param fail_loc=0
1593 # to be sure previous RESTORE result is gone
1595 wait_for_grace_delay
1597 diff -q /etc/hosts $f
1600 # we check we had a restore done
1601 wait_request_state $fid RESTORE SUCCEED
1603 [[ $st -eq 0 ]] || error "Restored file differs"
1605 run_test 12o "Layout-swap failure during Restore leaves file released"
1608 # test needs a running copytool
1612 local f=$DIR/$tdir/$tfile
1613 local fid=$(copy_file /etc/hosts $f)
1615 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1616 wait_request_state $fid ARCHIVE SUCCEED
1617 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1618 $LFS hsm_release $f || error "cannot release $f"
1619 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1620 $LFS hsm_release $f || error "cannot release $f"
1621 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1623 run_test 12p "implicit restore of a file on copytool mount point"
1626 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1627 skip "need MDS version at least 2.7.58"
1629 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1630 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1631 error "cannot mount $MOUNT3 on $SINGLEAGT"
1633 # test needs a running copytool
1634 copytool setup -m "$MOUNT3"
1636 local f=$DIR/$tdir/$tfile
1637 local f2=$DIR2/$tdir/$tfile
1638 local fid=$(create_small_file $f)
1639 local orig_size=$(stat -c "%s" $f)
1641 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1642 wait_request_state $fid ARCHIVE SUCCEED
1644 $LFS hsm_release $f || error "could not release file"
1645 check_hsm_flags $f "0x0000000d"
1648 wait_copytools || error "copytool failed to stop"
1650 cat $f > /dev/null &
1652 # wait a bit to allow implicit restore request to be handled.
1653 # if not, next stat would also block on layout-lock.
1656 local size=$(stat -c "%s" $f2)
1657 [ $size -eq $orig_size ] ||
1658 error "$f2: wrong size after archive: $size != $orig_size"
1660 copytool setup -m "$MOUNT3"
1664 size=$(stat -c "%s" $f)
1665 [ $size -eq $orig_size ] ||
1666 error "$f: wrong size after restore: $size != $orig_size"
1668 size=$(stat -c "%s" $f2)
1669 [ $size -eq $orig_size ] ||
1670 error "$f2: wrong size after restore: $size != $orig_size"
1674 size=$(stat -c "%s" $f)
1676 error "$f: wrong size after overwrite: $size != 0"
1678 size=$(stat -c "%s" $f2)
1680 error "$f2: wrong size after overwrite: $size != 0"
1682 run_test 12q "file attributes are refreshed after restore"
1686 for i in {1..10}; do
1687 local archive_dir="$(hsm_root)"/subdir/dir.$i
1689 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1690 for j in {1..10}; do
1691 local archive_file="$archive_dir"/file.$j
1693 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1699 copytool import "subdir" "$DIR/$tdir"
1701 # To check the import, the test uses diff with the -r flag
1702 # This is nice, but diff only checks files one by one, and triggering
1703 # an implicit restore for one file at a time will consume as many
1704 # seconds as there are files to compare. To speed this up, a restore
1705 # operation is triggered manually first.
1707 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1709 # Compare the imported data
1710 do_facet $SINGLEAGT \
1711 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1712 error "imported files differ from archived data"
1714 run_test 13 "Recursively import and restore a directory"
1717 # test needs a running copytool
1721 local f=$DIR/$tdir/$tfile
1722 local fid=$(create_small_file $f)
1723 local sum=$(md5sum $f | awk '{print $1}')
1724 $LFS hsm_archive $f || error "could not archive file"
1725 wait_request_state $fid ARCHIVE SUCCEED
1727 # create released file (simulate llapi_hsm_import call)
1728 local fid2=$(create_empty_file "$f")
1729 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1730 $LFS hsm_release $f || error "could not release file"
1732 # rebind the archive to the newly created file
1733 echo "rebind $fid to $fid2"
1735 copytool rebind $fid $fid2
1737 # restore file and compare md5sum
1738 local sum2=$(md5sum $f | awk '{print $1}')
1740 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1742 run_test 14 "Rebind archived file to a new fid"
1745 # test needs a running copytool
1749 local f=$DIR/$tdir/$tfile
1751 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1755 for i in $(seq 1 $count); do
1756 fids[$i]=$(create_small_file $f.$i)
1757 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1758 $LFS hsm_archive $f.$i || error "could not archive file"
1760 wait_all_done $(($count*60))
1762 stack_trap "rm -f $tmpfile" EXIT
1765 for i in $(seq 1 $count); do
1766 local fid2=$(create_empty_file "${f}.${i}")
1767 # add the rebind operation to the list
1768 echo ${fids[$i]} $fid2 >> $tmpfile
1770 # set it released (simulate llapi_hsm_import call)
1771 $LFS hsm_set --archived --exists $f.$i ||
1772 error "could not force hsm flags"
1773 $LFS hsm_release $f.$i || error "could not release file"
1775 nl=$(wc -l < $tmpfile)
1776 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1778 echo "rebind list of files"
1779 copytool rebind "$tmpfile"
1781 # restore files and compare md5sum
1782 for i in $(seq 1 $count); do
1783 local sum2=$(md5sum $f.$i | awk '{print $1}')
1784 [[ $sum2 == ${sums[$i]} ]] ||
1785 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1788 run_test 15 "Rebind a list of files"
1791 # test needs a running copytool
1795 # create a known size file so we can verify transfer speed
1798 dd if=/dev/zero of=$ref bs=1M count=20
1801 local f=$DIR/$tdir/$tfile
1802 local fid=$(copy_file $ref $f)
1804 local start=$(date +%s)
1806 wait_request_state $fid ARCHIVE SUCCEED
1807 local end=$(date +%s)
1808 # Add 1 to account for rounding errors between start and end (LU-8155)
1809 local duration=$((end - start + 1))
1811 [[ $duration -ge $((goal - 1)) ]] ||
1812 error "Transfer is too fast $duration < $goal"
1814 run_test 16 "Test CT bandwith control option"
1817 local f=$DIR/$tdir/$tfile
1818 create_empty_file "$f"
1820 # Could not release a non-archived file
1821 $LFS hsm_release $f && error "release should not succeed"
1823 # For following tests, we must test them with HS_ARCHIVED set
1824 $LFS hsm_set --exists --archived $f || error "could not add flag"
1826 # Could not release a file if no-release is set
1827 $LFS hsm_set --norelease $f || error "could not add flag"
1828 $LFS hsm_release $f && error "release should not succeed"
1829 $LFS hsm_clear --norelease $f || error "could not remove flag"
1831 # Could not release a file if lost
1832 $LFS hsm_set --lost $f || error "could not add flag"
1833 $LFS hsm_release $f && error "release should not succeed"
1834 $LFS hsm_clear --lost $f || error "could not remove flag"
1836 # Could not release a file if dirty
1837 $LFS hsm_set --dirty $f || error "could not add flag"
1838 $LFS hsm_release $f && error "release should not succeed"
1839 $LFS hsm_clear --dirty $f || error "could not remove flag"
1841 run_test 20 "Release is not permitted"
1844 # test needs a running copytool
1847 local f=$DIR/$tdir/test_release
1849 # Create a file and check its states
1850 local fid=$(create_small_file $f)
1851 check_hsm_flags $f "0x00000000"
1853 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1854 # used until file is flushed to disk
1855 if [ $(facet_fstype ost1) == "zfs" ]; then
1856 # this causes an OST_SYNC rpc to be sent
1857 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1858 # clear locks to reread file data
1859 cancel_lru_locks osc
1862 local orig_size=$(stat -c "%s" $f)
1863 local orig_blocks=$(stat -c "%b" $f)
1865 start_full_debug_logging
1867 $LFS hsm_archive $f || error "could not archive file"
1868 wait_request_state $fid ARCHIVE SUCCEED
1870 local blocks=$(stat -c "%b" $f)
1871 [ $blocks -eq $orig_blocks ] ||
1872 error "$f: wrong block number after archive: " \
1873 "$blocks != $orig_blocks"
1874 local size=$(stat -c "%s" $f)
1875 [ $size -eq $orig_size ] ||
1876 error "$f: wrong size after archive: $size != $orig_size"
1878 # Release and check states
1879 $LFS hsm_release $f || error "could not release file"
1880 check_hsm_flags $f "0x0000000d"
1882 blocks=$(stat -c "%b" $f)
1883 [ $blocks -gt 5 ] &&
1884 error "$f: too many blocks after release: $blocks > 5"
1885 size=$(stat -c "%s" $f)
1886 [ $size -ne $orig_size ] &&
1887 error "$f: wrong size after release: $size != $orig_size"
1889 # Check we can release an file without stripe info
1893 check_hsm_flags $f "0x00000000"
1894 $LFS hsm_archive $f || error "could not archive file"
1895 wait_request_state $fid ARCHIVE SUCCEED
1897 # Release and check states
1898 $LFS hsm_release $f || error "could not release file"
1899 check_hsm_flags $f "0x0000000d"
1901 # Release again a file that is already released is OK
1902 $LFS hsm_release $f || fail "second release should succeed"
1903 check_hsm_flags $f "0x0000000d"
1905 stop_full_debug_logging
1907 run_test 21 "Simple release tests"
1910 # test needs a running copytool
1913 local f=$DIR/$tdir/test_release
1914 local swap=$DIR/$tdir/test_swap
1916 # Create a file and check its states
1917 local fid=$(create_small_file $f)
1918 check_hsm_flags $f "0x00000000"
1920 $LFS hsm_archive $f || error "could not archive file"
1921 wait_request_state $fid ARCHIVE SUCCEED
1923 # Release and check states
1924 $LFS hsm_release $f || error "could not release file"
1925 check_hsm_flags $f "0x0000000d"
1927 create_small_file $swap
1928 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1932 run_test 22 "Could not swap a release file"
1935 # test needs a running copytool
1938 local f=$DIR/$tdir/test_mtime
1940 # Create a file and check its states
1941 local fid=$(create_small_file $f)
1942 check_hsm_flags $f "0x00000000"
1944 $LFS hsm_archive $f || error "could not archive file"
1945 wait_request_state $fid ARCHIVE SUCCEED
1947 # Set modification time in the past
1948 touch -m -a -d @978261179 $f
1950 # Release and check states
1951 $LFS hsm_release $f || error "could not release file"
1952 check_hsm_flags $f "0x0000000d"
1954 local MTIME=$(stat -c "%Y" $f)
1955 local ATIME=$(stat -c "%X" $f)
1956 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1957 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1959 run_test 23 "Release does not change a/mtime (utime)"
1962 local file=$DIR/$tdir/$tfile
1971 # test needs a running copytool
1974 fid=$(create_small_file $file)
1976 # Create a file and check its states
1977 check_hsm_flags $file "0x00000000"
1979 # Ensure atime is less than mtime and ctime.
1983 atime0=$(stat -c "%X" $file)
1984 mtime0=$(stat -c "%Y" $file)
1985 ctime0=$(stat -c "%Z" $file)
1987 [ $atime0 -lt $mtime0 ] ||
1988 error "atime $atime0 is not less than mtime $mtime0"
1990 [ $atime0 -lt $ctime0 ] ||
1991 error "atime $atime0 is not less than ctime $ctime0"
1993 # Archive should not change any timestamps.
1994 $LFS hsm_archive $file || error "cannot archive '$file'"
1995 wait_request_state $fid ARCHIVE SUCCEED
1997 atime1=$(stat -c "%X" $file)
1998 mtime1=$(stat -c "%Y" $file)
1999 ctime1=$(stat -c "%Z" $file)
2001 [ $atime0 -eq $atime1 ] ||
2002 error "archive changed atime from $atime0 to $atime1"
2004 [ $mtime0 -eq $mtime1 ] ||
2005 error "archive changed mtime from $mtime0 to $mtime1"
2007 [ $ctime0 -eq $ctime1 ] ||
2008 error "archive changed ctime from $ctime0 to $ctime1"
2010 # Release should not change any timestamps.
2011 $LFS hsm_release $file || error "cannot release '$file'"
2012 check_hsm_flags $file "0x0000000d"
2014 atime1=$(stat -c "%X" $file)
2015 mtime1=$(stat -c "%Y" $file)
2016 ctime1=$(stat -c "%Z" $file)
2018 [ $atime0 -eq $atime1 ] ||
2019 error "release changed atime from $atime0 to $atime1"
2021 [ $mtime0 -eq $mtime1 ] ||
2022 error "release changed mtime from $mtime0 to $mtime1"
2024 [ $ctime0 -eq $ctime1 ] ||
2025 error "release changed ctime from $ctime0 to $ctime1"
2027 # Restore should not change any timestamps.
2028 $LFS hsm_restore $file
2029 wait_request_state $fid RESTORE SUCCEED
2031 atime1=$(stat -c "%X" $file)
2032 mtime1=$(stat -c "%Y" $file)
2033 ctime1=$(stat -c "%Z" $file)
2035 [ $atime0 -eq $atime1 ] ||
2036 error "restore changed atime from $atime0 to $atime1"
2038 [ $mtime0 -eq $mtime1 ] ||
2039 error "restore changed mtime from $mtime0 to $mtime1"
2041 [ $ctime0 -eq $ctime1 ] ||
2042 error "restore changed ctime from $ctime0 to $ctime1"
2045 wait_copytools || error "Copytools failed to stop"
2047 # Once more, after unmount and mount.
2048 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2049 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2051 atime1=$(stat -c "%X" $file)
2052 mtime1=$(stat -c "%Y" $file)
2053 ctime1=$(stat -c "%Z" $file)
2055 [ $atime0 -eq $atime1 ] ||
2056 error "remount changed atime from $atime0 to $atime1"
2058 [ $mtime0 -eq $mtime1 ] ||
2059 error "remount changed mtime from $mtime0 to $mtime1"
2061 [ $ctime0 -eq $ctime1 ] ||
2062 error "remount changed ctime from $ctime0 to $ctime1"
2064 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2067 local file=$DIR/$tdir/$tfile
2073 # Test needs a running copytool.
2076 # Check that root can do HSM actions on a regular user's file.
2077 fid=$(create_small_file $file)
2078 sum0=$(md5sum $file)
2080 chown $RUNAS_ID:$RUNAS_GID $file ||
2081 error "cannot chown '$file' to '$RUNAS_ID'"
2083 chmod ugo-w $DIR/$tdir ||
2084 error "cannot chmod '$DIR/$tdir'"
2086 $LFS hsm_archive $file
2087 wait_request_state $fid ARCHIVE SUCCEED
2089 $LFS hsm_release $file
2090 check_hsm_flags $file "0x0000000d"
2092 $LFS hsm_restore $file
2093 wait_request_state $fid RESTORE SUCCEED
2095 # Check that ordinary user can get HSM state.
2096 $RUNAS $LFS hsm_state $file ||
2097 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2099 $LFS hsm_release $file
2100 check_hsm_flags $file "0x0000000d"
2102 # Check that ordinary user can accessed released file.
2103 sum1=$($RUNAS md5sum $file) ||
2104 error "user '$RUNAS_ID' cannot read '$file'"
2106 [ "$sum0" == "$sum1" ] ||
2107 error "md5sum mismatch for '$file'"
2109 run_test 24b "root can archive, release, and restore user files"
2112 local file=$DIR/$tdir/$tfile
2113 local action=archive
2118 # test needs a running copytool
2123 # Save the default masks and check that cleanup_24c will
2124 # restore the request masks correctly.
2125 user_save=$(get_hsm_param user_request_mask)
2126 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2127 group_save=$(get_hsm_param group_request_mask)
2128 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2129 other_save=$(get_hsm_param other_request_mask)
2130 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2132 [ "$user_save" == RESTORE ] ||
2133 error "user_request_mask is '$user_save' expected 'RESTORE'"
2134 [ "$group_save" == RESTORE ] ||
2135 error "group_request_mask is '$group_save' expected 'RESTORE'"
2136 [ "$other_save" == RESTORE ] ||
2137 error "other_request_mask is '$other_save' expected 'RESTORE'"
2140 create_small_file $file
2141 chown $RUNAS_ID:$GROUP $file ||
2142 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2144 $RUNAS $LFS hsm_$action $file &&
2145 error "$action by user should fail"
2147 set_hsm_param user_request_mask $action
2148 $RUNAS $LFS hsm_$action $file ||
2149 error "$action by user should succeed"
2152 create_small_file $file
2153 chown nobody:$RUNAS_GID $file ||
2154 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2156 $RUNAS $LFS hsm_$action $file &&
2157 error "$action by group should fail"
2159 set_hsm_param group_request_mask $action
2160 $RUNAS $LFS hsm_$action $file ||
2161 error "$action by group should succeed"
2164 create_small_file $file
2165 chown nobody:$GROUP $file ||
2166 error "cannot chown '$file' to 'nobody:$GROUP'"
2168 $RUNAS $LFS hsm_$action $file &&
2169 error "$action by other should fail"
2171 set_hsm_param other_request_mask $action
2172 $RUNAS $LFS hsm_$action $file ||
2173 error "$action by other should succeed"
2175 run_test 24c "check that user,group,other request masks work"
2178 local file1=$DIR/$tdir/$tfile
2179 local file2=$DIR2/$tdir/$tfile
2183 fid1=$(create_small_file $file1)
2186 $LFS getstripe $file1
2188 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2189 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2190 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2192 copytool setup -m "$MOUNT3"
2194 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2195 mount -o remount,ro $MOUNT2
2197 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2199 fid2=$(path2fid $file2)
2200 [ "$fid1" == "$fid2" ] ||
2201 error "FID mismatch '$fid1' != '$fid2'"
2203 $LFS hsm_archive $file2 &&
2204 error "archive should fail on read-only mount"
2205 check_hsm_flags $file1 "0x00000000"
2207 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2208 wait_request_state $fid1 ARCHIVE SUCCEED
2210 $LFS hsm_release $file1
2211 $LFS hsm_restore $file2
2212 wait_request_state $fid1 RESTORE SUCCEED
2214 $LFS hsm_release $file1 || error "cannot release '$file1'"
2215 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2217 $LFS hsm_release $file2 &&
2218 error "release should fail on read-only mount"
2222 run_test 24d "check that read-only mounts are respected"
2227 local f=$DIR/$tdir/$tfile
2230 fid=$(create_small_file $f) || error "cannot create $f"
2231 $LFS hsm_archive $f || error "cannot archive $f"
2232 wait_request_state $fid ARCHIVE SUCCEED
2233 $LFS hsm_release $f || error "cannot release $f"
2234 while ! $LFS hsm_state $f | grep released; do
2238 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2240 run_test 24e "tar succeeds on HSM released files" # LU-6213
2243 # test needs a running copytool
2246 mkdir -p $DIR/$tdir/d1
2247 local f=$DIR/$tdir/$tfile
2248 local fid=$(copy_file /etc/hosts $f)
2251 $LFS hsm_archive $f ||
2252 error "hsm_archive failed"
2253 wait_request_state $fid ARCHIVE SUCCEED
2254 $LFS hsm_release $f || error "cannot release $f"
2255 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2258 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2259 error "Can not recover the tar contents"
2261 echo "Sum0 = $sum0, sum1 = $sum1"
2262 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2264 run_test 24f "root can archive, release, and restore tar files"
2267 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2268 skip "need MDS version 2.11.56 or later"
2270 local file=$DIR/$tdir/$tfile
2273 echo "RUNAS = '$RUNAS'"
2278 chmod ugo+rwx $DIR/$tdir
2280 echo "Please listen carefully as our options have changed." | tee $file
2281 fid=$(path2fid $file)
2284 $LFS hsm_archive $file
2285 wait_request_state $fid ARCHIVE SUCCEED
2286 check_hsm_flags $file 0x00000009 # exists archived
2288 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2289 check_hsm_flags $file 0x0000000b # exists dirty archived
2291 run_test 24g "write by non-owner still sets dirty" # LU-11369
2294 # test needs a running copytool
2298 copy2archive /etc/hosts $tdir/$tfile
2300 local f=$DIR/$tdir/$tfile
2302 copytool import $tdir/$tfile $f
2304 $LFS hsm_set --lost $f
2309 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2311 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2312 " (Operation not permitted)"
2315 # test needs a running copytool
2320 local f=$DIR/$tdir/$tfile
2321 local fid=$(copy_file /etc/passwd $f)
2323 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2324 wait_request_state $fid ARCHIVE SUCCEED
2327 $LFS hsm_set --lost $f
2331 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2333 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2334 " (Operation not permitted)"
2336 test_26A() { # was test_26
2337 # test needs a running copytool
2340 local f=$DIR/$tdir/$tfile
2341 local fid=$(create_empty_file "$f")
2343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2344 wait_request_state $fid ARCHIVE SUCCEED
2347 wait_request_state $fid REMOVE SUCCEED
2349 check_hsm_flags $f "0x00000000"
2351 run_test 26A "Remove the archive of a valid file"
2354 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2355 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2357 # test needs a running copytool
2361 local f=$DIR/$tdir/$tfile
2362 local fid=$(copy_file /etc/passwd $f)
2364 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2365 wait_request_state $fid ARCHIVE SUCCEED
2367 local f2=$DIR/$tdir/${tfile}_2
2368 local fid2=$(copy_file /etc/passwd $f2)
2370 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2371 wait_request_state $fid2 ARCHIVE SUCCEED
2373 local f3=$DIR/$tdir/${tfile}_3
2374 local fid3=$(copy_file /etc/passwd $f3)
2376 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2377 wait_request_state $fid3 ARCHIVE SUCCEED
2379 # set a long grace_delay vs short loop_period
2380 local orig_loop_period=$(get_hsm_param loop_period)
2381 local orig_grace_delay=$(get_hsm_param grace_delay)
2382 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2383 set_hsm_param loop_period 10
2384 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2385 set_hsm_param grace_delay 100
2389 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2390 set_hsm_param remove_archive_on_last_unlink 1
2392 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2397 wait_request_state $fid2 REMOVE SUCCEED
2399 assert_request_count $fid REMOVE 0 \
2400 "Unexpected archived data remove request for $f"
2401 assert_request_count $fid3 REMOVE 0 \
2402 "Unexpected archived data remove request for $f3"
2404 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2407 # test needs a running copytool
2411 local f=$DIR/$tdir/$tfile
2412 local fid=$(copy_file /etc/passwd $f)
2414 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2415 wait_request_state $fid ARCHIVE SUCCEED
2417 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2418 set_hsm_param remove_archive_on_last_unlink 1
2421 cdt_check_state stopped
2425 wait_request_state $fid REMOVE WAITING
2429 # copytool must re-register
2431 wait_copytools || error "copytool failed to stop"
2434 wait_request_state $fid REMOVE SUCCEED
2436 run_test 26b "RAoLU policy when CDT off"
2439 # test needs a running copytool
2443 local f=$DIR/$tdir/$tfile
2444 local fid=$(copy_file /etc/passwd $f)
2446 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2447 wait_request_state $fid ARCHIVE SUCCEED
2449 local f2=$DIR/$tdir/${tfile}_2
2450 local fid2=$(copy_file /etc/passwd $f2)
2452 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2453 wait_request_state $fid2 ARCHIVE SUCCEED
2455 # set a long grace_delay vs short loop_period
2456 local orig_loop_period=$(get_hsm_param loop_period)
2457 local orig_grace_delay=$(get_hsm_param grace_delay)
2458 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2459 set_hsm_param loop_period 10
2460 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2461 set_hsm_param grace_delay 100
2463 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2464 set_hsm_param remove_archive_on_last_unlink 1
2466 multiop_bg_pause $f O_c || error "open $f failed"
2472 wait_request_state $fid2 REMOVE SUCCEED
2473 assert_request_count $fid REMOVE 0 \
2474 "Unexpected archived data remove request for $f"
2476 kill -USR1 $pid || error "multiop early exit"
2477 # should reach autotest timeout if multiop fails to trap
2478 # signal, close file, and exit ...
2479 wait $pid || error "wait PID $PID failed"
2481 wait_request_state $fid REMOVE SUCCEED
2483 run_test 26c "RAoLU effective when file closed"
2486 # test needs a running copytool
2490 local f=$DIR/$tdir/$tfile
2491 local fid=$(create_small_file $f)
2493 $LFS hsm_archive $f || error "could not archive file"
2494 wait_request_state $fid ARCHIVE SUCCEED
2496 # set a long grace_delay vs short loop_period
2497 local orig_loop_period=$(get_hsm_param loop_period)
2498 local orig_grace_delay=$(get_hsm_param grace_delay)
2499 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2500 set_hsm_param loop_period 10
2501 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2502 set_hsm_param grace_delay 100
2504 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2505 set_hsm_param remove_archive_on_last_unlink 1
2507 multiop_bg_pause $f O_c || error "multiop failed"
2514 wait_request_state $fid REMOVE SUCCEED
2516 client_up || client_up || true
2518 kill -USR1 $MULTIPID
2519 wait $MULTIPID || error "multiop close failed"
2521 run_test 26d "RAoLU when Client eviction"
2524 # test needs a running copytool
2527 create_archive_file $tdir/$tfile
2528 local f=$DIR/$tdir/$tfile
2529 copytool import $tdir/$tfile $f
2530 local fid=$(path2fid $f)
2534 [[ $? != 0 ]] || error "Remove of a released file should fail"
2536 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2539 # test needs a running copytool
2542 local f=$DIR/$tdir/$tfile
2543 local fid=$(create_empty_file "$f")
2545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2546 wait_request_state $fid ARCHIVE SUCCEED
2551 [[ $? != 0 ]] || error "Remove of a released file should fail"
2553 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2556 # test needs a running copytool
2559 local f=$DIR/$tdir/$tfile
2560 local fid=$(create_empty_file "$f")
2562 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2563 wait_request_state $fid ARCHIVE SUCCEED
2572 wait_request_state $fid REMOVE SUCCEED
2574 run_test 28 "Concurrent archive/file remove"
2577 # Tests --mntpath and --archive options
2580 copytool setup -m "$MOUNT" -a $archive_id
2582 # Bad archive number
2583 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2584 grep "Invalid argument" ||
2585 error "unexpected hsm_remove failure (1)"
2587 # mntpath is present but file is given
2588 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2589 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2590 error "unexpected hsm_remove failure (2)"
2592 run_test 29a "Tests --mntpath and --archive options"
2595 # test needs a running copytool
2598 local f=$DIR/$tdir/$tfile
2599 local fid=$(create_small_file $f)
2601 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2602 wait_request_state $fid ARCHIVE SUCCEED
2606 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2607 wait_request_state $fid REMOVE SUCCEED
2609 run_test 29b "Archive/delete/remove by FID from the archive."
2612 # test needs a running copytool
2615 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2616 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2617 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2619 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2620 wait_request_state $fid1 ARCHIVE SUCCEED
2621 wait_request_state $fid2 ARCHIVE SUCCEED
2622 wait_request_state $fid3 ARCHIVE SUCCEED
2624 rm -f $DIR/$tdir/$tfile-[1-3]
2626 echo $fid1 > $DIR/$tdir/list
2627 echo $fid2 >> $DIR/$tdir/list
2628 echo $fid3 >> $DIR/$tdir/list
2630 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2631 --filelist $DIR/$tdir/list
2632 wait_request_state $fid1 REMOVE SUCCEED
2633 wait_request_state $fid2 REMOVE SUCCEED
2634 wait_request_state $fid3 REMOVE SUCCEED
2636 run_test 29c "Archive/delete/remove by FID, using a file list."
2639 # test needs more than one CT
2640 needclients 3 || return 0
2646 # start all of the copytools
2647 for n in $(seq $AGTCOUNT); do
2648 copytool setup -f agt$n -a $n
2652 file=$DIR/$tdir/$tfile
2653 fid=$(create_small_file $file)
2655 $LFS hsm_archive $file
2656 wait_request_state $fid ARCHIVE SUCCEED
2657 check_hsm_flags $file "0x00000009"
2661 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2662 error "cannot hsm_remove '$fid'"
2664 # give time for CDT to handle remove request and create broadcasted
2667 # remove request has been broadcasted ?
2668 local cnt=$(get_request_count $fid REMOVE)
2669 # broadcasted requests + original
2670 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2671 error "remove not broadcasted to all CTs"
2673 # give time for CDT and CTs to handle broadcasted
2674 wait_for_loop_period
2676 # each agent serves one different archive_id, so broadcasted
2677 # hsm_remove request should only succeed once and fail at all others
2681 for n in $(seq $AGTCOUNT); do
2682 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2683 $HSM_PARAM.actions | awk \
2684 '/'$fid'.*action=REMOVE archive#='$n'/ \
2685 {print \\\$13}' | cut -f2 -d=")
2686 if [[ "$res" == "SUCCEED" ]]; then
2688 elif [[ "$res" == "FAILED" ]]; then
2693 [[ $scnt -eq 1 ]] ||
2694 error "one and only CT should have removed successfully"
2696 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2697 error "all but one CT should have failed to remove"
2699 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2700 "request to be sent once for each registered archive_id"
2703 # restore at exec cannot work on agent node (because of Linux kernel
2704 # protection of executables)
2705 needclients 2 || return 0
2707 # test needs a running copytool
2711 copy2archive /bin/true $tdir/$tfile
2713 local f=$DIR/$tdir/true
2714 copytool import $tdir/$tfile $f
2716 local fid=$(path2fid $f)
2718 stack_trap "cdt_clear_no_retry" EXIT
2719 # set no retry action mode
2726 [[ $st == 0 ]] || error "Failed to exec a released file"
2728 run_test 30a "Restore at exec (import case)"
2731 # restore at exec cannot work on agent node (because of Linux kernel
2732 # protection of executables)
2733 needclients 2 || return 0
2735 # test needs a running copytool
2739 local f=$DIR/$tdir/true
2740 local fid=$(copy_file /bin/true $f)
2742 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2743 wait_request_state $fid ARCHIVE SUCCEED
2747 stack_trap cdt_clear_no_retry EXIT
2748 # set no retry action mode
2756 [[ $st == 0 ]] || error "Failed to exec a released file"
2758 run_test 30b "Restore at exec (release case)"
2761 needclients 2 || return 0
2763 # test needs a running copytool
2767 local f=$DIR/$tdir/SLEEP
2768 local slp_sum1=$(md5sum /bin/sleep)
2769 local fid=$(copy_file /bin/sleep $f)
2771 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2772 wait_request_state $fid ARCHIVE SUCCEED
2774 check_hsm_flags $f "0x0000000d"
2776 stack_trap cdt_clear_no_retry EXIT
2777 # set no retry action mode
2780 do_node $CLIENT2 "$f 10" &
2784 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2786 [[ $? == 0 ]] || error "Execution failed during run"
2788 if [[ $? != 0 ]]; then
2789 local slp_sum2=$(md5sum /bin/sleep)
2790 # in case sleep file is modified during the test
2791 [[ $slp_sum1 == $slp_sum2 ]] &&
2792 error "Binary overwritten during exec"
2795 check_hsm_flags $f "0x00000009"
2797 run_test 30c "Update during exec of released file must fail"
2799 restore_and_check_size() {
2802 local s=$(stat -c "%s" $f)
2804 local st=$(get_hsm_flags $f)
2808 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2810 n=$(stat -c "%s" $f)
2811 # we echo in both cases to show stat is not hang
2812 if [[ $n != $s ]]; then
2813 echo "size seen is $n != $s"
2816 echo "size seen is right: $n == $s"
2820 st=$(get_hsm_flags $f)
2822 if [[ "$st" = "0x00000009" ]]; then
2825 echo " restore is too long"
2826 wait_request_state $fid RESTORE SUCCEED
2832 # test needs a running copytool
2835 create_archive_file $tdir/$tfile
2836 local f=$DIR/$tdir/$tfile
2837 copytool import $tdir/$tfile $f
2838 local fid=$($LFS path2fid $f)
2841 restore_and_check_size $f $fid
2844 [[ $err -eq 0 ]] || error "File size changed during restore"
2846 run_test 31a "Import a large file and check size during restore"
2850 # test needs a running copytool
2853 local f=$DIR/$tdir/$tfile
2854 local fid=$(create_file "$f" 1MB 39)
2856 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2857 wait_request_state $fid ARCHIVE SUCCEED
2860 restore_and_check_size $f $fid
2863 [[ $err -eq 0 ]] || error "File size changed during restore"
2865 run_test 31b "Restore a large unaligned file and check size during restore"
2868 # test needs a running copytool
2871 local f=$DIR/$tdir/$tfile
2872 local fid=$(create_file "$f" 1M 39)
2874 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2875 wait_request_state $fid ARCHIVE SUCCEED
2878 restore_and_check_size $f $fid
2881 [[ $err -eq 0 ]] || error "File size changed during restore"
2883 run_test 31c "Restore a large aligned file and check size during restore"
2886 local f=$DIR/$tdir/$tfile
2887 local fid=$(create_empty_file "$f")
2891 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2892 wait_request_state $fid ARCHIVE SUCCEED
2895 # Prevent restore from completing
2899 md5sum $f >/dev/null &
2902 wait_request_state $fid RESTORE STARTED
2907 # Check restore trigger process was killed
2909 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2911 run_test 33 "Kill a restore waiting process"
2914 # test needs a running copytool
2917 local f=$DIR/$tdir/$tfile
2918 local fid=$(create_empty_file "$f")
2920 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2921 wait_request_state $fid ARCHIVE SUCCEED
2924 # Prevent restore from completing
2927 md5sum $f >/dev/null &
2930 wait_request_state $fid RESTORE STARTED
2932 # rm must not block during restore
2933 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2936 wait_request_state $fid RESTORE SUCCEED
2938 # Check md5sum pgm finished
2939 kill -0 $pid && error "Restore initiatior still running"
2940 wait $pid || error "Restore initiator failed with $?"
2942 # Check the file was actually deleted
2943 [ ! -f "$f" ] || error "$f was not deleted"
2945 run_test 34 "Remove file during restore"
2948 # test needs a running copytool
2951 local f=$DIR/$tdir/$tfile
2952 local f1=$DIR/$tdir/$tfile-1
2953 local fid=$(create_empty_file "$f")
2954 local fid1=$(copy_file /etc/passwd $f1)
2956 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2957 wait_request_state $fid ARCHIVE SUCCEED
2960 # Prevent restore from completing
2963 md5sum $f >/dev/null &
2966 wait_request_state $fid RESTORE STARTED
2968 # mv must not block during restore
2969 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2972 wait_request_state $fid RESTORE SUCCEED
2974 # Check md5sum pgm finished
2975 kill -0 $pid && error "Restore initiatior still running"
2976 wait $pid || error "Restore initiator failed with $?"
2978 local fid2=$(path2fid $f)
2979 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2981 run_test 35 "Overwrite file during restore"
2984 # test needs a running copytool
2987 local f=$DIR/$tdir/$tfile
2988 local fid=$(create_empty_file "$f")
2990 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2991 wait_request_state $fid ARCHIVE SUCCEED
2994 # Prevent restore from completing
2997 md5sum $f >/dev/null &
3000 wait_request_state $fid RESTORE STARTED
3002 # mv must not block during restore
3003 timeout --signal=KILL 10 mv "$f" "$f.new" ||
3004 error "mv '$f' '$f.new' failed with rc=$?"
3007 wait_request_state $fid RESTORE SUCCEED
3009 # Check md5sum pgm finished
3010 kill -0 $pid && error "Restore initiator is still running"
3011 wait $pid || error "Restore initiator failed with $?"
3013 run_test 36 "Move file during restore"
3016 # LU-5683: check that an archived dirty file can be rearchived.
3019 local f=$DIR/$tdir/$tfile
3022 fid=$(create_small_file $f) || error "cannot create small file"
3024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3025 wait_request_state $fid ARCHIVE SUCCEED
3026 $LFS hsm_release $f || error "cannot release $f"
3028 # Allow previous archive request to expire from the actions log.
3029 wait_for_grace_delay
3032 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3034 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3035 wait_request_state $fid ARCHIVE SUCCEED
3037 run_test 37 "re-archive a dirty file"
3044 for n in $(seq 1 $count); do
3045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3047 echo "$count archive requests submitted"
3051 local stream_count=4
3052 local file_count=100
3054 local f=$DIR/$tdir/$tfile
3058 local max_requests=$(get_hsm_param max_requests)
3060 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3061 # Increase the number of HSM request that can be performed in
3062 # parallel. With the coordinator running once per second, this
3063 # also limits the number of requests per seconds that can be
3064 # performed, so we pick a decent number. But we also need to keep
3065 # that number low because the copytool has no rate limit and will
3066 # fail some requests if if gets too many at once.
3067 set_hsm_param max_requests 300
3069 for i in $(seq 1 $file_count); do
3070 for p in $(seq 1 $stream_count); do
3071 fid=$(copy_file /etc/hosts $f.$p.$i)
3077 # to be sure wait_all_done will not be mislead by previous tests
3079 wait_for_grace_delay
3081 # start archive streams in background (archive files in parallel)
3082 for p in $(seq 1 $stream_count); do
3083 multi_archive $f.$p $file_count &
3086 echo -n "Wait for all requests being enqueued..."
3091 run_test 40 "Parallel archive requests"
3094 # test needs a running copytool
3098 local f=$DIR/$tdir/$tfile
3099 local fid=$(create_small_file $f)
3101 $LFS hsm_archive $f || error "could not archive file"
3102 wait_request_state $fid ARCHIVE SUCCEED
3103 check_hsm_flags $f "0x00000009"
3105 multiop_bg_pause $f O_c || error "multiop failed"
3109 client_up || client_up || true
3111 kill -USR1 $MULTIPID
3112 wait $MULTIPID || error "multiop close failed"
3114 check_hsm_flags $f "0x0000000b"
3116 run_test 52 "Opened for write file on an evicted client should be set dirty"
3119 # test needs a running copytool
3123 local f=$DIR/$tdir/$tfile
3124 local fid=$(create_small_file $f)
3126 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3127 error "could not archive file"
3128 wait_request_state $fid ARCHIVE SUCCEED
3129 check_hsm_flags $f "0x00000009"
3131 multiop_bg_pause $f o_c || error "multiop failed"
3135 client_up || client_up || true
3137 kill -USR1 $MULTIPID
3138 wait $MULTIPID || error "multiop close failed"
3140 check_hsm_flags $f "0x00000009"
3142 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3145 local f=$DIR/$tdir/$tfile
3146 local fid=$(create_file "$f" 1MB 39)
3150 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3151 error "could not archive file"
3152 wait_request_state $fid ARCHIVE STARTED
3154 check_hsm_flags $f "0x00000001"
3156 stack_trap "cdt_clear_no_retry" EXIT
3157 # Avoid coordinator resending this request as soon it has failed.
3162 wait_request_state $fid ARCHIVE FAILED
3164 check_hsm_flags $f "0x00000003"
3166 run_test 54 "Write during an archive cancels it"
3169 local f=$DIR/$tdir/$tfile
3170 local fid=$(create_file "$f" 1MB 39)
3174 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3175 error "could not archive file"
3176 wait_request_state $fid ARCHIVE STARTED
3178 check_hsm_flags $f "0x00000001"
3180 stack_trap "cdt_clear_no_retry" EXIT
3181 # Avoid coordinator resending this request as soon it has failed.
3184 $TRUNCATE $f 1024 || error "truncate failed"
3186 wait_request_state $fid ARCHIVE FAILED
3188 check_hsm_flags $f "0x00000003"
3190 run_test 55 "Truncate during an archive cancels it"
3193 local f=$DIR/$tdir/$tfile
3194 local fid=$(create_file "$f" 1MB 39)
3198 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3199 error "could not archive file"
3200 wait_request_state $fid ARCHIVE STARTED
3202 check_hsm_flags $f "0x00000001"
3204 # Change metadata and sync to be sure we are not changing only
3209 wait_request_state $fid ARCHIVE SUCCEED
3211 check_hsm_flags $f "0x00000009"
3213 run_test 56 "Setattr during an archive is ok"
3216 # Need one client for I/O, one for request
3217 needclients 2 || return 0
3219 # test needs a running copytool
3223 local f=$DIR/$tdir/test_archive_remote
3224 # Create a file on a remote node
3225 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3226 "count=2 conv=fsync"
3229 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3230 error "hsm_archive failed"
3231 local fid=$(path2fid $f)
3232 wait_request_state $fid ARCHIVE SUCCEED
3234 # Release and implicit restore it
3235 do_node $CLIENT2 "$LFS hsm_release $f" ||
3236 error "hsm_release failed"
3237 do_node $CLIENT2 "md5sum $f" ||
3238 error "hsm_restore failed"
3240 wait_request_state $fid RESTORE SUCCEED
3242 run_test 57 "Archive a file with dirty cache on another node"
3244 truncate_released_file() {
3248 local sz=$(stat -c %s $src_file)
3249 local f=$DIR/$tdir/$tfile
3250 local fid=$(copy_file $1 $f)
3254 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3255 error "could not archive file"
3256 wait_request_state $fid ARCHIVE SUCCEED
3258 $LFS hsm_release $f || error "could not release file"
3260 $TRUNCATE $f $trunc_to || error "truncate failed"
3263 local sz1=$(stat -c %s $f)
3264 [[ $sz1 == $trunc_to ]] ||
3265 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3268 check_hsm_flags $f "0x0000000b"
3270 local state=$(get_request_state $fid RESTORE)
3271 [[ "$state" == "SUCCEED" ]] ||
3272 error "truncate $sz does not trig restore, state = $state"
3274 $TRUNCATE $ref $trunc_to
3275 cmp $ref $f || error "file data wrong after truncate"
3281 # test needs a running copytool
3286 local sz=$(stat -c %s /etc/passwd)
3288 echo "truncate up from $sz to $((sz*2))"
3289 truncate_released_file /etc/passwd $((sz*2))
3291 echo "truncate down from $sz to $((sz/2))"
3292 truncate_released_file /etc/passwd $((sz/2))
3294 echo "truncate to 0"
3295 truncate_released_file /etc/passwd 0
3297 run_test 58 "Truncate a released file will trigger restore"
3301 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3302 skip "Need MDS version at least 2.7.63"
3305 $MCREATE $DIR/$tfile || error "mcreate failed"
3306 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3307 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3308 fid=$(path2fid $DIR/$tfile)
3309 wait_request_state $fid ARCHIVE SUCCEED
3310 $LFS hsm_release $DIR/$tfile || error "release failed"
3312 run_test 59 "Release stripeless file with non-zero size"
3315 # This test validates the fix for LU-4512. Ensure that the -u
3316 # option changes the progress reporting interval from the
3317 # default (30 seconds) to the user-specified interval.
3318 local f=$DIR/$tdir/$tfile
3319 local fid=$(create_file "$f" 1M 10)
3322 local progress_timeout=$((interval * 4))
3323 copytool setup -b 1 --update-interval $interval
3326 local mdt=${MDT_PREFIX}${mdtidx}
3327 local mds=mds$((mdtidx + 1))
3329 # Wait for copytool to register
3330 wait_update_facet $mds \
3331 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3332 uuid 100 || error "coyptool failed to register with $mdt"
3334 local start_at=$(date +%s)
3335 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3336 error "could not archive file"
3338 local agent=$(facet_active_host $SINGLEAGT)
3339 local logfile=$(copytool_logfile $SINGLEAGT)
3341 wait_update $agent \
3342 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3343 error "copytool failed to start"
3345 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3346 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3352 echo -n "Expecting a progress update within $progress_timeout seconds... "
3354 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3355 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3356 echo "$RESULT bytes copied in $WAIT seconds."
3358 elif [ $WAIT -ge $progress_timeout ]; then
3359 error "Timed out waiting for progress update!"
3362 WAIT=$((WAIT + sleep))
3366 local finish_at=$(date +%s)
3367 local elapsed=$((finish_at - start_at))
3369 # Ensure that the progress update occurred within the expected window.
3370 if [ $elapsed -lt $((interval - 1)) ]; then
3371 error "Expected progress update after at least $interval seconds"
3374 echo "Wait for on going archive hsm action to complete"
3375 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3376 echo "File archiving not completed even after 10 secs"
3378 run_test 60 "Changing progress update interval from default"
3381 # test needs a running copytool
3385 local f=$DIR/$tdir/$tfile
3386 local fid=$(copy_file /etc/passwd $f)
3388 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3391 wait_request_state $fid ARCHIVE FAILED
3393 run_test 61 "Waiting archive of a removed file should fail"
3396 # test needs a new running copytool
3397 stack_trap copytool_monitor_cleanup EXIT
3398 copytool_monitor_setup
3399 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3401 # Wait for the copytool to register.
3402 wait_update --verbose $(facet_active_host mds1) \
3403 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3405 error "copytool failed to register with MDT0000"
3408 wait_copytools || error "Copytools failed to stop"
3410 local REGISTER_EVENT
3411 local UNREGISTER_EVENT
3412 while read event; do
3413 local parsed=$(parse_json_event "$event")
3414 if [ -z "$parsed" ]; then
3415 error "Copytool sent malformed event: $event"
3419 if [ $event_type == "REGISTER" ]; then
3420 REGISTER_EVENT=$event
3421 elif [ $event_type == "UNREGISTER" ]; then
3422 UNREGISTER_EVENT=$event
3424 done < <(echo $"$(get_copytool_event_log)")
3426 if [ -z "$REGISTER_EVENT" ]; then
3427 error "Copytool failed to send register event to FIFO"
3430 if [ -z "$UNREGISTER_EVENT" ]; then
3431 error "Copytool failed to send unregister event to FIFO"
3434 echo "Register/Unregister events look OK."
3436 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3439 # Bump progress interval for livelier events.
3442 # test needs a new running copytool
3443 stack_trap copytool_monitor_cleanup EXIT
3444 copytool_monitor_setup
3445 copytool setup --update-interval $interval --event-fifo \
3446 "$HSMTOOL_MONITOR_DIR/fifo"
3448 stack_trap "cdt_clear_no_retry" EXIT
3449 # Just start and stop the copytool to generate events.
3452 local f=$DIR/$tdir/$tfile
3453 local fid=$(create_small_file "$f")
3455 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3456 error "could not archive file"
3457 wait_request_state $fid ARCHIVE SUCCEED
3459 local expected_fields="event_time data_fid source_fid"
3460 expected_fields+=" total_bytes current_bytes"
3463 [ARCHIVE_START]=false
3464 [ARCHIVE_FINISH]=false
3465 [ARCHIVE_RUNNING]=false
3467 while read event; do
3468 # Make sure we're not getting anything from previous events.
3469 for field in $expected_fields; do
3473 local parsed=$(parse_json_event "$event")
3474 if [ -z "$parsed" ]; then
3475 error "Copytool sent malformed event: $event"
3479 events["$event_type"]=true
3481 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3483 # Do some simple checking of the progress update events.
3484 for expected_field in $expected_fields; do
3485 if [ -z ${!expected_field+x} ]; then
3486 error "Missing $expected_field field in event"
3490 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3492 # These should be identical throughout an archive operation
3493 [ $source_fid == $data_fid ] ||
3494 error "Expected source_fid to equal data_fid"
3495 done < <(echo $"$(get_copytool_event_log)")
3497 # Check we received every type of events we were expecting
3498 for event in "${!events[@]}"; do
3499 ${events["$event"]} ||
3500 error "Copytool failed to send '$event' event to FIFO"
3503 echo "Archive events look OK."
3505 run_test 71 "Copytool logs JSON archive events to FIFO"
3508 # Bump progress interval for livelier events.
3511 # test needs a new running copytool
3512 stack_trap copytool_monitor_cleanup EXIT
3513 copytool_monitor_setup
3514 copytool setup --update-interval $interval --event-fifo \
3515 "$HSMTOOL_MONITOR_DIR/fifo"
3516 local test_file=$HSMTOOL_MONITOR_DIR/file
3518 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3520 do_facet $SINGLEAGT "$cmd" ||
3521 error "cannot create $test_file on $SINGLEAGT"
3522 copy2archive $test_file $tdir/$tfile
3525 local f=$DIR/$tdir/$tfile
3526 copytool import $tdir/$tfile $f
3527 f=$DIR2/$tdir/$tfile
3528 echo "Verifying released state: "
3529 check_hsm_flags $f "0x0000000d"
3531 local fid=$(path2fid $f)
3533 wait_request_state $fid RESTORE SUCCEED
3535 local expected_fields="event_time data_fid source_fid"
3536 expected_fields+=" total_bytes current_bytes"
3540 while read event; do
3541 # Make sure we're not getting anything from previous events.
3542 for field in $expected_fields; do
3546 local parsed=$(parse_json_event "$event")
3547 if [ -z "$parsed" ]; then
3548 error "Copytool sent malformed event: $event"
3552 if [ $event_type == "RESTORE_START" ]; then
3554 if [ $source_fid != $data_fid ]; then
3555 error "source_fid should == data_fid at start"
3558 elif [ $event_type == "RESTORE_FINISH" ]; then
3560 if [ $source_fid != $data_fid ]; then
3561 error "source_fid should == data_fid at finish"
3564 elif [ $event_type != "RESTORE_RUNNING" ]; then
3568 # Do some simple checking of the progress update events.
3569 for expected_field in $expected_fields; do
3570 if [ -z ${!expected_field+x} ]; then
3571 error "Missing $expected_field field in event"
3575 if [ $total_bytes -eq 0 ]; then
3576 error "Expected total_bytes to be > 0"
3579 # When a restore starts out, the data fid is the same as the
3580 # source fid. After the restore has gotten going, we learn
3581 # the new data fid. Once the restore has finished, the source
3582 # fid is set to the new data fid.
3584 # We test this because some monitoring software may depend on
3585 # this behavior. If it changes, then the consumers of these
3586 # events may need to be modified.
3587 if [ $source_fid == $data_fid ]; then
3588 error "source_fid should != data_fid during restore"
3590 done < <(echo $"$(get_copytool_event_log)")
3592 if [ -z "$START_EVENT" ]; then
3593 error "Copytool failed to send restore start event to FIFO"
3596 if [ -z "$FINISH_EVENT" ]; then
3597 error "Copytool failed to send restore finish event to FIFO"
3600 echo "Restore events look OK."
3602 run_test 72 "Copytool logs JSON restore events to FIFO"
3605 file_count=51 # Max number of files constrained by LNET message size
3606 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3607 local f=$DIR/$tdir/$tfile
3608 local FILELIST=/tmp/filelist.txt
3612 for i in $(seq 1 $file_count); do
3613 fid=$(copy_file /etc/hosts $f.$i)
3614 echo $f.$i >> $FILELIST
3618 # to be sure wait_all_done will not be mislead by previous tests
3620 wait_for_grace_delay
3621 $LFS hsm_archive --filelist $FILELIST ||
3622 error "cannot archive a file list"
3624 $LFS hsm_release --filelist $FILELIST ||
3625 error "cannot release a file list"
3626 $LFS hsm_restore --filelist $FILELIST ||
3627 error "cannot restore a file list"
3630 run_test 90 "Archive/restore a file list"
3632 double_verify_reset_hsm_param() {
3634 echo "Testing $HSM_PARAM.$p"
3635 local val=$(get_hsm_param $p)
3637 local val2=$(($val * 2))
3638 set_hsm_param $p $val2
3639 val=$(get_hsm_param $p)
3640 [[ $val == $val2 ]] ||
3641 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3642 echo "Set $p to 0 must failed"
3646 set_hsm_param $p $save
3648 if [[ $rc == 0 ]]; then
3649 error "we must not be able to set $HSM_PARAM.$p to 0"
3654 double_verify_reset_hsm_param loop_period
3655 double_verify_reset_hsm_param grace_delay
3656 double_verify_reset_hsm_param active_request_timeout
3657 double_verify_reset_hsm_param max_requests
3658 double_verify_reset_hsm_param default_archive_id
3660 run_test 100 "Set coordinator /proc tunables"
3667 run_test 102 "Verify coordinator control"
3670 # test needs a running copytool
3677 for i in $(seq 1 20); do
3678 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3680 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3684 echo "Current requests"
3685 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3686 $HSM_PARAM.actions |\
3687 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3689 [[ -z "$res" ]] || error "Some request have not been canceled"
3691 run_test 103 "Purge all requests"
3696 local f=$DIR/$tdir/$tfile
3697 local fid=$(create_empty_file "$f")
3699 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3700 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3701 $HSM_PARAM.actions |\
3702 grep $fid | cut -f16 -d=")
3704 [[ "$data1" == "$DATAHEX" ]] ||
3705 error "Data field in records is ($data1) and not ($DATAHEX)"
3709 run_test 104 "Copy tool data field"
3712 local max_requests=$(get_hsm_param max_requests)
3716 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3717 set_hsm_param max_requests 300
3720 for i in $(seq -w 1 10); do
3721 cp /etc/passwd $DIR/$tdir/$i
3722 $LFS hsm_archive $DIR/$tdir/$i
3724 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3725 $HSM_PARAM.actions |\
3726 grep WAITING | wc -l")
3730 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3731 $HSM_PARAM.actions |\
3732 grep WAITING | wc -l")
3735 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3736 error "Requests count after shutdown $reqcnt2 != "\
3737 "before shutdown $reqcnt1"
3739 run_test 105 "Restart of coordinator"
3742 # test needs a running copytool
3745 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3747 check_agent_registered $uuid
3749 search_copytools || error "No copytool found"
3752 wait_copytools || error "Copytool failed to stop"
3754 check_agent_unregistered $uuid
3757 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3758 check_agent_registered $uuid
3760 run_test 106 "Copytool register/unregister"
3763 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3765 # test needs a running copytool
3767 # create and archive file
3769 local f1=$DIR/$tdir/$tfile
3770 local fid=$(copy_file /etc/passwd $f1)
3771 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3772 wait_request_state $fid ARCHIVE SUCCEED
3773 # shutdown and restart MDS
3775 # check the copytool still gets messages from MDT
3776 local f2=$DIR/$tdir/2
3777 local fid=$(copy_file /etc/passwd $f2)
3778 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3779 # main check of this sanity: this request MUST succeed
3780 wait_request_state $fid ARCHIVE SUCCEED
3782 run_test 107 "Copytool re-register after MDS restart"
3784 policy_set_and_test()
3788 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3789 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3790 [[ "$policy" == "$target" ]] ||
3791 error "Wrong policy after '$change': '$policy' != '$target'"
3795 # to force default policy setting if error
3796 CDT_POLICY_HAD_CHANGED=true
3798 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3799 local default="NonBlockingRestore [NoRetryAction]"
3800 [[ "$policy" == "$default" ]] ||
3801 error "default policy has changed,"\
3802 " '$policy' != '$default' update the test"
3803 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3804 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3805 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3806 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3807 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3808 # useless bacause we know but safer for futur changes to use real value
3809 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3810 echo "Next set_param must failed"
3811 policy_set_and_test "wrong" "$policy"
3814 echo "Back to default policy"
3815 cdt_set_sanity_policy
3817 run_test 109 "Policy display/change"
3820 # test needs a running copytool
3825 copy2archive /etc/passwd $tdir/$tfile
3827 local f=$DIR/$tdir/$tfile
3828 copytool import $tdir/$tfile $f
3829 local fid=$(path2fid $f)
3831 cdt_set_non_blocking_restore
3836 wait_request_state $fid RESTORE SUCCEED
3837 cdt_clear_non_blocking_restore
3841 error "md5sum returns $st != 1, "\
3842 "should also perror ENODATA (No data available)"
3844 run_test 110a "Non blocking restore policy (import case)"
3847 # test needs a running copytool
3851 local f=$DIR/$tdir/$tfile
3852 local fid=$(copy_file /etc/passwd $f)
3853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3854 wait_request_state $fid ARCHIVE SUCCEED
3857 cdt_set_non_blocking_restore
3862 wait_request_state $fid RESTORE SUCCEED
3863 cdt_clear_non_blocking_restore
3867 error "md5sum returns $st != 1, "\
3868 "should also perror ENODATA (No data available)"
3870 run_test 110b "Non blocking restore policy (release case)"
3873 # test needs a running copytool
3877 copy2archive /etc/passwd $tdir/$tfile
3879 local f=$DIR/$tdir/$tfile
3881 copytool import $tdir/$tfile $f
3882 local fid=$(path2fid $f)
3886 copytool_remove_backend $fid
3889 wait_request_state $fid RESTORE FAILED
3896 [[ $st == 0 ]] || error "Restore does not failed"
3898 run_test 111a "No retry policy (import case), restore will error"\
3899 " (No such file or directory)"
3902 # test needs a running copytool
3906 local f=$DIR/$tdir/$tfile
3907 local fid=$(copy_file /etc/passwd $f)
3908 stack_trap cdt_clear_no_retry EXIT
3910 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3911 wait_request_state $fid ARCHIVE SUCCEED
3914 copytool_remove_backend $fid
3917 wait_request_state $fid RESTORE FAILED
3921 [[ $st == 0 ]] || error "Restore does not failed"
3923 run_test 111b "No retry policy (release case), restore will error"\
3924 " (No such file or directory)"
3927 # test needs a running copytool
3931 local f=$DIR/$tdir/$tfile
3932 local fid=$(copy_file /etc/passwd $f)
3934 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3935 local l=$($LFS hsm_action $f)
3937 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3940 wait_request_state $fid ARCHIVE SUCCEED
3943 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3945 run_test 112 "State of recorded request"
3948 local f=$DIR/$tdir/$tfile
3949 local fid=$(create_empty_file "$f")
3953 # Prevent archive from completing
3956 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3957 # wait archive to register at CDT
3958 wait_request_state $fid ARCHIVE STARTED
3960 # Cancel the archive
3961 $LFS hsm_cancel "$f"
3963 wait_request_state $fid ARCHIVE CANCELED
3966 wait_request_state $fid CANCEL SUCCEED
3968 run_test 200 "Register/Cancel archive"
3971 # test needs a running copytool
3974 local f=$DIR/$tdir/$tfile
3975 create_archive_file $tdir/$tfile
3976 copytool import $tdir/$tfile $f
3977 local fid=$(path2fid $f)
3979 # test with cdt on is made in test_222
3982 # wait restore to register at CDT
3983 wait_request_state $fid RESTORE WAITING
3986 wait_request_state $fid RESTORE CANCELED
3987 wait_request_state $fid CANCEL SUCCEED
3989 run_test 201 "Register/Cancel restore"
3992 local f=$DIR/$tdir/$tfile
3993 local fid=$(create_empty_file "$f")
3995 # test needs a running copytool
3998 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3999 wait_request_state $fid ARCHIVE SUCCEED
4003 # wait remove to register at CDT
4004 wait_request_state $fid REMOVE STARTED
4007 wait_request_state $fid REMOVE CANCELED
4009 run_test 202 "Register/Cancel remove"
4011 test_220A() { # was test_220
4012 # test needs a running copytool
4017 local f=$DIR/$tdir/$tfile
4018 local fid=$(copy_file /etc/passwd $f)
4022 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4023 wait_request_state $fid ARCHIVE SUCCEED
4025 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4026 error "The expected changelog was not emitted"
4028 run_test 220A "Changelog for archive"
4031 # test needs a running copytool
4036 local f=$DIR/$tdir/$tfile
4037 local fid=$(copy_file /etc/passwd $f)
4041 # block copytool operations to allow for HSM request to be
4042 # submitted and file be unlinked (CDT will find object removed)
4045 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4047 # wait request to reach CT
4048 wait_request_state $fid ARCHIVE STARTED
4054 wait_request_state $fid ARCHIVE FAILED
4057 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4058 error "The expected changelog was not emitted"
4060 run_test 220a "Changelog for failed archive"
4063 local f=$DIR/$tdir/$tfile
4064 local fid=$(create_empty_file "$f")
4069 # Prevent archive from completing
4071 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4072 wait_request_state $fid ARCHIVE STARTED
4075 wait_request_state $fid ARCHIVE CANCELED
4078 wait_request_state $fid CANCEL SUCCEED
4080 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4081 error "The expected changelog was not emitted"
4083 run_test 221 "Changelog for archive canceled"
4086 # test needs a running copytool
4090 copy2archive /etc/passwd $tdir/$tfile
4092 local f=$DIR/$tdir/$tfile
4093 copytool import $tdir/$tfile $f
4094 local fid=$(path2fid $f)
4099 wait_request_state $fid RESTORE SUCCEED
4101 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4102 error "The expected changelog was not emitted"
4104 run_test 222a "Changelog for explicit restore"
4107 # test needs a running copytool
4111 local f=$DIR/$tdir/$tfile
4112 local fid=$(copy_file /etc/passwd $f)
4115 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4116 wait_request_state $fid ARCHIVE SUCCEED
4121 wait_request_state $fid RESTORE SUCCEED
4123 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4124 error "The expected changelog was not emitted"
4126 run_test 222b "Changelog for implicit restore"
4129 # test needs a running copytool
4133 copy2archive /etc/passwd $tdir/$tfile
4135 local f=$DIR/$tdir/$tfile
4136 copytool import $tdir/$tfile $f
4137 local fid=$(path2fid $f)
4141 # block copytool operations to allow for HSM request to be
4142 # submitted and file be unlinked (CDT will find object removed)
4147 # wait request to reach CT
4148 wait_request_state $fid RESTORE STARTED
4154 wait_request_state $fid RESTORE FAILED
4157 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4158 error "The expected changelog was not emitted"
4160 run_test 222c "Changelog for failed explicit restore"
4163 # test needs a running copytool
4167 local f=$DIR/$tdir/$tfile
4168 local fid=$(copy_file /etc/passwd $f)
4171 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4172 wait_request_state $fid ARCHIVE SUCCEED
4175 copytool_remove_backend $fid
4178 wait_request_state $fid RESTORE FAILED
4181 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4182 error "The expected changelog was not emitted"
4184 run_test 222d "Changelog for failed implicit restore"
4187 # test needs a running copytool
4190 local f=$DIR/$tdir/$tfile
4191 create_archive_file $tdir/$tfile
4195 copytool import $tdir/$tfile $f
4196 local fid=$(path2fid $f)
4199 wait_request_state $fid RESTORE STARTED
4201 wait_request_state $fid RESTORE CANCELED
4202 wait_request_state $fid CANCEL SUCCEED
4204 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4205 error "The expected changelog was not emitted"
4207 run_test 223a "Changelog for restore canceled (import case)"
4210 local f=$DIR/$tdir/$tfile
4211 local fid=$(create_empty_file "$f")
4216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4217 wait_request_state $fid ARCHIVE SUCCEED
4220 # Prevent restore from completing
4223 wait_request_state $fid RESTORE STARTED
4226 wait_request_state $fid RESTORE CANCELED
4229 wait_request_state $fid CANCEL SUCCEED
4231 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4232 error "The expected changelog was not emitted"
4234 run_test 223b "Changelog for restore canceled (release case)"
4236 test_224A() { # was test_224
4237 # test needs a running copytool
4242 local f=$DIR/$tdir/$tfile
4243 local fid=$(copy_file /etc/passwd $f)
4246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4247 wait_request_state $fid ARCHIVE SUCCEED
4250 wait_request_state $fid REMOVE SUCCEED
4252 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4253 error "The expected changelog was not emitted"
4255 run_test 224A "Changelog for remove"
4258 # test needs a running copytool
4263 local f=$DIR/$tdir/$tfile
4264 local fid=$(copy_file /etc/passwd $f)
4267 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4268 wait_request_state $fid ARCHIVE SUCCEED
4270 copytool_remove_backend $fid
4272 # block copytool operations to allow for HSM request to be
4273 # submitted and file be unlinked (CDT will find object removed)
4278 # wait for request to reach CT
4279 wait_request_state $fid REMOVE STARTED
4285 wait_request_state $fid REMOVE FAILED
4287 # HE_REMOVE|ENOENT=0x202
4288 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4289 error "The expected changelog was not emitted"
4291 run_test 224a "Changelog for failed remove"
4294 # test is not usable because remove request is too fast
4295 # so it is always finished before cancel can be done ...
4296 echo "Test disabled"
4299 # test needs a running copytool
4302 local f=$DIR/$tdir/$tfile
4303 local fid=$(create_empty_file "$f")
4306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4307 wait_request_state $fid ARCHIVE SUCCEED
4309 # Prevent restore from completing
4314 wait_request_state $fid REMOVE CANCELED
4317 wait_request_state $fid CANCEL SUCCEED
4319 changelog_find -type HSM -target-fid $fid -flags 0x27d
4320 error "The expected changelog was not emitted"
4322 run_test 225 "Changelog for remove canceled"
4325 # test needs a running copytool
4330 local f1=$DIR/$tdir/$tfile-1
4331 local f2=$DIR/$tdir/$tfile-2
4332 local f3=$DIR/$tdir/$tfile-3
4333 local fid1=$(copy_file /etc/passwd $f1)
4334 local fid2=$(copy_file /etc/passwd $f2)
4335 copy_file /etc/passwd $f3
4338 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4339 wait_request_state $fid1 ARCHIVE SUCCEED
4341 $LFS hsm_archive $f2
4342 wait_request_state $fid2 ARCHIVE SUCCEED
4344 rm $f1 || error "rm $f1 failed"
4347 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4348 error "The expected changelog was not emitted"
4350 mv $f3 $f2 || error "mv $f3 $f2 failed"
4352 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4353 error "The expected changelog was not emitted"
4355 run_test 226 "changelog for last rm/mv with exiting archive"
4357 # This is just a utility function to clarify what test_227 does
4362 "$LFS" "$action" --$flag "$file" ||
4363 error "Cannot ${action#hsm_} $flag on '$file'"
4365 # Only one changelog should be produced
4366 local entries="$(changelog_find -type HSM -target-fid $fid)"
4367 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4368 error "lfs $action --$flag '$file' produced more than one" \
4371 # Parse the last changelog record
4372 local entry="$(tail -n 1 <<< "$entries")"
4373 eval local -A changelog=$(changelog2array $entry)
4375 # Also check the flags match what is expected
4376 [[ ${changelog[flags]} == $target ]] ||
4377 error "Changelog flag is '${changelog[flags]}', not $target"
4381 local file="$DIR/$tdir/$tfile"
4382 local fid=$(create_empty_file "$file")
4387 for flag in norelease noarchive exists archived lost; do
4388 if [ "$flag" == lost ]; then
4389 # The flag "lost" only works on an archived file
4390 "$LFS" hsm_set --archived "$file"
4394 action="hsm_set" __test_227
4395 action="hsm_clear" __test_227
4398 run_test 227 "changelog when explicit setting of HSM flags"
4401 # test needs a running copytool
4404 local fid=$(create_small_sync_file $DIR/$tfile)
4405 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4406 wait_request_state $fid ARCHIVE SUCCEED
4408 $LFS hsm_release $DIR/$tfile
4409 check_hsm_flags $DIR/$tfile "0x0000000d"
4411 filefrag $DIR/$tfile | grep " 1 extent found" ||
4412 error "filefrag on released file must return only one extent"
4414 # only newer versions of cp detect sparse files by stat/FIEMAP
4416 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4417 error "copying $DIR/$tfile"
4418 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4420 $LFS hsm_release $DIR/$tfile
4421 check_hsm_flags $DIR/$tfile "0x0000000d"
4423 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4425 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4427 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4428 error "comparing untarred $DIR/$tfile"
4430 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4431 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4433 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4436 local file="$DIR/$tdir/$tfile"
4438 # set max_requests to allow one request of each type to be started (3)
4440 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4441 set_hsm_param max_requests 3
4444 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4445 set_hsm_param loop_period 1
4447 # send 1 requests of each kind twice
4450 for action in archive restore remove; do
4451 local filepath="$file"-to-$action
4452 local fid=$(create_empty_file "$filepath")
4453 local fid2=$(create_empty_file "$filepath".bis)
4455 if [ "$action" != archive ]; then
4456 "$LFS" hsm_archive "$filepath"
4457 wait_request_state $fid ARCHIVE SUCCEED
4458 "$LFS" hsm_archive "$filepath".bis
4459 wait_request_state $fid2 ARCHIVE SUCCEED
4461 if [ "$action" == restore ]; then
4462 "$LFS" hsm_release "$filepath"
4463 "$LFS" hsm_release "$filepath".bis
4467 # suspend the copytool to prevent requests from completing
4468 stack_trap "copytool_continue" EXIT
4471 # send `max_requests' requests (one of each kind)
4472 for action in archive restore remove; do
4473 filepath="$file"-to-$action
4474 "$LFS" hsm_${action} "$filepath"
4475 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4478 # send another batch of requests
4479 for action in archive restore remove; do
4480 "$LFS" hsm_${action} "$file-to-$action".bis
4482 # wait for `loop_period' seconds to make sure the coordinator has time
4483 # to register those, even though it should not
4486 # only the first batch of request should be started
4488 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4492 error "expected 3 STARTED requests, found $count"
4494 run_test 250 "Coordinator max request"
4497 local f=$DIR/$tdir/$tfile
4498 local fid=$(create_empty_file "$f")
4501 # to have a short test
4502 local old_to=$(get_hsm_param active_request_timeout)
4503 set_hsm_param active_request_timeout 1
4504 # to be sure the cdt will wake up frequently so
4505 # it will be able to cancel the "old" request
4506 local old_loop=$(get_hsm_param loop_period)
4507 set_hsm_param loop_period 1
4512 # Prevent archive from completing
4514 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4515 wait_request_state $fid ARCHIVE STARTED
4517 # Let the request timeout
4518 wait_request_state $fid ARCHIVE CANCELED
4520 set_hsm_param active_request_timeout $old_to
4521 set_hsm_param loop_period $old_loop
4523 run_test 251 "Coordinator request timeout"
4526 local f=$DIR/$tdir/$tfile
4527 local fid=$(create_empty_file "$f")
4529 # to have a short test
4530 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4531 set_hsm_param loop_period 1
4535 # Prevent archive from completing
4537 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4538 wait_request_state $fid ARCHIVE STARTED
4541 stack_trap "set_hsm_param active_request_timeout \
4542 $(get_hsm_param active_request_timeout)" EXIT
4543 set_hsm_param active_request_timeout 1
4545 wait_request_state $fid ARCHIVE CANCELED
4548 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4552 # test needs a running copytool
4556 local f=$DIR/$tdir/$tfile
4558 dd if=/dev/zero of=$f bs=1MB count=10
4559 local fid=$(path2fid $f)
4561 $LFS hsm_archive $f || error "could not archive file"
4562 wait_request_state $fid ARCHIVE SUCCEED
4564 # clear locks to discard inode data
4565 cancel_lru_locks osc
4567 #define OBD_FAIL_MDC_MERGE 0x807
4568 $LCTL set_param fail_loc=0x807
4570 #expect error here, instead of release with wrong size
4573 if ((rc == 0)); then
4574 file_size=$(stat -c '%s' $f)
4575 if ((file_size != 10485760)); then
4576 error "Wrong file size after hsm_release"
4579 echo "could not release file"
4582 run_test 253 "Check for wrong file size after release"
4586 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4587 skip "need MDS version at least 2.10.56"
4589 # Check that the counters are initialized to 0
4591 for request_type in archive restore remove; do
4592 count="$(get_hsm_param ${request_type}_count)" ||
4593 error "Reading ${request_type}_count failed with $?"
4595 [ "$count" -eq 0 ] ||
4596 error "Expected ${request_type}_count to be " \
4600 run_test 254a "Request counters are initialized to zero"
4604 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4605 skip "need MDS version at least 2.10.56"
4607 # The number of request to launch (at least 32)
4608 local request_count=$((RANDOM % 32 + 32))
4609 printf "Will launch %i requests of each type\n" "$request_count"
4611 # Launch a copytool to process requests
4614 # Set hsm.max_requests to allow starting all requests at the same time
4616 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4617 set_hsm_param max_requests "$request_count"
4621 for request_type in archive restore remove; do
4622 printf "Checking %s requests\n" "${request_type}"
4623 # Suspend the copytool to give us time to read the proc files
4626 for ((i = 0; i < $request_count; i++)); do
4627 case $request_type in
4629 create_empty_file "$DIR/$tdir/$tfile-$i" \
4633 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4636 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4639 # Give the coordinator 10 seconds to start every request
4641 while get_hsm_param actions | grep -q WAITING; do
4644 [ $timeout -gt 0 ] ||
4645 error "${request_type^} requests took too " \
4649 count="$(get_hsm_param ${request_type}_count)"
4650 [ "$count" -eq "$request_count" ] ||
4651 error "Expected '$request_count' (!= '$count') " \
4652 "active $request_type requests"
4654 # Let the copytool process the requests
4656 # Give it 10 seconds maximum
4658 while get_hsm_param actions | grep -q STARTED; do
4661 [ $timeout -gt 0 ] ||
4662 error "${request_type^} requests took too " \
4666 count="$(get_hsm_param ${request_type}_count)"
4667 [ "$count" -eq 0 ] ||
4668 error "Expected 0 (!= '$count') " \
4669 "active $request_type requests"
4672 run_test 254b "Request counters are correctly incremented and decremented"
4676 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4677 skip "Need MDS version at least 2.12.0"
4679 local file="$DIR/$tdir/$tfile"
4680 local fid=$(create_empty_file "$file")
4682 # How do you make sure the coordinator has consumed any outstanding
4683 # event, without triggering an event yourself?
4685 # You wait for a request to disappear from the coordinator's llog.
4687 # Warning: the setup represents 90% of this test
4689 # Create and process an HSM request
4691 "$LFS" hsm_archive "$file"
4692 wait_request_state $fid ARCHIVE SUCCEED
4695 wait_copytools || error "failed to stop copytools"
4697 # Launch a new HSM request
4699 create_empty_file "$file"
4700 "$LFS" hsm_archive "$file"
4704 # Have the completed request be removed as soon as the cdt wakes up
4705 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4706 set_hsm_param grace_delay 1
4707 # (Hopefully, time on the MDS will behave nicely)
4708 do_facet $SINGLEMDS sleep 2 &
4710 # Increase `loop_period' as a mean to prevent the coordinator from
4711 # waking itself up to do some housekeeping.
4712 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4713 set_hsm_param loop_period 1000
4715 wait $! || error "waiting failed"
4717 wait_request_state $fid ARCHIVE ""
4718 # The coordinator will not wake up on its own for ~`loop_period' secs...
4720 # ... Unless a copytool registers. Now the real test begins
4722 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4724 run_test 255 "Copytool registration wakes the coordinator up"
4726 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4727 # break in the future because of that.
4730 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4731 skip "need MDS version 2.11.56 or later"
4733 local -a files=("$DIR/$tdir/$tfile".{0..15})
4736 for file in "${files[@]}"; do
4737 create_small_file "$file"
4740 # Set a few hsm parameters
4742 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4743 set_hsm_param loop_period 1
4745 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4746 set_hsm_param max_requests 3
4750 "$LFS" hsm_archive "${files[0]}"
4751 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4752 "$LFS" hsm_release "${files[0]}"
4756 wait_copytools || error "copytools failed to stop"
4758 # Send several archive requests
4759 for file in "${files[@]:1}"; do
4760 "$LFS" hsm_archive "$file"
4763 # Send one restore request
4764 "$LFS" hsm_restore "${files[0]}"
4769 # Wait for all the requests to complete
4770 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4771 for file in "${files[@]:1}"; do
4772 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4775 # Collect the actions in the order in which the copytool processed them
4777 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4778 "$(copytool_logfile "$SINGLEAGT")")
4781 printf '%s\n' "${actions[@]}"
4784 for action in "${actions[@]:0:3}"; do
4785 [ "$action" == RESTORE ] && return
4788 error "Too many ARCHIVE requests were run before the RESTORE request"
4790 run_test 260a "Restore request have priority over other requests"
4792 # This test is very much tied to the implementation of the current priorisation
4793 # mechanism in the coordinator. It might not make sense to keep it in the future
4796 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4797 skip "need MDS version 2.11.56 or later"
4799 local -a files=("$DIR/$tdir/$tfile".{0..15})
4802 for file in "${files[@]}"; do
4803 create_small_file "$file"
4806 # Set a few hsm parameters
4808 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4809 set_hsm_param loop_period 1
4811 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4812 set_hsm_param max_requests 3
4815 copytool setup --archive-id 2
4816 "$LFS" hsm_archive --archive 2 "${files[0]}"
4817 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4818 "$LFS" hsm_release "${files[0]}"
4822 wait_copytools || error "copytools failed to stop"
4824 # Send several archive requests
4825 for file in "${files[@]:1}"; do
4826 "$LFS" hsm_archive "$file"
4829 # Send one restore request
4830 "$LFS" hsm_restore "${files[0]}"
4834 copytool setup --archive-id 2
4836 # Wait for all the requests to complete
4837 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4838 for file in "${files[@]:1}"; do
4839 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4842 # Collect the actions in the order in which the copytool processed them
4844 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4845 "$(copytool_logfile "$SINGLEAGT")")
4848 printf '%s\n' "${actions[@]}"
4851 for action in "${actions[@]:0:3}"; do
4852 [ "$action" == RESTORE ] && return
4855 error "Too many ARCHIVE requests were run before the RESTORE request"
4857 run_test 260b "Restore request have priority over other requests"
4859 # This test is very much tied to the implementation of the current priorisation
4860 # mechanism in the coordinator. It might not make sense to keep it in the future
4863 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4864 skip "Need MDS version at least 2.12.0"
4866 local -a files=("$DIR/$tdir/$tfile".{0..15})
4869 for file in "${files[@]}"; do
4870 create_small_file "$file"
4873 # Set a few hsm parameters
4875 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4876 set_hsm_param loop_period 1000
4878 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4879 set_hsm_param max_requests 3
4882 copytool setup --archive-id 2
4883 "$LFS" hsm_archive --archive 2 "${files[0]}"
4884 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4885 "$LFS" hsm_release "${files[0]}"
4889 wait_copytools || error "copytools failed to stop"
4891 # Force the next coordinator run to do housekeeping
4895 "$LFS" hsm_archive "${files[1]}"
4899 copytool setup --archive-id 2
4901 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4902 # The coordinator just did a housekeeping run it won't do another one
4903 # for around `loop_period' seconds => requests will not be reordered
4904 # if it costs too much (ie. when the coordinator has to discard a whole
4907 # Send several archive requests
4908 for file in "${files[@]:2}"; do
4909 "$LFS" hsm_archive "$file"
4912 # Send one restore request
4913 "$LFS" hsm_restore "${files[0]}"
4915 # Wait for all the requests to complete
4916 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4917 for file in "${files[@]:2}"; do
4918 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4921 # Collect the actions in the order in which the copytool processed them
4923 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4924 "$(copytool_logfile "$SINGLEAGT")")
4927 printf '%s\n' "${actions[@]}"
4930 for action in "${actions[@]:0:3}"; do
4931 [ "$action" == RESTORE ] &&
4932 error "Restore requests should not be prioritised" \
4933 "unless the coordinator is doing housekeeping"
4937 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4940 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4942 # the only way to test ondisk conf is to restart MDS ...
4943 echo "Stop coordinator and remove coordinator state at mount"
4946 # clean on disk conf set by default
4947 cdt_clear_mount_state
4948 cdt_check_state stopped
4950 # check cdt still off after umount/remount
4952 cdt_check_state stopped
4954 echo "Set coordinator start at mount, and start coordinator"
4955 cdt_set_mount_state enabled
4958 cdt_check_state enabled
4960 # check cdt still on after umount/remount
4962 cdt_check_state enabled
4964 # we are back to original state (cdt started at mount)
4966 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4969 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4971 local ai=$(get_hsm_param default_archive_id)
4972 local new=$((ai + 1))
4974 set_hsm_param default_archive_id $new -P
4976 local res=$(get_hsm_param default_archive_id)
4979 set_hsm_param default_archive_id "" "-P -d"
4981 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4983 run_test 301 "HSM tunnable are persistent"
4986 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4988 local ai=$(get_hsm_param default_archive_id)
4989 local new=$((ai + 1))
4994 set_hsm_param default_archive_id $new -P
4997 for mdtno in $(seq 1 $MDSCOUNT); do
5002 cdt_check_state enabled
5004 local res=$(get_hsm_param default_archive_id)
5007 set_hsm_param default_archive_id "" "-P -d"
5009 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5011 run_test 302 "HSM tunnable are persistent when CDT is off"
5014 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5020 local dir_mdt0=$DIR/$tdir/mdt0
5021 local dir_mdt1=$DIR/$tdir/mdt1
5023 # create 1 dir per MDT
5024 stack_trap "rm -rf $dir_mdt0" EXIT
5025 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5026 stack_trap "rm -rf $dir_mdt1" EXIT
5027 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5029 # create 1 file in each MDT
5030 local fid1=$(create_small_file $dir_mdt0/$tfile)
5031 local fid2=$(create_small_file $dir_mdt1/$tfile)
5033 # check that hsm request on mdt0 is sent to the right MDS
5034 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5035 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5036 echo "archive successful on mdt0"
5038 # check that hsm request on mdt1 is sent to the right MDS
5039 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5040 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5041 echo "archive successful on mdt1"
5043 run_test 400 "Single request is sent to the right MDT"
5046 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5052 local dir_mdt0=$DIR/$tdir/mdt0
5053 local dir_mdt1=$DIR/$tdir/mdt1
5055 # create 1 dir per MDT
5056 stack_trap "rm -rf $dir_mdt0" EXIT
5057 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5058 stack_trap "rm -rf $dir_mdt1" EXIT
5059 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5061 # create 1 file in each MDT
5062 local fid1=$(create_small_file $dir_mdt0/$tfile)
5063 local fid2=$(create_small_file $dir_mdt1/$tfile)
5065 # check that compound requests are shunt to the rights MDTs
5066 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5067 error "lfs hsm_archive"
5068 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5069 echo "archive successful on mdt0"
5070 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5071 echo "archive successful on mdt1"
5073 run_test 401 "Compound requests split and sent to their respective MDTs"
5075 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5080 local node=$(facet_active_host $facet)
5082 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5083 awk '{print $4}'); do
5084 echo "$3 $mdc on $node"
5085 do_facet $facet "$LCTL --device $mdc $state" || return 1
5090 # deactivate all mdc on agent1
5091 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5093 copytool setup --no-fail
5095 check_agent_unregistered "uuid" # match any agent
5097 # no expected running copytool
5098 search_copytools $agent && error "Copytool start should have failed"
5101 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5103 run_test 402a "Copytool start fails if all MDTs are inactive"
5110 local f=$DIR/$tdir/$tfile
5111 touch $f || error "touch $f failed"
5112 local fid=$(path2fid $f)
5114 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5115 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5116 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5118 # give time for CDT to send request and to keep it for retry
5119 wait_for_loop_period
5121 wait_request_state $fid ARCHIVE WAITING
5123 do_facet $SINGLEAGT lctl set_param fail_loc=0
5125 # request should succeed now
5126 wait_request_state $fid ARCHIVE SUCCEED
5128 run_test 402b "CDT must retry request upon slow start of CT"
5131 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5133 local agent=$(facet_active_host $SINGLEAGT)
5135 # deactivate all mdc for MDT0001
5136 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5139 local uuid=$(get_agent_uuid $agent)
5140 # check the agent is registered on MDT0000, and not on MDT0001
5141 check_agent_registered_by_mdt $uuid 0
5142 check_agent_unregistered_by_mdt $uuid 1
5144 # check running copytool process
5145 search_copytools $agent || error "No running copytools on $agent"
5147 # reactivate all mdc for MDT0001
5148 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5150 # make sure the copytool is now registered to all MDTs
5151 check_agent_registered $uuid
5153 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5156 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5160 # create files on both MDT0000 and MDT0001
5163 local dir_mdt0=$DIR/$tdir/mdt0
5164 stack_trap "rm -rf $dir_mdt0" EXIT
5165 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5167 # create 1 file on mdt0
5168 local fid1=$(create_small_file $dir_mdt0/$tfile)
5170 # deactivate all mdc for MDT0001
5171 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5173 # send an HSM request for files in MDT0000
5174 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5176 # check for completion of files in MDT0000
5177 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5178 echo "archive successful on mdt0"
5180 # reactivate all mdc for MDT0001
5181 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5183 run_test 404 "Inactive MDT does not block requests for active MDTs"
5186 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5192 local striped_dir=$DIR/$tdir/striped_dir
5194 # create striped dir on all of MDTs
5195 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5197 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5198 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5199 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5200 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5202 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5203 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5204 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5205 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5207 # check that compound requests are shunt to the rights MDTs
5208 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5209 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5210 error "lfs hsm_archive"
5212 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5213 echo "archive successful on $fid1"
5214 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5215 echo "archive successful on $fid2"
5216 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5217 echo "archive successful on $fid3"
5218 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5219 echo "archive successful on $fid4"
5221 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5222 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5223 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5224 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5226 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5227 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5228 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5229 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5231 run_test 405 "archive and release under striped directory"
5234 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5236 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5237 skip "need MDS version at least 2.7.64"
5242 fid=$(create_small_file $DIR/$tdir/$tfile)
5247 $LFS hsm_archive $DIR/$tdir/$tfile
5248 wait_request_state "$fid" ARCHIVE SUCCEED
5249 $LFS hsm_release $DIR/$tdir/$tfile
5251 # Should migrate $tdir but not $tfile.
5252 $LFS migrate -m1 $DIR/$tdir &&
5253 error "migrating HSM an archived file should fail"
5255 $LFS hsm_restore $DIR/$tdir/$tfile
5256 wait_request_state "$fid" RESTORE SUCCEED
5258 $LFS hsm_remove $DIR/$tdir/$tfile
5259 wait_request_state "$fid" REMOVE SUCCEED
5261 cat $DIR/$tdir/$tfile > /dev/null ||
5262 error "cannot read $DIR/$tdir/$tfile"
5264 $LFS migrate -m1 $DIR/$tdir ||
5265 error "cannot complete migration after HSM remove"
5267 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5268 if ((mdt_index != 1)); then
5269 error "expected MDT index 1, got $mdt_index"
5272 # Refresh fid after migration.
5273 fid=$(path2fid $DIR/$tdir/$tfile)
5276 $LFS hsm_archive $DIR/$tdir/$tfile
5277 wait_request_state "$fid" ARCHIVE SUCCEED 1
5279 lctl set_param debug=+trace
5280 $LFS hsm_release $DIR/$tdir/$tfile ||
5281 error "cannot release $DIR/$tdir/$tfile"
5283 $LFS hsm_restore $DIR/$tdir/$tfile
5284 wait_request_state "$fid" RESTORE SUCCEED 1
5286 cat $DIR/$tdir/$tfile > /dev/null ||
5287 error "cannot read $DIR/$tdir/$tfile"
5289 run_test 406 "attempting to migrate HSM archived files is safe"
5292 local f=$DIR/$tdir/$tfile
5293 local f2=$DIR2/$tdir/$tfile
5294 local fid=$(create_empty_file "$f")
5298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5299 wait_request_state $fid ARCHIVE SUCCEED
5302 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5303 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5305 # Prevent restore from completing
5309 # 1st request holds layout lock while appropriate
5310 # RESTORE record is still not added to llog
5314 # after umount hsm_actions->O/x/x log shouldn't have
5315 # double RESTORE records like below
5316 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5317 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5319 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5323 wait_request_state $fid RESTORE SUCCEED
5325 run_test 407 "Check for double RESTORE records in llog"
5329 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5330 skip "HSM migrate is not supported"
5332 test_mkdir -p $DIR/$tdir
5334 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5335 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5337 llapi_hsm_test -d $DIR/$tdir -b ||
5338 error "One llapi HSM test failed"
5340 llapi_hsm_test -d $DIR/$tdir ||
5341 error "One llapi HSM test failed"
5344 run_test 500 "various LLAPI HSM tests"
5347 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5348 skip "need MDS version at least 2.10.58"
5352 local f=$DIR/$tdir/$tfile
5355 # set changelog_mask to ALL
5356 changelog_chmask "ALL"
5358 chmod 777 $DIR/$tdir
5359 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5360 local fid=$(path2fid $f)
5363 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5364 -gid "$RUNAS_GID") ||
5365 error "No matching CREAT entry"
5367 # Parse the changelog
5368 eval local -A changelog=$(changelog2array $entry)
5369 local nid="${changelog[nid]}"
5372 echo "Got NID '$nid'"
5373 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5374 error "nid '$nid' does not match any client NID:" \
5377 run_test 600 "Changelog fields 'u=' and 'nid='"
5380 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5381 skip "need MDS version at least 2.10.58"
5385 local f=$DIR/$tdir/$tfile
5388 # set changelog_mask to ALL
5389 changelog_chmask "ALL"
5391 touch $f || error "touch $f failed"
5392 local fid=$(path2fid $f)
5395 cat $f || error "cat $f failed"
5397 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5398 error "No matching OPEN entry"
5400 run_test 601 "OPEN Changelog entry"
5403 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5404 skip "need MDS version at least 2.10.58"
5408 local f=$DIR/$tdir/$tfile
5411 # set changelog_mask to ALL
5412 changelog_chmask "ALL"
5414 touch $f || error "touch $f failed"
5415 local fid=$(path2fid $f)
5418 cat $f || error "cat $f failed"
5420 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5424 echo f > $f || error "write $f failed"
5427 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5429 # remove OPEN from changelog_mask
5430 changelog_chmask "-OPEN"
5434 cat $f || error "cat $f failed"
5437 changelog_find -type CLOSE -target-fid $fid &&
5438 error "There should be no CLOSE entry"
5442 echo f > $f || error "write $f failed"
5445 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5447 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5450 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5451 skip "need MDS version at least 2.10.58"
5455 local f=$DIR/$tdir/$tfile
5458 # set changelog_mask to ALL
5459 changelog_chmask "ALL"
5461 touch $f || error "touch $f failed"
5462 local fid=$(path2fid $f)
5464 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5467 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5469 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5470 error "No matching GXATR entry"
5472 run_test 603 "GETXATTR Changelog entry"
5475 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5476 skip "need MDS version at least 2.10.58"
5480 local f=$DIR/$tdir/$tfile
5481 local f2=$DIR2/$tdir/$tfile
5482 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5484 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5485 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5486 do_facet mds1 lctl set_param "$procname=20"
5490 # set changelog_mask to ALL
5491 changelog_chmask "ALL"
5493 touch $f || error "touch $f failed"
5494 local fid=$(path2fid $f)
5500 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5504 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5505 -gid "$RUNAS_GID" -mode "r--") ||
5506 error "No matching NOPEN entry"
5508 # Parse the changelog
5509 eval local -A changelog=$(changelog2array $entry)
5510 local nid="${changelog[nid]}"
5513 echo "Got NID '$nid'"
5514 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5515 error "nid '$nid' does not match any client NID:" \
5520 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5523 changelog_find -type NOPEN -target-fid $fid &&
5524 error "There should be no NOPEN entry"
5526 # Sleep for `changelog_deniednext` seconds
5531 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5534 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5535 -gid "$RUNAS_GID" -mode "r--") ||
5536 error "No matching NOPEN entry"
5538 # Parse the changelog
5539 eval local -A changelog=$(changelog2array $entry)
5540 local nid="${changelog[nid]}"
5543 echo "Got NID '$nid'"
5544 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5545 error "nid '$nid' does not match any client NID:" \
5548 run_test 604 "NOPEN Changelog entry"
5551 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5552 skip "need MDS version at least 2.10.58"
5556 local f=$DIR/$tdir/$tfile
5557 local f2=$DIR2/$tdir/$tfile
5560 # set changelog_mask to ALL
5561 changelog_chmask "ALL"
5563 touch $f || error "touch $f failed"
5564 local fid=$(path2fid $f)
5568 exec 3<> $f || error "open $f failed"
5572 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5576 exec 4<> $f || error "open $f failed"
5579 changelog_find -type OPEN -target-fid $fid &&
5580 error "There should be no OPEN entry"
5582 exec 4>&- || error "close $f failed"
5585 changelog_find -type CLOSE -target-fid $fid &&
5586 error "There should be no CLOSE entry"
5590 # access in rw, so different access mode should generate entries
5591 cat $f || error "cat $f failed"
5594 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5596 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5600 # same access as first one, should not generate new entries
5601 exec 4<> $f || error "open $f failed"
5604 changelog_find -type OPEN -target-fid $fid &&
5605 error "There should be no OPEN entry"
5607 exec 4>&- || error "close $f failed"
5610 changelog_find -type CLOSE -target-fid $fid &&
5611 error "There should be no CLOSE entry"
5615 # access by different user should generate new entries
5616 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5619 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5621 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5625 exec 3>&- || error "close $f failed"
5628 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5630 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5633 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5634 skip "need MDS version at least 2.10.58"
5636 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5637 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5638 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5639 skip_env "missing llog_reader" && return
5640 local fstype=$(facet_fstype mds1)
5644 local f=$DIR/$tdir/$tfile
5647 # set changelog_mask to ALL
5648 changelog_chmask "ALL"
5650 chmod 777 $DIR/$tdir
5651 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5652 local fid=$(path2fid $f)
5653 rm $f || error "rm $f failed"
5655 local mntpt=$(facet_mntpt mds1)
5659 #remount mds1 as ldiskfs or zfs type
5660 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5661 stop mds1 || error "stop mds1 failed"
5662 mount_fstype mds1 || error "remount mds1 failed"
5664 for ((i = 0; i < 1; i++)); do
5665 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5666 local cat_file=$(do_facet mds1 $llog_reader \
5667 $mntpt/changelog_catalog | awk \
5668 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5669 [ -n "$cat_file" ] || error "no catalog file"
5671 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5672 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5673 [ -n "$entry" ] || error "no CREAT entry"
5676 local uidgid=$(echo $entry |
5677 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5678 [ -n "$uidgid" ] || error "uidgid is empty"
5679 echo "Got UID/GID $uidgid"
5680 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5681 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5682 local nid=$(echo $entry |
5683 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5684 [ -n "$nid" ] || error "nid is empty"
5686 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5687 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5689 run_test 606 "llog_reader groks changelog fields"
5692 check_and_cleanup_lustre