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 LOCAL_HSM_ARCHIVE_NUMBER=33
997 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
998 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
999 # lustre in the new version supports unlimited archiveID.
1000 # Test whether setting archive number > 32 is supported
1001 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1002 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
1003 check_hsm_flags_user $f "0x00000001"
1005 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1006 st=$(get_hsm_archive_id $f)
1007 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1008 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1010 # old client or old mds can only support at most 32 archiveID
1011 # test whether setting archive number > 32 results in error.
1012 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
1013 error "bitmap archive number is larger than 32"
1014 check_hsm_flags_user $f "0x00000001"
1017 # Test whether setting archive number 16 and archived flag.
1018 LOCAL_HSM_ARCHIVE_NUMBER=16
1019 $LFS hsm_set --exists --archived \
1020 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1021 error "root could not change hsm flags"
1022 check_hsm_flags_user $f "0x00000009"
1023 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1024 st=$(get_hsm_archive_id $f)
1025 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1026 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1028 run_test 1c "Check setting archive-id in lfs hsm_set"
1031 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1032 skip "need MDS version at least 2.10.59"
1035 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1036 error "failed to set default stripe"
1037 local f=$DIR/$tdir/$tfile
1040 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1041 error "failed to create file"
1042 local fid=$(path2fid $f)
1047 $LFS hsm_archive $f || error "could not archive file"
1048 wait_request_state $fid ARCHIVE SUCCEED
1051 $LFS hsm_release $f || error "could not release file"
1052 echo "verify released state: "
1053 check_hsm_flags $f "0x0000000d" && echo "pass"
1056 $LFS hsm_restore $f || error "could not restore file"
1057 wait_request_state $fid RESTORE SUCCEED
1058 echo "verify restored state: "
1059 check_hsm_flags $f "0x00000009" && echo "pass"
1061 run_test 1d "Archive, Release and Restore DoM file"
1064 local f=$DIR/$tdir/$tfile
1066 create_empty_file "$f"
1067 # New files are not dirty
1068 check_hsm_flags $f "0x00000000"
1070 # For test, we simulate an archived file.
1071 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1072 check_hsm_flags $f "0x00000001"
1074 # chmod do not put the file dirty
1075 chmod 600 $f || error "could not chmod test file"
1076 check_hsm_flags $f "0x00000001"
1078 # chown do not put the file dirty
1079 chown $RUNAS_ID $f || error "could not chown test file"
1080 check_hsm_flags $f "0x00000001"
1082 # truncate put the file dirty
1083 $TRUNCATE $f 1 || error "could not truncate test file"
1084 check_hsm_flags $f "0x00000003"
1086 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1087 check_hsm_flags $f "0x00000001"
1089 run_test 2 "Check file dirtyness when doing setattr"
1095 # New files are not dirty
1096 cp -p /etc/passwd $f
1097 check_hsm_flags $f "0x00000000"
1099 # For test, we simulate an archived file.
1100 $LFS hsm_set --exists $f ||
1101 error "user could not change hsm flags"
1102 check_hsm_flags $f "0x00000001"
1104 # Reading a file, does not set dirty
1105 cat $f > /dev/null || error "could not read file"
1106 check_hsm_flags $f "0x00000001"
1108 # Open for write without modifying data, does not set dirty
1109 openfile -f O_WRONLY $f || error "could not open test file"
1110 check_hsm_flags $f "0x00000001"
1112 # Append to a file sets it dirty
1113 cp -p /etc/passwd $f.append || error "could not create file"
1114 $LFS hsm_set --exists $f.append ||
1115 error "user could not change hsm flags"
1116 dd if=/etc/passwd of=$f.append bs=1 count=3\
1117 conv=notrunc oflag=append status=noxfer ||
1118 file_creation_failure dd $f.append $?
1119 check_hsm_flags $f.append "0x00000003"
1121 # Modify a file sets it dirty
1122 cp -p /etc/passwd $f.modify || error "could not create file"
1123 $LFS hsm_set --exists $f.modify ||
1124 error "user could not change hsm flags"
1125 dd if=/dev/zero of=$f.modify bs=1 count=3\
1126 conv=notrunc status=noxfer ||
1127 file_creation_failure dd $f.modify $?
1128 check_hsm_flags $f.modify "0x00000003"
1130 # Open O_TRUNC sets dirty
1131 cp -p /etc/passwd $f.trunc || error "could not create file"
1132 $LFS hsm_set --exists $f.trunc ||
1133 error "user could not change hsm flags"
1134 cp /etc/group $f.trunc || error "could not override a file"
1135 check_hsm_flags $f.trunc "0x00000003"
1137 # Mmapped a file sets dirty
1138 cp -p /etc/passwd $f.mmap || error "could not create file"
1139 $LFS hsm_set --exists $f.mmap ||
1140 error "user could not change hsm flags"
1141 multiop $f.mmap OSMWUc || error "could not mmap a file"
1142 check_hsm_flags $f.mmap "0x00000003"
1144 run_test 3 "Check file dirtyness when opening for write"
1147 local f=$DIR/$tdir/$tfile
1148 local fid=$(create_small_file $f)
1151 local st=$(get_request_state $fid CANCEL)
1152 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1154 run_test 4 "Useless cancel must not be registered"
1157 # test needs a running copytool
1161 local f=$DIR/$tdir/$tfile
1162 local fid=$(copy_file /etc/passwd $f)
1164 wait_request_state $fid ARCHIVE SUCCEED
1166 check_hsm_flags $f "0x00000009"
1168 run_test 8 "Test default archive number"
1170 test_9A() { # was test_9
1171 # we do not use the default one to be sure
1172 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1173 copytool setup --archive-id $archive_id
1175 # give time for CT to register with MDTs
1176 sleep $(($MDSCOUNT*2))
1177 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1178 check_agent_registered $uuid
1181 local f=$DIR/$tdir/$tfile
1182 local fid=$(copy_file /etc/passwd $f)
1183 $LFS hsm_archive --archive $archive_id $f
1184 wait_request_state $fid ARCHIVE SUCCEED
1186 check_hsm_flags $f "0x00000009"
1188 run_test 9A "Use of explicit archive number, with dedicated copytool"
1191 needclients 3 || return 0
1197 # start all of the copytools
1198 for n in $(seq $AGTCOUNT); do
1199 copytool setup --facet agt$n
1203 for n in $(seq $AGTCOUNT); do
1204 file=$DIR/$tdir/$tfile.$n
1205 fid=$(create_small_file $file)
1207 $LFS hsm_archive $file || error "could not archive file $file"
1208 wait_request_state $fid ARCHIVE SUCCEED
1209 check_hsm_flags $file "0x00000009"
1212 run_test 9a "Multiple remote agents"
1215 # test needs a running copytool
1218 mkdir -p $DIR/$tdir/d1
1219 local f=$DIR/$tdir/$tfile
1220 local fid=$(copy_file /etc/hosts $f)
1221 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1222 error "hsm_archive failed"
1223 wait_request_state $fid ARCHIVE SUCCEED
1225 local hsm_root="$(copytool_device $SINGLEAGT)"
1226 local archive="$(do_facet $SINGLEAGT \
1227 find "$hsm_root" -name "$fid" -print0)"
1228 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1230 echo "Verifying content"
1231 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1232 echo "Verifying hsm state "
1233 check_hsm_flags $f "0x00000009"
1235 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1236 local st=$(get_hsm_archive_id $f)
1237 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1238 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1240 run_test 10a "Archive a file"
1243 # test needs a running copytool
1247 local f=$DIR/$tdir/$tfile
1248 local fid=$(copy_file /etc/hosts $f)
1249 $LFS hsm_archive $f || error "archive request failed"
1250 wait_request_state $fid ARCHIVE SUCCEED
1252 $LFS hsm_archive $f || error "archive of non dirty file failed"
1253 local cnt=$(get_request_count $fid ARCHIVE)
1254 [[ "$cnt" == "1" ]] ||
1255 error "archive of non dirty file must not make a request"
1257 run_test 10b "Archive of non dirty file must work without doing request"
1260 # test needs a running copytool
1264 local f=$DIR/$tdir/$tfile
1265 local fid=$(copy_file /etc/hosts $f)
1266 $LFS hsm_set --noarchive $f
1267 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1270 run_test 10c "Check forbidden archive"
1273 # test needs a running copytool
1277 local f=$DIR/$tdir/$tfile
1278 local fid=$(copy_file /etc/hosts $f)
1279 $LFS hsm_archive $f || error "cannot archive $f"
1280 wait_request_state $fid ARCHIVE SUCCEED
1282 local ar=$(get_hsm_archive_id $f)
1283 local dflt=$(get_hsm_param default_archive_id)
1284 [[ $ar == $dflt ]] ||
1285 error "archived file is not on default archive: $ar != $dflt"
1287 run_test 10d "Archive a file on the default archive id"
1291 copy2archive /etc/hosts $tdir/$tfile
1292 local f=$DIR/$tdir/$tfile
1294 copytool import $tdir/$tfile $f
1295 echo -n "Verifying released state: "
1296 check_hsm_flags $f "0x0000000d"
1298 local LSZ=$(stat -c "%s" $f)
1299 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1301 echo "Verifying imported size $LSZ=$ASZ"
1302 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1303 echo -n "Verifying released pattern: "
1304 local PTRN=$($GETSTRIPE -L $f)
1306 [[ $PTRN == released ]] || error "Is not released"
1307 local fid=$(path2fid $f)
1308 echo "Verifying new fid $fid in archive"
1310 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1311 error "No archive for fid $fid"
1313 run_test 11a "Import a file"
1316 # test needs a running copytool
1320 local f=$DIR/$tdir/$tfile
1321 local fid=$(copy_file /etc/hosts $f)
1322 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1323 error "hsm_archive failed"
1324 wait_request_state $fid ARCHIVE SUCCEED
1326 local FILE_HASH=$(md5sum $f)
1329 copytool import $fid $f
1331 echo "$FILE_HASH" | md5sum -c
1333 [[ $? -eq 0 ]] || error "Restored file differs"
1335 run_test 11b "Import a deleted file using its FID"
1338 # test needs a running copytool
1342 copy2archive /etc/hosts $tdir/$tfile
1344 local f=$DIR/$tdir/$tfile
1345 copytool import $tdir/$tfile $f
1346 local f2=$DIR2/$tdir/$tfile
1347 echo "Verifying released state: "
1348 check_hsm_flags $f2 "0x0000000d"
1350 local fid=$(path2fid $f2)
1351 $LFS hsm_restore $f2
1352 wait_request_state $fid RESTORE SUCCEED
1354 echo "Verifying file state: "
1355 check_hsm_flags $f2 "0x00000009"
1357 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1359 [[ $? -eq 0 ]] || error "Restored file differs"
1361 run_test 12a "Restore an imported file explicitly"
1364 # test needs a running copytool
1368 copy2archive /etc/hosts $tdir/$tfile
1370 local f=$DIR/$tdir/$tfile
1371 copytool import $tdir/$tfile $f
1372 echo "Verifying released state: "
1373 check_hsm_flags $f "0x0000000d"
1375 cat $f > /dev/null || error "File read failed"
1377 echo "Verifying file state after restore: "
1378 check_hsm_flags $f "0x00000009"
1380 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1382 [[ $? -eq 0 ]] || error "Restored file differs"
1384 run_test 12b "Restore an imported file implicitly"
1387 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1389 # test needs a running copytool
1392 local f=$DIR/$tdir/$tfile
1394 $LFS setstripe -c 2 "$f"
1395 local fid=$(create_file "$f" 1M 5)
1397 local FILE_CRC=$(md5sum $f)
1399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1400 wait_request_state $fid ARCHIVE SUCCEED
1401 $LFS hsm_release $f || error "release $f failed"
1403 echo "$FILE_CRC" | md5sum -c
1405 [[ $? -eq 0 ]] || error "Restored file differs"
1407 run_test 12c "Restore a file with stripe of 2"
1410 # test needs a running copytool
1415 local f=$DIR/$tdir/$tfile
1416 local fid=$(copy_file /etc/hosts $f)
1417 $LFS hsm_restore $f || error "restore of non archived file failed"
1418 local cnt=$(get_request_count $fid RESTORE)
1419 [[ "$cnt" == "0" ]] ||
1420 error "restore non archived must not make a request"
1421 $LFS hsm_archive $f ||
1422 error "archive request failed"
1423 wait_request_state $fid ARCHIVE SUCCEED
1424 $LFS hsm_restore $f ||
1425 error "restore of non released file failed"
1426 local cnt=$(get_request_count $fid RESTORE)
1427 [[ "$cnt" == "0" ]] ||
1428 error "restore a non dirty file must not make a request"
1430 run_test 12d "Restore of a non archived, non released file must work"\
1431 " without doing request"
1434 # test needs a running copytool
1438 local f=$DIR/$tdir/$tfile
1439 local fid=$(copy_file /etc/hosts $f)
1440 $LFS hsm_archive $f || error "archive request failed"
1441 wait_request_state $fid ARCHIVE SUCCEED
1444 cat /etc/hosts >> $f
1448 $LFS hsm_restore $f && error "restore a dirty file must fail"
1451 run_test 12e "Check forbidden restore"
1454 # test needs a running copytool
1458 local f=$DIR/$tdir/$tfile
1459 local fid=$(copy_file /etc/hosts $f)
1461 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1462 wait_request_state $fid ARCHIVE SUCCEED
1463 $LFS hsm_release $f || error "release of $f failed"
1465 wait_request_state $fid RESTORE SUCCEED
1467 echo -n "Verifying file state: "
1468 check_hsm_flags $f "0x00000009"
1470 diff -q /etc/hosts $f
1472 [[ $? -eq 0 ]] || error "Restored file differs"
1474 run_test 12f "Restore a released file explicitly"
1477 # test needs a running copytool
1481 local f=$DIR/$tdir/$tfile
1482 local fid=$(copy_file /etc/hosts $f)
1484 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1485 wait_request_state $fid ARCHIVE SUCCEED
1486 $LFS hsm_release $f || error "release of $f failed"
1488 diff -q /etc/hosts $f
1491 # we check we had a restore done
1492 wait_request_state $fid RESTORE SUCCEED
1494 [[ $st -eq 0 ]] || error "Restored file differs"
1496 run_test 12g "Restore a released file implicitly"
1499 needclients 2 || return 0
1501 # test needs a running copytool
1505 local f=$DIR/$tdir/$tfile
1506 local fid=$(copy_file /etc/hosts $f)
1508 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1509 wait_request_state $fid ARCHIVE SUCCEED
1510 $LFS hsm_release $f || error "release of $f failed"
1512 do_node $CLIENT2 diff -q /etc/hosts $f
1515 # we check we had a restore done
1516 wait_request_state $fid RESTORE SUCCEED
1518 [[ $st -eq 0 ]] || error "Restored file differs"
1520 run_test 12h "Restore a released file implicitly from a second node"
1523 # test needs a running copytool
1527 local f=$DIR/$tdir/$tfile
1528 local fid=$(copy_file /etc/passwd $f)
1529 $LFS hsm_archive $f || error "archive of $f failed"
1530 wait_request_state $fid ARCHIVE SUCCEED
1532 $LFS hsm_release $f || error "release of $f failed"
1536 [[ $? -eq 0 ]] || error "Restored file differs"
1538 run_test 12m "Archive/release/implicit restore"
1541 # test needs a running copytool
1545 copy2archive /etc/hosts $tdir/$tfile
1547 local f=$DIR/$tdir/$tfile
1548 copytool import $tdir/$tfile $f
1550 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1551 error "Restored file differs"
1553 $LFS hsm_release $f || error "release of $f failed"
1555 run_test 12n "Import/implicit restore/release"
1558 # test needs a running copytool
1562 local f=$DIR/$tdir/$tfile
1563 local fid=$(copy_file /etc/hosts $f)
1565 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1566 wait_request_state $fid ARCHIVE SUCCEED
1567 $LFS hsm_release $f || error "release of $f failed"
1569 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1570 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1572 # set no retry action mode
1575 diff -q /etc/hosts $f
1578 # we check we had a restore failure
1579 wait_request_state $fid RESTORE FAILED
1581 [[ $st -eq 0 ]] && error "Restore must fail"
1583 # remove no retry action mode
1586 # check file is still released
1587 check_hsm_flags $f "0x0000000d"
1589 # retry w/o failure injection
1590 do_facet $SINGLEMDS lctl set_param fail_loc=0
1592 # to be sure previous RESTORE result is gone
1594 wait_for_grace_delay
1596 diff -q /etc/hosts $f
1599 # we check we had a restore done
1600 wait_request_state $fid RESTORE SUCCEED
1602 [[ $st -eq 0 ]] || error "Restored file differs"
1604 run_test 12o "Layout-swap failure during Restore leaves file released"
1607 # test needs a running copytool
1611 local f=$DIR/$tdir/$tfile
1612 local fid=$(copy_file /etc/hosts $f)
1614 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1615 wait_request_state $fid ARCHIVE SUCCEED
1616 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1617 $LFS hsm_release $f || error "cannot release $f"
1618 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1619 $LFS hsm_release $f || error "cannot release $f"
1620 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1622 run_test 12p "implicit restore of a file on copytool mount point"
1625 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1626 skip "need MDS version at least 2.7.58"
1628 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1629 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1630 error "cannot mount $MOUNT3 on $SINGLEAGT"
1632 # test needs a running copytool
1633 copytool setup -m "$MOUNT3"
1635 local f=$DIR/$tdir/$tfile
1636 local f2=$DIR2/$tdir/$tfile
1637 local fid=$(create_small_file $f)
1638 local orig_size=$(stat -c "%s" $f)
1640 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1641 wait_request_state $fid ARCHIVE SUCCEED
1643 $LFS hsm_release $f || error "could not release file"
1644 check_hsm_flags $f "0x0000000d"
1647 wait_copytools || error "copytool failed to stop"
1649 cat $f > /dev/null &
1651 # wait a bit to allow implicit restore request to be handled.
1652 # if not, next stat would also block on layout-lock.
1655 local size=$(stat -c "%s" $f2)
1656 [ $size -eq $orig_size ] ||
1657 error "$f2: wrong size after archive: $size != $orig_size"
1659 copytool setup -m "$MOUNT3"
1663 size=$(stat -c "%s" $f)
1664 [ $size -eq $orig_size ] ||
1665 error "$f: wrong size after restore: $size != $orig_size"
1667 size=$(stat -c "%s" $f2)
1668 [ $size -eq $orig_size ] ||
1669 error "$f2: wrong size after restore: $size != $orig_size"
1673 size=$(stat -c "%s" $f)
1675 error "$f: wrong size after overwrite: $size != 0"
1677 size=$(stat -c "%s" $f2)
1679 error "$f2: wrong size after overwrite: $size != 0"
1681 run_test 12q "file attributes are refreshed after restore"
1685 for i in {1..10}; do
1686 local archive_dir="$(hsm_root)"/subdir/dir.$i
1688 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1689 for j in {1..10}; do
1690 local archive_file="$archive_dir"/file.$j
1692 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1698 copytool import "subdir" "$DIR/$tdir"
1700 # To check the import, the test uses diff with the -r flag
1701 # This is nice, but diff only checks files one by one, and triggering
1702 # an implicit restore for one file at a time will consume as many
1703 # seconds as there are files to compare. To speed this up, a restore
1704 # operation is triggered manually first.
1706 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1708 # Compare the imported data
1709 do_facet $SINGLEAGT \
1710 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1711 error "imported files differ from archived data"
1713 run_test 13 "Recursively import and restore a directory"
1716 # test needs a running copytool
1720 local f=$DIR/$tdir/$tfile
1721 local fid=$(create_small_file $f)
1722 local sum=$(md5sum $f | awk '{print $1}')
1723 $LFS hsm_archive $f || error "could not archive file"
1724 wait_request_state $fid ARCHIVE SUCCEED
1726 # create released file (simulate llapi_hsm_import call)
1727 local fid2=$(create_empty_file "$f")
1728 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1729 $LFS hsm_release $f || error "could not release file"
1731 # rebind the archive to the newly created file
1732 echo "rebind $fid to $fid2"
1734 copytool rebind $fid $fid2
1736 # restore file and compare md5sum
1737 local sum2=$(md5sum $f | awk '{print $1}')
1739 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1741 run_test 14 "Rebind archived file to a new fid"
1744 # test needs a running copytool
1748 local f=$DIR/$tdir/$tfile
1750 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1754 for i in $(seq 1 $count); do
1755 fids[$i]=$(create_small_file $f.$i)
1756 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1757 $LFS hsm_archive $f.$i || error "could not archive file"
1759 wait_all_done $(($count*60))
1761 stack_trap "rm -f $tmpfile" EXIT
1764 for i in $(seq 1 $count); do
1765 local fid2=$(create_empty_file "${f}.${i}")
1766 # add the rebind operation to the list
1767 echo ${fids[$i]} $fid2 >> $tmpfile
1769 # set it released (simulate llapi_hsm_import call)
1770 $LFS hsm_set --archived --exists $f.$i ||
1771 error "could not force hsm flags"
1772 $LFS hsm_release $f.$i || error "could not release file"
1774 nl=$(wc -l < $tmpfile)
1775 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1777 echo "rebind list of files"
1778 copytool rebind "$tmpfile"
1780 # restore files and compare md5sum
1781 for i in $(seq 1 $count); do
1782 local sum2=$(md5sum $f.$i | awk '{print $1}')
1783 [[ $sum2 == ${sums[$i]} ]] ||
1784 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1787 run_test 15 "Rebind a list of files"
1790 # test needs a running copytool
1794 # create a known size file so we can verify transfer speed
1797 dd if=/dev/zero of=$ref bs=1M count=20
1800 local f=$DIR/$tdir/$tfile
1801 local fid=$(copy_file $ref $f)
1803 local start=$(date +%s)
1805 wait_request_state $fid ARCHIVE SUCCEED
1806 local end=$(date +%s)
1807 # Add 1 to account for rounding errors between start and end (LU-8155)
1808 local duration=$((end - start + 1))
1810 [[ $duration -ge $((goal - 1)) ]] ||
1811 error "Transfer is too fast $duration < $goal"
1813 run_test 16 "Test CT bandwith control option"
1816 local f=$DIR/$tdir/$tfile
1817 create_empty_file "$f"
1819 # Could not release a non-archived file
1820 $LFS hsm_release $f && error "release should not succeed"
1822 # For following tests, we must test them with HS_ARCHIVED set
1823 $LFS hsm_set --exists --archived $f || error "could not add flag"
1825 # Could not release a file if no-release is set
1826 $LFS hsm_set --norelease $f || error "could not add flag"
1827 $LFS hsm_release $f && error "release should not succeed"
1828 $LFS hsm_clear --norelease $f || error "could not remove flag"
1830 # Could not release a file if lost
1831 $LFS hsm_set --lost $f || error "could not add flag"
1832 $LFS hsm_release $f && error "release should not succeed"
1833 $LFS hsm_clear --lost $f || error "could not remove flag"
1835 # Could not release a file if dirty
1836 $LFS hsm_set --dirty $f || error "could not add flag"
1837 $LFS hsm_release $f && error "release should not succeed"
1838 $LFS hsm_clear --dirty $f || error "could not remove flag"
1840 run_test 20 "Release is not permitted"
1843 # test needs a running copytool
1846 local f=$DIR/$tdir/test_release
1848 # Create a file and check its states
1849 local fid=$(create_small_file $f)
1850 check_hsm_flags $f "0x00000000"
1852 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1853 # used until file is flushed to disk
1854 if [ $(facet_fstype ost1) == "zfs" ]; then
1855 # this causes an OST_SYNC rpc to be sent
1856 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1857 # clear locks to reread file data
1858 cancel_lru_locks osc
1861 local orig_size=$(stat -c "%s" $f)
1862 local orig_blocks=$(stat -c "%b" $f)
1864 start_full_debug_logging
1866 $LFS hsm_archive $f || error "could not archive file"
1867 wait_request_state $fid ARCHIVE SUCCEED
1869 local blocks=$(stat -c "%b" $f)
1870 [ $blocks -eq $orig_blocks ] ||
1871 error "$f: wrong block number after archive: " \
1872 "$blocks != $orig_blocks"
1873 local size=$(stat -c "%s" $f)
1874 [ $size -eq $orig_size ] ||
1875 error "$f: wrong size after archive: $size != $orig_size"
1877 # Release and check states
1878 $LFS hsm_release $f || error "could not release file"
1879 check_hsm_flags $f "0x0000000d"
1881 blocks=$(stat -c "%b" $f)
1882 [ $blocks -gt 5 ] &&
1883 error "$f: too many blocks after release: $blocks > 5"
1884 size=$(stat -c "%s" $f)
1885 [ $size -ne $orig_size ] &&
1886 error "$f: wrong size after release: $size != $orig_size"
1888 # Check we can release an file without stripe info
1892 check_hsm_flags $f "0x00000000"
1893 $LFS hsm_archive $f || error "could not archive file"
1894 wait_request_state $fid ARCHIVE SUCCEED
1896 # Release and check states
1897 $LFS hsm_release $f || error "could not release file"
1898 check_hsm_flags $f "0x0000000d"
1900 # Release again a file that is already released is OK
1901 $LFS hsm_release $f || fail "second release should succeed"
1902 check_hsm_flags $f "0x0000000d"
1904 stop_full_debug_logging
1906 run_test 21 "Simple release tests"
1909 # test needs a running copytool
1912 local f=$DIR/$tdir/test_release
1913 local swap=$DIR/$tdir/test_swap
1915 # Create a file and check its states
1916 local fid=$(create_small_file $f)
1917 check_hsm_flags $f "0x00000000"
1919 $LFS hsm_archive $f || error "could not archive file"
1920 wait_request_state $fid ARCHIVE SUCCEED
1922 # Release and check states
1923 $LFS hsm_release $f || error "could not release file"
1924 check_hsm_flags $f "0x0000000d"
1926 create_small_file $swap
1927 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1931 run_test 22 "Could not swap a release file"
1934 # test needs a running copytool
1937 local f=$DIR/$tdir/test_mtime
1939 # Create a file and check its states
1940 local fid=$(create_small_file $f)
1941 check_hsm_flags $f "0x00000000"
1943 $LFS hsm_archive $f || error "could not archive file"
1944 wait_request_state $fid ARCHIVE SUCCEED
1946 # Set modification time in the past
1947 touch -m -a -d @978261179 $f
1949 # Release and check states
1950 $LFS hsm_release $f || error "could not release file"
1951 check_hsm_flags $f "0x0000000d"
1953 local MTIME=$(stat -c "%Y" $f)
1954 local ATIME=$(stat -c "%X" $f)
1955 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1956 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1958 run_test 23 "Release does not change a/mtime (utime)"
1961 local file=$DIR/$tdir/$tfile
1970 # test needs a running copytool
1973 fid=$(create_small_file $file)
1975 # Create a file and check its states
1976 check_hsm_flags $file "0x00000000"
1978 # Ensure atime is less than mtime and ctime.
1982 atime0=$(stat -c "%X" $file)
1983 mtime0=$(stat -c "%Y" $file)
1984 ctime0=$(stat -c "%Z" $file)
1986 [ $atime0 -lt $mtime0 ] ||
1987 error "atime $atime0 is not less than mtime $mtime0"
1989 [ $atime0 -lt $ctime0 ] ||
1990 error "atime $atime0 is not less than ctime $ctime0"
1992 # Archive should not change any timestamps.
1993 $LFS hsm_archive $file || error "cannot archive '$file'"
1994 wait_request_state $fid ARCHIVE SUCCEED
1996 atime1=$(stat -c "%X" $file)
1997 mtime1=$(stat -c "%Y" $file)
1998 ctime1=$(stat -c "%Z" $file)
2000 [ $atime0 -eq $atime1 ] ||
2001 error "archive changed atime from $atime0 to $atime1"
2003 [ $mtime0 -eq $mtime1 ] ||
2004 error "archive changed mtime from $mtime0 to $mtime1"
2006 [ $ctime0 -eq $ctime1 ] ||
2007 error "archive changed ctime from $ctime0 to $ctime1"
2009 # Release should not change any timestamps.
2010 $LFS hsm_release $file || error "cannot release '$file'"
2011 check_hsm_flags $file "0x0000000d"
2013 atime1=$(stat -c "%X" $file)
2014 mtime1=$(stat -c "%Y" $file)
2015 ctime1=$(stat -c "%Z" $file)
2017 [ $atime0 -eq $atime1 ] ||
2018 error "release changed atime from $atime0 to $atime1"
2020 [ $mtime0 -eq $mtime1 ] ||
2021 error "release changed mtime from $mtime0 to $mtime1"
2023 [ $ctime0 -eq $ctime1 ] ||
2024 error "release changed ctime from $ctime0 to $ctime1"
2026 # Restore should not change any timestamps.
2027 $LFS hsm_restore $file
2028 wait_request_state $fid RESTORE SUCCEED
2030 atime1=$(stat -c "%X" $file)
2031 mtime1=$(stat -c "%Y" $file)
2032 ctime1=$(stat -c "%Z" $file)
2034 [ $atime0 -eq $atime1 ] ||
2035 error "restore changed atime from $atime0 to $atime1"
2037 [ $mtime0 -eq $mtime1 ] ||
2038 error "restore changed mtime from $mtime0 to $mtime1"
2040 [ $ctime0 -eq $ctime1 ] ||
2041 error "restore changed ctime from $ctime0 to $ctime1"
2044 wait_copytools || error "Copytools failed to stop"
2046 # Once more, after unmount and mount.
2047 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2048 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2050 atime1=$(stat -c "%X" $file)
2051 mtime1=$(stat -c "%Y" $file)
2052 ctime1=$(stat -c "%Z" $file)
2054 [ $atime0 -eq $atime1 ] ||
2055 error "remount changed atime from $atime0 to $atime1"
2057 [ $mtime0 -eq $mtime1 ] ||
2058 error "remount changed mtime from $mtime0 to $mtime1"
2060 [ $ctime0 -eq $ctime1 ] ||
2061 error "remount changed ctime from $ctime0 to $ctime1"
2063 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2066 local file=$DIR/$tdir/$tfile
2072 # Test needs a running copytool.
2075 # Check that root can do HSM actions on a regular user's file.
2076 fid=$(create_small_file $file)
2077 sum0=$(md5sum $file)
2079 chown $RUNAS_ID:$RUNAS_GID $file ||
2080 error "cannot chown '$file' to '$RUNAS_ID'"
2082 chmod ugo-w $DIR/$tdir ||
2083 error "cannot chmod '$DIR/$tdir'"
2085 $LFS hsm_archive $file
2086 wait_request_state $fid ARCHIVE SUCCEED
2088 $LFS hsm_release $file
2089 check_hsm_flags $file "0x0000000d"
2091 $LFS hsm_restore $file
2092 wait_request_state $fid RESTORE SUCCEED
2094 # Check that ordinary user can get HSM state.
2095 $RUNAS $LFS hsm_state $file ||
2096 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2098 $LFS hsm_release $file
2099 check_hsm_flags $file "0x0000000d"
2101 # Check that ordinary user can accessed released file.
2102 sum1=$($RUNAS md5sum $file) ||
2103 error "user '$RUNAS_ID' cannot read '$file'"
2105 [ "$sum0" == "$sum1" ] ||
2106 error "md5sum mismatch for '$file'"
2108 run_test 24b "root can archive, release, and restore user files"
2111 local file=$DIR/$tdir/$tfile
2112 local action=archive
2117 # test needs a running copytool
2122 # Save the default masks and check that cleanup_24c will
2123 # restore the request masks correctly.
2124 user_save=$(get_hsm_param user_request_mask)
2125 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2126 group_save=$(get_hsm_param group_request_mask)
2127 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2128 other_save=$(get_hsm_param other_request_mask)
2129 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2131 [ "$user_save" == RESTORE ] ||
2132 error "user_request_mask is '$user_save' expected 'RESTORE'"
2133 [ "$group_save" == RESTORE ] ||
2134 error "group_request_mask is '$group_save' expected 'RESTORE'"
2135 [ "$other_save" == RESTORE ] ||
2136 error "other_request_mask is '$other_save' expected 'RESTORE'"
2139 create_small_file $file
2140 chown $RUNAS_ID:$GROUP $file ||
2141 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2143 $RUNAS $LFS hsm_$action $file &&
2144 error "$action by user should fail"
2146 set_hsm_param user_request_mask $action
2147 $RUNAS $LFS hsm_$action $file ||
2148 error "$action by user should succeed"
2151 create_small_file $file
2152 chown nobody:$RUNAS_GID $file ||
2153 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2155 $RUNAS $LFS hsm_$action $file &&
2156 error "$action by group should fail"
2158 set_hsm_param group_request_mask $action
2159 $RUNAS $LFS hsm_$action $file ||
2160 error "$action by group should succeed"
2163 create_small_file $file
2164 chown nobody:$GROUP $file ||
2165 error "cannot chown '$file' to 'nobody:$GROUP'"
2167 $RUNAS $LFS hsm_$action $file &&
2168 error "$action by other should fail"
2170 set_hsm_param other_request_mask $action
2171 $RUNAS $LFS hsm_$action $file ||
2172 error "$action by other should succeed"
2174 run_test 24c "check that user,group,other request masks work"
2177 local file1=$DIR/$tdir/$tfile
2178 local file2=$DIR2/$tdir/$tfile
2182 fid1=$(create_small_file $file1)
2185 $LFS getstripe $file1
2187 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2188 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2189 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2191 copytool setup -m "$MOUNT3"
2193 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2194 mount -o remount,ro $MOUNT2
2196 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2198 fid2=$(path2fid $file2)
2199 [ "$fid1" == "$fid2" ] ||
2200 error "FID mismatch '$fid1' != '$fid2'"
2202 $LFS hsm_archive $file2 &&
2203 error "archive should fail on read-only mount"
2204 check_hsm_flags $file1 "0x00000000"
2206 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2207 wait_request_state $fid1 ARCHIVE SUCCEED
2209 $LFS hsm_release $file1
2210 $LFS hsm_restore $file2
2211 wait_request_state $fid1 RESTORE SUCCEED
2213 $LFS hsm_release $file1 || error "cannot release '$file1'"
2214 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2216 $LFS hsm_release $file2 &&
2217 error "release should fail on read-only mount"
2221 run_test 24d "check that read-only mounts are respected"
2226 local f=$DIR/$tdir/$tfile
2229 fid=$(create_small_file $f) || error "cannot create $f"
2230 $LFS hsm_archive $f || error "cannot archive $f"
2231 wait_request_state $fid ARCHIVE SUCCEED
2232 $LFS hsm_release $f || error "cannot release $f"
2233 while ! $LFS hsm_state $f | grep released; do
2237 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2239 run_test 24e "tar succeeds on HSM released files" # LU-6213
2242 # test needs a running copytool
2245 mkdir -p $DIR/$tdir/d1
2246 local f=$DIR/$tdir/$tfile
2247 local fid=$(copy_file /etc/hosts $f)
2250 $LFS hsm_archive $f ||
2251 error "hsm_archive failed"
2252 wait_request_state $fid ARCHIVE SUCCEED
2253 $LFS hsm_release $f || error "cannot release $f"
2254 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2257 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2258 error "Can not recover the tar contents"
2260 echo "Sum0 = $sum0, sum1 = $sum1"
2261 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2263 run_test 24f "root can archive, release, and restore tar files"
2266 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2267 skip "need MDS version 2.11.56 or later"
2269 local file=$DIR/$tdir/$tfile
2272 echo "RUNAS = '$RUNAS'"
2277 chmod ugo+rwx $DIR/$tdir
2279 echo "Please listen carefully as our options have changed." | tee $file
2280 fid=$(path2fid $file)
2283 $LFS hsm_archive $file
2284 wait_request_state $fid ARCHIVE SUCCEED
2285 check_hsm_flags $file 0x00000009 # exists archived
2287 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2288 check_hsm_flags $file 0x0000000b # exists dirty archived
2290 run_test 24g "write by non-owner still sets dirty" # LU-11369
2293 # test needs a running copytool
2297 copy2archive /etc/hosts $tdir/$tfile
2299 local f=$DIR/$tdir/$tfile
2301 copytool import $tdir/$tfile $f
2303 $LFS hsm_set --lost $f
2308 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2310 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2311 " (Operation not permitted)"
2314 # test needs a running copytool
2319 local f=$DIR/$tdir/$tfile
2320 local fid=$(copy_file /etc/passwd $f)
2322 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2323 wait_request_state $fid ARCHIVE SUCCEED
2326 $LFS hsm_set --lost $f
2330 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2332 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2333 " (Operation not permitted)"
2335 test_26A() { # was test_26
2336 # test needs a running copytool
2339 local f=$DIR/$tdir/$tfile
2340 local fid=$(create_empty_file "$f")
2342 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2343 wait_request_state $fid ARCHIVE SUCCEED
2346 wait_request_state $fid REMOVE SUCCEED
2348 check_hsm_flags $f "0x00000000"
2350 run_test 26A "Remove the archive of a valid file"
2353 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2354 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2356 # test needs a running copytool
2360 local f=$DIR/$tdir/$tfile
2361 local fid=$(copy_file /etc/passwd $f)
2363 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2364 wait_request_state $fid ARCHIVE SUCCEED
2366 local f2=$DIR/$tdir/${tfile}_2
2367 local fid2=$(copy_file /etc/passwd $f2)
2369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2370 wait_request_state $fid2 ARCHIVE SUCCEED
2372 local f3=$DIR/$tdir/${tfile}_3
2373 local fid3=$(copy_file /etc/passwd $f3)
2375 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2376 wait_request_state $fid3 ARCHIVE SUCCEED
2378 # set a long grace_delay vs short loop_period
2379 local orig_loop_period=$(get_hsm_param loop_period)
2380 local orig_grace_delay=$(get_hsm_param grace_delay)
2381 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2382 set_hsm_param loop_period 10
2383 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2384 set_hsm_param grace_delay 100
2388 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2389 set_hsm_param remove_archive_on_last_unlink 1
2391 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2396 wait_request_state $fid2 REMOVE SUCCEED
2398 assert_request_count $fid REMOVE 0 \
2399 "Unexpected archived data remove request for $f"
2400 assert_request_count $fid3 REMOVE 0 \
2401 "Unexpected archived data remove request for $f3"
2403 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2406 # test needs a running copytool
2410 local f=$DIR/$tdir/$tfile
2411 local fid=$(copy_file /etc/passwd $f)
2413 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2414 wait_request_state $fid ARCHIVE SUCCEED
2416 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2417 set_hsm_param remove_archive_on_last_unlink 1
2420 cdt_check_state stopped
2424 wait_request_state $fid REMOVE WAITING
2428 # copytool must re-register
2430 wait_copytools || error "copytool failed to stop"
2433 wait_request_state $fid REMOVE SUCCEED
2435 run_test 26b "RAoLU policy when CDT off"
2438 # test needs a running copytool
2442 local f=$DIR/$tdir/$tfile
2443 local fid=$(copy_file /etc/passwd $f)
2445 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2446 wait_request_state $fid ARCHIVE SUCCEED
2448 local f2=$DIR/$tdir/${tfile}_2
2449 local fid2=$(copy_file /etc/passwd $f2)
2451 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2452 wait_request_state $fid2 ARCHIVE SUCCEED
2454 # set a long grace_delay vs short loop_period
2455 local orig_loop_period=$(get_hsm_param loop_period)
2456 local orig_grace_delay=$(get_hsm_param grace_delay)
2457 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2458 set_hsm_param loop_period 10
2459 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2460 set_hsm_param grace_delay 100
2462 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2463 set_hsm_param remove_archive_on_last_unlink 1
2465 multiop_bg_pause $f O_c || error "open $f failed"
2471 wait_request_state $fid2 REMOVE SUCCEED
2472 assert_request_count $fid REMOVE 0 \
2473 "Unexpected archived data remove request for $f"
2475 kill -USR1 $pid || error "multiop early exit"
2476 # should reach autotest timeout if multiop fails to trap
2477 # signal, close file, and exit ...
2478 wait $pid || error "wait PID $PID failed"
2480 wait_request_state $fid REMOVE SUCCEED
2482 run_test 26c "RAoLU effective when file closed"
2485 # test needs a running copytool
2489 local f=$DIR/$tdir/$tfile
2490 local fid=$(create_small_file $f)
2492 $LFS hsm_archive $f || error "could not archive file"
2493 wait_request_state $fid ARCHIVE SUCCEED
2495 # set a long grace_delay vs short loop_period
2496 local orig_loop_period=$(get_hsm_param loop_period)
2497 local orig_grace_delay=$(get_hsm_param grace_delay)
2498 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2499 set_hsm_param loop_period 10
2500 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2501 set_hsm_param grace_delay 100
2503 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2504 set_hsm_param remove_archive_on_last_unlink 1
2506 multiop_bg_pause $f O_c || error "multiop failed"
2513 wait_request_state $fid REMOVE SUCCEED
2515 client_up || client_up || true
2517 kill -USR1 $MULTIPID
2518 wait $MULTIPID || error "multiop close failed"
2520 run_test 26d "RAoLU when Client eviction"
2523 # test needs a running copytool
2526 create_archive_file $tdir/$tfile
2527 local f=$DIR/$tdir/$tfile
2528 copytool import $tdir/$tfile $f
2529 local fid=$(path2fid $f)
2533 [[ $? != 0 ]] || error "Remove of a released file should fail"
2535 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2538 # test needs a running copytool
2541 local f=$DIR/$tdir/$tfile
2542 local fid=$(create_empty_file "$f")
2544 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2545 wait_request_state $fid ARCHIVE SUCCEED
2550 [[ $? != 0 ]] || error "Remove of a released file should fail"
2552 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2555 # test needs a running copytool
2558 local f=$DIR/$tdir/$tfile
2559 local fid=$(create_empty_file "$f")
2561 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2562 wait_request_state $fid ARCHIVE SUCCEED
2571 wait_request_state $fid REMOVE SUCCEED
2573 run_test 28 "Concurrent archive/file remove"
2576 # Tests --mntpath and --archive options
2579 copytool setup -m "$MOUNT" -a $archive_id
2581 # Bad archive number
2582 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2583 grep "Invalid argument" ||
2584 error "unexpected hsm_remove failure (1)"
2586 # mntpath is present but file is given
2587 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2588 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2589 error "unexpected hsm_remove failure (2)"
2591 run_test 29a "Tests --mntpath and --archive options"
2594 # test needs a running copytool
2597 local f=$DIR/$tdir/$tfile
2598 local fid=$(create_small_file $f)
2600 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2601 wait_request_state $fid ARCHIVE SUCCEED
2605 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2606 wait_request_state $fid REMOVE SUCCEED
2608 run_test 29b "Archive/delete/remove by FID from the archive."
2611 # test needs a running copytool
2614 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2615 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2616 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2618 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2619 wait_request_state $fid1 ARCHIVE SUCCEED
2620 wait_request_state $fid2 ARCHIVE SUCCEED
2621 wait_request_state $fid3 ARCHIVE SUCCEED
2623 rm -f $DIR/$tdir/$tfile-[1-3]
2625 echo $fid1 > $DIR/$tdir/list
2626 echo $fid2 >> $DIR/$tdir/list
2627 echo $fid3 >> $DIR/$tdir/list
2629 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2630 --filelist $DIR/$tdir/list
2631 wait_request_state $fid1 REMOVE SUCCEED
2632 wait_request_state $fid2 REMOVE SUCCEED
2633 wait_request_state $fid3 REMOVE SUCCEED
2635 run_test 29c "Archive/delete/remove by FID, using a file list."
2638 # test needs more than one CT
2639 needclients 3 || return 0
2645 # start all of the copytools
2646 for n in $(seq $AGTCOUNT); do
2647 copytool setup -f agt$n -a $n
2651 file=$DIR/$tdir/$tfile
2652 fid=$(create_small_file $file)
2654 $LFS hsm_archive $file
2655 wait_request_state $fid ARCHIVE SUCCEED
2656 check_hsm_flags $file "0x00000009"
2660 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2661 error "cannot hsm_remove '$fid'"
2663 # give time for CDT to handle remove request and create broadcasted
2666 # remove request has been broadcasted ?
2667 local cnt=$(get_request_count $fid REMOVE)
2668 # broadcasted requests + original
2669 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2670 error "remove not broadcasted to all CTs"
2672 # give time for CDT and CTs to handle broadcasted
2673 wait_for_loop_period
2675 # each agent serves one different archive_id, so broadcasted
2676 # hsm_remove request should only succeed once and fail at all others
2680 for n in $(seq $AGTCOUNT); do
2681 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2682 $HSM_PARAM.actions | awk \
2683 '/'$fid'.*action=REMOVE archive#='$n'/ \
2684 {print \\\$13}' | cut -f2 -d=")
2685 if [[ "$res" == "SUCCEED" ]]; then
2687 elif [[ "$res" == "FAILED" ]]; then
2692 [[ $scnt -eq 1 ]] ||
2693 error "one and only CT should have removed successfully"
2695 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2696 error "all but one CT should have failed to remove"
2698 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2699 "request to be sent once for each registered archive_id"
2702 # restore at exec cannot work on agent node (because of Linux kernel
2703 # protection of executables)
2704 needclients 2 || return 0
2706 # test needs a running copytool
2710 copy2archive /bin/true $tdir/$tfile
2712 local f=$DIR/$tdir/true
2713 copytool import $tdir/$tfile $f
2715 local fid=$(path2fid $f)
2717 stack_trap "cdt_clear_no_retry" EXIT
2718 # set no retry action mode
2725 [[ $st == 0 ]] || error "Failed to exec a released file"
2727 run_test 30a "Restore at exec (import case)"
2730 # restore at exec cannot work on agent node (because of Linux kernel
2731 # protection of executables)
2732 needclients 2 || return 0
2734 # test needs a running copytool
2738 local f=$DIR/$tdir/true
2739 local fid=$(copy_file /bin/true $f)
2741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2742 wait_request_state $fid ARCHIVE SUCCEED
2746 stack_trap cdt_clear_no_retry EXIT
2747 # set no retry action mode
2755 [[ $st == 0 ]] || error "Failed to exec a released file"
2757 run_test 30b "Restore at exec (release case)"
2760 needclients 2 || return 0
2762 # test needs a running copytool
2766 local f=$DIR/$tdir/SLEEP
2767 local slp_sum1=$(md5sum /bin/sleep)
2768 local fid=$(copy_file /bin/sleep $f)
2770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2771 wait_request_state $fid ARCHIVE SUCCEED
2773 check_hsm_flags $f "0x0000000d"
2775 stack_trap cdt_clear_no_retry EXIT
2776 # set no retry action mode
2779 do_node $CLIENT2 "$f 10" &
2783 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2785 [[ $? == 0 ]] || error "Execution failed during run"
2787 if [[ $? != 0 ]]; then
2788 local slp_sum2=$(md5sum /bin/sleep)
2789 # in case sleep file is modified during the test
2790 [[ $slp_sum1 == $slp_sum2 ]] &&
2791 error "Binary overwritten during exec"
2794 check_hsm_flags $f "0x00000009"
2796 run_test 30c "Update during exec of released file must fail"
2798 restore_and_check_size() {
2801 local s=$(stat -c "%s" $f)
2803 local st=$(get_hsm_flags $f)
2807 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2809 n=$(stat -c "%s" $f)
2810 # we echo in both cases to show stat is not hang
2811 if [[ $n != $s ]]; then
2812 echo "size seen is $n != $s"
2815 echo "size seen is right: $n == $s"
2819 st=$(get_hsm_flags $f)
2821 if [[ "$st" = "0x00000009" ]]; then
2824 echo " restore is too long"
2825 wait_request_state $fid RESTORE SUCCEED
2831 # test needs a running copytool
2834 create_archive_file $tdir/$tfile
2835 local f=$DIR/$tdir/$tfile
2836 copytool import $tdir/$tfile $f
2837 local fid=$($LFS path2fid $f)
2840 restore_and_check_size $f $fid
2843 [[ $err -eq 0 ]] || error "File size changed during restore"
2845 run_test 31a "Import a large file and check size during restore"
2849 # test needs a running copytool
2852 local f=$DIR/$tdir/$tfile
2853 local fid=$(create_file "$f" 1MB 39)
2855 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2856 wait_request_state $fid ARCHIVE SUCCEED
2859 restore_and_check_size $f $fid
2862 [[ $err -eq 0 ]] || error "File size changed during restore"
2864 run_test 31b "Restore a large unaligned file and check size during restore"
2867 # test needs a running copytool
2870 local f=$DIR/$tdir/$tfile
2871 local fid=$(create_file "$f" 1M 39)
2873 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2874 wait_request_state $fid ARCHIVE SUCCEED
2877 restore_and_check_size $f $fid
2880 [[ $err -eq 0 ]] || error "File size changed during restore"
2882 run_test 31c "Restore a large aligned file and check size during restore"
2885 local f=$DIR/$tdir/$tfile
2886 local fid=$(create_empty_file "$f")
2890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2891 wait_request_state $fid ARCHIVE SUCCEED
2894 # Prevent restore from completing
2898 md5sum $f >/dev/null &
2901 wait_request_state $fid RESTORE STARTED
2906 # Check restore trigger process was killed
2908 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2910 run_test 33 "Kill a restore waiting process"
2913 # test needs a running copytool
2916 local f=$DIR/$tdir/$tfile
2917 local fid=$(create_empty_file "$f")
2919 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2920 wait_request_state $fid ARCHIVE SUCCEED
2923 # Prevent restore from completing
2926 md5sum $f >/dev/null &
2929 wait_request_state $fid RESTORE STARTED
2931 # rm must not block during restore
2932 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2935 wait_request_state $fid RESTORE SUCCEED
2937 # Check md5sum pgm finished
2938 kill -0 $pid && error "Restore initiatior still running"
2939 wait $pid || error "Restore initiator failed with $?"
2941 # Check the file was actually deleted
2942 [ ! -f "$f" ] || error "$f was not deleted"
2944 run_test 34 "Remove file during restore"
2947 # test needs a running copytool
2950 local f=$DIR/$tdir/$tfile
2951 local f1=$DIR/$tdir/$tfile-1
2952 local fid=$(create_empty_file "$f")
2953 local fid1=$(copy_file /etc/passwd $f1)
2955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2956 wait_request_state $fid ARCHIVE SUCCEED
2959 # Prevent restore from completing
2962 md5sum $f >/dev/null &
2965 wait_request_state $fid RESTORE STARTED
2967 # mv must not block during restore
2968 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2971 wait_request_state $fid RESTORE SUCCEED
2973 # Check md5sum pgm finished
2974 kill -0 $pid && error "Restore initiatior still running"
2975 wait $pid || error "Restore initiator failed with $?"
2977 local fid2=$(path2fid $f)
2978 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2980 run_test 35 "Overwrite file during restore"
2983 # test needs a running copytool
2986 local f=$DIR/$tdir/$tfile
2987 local fid=$(create_empty_file "$f")
2989 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2990 wait_request_state $fid ARCHIVE SUCCEED
2993 # Prevent restore from completing
2996 md5sum $f >/dev/null &
2999 wait_request_state $fid RESTORE STARTED
3001 # mv must not block during restore
3002 timeout --signal=KILL 10 mv "$f" "$f.new" ||
3003 error "mv '$f' '$f.new' failed with rc=$?"
3006 wait_request_state $fid RESTORE SUCCEED
3008 # Check md5sum pgm finished
3009 kill -0 $pid && error "Restore initiator is still running"
3010 wait $pid || error "Restore initiator failed with $?"
3012 run_test 36 "Move file during restore"
3015 # LU-5683: check that an archived dirty file can be rearchived.
3018 local f=$DIR/$tdir/$tfile
3021 fid=$(create_small_file $f) || error "cannot create small file"
3023 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3024 wait_request_state $fid ARCHIVE SUCCEED
3025 $LFS hsm_release $f || error "cannot release $f"
3027 # Allow previous archive request to expire from the actions log.
3028 wait_for_grace_delay
3031 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3033 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3034 wait_request_state $fid ARCHIVE SUCCEED
3036 run_test 37 "re-archive a dirty file"
3043 for n in $(seq 1 $count); do
3044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3046 echo "$count archive requests submitted"
3050 local stream_count=4
3051 local file_count=100
3053 local f=$DIR/$tdir/$tfile
3057 local max_requests=$(get_hsm_param max_requests)
3059 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3060 # Increase the number of HSM request that can be performed in
3061 # parallel. With the coordinator running once per second, this
3062 # also limits the number of requests per seconds that can be
3063 # performed, so we pick a decent number. But we also need to keep
3064 # that number low because the copytool has no rate limit and will
3065 # fail some requests if if gets too many at once.
3066 set_hsm_param max_requests 300
3068 for i in $(seq 1 $file_count); do
3069 for p in $(seq 1 $stream_count); do
3070 fid=$(copy_file /etc/hosts $f.$p.$i)
3076 # to be sure wait_all_done will not be mislead by previous tests
3078 wait_for_grace_delay
3080 # start archive streams in background (archive files in parallel)
3081 for p in $(seq 1 $stream_count); do
3082 multi_archive $f.$p $file_count &
3085 echo -n "Wait for all requests being enqueued..."
3090 run_test 40 "Parallel archive requests"
3093 # test needs a running copytool
3097 local f=$DIR/$tdir/$tfile
3098 local fid=$(create_small_file $f)
3100 $LFS hsm_archive $f || error "could not archive file"
3101 wait_request_state $fid ARCHIVE SUCCEED
3102 check_hsm_flags $f "0x00000009"
3104 multiop_bg_pause $f O_c || error "multiop failed"
3108 client_up || client_up || true
3110 kill -USR1 $MULTIPID
3111 wait $MULTIPID || error "multiop close failed"
3113 check_hsm_flags $f "0x0000000b"
3115 run_test 52 "Opened for write file on an evicted client should be set dirty"
3118 # test needs a running copytool
3122 local f=$DIR/$tdir/$tfile
3123 local fid=$(create_small_file $f)
3125 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3126 error "could not archive file"
3127 wait_request_state $fid ARCHIVE SUCCEED
3128 check_hsm_flags $f "0x00000009"
3130 multiop_bg_pause $f o_c || error "multiop failed"
3134 client_up || client_up || true
3136 kill -USR1 $MULTIPID
3137 wait $MULTIPID || error "multiop close failed"
3139 check_hsm_flags $f "0x00000009"
3141 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3144 local f=$DIR/$tdir/$tfile
3145 local fid=$(create_file "$f" 1MB 39)
3149 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3150 error "could not archive file"
3151 wait_request_state $fid ARCHIVE STARTED
3153 check_hsm_flags $f "0x00000001"
3155 stack_trap "cdt_clear_no_retry" EXIT
3156 # Avoid coordinator resending this request as soon it has failed.
3161 wait_request_state $fid ARCHIVE FAILED
3163 check_hsm_flags $f "0x00000003"
3165 run_test 54 "Write during an archive cancels it"
3168 local f=$DIR/$tdir/$tfile
3169 local fid=$(create_file "$f" 1MB 39)
3173 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3174 error "could not archive file"
3175 wait_request_state $fid ARCHIVE STARTED
3177 check_hsm_flags $f "0x00000001"
3179 stack_trap "cdt_clear_no_retry" EXIT
3180 # Avoid coordinator resending this request as soon it has failed.
3183 $TRUNCATE $f 1024 || error "truncate failed"
3185 wait_request_state $fid ARCHIVE FAILED
3187 check_hsm_flags $f "0x00000003"
3189 run_test 55 "Truncate during an archive cancels it"
3192 local f=$DIR/$tdir/$tfile
3193 local fid=$(create_file "$f" 1MB 39)
3197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3198 error "could not archive file"
3199 wait_request_state $fid ARCHIVE STARTED
3201 check_hsm_flags $f "0x00000001"
3203 # Change metadata and sync to be sure we are not changing only
3208 wait_request_state $fid ARCHIVE SUCCEED
3210 check_hsm_flags $f "0x00000009"
3212 run_test 56 "Setattr during an archive is ok"
3215 # Need one client for I/O, one for request
3216 needclients 2 || return 0
3218 # test needs a running copytool
3222 local f=$DIR/$tdir/test_archive_remote
3223 # Create a file on a remote node
3224 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3225 "count=2 conv=fsync"
3228 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3229 error "hsm_archive failed"
3230 local fid=$(path2fid $f)
3231 wait_request_state $fid ARCHIVE SUCCEED
3233 # Release and implicit restore it
3234 do_node $CLIENT2 "$LFS hsm_release $f" ||
3235 error "hsm_release failed"
3236 do_node $CLIENT2 "md5sum $f" ||
3237 error "hsm_restore failed"
3239 wait_request_state $fid RESTORE SUCCEED
3241 run_test 57 "Archive a file with dirty cache on another node"
3243 truncate_released_file() {
3247 local sz=$(stat -c %s $src_file)
3248 local f=$DIR/$tdir/$tfile
3249 local fid=$(copy_file $1 $f)
3253 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3254 error "could not archive file"
3255 wait_request_state $fid ARCHIVE SUCCEED
3257 $LFS hsm_release $f || error "could not release file"
3259 $TRUNCATE $f $trunc_to || error "truncate failed"
3262 local sz1=$(stat -c %s $f)
3263 [[ $sz1 == $trunc_to ]] ||
3264 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3267 check_hsm_flags $f "0x0000000b"
3269 local state=$(get_request_state $fid RESTORE)
3270 [[ "$state" == "SUCCEED" ]] ||
3271 error "truncate $sz does not trig restore, state = $state"
3273 $TRUNCATE $ref $trunc_to
3274 cmp $ref $f || error "file data wrong after truncate"
3280 # test needs a running copytool
3285 local sz=$(stat -c %s /etc/passwd)
3287 echo "truncate up from $sz to $((sz*2))"
3288 truncate_released_file /etc/passwd $((sz*2))
3290 echo "truncate down from $sz to $((sz/2))"
3291 truncate_released_file /etc/passwd $((sz/2))
3293 echo "truncate to 0"
3294 truncate_released_file /etc/passwd 0
3296 run_test 58 "Truncate a released file will trigger restore"
3300 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3301 skip "Need MDS version at least 2.7.63"
3304 $MCREATE $DIR/$tfile || error "mcreate failed"
3305 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3306 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3307 fid=$(path2fid $DIR/$tfile)
3308 wait_request_state $fid ARCHIVE SUCCEED
3309 $LFS hsm_release $DIR/$tfile || error "release failed"
3311 run_test 59 "Release stripeless file with non-zero size"
3314 # This test validates the fix for LU-4512. Ensure that the -u
3315 # option changes the progress reporting interval from the
3316 # default (30 seconds) to the user-specified interval.
3317 local f=$DIR/$tdir/$tfile
3318 local fid=$(create_file "$f" 1M 10)
3321 local progress_timeout=$((interval * 4))
3322 copytool setup -b 1 --update-interval $interval
3325 local mdt=${MDT_PREFIX}${mdtidx}
3326 local mds=mds$((mdtidx + 1))
3328 # Wait for copytool to register
3329 wait_update_facet $mds \
3330 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3331 uuid 100 || error "coyptool failed to register with $mdt"
3333 local start_at=$(date +%s)
3334 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3335 error "could not archive file"
3337 local agent=$(facet_active_host $SINGLEAGT)
3338 local logfile=$(copytool_logfile $SINGLEAGT)
3340 wait_update $agent \
3341 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3342 error "copytool failed to start"
3344 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3345 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3351 echo -n "Expecting a progress update within $progress_timeout seconds... "
3353 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3354 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3355 echo "$RESULT bytes copied in $WAIT seconds."
3357 elif [ $WAIT -ge $progress_timeout ]; then
3358 error "Timed out waiting for progress update!"
3361 WAIT=$((WAIT + sleep))
3365 local finish_at=$(date +%s)
3366 local elapsed=$((finish_at - start_at))
3368 # Ensure that the progress update occurred within the expected window.
3369 if [ $elapsed -lt $((interval - 1)) ]; then
3370 error "Expected progress update after at least $interval seconds"
3373 echo "Wait for on going archive hsm action to complete"
3374 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3375 echo "File archiving not completed even after 10 secs"
3377 run_test 60 "Changing progress update interval from default"
3380 # test needs a running copytool
3384 local f=$DIR/$tdir/$tfile
3385 local fid=$(copy_file /etc/passwd $f)
3387 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3390 wait_request_state $fid ARCHIVE FAILED
3392 run_test 61 "Waiting archive of a removed file should fail"
3395 # test needs a new running copytool
3396 stack_trap copytool_monitor_cleanup EXIT
3397 copytool_monitor_setup
3398 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3400 # Wait for the copytool to register.
3401 wait_update --verbose $(facet_active_host mds1) \
3402 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3404 error "copytool failed to register with MDT0000"
3407 wait_copytools || error "Copytools failed to stop"
3409 local REGISTER_EVENT
3410 local UNREGISTER_EVENT
3411 while read event; do
3412 local parsed=$(parse_json_event "$event")
3413 if [ -z "$parsed" ]; then
3414 error "Copytool sent malformed event: $event"
3418 if [ $event_type == "REGISTER" ]; then
3419 REGISTER_EVENT=$event
3420 elif [ $event_type == "UNREGISTER" ]; then
3421 UNREGISTER_EVENT=$event
3423 done < <(echo $"$(get_copytool_event_log)")
3425 if [ -z "$REGISTER_EVENT" ]; then
3426 error "Copytool failed to send register event to FIFO"
3429 if [ -z "$UNREGISTER_EVENT" ]; then
3430 error "Copytool failed to send unregister event to FIFO"
3433 echo "Register/Unregister events look OK."
3435 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3438 # Bump progress interval for livelier events.
3441 # test needs a new running copytool
3442 stack_trap copytool_monitor_cleanup EXIT
3443 copytool_monitor_setup
3444 copytool setup --update-interval $interval --event-fifo \
3445 "$HSMTOOL_MONITOR_DIR/fifo"
3447 stack_trap "cdt_clear_no_retry" EXIT
3448 # Just start and stop the copytool to generate events.
3451 local f=$DIR/$tdir/$tfile
3452 local fid=$(create_small_file "$f")
3454 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3455 error "could not archive file"
3456 wait_request_state $fid ARCHIVE SUCCEED
3458 local expected_fields="event_time data_fid source_fid"
3459 expected_fields+=" total_bytes current_bytes"
3462 [ARCHIVE_START]=false
3463 [ARCHIVE_FINISH]=false
3464 [ARCHIVE_RUNNING]=false
3466 while read event; do
3467 # Make sure we're not getting anything from previous events.
3468 for field in $expected_fields; do
3472 local parsed=$(parse_json_event "$event")
3473 if [ -z "$parsed" ]; then
3474 error "Copytool sent malformed event: $event"
3478 events["$event_type"]=true
3480 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3482 # Do some simple checking of the progress update events.
3483 for expected_field in $expected_fields; do
3484 if [ -z ${!expected_field+x} ]; then
3485 error "Missing $expected_field field in event"
3489 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3491 # These should be identical throughout an archive operation
3492 [ $source_fid == $data_fid ] ||
3493 error "Expected source_fid to equal data_fid"
3494 done < <(echo $"$(get_copytool_event_log)")
3496 # Check we received every type of events we were expecting
3497 for event in "${!events[@]}"; do
3498 ${events["$event"]} ||
3499 error "Copytool failed to send '$event' event to FIFO"
3502 echo "Archive events look OK."
3504 run_test 71 "Copytool logs JSON archive events to FIFO"
3507 # Bump progress interval for livelier events.
3510 # test needs a new running copytool
3511 stack_trap copytool_monitor_cleanup EXIT
3512 copytool_monitor_setup
3513 copytool setup --update-interval $interval --event-fifo \
3514 "$HSMTOOL_MONITOR_DIR/fifo"
3515 local test_file=$HSMTOOL_MONITOR_DIR/file
3517 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3519 do_facet $SINGLEAGT "$cmd" ||
3520 error "cannot create $test_file on $SINGLEAGT"
3521 copy2archive $test_file $tdir/$tfile
3524 local f=$DIR/$tdir/$tfile
3525 copytool import $tdir/$tfile $f
3526 f=$DIR2/$tdir/$tfile
3527 echo "Verifying released state: "
3528 check_hsm_flags $f "0x0000000d"
3530 local fid=$(path2fid $f)
3532 wait_request_state $fid RESTORE SUCCEED
3534 local expected_fields="event_time data_fid source_fid"
3535 expected_fields+=" total_bytes current_bytes"
3539 while read event; do
3540 # Make sure we're not getting anything from previous events.
3541 for field in $expected_fields; do
3545 local parsed=$(parse_json_event "$event")
3546 if [ -z "$parsed" ]; then
3547 error "Copytool sent malformed event: $event"
3551 if [ $event_type == "RESTORE_START" ]; then
3553 if [ $source_fid != $data_fid ]; then
3554 error "source_fid should == data_fid at start"
3557 elif [ $event_type == "RESTORE_FINISH" ]; then
3559 if [ $source_fid != $data_fid ]; then
3560 error "source_fid should == data_fid at finish"
3563 elif [ $event_type != "RESTORE_RUNNING" ]; then
3567 # Do some simple checking of the progress update events.
3568 for expected_field in $expected_fields; do
3569 if [ -z ${!expected_field+x} ]; then
3570 error "Missing $expected_field field in event"
3574 if [ $total_bytes -eq 0 ]; then
3575 error "Expected total_bytes to be > 0"
3578 # When a restore starts out, the data fid is the same as the
3579 # source fid. After the restore has gotten going, we learn
3580 # the new data fid. Once the restore has finished, the source
3581 # fid is set to the new data fid.
3583 # We test this because some monitoring software may depend on
3584 # this behavior. If it changes, then the consumers of these
3585 # events may need to be modified.
3586 if [ $source_fid == $data_fid ]; then
3587 error "source_fid should != data_fid during restore"
3589 done < <(echo $"$(get_copytool_event_log)")
3591 if [ -z "$START_EVENT" ]; then
3592 error "Copytool failed to send restore start event to FIFO"
3595 if [ -z "$FINISH_EVENT" ]; then
3596 error "Copytool failed to send restore finish event to FIFO"
3599 echo "Restore events look OK."
3601 run_test 72 "Copytool logs JSON restore events to FIFO"
3604 file_count=51 # Max number of files constrained by LNET message size
3605 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3606 local f=$DIR/$tdir/$tfile
3607 local FILELIST=/tmp/filelist.txt
3611 for i in $(seq 1 $file_count); do
3612 fid=$(copy_file /etc/hosts $f.$i)
3613 echo $f.$i >> $FILELIST
3617 # to be sure wait_all_done will not be mislead by previous tests
3619 wait_for_grace_delay
3620 $LFS hsm_archive --filelist $FILELIST ||
3621 error "cannot archive a file list"
3623 $LFS hsm_release --filelist $FILELIST ||
3624 error "cannot release a file list"
3625 $LFS hsm_restore --filelist $FILELIST ||
3626 error "cannot restore a file list"
3629 run_test 90 "Archive/restore a file list"
3631 double_verify_reset_hsm_param() {
3633 echo "Testing $HSM_PARAM.$p"
3634 local val=$(get_hsm_param $p)
3636 local val2=$(($val * 2))
3637 set_hsm_param $p $val2
3638 val=$(get_hsm_param $p)
3639 [[ $val == $val2 ]] ||
3640 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3641 echo "Set $p to 0 must failed"
3645 set_hsm_param $p $save
3647 if [[ $rc == 0 ]]; then
3648 error "we must not be able to set $HSM_PARAM.$p to 0"
3653 double_verify_reset_hsm_param loop_period
3654 double_verify_reset_hsm_param grace_delay
3655 double_verify_reset_hsm_param active_request_timeout
3656 double_verify_reset_hsm_param max_requests
3657 double_verify_reset_hsm_param default_archive_id
3659 run_test 100 "Set coordinator /proc tunables"
3666 run_test 102 "Verify coordinator control"
3669 # test needs a running copytool
3676 for i in $(seq 1 20); do
3677 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3679 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3683 echo "Current requests"
3684 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3685 $HSM_PARAM.actions |\
3686 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3688 [[ -z "$res" ]] || error "Some request have not been canceled"
3690 run_test 103 "Purge all requests"
3695 local f=$DIR/$tdir/$tfile
3696 local fid=$(create_empty_file "$f")
3698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3699 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3700 $HSM_PARAM.actions |\
3701 grep $fid | cut -f16 -d=")
3703 [[ "$data1" == "$DATAHEX" ]] ||
3704 error "Data field in records is ($data1) and not ($DATAHEX)"
3708 run_test 104 "Copy tool data field"
3711 local max_requests=$(get_hsm_param max_requests)
3715 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3716 set_hsm_param max_requests 300
3719 for i in $(seq -w 1 10); do
3720 cp /etc/passwd $DIR/$tdir/$i
3721 $LFS hsm_archive $DIR/$tdir/$i
3723 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3724 $HSM_PARAM.actions |\
3725 grep WAITING | wc -l")
3729 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3730 $HSM_PARAM.actions |\
3731 grep WAITING | wc -l")
3734 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3735 error "Requests count after shutdown $reqcnt2 != "\
3736 "before shutdown $reqcnt1"
3738 run_test 105 "Restart of coordinator"
3741 # test needs a running copytool
3744 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3746 check_agent_registered $uuid
3748 search_copytools || error "No copytool found"
3751 wait_copytools || error "Copytool failed to stop"
3753 check_agent_unregistered $uuid
3756 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3757 check_agent_registered $uuid
3759 run_test 106 "Copytool register/unregister"
3762 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3764 # test needs a running copytool
3766 # create and archive file
3768 local f1=$DIR/$tdir/$tfile
3769 local fid=$(copy_file /etc/passwd $f1)
3770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3771 wait_request_state $fid ARCHIVE SUCCEED
3772 # shutdown and restart MDS
3774 # check the copytool still gets messages from MDT
3775 local f2=$DIR/$tdir/2
3776 local fid=$(copy_file /etc/passwd $f2)
3777 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3778 # main check of this sanity: this request MUST succeed
3779 wait_request_state $fid ARCHIVE SUCCEED
3781 run_test 107 "Copytool re-register after MDS restart"
3783 policy_set_and_test()
3787 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3788 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3789 [[ "$policy" == "$target" ]] ||
3790 error "Wrong policy after '$change': '$policy' != '$target'"
3794 # to force default policy setting if error
3795 CDT_POLICY_HAD_CHANGED=true
3797 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3798 local default="NonBlockingRestore [NoRetryAction]"
3799 [[ "$policy" == "$default" ]] ||
3800 error "default policy has changed,"\
3801 " '$policy' != '$default' update the test"
3802 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3803 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3804 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3805 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3806 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3807 # useless bacause we know but safer for futur changes to use real value
3808 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3809 echo "Next set_param must failed"
3810 policy_set_and_test "wrong" "$policy"
3813 echo "Back to default policy"
3814 cdt_set_sanity_policy
3816 run_test 109 "Policy display/change"
3819 # test needs a running copytool
3824 copy2archive /etc/passwd $tdir/$tfile
3826 local f=$DIR/$tdir/$tfile
3827 copytool import $tdir/$tfile $f
3828 local fid=$(path2fid $f)
3830 cdt_set_non_blocking_restore
3835 wait_request_state $fid RESTORE SUCCEED
3836 cdt_clear_non_blocking_restore
3840 error "md5sum returns $st != 1, "\
3841 "should also perror ENODATA (No data available)"
3843 run_test 110a "Non blocking restore policy (import case)"
3846 # test needs a running copytool
3850 local f=$DIR/$tdir/$tfile
3851 local fid=$(copy_file /etc/passwd $f)
3852 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3853 wait_request_state $fid ARCHIVE SUCCEED
3856 cdt_set_non_blocking_restore
3861 wait_request_state $fid RESTORE SUCCEED
3862 cdt_clear_non_blocking_restore
3866 error "md5sum returns $st != 1, "\
3867 "should also perror ENODATA (No data available)"
3869 run_test 110b "Non blocking restore policy (release case)"
3872 # test needs a running copytool
3876 copy2archive /etc/passwd $tdir/$tfile
3878 local f=$DIR/$tdir/$tfile
3880 copytool import $tdir/$tfile $f
3881 local fid=$(path2fid $f)
3885 copytool_remove_backend $fid
3888 wait_request_state $fid RESTORE FAILED
3895 [[ $st == 0 ]] || error "Restore does not failed"
3897 run_test 111a "No retry policy (import case), restore will error"\
3898 " (No such file or directory)"
3901 # test needs a running copytool
3905 local f=$DIR/$tdir/$tfile
3906 local fid=$(copy_file /etc/passwd $f)
3907 stack_trap cdt_clear_no_retry EXIT
3909 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3910 wait_request_state $fid ARCHIVE SUCCEED
3913 copytool_remove_backend $fid
3916 wait_request_state $fid RESTORE FAILED
3920 [[ $st == 0 ]] || error "Restore does not failed"
3922 run_test 111b "No retry policy (release case), restore will error"\
3923 " (No such file or directory)"
3926 # test needs a running copytool
3930 local f=$DIR/$tdir/$tfile
3931 local fid=$(copy_file /etc/passwd $f)
3933 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3934 local l=$($LFS hsm_action $f)
3936 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3939 wait_request_state $fid ARCHIVE SUCCEED
3942 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3944 run_test 112 "State of recorded request"
3947 local f=$DIR/$tdir/$tfile
3948 local fid=$(create_empty_file "$f")
3952 # Prevent archive from completing
3955 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3956 # wait archive to register at CDT
3957 wait_request_state $fid ARCHIVE STARTED
3959 # Cancel the archive
3960 $LFS hsm_cancel "$f"
3962 wait_request_state $fid ARCHIVE CANCELED
3965 wait_request_state $fid CANCEL SUCCEED
3967 run_test 200 "Register/Cancel archive"
3970 # test needs a running copytool
3973 local f=$DIR/$tdir/$tfile
3974 create_archive_file $tdir/$tfile
3975 copytool import $tdir/$tfile $f
3976 local fid=$(path2fid $f)
3978 # test with cdt on is made in test_222
3981 # wait restore to register at CDT
3982 wait_request_state $fid RESTORE WAITING
3985 wait_request_state $fid RESTORE CANCELED
3986 wait_request_state $fid CANCEL SUCCEED
3988 run_test 201 "Register/Cancel restore"
3991 local f=$DIR/$tdir/$tfile
3992 local fid=$(create_empty_file "$f")
3994 # test needs a running copytool
3997 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3998 wait_request_state $fid ARCHIVE SUCCEED
4002 # wait remove to register at CDT
4003 wait_request_state $fid REMOVE STARTED
4006 wait_request_state $fid REMOVE CANCELED
4008 run_test 202 "Register/Cancel remove"
4010 test_220A() { # was test_220
4011 # test needs a running copytool
4016 local f=$DIR/$tdir/$tfile
4017 local fid=$(copy_file /etc/passwd $f)
4021 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4022 wait_request_state $fid ARCHIVE SUCCEED
4024 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4025 error "The expected changelog was not emitted"
4027 run_test 220A "Changelog for archive"
4030 # test needs a running copytool
4035 local f=$DIR/$tdir/$tfile
4036 local fid=$(copy_file /etc/passwd $f)
4040 # block copytool operations to allow for HSM request to be
4041 # submitted and file be unlinked (CDT will find object removed)
4044 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4046 # wait request to reach CT
4047 wait_request_state $fid ARCHIVE STARTED
4053 wait_request_state $fid ARCHIVE FAILED
4056 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4057 error "The expected changelog was not emitted"
4059 run_test 220a "Changelog for failed archive"
4062 local f=$DIR/$tdir/$tfile
4063 local fid=$(create_empty_file "$f")
4068 # Prevent archive from completing
4070 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4071 wait_request_state $fid ARCHIVE STARTED
4074 wait_request_state $fid ARCHIVE CANCELED
4077 wait_request_state $fid CANCEL SUCCEED
4079 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4080 error "The expected changelog was not emitted"
4082 run_test 221 "Changelog for archive canceled"
4085 # test needs a running copytool
4089 copy2archive /etc/passwd $tdir/$tfile
4091 local f=$DIR/$tdir/$tfile
4092 copytool import $tdir/$tfile $f
4093 local fid=$(path2fid $f)
4098 wait_request_state $fid RESTORE SUCCEED
4100 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4101 error "The expected changelog was not emitted"
4103 run_test 222a "Changelog for explicit restore"
4106 # test needs a running copytool
4110 local f=$DIR/$tdir/$tfile
4111 local fid=$(copy_file /etc/passwd $f)
4114 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4115 wait_request_state $fid ARCHIVE SUCCEED
4120 wait_request_state $fid RESTORE SUCCEED
4122 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4123 error "The expected changelog was not emitted"
4125 run_test 222b "Changelog for implicit restore"
4128 # test needs a running copytool
4132 copy2archive /etc/passwd $tdir/$tfile
4134 local f=$DIR/$tdir/$tfile
4135 copytool import $tdir/$tfile $f
4136 local fid=$(path2fid $f)
4140 # block copytool operations to allow for HSM request to be
4141 # submitted and file be unlinked (CDT will find object removed)
4146 # wait request to reach CT
4147 wait_request_state $fid RESTORE STARTED
4153 wait_request_state $fid RESTORE FAILED
4156 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4157 error "The expected changelog was not emitted"
4159 run_test 222c "Changelog for failed explicit restore"
4162 # test needs a running copytool
4166 local f=$DIR/$tdir/$tfile
4167 local fid=$(copy_file /etc/passwd $f)
4170 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4171 wait_request_state $fid ARCHIVE SUCCEED
4174 copytool_remove_backend $fid
4177 wait_request_state $fid RESTORE FAILED
4180 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4181 error "The expected changelog was not emitted"
4183 run_test 222d "Changelog for failed implicit restore"
4186 # test needs a running copytool
4189 local f=$DIR/$tdir/$tfile
4190 create_archive_file $tdir/$tfile
4194 copytool import $tdir/$tfile $f
4195 local fid=$(path2fid $f)
4198 wait_request_state $fid RESTORE STARTED
4200 wait_request_state $fid RESTORE CANCELED
4201 wait_request_state $fid CANCEL SUCCEED
4203 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4204 error "The expected changelog was not emitted"
4206 run_test 223a "Changelog for restore canceled (import case)"
4209 local f=$DIR/$tdir/$tfile
4210 local fid=$(create_empty_file "$f")
4215 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4216 wait_request_state $fid ARCHIVE SUCCEED
4219 # Prevent restore from completing
4222 wait_request_state $fid RESTORE STARTED
4225 wait_request_state $fid RESTORE CANCELED
4228 wait_request_state $fid CANCEL SUCCEED
4230 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4231 error "The expected changelog was not emitted"
4233 run_test 223b "Changelog for restore canceled (release case)"
4235 test_224A() { # was test_224
4236 # test needs a running copytool
4241 local f=$DIR/$tdir/$tfile
4242 local fid=$(copy_file /etc/passwd $f)
4245 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4246 wait_request_state $fid ARCHIVE SUCCEED
4249 wait_request_state $fid REMOVE SUCCEED
4251 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4252 error "The expected changelog was not emitted"
4254 run_test 224A "Changelog for remove"
4257 # test needs a running copytool
4262 local f=$DIR/$tdir/$tfile
4263 local fid=$(copy_file /etc/passwd $f)
4266 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4267 wait_request_state $fid ARCHIVE SUCCEED
4269 copytool_remove_backend $fid
4271 # block copytool operations to allow for HSM request to be
4272 # submitted and file be unlinked (CDT will find object removed)
4277 # wait for request to reach CT
4278 wait_request_state $fid REMOVE STARTED
4284 wait_request_state $fid REMOVE FAILED
4286 # HE_REMOVE|ENOENT=0x202
4287 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4288 error "The expected changelog was not emitted"
4290 run_test 224a "Changelog for failed remove"
4293 # test is not usable because remove request is too fast
4294 # so it is always finished before cancel can be done ...
4295 echo "Test disabled"
4298 # test needs a running copytool
4301 local f=$DIR/$tdir/$tfile
4302 local fid=$(create_empty_file "$f")
4305 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4306 wait_request_state $fid ARCHIVE SUCCEED
4308 # Prevent restore from completing
4313 wait_request_state $fid REMOVE CANCELED
4316 wait_request_state $fid CANCEL SUCCEED
4318 changelog_find -type HSM -target-fid $fid -flags 0x27d
4319 error "The expected changelog was not emitted"
4321 run_test 225 "Changelog for remove canceled"
4324 # test needs a running copytool
4329 local f1=$DIR/$tdir/$tfile-1
4330 local f2=$DIR/$tdir/$tfile-2
4331 local f3=$DIR/$tdir/$tfile-3
4332 local fid1=$(copy_file /etc/passwd $f1)
4333 local fid2=$(copy_file /etc/passwd $f2)
4334 copy_file /etc/passwd $f3
4337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4338 wait_request_state $fid1 ARCHIVE SUCCEED
4340 $LFS hsm_archive $f2
4341 wait_request_state $fid2 ARCHIVE SUCCEED
4343 rm $f1 || error "rm $f1 failed"
4346 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4347 error "The expected changelog was not emitted"
4349 mv $f3 $f2 || error "mv $f3 $f2 failed"
4351 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4352 error "The expected changelog was not emitted"
4354 run_test 226 "changelog for last rm/mv with exiting archive"
4356 # This is just a utility function to clarify what test_227 does
4361 "$LFS" "$action" --$flag "$file" ||
4362 error "Cannot ${action#hsm_} $flag on '$file'"
4364 # Only one changelog should be produced
4365 local entries="$(changelog_find -type HSM -target-fid $fid)"
4366 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4367 error "lfs $action --$flag '$file' produced more than one" \
4370 # Parse the last changelog record
4371 local entry="$(tail -n 1 <<< "$entries")"
4372 eval local -A changelog=$(changelog2array $entry)
4374 # Also check the flags match what is expected
4375 [[ ${changelog[flags]} == $target ]] ||
4376 error "Changelog flag is '${changelog[flags]}', not $target"
4380 local file="$DIR/$tdir/$tfile"
4381 local fid=$(create_empty_file "$file")
4386 for flag in norelease noarchive exists archived lost; do
4387 if [ "$flag" == lost ]; then
4388 # The flag "lost" only works on an archived file
4389 "$LFS" hsm_set --archived "$file"
4393 action="hsm_set" __test_227
4394 action="hsm_clear" __test_227
4397 run_test 227 "changelog when explicit setting of HSM flags"
4400 # test needs a running copytool
4403 local fid=$(create_small_sync_file $DIR/$tfile)
4404 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4405 wait_request_state $fid ARCHIVE SUCCEED
4407 $LFS hsm_release $DIR/$tfile
4408 check_hsm_flags $DIR/$tfile "0x0000000d"
4410 filefrag $DIR/$tfile | grep " 1 extent found" ||
4411 error "filefrag on released file must return only one extent"
4413 # only newer versions of cp detect sparse files by stat/FIEMAP
4415 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4416 error "copying $DIR/$tfile"
4417 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4419 $LFS hsm_release $DIR/$tfile
4420 check_hsm_flags $DIR/$tfile "0x0000000d"
4422 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4424 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4426 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4427 error "comparing untarred $DIR/$tfile"
4429 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4430 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4432 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4435 local file="$DIR/$tdir/$tfile"
4437 # set max_requests to allow one request of each type to be started (3)
4439 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4440 set_hsm_param max_requests 3
4443 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4444 set_hsm_param loop_period 1
4446 # send 1 requests of each kind twice
4449 for action in archive restore remove; do
4450 local filepath="$file"-to-$action
4451 local fid=$(create_empty_file "$filepath")
4452 local fid2=$(create_empty_file "$filepath".bis)
4454 if [ "$action" != archive ]; then
4455 "$LFS" hsm_archive "$filepath"
4456 wait_request_state $fid ARCHIVE SUCCEED
4457 "$LFS" hsm_archive "$filepath".bis
4458 wait_request_state $fid2 ARCHIVE SUCCEED
4460 if [ "$action" == restore ]; then
4461 "$LFS" hsm_release "$filepath"
4462 "$LFS" hsm_release "$filepath".bis
4466 # suspend the copytool to prevent requests from completing
4467 stack_trap "copytool_continue" EXIT
4470 # send `max_requests' requests (one of each kind)
4471 for action in archive restore remove; do
4472 filepath="$file"-to-$action
4473 "$LFS" hsm_${action} "$filepath"
4474 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4477 # send another batch of requests
4478 for action in archive restore remove; do
4479 "$LFS" hsm_${action} "$file-to-$action".bis
4481 # wait for `loop_period' seconds to make sure the coordinator has time
4482 # to register those, even though it should not
4485 # only the first batch of request should be started
4487 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4491 error "expected 3 STARTED requests, found $count"
4493 run_test 250 "Coordinator max request"
4496 local f=$DIR/$tdir/$tfile
4497 local fid=$(create_empty_file "$f")
4500 # to have a short test
4501 local old_to=$(get_hsm_param active_request_timeout)
4502 set_hsm_param active_request_timeout 1
4503 # to be sure the cdt will wake up frequently so
4504 # it will be able to cancel the "old" request
4505 local old_loop=$(get_hsm_param loop_period)
4506 set_hsm_param loop_period 1
4511 # Prevent archive from completing
4513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4514 wait_request_state $fid ARCHIVE STARTED
4516 # Let the request timeout
4517 wait_request_state $fid ARCHIVE CANCELED
4519 set_hsm_param active_request_timeout $old_to
4520 set_hsm_param loop_period $old_loop
4522 run_test 251 "Coordinator request timeout"
4525 local f=$DIR/$tdir/$tfile
4526 local fid=$(create_empty_file "$f")
4528 # to have a short test
4529 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4530 set_hsm_param loop_period 1
4534 # Prevent archive from completing
4536 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4537 wait_request_state $fid ARCHIVE STARTED
4540 stack_trap "set_hsm_param active_request_timeout \
4541 $(get_hsm_param active_request_timeout)" EXIT
4542 set_hsm_param active_request_timeout 1
4544 wait_request_state $fid ARCHIVE CANCELED
4547 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4551 # test needs a running copytool
4555 local f=$DIR/$tdir/$tfile
4557 dd if=/dev/zero of=$f bs=1MB count=10
4558 local fid=$(path2fid $f)
4560 $LFS hsm_archive $f || error "could not archive file"
4561 wait_request_state $fid ARCHIVE SUCCEED
4563 # clear locks to discard inode data
4564 cancel_lru_locks osc
4566 #define OBD_FAIL_MDC_MERGE 0x807
4567 $LCTL set_param fail_loc=0x807
4569 #expect error here, instead of release with wrong size
4572 if ((rc == 0)); then
4573 file_size=$(stat -c '%s' $f)
4574 if ((file_size != 10485760)); then
4575 error "Wrong file size after hsm_release"
4578 echo "could not release file"
4581 run_test 253 "Check for wrong file size after release"
4585 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4586 skip "need MDS version at least 2.10.56"
4588 # Check that the counters are initialized to 0
4590 for request_type in archive restore remove; do
4591 count="$(get_hsm_param ${request_type}_count)" ||
4592 error "Reading ${request_type}_count failed with $?"
4594 [ "$count" -eq 0 ] ||
4595 error "Expected ${request_type}_count to be " \
4599 run_test 254a "Request counters are initialized to zero"
4603 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4604 skip "need MDS version at least 2.10.56"
4606 # The number of request to launch (at least 32)
4607 local request_count=$((RANDOM % 32 + 32))
4608 printf "Will launch %i requests of each type\n" "$request_count"
4610 # Launch a copytool to process requests
4613 # Set hsm.max_requests to allow starting all requests at the same time
4615 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4616 set_hsm_param max_requests "$request_count"
4620 for request_type in archive restore remove; do
4621 printf "Checking %s requests\n" "${request_type}"
4622 # Suspend the copytool to give us time to read the proc files
4625 for ((i = 0; i < $request_count; i++)); do
4626 case $request_type in
4628 create_empty_file "$DIR/$tdir/$tfile-$i" \
4632 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4635 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4638 # Give the coordinator 10 seconds to start every request
4640 while get_hsm_param actions | grep -q WAITING; do
4643 [ $timeout -gt 0 ] ||
4644 error "${request_type^} requests took too " \
4648 count="$(get_hsm_param ${request_type}_count)"
4649 [ "$count" -eq "$request_count" ] ||
4650 error "Expected '$request_count' (!= '$count') " \
4651 "active $request_type requests"
4653 # Let the copytool process the requests
4655 # Give it 10 seconds maximum
4657 while get_hsm_param actions | grep -q STARTED; do
4660 [ $timeout -gt 0 ] ||
4661 error "${request_type^} requests took too " \
4665 count="$(get_hsm_param ${request_type}_count)"
4666 [ "$count" -eq 0 ] ||
4667 error "Expected 0 (!= '$count') " \
4668 "active $request_type requests"
4671 run_test 254b "Request counters are correctly incremented and decremented"
4675 local file="$DIR/$tdir/$tfile"
4676 local fid=$(create_empty_file "$file")
4678 # How do you make sure the coordinator has consumed any outstanding
4679 # event, without triggering an event yourself?
4681 # You wait for a request to disappear from the coordinator's llog.
4683 # Warning: the setup represents 90% of this test
4685 # Create and process an HSM request
4687 "$LFS" hsm_archive "$file"
4688 wait_request_state $fid ARCHIVE SUCCEED
4691 wait_copytools || error "failed to stop copytools"
4693 # Launch a new HSM request
4695 create_empty_file "$file"
4696 "$LFS" hsm_archive "$file"
4700 # Have the completed request be removed as soon as the cdt wakes up
4701 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4702 set_hsm_param grace_delay 1
4703 # (Hopefully, time on the MDS will behave nicely)
4704 do_facet $SINGLEMDS sleep 2 &
4706 # Increase `loop_period' as a mean to prevent the coordinator from
4707 # waking itself up to do some housekeeping.
4708 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4709 set_hsm_param loop_period 1000
4711 wait $! || error "waiting failed"
4713 wait_request_state $fid ARCHIVE ""
4714 # The coordinator will not wake up on its own for ~`loop_period' secs...
4716 # ... Unless a copytool registers. Now the real test begins
4718 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4720 run_test 255 "Copytool registration wakes the coordinator up"
4722 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4723 # break in the future because of that.
4726 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4727 skip "need MDS version 2.11.56 or later"
4729 local -a files=("$DIR/$tdir/$tfile".{0..15})
4732 for file in "${files[@]}"; do
4733 create_small_file "$file"
4736 # Set a few hsm parameters
4738 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4739 set_hsm_param loop_period 1
4741 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4742 set_hsm_param max_requests 3
4746 "$LFS" hsm_archive "${files[0]}"
4747 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4748 "$LFS" hsm_release "${files[0]}"
4752 wait_copytools || error "copytools failed to stop"
4754 # Send several archive requests
4755 for file in "${files[@]:1}"; do
4756 "$LFS" hsm_archive "$file"
4759 # Send one restore request
4760 "$LFS" hsm_restore "${files[0]}"
4765 # Wait for all the requests to complete
4766 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4767 for file in "${files[@]:1}"; do
4768 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4771 # Collect the actions in the order in which the copytool processed them
4773 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4774 "$(copytool_logfile "$SINGLEAGT")")
4777 printf '%s\n' "${actions[@]}"
4780 for action in "${actions[@]:0:3}"; do
4781 [ "$action" == RESTORE ] && return
4784 error "Too many ARCHIVE requests were run before the RESTORE request"
4786 run_test 260a "Restore request have priority over other requests"
4788 # This test is very much tied to the implementation of the current priorisation
4789 # mechanism in the coordinator. It might not make sense to keep it in the future
4792 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4793 skip "need MDS version 2.11.56 or later"
4795 local -a files=("$DIR/$tdir/$tfile".{0..15})
4798 for file in "${files[@]}"; do
4799 create_small_file "$file"
4802 # Set a few hsm parameters
4804 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4805 set_hsm_param loop_period 1
4807 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4808 set_hsm_param max_requests 3
4811 copytool setup --archive-id 2
4812 "$LFS" hsm_archive --archive 2 "${files[0]}"
4813 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4814 "$LFS" hsm_release "${files[0]}"
4818 wait_copytools || error "copytools failed to stop"
4820 # Send several archive requests
4821 for file in "${files[@]:1}"; do
4822 "$LFS" hsm_archive "$file"
4825 # Send one restore request
4826 "$LFS" hsm_restore "${files[0]}"
4830 copytool setup --archive-id 2
4832 # Wait for all the requests to complete
4833 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4834 for file in "${files[@]:1}"; do
4835 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4838 # Collect the actions in the order in which the copytool processed them
4840 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4841 "$(copytool_logfile "$SINGLEAGT")")
4844 printf '%s\n' "${actions[@]}"
4847 for action in "${actions[@]:0:3}"; do
4848 [ "$action" == RESTORE ] && return
4851 error "Too many ARCHIVE requests were run before the RESTORE request"
4853 run_test 260b "Restore request have priority over other requests"
4855 # This test is very much tied to the implementation of the current priorisation
4856 # mechanism in the coordinator. It might not make sense to keep it in the future
4859 local -a files=("$DIR/$tdir/$tfile".{0..15})
4862 for file in "${files[@]}"; do
4863 create_small_file "$file"
4866 # Set a few hsm parameters
4868 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4869 set_hsm_param loop_period 1000
4871 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4872 set_hsm_param max_requests 3
4875 copytool setup --archive-id 2
4876 "$LFS" hsm_archive --archive 2 "${files[0]}"
4877 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4878 "$LFS" hsm_release "${files[0]}"
4882 wait_copytools || error "copytools failed to stop"
4884 # Force the next coordinator run to do housekeeping
4888 "$LFS" hsm_archive "${files[1]}"
4892 copytool setup --archive-id 2
4894 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4895 # The coordinator just did a housekeeping run it won't do another one
4896 # for around `loop_period' seconds => requests will not be reordered
4897 # if it costs too much (ie. when the coordinator has to discard a whole
4900 # Send several archive requests
4901 for file in "${files[@]:2}"; do
4902 "$LFS" hsm_archive "$file"
4905 # Send one restore request
4906 "$LFS" hsm_restore "${files[0]}"
4908 # Wait for all the requests to complete
4909 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4910 for file in "${files[@]:2}"; do
4911 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4914 # Collect the actions in the order in which the copytool processed them
4916 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4917 "$(copytool_logfile "$SINGLEAGT")")
4920 printf '%s\n' "${actions[@]}"
4923 for action in "${actions[@]:0:3}"; do
4924 [ "$action" == RESTORE ] &&
4925 error "Restore requests should not be prioritised" \
4926 "unless the coordinator is doing housekeeping"
4930 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4933 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4935 # the only way to test ondisk conf is to restart MDS ...
4936 echo "Stop coordinator and remove coordinator state at mount"
4939 # clean on disk conf set by default
4940 cdt_clear_mount_state
4941 cdt_check_state stopped
4943 # check cdt still off after umount/remount
4945 cdt_check_state stopped
4947 echo "Set coordinator start at mount, and start coordinator"
4948 cdt_set_mount_state enabled
4951 cdt_check_state enabled
4953 # check cdt still on after umount/remount
4955 cdt_check_state enabled
4957 # we are back to original state (cdt started at mount)
4959 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4962 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4964 local ai=$(get_hsm_param default_archive_id)
4965 local new=$((ai + 1))
4967 set_hsm_param default_archive_id $new -P
4969 local res=$(get_hsm_param default_archive_id)
4972 set_hsm_param default_archive_id "" "-P -d"
4974 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4976 run_test 301 "HSM tunnable are persistent"
4979 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4981 local ai=$(get_hsm_param default_archive_id)
4982 local new=$((ai + 1))
4987 set_hsm_param default_archive_id $new -P
4990 for mdtno in $(seq 1 $MDSCOUNT); do
4995 cdt_check_state enabled
4997 local res=$(get_hsm_param default_archive_id)
5000 set_hsm_param default_archive_id "" "-P -d"
5002 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5004 run_test 302 "HSM tunnable are persistent when CDT is off"
5007 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5013 local dir_mdt0=$DIR/$tdir/mdt0
5014 local dir_mdt1=$DIR/$tdir/mdt1
5016 # create 1 dir per MDT
5017 stack_trap "rm -rf $dir_mdt0" EXIT
5018 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5019 stack_trap "rm -rf $dir_mdt1" EXIT
5020 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5022 # create 1 file in each MDT
5023 local fid1=$(create_small_file $dir_mdt0/$tfile)
5024 local fid2=$(create_small_file $dir_mdt1/$tfile)
5026 # check that hsm request on mdt0 is sent to the right MDS
5027 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5028 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5029 echo "archive successful on mdt0"
5031 # check that hsm request on mdt1 is sent to the right MDS
5032 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5033 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5034 echo "archive successful on mdt1"
5036 run_test 400 "Single request is sent to the right MDT"
5039 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5045 local dir_mdt0=$DIR/$tdir/mdt0
5046 local dir_mdt1=$DIR/$tdir/mdt1
5048 # create 1 dir per MDT
5049 stack_trap "rm -rf $dir_mdt0" EXIT
5050 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5051 stack_trap "rm -rf $dir_mdt1" EXIT
5052 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5054 # create 1 file in each MDT
5055 local fid1=$(create_small_file $dir_mdt0/$tfile)
5056 local fid2=$(create_small_file $dir_mdt1/$tfile)
5058 # check that compound requests are shunt to the rights MDTs
5059 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5060 error "lfs hsm_archive"
5061 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5062 echo "archive successful on mdt0"
5063 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5064 echo "archive successful on mdt1"
5066 run_test 401 "Compound requests split and sent to their respective MDTs"
5068 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5073 local node=$(facet_active_host $facet)
5075 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5076 awk '{print $4}'); do
5077 echo "$3 $mdc on $node"
5078 do_facet $facet "$LCTL --device $mdc $state" || return 1
5083 # deactivate all mdc on agent1
5084 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5086 copytool setup --no-fail
5088 check_agent_unregistered "uuid" # match any agent
5090 # no expected running copytool
5091 search_copytools $agent && error "Copytool start should have failed"
5094 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5096 run_test 402a "Copytool start fails if all MDTs are inactive"
5103 local f=$DIR/$tdir/$tfile
5104 touch $f || error "touch $f failed"
5105 local fid=$(path2fid $f)
5107 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5108 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5109 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5111 # give time for CDT to send request and to keep it for retry
5112 wait_for_loop_period
5114 wait_request_state $fid ARCHIVE WAITING
5116 do_facet $SINGLEAGT lctl set_param fail_loc=0
5118 # request should succeed now
5119 wait_request_state $fid ARCHIVE SUCCEED
5121 run_test 402b "CDT must retry request upon slow start of CT"
5124 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5126 local agent=$(facet_active_host $SINGLEAGT)
5128 # deactivate all mdc for MDT0001
5129 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5132 local uuid=$(get_agent_uuid $agent)
5133 # check the agent is registered on MDT0000, and not on MDT0001
5134 check_agent_registered_by_mdt $uuid 0
5135 check_agent_unregistered_by_mdt $uuid 1
5137 # check running copytool process
5138 search_copytools $agent || error "No running copytools on $agent"
5140 # reactivate all mdc for MDT0001
5141 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5143 # make sure the copytool is now registered to all MDTs
5144 check_agent_registered $uuid
5146 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5149 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5153 # create files on both MDT0000 and MDT0001
5156 local dir_mdt0=$DIR/$tdir/mdt0
5157 stack_trap "rm -rf $dir_mdt0" EXIT
5158 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5160 # create 1 file on mdt0
5161 local fid1=$(create_small_file $dir_mdt0/$tfile)
5163 # deactivate all mdc for MDT0001
5164 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5166 # send an HSM request for files in MDT0000
5167 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5169 # check for completion of files in MDT0000
5170 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5171 echo "archive successful on mdt0"
5173 # reactivate all mdc for MDT0001
5174 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5176 run_test 404 "Inactive MDT does not block requests for active MDTs"
5179 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5185 local striped_dir=$DIR/$tdir/striped_dir
5187 # create striped dir on all of MDTs
5188 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5190 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5191 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5192 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5193 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5195 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5196 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5197 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5198 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5200 # check that compound requests are shunt to the rights MDTs
5201 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5202 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5203 error "lfs hsm_archive"
5205 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5206 echo "archive successful on $fid1"
5207 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5208 echo "archive successful on $fid2"
5209 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5210 echo "archive successful on $fid3"
5211 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5212 echo "archive successful on $fid4"
5214 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5215 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5216 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5217 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5219 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5220 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5221 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5222 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5224 run_test 405 "archive and release under striped directory"
5227 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5229 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5230 skip "need MDS version at least 2.7.64"
5235 fid=$(create_small_file $DIR/$tdir/$tfile)
5240 $LFS hsm_archive $DIR/$tdir/$tfile
5241 wait_request_state "$fid" ARCHIVE SUCCEED
5242 $LFS hsm_release $DIR/$tdir/$tfile
5244 # Should migrate $tdir but not $tfile.
5245 $LFS migrate -m1 $DIR/$tdir &&
5246 error "migrating HSM an archived file should fail"
5248 $LFS hsm_restore $DIR/$tdir/$tfile
5249 wait_request_state "$fid" RESTORE SUCCEED
5251 $LFS hsm_remove $DIR/$tdir/$tfile
5252 wait_request_state "$fid" REMOVE SUCCEED
5254 cat $DIR/$tdir/$tfile > /dev/null ||
5255 error "cannot read $DIR/$tdir/$tfile"
5257 $LFS migrate -m1 $DIR/$tdir ||
5258 error "cannot complete migration after HSM remove"
5260 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5261 if ((mdt_index != 1)); then
5262 error "expected MDT index 1, got $mdt_index"
5265 # Refresh fid after migration.
5266 fid=$(path2fid $DIR/$tdir/$tfile)
5269 $LFS hsm_archive $DIR/$tdir/$tfile
5270 wait_request_state "$fid" ARCHIVE SUCCEED 1
5272 lctl set_param debug=+trace
5273 $LFS hsm_release $DIR/$tdir/$tfile ||
5274 error "cannot release $DIR/$tdir/$tfile"
5276 $LFS hsm_restore $DIR/$tdir/$tfile
5277 wait_request_state "$fid" RESTORE SUCCEED 1
5279 cat $DIR/$tdir/$tfile > /dev/null ||
5280 error "cannot read $DIR/$tdir/$tfile"
5282 run_test 406 "attempting to migrate HSM archived files is safe"
5285 local f=$DIR/$tdir/$tfile
5286 local f2=$DIR2/$tdir/$tfile
5287 local fid=$(create_empty_file "$f")
5291 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5292 wait_request_state $fid ARCHIVE SUCCEED
5295 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5296 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5298 # Prevent restore from completing
5302 # 1st request holds layout lock while appropriate
5303 # RESTORE record is still not added to llog
5307 # after umount hsm_actions->O/x/x log shouldn't have
5308 # double RESTORE records like below
5309 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5310 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5312 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5316 wait_request_state $fid RESTORE SUCCEED
5318 run_test 407 "Check for double RESTORE records in llog"
5322 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5323 skip "HSM migrate is not supported"
5325 test_mkdir -p $DIR/$tdir
5327 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5328 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5330 llapi_hsm_test -d $DIR/$tdir -b ||
5331 error "One llapi HSM test failed"
5333 llapi_hsm_test -d $DIR/$tdir ||
5334 error "One llapi HSM test failed"
5337 run_test 500 "various LLAPI HSM tests"
5340 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5341 skip "need MDS version at least 2.10.58"
5345 local f=$DIR/$tdir/$tfile
5348 # set changelog_mask to ALL
5349 changelog_chmask "ALL"
5351 chmod 777 $DIR/$tdir
5352 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5353 local fid=$(path2fid $f)
5356 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5357 -gid "$RUNAS_GID") ||
5358 error "No matching CREAT entry"
5360 # Parse the changelog
5361 eval local -A changelog=$(changelog2array $entry)
5362 local nid="${changelog[nid]}"
5365 echo "Got NID '$nid'"
5366 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5367 error "nid '$nid' does not match any client NID:" \
5370 run_test 600 "Changelog fields 'u=' and 'nid='"
5373 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5374 skip "need MDS version at least 2.10.58"
5378 local f=$DIR/$tdir/$tfile
5381 # set changelog_mask to ALL
5382 changelog_chmask "ALL"
5384 touch $f || error "touch $f failed"
5385 local fid=$(path2fid $f)
5388 cat $f || error "cat $f failed"
5390 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5391 error "No matching OPEN entry"
5393 run_test 601 "OPEN Changelog entry"
5396 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5397 skip "need MDS version at least 2.10.58"
5401 local f=$DIR/$tdir/$tfile
5404 # set changelog_mask to ALL
5405 changelog_chmask "ALL"
5407 touch $f || error "touch $f failed"
5408 local fid=$(path2fid $f)
5411 cat $f || error "cat $f failed"
5413 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5417 echo f > $f || error "write $f failed"
5420 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5422 # remove OPEN from changelog_mask
5423 changelog_chmask "-OPEN"
5427 cat $f || error "cat $f failed"
5430 changelog_find -type CLOSE -target-fid $fid &&
5431 error "There should be no CLOSE entry"
5435 echo f > $f || error "write $f failed"
5438 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5440 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5443 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5444 skip "need MDS version at least 2.10.58"
5448 local f=$DIR/$tdir/$tfile
5451 # set changelog_mask to ALL
5452 changelog_chmask "ALL"
5454 touch $f || error "touch $f failed"
5455 local fid=$(path2fid $f)
5457 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5460 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5462 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5463 error "No matching GXATR entry"
5465 run_test 603 "GETXATTR Changelog entry"
5468 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5469 skip "need MDS version at least 2.10.58"
5473 local f=$DIR/$tdir/$tfile
5474 local f2=$DIR2/$tdir/$tfile
5475 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5477 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5478 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5479 do_facet mds1 lctl set_param "$procname=20"
5483 # set changelog_mask to ALL
5484 changelog_chmask "ALL"
5486 touch $f || error "touch $f failed"
5487 local fid=$(path2fid $f)
5493 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5497 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5498 -gid "$RUNAS_GID" -mode "r--") ||
5499 error "No matching NOPEN entry"
5501 # Parse the changelog
5502 eval local -A changelog=$(changelog2array $entry)
5503 local nid="${changelog[nid]}"
5506 echo "Got NID '$nid'"
5507 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5508 error "nid '$nid' does not match any client NID:" \
5513 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5516 changelog_find -type NOPEN -target-fid $fid &&
5517 error "There should be no NOPEN entry"
5519 # Sleep for `changelog_deniednext` seconds
5524 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5527 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5528 -gid "$RUNAS_GID" -mode "r--") ||
5529 error "No matching NOPEN entry"
5531 # Parse the changelog
5532 eval local -A changelog=$(changelog2array $entry)
5533 local nid="${changelog[nid]}"
5536 echo "Got NID '$nid'"
5537 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5538 error "nid '$nid' does not match any client NID:" \
5541 run_test 604 "NOPEN Changelog entry"
5544 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5545 skip "need MDS version at least 2.10.58"
5549 local f=$DIR/$tdir/$tfile
5550 local f2=$DIR2/$tdir/$tfile
5553 # set changelog_mask to ALL
5554 changelog_chmask "ALL"
5556 touch $f || error "touch $f failed"
5557 local fid=$(path2fid $f)
5561 exec 3<> $f || error "open $f failed"
5565 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5569 exec 4<> $f || error "open $f failed"
5572 changelog_find -type OPEN -target-fid $fid &&
5573 error "There should be no OPEN entry"
5575 exec 4>&- || error "close $f failed"
5578 changelog_find -type CLOSE -target-fid $fid &&
5579 error "There should be no CLOSE entry"
5583 # access in rw, so different access mode should generate entries
5584 cat $f || error "cat $f failed"
5587 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5589 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5593 # same access as first one, should not generate new entries
5594 exec 4<> $f || error "open $f failed"
5597 changelog_find -type OPEN -target-fid $fid &&
5598 error "There should be no OPEN entry"
5600 exec 4>&- || error "close $f failed"
5603 changelog_find -type CLOSE -target-fid $fid &&
5604 error "There should be no CLOSE entry"
5608 # access by different user should generate new entries
5609 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5612 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5614 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5618 exec 3>&- || error "close $f failed"
5621 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5623 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5626 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5627 skip "need MDS version at least 2.10.58"
5629 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5630 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5631 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5632 skip_env "missing llog_reader" && return
5633 local fstype=$(facet_fstype mds1)
5637 local f=$DIR/$tdir/$tfile
5640 # set changelog_mask to ALL
5641 changelog_chmask "ALL"
5643 chmod 777 $DIR/$tdir
5644 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5645 local fid=$(path2fid $f)
5646 rm $f || error "rm $f failed"
5648 local mntpt=$(facet_mntpt mds1)
5652 #remount mds1 as ldiskfs or zfs type
5653 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5654 stop mds1 || error "stop mds1 failed"
5655 mount_fstype mds1 || error "remount mds1 failed"
5657 for ((i = 0; i < 1; i++)); do
5658 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5659 local cat_file=$(do_facet mds1 $llog_reader \
5660 $mntpt/changelog_catalog | awk \
5661 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5662 [ -n "$cat_file" ] || error "no catalog file"
5664 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5665 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5666 [ -n "$entry" ] || error "no CREAT entry"
5669 local uidgid=$(echo $entry |
5670 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5671 [ -n "$uidgid" ] || error "uidgid is empty"
5672 echo "Got UID/GID $uidgid"
5673 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5674 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5675 local nid=$(echo $entry |
5676 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5677 [ -n "$nid" ] || error "nid is empty"
5679 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5680 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5682 run_test 606 "llog_reader groks changelog fields"
5685 check_and_cleanup_lustre