3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/utils:$PATH:/sbin:/usr/sbin
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 # bug number for skipped tests: LU-9795 LU-9795
19 ALWAYS_EXCEPT=" 13 402b $ALWAYS_EXCEPT"
22 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
24 . $LUSTRE/tests/test-framework.sh
26 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30 MULTIOP=${MULTIOP:-multiop}
31 OPENFILE=${OPENFILE:-openfile}
32 MMAP_CAT=${MMAP_CAT:-mmap_cat}
33 MOUNT_2=${MOUNT_2:-"yes"}
35 MDS_VERSION_CODE=$(lustre_version_code $SINGLEMDS)
37 # script only handles up to 10 MDTs (because of MDT_PREFIX)
38 [ $MDSCOUNT -gt 9 ] &&
39 error "script cannot handle more than 9 MDTs, please fix" && exit
41 check_and_setup_lustre
43 if [[ $MDS_VERSION_CODE -lt $(version_code 2.4.53) ]]; then
44 skip_env "Need MDS version at least 2.4.53"
47 # $RUNAS_ID may get set incorrectly somewhere else
48 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
49 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
51 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
52 if getent group nobody; then
54 elif getent group nogroup; then
57 error "No generic nobody group"
62 # if there is no CLIENT1 defined, some tests can be ran on localhost
63 CLIENT1=${CLIENT1:-$HOSTNAME}
64 # if CLIENT2 doesn't exist then use CLIENT1 instead
65 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
67 # Exception is the test which need two separate nodes
68 CLIENT2=${CLIENT2:-$CLIENT1}
71 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
72 # the following associated variables are added:
74 # AGTCOUNT: number of agents
75 # AGTDEV{N}: target HSM mount point (root path of the backend)
76 # agt{N}_HOST: hostname of the agent agt{N}
77 # SINGLEAGT: facet of the single agent
79 # The number of agents is initialized as the number of remote client nodes.
80 # By default, only single copytool is started on a remote client/agent. If there
81 # was no remote client, then the copytool will be started on the local client.
87 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
88 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
90 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
91 if [[ $CLIENTCOUNT -gt 1 ]] &&
92 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
93 skip_env "SHARED_DIRECTORY should be accessible"\
98 # We used to put the HSM archive in $SHARED_DIRECTORY but that
99 # meant NFS issues could hose sanity-hsm sessions. So now we
101 for n in $(seq $AGTCOUNT); do
102 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
103 agent=CLIENT$((n + 1))
104 if [[ -z "${!agent}" ]]; then
105 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
108 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
111 export SINGLEAGT=${SINGLEAGT:-agt1}
113 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
114 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
115 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
116 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
117 export HSMTOOL_TESTDIR
121 # The test only support up to 10 MDTs
122 MDT_PREFIX="mdt.$FSNAME-MDT000"
123 HSM_PARAM="${MDT_PREFIX}0.hsm"
125 # archive is purged at copytool setup
126 HSM_ARCHIVE_PURGE=true
128 # Don't allow copytool error upon start/setup
129 HSMTOOL_NOERROR=false
132 # Get the backend root path for the given agent facet.
135 local dev=AGTDEV$(facet_number $facet)
142 # get MDT device for each mdc
143 for mdtno in $(seq 1 $MDSCOUNT); do
144 local idx=$(($mdtno - 1))
145 MDT[$idx]=$($LCTL get_param -n \
146 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
147 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
152 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
153 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
157 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
159 echo "Killing existing copytools on $hosts"
160 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
161 copytool_continue "$hosts"
165 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
166 local wait_timeout=200
167 local wait_start=$SECONDS
168 local wait_end=$((wait_start + wait_timeout))
169 local sleep_time=100000 # 0.1 second
171 while ((SECONDS < wait_end)); do
172 if ! search_copytools $hosts; then
173 echo "copytools stopped in $((SECONDS - wait_start))s"
177 echo "copytools still running on $hosts"
179 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
180 sleep_time=$(bc <<< "$sleep_time * 2")
183 # try to dump Copytool's stack
184 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
185 "echo t >/proc/sysrq-trigger"
187 echo "copytools failed to stop in ${wait_timeout}s"
192 copytool_monitor_setup() {
193 local facet=${1:-$SINGLEAGT}
194 local agent=$(facet_active_host $facet)
196 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
197 local test_dir=$(do_node $agent "$cmd") ||
198 error "Failed to create tempdir on $agent"
199 export HSMTOOL_MONITOR_DIR=$test_dir
201 # Create the fifo and a monitor (cat dies when copytool dies)
202 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
203 error "failed to create copytool fifo on $agent"
204 cmd="cat $test_dir/fifo > $test_dir/events &"
205 cmd+=" echo \\\$! > $test_dir/monitor_pid"
207 # This background subshell nonsense is required when pdsh/ssh decides
208 # to wait for the cat process to exit on the remote client
209 (do_node $agent "$cmd") &
210 export HSMTOOL_MONITOR_PDSH=$!
212 # Slightly racy, but just making a best-effort to catch obvious
215 do_node $agent "stat $HSMTOOL_MONITOR_DIR/monitor_pid 2>&1 > /dev/null"
217 error "Failed to start copytool monitor on $agent"
221 copytool_monitor_cleanup() {
222 local facet=${1:-$SINGLEAGT}
223 local agent=$(facet_active_host $facet)
225 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
226 # Should die when the copytool dies, but just in case.
227 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
228 cmd+=" 2>/dev/null || true"
229 do_node $agent "$cmd"
230 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
231 export HSMTOOL_MONITOR_DIR=
234 # The pdsh should die on its own when the monitor dies. Just
235 # in case, though, try to clean up to avoid any cruft.
236 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
237 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
238 export HSMTOOL_MONITOR_PDSH=
248 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
255 local host="$(facet_host "$1")"
256 local prefix=$TESTLOG_PREFIX
257 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
259 printf "${prefix}.copytool${archive_id}_log.${host}.log"
264 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
269 mkdir -p "$(dirname "$2")" ||
270 error "cannot create directory '$(dirname "$2")'"
271 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
276 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
277 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
278 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
279 [ ${#misc_options[@]} -gt 0 ] &&
280 cmd+=" $(IFS=" " echo "$@")"
281 cmd+=" \"$mountpoint\""
283 echo "Starting copytool $facet on $(facet_host $facet)"
284 stack_trap "do_facet $facet libtool execute pkill -x '$HSMTOOL' || true" EXIT
285 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
289 local facet="${1:-$SINGLEAGT}"
291 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
294 # Main entry point to perform copytool related operations
298 # setup setup a copytool to run in the background, that copytool will be
300 # import import a file from an HSM backend
301 # rebind rebind an archived file to a new fid
303 # Although the semantics might suggest otherwise, one does not need to 'setup'
304 # a copytool before a call to 'copytool import' or 'copytool rebind'.
312 local fail_on_error=true
313 local -a misc_options
314 while [ $# -gt 0 ]; do
322 local mountpoint="$1"
326 local archive_id="$1"
330 local bandwidth="$1" # in MB/s
333 local fail_on_error=false
336 # Uncommon(/copytool dependent) option
343 # Use default values if needed
344 local facet=${facet:-$SINGLEAGT}
345 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
346 local hsm_root="$(hsm_root "$facet")"
348 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
349 do_facet $facet mkdir -p "$hsm_root" ||
350 error "mkdir '$hsm_root' failed"
354 local copytool=lhsmtool
358 __${copytool}_${action} "${misc_options[@]}"
359 if [ $? -ne 0 ]; then
364 local host="$(facet_host $facet)"
365 error_msg="Failed to start copytool $facet on '$host'"
368 local src="${misc_options[0]}"
369 local dest="${misc_options[1]}"
370 error_msg="Failed to import '$src' to '$dest'"
373 error_msg="could not rebind file"
377 $fail_on_error && error "$error_msg" || echo "$error_msg"
381 get_copytool_event_log() {
382 local facet=${1:-$SINGLEAGT}
383 local agent=$(facet_active_host $facet)
385 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
386 error "Can't get event log: No monitor directory!"
388 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
389 error "Could not collect event log from $agent"
393 local agents=${1:-$(facet_active_host $SINGLEAGT)}
396 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
397 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
398 echo "Copytool is suspended on $agents"
401 copytool_continue() {
402 local agents=${1:-$(facet_active_host $SINGLEAGT)}
404 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
405 echo "Copytool is continued on $agents"
408 copytool_remove_backend() {
410 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
411 echo "Remove from backend: $fid = $be"
412 do_facet $SINGLEAGT rm -f $be
415 file_creation_failure() {
422 df $MOUNT $MOUNT2 >&2
423 error "Not enough space to create $file with $cmd"
426 error "cannot create $file with $cmd, status=$err"
431 # Creates a file using dd
437 local source=${5:-/dev/zero}
441 if [ -n "$conv" ]; then
445 # Create the directory in case it does not exist
446 mkdir -p "$(dirname "$file")"
447 # Delete the file in case it already exist
450 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
451 path2fid "$file" || error "cannot get FID of '$file'"
454 echo "cannot create file '$file'" >&2;
455 # Let the caller decide what to do on error
460 create_empty_file() {
461 create_file "${1/$DIR/$DIR2}" 1M 0 ||
462 file_creation_failure dd "${1/$DIR/$DIR2}" $?
465 create_small_file() {
466 local source_file=/dev/urandom
469 local conv=${2:-fsync}
471 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
472 file_creation_failure dd "${1/$DIR/$DIR2}" $?
475 create_small_sync_file() {
476 create_small_file "$1" sync
479 create_archive_file() {
480 local file="$(hsm_root)/$1"
482 local source=/dev/urandom
484 # Create the counterpart directory of the archive
485 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
486 error "cannot create archive directory '$(dirname "$file")'"
488 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
489 error "cannot create archive file '$file'"
493 local hsm_root="$(hsm_root)"
494 local file="$hsm_root/$2"
496 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
497 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
498 error "mkdir '$(dirname "$file")' failed"
499 do_facet $SINGLEAGT cp -p "$1" "$file" ||
500 error "cannot copy '$1' to '$file'"
509 if [[ "$value" != "" ]]; then
512 for mdtno in $(seq 1 $MDSCOUNT); do
513 local idx=$(($mdtno - 1))
514 local facet=mds${mdtno}
515 # if $arg include -P option, run 1 set_param per MDT on the MGS
516 # else, run set_param on each MDT
517 [[ $arg = *"-P"* ]] && facet=mgs
518 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
519 [[ $? != 0 ]] && rc=1
529 for mdtno in $(seq 1 $MDSCOUNT); do
530 local idx=$(($mdtno - 1))
531 wait_result mds${mdtno} \
532 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
534 error "$key state is not '$target' on mds${mdtno}"
540 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
548 mdts_set_param "$opt -n" "hsm.$param" "$value"
555 mdts_set_param "" hsm_control "$cmd"
556 mdts_check_param hsm_control "$target" 10
559 cdt_set_sanity_policy() {
560 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
563 mdts_set_param "" hsm.policy "+NRA"
564 mdts_set_param "" hsm.policy "-NBR"
565 CDT_POLICY_HAD_CHANGED=
570 mdts_set_param "" hsm.policy "+NRA"
571 CDT_POLICY_HAD_CHANGED=true
574 cdt_clear_no_retry() {
575 mdts_set_param "" hsm.policy "-NRA"
576 CDT_POLICY_HAD_CHANGED=true
579 cdt_set_non_blocking_restore() {
580 mdts_set_param "" hsm.policy "+NBR"
581 CDT_POLICY_HAD_CHANGED=true
584 cdt_clear_non_blocking_restore() {
585 mdts_set_param "" hsm.policy "-NBR"
586 CDT_POLICY_HAD_CHANGED=true
589 cdt_clear_mount_state() {
590 mdts_set_param "-P -d" hsm_control ""
593 cdt_set_mount_state() {
594 mdts_set_param "-P" hsm_control "$1"
595 # set_param -P is asynchronous operation and could race with set_param.
596 # In such case configs could be retrieved and applied at mgc after
597 # set_param -P completion. Sleep here to avoid race with set_param.
598 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
599 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
600 # and 10 seconds to retrieve config from server.
605 mdts_check_param hsm_control "$1" 20
609 set_test_state disabled disabled
613 set_test_state enabled enabled
617 set_test_state shutdown stopped
621 set_test_state purge enabled
627 cdt_set_sanity_policy
631 local client_count=$1
632 if [[ $CLIENTCOUNT -lt $client_count ]]; then
633 skip "Need $client_count or more clients, have $CLIENTCOUNT"
640 $LFS path2fid $1 | tr -d '[]'
641 return ${PIPESTATUS[0]}
649 if [[ $u == "user" ]]; then
650 st=$($RUNAS $LFS hsm_state $f)
653 st=$($LFS hsm_state $f)
656 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
658 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
662 get_hsm_archive_id() {
665 st=$($LFS hsm_state $f)
666 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
668 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
676 local st=$(get_hsm_flags $f)
677 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
680 check_hsm_flags_user() {
684 local st=$(get_hsm_flags $f user)
685 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
697 if [[ "$3" != 1 ]]; then
701 cp $1 $f || file_creation_failure cp $f $?
703 path2fid $f || error "cannot get fid on $f"
706 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
708 # Note that this might lead to surprising behaviours such as deleting an
709 # important file for the currently running test
710 delete_large_files() {
711 printf "Deleting large files...\n" >&2
712 find $MOUNT -size +10M -delete
713 wait_delete_completed
719 wait_update --verbose $(facet_active_host $facet) "$@"
722 wait_request_state() {
726 # 4th arg (mdt index) is optional
728 local mds=mds$(($mdtidx + 1))
730 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
731 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
733 wait_result $mds "$cmd" "$state" 200 ||
734 error "request on $fid is not $state on $mds"
737 get_request_state() {
741 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
742 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
745 get_request_count() {
749 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
750 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
753 # Ensure the number of HSM request for a given FID is correct
754 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
755 assert_request_count() {
756 local request_count=$(get_request_count $1 $2)
757 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
759 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
766 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
767 [[ -n $fid ]] && cmd+=" | grep '$fid'"
768 cmd+=" | egrep 'WAITING|STARTED'"
770 wait_result $SINGLEMDS "$cmd" "" $timeout ||
771 error "requests did not complete"
774 wait_for_grace_delay() {
775 local val=$(get_hsm_param grace_delay)
779 wait_for_loop_period() {
780 local val=$(get_hsm_param loop_period)
787 # python2.6 in EL6 includes an internal json module
788 local json_parser='import json; import fileinput;'
789 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
790 json_parser+='json.loads([line for line in '
791 json_parser+='fileinput.input()][0]).items()])'
793 echo $raw_event | python -c "$json_parser"
796 get_agent_by_uuid_mdt() {
799 local mds=mds$(($mdtidx + 1))
800 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
804 check_agent_registered_by_mdt() {
807 local mds=mds$(($mdtidx + 1))
808 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
809 if [[ ! -z "$agent" ]]; then
810 echo "found agent $agent on $mds"
812 error "uuid $uuid not found in agent list on $mds"
816 check_agent_unregistered_by_mdt() {
819 local mds=mds$(($mdtidx + 1))
820 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
821 if [[ -z "$agent" ]]; then
822 echo "uuid not found in agent list on $mds"
824 error "uuid found in agent list on $mds: $agent"
828 check_agent_registered() {
831 for mdsno in $(seq 1 $MDSCOUNT); do
832 check_agent_registered_by_mdt $uuid $((mdsno - 1))
836 check_agent_unregistered() {
839 for mdsno in $(seq 1 $MDSCOUNT); do
840 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
845 local agent=${1:-$(facet_active_host $SINGLEAGT)}
847 # Lustre mount-point is mandatory and last parameter on
849 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
851 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
853 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
859 # populate MDT device array
862 # cleanup from previous bad setup
865 # for recovery tests, coordinator needs to be started at mount
867 # the lustre conf must be without hsm on (like for sanity.sh)
868 echo "Set HSM on and start"
869 cdt_set_mount_state enabled
870 cdt_check_state enabled
872 echo "Set sanity-hsm HSM policy"
873 cdt_set_sanity_policy
875 # finished requests are quickly removed from list
876 set_hsm_param grace_delay 10
878 CLIENT_NIDS=( $($LCTL list_nids all) )
880 test_1A() { # was test_1
884 local f=$DIR/$tdir/$tfile
888 check_hsm_flags_user $f "0x00000000"
890 $RUNAS $LFS hsm_set --norelease $f ||
891 error "user could not change hsm flags"
892 check_hsm_flags_user $f "0x00000010"
894 $RUNAS $LFS hsm_clear --norelease $f ||
895 error "user could not clear hsm flags"
896 check_hsm_flags_user $f "0x00000000"
898 # User could not change those flags...
899 $RUNAS $LFS hsm_set --exists $f &&
900 error "user should not set this flag"
901 check_hsm_flags_user $f "0x00000000"
904 $LFS hsm_set --exists $f ||
905 error "root could not change hsm flags"
906 check_hsm_flags_user $f "0x00000001"
908 $LFS hsm_clear --exists $f ||
909 error "root could not clear hsm state"
910 check_hsm_flags_user $f "0x00000000"
913 run_test 1A "lfs hsm flags root/non-root access"
916 local f=$DIR/$tdir/$tfile
917 local fid=$(create_small_file $f)
921 $LFS hsm_archive $f || error "could not archive file"
922 wait_request_state $fid ARCHIVE SUCCEED
924 # Release and check states
925 $LFS hsm_release $f || error "could not release file"
926 echo -n "Verifying released state: "
927 check_hsm_flags $f "0x0000000d"
929 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
931 run_test 1a "mmap & cat a HSM released file"
935 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
936 error "failed to set default stripe"
937 local f=$DIR/$tdir/$tfile
940 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
941 error "failed to create file"
942 local fid=$(path2fid $f)
947 $LFS hsm_archive $f || error "could not archive file"
948 wait_request_state $fid ARCHIVE SUCCEED
951 $LFS hsm_release $f || error "could not release file"
952 echo "verify released state: "
953 check_hsm_flags $f "0x0000000d" && echo "pass"
956 $LFS hsm_restore $f || error "could not restore file"
957 wait_request_state $fid RESTORE SUCCEED
958 echo "verify restored state: "
959 check_hsm_flags $f "0x00000009" && echo "pass"
961 run_test 1b "Archive, Release and Restore composite file"
967 local f=$DIR/$tdir/$tfile
970 # Test whether we can set the maximum archive number.
971 local LOCAL_HSM_ARCHIVE_NUMBER=32
972 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
973 error "root could not change hsm flags"
974 check_hsm_flags_user $f "0x00000001"
975 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
976 local st=$(get_hsm_archive_id $f)
977 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
978 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
980 # Test whether setting archive number 0 results in no change.
981 $LFS hsm_set --exists --archive-id 0 $f ||
982 error "root could not change hsm flags"
983 check_hsm_flags_user $f "0x00000001"
984 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
985 st=$(get_hsm_archive_id $f)
986 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
987 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
989 LOCAL_HSM_ARCHIVE_NUMBER=33
990 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
991 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
992 # lustre in the new version supports unlimited archiveID.
993 # Test whether setting archive number > 32 is supported
994 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
995 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
996 check_hsm_flags_user $f "0x00000001"
998 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
999 st=$(get_hsm_archive_id $f)
1000 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1001 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1003 # old client or old mds can only support at most 32 archiveID
1004 # test whether setting archive number > 32 results in error.
1005 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
1006 error "bitmap archive number is larger than 32"
1007 check_hsm_flags_user $f "0x00000001"
1010 # Test whether setting archive number 16 and archived flag.
1011 LOCAL_HSM_ARCHIVE_NUMBER=16
1012 $LFS hsm_set --exists --archived \
1013 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1014 error "root could not change hsm flags"
1015 check_hsm_flags_user $f "0x00000009"
1016 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1017 st=$(get_hsm_archive_id $f)
1018 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1019 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1021 run_test 1c "Check setting archive-id in lfs hsm_set"
1024 [ $MDS_VERSION_CODE -lt $(version_code 2.10.59) ] &&
1025 skip "need MDS version at least 2.10.59"
1028 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1029 error "failed to set default stripe"
1030 local f=$DIR/$tdir/$tfile
1033 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1034 error "failed to create file"
1035 local fid=$(path2fid $f)
1040 $LFS hsm_archive $f || error "could not archive file"
1041 wait_request_state $fid ARCHIVE SUCCEED
1044 $LFS hsm_release $f || error "could not release file"
1045 echo "verify released state: "
1046 check_hsm_flags $f "0x0000000d" && echo "pass"
1049 $LFS hsm_restore $f || error "could not restore file"
1050 wait_request_state $fid RESTORE SUCCEED
1051 echo "verify restored state: "
1052 check_hsm_flags $f "0x00000009" && echo "pass"
1054 run_test 1d "Archive, Release and Restore DoM file"
1057 local f=$DIR/$tdir/$tfile
1059 create_empty_file "$f"
1060 # New files are not dirty
1061 check_hsm_flags $f "0x00000000"
1063 # For test, we simulate an archived file.
1064 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1065 check_hsm_flags $f "0x00000001"
1067 # chmod do not put the file dirty
1068 chmod 600 $f || error "could not chmod test file"
1069 check_hsm_flags $f "0x00000001"
1071 # chown do not put the file dirty
1072 chown $RUNAS_ID $f || error "could not chown test file"
1073 check_hsm_flags $f "0x00000001"
1075 # truncate put the file dirty
1076 $TRUNCATE $f 1 || error "could not truncate test file"
1077 check_hsm_flags $f "0x00000003"
1079 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1080 check_hsm_flags $f "0x00000001"
1082 run_test 2 "Check file dirtyness when doing setattr"
1088 # New files are not dirty
1089 cp -p /etc/passwd $f
1090 check_hsm_flags $f "0x00000000"
1092 # For test, we simulate an archived file.
1093 $LFS hsm_set --exists $f ||
1094 error "user could not change hsm flags"
1095 check_hsm_flags $f "0x00000001"
1097 # Reading a file, does not set dirty
1098 cat $f > /dev/null || error "could not read file"
1099 check_hsm_flags $f "0x00000001"
1101 # Open for write without modifying data, does not set dirty
1102 openfile -f O_WRONLY $f || error "could not open test file"
1103 check_hsm_flags $f "0x00000001"
1105 # Append to a file sets it dirty
1106 cp -p /etc/passwd $f.append || error "could not create file"
1107 $LFS hsm_set --exists $f.append ||
1108 error "user could not change hsm flags"
1109 dd if=/etc/passwd of=$f.append bs=1 count=3\
1110 conv=notrunc oflag=append status=noxfer ||
1111 file_creation_failure dd $f.append $?
1112 check_hsm_flags $f.append "0x00000003"
1114 # Modify a file sets it dirty
1115 cp -p /etc/passwd $f.modify || error "could not create file"
1116 $LFS hsm_set --exists $f.modify ||
1117 error "user could not change hsm flags"
1118 dd if=/dev/zero of=$f.modify bs=1 count=3\
1119 conv=notrunc status=noxfer ||
1120 file_creation_failure dd $f.modify $?
1121 check_hsm_flags $f.modify "0x00000003"
1123 # Open O_TRUNC sets dirty
1124 cp -p /etc/passwd $f.trunc || error "could not create file"
1125 $LFS hsm_set --exists $f.trunc ||
1126 error "user could not change hsm flags"
1127 cp /etc/group $f.trunc || error "could not override a file"
1128 check_hsm_flags $f.trunc "0x00000003"
1130 # Mmapped a file sets dirty
1131 cp -p /etc/passwd $f.mmap || error "could not create file"
1132 $LFS hsm_set --exists $f.mmap ||
1133 error "user could not change hsm flags"
1134 multiop $f.mmap OSMWUc || error "could not mmap a file"
1135 check_hsm_flags $f.mmap "0x00000003"
1137 run_test 3 "Check file dirtyness when opening for write"
1140 local f=$DIR/$tdir/$tfile
1141 local fid=$(create_small_file $f)
1144 local st=$(get_request_state $fid CANCEL)
1145 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1147 run_test 4 "Useless cancel must not be registered"
1150 # test needs a running copytool
1154 local f=$DIR/$tdir/$tfile
1155 local fid=$(copy_file /etc/passwd $f)
1157 wait_request_state $fid ARCHIVE SUCCEED
1159 check_hsm_flags $f "0x00000009"
1161 run_test 8 "Test default archive number"
1163 test_9A() { # was test_9
1164 # we do not use the default one to be sure
1165 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1166 copytool setup --archive-id $archive_id
1168 # give time for CT to register with MDTs
1169 sleep $(($MDSCOUNT*2))
1170 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1171 check_agent_registered $uuid
1174 local f=$DIR/$tdir/$tfile
1175 local fid=$(copy_file /etc/passwd $f)
1176 $LFS hsm_archive --archive $archive_id $f
1177 wait_request_state $fid ARCHIVE SUCCEED
1179 check_hsm_flags $f "0x00000009"
1181 run_test 9A "Use of explicit archive number, with dedicated copytool"
1184 needclients 3 || return 0
1190 # start all of the copytools
1191 for n in $(seq $AGTCOUNT); do
1192 copytool setup --facet agt$n
1196 for n in $(seq $AGTCOUNT); do
1197 file=$DIR/$tdir/$tfile.$n
1198 fid=$(create_small_file $file)
1200 $LFS hsm_archive $file || error "could not archive file $file"
1201 wait_request_state $fid ARCHIVE SUCCEED
1202 check_hsm_flags $file "0x00000009"
1205 run_test 9a "Multiple remote agents"
1208 # test needs a running copytool
1211 mkdir -p $DIR/$tdir/d1
1212 local f=$DIR/$tdir/$tfile
1213 local fid=$(copy_file /etc/hosts $f)
1214 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1215 error "hsm_archive failed"
1216 wait_request_state $fid ARCHIVE SUCCEED
1218 local hsm_root="$(copytool_device $SINGLEAGT)"
1219 local archive="$(do_facet $SINGLEAGT \
1220 find "$hsm_root" -name "$fid" -print0)"
1221 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1223 echo "Verifying content"
1224 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1225 echo "Verifying hsm state "
1226 check_hsm_flags $f "0x00000009"
1228 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1229 local st=$(get_hsm_archive_id $f)
1230 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1231 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1233 run_test 10a "Archive a file"
1236 # test needs a running copytool
1240 local f=$DIR/$tdir/$tfile
1241 local fid=$(copy_file /etc/hosts $f)
1242 $LFS hsm_archive $f || error "archive request failed"
1243 wait_request_state $fid ARCHIVE SUCCEED
1245 $LFS hsm_archive $f || error "archive of non dirty file failed"
1246 local cnt=$(get_request_count $fid ARCHIVE)
1247 [[ "$cnt" == "1" ]] ||
1248 error "archive of non dirty file must not make a request"
1250 run_test 10b "Archive of non dirty file must work without doing request"
1253 # test needs a running copytool
1257 local f=$DIR/$tdir/$tfile
1258 local fid=$(copy_file /etc/hosts $f)
1259 $LFS hsm_set --noarchive $f
1260 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1263 run_test 10c "Check forbidden archive"
1266 # test needs a running copytool
1270 local f=$DIR/$tdir/$tfile
1271 local fid=$(copy_file /etc/hosts $f)
1272 $LFS hsm_archive $f || error "cannot archive $f"
1273 wait_request_state $fid ARCHIVE SUCCEED
1275 local ar=$(get_hsm_archive_id $f)
1276 local dflt=$(get_hsm_param default_archive_id)
1277 [[ $ar == $dflt ]] ||
1278 error "archived file is not on default archive: $ar != $dflt"
1280 run_test 10d "Archive a file on the default archive id"
1284 copy2archive /etc/hosts $tdir/$tfile
1285 local f=$DIR/$tdir/$tfile
1287 copytool import $tdir/$tfile $f
1288 echo -n "Verifying released state: "
1289 check_hsm_flags $f "0x0000000d"
1291 local LSZ=$(stat -c "%s" $f)
1292 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1294 echo "Verifying imported size $LSZ=$ASZ"
1295 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1296 echo -n "Verifying released pattern: "
1297 local PTRN=$($GETSTRIPE -L $f)
1299 [[ $PTRN == released ]] || error "Is not released"
1300 local fid=$(path2fid $f)
1301 echo "Verifying new fid $fid in archive"
1303 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1304 error "No archive for fid $fid"
1306 run_test 11a "Import a file"
1309 # test needs a running copytool
1313 local f=$DIR/$tdir/$tfile
1314 local fid=$(copy_file /etc/hosts $f)
1315 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1316 error "hsm_archive failed"
1317 wait_request_state $fid ARCHIVE SUCCEED
1319 local FILE_HASH=$(md5sum $f)
1322 copytool import $fid $f
1324 echo "$FILE_HASH" | md5sum -c
1326 [[ $? -eq 0 ]] || error "Restored file differs"
1328 run_test 11b "Import a deleted file using its FID"
1331 # test needs a running copytool
1335 copy2archive /etc/hosts $tdir/$tfile
1337 local f=$DIR/$tdir/$tfile
1338 copytool import $tdir/$tfile $f
1339 local f2=$DIR2/$tdir/$tfile
1340 echo "Verifying released state: "
1341 check_hsm_flags $f2 "0x0000000d"
1343 local fid=$(path2fid $f2)
1344 $LFS hsm_restore $f2
1345 wait_request_state $fid RESTORE SUCCEED
1347 echo "Verifying file state: "
1348 check_hsm_flags $f2 "0x00000009"
1350 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1352 [[ $? -eq 0 ]] || error "Restored file differs"
1354 run_test 12a "Restore an imported file explicitly"
1357 # test needs a running copytool
1361 copy2archive /etc/hosts $tdir/$tfile
1363 local f=$DIR/$tdir/$tfile
1364 copytool import $tdir/$tfile $f
1365 echo "Verifying released state: "
1366 check_hsm_flags $f "0x0000000d"
1368 cat $f > /dev/null || error "File read failed"
1370 echo "Verifying file state after restore: "
1371 check_hsm_flags $f "0x00000009"
1373 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1375 [[ $? -eq 0 ]] || error "Restored file differs"
1377 run_test 12b "Restore an imported file implicitly"
1380 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1382 # test needs a running copytool
1385 local f=$DIR/$tdir/$tfile
1387 $LFS setstripe -c 2 "$f"
1388 local fid=$(create_file "$f" 1M 5)
1390 local FILE_CRC=$(md5sum $f)
1392 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1393 wait_request_state $fid ARCHIVE SUCCEED
1394 $LFS hsm_release $f || error "release $f failed"
1396 echo "$FILE_CRC" | md5sum -c
1398 [[ $? -eq 0 ]] || error "Restored file differs"
1400 run_test 12c "Restore a file with stripe of 2"
1403 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(copy_file /etc/hosts $f)
1410 $LFS hsm_restore $f || error "restore of non archived file failed"
1411 local cnt=$(get_request_count $fid RESTORE)
1412 [[ "$cnt" == "0" ]] ||
1413 error "restore non archived must not make a request"
1414 $LFS hsm_archive $f ||
1415 error "archive request failed"
1416 wait_request_state $fid ARCHIVE SUCCEED
1417 $LFS hsm_restore $f ||
1418 error "restore of non released file failed"
1419 local cnt=$(get_request_count $fid RESTORE)
1420 [[ "$cnt" == "0" ]] ||
1421 error "restore a non dirty file must not make a request"
1423 run_test 12d "Restore of a non archived, non released file must work"\
1424 " without doing request"
1427 # test needs a running copytool
1431 local f=$DIR/$tdir/$tfile
1432 local fid=$(copy_file /etc/hosts $f)
1433 $LFS hsm_archive $f || error "archive request failed"
1434 wait_request_state $fid ARCHIVE SUCCEED
1437 cat /etc/hosts >> $f
1441 $LFS hsm_restore $f && error "restore a dirty file must fail"
1444 run_test 12e "Check forbidden restore"
1447 # test needs a running copytool
1451 local f=$DIR/$tdir/$tfile
1452 local fid=$(copy_file /etc/hosts $f)
1454 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1455 wait_request_state $fid ARCHIVE SUCCEED
1456 $LFS hsm_release $f || error "release of $f failed"
1458 wait_request_state $fid RESTORE SUCCEED
1460 echo -n "Verifying file state: "
1461 check_hsm_flags $f "0x00000009"
1463 diff -q /etc/hosts $f
1465 [[ $? -eq 0 ]] || error "Restored file differs"
1467 run_test 12f "Restore a released file explicitly"
1470 # test needs a running copytool
1474 local f=$DIR/$tdir/$tfile
1475 local fid=$(copy_file /etc/hosts $f)
1477 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1478 wait_request_state $fid ARCHIVE SUCCEED
1479 $LFS hsm_release $f || error "release of $f failed"
1481 diff -q /etc/hosts $f
1484 # we check we had a restore done
1485 wait_request_state $fid RESTORE SUCCEED
1487 [[ $st -eq 0 ]] || error "Restored file differs"
1489 run_test 12g "Restore a released file implicitly"
1492 needclients 2 || return 0
1494 # test needs a running copytool
1498 local f=$DIR/$tdir/$tfile
1499 local fid=$(copy_file /etc/hosts $f)
1501 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1502 wait_request_state $fid ARCHIVE SUCCEED
1503 $LFS hsm_release $f || error "release of $f failed"
1505 do_node $CLIENT2 diff -q /etc/hosts $f
1508 # we check we had a restore done
1509 wait_request_state $fid RESTORE SUCCEED
1511 [[ $st -eq 0 ]] || error "Restored file differs"
1513 run_test 12h "Restore a released file implicitly from a second node"
1516 # test needs a running copytool
1520 local f=$DIR/$tdir/$tfile
1521 local fid=$(copy_file /etc/passwd $f)
1522 $LFS hsm_archive $f || error "archive of $f failed"
1523 wait_request_state $fid ARCHIVE SUCCEED
1525 $LFS hsm_release $f || error "release of $f failed"
1529 [[ $? -eq 0 ]] || error "Restored file differs"
1531 run_test 12m "Archive/release/implicit restore"
1534 # test needs a running copytool
1538 copy2archive /etc/hosts $tdir/$tfile
1540 local f=$DIR/$tdir/$tfile
1541 copytool import $tdir/$tfile $f
1543 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1544 error "Restored file differs"
1546 $LFS hsm_release $f || error "release of $f failed"
1548 run_test 12n "Import/implicit restore/release"
1551 # test needs a running copytool
1555 local f=$DIR/$tdir/$tfile
1556 local fid=$(copy_file /etc/hosts $f)
1558 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1559 wait_request_state $fid ARCHIVE SUCCEED
1560 $LFS hsm_release $f || error "release of $f failed"
1562 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1563 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1565 # set no retry action mode
1568 diff -q /etc/hosts $f
1571 # we check we had a restore failure
1572 wait_request_state $fid RESTORE FAILED
1574 [[ $st -eq 0 ]] && error "Restore must fail"
1576 # remove no retry action mode
1579 # check file is still released
1580 check_hsm_flags $f "0x0000000d"
1582 # retry w/o failure injection
1583 do_facet $SINGLEMDS lctl set_param fail_loc=0
1585 # to be sure previous RESTORE result is gone
1587 wait_for_grace_delay
1589 diff -q /etc/hosts $f
1592 # we check we had a restore done
1593 wait_request_state $fid RESTORE SUCCEED
1595 [[ $st -eq 0 ]] || error "Restored file differs"
1597 run_test 12o "Layout-swap failure during Restore leaves file released"
1600 # test needs a running copytool
1604 local f=$DIR/$tdir/$tfile
1605 local fid=$(copy_file /etc/hosts $f)
1607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1608 wait_request_state $fid ARCHIVE SUCCEED
1609 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1610 $LFS hsm_release $f || error "cannot release $f"
1611 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1612 $LFS hsm_release $f || error "cannot release $f"
1613 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1615 run_test 12p "implicit restore of a file on copytool mount point"
1618 [ $MDS_VERSION_CODE -lt $(version_code 2.7.58) ] &&
1619 skip "need MDS version at least 2.7.58"
1621 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1622 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1623 error "cannot mount $MOUNT3 on $SINGLEAGT"
1625 # test needs a running copytool
1626 copytool setup -m "$MOUNT3"
1628 local f=$DIR/$tdir/$tfile
1629 local f2=$DIR2/$tdir/$tfile
1630 local fid=$(create_small_file $f)
1631 local orig_size=$(stat -c "%s" $f)
1633 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1634 wait_request_state $fid ARCHIVE SUCCEED
1636 $LFS hsm_release $f || error "could not release file"
1637 check_hsm_flags $f "0x0000000d"
1640 wait_copytools || error "copytool failed to stop"
1642 cat $f > /dev/null &
1644 # wait a bit to allow implicit restore request to be handled.
1645 # if not, next stat would also block on layout-lock.
1648 local size=$(stat -c "%s" $f2)
1649 [ $size -eq $orig_size ] ||
1650 error "$f2: wrong size after archive: $size != $orig_size"
1652 copytool setup -m "$MOUNT3"
1656 size=$(stat -c "%s" $f)
1657 [ $size -eq $orig_size ] ||
1658 error "$f: wrong size after restore: $size != $orig_size"
1660 size=$(stat -c "%s" $f2)
1661 [ $size -eq $orig_size ] ||
1662 error "$f2: wrong size after restore: $size != $orig_size"
1666 size=$(stat -c "%s" $f)
1668 error "$f: wrong size after overwrite: $size != 0"
1670 size=$(stat -c "%s" $f2)
1672 error "$f2: wrong size after overwrite: $size != 0"
1674 run_test 12q "file attributes are refreshed after restore"
1678 for i in {1..10}; do
1679 local archive_dir="$(hsm_root)"/subdir/dir.$i
1681 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1682 for j in {1..10}; do
1683 local archive_file="$archive_dir"/file.$j
1685 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1691 copytool import "subdir" "$DIR/$tdir"
1693 # To check the import, the test uses diff with the -r flag
1694 # This is nice, but diff only checks files one by one, and triggering
1695 # an implicit restore for one file at a time will consume as many
1696 # seconds as there are files to compare. To speed this up, a restore
1697 # operation is triggered manually first.
1699 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1701 # Compare the imported data
1702 do_facet $SINGLEAGT \
1703 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1704 error "imported files differ from archived data"
1706 run_test 13 "Recursively import and restore a directory"
1709 # test needs a running copytool
1713 local f=$DIR/$tdir/$tfile
1714 local fid=$(create_small_file $f)
1715 local sum=$(md5sum $f | awk '{print $1}')
1716 $LFS hsm_archive $f || error "could not archive file"
1717 wait_request_state $fid ARCHIVE SUCCEED
1719 # create released file (simulate llapi_hsm_import call)
1720 local fid2=$(create_empty_file "$f")
1721 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1722 $LFS hsm_release $f || error "could not release file"
1724 # rebind the archive to the newly created file
1725 echo "rebind $fid to $fid2"
1727 copytool rebind $fid $fid2
1729 # restore file and compare md5sum
1730 local sum2=$(md5sum $f | awk '{print $1}')
1732 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1734 run_test 14 "Rebind archived file to a new fid"
1737 # test needs a running copytool
1741 local f=$DIR/$tdir/$tfile
1743 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1747 for i in $(seq 1 $count); do
1748 fids[$i]=$(create_small_file $f.$i)
1749 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1750 $LFS hsm_archive $f.$i || error "could not archive file"
1752 wait_all_done $(($count*60))
1754 stack_trap "rm -f $tmpfile" EXIT
1757 for i in $(seq 1 $count); do
1758 local fid2=$(create_empty_file "${f}.${i}")
1759 # add the rebind operation to the list
1760 echo ${fids[$i]} $fid2 >> $tmpfile
1762 # set it released (simulate llapi_hsm_import call)
1763 $LFS hsm_set --archived --exists $f.$i ||
1764 error "could not force hsm flags"
1765 $LFS hsm_release $f.$i || error "could not release file"
1767 nl=$(wc -l < $tmpfile)
1768 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1770 echo "rebind list of files"
1771 copytool rebind "$tmpfile"
1773 # restore files and compare md5sum
1774 for i in $(seq 1 $count); do
1775 local sum2=$(md5sum $f.$i | awk '{print $1}')
1776 [[ $sum2 == ${sums[$i]} ]] ||
1777 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1780 run_test 15 "Rebind a list of files"
1783 # test needs a running copytool
1787 # create a known size file so we can verify transfer speed
1790 dd if=/dev/zero of=$ref bs=1M count=20
1793 local f=$DIR/$tdir/$tfile
1794 local fid=$(copy_file $ref $f)
1796 local start=$(date +%s)
1798 wait_request_state $fid ARCHIVE SUCCEED
1799 local end=$(date +%s)
1800 # Add 1 to account for rounding errors between start and end (LU-8155)
1801 local duration=$((end - start + 1))
1803 [[ $duration -ge $((goal - 1)) ]] ||
1804 error "Transfer is too fast $duration < $goal"
1806 run_test 16 "Test CT bandwith control option"
1809 local f=$DIR/$tdir/$tfile
1810 create_empty_file "$f"
1812 # Could not release a non-archived file
1813 $LFS hsm_release $f && error "release should not succeed"
1815 # For following tests, we must test them with HS_ARCHIVED set
1816 $LFS hsm_set --exists --archived $f || error "could not add flag"
1818 # Could not release a file if no-release is set
1819 $LFS hsm_set --norelease $f || error "could not add flag"
1820 $LFS hsm_release $f && error "release should not succeed"
1821 $LFS hsm_clear --norelease $f || error "could not remove flag"
1823 # Could not release a file if lost
1824 $LFS hsm_set --lost $f || error "could not add flag"
1825 $LFS hsm_release $f && error "release should not succeed"
1826 $LFS hsm_clear --lost $f || error "could not remove flag"
1828 # Could not release a file if dirty
1829 $LFS hsm_set --dirty $f || error "could not add flag"
1830 $LFS hsm_release $f && error "release should not succeed"
1831 $LFS hsm_clear --dirty $f || error "could not remove flag"
1833 run_test 20 "Release is not permitted"
1836 # test needs a running copytool
1839 local f=$DIR/$tdir/test_release
1841 # Create a file and check its states
1842 local fid=$(create_small_file $f)
1843 check_hsm_flags $f "0x00000000"
1845 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1846 # used until file is flushed to disk
1847 if [ $(facet_fstype ost1) == "zfs" ]; then
1848 # this causes an OST_SYNC rpc to be sent
1849 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1850 # clear locks to reread file data
1851 cancel_lru_locks osc
1854 local orig_size=$(stat -c "%s" $f)
1855 local orig_blocks=$(stat -c "%b" $f)
1857 start_full_debug_logging
1859 $LFS hsm_archive $f || error "could not archive file"
1860 wait_request_state $fid ARCHIVE SUCCEED
1862 local blocks=$(stat -c "%b" $f)
1863 [ $blocks -eq $orig_blocks ] ||
1864 error "$f: wrong block number after archive: " \
1865 "$blocks != $orig_blocks"
1866 local size=$(stat -c "%s" $f)
1867 [ $size -eq $orig_size ] ||
1868 error "$f: wrong size after archive: $size != $orig_size"
1870 # Release and check states
1871 $LFS hsm_release $f || error "could not release file"
1872 check_hsm_flags $f "0x0000000d"
1874 blocks=$(stat -c "%b" $f)
1875 [ $blocks -gt 5 ] &&
1876 error "$f: too many blocks after release: $blocks > 5"
1877 size=$(stat -c "%s" $f)
1878 [ $size -ne $orig_size ] &&
1879 error "$f: wrong size after release: $size != $orig_size"
1881 # Check we can release an file without stripe info
1885 check_hsm_flags $f "0x00000000"
1886 $LFS hsm_archive $f || error "could not archive file"
1887 wait_request_state $fid ARCHIVE SUCCEED
1889 # Release and check states
1890 $LFS hsm_release $f || error "could not release file"
1891 check_hsm_flags $f "0x0000000d"
1893 # Release again a file that is already released is OK
1894 $LFS hsm_release $f || fail "second release should succeed"
1895 check_hsm_flags $f "0x0000000d"
1897 stop_full_debug_logging
1899 run_test 21 "Simple release tests"
1902 # test needs a running copytool
1905 local f=$DIR/$tdir/test_release
1906 local swap=$DIR/$tdir/test_swap
1908 # Create a file and check its states
1909 local fid=$(create_small_file $f)
1910 check_hsm_flags $f "0x00000000"
1912 $LFS hsm_archive $f || error "could not archive file"
1913 wait_request_state $fid ARCHIVE SUCCEED
1915 # Release and check states
1916 $LFS hsm_release $f || error "could not release file"
1917 check_hsm_flags $f "0x0000000d"
1919 create_small_file $swap
1920 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1924 run_test 22 "Could not swap a release file"
1927 # test needs a running copytool
1930 local f=$DIR/$tdir/test_mtime
1932 # Create a file and check its states
1933 local fid=$(create_small_file $f)
1934 check_hsm_flags $f "0x00000000"
1936 $LFS hsm_archive $f || error "could not archive file"
1937 wait_request_state $fid ARCHIVE SUCCEED
1939 # Set modification time in the past
1940 touch -m -a -d @978261179 $f
1942 # Release and check states
1943 $LFS hsm_release $f || error "could not release file"
1944 check_hsm_flags $f "0x0000000d"
1946 local MTIME=$(stat -c "%Y" $f)
1947 local ATIME=$(stat -c "%X" $f)
1948 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1949 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1951 run_test 23 "Release does not change a/mtime (utime)"
1954 local file=$DIR/$tdir/$tfile
1963 # test needs a running copytool
1966 fid=$(create_small_file $file)
1968 # Create a file and check its states
1969 check_hsm_flags $file "0x00000000"
1971 # Ensure atime is less than mtime and ctime.
1975 atime0=$(stat -c "%X" $file)
1976 mtime0=$(stat -c "%Y" $file)
1977 ctime0=$(stat -c "%Z" $file)
1979 [ $atime0 -lt $mtime0 ] ||
1980 error "atime $atime0 is not less than mtime $mtime0"
1982 [ $atime0 -lt $ctime0 ] ||
1983 error "atime $atime0 is not less than ctime $ctime0"
1985 # Archive should not change any timestamps.
1986 $LFS hsm_archive $file || error "cannot archive '$file'"
1987 wait_request_state $fid ARCHIVE SUCCEED
1989 atime1=$(stat -c "%X" $file)
1990 mtime1=$(stat -c "%Y" $file)
1991 ctime1=$(stat -c "%Z" $file)
1993 [ $atime0 -eq $atime1 ] ||
1994 error "archive changed atime from $atime0 to $atime1"
1996 [ $mtime0 -eq $mtime1 ] ||
1997 error "archive changed mtime from $mtime0 to $mtime1"
1999 [ $ctime0 -eq $ctime1 ] ||
2000 error "archive changed ctime from $ctime0 to $ctime1"
2002 # Release should not change any timestamps.
2003 $LFS hsm_release $file || error "cannot release '$file'"
2004 check_hsm_flags $file "0x0000000d"
2006 atime1=$(stat -c "%X" $file)
2007 mtime1=$(stat -c "%Y" $file)
2008 ctime1=$(stat -c "%Z" $file)
2010 [ $atime0 -eq $atime1 ] ||
2011 error "release changed atime from $atime0 to $atime1"
2013 [ $mtime0 -eq $mtime1 ] ||
2014 error "release changed mtime from $mtime0 to $mtime1"
2016 [ $ctime0 -eq $ctime1 ] ||
2017 error "release changed ctime from $ctime0 to $ctime1"
2019 # Restore should not change any timestamps.
2020 $LFS hsm_restore $file
2021 wait_request_state $fid RESTORE SUCCEED
2023 atime1=$(stat -c "%X" $file)
2024 mtime1=$(stat -c "%Y" $file)
2025 ctime1=$(stat -c "%Z" $file)
2027 [ $atime0 -eq $atime1 ] ||
2028 error "restore changed atime from $atime0 to $atime1"
2030 [ $mtime0 -eq $mtime1 ] ||
2031 error "restore changed mtime from $mtime0 to $mtime1"
2033 [ $ctime0 -eq $ctime1 ] ||
2034 error "restore changed ctime from $ctime0 to $ctime1"
2037 wait_copytools || error "Copytools failed to stop"
2039 # Once more, after unmount and mount.
2040 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2041 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2043 atime1=$(stat -c "%X" $file)
2044 mtime1=$(stat -c "%Y" $file)
2045 ctime1=$(stat -c "%Z" $file)
2047 [ $atime0 -eq $atime1 ] ||
2048 error "remount changed atime from $atime0 to $atime1"
2050 [ $mtime0 -eq $mtime1 ] ||
2051 error "remount changed mtime from $mtime0 to $mtime1"
2053 [ $ctime0 -eq $ctime1 ] ||
2054 error "remount changed ctime from $ctime0 to $ctime1"
2056 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2059 local file=$DIR/$tdir/$tfile
2065 # Test needs a running copytool.
2068 # Check that root can do HSM actions on a regular user's file.
2069 fid=$(create_small_file $file)
2070 sum0=$(md5sum $file)
2072 chown $RUNAS_ID:$RUNAS_GID $file ||
2073 error "cannot chown '$file' to '$RUNAS_ID'"
2075 chmod ugo-w $DIR/$tdir ||
2076 error "cannot chmod '$DIR/$tdir'"
2078 $LFS hsm_archive $file
2079 wait_request_state $fid ARCHIVE SUCCEED
2081 $LFS hsm_release $file
2082 check_hsm_flags $file "0x0000000d"
2084 $LFS hsm_restore $file
2085 wait_request_state $fid RESTORE SUCCEED
2087 # Check that ordinary user can get HSM state.
2088 $RUNAS $LFS hsm_state $file ||
2089 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2091 $LFS hsm_release $file
2092 check_hsm_flags $file "0x0000000d"
2094 # Check that ordinary user can accessed released file.
2095 sum1=$($RUNAS md5sum $file) ||
2096 error "user '$RUNAS_ID' cannot read '$file'"
2098 [ "$sum0" == "$sum1" ] ||
2099 error "md5sum mismatch for '$file'"
2101 run_test 24b "root can archive, release, and restore user files"
2104 local file=$DIR/$tdir/$tfile
2105 local action=archive
2110 # test needs a running copytool
2115 # Save the default masks and check that cleanup_24c will
2116 # restore the request masks correctly.
2117 user_save=$(get_hsm_param user_request_mask)
2118 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2119 group_save=$(get_hsm_param group_request_mask)
2120 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2121 other_save=$(get_hsm_param other_request_mask)
2122 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2124 [ "$user_save" == RESTORE ] ||
2125 error "user_request_mask is '$user_save' expected 'RESTORE'"
2126 [ "$group_save" == RESTORE ] ||
2127 error "group_request_mask is '$group_save' expected 'RESTORE'"
2128 [ "$other_save" == RESTORE ] ||
2129 error "other_request_mask is '$other_save' expected 'RESTORE'"
2132 create_small_file $file
2133 chown $RUNAS_ID:$GROUP $file ||
2134 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2136 $RUNAS $LFS hsm_$action $file &&
2137 error "$action by user should fail"
2139 set_hsm_param user_request_mask $action
2140 $RUNAS $LFS hsm_$action $file ||
2141 error "$action by user should succeed"
2144 create_small_file $file
2145 chown nobody:$RUNAS_GID $file ||
2146 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2148 $RUNAS $LFS hsm_$action $file &&
2149 error "$action by group should fail"
2151 set_hsm_param group_request_mask $action
2152 $RUNAS $LFS hsm_$action $file ||
2153 error "$action by group should succeed"
2156 create_small_file $file
2157 chown nobody:$GROUP $file ||
2158 error "cannot chown '$file' to 'nobody:$GROUP'"
2160 $RUNAS $LFS hsm_$action $file &&
2161 error "$action by other should fail"
2163 set_hsm_param other_request_mask $action
2164 $RUNAS $LFS hsm_$action $file ||
2165 error "$action by other should succeed"
2167 run_test 24c "check that user,group,other request masks work"
2170 local file1=$DIR/$tdir/$tfile
2171 local file2=$DIR2/$tdir/$tfile
2175 fid1=$(create_small_file $file1)
2178 $LFS getstripe $file1
2180 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2181 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2182 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2184 copytool setup -m "$MOUNT3"
2186 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2187 mount -o remount,ro $MOUNT2
2189 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2191 fid2=$(path2fid $file2)
2192 [ "$fid1" == "$fid2" ] ||
2193 error "FID mismatch '$fid1' != '$fid2'"
2195 $LFS hsm_archive $file2 &&
2196 error "archive should fail on read-only mount"
2197 check_hsm_flags $file1 "0x00000000"
2199 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2200 wait_request_state $fid1 ARCHIVE SUCCEED
2202 $LFS hsm_release $file1
2203 $LFS hsm_restore $file2
2204 wait_request_state $fid1 RESTORE SUCCEED
2206 $LFS hsm_release $file1 || error "cannot release '$file1'"
2207 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2209 $LFS hsm_release $file2 &&
2210 error "release should fail on read-only mount"
2214 run_test 24d "check that read-only mounts are respected"
2219 local f=$DIR/$tdir/$tfile
2222 fid=$(create_small_file $f) || error "cannot create $f"
2223 $LFS hsm_archive $f || error "cannot archive $f"
2224 wait_request_state $fid ARCHIVE SUCCEED
2225 $LFS hsm_release $f || error "cannot release $f"
2226 while ! $LFS hsm_state $f | grep released; do
2230 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2232 run_test 24e "tar succeeds on HSM released files" # LU-6213
2235 # test needs a running copytool
2238 mkdir -p $DIR/$tdir/d1
2239 local f=$DIR/$tdir/$tfile
2240 local fid=$(copy_file /etc/hosts $f)
2243 $LFS hsm_archive $f ||
2244 error "hsm_archive failed"
2245 wait_request_state $fid ARCHIVE SUCCEED
2246 $LFS hsm_release $f || error "cannot release $f"
2247 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2250 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2251 error "Can not recover the tar contents"
2253 echo "Sum0 = $sum0, sum1 = $sum1"
2254 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2256 run_test 24f "root can archive, release, and restore tar files"
2259 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
2260 skip "need MDS version 2.11.56 or later"
2262 local file=$DIR/$tdir/$tfile
2265 echo "RUNAS = '$RUNAS'"
2270 chmod ugo+rwx $DIR/$tdir
2272 echo "Please listen carefully as our options have changed." | tee $file
2273 fid=$(path2fid $file)
2276 $LFS hsm_archive $file
2277 wait_request_state $fid ARCHIVE SUCCEED
2278 check_hsm_flags $file 0x00000009 # exists archived
2280 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2281 check_hsm_flags $file 0x0000000b # exists dirty archived
2283 run_test 24g "write by non-owner still sets dirty" # LU-11369
2286 # test needs a running copytool
2290 copy2archive /etc/hosts $tdir/$tfile
2292 local f=$DIR/$tdir/$tfile
2294 copytool import $tdir/$tfile $f
2296 $LFS hsm_set --lost $f
2301 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2303 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2304 " (Operation not permitted)"
2307 # test needs a running copytool
2312 local f=$DIR/$tdir/$tfile
2313 local fid=$(copy_file /etc/passwd $f)
2315 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2316 wait_request_state $fid ARCHIVE SUCCEED
2319 $LFS hsm_set --lost $f
2323 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2325 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2326 " (Operation not permitted)"
2328 test_26A() { # was test_26
2329 # test needs a running copytool
2332 local f=$DIR/$tdir/$tfile
2333 local fid=$(create_empty_file "$f")
2335 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2336 wait_request_state $fid ARCHIVE SUCCEED
2339 wait_request_state $fid REMOVE SUCCEED
2341 check_hsm_flags $f "0x00000000"
2343 run_test 26A "Remove the archive of a valid file"
2346 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2347 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2349 # test needs a running copytool
2353 local f=$DIR/$tdir/$tfile
2354 local fid=$(copy_file /etc/passwd $f)
2356 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2357 wait_request_state $fid ARCHIVE SUCCEED
2359 local f2=$DIR/$tdir/${tfile}_2
2360 local fid2=$(copy_file /etc/passwd $f2)
2362 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2363 wait_request_state $fid2 ARCHIVE SUCCEED
2365 local f3=$DIR/$tdir/${tfile}_3
2366 local fid3=$(copy_file /etc/passwd $f3)
2368 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2369 wait_request_state $fid3 ARCHIVE SUCCEED
2371 # set a long grace_delay vs short loop_period
2372 local orig_loop_period=$(get_hsm_param loop_period)
2373 local orig_grace_delay=$(get_hsm_param grace_delay)
2374 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2375 set_hsm_param loop_period 10
2376 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2377 set_hsm_param grace_delay 100
2381 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2382 set_hsm_param remove_archive_on_last_unlink 1
2384 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2389 wait_request_state $fid2 REMOVE SUCCEED
2391 assert_request_count $fid REMOVE 0 \
2392 "Unexpected archived data remove request for $f"
2393 assert_request_count $fid3 REMOVE 0 \
2394 "Unexpected archived data remove request for $f3"
2396 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2399 # test needs a running copytool
2403 local f=$DIR/$tdir/$tfile
2404 local fid=$(copy_file /etc/passwd $f)
2406 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2407 wait_request_state $fid ARCHIVE SUCCEED
2409 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2410 set_hsm_param remove_archive_on_last_unlink 1
2413 cdt_check_state stopped
2417 wait_request_state $fid REMOVE WAITING
2421 # copytool must re-register
2423 wait_copytools || error "copytool failed to stop"
2426 wait_request_state $fid REMOVE SUCCEED
2428 run_test 26b "RAoLU policy when CDT off"
2431 # test needs a running copytool
2435 local f=$DIR/$tdir/$tfile
2436 local fid=$(copy_file /etc/passwd $f)
2438 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2439 wait_request_state $fid ARCHIVE SUCCEED
2441 local f2=$DIR/$tdir/${tfile}_2
2442 local fid2=$(copy_file /etc/passwd $f2)
2444 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2445 wait_request_state $fid2 ARCHIVE SUCCEED
2447 # set a long grace_delay vs short loop_period
2448 local orig_loop_period=$(get_hsm_param loop_period)
2449 local orig_grace_delay=$(get_hsm_param grace_delay)
2450 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2451 set_hsm_param loop_period 10
2452 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2453 set_hsm_param grace_delay 100
2455 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2456 set_hsm_param remove_archive_on_last_unlink 1
2458 multiop_bg_pause $f O_c || error "open $f failed"
2464 wait_request_state $fid2 REMOVE SUCCEED
2465 assert_request_count $fid REMOVE 0 \
2466 "Unexpected archived data remove request for $f"
2468 kill -USR1 $pid || error "multiop early exit"
2469 # should reach autotest timeout if multiop fails to trap
2470 # signal, close file, and exit ...
2471 wait $pid || error "wait PID $PID failed"
2473 wait_request_state $fid REMOVE SUCCEED
2475 run_test 26c "RAoLU effective when file closed"
2478 # test needs a running copytool
2482 local f=$DIR/$tdir/$tfile
2483 local fid=$(create_small_file $f)
2485 $LFS hsm_archive $f || error "could not archive file"
2486 wait_request_state $fid ARCHIVE SUCCEED
2488 # set a long grace_delay vs short loop_period
2489 local orig_loop_period=$(get_hsm_param loop_period)
2490 local orig_grace_delay=$(get_hsm_param grace_delay)
2491 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2492 set_hsm_param loop_period 10
2493 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2494 set_hsm_param grace_delay 100
2496 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2497 set_hsm_param remove_archive_on_last_unlink 1
2499 multiop_bg_pause $f O_c || error "multiop failed"
2506 wait_request_state $fid REMOVE SUCCEED
2508 client_up || client_up || true
2510 kill -USR1 $MULTIPID
2511 wait $MULTIPID || error "multiop close failed"
2513 run_test 26d "RAoLU when Client eviction"
2516 # test needs a running copytool
2519 create_archive_file $tdir/$tfile
2520 local f=$DIR/$tdir/$tfile
2521 copytool import $tdir/$tfile $f
2522 local fid=$(path2fid $f)
2526 [[ $? != 0 ]] || error "Remove of a released file should fail"
2528 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2531 # test needs a running copytool
2534 local f=$DIR/$tdir/$tfile
2535 local fid=$(create_empty_file "$f")
2537 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2538 wait_request_state $fid ARCHIVE SUCCEED
2543 [[ $? != 0 ]] || error "Remove of a released file should fail"
2545 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2548 # test needs a running copytool
2551 local f=$DIR/$tdir/$tfile
2552 local fid=$(create_empty_file "$f")
2554 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2555 wait_request_state $fid ARCHIVE SUCCEED
2564 wait_request_state $fid REMOVE SUCCEED
2566 run_test 28 "Concurrent archive/file remove"
2569 # Tests --mntpath and --archive options
2572 copytool setup -m "$MOUNT" -a $archive_id
2574 # Bad archive number
2575 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2576 grep "Invalid argument" ||
2577 error "unexpected hsm_remove failure (1)"
2579 # mntpath is present but file is given
2580 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2581 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2582 error "unexpected hsm_remove failure (2)"
2584 run_test 29a "Tests --mntpath and --archive options"
2587 # test needs a running copytool
2590 local f=$DIR/$tdir/$tfile
2591 local fid=$(create_small_file $f)
2593 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2594 wait_request_state $fid ARCHIVE SUCCEED
2598 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2599 wait_request_state $fid REMOVE SUCCEED
2601 run_test 29b "Archive/delete/remove by FID from the archive."
2604 # test needs a running copytool
2607 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2608 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2609 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2611 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2612 wait_request_state $fid1 ARCHIVE SUCCEED
2613 wait_request_state $fid2 ARCHIVE SUCCEED
2614 wait_request_state $fid3 ARCHIVE SUCCEED
2616 rm -f $DIR/$tdir/$tfile-[1-3]
2618 echo $fid1 > $DIR/$tdir/list
2619 echo $fid2 >> $DIR/$tdir/list
2620 echo $fid3 >> $DIR/$tdir/list
2622 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2623 --filelist $DIR/$tdir/list
2624 wait_request_state $fid1 REMOVE SUCCEED
2625 wait_request_state $fid2 REMOVE SUCCEED
2626 wait_request_state $fid3 REMOVE SUCCEED
2628 run_test 29c "Archive/delete/remove by FID, using a file list."
2631 # test needs more than one CT
2632 needclients 3 || return 0
2638 # start all of the copytools
2639 for n in $(seq $AGTCOUNT); do
2640 copytool setup -f agt$n -a $n
2644 file=$DIR/$tdir/$tfile
2645 fid=$(create_small_file $file)
2647 $LFS hsm_archive $file
2648 wait_request_state $fid ARCHIVE SUCCEED
2649 check_hsm_flags $file "0x00000009"
2653 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2654 error "cannot hsm_remove '$fid'"
2656 # give time for CDT to handle remove request and create broadcasted
2659 # remove request has been broadcasted ?
2660 local cnt=$(get_request_count $fid REMOVE)
2661 # broadcasted requests + original
2662 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2663 error "remove not broadcasted to all CTs"
2665 # give time for CDT and CTs to handle broadcasted
2666 wait_for_loop_period
2668 # each agent serves one different archive_id, so broadcasted
2669 # hsm_remove request should only succeed once and fail at all others
2673 for n in $(seq $AGTCOUNT); do
2674 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2675 $HSM_PARAM.actions | awk \
2676 '/'$fid'.*action=REMOVE archive#='$n'/ \
2677 {print \\\$13}' | cut -f2 -d=")
2678 if [[ "$res" == "SUCCEED" ]]; then
2680 elif [[ "$res" == "FAILED" ]]; then
2685 [[ $scnt -eq 1 ]] ||
2686 error "one and only CT should have removed successfully"
2688 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2689 error "all but one CT should have failed to remove"
2691 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2692 "request to be sent once for each registered archive_id"
2695 # restore at exec cannot work on agent node (because of Linux kernel
2696 # protection of executables)
2697 needclients 2 || return 0
2699 # test needs a running copytool
2703 copy2archive /bin/true $tdir/$tfile
2705 local f=$DIR/$tdir/true
2706 copytool import $tdir/$tfile $f
2708 local fid=$(path2fid $f)
2710 stack_trap "cdt_clear_no_retry" EXIT
2711 # set no retry action mode
2718 [[ $st == 0 ]] || error "Failed to exec a released file"
2720 run_test 30a "Restore at exec (import case)"
2723 # restore at exec cannot work on agent node (because of Linux kernel
2724 # protection of executables)
2725 needclients 2 || return 0
2727 # test needs a running copytool
2731 local f=$DIR/$tdir/true
2732 local fid=$(copy_file /bin/true $f)
2734 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2735 wait_request_state $fid ARCHIVE SUCCEED
2739 stack_trap cdt_clear_no_retry EXIT
2740 # set no retry action mode
2748 [[ $st == 0 ]] || error "Failed to exec a released file"
2750 run_test 30b "Restore at exec (release case)"
2753 needclients 2 || return 0
2755 # test needs a running copytool
2759 local f=$DIR/$tdir/SLEEP
2760 local slp_sum1=$(md5sum /bin/sleep)
2761 local fid=$(copy_file /bin/sleep $f)
2763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2764 wait_request_state $fid ARCHIVE SUCCEED
2766 check_hsm_flags $f "0x0000000d"
2768 stack_trap cdt_clear_no_retry EXIT
2769 # set no retry action mode
2772 do_node $CLIENT2 "$f 10" &
2776 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2778 [[ $? == 0 ]] || error "Execution failed during run"
2780 if [[ $? != 0 ]]; then
2781 local slp_sum2=$(md5sum /bin/sleep)
2782 # in case sleep file is modified during the test
2783 [[ $slp_sum1 == $slp_sum2 ]] &&
2784 error "Binary overwritten during exec"
2787 check_hsm_flags $f "0x00000009"
2789 run_test 30c "Update during exec of released file must fail"
2791 restore_and_check_size() {
2794 local s=$(stat -c "%s" $f)
2796 local st=$(get_hsm_flags $f)
2800 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2802 n=$(stat -c "%s" $f)
2803 # we echo in both cases to show stat is not hang
2804 if [[ $n != $s ]]; then
2805 echo "size seen is $n != $s"
2808 echo "size seen is right: $n == $s"
2812 st=$(get_hsm_flags $f)
2814 if [[ "$st" = "0x00000009" ]]; then
2817 echo " restore is too long"
2818 wait_request_state $fid RESTORE SUCCEED
2824 # test needs a running copytool
2827 create_archive_file $tdir/$tfile
2828 local f=$DIR/$tdir/$tfile
2829 copytool import $tdir/$tfile $f
2830 local fid=$($LFS path2fid $f)
2833 restore_and_check_size $f $fid
2836 [[ $err -eq 0 ]] || error "File size changed during restore"
2838 run_test 31a "Import a large file and check size during restore"
2842 # test needs a running copytool
2845 local f=$DIR/$tdir/$tfile
2846 local fid=$(create_file "$f" 1MB 39)
2848 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2849 wait_request_state $fid ARCHIVE SUCCEED
2852 restore_and_check_size $f $fid
2855 [[ $err -eq 0 ]] || error "File size changed during restore"
2857 run_test 31b "Restore a large unaligned file and check size during restore"
2860 # test needs a running copytool
2863 local f=$DIR/$tdir/$tfile
2864 local fid=$(create_file "$f" 1M 39)
2866 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2867 wait_request_state $fid ARCHIVE SUCCEED
2870 restore_and_check_size $f $fid
2873 [[ $err -eq 0 ]] || error "File size changed during restore"
2875 run_test 31c "Restore a large aligned file and check size during restore"
2878 local f=$DIR/$tdir/$tfile
2879 local fid=$(create_empty_file "$f")
2883 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2884 wait_request_state $fid ARCHIVE SUCCEED
2887 # Prevent restore from completing
2891 md5sum $f >/dev/null &
2894 wait_request_state $fid RESTORE STARTED
2899 # Check restore trigger process was killed
2901 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2903 run_test 33 "Kill a restore waiting process"
2906 # test needs a running copytool
2909 local f=$DIR/$tdir/$tfile
2910 local fid=$(create_empty_file "$f")
2912 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2913 wait_request_state $fid ARCHIVE SUCCEED
2916 # Prevent restore from completing
2919 md5sum $f >/dev/null &
2922 wait_request_state $fid RESTORE STARTED
2924 # rm must not block during restore
2925 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2928 wait_request_state $fid RESTORE SUCCEED
2930 # Check md5sum pgm finished
2931 kill -0 $pid && error "Restore initiatior still running"
2932 wait $pid || error "Restore initiator failed with $?"
2934 # Check the file was actually deleted
2935 [ ! -f "$f" ] || error "$f was not deleted"
2937 run_test 34 "Remove file during restore"
2940 # test needs a running copytool
2943 local f=$DIR/$tdir/$tfile
2944 local f1=$DIR/$tdir/$tfile-1
2945 local fid=$(create_empty_file "$f")
2946 local fid1=$(copy_file /etc/passwd $f1)
2948 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2949 wait_request_state $fid ARCHIVE SUCCEED
2952 # Prevent restore from completing
2955 md5sum $f >/dev/null &
2958 wait_request_state $fid RESTORE STARTED
2960 # mv must not block during restore
2961 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2964 wait_request_state $fid RESTORE SUCCEED
2966 # Check md5sum pgm finished
2967 kill -0 $pid && error "Restore initiatior still running"
2968 wait $pid || error "Restore initiator failed with $?"
2970 local fid2=$(path2fid $f)
2971 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2973 run_test 35 "Overwrite file during restore"
2976 # test needs a running copytool
2979 local f=$DIR/$tdir/$tfile
2980 local fid=$(create_empty_file "$f")
2982 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2983 wait_request_state $fid ARCHIVE SUCCEED
2986 # Prevent restore from completing
2989 md5sum $f >/dev/null &
2992 wait_request_state $fid RESTORE STARTED
2994 # mv must not block during restore
2995 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2996 error "mv '$f' '$f.new' failed with rc=$?"
2999 wait_request_state $fid RESTORE SUCCEED
3001 # Check md5sum pgm finished
3002 kill -0 $pid && error "Restore initiator is still running"
3003 wait $pid || error "Restore initiator failed with $?"
3005 run_test 36 "Move file during restore"
3008 # LU-5683: check that an archived dirty file can be rearchived.
3011 local f=$DIR/$tdir/$tfile
3014 fid=$(create_small_file $f) || error "cannot create small file"
3016 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3017 wait_request_state $fid ARCHIVE SUCCEED
3018 $LFS hsm_release $f || error "cannot release $f"
3020 # Allow previous archive request to expire from the actions log.
3021 wait_for_grace_delay
3024 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3027 wait_request_state $fid ARCHIVE SUCCEED
3029 run_test 37 "re-archive a dirty file"
3036 for n in $(seq 1 $count); do
3037 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3039 echo "$count archive requests submitted"
3043 local stream_count=4
3044 local file_count=100
3046 local f=$DIR/$tdir/$tfile
3050 local max_requests=$(get_hsm_param max_requests)
3052 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3053 # Increase the number of HSM request that can be performed in
3054 # parallel. With the coordinator running once per second, this
3055 # also limits the number of requests per seconds that can be
3056 # performed, so we pick a decent number. But we also need to keep
3057 # that number low because the copytool has no rate limit and will
3058 # fail some requests if if gets too many at once.
3059 set_hsm_param max_requests 300
3061 for i in $(seq 1 $file_count); do
3062 for p in $(seq 1 $stream_count); do
3063 fid=$(copy_file /etc/hosts $f.$p.$i)
3069 # to be sure wait_all_done will not be mislead by previous tests
3071 wait_for_grace_delay
3073 # start archive streams in background (archive files in parallel)
3074 for p in $(seq 1 $stream_count); do
3075 multi_archive $f.$p $file_count &
3078 echo -n "Wait for all requests being enqueued..."
3083 run_test 40 "Parallel archive requests"
3086 # test needs a running copytool
3090 local f=$DIR/$tdir/$tfile
3091 local fid=$(create_small_file $f)
3093 $LFS hsm_archive $f || error "could not archive file"
3094 wait_request_state $fid ARCHIVE SUCCEED
3095 check_hsm_flags $f "0x00000009"
3097 multiop_bg_pause $f O_c || error "multiop failed"
3101 client_up || client_up || true
3103 kill -USR1 $MULTIPID
3104 wait $MULTIPID || error "multiop close failed"
3106 check_hsm_flags $f "0x0000000b"
3108 run_test 52 "Opened for write file on an evicted client should be set dirty"
3111 # test needs a running copytool
3115 local f=$DIR/$tdir/$tfile
3116 local fid=$(create_small_file $f)
3118 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3119 error "could not archive file"
3120 wait_request_state $fid ARCHIVE SUCCEED
3121 check_hsm_flags $f "0x00000009"
3123 multiop_bg_pause $f o_c || error "multiop failed"
3127 client_up || client_up || true
3129 kill -USR1 $MULTIPID
3130 wait $MULTIPID || error "multiop close failed"
3132 check_hsm_flags $f "0x00000009"
3134 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3137 local f=$DIR/$tdir/$tfile
3138 local fid=$(create_file "$f" 1MB 39)
3142 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3143 error "could not archive file"
3144 wait_request_state $fid ARCHIVE STARTED
3146 check_hsm_flags $f "0x00000001"
3148 stack_trap "cdt_clear_no_retry" EXIT
3149 # Avoid coordinator resending this request as soon it has failed.
3154 wait_request_state $fid ARCHIVE FAILED
3156 check_hsm_flags $f "0x00000003"
3158 run_test 54 "Write during an archive cancels it"
3161 local f=$DIR/$tdir/$tfile
3162 local fid=$(create_file "$f" 1MB 39)
3166 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3167 error "could not archive file"
3168 wait_request_state $fid ARCHIVE STARTED
3170 check_hsm_flags $f "0x00000001"
3172 stack_trap "cdt_clear_no_retry" EXIT
3173 # Avoid coordinator resending this request as soon it has failed.
3176 $TRUNCATE $f 1024 || error "truncate failed"
3178 wait_request_state $fid ARCHIVE FAILED
3180 check_hsm_flags $f "0x00000003"
3182 run_test 55 "Truncate during an archive cancels it"
3185 local f=$DIR/$tdir/$tfile
3186 local fid=$(create_file "$f" 1MB 39)
3190 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3191 error "could not archive file"
3192 wait_request_state $fid ARCHIVE STARTED
3194 check_hsm_flags $f "0x00000001"
3196 # Change metadata and sync to be sure we are not changing only
3201 wait_request_state $fid ARCHIVE SUCCEED
3203 check_hsm_flags $f "0x00000009"
3205 run_test 56 "Setattr during an archive is ok"
3208 # Need one client for I/O, one for request
3209 needclients 2 || return 0
3211 # test needs a running copytool
3215 local f=$DIR/$tdir/test_archive_remote
3216 # Create a file on a remote node
3217 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3218 "count=2 conv=fsync"
3221 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3222 error "hsm_archive failed"
3223 local fid=$(path2fid $f)
3224 wait_request_state $fid ARCHIVE SUCCEED
3226 # Release and implicit restore it
3227 do_node $CLIENT2 "$LFS hsm_release $f" ||
3228 error "hsm_release failed"
3229 do_node $CLIENT2 "md5sum $f" ||
3230 error "hsm_restore failed"
3232 wait_request_state $fid RESTORE SUCCEED
3234 run_test 57 "Archive a file with dirty cache on another node"
3236 truncate_released_file() {
3240 local sz=$(stat -c %s $src_file)
3241 local f=$DIR/$tdir/$tfile
3242 local fid=$(copy_file $1 $f)
3246 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3247 error "could not archive file"
3248 wait_request_state $fid ARCHIVE SUCCEED
3250 $LFS hsm_release $f || error "could not release file"
3252 $TRUNCATE $f $trunc_to || error "truncate failed"
3255 local sz1=$(stat -c %s $f)
3256 [[ $sz1 == $trunc_to ]] ||
3257 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3260 check_hsm_flags $f "0x0000000b"
3262 local state=$(get_request_state $fid RESTORE)
3263 [[ "$state" == "SUCCEED" ]] ||
3264 error "truncate $sz does not trig restore, state = $state"
3266 $TRUNCATE $ref $trunc_to
3267 cmp $ref $f || error "file data wrong after truncate"
3273 # test needs a running copytool
3278 local sz=$(stat -c %s /etc/passwd)
3280 echo "truncate up from $sz to $((sz*2))"
3281 truncate_released_file /etc/passwd $((sz*2))
3283 echo "truncate down from $sz to $((sz/2))"
3284 truncate_released_file /etc/passwd $((sz/2))
3286 echo "truncate to 0"
3287 truncate_released_file /etc/passwd 0
3289 run_test 58 "Truncate a released file will trigger restore"
3293 [[ $MDS_VERSION_CODE -lt $(version_code 2.7.63) ]] &&
3294 skip "Need MDS version at least 2.7.63"
3297 $MCREATE $DIR/$tfile || error "mcreate failed"
3298 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3299 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3300 fid=$(path2fid $DIR/$tfile)
3301 wait_request_state $fid ARCHIVE SUCCEED
3302 $LFS hsm_release $DIR/$tfile || error "release failed"
3304 run_test 59 "Release stripeless file with non-zero size"
3307 # This test validates the fix for LU-4512. Ensure that the -u
3308 # option changes the progress reporting interval from the
3309 # default (30 seconds) to the user-specified interval.
3310 local f=$DIR/$tdir/$tfile
3311 local fid=$(create_file "$f" 1M 10)
3314 local progress_timeout=$((interval * 4))
3315 copytool setup -b 1 --update-interval $interval
3318 local mdt=${MDT_PREFIX}${mdtidx}
3319 local mds=mds$((mdtidx + 1))
3321 # Wait for copytool to register
3322 wait_update_facet $mds \
3323 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3324 uuid 100 || error "coyptool failed to register with $mdt"
3326 local start_at=$(date +%s)
3327 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3328 error "could not archive file"
3330 local agent=$(facet_active_host $SINGLEAGT)
3331 local logfile=$(copytool_logfile $SINGLEAGT)
3333 wait_update $agent \
3334 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3335 error "copytool failed to start"
3337 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3338 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3344 echo -n "Expecting a progress update within $progress_timeout seconds... "
3346 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3347 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3348 echo "$RESULT bytes copied in $WAIT seconds."
3350 elif [ $WAIT -ge $progress_timeout ]; then
3351 error "Timed out waiting for progress update!"
3354 WAIT=$((WAIT + sleep))
3358 local finish_at=$(date +%s)
3359 local elapsed=$((finish_at - start_at))
3361 # Ensure that the progress update occurred within the expected window.
3362 if [ $elapsed -lt $((interval - 1)) ]; then
3363 error "Expected progress update after at least $interval seconds"
3366 echo "Wait for on going archive hsm action to complete"
3367 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3368 echo "File archiving not completed even after 10 secs"
3370 run_test 60 "Changing progress update interval from default"
3373 # test needs a running copytool
3377 local f=$DIR/$tdir/$tfile
3378 local fid=$(copy_file /etc/passwd $f)
3380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3383 wait_request_state $fid ARCHIVE FAILED
3385 run_test 61 "Waiting archive of a removed file should fail"
3388 # test needs a new running copytool
3389 stack_trap copytool_monitor_cleanup EXIT
3390 copytool_monitor_setup
3391 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3393 # Wait for the copytool to register.
3394 wait_update --verbose $(facet_active_host mds1) \
3395 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3397 error "copytool failed to register with MDT0000"
3400 wait_copytools || error "Copytools failed to stop"
3402 local REGISTER_EVENT
3403 local UNREGISTER_EVENT
3404 while read event; do
3405 local parsed=$(parse_json_event "$event")
3406 if [ -z "$parsed" ]; then
3407 error "Copytool sent malformed event: $event"
3411 if [ $event_type == "REGISTER" ]; then
3412 REGISTER_EVENT=$event
3413 elif [ $event_type == "UNREGISTER" ]; then
3414 UNREGISTER_EVENT=$event
3416 done < <(echo $"$(get_copytool_event_log)")
3418 if [ -z "$REGISTER_EVENT" ]; then
3419 error "Copytool failed to send register event to FIFO"
3422 if [ -z "$UNREGISTER_EVENT" ]; then
3423 error "Copytool failed to send unregister event to FIFO"
3426 echo "Register/Unregister events look OK."
3428 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3431 # Bump progress interval for livelier events.
3434 # test needs a new running copytool
3435 stack_trap copytool_monitor_cleanup EXIT
3436 copytool_monitor_setup
3437 copytool setup --update-interval $interval --event-fifo \
3438 "$HSMTOOL_MONITOR_DIR/fifo"
3440 stack_trap "cdt_clear_no_retry" EXIT
3441 # Just start and stop the copytool to generate events.
3444 local f=$DIR/$tdir/$tfile
3445 local fid=$(create_small_file "$f")
3447 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3448 error "could not archive file"
3449 wait_request_state $fid ARCHIVE SUCCEED
3451 local expected_fields="event_time data_fid source_fid"
3452 expected_fields+=" total_bytes current_bytes"
3455 [ARCHIVE_START]=false
3456 [ARCHIVE_FINISH]=false
3457 [ARCHIVE_RUNNING]=false
3459 while read event; do
3460 # Make sure we're not getting anything from previous events.
3461 for field in $expected_fields; do
3465 local parsed=$(parse_json_event "$event")
3466 if [ -z "$parsed" ]; then
3467 error "Copytool sent malformed event: $event"
3471 events["$event_type"]=true
3473 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3475 # Do some simple checking of the progress update events.
3476 for expected_field in $expected_fields; do
3477 if [ -z ${!expected_field+x} ]; then
3478 error "Missing $expected_field field in event"
3482 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3484 # These should be identical throughout an archive operation
3485 [ $source_fid == $data_fid ] ||
3486 error "Expected source_fid to equal data_fid"
3487 done < <(echo $"$(get_copytool_event_log)")
3489 # Check we received every type of events we were expecting
3490 for event in "${!events[@]}"; do
3491 ${events["$event"]} ||
3492 error "Copytool failed to send '$event' event to FIFO"
3495 echo "Archive events look OK."
3497 run_test 71 "Copytool logs JSON archive events to FIFO"
3500 # Bump progress interval for livelier events.
3503 # test needs a new running copytool
3504 stack_trap copytool_monitor_cleanup EXIT
3505 copytool_monitor_setup
3506 copytool setup --update-interval $interval --event-fifo \
3507 "$HSMTOOL_MONITOR_DIR/fifo"
3508 local test_file=$HSMTOOL_MONITOR_DIR/file
3510 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3512 do_facet $SINGLEAGT "$cmd" ||
3513 error "cannot create $test_file on $SINGLEAGT"
3514 copy2archive $test_file $tdir/$tfile
3517 local f=$DIR/$tdir/$tfile
3518 copytool import $tdir/$tfile $f
3519 f=$DIR2/$tdir/$tfile
3520 echo "Verifying released state: "
3521 check_hsm_flags $f "0x0000000d"
3523 local fid=$(path2fid $f)
3525 wait_request_state $fid RESTORE SUCCEED
3527 local expected_fields="event_time data_fid source_fid"
3528 expected_fields+=" total_bytes current_bytes"
3532 while read event; do
3533 # Make sure we're not getting anything from previous events.
3534 for field in $expected_fields; do
3538 local parsed=$(parse_json_event "$event")
3539 if [ -z "$parsed" ]; then
3540 error "Copytool sent malformed event: $event"
3544 if [ $event_type == "RESTORE_START" ]; then
3546 if [ $source_fid != $data_fid ]; then
3547 error "source_fid should == data_fid at start"
3550 elif [ $event_type == "RESTORE_FINISH" ]; then
3552 if [ $source_fid != $data_fid ]; then
3553 error "source_fid should == data_fid at finish"
3556 elif [ $event_type != "RESTORE_RUNNING" ]; then
3560 # Do some simple checking of the progress update events.
3561 for expected_field in $expected_fields; do
3562 if [ -z ${!expected_field+x} ]; then
3563 error "Missing $expected_field field in event"
3567 if [ $total_bytes -eq 0 ]; then
3568 error "Expected total_bytes to be > 0"
3571 # When a restore starts out, the data fid is the same as the
3572 # source fid. After the restore has gotten going, we learn
3573 # the new data fid. Once the restore has finished, the source
3574 # fid is set to the new data fid.
3576 # We test this because some monitoring software may depend on
3577 # this behavior. If it changes, then the consumers of these
3578 # events may need to be modified.
3579 if [ $source_fid == $data_fid ]; then
3580 error "source_fid should != data_fid during restore"
3582 done < <(echo $"$(get_copytool_event_log)")
3584 if [ -z "$START_EVENT" ]; then
3585 error "Copytool failed to send restore start event to FIFO"
3588 if [ -z "$FINISH_EVENT" ]; then
3589 error "Copytool failed to send restore finish event to FIFO"
3592 echo "Restore events look OK."
3594 run_test 72 "Copytool logs JSON restore events to FIFO"
3597 file_count=51 # Max number of files constrained by LNET message size
3598 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3599 local f=$DIR/$tdir/$tfile
3600 local FILELIST=/tmp/filelist.txt
3604 for i in $(seq 1 $file_count); do
3605 fid=$(copy_file /etc/hosts $f.$i)
3606 echo $f.$i >> $FILELIST
3610 # to be sure wait_all_done will not be mislead by previous tests
3612 wait_for_grace_delay
3613 $LFS hsm_archive --filelist $FILELIST ||
3614 error "cannot archive a file list"
3616 $LFS hsm_release --filelist $FILELIST ||
3617 error "cannot release a file list"
3618 $LFS hsm_restore --filelist $FILELIST ||
3619 error "cannot restore a file list"
3622 run_test 90 "Archive/restore a file list"
3624 double_verify_reset_hsm_param() {
3626 echo "Testing $HSM_PARAM.$p"
3627 local val=$(get_hsm_param $p)
3629 local val2=$(($val * 2))
3630 set_hsm_param $p $val2
3631 val=$(get_hsm_param $p)
3632 [[ $val == $val2 ]] ||
3633 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3634 echo "Set $p to 0 must failed"
3638 set_hsm_param $p $save
3640 if [[ $rc == 0 ]]; then
3641 error "we must not be able to set $HSM_PARAM.$p to 0"
3646 double_verify_reset_hsm_param loop_period
3647 double_verify_reset_hsm_param grace_delay
3648 double_verify_reset_hsm_param active_request_timeout
3649 double_verify_reset_hsm_param max_requests
3650 double_verify_reset_hsm_param default_archive_id
3652 run_test 100 "Set coordinator /proc tunables"
3659 run_test 102 "Verify coordinator control"
3662 # test needs a running copytool
3669 for i in $(seq 1 20); do
3670 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3672 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3676 echo "Current requests"
3677 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3678 $HSM_PARAM.actions |\
3679 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3681 [[ -z "$res" ]] || error "Some request have not been canceled"
3683 run_test 103 "Purge all requests"
3688 local f=$DIR/$tdir/$tfile
3689 local fid=$(create_empty_file "$f")
3691 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3692 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3693 $HSM_PARAM.actions |\
3694 grep $fid | cut -f16 -d=")
3696 [[ "$data1" == "$DATAHEX" ]] ||
3697 error "Data field in records is ($data1) and not ($DATAHEX)"
3701 run_test 104 "Copy tool data field"
3704 local max_requests=$(get_hsm_param max_requests)
3708 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3709 set_hsm_param max_requests 300
3712 for i in $(seq -w 1 10); do
3713 cp /etc/passwd $DIR/$tdir/$i
3714 $LFS hsm_archive $DIR/$tdir/$i
3716 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3717 $HSM_PARAM.actions |\
3718 grep WAITING | wc -l")
3722 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3723 $HSM_PARAM.actions |\
3724 grep WAITING | wc -l")
3727 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3728 error "Requests count after shutdown $reqcnt2 != "\
3729 "before shutdown $reqcnt1"
3731 run_test 105 "Restart of coordinator"
3734 # test needs a running copytool
3737 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3739 check_agent_registered $uuid
3741 search_copytools || error "No copytool found"
3744 wait_copytools || error "Copytool failed to stop"
3746 check_agent_unregistered $uuid
3749 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3750 check_agent_registered $uuid
3752 run_test 106 "Copytool register/unregister"
3755 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3757 # test needs a running copytool
3759 # create and archive file
3761 local f1=$DIR/$tdir/$tfile
3762 local fid=$(copy_file /etc/passwd $f1)
3763 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3764 wait_request_state $fid ARCHIVE SUCCEED
3765 # shutdown and restart MDS
3767 # check the copytool still gets messages from MDT
3768 local f2=$DIR/$tdir/2
3769 local fid=$(copy_file /etc/passwd $f2)
3770 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3771 # main check of this sanity: this request MUST succeed
3772 wait_request_state $fid ARCHIVE SUCCEED
3774 run_test 107 "Copytool re-register after MDS restart"
3776 policy_set_and_test()
3780 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3781 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3782 [[ "$policy" == "$target" ]] ||
3783 error "Wrong policy after '$change': '$policy' != '$target'"
3787 # to force default policy setting if error
3788 CDT_POLICY_HAD_CHANGED=true
3790 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3791 local default="NonBlockingRestore [NoRetryAction]"
3792 [[ "$policy" == "$default" ]] ||
3793 error "default policy has changed,"\
3794 " '$policy' != '$default' update the test"
3795 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3796 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3797 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3798 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3799 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3800 # useless bacause we know but safer for futur changes to use real value
3801 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3802 echo "Next set_param must failed"
3803 policy_set_and_test "wrong" "$policy"
3806 echo "Back to default policy"
3807 cdt_set_sanity_policy
3809 run_test 109 "Policy display/change"
3812 # test needs a running copytool
3817 copy2archive /etc/passwd $tdir/$tfile
3819 local f=$DIR/$tdir/$tfile
3820 copytool import $tdir/$tfile $f
3821 local fid=$(path2fid $f)
3823 cdt_set_non_blocking_restore
3828 wait_request_state $fid RESTORE SUCCEED
3829 cdt_clear_non_blocking_restore
3833 error "md5sum returns $st != 1, "\
3834 "should also perror ENODATA (No data available)"
3836 run_test 110a "Non blocking restore policy (import case)"
3839 # test needs a running copytool
3843 local f=$DIR/$tdir/$tfile
3844 local fid=$(copy_file /etc/passwd $f)
3845 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3846 wait_request_state $fid ARCHIVE SUCCEED
3849 cdt_set_non_blocking_restore
3854 wait_request_state $fid RESTORE SUCCEED
3855 cdt_clear_non_blocking_restore
3859 error "md5sum returns $st != 1, "\
3860 "should also perror ENODATA (No data available)"
3862 run_test 110b "Non blocking restore policy (release case)"
3865 # test needs a running copytool
3869 copy2archive /etc/passwd $tdir/$tfile
3871 local f=$DIR/$tdir/$tfile
3873 copytool import $tdir/$tfile $f
3874 local fid=$(path2fid $f)
3878 copytool_remove_backend $fid
3881 wait_request_state $fid RESTORE FAILED
3888 [[ $st == 0 ]] || error "Restore does not failed"
3890 run_test 111a "No retry policy (import case), restore will error"\
3891 " (No such file or directory)"
3894 # test needs a running copytool
3898 local f=$DIR/$tdir/$tfile
3899 local fid=$(copy_file /etc/passwd $f)
3900 stack_trap cdt_clear_no_retry EXIT
3902 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3903 wait_request_state $fid ARCHIVE SUCCEED
3906 copytool_remove_backend $fid
3909 wait_request_state $fid RESTORE FAILED
3913 [[ $st == 0 ]] || error "Restore does not failed"
3915 run_test 111b "No retry policy (release case), restore will error"\
3916 " (No such file or directory)"
3919 # test needs a running copytool
3923 local f=$DIR/$tdir/$tfile
3924 local fid=$(copy_file /etc/passwd $f)
3926 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3927 local l=$($LFS hsm_action $f)
3929 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3932 wait_request_state $fid ARCHIVE SUCCEED
3935 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3937 run_test 112 "State of recorded request"
3940 (( $MDS1_VERSION >= $(version_code 2.12.3) )) ||
3941 skip "Need MDS version at least 2.12.3"
3943 local file1=$DIR/$tdir/$tfile
3944 local file2=$DIR2/$tdir/$tfile
3946 local fid=$(create_small_sync_file $file1)
3948 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3949 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3950 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3952 copytool setup -m "$MOUNT3"
3954 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3956 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3957 wait_request_state $fid ARCHIVE SUCCEED
3959 $LFS hsm_release $file1
3960 echo "Verifying released state: "
3961 check_hsm_flags $file1 "0x0000000d"
3963 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3966 kill -USR1 $MULTIPID
3971 local size1=$(stat -c "%s" $file1)
3972 local size2=$(stat -c "%s" $file2)
3974 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3976 run_test 113 "wrong stat after restore"
3979 local f=$DIR/$tdir/$tfile
3980 local fid=$(create_empty_file "$f")
3984 # Prevent archive from completing
3987 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3988 # wait archive to register at CDT
3989 wait_request_state $fid ARCHIVE STARTED
3991 # Cancel the archive
3992 $LFS hsm_cancel "$f"
3994 wait_request_state $fid ARCHIVE CANCELED
3997 wait_request_state $fid CANCEL SUCCEED
3999 run_test 200 "Register/Cancel archive"
4002 # test needs a running copytool
4005 local f=$DIR/$tdir/$tfile
4006 create_archive_file $tdir/$tfile
4007 copytool import $tdir/$tfile $f
4008 local fid=$(path2fid $f)
4010 # test with cdt on is made in test_222
4013 # wait restore to register at CDT
4014 wait_request_state $fid RESTORE WAITING
4017 wait_request_state $fid RESTORE CANCELED
4018 wait_request_state $fid CANCEL SUCCEED
4020 run_test 201 "Register/Cancel restore"
4023 local f=$DIR/$tdir/$tfile
4024 local fid=$(create_empty_file "$f")
4026 # test needs a running copytool
4029 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4030 wait_request_state $fid ARCHIVE SUCCEED
4034 # wait remove to register at CDT
4035 wait_request_state $fid REMOVE STARTED
4038 wait_request_state $fid REMOVE CANCELED
4040 run_test 202 "Register/Cancel remove"
4042 test_220A() { # was test_220
4043 # test needs a running copytool
4048 local f=$DIR/$tdir/$tfile
4049 local fid=$(copy_file /etc/passwd $f)
4053 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4054 wait_request_state $fid ARCHIVE SUCCEED
4056 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4057 error "The expected changelog was not emitted"
4059 run_test 220A "Changelog for archive"
4062 # test needs a running copytool
4067 local f=$DIR/$tdir/$tfile
4068 local fid=$(copy_file /etc/passwd $f)
4072 # block copytool operations to allow for HSM request to be
4073 # submitted and file be unlinked (CDT will find object removed)
4076 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4078 # wait request to reach CT
4079 wait_request_state $fid ARCHIVE STARTED
4085 wait_request_state $fid ARCHIVE FAILED
4088 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4089 error "The expected changelog was not emitted"
4091 run_test 220a "Changelog for failed archive"
4094 local f=$DIR/$tdir/$tfile
4095 local fid=$(create_empty_file "$f")
4100 # Prevent archive from completing
4102 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4103 wait_request_state $fid ARCHIVE STARTED
4106 wait_request_state $fid ARCHIVE CANCELED
4109 wait_request_state $fid CANCEL SUCCEED
4111 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4112 error "The expected changelog was not emitted"
4114 run_test 221 "Changelog for archive canceled"
4117 # test needs a running copytool
4121 copy2archive /etc/passwd $tdir/$tfile
4123 local f=$DIR/$tdir/$tfile
4124 copytool import $tdir/$tfile $f
4125 local fid=$(path2fid $f)
4130 wait_request_state $fid RESTORE SUCCEED
4132 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4133 error "The expected changelog was not emitted"
4135 run_test 222a "Changelog for explicit restore"
4138 # test needs a running copytool
4142 local f=$DIR/$tdir/$tfile
4143 local fid=$(copy_file /etc/passwd $f)
4146 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4147 wait_request_state $fid ARCHIVE SUCCEED
4152 wait_request_state $fid RESTORE SUCCEED
4154 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4155 error "The expected changelog was not emitted"
4157 run_test 222b "Changelog for implicit restore"
4160 # test needs a running copytool
4164 copy2archive /etc/passwd $tdir/$tfile
4166 local f=$DIR/$tdir/$tfile
4167 copytool import $tdir/$tfile $f
4168 local fid=$(path2fid $f)
4172 # block copytool operations to allow for HSM request to be
4173 # submitted and file be unlinked (CDT will find object removed)
4178 # wait request to reach CT
4179 wait_request_state $fid RESTORE STARTED
4185 wait_request_state $fid RESTORE FAILED
4188 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4189 error "The expected changelog was not emitted"
4191 run_test 222c "Changelog for failed explicit restore"
4194 # test needs a running copytool
4198 local f=$DIR/$tdir/$tfile
4199 local fid=$(copy_file /etc/passwd $f)
4202 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4203 wait_request_state $fid ARCHIVE SUCCEED
4206 copytool_remove_backend $fid
4209 wait_request_state $fid RESTORE FAILED
4212 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4213 error "The expected changelog was not emitted"
4215 run_test 222d "Changelog for failed implicit restore"
4218 # test needs a running copytool
4221 local f=$DIR/$tdir/$tfile
4222 create_archive_file $tdir/$tfile
4226 copytool import $tdir/$tfile $f
4227 local fid=$(path2fid $f)
4230 wait_request_state $fid RESTORE STARTED
4232 wait_request_state $fid RESTORE CANCELED
4233 wait_request_state $fid CANCEL SUCCEED
4235 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4236 error "The expected changelog was not emitted"
4238 run_test 223a "Changelog for restore canceled (import case)"
4241 local f=$DIR/$tdir/$tfile
4242 local fid=$(create_empty_file "$f")
4247 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4248 wait_request_state $fid ARCHIVE SUCCEED
4251 # Prevent restore from completing
4254 wait_request_state $fid RESTORE STARTED
4257 wait_request_state $fid RESTORE CANCELED
4260 wait_request_state $fid CANCEL SUCCEED
4262 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4263 error "The expected changelog was not emitted"
4265 run_test 223b "Changelog for restore canceled (release case)"
4267 test_224A() { # was test_224
4268 # test needs a running copytool
4273 local f=$DIR/$tdir/$tfile
4274 local fid=$(copy_file /etc/passwd $f)
4277 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4278 wait_request_state $fid ARCHIVE SUCCEED
4281 wait_request_state $fid REMOVE SUCCEED
4283 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4284 error "The expected changelog was not emitted"
4286 run_test 224A "Changelog for remove"
4289 # test needs a running copytool
4294 local f=$DIR/$tdir/$tfile
4295 local fid=$(copy_file /etc/passwd $f)
4298 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4299 wait_request_state $fid ARCHIVE SUCCEED
4301 copytool_remove_backend $fid
4303 # block copytool operations to allow for HSM request to be
4304 # submitted and file be unlinked (CDT will find object removed)
4309 # wait for request to reach CT
4310 wait_request_state $fid REMOVE STARTED
4316 wait_request_state $fid REMOVE FAILED
4318 # HE_REMOVE|ENOENT=0x202
4319 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4320 error "The expected changelog was not emitted"
4322 run_test 224a "Changelog for failed remove"
4325 # test is not usable because remove request is too fast
4326 # so it is always finished before cancel can be done ...
4327 echo "Test disabled"
4330 # test needs a running copytool
4333 local f=$DIR/$tdir/$tfile
4334 local fid=$(create_empty_file "$f")
4337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4338 wait_request_state $fid ARCHIVE SUCCEED
4340 # Prevent restore from completing
4345 wait_request_state $fid REMOVE CANCELED
4348 wait_request_state $fid CANCEL SUCCEED
4350 changelog_find -type HSM -target-fid $fid -flags 0x27d
4351 error "The expected changelog was not emitted"
4353 run_test 225 "Changelog for remove canceled"
4356 # test needs a running copytool
4361 local f1=$DIR/$tdir/$tfile-1
4362 local f2=$DIR/$tdir/$tfile-2
4363 local f3=$DIR/$tdir/$tfile-3
4364 local fid1=$(copy_file /etc/passwd $f1)
4365 local fid2=$(copy_file /etc/passwd $f2)
4366 copy_file /etc/passwd $f3
4369 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4370 wait_request_state $fid1 ARCHIVE SUCCEED
4372 $LFS hsm_archive $f2
4373 wait_request_state $fid2 ARCHIVE SUCCEED
4375 rm $f1 || error "rm $f1 failed"
4378 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4379 error "The expected changelog was not emitted"
4381 mv $f3 $f2 || error "mv $f3 $f2 failed"
4383 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4384 error "The expected changelog was not emitted"
4386 run_test 226 "changelog for last rm/mv with exiting archive"
4388 # This is just a utility function to clarify what test_227 does
4393 "$LFS" "$action" --$flag "$file" ||
4394 error "Cannot ${action#hsm_} $flag on '$file'"
4396 # Only one changelog should be produced
4397 local entries="$(changelog_find -type HSM -target-fid $fid)"
4398 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4399 error "lfs $action --$flag '$file' produced more than one" \
4402 # Parse the last changelog record
4403 local entry="$(tail -n 1 <<< "$entries")"
4404 eval local -A changelog=$(changelog2array $entry)
4406 # Also check the flags match what is expected
4407 [[ ${changelog[flags]} == $target ]] ||
4408 error "Changelog flag is '${changelog[flags]}', not $target"
4412 local file="$DIR/$tdir/$tfile"
4413 local fid=$(create_empty_file "$file")
4418 for flag in norelease noarchive exists archived lost; do
4419 if [ "$flag" == lost ]; then
4420 # The flag "lost" only works on an archived file
4421 "$LFS" hsm_set --archived "$file"
4425 action="hsm_set" __test_227
4426 action="hsm_clear" __test_227
4429 run_test 227 "changelog when explicit setting of HSM flags"
4432 # test needs a running copytool
4435 local fid=$(create_small_sync_file $DIR/$tfile)
4436 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4437 wait_request_state $fid ARCHIVE SUCCEED
4439 $LFS hsm_release $DIR/$tfile
4440 check_hsm_flags $DIR/$tfile "0x0000000d"
4442 filefrag $DIR/$tfile | grep " 1 extent found" ||
4443 error "filefrag on released file must return only one extent"
4445 # only newer versions of cp detect sparse files by stat/FIEMAP
4447 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4448 error "copying $DIR/$tfile"
4449 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4451 $LFS hsm_release $DIR/$tfile
4452 check_hsm_flags $DIR/$tfile "0x0000000d"
4454 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4456 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4458 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4459 error "comparing untarred $DIR/$tfile"
4461 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4462 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4464 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4467 local file="$DIR/$tdir/$tfile"
4469 # set max_requests to allow one request of each type to be started (3)
4471 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4472 set_hsm_param max_requests 3
4475 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4476 set_hsm_param loop_period 1
4478 # send 1 requests of each kind twice
4481 for action in archive restore remove; do
4482 local filepath="$file"-to-$action
4483 local fid=$(create_empty_file "$filepath")
4484 local fid2=$(create_empty_file "$filepath".bis)
4486 if [ "$action" != archive ]; then
4487 "$LFS" hsm_archive "$filepath"
4488 wait_request_state $fid ARCHIVE SUCCEED
4489 "$LFS" hsm_archive "$filepath".bis
4490 wait_request_state $fid2 ARCHIVE SUCCEED
4492 if [ "$action" == restore ]; then
4493 "$LFS" hsm_release "$filepath"
4494 "$LFS" hsm_release "$filepath".bis
4498 # suspend the copytool to prevent requests from completing
4499 stack_trap "copytool_continue" EXIT
4502 # send `max_requests' requests (one of each kind)
4503 for action in archive restore remove; do
4504 filepath="$file"-to-$action
4505 "$LFS" hsm_${action} "$filepath"
4506 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4509 # send another batch of requests
4510 for action in archive restore remove; do
4511 "$LFS" hsm_${action} "$file-to-$action".bis
4513 # wait for `loop_period' seconds to make sure the coordinator has time
4514 # to register those, even though it should not
4517 # only the first batch of request should be started
4519 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4523 error "expected 3 STARTED requests, found $count"
4525 run_test 250 "Coordinator max request"
4528 local f=$DIR/$tdir/$tfile
4529 local fid=$(create_empty_file "$f")
4532 # to have a short test
4533 local old_to=$(get_hsm_param active_request_timeout)
4534 set_hsm_param active_request_timeout 1
4535 # to be sure the cdt will wake up frequently so
4536 # it will be able to cancel the "old" request
4537 local old_loop=$(get_hsm_param loop_period)
4538 set_hsm_param loop_period 1
4543 # Prevent archive from completing
4545 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4546 wait_request_state $fid ARCHIVE STARTED
4548 # Let the request timeout
4549 wait_request_state $fid ARCHIVE CANCELED
4551 set_hsm_param active_request_timeout $old_to
4552 set_hsm_param loop_period $old_loop
4554 run_test 251 "Coordinator request timeout"
4557 local f=$DIR/$tdir/$tfile
4558 local fid=$(create_empty_file "$f")
4560 # to have a short test
4561 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4562 set_hsm_param loop_period 1
4566 # Prevent archive from completing
4568 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4569 wait_request_state $fid ARCHIVE STARTED
4572 stack_trap "set_hsm_param active_request_timeout \
4573 $(get_hsm_param active_request_timeout)" EXIT
4574 set_hsm_param active_request_timeout 1
4576 wait_request_state $fid ARCHIVE CANCELED
4579 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4583 # test needs a running copytool
4587 local f=$DIR/$tdir/$tfile
4589 dd if=/dev/zero of=$f bs=1MB count=10
4590 local fid=$(path2fid $f)
4592 $LFS hsm_archive $f || error "could not archive file"
4593 wait_request_state $fid ARCHIVE SUCCEED
4595 # clear locks to discard inode data
4596 cancel_lru_locks osc
4598 #define OBD_FAIL_MDC_MERGE 0x807
4599 $LCTL set_param fail_loc=0x807
4601 #expect error here, instead of release with wrong size
4604 if ((rc == 0)); then
4605 file_size=$(stat -c '%s' $f)
4606 if ((file_size != 10485760)); then
4607 error "Wrong file size after hsm_release"
4610 echo "could not release file"
4613 run_test 253 "Check for wrong file size after release"
4617 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4618 skip "need MDS version at least 2.10.56"
4620 # Check that the counters are initialized to 0
4622 for request_type in archive restore remove; do
4623 count="$(get_hsm_param ${request_type}_count)" ||
4624 error "Reading ${request_type}_count failed with $?"
4626 [ "$count" -eq 0 ] ||
4627 error "Expected ${request_type}_count to be " \
4631 run_test 254a "Request counters are initialized to zero"
4635 [ $MDS_VERSION_CODE -lt $(version_code 2.10.56) ] &&
4636 skip "need MDS version at least 2.10.56"
4638 # The number of request to launch (at least 32)
4639 local request_count=$((RANDOM % 32 + 32))
4640 printf "Will launch %i requests of each type\n" "$request_count"
4642 # Launch a copytool to process requests
4645 # Set hsm.max_requests to allow starting all requests at the same time
4647 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4648 set_hsm_param max_requests "$request_count"
4652 for request_type in archive restore remove; do
4653 printf "Checking %s requests\n" "${request_type}"
4654 # Suspend the copytool to give us time to read the proc files
4657 for ((i = 0; i < $request_count; i++)); do
4658 case $request_type in
4660 create_empty_file "$DIR/$tdir/$tfile-$i" \
4664 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4667 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4670 # Give the coordinator 10 seconds to start every request
4672 while get_hsm_param actions | grep -q WAITING; do
4675 [ $timeout -gt 0 ] ||
4676 error "${request_type^} requests took too " \
4680 count="$(get_hsm_param ${request_type}_count)"
4681 [ "$count" -eq "$request_count" ] ||
4682 error "Expected '$request_count' (!= '$count') " \
4683 "active $request_type requests"
4685 # Let the copytool process the requests
4687 # Give it 10 seconds maximum
4689 while get_hsm_param actions | grep -q STARTED; do
4692 [ $timeout -gt 0 ] ||
4693 error "${request_type^} requests took too " \
4697 count="$(get_hsm_param ${request_type}_count)"
4698 [ "$count" -eq 0 ] ||
4699 error "Expected 0 (!= '$count') " \
4700 "active $request_type requests"
4703 run_test 254b "Request counters are correctly incremented and decremented"
4707 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4708 skip "Need MDS version at least 2.12.0"
4710 local file="$DIR/$tdir/$tfile"
4711 local fid=$(create_empty_file "$file")
4713 # How do you make sure the coordinator has consumed any outstanding
4714 # event, without triggering an event yourself?
4716 # You wait for a request to disappear from the coordinator's llog.
4718 # Warning: the setup represents 90% of this test
4720 # Create and process an HSM request
4722 "$LFS" hsm_archive "$file"
4723 wait_request_state $fid ARCHIVE SUCCEED
4726 wait_copytools || error "failed to stop copytools"
4728 # Launch a new HSM request
4730 create_empty_file "$file"
4731 "$LFS" hsm_archive "$file"
4735 # Have the completed request be removed as soon as the cdt wakes up
4736 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4737 set_hsm_param grace_delay 1
4738 # (Hopefully, time on the MDS will behave nicely)
4739 do_facet $SINGLEMDS sleep 2 &
4741 # Increase `loop_period' as a mean to prevent the coordinator from
4742 # waking itself up to do some housekeeping.
4743 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4744 set_hsm_param loop_period 1000
4746 wait $! || error "waiting failed"
4748 wait_request_state $fid ARCHIVE ""
4749 # The coordinator will not wake up on its own for ~`loop_period' secs...
4751 # ... Unless a copytool registers. Now the real test begins
4753 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4755 run_test 255 "Copytool registration wakes the coordinator up"
4757 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4758 # break in the future because of that.
4761 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4762 skip "need MDS version 2.11.56 or later"
4764 local -a files=("$DIR/$tdir/$tfile".{0..15})
4767 for file in "${files[@]}"; do
4768 create_small_file "$file"
4771 # Set a few hsm parameters
4773 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4774 set_hsm_param loop_period 1
4776 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4777 set_hsm_param max_requests 3
4781 "$LFS" hsm_archive "${files[0]}"
4782 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4783 "$LFS" hsm_release "${files[0]}"
4787 wait_copytools || error "copytools failed to stop"
4789 # Send several archive requests
4790 for file in "${files[@]:1}"; do
4791 "$LFS" hsm_archive "$file"
4794 # Send one restore request
4795 "$LFS" hsm_restore "${files[0]}"
4800 # Wait for all the requests to complete
4801 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4802 for file in "${files[@]:1}"; do
4803 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4806 # Collect the actions in the order in which the copytool processed them
4808 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4809 "$(copytool_logfile "$SINGLEAGT")")
4812 printf '%s\n' "${actions[@]}"
4815 for action in "${actions[@]:0:3}"; do
4816 [ "$action" == RESTORE ] && return
4819 error "Too many ARCHIVE requests were run before the RESTORE request"
4821 run_test 260a "Restore request have priority over other requests"
4823 # This test is very much tied to the implementation of the current priorisation
4824 # mechanism in the coordinator. It might not make sense to keep it in the future
4827 [ $MDS_VERSION_CODE -lt $(version_code 2.11.56) ] &&
4828 skip "need MDS version 2.11.56 or later"
4830 local -a files=("$DIR/$tdir/$tfile".{0..15})
4833 for file in "${files[@]}"; do
4834 create_small_file "$file"
4837 # Set a few hsm parameters
4839 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4840 set_hsm_param loop_period 1
4842 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4843 set_hsm_param max_requests 3
4846 copytool setup --archive-id 2
4847 "$LFS" hsm_archive --archive 2 "${files[0]}"
4848 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4849 "$LFS" hsm_release "${files[0]}"
4853 wait_copytools || error "copytools failed to stop"
4855 # Send several archive requests
4856 for file in "${files[@]:1}"; do
4857 "$LFS" hsm_archive "$file"
4860 # Send one restore request
4861 "$LFS" hsm_restore "${files[0]}"
4865 copytool setup --archive-id 2
4867 # Wait for all the requests to complete
4868 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4869 for file in "${files[@]:1}"; do
4870 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4873 # Collect the actions in the order in which the copytool processed them
4875 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4876 "$(copytool_logfile "$SINGLEAGT")")
4879 printf '%s\n' "${actions[@]}"
4882 for action in "${actions[@]:0:3}"; do
4883 [ "$action" == RESTORE ] && return
4886 error "Too many ARCHIVE requests were run before the RESTORE request"
4888 run_test 260b "Restore request have priority over other requests"
4890 # This test is very much tied to the implementation of the current priorisation
4891 # mechanism in the coordinator. It might not make sense to keep it in the future
4894 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4895 skip "Need MDS version at least 2.12.0"
4897 local -a files=("$DIR/$tdir/$tfile".{0..15})
4900 for file in "${files[@]}"; do
4901 create_small_file "$file"
4904 # Set a few hsm parameters
4906 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4907 set_hsm_param loop_period 1000
4909 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4910 set_hsm_param max_requests 3
4913 copytool setup --archive-id 2
4914 "$LFS" hsm_archive --archive 2 "${files[0]}"
4915 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4916 "$LFS" hsm_release "${files[0]}"
4920 wait_copytools || error "copytools failed to stop"
4922 # Force the next coordinator run to do housekeeping
4926 "$LFS" hsm_archive "${files[1]}"
4930 copytool setup --archive-id 2
4932 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4933 # The coordinator just did a housekeeping run it won't do another one
4934 # for around `loop_period' seconds => requests will not be reordered
4935 # if it costs too much (ie. when the coordinator has to discard a whole
4938 # Send several archive requests
4939 for file in "${files[@]:2}"; do
4940 "$LFS" hsm_archive "$file"
4943 # Send one restore request
4944 "$LFS" hsm_restore "${files[0]}"
4946 # Wait for all the requests to complete
4947 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4948 for file in "${files[@]:2}"; do
4949 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4952 # Collect the actions in the order in which the copytool processed them
4954 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4955 "$(copytool_logfile "$SINGLEAGT")")
4958 printf '%s\n' "${actions[@]}"
4961 for action in "${actions[@]:0:3}"; do
4962 [ "$action" == RESTORE ] &&
4963 error "Restore requests should not be prioritised" \
4964 "unless the coordinator is doing housekeeping"
4968 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4971 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4973 # the only way to test ondisk conf is to restart MDS ...
4974 echo "Stop coordinator and remove coordinator state at mount"
4977 # clean on disk conf set by default
4978 cdt_clear_mount_state
4979 cdt_check_state stopped
4981 # check cdt still off after umount/remount
4983 cdt_check_state stopped
4985 echo "Set coordinator start at mount, and start coordinator"
4986 cdt_set_mount_state enabled
4989 cdt_check_state enabled
4991 # check cdt still on after umount/remount
4993 cdt_check_state enabled
4995 # we are back to original state (cdt started at mount)
4997 run_test 300 "On disk coordinator state kept between MDT umount/mount"
5000 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5002 local ai=$(get_hsm_param default_archive_id)
5003 local new=$((ai + 1))
5005 set_hsm_param default_archive_id $new -P
5007 local res=$(get_hsm_param default_archive_id)
5010 set_hsm_param default_archive_id "" "-P -d"
5012 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5014 run_test 301 "HSM tunnable are persistent"
5017 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
5019 local ai=$(get_hsm_param default_archive_id)
5020 local new=$((ai + 1))
5025 set_hsm_param default_archive_id $new -P
5028 for mdtno in $(seq 1 $MDSCOUNT); do
5033 cdt_check_state enabled
5035 local res=$(get_hsm_param default_archive_id)
5038 set_hsm_param default_archive_id "" "-P -d"
5040 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
5042 run_test 302 "HSM tunnable are persistent when CDT is off"
5045 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5051 local dir_mdt0=$DIR/$tdir/mdt0
5052 local dir_mdt1=$DIR/$tdir/mdt1
5054 # create 1 dir per MDT
5055 stack_trap "rm -rf $dir_mdt0" EXIT
5056 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5057 stack_trap "rm -rf $dir_mdt1" EXIT
5058 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5060 # create 1 file in each MDT
5061 local fid1=$(create_small_file $dir_mdt0/$tfile)
5062 local fid2=$(create_small_file $dir_mdt1/$tfile)
5064 # check that hsm request on mdt0 is sent to the right MDS
5065 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5066 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5067 echo "archive successful on mdt0"
5069 # check that hsm request on mdt1 is sent to the right MDS
5070 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
5071 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5072 echo "archive successful on mdt1"
5074 run_test 400 "Single request is sent to the right MDT"
5077 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5083 local dir_mdt0=$DIR/$tdir/mdt0
5084 local dir_mdt1=$DIR/$tdir/mdt1
5086 # create 1 dir per MDT
5087 stack_trap "rm -rf $dir_mdt0" EXIT
5088 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5089 stack_trap "rm -rf $dir_mdt1" EXIT
5090 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
5092 # create 1 file in each MDT
5093 local fid1=$(create_small_file $dir_mdt0/$tfile)
5094 local fid2=$(create_small_file $dir_mdt1/$tfile)
5096 # check that compound requests are shunt to the rights MDTs
5097 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
5098 error "lfs hsm_archive"
5099 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5100 echo "archive successful on mdt0"
5101 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
5102 echo "archive successful on mdt1"
5104 run_test 401 "Compound requests split and sent to their respective MDTs"
5106 mdc_change_state() # facet, MDT_pattern, activate|deactivate
5111 local node=$(facet_active_host $facet)
5113 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
5114 awk '{print $4}'); do
5115 echo "$3 $mdc on $node"
5116 do_facet $facet "$LCTL --device $mdc $state" || return 1
5121 # deactivate all mdc on agent1
5122 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
5124 copytool setup --no-fail
5126 check_agent_unregistered "uuid" # match any agent
5128 # no expected running copytool
5129 search_copytools $agent && error "Copytool start should have failed"
5132 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
5134 run_test 402a "Copytool start fails if all MDTs are inactive"
5141 local f=$DIR/$tdir/$tfile
5142 touch $f || error "touch $f failed"
5143 local fid=$(path2fid $f)
5145 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
5146 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
5147 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5149 # give time for CDT to send request and to keep it for retry
5150 wait_for_loop_period
5152 wait_request_state $fid ARCHIVE WAITING
5154 do_facet $SINGLEAGT lctl set_param fail_loc=0
5156 # request should succeed now
5157 wait_request_state $fid ARCHIVE SUCCEED
5159 run_test 402b "CDT must retry request upon slow start of CT"
5162 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5164 local agent=$(facet_active_host $SINGLEAGT)
5166 # deactivate all mdc for MDT0001
5167 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5170 local uuid=$(get_agent_uuid $agent)
5171 # check the agent is registered on MDT0000, and not on MDT0001
5172 check_agent_registered_by_mdt $uuid 0
5173 check_agent_unregistered_by_mdt $uuid 1
5175 # check running copytool process
5176 search_copytools $agent || error "No running copytools on $agent"
5178 # reactivate all mdc for MDT0001
5179 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5181 # make sure the copytool is now registered to all MDTs
5182 check_agent_registered $uuid
5184 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
5187 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5191 # create files on both MDT0000 and MDT0001
5194 local dir_mdt0=$DIR/$tdir/mdt0
5195 stack_trap "rm -rf $dir_mdt0" EXIT
5196 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
5198 # create 1 file on mdt0
5199 local fid1=$(create_small_file $dir_mdt0/$tfile)
5201 # deactivate all mdc for MDT0001
5202 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
5204 # send an HSM request for files in MDT0000
5205 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
5207 # check for completion of files in MDT0000
5208 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
5209 echo "archive successful on mdt0"
5211 # reactivate all mdc for MDT0001
5212 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
5214 run_test 404 "Inactive MDT does not block requests for active MDTs"
5217 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5223 local striped_dir=$DIR/$tdir/striped_dir
5225 # create striped dir on all of MDTs
5226 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
5228 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
5229 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
5230 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5231 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5233 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5234 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5235 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5236 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5238 # check that compound requests are shunt to the rights MDTs
5239 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5240 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5241 error "lfs hsm_archive"
5243 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5244 echo "archive successful on $fid1"
5245 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5246 echo "archive successful on $fid2"
5247 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5248 echo "archive successful on $fid3"
5249 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5250 echo "archive successful on $fid4"
5252 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5253 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5254 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5255 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5257 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5258 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5259 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5260 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5262 run_test 405 "archive and release under striped directory"
5265 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5267 [ $MDS_VERSION_CODE -lt $(version_code 2.7.64) ] &&
5268 skip "need MDS version at least 2.7.64"
5273 fid=$(create_small_file $DIR/$tdir/$tfile)
5278 $LFS hsm_archive $DIR/$tdir/$tfile
5279 wait_request_state "$fid" ARCHIVE SUCCEED
5280 $LFS hsm_release $DIR/$tdir/$tfile
5282 # Should migrate $tdir but not $tfile.
5283 $LFS migrate -m1 $DIR/$tdir &&
5284 error "migrating HSM an archived file should fail"
5286 $LFS hsm_restore $DIR/$tdir/$tfile
5287 wait_request_state "$fid" RESTORE SUCCEED
5289 $LFS hsm_remove $DIR/$tdir/$tfile
5290 wait_request_state "$fid" REMOVE SUCCEED
5292 cat $DIR/$tdir/$tfile > /dev/null ||
5293 error "cannot read $DIR/$tdir/$tfile"
5295 $LFS migrate -m1 $DIR/$tdir ||
5296 error "cannot complete migration after HSM remove"
5298 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5299 if ((mdt_index != 1)); then
5300 error "expected MDT index 1, got $mdt_index"
5303 # Refresh fid after migration.
5304 fid=$(path2fid $DIR/$tdir/$tfile)
5307 $LFS hsm_archive $DIR/$tdir/$tfile
5308 wait_request_state "$fid" ARCHIVE SUCCEED 1
5310 lctl set_param debug=+trace
5311 $LFS hsm_release $DIR/$tdir/$tfile ||
5312 error "cannot release $DIR/$tdir/$tfile"
5314 $LFS hsm_restore $DIR/$tdir/$tfile
5315 wait_request_state "$fid" RESTORE SUCCEED 1
5317 cat $DIR/$tdir/$tfile > /dev/null ||
5318 error "cannot read $DIR/$tdir/$tfile"
5320 run_test 406 "attempting to migrate HSM archived files is safe"
5323 local f=$DIR/$tdir/$tfile
5324 local f2=$DIR2/$tdir/$tfile
5325 local fid=$(create_empty_file "$f")
5329 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5330 wait_request_state $fid ARCHIVE SUCCEED
5333 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5334 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5336 # Prevent restore from completing
5340 # 1st request holds layout lock while appropriate
5341 # RESTORE record is still not added to llog
5345 # after umount hsm_actions->O/x/x log shouldn't have
5346 # double RESTORE records like below
5347 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5348 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5350 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5354 wait_request_state $fid RESTORE SUCCEED
5356 run_test 407 "Check for double RESTORE records in llog"
5360 [ $MDS_VERSION_CODE -lt $(version_code 2.6.92) ] &&
5361 skip "HSM migrate is not supported"
5363 test_mkdir -p $DIR/$tdir
5365 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5366 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5368 llapi_hsm_test -d $DIR/$tdir -b ||
5369 error "One llapi HSM test failed"
5371 llapi_hsm_test -d $DIR/$tdir ||
5372 error "One llapi HSM test failed"
5375 run_test 500 "various LLAPI HSM tests"
5378 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5379 skip "need MDS version at least 2.10.58"
5383 local f=$DIR/$tdir/$tfile
5386 # set changelog_mask to ALL
5387 changelog_chmask "ALL"
5389 chmod 777 $DIR/$tdir
5390 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5391 local fid=$(path2fid $f)
5394 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5395 -gid "$RUNAS_GID") ||
5396 error "No matching CREAT entry"
5398 # Parse the changelog
5399 eval local -A changelog=$(changelog2array $entry)
5400 local nid="${changelog[nid]}"
5403 echo "Got NID '$nid'"
5404 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5405 error "nid '$nid' does not match any client NID:" \
5408 run_test 600 "Changelog fields 'u=' and 'nid='"
5411 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5412 skip "need MDS version at least 2.10.58"
5416 local f=$DIR/$tdir/$tfile
5419 # set changelog_mask to ALL
5420 changelog_chmask "ALL"
5422 touch $f || error "touch $f failed"
5423 local fid=$(path2fid $f)
5426 cat $f || error "cat $f failed"
5428 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5429 error "No matching OPEN entry"
5431 run_test 601 "OPEN Changelog entry"
5434 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5435 skip "need MDS version at least 2.10.58"
5439 local f=$DIR/$tdir/$tfile
5442 # set changelog_mask to ALL
5443 changelog_chmask "ALL"
5445 touch $f || error "touch $f failed"
5446 local fid=$(path2fid $f)
5449 cat $f || error "cat $f failed"
5451 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5455 echo f > $f || error "write $f failed"
5458 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5460 # remove OPEN from changelog_mask
5461 changelog_chmask "-OPEN"
5465 cat $f || error "cat $f failed"
5468 changelog_find -type CLOSE -target-fid $fid &&
5469 error "There should be no CLOSE entry"
5473 echo f > $f || error "write $f failed"
5476 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5478 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5481 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5482 skip "need MDS version at least 2.10.58"
5486 local f=$DIR/$tdir/$tfile
5489 # set changelog_mask to ALL
5490 changelog_chmask "ALL"
5492 touch $f || error "touch $f failed"
5493 local fid=$(path2fid $f)
5495 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5498 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5500 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5501 error "No matching GXATR entry"
5503 run_test 603 "GETXATTR Changelog entry"
5506 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5507 skip "need MDS version at least 2.10.58"
5511 local f=$DIR/$tdir/$tfile
5512 local f2=$DIR2/$tdir/$tfile
5513 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5515 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5516 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5517 do_facet mds1 lctl set_param "$procname=20"
5521 # set changelog_mask to ALL
5522 changelog_chmask "ALL"
5524 touch $f || error "touch $f failed"
5525 local fid=$(path2fid $f)
5531 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5535 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5536 -gid "$RUNAS_GID" -mode "r--") ||
5537 error "No matching NOPEN entry"
5539 # Parse the changelog
5540 eval local -A changelog=$(changelog2array $entry)
5541 local nid="${changelog[nid]}"
5544 echo "Got NID '$nid'"
5545 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5546 error "nid '$nid' does not match any client NID:" \
5551 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5554 changelog_find -type NOPEN -target-fid $fid &&
5555 error "There should be no NOPEN entry"
5557 # Sleep for `changelog_deniednext` seconds
5562 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5565 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5566 -gid "$RUNAS_GID" -mode "r--") ||
5567 error "No matching NOPEN entry"
5569 # Parse the changelog
5570 eval local -A changelog=$(changelog2array $entry)
5571 local nid="${changelog[nid]}"
5574 echo "Got NID '$nid'"
5575 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5576 error "nid '$nid' does not match any client NID:" \
5579 run_test 604 "NOPEN Changelog entry"
5582 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5583 skip "need MDS version at least 2.10.58"
5587 local f=$DIR/$tdir/$tfile
5588 local f2=$DIR2/$tdir/$tfile
5591 # set changelog_mask to ALL
5592 changelog_chmask "ALL"
5594 touch $f || error "touch $f failed"
5595 local fid=$(path2fid $f)
5599 exec 3<> $f || error "open $f failed"
5603 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5607 exec 4<> $f || error "open $f failed"
5610 changelog_find -type OPEN -target-fid $fid &&
5611 error "There should be no OPEN entry"
5613 exec 4>&- || error "close $f failed"
5616 changelog_find -type CLOSE -target-fid $fid &&
5617 error "There should be no CLOSE entry"
5621 # access in rw, so different access mode should generate entries
5622 cat $f || error "cat $f failed"
5625 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5627 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5631 # same access as first one, should not generate new entries
5632 exec 4<> $f || error "open $f failed"
5635 changelog_find -type OPEN -target-fid $fid &&
5636 error "There should be no OPEN entry"
5638 exec 4>&- || error "close $f failed"
5641 changelog_find -type CLOSE -target-fid $fid &&
5642 error "There should be no CLOSE entry"
5646 # access by different user should generate new entries
5647 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5650 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5652 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5656 exec 3>&- || error "close $f failed"
5659 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5661 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5664 [ $MDS_VERSION_CODE -lt $(version_code 2.10.58) ] &&
5665 skip "need MDS version at least 2.10.58"
5667 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5668 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5669 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5670 skip_env "missing llog_reader" && return
5671 local fstype=$(facet_fstype mds1)
5675 local f=$DIR/$tdir/$tfile
5678 # set changelog_mask to ALL
5679 changelog_chmask "ALL"
5681 chmod 777 $DIR/$tdir
5682 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5683 local fid=$(path2fid $f)
5684 rm $f || error "rm $f failed"
5686 local mntpt=$(facet_mntpt mds1)
5690 #remount mds1 as ldiskfs or zfs type
5691 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5692 stop mds1 || error "stop mds1 failed"
5693 mount_fstype mds1 || error "remount mds1 failed"
5695 for ((i = 0; i < 1; i++)); do
5696 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5697 local cat_file=$(do_facet mds1 $llog_reader \
5698 $mntpt/changelog_catalog | awk \
5699 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5700 [ -n "$cat_file" ] || error "no catalog file"
5702 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5703 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5704 [ -n "$entry" ] || error "no CREAT entry"
5707 local uidgid=$(echo $entry |
5708 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5709 [ -n "$uidgid" ] || error "uidgid is empty"
5710 echo "Got UID/GID $uidgid"
5711 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5712 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5713 local nid=$(echo $entry |
5714 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5715 [ -n "$nid" ] || error "nid is empty"
5717 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5718 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5720 run_test 606 "llog_reader groks changelog fields"
5723 check_and_cleanup_lustre