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}
29 MULTIOP=${MULTIOP:-multiop}
30 OPENFILE=${OPENFILE:-openfile}
31 MMAP_CAT=${MMAP_CAT:-mmap_cat}
32 MOUNT_2=${MOUNT_2:-"yes"}
34 MDS_VERSION_CODE=$(lustre_version_code $SINGLEMDS)
36 # script only handles up to 10 MDTs (because of MDT_PREFIX)
37 [ $MDSCOUNT -gt 9 ] &&
38 error "script cannot handle more than 9 MDTs, please fix" && exit
40 check_and_setup_lustre
42 if [[ $MDS_VERSION_CODE -lt $(version_code 2.4.53) ]]; then
43 skip_env "Need MDS version at least 2.4.53"
46 # $RUNAS_ID may get set incorrectly somewhere else
47 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
48 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
50 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
51 if getent group nobody; then
53 elif getent group nogroup; then
56 error "No generic nobody group"
61 # if there is no CLIENT1 defined, some tests can be ran on localhost
62 CLIENT1=${CLIENT1:-$HOSTNAME}
63 # if CLIENT2 doesn't exist then use CLIENT1 instead
64 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
66 # Exception is the test which need two separate nodes
67 CLIENT2=${CLIENT2:-$CLIENT1}
70 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
71 # the following associated variables are added:
73 # AGTCOUNT: number of agents
74 # AGTDEV{N}: target HSM mount point (root path of the backend)
75 # agt{N}_HOST: hostname of the agent agt{N}
76 # SINGLEAGT: facet of the single agent
78 # The number of agents is initialized as the number of remote client nodes.
79 # By default, only single copytool is started on a remote client/agent. If there
80 # was no remote client, then the copytool will be started on the local client.
86 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
87 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
89 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
90 if [[ $CLIENTCOUNT -gt 1 ]] &&
91 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
92 skip_env "SHARED_DIRECTORY should be accessible"\
97 # We used to put the HSM archive in $SHARED_DIRECTORY but that
98 # meant NFS issues could hose sanity-hsm sessions. So now we
100 for n in $(seq $AGTCOUNT); do
101 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
102 agent=CLIENT$((n + 1))
103 if [[ -z "${!agent}" ]]; then
104 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
107 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
110 export SINGLEAGT=${SINGLEAGT:-agt1}
112 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
113 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
114 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
115 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
116 export HSMTOOL_TESTDIR
117 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
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 "pgrep -x $HSMTOOL_BASE"
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
159 echo "Killing existing copytools on $hosts"
160 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || 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 pkill -x '$HSMTOOL_BASE' || 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 pkill -CONT -x '$HSMTOOL_BASE' || true" EXIT
404 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
405 echo "Copytool is suspended on $agents"
408 copytool_continue() {
409 local agents=${1:-$(facet_active_host $SINGLEAGT)}
411 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || 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 ps -C $HSMTOOL_BASE -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 # Test whether setting archive number > 32 results in error.
997 $LFS hsm_set --exists --archive-id 33 $f &&
998 error "archive number is larger than 32"
999 check_hsm_flags_user $f "0x00000001"
1001 # Test whether setting archive number 16 and archived flag.
1002 LOCAL_HSM_ARCHIVE_NUMBER=16
1003 $LFS hsm_set --exists --archived \
1004 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1005 error "root could not change hsm flags"
1006 check_hsm_flags_user $f "0x00000009"
1007 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1008 st=$(get_hsm_archive_id $f)
1009 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1010 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1012 run_test 1c "Check setting archive-id in lfs hsm_set"
1015 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1016 skip "need MDS version at least 2.10.59"
1019 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1020 error "failed to set default stripe"
1021 local f=$DIR/$tdir/$tfile
1024 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1025 error "failed to create file"
1026 local fid=$(path2fid $f)
1031 $LFS hsm_archive $f || error "could not archive file"
1032 wait_request_state $fid ARCHIVE SUCCEED
1035 $LFS hsm_release $f || error "could not release file"
1036 echo "verify released state: "
1037 check_hsm_flags $f "0x0000000d" && echo "pass"
1040 $LFS hsm_restore $f || error "could not restore file"
1041 wait_request_state $fid RESTORE SUCCEED
1042 echo "verify restored state: "
1043 check_hsm_flags $f "0x00000009" && echo "pass"
1045 run_test 1d "Archive, Release and Restore DoM file"
1048 local f=$DIR/$tdir/$tfile
1050 create_empty_file "$f"
1051 # New files are not dirty
1052 check_hsm_flags $f "0x00000000"
1054 # For test, we simulate an archived file.
1055 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1056 check_hsm_flags $f "0x00000001"
1058 # chmod do not put the file dirty
1059 chmod 600 $f || error "could not chmod test file"
1060 check_hsm_flags $f "0x00000001"
1062 # chown do not put the file dirty
1063 chown $RUNAS_ID $f || error "could not chown test file"
1064 check_hsm_flags $f "0x00000001"
1066 # truncate put the file dirty
1067 $TRUNCATE $f 1 || error "could not truncate test file"
1068 check_hsm_flags $f "0x00000003"
1070 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1071 check_hsm_flags $f "0x00000001"
1073 run_test 2 "Check file dirtyness when doing setattr"
1079 # New files are not dirty
1080 cp -p /etc/passwd $f
1081 check_hsm_flags $f "0x00000000"
1083 # For test, we simulate an archived file.
1084 $LFS hsm_set --exists $f ||
1085 error "user could not change hsm flags"
1086 check_hsm_flags $f "0x00000001"
1088 # Reading a file, does not set dirty
1089 cat $f > /dev/null || error "could not read file"
1090 check_hsm_flags $f "0x00000001"
1092 # Open for write without modifying data, does not set dirty
1093 openfile -f O_WRONLY $f || error "could not open test file"
1094 check_hsm_flags $f "0x00000001"
1096 # Append to a file sets it dirty
1097 cp -p /etc/passwd $f.append || error "could not create file"
1098 $LFS hsm_set --exists $f.append ||
1099 error "user could not change hsm flags"
1100 dd if=/etc/passwd of=$f.append bs=1 count=3\
1101 conv=notrunc oflag=append status=noxfer ||
1102 file_creation_failure dd $f.append $?
1103 check_hsm_flags $f.append "0x00000003"
1105 # Modify a file sets it dirty
1106 cp -p /etc/passwd $f.modify || error "could not create file"
1107 $LFS hsm_set --exists $f.modify ||
1108 error "user could not change hsm flags"
1109 dd if=/dev/zero of=$f.modify bs=1 count=3\
1110 conv=notrunc status=noxfer ||
1111 file_creation_failure dd $f.modify $?
1112 check_hsm_flags $f.modify "0x00000003"
1114 # Open O_TRUNC sets dirty
1115 cp -p /etc/passwd $f.trunc || error "could not create file"
1116 $LFS hsm_set --exists $f.trunc ||
1117 error "user could not change hsm flags"
1118 cp /etc/group $f.trunc || error "could not override a file"
1119 check_hsm_flags $f.trunc "0x00000003"
1121 # Mmapped a file sets dirty
1122 cp -p /etc/passwd $f.mmap || error "could not create file"
1123 $LFS hsm_set --exists $f.mmap ||
1124 error "user could not change hsm flags"
1125 multiop $f.mmap OSMWUc || error "could not mmap a file"
1126 check_hsm_flags $f.mmap "0x00000003"
1128 run_test 3 "Check file dirtyness when opening for write"
1131 local f=$DIR/$tdir/$tfile
1132 local fid=$(create_small_file $f)
1135 local st=$(get_request_state $fid CANCEL)
1136 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1138 run_test 4 "Useless cancel must not be registered"
1141 # test needs a running copytool
1145 local f=$DIR/$tdir/$tfile
1146 local fid=$(copy_file /etc/passwd $f)
1148 wait_request_state $fid ARCHIVE SUCCEED
1150 check_hsm_flags $f "0x00000009"
1152 run_test 8 "Test default archive number"
1154 test_9A() { # was test_9
1155 # we do not use the default one to be sure
1156 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1157 copytool setup --archive-id $archive_id
1159 # give time for CT to register with MDTs
1160 sleep $(($MDSCOUNT*2))
1161 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1162 check_agent_registered $uuid
1165 local f=$DIR/$tdir/$tfile
1166 local fid=$(copy_file /etc/passwd $f)
1167 $LFS hsm_archive --archive $archive_id $f
1168 wait_request_state $fid ARCHIVE SUCCEED
1170 check_hsm_flags $f "0x00000009"
1172 run_test 9A "Use of explicit archive number, with dedicated copytool"
1175 needclients 3 || return 0
1181 # start all of the copytools
1182 for n in $(seq $AGTCOUNT); do
1183 copytool setup --facet agt$n
1187 for n in $(seq $AGTCOUNT); do
1188 file=$DIR/$tdir/$tfile.$n
1189 fid=$(create_small_file $file)
1191 $LFS hsm_archive $file || error "could not archive file $file"
1192 wait_request_state $fid ARCHIVE SUCCEED
1193 check_hsm_flags $file "0x00000009"
1196 run_test 9a "Multiple remote agents"
1199 # test needs a running copytool
1202 mkdir -p $DIR/$tdir/d1
1203 local f=$DIR/$tdir/$tfile
1204 local fid=$(copy_file /etc/hosts $f)
1205 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1206 error "hsm_archive failed"
1207 wait_request_state $fid ARCHIVE SUCCEED
1209 local hsm_root="$(copytool_device $SINGLEAGT)"
1210 local archive="$(do_facet $SINGLEAGT \
1211 find "$hsm_root" -name "$fid" -print0)"
1212 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1214 echo "Verifying content"
1215 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1216 echo "Verifying hsm state "
1217 check_hsm_flags $f "0x00000009"
1219 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1220 local st=$(get_hsm_archive_id $f)
1221 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1222 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1224 run_test 10a "Archive a file"
1227 # test needs a running copytool
1231 local f=$DIR/$tdir/$tfile
1232 local fid=$(copy_file /etc/hosts $f)
1233 $LFS hsm_archive $f || error "archive request failed"
1234 wait_request_state $fid ARCHIVE SUCCEED
1236 $LFS hsm_archive $f || error "archive of non dirty file failed"
1237 local cnt=$(get_request_count $fid ARCHIVE)
1238 [[ "$cnt" == "1" ]] ||
1239 error "archive of non dirty file must not make a request"
1241 run_test 10b "Archive of non dirty file must work without doing request"
1244 # test needs a running copytool
1248 local f=$DIR/$tdir/$tfile
1249 local fid=$(copy_file /etc/hosts $f)
1250 $LFS hsm_set --noarchive $f
1251 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1254 run_test 10c "Check forbidden archive"
1257 # test needs a running copytool
1261 local f=$DIR/$tdir/$tfile
1262 local fid=$(copy_file /etc/hosts $f)
1263 $LFS hsm_archive $f || error "cannot archive $f"
1264 wait_request_state $fid ARCHIVE SUCCEED
1266 local ar=$(get_hsm_archive_id $f)
1267 local dflt=$(get_hsm_param default_archive_id)
1268 [[ $ar == $dflt ]] ||
1269 error "archived file is not on default archive: $ar != $dflt"
1271 run_test 10d "Archive a file on the default archive id"
1275 copy2archive /etc/hosts $tdir/$tfile
1276 local f=$DIR/$tdir/$tfile
1278 copytool import $tdir/$tfile $f
1279 echo -n "Verifying released state: "
1280 check_hsm_flags $f "0x0000000d"
1282 local LSZ=$(stat -c "%s" $f)
1283 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1285 echo "Verifying imported size $LSZ=$ASZ"
1286 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1287 echo -n "Verifying released pattern: "
1288 local PTRN=$($GETSTRIPE -L $f)
1290 [[ $PTRN == released ]] || error "Is not released"
1291 local fid=$(path2fid $f)
1292 echo "Verifying new fid $fid in archive"
1294 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1295 error "No archive for fid $fid"
1297 run_test 11a "Import a file"
1300 # test needs a running copytool
1304 local f=$DIR/$tdir/$tfile
1305 local fid=$(copy_file /etc/hosts $f)
1306 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1307 error "hsm_archive failed"
1308 wait_request_state $fid ARCHIVE SUCCEED
1310 local FILE_HASH=$(md5sum $f)
1313 copytool import $fid $f
1315 echo "$FILE_HASH" | md5sum -c
1317 [[ $? -eq 0 ]] || error "Restored file differs"
1319 run_test 11b "Import a deleted file using its FID"
1322 # test needs a running copytool
1326 copy2archive /etc/hosts $tdir/$tfile
1328 local f=$DIR/$tdir/$tfile
1329 copytool import $tdir/$tfile $f
1330 local f2=$DIR2/$tdir/$tfile
1331 echo "Verifying released state: "
1332 check_hsm_flags $f2 "0x0000000d"
1334 local fid=$(path2fid $f2)
1335 $LFS hsm_restore $f2
1336 wait_request_state $fid RESTORE SUCCEED
1338 echo "Verifying file state: "
1339 check_hsm_flags $f2 "0x00000009"
1341 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1343 [[ $? -eq 0 ]] || error "Restored file differs"
1345 run_test 12a "Restore an imported file explicitly"
1348 # test needs a running copytool
1352 copy2archive /etc/hosts $tdir/$tfile
1354 local f=$DIR/$tdir/$tfile
1355 copytool import $tdir/$tfile $f
1356 echo "Verifying released state: "
1357 check_hsm_flags $f "0x0000000d"
1359 cat $f > /dev/null || error "File read failed"
1361 echo "Verifying file state after restore: "
1362 check_hsm_flags $f "0x00000009"
1364 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1366 [[ $? -eq 0 ]] || error "Restored file differs"
1368 run_test 12b "Restore an imported file implicitly"
1371 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1373 # test needs a running copytool
1376 local f=$DIR/$tdir/$tfile
1378 $LFS setstripe -c 2 "$f"
1379 local fid=$(create_file "$f" 1M 5)
1381 local FILE_CRC=$(md5sum $f)
1383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1384 wait_request_state $fid ARCHIVE SUCCEED
1385 $LFS hsm_release $f || error "release $f failed"
1387 echo "$FILE_CRC" | md5sum -c
1389 [[ $? -eq 0 ]] || error "Restored file differs"
1391 run_test 12c "Restore a file with stripe of 2"
1394 # test needs a running copytool
1399 local f=$DIR/$tdir/$tfile
1400 local fid=$(copy_file /etc/hosts $f)
1401 $LFS hsm_restore $f || error "restore of non archived file failed"
1402 local cnt=$(get_request_count $fid RESTORE)
1403 [[ "$cnt" == "0" ]] ||
1404 error "restore non archived must not make a request"
1405 $LFS hsm_archive $f ||
1406 error "archive request failed"
1407 wait_request_state $fid ARCHIVE SUCCEED
1408 $LFS hsm_restore $f ||
1409 error "restore of non released file failed"
1410 local cnt=$(get_request_count $fid RESTORE)
1411 [[ "$cnt" == "0" ]] ||
1412 error "restore a non dirty file must not make a request"
1414 run_test 12d "Restore of a non archived, non released file must work"\
1415 " without doing request"
1418 # test needs a running copytool
1422 local f=$DIR/$tdir/$tfile
1423 local fid=$(copy_file /etc/hosts $f)
1424 $LFS hsm_archive $f || error "archive request failed"
1425 wait_request_state $fid ARCHIVE SUCCEED
1428 cat /etc/hosts >> $f
1432 $LFS hsm_restore $f && error "restore a dirty file must fail"
1435 run_test 12e "Check forbidden restore"
1438 # test needs a running copytool
1442 local f=$DIR/$tdir/$tfile
1443 local fid=$(copy_file /etc/hosts $f)
1445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1446 wait_request_state $fid ARCHIVE SUCCEED
1447 $LFS hsm_release $f || error "release of $f failed"
1449 wait_request_state $fid RESTORE SUCCEED
1451 echo -n "Verifying file state: "
1452 check_hsm_flags $f "0x00000009"
1454 diff -q /etc/hosts $f
1456 [[ $? -eq 0 ]] || error "Restored file differs"
1458 run_test 12f "Restore a released file explicitly"
1461 # test needs a running copytool
1465 local f=$DIR/$tdir/$tfile
1466 local fid=$(copy_file /etc/hosts $f)
1468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1469 wait_request_state $fid ARCHIVE SUCCEED
1470 $LFS hsm_release $f || error "release of $f failed"
1472 diff -q /etc/hosts $f
1475 # we check we had a restore done
1476 wait_request_state $fid RESTORE SUCCEED
1478 [[ $st -eq 0 ]] || error "Restored file differs"
1480 run_test 12g "Restore a released file implicitly"
1483 needclients 2 || return 0
1485 # test needs a running copytool
1489 local f=$DIR/$tdir/$tfile
1490 local fid=$(copy_file /etc/hosts $f)
1492 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1493 wait_request_state $fid ARCHIVE SUCCEED
1494 $LFS hsm_release $f || error "release of $f failed"
1496 do_node $CLIENT2 diff -q /etc/hosts $f
1499 # we check we had a restore done
1500 wait_request_state $fid RESTORE SUCCEED
1502 [[ $st -eq 0 ]] || error "Restored file differs"
1504 run_test 12h "Restore a released file implicitly from a second node"
1507 # test needs a running copytool
1511 local f=$DIR/$tdir/$tfile
1512 local fid=$(copy_file /etc/passwd $f)
1513 $LFS hsm_archive $f || error "archive of $f failed"
1514 wait_request_state $fid ARCHIVE SUCCEED
1516 $LFS hsm_release $f || error "release of $f failed"
1520 [[ $? -eq 0 ]] || error "Restored file differs"
1522 run_test 12m "Archive/release/implicit restore"
1525 # test needs a running copytool
1529 copy2archive /etc/hosts $tdir/$tfile
1531 local f=$DIR/$tdir/$tfile
1532 copytool import $tdir/$tfile $f
1534 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1535 error "Restored file differs"
1537 $LFS hsm_release $f || error "release of $f failed"
1539 run_test 12n "Import/implicit restore/release"
1542 # test needs a running copytool
1546 local f=$DIR/$tdir/$tfile
1547 local fid=$(copy_file /etc/hosts $f)
1549 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1550 wait_request_state $fid ARCHIVE SUCCEED
1551 $LFS hsm_release $f || error "release of $f failed"
1553 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1554 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1556 # set no retry action mode
1559 diff -q /etc/hosts $f
1562 # we check we had a restore failure
1563 wait_request_state $fid RESTORE FAILED
1565 [[ $st -eq 0 ]] && error "Restore must fail"
1567 # remove no retry action mode
1570 # check file is still released
1571 check_hsm_flags $f "0x0000000d"
1573 # retry w/o failure injection
1574 do_facet $SINGLEMDS lctl set_param fail_loc=0
1576 # to be sure previous RESTORE result is gone
1578 wait_for_grace_delay
1580 diff -q /etc/hosts $f
1583 # we check we had a restore done
1584 wait_request_state $fid RESTORE SUCCEED
1586 [[ $st -eq 0 ]] || error "Restored file differs"
1588 run_test 12o "Layout-swap failure during Restore leaves file released"
1591 # test needs a running copytool
1595 local f=$DIR/$tdir/$tfile
1596 local fid=$(copy_file /etc/hosts $f)
1598 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1599 wait_request_state $fid ARCHIVE SUCCEED
1600 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1601 $LFS hsm_release $f || error "cannot release $f"
1602 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1603 $LFS hsm_release $f || error "cannot release $f"
1604 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1606 run_test 12p "implicit restore of a file on copytool mount point"
1609 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1610 skip "need MDS version at least 2.7.58"
1612 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1613 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1614 error "cannot mount $MOUNT3 on $SINGLEAGT"
1616 # test needs a running copytool
1617 copytool setup -m "$MOUNT3"
1619 local f=$DIR/$tdir/$tfile
1620 local f2=$DIR2/$tdir/$tfile
1621 local fid=$(create_small_file $f)
1622 local orig_size=$(stat -c "%s" $f)
1624 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1625 wait_request_state $fid ARCHIVE SUCCEED
1627 $LFS hsm_release $f || error "could not release file"
1628 check_hsm_flags $f "0x0000000d"
1631 wait_copytools || error "copytool failed to stop"
1633 cat $f > /dev/null &
1635 # wait a bit to allow implicit restore request to be handled.
1636 # if not, next stat would also block on layout-lock.
1639 local size=$(stat -c "%s" $f2)
1640 [ $size -eq $orig_size ] ||
1641 error "$f2: wrong size after archive: $size != $orig_size"
1643 copytool setup -m "$MOUNT3"
1647 size=$(stat -c "%s" $f)
1648 [ $size -eq $orig_size ] ||
1649 error "$f: wrong size after restore: $size != $orig_size"
1651 size=$(stat -c "%s" $f2)
1652 [ $size -eq $orig_size ] ||
1653 error "$f2: wrong size after restore: $size != $orig_size"
1657 size=$(stat -c "%s" $f)
1659 error "$f: wrong size after overwrite: $size != 0"
1661 size=$(stat -c "%s" $f2)
1663 error "$f2: wrong size after overwrite: $size != 0"
1665 run_test 12q "file attributes are refreshed after restore"
1669 for i in {1..10}; do
1670 local archive_dir="$(hsm_root)"/subdir/dir.$i
1672 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1673 for j in {1..10}; do
1674 local archive_file="$archive_dir"/file.$j
1676 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1682 copytool import "subdir" "$DIR/$tdir"
1684 # To check the import, the test uses diff with the -r flag
1685 # This is nice, but diff only checks files one by one, and triggering
1686 # an implicit restore for one file at a time will consume as many
1687 # seconds as there are files to compare. To speed this up, a restore
1688 # operation is triggered manually first.
1690 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1692 # Compare the imported data
1693 do_facet $SINGLEAGT \
1694 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1695 error "imported files differ from archived data"
1697 run_test 13 "Recursively import and restore a directory"
1700 # test needs a running copytool
1704 local f=$DIR/$tdir/$tfile
1705 local fid=$(create_small_file $f)
1706 local sum=$(md5sum $f | awk '{print $1}')
1707 $LFS hsm_archive $f || error "could not archive file"
1708 wait_request_state $fid ARCHIVE SUCCEED
1710 # create released file (simulate llapi_hsm_import call)
1711 local fid2=$(create_empty_file "$f")
1712 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1713 $LFS hsm_release $f || error "could not release file"
1715 # rebind the archive to the newly created file
1716 echo "rebind $fid to $fid2"
1718 copytool rebind $fid $fid2
1720 # restore file and compare md5sum
1721 local sum2=$(md5sum $f | awk '{print $1}')
1723 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1725 run_test 14 "Rebind archived file to a new fid"
1728 # test needs a running copytool
1732 local f=$DIR/$tdir/$tfile
1734 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1738 for i in $(seq 1 $count); do
1739 fids[$i]=$(create_small_file $f.$i)
1740 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1741 $LFS hsm_archive $f.$i || error "could not archive file"
1743 wait_all_done $(($count*60))
1745 stack_trap "rm -f $tmpfile" EXIT
1748 for i in $(seq 1 $count); do
1749 local fid2=$(create_empty_file "${f}.${i}")
1750 # add the rebind operation to the list
1751 echo ${fids[$i]} $fid2 >> $tmpfile
1753 # set it released (simulate llapi_hsm_import call)
1754 $LFS hsm_set --archived --exists $f.$i ||
1755 error "could not force hsm flags"
1756 $LFS hsm_release $f.$i || error "could not release file"
1758 nl=$(wc -l < $tmpfile)
1759 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1761 echo "rebind list of files"
1762 copytool rebind "$tmpfile"
1764 # restore files and compare md5sum
1765 for i in $(seq 1 $count); do
1766 local sum2=$(md5sum $f.$i | awk '{print $1}')
1767 [[ $sum2 == ${sums[$i]} ]] ||
1768 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1771 run_test 15 "Rebind a list of files"
1774 # test needs a running copytool
1778 # create a known size file so we can verify transfer speed
1781 dd if=/dev/zero of=$ref bs=1M count=20
1784 local f=$DIR/$tdir/$tfile
1785 local fid=$(copy_file $ref $f)
1787 local start=$(date +%s)
1789 wait_request_state $fid ARCHIVE SUCCEED
1790 local end=$(date +%s)
1791 # Add 1 to account for rounding errors between start and end (LU-8155)
1792 local duration=$((end - start + 1))
1794 [[ $duration -ge $((goal - 1)) ]] ||
1795 error "Transfer is too fast $duration < $goal"
1797 run_test 16 "Test CT bandwith control option"
1800 local f=$DIR/$tdir/$tfile
1801 create_empty_file "$f"
1803 # Could not release a non-archived file
1804 $LFS hsm_release $f && error "release should not succeed"
1806 # For following tests, we must test them with HS_ARCHIVED set
1807 $LFS hsm_set --exists --archived $f || error "could not add flag"
1809 # Could not release a file if no-release is set
1810 $LFS hsm_set --norelease $f || error "could not add flag"
1811 $LFS hsm_release $f && error "release should not succeed"
1812 $LFS hsm_clear --norelease $f || error "could not remove flag"
1814 # Could not release a file if lost
1815 $LFS hsm_set --lost $f || error "could not add flag"
1816 $LFS hsm_release $f && error "release should not succeed"
1817 $LFS hsm_clear --lost $f || error "could not remove flag"
1819 # Could not release a file if dirty
1820 $LFS hsm_set --dirty $f || error "could not add flag"
1821 $LFS hsm_release $f && error "release should not succeed"
1822 $LFS hsm_clear --dirty $f || error "could not remove flag"
1824 run_test 20 "Release is not permitted"
1827 # test needs a running copytool
1830 local f=$DIR/$tdir/test_release
1832 # Create a file and check its states
1833 local fid=$(create_small_file $f)
1834 check_hsm_flags $f "0x00000000"
1836 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1837 # used until file is flushed to disk
1838 if [ $(facet_fstype ost1) == "zfs" ]; then
1839 # this causes an OST_SYNC rpc to be sent
1840 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1841 # clear locks to reread file data
1842 cancel_lru_locks osc
1845 local orig_size=$(stat -c "%s" $f)
1846 local orig_blocks=$(stat -c "%b" $f)
1848 start_full_debug_logging
1850 $LFS hsm_archive $f || error "could not archive file"
1851 wait_request_state $fid ARCHIVE SUCCEED
1853 local blocks=$(stat -c "%b" $f)
1854 [ $blocks -eq $orig_blocks ] ||
1855 error "$f: wrong block number after archive: " \
1856 "$blocks != $orig_blocks"
1857 local size=$(stat -c "%s" $f)
1858 [ $size -eq $orig_size ] ||
1859 error "$f: wrong size after archive: $size != $orig_size"
1861 # Release and check states
1862 $LFS hsm_release $f || error "could not release file"
1863 check_hsm_flags $f "0x0000000d"
1865 blocks=$(stat -c "%b" $f)
1866 [ $blocks -gt 5 ] &&
1867 error "$f: too many blocks after release: $blocks > 5"
1868 size=$(stat -c "%s" $f)
1869 [ $size -ne $orig_size ] &&
1870 error "$f: wrong size after release: $size != $orig_size"
1872 # Check we can release an file without stripe info
1876 check_hsm_flags $f "0x00000000"
1877 $LFS hsm_archive $f || error "could not archive file"
1878 wait_request_state $fid ARCHIVE SUCCEED
1880 # Release and check states
1881 $LFS hsm_release $f || error "could not release file"
1882 check_hsm_flags $f "0x0000000d"
1884 # Release again a file that is already released is OK
1885 $LFS hsm_release $f || fail "second release should succeed"
1886 check_hsm_flags $f "0x0000000d"
1888 stop_full_debug_logging
1890 run_test 21 "Simple release tests"
1893 # test needs a running copytool
1896 local f=$DIR/$tdir/test_release
1897 local swap=$DIR/$tdir/test_swap
1899 # Create a file and check its states
1900 local fid=$(create_small_file $f)
1901 check_hsm_flags $f "0x00000000"
1903 $LFS hsm_archive $f || error "could not archive file"
1904 wait_request_state $fid ARCHIVE SUCCEED
1906 # Release and check states
1907 $LFS hsm_release $f || error "could not release file"
1908 check_hsm_flags $f "0x0000000d"
1910 create_small_file $swap
1911 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1915 run_test 22 "Could not swap a release file"
1918 # test needs a running copytool
1921 local f=$DIR/$tdir/test_mtime
1923 # Create a file and check its states
1924 local fid=$(create_small_file $f)
1925 check_hsm_flags $f "0x00000000"
1927 $LFS hsm_archive $f || error "could not archive file"
1928 wait_request_state $fid ARCHIVE SUCCEED
1930 # Set modification time in the past
1931 touch -m -a -d @978261179 $f
1933 # Release and check states
1934 $LFS hsm_release $f || error "could not release file"
1935 check_hsm_flags $f "0x0000000d"
1937 local MTIME=$(stat -c "%Y" $f)
1938 local ATIME=$(stat -c "%X" $f)
1939 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1940 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1942 run_test 23 "Release does not change a/mtime (utime)"
1945 local file=$DIR/$tdir/$tfile
1954 # test needs a running copytool
1957 fid=$(create_small_file $file)
1959 # Create a file and check its states
1960 check_hsm_flags $file "0x00000000"
1962 # Ensure atime is less than mtime and ctime.
1966 atime0=$(stat -c "%X" $file)
1967 mtime0=$(stat -c "%Y" $file)
1968 ctime0=$(stat -c "%Z" $file)
1970 [ $atime0 -lt $mtime0 ] ||
1971 error "atime $atime0 is not less than mtime $mtime0"
1973 [ $atime0 -lt $ctime0 ] ||
1974 error "atime $atime0 is not less than ctime $ctime0"
1976 # Archive should not change any timestamps.
1977 $LFS hsm_archive $file || error "cannot archive '$file'"
1978 wait_request_state $fid ARCHIVE SUCCEED
1980 atime1=$(stat -c "%X" $file)
1981 mtime1=$(stat -c "%Y" $file)
1982 ctime1=$(stat -c "%Z" $file)
1984 [ $atime0 -eq $atime1 ] ||
1985 error "archive changed atime from $atime0 to $atime1"
1987 [ $mtime0 -eq $mtime1 ] ||
1988 error "archive changed mtime from $mtime0 to $mtime1"
1990 [ $ctime0 -eq $ctime1 ] ||
1991 error "archive changed ctime from $ctime0 to $ctime1"
1993 # Release should not change any timestamps.
1994 $LFS hsm_release $file || error "cannot release '$file'"
1995 check_hsm_flags $file "0x0000000d"
1997 atime1=$(stat -c "%X" $file)
1998 mtime1=$(stat -c "%Y" $file)
1999 ctime1=$(stat -c "%Z" $file)
2001 [ $atime0 -eq $atime1 ] ||
2002 error "release changed atime from $atime0 to $atime1"
2004 [ $mtime0 -eq $mtime1 ] ||
2005 error "release changed mtime from $mtime0 to $mtime1"
2007 [ $ctime0 -eq $ctime1 ] ||
2008 error "release changed ctime from $ctime0 to $ctime1"
2010 # Restore should not change any timestamps.
2011 $LFS hsm_restore $file
2012 wait_request_state $fid RESTORE SUCCEED
2014 atime1=$(stat -c "%X" $file)
2015 mtime1=$(stat -c "%Y" $file)
2016 ctime1=$(stat -c "%Z" $file)
2018 [ $atime0 -eq $atime1 ] ||
2019 error "restore changed atime from $atime0 to $atime1"
2021 [ $mtime0 -eq $mtime1 ] ||
2022 error "restore changed mtime from $mtime0 to $mtime1"
2024 [ $ctime0 -eq $ctime1 ] ||
2025 error "restore changed ctime from $ctime0 to $ctime1"
2028 wait_copytools || error "Copytools failed to stop"
2030 # Once more, after unmount and mount.
2031 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2032 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2034 atime1=$(stat -c "%X" $file)
2035 mtime1=$(stat -c "%Y" $file)
2036 ctime1=$(stat -c "%Z" $file)
2038 [ $atime0 -eq $atime1 ] ||
2039 error "remount changed atime from $atime0 to $atime1"
2041 [ $mtime0 -eq $mtime1 ] ||
2042 error "remount changed mtime from $mtime0 to $mtime1"
2044 [ $ctime0 -eq $ctime1 ] ||
2045 error "remount changed ctime from $ctime0 to $ctime1"
2047 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2050 local file=$DIR/$tdir/$tfile
2056 # Test needs a running copytool.
2059 # Check that root can do HSM actions on a regular user's file.
2060 fid=$(create_small_file $file)
2061 sum0=$(md5sum $file)
2063 chown $RUNAS_ID:$RUNAS_GID $file ||
2064 error "cannot chown '$file' to '$RUNAS_ID'"
2066 chmod ugo-w $DIR/$tdir ||
2067 error "cannot chmod '$DIR/$tdir'"
2069 $LFS hsm_archive $file
2070 wait_request_state $fid ARCHIVE SUCCEED
2072 $LFS hsm_release $file
2073 check_hsm_flags $file "0x0000000d"
2075 $LFS hsm_restore $file
2076 wait_request_state $fid RESTORE SUCCEED
2078 # Check that ordinary user can get HSM state.
2079 $RUNAS $LFS hsm_state $file ||
2080 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2082 $LFS hsm_release $file
2083 check_hsm_flags $file "0x0000000d"
2085 # Check that ordinary user can accessed released file.
2086 sum1=$($RUNAS md5sum $file) ||
2087 error "user '$RUNAS_ID' cannot read '$file'"
2089 [ "$sum0" == "$sum1" ] ||
2090 error "md5sum mismatch for '$file'"
2092 run_test 24b "root can archive, release, and restore user files"
2095 local file=$DIR/$tdir/$tfile
2096 local action=archive
2101 # test needs a running copytool
2106 # Save the default masks and check that cleanup_24c will
2107 # restore the request masks correctly.
2108 user_save=$(get_hsm_param user_request_mask)
2109 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2110 group_save=$(get_hsm_param group_request_mask)
2111 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2112 other_save=$(get_hsm_param other_request_mask)
2113 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2115 [ "$user_save" == RESTORE ] ||
2116 error "user_request_mask is '$user_save' expected 'RESTORE'"
2117 [ "$group_save" == RESTORE ] ||
2118 error "group_request_mask is '$group_save' expected 'RESTORE'"
2119 [ "$other_save" == RESTORE ] ||
2120 error "other_request_mask is '$other_save' expected 'RESTORE'"
2123 create_small_file $file
2124 chown $RUNAS_ID:$GROUP $file ||
2125 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2127 $RUNAS $LFS hsm_$action $file &&
2128 error "$action by user should fail"
2130 set_hsm_param user_request_mask $action
2131 $RUNAS $LFS hsm_$action $file ||
2132 error "$action by user should succeed"
2135 create_small_file $file
2136 chown nobody:$RUNAS_GID $file ||
2137 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2139 $RUNAS $LFS hsm_$action $file &&
2140 error "$action by group should fail"
2142 set_hsm_param group_request_mask $action
2143 $RUNAS $LFS hsm_$action $file ||
2144 error "$action by group should succeed"
2147 create_small_file $file
2148 chown nobody:$GROUP $file ||
2149 error "cannot chown '$file' to 'nobody:$GROUP'"
2151 $RUNAS $LFS hsm_$action $file &&
2152 error "$action by other should fail"
2154 set_hsm_param other_request_mask $action
2155 $RUNAS $LFS hsm_$action $file ||
2156 error "$action by other should succeed"
2158 run_test 24c "check that user,group,other request masks work"
2161 local file1=$DIR/$tdir/$tfile
2162 local file2=$DIR2/$tdir/$tfile
2166 fid1=$(create_small_file $file1)
2169 $LFS getstripe $file1
2171 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2172 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2173 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2175 copytool setup -m "$MOUNT3"
2177 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2178 mount -o remount,ro $MOUNT2
2180 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2182 fid2=$(path2fid $file2)
2183 [ "$fid1" == "$fid2" ] ||
2184 error "FID mismatch '$fid1' != '$fid2'"
2186 $LFS hsm_archive $file2 &&
2187 error "archive should fail on read-only mount"
2188 check_hsm_flags $file1 "0x00000000"
2190 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2191 wait_request_state $fid1 ARCHIVE SUCCEED
2193 $LFS hsm_release $file1
2194 $LFS hsm_restore $file2
2195 wait_request_state $fid1 RESTORE SUCCEED
2197 $LFS hsm_release $file1 || error "cannot release '$file1'"
2198 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2200 $LFS hsm_release $file2 &&
2201 error "release should fail on read-only mount"
2205 run_test 24d "check that read-only mounts are respected"
2210 local f=$DIR/$tdir/$tfile
2213 fid=$(create_small_file $f) || error "cannot create $f"
2214 $LFS hsm_archive $f || error "cannot archive $f"
2215 wait_request_state $fid ARCHIVE SUCCEED
2216 $LFS hsm_release $f || error "cannot release $f"
2217 while ! $LFS hsm_state $f | grep released; do
2221 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2223 run_test 24e "tar succeeds on HSM released files" # LU-6213
2226 # test needs a running copytool
2229 mkdir -p $DIR/$tdir/d1
2230 local f=$DIR/$tdir/$tfile
2231 local fid=$(copy_file /etc/hosts $f)
2234 $LFS hsm_archive $f ||
2235 error "hsm_archive failed"
2236 wait_request_state $fid ARCHIVE SUCCEED
2237 $LFS hsm_release $f || error "cannot release $f"
2238 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2241 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2242 error "Can not recover the tar contents"
2244 echo "Sum0 = $sum0, sum1 = $sum1"
2245 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2247 run_test 24f "root can archive, release, and restore tar files"
2250 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2251 skip "need MDS version 2.11.56 or later"
2253 local file=$DIR/$tdir/$tfile
2256 echo "RUNAS = '$RUNAS'"
2261 chmod ugo+rwx $DIR/$tdir
2263 echo "Please listen carefully as our options have changed." | tee $file
2264 fid=$(path2fid $file)
2267 $LFS hsm_archive $file
2268 wait_request_state $fid ARCHIVE SUCCEED
2269 check_hsm_flags $file 0x00000009 # exists archived
2271 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2272 check_hsm_flags $file 0x0000000b # exists dirty archived
2274 run_test 24g "write by non-owner still sets dirty" # LU-11369
2277 # test needs a running copytool
2281 copy2archive /etc/hosts $tdir/$tfile
2283 local f=$DIR/$tdir/$tfile
2285 copytool import $tdir/$tfile $f
2287 $LFS hsm_set --lost $f
2292 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2294 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2295 " (Operation not permitted)"
2298 # test needs a running copytool
2303 local f=$DIR/$tdir/$tfile
2304 local fid=$(copy_file /etc/passwd $f)
2306 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2307 wait_request_state $fid ARCHIVE SUCCEED
2310 $LFS hsm_set --lost $f
2314 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2316 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2317 " (Operation not permitted)"
2319 test_26A() { # was test_26
2320 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2324 local fid=$(create_empty_file "$f")
2326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2327 wait_request_state $fid ARCHIVE SUCCEED
2330 wait_request_state $fid REMOVE SUCCEED
2332 check_hsm_flags $f "0x00000000"
2334 run_test 26A "Remove the archive of a valid file"
2337 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2338 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2340 # test needs a running copytool
2344 local f=$DIR/$tdir/$tfile
2345 local fid=$(copy_file /etc/passwd $f)
2347 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2348 wait_request_state $fid ARCHIVE SUCCEED
2350 local f2=$DIR/$tdir/${tfile}_2
2351 local fid2=$(copy_file /etc/passwd $f2)
2353 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2354 wait_request_state $fid2 ARCHIVE SUCCEED
2356 local f3=$DIR/$tdir/${tfile}_3
2357 local fid3=$(copy_file /etc/passwd $f3)
2359 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2360 wait_request_state $fid3 ARCHIVE SUCCEED
2362 # set a long grace_delay vs short loop_period
2363 local orig_loop_period=$(get_hsm_param loop_period)
2364 local orig_grace_delay=$(get_hsm_param grace_delay)
2365 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2366 set_hsm_param loop_period 10
2367 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2368 set_hsm_param grace_delay 100
2372 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2373 set_hsm_param remove_archive_on_last_unlink 1
2375 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2380 wait_request_state $fid2 REMOVE SUCCEED
2382 assert_request_count $fid REMOVE 0 \
2383 "Unexpected archived data remove request for $f"
2384 assert_request_count $fid3 REMOVE 0 \
2385 "Unexpected archived data remove request for $f3"
2387 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2390 # test needs a running copytool
2394 local f=$DIR/$tdir/$tfile
2395 local fid=$(copy_file /etc/passwd $f)
2397 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2398 wait_request_state $fid ARCHIVE SUCCEED
2400 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2401 set_hsm_param remove_archive_on_last_unlink 1
2404 cdt_check_state stopped
2408 wait_request_state $fid REMOVE WAITING
2412 # copytool must re-register
2414 wait_copytools || error "copytool failed to stop"
2417 wait_request_state $fid REMOVE SUCCEED
2419 run_test 26b "RAoLU policy when CDT off"
2422 # test needs a running copytool
2426 local f=$DIR/$tdir/$tfile
2427 local fid=$(copy_file /etc/passwd $f)
2429 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2430 wait_request_state $fid ARCHIVE SUCCEED
2432 local f2=$DIR/$tdir/${tfile}_2
2433 local fid2=$(copy_file /etc/passwd $f2)
2435 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2436 wait_request_state $fid2 ARCHIVE SUCCEED
2438 # set a long grace_delay vs short loop_period
2439 local orig_loop_period=$(get_hsm_param loop_period)
2440 local orig_grace_delay=$(get_hsm_param grace_delay)
2441 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2442 set_hsm_param loop_period 10
2443 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2444 set_hsm_param grace_delay 100
2446 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2447 set_hsm_param remove_archive_on_last_unlink 1
2449 multiop_bg_pause $f O_c || error "open $f failed"
2455 wait_request_state $fid2 REMOVE SUCCEED
2456 assert_request_count $fid REMOVE 0 \
2457 "Unexpected archived data remove request for $f"
2459 kill -USR1 $pid || error "multiop early exit"
2460 # should reach autotest timeout if multiop fails to trap
2461 # signal, close file, and exit ...
2462 wait $pid || error "wait PID $PID failed"
2464 wait_request_state $fid REMOVE SUCCEED
2466 run_test 26c "RAoLU effective when file closed"
2469 # test needs a running copytool
2473 local f=$DIR/$tdir/$tfile
2474 local fid=$(create_small_file $f)
2476 $LFS hsm_archive $f || error "could not archive file"
2477 wait_request_state $fid ARCHIVE SUCCEED
2479 # set a long grace_delay vs short loop_period
2480 local orig_loop_period=$(get_hsm_param loop_period)
2481 local orig_grace_delay=$(get_hsm_param grace_delay)
2482 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2483 set_hsm_param loop_period 10
2484 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2485 set_hsm_param grace_delay 100
2487 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2488 set_hsm_param remove_archive_on_last_unlink 1
2490 multiop_bg_pause $f O_c || error "multiop failed"
2497 wait_request_state $fid REMOVE SUCCEED
2499 client_up || client_up || true
2501 kill -USR1 $MULTIPID
2502 wait $MULTIPID || error "multiop close failed"
2504 run_test 26d "RAoLU when Client eviction"
2507 # test needs a running copytool
2510 create_archive_file $tdir/$tfile
2511 local f=$DIR/$tdir/$tfile
2512 copytool import $tdir/$tfile $f
2513 local fid=$(path2fid $f)
2517 [[ $? != 0 ]] || error "Remove of a released file should fail"
2519 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2522 # test needs a running copytool
2525 local f=$DIR/$tdir/$tfile
2526 local fid=$(create_empty_file "$f")
2528 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2529 wait_request_state $fid ARCHIVE SUCCEED
2534 [[ $? != 0 ]] || error "Remove of a released file should fail"
2536 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2539 # test needs a running copytool
2542 local f=$DIR/$tdir/$tfile
2543 local fid=$(create_empty_file "$f")
2545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2546 wait_request_state $fid ARCHIVE SUCCEED
2555 wait_request_state $fid REMOVE SUCCEED
2557 run_test 28 "Concurrent archive/file remove"
2560 # Tests --mntpath and --archive options
2563 copytool setup -m "$MOUNT" -a $archive_id
2565 # Bad archive number
2566 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2567 grep "Invalid argument" ||
2568 error "unexpected hsm_remove failure (1)"
2570 # mntpath is present but file is given
2571 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2572 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2573 error "unexpected hsm_remove failure (2)"
2575 run_test 29a "Tests --mntpath and --archive options"
2578 # test needs a running copytool
2581 local f=$DIR/$tdir/$tfile
2582 local fid=$(create_small_file $f)
2584 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2585 wait_request_state $fid ARCHIVE SUCCEED
2589 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2590 wait_request_state $fid REMOVE SUCCEED
2592 run_test 29b "Archive/delete/remove by FID from the archive."
2595 # test needs a running copytool
2598 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2599 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2600 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2602 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2603 wait_request_state $fid1 ARCHIVE SUCCEED
2604 wait_request_state $fid2 ARCHIVE SUCCEED
2605 wait_request_state $fid3 ARCHIVE SUCCEED
2607 rm -f $DIR/$tdir/$tfile-[1-3]
2609 echo $fid1 > $DIR/$tdir/list
2610 echo $fid2 >> $DIR/$tdir/list
2611 echo $fid3 >> $DIR/$tdir/list
2613 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2614 --filelist $DIR/$tdir/list
2615 wait_request_state $fid1 REMOVE SUCCEED
2616 wait_request_state $fid2 REMOVE SUCCEED
2617 wait_request_state $fid3 REMOVE SUCCEED
2619 run_test 29c "Archive/delete/remove by FID, using a file list."
2622 # test needs more than one CT
2623 needclients 3 || return 0
2629 # start all of the copytools
2630 for n in $(seq $AGTCOUNT); do
2631 copytool setup -f agt$n -a $n
2635 file=$DIR/$tdir/$tfile
2636 fid=$(create_small_file $file)
2638 $LFS hsm_archive $file
2639 wait_request_state $fid ARCHIVE SUCCEED
2640 check_hsm_flags $file "0x00000009"
2644 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2645 error "cannot hsm_remove '$fid'"
2647 # give time for CDT to handle remove request and create broadcasted
2650 # remove request has been broadcasted ?
2651 local cnt=$(get_request_count $fid REMOVE)
2652 # broadcasted requests + original
2653 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2654 error "remove not broadcasted to all CTs"
2656 # give time for CDT and CTs to handle broadcasted
2657 wait_for_loop_period
2659 # each agent serves one different archive_id, so broadcasted
2660 # hsm_remove request should only succeed once and fail at all others
2664 for n in $(seq $AGTCOUNT); do
2665 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2666 $HSM_PARAM.actions | awk \
2667 '/'$fid'.*action=REMOVE archive#='$n'/ \
2668 {print \\\$13}' | cut -f2 -d=")
2669 if [[ "$res" == "SUCCEED" ]]; then
2671 elif [[ "$res" == "FAILED" ]]; then
2676 [[ $scnt -eq 1 ]] ||
2677 error "one and only CT should have removed successfully"
2679 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2680 error "all but one CT should have failed to remove"
2682 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2683 "request to be sent once for each registered archive_id"
2686 # restore at exec cannot work on agent node (because of Linux kernel
2687 # protection of executables)
2688 needclients 2 || return 0
2690 # test needs a running copytool
2694 copy2archive /bin/true $tdir/$tfile
2696 local f=$DIR/$tdir/true
2697 copytool import $tdir/$tfile $f
2699 local fid=$(path2fid $f)
2701 stack_trap "cdt_clear_no_retry" EXIT
2702 # set no retry action mode
2709 [[ $st == 0 ]] || error "Failed to exec a released file"
2711 run_test 30a "Restore at exec (import case)"
2714 # restore at exec cannot work on agent node (because of Linux kernel
2715 # protection of executables)
2716 needclients 2 || return 0
2718 # test needs a running copytool
2722 local f=$DIR/$tdir/true
2723 local fid=$(copy_file /bin/true $f)
2725 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2726 wait_request_state $fid ARCHIVE SUCCEED
2730 stack_trap cdt_clear_no_retry EXIT
2731 # set no retry action mode
2739 [[ $st == 0 ]] || error "Failed to exec a released file"
2741 run_test 30b "Restore at exec (release case)"
2744 needclients 2 || return 0
2746 # test needs a running copytool
2750 local f=$DIR/$tdir/SLEEP
2751 local slp_sum1=$(md5sum /bin/sleep)
2752 local fid=$(copy_file /bin/sleep $f)
2754 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2755 wait_request_state $fid ARCHIVE SUCCEED
2757 check_hsm_flags $f "0x0000000d"
2759 stack_trap cdt_clear_no_retry EXIT
2760 # set no retry action mode
2763 do_node $CLIENT2 "$f 10" &
2767 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2769 [[ $? == 0 ]] || error "Execution failed during run"
2771 if [[ $? != 0 ]]; then
2772 local slp_sum2=$(md5sum /bin/sleep)
2773 # in case sleep file is modified during the test
2774 [[ $slp_sum1 == $slp_sum2 ]] &&
2775 error "Binary overwritten during exec"
2778 check_hsm_flags $f "0x00000009"
2780 run_test 30c "Update during exec of released file must fail"
2782 restore_and_check_size() {
2785 local s=$(stat -c "%s" $f)
2787 local st=$(get_hsm_flags $f)
2791 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2793 n=$(stat -c "%s" $f)
2794 # we echo in both cases to show stat is not hang
2795 if [[ $n != $s ]]; then
2796 echo "size seen is $n != $s"
2799 echo "size seen is right: $n == $s"
2803 st=$(get_hsm_flags $f)
2805 if [[ "$st" = "0x00000009" ]]; then
2808 echo " restore is too long"
2809 wait_request_state $fid RESTORE SUCCEED
2815 # test needs a running copytool
2818 create_archive_file $tdir/$tfile
2819 local f=$DIR/$tdir/$tfile
2820 copytool import $tdir/$tfile $f
2821 local fid=$($LFS path2fid $f)
2824 restore_and_check_size $f $fid
2827 [[ $err -eq 0 ]] || error "File size changed during restore"
2829 run_test 31a "Import a large file and check size during restore"
2833 # test needs a running copytool
2836 local f=$DIR/$tdir/$tfile
2837 local fid=$(create_file "$f" 1MB 39)
2839 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2840 wait_request_state $fid ARCHIVE SUCCEED
2843 restore_and_check_size $f $fid
2846 [[ $err -eq 0 ]] || error "File size changed during restore"
2848 run_test 31b "Restore a large unaligned file and check size during restore"
2851 # test needs a running copytool
2854 local f=$DIR/$tdir/$tfile
2855 local fid=$(create_file "$f" 1M 39)
2857 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2858 wait_request_state $fid ARCHIVE SUCCEED
2861 restore_and_check_size $f $fid
2864 [[ $err -eq 0 ]] || error "File size changed during restore"
2866 run_test 31c "Restore a large aligned file and check size during restore"
2869 local f=$DIR/$tdir/$tfile
2870 local fid=$(create_empty_file "$f")
2874 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2875 wait_request_state $fid ARCHIVE SUCCEED
2878 # Prevent restore from completing
2882 md5sum $f >/dev/null &
2885 wait_request_state $fid RESTORE STARTED
2890 # Check restore trigger process was killed
2892 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2894 run_test 33 "Kill a restore waiting process"
2897 # test needs a running copytool
2900 local f=$DIR/$tdir/$tfile
2901 local fid=$(create_empty_file "$f")
2903 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2904 wait_request_state $fid ARCHIVE SUCCEED
2907 # Prevent restore from completing
2910 md5sum $f >/dev/null &
2913 wait_request_state $fid RESTORE STARTED
2915 # rm must not block during restore
2916 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2919 wait_request_state $fid RESTORE SUCCEED
2921 # Check md5sum pgm finished
2922 kill -0 $pid && error "Restore initiatior still running"
2923 wait $pid || error "Restore initiator failed with $?"
2925 # Check the file was actually deleted
2926 [ ! -f "$f" ] || error "$f was not deleted"
2928 run_test 34 "Remove file during restore"
2931 # test needs a running copytool
2934 local f=$DIR/$tdir/$tfile
2935 local f1=$DIR/$tdir/$tfile-1
2936 local fid=$(create_empty_file "$f")
2937 local fid1=$(copy_file /etc/passwd $f1)
2939 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2940 wait_request_state $fid ARCHIVE SUCCEED
2943 # Prevent restore from completing
2946 md5sum $f >/dev/null &
2949 wait_request_state $fid RESTORE STARTED
2951 # mv must not block during restore
2952 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2955 wait_request_state $fid RESTORE SUCCEED
2957 # Check md5sum pgm finished
2958 kill -0 $pid && error "Restore initiatior still running"
2959 wait $pid || error "Restore initiator failed with $?"
2961 local fid2=$(path2fid $f)
2962 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2964 run_test 35 "Overwrite file during restore"
2967 # test needs a running copytool
2970 local f=$DIR/$tdir/$tfile
2971 local fid=$(create_empty_file "$f")
2973 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2974 wait_request_state $fid ARCHIVE SUCCEED
2977 # Prevent restore from completing
2980 md5sum $f >/dev/null &
2983 wait_request_state $fid RESTORE STARTED
2985 # mv must not block during restore
2986 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2987 error "mv '$f' '$f.new' failed with rc=$?"
2990 wait_request_state $fid RESTORE SUCCEED
2992 # Check md5sum pgm finished
2993 kill -0 $pid && error "Restore initiator is still running"
2994 wait $pid || error "Restore initiator failed with $?"
2996 run_test 36 "Move file during restore"
2999 # LU-5683: check that an archived dirty file can be rearchived.
3002 local f=$DIR/$tdir/$tfile
3005 fid=$(create_small_file $f) || error "cannot create small file"
3007 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3008 wait_request_state $fid ARCHIVE SUCCEED
3009 $LFS hsm_release $f || error "cannot release $f"
3011 # Allow previous archive request to expire from the actions log.
3012 wait_for_grace_delay
3015 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3017 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3018 wait_request_state $fid ARCHIVE SUCCEED
3020 run_test 37 "re-archive a dirty file"
3027 for n in $(seq 1 $count); do
3028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3030 echo "$count archive requests submitted"
3034 local stream_count=4
3035 local file_count=100
3037 local f=$DIR/$tdir/$tfile
3041 local max_requests=$(get_hsm_param max_requests)
3043 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3044 # Increase the number of HSM request that can be performed in
3045 # parallel. With the coordinator running once per second, this
3046 # also limits the number of requests per seconds that can be
3047 # performed, so we pick a decent number. But we also need to keep
3048 # that number low because the copytool has no rate limit and will
3049 # fail some requests if if gets too many at once.
3050 set_hsm_param max_requests 300
3052 for i in $(seq 1 $file_count); do
3053 for p in $(seq 1 $stream_count); do
3054 fid=$(copy_file /etc/hosts $f.$p.$i)
3060 # to be sure wait_all_done will not be mislead by previous tests
3062 wait_for_grace_delay
3064 # start archive streams in background (archive files in parallel)
3065 for p in $(seq 1 $stream_count); do
3066 multi_archive $f.$p $file_count &
3069 echo -n "Wait for all requests being enqueued..."
3074 run_test 40 "Parallel archive requests"
3077 # test needs a running copytool
3081 local f=$DIR/$tdir/$tfile
3082 local fid=$(create_small_file $f)
3084 $LFS hsm_archive $f || error "could not archive file"
3085 wait_request_state $fid ARCHIVE SUCCEED
3086 check_hsm_flags $f "0x00000009"
3088 multiop_bg_pause $f O_c || error "multiop failed"
3092 client_up || client_up || true
3094 kill -USR1 $MULTIPID
3095 wait $MULTIPID || error "multiop close failed"
3097 check_hsm_flags $f "0x0000000b"
3099 run_test 52 "Opened for write file on an evicted client should be set dirty"
3102 # test needs a running copytool
3106 local f=$DIR/$tdir/$tfile
3107 local fid=$(create_small_file $f)
3109 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3110 error "could not archive file"
3111 wait_request_state $fid ARCHIVE SUCCEED
3112 check_hsm_flags $f "0x00000009"
3114 multiop_bg_pause $f o_c || error "multiop failed"
3118 client_up || client_up || true
3120 kill -USR1 $MULTIPID
3121 wait $MULTIPID || error "multiop close failed"
3123 check_hsm_flags $f "0x00000009"
3125 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3128 local f=$DIR/$tdir/$tfile
3129 local fid=$(create_file "$f" 1MB 39)
3133 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3134 error "could not archive file"
3135 wait_request_state $fid ARCHIVE STARTED
3137 check_hsm_flags $f "0x00000001"
3139 stack_trap "cdt_clear_no_retry" EXIT
3140 # Avoid coordinator resending this request as soon it has failed.
3145 wait_request_state $fid ARCHIVE FAILED
3147 check_hsm_flags $f "0x00000003"
3149 run_test 54 "Write during an archive cancels it"
3152 local f=$DIR/$tdir/$tfile
3153 local fid=$(create_file "$f" 1MB 39)
3157 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3158 error "could not archive file"
3159 wait_request_state $fid ARCHIVE STARTED
3161 check_hsm_flags $f "0x00000001"
3163 stack_trap "cdt_clear_no_retry" EXIT
3164 # Avoid coordinator resending this request as soon it has failed.
3167 $TRUNCATE $f 1024 || error "truncate failed"
3169 wait_request_state $fid ARCHIVE FAILED
3171 check_hsm_flags $f "0x00000003"
3173 run_test 55 "Truncate during an archive cancels it"
3176 local f=$DIR/$tdir/$tfile
3177 local fid=$(create_file "$f" 1MB 39)
3181 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3182 error "could not archive file"
3183 wait_request_state $fid ARCHIVE STARTED
3185 check_hsm_flags $f "0x00000001"
3187 # Change metadata and sync to be sure we are not changing only
3192 wait_request_state $fid ARCHIVE SUCCEED
3194 check_hsm_flags $f "0x00000009"
3196 run_test 56 "Setattr during an archive is ok"
3199 # Need one client for I/O, one for request
3200 needclients 2 || return 0
3202 # test needs a running copytool
3206 local f=$DIR/$tdir/test_archive_remote
3207 # Create a file on a remote node
3208 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3209 "count=2 conv=fsync"
3212 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3213 error "hsm_archive failed"
3214 local fid=$(path2fid $f)
3215 wait_request_state $fid ARCHIVE SUCCEED
3217 # Release and implicit restore it
3218 do_node $CLIENT2 "$LFS hsm_release $f" ||
3219 error "hsm_release failed"
3220 do_node $CLIENT2 "md5sum $f" ||
3221 error "hsm_restore failed"
3223 wait_request_state $fid RESTORE SUCCEED
3225 run_test 57 "Archive a file with dirty cache on another node"
3227 truncate_released_file() {
3231 local sz=$(stat -c %s $src_file)
3232 local f=$DIR/$tdir/$tfile
3233 local fid=$(copy_file $1 $f)
3237 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3238 error "could not archive file"
3239 wait_request_state $fid ARCHIVE SUCCEED
3241 $LFS hsm_release $f || error "could not release file"
3243 $TRUNCATE $f $trunc_to || error "truncate failed"
3246 local sz1=$(stat -c %s $f)
3247 [[ $sz1 == $trunc_to ]] ||
3248 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3251 check_hsm_flags $f "0x0000000b"
3253 local state=$(get_request_state $fid RESTORE)
3254 [[ "$state" == "SUCCEED" ]] ||
3255 error "truncate $sz does not trig restore, state = $state"
3257 $TRUNCATE $ref $trunc_to
3258 cmp $ref $f || error "file data wrong after truncate"
3264 # test needs a running copytool
3269 local sz=$(stat -c %s /etc/passwd)
3271 echo "truncate up from $sz to $((sz*2))"
3272 truncate_released_file /etc/passwd $((sz*2))
3274 echo "truncate down from $sz to $((sz/2))"
3275 truncate_released_file /etc/passwd $((sz/2))
3277 echo "truncate to 0"
3278 truncate_released_file /etc/passwd 0
3280 run_test 58 "Truncate a released file will trigger restore"
3284 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3285 skip "Need MDS version at least 2.7.63"
3288 $MCREATE $DIR/$tfile || error "mcreate failed"
3289 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3290 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3291 fid=$(path2fid $DIR/$tfile)
3292 wait_request_state $fid ARCHIVE SUCCEED
3293 $LFS hsm_release $DIR/$tfile || error "release failed"
3295 run_test 59 "Release stripeless file with non-zero size"
3298 # This test validates the fix for LU-4512. Ensure that the -u
3299 # option changes the progress reporting interval from the
3300 # default (30 seconds) to the user-specified interval.
3301 local f=$DIR/$tdir/$tfile
3302 local fid=$(create_file "$f" 1M 10)
3305 local progress_timeout=$((interval * 4))
3306 copytool setup -b 1 --update-interval $interval
3309 local mdt=${MDT_PREFIX}${mdtidx}
3310 local mds=mds$((mdtidx + 1))
3312 # Wait for copytool to register
3313 wait_update_facet $mds \
3314 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3315 uuid 100 || error "coyptool failed to register with $mdt"
3317 local start_at=$(date +%s)
3318 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3319 error "could not archive file"
3321 local agent=$(facet_active_host $SINGLEAGT)
3322 local logfile=$(copytool_logfile $SINGLEAGT)
3324 wait_update $agent \
3325 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3326 error "copytool failed to start"
3328 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3329 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3335 echo -n "Expecting a progress update within $progress_timeout seconds... "
3337 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3338 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3339 echo "$RESULT bytes copied in $WAIT seconds."
3341 elif [ $WAIT -ge $progress_timeout ]; then
3342 error "Timed out waiting for progress update!"
3345 WAIT=$((WAIT + sleep))
3349 local finish_at=$(date +%s)
3350 local elapsed=$((finish_at - start_at))
3352 # Ensure that the progress update occurred within the expected window.
3353 if [ $elapsed -lt $((interval - 1)) ]; then
3354 error "Expected progress update after at least $interval seconds"
3357 echo "Wait for on going archive hsm action to complete"
3358 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3359 echo "File archiving not completed even after 10 secs"
3361 run_test 60 "Changing progress update interval from default"
3364 # test needs a running copytool
3368 local f=$DIR/$tdir/$tfile
3369 local fid=$(copy_file /etc/passwd $f)
3371 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3374 wait_request_state $fid ARCHIVE FAILED
3376 run_test 61 "Waiting archive of a removed file should fail"
3379 # test needs a new running copytool
3380 stack_trap copytool_monitor_cleanup EXIT
3381 copytool_monitor_setup
3382 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3384 # Wait for the copytool to register.
3385 wait_update --verbose $(facet_active_host mds1) \
3386 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3388 error "copytool failed to register with MDT0000"
3391 wait_copytools || error "Copytools failed to stop"
3393 local REGISTER_EVENT
3394 local UNREGISTER_EVENT
3395 while read event; do
3396 local parsed=$(parse_json_event "$event")
3397 if [ -z "$parsed" ]; then
3398 error "Copytool sent malformed event: $event"
3402 if [ $event_type == "REGISTER" ]; then
3403 REGISTER_EVENT=$event
3404 elif [ $event_type == "UNREGISTER" ]; then
3405 UNREGISTER_EVENT=$event
3407 done < <(echo $"$(get_copytool_event_log)")
3409 if [ -z "$REGISTER_EVENT" ]; then
3410 error "Copytool failed to send register event to FIFO"
3413 if [ -z "$UNREGISTER_EVENT" ]; then
3414 error "Copytool failed to send unregister event to FIFO"
3417 echo "Register/Unregister events look OK."
3419 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3422 # Bump progress interval for livelier events.
3425 # test needs a new running copytool
3426 stack_trap copytool_monitor_cleanup EXIT
3427 copytool_monitor_setup
3428 copytool setup --update-interval $interval --event-fifo \
3429 "$HSMTOOL_MONITOR_DIR/fifo"
3431 stack_trap "cdt_clear_no_retry" EXIT
3432 # Just start and stop the copytool to generate events.
3435 local f=$DIR/$tdir/$tfile
3436 local fid=$(create_small_file "$f")
3438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3439 error "could not archive file"
3440 wait_request_state $fid ARCHIVE SUCCEED
3442 local expected_fields="event_time data_fid source_fid"
3443 expected_fields+=" total_bytes current_bytes"
3446 [ARCHIVE_START]=false
3447 [ARCHIVE_FINISH]=false
3448 [ARCHIVE_RUNNING]=false
3450 while read event; do
3451 # Make sure we're not getting anything from previous events.
3452 for field in $expected_fields; do
3456 local parsed=$(parse_json_event "$event")
3457 if [ -z "$parsed" ]; then
3458 error "Copytool sent malformed event: $event"
3462 events["$event_type"]=true
3464 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3466 # Do some simple checking of the progress update events.
3467 for expected_field in $expected_fields; do
3468 if [ -z ${!expected_field+x} ]; then
3469 error "Missing $expected_field field in event"
3473 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3475 # These should be identical throughout an archive operation
3476 [ $source_fid == $data_fid ] ||
3477 error "Expected source_fid to equal data_fid"
3478 done < <(echo $"$(get_copytool_event_log)")
3480 # Check we received every type of events we were expecting
3481 for event in "${!events[@]}"; do
3482 ${events["$event"]} ||
3483 error "Copytool failed to send '$event' event to FIFO"
3486 echo "Archive events look OK."
3488 run_test 71 "Copytool logs JSON archive events to FIFO"
3491 # Bump progress interval for livelier events.
3494 # test needs a new running copytool
3495 stack_trap copytool_monitor_cleanup EXIT
3496 copytool_monitor_setup
3497 copytool setup --update-interval $interval --event-fifo \
3498 "$HSMTOOL_MONITOR_DIR/fifo"
3499 local test_file=$HSMTOOL_MONITOR_DIR/file
3501 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3503 do_facet $SINGLEAGT "$cmd" ||
3504 error "cannot create $test_file on $SINGLEAGT"
3505 copy2archive $test_file $tdir/$tfile
3508 local f=$DIR/$tdir/$tfile
3509 copytool import $tdir/$tfile $f
3510 f=$DIR2/$tdir/$tfile
3511 echo "Verifying released state: "
3512 check_hsm_flags $f "0x0000000d"
3514 local fid=$(path2fid $f)
3516 wait_request_state $fid RESTORE SUCCEED
3518 local expected_fields="event_time data_fid source_fid"
3519 expected_fields+=" total_bytes current_bytes"
3523 while read event; do
3524 # Make sure we're not getting anything from previous events.
3525 for field in $expected_fields; do
3529 local parsed=$(parse_json_event "$event")
3530 if [ -z "$parsed" ]; then
3531 error "Copytool sent malformed event: $event"
3535 if [ $event_type == "RESTORE_START" ]; then
3537 if [ $source_fid != $data_fid ]; then
3538 error "source_fid should == data_fid at start"
3541 elif [ $event_type == "RESTORE_FINISH" ]; then
3543 if [ $source_fid != $data_fid ]; then
3544 error "source_fid should == data_fid at finish"
3547 elif [ $event_type != "RESTORE_RUNNING" ]; then
3551 # Do some simple checking of the progress update events.
3552 for expected_field in $expected_fields; do
3553 if [ -z ${!expected_field+x} ]; then
3554 error "Missing $expected_field field in event"
3558 if [ $total_bytes -eq 0 ]; then
3559 error "Expected total_bytes to be > 0"
3562 # When a restore starts out, the data fid is the same as the
3563 # source fid. After the restore has gotten going, we learn
3564 # the new data fid. Once the restore has finished, the source
3565 # fid is set to the new data fid.
3567 # We test this because some monitoring software may depend on
3568 # this behavior. If it changes, then the consumers of these
3569 # events may need to be modified.
3570 if [ $source_fid == $data_fid ]; then
3571 error "source_fid should != data_fid during restore"
3573 done < <(echo $"$(get_copytool_event_log)")
3575 if [ -z "$START_EVENT" ]; then
3576 error "Copytool failed to send restore start event to FIFO"
3579 if [ -z "$FINISH_EVENT" ]; then
3580 error "Copytool failed to send restore finish event to FIFO"
3583 echo "Restore events look OK."
3585 run_test 72 "Copytool logs JSON restore events to FIFO"
3588 file_count=51 # Max number of files constrained by LNET message size
3589 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3590 local f=$DIR/$tdir/$tfile
3591 local FILELIST=/tmp/filelist.txt
3595 for i in $(seq 1 $file_count); do
3596 fid=$(copy_file /etc/hosts $f.$i)
3597 echo $f.$i >> $FILELIST
3601 # to be sure wait_all_done will not be mislead by previous tests
3603 wait_for_grace_delay
3604 $LFS hsm_archive --filelist $FILELIST ||
3605 error "cannot archive a file list"
3607 $LFS hsm_release --filelist $FILELIST ||
3608 error "cannot release a file list"
3609 $LFS hsm_restore --filelist $FILELIST ||
3610 error "cannot restore a file list"
3613 run_test 90 "Archive/restore a file list"
3615 double_verify_reset_hsm_param() {
3617 echo "Testing $HSM_PARAM.$p"
3618 local val=$(get_hsm_param $p)
3620 local val2=$(($val * 2))
3621 set_hsm_param $p $val2
3622 val=$(get_hsm_param $p)
3623 [[ $val == $val2 ]] ||
3624 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3625 echo "Set $p to 0 must failed"
3629 set_hsm_param $p $save
3631 if [[ $rc == 0 ]]; then
3632 error "we must not be able to set $HSM_PARAM.$p to 0"
3637 double_verify_reset_hsm_param loop_period
3638 double_verify_reset_hsm_param grace_delay
3639 double_verify_reset_hsm_param active_request_timeout
3640 double_verify_reset_hsm_param max_requests
3641 double_verify_reset_hsm_param default_archive_id
3643 run_test 100 "Set coordinator /proc tunables"
3650 run_test 102 "Verify coordinator control"
3653 # test needs a running copytool
3660 for i in $(seq 1 20); do
3661 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3663 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3667 echo "Current requests"
3668 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3669 $HSM_PARAM.actions |\
3670 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3672 [[ -z "$res" ]] || error "Some request have not been canceled"
3674 run_test 103 "Purge all requests"
3679 local f=$DIR/$tdir/$tfile
3680 local fid=$(create_empty_file "$f")
3682 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3683 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3684 $HSM_PARAM.actions |\
3685 grep $fid | cut -f16 -d=")
3687 [[ "$data1" == "$DATAHEX" ]] ||
3688 error "Data field in records is ($data1) and not ($DATAHEX)"
3692 run_test 104 "Copy tool data field"
3695 local max_requests=$(get_hsm_param max_requests)
3699 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3700 set_hsm_param max_requests 300
3703 for i in $(seq -w 1 10); do
3704 cp /etc/passwd $DIR/$tdir/$i
3705 $LFS hsm_archive $DIR/$tdir/$i
3707 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3708 $HSM_PARAM.actions |\
3709 grep WAITING | wc -l")
3713 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3714 $HSM_PARAM.actions |\
3715 grep WAITING | wc -l")
3718 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3719 error "Requests count after shutdown $reqcnt2 != "\
3720 "before shutdown $reqcnt1"
3722 run_test 105 "Restart of coordinator"
3725 # test needs a running copytool
3728 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3730 check_agent_registered $uuid
3732 search_copytools || error "No copytool found"
3735 wait_copytools || error "Copytool failed to stop"
3737 check_agent_unregistered $uuid
3740 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3741 check_agent_registered $uuid
3743 run_test 106 "Copytool register/unregister"
3746 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3748 # test needs a running copytool
3750 # create and archive file
3752 local f1=$DIR/$tdir/$tfile
3753 local fid=$(copy_file /etc/passwd $f1)
3754 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3755 wait_request_state $fid ARCHIVE SUCCEED
3756 # shutdown and restart MDS
3758 # check the copytool still gets messages from MDT
3759 local f2=$DIR/$tdir/2
3760 local fid=$(copy_file /etc/passwd $f2)
3761 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3762 # main check of this sanity: this request MUST succeed
3763 wait_request_state $fid ARCHIVE SUCCEED
3765 run_test 107 "Copytool re-register after MDS restart"
3767 policy_set_and_test()
3771 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3772 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3773 [[ "$policy" == "$target" ]] ||
3774 error "Wrong policy after '$change': '$policy' != '$target'"
3778 # to force default policy setting if error
3779 CDT_POLICY_HAD_CHANGED=true
3781 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3782 local default="NonBlockingRestore [NoRetryAction]"
3783 [[ "$policy" == "$default" ]] ||
3784 error "default policy has changed,"\
3785 " '$policy' != '$default' update the test"
3786 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3787 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3788 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3789 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3790 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3791 # useless bacause we know but safer for futur changes to use real value
3792 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3793 echo "Next set_param must failed"
3794 policy_set_and_test "wrong" "$policy"
3797 echo "Back to default policy"
3798 cdt_set_sanity_policy
3800 run_test 109 "Policy display/change"
3803 # test needs a running copytool
3808 copy2archive /etc/passwd $tdir/$tfile
3810 local f=$DIR/$tdir/$tfile
3811 copytool import $tdir/$tfile $f
3812 local fid=$(path2fid $f)
3814 cdt_set_non_blocking_restore
3819 wait_request_state $fid RESTORE SUCCEED
3820 cdt_clear_non_blocking_restore
3824 error "md5sum returns $st != 1, "\
3825 "should also perror ENODATA (No data available)"
3827 run_test 110a "Non blocking restore policy (import case)"
3830 # test needs a running copytool
3834 local f=$DIR/$tdir/$tfile
3835 local fid=$(copy_file /etc/passwd $f)
3836 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3837 wait_request_state $fid ARCHIVE SUCCEED
3840 cdt_set_non_blocking_restore
3845 wait_request_state $fid RESTORE SUCCEED
3846 cdt_clear_non_blocking_restore
3850 error "md5sum returns $st != 1, "\
3851 "should also perror ENODATA (No data available)"
3853 run_test 110b "Non blocking restore policy (release case)"
3856 # test needs a running copytool
3860 copy2archive /etc/passwd $tdir/$tfile
3862 local f=$DIR/$tdir/$tfile
3864 copytool import $tdir/$tfile $f
3865 local fid=$(path2fid $f)
3869 copytool_remove_backend $fid
3872 wait_request_state $fid RESTORE FAILED
3879 [[ $st == 0 ]] || error "Restore does not failed"
3881 run_test 111a "No retry policy (import case), restore will error"\
3882 " (No such file or directory)"
3885 # test needs a running copytool
3889 local f=$DIR/$tdir/$tfile
3890 local fid=$(copy_file /etc/passwd $f)
3891 stack_trap cdt_clear_no_retry EXIT
3893 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3894 wait_request_state $fid ARCHIVE SUCCEED
3897 copytool_remove_backend $fid
3900 wait_request_state $fid RESTORE FAILED
3904 [[ $st == 0 ]] || error "Restore does not failed"
3906 run_test 111b "No retry policy (release case), restore will error"\
3907 " (No such file or directory)"
3910 # test needs a running copytool
3914 local f=$DIR/$tdir/$tfile
3915 local fid=$(copy_file /etc/passwd $f)
3917 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3918 local l=$($LFS hsm_action $f)
3920 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3923 wait_request_state $fid ARCHIVE SUCCEED
3926 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3928 run_test 112 "State of recorded request"
3931 local f=$DIR/$tdir/$tfile
3932 local fid=$(create_empty_file "$f")
3936 # Prevent archive from completing
3939 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3940 # wait archive to register at CDT
3941 wait_request_state $fid ARCHIVE STARTED
3943 # Cancel the archive
3944 $LFS hsm_cancel "$f"
3946 wait_request_state $fid ARCHIVE CANCELED
3949 wait_request_state $fid CANCEL SUCCEED
3951 run_test 200 "Register/Cancel archive"
3954 # test needs a running copytool
3957 local f=$DIR/$tdir/$tfile
3958 create_archive_file $tdir/$tfile
3959 copytool import $tdir/$tfile $f
3960 local fid=$(path2fid $f)
3962 # test with cdt on is made in test_222
3965 # wait restore to register at CDT
3966 wait_request_state $fid RESTORE WAITING
3969 wait_request_state $fid RESTORE CANCELED
3970 wait_request_state $fid CANCEL SUCCEED
3972 run_test 201 "Register/Cancel restore"
3975 local f=$DIR/$tdir/$tfile
3976 local fid=$(create_empty_file "$f")
3978 # test needs a running copytool
3981 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3982 wait_request_state $fid ARCHIVE SUCCEED
3986 # wait remove to register at CDT
3987 wait_request_state $fid REMOVE STARTED
3990 wait_request_state $fid REMOVE CANCELED
3992 run_test 202 "Register/Cancel remove"
3994 test_220A() { # was test_220
3995 # test needs a running copytool
4000 local f=$DIR/$tdir/$tfile
4001 local fid=$(copy_file /etc/passwd $f)
4005 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4006 wait_request_state $fid ARCHIVE SUCCEED
4008 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4009 error "The expected changelog was not emitted"
4011 run_test 220A "Changelog for archive"
4014 # test needs a running copytool
4019 local f=$DIR/$tdir/$tfile
4020 local fid=$(copy_file /etc/passwd $f)
4024 # block copytool operations to allow for HSM request to be
4025 # submitted and file be unlinked (CDT will find object removed)
4028 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4030 # wait request to reach CT
4031 wait_request_state $fid ARCHIVE STARTED
4037 wait_request_state $fid ARCHIVE FAILED
4040 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4041 error "The expected changelog was not emitted"
4043 run_test 220a "Changelog for failed archive"
4046 local f=$DIR/$tdir/$tfile
4047 local fid=$(create_empty_file "$f")
4052 # Prevent archive from completing
4054 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4055 wait_request_state $fid ARCHIVE STARTED
4058 wait_request_state $fid ARCHIVE CANCELED
4061 wait_request_state $fid CANCEL SUCCEED
4063 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4064 error "The expected changelog was not emitted"
4066 run_test 221 "Changelog for archive canceled"
4069 # test needs a running copytool
4073 copy2archive /etc/passwd $tdir/$tfile
4075 local f=$DIR/$tdir/$tfile
4076 copytool import $tdir/$tfile $f
4077 local fid=$(path2fid $f)
4082 wait_request_state $fid RESTORE SUCCEED
4084 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4085 error "The expected changelog was not emitted"
4087 run_test 222a "Changelog for explicit restore"
4090 # test needs a running copytool
4094 local f=$DIR/$tdir/$tfile
4095 local fid=$(copy_file /etc/passwd $f)
4098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4099 wait_request_state $fid ARCHIVE SUCCEED
4104 wait_request_state $fid RESTORE SUCCEED
4106 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4107 error "The expected changelog was not emitted"
4109 run_test 222b "Changelog for implicit restore"
4112 # test needs a running copytool
4116 copy2archive /etc/passwd $tdir/$tfile
4118 local f=$DIR/$tdir/$tfile
4119 copytool import $tdir/$tfile $f
4120 local fid=$(path2fid $f)
4124 # block copytool operations to allow for HSM request to be
4125 # submitted and file be unlinked (CDT will find object removed)
4130 # wait request to reach CT
4131 wait_request_state $fid RESTORE STARTED
4137 wait_request_state $fid RESTORE FAILED
4140 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4141 error "The expected changelog was not emitted"
4143 run_test 222c "Changelog for failed explicit restore"
4146 # test needs a running copytool
4150 local f=$DIR/$tdir/$tfile
4151 local fid=$(copy_file /etc/passwd $f)
4154 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4155 wait_request_state $fid ARCHIVE SUCCEED
4158 copytool_remove_backend $fid
4161 wait_request_state $fid RESTORE FAILED
4164 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4165 error "The expected changelog was not emitted"
4167 run_test 222d "Changelog for failed implicit restore"
4170 # test needs a running copytool
4173 local f=$DIR/$tdir/$tfile
4174 create_archive_file $tdir/$tfile
4178 copytool import $tdir/$tfile $f
4179 local fid=$(path2fid $f)
4182 wait_request_state $fid RESTORE STARTED
4184 wait_request_state $fid RESTORE CANCELED
4185 wait_request_state $fid CANCEL SUCCEED
4187 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4188 error "The expected changelog was not emitted"
4190 run_test 223a "Changelog for restore canceled (import case)"
4193 local f=$DIR/$tdir/$tfile
4194 local fid=$(create_empty_file "$f")
4199 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4200 wait_request_state $fid ARCHIVE SUCCEED
4203 # Prevent restore from completing
4206 wait_request_state $fid RESTORE STARTED
4209 wait_request_state $fid RESTORE CANCELED
4212 wait_request_state $fid CANCEL SUCCEED
4214 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4215 error "The expected changelog was not emitted"
4217 run_test 223b "Changelog for restore canceled (release case)"
4219 test_224A() { # was test_224
4220 # test needs a running copytool
4225 local f=$DIR/$tdir/$tfile
4226 local fid=$(copy_file /etc/passwd $f)
4229 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4230 wait_request_state $fid ARCHIVE SUCCEED
4233 wait_request_state $fid REMOVE SUCCEED
4235 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4236 error "The expected changelog was not emitted"
4238 run_test 224A "Changelog for remove"
4241 # test needs a running copytool
4246 local f=$DIR/$tdir/$tfile
4247 local fid=$(copy_file /etc/passwd $f)
4250 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4251 wait_request_state $fid ARCHIVE SUCCEED
4253 copytool_remove_backend $fid
4255 # block copytool operations to allow for HSM request to be
4256 # submitted and file be unlinked (CDT will find object removed)
4261 # wait for request to reach CT
4262 wait_request_state $fid REMOVE STARTED
4268 wait_request_state $fid REMOVE FAILED
4270 # HE_REMOVE|ENOENT=0x202
4271 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4272 error "The expected changelog was not emitted"
4274 run_test 224a "Changelog for failed remove"
4277 # test is not usable because remove request is too fast
4278 # so it is always finished before cancel can be done ...
4279 echo "Test disabled"
4282 # test needs a running copytool
4285 local f=$DIR/$tdir/$tfile
4286 local fid=$(create_empty_file "$f")
4289 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4290 wait_request_state $fid ARCHIVE SUCCEED
4292 # Prevent restore from completing
4297 wait_request_state $fid REMOVE CANCELED
4300 wait_request_state $fid CANCEL SUCCEED
4302 changelog_find -type HSM -target-fid $fid -flags 0x27d
4303 error "The expected changelog was not emitted"
4305 run_test 225 "Changelog for remove canceled"
4308 # test needs a running copytool
4313 local f1=$DIR/$tdir/$tfile-1
4314 local f2=$DIR/$tdir/$tfile-2
4315 local f3=$DIR/$tdir/$tfile-3
4316 local fid1=$(copy_file /etc/passwd $f1)
4317 local fid2=$(copy_file /etc/passwd $f2)
4318 copy_file /etc/passwd $f3
4321 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4322 wait_request_state $fid1 ARCHIVE SUCCEED
4324 $LFS hsm_archive $f2
4325 wait_request_state $fid2 ARCHIVE SUCCEED
4327 rm $f1 || error "rm $f1 failed"
4330 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4331 error "The expected changelog was not emitted"
4333 mv $f3 $f2 || error "mv $f3 $f2 failed"
4335 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4336 error "The expected changelog was not emitted"
4338 run_test 226 "changelog for last rm/mv with exiting archive"
4340 # This is just a utility function to clarify what test_227 does
4345 "$LFS" "$action" --$flag "$file" ||
4346 error "Cannot ${action#hsm_} $flag on '$file'"
4348 # Only one changelog should be produced
4349 local entries="$(changelog_find -type HSM -target-fid $fid)"
4350 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4351 error "lfs $action --$flag '$file' produced more than one" \
4354 # Parse the last changelog record
4355 local entry="$(tail -n 1 <<< "$entries")"
4356 eval local -A changelog=$(changelog2array $entry)
4358 # Also check the flags match what is expected
4359 [[ ${changelog[flags]} == $target ]] ||
4360 error "Changelog flag is '${changelog[flags]}', not $target"
4364 local file="$DIR/$tdir/$tfile"
4365 local fid=$(create_empty_file "$file")
4370 for flag in norelease noarchive exists archived lost; do
4371 if [ "$flag" == lost ]; then
4372 # The flag "lost" only works on an archived file
4373 "$LFS" hsm_set --archived "$file"
4377 action="hsm_set" __test_227
4378 action="hsm_clear" __test_227
4381 run_test 227 "changelog when explicit setting of HSM flags"
4384 # test needs a running copytool
4387 local fid=$(create_small_sync_file $DIR/$tfile)
4388 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4389 wait_request_state $fid ARCHIVE SUCCEED
4391 $LFS hsm_release $DIR/$tfile
4392 check_hsm_flags $DIR/$tfile "0x0000000d"
4394 filefrag $DIR/$tfile | grep " 1 extent found" ||
4395 error "filefrag on released file must return only one extent"
4397 # only newer versions of cp detect sparse files by stat/FIEMAP
4399 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4400 error "copying $DIR/$tfile"
4401 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4403 $LFS hsm_release $DIR/$tfile
4404 check_hsm_flags $DIR/$tfile "0x0000000d"
4406 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4408 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4410 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4411 error "comparing untarred $DIR/$tfile"
4413 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4414 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4416 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4419 # test needs a running copytool
4423 local maxrequest=$(get_hsm_param max_requests)
4424 local rqcnt=$(($maxrequest * 3))
4428 for i in $(seq -w 1 $rqcnt); do
4430 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4432 # we do it in 2 steps, so all requests arrive at the same time
4433 for i in $(seq -w 1 $rqcnt); do
4434 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4439 while [[ $cnt != 0 || $wt != 0 ]]; do
4441 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4442 $HSM_PARAM.actions |\
4443 grep STARTED | grep -v CANCEL | wc -l")
4444 [[ $cnt -le $maxrequest ]] ||
4445 error "$cnt > $maxrequest too many started requests"
4446 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4447 $HSM_PARAM.actions |\
4448 grep WAITING | wc -l")
4449 echo "max=$maxrequest started=$cnt waiting=$wt"
4452 run_test 250 "Coordinator max request"
4455 local f=$DIR/$tdir/$tfile
4456 local fid=$(create_empty_file "$f")
4459 # to have a short test
4460 local old_to=$(get_hsm_param active_request_timeout)
4461 set_hsm_param active_request_timeout 1
4462 # to be sure the cdt will wake up frequently so
4463 # it will be able to cancel the "old" request
4464 local old_loop=$(get_hsm_param loop_period)
4465 set_hsm_param loop_period 1
4470 # Prevent archive from completing
4472 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4473 wait_request_state $fid ARCHIVE STARTED
4475 # Let the request timeout
4476 wait_request_state $fid ARCHIVE CANCELED
4478 set_hsm_param active_request_timeout $old_to
4479 set_hsm_param loop_period $old_loop
4481 run_test 251 "Coordinator request timeout"
4484 local f=$DIR/$tdir/$tfile
4485 local fid=$(create_empty_file "$f")
4487 # to have a short test
4488 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4489 set_hsm_param loop_period 1
4493 # Prevent archive from completing
4495 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4496 wait_request_state $fid ARCHIVE STARTED
4499 stack_trap "set_hsm_param active_request_timeout \
4500 $(get_hsm_param active_request_timeout)" EXIT
4501 set_hsm_param active_request_timeout 1
4503 wait_request_state $fid ARCHIVE CANCELED
4506 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4510 # test needs a running copytool
4514 local f=$DIR/$tdir/$tfile
4516 dd if=/dev/zero of=$f bs=1MB count=10
4517 local fid=$(path2fid $f)
4519 $LFS hsm_archive $f || error "could not archive file"
4520 wait_request_state $fid ARCHIVE SUCCEED
4522 # clear locks to discard inode data
4523 cancel_lru_locks osc
4525 #define OBD_FAIL_MDC_MERGE 0x807
4526 $LCTL set_param fail_loc=0x807
4528 #expect error here, instead of release with wrong size
4531 if ((rc == 0)); then
4532 file_size=$(stat -c '%s' $f)
4533 if ((file_size != 10485760)); then
4534 error "Wrong file size after hsm_release"
4537 echo "could not release file"
4540 run_test 253 "Check for wrong file size after release"
4544 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4545 skip "need MDS version at least 2.10.56"
4547 # Check that the counters are initialized to 0
4549 for request_type in archive restore remove; do
4550 count="$(get_hsm_param ${request_type}_count)" ||
4551 error "Reading ${request_type}_count failed with $?"
4553 [ "$count" -eq 0 ] ||
4554 error "Expected ${request_type}_count to be " \
4558 run_test 254a "Request counters are initialized to zero"
4562 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4563 skip "need MDS version at least 2.10.56"
4565 # The number of request to launch (at least 32)
4566 local request_count=$((RANDOM % 32 + 32))
4567 printf "Will launch %i requests of each type\n" "$request_count"
4569 # Launch a copytool to process requests
4572 # Set hsm.max_requests to allow starting all requests at the same time
4574 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4575 set_hsm_param max_requests "$request_count"
4579 for request_type in archive restore remove; do
4580 printf "Checking %s requests\n" "${request_type}"
4581 # Suspend the copytool to give us time to read the proc files
4584 for ((i = 0; i < $request_count; i++)); do
4585 case $request_type in
4587 create_empty_file "$DIR/$tdir/$tfile-$i" \
4591 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4594 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4597 # Give the coordinator 10 seconds to start every request
4599 while get_hsm_param actions | grep -q WAITING; do
4602 [ $timeout -gt 0 ] ||
4603 error "${request_type^} requests took too " \
4607 count="$(get_hsm_param ${request_type}_count)"
4608 [ "$count" -eq "$request_count" ] ||
4609 error "Expected '$request_count' (!= '$count') " \
4610 "active $request_type requests"
4612 # Let the copytool process the requests
4614 # Give it 10 seconds maximum
4616 while get_hsm_param actions | grep -q STARTED; do
4619 [ $timeout -gt 0 ] ||
4620 error "${request_type^} requests took too " \
4624 count="$(get_hsm_param ${request_type}_count)"
4625 [ "$count" -eq 0 ] ||
4626 error "Expected 0 (!= '$count') " \
4627 "active $request_type requests"
4630 run_test 254b "Request counters are correctly incremented and decremented"
4632 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4633 # break in the future because of that.
4636 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4637 skip "need MDS version 2.11.56 or later"
4639 local -a files=("$DIR/$tdir/$tfile".{0..15})
4642 for file in "${files[@]}"; do
4643 create_small_file "$file"
4646 # Set a few hsm parameters
4648 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4649 set_hsm_param loop_period 1
4651 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4652 set_hsm_param max_requests 3
4656 "$LFS" hsm_archive "${files[0]}"
4657 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4658 "$LFS" hsm_release "${files[0]}"
4662 wait_copytools || error "copytools failed to stop"
4664 # Send several archive requests
4665 for file in "${files[@]:1}"; do
4666 "$LFS" hsm_archive "$file"
4669 # Send one restore request
4670 "$LFS" hsm_restore "${files[0]}"
4675 # Wait for all the requests to complete
4676 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4677 for file in "${files[@]:1}"; do
4678 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4681 # Collect the actions in the order in which the copytool processed them
4683 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4684 "$(copytool_logfile "$SINGLEAGT")")
4687 printf '%s\n' "${actions[@]}"
4690 for action in "${actions[@]:0:3}"; do
4691 [ "$action" == RESTORE ] && return
4694 error "Too many ARCHIVE requests were run before the RESTORE request"
4696 run_test 260a "Restore request have priority over other requests"
4698 # This test is very much tied to the implementation of the current priorisation
4699 # mechanism in the coordinator. It might not make sense to keep it in the future
4702 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4703 skip "need MDS version 2.11.56 or later"
4705 local -a files=("$DIR/$tdir/$tfile".{0..15})
4708 for file in "${files[@]}"; do
4709 create_small_file "$file"
4712 # Set a few hsm parameters
4714 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4715 set_hsm_param loop_period 1
4717 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4718 set_hsm_param max_requests 3
4721 copytool setup --archive-id 2
4722 "$LFS" hsm_archive --archive 2 "${files[0]}"
4723 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4724 "$LFS" hsm_release "${files[0]}"
4728 wait_copytools || error "copytools failed to stop"
4730 # Send several archive requests
4731 for file in "${files[@]:1}"; do
4732 "$LFS" hsm_archive "$file"
4735 # Send one restore request
4736 "$LFS" hsm_restore "${files[0]}"
4740 copytool setup --archive-id 2
4742 # Wait for all the requests to complete
4743 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4744 for file in "${files[@]:1}"; do
4745 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4748 # Collect the actions in the order in which the copytool processed them
4750 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4751 "$(copytool_logfile "$SINGLEAGT")")
4754 printf '%s\n' "${actions[@]}"
4757 for action in "${actions[@]:0:3}"; do
4758 [ "$action" == RESTORE ] && return
4761 error "Too many ARCHIVE requests were run before the RESTORE request"
4763 run_test 260b "Restore request have priority over other requests"
4765 # This test is very much tied to the implementation of the current priorisation
4766 # mechanism in the coordinator. It might not make sense to keep it in the future
4769 local -a files=("$DIR/$tdir/$tfile".{0..15})
4772 for file in "${files[@]}"; do
4773 create_small_file "$file"
4776 # Set a few hsm parameters
4778 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4779 set_hsm_param loop_period 10
4781 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4782 set_hsm_param max_requests 3
4785 copytool setup --archive-id 2
4786 "$LFS" hsm_archive --archive 2 "${files[0]}"
4787 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4788 "$LFS" hsm_release "${files[0]}"
4792 wait_copytools || error "copytools failed to stop"
4794 "$LFS" hsm_archive "${files[1]}"
4798 copytool setup --archive-id 2
4800 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4802 # Send several archive requests
4803 for file in "${files[@]:2}"; do
4804 "$LFS" hsm_archive "$file"
4807 # Send one restore request
4808 "$LFS" hsm_restore "${files[0]}"
4810 # Wait for all the requests to complete
4811 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4812 for file in "${files[@]:2}"; do
4813 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4816 # Collect the actions in the order in which the copytool processed them
4818 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4819 "$(copytool_logfile "$SINGLEAGT")")
4822 printf '%s\n' "${actions[@]}"
4825 for action in "${actions[@]:0:3}"; do
4826 [ "$action" == RESTORE ] &&
4827 error "Restore requests should not be prioritised" \
4828 "unless the coordinator is doing housekeeping"
4832 run_test 260c "Restore request have priority over other requests"
4835 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4837 # the only way to test ondisk conf is to restart MDS ...
4838 echo "Stop coordinator and remove coordinator state at mount"
4841 # clean on disk conf set by default
4842 cdt_clear_mount_state
4843 cdt_check_state stopped
4845 # check cdt still off after umount/remount
4847 cdt_check_state stopped
4849 echo "Set coordinator start at mount, and start coordinator"
4850 cdt_set_mount_state enabled
4853 cdt_check_state enabled
4855 # check cdt still on after umount/remount
4857 cdt_check_state enabled
4859 # we are back to original state (cdt started at mount)
4861 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4864 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4866 local ai=$(get_hsm_param default_archive_id)
4867 local new=$((ai + 1))
4869 set_hsm_param default_archive_id $new -P
4871 local res=$(get_hsm_param default_archive_id)
4874 set_hsm_param default_archive_id "" "-P -d"
4876 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4878 run_test 301 "HSM tunnable are persistent"
4881 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4883 local ai=$(get_hsm_param default_archive_id)
4884 local new=$((ai + 1))
4889 set_hsm_param default_archive_id $new -P
4892 for mdtno in $(seq 1 $MDSCOUNT); do
4897 cdt_check_state enabled
4899 local res=$(get_hsm_param default_archive_id)
4902 set_hsm_param default_archive_id "" "-P -d"
4904 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4906 run_test 302 "HSM tunnable are persistent when CDT is off"
4909 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4915 local dir_mdt0=$DIR/$tdir/mdt0
4916 local dir_mdt1=$DIR/$tdir/mdt1
4918 # create 1 dir per MDT
4919 stack_trap "rm -rf $dir_mdt0" EXIT
4920 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4921 stack_trap "rm -rf $dir_mdt1" EXIT
4922 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4924 # create 1 file in each MDT
4925 local fid1=$(create_small_file $dir_mdt0/$tfile)
4926 local fid2=$(create_small_file $dir_mdt1/$tfile)
4928 # check that hsm request on mdt0 is sent to the right MDS
4929 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4930 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4931 echo "archive successful on mdt0"
4933 # check that hsm request on mdt1 is sent to the right MDS
4934 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4935 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4936 echo "archive successful on mdt1"
4938 run_test 400 "Single request is sent to the right MDT"
4941 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4947 local dir_mdt0=$DIR/$tdir/mdt0
4948 local dir_mdt1=$DIR/$tdir/mdt1
4950 # create 1 dir per MDT
4951 stack_trap "rm -rf $dir_mdt0" EXIT
4952 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4953 stack_trap "rm -rf $dir_mdt1" EXIT
4954 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4956 # create 1 file in each MDT
4957 local fid1=$(create_small_file $dir_mdt0/$tfile)
4958 local fid2=$(create_small_file $dir_mdt1/$tfile)
4960 # check that compound requests are shunt to the rights MDTs
4961 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4962 error "lfs hsm_archive"
4963 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4964 echo "archive successful on mdt0"
4965 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4966 echo "archive successful on mdt1"
4968 run_test 401 "Compound requests split and sent to their respective MDTs"
4970 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4975 local node=$(facet_active_host $facet)
4977 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4978 awk '{print $4}'); do
4979 echo "$3 $mdc on $node"
4980 do_facet $facet "$LCTL --device $mdc $state" || return 1
4985 # deactivate all mdc on agent1
4986 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4988 copytool setup --no-fail
4990 check_agent_unregistered "uuid" # match any agent
4992 # no expected running copytool
4993 search_copytools $agent && error "Copytool start should have failed"
4996 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4998 run_test 402a "Copytool start fails if all MDTs are inactive"
5005 local f=$DIR/$tdir/$tfile
5006 touch $f || error "touch $f failed"
5007 local fid=$(path2fid $f)
5009 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5010 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5011 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5013 # give time for CDT to send request and to keep it for retry
5014 wait_for_loop_period
5016 wait_request_state $fid ARCHIVE WAITING
5018 do_facet $SINGLEAGT lctl set_param fail_loc=0
5020 # request should succeed now
5021 wait_request_state $fid ARCHIVE SUCCEED
5023 run_test 402b "CDT must retry request upon slow start of CT"
5026 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5028 local agent=$(facet_active_host $SINGLEAGT)
5030 # deactivate all mdc for MDT0001
5031 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5034 local uuid=$(get_agent_uuid $agent)
5035 # check the agent is registered on MDT0000, and not on MDT0001
5036 check_agent_registered_by_mdt $uuid 0
5037 check_agent_unregistered_by_mdt $uuid 1
5039 # check running copytool process
5040 search_copytools $agent || error "No running copytools on $agent"
5042 # reactivate all mdc for MDT0001
5043 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5045 # make sure the copytool is now registered to all MDTs
5046 check_agent_registered $uuid
5048 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5051 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5055 # create files on both MDT0000 and MDT0001
5058 local dir_mdt0=$DIR/$tdir/mdt0
5059 stack_trap "rm -rf $dir_mdt0" EXIT
5060 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5062 # create 1 file on mdt0
5063 local fid1=$(create_small_file $dir_mdt0/$tfile)
5065 # deactivate all mdc for MDT0001
5066 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5068 # send an HSM request for files in MDT0000
5069 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5071 # check for completion of files in MDT0000
5072 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5073 echo "archive successful on mdt0"
5075 # reactivate all mdc for MDT0001
5076 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5078 run_test 404 "Inactive MDT does not block requests for active MDTs"
5081 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5087 local striped_dir=$DIR/$tdir/striped_dir
5089 # create striped dir on all of MDTs
5090 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5092 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5093 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5094 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5095 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5097 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5098 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5099 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5100 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5102 # check that compound requests are shunt to the rights MDTs
5103 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5104 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5105 error "lfs hsm_archive"
5107 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5108 echo "archive successful on $fid1"
5109 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5110 echo "archive successful on $fid2"
5111 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5112 echo "archive successful on $fid3"
5113 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5114 echo "archive successful on $fid4"
5116 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5117 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5118 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5119 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5121 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5122 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5123 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5124 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5126 run_test 405 "archive and release under striped directory"
5129 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5131 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5132 skip "need MDS version at least 2.7.64"
5137 fid=$(create_small_file $DIR/$tdir/$tfile)
5142 $LFS hsm_archive $DIR/$tdir/$tfile
5143 wait_request_state "$fid" ARCHIVE SUCCEED
5144 $LFS hsm_release $DIR/$tdir/$tfile
5146 # Should migrate $tdir but not $tfile.
5147 $LFS migrate -m1 $DIR/$tdir &&
5148 error "migrating HSM an archived file should fail"
5150 $LFS hsm_restore $DIR/$tdir/$tfile
5151 wait_request_state "$fid" RESTORE SUCCEED
5153 $LFS hsm_remove $DIR/$tdir/$tfile
5154 wait_request_state "$fid" REMOVE SUCCEED
5156 cat $DIR/$tdir/$tfile > /dev/null ||
5157 error "cannot read $DIR/$tdir/$tfile"
5159 $LFS migrate -m1 $DIR/$tdir ||
5160 error "cannot complete migration after HSM remove"
5162 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5163 if ((mdt_index != 1)); then
5164 error "expected MDT index 1, got $mdt_index"
5167 # Refresh fid after migration.
5168 fid=$(path2fid $DIR/$tdir/$tfile)
5171 $LFS hsm_archive $DIR/$tdir/$tfile
5172 wait_request_state "$fid" ARCHIVE SUCCEED 1
5174 lctl set_param debug=+trace
5175 $LFS hsm_release $DIR/$tdir/$tfile ||
5176 error "cannot release $DIR/$tdir/$tfile"
5178 $LFS hsm_restore $DIR/$tdir/$tfile
5179 wait_request_state "$fid" RESTORE SUCCEED 1
5181 cat $DIR/$tdir/$tfile > /dev/null ||
5182 error "cannot read $DIR/$tdir/$tfile"
5184 run_test 406 "attempting to migrate HSM archived files is safe"
5187 local f=$DIR/$tdir/$tfile
5188 local f2=$DIR2/$tdir/$tfile
5189 local fid=$(create_empty_file "$f")
5193 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5194 wait_request_state $fid ARCHIVE SUCCEED
5197 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5198 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5200 # Prevent restore from completing
5204 # 1st request holds layout lock while appropriate
5205 # RESTORE record is still not added to llog
5209 # after umount hsm_actions->O/x/x log shouldn't have
5210 # double RESTORE records like below
5211 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5212 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5214 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5218 wait_request_state $fid RESTORE SUCCEED
5220 run_test 407 "Check for double RESTORE records in llog"
5224 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5225 skip "HSM migrate is not supported"
5227 test_mkdir -p $DIR/$tdir
5228 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5230 run_test 500 "various LLAPI HSM tests"
5233 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5234 skip "need MDS version at least 2.10.58"
5238 local f=$DIR/$tdir/$tfile
5241 # set changelog_mask to ALL
5242 changelog_chmask "ALL"
5244 chmod 777 $DIR/$tdir
5245 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5246 local fid=$(path2fid $f)
5249 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5250 -gid "$RUNAS_GID") ||
5251 error "No matching CREAT entry"
5253 # Parse the changelog
5254 eval local -A changelog=$(changelog2array $entry)
5255 local nid="${changelog[nid]}"
5258 echo "Got NID '$nid'"
5259 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5260 error "nid '$nid' does not match any client NID:" \
5263 run_test 600 "Changelog fields 'u=' and 'nid='"
5266 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5267 skip "need MDS version at least 2.10.58"
5271 local f=$DIR/$tdir/$tfile
5274 # set changelog_mask to ALL
5275 changelog_chmask "ALL"
5277 touch $f || error "touch $f failed"
5278 local fid=$(path2fid $f)
5281 cat $f || error "cat $f failed"
5283 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5284 error "No matching OPEN entry"
5286 run_test 601 "OPEN Changelog entry"
5289 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5290 skip "need MDS version at least 2.10.58"
5294 local f=$DIR/$tdir/$tfile
5297 # set changelog_mask to ALL
5298 changelog_chmask "ALL"
5300 touch $f || error "touch $f failed"
5301 local fid=$(path2fid $f)
5304 cat $f || error "cat $f failed"
5306 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5310 echo f > $f || error "write $f failed"
5313 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5315 # remove OPEN from changelog_mask
5316 changelog_chmask "-OPEN"
5320 cat $f || error "cat $f failed"
5323 changelog_find -type CLOSE -target-fid $fid &&
5324 error "There should be no CLOSE entry"
5328 echo f > $f || error "write $f failed"
5331 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5333 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5336 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5337 skip "need MDS version at least 2.10.58"
5341 local f=$DIR/$tdir/$tfile
5344 # set changelog_mask to ALL
5345 changelog_chmask "ALL"
5347 touch $f || error "touch $f failed"
5348 local fid=$(path2fid $f)
5350 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5353 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5355 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5356 error "No matching GXATR entry"
5358 run_test 603 "GETXATTR Changelog entry"
5361 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5362 skip "need MDS version at least 2.10.58"
5366 local f=$DIR/$tdir/$tfile
5367 local f2=$DIR2/$tdir/$tfile
5368 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5370 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5371 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5372 do_facet mds1 lctl set_param "$procname=20"
5376 # set changelog_mask to ALL
5377 changelog_chmask "ALL"
5379 touch $f || error "touch $f failed"
5380 local fid=$(path2fid $f)
5386 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5390 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5391 -gid "$RUNAS_GID" -mode "r--") ||
5392 error "No matching NOPEN entry"
5394 # Parse the changelog
5395 eval local -A changelog=$(changelog2array $entry)
5396 local nid="${changelog[nid]}"
5399 echo "Got NID '$nid'"
5400 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5401 error "nid '$nid' does not match any client NID:" \
5406 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5409 changelog_find -type NOPEN -target-fid $fid &&
5410 error "There should be no NOPEN entry"
5412 # Sleep for `changelog_deniednext` seconds
5417 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5420 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5421 -gid "$RUNAS_GID" -mode "r--") ||
5422 error "No matching NOPEN entry"
5424 # Parse the changelog
5425 eval local -A changelog=$(changelog2array $entry)
5426 local nid="${changelog[nid]}"
5429 echo "Got NID '$nid'"
5430 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5431 error "nid '$nid' does not match any client NID:" \
5434 run_test 604 "NOPEN Changelog entry"
5437 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5438 skip "need MDS version at least 2.10.58"
5442 local f=$DIR/$tdir/$tfile
5443 local f2=$DIR2/$tdir/$tfile
5446 # set changelog_mask to ALL
5447 changelog_chmask "ALL"
5449 touch $f || error "touch $f failed"
5450 local fid=$(path2fid $f)
5454 exec 3<> $f || error "open $f failed"
5458 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5462 exec 4<> $f || error "open $f failed"
5465 changelog_find -type OPEN -target-fid $fid &&
5466 error "There should be no OPEN entry"
5468 exec 4>&- || error "close $f failed"
5471 changelog_find -type CLOSE -target-fid $fid &&
5472 error "There should be no CLOSE entry"
5476 # access in rw, so different access mode should generate entries
5477 cat $f || error "cat $f failed"
5480 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5482 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5486 # same access as first one, should not generate new entries
5487 exec 4<> $f || error "open $f failed"
5490 changelog_find -type OPEN -target-fid $fid &&
5491 error "There should be no OPEN entry"
5493 exec 4>&- || error "close $f failed"
5496 changelog_find -type CLOSE -target-fid $fid &&
5497 error "There should be no CLOSE entry"
5501 # access by different user should generate new entries
5502 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5505 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5507 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5511 exec 3>&- || error "close $f failed"
5514 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5516 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5519 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5520 skip "need MDS version at least 2.10.58"
5522 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5523 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5524 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5525 skip_env "missing llog_reader" && return
5526 local fstype=$(facet_fstype mds1)
5530 local f=$DIR/$tdir/$tfile
5533 # set changelog_mask to ALL
5534 changelog_chmask "ALL"
5536 chmod 777 $DIR/$tdir
5537 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5538 local fid=$(path2fid $f)
5539 rm $f || error "rm $f failed"
5541 local mntpt=$(facet_mntpt mds1)
5545 #remount mds1 as ldiskfs or zfs type
5546 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5547 stop mds1 || error "stop mds1 failed"
5548 mount_fstype mds1 || error "remount mds1 failed"
5550 for ((i = 0; i < 1; i++)); do
5551 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5552 local cat_file=$(do_facet mds1 $llog_reader \
5553 $mntpt/changelog_catalog | awk \
5554 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5555 [ -n "$cat_file" ] || error "no catalog file"
5557 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5558 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5559 [ -n "$entry" ] || error "no CREAT entry"
5562 local uidgid=$(echo $entry |
5563 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5564 [ -n "$uidgid" ] || error "uidgid is empty"
5565 echo "Got UID/GID $uidgid"
5566 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5567 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5568 local nid=$(echo $entry |
5569 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5570 [ -n "$nid" ] || error "nid is empty"
5572 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5573 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5575 run_test 606 "llog_reader groks changelog fields"
5578 check_and_cleanup_lustre