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
121 # The test only support up to 10 MDTs
122 MDT_PREFIX="mdt.$FSNAME-MDT000"
123 HSM_PARAM="${MDT_PREFIX}0.hsm"
125 # archive is purged at copytool setup
126 HSM_ARCHIVE_PURGE=true
128 # Don't allow copytool error upon start/setup
129 HSMTOOL_NOERROR=false
132 # Get the backend root path for the given agent facet.
135 local dev=AGTDEV$(facet_number $facet)
142 # get MDT device for each mdc
143 for mdtno in $(seq 1 $MDSCOUNT); do
144 local idx=$(($mdtno - 1))
145 MDT[$idx]=$($LCTL get_param -n \
146 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
147 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
152 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
153 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
159 echo "Killing existing copytools on $hosts"
160 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
161 copytool_continue "$hosts"
165 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
166 local wait_timeout=200
167 local wait_start=$SECONDS
168 local wait_end=$((wait_start + wait_timeout))
169 local sleep_time=100000 # 0.1 second
171 while ((SECONDS < wait_end)); do
172 if ! search_copytools $hosts; then
173 echo "copytools stopped in $((SECONDS - wait_start))s"
177 echo "copytools still running on $hosts"
179 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
180 sleep_time=$(bc <<< "$sleep_time * 2")
183 # try to dump Copytool's stack
184 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
185 "echo t >/proc/sysrq-trigger"
187 echo "copytools failed to stop in ${wait_timeout}s"
192 copytool_monitor_setup() {
193 local facet=${1:-$SINGLEAGT}
194 local agent=$(facet_active_host $facet)
196 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
197 local test_dir=$(do_node $agent "$cmd") ||
198 error "Failed to create tempdir on $agent"
199 export HSMTOOL_MONITOR_DIR=$test_dir
201 # Create the fifo and a monitor (cat dies when copytool dies)
202 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
203 error "failed to create copytool fifo on $agent"
204 cmd="cat $test_dir/fifo > $test_dir/events &"
205 cmd+=" echo \\\$! > $test_dir/monitor_pid"
207 if [[ $PDSH == *Rmrsh* ]]; then
208 # This is required for pdsh -Rmrsh and its handling of remote
210 # Regular ssh and pdsh -Rssh work fine without this
211 # backgrounded subshell nonsense.
212 (do_node $agent "$cmd") &
213 export HSMTOOL_MONITOR_PDSH=$!
215 # Slightly racy, but just making a best-effort to catch obvious
218 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
219 error "Failed to start copytool monitor on $agent"
221 do_node $agent "$cmd"
223 error "Failed to start copytool monitor on $agent"
228 copytool_monitor_cleanup() {
229 local facet=${1:-$SINGLEAGT}
230 local agent=$(facet_active_host $facet)
232 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
233 # Should die when the copytool dies, but just in case.
234 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
235 cmd+=" 2>/dev/null || true"
236 do_node $agent "$cmd"
237 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
238 export HSMTOOL_MONITOR_DIR=
241 # The pdsh should die on its own when the monitor dies. Just
242 # in case, though, try to clean up to avoid any cruft.
243 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
244 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
245 export HSMTOOL_MONITOR_PDSH=
255 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
262 local host="$(facet_host "$1")"
263 local prefix=$TESTLOG_PREFIX
264 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
266 printf "${prefix}.copytool${archive_id}_log.${host}.log"
271 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
276 mkdir -p "$(dirname "$2")" ||
277 error "cannot create directory '$(dirname "$2")'"
278 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
283 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
284 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
285 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
286 [ ${#misc_options[@]} -gt 0 ] &&
287 cmd+=" $(IFS=" " echo "$@")"
288 cmd+=" \"$mountpoint\""
290 echo "Starting copytool $facet on $(facet_host $facet)"
291 stack_trap "do_facet $facet libtool execute pkill -x '$HSMTOOL' || true" EXIT
292 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
296 local facet="${1:-$SINGLEAGT}"
298 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
301 # Main entry point to perform copytool related operations
305 # setup setup a copytool to run in the background, that copytool will be
307 # import import a file from an HSM backend
308 # rebind rebind an archived file to a new fid
310 # Although the semantics might suggest otherwise, one does not need to 'setup'
311 # a copytool before a call to 'copytool import' or 'copytool rebind'.
319 local fail_on_error=true
320 local -a misc_options
321 while [ $# -gt 0 ]; do
329 local mountpoint="$1"
333 local archive_id="$1"
337 local bandwidth="$1" # in MB/s
340 local fail_on_error=false
343 # Uncommon(/copytool dependent) option
350 # Use default values if needed
351 local facet=${facet:-$SINGLEAGT}
352 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
353 local hsm_root="$(hsm_root "$facet")"
355 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
356 do_facet $facet mkdir -p "$hsm_root" ||
357 error "mkdir '$hsm_root' failed"
361 local copytool=lhsmtool
365 __${copytool}_${action} "${misc_options[@]}"
366 if [ $? -ne 0 ]; then
371 local host="$(facet_host $facet)"
372 error_msg="Failed to start copytool $facet on '$host'"
375 local src="${misc_options[0]}"
376 local dest="${misc_options[1]}"
377 error_msg="Failed to import '$src' to '$dest'"
380 error_msg="could not rebind file"
384 $fail_on_error && error "$error_msg" || echo "$error_msg"
388 get_copytool_event_log() {
389 local facet=${1:-$SINGLEAGT}
390 local agent=$(facet_active_host $facet)
392 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
393 error "Can't get event log: No monitor directory!"
395 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
396 error "Could not collect event log from $agent"
400 local agents=${1:-$(facet_active_host $SINGLEAGT)}
403 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
404 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
405 echo "Copytool is suspended on $agents"
408 copytool_continue() {
409 local agents=${1:-$(facet_active_host $SINGLEAGT)}
411 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
412 echo "Copytool is continued on $agents"
415 copytool_remove_backend() {
417 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
418 echo "Remove from backend: $fid = $be"
419 do_facet $SINGLEAGT rm -f $be
422 file_creation_failure() {
429 df $MOUNT $MOUNT2 >&2
430 error "Not enough space to create $file with $cmd"
433 error "cannot create $file with $cmd, status=$err"
438 # Creates a file using dd
444 local source=${5:-/dev/zero}
448 if [ -n "$conv" ]; then
452 # Create the directory in case it does not exist
453 mkdir -p "$(dirname "$file")"
454 # Delete the file in case it already exist
457 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
458 path2fid "$file" || error "cannot get FID of '$file'"
461 echo "cannot create file '$file'" >&2;
462 # Let the caller decide what to do on error
467 create_empty_file() {
468 create_file "${1/$DIR/$DIR2}" 1M 0 ||
469 file_creation_failure dd "${1/$DIR/$DIR2}" $?
472 create_small_file() {
473 local source_file=/dev/urandom
476 local conv=${2:-fsync}
478 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
479 file_creation_failure dd "${1/$DIR/$DIR2}" $?
482 create_small_sync_file() {
483 create_small_file "$1" sync
486 create_archive_file() {
487 local file="$(hsm_root)/$1"
489 local source=/dev/urandom
491 # Create the counterpart directory of the archive
492 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
493 error "cannot create archive directory '$(dirname "$file")'"
495 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
496 error "cannot create archive file '$file'"
500 local hsm_root="$(hsm_root)"
501 local file="$hsm_root/$2"
503 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
504 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
505 error "mkdir '$(dirname "$file")' failed"
506 do_facet $SINGLEAGT cp -p "$1" "$file" ||
507 error "cannot copy '$1' to '$file'"
516 if [[ "$value" != "" ]]; then
519 for mdtno in $(seq 1 $MDSCOUNT); do
520 local idx=$(($mdtno - 1))
521 local facet=mds${mdtno}
522 # if $arg include -P option, run 1 set_param per MDT on the MGS
523 # else, run set_param on each MDT
524 [[ $arg = *"-P"* ]] && facet=mgs
525 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
526 [[ $? != 0 ]] && rc=1
536 for mdtno in $(seq 1 $MDSCOUNT); do
537 local idx=$(($mdtno - 1))
538 wait_result mds${mdtno} \
539 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
541 error "$key state is not '$target' on mds${mdtno}"
547 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
555 mdts_set_param "$opt -n" "hsm.$param" "$value"
562 mdts_set_param "" hsm_control "$cmd"
563 mdts_check_param hsm_control "$target" 10
566 cdt_set_sanity_policy() {
567 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
570 mdts_set_param "" hsm.policy "+NRA"
571 mdts_set_param "" hsm.policy "-NBR"
572 CDT_POLICY_HAD_CHANGED=
577 mdts_set_param "" hsm.policy "+NRA"
578 CDT_POLICY_HAD_CHANGED=true
581 cdt_clear_no_retry() {
582 mdts_set_param "" hsm.policy "-NRA"
583 CDT_POLICY_HAD_CHANGED=true
586 cdt_set_non_blocking_restore() {
587 mdts_set_param "" hsm.policy "+NBR"
588 CDT_POLICY_HAD_CHANGED=true
591 cdt_clear_non_blocking_restore() {
592 mdts_set_param "" hsm.policy "-NBR"
593 CDT_POLICY_HAD_CHANGED=true
596 cdt_clear_mount_state() {
597 mdts_set_param "-P -d" hsm_control ""
600 cdt_set_mount_state() {
601 mdts_set_param "-P" hsm_control "$1"
602 # set_param -P is asynchronous operation and could race with set_param.
603 # In such case configs could be retrieved and applied at mgc after
604 # set_param -P completion. Sleep here to avoid race with set_param.
605 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
606 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
607 # and 10 seconds to retrieve config from server.
612 mdts_check_param hsm_control "$1" 20
616 set_test_state disabled disabled
620 set_test_state enabled enabled
624 set_test_state shutdown stopped
628 set_test_state purge enabled
634 cdt_set_sanity_policy
638 local client_count=$1
639 if [[ $CLIENTCOUNT -lt $client_count ]]; then
640 skip "Need $client_count or more clients, have $CLIENTCOUNT"
647 $LFS path2fid $1 | tr -d '[]'
648 return ${PIPESTATUS[0]}
656 if [[ $u == "user" ]]; then
657 st=$($RUNAS $LFS hsm_state $f)
660 st=$($LFS hsm_state $f)
663 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
665 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
669 get_hsm_archive_id() {
672 st=$($LFS hsm_state $f)
673 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
675 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
683 local st=$(get_hsm_flags $f)
684 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
687 check_hsm_flags_user() {
691 local st=$(get_hsm_flags $f user)
692 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
704 if [[ "$3" != 1 ]]; then
708 cp $1 $f || file_creation_failure cp $f $?
710 path2fid $f || error "cannot get fid on $f"
713 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
715 # Note that this might lead to surprising behaviours such as deleting an
716 # important file for the currently running test
717 delete_large_files() {
718 printf "Deleting large files...\n" >&2
719 find $MOUNT -size +10M -delete
720 wait_delete_completed
726 wait_update --verbose $(facet_active_host $facet) "$@"
729 wait_request_state() {
733 # 4th arg (mdt index) is optional
735 local mds=mds$(($mdtidx + 1))
737 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
738 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
740 wait_result $mds "$cmd" "$state" 200 ||
741 error "request on $fid is not $state on $mds"
744 get_request_state() {
748 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
749 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
752 get_request_count() {
756 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
757 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
760 # Ensure the number of HSM request for a given FID is correct
761 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
762 assert_request_count() {
763 local request_count=$(get_request_count $1 $2)
764 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
766 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
773 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
774 [[ -n $fid ]] && cmd+=" | grep '$fid'"
775 cmd+=" | egrep 'WAITING|STARTED'"
777 wait_result $SINGLEMDS "$cmd" "" $timeout ||
778 error "requests did not complete"
781 wait_for_grace_delay() {
782 local val=$(get_hsm_param grace_delay)
786 wait_for_loop_period() {
787 local val=$(get_hsm_param loop_period)
794 # python2.6 in EL6 includes an internal json module
795 local json_parser='import json; import fileinput;'
796 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
797 json_parser+='json.loads([line for line in '
798 json_parser+='fileinput.input()][0]).items()])'
800 echo $raw_event | python -c "$json_parser"
803 get_agent_by_uuid_mdt() {
806 local mds=mds$(($mdtidx + 1))
807 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
811 check_agent_registered_by_mdt() {
814 local mds=mds$(($mdtidx + 1))
815 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
816 if [[ ! -z "$agent" ]]; then
817 echo "found agent $agent on $mds"
819 error "uuid $uuid not found in agent list on $mds"
823 check_agent_unregistered_by_mdt() {
826 local mds=mds$(($mdtidx + 1))
827 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
828 if [[ -z "$agent" ]]; then
829 echo "uuid not found in agent list on $mds"
831 error "uuid found in agent list on $mds: $agent"
835 check_agent_registered() {
838 for mdsno in $(seq 1 $MDSCOUNT); do
839 check_agent_registered_by_mdt $uuid $((mdsno - 1))
843 check_agent_unregistered() {
846 for mdsno in $(seq 1 $MDSCOUNT); do
847 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
852 local agent=${1:-$(facet_active_host $SINGLEAGT)}
854 # Lustre mount-point is mandatory and last parameter on
856 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
858 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
860 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
866 # populate MDT device array
869 # cleanup from previous bad setup
872 # for recovery tests, coordinator needs to be started at mount
874 # the lustre conf must be without hsm on (like for sanity.sh)
875 echo "Set HSM on and start"
876 cdt_set_mount_state enabled
877 cdt_check_state enabled
879 echo "Set sanity-hsm HSM policy"
880 cdt_set_sanity_policy
882 # finished requests are quickly removed from list
883 set_hsm_param grace_delay 10
885 CLIENT_NIDS=( $($LCTL list_nids all) )
887 test_1A() { # was test_1
891 local f=$DIR/$tdir/$tfile
895 check_hsm_flags_user $f "0x00000000"
897 $RUNAS $LFS hsm_set --norelease $f ||
898 error "user could not change hsm flags"
899 check_hsm_flags_user $f "0x00000010"
901 $RUNAS $LFS hsm_clear --norelease $f ||
902 error "user could not clear hsm flags"
903 check_hsm_flags_user $f "0x00000000"
905 # User could not change those flags...
906 $RUNAS $LFS hsm_set --exists $f &&
907 error "user should not set this flag"
908 check_hsm_flags_user $f "0x00000000"
911 $LFS hsm_set --exists $f ||
912 error "root could not change hsm flags"
913 check_hsm_flags_user $f "0x00000001"
915 $LFS hsm_clear --exists $f ||
916 error "root could not clear hsm state"
917 check_hsm_flags_user $f "0x00000000"
920 run_test 1A "lfs hsm flags root/non-root access"
923 local f=$DIR/$tdir/$tfile
924 local fid=$(create_small_file $f)
928 $LFS hsm_archive $f || error "could not archive file"
929 wait_request_state $fid ARCHIVE SUCCEED
931 # Release and check states
932 $LFS hsm_release $f || error "could not release file"
933 echo -n "Verifying released state: "
934 check_hsm_flags $f "0x0000000d"
936 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
938 run_test 1a "mmap & cat a HSM released file"
942 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
943 error "failed to set default stripe"
944 local f=$DIR/$tdir/$tfile
947 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
948 error "failed to create file"
949 local fid=$(path2fid $f)
954 $LFS hsm_archive $f || error "could not archive file"
955 wait_request_state $fid ARCHIVE SUCCEED
958 $LFS hsm_release $f || error "could not release file"
959 echo "verify released state: "
960 check_hsm_flags $f "0x0000000d" && echo "pass"
963 $LFS hsm_restore $f || error "could not restore file"
964 wait_request_state $fid RESTORE SUCCEED
965 echo "verify restored state: "
966 check_hsm_flags $f "0x00000009" && echo "pass"
968 run_test 1b "Archive, Release and Restore composite file"
974 local f=$DIR/$tdir/$tfile
977 # Test whether we can set the maximum archive number.
978 local LOCAL_HSM_ARCHIVE_NUMBER=32
979 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
980 error "root could not change hsm flags"
981 check_hsm_flags_user $f "0x00000001"
982 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
983 local st=$(get_hsm_archive_id $f)
984 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
985 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
987 # Test whether setting archive number 0 results in no change.
988 $LFS hsm_set --exists --archive-id 0 $f ||
989 error "root could not change hsm flags"
990 check_hsm_flags_user $f "0x00000001"
991 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
992 st=$(get_hsm_archive_id $f)
993 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
994 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
996 LOCAL_HSM_ARCHIVE_NUMBER=33
997 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
998 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
999 # lustre in the new version supports unlimited archiveID.
1000 # Test whether setting archive number > 32 is supported
1001 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1002 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
1003 check_hsm_flags_user $f "0x00000001"
1005 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1006 st=$(get_hsm_archive_id $f)
1007 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1008 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1010 # old client or old mds can only support at most 32 archiveID
1011 # test whether setting archive number > 32 results in error.
1012 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
1013 error "bitmap archive number is larger than 32"
1014 check_hsm_flags_user $f "0x00000001"
1017 # Test whether setting archive number 16 and archived flag.
1018 LOCAL_HSM_ARCHIVE_NUMBER=16
1019 $LFS hsm_set --exists --archived \
1020 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1021 error "root could not change hsm flags"
1022 check_hsm_flags_user $f "0x00000009"
1023 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1024 st=$(get_hsm_archive_id $f)
1025 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1026 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1028 run_test 1c "Check setting archive-id in lfs hsm_set"
1031 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1032 skip "need MDS version at least 2.10.59"
1035 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1036 error "failed to set default stripe"
1037 local f=$DIR/$tdir/$tfile
1040 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1041 error "failed to create file"
1042 local fid=$(path2fid $f)
1047 $LFS hsm_archive $f || error "could not archive file"
1048 wait_request_state $fid ARCHIVE SUCCEED
1051 $LFS hsm_release $f || error "could not release file"
1052 echo "verify released state: "
1053 check_hsm_flags $f "0x0000000d" && echo "pass"
1056 $LFS hsm_restore $f || error "could not restore file"
1057 wait_request_state $fid RESTORE SUCCEED
1058 echo "verify restored state: "
1059 check_hsm_flags $f "0x00000009" && echo "pass"
1061 run_test 1d "Archive, Release and Restore DoM file"
1064 local f=$DIR/$tdir/$tfile
1066 create_empty_file "$f"
1067 # New files are not dirty
1068 check_hsm_flags $f "0x00000000"
1070 # For test, we simulate an archived file.
1071 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1072 check_hsm_flags $f "0x00000001"
1074 # chmod do not put the file dirty
1075 chmod 600 $f || error "could not chmod test file"
1076 check_hsm_flags $f "0x00000001"
1078 # chown do not put the file dirty
1079 chown $RUNAS_ID $f || error "could not chown test file"
1080 check_hsm_flags $f "0x00000001"
1082 # truncate put the file dirty
1083 $TRUNCATE $f 1 || error "could not truncate test file"
1084 check_hsm_flags $f "0x00000003"
1086 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1087 check_hsm_flags $f "0x00000001"
1089 run_test 2 "Check file dirtyness when doing setattr"
1095 # New files are not dirty
1096 cp -p /etc/passwd $f
1097 check_hsm_flags $f "0x00000000"
1099 # For test, we simulate an archived file.
1100 $LFS hsm_set --exists $f ||
1101 error "user could not change hsm flags"
1102 check_hsm_flags $f "0x00000001"
1104 # Reading a file, does not set dirty
1105 cat $f > /dev/null || error "could not read file"
1106 check_hsm_flags $f "0x00000001"
1108 # Open for write without modifying data, does not set dirty
1109 openfile -f O_WRONLY $f || error "could not open test file"
1110 check_hsm_flags $f "0x00000001"
1112 # Append to a file sets it dirty
1113 cp -p /etc/passwd $f.append || error "could not create file"
1114 $LFS hsm_set --exists $f.append ||
1115 error "user could not change hsm flags"
1116 dd if=/etc/passwd of=$f.append bs=1 count=3\
1117 conv=notrunc oflag=append status=noxfer ||
1118 file_creation_failure dd $f.append $?
1119 check_hsm_flags $f.append "0x00000003"
1121 # Modify a file sets it dirty
1122 cp -p /etc/passwd $f.modify || error "could not create file"
1123 $LFS hsm_set --exists $f.modify ||
1124 error "user could not change hsm flags"
1125 dd if=/dev/zero of=$f.modify bs=1 count=3\
1126 conv=notrunc status=noxfer ||
1127 file_creation_failure dd $f.modify $?
1128 check_hsm_flags $f.modify "0x00000003"
1130 # Open O_TRUNC sets dirty
1131 cp -p /etc/passwd $f.trunc || error "could not create file"
1132 $LFS hsm_set --exists $f.trunc ||
1133 error "user could not change hsm flags"
1134 cp /etc/group $f.trunc || error "could not override a file"
1135 check_hsm_flags $f.trunc "0x00000003"
1137 # Mmapped a file sets dirty
1138 cp -p /etc/passwd $f.mmap || error "could not create file"
1139 $LFS hsm_set --exists $f.mmap ||
1140 error "user could not change hsm flags"
1141 multiop $f.mmap OSMWUc || error "could not mmap a file"
1142 check_hsm_flags $f.mmap "0x00000003"
1144 run_test 3 "Check file dirtyness when opening for write"
1147 local f=$DIR/$tdir/$tfile
1148 local fid=$(create_small_file $f)
1151 local st=$(get_request_state $fid CANCEL)
1152 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1154 run_test 4 "Useless cancel must not be registered"
1157 # test needs a running copytool
1161 local f=$DIR/$tdir/$tfile
1162 local fid=$(copy_file /etc/passwd $f)
1164 wait_request_state $fid ARCHIVE SUCCEED
1166 check_hsm_flags $f "0x00000009"
1168 run_test 8 "Test default archive number"
1170 test_9A() { # was test_9
1171 # we do not use the default one to be sure
1172 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1173 copytool setup --archive-id $archive_id
1175 # give time for CT to register with MDTs
1176 sleep $(($MDSCOUNT*2))
1177 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1178 check_agent_registered $uuid
1181 local f=$DIR/$tdir/$tfile
1182 local fid=$(copy_file /etc/passwd $f)
1183 $LFS hsm_archive --archive $archive_id $f
1184 wait_request_state $fid ARCHIVE SUCCEED
1186 check_hsm_flags $f "0x00000009"
1188 run_test 9A "Use of explicit archive number, with dedicated copytool"
1191 needclients 3 || return 0
1197 # start all of the copytools
1198 for n in $(seq $AGTCOUNT); do
1199 copytool setup --facet agt$n
1203 for n in $(seq $AGTCOUNT); do
1204 file=$DIR/$tdir/$tfile.$n
1205 fid=$(create_small_file $file)
1207 $LFS hsm_archive $file || error "could not archive file $file"
1208 wait_request_state $fid ARCHIVE SUCCEED
1209 check_hsm_flags $file "0x00000009"
1212 run_test 9a "Multiple remote agents"
1215 # test needs a running copytool
1218 mkdir -p $DIR/$tdir/d1
1219 local f=$DIR/$tdir/$tfile
1220 local fid=$(copy_file /etc/hosts $f)
1221 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1222 error "hsm_archive failed"
1223 wait_request_state $fid ARCHIVE SUCCEED
1225 local hsm_root="$(copytool_device $SINGLEAGT)"
1226 local archive="$(do_facet $SINGLEAGT \
1227 find "$hsm_root" -name "$fid" -print0)"
1228 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1230 echo "Verifying content"
1231 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1232 echo "Verifying hsm state "
1233 check_hsm_flags $f "0x00000009"
1235 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1236 local st=$(get_hsm_archive_id $f)
1237 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1238 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1240 run_test 10a "Archive a file"
1243 # test needs a running copytool
1247 local f=$DIR/$tdir/$tfile
1248 local fid=$(copy_file /etc/hosts $f)
1249 $LFS hsm_archive $f || error "archive request failed"
1250 wait_request_state $fid ARCHIVE SUCCEED
1252 $LFS hsm_archive $f || error "archive of non dirty file failed"
1253 local cnt=$(get_request_count $fid ARCHIVE)
1254 [[ "$cnt" == "1" ]] ||
1255 error "archive of non dirty file must not make a request"
1257 run_test 10b "Archive of non dirty file must work without doing request"
1260 # test needs a running copytool
1264 local f=$DIR/$tdir/$tfile
1265 local fid=$(copy_file /etc/hosts $f)
1266 $LFS hsm_set --noarchive $f
1267 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1270 run_test 10c "Check forbidden archive"
1273 # test needs a running copytool
1277 local f=$DIR/$tdir/$tfile
1278 local fid=$(copy_file /etc/hosts $f)
1279 $LFS hsm_archive $f || error "cannot archive $f"
1280 wait_request_state $fid ARCHIVE SUCCEED
1282 local ar=$(get_hsm_archive_id $f)
1283 local dflt=$(get_hsm_param default_archive_id)
1284 [[ $ar == $dflt ]] ||
1285 error "archived file is not on default archive: $ar != $dflt"
1287 run_test 10d "Archive a file on the default archive id"
1291 copy2archive /etc/hosts $tdir/$tfile
1292 local f=$DIR/$tdir/$tfile
1294 copytool import $tdir/$tfile $f
1295 echo -n "Verifying released state: "
1296 check_hsm_flags $f "0x0000000d"
1298 local LSZ=$(stat -c "%s" $f)
1299 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1301 echo "Verifying imported size $LSZ=$ASZ"
1302 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1303 echo -n "Verifying released pattern: "
1304 local PTRN=$($GETSTRIPE -L $f)
1306 [[ $PTRN == released ]] || error "Is not released"
1307 local fid=$(path2fid $f)
1308 echo "Verifying new fid $fid in archive"
1310 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1311 error "No archive for fid $fid"
1313 run_test 11a "Import a file"
1316 # test needs a running copytool
1320 local f=$DIR/$tdir/$tfile
1321 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1323 error "hsm_archive failed"
1324 wait_request_state $fid ARCHIVE SUCCEED
1326 local FILE_HASH=$(md5sum $f)
1329 copytool import $fid $f
1331 echo "$FILE_HASH" | md5sum -c
1333 [[ $? -eq 0 ]] || error "Restored file differs"
1335 run_test 11b "Import a deleted file using its FID"
1338 # test needs a running copytool
1342 copy2archive /etc/hosts $tdir/$tfile
1344 local f=$DIR/$tdir/$tfile
1345 copytool import $tdir/$tfile $f
1346 local f2=$DIR2/$tdir/$tfile
1347 echo "Verifying released state: "
1348 check_hsm_flags $f2 "0x0000000d"
1350 local fid=$(path2fid $f2)
1351 $LFS hsm_restore $f2
1352 wait_request_state $fid RESTORE SUCCEED
1354 echo "Verifying file state: "
1355 check_hsm_flags $f2 "0x00000009"
1357 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1359 [[ $? -eq 0 ]] || error "Restored file differs"
1361 run_test 12a "Restore an imported file explicitly"
1364 # test needs a running copytool
1368 copy2archive /etc/hosts $tdir/$tfile
1370 local f=$DIR/$tdir/$tfile
1371 copytool import $tdir/$tfile $f
1372 echo "Verifying released state: "
1373 check_hsm_flags $f "0x0000000d"
1375 cat $f > /dev/null || error "File read failed"
1377 echo "Verifying file state after restore: "
1378 check_hsm_flags $f "0x00000009"
1380 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1382 [[ $? -eq 0 ]] || error "Restored file differs"
1384 run_test 12b "Restore an imported file implicitly"
1387 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1389 # test needs a running copytool
1392 local f=$DIR/$tdir/$tfile
1394 $LFS setstripe -c 2 "$f"
1395 local fid=$(create_file "$f" 1M 5)
1397 local FILE_CRC=$(md5sum $f)
1399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1400 wait_request_state $fid ARCHIVE SUCCEED
1401 $LFS hsm_release $f || error "release $f failed"
1403 echo "$FILE_CRC" | md5sum -c
1405 [[ $? -eq 0 ]] || error "Restored file differs"
1407 run_test 12c "Restore a file with stripe of 2"
1410 # test needs a running copytool
1415 local f=$DIR/$tdir/$tfile
1416 local fid=$(copy_file /etc/hosts $f)
1417 $LFS hsm_restore $f || error "restore of non archived file failed"
1418 local cnt=$(get_request_count $fid RESTORE)
1419 [[ "$cnt" == "0" ]] ||
1420 error "restore non archived must not make a request"
1421 $LFS hsm_archive $f ||
1422 error "archive request failed"
1423 wait_request_state $fid ARCHIVE SUCCEED
1424 $LFS hsm_restore $f ||
1425 error "restore of non released file failed"
1426 local cnt=$(get_request_count $fid RESTORE)
1427 [[ "$cnt" == "0" ]] ||
1428 error "restore a non dirty file must not make a request"
1430 run_test 12d "Restore of a non archived, non released file must work"\
1431 " without doing request"
1434 # test needs a running copytool
1438 local f=$DIR/$tdir/$tfile
1439 local fid=$(copy_file /etc/hosts $f)
1440 $LFS hsm_archive $f || error "archive request failed"
1441 wait_request_state $fid ARCHIVE SUCCEED
1444 cat /etc/hosts >> $f
1448 $LFS hsm_restore $f && error "restore a dirty file must fail"
1451 run_test 12e "Check forbidden restore"
1454 # test needs a running copytool
1458 local f=$DIR/$tdir/$tfile
1459 local fid=$(copy_file /etc/hosts $f)
1461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1462 wait_request_state $fid ARCHIVE SUCCEED
1463 $LFS hsm_release $f || error "release of $f failed"
1465 wait_request_state $fid RESTORE SUCCEED
1467 echo -n "Verifying file state: "
1468 check_hsm_flags $f "0x00000009"
1470 diff -q /etc/hosts $f
1472 [[ $? -eq 0 ]] || error "Restored file differs"
1474 run_test 12f "Restore a released file explicitly"
1477 # test needs a running copytool
1481 local f=$DIR/$tdir/$tfile
1482 local fid=$(copy_file /etc/hosts $f)
1484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1485 wait_request_state $fid ARCHIVE SUCCEED
1486 $LFS hsm_release $f || error "release of $f failed"
1488 diff -q /etc/hosts $f
1491 # we check we had a restore done
1492 wait_request_state $fid RESTORE SUCCEED
1494 [[ $st -eq 0 ]] || error "Restored file differs"
1496 run_test 12g "Restore a released file implicitly"
1499 needclients 2 || return 0
1501 # test needs a running copytool
1505 local f=$DIR/$tdir/$tfile
1506 local fid=$(copy_file /etc/hosts $f)
1508 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1509 wait_request_state $fid ARCHIVE SUCCEED
1510 $LFS hsm_release $f || error "release of $f failed"
1512 do_node $CLIENT2 diff -q /etc/hosts $f
1515 # we check we had a restore done
1516 wait_request_state $fid RESTORE SUCCEED
1518 [[ $st -eq 0 ]] || error "Restored file differs"
1520 run_test 12h "Restore a released file implicitly from a second node"
1523 # test needs a running copytool
1527 local f=$DIR/$tdir/$tfile
1528 local fid=$(copy_file /etc/passwd $f)
1529 $LFS hsm_archive $f || error "archive of $f failed"
1530 wait_request_state $fid ARCHIVE SUCCEED
1532 $LFS hsm_release $f || error "release of $f failed"
1536 [[ $? -eq 0 ]] || error "Restored file differs"
1538 run_test 12m "Archive/release/implicit restore"
1541 # test needs a running copytool
1545 copy2archive /etc/hosts $tdir/$tfile
1547 local f=$DIR/$tdir/$tfile
1548 copytool import $tdir/$tfile $f
1550 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1551 error "Restored file differs"
1553 $LFS hsm_release $f || error "release of $f failed"
1555 run_test 12n "Import/implicit restore/release"
1558 # test needs a running copytool
1562 local f=$DIR/$tdir/$tfile
1563 local fid=$(copy_file /etc/hosts $f)
1565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1566 wait_request_state $fid ARCHIVE SUCCEED
1567 $LFS hsm_release $f || error "release of $f failed"
1569 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1570 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1572 # set no retry action mode
1575 diff -q /etc/hosts $f
1578 # we check we had a restore failure
1579 wait_request_state $fid RESTORE FAILED
1581 [[ $st -eq 0 ]] && error "Restore must fail"
1583 # remove no retry action mode
1586 # check file is still released
1587 check_hsm_flags $f "0x0000000d"
1589 # retry w/o failure injection
1590 do_facet $SINGLEMDS lctl set_param fail_loc=0
1592 # to be sure previous RESTORE result is gone
1594 wait_for_grace_delay
1596 diff -q /etc/hosts $f
1599 # we check we had a restore done
1600 wait_request_state $fid RESTORE SUCCEED
1602 [[ $st -eq 0 ]] || error "Restored file differs"
1604 run_test 12o "Layout-swap failure during Restore leaves file released"
1607 # test needs a running copytool
1611 local f=$DIR/$tdir/$tfile
1612 local fid=$(copy_file /etc/hosts $f)
1614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1615 wait_request_state $fid ARCHIVE SUCCEED
1616 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1617 $LFS hsm_release $f || error "cannot release $f"
1618 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1619 $LFS hsm_release $f || error "cannot release $f"
1620 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1622 run_test 12p "implicit restore of a file on copytool mount point"
1625 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1626 skip "need MDS version at least 2.7.58"
1628 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1629 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1630 error "cannot mount $MOUNT3 on $SINGLEAGT"
1632 # test needs a running copytool
1633 copytool setup -m "$MOUNT3"
1635 local f=$DIR/$tdir/$tfile
1636 local f2=$DIR2/$tdir/$tfile
1637 local fid=$(create_small_file $f)
1638 local orig_size=$(stat -c "%s" $f)
1640 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1641 wait_request_state $fid ARCHIVE SUCCEED
1643 $LFS hsm_release $f || error "could not release file"
1644 check_hsm_flags $f "0x0000000d"
1647 wait_copytools || error "copytool failed to stop"
1649 cat $f > /dev/null &
1651 # wait a bit to allow implicit restore request to be handled.
1652 # if not, next stat would also block on layout-lock.
1655 local size=$(stat -c "%s" $f2)
1656 [ $size -eq $orig_size ] ||
1657 error "$f2: wrong size after archive: $size != $orig_size"
1659 copytool setup -m "$MOUNT3"
1663 size=$(stat -c "%s" $f)
1664 [ $size -eq $orig_size ] ||
1665 error "$f: wrong size after restore: $size != $orig_size"
1667 size=$(stat -c "%s" $f2)
1668 [ $size -eq $orig_size ] ||
1669 error "$f2: wrong size after restore: $size != $orig_size"
1673 size=$(stat -c "%s" $f)
1675 error "$f: wrong size after overwrite: $size != 0"
1677 size=$(stat -c "%s" $f2)
1679 error "$f2: wrong size after overwrite: $size != 0"
1681 run_test 12q "file attributes are refreshed after restore"
1685 for i in {1..10}; do
1686 local archive_dir="$(hsm_root)"/subdir/dir.$i
1688 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1689 for j in {1..10}; do
1690 local archive_file="$archive_dir"/file.$j
1692 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1698 copytool import "subdir" "$DIR/$tdir"
1700 # To check the import, the test uses diff with the -r flag
1701 # This is nice, but diff only checks files one by one, and triggering
1702 # an implicit restore for one file at a time will consume as many
1703 # seconds as there are files to compare. To speed this up, a restore
1704 # operation is triggered manually first.
1706 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1708 # Compare the imported data
1709 do_facet $SINGLEAGT \
1710 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1711 error "imported files differ from archived data"
1713 run_test 13 "Recursively import and restore a directory"
1716 # test needs a running copytool
1720 local f=$DIR/$tdir/$tfile
1721 local fid=$(create_small_file $f)
1722 local sum=$(md5sum $f | awk '{print $1}')
1723 $LFS hsm_archive $f || error "could not archive file"
1724 wait_request_state $fid ARCHIVE SUCCEED
1726 # create released file (simulate llapi_hsm_import call)
1727 local fid2=$(create_empty_file "$f")
1728 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1729 $LFS hsm_release $f || error "could not release file"
1731 # rebind the archive to the newly created file
1732 echo "rebind $fid to $fid2"
1734 copytool rebind $fid $fid2
1736 # restore file and compare md5sum
1737 local sum2=$(md5sum $f | awk '{print $1}')
1739 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1741 run_test 14 "Rebind archived file to a new fid"
1744 # test needs a running copytool
1748 local f=$DIR/$tdir/$tfile
1750 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1754 for i in $(seq 1 $count); do
1755 fids[$i]=$(create_small_file $f.$i)
1756 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1757 $LFS hsm_archive $f.$i || error "could not archive file"
1759 wait_all_done $(($count*60))
1761 stack_trap "rm -f $tmpfile" EXIT
1764 for i in $(seq 1 $count); do
1765 local fid2=$(create_empty_file "${f}.${i}")
1766 # add the rebind operation to the list
1767 echo ${fids[$i]} $fid2 >> $tmpfile
1769 # set it released (simulate llapi_hsm_import call)
1770 $LFS hsm_set --archived --exists $f.$i ||
1771 error "could not force hsm flags"
1772 $LFS hsm_release $f.$i || error "could not release file"
1774 nl=$(wc -l < $tmpfile)
1775 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1777 echo "rebind list of files"
1778 copytool rebind "$tmpfile"
1780 # restore files and compare md5sum
1781 for i in $(seq 1 $count); do
1782 local sum2=$(md5sum $f.$i | awk '{print $1}')
1783 [[ $sum2 == ${sums[$i]} ]] ||
1784 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1787 run_test 15 "Rebind a list of files"
1790 # test needs a running copytool
1794 # create a known size file so we can verify transfer speed
1797 dd if=/dev/zero of=$ref bs=1M count=20
1800 local f=$DIR/$tdir/$tfile
1801 local fid=$(copy_file $ref $f)
1803 local start=$(date +%s)
1805 wait_request_state $fid ARCHIVE SUCCEED
1806 local end=$(date +%s)
1807 # Add 1 to account for rounding errors between start and end (LU-8155)
1808 local duration=$((end - start + 1))
1810 [[ $duration -ge $((goal - 1)) ]] ||
1811 error "Transfer is too fast $duration < $goal"
1813 run_test 16 "Test CT bandwith control option"
1816 local f=$DIR/$tdir/$tfile
1817 create_empty_file "$f"
1819 # Could not release a non-archived file
1820 $LFS hsm_release $f && error "release should not succeed"
1822 # For following tests, we must test them with HS_ARCHIVED set
1823 $LFS hsm_set --exists --archived $f || error "could not add flag"
1825 # Could not release a file if no-release is set
1826 $LFS hsm_set --norelease $f || error "could not add flag"
1827 $LFS hsm_release $f && error "release should not succeed"
1828 $LFS hsm_clear --norelease $f || error "could not remove flag"
1830 # Could not release a file if lost
1831 $LFS hsm_set --lost $f || error "could not add flag"
1832 $LFS hsm_release $f && error "release should not succeed"
1833 $LFS hsm_clear --lost $f || error "could not remove flag"
1835 # Could not release a file if dirty
1836 $LFS hsm_set --dirty $f || error "could not add flag"
1837 $LFS hsm_release $f && error "release should not succeed"
1838 $LFS hsm_clear --dirty $f || error "could not remove flag"
1840 run_test 20 "Release is not permitted"
1843 # test needs a running copytool
1846 local f=$DIR/$tdir/test_release
1848 # Create a file and check its states
1849 local fid=$(create_small_file $f)
1850 check_hsm_flags $f "0x00000000"
1852 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1853 # used until file is flushed to disk
1854 if [ $(facet_fstype ost1) == "zfs" ]; then
1855 # this causes an OST_SYNC rpc to be sent
1856 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1857 # clear locks to reread file data
1858 cancel_lru_locks osc
1861 local orig_size=$(stat -c "%s" $f)
1862 local orig_blocks=$(stat -c "%b" $f)
1864 start_full_debug_logging
1866 $LFS hsm_archive $f || error "could not archive file"
1867 wait_request_state $fid ARCHIVE SUCCEED
1869 local blocks=$(stat -c "%b" $f)
1870 [ $blocks -eq $orig_blocks ] ||
1871 error "$f: wrong block number after archive: " \
1872 "$blocks != $orig_blocks"
1873 local size=$(stat -c "%s" $f)
1874 [ $size -eq $orig_size ] ||
1875 error "$f: wrong size after archive: $size != $orig_size"
1877 # Release and check states
1878 $LFS hsm_release $f || error "could not release file"
1879 check_hsm_flags $f "0x0000000d"
1881 blocks=$(stat -c "%b" $f)
1882 [ $blocks -gt 5 ] &&
1883 error "$f: too many blocks after release: $blocks > 5"
1884 size=$(stat -c "%s" $f)
1885 [ $size -ne $orig_size ] &&
1886 error "$f: wrong size after release: $size != $orig_size"
1888 # Check we can release an file without stripe info
1892 check_hsm_flags $f "0x00000000"
1893 $LFS hsm_archive $f || error "could not archive file"
1894 wait_request_state $fid ARCHIVE SUCCEED
1896 # Release and check states
1897 $LFS hsm_release $f || error "could not release file"
1898 check_hsm_flags $f "0x0000000d"
1900 # Release again a file that is already released is OK
1901 $LFS hsm_release $f || fail "second release should succeed"
1902 check_hsm_flags $f "0x0000000d"
1904 stop_full_debug_logging
1906 run_test 21 "Simple release tests"
1909 # test needs a running copytool
1912 local f=$DIR/$tdir/test_release
1913 local swap=$DIR/$tdir/test_swap
1915 # Create a file and check its states
1916 local fid=$(create_small_file $f)
1917 check_hsm_flags $f "0x00000000"
1919 $LFS hsm_archive $f || error "could not archive file"
1920 wait_request_state $fid ARCHIVE SUCCEED
1922 # Release and check states
1923 $LFS hsm_release $f || error "could not release file"
1924 check_hsm_flags $f "0x0000000d"
1926 create_small_file $swap
1927 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1931 run_test 22 "Could not swap a release file"
1934 # test needs a running copytool
1937 local f=$DIR/$tdir/test_mtime
1939 # Create a file and check its states
1940 local fid=$(create_small_file $f)
1941 check_hsm_flags $f "0x00000000"
1943 $LFS hsm_archive $f || error "could not archive file"
1944 wait_request_state $fid ARCHIVE SUCCEED
1946 # Set modification time in the past
1947 touch -m -a -d @978261179 $f
1949 # Release and check states
1950 $LFS hsm_release $f || error "could not release file"
1951 check_hsm_flags $f "0x0000000d"
1953 local MTIME=$(stat -c "%Y" $f)
1954 local ATIME=$(stat -c "%X" $f)
1955 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1956 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1958 run_test 23 "Release does not change a/mtime (utime)"
1961 local file=$DIR/$tdir/$tfile
1970 # test needs a running copytool
1973 fid=$(create_small_file $file)
1975 # Create a file and check its states
1976 check_hsm_flags $file "0x00000000"
1978 # Ensure atime is less than mtime and ctime.
1982 atime0=$(stat -c "%X" $file)
1983 mtime0=$(stat -c "%Y" $file)
1984 ctime0=$(stat -c "%Z" $file)
1986 [ $atime0 -lt $mtime0 ] ||
1987 error "atime $atime0 is not less than mtime $mtime0"
1989 [ $atime0 -lt $ctime0 ] ||
1990 error "atime $atime0 is not less than ctime $ctime0"
1992 # Archive should not change any timestamps.
1993 $LFS hsm_archive $file || error "cannot archive '$file'"
1994 wait_request_state $fid ARCHIVE SUCCEED
1996 atime1=$(stat -c "%X" $file)
1997 mtime1=$(stat -c "%Y" $file)
1998 ctime1=$(stat -c "%Z" $file)
2000 [ $atime0 -eq $atime1 ] ||
2001 error "archive changed atime from $atime0 to $atime1"
2003 [ $mtime0 -eq $mtime1 ] ||
2004 error "archive changed mtime from $mtime0 to $mtime1"
2006 [ $ctime0 -eq $ctime1 ] ||
2007 error "archive changed ctime from $ctime0 to $ctime1"
2009 # Release should not change any timestamps.
2010 $LFS hsm_release $file || error "cannot release '$file'"
2011 check_hsm_flags $file "0x0000000d"
2013 atime1=$(stat -c "%X" $file)
2014 mtime1=$(stat -c "%Y" $file)
2015 ctime1=$(stat -c "%Z" $file)
2017 [ $atime0 -eq $atime1 ] ||
2018 error "release changed atime from $atime0 to $atime1"
2020 [ $mtime0 -eq $mtime1 ] ||
2021 error "release changed mtime from $mtime0 to $mtime1"
2023 [ $ctime0 -eq $ctime1 ] ||
2024 error "release changed ctime from $ctime0 to $ctime1"
2026 # Restore should not change any timestamps.
2027 $LFS hsm_restore $file
2028 wait_request_state $fid RESTORE SUCCEED
2030 atime1=$(stat -c "%X" $file)
2031 mtime1=$(stat -c "%Y" $file)
2032 ctime1=$(stat -c "%Z" $file)
2034 [ $atime0 -eq $atime1 ] ||
2035 error "restore changed atime from $atime0 to $atime1"
2037 [ $mtime0 -eq $mtime1 ] ||
2038 error "restore changed mtime from $mtime0 to $mtime1"
2040 [ $ctime0 -eq $ctime1 ] ||
2041 error "restore changed ctime from $ctime0 to $ctime1"
2044 wait_copytools || error "Copytools failed to stop"
2046 # Once more, after unmount and mount.
2047 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2048 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2050 atime1=$(stat -c "%X" $file)
2051 mtime1=$(stat -c "%Y" $file)
2052 ctime1=$(stat -c "%Z" $file)
2054 [ $atime0 -eq $atime1 ] ||
2055 error "remount changed atime from $atime0 to $atime1"
2057 [ $mtime0 -eq $mtime1 ] ||
2058 error "remount changed mtime from $mtime0 to $mtime1"
2060 [ $ctime0 -eq $ctime1 ] ||
2061 error "remount changed ctime from $ctime0 to $ctime1"
2063 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2066 local file=$DIR/$tdir/$tfile
2072 # Test needs a running copytool.
2075 # Check that root can do HSM actions on a regular user's file.
2076 fid=$(create_small_file $file)
2077 sum0=$(md5sum $file)
2079 chown $RUNAS_ID:$RUNAS_GID $file ||
2080 error "cannot chown '$file' to '$RUNAS_ID'"
2082 chmod ugo-w $DIR/$tdir ||
2083 error "cannot chmod '$DIR/$tdir'"
2085 $LFS hsm_archive $file
2086 wait_request_state $fid ARCHIVE SUCCEED
2088 $LFS hsm_release $file
2089 check_hsm_flags $file "0x0000000d"
2091 $LFS hsm_restore $file
2092 wait_request_state $fid RESTORE SUCCEED
2094 # Check that ordinary user can get HSM state.
2095 $RUNAS $LFS hsm_state $file ||
2096 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2098 $LFS hsm_release $file
2099 check_hsm_flags $file "0x0000000d"
2101 # Check that ordinary user can accessed released file.
2102 sum1=$($RUNAS md5sum $file) ||
2103 error "user '$RUNAS_ID' cannot read '$file'"
2105 [ "$sum0" == "$sum1" ] ||
2106 error "md5sum mismatch for '$file'"
2108 run_test 24b "root can archive, release, and restore user files"
2111 local file=$DIR/$tdir/$tfile
2112 local action=archive
2117 # test needs a running copytool
2122 # Save the default masks and check that cleanup_24c will
2123 # restore the request masks correctly.
2124 user_save=$(get_hsm_param user_request_mask)
2125 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2126 group_save=$(get_hsm_param group_request_mask)
2127 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2128 other_save=$(get_hsm_param other_request_mask)
2129 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2131 [ "$user_save" == RESTORE ] ||
2132 error "user_request_mask is '$user_save' expected 'RESTORE'"
2133 [ "$group_save" == RESTORE ] ||
2134 error "group_request_mask is '$group_save' expected 'RESTORE'"
2135 [ "$other_save" == RESTORE ] ||
2136 error "other_request_mask is '$other_save' expected 'RESTORE'"
2139 create_small_file $file
2140 chown $RUNAS_ID:$GROUP $file ||
2141 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2143 $RUNAS $LFS hsm_$action $file &&
2144 error "$action by user should fail"
2146 set_hsm_param user_request_mask $action
2147 $RUNAS $LFS hsm_$action $file ||
2148 error "$action by user should succeed"
2151 create_small_file $file
2152 chown nobody:$RUNAS_GID $file ||
2153 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2155 $RUNAS $LFS hsm_$action $file &&
2156 error "$action by group should fail"
2158 set_hsm_param group_request_mask $action
2159 $RUNAS $LFS hsm_$action $file ||
2160 error "$action by group should succeed"
2163 create_small_file $file
2164 chown nobody:$GROUP $file ||
2165 error "cannot chown '$file' to 'nobody:$GROUP'"
2167 $RUNAS $LFS hsm_$action $file &&
2168 error "$action by other should fail"
2170 set_hsm_param other_request_mask $action
2171 $RUNAS $LFS hsm_$action $file ||
2172 error "$action by other should succeed"
2174 run_test 24c "check that user,group,other request masks work"
2177 local file1=$DIR/$tdir/$tfile
2178 local file2=$DIR2/$tdir/$tfile
2182 fid1=$(create_small_file $file1)
2185 $LFS getstripe $file1
2187 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2188 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2189 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2191 copytool setup -m "$MOUNT3"
2193 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2194 mount -o remount,ro $MOUNT2
2196 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2198 fid2=$(path2fid $file2)
2199 [ "$fid1" == "$fid2" ] ||
2200 error "FID mismatch '$fid1' != '$fid2'"
2202 $LFS hsm_archive $file2 &&
2203 error "archive should fail on read-only mount"
2204 check_hsm_flags $file1 "0x00000000"
2206 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2207 wait_request_state $fid1 ARCHIVE SUCCEED
2209 $LFS hsm_release $file1
2210 $LFS hsm_restore $file2
2211 wait_request_state $fid1 RESTORE SUCCEED
2213 $LFS hsm_release $file1 || error "cannot release '$file1'"
2214 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2216 $LFS hsm_release $file2 &&
2217 error "release should fail on read-only mount"
2221 run_test 24d "check that read-only mounts are respected"
2226 local f=$DIR/$tdir/$tfile
2229 fid=$(create_small_file $f) || error "cannot create $f"
2230 $LFS hsm_archive $f || error "cannot archive $f"
2231 wait_request_state $fid ARCHIVE SUCCEED
2232 $LFS hsm_release $f || error "cannot release $f"
2233 while ! $LFS hsm_state $f | grep released; do
2237 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2239 run_test 24e "tar succeeds on HSM released files" # LU-6213
2242 # test needs a running copytool
2245 mkdir -p $DIR/$tdir/d1
2246 local f=$DIR/$tdir/$tfile
2247 local fid=$(copy_file /etc/hosts $f)
2250 $LFS hsm_archive $f ||
2251 error "hsm_archive failed"
2252 wait_request_state $fid ARCHIVE SUCCEED
2253 $LFS hsm_release $f || error "cannot release $f"
2254 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2257 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2258 error "Can not recover the tar contents"
2260 echo "Sum0 = $sum0, sum1 = $sum1"
2261 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2263 run_test 24f "root can archive, release, and restore tar files"
2266 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2267 skip "need MDS version 2.11.56 or later"
2269 local file=$DIR/$tdir/$tfile
2272 echo "RUNAS = '$RUNAS'"
2277 chmod ugo+rwx $DIR/$tdir
2279 echo "Please listen carefully as our options have changed." | tee $file
2280 fid=$(path2fid $file)
2283 $LFS hsm_archive $file
2284 wait_request_state $fid ARCHIVE SUCCEED
2285 check_hsm_flags $file 0x00000009 # exists archived
2287 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2288 check_hsm_flags $file 0x0000000b # exists dirty archived
2290 run_test 24g "write by non-owner still sets dirty" # LU-11369
2293 # test needs a running copytool
2297 copy2archive /etc/hosts $tdir/$tfile
2299 local f=$DIR/$tdir/$tfile
2301 copytool import $tdir/$tfile $f
2303 $LFS hsm_set --lost $f
2308 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2310 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2311 " (Operation not permitted)"
2314 # test needs a running copytool
2319 local f=$DIR/$tdir/$tfile
2320 local fid=$(copy_file /etc/passwd $f)
2322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2323 wait_request_state $fid ARCHIVE SUCCEED
2326 $LFS hsm_set --lost $f
2330 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2332 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2333 " (Operation not permitted)"
2335 test_26A() { # was test_26
2336 # test needs a running copytool
2339 local f=$DIR/$tdir/$tfile
2340 local fid=$(create_empty_file "$f")
2342 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2343 wait_request_state $fid ARCHIVE SUCCEED
2346 wait_request_state $fid REMOVE SUCCEED
2348 check_hsm_flags $f "0x00000000"
2350 run_test 26A "Remove the archive of a valid file"
2353 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2354 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2356 # test needs a running copytool
2360 local f=$DIR/$tdir/$tfile
2361 local fid=$(copy_file /etc/passwd $f)
2363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2364 wait_request_state $fid ARCHIVE SUCCEED
2366 local f2=$DIR/$tdir/${tfile}_2
2367 local fid2=$(copy_file /etc/passwd $f2)
2369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2370 wait_request_state $fid2 ARCHIVE SUCCEED
2372 local f3=$DIR/$tdir/${tfile}_3
2373 local fid3=$(copy_file /etc/passwd $f3)
2375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2376 wait_request_state $fid3 ARCHIVE SUCCEED
2378 # set a long grace_delay vs short loop_period
2379 local orig_loop_period=$(get_hsm_param loop_period)
2380 local orig_grace_delay=$(get_hsm_param grace_delay)
2381 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2382 set_hsm_param loop_period 10
2383 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2384 set_hsm_param grace_delay 100
2388 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2389 set_hsm_param remove_archive_on_last_unlink 1
2391 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2396 wait_request_state $fid2 REMOVE SUCCEED
2398 assert_request_count $fid REMOVE 0 \
2399 "Unexpected archived data remove request for $f"
2400 assert_request_count $fid3 REMOVE 0 \
2401 "Unexpected archived data remove request for $f3"
2403 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2406 # test needs a running copytool
2410 local f=$DIR/$tdir/$tfile
2411 local fid=$(copy_file /etc/passwd $f)
2413 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2414 wait_request_state $fid ARCHIVE SUCCEED
2416 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2417 set_hsm_param remove_archive_on_last_unlink 1
2420 cdt_check_state stopped
2424 wait_request_state $fid REMOVE WAITING
2428 # copytool must re-register
2430 wait_copytools || error "copytool failed to stop"
2433 wait_request_state $fid REMOVE SUCCEED
2435 run_test 26b "RAoLU policy when CDT off"
2438 # test needs a running copytool
2442 local f=$DIR/$tdir/$tfile
2443 local fid=$(copy_file /etc/passwd $f)
2445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2446 wait_request_state $fid ARCHIVE SUCCEED
2448 local f2=$DIR/$tdir/${tfile}_2
2449 local fid2=$(copy_file /etc/passwd $f2)
2451 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2452 wait_request_state $fid2 ARCHIVE SUCCEED
2454 # set a long grace_delay vs short loop_period
2455 local orig_loop_period=$(get_hsm_param loop_period)
2456 local orig_grace_delay=$(get_hsm_param grace_delay)
2457 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2458 set_hsm_param loop_period 10
2459 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2460 set_hsm_param grace_delay 100
2462 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2463 set_hsm_param remove_archive_on_last_unlink 1
2465 multiop_bg_pause $f O_c || error "open $f failed"
2471 wait_request_state $fid2 REMOVE SUCCEED
2472 assert_request_count $fid REMOVE 0 \
2473 "Unexpected archived data remove request for $f"
2475 kill -USR1 $pid || error "multiop early exit"
2476 # should reach autotest timeout if multiop fails to trap
2477 # signal, close file, and exit ...
2478 wait $pid || error "wait PID $PID failed"
2480 wait_request_state $fid REMOVE SUCCEED
2482 run_test 26c "RAoLU effective when file closed"
2485 # test needs a running copytool
2489 local f=$DIR/$tdir/$tfile
2490 local fid=$(create_small_file $f)
2492 $LFS hsm_archive $f || error "could not archive file"
2493 wait_request_state $fid ARCHIVE SUCCEED
2495 # set a long grace_delay vs short loop_period
2496 local orig_loop_period=$(get_hsm_param loop_period)
2497 local orig_grace_delay=$(get_hsm_param grace_delay)
2498 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2499 set_hsm_param loop_period 10
2500 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2501 set_hsm_param grace_delay 100
2503 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2504 set_hsm_param remove_archive_on_last_unlink 1
2506 multiop_bg_pause $f O_c || error "multiop failed"
2513 wait_request_state $fid REMOVE SUCCEED
2515 client_up || client_up || true
2517 kill -USR1 $MULTIPID
2518 wait $MULTIPID || error "multiop close failed"
2520 run_test 26d "RAoLU when Client eviction"
2523 # test needs a running copytool
2526 create_archive_file $tdir/$tfile
2527 local f=$DIR/$tdir/$tfile
2528 copytool import $tdir/$tfile $f
2529 local fid=$(path2fid $f)
2533 [[ $? != 0 ]] || error "Remove of a released file should fail"
2535 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2538 # test needs a running copytool
2541 local f=$DIR/$tdir/$tfile
2542 local fid=$(create_empty_file "$f")
2544 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2545 wait_request_state $fid ARCHIVE SUCCEED
2550 [[ $? != 0 ]] || error "Remove of a released file should fail"
2552 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2555 # test needs a running copytool
2558 local f=$DIR/$tdir/$tfile
2559 local fid=$(create_empty_file "$f")
2561 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2562 wait_request_state $fid ARCHIVE SUCCEED
2571 wait_request_state $fid REMOVE SUCCEED
2573 run_test 28 "Concurrent archive/file remove"
2576 # Tests --mntpath and --archive options
2579 copytool setup -m "$MOUNT" -a $archive_id
2581 # Bad archive number
2582 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2583 grep "Invalid argument" ||
2584 error "unexpected hsm_remove failure (1)"
2586 # mntpath is present but file is given
2587 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2588 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2589 error "unexpected hsm_remove failure (2)"
2591 run_test 29a "Tests --mntpath and --archive options"
2594 # test needs a running copytool
2597 local f=$DIR/$tdir/$tfile
2598 local fid=$(create_small_file $f)
2600 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2601 wait_request_state $fid ARCHIVE SUCCEED
2605 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2606 wait_request_state $fid REMOVE SUCCEED
2608 run_test 29b "Archive/delete/remove by FID from the archive."
2611 # test needs a running copytool
2614 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2615 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2616 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2619 wait_request_state $fid1 ARCHIVE SUCCEED
2620 wait_request_state $fid2 ARCHIVE SUCCEED
2621 wait_request_state $fid3 ARCHIVE SUCCEED
2623 rm -f $DIR/$tdir/$tfile-[1-3]
2625 echo $fid1 > $DIR/$tdir/list
2626 echo $fid2 >> $DIR/$tdir/list
2627 echo $fid3 >> $DIR/$tdir/list
2629 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2630 --filelist $DIR/$tdir/list
2631 wait_request_state $fid1 REMOVE SUCCEED
2632 wait_request_state $fid2 REMOVE SUCCEED
2633 wait_request_state $fid3 REMOVE SUCCEED
2635 run_test 29c "Archive/delete/remove by FID, using a file list."
2638 # test needs more than one CT
2639 needclients 3 || return 0
2645 # start all of the copytools
2646 for n in $(seq $AGTCOUNT); do
2647 copytool setup -f agt$n -a $n
2651 file=$DIR/$tdir/$tfile
2652 fid=$(create_small_file $file)
2654 $LFS hsm_archive $file
2655 wait_request_state $fid ARCHIVE SUCCEED
2656 check_hsm_flags $file "0x00000009"
2660 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2661 error "cannot hsm_remove '$fid'"
2663 # give time for CDT to handle remove request and create broadcasted
2666 # remove request has been broadcasted ?
2667 local cnt=$(get_request_count $fid REMOVE)
2668 # broadcasted requests + original
2669 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2670 error "remove not broadcasted to all CTs"
2672 # give time for CDT and CTs to handle broadcasted
2673 wait_for_loop_period
2675 # each agent serves one different archive_id, so broadcasted
2676 # hsm_remove request should only succeed once and fail at all others
2680 for n in $(seq $AGTCOUNT); do
2681 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2682 $HSM_PARAM.actions | awk \
2683 '/'$fid'.*action=REMOVE archive#='$n'/ \
2684 {print \\\$13}' | cut -f2 -d=")
2685 if [[ "$res" == "SUCCEED" ]]; then
2687 elif [[ "$res" == "FAILED" ]]; then
2692 [[ $scnt -eq 1 ]] ||
2693 error "one and only CT should have removed successfully"
2695 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2696 error "all but one CT should have failed to remove"
2698 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2699 "request to be sent once for each registered archive_id"
2702 # restore at exec cannot work on agent node (because of Linux kernel
2703 # protection of executables)
2704 needclients 2 || return 0
2706 # test needs a running copytool
2710 copy2archive /bin/true $tdir/$tfile
2712 local f=$DIR/$tdir/true
2713 copytool import $tdir/$tfile $f
2715 local fid=$(path2fid $f)
2717 stack_trap "cdt_clear_no_retry" EXIT
2718 # set no retry action mode
2725 [[ $st == 0 ]] || error "Failed to exec a released file"
2727 run_test 30a "Restore at exec (import case)"
2730 # restore at exec cannot work on agent node (because of Linux kernel
2731 # protection of executables)
2732 needclients 2 || return 0
2734 # test needs a running copytool
2738 local f=$DIR/$tdir/true
2739 local fid=$(copy_file /bin/true $f)
2741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2742 wait_request_state $fid ARCHIVE SUCCEED
2746 stack_trap cdt_clear_no_retry EXIT
2747 # set no retry action mode
2755 [[ $st == 0 ]] || error "Failed to exec a released file"
2757 run_test 30b "Restore at exec (release case)"
2760 needclients 2 || return 0
2762 # test needs a running copytool
2766 local f=$DIR/$tdir/SLEEP
2767 local slp_sum1=$(md5sum /bin/sleep)
2768 local fid=$(copy_file /bin/sleep $f)
2770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2771 wait_request_state $fid ARCHIVE SUCCEED
2773 check_hsm_flags $f "0x0000000d"
2775 stack_trap cdt_clear_no_retry EXIT
2776 # set no retry action mode
2779 do_node $CLIENT2 "$f 10" &
2783 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2785 [[ $? == 0 ]] || error "Execution failed during run"
2787 if [[ $? != 0 ]]; then
2788 local slp_sum2=$(md5sum /bin/sleep)
2789 # in case sleep file is modified during the test
2790 [[ $slp_sum1 == $slp_sum2 ]] &&
2791 error "Binary overwritten during exec"
2794 check_hsm_flags $f "0x00000009"
2796 run_test 30c "Update during exec of released file must fail"
2798 restore_and_check_size() {
2801 local s=$(stat -c "%s" $f)
2803 local st=$(get_hsm_flags $f)
2807 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2809 n=$(stat -c "%s" $f)
2810 # we echo in both cases to show stat is not hang
2811 if [[ $n != $s ]]; then
2812 echo "size seen is $n != $s"
2815 echo "size seen is right: $n == $s"
2819 st=$(get_hsm_flags $f)
2821 if [[ "$st" = "0x00000009" ]]; then
2824 echo " restore is too long"
2825 wait_request_state $fid RESTORE SUCCEED
2831 # test needs a running copytool
2834 create_archive_file $tdir/$tfile
2835 local f=$DIR/$tdir/$tfile
2836 copytool import $tdir/$tfile $f
2837 local fid=$($LFS path2fid $f)
2840 restore_and_check_size $f $fid
2843 [[ $err -eq 0 ]] || error "File size changed during restore"
2845 run_test 31a "Import a large file and check size during restore"
2849 # test needs a running copytool
2852 local f=$DIR/$tdir/$tfile
2853 local fid=$(create_file "$f" 1MB 39)
2855 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2856 wait_request_state $fid ARCHIVE SUCCEED
2859 restore_and_check_size $f $fid
2862 [[ $err -eq 0 ]] || error "File size changed during restore"
2864 run_test 31b "Restore a large unaligned file and check size during restore"
2867 # test needs a running copytool
2870 local f=$DIR/$tdir/$tfile
2871 local fid=$(create_file "$f" 1M 39)
2873 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2874 wait_request_state $fid ARCHIVE SUCCEED
2877 restore_and_check_size $f $fid
2880 [[ $err -eq 0 ]] || error "File size changed during restore"
2882 run_test 31c "Restore a large aligned file and check size during restore"
2885 local f=$DIR/$tdir/$tfile
2886 local fid=$(create_empty_file "$f")
2890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2891 wait_request_state $fid ARCHIVE SUCCEED
2894 # Prevent restore from completing
2898 md5sum $f >/dev/null &
2901 wait_request_state $fid RESTORE STARTED
2906 # Check restore trigger process was killed
2908 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2910 run_test 33 "Kill a restore waiting process"
2913 # test needs a running copytool
2916 local f=$DIR/$tdir/$tfile
2917 local fid=$(create_empty_file "$f")
2919 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2920 wait_request_state $fid ARCHIVE SUCCEED
2923 # Prevent restore from completing
2926 md5sum $f >/dev/null &
2929 wait_request_state $fid RESTORE STARTED
2931 # rm must not block during restore
2932 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2935 wait_request_state $fid RESTORE SUCCEED
2937 # Check md5sum pgm finished
2938 kill -0 $pid && error "Restore initiatior still running"
2939 wait $pid || error "Restore initiator failed with $?"
2941 # Check the file was actually deleted
2942 [ ! -f "$f" ] || error "$f was not deleted"
2944 run_test 34 "Remove file during restore"
2947 # test needs a running copytool
2950 local f=$DIR/$tdir/$tfile
2951 local f1=$DIR/$tdir/$tfile-1
2952 local fid=$(create_empty_file "$f")
2953 local fid1=$(copy_file /etc/passwd $f1)
2955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2956 wait_request_state $fid ARCHIVE SUCCEED
2959 # Prevent restore from completing
2962 md5sum $f >/dev/null &
2965 wait_request_state $fid RESTORE STARTED
2967 # mv must not block during restore
2968 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2971 wait_request_state $fid RESTORE SUCCEED
2973 # Check md5sum pgm finished
2974 kill -0 $pid && error "Restore initiatior still running"
2975 wait $pid || error "Restore initiator failed with $?"
2977 local fid2=$(path2fid $f)
2978 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2980 run_test 35 "Overwrite file during restore"
2983 # test needs a running copytool
2986 local f=$DIR/$tdir/$tfile
2987 local fid=$(create_empty_file "$f")
2989 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2990 wait_request_state $fid ARCHIVE SUCCEED
2993 # Prevent restore from completing
2996 md5sum $f >/dev/null &
2999 wait_request_state $fid RESTORE STARTED
3001 # mv must not block during restore
3002 timeout --signal=KILL 10 mv "$f" "$f.new" ||
3003 error "mv '$f' '$f.new' failed with rc=$?"
3006 wait_request_state $fid RESTORE SUCCEED
3008 # Check md5sum pgm finished
3009 kill -0 $pid && error "Restore initiator is still running"
3010 wait $pid || error "Restore initiator failed with $?"
3012 run_test 36 "Move file during restore"
3015 # LU-5683: check that an archived dirty file can be rearchived.
3018 local f=$DIR/$tdir/$tfile
3021 fid=$(create_small_file $f) || error "cannot create small file"
3023 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3024 wait_request_state $fid ARCHIVE SUCCEED
3025 $LFS hsm_release $f || error "cannot release $f"
3027 # Allow previous archive request to expire from the actions log.
3028 wait_for_grace_delay
3031 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3034 wait_request_state $fid ARCHIVE SUCCEED
3036 run_test 37 "re-archive a dirty file"
3043 for n in $(seq 1 $count); do
3044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3046 echo "$count archive requests submitted"
3050 local stream_count=4
3051 local file_count=100
3053 local f=$DIR/$tdir/$tfile
3057 local max_requests=$(get_hsm_param max_requests)
3059 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3060 # Increase the number of HSM request that can be performed in
3061 # parallel. With the coordinator running once per second, this
3062 # also limits the number of requests per seconds that can be
3063 # performed, so we pick a decent number. But we also need to keep
3064 # that number low because the copytool has no rate limit and will
3065 # fail some requests if if gets too many at once.
3066 set_hsm_param max_requests 300
3068 for i in $(seq 1 $file_count); do
3069 for p in $(seq 1 $stream_count); do
3070 fid=$(copy_file /etc/hosts $f.$p.$i)
3076 # to be sure wait_all_done will not be mislead by previous tests
3078 wait_for_grace_delay
3080 # start archive streams in background (archive files in parallel)
3081 for p in $(seq 1 $stream_count); do
3082 multi_archive $f.$p $file_count &
3085 echo -n "Wait for all requests being enqueued..."
3090 run_test 40 "Parallel archive requests"
3093 # test needs a running copytool
3097 local f=$DIR/$tdir/$tfile
3098 local fid=$(create_small_file $f)
3100 $LFS hsm_archive $f || error "could not archive file"
3101 wait_request_state $fid ARCHIVE SUCCEED
3102 check_hsm_flags $f "0x00000009"
3104 multiop_bg_pause $f O_c || error "multiop failed"
3108 client_up || client_up || true
3110 kill -USR1 $MULTIPID
3111 wait $MULTIPID || error "multiop close failed"
3113 check_hsm_flags $f "0x0000000b"
3115 run_test 52 "Opened for write file on an evicted client should be set dirty"
3118 # test needs a running copytool
3122 local f=$DIR/$tdir/$tfile
3123 local fid=$(create_small_file $f)
3125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3126 error "could not archive file"
3127 wait_request_state $fid ARCHIVE SUCCEED
3128 check_hsm_flags $f "0x00000009"
3130 multiop_bg_pause $f o_c || error "multiop failed"
3134 client_up || client_up || true
3136 kill -USR1 $MULTIPID
3137 wait $MULTIPID || error "multiop close failed"
3139 check_hsm_flags $f "0x00000009"
3141 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3144 local f=$DIR/$tdir/$tfile
3145 local fid=$(create_file "$f" 1MB 39)
3149 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3150 error "could not archive file"
3151 wait_request_state $fid ARCHIVE STARTED
3153 check_hsm_flags $f "0x00000001"
3155 stack_trap "cdt_clear_no_retry" EXIT
3156 # Avoid coordinator resending this request as soon it has failed.
3161 wait_request_state $fid ARCHIVE FAILED
3163 check_hsm_flags $f "0x00000003"
3165 run_test 54 "Write during an archive cancels it"
3168 local f=$DIR/$tdir/$tfile
3169 local fid=$(create_file "$f" 1MB 39)
3173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3174 error "could not archive file"
3175 wait_request_state $fid ARCHIVE STARTED
3177 check_hsm_flags $f "0x00000001"
3179 stack_trap "cdt_clear_no_retry" EXIT
3180 # Avoid coordinator resending this request as soon it has failed.
3183 $TRUNCATE $f 1024 || error "truncate failed"
3185 wait_request_state $fid ARCHIVE FAILED
3187 check_hsm_flags $f "0x00000003"
3189 run_test 55 "Truncate during an archive cancels it"
3192 local f=$DIR/$tdir/$tfile
3193 local fid=$(create_file "$f" 1MB 39)
3197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3198 error "could not archive file"
3199 wait_request_state $fid ARCHIVE STARTED
3201 check_hsm_flags $f "0x00000001"
3203 # Change metadata and sync to be sure we are not changing only
3208 wait_request_state $fid ARCHIVE SUCCEED
3210 check_hsm_flags $f "0x00000009"
3212 run_test 56 "Setattr during an archive is ok"
3215 # Need one client for I/O, one for request
3216 needclients 2 || return 0
3218 # test needs a running copytool
3222 local f=$DIR/$tdir/test_archive_remote
3223 # Create a file on a remote node
3224 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3225 "count=2 conv=fsync"
3228 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3229 error "hsm_archive failed"
3230 local fid=$(path2fid $f)
3231 wait_request_state $fid ARCHIVE SUCCEED
3233 # Release and implicit restore it
3234 do_node $CLIENT2 "$LFS hsm_release $f" ||
3235 error "hsm_release failed"
3236 do_node $CLIENT2 "md5sum $f" ||
3237 error "hsm_restore failed"
3239 wait_request_state $fid RESTORE SUCCEED
3241 run_test 57 "Archive a file with dirty cache on another node"
3243 truncate_released_file() {
3247 local sz=$(stat -c %s $src_file)
3248 local f=$DIR/$tdir/$tfile
3249 local fid=$(copy_file $1 $f)
3253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3254 error "could not archive file"
3255 wait_request_state $fid ARCHIVE SUCCEED
3257 $LFS hsm_release $f || error "could not release file"
3259 $TRUNCATE $f $trunc_to || error "truncate failed"
3262 local sz1=$(stat -c %s $f)
3263 [[ $sz1 == $trunc_to ]] ||
3264 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3267 check_hsm_flags $f "0x0000000b"
3269 local state=$(get_request_state $fid RESTORE)
3270 [[ "$state" == "SUCCEED" ]] ||
3271 error "truncate $sz does not trig restore, state = $state"
3273 $TRUNCATE $ref $trunc_to
3274 cmp $ref $f || error "file data wrong after truncate"
3280 # test needs a running copytool
3285 local sz=$(stat -c %s /etc/passwd)
3287 echo "truncate up from $sz to $((sz*2))"
3288 truncate_released_file /etc/passwd $((sz*2))
3290 echo "truncate down from $sz to $((sz/2))"
3291 truncate_released_file /etc/passwd $((sz/2))
3293 echo "truncate to 0"
3294 truncate_released_file /etc/passwd 0
3296 run_test 58 "Truncate a released file will trigger restore"
3300 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3301 skip "Need MDS version at least 2.7.63"
3304 $MCREATE $DIR/$tfile || error "mcreate failed"
3305 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3306 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3307 fid=$(path2fid $DIR/$tfile)
3308 wait_request_state $fid ARCHIVE SUCCEED
3309 $LFS hsm_release $DIR/$tfile || error "release failed"
3311 run_test 59 "Release stripeless file with non-zero size"
3314 # This test validates the fix for LU-4512. Ensure that the -u
3315 # option changes the progress reporting interval from the
3316 # default (30 seconds) to the user-specified interval.
3317 local f=$DIR/$tdir/$tfile
3318 local fid=$(create_file "$f" 1M 10)
3321 local progress_timeout=$((interval * 4))
3322 copytool setup -b 1 --update-interval $interval
3325 local mdt=${MDT_PREFIX}${mdtidx}
3326 local mds=mds$((mdtidx + 1))
3328 # Wait for copytool to register
3329 wait_update_facet $mds \
3330 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3331 uuid 100 || error "coyptool failed to register with $mdt"
3333 local start_at=$(date +%s)
3334 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3335 error "could not archive file"
3337 local agent=$(facet_active_host $SINGLEAGT)
3338 local logfile=$(copytool_logfile $SINGLEAGT)
3340 wait_update $agent \
3341 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3342 error "copytool failed to start"
3344 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3345 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3351 echo -n "Expecting a progress update within $progress_timeout seconds... "
3353 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3354 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3355 echo "$RESULT bytes copied in $WAIT seconds."
3357 elif [ $WAIT -ge $progress_timeout ]; then
3358 error "Timed out waiting for progress update!"
3361 WAIT=$((WAIT + sleep))
3365 local finish_at=$(date +%s)
3366 local elapsed=$((finish_at - start_at))
3368 # Ensure that the progress update occurred within the expected window.
3369 if [ $elapsed -lt $((interval - 1)) ]; then
3370 error "Expected progress update after at least $interval seconds"
3373 echo "Wait for on going archive hsm action to complete"
3374 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3375 echo "File archiving not completed even after 10 secs"
3377 run_test 60 "Changing progress update interval from default"
3380 # test needs a running copytool
3384 local f=$DIR/$tdir/$tfile
3385 local fid=$(copy_file /etc/passwd $f)
3387 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3390 wait_request_state $fid ARCHIVE FAILED
3392 run_test 61 "Waiting archive of a removed file should fail"
3395 # test needs a new running copytool
3396 stack_trap copytool_monitor_cleanup EXIT
3397 copytool_monitor_setup
3398 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3400 # Wait for the copytool to register.
3401 wait_update --verbose $(facet_active_host mds1) \
3402 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3404 error "copytool failed to register with MDT0000"
3407 wait_copytools || error "Copytools failed to stop"
3409 local REGISTER_EVENT
3410 local UNREGISTER_EVENT
3411 while read event; do
3412 local parsed=$(parse_json_event "$event")
3413 if [ -z "$parsed" ]; then
3414 error "Copytool sent malformed event: $event"
3418 if [ $event_type == "REGISTER" ]; then
3419 REGISTER_EVENT=$event
3420 elif [ $event_type == "UNREGISTER" ]; then
3421 UNREGISTER_EVENT=$event
3423 done < <(echo $"$(get_copytool_event_log)")
3425 if [ -z "$REGISTER_EVENT" ]; then
3426 error "Copytool failed to send register event to FIFO"
3429 if [ -z "$UNREGISTER_EVENT" ]; then
3430 error "Copytool failed to send unregister event to FIFO"
3433 echo "Register/Unregister events look OK."
3435 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3438 # Bump progress interval for livelier events.
3441 # test needs a new running copytool
3442 stack_trap copytool_monitor_cleanup EXIT
3443 copytool_monitor_setup
3444 copytool setup --update-interval $interval --event-fifo \
3445 "$HSMTOOL_MONITOR_DIR/fifo"
3447 stack_trap "cdt_clear_no_retry" EXIT
3448 # Just start and stop the copytool to generate events.
3451 local f=$DIR/$tdir/$tfile
3452 local fid=$(create_small_file "$f")
3454 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3455 error "could not archive file"
3456 wait_request_state $fid ARCHIVE SUCCEED
3458 local expected_fields="event_time data_fid source_fid"
3459 expected_fields+=" total_bytes current_bytes"
3462 [ARCHIVE_START]=false
3463 [ARCHIVE_FINISH]=false
3464 [ARCHIVE_RUNNING]=false
3466 while read event; do
3467 # Make sure we're not getting anything from previous events.
3468 for field in $expected_fields; do
3472 local parsed=$(parse_json_event "$event")
3473 if [ -z "$parsed" ]; then
3474 error "Copytool sent malformed event: $event"
3478 events["$event_type"]=true
3480 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3482 # Do some simple checking of the progress update events.
3483 for expected_field in $expected_fields; do
3484 if [ -z ${!expected_field+x} ]; then
3485 error "Missing $expected_field field in event"
3489 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3491 # These should be identical throughout an archive operation
3492 [ $source_fid == $data_fid ] ||
3493 error "Expected source_fid to equal data_fid"
3494 done < <(echo $"$(get_copytool_event_log)")
3496 # Check we received every type of events we were expecting
3497 for event in "${!events[@]}"; do
3498 ${events["$event"]} ||
3499 error "Copytool failed to send '$event' event to FIFO"
3502 echo "Archive events look OK."
3504 run_test 71 "Copytool logs JSON archive events to FIFO"
3507 # Bump progress interval for livelier events.
3510 # test needs a new running copytool
3511 stack_trap copytool_monitor_cleanup EXIT
3512 copytool_monitor_setup
3513 copytool setup --update-interval $interval --event-fifo \
3514 "$HSMTOOL_MONITOR_DIR/fifo"
3515 local test_file=$HSMTOOL_MONITOR_DIR/file
3517 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3519 do_facet $SINGLEAGT "$cmd" ||
3520 error "cannot create $test_file on $SINGLEAGT"
3521 copy2archive $test_file $tdir/$tfile
3524 local f=$DIR/$tdir/$tfile
3525 copytool import $tdir/$tfile $f
3526 f=$DIR2/$tdir/$tfile
3527 echo "Verifying released state: "
3528 check_hsm_flags $f "0x0000000d"
3530 local fid=$(path2fid $f)
3532 wait_request_state $fid RESTORE SUCCEED
3534 local expected_fields="event_time data_fid source_fid"
3535 expected_fields+=" total_bytes current_bytes"
3539 while read event; do
3540 # Make sure we're not getting anything from previous events.
3541 for field in $expected_fields; do
3545 local parsed=$(parse_json_event "$event")
3546 if [ -z "$parsed" ]; then
3547 error "Copytool sent malformed event: $event"
3551 if [ $event_type == "RESTORE_START" ]; then
3553 if [ $source_fid != $data_fid ]; then
3554 error "source_fid should == data_fid at start"
3557 elif [ $event_type == "RESTORE_FINISH" ]; then
3559 if [ $source_fid != $data_fid ]; then
3560 error "source_fid should == data_fid at finish"
3563 elif [ $event_type != "RESTORE_RUNNING" ]; then
3567 # Do some simple checking of the progress update events.
3568 for expected_field in $expected_fields; do
3569 if [ -z ${!expected_field+x} ]; then
3570 error "Missing $expected_field field in event"
3574 if [ $total_bytes -eq 0 ]; then
3575 error "Expected total_bytes to be > 0"
3578 # When a restore starts out, the data fid is the same as the
3579 # source fid. After the restore has gotten going, we learn
3580 # the new data fid. Once the restore has finished, the source
3581 # fid is set to the new data fid.
3583 # We test this because some monitoring software may depend on
3584 # this behavior. If it changes, then the consumers of these
3585 # events may need to be modified.
3586 if [ $source_fid == $data_fid ]; then
3587 error "source_fid should != data_fid during restore"
3589 done < <(echo $"$(get_copytool_event_log)")
3591 if [ -z "$START_EVENT" ]; then
3592 error "Copytool failed to send restore start event to FIFO"
3595 if [ -z "$FINISH_EVENT" ]; then
3596 error "Copytool failed to send restore finish event to FIFO"
3599 echo "Restore events look OK."
3601 run_test 72 "Copytool logs JSON restore events to FIFO"
3604 file_count=51 # Max number of files constrained by LNET message size
3605 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3606 local f=$DIR/$tdir/$tfile
3607 local FILELIST=/tmp/filelist.txt
3611 for i in $(seq 1 $file_count); do
3612 fid=$(copy_file /etc/hosts $f.$i)
3613 echo $f.$i >> $FILELIST
3617 # to be sure wait_all_done will not be mislead by previous tests
3619 wait_for_grace_delay
3620 $LFS hsm_archive --filelist $FILELIST ||
3621 error "cannot archive a file list"
3623 $LFS hsm_release --filelist $FILELIST ||
3624 error "cannot release a file list"
3625 $LFS hsm_restore --filelist $FILELIST ||
3626 error "cannot restore a file list"
3629 run_test 90 "Archive/restore a file list"
3631 double_verify_reset_hsm_param() {
3633 echo "Testing $HSM_PARAM.$p"
3634 local val=$(get_hsm_param $p)
3636 local val2=$(($val * 2))
3637 set_hsm_param $p $val2
3638 val=$(get_hsm_param $p)
3639 [[ $val == $val2 ]] ||
3640 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3641 echo "Set $p to 0 must failed"
3645 set_hsm_param $p $save
3647 if [[ $rc == 0 ]]; then
3648 error "we must not be able to set $HSM_PARAM.$p to 0"
3653 double_verify_reset_hsm_param loop_period
3654 double_verify_reset_hsm_param grace_delay
3655 double_verify_reset_hsm_param active_request_timeout
3656 double_verify_reset_hsm_param max_requests
3657 double_verify_reset_hsm_param default_archive_id
3659 run_test 100 "Set coordinator /proc tunables"
3666 run_test 102 "Verify coordinator control"
3669 # test needs a running copytool
3676 for i in $(seq 1 20); do
3677 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3683 echo "Current requests"
3684 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3685 $HSM_PARAM.actions |\
3686 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3688 [[ -z "$res" ]] || error "Some request have not been canceled"
3690 run_test 103 "Purge all requests"
3695 local f=$DIR/$tdir/$tfile
3696 local fid=$(create_empty_file "$f")
3698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3699 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3700 $HSM_PARAM.actions |\
3701 grep $fid | cut -f16 -d=")
3703 [[ "$data1" == "$DATAHEX" ]] ||
3704 error "Data field in records is ($data1) and not ($DATAHEX)"
3708 run_test 104 "Copy tool data field"
3711 local max_requests=$(get_hsm_param max_requests)
3715 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3716 set_hsm_param max_requests 300
3719 for i in $(seq -w 1 10); do
3720 cp /etc/passwd $DIR/$tdir/$i
3721 $LFS hsm_archive $DIR/$tdir/$i
3723 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3724 $HSM_PARAM.actions |\
3725 grep WAITING | wc -l")
3729 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3730 $HSM_PARAM.actions |\
3731 grep WAITING | wc -l")
3734 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3735 error "Requests count after shutdown $reqcnt2 != "\
3736 "before shutdown $reqcnt1"
3738 run_test 105 "Restart of coordinator"
3741 # test needs a running copytool
3744 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3746 check_agent_registered $uuid
3748 search_copytools || error "No copytool found"
3751 wait_copytools || error "Copytool failed to stop"
3753 check_agent_unregistered $uuid
3756 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3757 check_agent_registered $uuid
3759 run_test 106 "Copytool register/unregister"
3762 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3764 # test needs a running copytool
3766 # create and archive file
3768 local f1=$DIR/$tdir/$tfile
3769 local fid=$(copy_file /etc/passwd $f1)
3770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3771 wait_request_state $fid ARCHIVE SUCCEED
3772 # shutdown and restart MDS
3774 # check the copytool still gets messages from MDT
3775 local f2=$DIR/$tdir/2
3776 local fid=$(copy_file /etc/passwd $f2)
3777 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3778 # main check of this sanity: this request MUST succeed
3779 wait_request_state $fid ARCHIVE SUCCEED
3781 run_test 107 "Copytool re-register after MDS restart"
3783 policy_set_and_test()
3787 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3788 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3789 [[ "$policy" == "$target" ]] ||
3790 error "Wrong policy after '$change': '$policy' != '$target'"
3794 # to force default policy setting if error
3795 CDT_POLICY_HAD_CHANGED=true
3797 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3798 local default="NonBlockingRestore [NoRetryAction]"
3799 [[ "$policy" == "$default" ]] ||
3800 error "default policy has changed,"\
3801 " '$policy' != '$default' update the test"
3802 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3803 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3804 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3805 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3806 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3807 # useless bacause we know but safer for futur changes to use real value
3808 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3809 echo "Next set_param must failed"
3810 policy_set_and_test "wrong" "$policy"
3813 echo "Back to default policy"
3814 cdt_set_sanity_policy
3816 run_test 109 "Policy display/change"
3819 # test needs a running copytool
3824 copy2archive /etc/passwd $tdir/$tfile
3826 local f=$DIR/$tdir/$tfile
3827 copytool import $tdir/$tfile $f
3828 local fid=$(path2fid $f)
3830 cdt_set_non_blocking_restore
3835 wait_request_state $fid RESTORE SUCCEED
3836 cdt_clear_non_blocking_restore
3840 error "md5sum returns $st != 1, "\
3841 "should also perror ENODATA (No data available)"
3843 run_test 110a "Non blocking restore policy (import case)"
3846 # test needs a running copytool
3850 local f=$DIR/$tdir/$tfile
3851 local fid=$(copy_file /etc/passwd $f)
3852 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3853 wait_request_state $fid ARCHIVE SUCCEED
3856 cdt_set_non_blocking_restore
3861 wait_request_state $fid RESTORE SUCCEED
3862 cdt_clear_non_blocking_restore
3866 error "md5sum returns $st != 1, "\
3867 "should also perror ENODATA (No data available)"
3869 run_test 110b "Non blocking restore policy (release case)"
3872 # test needs a running copytool
3876 copy2archive /etc/passwd $tdir/$tfile
3878 local f=$DIR/$tdir/$tfile
3880 copytool import $tdir/$tfile $f
3881 local fid=$(path2fid $f)
3885 copytool_remove_backend $fid
3888 wait_request_state $fid RESTORE FAILED
3895 [[ $st == 0 ]] || error "Restore does not failed"
3897 run_test 111a "No retry policy (import case), restore will error"\
3898 " (No such file or directory)"
3901 # test needs a running copytool
3905 local f=$DIR/$tdir/$tfile
3906 local fid=$(copy_file /etc/passwd $f)
3907 stack_trap cdt_clear_no_retry EXIT
3909 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3910 wait_request_state $fid ARCHIVE SUCCEED
3913 copytool_remove_backend $fid
3916 wait_request_state $fid RESTORE FAILED
3920 [[ $st == 0 ]] || error "Restore does not failed"
3922 run_test 111b "No retry policy (release case), restore will error"\
3923 " (No such file or directory)"
3926 # test needs a running copytool
3930 local f=$DIR/$tdir/$tfile
3931 local fid=$(copy_file /etc/passwd $f)
3933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3934 local l=$($LFS hsm_action $f)
3936 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3939 wait_request_state $fid ARCHIVE SUCCEED
3942 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3944 run_test 112 "State of recorded request"
3947 local file1=$DIR/$tdir/$tfile
3948 local file2=$DIR2/$tdir/$tfile
3950 local fid=$(create_small_sync_file $file1)
3952 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3953 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3954 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3956 copytool setup -m "$MOUNT3"
3958 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3960 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3961 wait_request_state $fid ARCHIVE SUCCEED
3963 $LFS hsm_release $file1
3964 echo "Verifying released state: "
3965 check_hsm_flags $file1 "0x0000000d"
3967 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3970 kill -USR1 $MULTIPID
3975 local size1=$(stat -c "%s" $file1)
3976 local size2=$(stat -c "%s" $file2)
3978 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3980 run_test 113 "wrong stat after restore"
3983 local f=$DIR/$tdir/$tfile
3984 local fid=$(create_empty_file "$f")
3988 # Prevent archive from completing
3991 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3992 # wait archive to register at CDT
3993 wait_request_state $fid ARCHIVE STARTED
3995 # Cancel the archive
3996 $LFS hsm_cancel "$f"
3998 wait_request_state $fid ARCHIVE CANCELED
4001 wait_request_state $fid CANCEL SUCCEED
4003 run_test 200 "Register/Cancel archive"
4006 # test needs a running copytool
4009 local f=$DIR/$tdir/$tfile
4010 create_archive_file $tdir/$tfile
4011 copytool import $tdir/$tfile $f
4012 local fid=$(path2fid $f)
4014 # test with cdt on is made in test_222
4017 # wait restore to register at CDT
4018 wait_request_state $fid RESTORE WAITING
4021 wait_request_state $fid RESTORE CANCELED
4022 wait_request_state $fid CANCEL SUCCEED
4024 run_test 201 "Register/Cancel restore"
4027 local f=$DIR/$tdir/$tfile
4028 local fid=$(create_empty_file "$f")
4030 # test needs a running copytool
4033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4034 wait_request_state $fid ARCHIVE SUCCEED
4038 # wait remove to register at CDT
4039 wait_request_state $fid REMOVE STARTED
4042 wait_request_state $fid REMOVE CANCELED
4044 run_test 202 "Register/Cancel remove"
4046 test_220A() { # was test_220
4047 # test needs a running copytool
4052 local f=$DIR/$tdir/$tfile
4053 local fid=$(copy_file /etc/passwd $f)
4057 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4058 wait_request_state $fid ARCHIVE SUCCEED
4060 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4061 error "The expected changelog was not emitted"
4063 run_test 220A "Changelog for archive"
4066 # test needs a running copytool
4071 local f=$DIR/$tdir/$tfile
4072 local fid=$(copy_file /etc/passwd $f)
4076 # block copytool operations to allow for HSM request to be
4077 # submitted and file be unlinked (CDT will find object removed)
4080 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4082 # wait request to reach CT
4083 wait_request_state $fid ARCHIVE STARTED
4089 wait_request_state $fid ARCHIVE FAILED
4092 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4093 error "The expected changelog was not emitted"
4095 run_test 220a "Changelog for failed archive"
4098 local f=$DIR/$tdir/$tfile
4099 local fid=$(create_empty_file "$f")
4104 # Prevent archive from completing
4106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4107 wait_request_state $fid ARCHIVE STARTED
4110 wait_request_state $fid ARCHIVE CANCELED
4113 wait_request_state $fid CANCEL SUCCEED
4115 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4116 error "The expected changelog was not emitted"
4118 run_test 221 "Changelog for archive canceled"
4121 # test needs a running copytool
4125 copy2archive /etc/passwd $tdir/$tfile
4127 local f=$DIR/$tdir/$tfile
4128 copytool import $tdir/$tfile $f
4129 local fid=$(path2fid $f)
4134 wait_request_state $fid RESTORE SUCCEED
4136 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4137 error "The expected changelog was not emitted"
4139 run_test 222a "Changelog for explicit restore"
4142 # test needs a running copytool
4146 local f=$DIR/$tdir/$tfile
4147 local fid=$(copy_file /etc/passwd $f)
4150 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4151 wait_request_state $fid ARCHIVE SUCCEED
4156 wait_request_state $fid RESTORE SUCCEED
4158 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4159 error "The expected changelog was not emitted"
4161 run_test 222b "Changelog for implicit restore"
4164 # test needs a running copytool
4168 copy2archive /etc/passwd $tdir/$tfile
4170 local f=$DIR/$tdir/$tfile
4171 copytool import $tdir/$tfile $f
4172 local fid=$(path2fid $f)
4176 # block copytool operations to allow for HSM request to be
4177 # submitted and file be unlinked (CDT will find object removed)
4182 # wait request to reach CT
4183 wait_request_state $fid RESTORE STARTED
4189 wait_request_state $fid RESTORE FAILED
4192 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4193 error "The expected changelog was not emitted"
4195 run_test 222c "Changelog for failed explicit restore"
4198 # test needs a running copytool
4202 local f=$DIR/$tdir/$tfile
4203 local fid=$(copy_file /etc/passwd $f)
4206 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4207 wait_request_state $fid ARCHIVE SUCCEED
4210 copytool_remove_backend $fid
4213 wait_request_state $fid RESTORE FAILED
4216 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4217 error "The expected changelog was not emitted"
4219 run_test 222d "Changelog for failed implicit restore"
4222 # test needs a running copytool
4225 local f=$DIR/$tdir/$tfile
4226 create_archive_file $tdir/$tfile
4230 copytool import $tdir/$tfile $f
4231 local fid=$(path2fid $f)
4234 wait_request_state $fid RESTORE STARTED
4236 wait_request_state $fid RESTORE CANCELED
4237 wait_request_state $fid CANCEL SUCCEED
4239 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4240 error "The expected changelog was not emitted"
4242 run_test 223a "Changelog for restore canceled (import case)"
4245 local f=$DIR/$tdir/$tfile
4246 local fid=$(create_empty_file "$f")
4251 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4252 wait_request_state $fid ARCHIVE SUCCEED
4255 # Prevent restore from completing
4258 wait_request_state $fid RESTORE STARTED
4261 wait_request_state $fid RESTORE CANCELED
4264 wait_request_state $fid CANCEL SUCCEED
4266 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4267 error "The expected changelog was not emitted"
4269 run_test 223b "Changelog for restore canceled (release case)"
4271 test_224A() { # was test_224
4272 # test needs a running copytool
4277 local f=$DIR/$tdir/$tfile
4278 local fid=$(copy_file /etc/passwd $f)
4281 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4282 wait_request_state $fid ARCHIVE SUCCEED
4285 wait_request_state $fid REMOVE SUCCEED
4287 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4288 error "The expected changelog was not emitted"
4290 run_test 224A "Changelog for remove"
4293 # test needs a running copytool
4298 local f=$DIR/$tdir/$tfile
4299 local fid=$(copy_file /etc/passwd $f)
4302 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4303 wait_request_state $fid ARCHIVE SUCCEED
4305 copytool_remove_backend $fid
4307 # block copytool operations to allow for HSM request to be
4308 # submitted and file be unlinked (CDT will find object removed)
4313 # wait for request to reach CT
4314 wait_request_state $fid REMOVE STARTED
4320 wait_request_state $fid REMOVE FAILED
4322 # HE_REMOVE|ENOENT=0x202
4323 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4324 error "The expected changelog was not emitted"
4326 run_test 224a "Changelog for failed remove"
4329 # test is not usable because remove request is too fast
4330 # so it is always finished before cancel can be done ...
4331 echo "Test disabled"
4334 # test needs a running copytool
4337 local f=$DIR/$tdir/$tfile
4338 local fid=$(create_empty_file "$f")
4341 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4342 wait_request_state $fid ARCHIVE SUCCEED
4344 # Prevent restore from completing
4349 wait_request_state $fid REMOVE CANCELED
4352 wait_request_state $fid CANCEL SUCCEED
4354 changelog_find -type HSM -target-fid $fid -flags 0x27d
4355 error "The expected changelog was not emitted"
4357 run_test 225 "Changelog for remove canceled"
4360 # test needs a running copytool
4365 local f1=$DIR/$tdir/$tfile-1
4366 local f2=$DIR/$tdir/$tfile-2
4367 local f3=$DIR/$tdir/$tfile-3
4368 local fid1=$(copy_file /etc/passwd $f1)
4369 local fid2=$(copy_file /etc/passwd $f2)
4370 copy_file /etc/passwd $f3
4373 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4374 wait_request_state $fid1 ARCHIVE SUCCEED
4376 $LFS hsm_archive $f2
4377 wait_request_state $fid2 ARCHIVE SUCCEED
4379 rm $f1 || error "rm $f1 failed"
4382 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4383 error "The expected changelog was not emitted"
4385 mv $f3 $f2 || error "mv $f3 $f2 failed"
4387 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4388 error "The expected changelog was not emitted"
4390 run_test 226 "changelog for last rm/mv with exiting archive"
4392 # This is just a utility function to clarify what test_227 does
4397 "$LFS" "$action" --$flag "$file" ||
4398 error "Cannot ${action#hsm_} $flag on '$file'"
4400 # Only one changelog should be produced
4401 local entries="$(changelog_find -type HSM -target-fid $fid)"
4402 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4403 error "lfs $action --$flag '$file' produced more than one" \
4406 # Parse the last changelog record
4407 local entry="$(tail -n 1 <<< "$entries")"
4408 eval local -A changelog=$(changelog2array $entry)
4410 # Also check the flags match what is expected
4411 [[ ${changelog[flags]} == $target ]] ||
4412 error "Changelog flag is '${changelog[flags]}', not $target"
4416 local file="$DIR/$tdir/$tfile"
4417 local fid=$(create_empty_file "$file")
4422 for flag in norelease noarchive exists archived lost; do
4423 if [ "$flag" == lost ]; then
4424 # The flag "lost" only works on an archived file
4425 "$LFS" hsm_set --archived "$file"
4429 action="hsm_set" __test_227
4430 action="hsm_clear" __test_227
4433 run_test 227 "changelog when explicit setting of HSM flags"
4436 # test needs a running copytool
4439 local fid=$(create_small_sync_file $DIR/$tfile)
4440 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4441 wait_request_state $fid ARCHIVE SUCCEED
4443 $LFS hsm_release $DIR/$tfile
4444 check_hsm_flags $DIR/$tfile "0x0000000d"
4446 filefrag $DIR/$tfile | grep " 1 extent found" ||
4447 error "filefrag on released file must return only one extent"
4449 # only newer versions of cp detect sparse files by stat/FIEMAP
4451 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4452 error "copying $DIR/$tfile"
4453 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4455 $LFS hsm_release $DIR/$tfile
4456 check_hsm_flags $DIR/$tfile "0x0000000d"
4458 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4460 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4462 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4463 error "comparing untarred $DIR/$tfile"
4465 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4466 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4468 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4471 local file="$DIR/$tdir/$tfile"
4473 # set max_requests to allow one request of each type to be started (3)
4475 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4476 set_hsm_param max_requests 3
4479 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4480 set_hsm_param loop_period 1
4482 # send 1 requests of each kind twice
4485 for action in archive restore remove; do
4486 local filepath="$file"-to-$action
4487 local fid=$(create_empty_file "$filepath")
4488 local fid2=$(create_empty_file "$filepath".bis)
4490 if [ "$action" != archive ]; then
4491 "$LFS" hsm_archive "$filepath"
4492 wait_request_state $fid ARCHIVE SUCCEED
4493 "$LFS" hsm_archive "$filepath".bis
4494 wait_request_state $fid2 ARCHIVE SUCCEED
4496 if [ "$action" == restore ]; then
4497 "$LFS" hsm_release "$filepath"
4498 "$LFS" hsm_release "$filepath".bis
4502 # suspend the copytool to prevent requests from completing
4503 stack_trap "copytool_continue" EXIT
4506 # send `max_requests' requests (one of each kind)
4507 for action in archive restore remove; do
4508 filepath="$file"-to-$action
4509 "$LFS" hsm_${action} "$filepath"
4510 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4513 # send another batch of requests
4514 for action in archive restore remove; do
4515 "$LFS" hsm_${action} "$file-to-$action".bis
4517 # wait for `loop_period' seconds to make sure the coordinator has time
4518 # to register those, even though it should not
4521 # only the first batch of request should be started
4523 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4527 error "expected 3 STARTED requests, found $count"
4529 run_test 250 "Coordinator max request"
4532 local f=$DIR/$tdir/$tfile
4533 local fid=$(create_empty_file "$f")
4536 # to have a short test
4537 local old_to=$(get_hsm_param active_request_timeout)
4538 set_hsm_param active_request_timeout 1
4539 # to be sure the cdt will wake up frequently so
4540 # it will be able to cancel the "old" request
4541 local old_loop=$(get_hsm_param loop_period)
4542 set_hsm_param loop_period 1
4547 # Prevent archive from completing
4549 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4550 wait_request_state $fid ARCHIVE STARTED
4552 # Let the request timeout
4553 wait_request_state $fid ARCHIVE CANCELED
4555 set_hsm_param active_request_timeout $old_to
4556 set_hsm_param loop_period $old_loop
4558 run_test 251 "Coordinator request timeout"
4561 local f=$DIR/$tdir/$tfile
4562 local fid=$(create_empty_file "$f")
4564 # to have a short test
4565 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4566 set_hsm_param loop_period 1
4570 # Prevent archive from completing
4572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4573 wait_request_state $fid ARCHIVE STARTED
4576 stack_trap "set_hsm_param active_request_timeout \
4577 $(get_hsm_param active_request_timeout)" EXIT
4578 set_hsm_param active_request_timeout 1
4580 wait_request_state $fid ARCHIVE CANCELED
4583 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4587 # test needs a running copytool
4591 local f=$DIR/$tdir/$tfile
4593 dd if=/dev/zero of=$f bs=1MB count=10
4594 local fid=$(path2fid $f)
4596 $LFS hsm_archive $f || error "could not archive file"
4597 wait_request_state $fid ARCHIVE SUCCEED
4599 # clear locks to discard inode data
4600 cancel_lru_locks osc
4602 #define OBD_FAIL_MDC_MERGE 0x807
4603 $LCTL set_param fail_loc=0x807
4605 #expect error here, instead of release with wrong size
4608 if ((rc == 0)); then
4609 file_size=$(stat -c '%s' $f)
4610 if ((file_size != 10485760)); then
4611 error "Wrong file size after hsm_release"
4614 echo "could not release file"
4617 run_test 253 "Check for wrong file size after release"
4621 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4622 skip "need MDS version at least 2.10.56"
4624 # Check that the counters are initialized to 0
4626 for request_type in archive restore remove; do
4627 count="$(get_hsm_param ${request_type}_count)" ||
4628 error "Reading ${request_type}_count failed with $?"
4630 [ "$count" -eq 0 ] ||
4631 error "Expected ${request_type}_count to be " \
4635 run_test 254a "Request counters are initialized to zero"
4639 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4640 skip "need MDS version at least 2.10.56"
4642 # The number of request to launch (at least 32)
4643 local request_count=$((RANDOM % 32 + 32))
4644 printf "Will launch %i requests of each type\n" "$request_count"
4646 # Launch a copytool to process requests
4649 # Set hsm.max_requests to allow starting all requests at the same time
4651 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4652 set_hsm_param max_requests "$request_count"
4656 for request_type in archive restore remove; do
4657 printf "Checking %s requests\n" "${request_type}"
4658 # Suspend the copytool to give us time to read the proc files
4661 for ((i = 0; i < $request_count; i++)); do
4662 case $request_type in
4664 create_empty_file "$DIR/$tdir/$tfile-$i" \
4668 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4671 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4674 # Give the coordinator 10 seconds to start every request
4676 while get_hsm_param actions | grep -q WAITING; do
4679 [ $timeout -gt 0 ] ||
4680 error "${request_type^} requests took too " \
4684 count="$(get_hsm_param ${request_type}_count)"
4685 [ "$count" -eq "$request_count" ] ||
4686 error "Expected '$request_count' (!= '$count') " \
4687 "active $request_type requests"
4689 # Let the copytool process the requests
4691 # Give it 10 seconds maximum
4693 while get_hsm_param actions | grep -q STARTED; do
4696 [ $timeout -gt 0 ] ||
4697 error "${request_type^} requests took too " \
4701 count="$(get_hsm_param ${request_type}_count)"
4702 [ "$count" -eq 0 ] ||
4703 error "Expected 0 (!= '$count') " \
4704 "active $request_type requests"
4707 run_test 254b "Request counters are correctly incremented and decremented"
4711 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4712 skip "Need MDS version at least 2.12.0"
4714 local file="$DIR/$tdir/$tfile"
4715 local fid=$(create_empty_file "$file")
4717 # How do you make sure the coordinator has consumed any outstanding
4718 # event, without triggering an event yourself?
4720 # You wait for a request to disappear from the coordinator's llog.
4722 # Warning: the setup represents 90% of this test
4724 # Create and process an HSM request
4726 "$LFS" hsm_archive "$file"
4727 wait_request_state $fid ARCHIVE SUCCEED
4730 wait_copytools || error "failed to stop copytools"
4732 # Launch a new HSM request
4734 create_empty_file "$file"
4735 "$LFS" hsm_archive "$file"
4739 # Have the completed request be removed as soon as the cdt wakes up
4740 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4741 set_hsm_param grace_delay 1
4742 # (Hopefully, time on the MDS will behave nicely)
4743 do_facet $SINGLEMDS sleep 2 &
4745 # Increase `loop_period' as a mean to prevent the coordinator from
4746 # waking itself up to do some housekeeping.
4747 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4748 set_hsm_param loop_period 1000
4750 wait $! || error "waiting failed"
4752 wait_request_state $fid ARCHIVE ""
4753 # The coordinator will not wake up on its own for ~`loop_period' secs...
4755 # ... Unless a copytool registers. Now the real test begins
4757 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4759 run_test 255 "Copytool registration wakes the coordinator up"
4761 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4762 # break in the future because of that.
4765 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4766 skip "need MDS version 2.11.56 or later"
4768 local -a files=("$DIR/$tdir/$tfile".{0..15})
4771 for file in "${files[@]}"; do
4772 create_small_file "$file"
4775 # Set a few hsm parameters
4777 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4778 set_hsm_param loop_period 1
4780 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4781 set_hsm_param max_requests 3
4785 "$LFS" hsm_archive "${files[0]}"
4786 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4787 "$LFS" hsm_release "${files[0]}"
4791 wait_copytools || error "copytools failed to stop"
4793 # Send several archive requests
4794 for file in "${files[@]:1}"; do
4795 "$LFS" hsm_archive "$file"
4798 # Send one restore request
4799 "$LFS" hsm_restore "${files[0]}"
4804 # Wait for all the requests to complete
4805 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4806 for file in "${files[@]:1}"; do
4807 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4810 # Collect the actions in the order in which the copytool processed them
4812 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4813 "$(copytool_logfile "$SINGLEAGT")")
4816 printf '%s\n' "${actions[@]}"
4819 for action in "${actions[@]:0:3}"; do
4820 [ "$action" == RESTORE ] && return
4823 error "Too many ARCHIVE requests were run before the RESTORE request"
4825 run_test 260a "Restore request have priority over other requests"
4827 # This test is very much tied to the implementation of the current priorisation
4828 # mechanism in the coordinator. It might not make sense to keep it in the future
4831 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4832 skip "need MDS version 2.11.56 or later"
4834 local -a files=("$DIR/$tdir/$tfile".{0..15})
4837 for file in "${files[@]}"; do
4838 create_small_file "$file"
4841 # Set a few hsm parameters
4843 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4844 set_hsm_param loop_period 1
4846 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4847 set_hsm_param max_requests 3
4850 copytool setup --archive-id 2
4851 "$LFS" hsm_archive --archive 2 "${files[0]}"
4852 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4853 "$LFS" hsm_release "${files[0]}"
4857 wait_copytools || error "copytools failed to stop"
4859 # Send several archive requests
4860 for file in "${files[@]:1}"; do
4861 "$LFS" hsm_archive "$file"
4864 # Send one restore request
4865 "$LFS" hsm_restore "${files[0]}"
4869 copytool setup --archive-id 2
4871 # Wait for all the requests to complete
4872 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4873 for file in "${files[@]:1}"; do
4874 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4877 # Collect the actions in the order in which the copytool processed them
4879 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4880 "$(copytool_logfile "$SINGLEAGT")")
4883 printf '%s\n' "${actions[@]}"
4886 for action in "${actions[@]:0:3}"; do
4887 [ "$action" == RESTORE ] && return
4890 error "Too many ARCHIVE requests were run before the RESTORE request"
4892 run_test 260b "Restore request have priority over other requests"
4894 # This test is very much tied to the implementation of the current priorisation
4895 # mechanism in the coordinator. It might not make sense to keep it in the future
4898 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4899 skip "Need MDS version at least 2.12.0"
4901 local -a files=("$DIR/$tdir/$tfile".{0..15})
4904 for file in "${files[@]}"; do
4905 create_small_file "$file"
4908 # Set a few hsm parameters
4910 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4911 set_hsm_param loop_period 1000
4913 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4914 set_hsm_param max_requests 3
4917 copytool setup --archive-id 2
4918 "$LFS" hsm_archive --archive 2 "${files[0]}"
4919 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4920 "$LFS" hsm_release "${files[0]}"
4924 wait_copytools || error "copytools failed to stop"
4926 # Force the next coordinator run to do housekeeping
4930 "$LFS" hsm_archive "${files[1]}"
4934 copytool setup --archive-id 2
4936 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4937 # The coordinator just did a housekeeping run it won't do another one
4938 # for around `loop_period' seconds => requests will not be reordered
4939 # if it costs too much (ie. when the coordinator has to discard a whole
4942 # Send several archive requests
4943 for file in "${files[@]:2}"; do
4944 "$LFS" hsm_archive "$file"
4947 # Send one restore request
4948 "$LFS" hsm_restore "${files[0]}"
4950 # Wait for all the requests to complete
4951 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4952 for file in "${files[@]:2}"; do
4953 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4956 # Collect the actions in the order in which the copytool processed them
4958 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4959 "$(copytool_logfile "$SINGLEAGT")")
4962 printf '%s\n' "${actions[@]}"
4965 for action in "${actions[@]:0:3}"; do
4966 [ "$action" == RESTORE ] &&
4967 error "Restore requests should not be prioritised" \
4968 "unless the coordinator is doing housekeeping"
4972 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4975 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4977 # the only way to test ondisk conf is to restart MDS ...
4978 echo "Stop coordinator and remove coordinator state at mount"
4981 # clean on disk conf set by default
4982 cdt_clear_mount_state
4983 cdt_check_state stopped
4985 # check cdt still off after umount/remount
4987 cdt_check_state stopped
4989 echo "Set coordinator start at mount, and start coordinator"
4990 cdt_set_mount_state enabled
4993 cdt_check_state enabled
4995 # check cdt still on after umount/remount
4997 cdt_check_state enabled
4999 # we are back to original state (cdt started at mount)
5001 run_test 300 "On disk coordinator state kept between MDT umount/mount"
5004 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5006 local ai=$(get_hsm_param default_archive_id)
5007 local new=$((ai + 1))
5009 set_hsm_param default_archive_id $new -P
5011 local res=$(get_hsm_param default_archive_id)
5014 set_hsm_param default_archive_id "" "-P -d"
5016 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5018 run_test 301 "HSM tunnable are persistent"
5021 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5023 local ai=$(get_hsm_param default_archive_id)
5024 local new=$((ai + 1))
5029 set_hsm_param default_archive_id $new -P
5032 for mdtno in $(seq 1 $MDSCOUNT); do
5037 cdt_check_state enabled
5039 local res=$(get_hsm_param default_archive_id)
5042 set_hsm_param default_archive_id "" "-P -d"
5044 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5046 run_test 302 "HSM tunnable are persistent when CDT is off"
5049 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5055 local dir_mdt0=$DIR/$tdir/mdt0
5056 local dir_mdt1=$DIR/$tdir/mdt1
5058 # create 1 dir per MDT
5059 stack_trap "rm -rf $dir_mdt0" EXIT
5060 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5061 stack_trap "rm -rf $dir_mdt1" EXIT
5062 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5064 # create 1 file in each MDT
5065 local fid1=$(create_small_file $dir_mdt0/$tfile)
5066 local fid2=$(create_small_file $dir_mdt1/$tfile)
5068 # check that hsm request on mdt0 is sent to the right MDS
5069 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5070 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5071 echo "archive successful on mdt0"
5073 # check that hsm request on mdt1 is sent to the right MDS
5074 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5075 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5076 echo "archive successful on mdt1"
5078 run_test 400 "Single request is sent to the right MDT"
5081 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5087 local dir_mdt0=$DIR/$tdir/mdt0
5088 local dir_mdt1=$DIR/$tdir/mdt1
5090 # create 1 dir per MDT
5091 stack_trap "rm -rf $dir_mdt0" EXIT
5092 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5093 stack_trap "rm -rf $dir_mdt1" EXIT
5094 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5096 # create 1 file in each MDT
5097 local fid1=$(create_small_file $dir_mdt0/$tfile)
5098 local fid2=$(create_small_file $dir_mdt1/$tfile)
5100 # check that compound requests are shunt to the rights MDTs
5101 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5102 error "lfs hsm_archive"
5103 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5104 echo "archive successful on mdt0"
5105 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5106 echo "archive successful on mdt1"
5108 run_test 401 "Compound requests split and sent to their respective MDTs"
5110 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5115 local node=$(facet_active_host $facet)
5117 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5118 awk '{print $4}'); do
5119 echo "$3 $mdc on $node"
5120 do_facet $facet "$LCTL --device $mdc $state" || return 1
5125 # deactivate all mdc on agent1
5126 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5128 copytool setup --no-fail
5130 check_agent_unregistered "uuid" # match any agent
5132 # no expected running copytool
5133 search_copytools $agent && error "Copytool start should have failed"
5136 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5138 run_test 402a "Copytool start fails if all MDTs are inactive"
5145 local f=$DIR/$tdir/$tfile
5146 touch $f || error "touch $f failed"
5147 local fid=$(path2fid $f)
5149 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5150 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5151 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5153 # give time for CDT to send request and to keep it for retry
5154 wait_for_loop_period
5156 wait_request_state $fid ARCHIVE WAITING
5158 do_facet $SINGLEAGT lctl set_param fail_loc=0
5160 # request should succeed now
5161 wait_request_state $fid ARCHIVE SUCCEED
5163 run_test 402b "CDT must retry request upon slow start of CT"
5166 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5168 local agent=$(facet_active_host $SINGLEAGT)
5170 # deactivate all mdc for MDT0001
5171 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5174 local uuid=$(get_agent_uuid $agent)
5175 # check the agent is registered on MDT0000, and not on MDT0001
5176 check_agent_registered_by_mdt $uuid 0
5177 check_agent_unregistered_by_mdt $uuid 1
5179 # check running copytool process
5180 search_copytools $agent || error "No running copytools on $agent"
5182 # reactivate all mdc for MDT0001
5183 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5185 # make sure the copytool is now registered to all MDTs
5186 check_agent_registered $uuid
5188 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5191 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5195 # create files on both MDT0000 and MDT0001
5198 local dir_mdt0=$DIR/$tdir/mdt0
5199 stack_trap "rm -rf $dir_mdt0" EXIT
5200 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5202 # create 1 file on mdt0
5203 local fid1=$(create_small_file $dir_mdt0/$tfile)
5205 # deactivate all mdc for MDT0001
5206 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5208 # send an HSM request for files in MDT0000
5209 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5211 # check for completion of files in MDT0000
5212 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5213 echo "archive successful on mdt0"
5215 # reactivate all mdc for MDT0001
5216 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5218 run_test 404 "Inactive MDT does not block requests for active MDTs"
5221 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5227 local striped_dir=$DIR/$tdir/striped_dir
5229 # create striped dir on all of MDTs
5230 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5232 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5233 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5234 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5235 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5237 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5238 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5239 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5240 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5242 # check that compound requests are shunt to the rights MDTs
5243 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5244 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5245 error "lfs hsm_archive"
5247 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5248 echo "archive successful on $fid1"
5249 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5250 echo "archive successful on $fid2"
5251 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5252 echo "archive successful on $fid3"
5253 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5254 echo "archive successful on $fid4"
5256 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5257 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5258 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5259 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5261 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5262 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5263 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5264 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5266 run_test 405 "archive and release under striped directory"
5269 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5271 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5272 skip "need MDS version at least 2.7.64"
5277 fid=$(create_small_file $DIR/$tdir/$tfile)
5282 $LFS hsm_archive $DIR/$tdir/$tfile
5283 wait_request_state "$fid" ARCHIVE SUCCEED
5284 $LFS hsm_release $DIR/$tdir/$tfile
5286 # Should migrate $tdir but not $tfile.
5287 $LFS migrate -m1 $DIR/$tdir &&
5288 error "migrating HSM an archived file should fail"
5290 $LFS hsm_restore $DIR/$tdir/$tfile
5291 wait_request_state "$fid" RESTORE SUCCEED
5293 $LFS hsm_remove $DIR/$tdir/$tfile
5294 wait_request_state "$fid" REMOVE SUCCEED
5296 cat $DIR/$tdir/$tfile > /dev/null ||
5297 error "cannot read $DIR/$tdir/$tfile"
5299 $LFS migrate -m1 $DIR/$tdir ||
5300 error "cannot complete migration after HSM remove"
5302 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5303 if ((mdt_index != 1)); then
5304 error "expected MDT index 1, got $mdt_index"
5307 # Refresh fid after migration.
5308 fid=$(path2fid $DIR/$tdir/$tfile)
5311 $LFS hsm_archive $DIR/$tdir/$tfile
5312 wait_request_state "$fid" ARCHIVE SUCCEED 1
5314 lctl set_param debug=+trace
5315 $LFS hsm_release $DIR/$tdir/$tfile ||
5316 error "cannot release $DIR/$tdir/$tfile"
5318 $LFS hsm_restore $DIR/$tdir/$tfile
5319 wait_request_state "$fid" RESTORE SUCCEED 1
5321 cat $DIR/$tdir/$tfile > /dev/null ||
5322 error "cannot read $DIR/$tdir/$tfile"
5324 run_test 406 "attempting to migrate HSM archived files is safe"
5327 local f=$DIR/$tdir/$tfile
5328 local f2=$DIR2/$tdir/$tfile
5329 local fid=$(create_empty_file "$f")
5333 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5334 wait_request_state $fid ARCHIVE SUCCEED
5337 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5338 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5340 # Prevent restore from completing
5344 # 1st request holds layout lock while appropriate
5345 # RESTORE record is still not added to llog
5349 # after umount hsm_actions->O/x/x log shouldn't have
5350 # double RESTORE records like below
5351 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5352 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5354 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5358 wait_request_state $fid RESTORE SUCCEED
5360 run_test 407 "Check for double RESTORE records in llog"
5364 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5365 skip "HSM migrate is not supported"
5367 test_mkdir -p $DIR/$tdir
5369 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5370 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5372 llapi_hsm_test -d $DIR/$tdir -b ||
5373 error "One llapi HSM test failed"
5375 llapi_hsm_test -d $DIR/$tdir ||
5376 error "One llapi HSM test failed"
5379 run_test 500 "various LLAPI HSM tests"
5382 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5383 skip "need MDS version at least 2.10.58"
5387 local f=$DIR/$tdir/$tfile
5390 # set changelog_mask to ALL
5391 changelog_chmask "ALL"
5393 chmod 777 $DIR/$tdir
5394 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5395 local fid=$(path2fid $f)
5398 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5399 -gid "$RUNAS_GID") ||
5400 error "No matching CREAT entry"
5402 # Parse the changelog
5403 eval local -A changelog=$(changelog2array $entry)
5404 local nid="${changelog[nid]}"
5407 echo "Got NID '$nid'"
5408 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5409 error "nid '$nid' does not match any client NID:" \
5412 run_test 600 "Changelog fields 'u=' and 'nid='"
5415 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5416 skip "need MDS version at least 2.10.58"
5420 local f=$DIR/$tdir/$tfile
5423 # set changelog_mask to ALL
5424 changelog_chmask "ALL"
5426 touch $f || error "touch $f failed"
5427 local fid=$(path2fid $f)
5430 cat $f || error "cat $f failed"
5432 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5433 error "No matching OPEN entry"
5435 run_test 601 "OPEN Changelog entry"
5438 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5439 skip "need MDS version at least 2.10.58"
5443 local f=$DIR/$tdir/$tfile
5446 # set changelog_mask to ALL
5447 changelog_chmask "ALL"
5449 touch $f || error "touch $f failed"
5450 local fid=$(path2fid $f)
5453 cat $f || error "cat $f failed"
5455 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5459 echo f > $f || error "write $f failed"
5462 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5464 # remove OPEN from changelog_mask
5465 changelog_chmask "-OPEN"
5469 cat $f || error "cat $f failed"
5472 changelog_find -type CLOSE -target-fid $fid &&
5473 error "There should be no CLOSE entry"
5477 echo f > $f || error "write $f failed"
5480 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5482 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5485 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5486 skip "need MDS version at least 2.10.58"
5490 local f=$DIR/$tdir/$tfile
5493 # set changelog_mask to ALL
5494 changelog_chmask "ALL"
5496 touch $f || error "touch $f failed"
5497 local fid=$(path2fid $f)
5499 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5502 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5504 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5505 error "No matching GXATR entry"
5507 run_test 603 "GETXATTR Changelog entry"
5510 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5511 skip "need MDS version at least 2.10.58"
5515 local f=$DIR/$tdir/$tfile
5516 local f2=$DIR2/$tdir/$tfile
5517 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5519 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5520 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5521 do_facet mds1 lctl set_param "$procname=20"
5525 # set changelog_mask to ALL
5526 changelog_chmask "ALL"
5528 touch $f || error "touch $f failed"
5529 local fid=$(path2fid $f)
5535 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5539 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5540 -gid "$RUNAS_GID" -mode "r--") ||
5541 error "No matching NOPEN entry"
5543 # Parse the changelog
5544 eval local -A changelog=$(changelog2array $entry)
5545 local nid="${changelog[nid]}"
5548 echo "Got NID '$nid'"
5549 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5550 error "nid '$nid' does not match any client NID:" \
5555 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5558 changelog_find -type NOPEN -target-fid $fid &&
5559 error "There should be no NOPEN entry"
5561 # Sleep for `changelog_deniednext` seconds
5566 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5569 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5570 -gid "$RUNAS_GID" -mode "r--") ||
5571 error "No matching NOPEN entry"
5573 # Parse the changelog
5574 eval local -A changelog=$(changelog2array $entry)
5575 local nid="${changelog[nid]}"
5578 echo "Got NID '$nid'"
5579 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5580 error "nid '$nid' does not match any client NID:" \
5583 run_test 604 "NOPEN Changelog entry"
5586 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5587 skip "need MDS version at least 2.10.58"
5591 local f=$DIR/$tdir/$tfile
5592 local f2=$DIR2/$tdir/$tfile
5595 # set changelog_mask to ALL
5596 changelog_chmask "ALL"
5598 touch $f || error "touch $f failed"
5599 local fid=$(path2fid $f)
5603 exec 3<> $f || error "open $f failed"
5607 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5611 exec 4<> $f || error "open $f failed"
5614 changelog_find -type OPEN -target-fid $fid &&
5615 error "There should be no OPEN entry"
5617 exec 4>&- || error "close $f failed"
5620 changelog_find -type CLOSE -target-fid $fid &&
5621 error "There should be no CLOSE entry"
5625 # access in rw, so different access mode should generate entries
5626 cat $f || error "cat $f failed"
5629 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5631 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5635 # same access as first one, should not generate new entries
5636 exec 4<> $f || error "open $f failed"
5639 changelog_find -type OPEN -target-fid $fid &&
5640 error "There should be no OPEN entry"
5642 exec 4>&- || error "close $f failed"
5645 changelog_find -type CLOSE -target-fid $fid &&
5646 error "There should be no CLOSE entry"
5650 # access by different user should generate new entries
5651 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5654 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5656 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5660 exec 3>&- || error "close $f failed"
5663 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5665 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5668 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5669 skip "need MDS version at least 2.10.58"
5671 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5672 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5673 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5674 skip_env "missing llog_reader" && return
5675 local fstype=$(facet_fstype mds1)
5679 local f=$DIR/$tdir/$tfile
5682 # set changelog_mask to ALL
5683 changelog_chmask "ALL"
5685 chmod 777 $DIR/$tdir
5686 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5687 local fid=$(path2fid $f)
5688 rm $f || error "rm $f failed"
5690 local mntpt=$(facet_mntpt mds1)
5694 #remount mds1 as ldiskfs or zfs type
5695 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5696 stop mds1 || error "stop mds1 failed"
5697 mount_fstype mds1 || error "remount mds1 failed"
5699 for ((i = 0; i < 1; i++)); do
5700 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5701 local cat_file=$(do_facet mds1 $llog_reader \
5702 $mntpt/changelog_catalog | awk \
5703 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5704 [ -n "$cat_file" ] || error "no catalog file"
5706 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5707 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5708 [ -n "$entry" ] || error "no CREAT entry"
5711 local uidgid=$(echo $entry |
5712 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5713 [ -n "$uidgid" ] || error "uidgid is empty"
5714 echo "Got UID/GID $uidgid"
5715 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5716 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5717 local nid=$(echo $entry |
5718 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5719 [ -n "$nid" ] || error "nid is empty"
5721 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5722 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5724 run_test 606 "llog_reader groks changelog fields"
5727 check_and_cleanup_lustre