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 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
20 . $LUSTRE/tests/test-framework.sh
22 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 MULTIOP=${MULTIOP:-multiop}
26 OPENFILE=${OPENFILE:-openfile}
27 MMAP_CAT=${MMAP_CAT:-mmap_cat}
28 MOUNT_2=${MOUNT_2:-"yes"}
31 # script only handles up to 10 MDTs (because of MDT_PREFIX)
32 [ $MDSCOUNT -gt 9 ] &&
33 error "script cannot handle more than 9 MDTs, please fix" && exit
35 check_and_setup_lustre
37 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
38 skip_env "Need MDS version at least 2.4.53" && exit
41 # $RUNAS_ID may get set incorrectly somewhere else
42 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
43 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
45 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
46 if getent group nobody; then
48 elif getent group nogroup; then
51 error "No generic nobody group"
56 # if there is no CLIENT1 defined, some tests can be ran on localhost
57 CLIENT1=${CLIENT1:-$HOSTNAME}
58 # if CLIENT2 doesn't exist then use CLIENT1 instead
59 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
61 # Exception is the test which need two separate nodes
62 CLIENT2=${CLIENT2:-$CLIENT1}
65 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
66 # the following associated variables are added:
68 # AGTCOUNT: number of agents
69 # AGTDEV{N}: target HSM mount point (root path of the backend)
70 # agt{N}_HOST: hostname of the agent agt{N}
71 # SINGLEAGT: facet of the single agent
73 # The number of agents is initialized as the number of remote client nodes.
74 # By default, only single copytool is started on a remote client/agent. If there
75 # was no remote client, then the copytool will be started on the local client.
81 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
82 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
84 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
85 if [[ $CLIENTCOUNT -gt 1 ]] &&
86 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
87 skip_env "SHARED_DIRECTORY should be accessible"\
92 # We used to put the HSM archive in $SHARED_DIRECTORY but that
93 # meant NFS issues could hose sanity-hsm sessions. So now we
95 for n in $(seq $AGTCOUNT); do
96 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
97 agent=CLIENT$((n + 1))
98 if [[ -z "${!agent}" ]]; then
99 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
102 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
105 export SINGLEAGT=${SINGLEAGT:-agt1}
107 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
108 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
109 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
110 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
111 export HSMTOOL_TESTDIR
112 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
116 # The test only support up to 10 MDTs
117 MDT_PREFIX="mdt.$FSNAME-MDT000"
118 HSM_PARAM="${MDT_PREFIX}0.hsm"
120 # archive is purged at copytool setup
121 HSM_ARCHIVE_PURGE=true
123 # Don't allow copytool error upon start/setup
124 HSMTOOL_NOERROR=false
127 # Get the backend root path for the given agent facet.
130 local dev=AGTDEV$(facet_number $facet)
137 # get MDT device for each mdc
138 for mdtno in $(seq 1 $MDSCOUNT); do
139 local idx=$(($mdtno - 1))
140 MDT[$idx]=$($LCTL get_param -n \
141 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
142 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
147 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
148 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
152 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
154 echo "Killing existing copytools on $hosts"
155 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
159 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
160 local wait_timeout=200
161 local wait_start=$SECONDS
162 local wait_end=$((wait_start + wait_timeout))
163 local sleep_time=100000 # 0.1 second
165 while ((SECONDS < wait_end)); do
166 if ! search_copytools $hosts; then
167 echo "copytools stopped in $((SECONDS - wait_start))s"
171 echo "copytools still running on $hosts"
173 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
174 sleep_time=$(bc <<< "$sleep_time * 2")
177 # try to dump Copytool's stack
178 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
179 "echo t >/proc/sysrq-trigger"
181 echo "copytools failed to stop in ${wait_timeout}s"
186 copytool_monitor_setup() {
187 local facet=${1:-$SINGLEAGT}
188 local agent=$(facet_active_host $facet)
190 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
191 local test_dir=$(do_node $agent "$cmd") ||
192 error "Failed to create tempdir on $agent"
193 export HSMTOOL_MONITOR_DIR=$test_dir
195 # Create the fifo and a monitor (cat dies when copytool dies)
196 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
197 error "failed to create copytool fifo on $agent"
198 cmd="cat $test_dir/fifo > $test_dir/events &"
199 cmd+=" echo \\\$! > $test_dir/monitor_pid"
201 if [[ $PDSH == *Rmrsh* ]]; then
202 # This is required for pdsh -Rmrsh and its handling of remote
204 # Regular ssh and pdsh -Rssh work fine without this
205 # backgrounded subshell nonsense.
206 (do_node $agent "$cmd") &
207 export HSMTOOL_MONITOR_PDSH=$!
209 # Slightly racy, but just making a best-effort to catch obvious
212 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
213 error "Failed to start copytool monitor on $agent"
215 do_node $agent "$cmd"
217 error "Failed to start copytool monitor on $agent"
222 copytool_monitor_cleanup() {
223 local facet=${1:-$SINGLEAGT}
224 local agent=$(facet_active_host $facet)
226 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
227 # Should die when the copytool dies, but just in case.
228 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
229 cmd+=" 2>/dev/null || true"
230 do_node $agent "$cmd"
231 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
232 export HSMTOOL_MONITOR_DIR=
235 # The pdsh should die on its own when the monitor dies. Just
236 # in case, though, try to clean up to avoid any cruft.
237 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
238 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
239 export HSMTOOL_MONITOR_PDSH=
249 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
256 local host="$(facet_host "$1")"
257 local prefix=$TESTLOG_PREFIX
258 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
260 printf "${prefix}.copytool${archive_id}_log.${host}.log"
265 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
270 mkdir -p "$(dirname "$2")" ||
271 error "cannot create directory '$(dirname "$2")'"
272 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
277 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
278 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
279 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
280 [ ${#misc_options[@]} -gt 0 ] &&
281 cmd+=" $(IFS=" " echo "$@")"
282 cmd+=" \"$mountpoint\""
284 echo "Starting copytool $facet on $(facet_host $facet)"
285 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
286 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
290 local facet="${1:-$SINGLEAGT}"
292 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
295 # Main entry point to perform copytool related operations
299 # setup setup a copytool to run in the background, that copytool will be
301 # import import a file from an HSM backend
302 # rebind rebind an archived file to a new fid
304 # Although the semantics might suggest otherwise, one does not need to 'setup'
305 # a copytool before a call to 'copytool import' or 'copytool rebind'.
313 local fail_on_error=true
314 local -a misc_options
315 while [ $# -gt 0 ]; do
323 local mountpoint="$1"
327 local archive_id="$1"
331 local bandwidth="$1" # in MB/s
334 local fail_on_error=false
337 # Uncommon(/copytool dependent) option
344 # Use default values if needed
345 local facet=${facet:-$SINGLEAGT}
346 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
347 local hsm_root="$(hsm_root "$facet")"
349 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
350 do_facet $facet mkdir -p "$hsm_root" ||
351 error "mkdir '$hsm_root' failed"
355 local copytool=lhsmtool
359 __${copytool}_${action} "${misc_options[@]}"
360 if [ $? -ne 0 ]; then
365 local host="$(facet_host $facet)"
366 error_msg="Failed to start copytool $facet on '$host'"
369 local src="${misc_options[0]}"
370 local dest="${misc_options[1]}"
371 error_msg="Failed to import '$src' to '$dest'"
374 error_msg="could not rebind file"
378 $fail_on_error && error "$error_msg" || echo "$error_msg"
382 get_copytool_event_log() {
383 local facet=${1:-$SINGLEAGT}
384 local agent=$(facet_active_host $facet)
386 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
387 error "Can't get event log: No monitor directory!"
389 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
390 error "Could not collect event log from $agent"
394 local agents=${1:-$(facet_active_host $SINGLEAGT)}
396 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
397 echo "Copytool is suspended on $agents"
400 copytool_continue() {
401 local agents=${1:-$(facet_active_host $SINGLEAGT)}
403 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
404 echo "Copytool is continued on $agents"
407 copytool_remove_backend() {
409 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
410 echo "Remove from backend: $fid = $be"
411 do_facet $SINGLEAGT rm -f $be
414 file_creation_failure() {
421 df $MOUNT $MOUNT2 >&2
422 error "Not enough space to create $file with $cmd"
425 error "cannot create $file with $cmd, status=$err"
430 # Creates a file using dd
436 local source=${5:-/dev/zero}
440 if [ -n "$conv" ]; then
444 # Create the directory in case it does not exist
445 mkdir -p "$(dirname "$file")"
446 # Delete the file in case it already exist
449 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
450 path2fid "$file" || error "cannot get FID of '$file'"
453 echo "cannot create file '$file'" >&2;
454 # Let the caller decide what to do on error
459 create_empty_file() {
460 create_file "${1/$DIR/$DIR2}" 1M 0 ||
461 file_creation_failure dd "${1/$DIR/$DIR2}" $?
464 create_small_file() {
465 local source_file=/dev/urandom
468 local conv=${2:-fsync}
470 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
471 file_creation_failure dd "${1/$DIR/$DIR2}" $?
474 create_small_sync_file() {
475 create_small_file "$1" sync
478 create_archive_file() {
479 local file="$(hsm_root)/$1"
481 local source=/dev/urandom
483 # Create the counterpart directory of the archive
484 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
485 error "cannot create archive directory '$(dirname "$file")'"
487 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
488 error "cannot create archive file '$file'"
492 local hsm_root="$(hsm_root)"
493 local file="$hsm_root/$2"
495 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
496 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
497 error "mkdir '$(dirname "$file")' failed"
498 do_facet $SINGLEAGT cp -p "$1" "$file" ||
499 error "cannot copy '$1' to '$file'"
508 if [[ "$value" != "" ]]; then
511 for mdtno in $(seq 1 $MDSCOUNT); do
512 local idx=$(($mdtno - 1))
513 local facet=mds${mdtno}
514 # if $arg include -P option, run 1 set_param per MDT on the MGS
515 # else, run set_param on each MDT
516 [[ $arg = *"-P"* ]] && facet=mgs
517 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
518 [[ $? != 0 ]] && rc=1
528 for mdtno in $(seq 1 $MDSCOUNT); do
529 local idx=$(($mdtno - 1))
530 wait_result mds${mdtno} \
531 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
533 error "$key state is not '$target' on mds${mdtno}"
539 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
547 mdts_set_param "$opt -n" "hsm.$param" "$value"
554 mdts_set_param "" hsm_control "$cmd"
555 mdts_check_param hsm_control "$target" 10
558 cdt_set_sanity_policy() {
559 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
562 mdts_set_param "" hsm.policy "+NRA"
563 mdts_set_param "" hsm.policy "-NBR"
564 CDT_POLICY_HAD_CHANGED=
569 mdts_set_param "" hsm.policy "+NRA"
570 CDT_POLICY_HAD_CHANGED=true
573 cdt_clear_no_retry() {
574 mdts_set_param "" hsm.policy "-NRA"
575 CDT_POLICY_HAD_CHANGED=true
578 cdt_set_non_blocking_restore() {
579 mdts_set_param "" hsm.policy "+NBR"
580 CDT_POLICY_HAD_CHANGED=true
583 cdt_clear_non_blocking_restore() {
584 mdts_set_param "" hsm.policy "-NBR"
585 CDT_POLICY_HAD_CHANGED=true
588 cdt_clear_mount_state() {
589 mdts_set_param "-P -d" hsm_control ""
592 cdt_set_mount_state() {
593 mdts_set_param "-P" hsm_control "$1"
594 # set_param -P is asynchronous operation and could race with set_param.
595 # In such case configs could be retrieved and applied at mgc after
596 # set_param -P completion. Sleep here to avoid race with set_param.
597 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
598 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
599 # and 10 seconds to retrieve config from server.
604 mdts_check_param hsm_control "$1" 20
608 set_test_state disabled disabled
612 set_test_state enabled enabled
616 set_test_state shutdown stopped
620 set_test_state purge enabled
626 cdt_set_sanity_policy
630 local client_count=$1
631 if [[ $CLIENTCOUNT -lt $client_count ]]; then
632 skip "Need $client_count or more clients, have $CLIENTCOUNT"
639 $LFS path2fid $1 | tr -d '[]'
640 return ${PIPESTATUS[0]}
648 if [[ $u == "user" ]]; then
649 st=$($RUNAS $LFS hsm_state $f)
652 st=$($LFS hsm_state $f)
655 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
657 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
661 get_hsm_archive_id() {
664 st=$($LFS hsm_state $f)
665 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
667 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
675 local st=$(get_hsm_flags $f)
676 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
679 check_hsm_flags_user() {
683 local st=$(get_hsm_flags $f user)
684 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
696 if [[ "$3" != 1 ]]; then
700 cp $1 $f || file_creation_failure cp $f $?
702 path2fid $f || error "cannot get fid on $f"
705 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
707 # Note that this might lead to surprising behaviours such as deleting an
708 # important file for the currently running test
709 delete_large_files() {
710 printf "Deleting large files...\n" >&2
711 find $MOUNT -size +10M -delete
712 wait_delete_completed
715 make_custom_file_for_progress() {
716 local count=${2:-"39"}
717 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
720 [[ $count -gt 0 ]] || error "Invalid file size"
721 [[ $bs -gt 0 ]] || error "Invalid stripe size"
723 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
724 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
725 echo "It might be due to a lack of space in the filesystem" >&2
726 delete_large_files >&2
727 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
728 file_creation_failure dd "${1/$DIR/$DIR2}" $?
735 wait_update --verbose $(facet_active_host $facet) "$@"
738 wait_request_state() {
742 # 4th arg (mdt index) is optional
744 local mds=mds$(($mdtidx + 1))
746 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
747 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
749 wait_result $mds "$cmd" $state 200 ||
750 error "request on $fid is not $state on $mds"
753 get_request_state() {
757 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
758 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
761 get_request_count() {
765 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
766 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
769 # Ensure the number of HSM request for a given FID is correct
770 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
771 assert_request_count() {
772 local request_count=$(get_request_count $1 $2)
773 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
775 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
782 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
783 [[ -n $fid ]] && cmd+=" | grep '$fid'"
784 cmd+=" | egrep 'WAITING|STARTED'"
786 wait_result $SINGLEMDS "$cmd" "" $timeout ||
787 error "requests did not complete"
790 wait_for_grace_delay() {
791 local val=$(get_hsm_param grace_delay)
795 wait_for_loop_period() {
796 local val=$(get_hsm_param loop_period)
803 # python2.6 in EL6 includes an internal json module
804 local json_parser='import json; import fileinput;'
805 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
806 json_parser+='json.loads([line for line in '
807 json_parser+='fileinput.input()][0]).items()])'
809 echo $raw_event | python -c "$json_parser"
812 get_agent_by_uuid_mdt() {
815 local mds=mds$(($mdtidx + 1))
816 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
820 check_agent_registered_by_mdt() {
823 local mds=mds$(($mdtidx + 1))
824 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
825 if [[ ! -z "$agent" ]]; then
826 echo "found agent $agent on $mds"
828 error "uuid $uuid not found in agent list on $mds"
832 check_agent_unregistered_by_mdt() {
835 local mds=mds$(($mdtidx + 1))
836 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
837 if [[ -z "$agent" ]]; then
838 echo "uuid not found in agent list on $mds"
840 error "uuid found in agent list on $mds: $agent"
844 check_agent_registered() {
847 for mdsno in $(seq 1 $MDSCOUNT); do
848 check_agent_registered_by_mdt $uuid $((mdsno - 1))
852 check_agent_unregistered() {
855 for mdsno in $(seq 1 $MDSCOUNT); do
856 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
861 local agent=${1:-$(facet_active_host $SINGLEAGT)}
863 # Lustre mount-point is mandatory and last parameter on
865 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
867 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
869 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
875 # populate MDT device array
878 # cleanup from previous bad setup
881 # for recovery tests, coordinator needs to be started at mount
883 # the lustre conf must be without hsm on (like for sanity.sh)
884 echo "Set HSM on and start"
885 cdt_set_mount_state enabled
886 cdt_check_state enabled
888 echo "Set sanity-hsm HSM policy"
889 cdt_set_sanity_policy
891 # finished requests are quickly removed from list
892 set_hsm_param grace_delay 10
894 CLIENT_NIDS=( $($LCTL list_nids all) )
896 test_1A() { # was test_1
900 local f=$DIR/$tdir/$tfile
904 check_hsm_flags_user $f "0x00000000"
906 $RUNAS $LFS hsm_set --norelease $f ||
907 error "user could not change hsm flags"
908 check_hsm_flags_user $f "0x00000010"
910 $RUNAS $LFS hsm_clear --norelease $f ||
911 error "user could not clear hsm flags"
912 check_hsm_flags_user $f "0x00000000"
914 # User could not change those flags...
915 $RUNAS $LFS hsm_set --exists $f &&
916 error "user should not set this flag"
917 check_hsm_flags_user $f "0x00000000"
920 $LFS hsm_set --exists $f ||
921 error "root could not change hsm flags"
922 check_hsm_flags_user $f "0x00000001"
924 $LFS hsm_clear --exists $f ||
925 error "root could not clear hsm state"
926 check_hsm_flags_user $f "0x00000000"
929 run_test 1A "lfs hsm flags root/non-root access"
932 local f=$DIR/$tdir/$tfile
933 local fid=$(create_small_file $f)
937 $LFS hsm_archive $f || error "could not archive file"
938 wait_request_state $fid ARCHIVE SUCCEED
940 # Release and check states
941 $LFS hsm_release $f || error "could not release file"
942 echo -n "Verifying released state: "
943 check_hsm_flags $f "0x0000000d"
945 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
947 run_test 1a "mmap & cat a HSM released file"
951 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
952 error "failed to set default stripe"
953 local f=$DIR/$tdir/$tfile
956 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
957 error "failed to create file"
958 local fid=$(path2fid $f)
963 $LFS hsm_archive $f || error "could not archive file"
964 wait_request_state $fid ARCHIVE SUCCEED
967 $LFS hsm_release $f || error "could not release file"
968 echo "verify released state: "
969 check_hsm_flags $f "0x0000000d" && echo "pass"
972 $LFS hsm_restore $f || error "could not restore file"
973 wait_request_state $fid RESTORE SUCCEED
974 echo "verify restored state: "
975 check_hsm_flags $f "0x00000009" && echo "pass"
977 run_test 1b "Archive, Release and Restore composite file"
983 local f=$DIR/$tdir/$tfile
986 # Test whether we can set the maximum archive number.
987 local LOCAL_HSM_ARCHIVE_NUMBER=32
988 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
989 error "root could not change hsm flags"
990 check_hsm_flags_user $f "0x00000001"
991 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
992 local st=$(get_hsm_archive_id $f)
993 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
994 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
996 # Test whether setting archive number 0 results in no change.
997 $LFS hsm_set --exists --archive-id 0 $f ||
998 error "root could not change hsm flags"
999 check_hsm_flags_user $f "0x00000001"
1000 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1001 st=$(get_hsm_archive_id $f)
1002 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1003 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1005 # Test whether setting archive number > 32 results in error.
1006 $LFS hsm_set --exists --archive-id 33 $f &&
1007 error "archive number is larger than 32"
1008 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"
1025 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1026 error "failed to set default stripe"
1027 local f=$DIR/$tdir/$tfile
1030 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1031 error "failed to create file"
1032 local fid=$(path2fid $f)
1037 $LFS hsm_archive $f || error "could not archive file"
1038 wait_request_state $fid ARCHIVE SUCCEED
1041 $LFS hsm_release $f || error "could not release file"
1042 echo "verify released state: "
1043 check_hsm_flags $f "0x0000000d" && echo "pass"
1046 $LFS hsm_restore $f || error "could not restore file"
1047 wait_request_state $fid RESTORE SUCCEED
1048 echo "verify restored state: "
1049 check_hsm_flags $f "0x00000009" && echo "pass"
1051 run_test 1d "Archive, Release and Restore DoM file"
1054 local f=$DIR/$tdir/$tfile
1056 create_empty_file "$f"
1057 # New files are not dirty
1058 check_hsm_flags $f "0x00000000"
1060 # For test, we simulate an archived file.
1061 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1062 check_hsm_flags $f "0x00000001"
1064 # chmod do not put the file dirty
1065 chmod 600 $f || error "could not chmod test file"
1066 check_hsm_flags $f "0x00000001"
1068 # chown do not put the file dirty
1069 chown $RUNAS_ID $f || error "could not chown test file"
1070 check_hsm_flags $f "0x00000001"
1072 # truncate put the file dirty
1073 $TRUNCATE $f 1 || error "could not truncate test file"
1074 check_hsm_flags $f "0x00000003"
1076 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1077 check_hsm_flags $f "0x00000001"
1079 run_test 2 "Check file dirtyness when doing setattr"
1085 # New files are not dirty
1086 cp -p /etc/passwd $f
1087 check_hsm_flags $f "0x00000000"
1089 # For test, we simulate an archived file.
1090 $LFS hsm_set --exists $f ||
1091 error "user could not change hsm flags"
1092 check_hsm_flags $f "0x00000001"
1094 # Reading a file, does not set dirty
1095 cat $f > /dev/null || error "could not read file"
1096 check_hsm_flags $f "0x00000001"
1098 # Open for write without modifying data, does not set dirty
1099 openfile -f O_WRONLY $f || error "could not open test file"
1100 check_hsm_flags $f "0x00000001"
1102 # Append to a file sets it dirty
1103 cp -p /etc/passwd $f.append || error "could not create file"
1104 $LFS hsm_set --exists $f.append ||
1105 error "user could not change hsm flags"
1106 dd if=/etc/passwd of=$f.append bs=1 count=3\
1107 conv=notrunc oflag=append status=noxfer ||
1108 file_creation_failure dd $f.append $?
1109 check_hsm_flags $f.append "0x00000003"
1111 # Modify a file sets it dirty
1112 cp -p /etc/passwd $f.modify || error "could not create file"
1113 $LFS hsm_set --exists $f.modify ||
1114 error "user could not change hsm flags"
1115 dd if=/dev/zero of=$f.modify bs=1 count=3\
1116 conv=notrunc status=noxfer ||
1117 file_creation_failure dd $f.modify $?
1118 check_hsm_flags $f.modify "0x00000003"
1120 # Open O_TRUNC sets dirty
1121 cp -p /etc/passwd $f.trunc || error "could not create file"
1122 $LFS hsm_set --exists $f.trunc ||
1123 error "user could not change hsm flags"
1124 cp /etc/group $f.trunc || error "could not override a file"
1125 check_hsm_flags $f.trunc "0x00000003"
1127 # Mmapped a file sets dirty
1128 cp -p /etc/passwd $f.mmap || error "could not create file"
1129 $LFS hsm_set --exists $f.mmap ||
1130 error "user could not change hsm flags"
1131 multiop $f.mmap OSMWUc || error "could not mmap a file"
1132 check_hsm_flags $f.mmap "0x00000003"
1134 run_test 3 "Check file dirtyness when opening for write"
1137 local f=$DIR/$tdir/$tfile
1138 local fid=$(create_small_file $f)
1141 local st=$(get_request_state $fid CANCEL)
1142 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1144 run_test 4 "Useless cancel must not be registered"
1147 # test needs a running copytool
1151 local f=$DIR/$tdir/$tfile
1152 local fid=$(copy_file /etc/passwd $f)
1154 wait_request_state $fid ARCHIVE SUCCEED
1156 check_hsm_flags $f "0x00000009"
1158 run_test 8 "Test default archive number"
1160 test_9A() { # was test_9
1161 # we do not use the default one to be sure
1162 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1163 copytool setup --archive-id $archive_id
1165 # give time for CT to register with MDTs
1166 sleep $(($MDSCOUNT*2))
1167 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1168 check_agent_registered $uuid
1171 local f=$DIR/$tdir/$tfile
1172 local fid=$(copy_file /etc/passwd $f)
1173 $LFS hsm_archive --archive $archive_id $f
1174 wait_request_state $fid ARCHIVE SUCCEED
1176 check_hsm_flags $f "0x00000009"
1178 run_test 9A "Use of explicit archive number, with dedicated copytool"
1181 needclients 3 || return 0
1187 # start all of the copytools
1188 for n in $(seq $AGTCOUNT); do
1189 copytool setup --facet agt$n
1193 for n in $(seq $AGTCOUNT); do
1194 file=$DIR/$tdir/$tfile.$n
1195 fid=$(create_small_file $file)
1197 $LFS hsm_archive $file || error "could not archive file $file"
1198 wait_request_state $fid ARCHIVE SUCCEED
1199 check_hsm_flags $file "0x00000009"
1202 run_test 9a "Multiple remote agents"
1205 # test needs a running copytool
1208 mkdir -p $DIR/$tdir/d1
1209 local f=$DIR/$tdir/$tfile
1210 local fid=$(copy_file /etc/hosts $f)
1211 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1212 error "hsm_archive failed"
1213 wait_request_state $fid ARCHIVE SUCCEED
1215 local hsm_root="$(copytool_device $SINGLEAGT)"
1216 local archive="$(do_facet $SINGLEAGT \
1217 find "$hsm_root" -name "$fid" -print0)"
1218 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1220 echo "Verifying content"
1221 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1222 echo "Verifying hsm state "
1223 check_hsm_flags $f "0x00000009"
1225 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1226 local st=$(get_hsm_archive_id $f)
1227 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1228 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1230 run_test 10a "Archive a file"
1233 # test needs a running copytool
1237 local f=$DIR/$tdir/$tfile
1238 local fid=$(copy_file /etc/hosts $f)
1239 $LFS hsm_archive $f || error "archive request failed"
1240 wait_request_state $fid ARCHIVE SUCCEED
1242 $LFS hsm_archive $f || error "archive of non dirty file failed"
1243 local cnt=$(get_request_count $fid ARCHIVE)
1244 [[ "$cnt" == "1" ]] ||
1245 error "archive of non dirty file must not make a request"
1247 run_test 10b "Archive of non dirty file must work without doing request"
1250 # test needs a running copytool
1254 local f=$DIR/$tdir/$tfile
1255 local fid=$(copy_file /etc/hosts $f)
1256 $LFS hsm_set --noarchive $f
1257 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1260 run_test 10c "Check forbidden archive"
1263 # test needs a running copytool
1267 local f=$DIR/$tdir/$tfile
1268 local fid=$(copy_file /etc/hosts $f)
1269 $LFS hsm_archive $f || error "cannot archive $f"
1270 wait_request_state $fid ARCHIVE SUCCEED
1272 local ar=$(get_hsm_archive_id $f)
1273 local dflt=$(get_hsm_param default_archive_id)
1274 [[ $ar == $dflt ]] ||
1275 error "archived file is not on default archive: $ar != $dflt"
1277 run_test 10d "Archive a file on the default archive id"
1281 copy2archive /etc/hosts $tdir/$tfile
1282 local f=$DIR/$tdir/$tfile
1284 copytool import $tdir/$tfile $f
1285 echo -n "Verifying released state: "
1286 check_hsm_flags $f "0x0000000d"
1288 local LSZ=$(stat -c "%s" $f)
1289 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1291 echo "Verifying imported size $LSZ=$ASZ"
1292 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1293 echo -n "Verifying released pattern: "
1294 local PTRN=$($GETSTRIPE -L $f)
1296 [[ $PTRN == released ]] || error "Is not released"
1297 local fid=$(path2fid $f)
1298 echo "Verifying new fid $fid in archive"
1300 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1301 error "No archive for fid $fid"
1303 run_test 11a "Import a file"
1306 # test needs a running copytool
1310 local f=$DIR/$tdir/$tfile
1311 local fid=$(copy_file /etc/hosts $f)
1312 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1313 error "hsm_archive failed"
1314 wait_request_state $fid ARCHIVE SUCCEED
1316 local FILE_HASH=$(md5sum $f)
1319 copytool import $fid $f
1321 echo "$FILE_HASH" | md5sum -c
1323 [[ $? -eq 0 ]] || error "Restored file differs"
1325 run_test 11b "Import a deleted file using its FID"
1328 # test needs a running copytool
1332 copy2archive /etc/hosts $tdir/$tfile
1334 local f=$DIR/$tdir/$tfile
1335 copytool import $tdir/$tfile $f
1336 local f2=$DIR2/$tdir/$tfile
1337 echo "Verifying released state: "
1338 check_hsm_flags $f2 "0x0000000d"
1340 local fid=$(path2fid $f2)
1341 $LFS hsm_restore $f2
1342 wait_request_state $fid RESTORE SUCCEED
1344 echo "Verifying file state: "
1345 check_hsm_flags $f2 "0x00000009"
1347 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1349 [[ $? -eq 0 ]] || error "Restored file differs"
1351 run_test 12a "Restore an imported file explicitly"
1354 # test needs a running copytool
1358 copy2archive /etc/hosts $tdir/$tfile
1360 local f=$DIR/$tdir/$tfile
1361 copytool import $tdir/$tfile $f
1362 echo "Verifying released state: "
1363 check_hsm_flags $f "0x0000000d"
1365 cat $f > /dev/null || error "File read failed"
1367 echo "Verifying file state after restore: "
1368 check_hsm_flags $f "0x00000009"
1370 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1372 [[ $? -eq 0 ]] || error "Restored file differs"
1374 run_test 12b "Restore an imported file implicitly"
1377 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1379 # test needs a running copytool
1382 local f=$DIR/$tdir/$tfile
1384 $LFS setstripe -c 2 "$f"
1386 fid=$(make_custom_file_for_progress $f 5)
1387 [ $? != 0 ] && skip "not enough free space" && return
1389 local FILE_CRC=$(md5sum $f)
1391 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1392 wait_request_state $fid ARCHIVE SUCCEED
1393 $LFS hsm_release $f || error "release $f failed"
1395 echo "$FILE_CRC" | md5sum -c
1397 [[ $? -eq 0 ]] || error "Restored file differs"
1399 run_test 12c "Restore a file with stripe of 2"
1402 # test needs a running copytool
1407 local f=$DIR/$tdir/$tfile
1408 local fid=$(copy_file /etc/hosts $f)
1409 $LFS hsm_restore $f || error "restore of non archived file failed"
1410 local cnt=$(get_request_count $fid RESTORE)
1411 [[ "$cnt" == "0" ]] ||
1412 error "restore non archived must not make a request"
1413 $LFS hsm_archive $f ||
1414 error "archive request failed"
1415 wait_request_state $fid ARCHIVE SUCCEED
1416 $LFS hsm_restore $f ||
1417 error "restore of non released file failed"
1418 local cnt=$(get_request_count $fid RESTORE)
1419 [[ "$cnt" == "0" ]] ||
1420 error "restore a non dirty file must not make a request"
1422 run_test 12d "Restore of a non archived, non released file must work"\
1423 " without doing request"
1426 # test needs a running copytool
1430 local f=$DIR/$tdir/$tfile
1431 local fid=$(copy_file /etc/hosts $f)
1432 $LFS hsm_archive $f || error "archive request failed"
1433 wait_request_state $fid ARCHIVE SUCCEED
1436 cat /etc/hosts >> $f
1440 $LFS hsm_restore $f && error "restore a dirty file must fail"
1443 run_test 12e "Check forbidden restore"
1446 # test needs a running copytool
1450 local f=$DIR/$tdir/$tfile
1451 local fid=$(copy_file /etc/hosts $f)
1453 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1454 wait_request_state $fid ARCHIVE SUCCEED
1455 $LFS hsm_release $f || error "release of $f failed"
1457 wait_request_state $fid RESTORE SUCCEED
1459 echo -n "Verifying file state: "
1460 check_hsm_flags $f "0x00000009"
1462 diff -q /etc/hosts $f
1464 [[ $? -eq 0 ]] || error "Restored file differs"
1466 run_test 12f "Restore a released file explicitly"
1469 # test needs a running copytool
1473 local f=$DIR/$tdir/$tfile
1474 local fid=$(copy_file /etc/hosts $f)
1476 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1477 wait_request_state $fid ARCHIVE SUCCEED
1478 $LFS hsm_release $f || error "release of $f failed"
1480 diff -q /etc/hosts $f
1483 # we check we had a restore done
1484 wait_request_state $fid RESTORE SUCCEED
1486 [[ $st -eq 0 ]] || error "Restored file differs"
1488 run_test 12g "Restore a released file implicitly"
1491 needclients 2 || return 0
1493 # test needs a running copytool
1497 local f=$DIR/$tdir/$tfile
1498 local fid=$(copy_file /etc/hosts $f)
1500 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1501 wait_request_state $fid ARCHIVE SUCCEED
1502 $LFS hsm_release $f || error "release of $f failed"
1504 do_node $CLIENT2 diff -q /etc/hosts $f
1507 # we check we had a restore done
1508 wait_request_state $fid RESTORE SUCCEED
1510 [[ $st -eq 0 ]] || error "Restored file differs"
1512 run_test 12h "Restore a released file implicitly from a second node"
1515 # test needs a running copytool
1519 local f=$DIR/$tdir/$tfile
1520 local fid=$(copy_file /etc/passwd $f)
1521 $LFS hsm_archive $f || error "archive of $f failed"
1522 wait_request_state $fid ARCHIVE SUCCEED
1524 $LFS hsm_release $f || error "release of $f failed"
1528 [[ $? -eq 0 ]] || error "Restored file differs"
1530 run_test 12m "Archive/release/implicit restore"
1533 # test needs a running copytool
1537 copy2archive /etc/hosts $tdir/$tfile
1539 local f=$DIR/$tdir/$tfile
1540 copytool import $tdir/$tfile $f
1542 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1543 error "Restored file differs"
1545 $LFS hsm_release $f || error "release of $f failed"
1547 run_test 12n "Import/implicit restore/release"
1550 # test needs a running copytool
1554 local f=$DIR/$tdir/$tfile
1555 local fid=$(copy_file /etc/hosts $f)
1557 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1558 wait_request_state $fid ARCHIVE SUCCEED
1559 $LFS hsm_release $f || error "release of $f failed"
1561 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1562 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1564 # set no retry action mode
1567 diff -q /etc/hosts $f
1570 # we check we had a restore failure
1571 wait_request_state $fid RESTORE FAILED
1573 [[ $st -eq 0 ]] && error "Restore must fail"
1575 # remove no retry action mode
1578 # check file is still released
1579 check_hsm_flags $f "0x0000000d"
1581 # retry w/o failure injection
1582 do_facet $SINGLEMDS lctl set_param fail_loc=0
1584 # to be sure previous RESTORE result is gone
1586 wait_for_grace_delay
1588 diff -q /etc/hosts $f
1591 # we check we had a restore done
1592 wait_request_state $fid RESTORE SUCCEED
1594 [[ $st -eq 0 ]] || error "Restored file differs"
1596 run_test 12o "Layout-swap failure during Restore leaves file released"
1599 # test needs a running copytool
1603 local f=$DIR/$tdir/$tfile
1604 local fid=$(copy_file /etc/hosts $f)
1606 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1607 wait_request_state $fid ARCHIVE SUCCEED
1608 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1609 $LFS hsm_release $f || error "cannot release $f"
1610 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1611 $LFS hsm_release $f || error "cannot release $f"
1612 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1614 run_test 12p "implicit restore of a file on copytool mount point"
1617 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1618 skip "need MDS version at least 2.7.58" && return 0
1620 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1621 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1622 error "cannot mount $MOUNT3 on $SINGLEAGT"
1624 # test needs a running copytool
1625 copytool setup -m "$MOUNT3"
1627 local f=$DIR/$tdir/$tfile
1628 local f2=$DIR2/$tdir/$tfile
1629 local fid=$(create_small_file $f)
1630 local orig_size=$(stat -c "%s" $f)
1632 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1633 wait_request_state $fid ARCHIVE SUCCEED
1635 $LFS hsm_release $f || error "could not release file"
1636 check_hsm_flags $f "0x0000000d"
1639 wait_copytools || error "copytool failed to stop"
1641 cat $f > /dev/null &
1643 # wait a bit to allow implicit restore request to be handled.
1644 # if not, next stat would also block on layout-lock.
1647 local size=$(stat -c "%s" $f2)
1648 [ $size -eq $orig_size ] ||
1649 error "$f2: wrong size after archive: $size != $orig_size"
1651 copytool setup -m "$MOUNT3"
1655 size=$(stat -c "%s" $f)
1656 [ $size -eq $orig_size ] ||
1657 error "$f: wrong size after restore: $size != $orig_size"
1659 size=$(stat -c "%s" $f2)
1660 [ $size -eq $orig_size ] ||
1661 error "$f2: wrong size after restore: $size != $orig_size"
1665 size=$(stat -c "%s" $f)
1667 error "$f: wrong size after overwrite: $size != 0"
1669 size=$(stat -c "%s" $f2)
1671 error "$f2: wrong size after overwrite: $size != 0"
1673 run_test 12q "file attributes are refreshed after restore"
1677 for i in {1..10}; do
1678 local archive_dir="$(hsm_root)"/subdir/dir.$i
1680 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1681 for j in {1..10}; do
1682 local archive_file="$archive_dir"/file.$j
1684 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1690 copytool import "subdir" "$DIR/$tdir"
1692 # To check the import, the test uses diff with the -r flag
1693 # This is nice, but diff only checks files one by one, and triggering
1694 # an implicit restore for one file at a time will consume as many
1695 # seconds as there are files to compare. To speed this up, a restore
1696 # operation is triggered manually first.
1698 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1700 # Compare the imported data
1701 do_facet $SINGLEAGT \
1702 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1703 error "imported files differ from archived data"
1705 run_test 13 "Recursively import and restore a directory"
1708 # test needs a running copytool
1712 local f=$DIR/$tdir/$tfile
1713 local fid=$(create_small_file $f)
1714 local sum=$(md5sum $f | awk '{print $1}')
1715 $LFS hsm_archive $f || error "could not archive file"
1716 wait_request_state $fid ARCHIVE SUCCEED
1718 # create released file (simulate llapi_hsm_import call)
1719 local fid2=$(create_empty_file "$f")
1720 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1721 $LFS hsm_release $f || error "could not release file"
1723 # rebind the archive to the newly created file
1724 echo "rebind $fid to $fid2"
1726 copytool rebind $fid $fid2
1728 # restore file and compare md5sum
1729 local sum2=$(md5sum $f | awk '{print $1}')
1731 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1733 run_test 14 "Rebind archived file to a new fid"
1736 # test needs a running copytool
1740 local f=$DIR/$tdir/$tfile
1742 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1746 for i in $(seq 1 $count); do
1747 fids[$i]=$(create_small_file $f.$i)
1748 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1749 $LFS hsm_archive $f.$i || error "could not archive file"
1751 wait_all_done $(($count*60))
1753 stack_trap "rm -f $tmpfile" EXIT
1756 for i in $(seq 1 $count); do
1757 local fid2=$(create_empty_file "${f}.${i}")
1758 # add the rebind operation to the list
1759 echo ${fids[$i]} $fid2 >> $tmpfile
1761 # set it released (simulate llapi_hsm_import call)
1762 $LFS hsm_set --archived --exists $f.$i ||
1763 error "could not force hsm flags"
1764 $LFS hsm_release $f.$i || error "could not release file"
1766 nl=$(wc -l < $tmpfile)
1767 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1769 echo "rebind list of files"
1770 copytool rebind "$tmpfile"
1772 # restore files and compare md5sum
1773 for i in $(seq 1 $count); do
1774 local sum2=$(md5sum $f.$i | awk '{print $1}')
1775 [[ $sum2 == ${sums[$i]} ]] ||
1776 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1779 run_test 15 "Rebind a list of files"
1782 # test needs a running copytool
1786 # create a known size file so we can verify transfer speed
1789 dd if=/dev/zero of=$ref bs=1M count=20
1792 local f=$DIR/$tdir/$tfile
1793 local fid=$(copy_file $ref $f)
1795 local start=$(date +%s)
1797 wait_request_state $fid ARCHIVE SUCCEED
1798 local end=$(date +%s)
1799 # Add 1 to account for rounding errors between start and end (LU-8155)
1800 local duration=$((end - start + 1))
1802 [[ $duration -ge $((goal - 1)) ]] ||
1803 error "Transfer is too fast $duration < $goal"
1805 run_test 16 "Test CT bandwith control option"
1808 local f=$DIR/$tdir/$tfile
1809 create_empty_file "$f"
1811 # Could not release a non-archived file
1812 $LFS hsm_release $f && error "release should not succeed"
1814 # For following tests, we must test them with HS_ARCHIVED set
1815 $LFS hsm_set --exists --archived $f || error "could not add flag"
1817 # Could not release a file if no-release is set
1818 $LFS hsm_set --norelease $f || error "could not add flag"
1819 $LFS hsm_release $f && error "release should not succeed"
1820 $LFS hsm_clear --norelease $f || error "could not remove flag"
1822 # Could not release a file if lost
1823 $LFS hsm_set --lost $f || error "could not add flag"
1824 $LFS hsm_release $f && error "release should not succeed"
1825 $LFS hsm_clear --lost $f || error "could not remove flag"
1827 # Could not release a file if dirty
1828 $LFS hsm_set --dirty $f || error "could not add flag"
1829 $LFS hsm_release $f && error "release should not succeed"
1830 $LFS hsm_clear --dirty $f || error "could not remove flag"
1832 run_test 20 "Release is not permitted"
1835 # test needs a running copytool
1838 local f=$DIR/$tdir/test_release
1840 # Create a file and check its states
1841 local fid=$(create_small_file $f)
1842 check_hsm_flags $f "0x00000000"
1844 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1845 # used until file is flushed to disk
1846 if [ $(facet_fstype ost1) == "zfs" ]; then
1847 # this causes an OST_SYNC rpc to be sent
1848 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1849 # clear locks to reread file data
1850 cancel_lru_locks osc
1853 local orig_size=$(stat -c "%s" $f)
1854 local orig_blocks=$(stat -c "%b" $f)
1856 start_full_debug_logging
1858 $LFS hsm_archive $f || error "could not archive file"
1859 wait_request_state $fid ARCHIVE SUCCEED
1861 local blocks=$(stat -c "%b" $f)
1862 [ $blocks -eq $orig_blocks ] ||
1863 error "$f: wrong block number after archive: " \
1864 "$blocks != $orig_blocks"
1865 local size=$(stat -c "%s" $f)
1866 [ $size -eq $orig_size ] ||
1867 error "$f: wrong size after archive: $size != $orig_size"
1869 # Release and check states
1870 $LFS hsm_release $f || error "could not release file"
1871 check_hsm_flags $f "0x0000000d"
1873 blocks=$(stat -c "%b" $f)
1874 [ $blocks -gt 5 ] &&
1875 error "$f: too many blocks after release: $blocks > 5"
1876 size=$(stat -c "%s" $f)
1877 [ $size -ne $orig_size ] &&
1878 error "$f: wrong size after release: $size != $orig_size"
1880 # Check we can release an file without stripe info
1884 check_hsm_flags $f "0x00000000"
1885 $LFS hsm_archive $f || error "could not archive file"
1886 wait_request_state $fid ARCHIVE SUCCEED
1888 # Release and check states
1889 $LFS hsm_release $f || error "could not release file"
1890 check_hsm_flags $f "0x0000000d"
1892 # Release again a file that is already released is OK
1893 $LFS hsm_release $f || fail "second release should succeed"
1894 check_hsm_flags $f "0x0000000d"
1896 stop_full_debug_logging
1898 run_test 21 "Simple release tests"
1901 # test needs a running copytool
1904 local f=$DIR/$tdir/test_release
1905 local swap=$DIR/$tdir/test_swap
1907 # Create a file and check its states
1908 local fid=$(create_small_file $f)
1909 check_hsm_flags $f "0x00000000"
1911 $LFS hsm_archive $f || error "could not archive file"
1912 wait_request_state $fid ARCHIVE SUCCEED
1914 # Release and check states
1915 $LFS hsm_release $f || error "could not release file"
1916 check_hsm_flags $f "0x0000000d"
1918 create_small_file $swap
1919 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1923 run_test 22 "Could not swap a release file"
1926 # test needs a running copytool
1929 local f=$DIR/$tdir/test_mtime
1931 # Create a file and check its states
1932 local fid=$(create_small_file $f)
1933 check_hsm_flags $f "0x00000000"
1935 $LFS hsm_archive $f || error "could not archive file"
1936 wait_request_state $fid ARCHIVE SUCCEED
1938 # Set modification time in the past
1939 touch -m -a -d @978261179 $f
1941 # Release and check states
1942 $LFS hsm_release $f || error "could not release file"
1943 check_hsm_flags $f "0x0000000d"
1945 local MTIME=$(stat -c "%Y" $f)
1946 local ATIME=$(stat -c "%X" $f)
1947 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1948 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1950 run_test 23 "Release does not change a/mtime (utime)"
1953 local file=$DIR/$tdir/$tfile
1962 # test needs a running copytool
1965 fid=$(create_small_file $file)
1967 # Create a file and check its states
1968 check_hsm_flags $file "0x00000000"
1970 # Ensure atime is less than mtime and ctime.
1974 atime0=$(stat -c "%X" $file)
1975 mtime0=$(stat -c "%Y" $file)
1976 ctime0=$(stat -c "%Z" $file)
1978 [ $atime0 -lt $mtime0 ] ||
1979 error "atime $atime0 is not less than mtime $mtime0"
1981 [ $atime0 -lt $ctime0 ] ||
1982 error "atime $atime0 is not less than ctime $ctime0"
1984 # Archive should not change any timestamps.
1985 $LFS hsm_archive $file || error "cannot archive '$file'"
1986 wait_request_state $fid ARCHIVE SUCCEED
1988 atime1=$(stat -c "%X" $file)
1989 mtime1=$(stat -c "%Y" $file)
1990 ctime1=$(stat -c "%Z" $file)
1992 [ $atime0 -eq $atime1 ] ||
1993 error "archive changed atime from $atime0 to $atime1"
1995 [ $mtime0 -eq $mtime1 ] ||
1996 error "archive changed mtime from $mtime0 to $mtime1"
1998 [ $ctime0 -eq $ctime1 ] ||
1999 error "archive changed ctime from $ctime0 to $ctime1"
2001 # Release should not change any timestamps.
2002 $LFS hsm_release $file || error "cannot release '$file'"
2003 check_hsm_flags $file "0x0000000d"
2005 atime1=$(stat -c "%X" $file)
2006 mtime1=$(stat -c "%Y" $file)
2007 ctime1=$(stat -c "%Z" $file)
2009 [ $atime0 -eq $atime1 ] ||
2010 error "release changed atime from $atime0 to $atime1"
2012 [ $mtime0 -eq $mtime1 ] ||
2013 error "release changed mtime from $mtime0 to $mtime1"
2015 [ $ctime0 -eq $ctime1 ] ||
2016 error "release changed ctime from $ctime0 to $ctime1"
2018 # Restore should not change any timestamps.
2019 $LFS hsm_restore $file
2020 wait_request_state $fid RESTORE SUCCEED
2022 atime1=$(stat -c "%X" $file)
2023 mtime1=$(stat -c "%Y" $file)
2024 ctime1=$(stat -c "%Z" $file)
2026 [ $atime0 -eq $atime1 ] ||
2027 error "restore changed atime from $atime0 to $atime1"
2029 [ $mtime0 -eq $mtime1 ] ||
2030 error "restore changed mtime from $mtime0 to $mtime1"
2032 [ $ctime0 -eq $ctime1 ] ||
2033 error "restore changed ctime from $ctime0 to $ctime1"
2036 wait_copytools || error "Copytools failed to stop"
2038 # Once more, after unmount and mount.
2039 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2040 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2042 atime1=$(stat -c "%X" $file)
2043 mtime1=$(stat -c "%Y" $file)
2044 ctime1=$(stat -c "%Z" $file)
2046 [ $atime0 -eq $atime1 ] ||
2047 error "remount changed atime from $atime0 to $atime1"
2049 [ $mtime0 -eq $mtime1 ] ||
2050 error "remount changed mtime from $mtime0 to $mtime1"
2052 [ $ctime0 -eq $ctime1 ] ||
2053 error "remount changed ctime from $ctime0 to $ctime1"
2055 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2058 local file=$DIR/$tdir/$tfile
2064 # Test needs a running copytool.
2067 # Check that root can do HSM actions on a regular user's file.
2068 fid=$(create_small_file $file)
2069 sum0=$(md5sum $file)
2071 chown $RUNAS_ID:$RUNAS_GID $file ||
2072 error "cannot chown '$file' to '$RUNAS_ID'"
2074 chmod ugo-w $DIR/$tdir ||
2075 error "cannot chmod '$DIR/$tdir'"
2077 $LFS hsm_archive $file
2078 wait_request_state $fid ARCHIVE SUCCEED
2080 $LFS hsm_release $file
2081 check_hsm_flags $file "0x0000000d"
2083 $LFS hsm_restore $file
2084 wait_request_state $fid RESTORE SUCCEED
2086 # Check that ordinary user can get HSM state.
2087 $RUNAS $LFS hsm_state $file ||
2088 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2090 $LFS hsm_release $file
2091 check_hsm_flags $file "0x0000000d"
2093 # Check that ordinary user can accessed released file.
2094 sum1=$($RUNAS md5sum $file) ||
2095 error "user '$RUNAS_ID' cannot read '$file'"
2097 [ "$sum0" == "$sum1" ] ||
2098 error "md5sum mismatch for '$file'"
2100 run_test 24b "root can archive, release, and restore user files"
2103 local file=$DIR/$tdir/$tfile
2104 local action=archive
2109 # test needs a running copytool
2114 # Save the default masks and check that cleanup_24c will
2115 # restore the request masks correctly.
2116 user_save=$(get_hsm_param user_request_mask)
2117 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2118 group_save=$(get_hsm_param group_request_mask)
2119 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2120 other_save=$(get_hsm_param other_request_mask)
2121 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2123 [ "$user_save" == RESTORE ] ||
2124 error "user_request_mask is '$user_save' expected 'RESTORE'"
2125 [ "$group_save" == RESTORE ] ||
2126 error "group_request_mask is '$group_save' expected 'RESTORE'"
2127 [ "$other_save" == RESTORE ] ||
2128 error "other_request_mask is '$other_save' expected 'RESTORE'"
2131 create_small_file $file
2132 chown $RUNAS_ID:$GROUP $file ||
2133 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2135 $RUNAS $LFS hsm_$action $file &&
2136 error "$action by user should fail"
2138 set_hsm_param user_request_mask $action
2139 $RUNAS $LFS hsm_$action $file ||
2140 error "$action by user should succeed"
2143 create_small_file $file
2144 chown nobody:$RUNAS_GID $file ||
2145 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2147 $RUNAS $LFS hsm_$action $file &&
2148 error "$action by group should fail"
2150 set_hsm_param group_request_mask $action
2151 $RUNAS $LFS hsm_$action $file ||
2152 error "$action by group should succeed"
2155 create_small_file $file
2156 chown nobody:$GROUP $file ||
2157 error "cannot chown '$file' to 'nobody:$GROUP'"
2159 $RUNAS $LFS hsm_$action $file &&
2160 error "$action by other should fail"
2162 set_hsm_param other_request_mask $action
2163 $RUNAS $LFS hsm_$action $file ||
2164 error "$action by other should succeed"
2166 run_test 24c "check that user,group,other request masks work"
2169 local file1=$DIR/$tdir/$tfile
2170 local file2=$DIR2/$tdir/$tfile
2174 fid1=$(create_small_file $file1)
2177 $LFS getstripe $file1
2179 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2180 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2181 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2183 copytool setup -m "$MOUNT3"
2185 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2186 mount -o remount,ro $MOUNT2
2188 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2190 fid2=$(path2fid $file2)
2191 [ "$fid1" == "$fid2" ] ||
2192 error "FID mismatch '$fid1' != '$fid2'"
2194 $LFS hsm_archive $file2 &&
2195 error "archive should fail on read-only mount"
2196 check_hsm_flags $file1 "0x00000000"
2198 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2199 wait_request_state $fid1 ARCHIVE SUCCEED
2201 $LFS hsm_release $file1
2202 $LFS hsm_restore $file2
2203 wait_request_state $fid1 RESTORE SUCCEED
2205 $LFS hsm_release $file1 || error "cannot release '$file1'"
2206 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2208 $LFS hsm_release $file2 &&
2209 error "release should fail on read-only mount"
2213 run_test 24d "check that read-only mounts are respected"
2218 local f=$DIR/$tdir/$tfile
2221 fid=$(create_small_file $f) || error "cannot create $f"
2222 $LFS hsm_archive $f || error "cannot archive $f"
2223 wait_request_state $fid ARCHIVE SUCCEED
2224 $LFS hsm_release $f || error "cannot release $f"
2225 while ! $LFS hsm_state $f | grep released; do
2229 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2231 run_test 24e "tar succeeds on HSM released files" # LU-6213
2234 # test needs a running copytool
2237 mkdir -p $DIR/$tdir/d1
2238 local f=$DIR/$tdir/$tfile
2239 local fid=$(copy_file /etc/hosts $f)
2242 $LFS hsm_archive $f ||
2243 error "hsm_archive failed"
2244 wait_request_state $fid ARCHIVE SUCCEED
2245 $LFS hsm_release $f || error "cannot release $f"
2246 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2249 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2250 error "Can not recover the tar contents"
2252 echo "Sum0 = $sum0, sum1 = $sum1"
2253 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2255 run_test 24f "root can archive, release, and restore tar files"
2258 # test needs a running copytool
2262 copy2archive /etc/hosts $tdir/$tfile
2264 local f=$DIR/$tdir/$tfile
2266 copytool import $tdir/$tfile $f
2268 $LFS hsm_set --lost $f
2273 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2275 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2276 " (Operation not permitted)"
2279 # test needs a running copytool
2284 local f=$DIR/$tdir/$tfile
2285 local fid=$(copy_file /etc/passwd $f)
2287 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2288 wait_request_state $fid ARCHIVE SUCCEED
2291 $LFS hsm_set --lost $f
2295 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2297 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2298 " (Operation not permitted)"
2300 test_26A() { # was test_26
2301 # test needs a running copytool
2304 local f=$DIR/$tdir/$tfile
2306 fid=$(make_custom_file_for_progress $f 39 1000000)
2307 [ $? != 0 ] && skip "not enough free space" && return
2309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2310 wait_request_state $fid ARCHIVE SUCCEED
2313 wait_request_state $fid REMOVE SUCCEED
2315 check_hsm_flags $f "0x00000000"
2317 run_test 26A "Remove the archive of a valid file"
2320 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2321 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2323 # test needs a running copytool
2327 local f=$DIR/$tdir/$tfile
2328 local fid=$(copy_file /etc/passwd $f)
2330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2331 wait_request_state $fid ARCHIVE SUCCEED
2333 local f2=$DIR/$tdir/${tfile}_2
2334 local fid2=$(copy_file /etc/passwd $f2)
2336 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2337 wait_request_state $fid2 ARCHIVE SUCCEED
2339 local f3=$DIR/$tdir/${tfile}_3
2340 local fid3=$(copy_file /etc/passwd $f3)
2342 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2343 wait_request_state $fid3 ARCHIVE SUCCEED
2345 # set a long grace_delay vs short loop_period
2346 local orig_loop_period=$(get_hsm_param loop_period)
2347 local orig_grace_delay=$(get_hsm_param grace_delay)
2348 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2349 set_hsm_param loop_period 10
2350 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2351 set_hsm_param grace_delay 100
2355 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2356 set_hsm_param remove_archive_on_last_unlink 1
2358 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2363 wait_request_state $fid2 REMOVE SUCCEED
2365 assert_request_count $fid REMOVE 0 \
2366 "Unexpected archived data remove request for $f"
2367 assert_request_count $fid3 REMOVE 0 \
2368 "Unexpected archived data remove request for $f3"
2370 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2373 # test needs a running copytool
2377 local f=$DIR/$tdir/$tfile
2378 local fid=$(copy_file /etc/passwd $f)
2380 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2381 wait_request_state $fid ARCHIVE SUCCEED
2383 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2384 set_hsm_param remove_archive_on_last_unlink 1
2387 cdt_check_state stopped
2391 wait_request_state $fid REMOVE WAITING
2395 # copytool must re-register
2397 wait_copytools || error "copytool failed to stop"
2400 wait_request_state $fid REMOVE SUCCEED
2402 run_test 26b "RAoLU policy when CDT off"
2405 # test needs a running copytool
2409 local f=$DIR/$tdir/$tfile
2410 local fid=$(copy_file /etc/passwd $f)
2412 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2413 wait_request_state $fid ARCHIVE SUCCEED
2415 local f2=$DIR/$tdir/${tfile}_2
2416 local fid2=$(copy_file /etc/passwd $f2)
2418 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2419 wait_request_state $fid2 ARCHIVE SUCCEED
2421 # set a long grace_delay vs short loop_period
2422 local orig_loop_period=$(get_hsm_param loop_period)
2423 local orig_grace_delay=$(get_hsm_param grace_delay)
2424 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2425 set_hsm_param loop_period 10
2426 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2427 set_hsm_param grace_delay 100
2429 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2430 set_hsm_param remove_archive_on_last_unlink 1
2432 multiop_bg_pause $f O_c || error "open $f failed"
2438 wait_request_state $fid2 REMOVE SUCCEED
2439 assert_request_count $fid REMOVE 0 \
2440 "Unexpected archived data remove request for $f"
2442 kill -USR1 $pid || error "multiop early exit"
2443 # should reach autotest timeout if multiop fails to trap
2444 # signal, close file, and exit ...
2445 wait $pid || error "wait PID $PID failed"
2447 wait_request_state $fid REMOVE SUCCEED
2449 run_test 26c "RAoLU effective when file closed"
2452 # test needs a running copytool
2456 local f=$DIR/$tdir/$tfile
2457 local fid=$(create_small_file $f)
2459 $LFS hsm_archive $f || error "could not archive file"
2460 wait_request_state $fid ARCHIVE SUCCEED
2462 # set a long grace_delay vs short loop_period
2463 local orig_loop_period=$(get_hsm_param loop_period)
2464 local orig_grace_delay=$(get_hsm_param grace_delay)
2465 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2466 set_hsm_param loop_period 10
2467 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2468 set_hsm_param grace_delay 100
2470 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2471 set_hsm_param remove_archive_on_last_unlink 1
2473 multiop_bg_pause $f O_c || error "multiop failed"
2480 wait_request_state $fid REMOVE SUCCEED
2482 client_up || client_up || true
2484 kill -USR1 $MULTIPID
2485 wait $MULTIPID || error "multiop close failed"
2487 run_test 26d "RAoLU when Client eviction"
2490 # test needs a running copytool
2493 create_archive_file $tdir/$tfile
2494 local f=$DIR/$tdir/$tfile
2495 copytool import $tdir/$tfile $f
2496 local fid=$(path2fid $f)
2500 [[ $? != 0 ]] || error "Remove of a released file should fail"
2502 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2505 # test needs a running copytool
2508 local f=$DIR/$tdir/$tfile
2510 fid=$(make_custom_file_for_progress $f 39 1000000)
2511 [ $? != 0 ] && skip "not enough free space" && return
2513 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2514 wait_request_state $fid ARCHIVE SUCCEED
2519 [[ $? != 0 ]] || error "Remove of a released file should fail"
2521 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2524 # test needs a running copytool
2527 local f=$DIR/$tdir/$tfile
2529 fid=$(make_custom_file_for_progress $f 39 1000000)
2530 [ $? != 0 ] && skip "not enough free space" && return
2532 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2533 wait_request_state $fid ARCHIVE SUCCEED
2542 wait_request_state $fid REMOVE SUCCEED
2544 run_test 28 "Concurrent archive/file remove"
2547 # Tests --mntpath and --archive options
2550 copytool setup -m "$MOUNT" -a $archive_id
2552 # Bad archive number
2553 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2554 grep "Invalid argument" ||
2555 error "unexpected hsm_remove failure (1)"
2557 # mntpath is present but file is given
2558 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2559 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2560 error "unexpected hsm_remove failure (2)"
2562 run_test 29a "Tests --mntpath and --archive options"
2565 # test needs a running copytool
2568 local f=$DIR/$tdir/$tfile
2569 local fid=$(create_small_file $f)
2571 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2572 wait_request_state $fid ARCHIVE SUCCEED
2576 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2577 wait_request_state $fid REMOVE SUCCEED
2579 run_test 29b "Archive/delete/remove by FID from the archive."
2582 # test needs a running copytool
2585 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2586 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2587 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2589 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2590 wait_request_state $fid1 ARCHIVE SUCCEED
2591 wait_request_state $fid2 ARCHIVE SUCCEED
2592 wait_request_state $fid3 ARCHIVE SUCCEED
2594 rm -f $DIR/$tdir/$tfile-[1-3]
2596 echo $fid1 > $DIR/$tdir/list
2597 echo $fid2 >> $DIR/$tdir/list
2598 echo $fid3 >> $DIR/$tdir/list
2600 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2601 --filelist $DIR/$tdir/list
2602 wait_request_state $fid1 REMOVE SUCCEED
2603 wait_request_state $fid2 REMOVE SUCCEED
2604 wait_request_state $fid3 REMOVE SUCCEED
2606 run_test 29c "Archive/delete/remove by FID, using a file list."
2609 # test needs more than one CT
2610 needclients 3 || return 0
2616 # start all of the copytools
2617 for n in $(seq $AGTCOUNT); do
2618 copytool setup -f agt$n -a $n
2622 file=$DIR/$tdir/$tfile
2623 fid=$(create_small_file $file)
2625 $LFS hsm_archive $file
2626 wait_request_state $fid ARCHIVE SUCCEED
2627 check_hsm_flags $file "0x00000009"
2631 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2632 error "cannot hsm_remove '$fid'"
2634 # give time for CDT to handle remove request and create broadcasted
2637 # remove request has been broadcasted ?
2638 local cnt=$(get_request_count $fid REMOVE)
2639 # broadcasted requests + original
2640 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2641 error "remove not broadcasted to all CTs"
2643 # give time for CDT and CTs to handle broadcasted
2644 wait_for_loop_period
2646 # each agent serves one different archive_id, so broadcasted
2647 # hsm_remove request should only succeed once and fail at all others
2651 for n in $(seq $AGTCOUNT); do
2652 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2653 $HSM_PARAM.actions | awk \
2654 '/'$fid'.*action=REMOVE archive#='$n'/ \
2655 {print \\\$13}' | cut -f2 -d=")
2656 if [[ "$res" == "SUCCEED" ]]; then
2658 elif [[ "$res" == "FAILED" ]]; then
2663 [[ $scnt -eq 1 ]] ||
2664 error "one and only CT should have removed successfully"
2666 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2667 error "all but one CT should have failed to remove"
2669 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2670 "request to be sent once for each registered archive_id"
2673 # restore at exec cannot work on agent node (because of Linux kernel
2674 # protection of executables)
2675 needclients 2 || return 0
2677 # test needs a running copytool
2681 copy2archive /bin/true $tdir/$tfile
2683 local f=$DIR/$tdir/true
2684 copytool import $tdir/$tfile $f
2686 local fid=$(path2fid $f)
2688 stack_trap "cdt_clear_no_retry" EXIT
2689 # set no retry action mode
2696 [[ $st == 0 ]] || error "Failed to exec a released file"
2698 run_test 30a "Restore at exec (import case)"
2701 # restore at exec cannot work on agent node (because of Linux kernel
2702 # protection of executables)
2703 needclients 2 || return 0
2705 # test needs a running copytool
2709 local f=$DIR/$tdir/true
2710 local fid=$(copy_file /bin/true $f)
2712 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2713 wait_request_state $fid ARCHIVE SUCCEED
2717 stack_trap cdt_clear_no_retry EXIT
2718 # set no retry action mode
2726 [[ $st == 0 ]] || error "Failed to exec a released file"
2728 run_test 30b "Restore at exec (release case)"
2731 needclients 2 || return 0
2733 # test needs a running copytool
2737 local f=$DIR/$tdir/SLEEP
2738 local slp_sum1=$(md5sum /bin/sleep)
2739 local fid=$(copy_file /bin/sleep $f)
2741 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2742 wait_request_state $fid ARCHIVE SUCCEED
2744 check_hsm_flags $f "0x0000000d"
2746 stack_trap cdt_clear_no_retry EXIT
2747 # set no retry action mode
2750 do_node $CLIENT2 "$f 10" &
2754 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2756 [[ $? == 0 ]] || error "Execution failed during run"
2758 if [[ $? != 0 ]]; then
2759 local slp_sum2=$(md5sum /bin/sleep)
2760 # in case sleep file is modified during the test
2761 [[ $slp_sum1 == $slp_sum2 ]] &&
2762 error "Binary overwritten during exec"
2765 check_hsm_flags $f "0x00000009"
2767 run_test 30c "Update during exec of released file must fail"
2769 restore_and_check_size() {
2772 local s=$(stat -c "%s" $f)
2774 local st=$(get_hsm_flags $f)
2778 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2780 n=$(stat -c "%s" $f)
2781 # we echo in both cases to show stat is not hang
2782 if [[ $n != $s ]]; then
2783 echo "size seen is $n != $s"
2786 echo "size seen is right: $n == $s"
2790 st=$(get_hsm_flags $f)
2792 if [[ "$st" = "0x00000009" ]]; then
2795 echo " restore is too long"
2796 wait_request_state $fid RESTORE SUCCEED
2802 # test needs a running copytool
2805 create_archive_file $tdir/$tfile
2806 local f=$DIR/$tdir/$tfile
2807 copytool import $tdir/$tfile $f
2808 local fid=$($LFS path2fid $f)
2811 restore_and_check_size $f $fid
2814 [[ $err -eq 0 ]] || error "File size changed during restore"
2816 run_test 31a "Import a large file and check size during restore"
2820 # test needs a running copytool
2823 local f=$DIR/$tdir/$tfile
2825 fid=$(make_custom_file_for_progress $f 39 1000000)
2826 [ $? != 0 ] && skip "not enough free space" && return
2828 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2829 wait_request_state $fid ARCHIVE SUCCEED
2832 restore_and_check_size $f $fid
2835 [[ $err -eq 0 ]] || error "File size changed during restore"
2837 run_test 31b "Restore a large unaligned file and check size during restore"
2840 # test needs a running copytool
2843 local f=$DIR/$tdir/$tfile
2845 fid=$(make_custom_file_for_progress $f 33 1048576)
2846 [ $? != 0 ] && skip "not enough free space" && return
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 31c "Restore a large aligned file and check size during restore"
2860 # test needs a running copytool
2863 local f=$DIR/$tdir/$tfile
2865 fid=$(make_custom_file_for_progress $f 39 1000000)
2866 [ $? != 0 ] && skip "not enough free space" && return
2868 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2869 wait_request_state $fid ARCHIVE SUCCEED
2872 # to be sure wait_all_done will not be mislead by previous tests
2875 wait_for_grace_delay
2876 # Also raise grace_delay significantly so the Canceled
2877 # Restore action will stay enough long avail.
2878 local old_grace=$(get_hsm_param grace_delay)
2879 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
2880 set_hsm_param grace_delay 100
2882 md5sum $f >/dev/null &
2884 wait_request_state $fid RESTORE STARTED
2889 # Check restore trigger process was killed
2890 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2894 # instead of waiting+checking both Restore and Cancel ops
2895 # sequentially, wait for both to be finished and then check
2897 wait_all_done 100 $fid
2898 local rstate=$(get_request_state $fid RESTORE)
2899 local cstate=$(get_request_state $fid CANCEL)
2901 if [[ "$rstate" == "CANCELED" ]] ; then
2902 [[ "$cstate" == "SUCCEED" ]] ||
2903 error "Restore state is CANCELED and Cancel state " \
2904 "is not SUCCEED but $cstate"
2905 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2906 elif [[ "$rstate" == "SUCCEED" ]] ; then
2907 [[ "$cstate" == "FAILED" ]] ||
2908 error "Restore state is SUCCEED and Cancel state " \
2909 "is not FAILED but $cstate"
2910 echo "Restore state is SUCCEED, Cancel state is FAILED"
2912 error "Restore state is $rstate and Cancel state is $cstate"
2916 error "Cannot kill process waiting for restore ($killed)"
2918 run_test 33 "Kill a restore waiting process"
2921 # test needs a running copytool
2924 local f=$DIR/$tdir/$tfile
2926 fid=$(make_custom_file_for_progress $f 39 1000000)
2927 [ $? != 0 ] && skip "not enough free space" && return
2929 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2930 wait_request_state $fid ARCHIVE SUCCEED
2933 md5sum $f >/dev/null &
2935 wait_request_state $fid RESTORE STARTED
2937 rm $f || error "rm $f failed"
2938 # rm must not block during restore
2939 wait_request_state $fid RESTORE STARTED
2941 wait_request_state $fid RESTORE SUCCEED
2942 # check md5sum pgm finished
2943 local there=$(ps -o pid,comm hp $pid >/dev/null)
2944 [[ -z $there ]] || error "Restore initiator does not exit"
2946 wait $pid || error "Restore initiator failed with $?"
2948 run_test 34 "Remove file during restore"
2951 # test needs a running copytool
2954 local f=$DIR/$tdir/$tfile
2955 local f1=$DIR/$tdir/$tfile-1
2957 fid=$(make_custom_file_for_progress $f 39 1000000)
2958 [ $? != 0 ] && skip "not enough free space" && return
2960 local fid1=$(copy_file /etc/passwd $f1)
2961 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2962 wait_request_state $fid ARCHIVE SUCCEED
2965 md5sum $f >/dev/null &
2967 wait_request_state $fid RESTORE STARTED
2969 mv $f1 $f || error "mv $f1 $f failed"
2970 # mv must not block during restore
2971 wait_request_state $fid RESTORE STARTED
2973 wait_request_state $fid RESTORE SUCCEED
2974 # check md5sum pgm finished
2975 local there=$(ps -o pid,comm hp $pid >/dev/null)
2976 [[ -z $there ]] || error "Restore initiator does not exit"
2978 wait $pid || error "Restore initiator failed with $?"
2981 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2983 run_test 35 "Overwrite file during restore"
2986 # test needs a running copytool
2989 local f=$DIR/$tdir/$tfile
2991 fid=$(make_custom_file_for_progress $f 39 1000000)
2992 [ $? != 0 ] && skip "not enough free space" && return
2994 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2995 wait_request_state $fid ARCHIVE SUCCEED
2998 md5sum $f >/dev/null &
3000 wait_request_state $fid RESTORE STARTED
3003 # rm must not block during restore
3004 wait_request_state $fid RESTORE STARTED
3006 wait_request_state $fid RESTORE SUCCEED
3007 # check md5sum pgm finished
3008 local there=$(ps -o pid,comm hp $pid >/dev/null)
3010 error "Restore initiator does not exit"
3012 wait $pid || error "Restore initiator failed with $?"
3014 run_test 36 "Move file during restore"
3017 # LU-5683: check that an archived dirty file can be rearchived.
3020 local f=$DIR/$tdir/$tfile
3023 fid=$(create_small_file $f) || error "cannot create small file"
3025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3026 wait_request_state $fid ARCHIVE SUCCEED
3027 $LFS hsm_release $f || error "cannot release $f"
3029 # Allow previous archive request to expire from the actions log.
3030 wait_for_grace_delay
3033 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3035 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3036 wait_request_state $fid ARCHIVE SUCCEED
3038 run_test 37 "re-archive a dirty file"
3045 for n in $(seq 1 $count); do
3046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3048 echo "$count archive requests submitted"
3052 local stream_count=4
3053 local file_count=100
3055 local f=$DIR/$tdir/$tfile
3059 local max_requests=$(get_hsm_param max_requests)
3061 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3062 # Increase the number of HSM request that can be performed in
3063 # parallel. With the coordinator running once per second, this
3064 # also limits the number of requests per seconds that can be
3065 # performed, so we pick a decent number. But we also need to keep
3066 # that number low because the copytool has no rate limit and will
3067 # fail some requests if if gets too many at once.
3068 set_hsm_param max_requests 300
3070 for i in $(seq 1 $file_count); do
3071 for p in $(seq 1 $stream_count); do
3072 fid=$(copy_file /etc/hosts $f.$p.$i)
3078 # to be sure wait_all_done will not be mislead by previous tests
3080 wait_for_grace_delay
3082 # start archive streams in background (archive files in parallel)
3083 for p in $(seq 1 $stream_count); do
3084 multi_archive $f.$p $file_count &
3087 echo -n "Wait for all requests being enqueued..."
3092 run_test 40 "Parallel archive requests"
3095 # test needs a running copytool
3099 local f=$DIR/$tdir/$tfile
3100 local fid=$(create_small_file $f)
3102 $LFS hsm_archive $f || error "could not archive file"
3103 wait_request_state $fid ARCHIVE SUCCEED
3104 check_hsm_flags $f "0x00000009"
3106 multiop_bg_pause $f O_c || error "multiop failed"
3110 client_up || client_up || true
3112 kill -USR1 $MULTIPID
3113 wait $MULTIPID || error "multiop close failed"
3115 check_hsm_flags $f "0x0000000b"
3117 run_test 52 "Opened for write file on an evicted client should be set dirty"
3120 # test needs a running copytool
3124 local f=$DIR/$tdir/$tfile
3125 local fid=$(create_small_file $f)
3127 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3128 error "could not archive file"
3129 wait_request_state $fid ARCHIVE SUCCEED
3130 check_hsm_flags $f "0x00000009"
3132 multiop_bg_pause $f o_c || error "multiop failed"
3136 client_up || client_up || true
3138 kill -USR1 $MULTIPID
3139 wait $MULTIPID || error "multiop close failed"
3141 check_hsm_flags $f "0x00000009"
3143 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3146 # test needs a running copytool
3149 local f=$DIR/$tdir/$tfile
3150 local fid=$(make_custom_file_for_progress $f 39 1000000)
3152 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3153 error "could not archive file"
3154 wait_request_state $fid ARCHIVE STARTED
3156 check_hsm_flags $f "0x00000001"
3158 stack_trap "cdt_clear_no_retry" EXIT
3159 # Avoid coordinator resending this request as soon it has failed.
3164 wait_request_state $fid ARCHIVE FAILED
3166 check_hsm_flags $f "0x00000003"
3168 run_test 54 "Write during an archive cancels it"
3171 # test needs a running copytool
3174 local f=$DIR/$tdir/$tfile
3175 local fid=$(make_custom_file_for_progress $f 39 1000000)
3177 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3178 error "could not archive file"
3179 wait_request_state $fid ARCHIVE STARTED
3181 check_hsm_flags $f "0x00000001"
3183 stack_trap "cdt_clear_no_retry" EXIT
3184 # Avoid coordinator resending this request as soon it has failed.
3187 $TRUNCATE $f 1024 || error "truncate failed"
3189 wait_request_state $fid ARCHIVE FAILED
3191 check_hsm_flags $f "0x00000003"
3193 run_test 55 "Truncate during an archive cancels it"
3196 # test needs a running copytool
3199 local f=$DIR/$tdir/$tfile
3201 fid=$(make_custom_file_for_progress $f 39 1000000)
3202 [ $? != 0 ] && skip "not enough free space" && return
3204 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3205 error "could not archive file"
3206 wait_request_state $fid ARCHIVE STARTED
3208 check_hsm_flags $f "0x00000001"
3210 # Change metadata and sync to be sure we are not changing only
3215 wait_request_state $fid ARCHIVE SUCCEED
3217 check_hsm_flags $f "0x00000009"
3219 run_test 56 "Setattr during an archive is ok"
3222 # Need one client for I/O, one for request
3223 needclients 2 || return 0
3225 # test needs a running copytool
3229 local f=$DIR/$tdir/test_archive_remote
3230 # Create a file on a remote node
3231 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3232 "count=2 conv=fsync"
3235 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3236 error "hsm_archive failed"
3237 local fid=$(path2fid $f)
3238 wait_request_state $fid ARCHIVE SUCCEED
3240 # Release and implicit restore it
3241 do_node $CLIENT2 "$LFS hsm_release $f" ||
3242 error "hsm_release failed"
3243 do_node $CLIENT2 "md5sum $f" ||
3244 error "hsm_restore failed"
3246 wait_request_state $fid RESTORE SUCCEED
3248 run_test 57 "Archive a file with dirty cache on another node"
3250 truncate_released_file() {
3254 local sz=$(stat -c %s $src_file)
3255 local f=$DIR/$tdir/$tfile
3256 local fid=$(copy_file $1 $f)
3260 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3261 error "could not archive file"
3262 wait_request_state $fid ARCHIVE SUCCEED
3264 $LFS hsm_release $f || error "could not release file"
3266 $TRUNCATE $f $trunc_to || error "truncate failed"
3269 local sz1=$(stat -c %s $f)
3270 [[ $sz1 == $trunc_to ]] ||
3271 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3274 check_hsm_flags $f "0x0000000b"
3276 local state=$(get_request_state $fid RESTORE)
3277 [[ "$state" == "SUCCEED" ]] ||
3278 error "truncate $sz does not trig restore, state = $state"
3280 $TRUNCATE $ref $trunc_to
3281 cmp $ref $f || error "file data wrong after truncate"
3287 # test needs a running copytool
3292 local sz=$(stat -c %s /etc/passwd)
3294 echo "truncate up from $sz to $((sz*2))"
3295 truncate_released_file /etc/passwd $((sz*2))
3297 echo "truncate down from $sz to $((sz/2))"
3298 truncate_released_file /etc/passwd $((sz/2))
3300 echo "truncate to 0"
3301 truncate_released_file /etc/passwd 0
3303 run_test 58 "Truncate a released file will trigger restore"
3307 local server_version=$(lustre_version_code $SINGLEMDS)
3308 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3309 skip "Need MDS version at least 2.7.63" && return
3312 $MCREATE $DIR/$tfile || error "mcreate failed"
3313 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3314 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3315 fid=$(path2fid $DIR/$tfile)
3316 wait_request_state $fid ARCHIVE SUCCEED
3317 $LFS hsm_release $DIR/$tfile || error "release failed"
3319 run_test 59 "Release stripeless file with non-zero size"
3322 # This test validates the fix for LU-4512. Ensure that the -u
3323 # option changes the progress reporting interval from the
3324 # default (30 seconds) to the user-specified interval.
3326 local progress_timeout=$((interval * 4))
3328 copytool setup -b 1 --update-interval $interval
3330 local f=$DIR/$tdir/$tfile
3332 fid=$(make_custom_file_for_progress $f 10)
3333 [ $? != 0 ] && skip "not enough free space" && return
3336 local mdt=${MDT_PREFIX}${mdtidx}
3337 local mds=mds$((mdtidx + 1))
3339 # Wait for copytool to register
3340 wait_update_facet $mds \
3341 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3342 uuid 100 || error "coyptool failed to register with $mdt"
3344 local start_at=$(date +%s)
3345 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3346 error "could not archive file"
3348 local agent=$(facet_active_host $SINGLEAGT)
3349 local logfile=$(copytool_logfile $SINGLEAGT)
3351 wait_update $agent \
3352 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3353 error "copytool failed to start"
3355 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3356 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3362 echo -n "Expecting a progress update within $progress_timeout seconds... "
3364 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3365 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3366 echo "$RESULT bytes copied in $WAIT seconds."
3368 elif [ $WAIT -ge $progress_timeout ]; then
3369 error "Timed out waiting for progress update!"
3372 WAIT=$((WAIT + sleep))
3376 local finish_at=$(date +%s)
3377 local elapsed=$((finish_at - start_at))
3379 # Ensure that the progress update occurred within the expected window.
3380 if [ $elapsed -lt $((interval - 1)) ]; then
3381 error "Expected progress update after at least $interval seconds"
3384 echo "Wait for on going archive hsm action to complete"
3385 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3386 echo "File archiving not completed even after 10 secs"
3388 run_test 60 "Changing progress update interval from default"
3391 # test needs a running copytool
3395 local f=$DIR/$tdir/$tfile
3396 local fid=$(copy_file /etc/passwd $f)
3398 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3401 wait_request_state $fid ARCHIVE FAILED
3403 run_test 61 "Waiting archive of a removed file should fail"
3406 # test needs a new running copytool
3407 stack_trap copytool_monitor_cleanup EXIT
3408 copytool_monitor_setup
3409 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3411 # Wait for the copytool to register.
3412 wait_update --verbose $(facet_active_host mds1) \
3413 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3415 error "copytool failed to register with MDT0000"
3418 wait_copytools || error "Copytools failed to stop"
3420 local REGISTER_EVENT
3421 local UNREGISTER_EVENT
3422 while read event; do
3423 local parsed=$(parse_json_event "$event")
3424 if [ -z "$parsed" ]; then
3425 error "Copytool sent malformed event: $event"
3429 if [ $event_type == "REGISTER" ]; then
3430 REGISTER_EVENT=$event
3431 elif [ $event_type == "UNREGISTER" ]; then
3432 UNREGISTER_EVENT=$event
3434 done < <(echo $"$(get_copytool_event_log)")
3436 if [ -z "$REGISTER_EVENT" ]; then
3437 error "Copytool failed to send register event to FIFO"
3440 if [ -z "$UNREGISTER_EVENT" ]; then
3441 error "Copytool failed to send unregister event to FIFO"
3444 echo "Register/Unregister events look OK."
3446 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3449 # Bump progress interval for livelier events.
3452 # test needs a new running copytool
3453 stack_trap copytool_monitor_cleanup EXIT
3454 copytool_monitor_setup
3455 copytool setup --update-interval $interval --event-fifo \
3456 "$HSMTOOL_MONITOR_DIR/fifo"
3458 stack_trap "cdt_clear_no_retry" EXIT
3459 # Just start and stop the copytool to generate events.
3462 local f=$DIR/$tdir/$tfile
3464 fid=$(make_custom_file_for_progress $f 39 1000000)
3465 [ $? != 0 ] && skip "not enough free space" && return
3467 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3468 error "could not archive file"
3469 wait_request_state $fid ARCHIVE SUCCEED
3471 local expected_fields="event_time data_fid source_fid"
3472 expected_fields+=" total_bytes current_bytes"
3476 while read event; do
3477 # Make sure we're not getting anything from previous events.
3478 for field in $expected_fields; do
3482 local parsed=$(parse_json_event "$event")
3483 if [ -z "$parsed" ]; then
3484 error "Copytool sent malformed event: $event"
3488 if [ $event_type == "ARCHIVE_START" ]; then
3491 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3494 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3498 # Do some simple checking of the progress update events.
3499 for expected_field in $expected_fields; do
3500 if [ -z ${!expected_field+x} ]; then
3501 error "Missing $expected_field field in event"
3505 if [ $total_bytes -eq 0 ]; then
3506 error "Expected total_bytes to be > 0"
3509 # These should be identical throughout an archive
3511 if [ $source_fid != $data_fid ]; then
3512 error "Expected source_fid to equal data_fid"
3514 done < <(echo $"$(get_copytool_event_log)")
3516 if [ -z "$START_EVENT" ]; then
3517 error "Copytool failed to send archive start event to FIFO"
3520 if [ -z "$FINISH_EVENT" ]; then
3521 error "Copytool failed to send archive finish event to FIFO"
3524 echo "Archive events look OK."
3526 run_test 71 "Copytool logs JSON archive events to FIFO"
3529 # Bump progress interval for livelier events.
3532 # test needs a new running copytool
3533 stack_trap copytool_monitor_cleanup EXIT
3534 copytool_monitor_setup
3535 copytool setup --update-interval $interval --event-fifo \
3536 "$HSMTOOL_MONITOR_DIR/fifo"
3537 local test_file=$HSMTOOL_MONITOR_DIR/file
3539 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3541 do_facet $SINGLEAGT "$cmd" ||
3542 error "cannot create $test_file on $SINGLEAGT"
3543 copy2archive $test_file $tdir/$tfile
3546 local f=$DIR/$tdir/$tfile
3547 copytool import $tdir/$tfile $f
3548 f=$DIR2/$tdir/$tfile
3549 echo "Verifying released state: "
3550 check_hsm_flags $f "0x0000000d"
3552 local fid=$(path2fid $f)
3554 wait_request_state $fid RESTORE SUCCEED
3556 local expected_fields="event_time data_fid source_fid"
3557 expected_fields+=" total_bytes current_bytes"
3561 while read event; do
3562 # Make sure we're not getting anything from previous events.
3563 for field in $expected_fields; do
3567 local parsed=$(parse_json_event "$event")
3568 if [ -z "$parsed" ]; then
3569 error "Copytool sent malformed event: $event"
3573 if [ $event_type == "RESTORE_START" ]; then
3575 if [ $source_fid != $data_fid ]; then
3576 error "source_fid should == data_fid at start"
3579 elif [ $event_type == "RESTORE_FINISH" ]; then
3581 if [ $source_fid != $data_fid ]; then
3582 error "source_fid should == data_fid at finish"
3585 elif [ $event_type != "RESTORE_RUNNING" ]; then
3589 # Do some simple checking of the progress update events.
3590 for expected_field in $expected_fields; do
3591 if [ -z ${!expected_field+x} ]; then
3592 error "Missing $expected_field field in event"
3596 if [ $total_bytes -eq 0 ]; then
3597 error "Expected total_bytes to be > 0"
3600 # When a restore starts out, the data fid is the same as the
3601 # source fid. After the restore has gotten going, we learn
3602 # the new data fid. Once the restore has finished, the source
3603 # fid is set to the new data fid.
3605 # We test this because some monitoring software may depend on
3606 # this behavior. If it changes, then the consumers of these
3607 # events may need to be modified.
3608 if [ $source_fid == $data_fid ]; then
3609 error "source_fid should != data_fid during restore"
3611 done < <(echo $"$(get_copytool_event_log)")
3613 if [ -z "$START_EVENT" ]; then
3614 error "Copytool failed to send restore start event to FIFO"
3617 if [ -z "$FINISH_EVENT" ]; then
3618 error "Copytool failed to send restore finish event to FIFO"
3621 echo "Restore events look OK."
3623 run_test 72 "Copytool logs JSON restore events to FIFO"
3626 file_count=51 # Max number of files constrained by LNET message size
3627 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3628 local f=$DIR/$tdir/$tfile
3629 local FILELIST=/tmp/filelist.txt
3633 for i in $(seq 1 $file_count); do
3634 fid=$(copy_file /etc/hosts $f.$i)
3635 echo $f.$i >> $FILELIST
3639 # to be sure wait_all_done will not be mislead by previous tests
3641 wait_for_grace_delay
3642 $LFS hsm_archive --filelist $FILELIST ||
3643 error "cannot archive a file list"
3645 $LFS hsm_release --filelist $FILELIST ||
3646 error "cannot release a file list"
3647 $LFS hsm_restore --filelist $FILELIST ||
3648 error "cannot restore a file list"
3651 run_test 90 "Archive/restore a file list"
3653 double_verify_reset_hsm_param() {
3655 echo "Testing $HSM_PARAM.$p"
3656 local val=$(get_hsm_param $p)
3658 local val2=$(($val * 2))
3659 set_hsm_param $p $val2
3660 val=$(get_hsm_param $p)
3661 [[ $val == $val2 ]] ||
3662 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3663 echo "Set $p to 0 must failed"
3667 set_hsm_param $p $save
3669 if [[ $rc == 0 ]]; then
3670 error "we must not be able to set $HSM_PARAM.$p to 0"
3675 double_verify_reset_hsm_param loop_period
3676 double_verify_reset_hsm_param grace_delay
3677 double_verify_reset_hsm_param active_request_timeout
3678 double_verify_reset_hsm_param max_requests
3679 double_verify_reset_hsm_param default_archive_id
3681 run_test 100 "Set coordinator /proc tunables"
3688 run_test 102 "Verify coordinator control"
3691 # test needs a running copytool
3698 for i in $(seq 1 20); do
3699 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3701 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3705 echo "Current requests"
3706 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3707 $HSM_PARAM.actions |\
3708 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3710 [[ -z "$res" ]] || error "Some request have not been canceled"
3712 run_test 103 "Purge all requests"
3717 local f=$DIR/$tdir/$tfile
3719 fid=$(make_custom_file_for_progress $f 39 1000000)
3720 [ $? != 0 ] && skip "not enough free space" && return
3722 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3723 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3724 $HSM_PARAM.actions |\
3725 grep $fid | cut -f16 -d=")
3727 [[ "$data1" == "$DATAHEX" ]] ||
3728 error "Data field in records is ($data1) and not ($DATAHEX)"
3733 wait_request_state $fid ARCHIVE SUCCEED
3735 run_test 104 "Copy tool data field"
3738 local max_requests=$(get_hsm_param max_requests)
3742 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3743 set_hsm_param max_requests 300
3746 for i in $(seq -w 1 10); do
3747 cp /etc/passwd $DIR/$tdir/$i
3748 $LFS hsm_archive $DIR/$tdir/$i
3750 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3751 $HSM_PARAM.actions |\
3752 grep WAITING | wc -l")
3756 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3757 $HSM_PARAM.actions |\
3758 grep WAITING | wc -l")
3761 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3762 error "Requests count after shutdown $reqcnt2 != "\
3763 "before shutdown $reqcnt1"
3765 run_test 105 "Restart of coordinator"
3768 # test needs a running copytool
3771 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3773 check_agent_registered $uuid
3775 search_copytools || error "No copytool found"
3778 wait_copytools || error "Copytool failed to stop"
3780 check_agent_unregistered $uuid
3783 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3784 check_agent_registered $uuid
3786 run_test 106 "Copytool register/unregister"
3789 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3791 # test needs a running copytool
3793 # create and archive file
3795 local f1=$DIR/$tdir/$tfile
3796 local fid=$(copy_file /etc/passwd $f1)
3797 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3798 wait_request_state $fid ARCHIVE SUCCEED
3799 # shutdown and restart MDS
3801 # check the copytool still gets messages from MDT
3802 local f2=$DIR/$tdir/2
3803 local fid=$(copy_file /etc/passwd $f2)
3804 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3805 # main check of this sanity: this request MUST succeed
3806 wait_request_state $fid ARCHIVE SUCCEED
3808 run_test 107 "Copytool re-register after MDS restart"
3810 policy_set_and_test()
3814 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3815 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3816 [[ "$policy" == "$target" ]] ||
3817 error "Wrong policy after '$change': '$policy' != '$target'"
3821 # to force default policy setting if error
3822 CDT_POLICY_HAD_CHANGED=true
3824 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3825 local default="NonBlockingRestore [NoRetryAction]"
3826 [[ "$policy" == "$default" ]] ||
3827 error "default policy has changed,"\
3828 " '$policy' != '$default' update the test"
3829 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3830 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3831 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3832 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3833 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3834 # useless bacause we know but safer for futur changes to use real value
3835 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3836 echo "Next set_param must failed"
3837 policy_set_and_test "wrong" "$policy"
3840 echo "Back to default policy"
3841 cdt_set_sanity_policy
3843 run_test 109 "Policy display/change"
3846 # test needs a running copytool
3851 copy2archive /etc/passwd $tdir/$tfile
3853 local f=$DIR/$tdir/$tfile
3854 copytool import $tdir/$tfile $f
3855 local fid=$(path2fid $f)
3857 cdt_set_non_blocking_restore
3862 wait_request_state $fid RESTORE SUCCEED
3863 cdt_clear_non_blocking_restore
3867 error "md5sum returns $st != 1, "\
3868 "should also perror ENODATA (No data available)"
3870 run_test 110a "Non blocking restore policy (import case)"
3873 # test needs a running copytool
3877 local f=$DIR/$tdir/$tfile
3878 local fid=$(copy_file /etc/passwd $f)
3879 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3880 wait_request_state $fid ARCHIVE SUCCEED
3883 cdt_set_non_blocking_restore
3888 wait_request_state $fid RESTORE SUCCEED
3889 cdt_clear_non_blocking_restore
3893 error "md5sum returns $st != 1, "\
3894 "should also perror ENODATA (No data available)"
3896 run_test 110b "Non blocking restore policy (release case)"
3899 # test needs a running copytool
3903 copy2archive /etc/passwd $tdir/$tfile
3905 local f=$DIR/$tdir/$tfile
3907 copytool import $tdir/$tfile $f
3908 local fid=$(path2fid $f)
3912 copytool_remove_backend $fid
3915 wait_request_state $fid RESTORE FAILED
3922 [[ $st == 0 ]] || error "Restore does not failed"
3924 run_test 111a "No retry policy (import case), restore will error"\
3925 " (No such file or directory)"
3928 # test needs a running copytool
3932 local f=$DIR/$tdir/$tfile
3933 local fid=$(copy_file /etc/passwd $f)
3934 stack_trap cdt_clear_no_retry EXIT
3936 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3937 wait_request_state $fid ARCHIVE SUCCEED
3940 copytool_remove_backend $fid
3943 wait_request_state $fid RESTORE FAILED
3947 [[ $st == 0 ]] || error "Restore does not failed"
3949 run_test 111b "No retry policy (release case), restore will error"\
3950 " (No such file or directory)"
3953 # test needs a running copytool
3957 local f=$DIR/$tdir/$tfile
3958 local fid=$(copy_file /etc/passwd $f)
3960 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3961 local l=$($LFS hsm_action $f)
3963 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3966 wait_request_state $fid ARCHIVE SUCCEED
3969 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3971 run_test 112 "State of recorded request"
3974 # test needs a running copytool
3977 local f=$DIR/$tdir/$tfile
3979 fid=$(make_custom_file_for_progress $f 103 1048576)
3980 [ $? != 0 ] && skip "not enough free space" && return
3982 # test with cdt on is made in test_221
3984 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3985 # wait archive to register at CDT
3986 wait_request_state $fid ARCHIVE WAITING
3989 wait_request_state $fid ARCHIVE CANCELED
3990 wait_request_state $fid CANCEL SUCCEED
3992 run_test 200 "Register/Cancel archive"
3995 # test needs a running copytool
3998 local f=$DIR/$tdir/$tfile
3999 create_archive_file $tdir/$tfile
4000 copytool import $tdir/$tfile $f
4001 local fid=$(path2fid $f)
4003 # test with cdt on is made in test_222
4006 # wait restore to register at CDT
4007 wait_request_state $fid RESTORE WAITING
4010 wait_request_state $fid RESTORE CANCELED
4011 wait_request_state $fid CANCEL SUCCEED
4013 run_test 201 "Register/Cancel restore"
4016 # test needs a running copytool
4019 local f=$DIR/$tdir/$tfile
4021 fid=$(make_custom_file_for_progress $f 39 1000000)
4022 [ $? != 0 ] && skip "not enough free space" && return
4024 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4025 wait_request_state $fid ARCHIVE SUCCEED
4029 # wait remove to register at CDT
4030 wait_request_state $fid REMOVE WAITING
4033 wait_request_state $fid REMOVE CANCELED
4035 run_test 202 "Register/Cancel remove"
4037 test_220A() { # was test_220
4038 # test needs a running copytool
4043 local f=$DIR/$tdir/$tfile
4044 local fid=$(copy_file /etc/passwd $f)
4048 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4049 wait_request_state $fid ARCHIVE SUCCEED
4051 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4052 error "The expected changelog was not emitted"
4054 run_test 220A "Changelog for archive"
4057 # test needs a running copytool
4062 local f=$DIR/$tdir/$tfile
4063 local fid=$(copy_file /etc/passwd $f)
4067 # block copytool operations to allow for HSM request to be
4068 # submitted and file be unlinked (CDT will find object removed)
4071 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4073 # wait request to reach CT
4074 wait_request_state $fid ARCHIVE STARTED
4080 wait_request_state $fid ARCHIVE FAILED
4083 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4084 error "The expected changelog was not emitted"
4086 run_test 220a "Changelog for failed archive"
4089 # test needs a running copytool
4092 local f=$DIR/$tdir/$tfile
4094 fid=$(make_custom_file_for_progress $f 103 1048576)
4095 [ $? != 0 ] && skip "not enough free space" && return
4099 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4100 wait_request_state $fid ARCHIVE STARTED
4102 wait_request_state $fid ARCHIVE CANCELED
4103 wait_request_state $fid CANCEL SUCCEED
4105 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4106 error "The expected changelog was not emitted"
4108 run_test 221 "Changelog for archive canceled"
4111 # test needs a running copytool
4115 copy2archive /etc/passwd $tdir/$tfile
4117 local f=$DIR/$tdir/$tfile
4118 copytool import $tdir/$tfile $f
4119 local fid=$(path2fid $f)
4124 wait_request_state $fid RESTORE SUCCEED
4126 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4127 error "The expected changelog was not emitted"
4129 run_test 222a "Changelog for explicit restore"
4132 # test needs a running copytool
4136 local f=$DIR/$tdir/$tfile
4137 local fid=$(copy_file /etc/passwd $f)
4140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4141 wait_request_state $fid ARCHIVE SUCCEED
4146 wait_request_state $fid RESTORE SUCCEED
4148 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4149 error "The expected changelog was not emitted"
4151 run_test 222b "Changelog for implicit restore"
4154 # test needs a running copytool
4158 copy2archive /etc/passwd $tdir/$tfile
4160 local f=$DIR/$tdir/$tfile
4161 copytool import $tdir/$tfile $f
4162 local fid=$(path2fid $f)
4166 # block copytool operations to allow for HSM request to be
4167 # submitted and file be unlinked (CDT will find object removed)
4172 # wait request to reach CT
4173 wait_request_state $fid RESTORE STARTED
4179 wait_request_state $fid RESTORE FAILED
4182 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4183 error "The expected changelog was not emitted"
4185 run_test 222c "Changelog for failed explicit restore"
4188 # test needs a running copytool
4192 local f=$DIR/$tdir/$tfile
4193 local fid=$(copy_file /etc/passwd $f)
4196 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4197 wait_request_state $fid ARCHIVE SUCCEED
4200 copytool_remove_backend $fid
4203 wait_request_state $fid RESTORE FAILED
4206 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4207 error "The expected changelog was not emitted"
4209 run_test 222d "Changelog for failed implicit restore"
4212 # test needs a running copytool
4215 local f=$DIR/$tdir/$tfile
4216 create_archive_file $tdir/$tfile
4220 copytool import $tdir/$tfile $f
4221 local fid=$(path2fid $f)
4224 wait_request_state $fid RESTORE STARTED
4226 wait_request_state $fid RESTORE CANCELED
4227 wait_request_state $fid CANCEL SUCCEED
4229 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4230 error "The expected changelog was not emitted"
4232 run_test 223a "Changelog for restore canceled (import case)"
4235 # test needs a running copytool
4238 local f=$DIR/$tdir/$tfile
4240 fid=$(make_custom_file_for_progress $f 39 1000000)
4241 [ $? != 0 ] && skip "not enough free space" && return
4244 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4245 wait_request_state $fid ARCHIVE SUCCEED
4248 wait_request_state $fid RESTORE STARTED
4250 wait_request_state $fid RESTORE CANCELED
4251 wait_request_state $fid CANCEL SUCCEED
4253 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4254 error "The expected changelog was not emitted"
4256 run_test 223b "Changelog for restore canceled (release case)"
4258 test_224A() { # was test_224
4259 # test needs a running copytool
4264 local f=$DIR/$tdir/$tfile
4265 local fid=$(copy_file /etc/passwd $f)
4268 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4269 wait_request_state $fid ARCHIVE SUCCEED
4272 wait_request_state $fid REMOVE SUCCEED
4274 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4275 error "The expected changelog was not emitted"
4277 run_test 224A "Changelog for remove"
4280 # test needs a running copytool
4285 local f=$DIR/$tdir/$tfile
4286 local fid=$(copy_file /etc/passwd $f)
4289 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4290 wait_request_state $fid ARCHIVE SUCCEED
4292 copytool_remove_backend $fid
4294 # block copytool operations to allow for HSM request to be
4295 # submitted and file be unlinked (CDT will find object removed)
4300 # wait for request to reach CT
4301 wait_request_state $fid REMOVE STARTED
4307 wait_request_state $fid REMOVE FAILED
4309 # HE_REMOVE|ENOENT=0x202
4310 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4311 error "The expected changelog was not emitted"
4313 run_test 224a "Changelog for failed remove"
4316 # test is not usable because remove request is too fast
4317 # so it is always finished before cancel can be done ...
4318 echo "Test disabled"
4321 # test needs a running copytool
4324 local f=$DIR/$tdir/$tfile
4326 fid=$(make_custom_file_for_progress $f 39 1000000)
4327 [ $? != 0 ] && skip "not enough free space" && return
4330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4331 wait_request_state $fid ARCHIVE SUCCEED
4333 # if cdt is on, it can serve too quickly the request
4338 wait_request_state $fid REMOVE CANCELED
4339 wait_request_state $fid CANCEL SUCCEED
4341 changelog_find -type HSM -target-fid $fid -flags 0x27d
4342 error "The expected changelog was not emitted"
4344 run_test 225 "Changelog for remove canceled"
4347 # test needs a running copytool
4352 local f1=$DIR/$tdir/$tfile-1
4353 local f2=$DIR/$tdir/$tfile-2
4354 local f3=$DIR/$tdir/$tfile-3
4355 local fid1=$(copy_file /etc/passwd $f1)
4356 local fid2=$(copy_file /etc/passwd $f2)
4357 copy_file /etc/passwd $f3
4360 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4361 wait_request_state $fid1 ARCHIVE SUCCEED
4363 $LFS hsm_archive $f2
4364 wait_request_state $fid2 ARCHIVE SUCCEED
4366 rm $f1 || error "rm $f1 failed"
4369 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4370 error "The expected changelog was not emitted"
4372 mv $f3 $f2 || error "mv $f3 $f2 failed"
4374 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4375 error "The expected changelog was not emitted"
4377 run_test 226 "changelog for last rm/mv with exiting archive"
4379 # This is just a utility function to clarify what test_227 does
4384 "$LFS" "$action" --$flag "$file" ||
4385 error "Cannot ${action#hsm_} $flag on '$file'"
4387 # Only one changelog should be produced
4388 local entries="$(changelog_find -type HSM -target-fid $fid)"
4389 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4390 error "lfs $action --$flag '$file' produced more than one" \
4393 # Parse the last changelog record
4394 local entry="$(tail -n 1 <<< "$entries")"
4395 eval local -A changelog=$(changelog2array $entry)
4397 # Also check the flags match what is expected
4398 [[ ${changelog[flags]} == $target ]] ||
4399 error "Changelog flag is '${changelog[flags]}', not $target"
4403 local file="$DIR/$tdir/$tfile"
4404 local fid=$(create_empty_file "$file")
4409 for flag in norelease noarchive exists archived lost; do
4410 if [ "$flag" == lost ]; then
4411 # The flag "lost" only works on an archived file
4412 "$LFS" hsm_set --archived "$file"
4416 action="hsm_set" __test_227
4417 action="hsm_clear" __test_227
4420 run_test 227 "changelog when explicit setting of HSM flags"
4423 # test needs a running copytool
4426 local fid=$(create_small_sync_file $DIR/$tfile)
4427 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4428 wait_request_state $fid ARCHIVE SUCCEED
4430 $LFS hsm_release $DIR/$tfile
4431 check_hsm_flags $DIR/$tfile "0x0000000d"
4433 filefrag $DIR/$tfile | grep " 1 extent found" ||
4434 error "filefrag on released file must return only one extent"
4436 # only newer versions of cp detect sparse files by stat/FIEMAP
4438 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4439 error "copying $DIR/$tfile"
4440 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4442 $LFS hsm_release $DIR/$tfile
4443 check_hsm_flags $DIR/$tfile "0x0000000d"
4445 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4447 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4449 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4450 error "comparing untarred $DIR/$tfile"
4452 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4453 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4455 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4458 # test needs a running copytool
4462 local maxrequest=$(get_hsm_param max_requests)
4463 local rqcnt=$(($maxrequest * 3))
4467 for i in $(seq -w 1 $rqcnt); do
4469 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4471 # we do it in 2 steps, so all requests arrive at the same time
4472 for i in $(seq -w 1 $rqcnt); do
4473 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4478 while [[ $cnt != 0 || $wt != 0 ]]; do
4480 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4481 $HSM_PARAM.actions |\
4482 grep STARTED | grep -v CANCEL | wc -l")
4483 [[ $cnt -le $maxrequest ]] ||
4484 error "$cnt > $maxrequest too many started requests"
4485 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4486 $HSM_PARAM.actions |\
4487 grep WAITING | wc -l")
4488 echo "max=$maxrequest started=$cnt waiting=$wt"
4491 run_test 250 "Coordinator max request"
4494 # test needs a running copytool
4497 local f=$DIR/$tdir/$tfile
4499 fid=$(make_custom_file_for_progress $f 103 1048576)
4500 [ $? != 0 ] && skip "not enough free space" && return
4503 # to have a short test
4504 local old_to=$(get_hsm_param active_request_timeout)
4505 set_hsm_param active_request_timeout 4
4506 # to be sure the cdt will wake up frequently so
4507 # it will be able to cancel the "old" request
4508 local old_loop=$(get_hsm_param loop_period)
4509 set_hsm_param loop_period 2
4512 # clear locks to avoid extra delay caused by flush/cancel
4513 # and thus prevent early copytool death to timeout.
4514 cancel_lru_locks osc
4516 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4517 wait_request_state $fid ARCHIVE STARTED
4519 wait_request_state $fid ARCHIVE CANCELED
4521 set_hsm_param active_request_timeout $old_to
4522 set_hsm_param loop_period $old_loop
4524 run_test 251 "Coordinator request timeout"
4528 local f=$DIR/$tdir/$tfile
4529 local fid=$(create_empty_file "$f")
4531 # to have a short test
4532 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4533 set_hsm_param loop_period 1
4538 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4539 wait_request_state $fid ARCHIVE STARTED
4542 stack_trap "set_hsm_param active_request_timeout \
4543 $(get_hsm_param active_request_timeout)" EXIT
4544 set_hsm_param active_request_timeout 1
4546 wait_request_state $fid ARCHIVE CANCELED
4549 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4553 # test needs a running copytool
4557 local f=$DIR/$tdir/$tfile
4559 dd if=/dev/zero of=$f bs=1MB count=10
4560 local fid=$(path2fid $f)
4562 $LFS hsm_archive $f || error "could not archive file"
4563 wait_request_state $fid ARCHIVE SUCCEED
4565 # clear locks to discard inode data
4566 cancel_lru_locks osc
4568 #define OBD_FAIL_MDC_MERGE 0x807
4569 $LCTL set_param fail_loc=0x807
4571 #expect error here, instead of release with wrong size
4574 if ((rc == 0)); then
4575 file_size=$(stat -c '%s' $f)
4576 if ((file_size != 10485760)); then
4577 error "Wrong file size after hsm_release"
4580 echo "could not release file"
4583 run_test 253 "Check for wrong file size after release"
4587 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4588 skip "need MDS version at least 2.10.56" && return
4590 # Check that the counters are initialized to 0
4592 for request_type in archive restore remove; do
4593 count="$(get_hsm_param ${request_type}_count)" ||
4594 error "Reading ${request_type}_count failed with $?"
4596 [ "$count" -eq 0 ] ||
4597 error "Expected ${request_type}_count to be " \
4601 run_test 254a "Request counters are initialized to zero"
4605 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4606 skip "need MDS version at least 2.10.56" && return
4608 # The number of request to launch (at least 32)
4609 local request_count=$((RANDOM % 32 + 32))
4610 printf "Will launch %i requests of each type\n" "$request_count"
4612 # Launch a copytool to process requests
4615 # Set hsm.max_requests to allow starting all requests at the same time
4617 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4618 set_hsm_param max_requests "$request_count"
4622 for request_type in archive restore remove; do
4623 printf "Checking %s requests\n" "${request_type}"
4624 # Suspend the copytool to give us time to read the proc files
4627 for ((i = 0; i < $request_count; i++)); do
4628 case $request_type in
4630 create_empty_file "$DIR/$tdir/$tfile-$i" \
4634 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4637 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4640 # Give the coordinator 10 seconds to start every request
4642 while get_hsm_param actions | grep -q WAITING; do
4645 [ $timeout -gt 0 ] ||
4646 error "${request_type^} requests took too " \
4650 count="$(get_hsm_param ${request_type}_count)"
4651 [ "$count" -eq "$request_count" ] ||
4652 error "Expected '$request_count' (!= '$count') " \
4653 "active $request_type requests"
4655 # Let the copytool process the requests
4657 # Give it 10 seconds maximum
4659 while get_hsm_param actions | grep -q STARTED; do
4662 [ $timeout -gt 0 ] ||
4663 error "${request_type^} requests took too " \
4667 count="$(get_hsm_param ${request_type}_count)"
4668 [ "$count" -eq 0 ] ||
4669 error "Expected 0 (!= '$count') " \
4670 "active $request_type requests"
4673 run_test 254b "Request counters are correctly incremented and decremented"
4676 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4678 # the only way to test ondisk conf is to restart MDS ...
4679 echo "Stop coordinator and remove coordinator state at mount"
4682 # clean on disk conf set by default
4683 cdt_clear_mount_state
4684 cdt_check_state stopped
4686 # check cdt still off after umount/remount
4688 cdt_check_state stopped
4690 echo "Set coordinator start at mount, and start coordinator"
4691 cdt_set_mount_state enabled
4694 cdt_check_state enabled
4696 # check cdt still on after umount/remount
4698 cdt_check_state enabled
4700 # we are back to original state (cdt started at mount)
4702 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4705 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4707 local ai=$(get_hsm_param default_archive_id)
4708 local new=$((ai + 1))
4710 set_hsm_param default_archive_id $new -P
4712 local res=$(get_hsm_param default_archive_id)
4715 set_hsm_param default_archive_id "" "-P -d"
4717 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4719 run_test 301 "HSM tunnable are persistent"
4722 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4724 local ai=$(get_hsm_param default_archive_id)
4725 local new=$((ai + 1))
4730 set_hsm_param default_archive_id $new -P
4733 for mdtno in $(seq 1 $MDSCOUNT); do
4738 cdt_check_state enabled
4740 local res=$(get_hsm_param default_archive_id)
4743 set_hsm_param default_archive_id "" "-P -d"
4745 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4747 run_test 302 "HSM tunnable are persistent when CDT is off"
4750 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4756 local dir_mdt0=$DIR/$tdir/mdt0
4757 local dir_mdt1=$DIR/$tdir/mdt1
4759 # create 1 dir per MDT
4760 stack_trap "rm -rf $dir_mdt0" EXIT
4761 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4762 stack_trap "rm -rf $dir_mdt1" EXIT
4763 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4765 # create 1 file in each MDT
4766 local fid1=$(create_small_file $dir_mdt0/$tfile)
4767 local fid2=$(create_small_file $dir_mdt1/$tfile)
4769 # check that hsm request on mdt0 is sent to the right MDS
4770 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4771 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4772 echo "archive successful on mdt0"
4774 # check that hsm request on mdt1 is sent to the right MDS
4775 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4776 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4777 echo "archive successful on mdt1"
4779 run_test 400 "Single request is sent to the right MDT"
4782 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4788 local dir_mdt0=$DIR/$tdir/mdt0
4789 local dir_mdt1=$DIR/$tdir/mdt1
4791 # create 1 dir per MDT
4792 stack_trap "rm -rf $dir_mdt0" EXIT
4793 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4794 stack_trap "rm -rf $dir_mdt1" EXIT
4795 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4797 # create 1 file in each MDT
4798 local fid1=$(create_small_file $dir_mdt0/$tfile)
4799 local fid2=$(create_small_file $dir_mdt1/$tfile)
4801 # check that compound requests are shunt to the rights MDTs
4802 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4803 error "lfs hsm_archive"
4804 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4805 echo "archive successful on mdt0"
4806 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4807 echo "archive successful on mdt1"
4809 run_test 401 "Compound requests split and sent to their respective MDTs"
4811 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4816 local node=$(facet_active_host $facet)
4818 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4819 awk '{print $4}'); do
4820 echo "$3 $mdc on $node"
4821 do_facet $facet "$LCTL --device $mdc $state" || return 1
4826 # deactivate all mdc on agent1
4827 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4829 copytool setup --no-fail
4831 check_agent_unregistered "uuid" # match any agent
4833 # no expected running copytool
4834 search_copytools $agent && error "Copytool start should have failed"
4837 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4839 run_test 402a "Copytool start fails if all MDTs are inactive"
4846 local f=$DIR/$tdir/$tfile
4847 touch $f || error "touch $f failed"
4848 local fid=$(path2fid $f)
4850 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4851 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4852 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4854 # give time for CDT to send request and to keep it for retry
4855 wait_for_loop_period
4857 wait_request_state $fid ARCHIVE WAITING
4859 do_facet $SINGLEAGT lctl set_param fail_loc=0
4861 # request should succeed now
4862 wait_request_state $fid ARCHIVE SUCCEED
4864 run_test 402b "CDT must retry request upon slow start of CT"
4867 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4869 local agent=$(facet_active_host $SINGLEAGT)
4871 # deactivate all mdc for MDT0001
4872 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4875 local uuid=$(get_agent_uuid $agent)
4876 # check the agent is registered on MDT0000, and not on MDT0001
4877 check_agent_registered_by_mdt $uuid 0
4878 check_agent_unregistered_by_mdt $uuid 1
4880 # check running copytool process
4881 search_copytools $agent || error "No running copytools on $agent"
4883 # reactivate all mdc for MDT0001
4884 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4886 # make sure the copytool is now registered to all MDTs
4887 check_agent_registered $uuid
4889 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4892 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4896 # create files on both MDT0000 and MDT0001
4899 local dir_mdt0=$DIR/$tdir/mdt0
4900 stack_trap "rm -rf $dir_mdt0" EXIT
4901 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4903 # create 1 file on mdt0
4904 local fid1=$(create_small_file $dir_mdt0/$tfile)
4906 # deactivate all mdc for MDT0001
4907 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4909 # send an HSM request for files in MDT0000
4910 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4912 # check for completion of files in MDT0000
4913 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4914 echo "archive successful on mdt0"
4916 # reactivate all mdc for MDT0001
4917 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4919 run_test 404 "Inactive MDT does not block requests for active MDTs"
4922 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4928 local striped_dir=$DIR/$tdir/striped_dir
4930 # create striped dir on all of MDTs
4931 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4933 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4934 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4935 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4936 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4938 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4939 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4940 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4941 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4943 # check that compound requests are shunt to the rights MDTs
4944 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4945 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4946 error "lfs hsm_archive"
4948 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4949 echo "archive successful on $fid1"
4950 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4951 echo "archive successful on $fid2"
4952 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4953 echo "archive successful on $fid3"
4954 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4955 echo "archive successful on $fid4"
4957 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4958 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4959 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4960 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4962 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4963 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4964 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4965 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4967 run_test 405 "archive and release under striped directory"
4970 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4972 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4973 skip "need MDS version at least 2.7.64" && return 0
4978 fid=$(create_small_file $DIR/$tdir/$tfile)
4983 $LFS hsm_archive $DIR/$tdir/$tfile
4984 wait_request_state "$fid" ARCHIVE SUCCEED
4985 $LFS hsm_release $DIR/$tdir/$tfile
4987 # Should migrate $tdir but not $tfile.
4988 $LFS migrate -m1 $DIR/$tdir &&
4989 error "migrating HSM an archived file should fail"
4991 $LFS hsm_restore $DIR/$tdir/$tfile
4992 wait_request_state "$fid" RESTORE SUCCEED
4994 $LFS hsm_remove $DIR/$tdir/$tfile
4995 wait_request_state "$fid" REMOVE SUCCEED
4997 cat $DIR/$tdir/$tfile > /dev/null ||
4998 error "cannot read $DIR/$tdir/$tfile"
5000 $LFS migrate -m1 $DIR/$tdir ||
5001 error "cannot complete migration after HSM remove"
5003 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5004 if ((mdt_index != 1)); then
5005 error "expected MDT index 1, got $mdt_index"
5008 # Refresh fid after migration.
5009 fid=$(path2fid $DIR/$tdir/$tfile)
5012 $LFS hsm_archive $DIR/$tdir/$tfile
5013 wait_request_state "$fid" ARCHIVE SUCCEED 1
5015 lctl set_param debug=+trace
5016 $LFS hsm_release $DIR/$tdir/$tfile ||
5017 error "cannot release $DIR/$tdir/$tfile"
5019 $LFS hsm_restore $DIR/$tdir/$tfile
5020 wait_request_state "$fid" RESTORE SUCCEED 1
5022 cat $DIR/$tdir/$tfile > /dev/null ||
5023 error "cannot read $DIR/$tdir/$tfile"
5025 run_test 406 "attempting to migrate HSM archived files is safe"
5028 needclients 2 || return 0
5029 # test needs a running copytool
5034 local f=$DIR/$tdir/$tfile
5035 local f2=$DIR2/$tdir/$tfile
5037 fid=$(make_custom_file_for_progress $f 39 1000000)
5038 [ $? != 0 ] && skip "not enough free space" && return
5040 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5041 wait_request_state $fid ARCHIVE SUCCEED
5044 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5045 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5048 # 1st request holds layout lock while appropriate
5049 # RESTORE record is still not added to llog
5053 # after umount hsm_actions->O/x/x log shouldn't have
5054 # double RESTORE records like below
5055 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5056 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5058 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5061 wait_request_state $fid RESTORE SUCCEED
5063 run_test 407 "Check for double RESTORE records in llog"
5067 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5068 skip "HSM migrate is not supported" && return
5070 test_mkdir -p $DIR/$tdir
5071 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5073 run_test 500 "various LLAPI HSM tests"
5076 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5077 skip "need MDS version at least 2.10.58" && return 0
5081 local f=$DIR/$tdir/$tfile
5084 # set changelog_mask to ALL
5085 changelog_chmask "ALL"
5087 chmod 777 $DIR/$tdir
5088 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5089 local fid=$(path2fid $f)
5092 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5093 -gid "$RUNAS_GID") ||
5094 error "No matching CREAT entry"
5096 # Parse the changelog
5097 eval local -A changelog=$(changelog2array $entry)
5098 local nid="${changelog[nid]}"
5101 echo "Got NID '$nid'"
5102 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5103 error "nid '$nid' does not match any client NID:" \
5106 run_test 600 "Changelog fields 'u=' and 'nid='"
5109 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5110 skip "need MDS version at least 2.10.58" && return 0
5114 local f=$DIR/$tdir/$tfile
5117 # set changelog_mask to ALL
5118 changelog_chmask "ALL"
5120 touch $f || error "touch $f failed"
5121 local fid=$(path2fid $f)
5124 cat $f || error "cat $f failed"
5126 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5127 error "No matching OPEN entry"
5129 run_test 601 "OPEN Changelog entry"
5132 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5133 skip "need MDS version at least 2.10.58" && return 0
5137 local f=$DIR/$tdir/$tfile
5140 # set changelog_mask to ALL
5141 changelog_chmask "ALL"
5143 touch $f || error "touch $f failed"
5144 local fid=$(path2fid $f)
5147 cat $f || error "cat $f failed"
5149 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5153 echo f > $f || error "write $f failed"
5156 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5158 # remove OPEN from changelog_mask
5159 changelog_chmask "-OPEN"
5163 cat $f || error "cat $f failed"
5166 changelog_find -type CLOSE -target-fid $fid &&
5167 error "There should be no CLOSE entry"
5171 echo f > $f || error "write $f failed"
5174 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5176 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5179 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5180 skip "need MDS version at least 2.10.58" && return 0
5184 local f=$DIR/$tdir/$tfile
5187 # set changelog_mask to ALL
5188 changelog_chmask "ALL"
5190 touch $f || error "touch $f failed"
5191 local fid=$(path2fid $f)
5193 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5196 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5198 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5199 error "No matching GXATR entry"
5201 run_test 603 "GETXATTR Changelog entry"
5204 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5205 skip "need MDS version at least 2.10.58" && return 0
5209 local f=$DIR/$tdir/$tfile
5210 local f2=$DIR2/$tdir/$tfile
5211 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5213 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5214 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5215 do_facet mds1 lctl set_param "$procname=20"
5219 # set changelog_mask to ALL
5220 changelog_chmask "ALL"
5222 touch $f || error "touch $f failed"
5223 local fid=$(path2fid $f)
5229 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5233 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5234 -gid "$RUNAS_GID" -mode "r--") ||
5235 error "No matching NOPEN entry"
5237 # Parse the changelog
5238 eval local -A changelog=$(changelog2array $entry)
5239 local nid="${changelog[nid]}"
5242 echo "Got NID '$nid'"
5243 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5244 error "nid '$nid' does not match any client NID:" \
5249 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5252 changelog_find -type NOPEN -target-fid $fid &&
5253 error "There should be no NOPEN entry"
5255 # Sleep for `changelog_deniednext` seconds
5260 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5263 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5264 -gid "$RUNAS_GID" -mode "r--") ||
5265 error "No matching NOPEN entry"
5267 # Parse the changelog
5268 eval local -A changelog=$(changelog2array $entry)
5269 local nid="${changelog[nid]}"
5272 echo "Got NID '$nid'"
5273 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5274 error "nid '$nid' does not match any client NID:" \
5277 run_test 604 "NOPEN Changelog entry"
5280 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5281 skip "need MDS version at least 2.10.58" && return 0
5285 local f=$DIR/$tdir/$tfile
5286 local f2=$DIR2/$tdir/$tfile
5289 # set changelog_mask to ALL
5290 changelog_chmask "ALL"
5292 touch $f || error "touch $f failed"
5293 local fid=$(path2fid $f)
5297 exec 3<> $f || error "open $f failed"
5301 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5305 exec 4<> $f || error "open $f failed"
5308 changelog_find -type OPEN -target-fid $fid &&
5309 error "There should be no OPEN entry"
5311 exec 4>&- || error "close $f failed"
5314 changelog_find -type CLOSE -target-fid $fid &&
5315 error "There should be no CLOSE entry"
5319 # access in rw, so different access mode should generate entries
5320 cat $f || error "cat $f failed"
5323 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5325 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5329 # same access as first one, should not generate new entries
5330 exec 4<> $f || error "open $f failed"
5333 changelog_find -type OPEN -target-fid $fid &&
5334 error "There should be no OPEN entry"
5336 exec 4>&- || error "close $f failed"
5339 changelog_find -type CLOSE -target-fid $fid &&
5340 error "There should be no CLOSE entry"
5344 # access by different user should generate new entries
5345 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5348 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5350 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5354 exec 3>&- || error "close $f failed"
5357 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5359 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5362 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5363 skip "need MDS version at least 2.10.58" && return 0
5365 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5366 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5367 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5368 skip_env "missing llog_reader" && return
5369 local fstype=$(facet_fstype mds1)
5373 local f=$DIR/$tdir/$tfile
5376 # set changelog_mask to ALL
5377 changelog_chmask "ALL"
5379 chmod 777 $DIR/$tdir
5380 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5381 local fid=$(path2fid $f)
5382 rm $f || error "rm $f failed"
5384 local mntpt=$(facet_mntpt mds1)
5388 #remount mds1 as ldiskfs or zfs type
5389 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5390 stop mds1 || error "stop mds1 failed"
5391 mount_fstype mds1 || error "remount mds1 failed"
5393 for ((i = 0; i < 1; i++)); do
5394 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5395 local cat_file=$(do_facet mds1 $llog_reader \
5396 $mntpt/changelog_catalog | awk \
5397 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5398 [ -n "$cat_file" ] || error "no catalog file"
5400 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5401 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5402 [ -n "$entry" ] || error "no CREAT entry"
5405 local uidgid=$(echo $entry |
5406 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5407 [ -n "$uidgid" ] || error "uidgid is empty"
5408 echo "Got UID/GID $uidgid"
5409 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5410 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5411 local nid=$(echo $entry |
5412 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5413 [ -n "$nid" ] || error "nid is empty"
5415 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5416 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5418 run_test 606 "llog_reader groks changelog fields"
5421 check_and_cleanup_lustre