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:
16 ALWAYS_EXCEPT="406 $SANITY_HSM_EXCEPT"
17 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
19 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
21 . $LUSTRE/tests/test-framework.sh
23 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
26 MULTIOP=${MULTIOP:-multiop}
27 OPENFILE=${OPENFILE:-openfile}
28 MMAP_CAT=${MMAP_CAT:-mmap_cat}
29 MOUNT_2=${MOUNT_2:-"yes"}
32 # script only handles up to 10 MDTs (because of MDT_PREFIX)
33 [ $MDSCOUNT -gt 9 ] &&
34 error "script cannot handle more than 9 MDTs, please fix" && exit
36 check_and_setup_lustre
38 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.53) ]]; then
39 skip_env "Need MDS version at least 2.4.53" && exit
42 # $RUNAS_ID may get set incorrectly somewhere else
43 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
44 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!" && exit
46 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
47 if getent group nobody; then
49 elif getent group nogroup; then
52 error "No generic nobody group"
57 # if there is no CLIENT1 defined, some tests can be ran on localhost
58 CLIENT1=${CLIENT1:-$HOSTNAME}
59 # if CLIENT2 doesn't exist then use CLIENT1 instead
60 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
62 # Exception is the test which need two separate nodes
63 CLIENT2=${CLIENT2:-$CLIENT1}
66 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
67 # the following associated variables are added:
69 # AGTCOUNT: number of agents
70 # AGTDEV{N}: target HSM mount point (root path of the backend)
71 # agt{N}_HOST: hostname of the agent agt{N}
72 # SINGLEAGT: facet of the single agent
74 # The number of agents is initialized as the number of remote client nodes.
75 # By default, only single copytool is started on a remote client/agent. If there
76 # was no remote client, then the copytool will be started on the local client.
82 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
83 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
85 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
86 if [[ $CLIENTCOUNT -gt 1 ]] &&
87 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
88 skip_env "SHARED_DIRECTORY should be accessible"\
93 # We used to put the HSM archive in $SHARED_DIRECTORY but that
94 # meant NFS issues could hose sanity-hsm sessions. So now we
96 for n in $(seq $AGTCOUNT); do
97 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
98 agent=CLIENT$((n + 1))
99 if [[ -z "${!agent}" ]]; then
100 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
103 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
106 export SINGLEAGT=${SINGLEAGT:-agt1}
108 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
109 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
110 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
111 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
112 export HSMTOOL_TESTDIR
113 export HSMTOOL_BASE=$(basename "$HSMTOOL" | cut -f1 -d" ")
117 # The test only support up to 10 MDTs
118 MDT_PREFIX="mdt.$FSNAME-MDT000"
119 HSM_PARAM="${MDT_PREFIX}0.hsm"
121 # archive is purged at copytool setup
122 HSM_ARCHIVE_PURGE=true
124 # Don't allow copytool error upon start/setup
125 HSMTOOL_NOERROR=false
128 # Get the backend root path for the given agent facet.
131 local dev=AGTDEV$(facet_number $facet)
138 # get MDT device for each mdc
139 for mdtno in $(seq 1 $MDSCOUNT); do
140 local idx=$(($mdtno - 1))
141 MDT[$idx]=$($LCTL get_param -n \
142 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
143 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
148 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
149 do_nodesv $hosts "pgrep -x $HSMTOOL_BASE"
153 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
155 echo "Killing existing copytools on $hosts"
156 do_nodesv $hosts "killall -q $HSMTOOL_BASE" || true
160 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
161 local wait_timeout=200
162 local wait_start=$SECONDS
163 local wait_end=$((wait_start + wait_timeout))
164 local sleep_time=100000 # 0.1 second
166 while ((SECONDS < wait_end)); do
167 if ! search_copytools $hosts; then
168 echo "copytools stopped in $((SECONDS - wait_start))s"
172 echo "copytools still running on $hosts"
174 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
175 sleep_time=$(bc <<< "$sleep_time * 2")
178 # try to dump Copytool's stack
179 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
180 "echo t >/proc/sysrq-trigger"
182 echo "copytools failed to stop in ${wait_timeout}s"
187 copytool_monitor_setup() {
188 local facet=${1:-$SINGLEAGT}
189 local agent=$(facet_active_host $facet)
191 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
192 local test_dir=$(do_node $agent "$cmd") ||
193 error "Failed to create tempdir on $agent"
194 export HSMTOOL_MONITOR_DIR=$test_dir
196 # Create the fifo and a monitor (cat dies when copytool dies)
197 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
198 error "failed to create copytool fifo on $agent"
199 cmd="cat $test_dir/fifo > $test_dir/events &"
200 cmd+=" echo \\\$! > $test_dir/monitor_pid"
202 if [[ $PDSH == *Rmrsh* ]]; then
203 # This is required for pdsh -Rmrsh and its handling of remote
205 # Regular ssh and pdsh -Rssh work fine without this
206 # backgrounded subshell nonsense.
207 (do_node $agent "$cmd") &
208 export HSMTOOL_MONITOR_PDSH=$!
210 # Slightly racy, but just making a best-effort to catch obvious
213 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
214 error "Failed to start copytool monitor on $agent"
216 do_node $agent "$cmd"
218 error "Failed to start copytool monitor on $agent"
223 copytool_monitor_cleanup() {
224 local facet=${1:-$SINGLEAGT}
225 local agent=$(facet_active_host $facet)
227 if [ -n "$HSMTOOL_MONITOR_DIR" ]; then
228 # Should die when the copytool dies, but just in case.
229 local cmd="kill \\\$(cat $HSMTOOL_MONITOR_DIR/monitor_pid)"
230 cmd+=" 2>/dev/null || true"
231 do_node $agent "$cmd"
232 do_node $agent "rm -fr $HSMTOOL_MONITOR_DIR"
233 export HSMTOOL_MONITOR_DIR=
236 # The pdsh should die on its own when the monitor dies. Just
237 # in case, though, try to clean up to avoid any cruft.
238 if [ -n "$HSMTOOL_MONITOR_PDSH" ]; then
239 kill $HSMTOOL_MONITOR_PDSH 2>/dev/null || true
240 export HSMTOOL_MONITOR_PDSH=
250 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
257 local host="$(facet_host "$1")"
258 local prefix=$TESTLOG_PREFIX
259 [ -n "$TESTNAME" ] && prefix+=.$TESTNAME
261 printf "${prefix}.copytool${archive_id}_log.${host}.log"
266 do_facet $facet $HSMTOOL -p "$hsm_root" --rebind "$@" "$mountpoint"
271 mkdir -p "$(dirname "$2")" ||
272 error "cannot create directory '$(dirname "$2")'"
273 do_facet $facet $HSMTOOL -p "$hsm_root" --import "$@" "$mountpoint"
278 local cmd="$HSMTOOL $HSMTOOL_VERBOSE --daemon --hsm-root \"$hsm_root\""
279 [ -n "$bandwidth" ] && cmd+=" --bandwidth $bandwidth"
280 [ -n "$archive_id" ] && cmd+=" --archive $archive_id"
281 [ ${#misc_options[@]} -gt 0 ] &&
282 cmd+=" $(IFS=" " echo "$@")"
283 cmd+=" \"$mountpoint\""
285 echo "Starting copytool $facet on $(facet_host $facet)"
286 stack_trap "do_facet $facet \"pkill -x $HSMTOOL_BASE\" || true" EXIT
287 do_facet $facet "$cmd < /dev/null > \"$(copytool_logfile $facet)\" 2>&1"
291 local facet="${1:-$SINGLEAGT}"
293 printf "$(copytool_device "$facet")/${TESTSUITE}.${TESTNAME}/"
296 # Main entry point to perform copytool related operations
300 # setup setup a copytool to run in the background, that copytool will be
302 # import import a file from an HSM backend
303 # rebind rebind an archived file to a new fid
305 # Although the semantics might suggest otherwise, one does not need to 'setup'
306 # a copytool before a call to 'copytool import' or 'copytool rebind'.
314 local fail_on_error=true
315 local -a misc_options
316 while [ $# -gt 0 ]; do
324 local mountpoint="$1"
328 local archive_id="$1"
332 local bandwidth="$1" # in MB/s
335 local fail_on_error=false
338 # Uncommon(/copytool dependent) option
345 # Use default values if needed
346 local facet=${facet:-$SINGLEAGT}
347 local mountpoint="${mountpoint:-${MOUNT2:-$MOUNT}}"
348 local hsm_root="$(hsm_root "$facet")"
350 stack_trap "do_facet $facet rm -rf '$hsm_root'" EXIT
351 do_facet $facet mkdir -p "$hsm_root" ||
352 error "mkdir '$hsm_root' failed"
356 local copytool=lhsmtool
360 __${copytool}_${action} "${misc_options[@]}"
361 if [ $? -ne 0 ]; then
366 local host="$(facet_host $facet)"
367 error_msg="Failed to start copytool $facet on '$host'"
370 local src="${misc_options[0]}"
371 local dest="${misc_options[1]}"
372 error_msg="Failed to import '$src' to '$dest'"
375 error_msg="could not rebind file"
379 $fail_on_error && error "$error_msg" || echo "$error_msg"
383 get_copytool_event_log() {
384 local facet=${1:-$SINGLEAGT}
385 local agent=$(facet_active_host $facet)
387 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
388 error "Can't get event log: No monitor directory!"
390 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
391 error "Could not collect event log from $agent"
395 local agents=${1:-$(facet_active_host $SINGLEAGT)}
397 do_nodesv $agents "pkill -STOP -x $HSMTOOL_BASE" || return 0
398 echo "Copytool is suspended on $agents"
401 copytool_continue() {
402 local agents=${1:-$(facet_active_host $SINGLEAGT)}
404 do_nodesv $agents "pkill -CONT -x $HSMTOOL_BASE" || return 0
405 echo "Copytool is continued on $agents"
408 copytool_remove_backend() {
410 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
411 echo "Remove from backend: $fid = $be"
412 do_facet $SINGLEAGT rm -f $be
415 file_creation_failure() {
422 df $MOUNT $MOUNT2 >&2
423 error "Not enough space to create $file with $cmd"
426 error "cannot create $file with $cmd, status=$err"
431 # Creates a file using dd
437 local source=${5:-/dev/zero}
441 if [ -n "$conv" ]; then
445 # Create the directory in case it does not exist
446 mkdir -p "$(dirname "$file")"
447 # Delete the file in case it already exist
450 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
451 path2fid "$file" || error "cannot get FID of '$file'"
454 echo "cannot create file '$file'" >&2;
455 # Let the caller decide what to do on error
460 create_empty_file() {
461 create_file "${1/$DIR/$DIR2}" 1M 0 ||
462 file_creation_failure dd "${1/$DIR/$DIR2}" $?
465 create_small_file() {
466 local source_file=/dev/urandom
469 local conv=${2:-fsync}
471 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
472 file_creation_failure dd "${1/$DIR/$DIR2}" $?
475 create_small_sync_file() {
476 create_small_file "$1" sync
479 create_archive_file() {
480 local file="$(hsm_root)/$1"
482 local source=/dev/urandom
484 # Create the counterpart directory of the archive
485 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
486 error "cannot create archive directory '$(dirname "$file")'"
488 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
489 error "cannot create archive file '$file'"
493 local hsm_root="$(hsm_root)"
494 local file="$hsm_root/$2"
496 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
497 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
498 error "mkdir '$(dirname "$file")' failed"
499 do_facet $SINGLEAGT cp -p "$1" "$file" ||
500 error "cannot copy '$1' to '$file'"
509 if [[ "$value" != "" ]]; then
512 for mdtno in $(seq 1 $MDSCOUNT); do
513 local idx=$(($mdtno - 1))
514 local facet=mds${mdtno}
515 # if $arg include -P option, run 1 set_param per MDT on the MGS
516 # else, run set_param on each MDT
517 [[ $arg = *"-P"* ]] && facet=mgs
518 do_facet $facet $LCTL set_param $arg mdt.${MDT[$idx]}.$key$value
519 [[ $? != 0 ]] && rc=1
529 for mdtno in $(seq 1 $MDSCOUNT); do
530 local idx=$(($mdtno - 1))
531 wait_result mds${mdtno} \
532 "$LCTL get_param -n $MDT_PREFIX${idx}.$key" "$target" \
534 error "$key state is not '$target' on mds${mdtno}"
540 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
548 mdts_set_param "$opt -n" "hsm.$param" "$value"
555 mdts_set_param "" hsm_control "$cmd"
556 mdts_check_param hsm_control "$target" 10
559 cdt_set_sanity_policy() {
560 if [[ "$CDT_POLICY_HAD_CHANGED" ]]
563 mdts_set_param "" hsm.policy "+NRA"
564 mdts_set_param "" hsm.policy "-NBR"
565 CDT_POLICY_HAD_CHANGED=
570 mdts_set_param "" hsm.policy "+NRA"
571 CDT_POLICY_HAD_CHANGED=true
574 cdt_clear_no_retry() {
575 mdts_set_param "" hsm.policy "-NRA"
576 CDT_POLICY_HAD_CHANGED=true
579 cdt_set_non_blocking_restore() {
580 mdts_set_param "" hsm.policy "+NBR"
581 CDT_POLICY_HAD_CHANGED=true
584 cdt_clear_non_blocking_restore() {
585 mdts_set_param "" hsm.policy "-NBR"
586 CDT_POLICY_HAD_CHANGED=true
589 cdt_clear_mount_state() {
590 mdts_set_param "-P -d" hsm_control ""
593 cdt_set_mount_state() {
594 mdts_set_param "-P" hsm_control "$1"
595 # set_param -P is asynchronous operation and could race with set_param.
596 # In such case configs could be retrieved and applied at mgc after
597 # set_param -P completion. Sleep here to avoid race with set_param.
598 # We need at least 20 seconds. 10 for mgc_requeue_thread to wake up
599 # MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC(5 + 5)
600 # and 10 seconds to retrieve config from server.
605 mdts_check_param hsm_control "$1" 20
609 set_test_state disabled disabled
613 set_test_state enabled enabled
617 set_test_state shutdown stopped
621 set_test_state purge enabled
627 cdt_set_sanity_policy
631 local client_count=$1
632 if [[ $CLIENTCOUNT -lt $client_count ]]; then
633 skip "Need $client_count or more clients, have $CLIENTCOUNT"
640 $LFS path2fid $1 | tr -d '[]'
641 return ${PIPESTATUS[0]}
649 if [[ $u == "user" ]]; then
650 st=$($RUNAS $LFS hsm_state $f)
653 st=$($LFS hsm_state $f)
656 [[ $? == 0 ]] || error "$LFS hsm_state $f failed (run as $u)"
658 st=$(echo $st | cut -f 2 -d" " | tr -d "()," )
662 get_hsm_archive_id() {
665 st=$($LFS hsm_state $f)
666 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
668 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
676 local st=$(get_hsm_flags $f)
677 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
680 check_hsm_flags_user() {
684 local st=$(get_hsm_flags $f user)
685 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
697 if [[ "$3" != 1 ]]; then
701 cp $1 $f || file_creation_failure cp $f $?
703 path2fid $f || error "cannot get fid on $f"
706 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
708 # Note that this might lead to surprising behaviours such as deleting an
709 # important file for the currently running test
710 delete_large_files() {
711 printf "Deleting large files...\n" >&2
712 find $MOUNT -size +10M -delete
713 wait_delete_completed
716 make_custom_file_for_progress() {
717 local count=${2:-"39"}
718 local bs=$($LCTL get_param -n lov.*-clilov-*.stripesize | head -n1)
721 [[ $count -gt 0 ]] || error "Invalid file size"
722 [[ $bs -gt 0 ]] || error "Invalid stripe size"
724 if ! create_file "${1/$DIR/$DIR2}" $bs $count fsync; then
725 echo "The creation of '${1/$DIR/$DIR2}' failed" >&2
726 echo "It might be due to a lack of space in the filesystem" >&2
727 delete_large_files >&2
728 create_file "${1/$DIR/$DIR2}" $bs $count fsync ||
729 file_creation_failure dd "${1/$DIR/$DIR2}" $?
736 wait_update --verbose $(facet_active_host $facet) "$@"
739 wait_request_state() {
743 # 4th arg (mdt index) is optional
745 local mds=mds$(($mdtidx + 1))
747 local cmd="$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.actions"
748 cmd+=" | awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
750 wait_result $mds "$cmd" $state 200 ||
751 error "request on $fid is not $state on $mds"
754 get_request_state() {
758 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
759 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
762 get_request_count() {
766 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
767 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
770 # Ensure the number of HSM request for a given FID is correct
771 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
772 assert_request_count() {
773 local request_count=$(get_request_count $1 $2)
774 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
776 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
783 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
784 [[ -n $fid ]] && cmd+=" | grep '$fid'"
785 cmd+=" | egrep 'WAITING|STARTED'"
787 wait_result $SINGLEMDS "$cmd" "" $timeout ||
788 error "requests did not complete"
791 wait_for_grace_delay() {
792 local val=$(get_hsm_param grace_delay)
796 wait_for_loop_period() {
797 local val=$(get_hsm_param loop_period)
804 # python2.6 in EL6 includes an internal json module
805 local json_parser='import json; import fileinput;'
806 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
807 json_parser+='json.loads([line for line in '
808 json_parser+='fileinput.input()][0]).items()])'
810 echo $raw_event | python -c "$json_parser"
813 get_agent_by_uuid_mdt() {
816 local mds=mds$(($mdtidx + 1))
817 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
821 check_agent_registered_by_mdt() {
824 local mds=mds$(($mdtidx + 1))
825 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
826 if [[ ! -z "$agent" ]]; then
827 echo "found agent $agent on $mds"
829 error "uuid $uuid not found in agent list on $mds"
833 check_agent_unregistered_by_mdt() {
836 local mds=mds$(($mdtidx + 1))
837 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
838 if [[ -z "$agent" ]]; then
839 echo "uuid not found in agent list on $mds"
841 error "uuid found in agent list on $mds: $agent"
845 check_agent_registered() {
848 for mdsno in $(seq 1 $MDSCOUNT); do
849 check_agent_registered_by_mdt $uuid $((mdsno - 1))
853 check_agent_unregistered() {
856 for mdsno in $(seq 1 $MDSCOUNT); do
857 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
862 local agent=${1:-$(facet_active_host $SINGLEAGT)}
864 # Lustre mount-point is mandatory and last parameter on
866 local mntpnt=$(do_rpc_nodes $agent ps -C $HSMTOOL_BASE -o args= |
868 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
870 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
876 # populate MDT device array
879 # cleanup from previous bad setup
882 # for recovery tests, coordinator needs to be started at mount
884 # the lustre conf must be without hsm on (like for sanity.sh)
885 echo "Set HSM on and start"
886 cdt_set_mount_state enabled
887 cdt_check_state enabled
889 echo "Set sanity-hsm HSM policy"
890 cdt_set_sanity_policy
892 # finished requests are quickly removed from list
893 set_hsm_param grace_delay 10
895 CLIENT_NIDS=( $($LCTL list_nids all) )
897 test_1A() { # was test_1
901 local f=$DIR/$tdir/$tfile
905 check_hsm_flags_user $f "0x00000000"
907 $RUNAS $LFS hsm_set --norelease $f ||
908 error "user could not change hsm flags"
909 check_hsm_flags_user $f "0x00000010"
911 $RUNAS $LFS hsm_clear --norelease $f ||
912 error "user could not clear hsm flags"
913 check_hsm_flags_user $f "0x00000000"
915 # User could not change those flags...
916 $RUNAS $LFS hsm_set --exists $f &&
917 error "user should not set this flag"
918 check_hsm_flags_user $f "0x00000000"
921 $LFS hsm_set --exists $f ||
922 error "root could not change hsm flags"
923 check_hsm_flags_user $f "0x00000001"
925 $LFS hsm_clear --exists $f ||
926 error "root could not clear hsm state"
927 check_hsm_flags_user $f "0x00000000"
930 run_test 1A "lfs hsm flags root/non-root access"
933 local f=$DIR/$tdir/$tfile
934 local fid=$(create_small_file $f)
938 $LFS hsm_archive $f || error "could not archive file"
939 wait_request_state $fid ARCHIVE SUCCEED
941 # Release and check states
942 $LFS hsm_release $f || error "could not release file"
943 echo -n "Verifying released state: "
944 check_hsm_flags $f "0x0000000d"
946 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
948 run_test 1a "mmap & cat a HSM released file"
952 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
953 error "failed to set default stripe"
954 local f=$DIR/$tdir/$tfile
957 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
958 error "failed to create file"
959 local fid=$(path2fid $f)
964 $LFS hsm_archive $f || error "could not archive file"
965 wait_request_state $fid ARCHIVE SUCCEED
968 $LFS hsm_release $f || error "could not release file"
969 echo "verify released state: "
970 check_hsm_flags $f "0x0000000d" && echo "pass"
973 $LFS hsm_restore $f || error "could not restore file"
974 wait_request_state $fid RESTORE SUCCEED
975 echo "verify restored state: "
976 check_hsm_flags $f "0x00000009" && echo "pass"
978 run_test 1b "Archive, Release and Restore composite file"
984 local f=$DIR/$tdir/$tfile
987 # Test whether we can set the maximum archive number.
988 local LOCAL_HSM_ARCHIVE_NUMBER=32
989 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
990 error "root could not change hsm flags"
991 check_hsm_flags_user $f "0x00000001"
992 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
993 local st=$(get_hsm_archive_id $f)
994 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
995 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
997 # Test whether setting archive number 0 results in no change.
998 $LFS hsm_set --exists --archive-id 0 $f ||
999 error "root could not change hsm flags"
1000 check_hsm_flags_user $f "0x00000001"
1001 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
1002 st=$(get_hsm_archive_id $f)
1003 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1004 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1006 # Test whether setting archive number > 32 results in error.
1007 $LFS hsm_set --exists --archive-id 33 $f &&
1008 error "archive number is larger than 32"
1009 check_hsm_flags_user $f "0x00000001"
1011 # Test whether setting archive number 16 and archived flag.
1012 LOCAL_HSM_ARCHIVE_NUMBER=16
1013 $LFS hsm_set --exists --archived \
1014 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
1015 error "root could not change hsm flags"
1016 check_hsm_flags_user $f "0x00000009"
1017 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
1018 st=$(get_hsm_archive_id $f)
1019 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
1020 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
1022 run_test 1c "Check setting archive-id in lfs hsm_set"
1026 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
1027 error "failed to set default stripe"
1028 local f=$DIR/$tdir/$tfile
1031 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
1032 error "failed to create file"
1033 local fid=$(path2fid $f)
1038 $LFS hsm_archive $f || error "could not archive file"
1039 wait_request_state $fid ARCHIVE SUCCEED
1042 $LFS hsm_release $f || error "could not release file"
1043 echo "verify released state: "
1044 check_hsm_flags $f "0x0000000d" && echo "pass"
1047 $LFS hsm_restore $f || error "could not restore file"
1048 wait_request_state $fid RESTORE SUCCEED
1049 echo "verify restored state: "
1050 check_hsm_flags $f "0x00000009" && echo "pass"
1052 run_test 1d "Archive, Release and Restore DoM file"
1055 local f=$DIR/$tdir/$tfile
1057 create_empty_file "$f"
1058 # New files are not dirty
1059 check_hsm_flags $f "0x00000000"
1061 # For test, we simulate an archived file.
1062 $LFS hsm_set --exists $f || error "user could not change hsm flags"
1063 check_hsm_flags $f "0x00000001"
1065 # chmod do not put the file dirty
1066 chmod 600 $f || error "could not chmod test file"
1067 check_hsm_flags $f "0x00000001"
1069 # chown do not put the file dirty
1070 chown $RUNAS_ID $f || error "could not chown test file"
1071 check_hsm_flags $f "0x00000001"
1073 # truncate put the file dirty
1074 $TRUNCATE $f 1 || error "could not truncate test file"
1075 check_hsm_flags $f "0x00000003"
1077 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
1078 check_hsm_flags $f "0x00000001"
1080 run_test 2 "Check file dirtyness when doing setattr"
1086 # New files are not dirty
1087 cp -p /etc/passwd $f
1088 check_hsm_flags $f "0x00000000"
1090 # For test, we simulate an archived file.
1091 $LFS hsm_set --exists $f ||
1092 error "user could not change hsm flags"
1093 check_hsm_flags $f "0x00000001"
1095 # Reading a file, does not set dirty
1096 cat $f > /dev/null || error "could not read file"
1097 check_hsm_flags $f "0x00000001"
1099 # Open for write without modifying data, does not set dirty
1100 openfile -f O_WRONLY $f || error "could not open test file"
1101 check_hsm_flags $f "0x00000001"
1103 # Append to a file sets it dirty
1104 cp -p /etc/passwd $f.append || error "could not create file"
1105 $LFS hsm_set --exists $f.append ||
1106 error "user could not change hsm flags"
1107 dd if=/etc/passwd of=$f.append bs=1 count=3\
1108 conv=notrunc oflag=append status=noxfer ||
1109 file_creation_failure dd $f.append $?
1110 check_hsm_flags $f.append "0x00000003"
1112 # Modify a file sets it dirty
1113 cp -p /etc/passwd $f.modify || error "could not create file"
1114 $LFS hsm_set --exists $f.modify ||
1115 error "user could not change hsm flags"
1116 dd if=/dev/zero of=$f.modify bs=1 count=3\
1117 conv=notrunc status=noxfer ||
1118 file_creation_failure dd $f.modify $?
1119 check_hsm_flags $f.modify "0x00000003"
1121 # Open O_TRUNC sets dirty
1122 cp -p /etc/passwd $f.trunc || error "could not create file"
1123 $LFS hsm_set --exists $f.trunc ||
1124 error "user could not change hsm flags"
1125 cp /etc/group $f.trunc || error "could not override a file"
1126 check_hsm_flags $f.trunc "0x00000003"
1128 # Mmapped a file sets dirty
1129 cp -p /etc/passwd $f.mmap || error "could not create file"
1130 $LFS hsm_set --exists $f.mmap ||
1131 error "user could not change hsm flags"
1132 multiop $f.mmap OSMWUc || error "could not mmap a file"
1133 check_hsm_flags $f.mmap "0x00000003"
1135 run_test 3 "Check file dirtyness when opening for write"
1138 local f=$DIR/$tdir/$tfile
1139 local fid=$(create_small_file $f)
1142 local st=$(get_request_state $fid CANCEL)
1143 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
1145 run_test 4 "Useless cancel must not be registered"
1148 # test needs a running copytool
1152 local f=$DIR/$tdir/$tfile
1153 local fid=$(copy_file /etc/passwd $f)
1155 wait_request_state $fid ARCHIVE SUCCEED
1157 check_hsm_flags $f "0x00000009"
1159 run_test 8 "Test default archive number"
1161 test_9A() { # was test_9
1162 # we do not use the default one to be sure
1163 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
1164 copytool setup --archive-id $archive_id
1166 # give time for CT to register with MDTs
1167 sleep $(($MDSCOUNT*2))
1168 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
1169 check_agent_registered $uuid
1172 local f=$DIR/$tdir/$tfile
1173 local fid=$(copy_file /etc/passwd $f)
1174 $LFS hsm_archive --archive $archive_id $f
1175 wait_request_state $fid ARCHIVE SUCCEED
1177 check_hsm_flags $f "0x00000009"
1179 run_test 9A "Use of explicit archive number, with dedicated copytool"
1182 needclients 3 || return 0
1188 # start all of the copytools
1189 for n in $(seq $AGTCOUNT); do
1190 copytool setup --facet agt$n
1194 for n in $(seq $AGTCOUNT); do
1195 file=$DIR/$tdir/$tfile.$n
1196 fid=$(create_small_file $file)
1198 $LFS hsm_archive $file || error "could not archive file $file"
1199 wait_request_state $fid ARCHIVE SUCCEED
1200 check_hsm_flags $file "0x00000009"
1203 run_test 9a "Multiple remote agents"
1206 # test needs a running copytool
1209 mkdir -p $DIR/$tdir/d1
1210 local f=$DIR/$tdir/$tfile
1211 local fid=$(copy_file /etc/hosts $f)
1212 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1213 error "hsm_archive failed"
1214 wait_request_state $fid ARCHIVE SUCCEED
1216 local hsm_root="$(copytool_device $SINGLEAGT)"
1217 local archive="$(do_facet $SINGLEAGT \
1218 find "$hsm_root" -name "$fid" -print0)"
1219 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
1221 echo "Verifying content"
1222 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
1223 echo "Verifying hsm state "
1224 check_hsm_flags $f "0x00000009"
1226 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1227 local st=$(get_hsm_archive_id $f)
1228 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1229 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1231 run_test 10a "Archive a file"
1234 # test needs a running copytool
1238 local f=$DIR/$tdir/$tfile
1239 local fid=$(copy_file /etc/hosts $f)
1240 $LFS hsm_archive $f || error "archive request failed"
1241 wait_request_state $fid ARCHIVE SUCCEED
1243 $LFS hsm_archive $f || error "archive of non dirty file failed"
1244 local cnt=$(get_request_count $fid ARCHIVE)
1245 [[ "$cnt" == "1" ]] ||
1246 error "archive of non dirty file must not make a request"
1248 run_test 10b "Archive of non dirty file must work without doing request"
1251 # test needs a running copytool
1255 local f=$DIR/$tdir/$tfile
1256 local fid=$(copy_file /etc/hosts $f)
1257 $LFS hsm_set --noarchive $f
1258 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1261 run_test 10c "Check forbidden archive"
1264 # test needs a running copytool
1268 local f=$DIR/$tdir/$tfile
1269 local fid=$(copy_file /etc/hosts $f)
1270 $LFS hsm_archive $f || error "cannot archive $f"
1271 wait_request_state $fid ARCHIVE SUCCEED
1273 local ar=$(get_hsm_archive_id $f)
1274 local dflt=$(get_hsm_param default_archive_id)
1275 [[ $ar == $dflt ]] ||
1276 error "archived file is not on default archive: $ar != $dflt"
1278 run_test 10d "Archive a file on the default archive id"
1282 copy2archive /etc/hosts $tdir/$tfile
1283 local f=$DIR/$tdir/$tfile
1285 copytool import $tdir/$tfile $f
1286 echo -n "Verifying released state: "
1287 check_hsm_flags $f "0x0000000d"
1289 local LSZ=$(stat -c "%s" $f)
1290 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1292 echo "Verifying imported size $LSZ=$ASZ"
1293 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1294 echo -n "Verifying released pattern: "
1295 local PTRN=$($GETSTRIPE -L $f)
1297 [[ $PTRN == released ]] || error "Is not released"
1298 local fid=$(path2fid $f)
1299 echo "Verifying new fid $fid in archive"
1301 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1302 error "No archive for fid $fid"
1304 run_test 11a "Import a file"
1307 # test needs a running copytool
1311 local f=$DIR/$tdir/$tfile
1312 local fid=$(copy_file /etc/hosts $f)
1313 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1314 error "hsm_archive failed"
1315 wait_request_state $fid ARCHIVE SUCCEED
1317 local FILE_HASH=$(md5sum $f)
1320 copytool import $fid $f
1322 echo "$FILE_HASH" | md5sum -c
1324 [[ $? -eq 0 ]] || error "Restored file differs"
1326 run_test 11b "Import a deleted file using its FID"
1329 # test needs a running copytool
1333 copy2archive /etc/hosts $tdir/$tfile
1335 local f=$DIR/$tdir/$tfile
1336 copytool import $tdir/$tfile $f
1337 local f2=$DIR2/$tdir/$tfile
1338 echo "Verifying released state: "
1339 check_hsm_flags $f2 "0x0000000d"
1341 local fid=$(path2fid $f2)
1342 $LFS hsm_restore $f2
1343 wait_request_state $fid RESTORE SUCCEED
1345 echo "Verifying file state: "
1346 check_hsm_flags $f2 "0x00000009"
1348 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1350 [[ $? -eq 0 ]] || error "Restored file differs"
1352 run_test 12a "Restore an imported file explicitly"
1355 # test needs a running copytool
1359 copy2archive /etc/hosts $tdir/$tfile
1361 local f=$DIR/$tdir/$tfile
1362 copytool import $tdir/$tfile $f
1363 echo "Verifying released state: "
1364 check_hsm_flags $f "0x0000000d"
1366 cat $f > /dev/null || error "File read failed"
1368 echo "Verifying file state after restore: "
1369 check_hsm_flags $f "0x00000009"
1371 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1373 [[ $? -eq 0 ]] || error "Restored file differs"
1375 run_test 12b "Restore an imported file implicitly"
1378 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1380 # test needs a running copytool
1383 local f=$DIR/$tdir/$tfile
1385 $LFS setstripe -c 2 "$f"
1387 fid=$(make_custom_file_for_progress $f 5)
1388 [ $? != 0 ] && skip "not enough free space" && return
1390 local FILE_CRC=$(md5sum $f)
1392 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1393 wait_request_state $fid ARCHIVE SUCCEED
1394 $LFS hsm_release $f || error "release $f failed"
1396 echo "$FILE_CRC" | md5sum -c
1398 [[ $? -eq 0 ]] || error "Restored file differs"
1400 run_test 12c "Restore a file with stripe of 2"
1403 # test needs a running copytool
1408 local f=$DIR/$tdir/$tfile
1409 local fid=$(copy_file /etc/hosts $f)
1410 $LFS hsm_restore $f || error "restore of non archived file failed"
1411 local cnt=$(get_request_count $fid RESTORE)
1412 [[ "$cnt" == "0" ]] ||
1413 error "restore non archived must not make a request"
1414 $LFS hsm_archive $f ||
1415 error "archive request failed"
1416 wait_request_state $fid ARCHIVE SUCCEED
1417 $LFS hsm_restore $f ||
1418 error "restore of non released file failed"
1419 local cnt=$(get_request_count $fid RESTORE)
1420 [[ "$cnt" == "0" ]] ||
1421 error "restore a non dirty file must not make a request"
1423 run_test 12d "Restore of a non archived, non released file must work"\
1424 " without doing request"
1427 # test needs a running copytool
1431 local f=$DIR/$tdir/$tfile
1432 local fid=$(copy_file /etc/hosts $f)
1433 $LFS hsm_archive $f || error "archive request failed"
1434 wait_request_state $fid ARCHIVE SUCCEED
1437 cat /etc/hosts >> $f
1441 $LFS hsm_restore $f && error "restore a dirty file must fail"
1444 run_test 12e "Check forbidden restore"
1447 # test needs a running copytool
1451 local f=$DIR/$tdir/$tfile
1452 local fid=$(copy_file /etc/hosts $f)
1454 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1455 wait_request_state $fid ARCHIVE SUCCEED
1456 $LFS hsm_release $f || error "release of $f failed"
1458 wait_request_state $fid RESTORE SUCCEED
1460 echo -n "Verifying file state: "
1461 check_hsm_flags $f "0x00000009"
1463 diff -q /etc/hosts $f
1465 [[ $? -eq 0 ]] || error "Restored file differs"
1467 run_test 12f "Restore a released file explicitly"
1470 # test needs a running copytool
1474 local f=$DIR/$tdir/$tfile
1475 local fid=$(copy_file /etc/hosts $f)
1477 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1478 wait_request_state $fid ARCHIVE SUCCEED
1479 $LFS hsm_release $f || error "release of $f failed"
1481 diff -q /etc/hosts $f
1484 # we check we had a restore done
1485 wait_request_state $fid RESTORE SUCCEED
1487 [[ $st -eq 0 ]] || error "Restored file differs"
1489 run_test 12g "Restore a released file implicitly"
1492 needclients 2 || return 0
1494 # test needs a running copytool
1498 local f=$DIR/$tdir/$tfile
1499 local fid=$(copy_file /etc/hosts $f)
1501 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1502 wait_request_state $fid ARCHIVE SUCCEED
1503 $LFS hsm_release $f || error "release of $f failed"
1505 do_node $CLIENT2 diff -q /etc/hosts $f
1508 # we check we had a restore done
1509 wait_request_state $fid RESTORE SUCCEED
1511 [[ $st -eq 0 ]] || error "Restored file differs"
1513 run_test 12h "Restore a released file implicitly from a second node"
1516 # test needs a running copytool
1520 local f=$DIR/$tdir/$tfile
1521 local fid=$(copy_file /etc/passwd $f)
1522 $LFS hsm_archive $f || error "archive of $f failed"
1523 wait_request_state $fid ARCHIVE SUCCEED
1525 $LFS hsm_release $f || error "release of $f failed"
1529 [[ $? -eq 0 ]] || error "Restored file differs"
1531 run_test 12m "Archive/release/implicit restore"
1534 # test needs a running copytool
1538 copy2archive /etc/hosts $tdir/$tfile
1540 local f=$DIR/$tdir/$tfile
1541 copytool import $tdir/$tfile $f
1543 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1544 error "Restored file differs"
1546 $LFS hsm_release $f || error "release of $f failed"
1548 run_test 12n "Import/implicit restore/release"
1551 # test needs a running copytool
1555 local f=$DIR/$tdir/$tfile
1556 local fid=$(copy_file /etc/hosts $f)
1558 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1559 wait_request_state $fid ARCHIVE SUCCEED
1560 $LFS hsm_release $f || error "release of $f failed"
1562 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1563 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1565 # set no retry action mode
1568 diff -q /etc/hosts $f
1571 # we check we had a restore failure
1572 wait_request_state $fid RESTORE FAILED
1574 [[ $st -eq 0 ]] && error "Restore must fail"
1576 # remove no retry action mode
1579 # check file is still released
1580 check_hsm_flags $f "0x0000000d"
1582 # retry w/o failure injection
1583 do_facet $SINGLEMDS lctl set_param fail_loc=0
1585 # to be sure previous RESTORE result is gone
1587 wait_for_grace_delay
1589 diff -q /etc/hosts $f
1592 # we check we had a restore done
1593 wait_request_state $fid RESTORE SUCCEED
1595 [[ $st -eq 0 ]] || error "Restored file differs"
1597 run_test 12o "Layout-swap failure during Restore leaves file released"
1600 # test needs a running copytool
1604 local f=$DIR/$tdir/$tfile
1605 local fid=$(copy_file /etc/hosts $f)
1607 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1608 wait_request_state $fid ARCHIVE SUCCEED
1609 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1610 $LFS hsm_release $f || error "cannot release $f"
1611 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1612 $LFS hsm_release $f || error "cannot release $f"
1613 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1615 run_test 12p "implicit restore of a file on copytool mount point"
1618 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.58) ] &&
1619 skip "need MDS version at least 2.7.58" && return 0
1621 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1622 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1623 error "cannot mount $MOUNT3 on $SINGLEAGT"
1625 # test needs a running copytool
1626 copytool setup -m "$MOUNT3"
1628 local f=$DIR/$tdir/$tfile
1629 local f2=$DIR2/$tdir/$tfile
1630 local fid=$(create_small_file $f)
1631 local orig_size=$(stat -c "%s" $f)
1633 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1634 wait_request_state $fid ARCHIVE SUCCEED
1636 $LFS hsm_release $f || error "could not release file"
1637 check_hsm_flags $f "0x0000000d"
1640 wait_copytools || error "copytool failed to stop"
1642 cat $f > /dev/null &
1644 # wait a bit to allow implicit restore request to be handled.
1645 # if not, next stat would also block on layout-lock.
1648 local size=$(stat -c "%s" $f2)
1649 [ $size -eq $orig_size ] ||
1650 error "$f2: wrong size after archive: $size != $orig_size"
1652 copytool setup -m "$MOUNT3"
1656 size=$(stat -c "%s" $f)
1657 [ $size -eq $orig_size ] ||
1658 error "$f: wrong size after restore: $size != $orig_size"
1660 size=$(stat -c "%s" $f2)
1661 [ $size -eq $orig_size ] ||
1662 error "$f2: wrong size after restore: $size != $orig_size"
1666 size=$(stat -c "%s" $f)
1668 error "$f: wrong size after overwrite: $size != 0"
1670 size=$(stat -c "%s" $f2)
1672 error "$f2: wrong size after overwrite: $size != 0"
1674 run_test 12q "file attributes are refreshed after restore"
1678 for i in {1..10}; do
1679 local archive_dir="$(hsm_root)"/subdir/dir.$i
1681 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1682 for j in {1..10}; do
1683 local archive_file="$archive_dir"/file.$j
1685 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1691 copytool import "subdir" "$DIR/$tdir"
1693 # To check the import, the test uses diff with the -r flag
1694 # This is nice, but diff only checks files one by one, and triggering
1695 # an implicit restore for one file at a time will consume as many
1696 # seconds as there are files to compare. To speed this up, a restore
1697 # operation is triggered manually first.
1699 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1701 # Compare the imported data
1702 do_facet $SINGLEAGT \
1703 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1704 error "imported files differ from archived data"
1706 run_test 13 "Recursively import and restore a directory"
1709 # test needs a running copytool
1713 local f=$DIR/$tdir/$tfile
1714 local fid=$(create_small_file $f)
1715 local sum=$(md5sum $f | awk '{print $1}')
1716 $LFS hsm_archive $f || error "could not archive file"
1717 wait_request_state $fid ARCHIVE SUCCEED
1719 # create released file (simulate llapi_hsm_import call)
1720 local fid2=$(create_empty_file "$f")
1721 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1722 $LFS hsm_release $f || error "could not release file"
1724 # rebind the archive to the newly created file
1725 echo "rebind $fid to $fid2"
1727 copytool rebind $fid $fid2
1729 # restore file and compare md5sum
1730 local sum2=$(md5sum $f | awk '{print $1}')
1732 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1734 run_test 14 "Rebind archived file to a new fid"
1737 # test needs a running copytool
1741 local f=$DIR/$tdir/$tfile
1743 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1747 for i in $(seq 1 $count); do
1748 fids[$i]=$(create_small_file $f.$i)
1749 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1750 $LFS hsm_archive $f.$i || error "could not archive file"
1752 wait_all_done $(($count*60))
1754 stack_trap "rm -f $tmpfile" EXIT
1757 for i in $(seq 1 $count); do
1758 local fid2=$(create_empty_file "${f}.${i}")
1759 # add the rebind operation to the list
1760 echo ${fids[$i]} $fid2 >> $tmpfile
1762 # set it released (simulate llapi_hsm_import call)
1763 $LFS hsm_set --archived --exists $f.$i ||
1764 error "could not force hsm flags"
1765 $LFS hsm_release $f.$i || error "could not release file"
1767 nl=$(wc -l < $tmpfile)
1768 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1770 echo "rebind list of files"
1771 copytool rebind "$tmpfile"
1773 # restore files and compare md5sum
1774 for i in $(seq 1 $count); do
1775 local sum2=$(md5sum $f.$i | awk '{print $1}')
1776 [[ $sum2 == ${sums[$i]} ]] ||
1777 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1780 run_test 15 "Rebind a list of files"
1783 # test needs a running copytool
1787 # create a known size file so we can verify transfer speed
1790 dd if=/dev/zero of=$ref bs=1M count=20
1793 local f=$DIR/$tdir/$tfile
1794 local fid=$(copy_file $ref $f)
1796 local start=$(date +%s)
1798 wait_request_state $fid ARCHIVE SUCCEED
1799 local end=$(date +%s)
1800 # Add 1 to account for rounding errors between start and end (LU-8155)
1801 local duration=$((end - start + 1))
1803 [[ $duration -ge $((goal - 1)) ]] ||
1804 error "Transfer is too fast $duration < $goal"
1806 run_test 16 "Test CT bandwith control option"
1809 local f=$DIR/$tdir/$tfile
1810 create_empty_file "$f"
1812 # Could not release a non-archived file
1813 $LFS hsm_release $f && error "release should not succeed"
1815 # For following tests, we must test them with HS_ARCHIVED set
1816 $LFS hsm_set --exists --archived $f || error "could not add flag"
1818 # Could not release a file if no-release is set
1819 $LFS hsm_set --norelease $f || error "could not add flag"
1820 $LFS hsm_release $f && error "release should not succeed"
1821 $LFS hsm_clear --norelease $f || error "could not remove flag"
1823 # Could not release a file if lost
1824 $LFS hsm_set --lost $f || error "could not add flag"
1825 $LFS hsm_release $f && error "release should not succeed"
1826 $LFS hsm_clear --lost $f || error "could not remove flag"
1828 # Could not release a file if dirty
1829 $LFS hsm_set --dirty $f || error "could not add flag"
1830 $LFS hsm_release $f && error "release should not succeed"
1831 $LFS hsm_clear --dirty $f || error "could not remove flag"
1833 run_test 20 "Release is not permitted"
1836 # test needs a running copytool
1839 local f=$DIR/$tdir/test_release
1841 # Create a file and check its states
1842 local fid=$(create_small_file $f)
1843 check_hsm_flags $f "0x00000000"
1845 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1846 # used until file is flushed to disk
1847 if [ $(facet_fstype ost1) == "zfs" ]; then
1848 # this causes an OST_SYNC rpc to be sent
1849 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1850 # clear locks to reread file data
1851 cancel_lru_locks osc
1854 local orig_size=$(stat -c "%s" $f)
1855 local orig_blocks=$(stat -c "%b" $f)
1857 start_full_debug_logging
1859 $LFS hsm_archive $f || error "could not archive file"
1860 wait_request_state $fid ARCHIVE SUCCEED
1862 local blocks=$(stat -c "%b" $f)
1863 [ $blocks -eq $orig_blocks ] ||
1864 error "$f: wrong block number after archive: " \
1865 "$blocks != $orig_blocks"
1866 local size=$(stat -c "%s" $f)
1867 [ $size -eq $orig_size ] ||
1868 error "$f: wrong size after archive: $size != $orig_size"
1870 # Release and check states
1871 $LFS hsm_release $f || error "could not release file"
1872 check_hsm_flags $f "0x0000000d"
1874 blocks=$(stat -c "%b" $f)
1875 [ $blocks -gt 5 ] &&
1876 error "$f: too many blocks after release: $blocks > 5"
1877 size=$(stat -c "%s" $f)
1878 [ $size -ne $orig_size ] &&
1879 error "$f: wrong size after release: $size != $orig_size"
1881 # Check we can release an file without stripe info
1885 check_hsm_flags $f "0x00000000"
1886 $LFS hsm_archive $f || error "could not archive file"
1887 wait_request_state $fid ARCHIVE SUCCEED
1889 # Release and check states
1890 $LFS hsm_release $f || error "could not release file"
1891 check_hsm_flags $f "0x0000000d"
1893 # Release again a file that is already released is OK
1894 $LFS hsm_release $f || fail "second release should succeed"
1895 check_hsm_flags $f "0x0000000d"
1897 stop_full_debug_logging
1899 run_test 21 "Simple release tests"
1902 # test needs a running copytool
1905 local f=$DIR/$tdir/test_release
1906 local swap=$DIR/$tdir/test_swap
1908 # Create a file and check its states
1909 local fid=$(create_small_file $f)
1910 check_hsm_flags $f "0x00000000"
1912 $LFS hsm_archive $f || error "could not archive file"
1913 wait_request_state $fid ARCHIVE SUCCEED
1915 # Release and check states
1916 $LFS hsm_release $f || error "could not release file"
1917 check_hsm_flags $f "0x0000000d"
1919 create_small_file $swap
1920 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1924 run_test 22 "Could not swap a release file"
1927 # test needs a running copytool
1930 local f=$DIR/$tdir/test_mtime
1932 # Create a file and check its states
1933 local fid=$(create_small_file $f)
1934 check_hsm_flags $f "0x00000000"
1936 $LFS hsm_archive $f || error "could not archive file"
1937 wait_request_state $fid ARCHIVE SUCCEED
1939 # Set modification time in the past
1940 touch -m -a -d @978261179 $f
1942 # Release and check states
1943 $LFS hsm_release $f || error "could not release file"
1944 check_hsm_flags $f "0x0000000d"
1946 local MTIME=$(stat -c "%Y" $f)
1947 local ATIME=$(stat -c "%X" $f)
1948 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1949 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1951 run_test 23 "Release does not change a/mtime (utime)"
1954 local file=$DIR/$tdir/$tfile
1963 # test needs a running copytool
1966 fid=$(create_small_file $file)
1968 # Create a file and check its states
1969 check_hsm_flags $file "0x00000000"
1971 # Ensure atime is less than mtime and ctime.
1975 atime0=$(stat -c "%X" $file)
1976 mtime0=$(stat -c "%Y" $file)
1977 ctime0=$(stat -c "%Z" $file)
1979 [ $atime0 -lt $mtime0 ] ||
1980 error "atime $atime0 is not less than mtime $mtime0"
1982 [ $atime0 -lt $ctime0 ] ||
1983 error "atime $atime0 is not less than ctime $ctime0"
1985 # Archive should not change any timestamps.
1986 $LFS hsm_archive $file || error "cannot archive '$file'"
1987 wait_request_state $fid ARCHIVE SUCCEED
1989 atime1=$(stat -c "%X" $file)
1990 mtime1=$(stat -c "%Y" $file)
1991 ctime1=$(stat -c "%Z" $file)
1993 [ $atime0 -eq $atime1 ] ||
1994 error "archive changed atime from $atime0 to $atime1"
1996 [ $mtime0 -eq $mtime1 ] ||
1997 error "archive changed mtime from $mtime0 to $mtime1"
1999 [ $ctime0 -eq $ctime1 ] ||
2000 error "archive changed ctime from $ctime0 to $ctime1"
2002 # Release should not change any timestamps.
2003 $LFS hsm_release $file || error "cannot release '$file'"
2004 check_hsm_flags $file "0x0000000d"
2006 atime1=$(stat -c "%X" $file)
2007 mtime1=$(stat -c "%Y" $file)
2008 ctime1=$(stat -c "%Z" $file)
2010 [ $atime0 -eq $atime1 ] ||
2011 error "release changed atime from $atime0 to $atime1"
2013 [ $mtime0 -eq $mtime1 ] ||
2014 error "release changed mtime from $mtime0 to $mtime1"
2016 [ $ctime0 -eq $ctime1 ] ||
2017 error "release changed ctime from $ctime0 to $ctime1"
2019 # Restore should not change any timestamps.
2020 $LFS hsm_restore $file
2021 wait_request_state $fid RESTORE SUCCEED
2023 atime1=$(stat -c "%X" $file)
2024 mtime1=$(stat -c "%Y" $file)
2025 ctime1=$(stat -c "%Z" $file)
2027 [ $atime0 -eq $atime1 ] ||
2028 error "restore changed atime from $atime0 to $atime1"
2030 [ $mtime0 -eq $mtime1 ] ||
2031 error "restore changed mtime from $mtime0 to $mtime1"
2033 [ $ctime0 -eq $ctime1 ] ||
2034 error "restore changed ctime from $ctime0 to $ctime1"
2037 wait_copytools || error "Copytools failed to stop"
2039 # Once more, after unmount and mount.
2040 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
2041 mount_client $MOUNT || error "cannot mount '$MOUNT'"
2043 atime1=$(stat -c "%X" $file)
2044 mtime1=$(stat -c "%Y" $file)
2045 ctime1=$(stat -c "%Z" $file)
2047 [ $atime0 -eq $atime1 ] ||
2048 error "remount changed atime from $atime0 to $atime1"
2050 [ $mtime0 -eq $mtime1 ] ||
2051 error "remount changed mtime from $mtime0 to $mtime1"
2053 [ $ctime0 -eq $ctime1 ] ||
2054 error "remount changed ctime from $ctime0 to $ctime1"
2056 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
2059 local file=$DIR/$tdir/$tfile
2065 # Test needs a running copytool.
2068 # Check that root can do HSM actions on a regular user's file.
2069 fid=$(create_small_file $file)
2070 sum0=$(md5sum $file)
2072 chown $RUNAS_ID:$RUNAS_GID $file ||
2073 error "cannot chown '$file' to '$RUNAS_ID'"
2075 chmod ugo-w $DIR/$tdir ||
2076 error "cannot chmod '$DIR/$tdir'"
2078 $LFS hsm_archive $file
2079 wait_request_state $fid ARCHIVE SUCCEED
2081 $LFS hsm_release $file
2082 check_hsm_flags $file "0x0000000d"
2084 $LFS hsm_restore $file
2085 wait_request_state $fid RESTORE SUCCEED
2087 # Check that ordinary user can get HSM state.
2088 $RUNAS $LFS hsm_state $file ||
2089 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
2091 $LFS hsm_release $file
2092 check_hsm_flags $file "0x0000000d"
2094 # Check that ordinary user can accessed released file.
2095 sum1=$($RUNAS md5sum $file) ||
2096 error "user '$RUNAS_ID' cannot read '$file'"
2098 [ "$sum0" == "$sum1" ] ||
2099 error "md5sum mismatch for '$file'"
2101 run_test 24b "root can archive, release, and restore user files"
2104 local file=$DIR/$tdir/$tfile
2105 local action=archive
2110 # test needs a running copytool
2115 # Save the default masks and check that cleanup_24c will
2116 # restore the request masks correctly.
2117 user_save=$(get_hsm_param user_request_mask)
2118 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
2119 group_save=$(get_hsm_param group_request_mask)
2120 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
2121 other_save=$(get_hsm_param other_request_mask)
2122 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
2124 [ "$user_save" == RESTORE ] ||
2125 error "user_request_mask is '$user_save' expected 'RESTORE'"
2126 [ "$group_save" == RESTORE ] ||
2127 error "group_request_mask is '$group_save' expected 'RESTORE'"
2128 [ "$other_save" == RESTORE ] ||
2129 error "other_request_mask is '$other_save' expected 'RESTORE'"
2132 create_small_file $file
2133 chown $RUNAS_ID:$GROUP $file ||
2134 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
2136 $RUNAS $LFS hsm_$action $file &&
2137 error "$action by user should fail"
2139 set_hsm_param user_request_mask $action
2140 $RUNAS $LFS hsm_$action $file ||
2141 error "$action by user should succeed"
2144 create_small_file $file
2145 chown nobody:$RUNAS_GID $file ||
2146 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
2148 $RUNAS $LFS hsm_$action $file &&
2149 error "$action by group should fail"
2151 set_hsm_param group_request_mask $action
2152 $RUNAS $LFS hsm_$action $file ||
2153 error "$action by group should succeed"
2156 create_small_file $file
2157 chown nobody:$GROUP $file ||
2158 error "cannot chown '$file' to 'nobody:$GROUP'"
2160 $RUNAS $LFS hsm_$action $file &&
2161 error "$action by other should fail"
2163 set_hsm_param other_request_mask $action
2164 $RUNAS $LFS hsm_$action $file ||
2165 error "$action by other should succeed"
2167 run_test 24c "check that user,group,other request masks work"
2170 local file1=$DIR/$tdir/$tfile
2171 local file2=$DIR2/$tdir/$tfile
2175 fid1=$(create_small_file $file1)
2178 $LFS getstripe $file1
2180 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
2181 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
2182 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
2184 copytool setup -m "$MOUNT3"
2186 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
2187 mount -o remount,ro $MOUNT2
2189 do_nodes $(comma_list $(nodes_list)) $LCTL clear
2191 fid2=$(path2fid $file2)
2192 [ "$fid1" == "$fid2" ] ||
2193 error "FID mismatch '$fid1' != '$fid2'"
2195 $LFS hsm_archive $file2 &&
2196 error "archive should fail on read-only mount"
2197 check_hsm_flags $file1 "0x00000000"
2199 $LFS hsm_archive $file1 || error "Fail to archive $file1"
2200 wait_request_state $fid1 ARCHIVE SUCCEED
2202 $LFS hsm_release $file1
2203 $LFS hsm_restore $file2
2204 wait_request_state $fid1 RESTORE SUCCEED
2206 $LFS hsm_release $file1 || error "cannot release '$file1'"
2207 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
2209 $LFS hsm_release $file2 &&
2210 error "release should fail on read-only mount"
2214 run_test 24d "check that read-only mounts are respected"
2219 local f=$DIR/$tdir/$tfile
2222 fid=$(create_small_file $f) || error "cannot create $f"
2223 $LFS hsm_archive $f || error "cannot archive $f"
2224 wait_request_state $fid ARCHIVE SUCCEED
2225 $LFS hsm_release $f || error "cannot release $f"
2226 while ! $LFS hsm_state $f | grep released; do
2230 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2232 run_test 24e "tar succeeds on HSM released files" # LU-6213
2235 # test needs a running copytool
2238 mkdir -p $DIR/$tdir/d1
2239 local f=$DIR/$tdir/$tfile
2240 local fid=$(copy_file /etc/hosts $f)
2243 $LFS hsm_archive $f ||
2244 error "hsm_archive failed"
2245 wait_request_state $fid ARCHIVE SUCCEED
2246 $LFS hsm_release $f || error "cannot release $f"
2247 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2250 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2251 error "Can not recover the tar contents"
2253 echo "Sum0 = $sum0, sum1 = $sum1"
2254 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2256 run_test 24f "root can archive, release, and restore tar files"
2259 # test needs a running copytool
2263 copy2archive /etc/hosts $tdir/$tfile
2265 local f=$DIR/$tdir/$tfile
2267 copytool import $tdir/$tfile $f
2269 $LFS hsm_set --lost $f
2274 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2276 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2277 " (Operation not permitted)"
2280 # test needs a running copytool
2285 local f=$DIR/$tdir/$tfile
2286 local fid=$(copy_file /etc/passwd $f)
2288 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2289 wait_request_state $fid ARCHIVE SUCCEED
2292 $LFS hsm_set --lost $f
2296 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2298 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2299 " (Operation not permitted)"
2301 test_26A() { # was test_26
2302 # test needs a running copytool
2305 local f=$DIR/$tdir/$tfile
2307 fid=$(make_custom_file_for_progress $f 39 1000000)
2308 [ $? != 0 ] && skip "not enough free space" && return
2310 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2311 wait_request_state $fid ARCHIVE SUCCEED
2314 wait_request_state $fid REMOVE SUCCEED
2316 check_hsm_flags $f "0x00000000"
2318 run_test 26A "Remove the archive of a valid file"
2321 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2322 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2324 # test needs a running copytool
2328 local f=$DIR/$tdir/$tfile
2329 local fid=$(copy_file /etc/passwd $f)
2331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2332 wait_request_state $fid ARCHIVE SUCCEED
2334 local f2=$DIR/$tdir/${tfile}_2
2335 local fid2=$(copy_file /etc/passwd $f2)
2337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2338 wait_request_state $fid2 ARCHIVE SUCCEED
2340 local f3=$DIR/$tdir/${tfile}_3
2341 local fid3=$(copy_file /etc/passwd $f3)
2343 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2344 wait_request_state $fid3 ARCHIVE SUCCEED
2346 # set a long grace_delay vs short loop_period
2347 local orig_loop_period=$(get_hsm_param loop_period)
2348 local orig_grace_delay=$(get_hsm_param grace_delay)
2349 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2350 set_hsm_param loop_period 10
2351 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2352 set_hsm_param grace_delay 100
2356 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2357 set_hsm_param remove_archive_on_last_unlink 1
2359 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2364 wait_request_state $fid2 REMOVE SUCCEED
2366 assert_request_count $fid REMOVE 0 \
2367 "Unexpected archived data remove request for $f"
2368 assert_request_count $fid3 REMOVE 0 \
2369 "Unexpected archived data remove request for $f3"
2371 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2374 # test needs a running copytool
2378 local f=$DIR/$tdir/$tfile
2379 local fid=$(copy_file /etc/passwd $f)
2381 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2382 wait_request_state $fid ARCHIVE SUCCEED
2384 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2385 set_hsm_param remove_archive_on_last_unlink 1
2388 cdt_check_state stopped
2392 wait_request_state $fid REMOVE WAITING
2396 # copytool must re-register
2398 wait_copytools || error "copytool failed to stop"
2401 wait_request_state $fid REMOVE SUCCEED
2403 run_test 26b "RAoLU policy when CDT off"
2406 # test needs a running copytool
2410 local f=$DIR/$tdir/$tfile
2411 local fid=$(copy_file /etc/passwd $f)
2413 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2414 wait_request_state $fid ARCHIVE SUCCEED
2416 local f2=$DIR/$tdir/${tfile}_2
2417 local fid2=$(copy_file /etc/passwd $f2)
2419 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2420 wait_request_state $fid2 ARCHIVE SUCCEED
2422 # set a long grace_delay vs short loop_period
2423 local orig_loop_period=$(get_hsm_param loop_period)
2424 local orig_grace_delay=$(get_hsm_param grace_delay)
2425 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2426 set_hsm_param loop_period 10
2427 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2428 set_hsm_param grace_delay 100
2430 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2431 set_hsm_param remove_archive_on_last_unlink 1
2433 multiop_bg_pause $f O_c || error "open $f failed"
2439 wait_request_state $fid2 REMOVE SUCCEED
2440 assert_request_count $fid REMOVE 0 \
2441 "Unexpected archived data remove request for $f"
2443 kill -USR1 $pid || error "multiop early exit"
2444 # should reach autotest timeout if multiop fails to trap
2445 # signal, close file, and exit ...
2446 wait $pid || error "wait PID $PID failed"
2448 wait_request_state $fid REMOVE SUCCEED
2450 run_test 26c "RAoLU effective when file closed"
2453 # test needs a running copytool
2457 local f=$DIR/$tdir/$tfile
2458 local fid=$(create_small_file $f)
2460 $LFS hsm_archive $f || error "could not archive file"
2461 wait_request_state $fid ARCHIVE SUCCEED
2463 # set a long grace_delay vs short loop_period
2464 local orig_loop_period=$(get_hsm_param loop_period)
2465 local orig_grace_delay=$(get_hsm_param grace_delay)
2466 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2467 set_hsm_param loop_period 10
2468 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2469 set_hsm_param grace_delay 100
2471 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2472 set_hsm_param remove_archive_on_last_unlink 1
2474 multiop_bg_pause $f O_c || error "multiop failed"
2481 wait_request_state $fid REMOVE SUCCEED
2483 client_up || client_up || true
2485 kill -USR1 $MULTIPID
2486 wait $MULTIPID || error "multiop close failed"
2488 run_test 26d "RAoLU when Client eviction"
2491 # test needs a running copytool
2494 create_archive_file $tdir/$tfile
2495 local f=$DIR/$tdir/$tfile
2496 copytool import $tdir/$tfile $f
2497 local fid=$(path2fid $f)
2501 [[ $? != 0 ]] || error "Remove of a released file should fail"
2503 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2506 # test needs a running copytool
2509 local f=$DIR/$tdir/$tfile
2511 fid=$(make_custom_file_for_progress $f 39 1000000)
2512 [ $? != 0 ] && skip "not enough free space" && return
2514 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2515 wait_request_state $fid ARCHIVE SUCCEED
2520 [[ $? != 0 ]] || error "Remove of a released file should fail"
2522 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2525 # test needs a running copytool
2528 local f=$DIR/$tdir/$tfile
2530 fid=$(make_custom_file_for_progress $f 39 1000000)
2531 [ $? != 0 ] && skip "not enough free space" && return
2533 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2534 wait_request_state $fid ARCHIVE SUCCEED
2543 wait_request_state $fid REMOVE SUCCEED
2545 run_test 28 "Concurrent archive/file remove"
2548 # Tests --mntpath and --archive options
2551 copytool setup -m "$MOUNT" -a $archive_id
2553 # Bad archive number
2554 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2555 grep "Invalid argument" ||
2556 error "unexpected hsm_remove failure (1)"
2558 # mntpath is present but file is given
2559 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2560 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2561 error "unexpected hsm_remove failure (2)"
2563 run_test 29a "Tests --mntpath and --archive options"
2566 # test needs a running copytool
2569 local f=$DIR/$tdir/$tfile
2570 local fid=$(create_small_file $f)
2572 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2573 wait_request_state $fid ARCHIVE SUCCEED
2577 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2578 wait_request_state $fid REMOVE SUCCEED
2580 run_test 29b "Archive/delete/remove by FID from the archive."
2583 # test needs a running copytool
2586 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2587 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2588 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2590 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2591 wait_request_state $fid1 ARCHIVE SUCCEED
2592 wait_request_state $fid2 ARCHIVE SUCCEED
2593 wait_request_state $fid3 ARCHIVE SUCCEED
2595 rm -f $DIR/$tdir/$tfile-[1-3]
2597 echo $fid1 > $DIR/$tdir/list
2598 echo $fid2 >> $DIR/$tdir/list
2599 echo $fid3 >> $DIR/$tdir/list
2601 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2602 --filelist $DIR/$tdir/list
2603 wait_request_state $fid1 REMOVE SUCCEED
2604 wait_request_state $fid2 REMOVE SUCCEED
2605 wait_request_state $fid3 REMOVE SUCCEED
2607 run_test 29c "Archive/delete/remove by FID, using a file list."
2610 # test needs more than one CT
2611 needclients 3 || return 0
2617 # start all of the copytools
2618 for n in $(seq $AGTCOUNT); do
2619 copytool setup -f agt$n -a $n
2623 file=$DIR/$tdir/$tfile
2624 fid=$(create_small_file $file)
2626 $LFS hsm_archive $file
2627 wait_request_state $fid ARCHIVE SUCCEED
2628 check_hsm_flags $file "0x00000009"
2632 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2633 error "cannot hsm_remove '$fid'"
2635 # give time for CDT to handle remove request and create broadcasted
2638 # remove request has been broadcasted ?
2639 local cnt=$(get_request_count $fid REMOVE)
2640 # broadcasted requests + original
2641 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2642 error "remove not broadcasted to all CTs"
2644 # give time for CDT and CTs to handle broadcasted
2645 wait_for_loop_period
2647 # each agent serves one different archive_id, so broadcasted
2648 # hsm_remove request should only succeed once and fail at all others
2652 for n in $(seq $AGTCOUNT); do
2653 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2654 $HSM_PARAM.actions | awk \
2655 '/'$fid'.*action=REMOVE archive#='$n'/ \
2656 {print \\\$13}' | cut -f2 -d=")
2657 if [[ "$res" == "SUCCEED" ]]; then
2659 elif [[ "$res" == "FAILED" ]]; then
2664 [[ $scnt -eq 1 ]] ||
2665 error "one and only CT should have removed successfully"
2667 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2668 error "all but one CT should have failed to remove"
2670 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2671 "request to be sent once for each registered archive_id"
2674 # restore at exec cannot work on agent node (because of Linux kernel
2675 # protection of executables)
2676 needclients 2 || return 0
2678 # test needs a running copytool
2682 copy2archive /bin/true $tdir/$tfile
2684 local f=$DIR/$tdir/true
2685 copytool import $tdir/$tfile $f
2687 local fid=$(path2fid $f)
2689 stack_trap "cdt_clear_no_retry" EXIT
2690 # set no retry action mode
2697 [[ $st == 0 ]] || error "Failed to exec a released file"
2699 run_test 30a "Restore at exec (import case)"
2702 # restore at exec cannot work on agent node (because of Linux kernel
2703 # protection of executables)
2704 needclients 2 || return 0
2706 # test needs a running copytool
2710 local f=$DIR/$tdir/true
2711 local fid=$(copy_file /bin/true $f)
2713 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2714 wait_request_state $fid ARCHIVE SUCCEED
2718 stack_trap cdt_clear_no_retry EXIT
2719 # set no retry action mode
2727 [[ $st == 0 ]] || error "Failed to exec a released file"
2729 run_test 30b "Restore at exec (release case)"
2732 needclients 2 || return 0
2734 # test needs a running copytool
2738 local f=$DIR/$tdir/SLEEP
2739 local slp_sum1=$(md5sum /bin/sleep)
2740 local fid=$(copy_file /bin/sleep $f)
2742 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2743 wait_request_state $fid ARCHIVE SUCCEED
2745 check_hsm_flags $f "0x0000000d"
2747 stack_trap cdt_clear_no_retry EXIT
2748 # set no retry action mode
2751 do_node $CLIENT2 "$f 10" &
2755 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2757 [[ $? == 0 ]] || error "Execution failed during run"
2759 if [[ $? != 0 ]]; then
2760 local slp_sum2=$(md5sum /bin/sleep)
2761 # in case sleep file is modified during the test
2762 [[ $slp_sum1 == $slp_sum2 ]] &&
2763 error "Binary overwritten during exec"
2766 check_hsm_flags $f "0x00000009"
2768 run_test 30c "Update during exec of released file must fail"
2770 restore_and_check_size() {
2773 local s=$(stat -c "%s" $f)
2775 local st=$(get_hsm_flags $f)
2779 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2781 n=$(stat -c "%s" $f)
2782 # we echo in both cases to show stat is not hang
2783 if [[ $n != $s ]]; then
2784 echo "size seen is $n != $s"
2787 echo "size seen is right: $n == $s"
2791 st=$(get_hsm_flags $f)
2793 if [[ "$st" = "0x00000009" ]]; then
2796 echo " restore is too long"
2797 wait_request_state $fid RESTORE SUCCEED
2803 # test needs a running copytool
2806 create_archive_file $tdir/$tfile
2807 local f=$DIR/$tdir/$tfile
2808 copytool import $tdir/$tfile $f
2809 local fid=$($LFS path2fid $f)
2812 restore_and_check_size $f $fid
2815 [[ $err -eq 0 ]] || error "File size changed during restore"
2817 run_test 31a "Import a large file and check size during restore"
2821 # test needs a running copytool
2824 local f=$DIR/$tdir/$tfile
2826 fid=$(make_custom_file_for_progress $f 39 1000000)
2827 [ $? != 0 ] && skip "not enough free space" && return
2829 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2830 wait_request_state $fid ARCHIVE SUCCEED
2833 restore_and_check_size $f $fid
2836 [[ $err -eq 0 ]] || error "File size changed during restore"
2838 run_test 31b "Restore a large unaligned file and check size during restore"
2841 # test needs a running copytool
2844 local f=$DIR/$tdir/$tfile
2846 fid=$(make_custom_file_for_progress $f 33 1048576)
2847 [ $? != 0 ] && skip "not enough free space" && return
2849 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2850 wait_request_state $fid ARCHIVE SUCCEED
2853 restore_and_check_size $f $fid
2856 [[ $err -eq 0 ]] || error "File size changed during restore"
2858 run_test 31c "Restore a large aligned file and check size during restore"
2861 # test needs a running copytool
2864 local f=$DIR/$tdir/$tfile
2866 fid=$(make_custom_file_for_progress $f 39 1000000)
2867 [ $? != 0 ] && skip "not enough free space" && return
2869 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2870 wait_request_state $fid ARCHIVE SUCCEED
2873 # to be sure wait_all_done will not be mislead by previous tests
2876 wait_for_grace_delay
2877 # Also raise grace_delay significantly so the Canceled
2878 # Restore action will stay enough long avail.
2879 local old_grace=$(get_hsm_param grace_delay)
2880 stack_trap "set_hsm_param grace_delay $old_grace" EXIT
2881 set_hsm_param grace_delay 100
2883 md5sum $f >/dev/null &
2885 wait_request_state $fid RESTORE STARTED
2890 # Check restore trigger process was killed
2891 local killed=$(ps -o pid,comm hp $pid >/dev/null)
2895 # instead of waiting+checking both Restore and Cancel ops
2896 # sequentially, wait for both to be finished and then check
2898 wait_all_done 100 $fid
2899 local rstate=$(get_request_state $fid RESTORE)
2900 local cstate=$(get_request_state $fid CANCEL)
2902 if [[ "$rstate" == "CANCELED" ]] ; then
2903 [[ "$cstate" == "SUCCEED" ]] ||
2904 error "Restore state is CANCELED and Cancel state " \
2905 "is not SUCCEED but $cstate"
2906 echo "Restore state is CANCELED, Cancel state is SUCCEED"
2907 elif [[ "$rstate" == "SUCCEED" ]] ; then
2908 [[ "$cstate" == "FAILED" ]] ||
2909 error "Restore state is SUCCEED and Cancel state " \
2910 "is not FAILED but $cstate"
2911 echo "Restore state is SUCCEED, Cancel state is FAILED"
2913 error "Restore state is $rstate and Cancel state is $cstate"
2917 error "Cannot kill process waiting for restore ($killed)"
2919 run_test 33 "Kill a restore waiting process"
2922 # test needs a running copytool
2925 local f=$DIR/$tdir/$tfile
2927 fid=$(make_custom_file_for_progress $f 39 1000000)
2928 [ $? != 0 ] && skip "not enough free space" && return
2930 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2931 wait_request_state $fid ARCHIVE SUCCEED
2934 md5sum $f >/dev/null &
2936 wait_request_state $fid RESTORE STARTED
2938 rm $f || error "rm $f failed"
2939 # rm must not block during restore
2940 wait_request_state $fid RESTORE STARTED
2942 wait_request_state $fid RESTORE SUCCEED
2943 # check md5sum pgm finished
2944 local there=$(ps -o pid,comm hp $pid >/dev/null)
2945 [[ -z $there ]] || error "Restore initiator does not exit"
2947 wait $pid || error "Restore initiator failed with $?"
2949 run_test 34 "Remove file during restore"
2952 # test needs a running copytool
2955 local f=$DIR/$tdir/$tfile
2956 local f1=$DIR/$tdir/$tfile-1
2958 fid=$(make_custom_file_for_progress $f 39 1000000)
2959 [ $? != 0 ] && skip "not enough free space" && return
2961 local fid1=$(copy_file /etc/passwd $f1)
2962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2963 wait_request_state $fid ARCHIVE SUCCEED
2966 md5sum $f >/dev/null &
2968 wait_request_state $fid RESTORE STARTED
2970 mv $f1 $f || error "mv $f1 $f failed"
2971 # mv must not block during restore
2972 wait_request_state $fid RESTORE STARTED
2974 wait_request_state $fid RESTORE SUCCEED
2975 # check md5sum pgm finished
2976 local there=$(ps -o pid,comm hp $pid >/dev/null)
2977 [[ -z $there ]] || error "Restore initiator does not exit"
2979 wait $pid || error "Restore initiator failed with $?"
2982 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2984 run_test 35 "Overwrite file during restore"
2987 # test needs a running copytool
2990 local f=$DIR/$tdir/$tfile
2992 fid=$(make_custom_file_for_progress $f 39 1000000)
2993 [ $? != 0 ] && skip "not enough free space" && return
2995 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2996 wait_request_state $fid ARCHIVE SUCCEED
2999 md5sum $f >/dev/null &
3001 wait_request_state $fid RESTORE STARTED
3004 # rm must not block during restore
3005 wait_request_state $fid RESTORE STARTED
3007 wait_request_state $fid RESTORE SUCCEED
3008 # check md5sum pgm finished
3009 local there=$(ps -o pid,comm hp $pid >/dev/null)
3011 error "Restore initiator does not exit"
3013 wait $pid || error "Restore initiator failed with $?"
3015 run_test 36 "Move file during restore"
3018 # LU-5683: check that an archived dirty file can be rearchived.
3021 local f=$DIR/$tdir/$tfile
3024 fid=$(create_small_file $f) || error "cannot create small file"
3026 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3027 wait_request_state $fid ARCHIVE SUCCEED
3028 $LFS hsm_release $f || error "cannot release $f"
3030 # Allow previous archive request to expire from the actions log.
3031 wait_for_grace_delay
3034 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
3036 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3037 wait_request_state $fid ARCHIVE SUCCEED
3039 run_test 37 "re-archive a dirty file"
3046 for n in $(seq 1 $count); do
3047 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
3049 echo "$count archive requests submitted"
3053 local stream_count=4
3054 local file_count=100
3056 local f=$DIR/$tdir/$tfile
3060 local max_requests=$(get_hsm_param max_requests)
3062 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3063 # Increase the number of HSM request that can be performed in
3064 # parallel. With the coordinator running once per second, this
3065 # also limits the number of requests per seconds that can be
3066 # performed, so we pick a decent number. But we also need to keep
3067 # that number low because the copytool has no rate limit and will
3068 # fail some requests if if gets too many at once.
3069 set_hsm_param max_requests 300
3071 for i in $(seq 1 $file_count); do
3072 for p in $(seq 1 $stream_count); do
3073 fid=$(copy_file /etc/hosts $f.$p.$i)
3079 # to be sure wait_all_done will not be mislead by previous tests
3081 wait_for_grace_delay
3083 # start archive streams in background (archive files in parallel)
3084 for p in $(seq 1 $stream_count); do
3085 multi_archive $f.$p $file_count &
3088 echo -n "Wait for all requests being enqueued..."
3093 run_test 40 "Parallel archive requests"
3096 # test needs a running copytool
3100 local f=$DIR/$tdir/$tfile
3101 local fid=$(create_small_file $f)
3103 $LFS hsm_archive $f || error "could not archive file"
3104 wait_request_state $fid ARCHIVE SUCCEED
3105 check_hsm_flags $f "0x00000009"
3107 multiop_bg_pause $f O_c || error "multiop failed"
3111 client_up || client_up || true
3113 kill -USR1 $MULTIPID
3114 wait $MULTIPID || error "multiop close failed"
3116 check_hsm_flags $f "0x0000000b"
3118 run_test 52 "Opened for write file on an evicted client should be set dirty"
3121 # test needs a running copytool
3125 local f=$DIR/$tdir/$tfile
3126 local fid=$(create_small_file $f)
3128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3129 error "could not archive file"
3130 wait_request_state $fid ARCHIVE SUCCEED
3131 check_hsm_flags $f "0x00000009"
3133 multiop_bg_pause $f o_c || error "multiop failed"
3137 client_up || client_up || true
3139 kill -USR1 $MULTIPID
3140 wait $MULTIPID || error "multiop close failed"
3142 check_hsm_flags $f "0x00000009"
3144 run_test 53 "Opened for read file on an evicted client should not be set dirty"
3147 # test needs a running copytool
3150 local f=$DIR/$tdir/$tfile
3151 local fid=$(make_custom_file_for_progress $f 39 1000000)
3153 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3154 error "could not archive file"
3155 wait_request_state $fid ARCHIVE STARTED
3157 check_hsm_flags $f "0x00000001"
3159 stack_trap "cdt_clear_no_retry" EXIT
3160 # Avoid coordinator resending this request as soon it has failed.
3165 wait_request_state $fid ARCHIVE FAILED
3167 check_hsm_flags $f "0x00000003"
3169 run_test 54 "Write during an archive cancels it"
3172 # test needs a running copytool
3175 local f=$DIR/$tdir/$tfile
3176 local fid=$(make_custom_file_for_progress $f 39 1000000)
3178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3179 error "could not archive file"
3180 wait_request_state $fid ARCHIVE STARTED
3182 check_hsm_flags $f "0x00000001"
3184 stack_trap "cdt_clear_no_retry" EXIT
3185 # Avoid coordinator resending this request as soon it has failed.
3188 $TRUNCATE $f 1024 || error "truncate failed"
3190 wait_request_state $fid ARCHIVE FAILED
3192 check_hsm_flags $f "0x00000003"
3194 run_test 55 "Truncate during an archive cancels it"
3197 # test needs a running copytool
3200 local f=$DIR/$tdir/$tfile
3202 fid=$(make_custom_file_for_progress $f 39 1000000)
3203 [ $? != 0 ] && skip "not enough free space" && return
3205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3206 error "could not archive file"
3207 wait_request_state $fid ARCHIVE STARTED
3209 check_hsm_flags $f "0x00000001"
3211 # Change metadata and sync to be sure we are not changing only
3216 wait_request_state $fid ARCHIVE SUCCEED
3218 check_hsm_flags $f "0x00000009"
3220 run_test 56 "Setattr during an archive is ok"
3223 # Need one client for I/O, one for request
3224 needclients 2 || return 0
3226 # test needs a running copytool
3230 local f=$DIR/$tdir/test_archive_remote
3231 # Create a file on a remote node
3232 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
3233 "count=2 conv=fsync"
3236 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
3237 error "hsm_archive failed"
3238 local fid=$(path2fid $f)
3239 wait_request_state $fid ARCHIVE SUCCEED
3241 # Release and implicit restore it
3242 do_node $CLIENT2 "$LFS hsm_release $f" ||
3243 error "hsm_release failed"
3244 do_node $CLIENT2 "md5sum $f" ||
3245 error "hsm_restore failed"
3247 wait_request_state $fid RESTORE SUCCEED
3249 run_test 57 "Archive a file with dirty cache on another node"
3251 truncate_released_file() {
3255 local sz=$(stat -c %s $src_file)
3256 local f=$DIR/$tdir/$tfile
3257 local fid=$(copy_file $1 $f)
3261 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3262 error "could not archive file"
3263 wait_request_state $fid ARCHIVE SUCCEED
3265 $LFS hsm_release $f || error "could not release file"
3267 $TRUNCATE $f $trunc_to || error "truncate failed"
3270 local sz1=$(stat -c %s $f)
3271 [[ $sz1 == $trunc_to ]] ||
3272 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3275 check_hsm_flags $f "0x0000000b"
3277 local state=$(get_request_state $fid RESTORE)
3278 [[ "$state" == "SUCCEED" ]] ||
3279 error "truncate $sz does not trig restore, state = $state"
3281 $TRUNCATE $ref $trunc_to
3282 cmp $ref $f || error "file data wrong after truncate"
3288 # test needs a running copytool
3293 local sz=$(stat -c %s /etc/passwd)
3295 echo "truncate up from $sz to $((sz*2))"
3296 truncate_released_file /etc/passwd $((sz*2))
3298 echo "truncate down from $sz to $((sz/2))"
3299 truncate_released_file /etc/passwd $((sz/2))
3301 echo "truncate to 0"
3302 truncate_released_file /etc/passwd 0
3304 run_test 58 "Truncate a released file will trigger restore"
3308 local server_version=$(lustre_version_code $SINGLEMDS)
3309 [[ $server_version -lt $(version_code 2.7.63) ]] &&
3310 skip "Need MDS version at least 2.7.63" && return
3313 $MCREATE $DIR/$tfile || error "mcreate failed"
3314 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3315 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3316 fid=$(path2fid $DIR/$tfile)
3317 wait_request_state $fid ARCHIVE SUCCEED
3318 $LFS hsm_release $DIR/$tfile || error "release failed"
3320 run_test 59 "Release stripeless file with non-zero size"
3323 # This test validates the fix for LU-4512. Ensure that the -u
3324 # option changes the progress reporting interval from the
3325 # default (30 seconds) to the user-specified interval.
3327 local progress_timeout=$((interval * 4))
3329 copytool setup -b 1 --update-interval $interval
3331 local f=$DIR/$tdir/$tfile
3333 fid=$(make_custom_file_for_progress $f 10)
3334 [ $? != 0 ] && skip "not enough free space" && return
3337 local mdt=${MDT_PREFIX}${mdtidx}
3338 local mds=mds$((mdtidx + 1))
3340 # Wait for copytool to register
3341 wait_update_facet $mds \
3342 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3343 uuid 100 || error "coyptool failed to register with $mdt"
3345 local start_at=$(date +%s)
3346 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3347 error "could not archive file"
3349 local agent=$(facet_active_host $SINGLEAGT)
3350 local logfile=$(copytool_logfile $SINGLEAGT)
3352 wait_update $agent \
3353 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3354 error "copytool failed to start"
3356 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3357 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3363 echo -n "Expecting a progress update within $progress_timeout seconds... "
3365 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3366 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3367 echo "$RESULT bytes copied in $WAIT seconds."
3369 elif [ $WAIT -ge $progress_timeout ]; then
3370 error "Timed out waiting for progress update!"
3373 WAIT=$((WAIT + sleep))
3377 local finish_at=$(date +%s)
3378 local elapsed=$((finish_at - start_at))
3380 # Ensure that the progress update occurred within the expected window.
3381 if [ $elapsed -lt $((interval - 1)) ]; then
3382 error "Expected progress update after at least $interval seconds"
3385 echo "Wait for on going archive hsm action to complete"
3386 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3387 echo "File archiving not completed even after 10 secs"
3389 run_test 60 "Changing progress update interval from default"
3392 # test needs a running copytool
3396 local f=$DIR/$tdir/$tfile
3397 local fid=$(copy_file /etc/passwd $f)
3399 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3402 wait_request_state $fid ARCHIVE FAILED
3404 run_test 61 "Waiting archive of a removed file should fail"
3407 # test needs a new running copytool
3408 stack_trap copytool_monitor_cleanup EXIT
3409 copytool_monitor_setup
3410 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3412 # Wait for the copytool to register.
3413 wait_update --verbose $(facet_active_host mds1) \
3414 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3416 error "copytool failed to register with MDT0000"
3419 wait_copytools || error "Copytools failed to stop"
3421 local REGISTER_EVENT
3422 local UNREGISTER_EVENT
3423 while read event; do
3424 local parsed=$(parse_json_event "$event")
3425 if [ -z "$parsed" ]; then
3426 error "Copytool sent malformed event: $event"
3430 if [ $event_type == "REGISTER" ]; then
3431 REGISTER_EVENT=$event
3432 elif [ $event_type == "UNREGISTER" ]; then
3433 UNREGISTER_EVENT=$event
3435 done < <(echo $"$(get_copytool_event_log)")
3437 if [ -z "$REGISTER_EVENT" ]; then
3438 error "Copytool failed to send register event to FIFO"
3441 if [ -z "$UNREGISTER_EVENT" ]; then
3442 error "Copytool failed to send unregister event to FIFO"
3445 echo "Register/Unregister events look OK."
3447 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3450 # Bump progress interval for livelier events.
3453 # test needs a new running copytool
3454 stack_trap copytool_monitor_cleanup EXIT
3455 copytool_monitor_setup
3456 copytool setup --update-interval $interval --event-fifo \
3457 "$HSMTOOL_MONITOR_DIR/fifo"
3459 stack_trap "cdt_clear_no_retry" EXIT
3460 # Just start and stop the copytool to generate events.
3463 local f=$DIR/$tdir/$tfile
3465 fid=$(make_custom_file_for_progress $f 39 1000000)
3466 [ $? != 0 ] && skip "not enough free space" && return
3468 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3469 error "could not archive file"
3470 wait_request_state $fid ARCHIVE SUCCEED
3472 local expected_fields="event_time data_fid source_fid"
3473 expected_fields+=" total_bytes current_bytes"
3477 while read event; do
3478 # Make sure we're not getting anything from previous events.
3479 for field in $expected_fields; do
3483 local parsed=$(parse_json_event "$event")
3484 if [ -z "$parsed" ]; then
3485 error "Copytool sent malformed event: $event"
3489 if [ $event_type == "ARCHIVE_START" ]; then
3492 elif [ $event_type == "ARCHIVE_FINISH" ]; then
3495 elif [ $event_type != "ARCHIVE_RUNNING" ]; then
3499 # Do some simple checking of the progress update events.
3500 for expected_field in $expected_fields; do
3501 if [ -z ${!expected_field+x} ]; then
3502 error "Missing $expected_field field in event"
3506 if [ $total_bytes -eq 0 ]; then
3507 error "Expected total_bytes to be > 0"
3510 # These should be identical throughout an archive
3512 if [ $source_fid != $data_fid ]; then
3513 error "Expected source_fid to equal data_fid"
3515 done < <(echo $"$(get_copytool_event_log)")
3517 if [ -z "$START_EVENT" ]; then
3518 error "Copytool failed to send archive start event to FIFO"
3521 if [ -z "$FINISH_EVENT" ]; then
3522 error "Copytool failed to send archive finish event to FIFO"
3525 echo "Archive events look OK."
3527 run_test 71 "Copytool logs JSON archive events to FIFO"
3530 # Bump progress interval for livelier events.
3533 # test needs a new running copytool
3534 stack_trap copytool_monitor_cleanup EXIT
3535 copytool_monitor_setup
3536 copytool setup --update-interval $interval --event-fifo \
3537 "$HSMTOOL_MONITOR_DIR/fifo"
3538 local test_file=$HSMTOOL_MONITOR_DIR/file
3540 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3542 do_facet $SINGLEAGT "$cmd" ||
3543 error "cannot create $test_file on $SINGLEAGT"
3544 copy2archive $test_file $tdir/$tfile
3547 local f=$DIR/$tdir/$tfile
3548 copytool import $tdir/$tfile $f
3549 f=$DIR2/$tdir/$tfile
3550 echo "Verifying released state: "
3551 check_hsm_flags $f "0x0000000d"
3553 local fid=$(path2fid $f)
3555 wait_request_state $fid RESTORE SUCCEED
3557 local expected_fields="event_time data_fid source_fid"
3558 expected_fields+=" total_bytes current_bytes"
3562 while read event; do
3563 # Make sure we're not getting anything from previous events.
3564 for field in $expected_fields; do
3568 local parsed=$(parse_json_event "$event")
3569 if [ -z "$parsed" ]; then
3570 error "Copytool sent malformed event: $event"
3574 if [ $event_type == "RESTORE_START" ]; then
3576 if [ $source_fid != $data_fid ]; then
3577 error "source_fid should == data_fid at start"
3580 elif [ $event_type == "RESTORE_FINISH" ]; then
3582 if [ $source_fid != $data_fid ]; then
3583 error "source_fid should == data_fid at finish"
3586 elif [ $event_type != "RESTORE_RUNNING" ]; then
3590 # Do some simple checking of the progress update events.
3591 for expected_field in $expected_fields; do
3592 if [ -z ${!expected_field+x} ]; then
3593 error "Missing $expected_field field in event"
3597 if [ $total_bytes -eq 0 ]; then
3598 error "Expected total_bytes to be > 0"
3601 # When a restore starts out, the data fid is the same as the
3602 # source fid. After the restore has gotten going, we learn
3603 # the new data fid. Once the restore has finished, the source
3604 # fid is set to the new data fid.
3606 # We test this because some monitoring software may depend on
3607 # this behavior. If it changes, then the consumers of these
3608 # events may need to be modified.
3609 if [ $source_fid == $data_fid ]; then
3610 error "source_fid should != data_fid during restore"
3612 done < <(echo $"$(get_copytool_event_log)")
3614 if [ -z "$START_EVENT" ]; then
3615 error "Copytool failed to send restore start event to FIFO"
3618 if [ -z "$FINISH_EVENT" ]; then
3619 error "Copytool failed to send restore finish event to FIFO"
3622 echo "Restore events look OK."
3624 run_test 72 "Copytool logs JSON restore events to FIFO"
3627 file_count=51 # Max number of files constrained by LNET message size
3628 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3629 local f=$DIR/$tdir/$tfile
3630 local FILELIST=/tmp/filelist.txt
3634 for i in $(seq 1 $file_count); do
3635 fid=$(copy_file /etc/hosts $f.$i)
3636 echo $f.$i >> $FILELIST
3640 # to be sure wait_all_done will not be mislead by previous tests
3642 wait_for_grace_delay
3643 $LFS hsm_archive --filelist $FILELIST ||
3644 error "cannot archive a file list"
3646 $LFS hsm_release --filelist $FILELIST ||
3647 error "cannot release a file list"
3648 $LFS hsm_restore --filelist $FILELIST ||
3649 error "cannot restore a file list"
3652 run_test 90 "Archive/restore a file list"
3654 double_verify_reset_hsm_param() {
3656 echo "Testing $HSM_PARAM.$p"
3657 local val=$(get_hsm_param $p)
3659 local val2=$(($val * 2))
3660 set_hsm_param $p $val2
3661 val=$(get_hsm_param $p)
3662 [[ $val == $val2 ]] ||
3663 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3664 echo "Set $p to 0 must failed"
3668 set_hsm_param $p $save
3670 if [[ $rc == 0 ]]; then
3671 error "we must not be able to set $HSM_PARAM.$p to 0"
3676 double_verify_reset_hsm_param loop_period
3677 double_verify_reset_hsm_param grace_delay
3678 double_verify_reset_hsm_param active_request_timeout
3679 double_verify_reset_hsm_param max_requests
3680 double_verify_reset_hsm_param default_archive_id
3682 run_test 100 "Set coordinator /proc tunables"
3689 run_test 102 "Verify coordinator control"
3692 # test needs a running copytool
3699 for i in $(seq 1 20); do
3700 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3702 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3706 echo "Current requests"
3707 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3708 $HSM_PARAM.actions |\
3709 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3711 [[ -z "$res" ]] || error "Some request have not been canceled"
3713 run_test 103 "Purge all requests"
3718 local f=$DIR/$tdir/$tfile
3720 fid=$(make_custom_file_for_progress $f 39 1000000)
3721 [ $? != 0 ] && skip "not enough free space" && return
3723 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3724 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3725 $HSM_PARAM.actions |\
3726 grep $fid | cut -f16 -d=")
3728 [[ "$data1" == "$DATAHEX" ]] ||
3729 error "Data field in records is ($data1) and not ($DATAHEX)"
3734 wait_request_state $fid ARCHIVE SUCCEED
3736 run_test 104 "Copy tool data field"
3739 local max_requests=$(get_hsm_param max_requests)
3743 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3744 set_hsm_param max_requests 300
3747 for i in $(seq -w 1 10); do
3748 cp /etc/passwd $DIR/$tdir/$i
3749 $LFS hsm_archive $DIR/$tdir/$i
3751 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3752 $HSM_PARAM.actions |\
3753 grep WAITING | wc -l")
3757 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3758 $HSM_PARAM.actions |\
3759 grep WAITING | wc -l")
3762 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3763 error "Requests count after shutdown $reqcnt2 != "\
3764 "before shutdown $reqcnt1"
3766 run_test 105 "Restart of coordinator"
3769 # test needs a running copytool
3772 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3774 check_agent_registered $uuid
3776 search_copytools || error "No copytool found"
3779 wait_copytools || error "Copytool failed to stop"
3781 check_agent_unregistered $uuid
3784 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3785 check_agent_registered $uuid
3787 run_test 106 "Copytool register/unregister"
3790 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3792 # test needs a running copytool
3794 # create and archive file
3796 local f1=$DIR/$tdir/$tfile
3797 local fid=$(copy_file /etc/passwd $f1)
3798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3799 wait_request_state $fid ARCHIVE SUCCEED
3800 # shutdown and restart MDS
3802 # check the copytool still gets messages from MDT
3803 local f2=$DIR/$tdir/2
3804 local fid=$(copy_file /etc/passwd $f2)
3805 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3806 # main check of this sanity: this request MUST succeed
3807 wait_request_state $fid ARCHIVE SUCCEED
3809 run_test 107 "Copytool re-register after MDS restart"
3811 policy_set_and_test()
3815 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3816 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3817 [[ "$policy" == "$target" ]] ||
3818 error "Wrong policy after '$change': '$policy' != '$target'"
3822 # to force default policy setting if error
3823 CDT_POLICY_HAD_CHANGED=true
3825 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3826 local default="NonBlockingRestore [NoRetryAction]"
3827 [[ "$policy" == "$default" ]] ||
3828 error "default policy has changed,"\
3829 " '$policy' != '$default' update the test"
3830 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3831 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3832 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3833 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3834 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3835 # useless bacause we know but safer for futur changes to use real value
3836 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3837 echo "Next set_param must failed"
3838 policy_set_and_test "wrong" "$policy"
3841 echo "Back to default policy"
3842 cdt_set_sanity_policy
3844 run_test 109 "Policy display/change"
3847 # test needs a running copytool
3852 copy2archive /etc/passwd $tdir/$tfile
3854 local f=$DIR/$tdir/$tfile
3855 copytool import $tdir/$tfile $f
3856 local fid=$(path2fid $f)
3858 cdt_set_non_blocking_restore
3863 wait_request_state $fid RESTORE SUCCEED
3864 cdt_clear_non_blocking_restore
3868 error "md5sum returns $st != 1, "\
3869 "should also perror ENODATA (No data available)"
3871 run_test 110a "Non blocking restore policy (import case)"
3874 # test needs a running copytool
3878 local f=$DIR/$tdir/$tfile
3879 local fid=$(copy_file /etc/passwd $f)
3880 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3881 wait_request_state $fid ARCHIVE SUCCEED
3884 cdt_set_non_blocking_restore
3889 wait_request_state $fid RESTORE SUCCEED
3890 cdt_clear_non_blocking_restore
3894 error "md5sum returns $st != 1, "\
3895 "should also perror ENODATA (No data available)"
3897 run_test 110b "Non blocking restore policy (release case)"
3900 # test needs a running copytool
3904 copy2archive /etc/passwd $tdir/$tfile
3906 local f=$DIR/$tdir/$tfile
3908 copytool import $tdir/$tfile $f
3909 local fid=$(path2fid $f)
3913 copytool_remove_backend $fid
3916 wait_request_state $fid RESTORE FAILED
3923 [[ $st == 0 ]] || error "Restore does not failed"
3925 run_test 111a "No retry policy (import case), restore will error"\
3926 " (No such file or directory)"
3929 # test needs a running copytool
3933 local f=$DIR/$tdir/$tfile
3934 local fid=$(copy_file /etc/passwd $f)
3935 stack_trap cdt_clear_no_retry EXIT
3937 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3938 wait_request_state $fid ARCHIVE SUCCEED
3941 copytool_remove_backend $fid
3944 wait_request_state $fid RESTORE FAILED
3948 [[ $st == 0 ]] || error "Restore does not failed"
3950 run_test 111b "No retry policy (release case), restore will error"\
3951 " (No such file or directory)"
3954 # test needs a running copytool
3958 local f=$DIR/$tdir/$tfile
3959 local fid=$(copy_file /etc/passwd $f)
3961 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3962 local l=$($LFS hsm_action $f)
3964 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3967 wait_request_state $fid ARCHIVE SUCCEED
3970 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3972 run_test 112 "State of recorded request"
3975 # test needs a running copytool
3978 local f=$DIR/$tdir/$tfile
3980 fid=$(make_custom_file_for_progress $f 103 1048576)
3981 [ $? != 0 ] && skip "not enough free space" && return
3983 # test with cdt on is made in test_221
3985 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3986 # wait archive to register at CDT
3987 wait_request_state $fid ARCHIVE WAITING
3990 wait_request_state $fid ARCHIVE CANCELED
3991 wait_request_state $fid CANCEL SUCCEED
3993 run_test 200 "Register/Cancel archive"
3996 # test needs a running copytool
3999 local f=$DIR/$tdir/$tfile
4000 create_archive_file $tdir/$tfile
4001 copytool import $tdir/$tfile $f
4002 local fid=$(path2fid $f)
4004 # test with cdt on is made in test_222
4007 # wait restore to register at CDT
4008 wait_request_state $fid RESTORE WAITING
4011 wait_request_state $fid RESTORE CANCELED
4012 wait_request_state $fid CANCEL SUCCEED
4014 run_test 201 "Register/Cancel restore"
4017 # test needs a running copytool
4020 local f=$DIR/$tdir/$tfile
4022 fid=$(make_custom_file_for_progress $f 39 1000000)
4023 [ $? != 0 ] && skip "not enough free space" && return
4025 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4026 wait_request_state $fid ARCHIVE SUCCEED
4030 # wait remove to register at CDT
4031 wait_request_state $fid REMOVE WAITING
4034 wait_request_state $fid REMOVE CANCELED
4036 run_test 202 "Register/Cancel remove"
4038 test_220A() { # was test_220
4039 # test needs a running copytool
4044 local f=$DIR/$tdir/$tfile
4045 local fid=$(copy_file /etc/passwd $f)
4049 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4050 wait_request_state $fid ARCHIVE SUCCEED
4052 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
4053 error "The expected changelog was not emitted"
4055 run_test 220A "Changelog for archive"
4058 # test needs a running copytool
4063 local f=$DIR/$tdir/$tfile
4064 local fid=$(copy_file /etc/passwd $f)
4068 # block copytool operations to allow for HSM request to be
4069 # submitted and file be unlinked (CDT will find object removed)
4072 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4074 # wait request to reach CT
4075 wait_request_state $fid ARCHIVE STARTED
4081 wait_request_state $fid ARCHIVE FAILED
4084 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
4085 error "The expected changelog was not emitted"
4087 run_test 220a "Changelog for failed archive"
4090 # test needs a running copytool
4093 local f=$DIR/$tdir/$tfile
4095 fid=$(make_custom_file_for_progress $f 103 1048576)
4096 [ $? != 0 ] && skip "not enough free space" && return
4100 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4101 wait_request_state $fid ARCHIVE STARTED
4103 wait_request_state $fid ARCHIVE CANCELED
4104 wait_request_state $fid CANCEL SUCCEED
4106 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
4107 error "The expected changelog was not emitted"
4109 run_test 221 "Changelog for archive canceled"
4112 # test needs a running copytool
4116 copy2archive /etc/passwd $tdir/$tfile
4118 local f=$DIR/$tdir/$tfile
4119 copytool import $tdir/$tfile $f
4120 local fid=$(path2fid $f)
4125 wait_request_state $fid RESTORE SUCCEED
4127 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4128 error "The expected changelog was not emitted"
4130 run_test 222a "Changelog for explicit restore"
4133 # test needs a running copytool
4137 local f=$DIR/$tdir/$tfile
4138 local fid=$(copy_file /etc/passwd $f)
4141 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4142 wait_request_state $fid ARCHIVE SUCCEED
4147 wait_request_state $fid RESTORE SUCCEED
4149 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
4150 error "The expected changelog was not emitted"
4152 run_test 222b "Changelog for implicit restore"
4155 # test needs a running copytool
4159 copy2archive /etc/passwd $tdir/$tfile
4161 local f=$DIR/$tdir/$tfile
4162 copytool import $tdir/$tfile $f
4163 local fid=$(path2fid $f)
4167 # block copytool operations to allow for HSM request to be
4168 # submitted and file be unlinked (CDT will find object removed)
4173 # wait request to reach CT
4174 wait_request_state $fid RESTORE STARTED
4180 wait_request_state $fid RESTORE FAILED
4183 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4184 error "The expected changelog was not emitted"
4186 run_test 222c "Changelog for failed explicit restore"
4189 # test needs a running copytool
4193 local f=$DIR/$tdir/$tfile
4194 local fid=$(copy_file /etc/passwd $f)
4197 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4198 wait_request_state $fid ARCHIVE SUCCEED
4201 copytool_remove_backend $fid
4204 wait_request_state $fid RESTORE FAILED
4207 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
4208 error "The expected changelog was not emitted"
4210 run_test 222d "Changelog for failed implicit restore"
4213 # test needs a running copytool
4216 local f=$DIR/$tdir/$tfile
4217 create_archive_file $tdir/$tfile
4221 copytool import $tdir/$tfile $f
4222 local fid=$(path2fid $f)
4225 wait_request_state $fid RESTORE STARTED
4227 wait_request_state $fid RESTORE CANCELED
4228 wait_request_state $fid CANCEL SUCCEED
4230 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4231 error "The expected changelog was not emitted"
4233 run_test 223a "Changelog for restore canceled (import case)"
4236 # test needs a running copytool
4239 local f=$DIR/$tdir/$tfile
4241 fid=$(make_custom_file_for_progress $f 39 1000000)
4242 [ $? != 0 ] && skip "not enough free space" && return
4245 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4246 wait_request_state $fid ARCHIVE SUCCEED
4249 wait_request_state $fid RESTORE STARTED
4251 wait_request_state $fid RESTORE CANCELED
4252 wait_request_state $fid CANCEL SUCCEED
4254 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4255 error "The expected changelog was not emitted"
4257 run_test 223b "Changelog for restore canceled (release case)"
4259 test_224A() { # was test_224
4260 # test needs a running copytool
4265 local f=$DIR/$tdir/$tfile
4266 local fid=$(copy_file /etc/passwd $f)
4269 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4270 wait_request_state $fid ARCHIVE SUCCEED
4273 wait_request_state $fid REMOVE SUCCEED
4275 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4276 error "The expected changelog was not emitted"
4278 run_test 224A "Changelog for remove"
4281 # test needs a running copytool
4286 local f=$DIR/$tdir/$tfile
4287 local fid=$(copy_file /etc/passwd $f)
4290 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4291 wait_request_state $fid ARCHIVE SUCCEED
4293 copytool_remove_backend $fid
4295 # block copytool operations to allow for HSM request to be
4296 # submitted and file be unlinked (CDT will find object removed)
4301 # wait for request to reach CT
4302 wait_request_state $fid REMOVE STARTED
4308 wait_request_state $fid REMOVE FAILED
4310 # HE_REMOVE|ENOENT=0x202
4311 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4312 error "The expected changelog was not emitted"
4314 run_test 224a "Changelog for failed remove"
4317 # test is not usable because remove request is too fast
4318 # so it is always finished before cancel can be done ...
4319 echo "Test disabled"
4322 # test needs a running copytool
4325 local f=$DIR/$tdir/$tfile
4327 fid=$(make_custom_file_for_progress $f 39 1000000)
4328 [ $? != 0 ] && skip "not enough free space" && return
4331 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4332 wait_request_state $fid ARCHIVE SUCCEED
4334 # if cdt is on, it can serve too quickly the request
4339 wait_request_state $fid REMOVE CANCELED
4340 wait_request_state $fid CANCEL SUCCEED
4342 changelog_find -type HSM -target-fid $fid -flags 0x27d
4343 error "The expected changelog was not emitted"
4345 run_test 225 "Changelog for remove canceled"
4348 # test needs a running copytool
4353 local f1=$DIR/$tdir/$tfile-1
4354 local f2=$DIR/$tdir/$tfile-2
4355 local f3=$DIR/$tdir/$tfile-3
4356 local fid1=$(copy_file /etc/passwd $f1)
4357 local fid2=$(copy_file /etc/passwd $f2)
4358 copy_file /etc/passwd $f3
4361 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4362 wait_request_state $fid1 ARCHIVE SUCCEED
4364 $LFS hsm_archive $f2
4365 wait_request_state $fid2 ARCHIVE SUCCEED
4367 rm $f1 || error "rm $f1 failed"
4370 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4371 error "The expected changelog was not emitted"
4373 mv $f3 $f2 || error "mv $f3 $f2 failed"
4375 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4376 error "The expected changelog was not emitted"
4378 run_test 226 "changelog for last rm/mv with exiting archive"
4380 # This is just a utility function to clarify what test_227 does
4385 "$LFS" "$action" --$flag "$file" ||
4386 error "Cannot ${action#hsm_} $flag on '$file'"
4388 # Only one changelog should be produced
4389 local entries="$(changelog_find -type HSM -target-fid $fid)"
4390 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4391 error "lfs $action --$flag '$file' produced more than one" \
4394 # Parse the last changelog record
4395 local entry="$(tail -n 1 <<< "$entries")"
4396 eval local -A changelog=$(changelog2array $entry)
4398 # Also check the flags match what is expected
4399 [[ ${changelog[flags]} == $target ]] ||
4400 error "Changelog flag is '${changelog[flags]}', not $target"
4404 local file="$DIR/$tdir/$tfile"
4405 local fid=$(create_empty_file "$file")
4410 for flag in norelease noarchive exists archived lost; do
4411 if [ "$flag" == lost ]; then
4412 # The flag "lost" only works on an archived file
4413 "$LFS" hsm_set --archived "$file"
4417 action="hsm_set" __test_227
4418 action="hsm_clear" __test_227
4421 run_test 227 "changelog when explicit setting of HSM flags"
4424 # test needs a running copytool
4427 local fid=$(create_small_sync_file $DIR/$tfile)
4428 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4429 wait_request_state $fid ARCHIVE SUCCEED
4431 $LFS hsm_release $DIR/$tfile
4432 check_hsm_flags $DIR/$tfile "0x0000000d"
4434 filefrag $DIR/$tfile | grep " 1 extent found" ||
4435 error "filefrag on released file must return only one extent"
4437 # only newer versions of cp detect sparse files by stat/FIEMAP
4439 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4440 error "copying $DIR/$tfile"
4441 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4443 $LFS hsm_release $DIR/$tfile
4444 check_hsm_flags $DIR/$tfile "0x0000000d"
4446 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4448 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4450 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4451 error "comparing untarred $DIR/$tfile"
4453 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4454 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4456 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4459 # test needs a running copytool
4463 local maxrequest=$(get_hsm_param max_requests)
4464 local rqcnt=$(($maxrequest * 3))
4468 for i in $(seq -w 1 $rqcnt); do
4470 dd if=/dev/urandom of=$DIR/$tdir/$i bs=1M count=10 conv=fsync
4472 # we do it in 2 steps, so all requests arrive at the same time
4473 for i in $(seq -w 1 $rqcnt); do
4474 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$i
4479 while [[ $cnt != 0 || $wt != 0 ]]; do
4481 cnt=$(do_facet $SINGLEMDS "$LCTL get_param -n\
4482 $HSM_PARAM.actions |\
4483 grep STARTED | grep -v CANCEL | wc -l")
4484 [[ $cnt -le $maxrequest ]] ||
4485 error "$cnt > $maxrequest too many started requests"
4486 wt=$(do_facet $SINGLEMDS "$LCTL get_param\
4487 $HSM_PARAM.actions |\
4488 grep WAITING | wc -l")
4489 echo "max=$maxrequest started=$cnt waiting=$wt"
4492 run_test 250 "Coordinator max request"
4495 # test needs a running copytool
4498 local f=$DIR/$tdir/$tfile
4500 fid=$(make_custom_file_for_progress $f 103 1048576)
4501 [ $? != 0 ] && skip "not enough free space" && return
4504 # to have a short test
4505 local old_to=$(get_hsm_param active_request_timeout)
4506 set_hsm_param active_request_timeout 4
4507 # to be sure the cdt will wake up frequently so
4508 # it will be able to cancel the "old" request
4509 local old_loop=$(get_hsm_param loop_period)
4510 set_hsm_param loop_period 2
4513 # clear locks to avoid extra delay caused by flush/cancel
4514 # and thus prevent early copytool death to timeout.
4515 cancel_lru_locks osc
4517 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4518 wait_request_state $fid ARCHIVE STARTED
4520 wait_request_state $fid ARCHIVE CANCELED
4522 set_hsm_param active_request_timeout $old_to
4523 set_hsm_param loop_period $old_loop
4525 run_test 251 "Coordinator request timeout"
4529 local f=$DIR/$tdir/$tfile
4530 local fid=$(create_empty_file "$f")
4532 # to have a short test
4533 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4534 set_hsm_param loop_period 1
4539 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4540 wait_request_state $fid ARCHIVE STARTED
4543 stack_trap "set_hsm_param active_request_timeout \
4544 $(get_hsm_param active_request_timeout)" EXIT
4545 set_hsm_param active_request_timeout 1
4547 wait_request_state $fid ARCHIVE CANCELED
4550 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4554 # test needs a running copytool
4558 local f=$DIR/$tdir/$tfile
4560 dd if=/dev/zero of=$f bs=1MB count=10
4561 local fid=$(path2fid $f)
4563 $LFS hsm_archive $f || error "could not archive file"
4564 wait_request_state $fid ARCHIVE SUCCEED
4566 # clear locks to discard inode data
4567 cancel_lru_locks osc
4569 #define OBD_FAIL_MDC_MERGE 0x807
4570 $LCTL set_param fail_loc=0x807
4572 #expect error here, instead of release with wrong size
4575 if ((rc == 0)); then
4576 file_size=$(stat -c '%s' $f)
4577 if ((file_size != 10485760)); then
4578 error "Wrong file size after hsm_release"
4581 echo "could not release file"
4584 run_test 253 "Check for wrong file size after release"
4588 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4589 skip "need MDS version at least 2.10.56" && return
4591 # Check that the counters are initialized to 0
4593 for request_type in archive restore remove; do
4594 count="$(get_hsm_param ${request_type}_count)" ||
4595 error "Reading ${request_type}_count failed with $?"
4597 [ "$count" -eq 0 ] ||
4598 error "Expected ${request_type}_count to be " \
4602 run_test 254a "Request counters are initialized to zero"
4606 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.56) ] &&
4607 skip "need MDS version at least 2.10.56" && return
4609 # The number of request to launch (at least 32)
4610 local request_count=$((RANDOM % 32 + 32))
4611 printf "Will launch %i requests of each type\n" "$request_count"
4613 # Launch a copytool to process requests
4616 # Set hsm.max_requests to allow starting all requests at the same time
4618 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4619 set_hsm_param max_requests "$request_count"
4623 for request_type in archive restore remove; do
4624 printf "Checking %s requests\n" "${request_type}"
4625 # Suspend the copytool to give us time to read the proc files
4628 for ((i = 0; i < $request_count; i++)); do
4629 case $request_type in
4631 create_empty_file "$DIR/$tdir/$tfile-$i" \
4635 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4638 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4641 # Give the coordinator 10 seconds to start every request
4643 while get_hsm_param actions | grep -q WAITING; do
4646 [ $timeout -gt 0 ] ||
4647 error "${request_type^} requests took too " \
4651 count="$(get_hsm_param ${request_type}_count)"
4652 [ "$count" -eq "$request_count" ] ||
4653 error "Expected '$request_count' (!= '$count') " \
4654 "active $request_type requests"
4656 # Let the copytool process the requests
4658 # Give it 10 seconds maximum
4660 while get_hsm_param actions | grep -q STARTED; do
4663 [ $timeout -gt 0 ] ||
4664 error "${request_type^} requests took too " \
4668 count="$(get_hsm_param ${request_type}_count)"
4669 [ "$count" -eq 0 ] ||
4670 error "Expected 0 (!= '$count') " \
4671 "active $request_type requests"
4674 run_test 254b "Request counters are correctly incremented and decremented"
4677 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4679 # the only way to test ondisk conf is to restart MDS ...
4680 echo "Stop coordinator and remove coordinator state at mount"
4683 # clean on disk conf set by default
4684 cdt_clear_mount_state
4685 cdt_check_state stopped
4687 # check cdt still off after umount/remount
4689 cdt_check_state stopped
4691 echo "Set coordinator start at mount, and start coordinator"
4692 cdt_set_mount_state enabled
4695 cdt_check_state enabled
4697 # check cdt still on after umount/remount
4699 cdt_check_state enabled
4701 # we are back to original state (cdt started at mount)
4703 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4706 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4708 local ai=$(get_hsm_param default_archive_id)
4709 local new=$((ai + 1))
4711 set_hsm_param default_archive_id $new -P
4713 local res=$(get_hsm_param default_archive_id)
4716 set_hsm_param default_archive_id "" "-P -d"
4718 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4720 run_test 301 "HSM tunnable are persistent"
4723 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4725 local ai=$(get_hsm_param default_archive_id)
4726 local new=$((ai + 1))
4731 set_hsm_param default_archive_id $new -P
4734 for mdtno in $(seq 1 $MDSCOUNT); do
4739 cdt_check_state enabled
4741 local res=$(get_hsm_param default_archive_id)
4744 set_hsm_param default_archive_id "" "-P -d"
4746 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4748 run_test 302 "HSM tunnable are persistent when CDT is off"
4751 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4757 local dir_mdt0=$DIR/$tdir/mdt0
4758 local dir_mdt1=$DIR/$tdir/mdt1
4760 # create 1 dir per MDT
4761 stack_trap "rm -rf $dir_mdt0" EXIT
4762 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4763 stack_trap "rm -rf $dir_mdt1" EXIT
4764 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4766 # create 1 file in each MDT
4767 local fid1=$(create_small_file $dir_mdt0/$tfile)
4768 local fid2=$(create_small_file $dir_mdt1/$tfile)
4770 # check that hsm request on mdt0 is sent to the right MDS
4771 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4772 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4773 echo "archive successful on mdt0"
4775 # check that hsm request on mdt1 is sent to the right MDS
4776 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4777 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4778 echo "archive successful on mdt1"
4780 run_test 400 "Single request is sent to the right MDT"
4783 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4789 local dir_mdt0=$DIR/$tdir/mdt0
4790 local dir_mdt1=$DIR/$tdir/mdt1
4792 # create 1 dir per MDT
4793 stack_trap "rm -rf $dir_mdt0" EXIT
4794 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4795 stack_trap "rm -rf $dir_mdt1" EXIT
4796 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4798 # create 1 file in each MDT
4799 local fid1=$(create_small_file $dir_mdt0/$tfile)
4800 local fid2=$(create_small_file $dir_mdt1/$tfile)
4802 # check that compound requests are shunt to the rights MDTs
4803 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4804 error "lfs hsm_archive"
4805 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4806 echo "archive successful on mdt0"
4807 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4808 echo "archive successful on mdt1"
4810 run_test 401 "Compound requests split and sent to their respective MDTs"
4812 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4817 local node=$(facet_active_host $facet)
4819 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4820 awk '{print $4}'); do
4821 echo "$3 $mdc on $node"
4822 do_facet $facet "$LCTL --device $mdc $state" || return 1
4827 # deactivate all mdc on agent1
4828 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4830 copytool setup --no-fail
4832 check_agent_unregistered "uuid" # match any agent
4834 # no expected running copytool
4835 search_copytools $agent && error "Copytool start should have failed"
4838 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4840 run_test 402a "Copytool start fails if all MDTs are inactive"
4847 local f=$DIR/$tdir/$tfile
4848 touch $f || error "touch $f failed"
4849 local fid=$(path2fid $f)
4851 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4852 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4853 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4855 # give time for CDT to send request and to keep it for retry
4856 wait_for_loop_period
4858 wait_request_state $fid ARCHIVE WAITING
4860 do_facet $SINGLEAGT lctl set_param fail_loc=0
4862 # request should succeed now
4863 wait_request_state $fid ARCHIVE SUCCEED
4865 run_test 402b "CDT must retry request upon slow start of CT"
4868 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4870 local agent=$(facet_active_host $SINGLEAGT)
4872 # deactivate all mdc for MDT0001
4873 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4876 local uuid=$(get_agent_uuid $agent)
4877 # check the agent is registered on MDT0000, and not on MDT0001
4878 check_agent_registered_by_mdt $uuid 0
4879 check_agent_unregistered_by_mdt $uuid 1
4881 # check running copytool process
4882 search_copytools $agent || error "No running copytools on $agent"
4884 # reactivate all mdc for MDT0001
4885 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4887 # make sure the copytool is now registered to all MDTs
4888 check_agent_registered $uuid
4890 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4893 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4897 # create files on both MDT0000 and MDT0001
4900 local dir_mdt0=$DIR/$tdir/mdt0
4901 stack_trap "rm -rf $dir_mdt0" EXIT
4902 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4904 # create 1 file on mdt0
4905 local fid1=$(create_small_file $dir_mdt0/$tfile)
4907 # deactivate all mdc for MDT0001
4908 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4910 # send an HSM request for files in MDT0000
4911 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4913 # check for completion of files in MDT0000
4914 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4915 echo "archive successful on mdt0"
4917 # reactivate all mdc for MDT0001
4918 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4920 run_test 404 "Inactive MDT does not block requests for active MDTs"
4923 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4929 local striped_dir=$DIR/$tdir/striped_dir
4931 # create striped dir on all of MDTs
4932 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4934 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4935 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4936 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
4937 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
4939 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
4940 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
4941 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
4942 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
4944 # check that compound requests are shunt to the rights MDTs
4945 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
4946 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
4947 error "lfs hsm_archive"
4949 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
4950 echo "archive successful on $fid1"
4951 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
4952 echo "archive successful on $fid2"
4953 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
4954 echo "archive successful on $fid3"
4955 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
4956 echo "archive successful on $fid4"
4958 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
4959 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
4960 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
4961 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
4963 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
4964 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
4965 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
4966 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
4968 run_test 405 "archive and release under striped directory"
4971 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4973 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4974 skip "need MDS version at least 2.7.64" && return 0
4979 fid=$(create_small_file $DIR/$tdir/$tfile)
4984 $LFS hsm_archive $DIR/$tdir/$tfile
4985 wait_request_state "$fid" ARCHIVE SUCCEED
4986 $LFS hsm_release $DIR/$tdir/$tfile
4988 # Should migrate $tdir but not $tfile.
4989 $LFS migrate -m1 $DIR/$tdir &&
4990 error "migrating HSM an archived file should fail"
4992 $LFS hsm_restore $DIR/$tdir/$tfile
4993 wait_request_state "$fid" RESTORE SUCCEED
4995 $LFS hsm_remove $DIR/$tdir/$tfile
4996 wait_request_state "$fid" REMOVE SUCCEED
4998 cat $DIR/$tdir/$tfile > /dev/null ||
4999 error "cannot read $DIR/$tdir/$tfile"
5001 $LFS migrate -m1 $DIR/$tdir ||
5002 error "cannot complete migration after HSM remove"
5004 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5005 if ((mdt_index != 1)); then
5006 error "expected MDT index 1, got $mdt_index"
5009 # Refresh fid after migration.
5010 fid=$(path2fid $DIR/$tdir/$tfile)
5013 $LFS hsm_archive $DIR/$tdir/$tfile
5014 wait_request_state "$fid" ARCHIVE SUCCEED 1
5016 lctl set_param debug=+trace
5017 $LFS hsm_release $DIR/$tdir/$tfile ||
5018 error "cannot release $DIR/$tdir/$tfile"
5020 $LFS hsm_restore $DIR/$tdir/$tfile
5021 wait_request_state "$fid" RESTORE SUCCEED 1
5023 cat $DIR/$tdir/$tfile > /dev/null ||
5024 error "cannot read $DIR/$tdir/$tfile"
5026 run_test 406 "attempting to migrate HSM archived files is safe"
5029 needclients 2 || return 0
5030 # test needs a running copytool
5035 local f=$DIR/$tdir/$tfile
5036 local f2=$DIR2/$tdir/$tfile
5038 fid=$(make_custom_file_for_progress $f 39 1000000)
5039 [ $? != 0 ] && skip "not enough free space" && return
5041 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5042 wait_request_state $fid ARCHIVE SUCCEED
5045 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5046 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5049 # 1st request holds layout lock while appropriate
5050 # RESTORE record is still not added to llog
5054 # after umount hsm_actions->O/x/x log shouldn't have
5055 # double RESTORE records like below
5056 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5057 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5059 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5062 wait_request_state $fid RESTORE SUCCEED
5064 run_test 407 "Check for double RESTORE records in llog"
5068 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
5069 skip "HSM migrate is not supported" && return
5071 test_mkdir -p $DIR/$tdir
5072 llapi_hsm_test -d $DIR/$tdir || error "One llapi HSM test failed"
5074 run_test 500 "various LLAPI HSM tests"
5077 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5078 skip "need MDS version at least 2.10.58" && return 0
5082 local f=$DIR/$tdir/$tfile
5085 # set changelog_mask to ALL
5086 changelog_chmask "ALL"
5088 chmod 777 $DIR/$tdir
5089 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5090 local fid=$(path2fid $f)
5093 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5094 -gid "$RUNAS_GID") ||
5095 error "No matching CREAT entry"
5097 # Parse the changelog
5098 eval local -A changelog=$(changelog2array $entry)
5099 local nid="${changelog[nid]}"
5102 echo "Got NID '$nid'"
5103 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5104 error "nid '$nid' does not match any client NID:" \
5107 run_test 600 "Changelog fields 'u=' and 'nid='"
5110 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5111 skip "need MDS version at least 2.10.58" && return 0
5115 local f=$DIR/$tdir/$tfile
5118 # set changelog_mask to ALL
5119 changelog_chmask "ALL"
5121 touch $f || error "touch $f failed"
5122 local fid=$(path2fid $f)
5125 cat $f || error "cat $f failed"
5127 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5128 error "No matching OPEN entry"
5130 run_test 601 "OPEN Changelog entry"
5133 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5134 skip "need MDS version at least 2.10.58" && return 0
5138 local f=$DIR/$tdir/$tfile
5141 # set changelog_mask to ALL
5142 changelog_chmask "ALL"
5144 touch $f || error "touch $f failed"
5145 local fid=$(path2fid $f)
5148 cat $f || error "cat $f failed"
5150 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5154 echo f > $f || error "write $f failed"
5157 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5159 # remove OPEN from changelog_mask
5160 changelog_chmask "-OPEN"
5164 cat $f || error "cat $f failed"
5167 changelog_find -type CLOSE -target-fid $fid &&
5168 error "There should be no CLOSE entry"
5172 echo f > $f || error "write $f failed"
5175 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5177 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5180 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5181 skip "need MDS version at least 2.10.58" && return 0
5185 local f=$DIR/$tdir/$tfile
5188 # set changelog_mask to ALL
5189 changelog_chmask "ALL"
5191 touch $f || error "touch $f failed"
5192 local fid=$(path2fid $f)
5194 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5197 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5199 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5200 error "No matching GXATR entry"
5202 run_test 603 "GETXATTR Changelog entry"
5205 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5206 skip "need MDS version at least 2.10.58" && return 0
5210 local f=$DIR/$tdir/$tfile
5211 local f2=$DIR2/$tdir/$tfile
5212 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5214 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5215 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5216 do_facet mds1 lctl set_param "$procname=20"
5220 # set changelog_mask to ALL
5221 changelog_chmask "ALL"
5223 touch $f || error "touch $f failed"
5224 local fid=$(path2fid $f)
5230 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5234 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5235 -gid "$RUNAS_GID" -mode "r--") ||
5236 error "No matching NOPEN entry"
5238 # Parse the changelog
5239 eval local -A changelog=$(changelog2array $entry)
5240 local nid="${changelog[nid]}"
5243 echo "Got NID '$nid'"
5244 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5245 error "nid '$nid' does not match any client NID:" \
5250 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5253 changelog_find -type NOPEN -target-fid $fid &&
5254 error "There should be no NOPEN entry"
5256 # Sleep for `changelog_deniednext` seconds
5261 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5264 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5265 -gid "$RUNAS_GID" -mode "r--") ||
5266 error "No matching NOPEN entry"
5268 # Parse the changelog
5269 eval local -A changelog=$(changelog2array $entry)
5270 local nid="${changelog[nid]}"
5273 echo "Got NID '$nid'"
5274 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5275 error "nid '$nid' does not match any client NID:" \
5278 run_test 604 "NOPEN Changelog entry"
5281 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5282 skip "need MDS version at least 2.10.58" && return 0
5286 local f=$DIR/$tdir/$tfile
5287 local f2=$DIR2/$tdir/$tfile
5290 # set changelog_mask to ALL
5291 changelog_chmask "ALL"
5293 touch $f || error "touch $f failed"
5294 local fid=$(path2fid $f)
5298 exec 3<> $f || error "open $f failed"
5302 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5306 exec 4<> $f || error "open $f failed"
5309 changelog_find -type OPEN -target-fid $fid &&
5310 error "There should be no OPEN entry"
5312 exec 4>&- || error "close $f failed"
5315 changelog_find -type CLOSE -target-fid $fid &&
5316 error "There should be no CLOSE entry"
5320 # access in rw, so different access mode should generate entries
5321 cat $f || error "cat $f failed"
5324 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5326 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5330 # same access as first one, should not generate new entries
5331 exec 4<> $f || error "open $f failed"
5334 changelog_find -type OPEN -target-fid $fid &&
5335 error "There should be no OPEN entry"
5337 exec 4>&- || error "close $f failed"
5340 changelog_find -type CLOSE -target-fid $fid &&
5341 error "There should be no CLOSE entry"
5345 # access by different user should generate new entries
5346 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5349 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5351 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5355 exec 3>&- || error "close $f failed"
5358 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5360 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5363 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
5364 skip "need MDS version at least 2.10.58" && return 0
5366 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5367 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5368 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5369 skip_env "missing llog_reader" && return
5370 local fstype=$(facet_fstype mds1)
5374 local f=$DIR/$tdir/$tfile
5377 # set changelog_mask to ALL
5378 changelog_chmask "ALL"
5380 chmod 777 $DIR/$tdir
5381 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5382 local fid=$(path2fid $f)
5383 rm $f || error "rm $f failed"
5385 local mntpt=$(facet_mntpt mds1)
5389 #remount mds1 as ldiskfs or zfs type
5390 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5391 stop mds1 || error "stop mds1 failed"
5392 mount_fstype mds1 || error "remount mds1 failed"
5394 for ((i = 0; i < 1; i++)); do
5395 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5396 local cat_file=$(do_facet mds1 $llog_reader \
5397 $mntpt/changelog_catalog | awk \
5398 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5399 [ -n "$cat_file" ] || error "no catalog file"
5401 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5402 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5403 [ -n "$entry" ] || error "no CREAT entry"
5406 local uidgid=$(echo $entry |
5407 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5408 [ -n "$uidgid" ] || error "uidgid is empty"
5409 echo "Got UID/GID $uidgid"
5410 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5411 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5412 local nid=$(echo $entry |
5413 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5414 [ -n "$nid" ] || error "nid is empty"
5416 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5417 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5419 run_test 606 "llog_reader groks changelog fields"
5422 check_and_cleanup_lustre