3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
12 LUSTRE=${LUSTRE:-$(dirname $0)/..}
13 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_HSM_EXCEPT "
19 # bug number for skipped tests: LU-9795 LU-9795
20 ALWAYS_EXCEPT+=" 13 402b "
21 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24 # Skip tests for PPC that fail frequently
25 if [[ $(uname -m) = ppc64 ]]; then
26 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
27 ALWAYS_EXCEPT+=" 1a 1b 1d 1e 12c 12f "
28 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
29 ALWAYS_EXCEPT+=" 12g 12h 12m 12n 12o 12p "
30 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
31 ALWAYS_EXCEPT+=" 12q 21 22 23 24a 24b "
32 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
33 ALWAYS_EXCEPT+=" 24d 24e 24f 25b 30c 37 "
34 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
35 ALWAYS_EXCEPT+=" 57 58 90 110b 111b 113 "
36 # bug number: LU-12251 LU-12251 LU-12251 LU-12251 LU-12251 LU-12251
37 ALWAYS_EXCEPT+=" 222b 222d 228 260a 260b 260c "
38 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
39 ALWAYS_EXCEPT+=" 220A 220a 221 222a 222c 223a "
40 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
41 ALWAYS_EXCEPT+=" 223b 224A 224a 226 227 600"
42 # bug number: LU-12252 LU-12252 LU-12252 LU-12252 LU-12252 LU-12252
43 ALWAYS_EXCEPT+=" 601 602 603 604 605 "
48 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
50 OPENFILE=${OPENFILE:-openfile}
51 MMAP_CAT=${MMAP_CAT:-mmap_cat}
52 MOUNT_2=${MOUNT_2:-"yes"}
55 # script only handles up to 10 MDTs (because of MDT_PREFIX)
56 [ $MDSCOUNT -gt 9 ] &&
57 error "script cannot handle more than 9 MDTs, please fix"
59 check_and_setup_lustre
61 if [[ $MDS1_VERSION -lt $(version_code 2.4.53) ]]; then
62 skip_env "Need MDS version at least 2.4.53"
65 # $RUNAS_ID may get set incorrectly somewhere else
66 if [[ $UID -eq 0 && $RUNAS_ID -eq 0 ]]; then
67 skip_env "\$RUNAS_ID set to 0, but \$UID is also 0!"
69 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
70 if getent group nobody; then
72 elif getent group nogroup; then
75 error "No generic nobody group"
78 # if there is no CLIENT1 defined, some tests can be ran on localhost
79 CLIENT1=${CLIENT1:-$HOSTNAME}
80 # if CLIENT2 doesn't exist then use CLIENT1 instead
81 # All tests should use CLIENT2 with MOUNT2 only therefore it will work if
83 # Exception is the test which need two separate nodes
84 CLIENT2=${CLIENT2:-$CLIENT1}
87 # In order to test multiple remote HSM agents, a new facet type named "AGT" and
88 # the following associated variables are added:
90 # AGTCOUNT: number of agents
91 # AGTDEV{N}: target HSM mount point (root path of the backend)
92 # agt{N}_HOST: hostname of the agent agt{N}
93 # SINGLEAGT: facet of the single agent
95 # The number of agents is initialized as the number of remote client nodes.
96 # By default, only single copytool is started on a remote client/agent. If there
97 # was no remote client, then the copytool will be started on the local client.
103 export AGTCOUNT=${AGTCOUNT:-$((CLIENTCOUNT - 1))}
104 [[ $AGTCOUNT -gt 0 ]] || AGTCOUNT=1
106 export SHARED_DIRECTORY=${SHARED_DIRECTORY:-$TMP}
107 if [[ $CLIENTCOUNT -gt 1 ]] &&
108 ! check_shared_dir $SHARED_DIRECTORY $CLIENTS; then
109 skip_env "SHARED_DIRECTORY should be accessible"\
110 "on all client nodes"
114 # We used to put the HSM archive in $SHARED_DIRECTORY but that
115 # meant NFS issues could hose sanity-hsm sessions. So now we
117 for n in $(seq $AGTCOUNT); do
118 eval export AGTDEV$n=\$\{AGTDEV$n:-"$TMP/arc$n"\}
119 agent=CLIENT$((n + 1))
120 if [[ -z "${!agent}" ]]; then
121 [[ $CLIENTCOUNT -eq 1 ]] && agent=CLIENT1 ||
124 eval export agt${n}_HOST=\$\{agt${n}_HOST:-${!agent}\}
127 export SINGLEAGT=${SINGLEAGT:-agt1}
129 export HSMTOOL=${HSMTOOL:-"lhsmtool_posix"}
130 export HSMTOOL_VERBOSE=${HSMTOOL_VERBOSE:-""}
131 export HSMTOOL_UPDATE_INTERVAL=${HSMTOOL_UPDATE_INTERVAL:=""}
132 export HSMTOOL_EVENT_FIFO=${HSMTOOL_EVENT_FIFO:=""}
133 export HSMTOOL_TESTDIR
137 # The test only support up to 10 MDTs
138 MDT_PREFIX="mdt.$FSNAME-MDT000"
139 HSM_PARAM="${MDT_PREFIX}0.hsm"
141 # archive is purged at copytool setup
142 HSM_ARCHIVE_PURGE=true
144 # Don't allow copytool error upon start/setup
145 HSMTOOL_NOERROR=false
148 # Get the backend root path for the given agent facet.
151 local dev=AGTDEV$(facet_number $facet)
158 # get MDT device for each mdc
159 for mdtno in $(seq 1 $MDSCOUNT); do
160 local idx=$(($mdtno - 1))
161 MDT[$idx]=$($LCTL get_param -n \
162 mdc.$FSNAME-MDT000${idx}-mdc-*.mds_server_uuid |
163 awk '{gsub(/_UUID/,""); print $1}' | head -n1)
168 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
169 do_nodesv $hosts "libtool execute pgrep -x $HSMTOOL"
173 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
175 echo "Killing existing copytools on $hosts"
176 do_nodesv $hosts "libtool execute killall -q $HSMTOOL" || true
177 copytool_continue "$hosts"
181 local hosts=${1:-$(facet_active_host $SINGLEAGT)}
182 local wait_timeout=200
183 local wait_start=$SECONDS
184 local wait_end=$((wait_start + wait_timeout))
185 local sleep_time=100000 # 0.1 second
187 while ((SECONDS < wait_end)); do
188 if ! search_copytools $hosts; then
189 echo "copytools stopped in $((SECONDS - wait_start))s"
193 echo "copytools still running on $hosts"
195 [ $sleep_time -lt 32000000 ] && # 3.2 seconds
196 sleep_time=$(bc <<< "$sleep_time * 2")
199 # try to dump Copytool's stack
200 do_nodesv $hosts "echo 1 >/proc/sys/kernel/sysrq ; " \
201 "echo t >/proc/sysrq-trigger"
203 echo "copytools failed to stop in ${wait_timeout}s"
208 copytool_monitor_setup() {
209 local facet=${1:-$SINGLEAGT}
210 local agent=$(facet_active_host $facet)
212 local cmd="mktemp --tmpdir=/tmp -d ${TESTSUITE}.${TESTNAME}.XXXX"
213 local test_dir=$(do_node $agent "$cmd") ||
214 error "Failed to create tempdir on $agent"
215 export HSMTOOL_MONITOR_DIR=$test_dir
217 # Create the fifo and a monitor (cat dies when copytool dies)
218 do_node $agent "mkfifo -m 0644 $test_dir/fifo" ||
219 error "failed to create copytool fifo on $agent"
220 cmd="cat $test_dir/fifo > $test_dir/events &"
221 cmd+=" echo \\\$! > $test_dir/monitor_pid"
223 if [[ $PDSH == *Rmrsh* ]]; then
224 # This is required for pdsh -Rmrsh and its handling of remote
226 # Regular ssh and pdsh -Rssh work fine without this
227 # backgrounded subshell nonsense.
228 (do_node $agent "$cmd") &
229 export HSMTOOL_MONITOR_PDSH=$!
231 # Slightly racy, but just making a best-effort to catch obvious
234 ps -p $HSMTOOL_MONITOR_PDSH > /dev/null ||
235 error "Failed to start copytool monitor on $agent"
237 do_node $agent "$cmd"
239 error "Failed to start copytool monitor on $agent"
250 printf "%s" "$(hsm_root)/*/*/*/*/*/*/$fid"
255 get_copytool_event_log() {
256 local facet=${1:-$SINGLEAGT}
257 local agent=$(facet_active_host $facet)
259 [ -z "$HSMTOOL_MONITOR_DIR" ] &&
260 error "Can't get event log: No monitor directory!"
262 do_node $agent "cat $HSMTOOL_MONITOR_DIR/events" ||
263 error "Could not collect event log from $agent"
267 local agents=${1:-$(facet_active_host $SINGLEAGT)}
270 "do_nodesv $agents libtool execute pkill -CONT -x '$HSMTOOL' || true" EXIT
271 do_nodesv $agents "libtool execute pkill -STOP -x $HSMTOOL" || return 0
272 echo "Copytool is suspended on $agents"
275 copytool_continue() {
276 local agents=${1:-$(facet_active_host $SINGLEAGT)}
278 do_nodesv $agents "libtool execute pkill -CONT -x $HSMTOOL" || return 0
279 echo "Copytool is continued on $agents"
282 copytool_remove_backend() {
284 local be=$(do_facet $SINGLEAGT find "$(hsm_root)" -name $fid)
285 echo "Remove from backend: $fid = $be"
286 do_facet $SINGLEAGT rm -f $be
289 file_creation_failure() {
296 df $MOUNT $MOUNT2 >&2
297 error "Not enough space to create $file with $cmd"
300 error "cannot create $file with $cmd, status=$err"
305 # Creates a file using dd
311 local source=${5:-/dev/zero}
315 if [ -n "$conv" ]; then
319 # Create the directory in case it does not exist
320 mkdir -p "$(dirname "$file")"
321 # Delete the file in case it already exist
324 if dd if="$source" of="$file" count="$count" bs="$bs" $args; then
325 path2fid "$file" || error "cannot get FID of '$file'"
328 echo "cannot create file '$file'" >&2;
329 # Let the caller decide what to do on error
334 create_empty_file() {
335 create_file "${1/$DIR/$DIR2}" 1M 0 ||
336 file_creation_failure dd "${1/$DIR/$DIR2}" $?
339 create_small_file() {
340 local source_file=/dev/urandom
343 local conv=${2:-fsync}
345 create_file "${1/$DIR/$DIR2}" $bs $count $conv $source_file ||
346 file_creation_failure dd "${1/$DIR/$DIR2}" $?
349 create_small_sync_file() {
350 create_small_file "$1" sync
353 create_archive_file() {
354 local file="$(hsm_root)/$1"
356 local source=/dev/urandom
358 # Create the counterpart directory of the archive
359 do_facet "$SINGLEAGT" mkdir -p "$(dirname "$file")" ||
360 error "cannot create archive directory '$(dirname "$file")'"
362 do_facet "$SINGLEAGT" dd if=$source of="$file" bs=1M count=$count ||
363 error "cannot create archive file '$file'"
367 local hsm_root="$(hsm_root)"
368 local file="$hsm_root/$2"
370 stack_trap "do_facet $SINGLEAGT rm -rf '$hsm_root'" EXIT
371 do_facet $SINGLEAGT mkdir -p "$(dirname "$file")" ||
372 error "mkdir '$(dirname "$file")' failed"
373 do_facet $SINGLEAGT cp -p "$1" "$file" ||
374 error "cannot copy '$1' to '$file'"
379 local val=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.$param)
386 mdts_set_param "" hsm_control "$cmd"
387 mdts_check_param hsm_control "$target" 10
392 mdts_set_param "" hsm.policy "+NRA"
393 CDT_POLICY_HAD_CHANGED=true
396 cdt_clear_no_retry() {
397 mdts_set_param "" hsm.policy "-NRA"
398 CDT_POLICY_HAD_CHANGED=true
401 cdt_set_non_blocking_restore() {
402 mdts_set_param "" hsm.policy "+NBR"
403 CDT_POLICY_HAD_CHANGED=true
406 cdt_clear_non_blocking_restore() {
407 mdts_set_param "" hsm.policy "-NBR"
408 CDT_POLICY_HAD_CHANGED=true
411 cdt_clear_mount_state() {
412 mdts_set_param "-P -d" hsm_control ""
416 set_test_state disabled disabled
420 set_test_state enabled enabled
424 set_test_state shutdown stopped
428 set_test_state purge enabled
434 cdt_set_sanity_policy
438 get_hsm_archive_id() {
441 st=$($LFS hsm_state $f)
442 [[ $? == 0 ]] || error "$LFS hsm_state $f failed"
444 local ar=$(echo $st | grep -oP '(?<=archive_id:).*')
448 check_hsm_flags_user() {
452 local st=$(get_hsm_flags $f user)
453 [[ $st == $fl ]] || error "hsm flags on $f are $st != $fl"
465 if [[ "$3" != 1 ]]; then
469 cp $1 $f || file_creation_failure cp $f $?
471 path2fid $f || error "cannot get fid on $f"
474 # Delete any file bigger than 10M under $MOUNT and wait for deletes to complete
476 # Note that this might lead to surprising behaviours such as deleting an
477 # important file for the currently running test
478 delete_large_files() {
479 printf "Deleting large files...\n" >&2
480 find $MOUNT -size +10M -delete
481 wait_delete_completed
484 get_request_state() {
488 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
489 "awk '/'$fid'.*action='$request'/ {print \\\$13}' | cut -f2 -d="
492 get_request_count() {
496 do_facet $SINGLEMDS "$LCTL get_param -n $HSM_PARAM.actions |"\
497 "awk -vn=0 '/'$fid'.*action='$request'/ {n++}; END {print n}'"
500 # Ensure the number of HSM request for a given FID is correct
501 # assert_request_count FID REQUEST_TYPE COUNT [ERROR_MSG]
502 assert_request_count() {
503 local request_count=$(get_request_count $1 $2)
504 local default_error_msg=("expected $3 '$2' request(s) for '$1', found "
506 [ $request_count -eq $3 ] || error "${4:-"${default_error_msg[@]}"}"
513 local cmd="$LCTL get_param -n $HSM_PARAM.actions"
514 [[ -n $fid ]] && cmd+=" | grep '$fid'"
515 cmd+=" | egrep 'WAITING|STARTED'"
517 wait_result $SINGLEMDS "$cmd" "" $timeout ||
518 error "requests did not complete"
521 wait_for_grace_delay() {
522 local val=$(get_hsm_param grace_delay)
526 wait_for_loop_period() {
527 local val=$(get_hsm_param loop_period)
534 # python2.6 in EL6 includes an internal json module
535 local json_parser='import json; import fileinput;'
536 json_parser+=' print "\n".join(["local %s=\"%s\"" % tuple for tuple in '
537 json_parser+='json.loads([line for line in '
538 json_parser+='fileinput.input()][0]).items()])'
540 echo $raw_event | python -c "$json_parser"
543 get_agent_by_uuid_mdt() {
546 local mds=mds$(($mdtidx + 1))
547 do_facet $mds "$LCTL get_param -n ${MDT_PREFIX}${mdtidx}.hsm.agents |\
551 check_agent_registered_by_mdt() {
554 local mds=mds$(($mdtidx + 1))
555 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
556 if [[ ! -z "$agent" ]]; then
557 echo "found agent $agent on $mds"
559 error "uuid $uuid not found in agent list on $mds"
563 check_agent_unregistered_by_mdt() {
566 local mds=mds$(($mdtidx + 1))
567 local agent=$(get_agent_by_uuid_mdt $uuid $mdtidx)
568 if [[ -z "$agent" ]]; then
569 echo "uuid not found in agent list on $mds"
571 error "uuid found in agent list on $mds: $agent"
575 check_agent_registered() {
578 for mdsno in $(seq 1 $MDSCOUNT); do
579 check_agent_registered_by_mdt $uuid $((mdsno - 1))
583 check_agent_unregistered() {
586 for mdsno in $(seq 1 $MDSCOUNT); do
587 check_agent_unregistered_by_mdt $uuid $((mdsno - 1))
592 local agent=${1:-$(facet_active_host $SINGLEAGT)}
594 # Lustre mount-point is mandatory and last parameter on
596 local mntpnt=$(do_rpc_nodes $agent libtool execute ps -C $HSMTOOL -o args= |
598 [ -n "$mntpnt" ] || error "Found no Agent or with no mount-point "\
600 do_rpc_nodes $agent get_client_uuid $mntpnt | cut -d' ' -f2
606 # populate MDT device array
609 # cleanup from previous bad setup
612 # for recovery tests, coordinator needs to be started at mount
614 # the lustre conf must be without hsm on (like for sanity.sh)
615 echo "Set HSM on and start"
616 cdt_set_mount_state enabled
617 cdt_check_state enabled
619 echo "Set sanity-hsm HSM policy"
620 cdt_set_sanity_policy
622 # finished requests are quickly removed from list
623 set_hsm_param grace_delay 10
625 CLIENT_NIDS=( $($LCTL list_nids all) )
627 test_1A() { # was test_1
631 local f=$DIR/$tdir/$tfile
635 check_hsm_flags_user $f "0x00000000"
637 $RUNAS $LFS hsm_set --norelease $f ||
638 error "user could not change hsm flags"
639 check_hsm_flags_user $f "0x00000010"
641 $RUNAS $LFS hsm_clear --norelease $f ||
642 error "user could not clear hsm flags"
643 check_hsm_flags_user $f "0x00000000"
645 # User could not change those flags...
646 $RUNAS $LFS hsm_set --exists $f &&
647 error "user should not set this flag"
648 check_hsm_flags_user $f "0x00000000"
651 $LFS hsm_set --exists $f ||
652 error "root could not change hsm flags"
653 check_hsm_flags_user $f "0x00000001"
655 $LFS hsm_clear --exists $f ||
656 error "root could not clear hsm state"
657 check_hsm_flags_user $f "0x00000000"
660 run_test 1A "lfs hsm flags root/non-root access"
663 local f=$DIR/$tdir/$tfile
664 local fid=$(create_small_file $f)
668 $LFS hsm_archive $f || error "could not archive file"
669 wait_request_state $fid ARCHIVE SUCCEED
671 # Release and check states
672 $LFS hsm_release $f || error "could not release file"
673 echo -n "Verifying released state: "
674 check_hsm_flags $f "0x0000000d"
676 $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
678 run_test 1a "mmap & cat a HSM released file"
684 dd if=/dev/urandom of=$f bs=1M count=1 conv=sync ||
685 error "failed to create file"
686 local fid=$(path2fid $f)
691 $LFS hsm_archive $f || error "could not archive file"
692 wait_request_state $fid ARCHIVE SUCCEED
695 $LFS hsm_release $f || error "could not release file"
696 echo "verify released state: "
697 check_hsm_flags $f "0x0000000d" && echo "pass"
700 $LFS hsm_restore $f || error "could not restore file"
701 wait_request_state $fid RESTORE SUCCEED
702 echo "verify restored state: "
703 check_hsm_flags $f "0x00000009" && echo "pass"
708 $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 4 $DIR/$tdir ||
709 error "failed to set default stripe"
710 local f=$DIR/$tdir/$tfile
714 run_test 1b "Archive, Release and Restore composite file"
720 local f=$DIR/$tdir/$tfile
723 # Test whether we can set the maximum archive number.
724 local LOCAL_HSM_ARCHIVE_NUMBER=32
725 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
726 error "root could not change hsm flags"
727 check_hsm_flags_user $f "0x00000001"
728 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
729 local st=$(get_hsm_archive_id $f)
730 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
731 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
733 # Test whether setting archive number 0 results in no change.
734 $LFS hsm_set --exists --archive-id 0 $f ||
735 error "root could not change hsm flags"
736 check_hsm_flags_user $f "0x00000001"
737 echo "verifying archive number is still $LOCAL_HSM_ARCHIVE_NUMBER"
738 st=$(get_hsm_archive_id $f)
739 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
740 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
742 LOCAL_HSM_ARCHIVE_NUMBER=33
743 if [ $(lustre_version_code client) -ge $(version_code 2.11.56) ] &&
744 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.11.56) ]; then
745 # lustre in the new version supports unlimited archiveID.
746 # Test whether setting archive number > 32 is supported
747 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
748 error "archive ID $LOCAL_HSM_ARCHIVE_NUMBER too large?"
749 check_hsm_flags_user $f "0x00000001"
751 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
752 st=$(get_hsm_archive_id $f)
753 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
754 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
756 # old client or old mds can only support at most 32 archiveID
757 # test whether setting archive number > 32 results in error.
758 $LFS hsm_set --exists --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f &&
759 error "bitmap archive number is larger than 32"
760 check_hsm_flags_user $f "0x00000001"
763 # Test whether setting archive number 16 and archived flag.
764 LOCAL_HSM_ARCHIVE_NUMBER=16
765 $LFS hsm_set --exists --archived \
766 --archive-id $LOCAL_HSM_ARCHIVE_NUMBER $f ||
767 error "root could not change hsm flags"
768 check_hsm_flags_user $f "0x00000009"
769 echo "verifying archive number is $LOCAL_HSM_ARCHIVE_NUMBER"
770 st=$(get_hsm_archive_id $f)
771 [[ $st == $LOCAL_HSM_ARCHIVE_NUMBER ]] ||
772 error "wrong archive number, $st != $LOCAL_HSM_ARCHIVE_NUMBER"
774 run_test 1c "Check setting archive-id in lfs hsm_set"
777 [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
778 skip "need MDS version at least 2.10.59"
781 $LFS setstripe -E 1M -L mdt -E -1 -c 2 $DIR/$tdir ||
782 error "failed to set default stripe"
783 local f=$DIR/$tdir/$tfile
787 run_test 1d "Archive, Release and Restore DoM file"
790 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
791 skip "skipped for lustre < $SEL_VER"
794 $LFS setstripe -E 1G -z 64M -E 10G -z 512M -E -1 -z 1G $DIR/$tdir ||
795 error "failed to set default stripe"
796 local comp_file=$DIR/$tdir/$tfile
798 test_1bde_base $comp_file
800 local flg_opts="--comp-start 0 -E 64M --comp-flags init"
801 local found=$($LFS find $flg_opts $comp_file | wc -l)
802 [ $found -eq 1 ] || error "1st component not found"
804 flg_opts="--comp-start 64M -E 1G --comp-flags extension"
805 found=$($LFS find $flg_opts $comp_file | wc -l)
806 [ $found -eq 1 ] || error "2nd component not found"
808 flg_opts="--comp-start 1G -E 1G --comp-flags ^init"
809 found=$($LFS find $flg_opts $comp_file | wc -l)
810 [ $found -eq 1 ] || error "3rd component not found"
812 flg_opts="--comp-start 1G -E 10G --comp-flags extension"
813 found=$($LFS find $flg_opts $comp_file | wc -l)
814 [ $found -eq 1 ] || error "4th component not found"
816 flg_opts="--comp-start 10G -E 10G --comp-flags ^init"
817 found=$($LFS find $flg_opts $comp_file | wc -l)
818 [ $found -eq 1 ] || error "5th component not found"
820 flg_opts="--comp-start 10G -E EOF --comp-flags extension"
821 found=$($LFS find $flg_opts $comp_file | wc -l)
822 [ $found -eq 1 ] || error "6th component not found"
824 sel_layout_sanity $comp_file 6
826 run_test 1e "Archive, Release and Restore SEL file"
829 local f=$DIR/$tdir/$tfile
831 create_empty_file "$f"
832 # New files are not dirty
833 check_hsm_flags $f "0x00000000"
835 # For test, we simulate an archived file.
836 $LFS hsm_set --exists $f || error "user could not change hsm flags"
837 check_hsm_flags $f "0x00000001"
839 # chmod do not put the file dirty
840 chmod 600 $f || error "could not chmod test file"
841 check_hsm_flags $f "0x00000001"
843 # chown do not put the file dirty
844 chown $RUNAS_ID $f || error "could not chown test file"
845 check_hsm_flags $f "0x00000001"
847 # truncate put the file dirty
848 $TRUNCATE $f 1 || error "could not truncate test file"
849 check_hsm_flags $f "0x00000003"
851 $LFS hsm_clear --dirty $f || error "could not clear hsm flags"
852 check_hsm_flags $f "0x00000001"
854 run_test 2 "Check file dirtyness when doing setattr"
860 # New files are not dirty
862 check_hsm_flags $f "0x00000000"
864 # For test, we simulate an archived file.
865 $LFS hsm_set --exists $f ||
866 error "user could not change hsm flags"
867 check_hsm_flags $f "0x00000001"
869 # Reading a file, does not set dirty
870 cat $f > /dev/null || error "could not read file"
871 check_hsm_flags $f "0x00000001"
873 # Open for write without modifying data, does not set dirty
874 openfile -f O_WRONLY $f || error "could not open test file"
875 check_hsm_flags $f "0x00000001"
877 # Append to a file sets it dirty
878 cp -p /etc/passwd $f.append || error "could not create file"
879 $LFS hsm_set --exists $f.append ||
880 error "user could not change hsm flags"
881 dd if=/etc/passwd of=$f.append bs=1 count=3\
882 conv=notrunc oflag=append status=noxfer ||
883 file_creation_failure dd $f.append $?
884 check_hsm_flags $f.append "0x00000003"
886 # Modify a file sets it dirty
887 cp -p /etc/passwd $f.modify || error "could not create file"
888 $LFS hsm_set --exists $f.modify ||
889 error "user could not change hsm flags"
890 dd if=/dev/zero of=$f.modify bs=1 count=3\
891 conv=notrunc status=noxfer ||
892 file_creation_failure dd $f.modify $?
893 check_hsm_flags $f.modify "0x00000003"
895 # Open O_TRUNC sets dirty
896 cp -p /etc/passwd $f.trunc || error "could not create file"
897 $LFS hsm_set --exists $f.trunc ||
898 error "user could not change hsm flags"
899 cp /etc/group $f.trunc || error "could not override a file"
900 check_hsm_flags $f.trunc "0x00000003"
902 # Mmapped a file sets dirty
903 cp -p /etc/passwd $f.mmap || error "could not create file"
904 $LFS hsm_set --exists $f.mmap ||
905 error "user could not change hsm flags"
906 multiop $f.mmap OSMWUc || error "could not mmap a file"
907 check_hsm_flags $f.mmap "0x00000003"
909 run_test 3 "Check file dirtyness when opening for write"
912 local f=$DIR/$tdir/$tfile
913 local fid=$(create_small_file $f)
916 local st=$(get_request_state $fid CANCEL)
917 [[ -z "$st" ]] || error "hsm_cancel must not be registered (state=$st)"
919 run_test 4 "Useless cancel must not be registered"
922 # test needs a running copytool
926 local f=$DIR/$tdir/$tfile
927 local fid=$(copy_file /etc/passwd $f)
929 wait_request_state $fid ARCHIVE SUCCEED
931 check_hsm_flags $f "0x00000009"
933 run_test 8 "Test default archive number"
935 test_9A() { # was test_9
936 # we do not use the default one to be sure
937 local archive_id=$((HSM_ARCHIVE_NUMBER + 1))
938 copytool setup --archive-id $archive_id
940 # give time for CT to register with MDTs
941 sleep $(($MDSCOUNT*2))
942 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
943 check_agent_registered $uuid
946 local f=$DIR/$tdir/$tfile
947 local fid=$(copy_file /etc/passwd $f)
948 $LFS hsm_archive --archive $archive_id $f
949 wait_request_state $fid ARCHIVE SUCCEED
951 check_hsm_flags $f "0x00000009"
953 run_test 9A "Use of explicit archive number, with dedicated copytool"
956 needclients 3 || return 0
962 # start all of the copytools
963 for n in $(seq $AGTCOUNT); do
964 copytool setup --facet agt$n
968 for n in $(seq $AGTCOUNT); do
969 file=$DIR/$tdir/$tfile.$n
970 fid=$(create_small_file $file)
972 $LFS hsm_archive $file || error "could not archive file $file"
973 wait_request_state $fid ARCHIVE SUCCEED
974 check_hsm_flags $file "0x00000009"
977 run_test 9a "Multiple remote agents"
980 # test needs a running copytool
983 mkdir -p $DIR/$tdir/d1
984 local f=$DIR/$tdir/$tfile
985 local fid=$(copy_file /etc/hosts $f)
986 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
987 error "hsm_archive failed"
988 wait_request_state $fid ARCHIVE SUCCEED
990 local hsm_root="$(copytool_device $SINGLEAGT)"
991 local archive="$(do_facet $SINGLEAGT \
992 find "$hsm_root" -name "$fid" -print0)"
993 [ -n "$archive" ] || error "fid '$fid' not in archive '$hsm_root'"
995 echo "Verifying content"
996 do_facet $SINGLEAGT diff $f $archive || error "archived file differs"
997 echo "Verifying hsm state "
998 check_hsm_flags $f "0x00000009"
1000 echo "Verifying archive number is $HSM_ARCHIVE_NUMBER"
1001 local st=$(get_hsm_archive_id $f)
1002 [[ $st == $HSM_ARCHIVE_NUMBER ]] ||
1003 error "Wrong archive number, $st != $HSM_ARCHIVE_NUMBER"
1005 run_test 10a "Archive a file"
1008 # test needs a running copytool
1012 local f=$DIR/$tdir/$tfile
1013 local fid=$(copy_file /etc/hosts $f)
1014 $LFS hsm_archive $f || error "archive request failed"
1015 wait_request_state $fid ARCHIVE SUCCEED
1017 $LFS hsm_archive $f || error "archive of non dirty file failed"
1018 local cnt=$(get_request_count $fid ARCHIVE)
1019 [[ "$cnt" == "1" ]] ||
1020 error "archive of non dirty file must not make a request"
1022 run_test 10b "Archive of non dirty file must work without doing request"
1025 # test needs a running copytool
1029 local f=$DIR/$tdir/$tfile
1030 local fid=$(copy_file /etc/hosts $f)
1031 $LFS hsm_set --noarchive $f
1032 $LFS hsm_archive $f && error "archive a noarchive file must fail"
1035 run_test 10c "Check forbidden archive"
1038 # test needs a running copytool
1042 local f=$DIR/$tdir/$tfile
1043 local fid=$(copy_file /etc/hosts $f)
1044 $LFS hsm_archive $f || error "cannot archive $f"
1045 wait_request_state $fid ARCHIVE SUCCEED
1047 local ar=$(get_hsm_archive_id $f)
1048 local dflt=$(get_hsm_param default_archive_id)
1049 [[ $ar == $dflt ]] ||
1050 error "archived file is not on default archive: $ar != $dflt"
1052 run_test 10d "Archive a file on the default archive id"
1056 copy2archive /etc/hosts $tdir/$tfile
1057 local f=$DIR/$tdir/$tfile
1059 copytool import $tdir/$tfile $f
1060 echo -n "Verifying released state: "
1061 check_hsm_flags $f "0x0000000d"
1063 local LSZ=$(stat -c "%s" $f)
1064 local ASZ=$(do_facet $SINGLEAGT stat -c "%s" "$(hsm_root)/$tdir/$tfile")
1066 echo "Verifying imported size $LSZ=$ASZ"
1067 [[ $LSZ -eq $ASZ ]] || error "Incorrect size $LSZ != $ASZ"
1068 echo -n "Verifying released pattern: "
1069 local PTRN=$($LFS getstripe -L $f)
1071 [[ $PTRN == released ]] || error "Is not released"
1072 local fid=$(path2fid $f)
1073 echo "Verifying new fid $fid in archive"
1075 do_facet $SINGLEAGT "[ -f \"$(fid2archive "$fid")\" ]" ||
1076 error "No archive for fid $fid"
1078 run_test 11a "Import a file"
1081 # test needs a running copytool
1085 local f=$DIR/$tdir/$tfile
1086 local fid=$(copy_file /etc/hosts $f)
1087 $LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f ||
1088 error "hsm_archive failed"
1089 wait_request_state $fid ARCHIVE SUCCEED
1091 local FILE_HASH=$(md5sum $f)
1094 copytool import $fid $f
1096 echo "$FILE_HASH" | md5sum -c
1098 [[ $? -eq 0 ]] || error "Restored file differs"
1100 run_test 11b "Import a deleted file using its FID"
1103 # test needs a running copytool
1107 copy2archive /etc/hosts $tdir/$tfile
1109 local f=$DIR/$tdir/$tfile
1110 copytool import $tdir/$tfile $f
1111 local f2=$DIR2/$tdir/$tfile
1112 echo "Verifying released state: "
1113 check_hsm_flags $f2 "0x0000000d"
1115 local fid=$(path2fid $f2)
1116 $LFS hsm_restore $f2
1117 wait_request_state $fid RESTORE SUCCEED
1119 echo "Verifying file state: "
1120 check_hsm_flags $f2 "0x00000009"
1122 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1124 [[ $? -eq 0 ]] || error "Restored file differs"
1126 run_test 12a "Restore an imported file explicitly"
1129 # test needs a running copytool
1133 copy2archive /etc/hosts $tdir/$tfile
1135 local f=$DIR/$tdir/$tfile
1136 copytool import $tdir/$tfile $f
1137 echo "Verifying released state: "
1138 check_hsm_flags $f "0x0000000d"
1140 cat $f > /dev/null || error "File read failed"
1142 echo "Verifying file state after restore: "
1143 check_hsm_flags $f "0x00000009"
1145 do_facet $SINGLEAGT diff -q $(hsm_root)/$tdir/$tfile $f
1147 [[ $? -eq 0 ]] || error "Restored file differs"
1149 run_test 12b "Restore an imported file implicitly"
1152 [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1154 # test needs a running copytool
1157 local f=$DIR/$tdir/$tfile
1159 $LFS setstripe -c 2 "$f"
1160 local fid=$(create_file "$f" 1M 5)
1162 local FILE_CRC=$(md5sum $f)
1164 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1165 wait_request_state $fid ARCHIVE SUCCEED
1166 $LFS hsm_release $f || error "release $f failed"
1168 echo "$FILE_CRC" | md5sum -c
1170 [[ $? -eq 0 ]] || error "Restored file differs"
1172 run_test 12c "Restore a file with stripe of 2"
1175 # test needs a running copytool
1180 local f=$DIR/$tdir/$tfile
1181 local fid=$(copy_file /etc/hosts $f)
1182 $LFS hsm_restore $f || error "restore of non archived file failed"
1183 local cnt=$(get_request_count $fid RESTORE)
1184 [[ "$cnt" == "0" ]] ||
1185 error "restore non archived must not make a request"
1186 $LFS hsm_archive $f ||
1187 error "archive request failed"
1188 wait_request_state $fid ARCHIVE SUCCEED
1189 $LFS hsm_restore $f ||
1190 error "restore of non released file failed"
1191 local cnt=$(get_request_count $fid RESTORE)
1192 [[ "$cnt" == "0" ]] ||
1193 error "restore a non dirty file must not make a request"
1195 run_test 12d "Restore of a non archived, non released file must work"\
1196 " without doing request"
1199 # test needs a running copytool
1203 local f=$DIR/$tdir/$tfile
1204 local fid=$(copy_file /etc/hosts $f)
1205 $LFS hsm_archive $f || error "archive request failed"
1206 wait_request_state $fid ARCHIVE SUCCEED
1209 cat /etc/hosts >> $f
1213 $LFS hsm_restore $f && error "restore a dirty file must fail"
1216 run_test 12e "Check forbidden restore"
1219 # test needs a running copytool
1223 local f=$DIR/$tdir/$tfile
1224 local fid=$(copy_file /etc/hosts $f)
1226 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1227 wait_request_state $fid ARCHIVE SUCCEED
1228 $LFS hsm_release $f || error "release of $f failed"
1230 wait_request_state $fid RESTORE SUCCEED
1232 echo -n "Verifying file state: "
1233 check_hsm_flags $f "0x00000009"
1235 diff -q /etc/hosts $f
1237 [[ $? -eq 0 ]] || error "Restored file differs"
1239 run_test 12f "Restore a released file explicitly"
1242 # test needs a running copytool
1246 local f=$DIR/$tdir/$tfile
1247 local fid=$(copy_file /etc/hosts $f)
1249 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1250 wait_request_state $fid ARCHIVE SUCCEED
1251 $LFS hsm_release $f || error "release of $f failed"
1253 diff -q /etc/hosts $f
1256 # we check we had a restore done
1257 wait_request_state $fid RESTORE SUCCEED
1259 [[ $st -eq 0 ]] || error "Restored file differs"
1261 run_test 12g "Restore a released file implicitly"
1264 needclients 2 || return 0
1266 # test needs a running copytool
1270 local f=$DIR/$tdir/$tfile
1271 local fid=$(copy_file /etc/hosts $f)
1273 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1274 wait_request_state $fid ARCHIVE SUCCEED
1275 $LFS hsm_release $f || error "release of $f failed"
1277 do_node $CLIENT2 diff -q /etc/hosts $f
1280 # we check we had a restore done
1281 wait_request_state $fid RESTORE SUCCEED
1283 [[ $st -eq 0 ]] || error "Restored file differs"
1285 run_test 12h "Restore a released file implicitly from a second node"
1288 # test needs a running copytool
1292 local f=$DIR/$tdir/$tfile
1293 local fid=$(copy_file /etc/passwd $f)
1294 $LFS hsm_archive $f || error "archive of $f failed"
1295 wait_request_state $fid ARCHIVE SUCCEED
1297 $LFS hsm_release $f || error "release of $f failed"
1301 [[ $? -eq 0 ]] || error "Restored file differs"
1303 run_test 12m "Archive/release/implicit restore"
1306 # test needs a running copytool
1310 copy2archive /etc/hosts $tdir/$tfile
1312 local f=$DIR/$tdir/$tfile
1313 copytool import $tdir/$tfile $f
1315 do_facet $SINGLEAGT cmp /etc/hosts $f ||
1316 error "Restored file differs"
1318 $LFS hsm_release $f || error "release of $f failed"
1320 run_test 12n "Import/implicit restore/release"
1323 # test needs a running copytool
1327 local f=$DIR/$tdir/$tfile
1328 local fid=$(copy_file /etc/hosts $f)
1330 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1331 wait_request_state $fid ARCHIVE SUCCEED
1332 $LFS hsm_release $f || error "release of $f failed"
1334 #define OBD_FAIL_MDS_HSM_SWAP_LAYOUTS 0x152
1335 do_facet $SINGLEMDS lctl set_param fail_loc=0x152
1337 # set no retry action mode
1340 diff -q /etc/hosts $f
1343 # we check we had a restore failure
1344 wait_request_state $fid RESTORE FAILED
1346 [[ $st -eq 0 ]] && error "Restore must fail"
1348 # remove no retry action mode
1351 # check file is still released
1352 check_hsm_flags $f "0x0000000d"
1354 # retry w/o failure injection
1355 do_facet $SINGLEMDS lctl set_param fail_loc=0
1357 # to be sure previous RESTORE result is gone
1359 wait_for_grace_delay
1361 diff -q /etc/hosts $f
1364 # we check we had a restore done
1365 wait_request_state $fid RESTORE SUCCEED
1367 [[ $st -eq 0 ]] || error "Restored file differs"
1369 run_test 12o "Layout-swap failure during Restore leaves file released"
1372 # test needs a running copytool
1376 local f=$DIR/$tdir/$tfile
1377 local fid=$(copy_file /etc/hosts $f)
1379 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1380 wait_request_state $fid ARCHIVE SUCCEED
1381 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1382 $LFS hsm_release $f || error "cannot release $f"
1383 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1384 $LFS hsm_release $f || error "cannot release $f"
1385 do_facet $SINGLEAGT cat $f > /dev/null || error "cannot cat $f"
1387 run_test 12p "implicit restore of a file on copytool mount point"
1390 [ $MDS1_VERSION -lt $(version_code 2.7.58) ] &&
1391 skip "need MDS version at least 2.7.58"
1393 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1394 zconf_mount $(facet_host $SINGLEAGT) $MOUNT3 ||
1395 error "cannot mount $MOUNT3 on $SINGLEAGT"
1397 # test needs a running copytool
1398 copytool setup -m "$MOUNT3"
1400 local f=$DIR/$tdir/$tfile
1401 local f2=$DIR2/$tdir/$tfile
1402 local fid=$(create_small_file $f)
1403 local orig_size=$(stat -c "%s" $f)
1405 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
1406 wait_request_state $fid ARCHIVE SUCCEED
1408 $LFS hsm_release $f || error "could not release file"
1409 check_hsm_flags $f "0x0000000d"
1412 wait_copytools || error "copytool failed to stop"
1414 cat $f > /dev/null &
1416 # wait a bit to allow implicit restore request to be handled.
1417 # if not, next stat would also block on layout-lock.
1420 local size=$(stat -c "%s" $f2)
1421 [ $size -eq $orig_size ] ||
1422 error "$f2: wrong size after archive: $size != $orig_size"
1424 copytool setup -m "$MOUNT3"
1428 size=$(stat -c "%s" $f)
1429 [ $size -eq $orig_size ] ||
1430 error "$f: wrong size after restore: $size != $orig_size"
1432 size=$(stat -c "%s" $f2)
1433 [ $size -eq $orig_size ] ||
1434 error "$f2: wrong size after restore: $size != $orig_size"
1438 size=$(stat -c "%s" $f)
1440 error "$f: wrong size after overwrite: $size != 0"
1442 size=$(stat -c "%s" $f2)
1444 error "$f2: wrong size after overwrite: $size != 0"
1446 run_test 12q "file attributes are refreshed after restore"
1450 for i in {1..10}; do
1451 local archive_dir="$(hsm_root)"/subdir/dir.$i
1453 do_facet $SINGLEAGT mkdir -p "$archive_dir"
1454 for j in {1..10}; do
1455 local archive_file="$archive_dir"/file.$j
1457 do_facet $SINGLEAGT "echo $k > \"$archive_dir\"/file.$j"
1463 copytool import "subdir" "$DIR/$tdir"
1465 # To check the import, the test uses diff with the -r flag
1466 # This is nice, but diff only checks files one by one, and triggering
1467 # an implicit restore for one file at a time will consume as many
1468 # seconds as there are files to compare. To speed this up, a restore
1469 # operation is triggered manually first.
1471 find "$DIR/$tdir"/subdir -type f -exec $LFS hsm_restore {} \;
1473 # Compare the imported data
1474 do_facet $SINGLEAGT \
1475 diff -r "$(hsm_root)"/subdir "$DIR/$tdir"/subdir ||
1476 error "imported files differ from archived data"
1478 run_test 13 "Recursively import and restore a directory"
1481 # test needs a running copytool
1485 local f=$DIR/$tdir/$tfile
1486 local fid=$(create_small_file $f)
1487 local sum=$(md5sum $f | awk '{print $1}')
1488 $LFS hsm_archive $f || error "could not archive file"
1489 wait_request_state $fid ARCHIVE SUCCEED
1491 # create released file (simulate llapi_hsm_import call)
1492 local fid2=$(create_empty_file "$f")
1493 $LFS hsm_set --archived --exists $f || error "could not force hsm flags"
1494 $LFS hsm_release $f || error "could not release file"
1496 # rebind the archive to the newly created file
1497 echo "rebind $fid to $fid2"
1499 copytool rebind $fid $fid2
1501 # restore file and compare md5sum
1502 local sum2=$(md5sum $f | awk '{print $1}')
1504 [[ $sum == $sum2 ]] || error "md5sum mismatch after restore"
1506 run_test 14 "Rebind archived file to a new fid"
1509 # test needs a running copytool
1513 local f=$DIR/$tdir/$tfile
1515 local tmpfile=$SHARED_DIRECTORY/tmp.$$
1519 for i in $(seq 1 $count); do
1520 fids[$i]=$(create_small_file $f.$i)
1521 sums[$i]=$(md5sum $f.$i | awk '{print $1}')
1522 $LFS hsm_archive $f.$i || error "could not archive file"
1524 wait_all_done $(($count*60))
1526 stack_trap "rm -f $tmpfile" EXIT
1529 for i in $(seq 1 $count); do
1530 local fid2=$(create_empty_file "${f}.${i}")
1531 # add the rebind operation to the list
1532 echo ${fids[$i]} $fid2 >> $tmpfile
1534 # set it released (simulate llapi_hsm_import call)
1535 $LFS hsm_set --archived --exists $f.$i ||
1536 error "could not force hsm flags"
1537 $LFS hsm_release $f.$i || error "could not release file"
1539 nl=$(wc -l < $tmpfile)
1540 [[ $nl == $count ]] || error "$nl files in list, $count expected"
1542 echo "rebind list of files"
1543 copytool rebind "$tmpfile"
1545 # restore files and compare md5sum
1546 for i in $(seq 1 $count); do
1547 local sum2=$(md5sum $f.$i | awk '{print $1}')
1548 [[ $sum2 == ${sums[$i]} ]] ||
1549 error "md5sum mismatch after restore ($sum2 != ${sums[$i]})"
1552 run_test 15 "Rebind a list of files"
1555 # test needs a running copytool
1559 # create a known size file so we can verify transfer speed
1562 dd if=/dev/zero of=$ref bs=1M count=20
1565 local f=$DIR/$tdir/$tfile
1566 local fid=$(copy_file $ref $f)
1568 local start=$(date +%s)
1570 wait_request_state $fid ARCHIVE SUCCEED
1571 local end=$(date +%s)
1572 # Add 1 to account for rounding errors between start and end (LU-8155)
1573 local duration=$((end - start + 1))
1575 [[ $duration -ge $((goal - 1)) ]] ||
1576 error "Transfer is too fast $duration < $goal"
1578 run_test 16 "Test CT bandwith control option"
1581 local f=$DIR/$tdir/$tfile
1582 create_empty_file "$f"
1584 # Could not release a non-archived file
1585 $LFS hsm_release $f && error "release should not succeed"
1587 # For following tests, we must test them with HS_ARCHIVED set
1588 $LFS hsm_set --exists --archived $f || error "could not add flag"
1590 # Could not release a file if no-release is set
1591 $LFS hsm_set --norelease $f || error "could not add flag"
1592 $LFS hsm_release $f && error "release should not succeed"
1593 $LFS hsm_clear --norelease $f || error "could not remove flag"
1595 # Could not release a file if lost
1596 $LFS hsm_set --lost $f || error "could not add flag"
1597 $LFS hsm_release $f && error "release should not succeed"
1598 $LFS hsm_clear --lost $f || error "could not remove flag"
1600 # Could not release a file if dirty
1601 $LFS hsm_set --dirty $f || error "could not add flag"
1602 $LFS hsm_release $f && error "release should not succeed"
1603 $LFS hsm_clear --dirty $f || error "could not remove flag"
1605 run_test 20 "Release is not permitted"
1608 # test needs a running copytool
1611 local f=$DIR/$tdir/test_release
1613 # Create a file and check its states
1614 local fid=$(create_small_file $f)
1615 check_hsm_flags $f "0x00000000"
1617 # LU-4388/LU-4389 - ZFS does not report full number of blocks
1618 # used until file is flushed to disk
1619 if [ $(facet_fstype ost1) == "zfs" ]; then
1620 # this causes an OST_SYNC rpc to be sent
1621 dd if=/dev/zero of=$f bs=512 count=1 oflag=sync conv=notrunc,fsync
1622 # clear locks to reread file data
1623 cancel_lru_locks osc
1626 local orig_size=$(stat -c "%s" $f)
1627 local orig_blocks=$(stat -c "%b" $f)
1629 start_full_debug_logging
1631 $LFS hsm_archive $f || error "could not archive file"
1632 wait_request_state $fid ARCHIVE SUCCEED
1634 local blocks=$(stat -c "%b" $f)
1635 [ $blocks -eq $orig_blocks ] ||
1636 error "$f: wrong block number after archive: " \
1637 "$blocks != $orig_blocks"
1638 local size=$(stat -c "%s" $f)
1639 [ $size -eq $orig_size ] ||
1640 error "$f: wrong size after archive: $size != $orig_size"
1642 # Release and check states
1643 $LFS hsm_release $f || error "could not release file"
1644 check_hsm_flags $f "0x0000000d"
1646 blocks=$(stat -c "%b" $f)
1647 [ $blocks -gt 5 ] &&
1648 error "$f: too many blocks after release: $blocks > 5"
1649 size=$(stat -c "%s" $f)
1650 [ $size -ne $orig_size ] &&
1651 error "$f: wrong size after release: $size != $orig_size"
1653 # Check we can release an file without stripe info
1657 check_hsm_flags $f "0x00000000"
1658 $LFS hsm_archive $f || error "could not archive file"
1659 wait_request_state $fid ARCHIVE SUCCEED
1661 # Release and check states
1662 $LFS hsm_release $f || error "could not release file"
1663 check_hsm_flags $f "0x0000000d"
1665 # Release again a file that is already released is OK
1666 $LFS hsm_release $f || fail "second release should succeed"
1667 check_hsm_flags $f "0x0000000d"
1669 stop_full_debug_logging
1671 run_test 21 "Simple release tests"
1674 # test needs a running copytool
1677 local f=$DIR/$tdir/test_release
1678 local swap=$DIR/$tdir/test_swap
1680 # Create a file and check its states
1681 local fid=$(create_small_file $f)
1682 check_hsm_flags $f "0x00000000"
1684 $LFS hsm_archive $f || error "could not archive file"
1685 wait_request_state $fid ARCHIVE SUCCEED
1687 # Release and check states
1688 $LFS hsm_release $f || error "could not release file"
1689 check_hsm_flags $f "0x0000000d"
1691 create_small_file $swap
1692 $LFS swap_layouts $swap $f && error "swap_layouts should failed"
1696 run_test 22 "Could not swap a release file"
1699 # test needs a running copytool
1702 local f=$DIR/$tdir/test_mtime
1704 # Create a file and check its states
1705 local fid=$(create_small_file $f)
1706 check_hsm_flags $f "0x00000000"
1708 $LFS hsm_archive $f || error "could not archive file"
1709 wait_request_state $fid ARCHIVE SUCCEED
1711 # Set modification time in the past
1712 touch -m -a -d @978261179 $f
1714 # Release and check states
1715 $LFS hsm_release $f || error "could not release file"
1716 check_hsm_flags $f "0x0000000d"
1718 local MTIME=$(stat -c "%Y" $f)
1719 local ATIME=$(stat -c "%X" $f)
1720 [ $MTIME -eq "978261179" ] || fail "bad mtime: $MTIME"
1721 [ $ATIME -eq "978261179" ] || fail "bad atime: $ATIME"
1723 run_test 23 "Release does not change a/mtime (utime)"
1726 local file=$DIR/$tdir/$tfile
1735 # test needs a running copytool
1738 fid=$(create_small_file $file)
1740 # Create a file and check its states
1741 check_hsm_flags $file "0x00000000"
1743 # Ensure atime is less than mtime and ctime.
1747 atime0=$(stat -c "%X" $file)
1748 mtime0=$(stat -c "%Y" $file)
1749 ctime0=$(stat -c "%Z" $file)
1751 [ $atime0 -lt $mtime0 ] ||
1752 error "atime $atime0 is not less than mtime $mtime0"
1754 [ $atime0 -lt $ctime0 ] ||
1755 error "atime $atime0 is not less than ctime $ctime0"
1757 # Archive should not change any timestamps.
1758 $LFS hsm_archive $file || error "cannot archive '$file'"
1759 wait_request_state $fid ARCHIVE SUCCEED
1761 atime1=$(stat -c "%X" $file)
1762 mtime1=$(stat -c "%Y" $file)
1763 ctime1=$(stat -c "%Z" $file)
1765 [ $atime0 -eq $atime1 ] ||
1766 error "archive changed atime from $atime0 to $atime1"
1768 [ $mtime0 -eq $mtime1 ] ||
1769 error "archive changed mtime from $mtime0 to $mtime1"
1771 [ $ctime0 -eq $ctime1 ] ||
1772 error "archive changed ctime from $ctime0 to $ctime1"
1774 # Release should not change any timestamps.
1775 $LFS hsm_release $file || error "cannot release '$file'"
1776 check_hsm_flags $file "0x0000000d"
1778 atime1=$(stat -c "%X" $file)
1779 mtime1=$(stat -c "%Y" $file)
1780 ctime1=$(stat -c "%Z" $file)
1782 [ $atime0 -eq $atime1 ] ||
1783 error "release changed atime from $atime0 to $atime1"
1785 [ $mtime0 -eq $mtime1 ] ||
1786 error "release changed mtime from $mtime0 to $mtime1"
1788 [ $ctime0 -eq $ctime1 ] ||
1789 error "release changed ctime from $ctime0 to $ctime1"
1791 # Restore should not change any timestamps.
1792 $LFS hsm_restore $file
1793 wait_request_state $fid RESTORE SUCCEED
1795 atime1=$(stat -c "%X" $file)
1796 mtime1=$(stat -c "%Y" $file)
1797 ctime1=$(stat -c "%Z" $file)
1799 [ $atime0 -eq $atime1 ] ||
1800 error "restore changed atime from $atime0 to $atime1"
1802 [ $mtime0 -eq $mtime1 ] ||
1803 error "restore changed mtime from $mtime0 to $mtime1"
1805 [ $ctime0 -eq $ctime1 ] ||
1806 error "restore changed ctime from $ctime0 to $ctime1"
1809 wait_copytools || error "Copytools failed to stop"
1811 # Once more, after unmount and mount.
1812 umount_client $MOUNT || error "cannot unmount '$MOUNT'"
1813 mount_client $MOUNT || error "cannot mount '$MOUNT'"
1815 atime1=$(stat -c "%X" $file)
1816 mtime1=$(stat -c "%Y" $file)
1817 ctime1=$(stat -c "%Z" $file)
1819 [ $atime0 -eq $atime1 ] ||
1820 error "remount changed atime from $atime0 to $atime1"
1822 [ $mtime0 -eq $mtime1 ] ||
1823 error "remount changed mtime from $mtime0 to $mtime1"
1825 [ $ctime0 -eq $ctime1 ] ||
1826 error "remount changed ctime from $ctime0 to $ctime1"
1828 run_test 24a "Archive, release, and restore does not change a/mtime (i/o)"
1831 local file=$DIR/$tdir/$tfile
1837 # Test needs a running copytool.
1840 # Check that root can do HSM actions on a regular user's file.
1841 fid=$(create_small_file $file)
1842 sum0=$(md5sum $file)
1844 chown $RUNAS_ID:$RUNAS_GID $file ||
1845 error "cannot chown '$file' to '$RUNAS_ID'"
1847 chmod ugo-w $DIR/$tdir ||
1848 error "cannot chmod '$DIR/$tdir'"
1850 $LFS hsm_archive $file
1851 wait_request_state $fid ARCHIVE SUCCEED
1853 $LFS hsm_release $file
1854 check_hsm_flags $file "0x0000000d"
1856 $LFS hsm_restore $file
1857 wait_request_state $fid RESTORE SUCCEED
1859 # Check that ordinary user can get HSM state.
1860 $RUNAS $LFS hsm_state $file ||
1861 error "user '$RUNAS_ID' cannot get HSM state of '$file'"
1863 $LFS hsm_release $file
1864 check_hsm_flags $file "0x0000000d"
1866 # Check that ordinary user can accessed released file.
1867 sum1=$($RUNAS md5sum $file) ||
1868 error "user '$RUNAS_ID' cannot read '$file'"
1870 [ "$sum0" == "$sum1" ] ||
1871 error "md5sum mismatch for '$file'"
1873 run_test 24b "root can archive, release, and restore user files"
1876 local file=$DIR/$tdir/$tfile
1877 local action=archive
1882 # test needs a running copytool
1887 # Save the default masks and check that cleanup_24c will
1888 # restore the request masks correctly.
1889 user_save=$(get_hsm_param user_request_mask)
1890 stack_trap "set_hsm_param user_request_mask $user_save" EXIT
1891 group_save=$(get_hsm_param group_request_mask)
1892 stack_trap "set_hsm_param user_request_mask $group_save" EXIT
1893 other_save=$(get_hsm_param other_request_mask)
1894 stack_trap "set_hsm_param user_request_mask $other_save" EXIT
1896 [ "$user_save" == RESTORE ] ||
1897 error "user_request_mask is '$user_save' expected 'RESTORE'"
1898 [ "$group_save" == RESTORE ] ||
1899 error "group_request_mask is '$group_save' expected 'RESTORE'"
1900 [ "$other_save" == RESTORE ] ||
1901 error "other_request_mask is '$other_save' expected 'RESTORE'"
1904 create_small_file $file
1905 chown $RUNAS_ID:$GROUP $file ||
1906 error "cannot chown '$file' to '$RUNAS_ID:$GROUP'"
1908 $RUNAS $LFS hsm_$action $file &&
1909 error "$action by user should fail"
1911 set_hsm_param user_request_mask $action
1912 $RUNAS $LFS hsm_$action $file ||
1913 error "$action by user should succeed"
1916 create_small_file $file
1917 chown nobody:$RUNAS_GID $file ||
1918 error "cannot chown '$file' to 'nobody:$RUNAS_GID'"
1920 $RUNAS $LFS hsm_$action $file &&
1921 error "$action by group should fail"
1923 set_hsm_param group_request_mask $action
1924 $RUNAS $LFS hsm_$action $file ||
1925 error "$action by group should succeed"
1928 create_small_file $file
1929 chown nobody:$GROUP $file ||
1930 error "cannot chown '$file' to 'nobody:$GROUP'"
1932 $RUNAS $LFS hsm_$action $file &&
1933 error "$action by other should fail"
1935 set_hsm_param other_request_mask $action
1936 $RUNAS $LFS hsm_$action $file ||
1937 error "$action by other should succeed"
1939 run_test 24c "check that user,group,other request masks work"
1942 local file1=$DIR/$tdir/$tfile
1943 local file2=$DIR2/$tdir/$tfile
1947 fid1=$(create_small_file $file1)
1950 $LFS getstripe $file1
1952 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
1953 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
1954 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
1956 copytool setup -m "$MOUNT3"
1958 stack_trap "mount -o remount,rw \"$MOUNT2\"" EXIT
1959 mount -o remount,ro $MOUNT2
1961 do_nodes $(comma_list $(nodes_list)) $LCTL clear
1963 fid2=$(path2fid $file2)
1964 [ "$fid1" == "$fid2" ] ||
1965 error "FID mismatch '$fid1' != '$fid2'"
1967 $LFS hsm_archive $file2 &&
1968 error "archive should fail on read-only mount"
1969 check_hsm_flags $file1 "0x00000000"
1971 $LFS hsm_archive $file1 || error "Fail to archive $file1"
1972 wait_request_state $fid1 ARCHIVE SUCCEED
1974 $LFS hsm_release $file1
1975 $LFS hsm_restore $file2
1976 wait_request_state $fid1 RESTORE SUCCEED
1978 $LFS hsm_release $file1 || error "cannot release '$file1'"
1979 dd if=$file2 of=/dev/null bs=1M || error "cannot read '$file2'"
1981 $LFS hsm_release $file2 &&
1982 error "release should fail on read-only mount"
1986 run_test 24d "check that read-only mounts are respected"
1991 local f=$DIR/$tdir/$tfile
1994 fid=$(create_small_file $f) || error "cannot create $f"
1995 $LFS hsm_archive $f || error "cannot archive $f"
1996 wait_request_state $fid ARCHIVE SUCCEED
1997 $LFS hsm_release $f || error "cannot release $f"
1998 while ! $LFS hsm_state $f | grep released; do
2002 tar -cf $TMP/$tfile.tar $DIR/$tdir || error "cannot tar $DIR/$tdir"
2004 run_test 24e "tar succeeds on HSM released files" # LU-6213
2007 # test needs a running copytool
2010 mkdir -p $DIR/$tdir/d1
2011 local f=$DIR/$tdir/$tfile
2012 local fid=$(copy_file /etc/hosts $f)
2015 $LFS hsm_archive $f ||
2016 error "hsm_archive failed"
2017 wait_request_state $fid ARCHIVE SUCCEED
2018 $LFS hsm_release $f || error "cannot release $f"
2019 tar --xattrs -cvf $f.tar -C $DIR/$tdir $tfile
2022 tar --xattrs -xvf $f.tar -C $DIR/$tdir ||
2023 error "Can not recover the tar contents"
2025 echo "Sum0 = $sum0, sum1 = $sum1"
2026 [ "$sum0" == "$sum1" ] || error "md5sum mismatch for '$tfile'"
2028 run_test 24f "root can archive, release, and restore tar files"
2031 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
2032 skip "need MDS version 2.11.56 or later"
2034 local file=$DIR/$tdir/$tfile
2037 echo "RUNAS = '$RUNAS'"
2042 chmod ugo+rwx $DIR/$tdir
2044 echo "Please listen carefully as our options have changed." | tee $file
2045 fid=$(path2fid $file)
2048 $LFS hsm_archive $file
2049 wait_request_state $fid ARCHIVE SUCCEED
2050 check_hsm_flags $file 0x00000009 # exists archived
2052 echo "To be electrocuted by your telephone, press #." | $RUNAS tee $file
2053 check_hsm_flags $file 0x0000000b # exists dirty archived
2055 run_test 24g "write by non-owner still sets dirty" # LU-11369
2058 # test needs a running copytool
2062 copy2archive /etc/hosts $tdir/$tfile
2064 local f=$DIR/$tdir/$tfile
2066 copytool import $tdir/$tfile $f
2068 $LFS hsm_set --lost $f
2073 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2075 run_test 25a "Restore lost file (HS_LOST flag) from import"\
2076 " (Operation not permitted)"
2079 # test needs a running copytool
2084 local f=$DIR/$tdir/$tfile
2085 local fid=$(copy_file /etc/passwd $f)
2087 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2088 wait_request_state $fid ARCHIVE SUCCEED
2091 $LFS hsm_set --lost $f
2095 [[ $st == 1 ]] || error "lost file access should failed (returns $st)"
2097 run_test 25b "Restore lost file (HS_LOST flag) after release"\
2098 " (Operation not permitted)"
2100 test_26A() { # was test_26
2101 # test needs a running copytool
2104 local f=$DIR/$tdir/$tfile
2105 local fid=$(create_empty_file "$f")
2107 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2108 wait_request_state $fid ARCHIVE SUCCEED
2111 wait_request_state $fid REMOVE SUCCEED
2113 check_hsm_flags $f "0x00000000"
2115 run_test 26A "Remove the archive of a valid file"
2118 local raolu=$(get_hsm_param remove_archive_on_last_unlink)
2119 [[ $raolu -eq 0 ]] || error "RAoLU policy should be off"
2121 # test needs a running copytool
2125 local f=$DIR/$tdir/$tfile
2126 local fid=$(copy_file /etc/passwd $f)
2128 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2129 wait_request_state $fid ARCHIVE SUCCEED
2131 local f2=$DIR/$tdir/${tfile}_2
2132 local fid2=$(copy_file /etc/passwd $f2)
2134 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2135 wait_request_state $fid2 ARCHIVE SUCCEED
2137 local f3=$DIR/$tdir/${tfile}_3
2138 local fid3=$(copy_file /etc/passwd $f3)
2140 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f3
2141 wait_request_state $fid3 ARCHIVE SUCCEED
2143 # set a long grace_delay vs short loop_period
2144 local orig_loop_period=$(get_hsm_param loop_period)
2145 local orig_grace_delay=$(get_hsm_param grace_delay)
2146 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2147 set_hsm_param loop_period 10
2148 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2149 set_hsm_param grace_delay 100
2153 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2154 set_hsm_param remove_archive_on_last_unlink 1
2156 ln "$f3" "$f3"_bis || error "Unable to create hard-link"
2161 wait_request_state $fid2 REMOVE SUCCEED
2163 assert_request_count $fid REMOVE 0 \
2164 "Unexpected archived data remove request for $f"
2165 assert_request_count $fid3 REMOVE 0 \
2166 "Unexpected archived data remove request for $f3"
2168 run_test 26a "Remove Archive On Last Unlink (RAoLU) policy"
2171 # test needs a running copytool
2175 local f=$DIR/$tdir/$tfile
2176 local fid=$(copy_file /etc/passwd $f)
2178 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2179 wait_request_state $fid ARCHIVE SUCCEED
2181 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2182 set_hsm_param remove_archive_on_last_unlink 1
2185 cdt_check_state stopped
2189 wait_request_state $fid REMOVE WAITING
2193 # copytool must re-register
2195 wait_copytools || error "copytool failed to stop"
2198 wait_request_state $fid REMOVE SUCCEED
2200 run_test 26b "RAoLU policy when CDT off"
2203 # test needs a running copytool
2207 local f=$DIR/$tdir/$tfile
2208 local fid=$(copy_file /etc/passwd $f)
2210 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2211 wait_request_state $fid ARCHIVE SUCCEED
2213 local f2=$DIR/$tdir/${tfile}_2
2214 local fid2=$(copy_file /etc/passwd $f2)
2216 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
2217 wait_request_state $fid2 ARCHIVE SUCCEED
2219 # set a long grace_delay vs short loop_period
2220 local orig_loop_period=$(get_hsm_param loop_period)
2221 local orig_grace_delay=$(get_hsm_param grace_delay)
2222 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2223 set_hsm_param loop_period 10
2224 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2225 set_hsm_param grace_delay 100
2227 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2228 set_hsm_param remove_archive_on_last_unlink 1
2230 multiop_bg_pause $f O_c || error "open $f failed"
2236 wait_request_state $fid2 REMOVE SUCCEED
2237 assert_request_count $fid REMOVE 0 \
2238 "Unexpected archived data remove request for $f"
2240 kill -USR1 $pid || error "multiop early exit"
2241 # should reach autotest timeout if multiop fails to trap
2242 # signal, close file, and exit ...
2243 wait $pid || error "wait PID $PID failed"
2245 wait_request_state $fid REMOVE SUCCEED
2247 run_test 26c "RAoLU effective when file closed"
2250 # test needs a running copytool
2254 local f=$DIR/$tdir/$tfile
2255 local fid=$(create_small_file $f)
2257 $LFS hsm_archive $f || error "could not archive file"
2258 wait_request_state $fid ARCHIVE SUCCEED
2260 # set a long grace_delay vs short loop_period
2261 local orig_loop_period=$(get_hsm_param loop_period)
2262 local orig_grace_delay=$(get_hsm_param grace_delay)
2263 stack_trap "set_hsm_param loop_period $orig_loop_period" EXIT
2264 set_hsm_param loop_period 10
2265 stack_trap "set_hsm_param grace_delay $orig_grace_delay" EXIT
2266 set_hsm_param grace_delay 100
2268 stack_trap "set_hsm_param remove_archive_on_last_unlink 0" EXIT
2269 set_hsm_param remove_archive_on_last_unlink 1
2271 multiop_bg_pause $f O_c || error "multiop failed"
2278 wait_request_state $fid REMOVE SUCCEED
2280 client_up || client_up || true
2282 kill -USR1 $MULTIPID
2283 wait $MULTIPID || error "multiop close failed"
2285 run_test 26d "RAoLU when Client eviction"
2288 # test needs a running copytool
2291 create_archive_file $tdir/$tfile
2292 local f=$DIR/$tdir/$tfile
2293 copytool import $tdir/$tfile $f
2294 local fid=$(path2fid $f)
2298 [[ $? != 0 ]] || error "Remove of a released file should fail"
2300 run_test 27a "Remove the archive of an imported file (Operation not permitted)"
2303 # test needs a running copytool
2306 local f=$DIR/$tdir/$tfile
2307 local fid=$(create_empty_file "$f")
2309 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2310 wait_request_state $fid ARCHIVE SUCCEED
2315 [[ $? != 0 ]] || error "Remove of a released file should fail"
2317 run_test 27b "Remove the archive of a relased file (Operation not permitted)"
2320 # test needs a running copytool
2323 local f=$DIR/$tdir/$tfile
2324 local fid=$(create_empty_file "$f")
2326 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2327 wait_request_state $fid ARCHIVE SUCCEED
2336 wait_request_state $fid REMOVE SUCCEED
2338 run_test 28 "Concurrent archive/file remove"
2341 # Tests --mntpath and --archive options
2344 copytool setup -m "$MOUNT" -a $archive_id
2346 # Bad archive number
2347 $LFS hsm_remove -m "$MOUNT" -a 33 0x857765760:0x8:0x2 2>&1 |
2348 grep "Invalid argument" ||
2349 error "unexpected hsm_remove failure (1)"
2351 # mntpath is present but file is given
2352 $LFS hsm_remove --mntpath "$MOUNT" --archive 30 /qwerty/uyt 2>&1 |
2353 grep "hsm: '/qwerty/uyt' is not a valid FID" ||
2354 error "unexpected hsm_remove failure (2)"
2356 run_test 29a "Tests --mntpath and --archive options"
2359 # test needs a running copytool
2362 local f=$DIR/$tdir/$tfile
2363 local fid=$(create_small_file $f)
2365 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2366 wait_request_state $fid ARCHIVE SUCCEED
2370 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER $fid
2371 wait_request_state $fid REMOVE SUCCEED
2373 run_test 29b "Archive/delete/remove by FID from the archive."
2376 # test needs a running copytool
2379 local fid1=$(create_small_file $DIR/$tdir/$tfile-1)
2380 local fid2=$(create_small_file $DIR/$tdir/$tfile-2)
2381 local fid3=$(create_small_file $DIR/$tdir/$tfile-3)
2383 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/$tfile-[1-3]
2384 wait_request_state $fid1 ARCHIVE SUCCEED
2385 wait_request_state $fid2 ARCHIVE SUCCEED
2386 wait_request_state $fid3 ARCHIVE SUCCEED
2388 rm -f $DIR/$tdir/$tfile-[1-3]
2390 echo $fid1 > $DIR/$tdir/list
2391 echo $fid2 >> $DIR/$tdir/list
2392 echo $fid3 >> $DIR/$tdir/list
2394 $LFS hsm_remove -m $MOUNT -a $HSM_ARCHIVE_NUMBER \
2395 --filelist $DIR/$tdir/list
2396 wait_request_state $fid1 REMOVE SUCCEED
2397 wait_request_state $fid2 REMOVE SUCCEED
2398 wait_request_state $fid3 REMOVE SUCCEED
2400 run_test 29c "Archive/delete/remove by FID, using a file list."
2403 # test needs more than one CT
2404 needclients 3 || return 0
2410 # start all of the copytools
2411 for n in $(seq $AGTCOUNT); do
2412 copytool setup -f agt$n -a $n
2416 file=$DIR/$tdir/$tfile
2417 fid=$(create_small_file $file)
2419 $LFS hsm_archive $file
2420 wait_request_state $fid ARCHIVE SUCCEED
2421 check_hsm_flags $file "0x00000009"
2425 $LFS hsm_remove --mntpath "$MOUNT" -a 0 $fid ||
2426 error "cannot hsm_remove '$fid'"
2428 # give time for CDT to handle remove request and create broadcasted
2431 # remove request has been broadcasted ?
2432 local cnt=$(get_request_count $fid REMOVE)
2433 # broadcasted requests + original
2434 [[ $cnt -eq $((AGTCOUNT + 1)) ]] ||
2435 error "remove not broadcasted to all CTs"
2437 # give time for CDT and CTs to handle broadcasted
2438 wait_for_loop_period
2440 # each agent serves one different archive_id, so broadcasted
2441 # hsm_remove request should only succeed once and fail at all others
2445 for n in $(seq $AGTCOUNT); do
2446 res=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2447 $HSM_PARAM.actions | awk \
2448 '/'$fid'.*action=REMOVE archive#='$n'/ \
2449 {print \\\$13}' | cut -f2 -d=")
2450 if [[ "$res" == "SUCCEED" ]]; then
2452 elif [[ "$res" == "FAILED" ]]; then
2457 [[ $scnt -eq 1 ]] ||
2458 error "one and only CT should have removed successfully"
2460 [[ $AGTCOUNT -eq $((scnt + fcnt)) ]] ||
2461 error "all but one CT should have failed to remove"
2463 run_test 29d "hsm_remove by FID with archive_id 0 for unlinked file cause "\
2464 "request to be sent once for each registered archive_id"
2467 # restore at exec cannot work on agent node (because of Linux kernel
2468 # protection of executables)
2469 needclients 2 || return 0
2471 # test needs a running copytool
2475 copy2archive /bin/true $tdir/$tfile
2477 local f=$DIR/$tdir/true
2478 copytool import $tdir/$tfile $f
2480 local fid=$(path2fid $f)
2482 stack_trap "cdt_clear_no_retry" EXIT
2483 # set no retry action mode
2490 [[ $st == 0 ]] || error "Failed to exec a released file"
2492 run_test 30a "Restore at exec (import case)"
2495 # restore at exec cannot work on agent node (because of Linux kernel
2496 # protection of executables)
2497 needclients 2 || return 0
2499 # test needs a running copytool
2503 local f=$DIR/$tdir/true
2504 local fid=$(copy_file /bin/true $f)
2506 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2507 wait_request_state $fid ARCHIVE SUCCEED
2511 stack_trap cdt_clear_no_retry EXIT
2512 # set no retry action mode
2520 [[ $st == 0 ]] || error "Failed to exec a released file"
2522 run_test 30b "Restore at exec (release case)"
2525 needclients 2 || return 0
2527 # test needs a running copytool
2531 local f=$DIR/$tdir/SLEEP
2532 local slp_sum1=$(md5sum /bin/sleep)
2533 local fid=$(copy_file /bin/sleep $f)
2535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2536 wait_request_state $fid ARCHIVE SUCCEED
2538 check_hsm_flags $f "0x0000000d"
2540 stack_trap cdt_clear_no_retry EXIT
2541 # set no retry action mode
2544 do_node $CLIENT2 "$f 10" &
2548 [[ $? == 0 ]] && error "Update during exec of released file must fail"
2550 [[ $? == 0 ]] || error "Execution failed during run"
2552 if [[ $? != 0 ]]; then
2553 local slp_sum2=$(md5sum /bin/sleep)
2554 # in case sleep file is modified during the test
2555 [[ $slp_sum1 == $slp_sum2 ]] &&
2556 error "Binary overwritten during exec"
2559 check_hsm_flags $f "0x00000009"
2561 run_test 30c "Update during exec of released file must fail"
2563 restore_and_check_size() {
2566 local s=$(stat -c "%s" $f)
2568 local st=$(get_hsm_flags $f)
2572 while [[ "$st" != "0x00000009" && $cpt -le 10 ]]
2574 n=$(stat -c "%s" $f)
2575 # we echo in both cases to show stat is not hang
2576 if [[ $n != $s ]]; then
2577 echo "size seen is $n != $s"
2580 echo "size seen is right: $n == $s"
2584 st=$(get_hsm_flags $f)
2586 if [[ "$st" = "0x00000009" ]]; then
2589 echo " restore is too long"
2590 wait_request_state $fid RESTORE SUCCEED
2596 # test needs a running copytool
2599 create_archive_file $tdir/$tfile
2600 local f=$DIR/$tdir/$tfile
2601 copytool import $tdir/$tfile $f
2602 local fid=$($LFS path2fid $f)
2605 restore_and_check_size $f $fid
2608 [[ $err -eq 0 ]] || error "File size changed during restore"
2610 run_test 31a "Import a large file and check size during restore"
2614 # test needs a running copytool
2617 local f=$DIR/$tdir/$tfile
2618 local fid=$(create_file "$f" 1MB 39)
2620 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2621 wait_request_state $fid ARCHIVE SUCCEED
2624 restore_and_check_size $f $fid
2627 [[ $err -eq 0 ]] || error "File size changed during restore"
2629 run_test 31b "Restore a large unaligned file and check size during restore"
2632 # test needs a running copytool
2635 local f=$DIR/$tdir/$tfile
2636 local fid=$(create_file "$f" 1M 39)
2638 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2639 wait_request_state $fid ARCHIVE SUCCEED
2642 restore_and_check_size $f $fid
2645 [[ $err -eq 0 ]] || error "File size changed during restore"
2647 run_test 31c "Restore a large aligned file and check size during restore"
2650 local f=$DIR/$tdir/$tfile
2651 local fid=$(create_empty_file "$f")
2655 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2656 wait_request_state $fid ARCHIVE SUCCEED
2659 # Prevent restore from completing
2663 md5sum $f >/dev/null &
2666 wait_request_state $fid RESTORE STARTED
2671 # Check restore trigger process was killed
2673 [ $? -eq 143 ] || error "md5sum was not 'Terminated'"
2675 run_test 33 "Kill a restore waiting process"
2678 # test needs a running copytool
2681 local f=$DIR/$tdir/$tfile
2682 local fid=$(create_empty_file "$f")
2684 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2685 wait_request_state $fid ARCHIVE SUCCEED
2688 # Prevent restore from completing
2691 md5sum $f >/dev/null &
2694 wait_request_state $fid RESTORE STARTED
2696 # rm must not block during restore
2697 timeout --signal=KILL 1 rm "$f" || error "rm $f failed"
2700 wait_request_state $fid RESTORE SUCCEED
2702 # Check md5sum pgm finished
2703 kill -0 $pid && error "Restore initiatior still running"
2704 wait $pid || error "Restore initiator failed with $?"
2706 # Check the file was actually deleted
2707 [ ! -f "$f" ] || error "$f was not deleted"
2709 run_test 34 "Remove file during restore"
2712 # test needs a running copytool
2715 local f=$DIR/$tdir/$tfile
2716 local f1=$DIR/$tdir/$tfile-1
2717 local fid=$(create_empty_file "$f")
2718 local fid1=$(copy_file /etc/passwd $f1)
2720 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2721 wait_request_state $fid ARCHIVE SUCCEED
2724 # Prevent restore from completing
2727 md5sum $f >/dev/null &
2730 wait_request_state $fid RESTORE STARTED
2732 # mv must not block during restore
2733 timeout --signal=KILL 1 mv "$f1" "$f" || error "mv $f1 $f failed"
2736 wait_request_state $fid RESTORE SUCCEED
2738 # Check md5sum pgm finished
2739 kill -0 $pid && error "Restore initiatior still running"
2740 wait $pid || error "Restore initiator failed with $?"
2742 local fid2=$(path2fid $f)
2743 [[ $fid2 == $fid1 ]] || error "Wrong fid after mv $fid2 != $fid1"
2745 run_test 35 "Overwrite file during restore"
2748 # test needs a running copytool
2751 local f=$DIR/$tdir/$tfile
2752 local fid=$(create_empty_file "$f")
2754 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2755 wait_request_state $fid ARCHIVE SUCCEED
2758 # Prevent restore from completing
2761 md5sum $f >/dev/null &
2764 wait_request_state $fid RESTORE STARTED
2766 # mv must not block during restore
2767 timeout --signal=KILL 10 mv "$f" "$f.new" ||
2768 error "mv '$f' '$f.new' failed with rc=$?"
2771 wait_request_state $fid RESTORE SUCCEED
2773 # Check md5sum pgm finished
2774 kill -0 $pid && error "Restore initiator is still running"
2775 wait $pid || error "Restore initiator failed with $?"
2777 run_test 36 "Move file during restore"
2780 # LU-5683: check that an archived dirty file can be rearchived.
2783 local f=$DIR/$tdir/$tfile
2786 fid=$(create_small_file $f) || error "cannot create small file"
2788 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2789 wait_request_state $fid ARCHIVE SUCCEED
2790 $LFS hsm_release $f || error "cannot release $f"
2792 # Allow previous archive request to expire from the actions log.
2793 wait_for_grace_delay
2796 dd if=/dev/urandom of=$f bs=1M count=1 || error "cannot dirty file"
2798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
2799 wait_request_state $fid ARCHIVE SUCCEED
2801 run_test 37 "re-archive a dirty file"
2808 for n in $(seq 1 $count); do
2809 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $prefix.$n
2811 echo "$count archive requests submitted"
2815 local stream_count=4
2816 local file_count=100
2818 local f=$DIR/$tdir/$tfile
2822 local max_requests=$(get_hsm_param max_requests)
2824 stack_trap "set_hsm_param max_requests $max_requests" EXIT
2825 # Increase the number of HSM request that can be performed in
2826 # parallel. With the coordinator running once per second, this
2827 # also limits the number of requests per seconds that can be
2828 # performed, so we pick a decent number. But we also need to keep
2829 # that number low because the copytool has no rate limit and will
2830 # fail some requests if if gets too many at once.
2831 set_hsm_param max_requests 300
2833 for i in $(seq 1 $file_count); do
2834 for p in $(seq 1 $stream_count); do
2835 fid=$(copy_file /etc/hosts $f.$p.$i)
2841 # to be sure wait_all_done will not be mislead by previous tests
2843 wait_for_grace_delay
2845 # start archive streams in background (archive files in parallel)
2846 for p in $(seq 1 $stream_count); do
2847 multi_archive $f.$p $file_count &
2850 echo -n "Wait for all requests being enqueued..."
2855 run_test 40 "Parallel archive requests"
2858 # test needs a running copytool
2862 local f=$DIR/$tdir/$tfile
2863 local fid=$(create_small_file $f)
2865 $LFS hsm_archive $f || error "could not archive file"
2866 wait_request_state $fid ARCHIVE SUCCEED
2867 check_hsm_flags $f "0x00000009"
2869 multiop_bg_pause $f O_c || error "multiop failed"
2873 client_up || client_up || true
2875 kill -USR1 $MULTIPID
2876 wait $MULTIPID || error "multiop close failed"
2878 check_hsm_flags $f "0x0000000b"
2880 run_test 52 "Opened for write file on an evicted client should be set dirty"
2883 # test needs a running copytool
2887 local f=$DIR/$tdir/$tfile
2888 local fid=$(create_small_file $f)
2890 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2891 error "could not archive file"
2892 wait_request_state $fid ARCHIVE SUCCEED
2893 check_hsm_flags $f "0x00000009"
2895 multiop_bg_pause $f o_c || error "multiop failed"
2899 client_up || client_up || true
2901 kill -USR1 $MULTIPID
2902 wait $MULTIPID || error "multiop close failed"
2904 check_hsm_flags $f "0x00000009"
2906 run_test 53 "Opened for read file on an evicted client should not be set dirty"
2909 local f=$DIR/$tdir/$tfile
2910 local fid=$(create_file "$f" 1MB 39)
2914 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2915 error "could not archive file"
2916 wait_request_state $fid ARCHIVE STARTED
2918 check_hsm_flags $f "0x00000001"
2920 stack_trap "cdt_clear_no_retry" EXIT
2921 # Avoid coordinator resending this request as soon it has failed.
2926 wait_request_state $fid ARCHIVE FAILED
2928 check_hsm_flags $f "0x00000003"
2930 run_test 54 "Write during an archive cancels it"
2933 local f=$DIR/$tdir/$tfile
2934 local fid=$(create_file "$f" 1MB 39)
2938 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2939 error "could not archive file"
2940 wait_request_state $fid ARCHIVE STARTED
2942 check_hsm_flags $f "0x00000001"
2944 stack_trap "cdt_clear_no_retry" EXIT
2945 # Avoid coordinator resending this request as soon it has failed.
2948 $TRUNCATE $f 1024 || error "truncate failed"
2950 wait_request_state $fid ARCHIVE FAILED
2952 check_hsm_flags $f "0x00000003"
2954 run_test 55 "Truncate during an archive cancels it"
2957 local f=$DIR/$tdir/$tfile
2958 local fid=$(create_file "$f" 1MB 39)
2962 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
2963 error "could not archive file"
2964 wait_request_state $fid ARCHIVE STARTED
2966 check_hsm_flags $f "0x00000001"
2968 # Change metadata and sync to be sure we are not changing only
2973 wait_request_state $fid ARCHIVE SUCCEED
2975 check_hsm_flags $f "0x00000009"
2977 run_test 56 "Setattr during an archive is ok"
2980 # Need one client for I/O, one for request
2981 needclients 2 || return 0
2983 # test needs a running copytool
2987 local f=$DIR/$tdir/test_archive_remote
2988 # Create a file on a remote node
2989 do_node $CLIENT2 "dd if=/dev/urandom of=$f bs=1M "\
2990 "count=2 conv=fsync"
2993 do_node $CLIENT2 "$LFS hsm_archive -a $HSM_ARCHIVE_NUMBER $f" ||
2994 error "hsm_archive failed"
2995 local fid=$(path2fid $f)
2996 wait_request_state $fid ARCHIVE SUCCEED
2998 # Release and implicit restore it
2999 do_node $CLIENT2 "$LFS hsm_release $f" ||
3000 error "hsm_release failed"
3001 do_node $CLIENT2 "md5sum $f" ||
3002 error "hsm_restore failed"
3004 wait_request_state $fid RESTORE SUCCEED
3006 run_test 57 "Archive a file with dirty cache on another node"
3008 truncate_released_file() {
3012 local sz=$(stat -c %s $src_file)
3013 local f=$DIR/$tdir/$tfile
3014 local fid=$(copy_file $1 $f)
3018 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3019 error "could not archive file"
3020 wait_request_state $fid ARCHIVE SUCCEED
3022 $LFS hsm_release $f || error "could not release file"
3024 $TRUNCATE $f $trunc_to || error "truncate failed"
3027 local sz1=$(stat -c %s $f)
3028 [[ $sz1 == $trunc_to ]] ||
3029 error "size after trunc: $sz1 expect $trunc_to, original $sz"
3032 check_hsm_flags $f "0x0000000b"
3034 local state=$(get_request_state $fid RESTORE)
3035 [[ "$state" == "SUCCEED" ]] ||
3036 error "truncate $sz does not trig restore, state = $state"
3038 $TRUNCATE $ref $trunc_to
3039 cmp $ref $f || error "file data wrong after truncate"
3045 # test needs a running copytool
3050 local sz=$(stat -c %s /etc/passwd)
3052 echo "truncate up from $sz to $((sz*2))"
3053 truncate_released_file /etc/passwd $((sz*2))
3055 echo "truncate down from $sz to $((sz/2))"
3056 truncate_released_file /etc/passwd $((sz/2))
3058 echo "truncate to 0"
3059 truncate_released_file /etc/passwd 0
3061 run_test 58 "Truncate a released file will trigger restore"
3065 [[ $MDS1_VERSION -lt $(version_code 2.7.63) ]] &&
3066 skip "Need MDS version at least 2.7.63"
3069 $MCREATE $DIR/$tfile || error "mcreate failed"
3070 $TRUNCATE $DIR/$tfile 42 || error "truncate failed"
3071 $LFS hsm_archive $DIR/$tfile || error "archive request failed"
3072 fid=$(path2fid $DIR/$tfile)
3073 wait_request_state $fid ARCHIVE SUCCEED
3074 $LFS hsm_release $DIR/$tfile || error "release failed"
3076 run_test 59 "Release stripeless file with non-zero size"
3079 # This test validates the fix for LU-4512. Ensure that the -u
3080 # option changes the progress reporting interval from the
3081 # default (30 seconds) to the user-specified interval.
3082 local f=$DIR/$tdir/$tfile
3083 local fid=$(create_file "$f" 1M 10)
3086 local progress_timeout=$((interval * 4))
3087 copytool setup -b 1 --update-interval $interval
3090 local mdt=${MDT_PREFIX}${mdtidx}
3091 local mds=mds$((mdtidx + 1))
3093 # Wait for copytool to register
3094 wait_update_facet $mds \
3095 "$LCTL get_param -n ${mdt}.hsm.agents | grep -o ^uuid" \
3096 uuid 100 || error "coyptool failed to register with $mdt"
3098 local start_at=$(date +%s)
3099 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3100 error "could not archive file"
3102 local agent=$(facet_active_host $SINGLEAGT)
3103 local logfile=$(copytool_logfile $SINGLEAGT)
3105 wait_update $agent \
3106 "grep -o start.copy \"$logfile\"" "start copy" 100 ||
3107 error "copytool failed to start"
3109 local cmd="$LCTL get_param -n ${mdt}.hsm.active_requests"
3110 cmd+=" | awk '/'$fid'.*action=ARCHIVE/ {print \\\$12}' | cut -f2 -d="
3116 echo -n "Expecting a progress update within $progress_timeout seconds... "
3118 RESULT=$(do_node $(facet_active_host $mds) "$cmd")
3119 if [ -n "$RESULT" ] && [ "$RESULT" -gt 0 ]; then
3120 echo "$RESULT bytes copied in $WAIT seconds."
3122 elif [ $WAIT -ge $progress_timeout ]; then
3123 error "Timed out waiting for progress update!"
3126 WAIT=$((WAIT + sleep))
3130 local finish_at=$(date +%s)
3131 local elapsed=$((finish_at - start_at))
3133 # Ensure that the progress update occurred within the expected window.
3134 if [ $elapsed -lt $((interval - 1)) ]; then
3135 error "Expected progress update after at least $interval seconds"
3138 echo "Wait for on going archive hsm action to complete"
3139 wait_update $agent "grep -o copied \"$logfile\"" "copied" 10 ||
3140 echo "File archiving not completed even after 10 secs"
3142 run_test 60 "Changing progress update interval from default"
3145 # test needs a running copytool
3149 local f=$DIR/$tdir/$tfile
3150 local fid=$(copy_file /etc/passwd $f)
3152 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3155 wait_request_state $fid ARCHIVE FAILED
3157 run_test 61 "Waiting archive of a removed file should fail"
3160 # test needs a new running copytool
3161 stack_trap copytool_monitor_cleanup EXIT
3162 copytool_monitor_setup
3163 copytool setup --event-fifo "$HSMTOOL_MONITOR_DIR/fifo"
3165 # Wait for the copytool to register.
3166 wait_update --verbose $(facet_active_host mds1) \
3167 "$LCTL get_param -n ${MDT_PREFIX}0.hsm.agents | grep -o ^uuid" \
3169 error "copytool failed to register with MDT0000"
3172 wait_copytools || error "Copytools failed to stop"
3174 local REGISTER_EVENT
3175 local UNREGISTER_EVENT
3176 while read event; do
3177 local parsed=$(parse_json_event "$event")
3178 if [ -z "$parsed" ]; then
3179 error "Copytool sent malformed event: $event"
3183 if [ $event_type == "REGISTER" ]; then
3184 REGISTER_EVENT=$event
3185 elif [ $event_type == "UNREGISTER" ]; then
3186 UNREGISTER_EVENT=$event
3188 done < <(echo $"$(get_copytool_event_log)")
3190 if [ -z "$REGISTER_EVENT" ]; then
3191 error "Copytool failed to send register event to FIFO"
3194 if [ -z "$UNREGISTER_EVENT" ]; then
3195 error "Copytool failed to send unregister event to FIFO"
3198 echo "Register/Unregister events look OK."
3200 run_test 70 "Copytool logs JSON register/unregister events to FIFO"
3203 # Bump progress interval for livelier events.
3206 # test needs a new running copytool
3207 stack_trap copytool_monitor_cleanup EXIT
3208 copytool_monitor_setup
3209 copytool setup --update-interval $interval --event-fifo \
3210 "$HSMTOOL_MONITOR_DIR/fifo"
3212 stack_trap "cdt_clear_no_retry" EXIT
3213 # Just start and stop the copytool to generate events.
3216 local f=$DIR/$tdir/$tfile
3217 local fid=$(create_small_file "$f")
3219 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f ||
3220 error "could not archive file"
3221 wait_request_state $fid ARCHIVE SUCCEED
3223 local expected_fields="event_time data_fid source_fid"
3224 expected_fields+=" total_bytes current_bytes"
3227 [ARCHIVE_START]=false
3228 [ARCHIVE_FINISH]=false
3229 [ARCHIVE_RUNNING]=false
3231 while read event; do
3232 # Make sure we're not getting anything from previous events.
3233 for field in $expected_fields; do
3237 local parsed=$(parse_json_event "$event")
3238 if [ -z "$parsed" ]; then
3239 error "Copytool sent malformed event: $event"
3243 events["$event_type"]=true
3245 [ "$event_type" != ARCHIVE_RUNNING ] && continue
3247 # Do some simple checking of the progress update events.
3248 for expected_field in $expected_fields; do
3249 if [ -z ${!expected_field+x} ]; then
3250 error "Missing $expected_field field in event"
3254 [ $total_bytes -gt 0 ] || error "Expected total_bytes to be > 0"
3256 # These should be identical throughout an archive operation
3257 [ $source_fid == $data_fid ] ||
3258 error "Expected source_fid to equal data_fid"
3259 done < <(echo $"$(get_copytool_event_log)")
3261 # Check we received every type of events we were expecting
3262 for event in "${!events[@]}"; do
3263 ${events["$event"]} ||
3264 error "Copytool failed to send '$event' event to FIFO"
3267 echo "Archive events look OK."
3269 run_test 71 "Copytool logs JSON archive events to FIFO"
3272 # Bump progress interval for livelier events.
3275 # test needs a new running copytool
3276 stack_trap copytool_monitor_cleanup EXIT
3277 copytool_monitor_setup
3278 copytool setup --update-interval $interval --event-fifo \
3279 "$HSMTOOL_MONITOR_DIR/fifo"
3280 local test_file=$HSMTOOL_MONITOR_DIR/file
3282 local cmd="dd if=/dev/urandom of=$test_file count=16 bs=1000000 "
3284 do_facet $SINGLEAGT "$cmd" ||
3285 error "cannot create $test_file on $SINGLEAGT"
3286 copy2archive $test_file $tdir/$tfile
3289 local f=$DIR/$tdir/$tfile
3290 copytool import $tdir/$tfile $f
3291 f=$DIR2/$tdir/$tfile
3292 echo "Verifying released state: "
3293 check_hsm_flags $f "0x0000000d"
3295 local fid=$(path2fid $f)
3297 wait_request_state $fid RESTORE SUCCEED
3299 local expected_fields="event_time data_fid source_fid"
3300 expected_fields+=" total_bytes current_bytes"
3304 while read event; do
3305 # Make sure we're not getting anything from previous events.
3306 for field in $expected_fields; do
3310 local parsed=$(parse_json_event "$event")
3311 if [ -z "$parsed" ]; then
3312 error "Copytool sent malformed event: $event"
3316 if [ $event_type == "RESTORE_START" ]; then
3318 if [ $source_fid != $data_fid ]; then
3319 error "source_fid should == data_fid at start"
3322 elif [ $event_type == "RESTORE_FINISH" ]; then
3324 if [ $source_fid != $data_fid ]; then
3325 error "source_fid should == data_fid at finish"
3328 elif [ $event_type != "RESTORE_RUNNING" ]; then
3332 # Do some simple checking of the progress update events.
3333 for expected_field in $expected_fields; do
3334 if [ -z ${!expected_field+x} ]; then
3335 error "Missing $expected_field field in event"
3339 if [ $total_bytes -eq 0 ]; then
3340 error "Expected total_bytes to be > 0"
3343 # When a restore starts out, the data fid is the same as the
3344 # source fid. After the restore has gotten going, we learn
3345 # the new data fid. Once the restore has finished, the source
3346 # fid is set to the new data fid.
3348 # We test this because some monitoring software may depend on
3349 # this behavior. If it changes, then the consumers of these
3350 # events may need to be modified.
3351 if [ $source_fid == $data_fid ]; then
3352 error "source_fid should != data_fid during restore"
3354 done < <(echo $"$(get_copytool_event_log)")
3356 if [ -z "$START_EVENT" ]; then
3357 error "Copytool failed to send restore start event to FIFO"
3360 if [ -z "$FINISH_EVENT" ]; then
3361 error "Copytool failed to send restore finish event to FIFO"
3364 echo "Restore events look OK."
3366 run_test 72 "Copytool logs JSON restore events to FIFO"
3369 file_count=51 # Max number of files constrained by LNET message size
3370 mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3371 local f=$DIR/$tdir/$tfile
3372 local FILELIST=/tmp/filelist.txt
3376 for i in $(seq 1 $file_count); do
3377 fid=$(copy_file /etc/hosts $f.$i)
3378 echo $f.$i >> $FILELIST
3382 # to be sure wait_all_done will not be mislead by previous tests
3384 wait_for_grace_delay
3385 $LFS hsm_archive --filelist $FILELIST ||
3386 error "cannot archive a file list"
3388 $LFS hsm_release --filelist $FILELIST ||
3389 error "cannot release a file list"
3390 $LFS hsm_restore --filelist $FILELIST ||
3391 error "cannot restore a file list"
3394 run_test 90 "Archive/restore a file list"
3396 double_verify_reset_hsm_param() {
3398 echo "Testing $HSM_PARAM.$p"
3399 local val=$(get_hsm_param $p)
3401 local val2=$(($val * 2))
3402 set_hsm_param $p $val2
3403 val=$(get_hsm_param $p)
3404 [[ $val == $val2 ]] ||
3405 error "$HSM_PARAM.$p: $val != $val2 should be (2 * $save)"
3406 echo "Set $p to 0 must failed"
3410 set_hsm_param $p $save
3412 if [[ $rc == 0 ]]; then
3413 error "we must not be able to set $HSM_PARAM.$p to 0"
3418 double_verify_reset_hsm_param loop_period
3419 double_verify_reset_hsm_param grace_delay
3420 double_verify_reset_hsm_param active_request_timeout
3421 double_verify_reset_hsm_param max_requests
3422 double_verify_reset_hsm_param default_archive_id
3424 run_test 100 "Set coordinator /proc tunables"
3431 run_test 102 "Verify coordinator control"
3434 # test needs a running copytool
3441 for i in $(seq 1 20); do
3442 fid=$(copy_file /etc/passwd $DIR/$tdir/$i)
3444 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tdir/*
3448 echo "Current requests"
3449 local res=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3450 $HSM_PARAM.actions |\
3451 grep -v CANCELED | grep -v SUCCEED | grep -v FAILED")
3453 [[ -z "$res" ]] || error "Some request have not been canceled"
3455 run_test 103 "Purge all requests"
3460 local f=$DIR/$tdir/$tfile
3461 local fid=$(create_empty_file "$f")
3463 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER --data $DATA $f
3464 local data1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3465 $HSM_PARAM.actions |\
3466 grep $fid | cut -f16 -d=")
3468 [[ "$data1" == "$DATAHEX" ]] ||
3469 error "Data field in records is ($data1) and not ($DATAHEX)"
3473 run_test 104 "Copy tool data field"
3476 local max_requests=$(get_hsm_param max_requests)
3480 stack_trap "set_hsm_param max_requests $max_requests" EXIT
3481 set_hsm_param max_requests 300
3484 for i in $(seq -w 1 10); do
3485 cp /etc/passwd $DIR/$tdir/$i
3486 $LFS hsm_archive $DIR/$tdir/$i
3488 local reqcnt1=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3489 $HSM_PARAM.actions |\
3490 grep WAITING | wc -l")
3494 local reqcnt2=$(do_facet $SINGLEMDS "$LCTL get_param -n\
3495 $HSM_PARAM.actions |\
3496 grep WAITING | wc -l")
3499 [[ "$reqcnt1" == "$reqcnt2" ]] ||
3500 error "Requests count after shutdown $reqcnt2 != "\
3501 "before shutdown $reqcnt1"
3503 run_test 105 "Restart of coordinator"
3506 # test needs a running copytool
3509 local uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3511 check_agent_registered $uuid
3513 search_copytools || error "No copytool found"
3516 wait_copytools || error "Copytool failed to stop"
3518 check_agent_unregistered $uuid
3521 uuid=$(get_agent_uuid $(facet_active_host $SINGLEAGT))
3522 check_agent_registered $uuid
3524 run_test 106 "Copytool register/unregister"
3527 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
3529 # test needs a running copytool
3531 # create and archive file
3533 local f1=$DIR/$tdir/$tfile
3534 local fid=$(copy_file /etc/passwd $f1)
3535 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
3536 wait_request_state $fid ARCHIVE SUCCEED
3537 # shutdown and restart MDS
3539 # check the copytool still gets messages from MDT
3540 local f2=$DIR/$tdir/2
3541 local fid=$(copy_file /etc/passwd $f2)
3542 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f2
3543 # main check of this sanity: this request MUST succeed
3544 wait_request_state $fid ARCHIVE SUCCEED
3546 run_test 107 "Copytool re-register after MDS restart"
3548 policy_set_and_test()
3552 do_facet $SINGLEMDS $LCTL set_param "$HSM_PARAM.policy=\\\"$change\\\""
3553 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3554 [[ "$policy" == "$target" ]] ||
3555 error "Wrong policy after '$change': '$policy' != '$target'"
3559 # to force default policy setting if error
3560 CDT_POLICY_HAD_CHANGED=true
3562 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3563 local default="NonBlockingRestore [NoRetryAction]"
3564 [[ "$policy" == "$default" ]] ||
3565 error "default policy has changed,"\
3566 " '$policy' != '$default' update the test"
3567 policy_set_and_test "+NBR" "[NonBlockingRestore] [NoRetryAction]"
3568 policy_set_and_test "+NRA" "[NonBlockingRestore] [NoRetryAction]"
3569 policy_set_and_test "-NBR" "NonBlockingRestore [NoRetryAction]"
3570 policy_set_and_test "-NRA" "NonBlockingRestore NoRetryAction"
3571 policy_set_and_test "NRA NBR" "[NonBlockingRestore] [NoRetryAction]"
3572 # useless bacause we know but safer for futur changes to use real value
3573 local policy=$(do_facet $SINGLEMDS $LCTL get_param -n $HSM_PARAM.policy)
3574 echo "Next set_param must failed"
3575 policy_set_and_test "wrong" "$policy"
3578 echo "Back to default policy"
3579 cdt_set_sanity_policy
3581 run_test 109 "Policy display/change"
3584 # test needs a running copytool
3589 copy2archive /etc/passwd $tdir/$tfile
3591 local f=$DIR/$tdir/$tfile
3592 copytool import $tdir/$tfile $f
3593 local fid=$(path2fid $f)
3595 cdt_set_non_blocking_restore
3600 wait_request_state $fid RESTORE SUCCEED
3601 cdt_clear_non_blocking_restore
3605 error "md5sum returns $st != 1, "\
3606 "should also perror ENODATA (No data available)"
3608 run_test 110a "Non blocking restore policy (import case)"
3611 # test needs a running copytool
3615 local f=$DIR/$tdir/$tfile
3616 local fid=$(copy_file /etc/passwd $f)
3617 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3618 wait_request_state $fid ARCHIVE SUCCEED
3621 cdt_set_non_blocking_restore
3626 wait_request_state $fid RESTORE SUCCEED
3627 cdt_clear_non_blocking_restore
3631 error "md5sum returns $st != 1, "\
3632 "should also perror ENODATA (No data available)"
3634 run_test 110b "Non blocking restore policy (release case)"
3637 # test needs a running copytool
3641 copy2archive /etc/passwd $tdir/$tfile
3643 local f=$DIR/$tdir/$tfile
3645 copytool import $tdir/$tfile $f
3646 local fid=$(path2fid $f)
3650 copytool_remove_backend $fid
3653 wait_request_state $fid RESTORE FAILED
3660 [[ $st == 0 ]] || error "Restore does not failed"
3662 run_test 111a "No retry policy (import case), restore will error"\
3663 " (No such file or directory)"
3666 # test needs a running copytool
3670 local f=$DIR/$tdir/$tfile
3671 local fid=$(copy_file /etc/passwd $f)
3672 stack_trap cdt_clear_no_retry EXIT
3674 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3675 wait_request_state $fid ARCHIVE SUCCEED
3678 copytool_remove_backend $fid
3681 wait_request_state $fid RESTORE FAILED
3685 [[ $st == 0 ]] || error "Restore does not failed"
3687 run_test 111b "No retry policy (release case), restore will error"\
3688 " (No such file or directory)"
3691 # test needs a running copytool
3695 local f=$DIR/$tdir/$tfile
3696 local fid=$(copy_file /etc/passwd $f)
3698 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3699 local l=$($LFS hsm_action $f)
3701 local res=$(echo $l | cut -f 2- -d" " | grep ARCHIVE)
3704 wait_request_state $fid ARCHIVE SUCCEED
3707 [[ ! -z "$res" ]] || error "action is $l which is not an ARCHIVE"
3709 run_test 112 "State of recorded request"
3712 local file1=$DIR/$tdir/$tfile
3713 local file2=$DIR2/$tdir/$tfile
3715 local fid=$(create_small_sync_file $file1)
3717 stack_trap "zconf_umount \"$(facet_host $SINGLEAGT)\" \"$MOUNT3\"" EXIT
3718 zconf_mount "$(facet_host $SINGLEAGT)" "$MOUNT3" ||
3719 error "cannot mount '$MOUNT3' on '$SINGLEAGT'"
3721 copytool setup -m "$MOUNT3"
3723 do_nodes $(comma_list $(nodes_list)) $LCTL clear
3725 $LFS hsm_archive $file1 || error "Fail to archive $file1"
3726 wait_request_state $fid ARCHIVE SUCCEED
3728 $LFS hsm_release $file1
3729 echo "Verifying released state: "
3730 check_hsm_flags $file1 "0x0000000d"
3732 multiop_bg_pause $file1 oO_WRONLY:O_APPEND:_w4c || error "multiop failed"
3735 kill -USR1 $MULTIPID
3740 local size1=$(stat -c "%s" $file1)
3741 local size2=$(stat -c "%s" $file2)
3743 [ $size1 -eq $size2 ] || error "sizes are different $size1 $size2"
3745 run_test 113 "wrong stat after restore"
3748 local f=$DIR/$tdir/$tfile
3749 local fid=$(create_empty_file "$f")
3753 # Prevent archive from completing
3756 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3757 # wait archive to register at CDT
3758 wait_request_state $fid ARCHIVE STARTED
3760 # Cancel the archive
3761 $LFS hsm_cancel "$f"
3763 wait_request_state $fid ARCHIVE CANCELED
3766 wait_request_state $fid CANCEL SUCCEED
3768 run_test 200 "Register/Cancel archive"
3771 # test needs a running copytool
3774 local f=$DIR/$tdir/$tfile
3775 create_archive_file $tdir/$tfile
3776 copytool import $tdir/$tfile $f
3777 local fid=$(path2fid $f)
3779 # test with cdt on is made in test_222
3782 # wait restore to register at CDT
3783 wait_request_state $fid RESTORE WAITING
3786 wait_request_state $fid RESTORE CANCELED
3787 wait_request_state $fid CANCEL SUCCEED
3789 run_test 201 "Register/Cancel restore"
3792 local f=$DIR/$tdir/$tfile
3793 local fid=$(create_empty_file "$f")
3795 # test needs a running copytool
3798 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3799 wait_request_state $fid ARCHIVE SUCCEED
3803 # wait remove to register at CDT
3804 wait_request_state $fid REMOVE STARTED
3807 wait_request_state $fid REMOVE CANCELED
3809 run_test 202 "Register/Cancel remove"
3811 test_220A() { # was test_220
3812 # test needs a running copytool
3817 local f=$DIR/$tdir/$tfile
3818 local fid=$(copy_file /etc/passwd $f)
3822 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3823 wait_request_state $fid ARCHIVE SUCCEED
3825 changelog_find -type HSM -target-fid $fid -flags 0x0 ||
3826 error "The expected changelog was not emitted"
3828 run_test 220A "Changelog for archive"
3831 # test needs a running copytool
3836 local f=$DIR/$tdir/$tfile
3837 local fid=$(copy_file /etc/passwd $f)
3841 # block copytool operations to allow for HSM request to be
3842 # submitted and file be unlinked (CDT will find object removed)
3845 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3847 # wait request to reach CT
3848 wait_request_state $fid ARCHIVE STARTED
3854 wait_request_state $fid ARCHIVE FAILED
3857 changelog_find -type HSM -target-fid $fid -flags 0x2 ||
3858 error "The expected changelog was not emitted"
3860 run_test 220a "Changelog for failed archive"
3863 local f=$DIR/$tdir/$tfile
3864 local fid=$(create_empty_file "$f")
3869 # Prevent archive from completing
3871 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3872 wait_request_state $fid ARCHIVE STARTED
3875 wait_request_state $fid ARCHIVE CANCELED
3878 wait_request_state $fid CANCEL SUCCEED
3880 changelog_find -type HSM -target-fid $fid -flags 0x7d ||
3881 error "The expected changelog was not emitted"
3883 run_test 221 "Changelog for archive canceled"
3886 # test needs a running copytool
3890 copy2archive /etc/passwd $tdir/$tfile
3892 local f=$DIR/$tdir/$tfile
3893 copytool import $tdir/$tfile $f
3894 local fid=$(path2fid $f)
3899 wait_request_state $fid RESTORE SUCCEED
3901 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3902 error "The expected changelog was not emitted"
3904 run_test 222a "Changelog for explicit restore"
3907 # test needs a running copytool
3911 local f=$DIR/$tdir/$tfile
3912 local fid=$(copy_file /etc/passwd $f)
3915 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3916 wait_request_state $fid ARCHIVE SUCCEED
3921 wait_request_state $fid RESTORE SUCCEED
3923 changelog_find -type HSM -target-fid $fid -flags 0x80 ||
3924 error "The expected changelog was not emitted"
3926 run_test 222b "Changelog for implicit restore"
3929 # test needs a running copytool
3933 copy2archive /etc/passwd $tdir/$tfile
3935 local f=$DIR/$tdir/$tfile
3936 copytool import $tdir/$tfile $f
3937 local fid=$(path2fid $f)
3941 # block copytool operations to allow for HSM request to be
3942 # submitted and file be unlinked (CDT will find object removed)
3947 # wait request to reach CT
3948 wait_request_state $fid RESTORE STARTED
3954 wait_request_state $fid RESTORE FAILED
3957 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3958 error "The expected changelog was not emitted"
3960 run_test 222c "Changelog for failed explicit restore"
3963 # test needs a running copytool
3967 local f=$DIR/$tdir/$tfile
3968 local fid=$(copy_file /etc/passwd $f)
3971 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
3972 wait_request_state $fid ARCHIVE SUCCEED
3975 copytool_remove_backend $fid
3978 wait_request_state $fid RESTORE FAILED
3981 changelog_find -type HSM -target-fid $fid -flags 0x82 ||
3982 error "The expected changelog was not emitted"
3984 run_test 222d "Changelog for failed implicit restore"
3987 # test needs a running copytool
3990 local f=$DIR/$tdir/$tfile
3991 create_archive_file $tdir/$tfile
3995 copytool import $tdir/$tfile $f
3996 local fid=$(path2fid $f)
3999 wait_request_state $fid RESTORE STARTED
4001 wait_request_state $fid RESTORE CANCELED
4002 wait_request_state $fid CANCEL SUCCEED
4004 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4005 error "The expected changelog was not emitted"
4007 run_test 223a "Changelog for restore canceled (import case)"
4010 local f=$DIR/$tdir/$tfile
4011 local fid=$(create_empty_file "$f")
4016 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4017 wait_request_state $fid ARCHIVE SUCCEED
4020 # Prevent restore from completing
4023 wait_request_state $fid RESTORE STARTED
4026 wait_request_state $fid RESTORE CANCELED
4029 wait_request_state $fid CANCEL SUCCEED
4031 changelog_find -type HSM -target-fid $fid -flags 0xfd ||
4032 error "The expected changelog was not emitted"
4034 run_test 223b "Changelog for restore canceled (release case)"
4036 test_224A() { # was test_224
4037 # test needs a running copytool
4042 local f=$DIR/$tdir/$tfile
4043 local fid=$(copy_file /etc/passwd $f)
4046 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4047 wait_request_state $fid ARCHIVE SUCCEED
4050 wait_request_state $fid REMOVE SUCCEED
4052 changelog_find -type HSM -target-fid $fid -flags 0x200 ||
4053 error "The expected changelog was not emitted"
4055 run_test 224A "Changelog for remove"
4058 # test needs a running copytool
4063 local f=$DIR/$tdir/$tfile
4064 local fid=$(copy_file /etc/passwd $f)
4067 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4068 wait_request_state $fid ARCHIVE SUCCEED
4070 copytool_remove_backend $fid
4072 # block copytool operations to allow for HSM request to be
4073 # submitted and file be unlinked (CDT will find object removed)
4078 # wait for request to reach CT
4079 wait_request_state $fid REMOVE STARTED
4085 wait_request_state $fid REMOVE FAILED
4087 # HE_REMOVE|ENOENT=0x202
4088 changelog_find -type HSM -target-fid $fid -flags 0x202 ||
4089 error "The expected changelog was not emitted"
4091 run_test 224a "Changelog for failed remove"
4094 # test is not usable because remove request is too fast
4095 # so it is always finished before cancel can be done ...
4096 echo "Test disabled"
4099 # test needs a running copytool
4102 local f=$DIR/$tdir/$tfile
4103 local fid=$(create_empty_file "$f")
4106 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4107 wait_request_state $fid ARCHIVE SUCCEED
4109 # Prevent restore from completing
4114 wait_request_state $fid REMOVE CANCELED
4117 wait_request_state $fid CANCEL SUCCEED
4119 changelog_find -type HSM -target-fid $fid -flags 0x27d
4120 error "The expected changelog was not emitted"
4122 run_test 225 "Changelog for remove canceled"
4125 # test needs a running copytool
4130 local f1=$DIR/$tdir/$tfile-1
4131 local f2=$DIR/$tdir/$tfile-2
4132 local f3=$DIR/$tdir/$tfile-3
4133 local fid1=$(copy_file /etc/passwd $f1)
4134 local fid2=$(copy_file /etc/passwd $f2)
4135 copy_file /etc/passwd $f3
4138 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f1
4139 wait_request_state $fid1 ARCHIVE SUCCEED
4141 $LFS hsm_archive $f2
4142 wait_request_state $fid2 ARCHIVE SUCCEED
4144 rm $f1 || error "rm $f1 failed"
4147 changelog_find -type UNLNK -target-fid $fid1 -flags 0x3 ||
4148 error "The expected changelog was not emitted"
4150 mv $f3 $f2 || error "mv $f3 $f2 failed"
4152 changelog_find -type RENME -target-fid $fid2 -flags 0x3 ||
4153 error "The expected changelog was not emitted"
4155 run_test 226 "changelog for last rm/mv with exiting archive"
4157 # This is just a utility function to clarify what test_227 does
4162 "$LFS" "$action" --$flag "$file" ||
4163 error "Cannot ${action#hsm_} $flag on '$file'"
4165 # Only one changelog should be produced
4166 local entries="$(changelog_find -type HSM -target-fid $fid)"
4167 [ $(wc -l <<< "$entries") -eq $((++count)) ] ||
4168 error "lfs $action --$flag '$file' produced more than one" \
4171 # Parse the last changelog record
4172 local entry="$(tail -n 1 <<< "$entries")"
4173 eval local -A changelog=$(changelog2array $entry)
4175 # Also check the flags match what is expected
4176 [[ ${changelog[flags]} == $target ]] ||
4177 error "Changelog flag is '${changelog[flags]}', not $target"
4181 local file="$DIR/$tdir/$tfile"
4182 local fid=$(create_empty_file "$file")
4187 for flag in norelease noarchive exists archived lost; do
4188 if [ "$flag" == lost ]; then
4189 # The flag "lost" only works on an archived file
4190 "$LFS" hsm_set --archived "$file"
4194 action="hsm_set" __test_227
4195 action="hsm_clear" __test_227
4198 run_test 227 "changelog when explicit setting of HSM flags"
4201 # test needs a running copytool
4204 local fid=$(create_small_sync_file $DIR/$tfile)
4205 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $DIR/$tfile
4206 wait_request_state $fid ARCHIVE SUCCEED
4208 $LFS hsm_release $DIR/$tfile
4209 check_hsm_flags $DIR/$tfile "0x0000000d"
4211 filefrag $DIR/$tfile | grep " 1 extent found" ||
4212 error "filefrag on released file must return only one extent"
4214 # only newer versions of cp detect sparse files by stat/FIEMAP
4216 cp --sparse=auto $DIR/$tfile $DIR/$tfile.2 ||
4217 error "copying $DIR/$tfile"
4218 cmp $DIR/$tfile $DIR/$tfile.2 || error "comparing copied $DIR/$tfile"
4220 $LFS hsm_release $DIR/$tfile
4221 check_hsm_flags $DIR/$tfile "0x0000000d"
4223 mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
4225 tar cf - --sparse $DIR/$tfile | tar xvf - -C $DIR/$tdir ||
4227 cmp $DIR/$tfile $DIR/$tdir/$DIR/$tfile ||
4228 error "comparing untarred $DIR/$tfile"
4230 rm -f $DIR/$tfile $DIR/$tfile.2 ||
4231 error "rm $DIR/$tfile or $DIR/$tfile.2 failed"
4233 run_test 228 "On released file, return extend to FIEMAP. For [cp,tar] --sparse"
4236 local file="$DIR/$tdir/$tfile"
4238 # set max_requests to allow one request of each type to be started (3)
4240 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4241 set_hsm_param max_requests 3
4244 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4245 set_hsm_param loop_period 1
4247 # send 1 requests of each kind twice
4250 for action in archive restore remove; do
4251 local filepath="$file"-to-$action
4252 local fid=$(create_empty_file "$filepath")
4253 local fid2=$(create_empty_file "$filepath".bis)
4255 if [ "$action" != archive ]; then
4256 "$LFS" hsm_archive "$filepath"
4257 wait_request_state $fid ARCHIVE SUCCEED
4258 "$LFS" hsm_archive "$filepath".bis
4259 wait_request_state $fid2 ARCHIVE SUCCEED
4261 if [ "$action" == restore ]; then
4262 "$LFS" hsm_release "$filepath"
4263 "$LFS" hsm_release "$filepath".bis
4267 # suspend the copytool to prevent requests from completing
4268 stack_trap "copytool_continue" EXIT
4271 # send `max_requests' requests (one of each kind)
4272 for action in archive restore remove; do
4273 filepath="$file"-to-$action
4274 "$LFS" hsm_${action} "$filepath"
4275 wait_request_state $(path2fid "$filepath") "${action^^}" STARTED
4278 # send another batch of requests
4279 for action in archive restore remove; do
4280 "$LFS" hsm_${action} "$file-to-$action".bis
4282 # wait for `loop_period' seconds to make sure the coordinator has time
4283 # to register those, even though it should not
4286 # only the first batch of request should be started
4288 count=$(do_facet $SINGLEMDS "$LCTL" get_param -n $HSM_PARAM.actions |
4292 error "expected 3 STARTED requests, found $count"
4294 run_test 250 "Coordinator max request"
4297 local f=$DIR/$tdir/$tfile
4298 local fid=$(create_empty_file "$f")
4301 # to have a short test
4302 local old_to=$(get_hsm_param active_request_timeout)
4303 set_hsm_param active_request_timeout 1
4304 # to be sure the cdt will wake up frequently so
4305 # it will be able to cancel the "old" request
4306 local old_loop=$(get_hsm_param loop_period)
4307 set_hsm_param loop_period 1
4312 # Prevent archive from completing
4314 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4315 wait_request_state $fid ARCHIVE STARTED
4317 # Let the request timeout
4318 wait_request_state $fid ARCHIVE CANCELED
4320 set_hsm_param active_request_timeout $old_to
4321 set_hsm_param loop_period $old_loop
4323 run_test 251 "Coordinator request timeout"
4326 local f=$DIR/$tdir/$tfile
4327 local fid=$(create_empty_file "$f")
4329 # to have a short test
4330 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4331 set_hsm_param loop_period 1
4335 # Prevent archive from completing
4337 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4338 wait_request_state $fid ARCHIVE STARTED
4341 stack_trap "set_hsm_param active_request_timeout \
4342 $(get_hsm_param active_request_timeout)" EXIT
4343 set_hsm_param active_request_timeout 1
4345 wait_request_state $fid ARCHIVE CANCELED
4348 run_test 252 "Timeout'ed running archive of a removed file should be canceled"
4352 # test needs a running copytool
4356 local f=$DIR/$tdir/$tfile
4358 dd if=/dev/zero of=$f bs=1MB count=10
4359 local fid=$(path2fid $f)
4361 $LFS hsm_archive $f || error "could not archive file"
4362 wait_request_state $fid ARCHIVE SUCCEED
4364 # clear locks to discard inode data
4365 cancel_lru_locks osc
4367 #define OBD_FAIL_MDC_MERGE 0x807
4368 $LCTL set_param fail_loc=0x807
4370 #expect error here, instead of release with wrong size
4373 if ((rc == 0)); then
4374 file_size=$(stat -c '%s' $f)
4375 if ((file_size != 10485760)); then
4376 error "Wrong file size after hsm_release"
4379 echo "could not release file"
4382 run_test 253 "Check for wrong file size after release"
4386 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4387 skip "need MDS version at least 2.10.56"
4389 # Check that the counters are initialized to 0
4391 for request_type in archive restore remove; do
4392 count="$(get_hsm_param ${request_type}_count)" ||
4393 error "Reading ${request_type}_count failed with $?"
4395 [ "$count" -eq 0 ] ||
4396 error "Expected ${request_type}_count to be " \
4400 run_test 254a "Request counters are initialized to zero"
4404 [ $MDS1_VERSION -lt $(version_code 2.10.56) ] &&
4405 skip "need MDS version at least 2.10.56"
4407 # The number of request to launch (at least 32)
4408 local request_count=$((RANDOM % 32 + 32))
4409 printf "Will launch %i requests of each type\n" "$request_count"
4411 # Launch a copytool to process requests
4414 # Set hsm.max_requests to allow starting all requests at the same time
4416 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4417 set_hsm_param max_requests "$request_count"
4421 for request_type in archive restore remove; do
4422 printf "Checking %s requests\n" "${request_type}"
4423 # Suspend the copytool to give us time to read the proc files
4426 for ((i = 0; i < $request_count; i++)); do
4427 case $request_type in
4429 create_empty_file "$DIR/$tdir/$tfile-$i" \
4433 lfs hsm_release "$DIR/$tdir/$tfile-$i"
4436 $LFS hsm_${request_type} "$DIR/$tdir/$tfile-$i"
4439 # Give the coordinator 10 seconds to start every request
4441 while get_hsm_param actions | grep -q WAITING; do
4444 [ $timeout -gt 0 ] ||
4445 error "${request_type^} requests took too " \
4449 count="$(get_hsm_param ${request_type}_count)"
4450 [ "$count" -eq "$request_count" ] ||
4451 error "Expected '$request_count' (!= '$count') " \
4452 "active $request_type requests"
4454 # Let the copytool process the requests
4456 # Give it 10 seconds maximum
4458 while get_hsm_param actions | grep -q STARTED; do
4461 [ $timeout -gt 0 ] ||
4462 error "${request_type^} requests took too " \
4466 count="$(get_hsm_param ${request_type}_count)"
4467 [ "$count" -eq 0 ] ||
4468 error "Expected 0 (!= '$count') " \
4469 "active $request_type requests"
4472 run_test 254b "Request counters are correctly incremented and decremented"
4476 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4477 skip "Need MDS version at least 2.12.0"
4479 local file="$DIR/$tdir/$tfile"
4480 local fid=$(create_empty_file "$file")
4482 # How do you make sure the coordinator has consumed any outstanding
4483 # event, without triggering an event yourself?
4485 # You wait for a request to disappear from the coordinator's llog.
4487 # Warning: the setup represents 90% of this test
4489 # Create and process an HSM request
4491 "$LFS" hsm_archive "$file"
4492 wait_request_state $fid ARCHIVE SUCCEED
4495 wait_copytools || error "failed to stop copytools"
4497 # Launch a new HSM request
4499 create_empty_file "$file"
4500 "$LFS" hsm_archive "$file"
4504 # Have the completed request be removed as soon as the cdt wakes up
4505 stack_trap "set_hsm_param grace_delay $(get_hsm_param grace_delay)" EXIT
4506 set_hsm_param grace_delay 1
4507 # (Hopefully, time on the MDS will behave nicely)
4508 do_facet $SINGLEMDS sleep 2 &
4510 # Increase `loop_period' as a mean to prevent the coordinator from
4511 # waking itself up to do some housekeeping.
4512 stack_trap "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4513 set_hsm_param loop_period 1000
4515 wait $! || error "waiting failed"
4517 wait_request_state $fid ARCHIVE ""
4518 # The coordinator will not wake up on its own for ~`loop_period' secs...
4520 # ... Unless a copytool registers. Now the real test begins
4522 wait_request_state $(path2fid "$file") ARCHIVE SUCCEED
4524 run_test 255 "Copytool registration wakes the coordinator up"
4526 # tests 260[a-c] rely on the parsing of the copytool's log file, they might
4527 # break in the future because of that.
4530 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4531 skip "need MDS version 2.11.56 or later"
4533 local -a files=("$DIR/$tdir/$tfile".{0..15})
4536 for file in "${files[@]}"; do
4537 create_small_file "$file"
4540 # Set a few hsm parameters
4542 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4543 set_hsm_param loop_period 1
4545 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4546 set_hsm_param max_requests 3
4550 "$LFS" hsm_archive "${files[0]}"
4551 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4552 "$LFS" hsm_release "${files[0]}"
4556 wait_copytools || error "copytools failed to stop"
4558 # Send several archive requests
4559 for file in "${files[@]:1}"; do
4560 "$LFS" hsm_archive "$file"
4563 # Send one restore request
4564 "$LFS" hsm_restore "${files[0]}"
4569 # Wait for all the requests to complete
4570 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4571 for file in "${files[@]:1}"; do
4572 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4575 # Collect the actions in the order in which the copytool processed them
4577 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4578 "$(copytool_logfile "$SINGLEAGT")")
4581 printf '%s\n' "${actions[@]}"
4584 for action in "${actions[@]:0:3}"; do
4585 [ "$action" == RESTORE ] && return
4588 error "Too many ARCHIVE requests were run before the RESTORE request"
4590 run_test 260a "Restore request have priority over other requests"
4592 # This test is very much tied to the implementation of the current priorisation
4593 # mechanism in the coordinator. It might not make sense to keep it in the future
4596 [ $MDS1_VERSION -lt $(version_code 2.11.56) ] &&
4597 skip "need MDS version 2.11.56 or later"
4599 local -a files=("$DIR/$tdir/$tfile".{0..15})
4602 for file in "${files[@]}"; do
4603 create_small_file "$file"
4606 # Set a few hsm parameters
4608 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4609 set_hsm_param loop_period 1
4611 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4612 set_hsm_param max_requests 3
4615 copytool setup --archive-id 2
4616 "$LFS" hsm_archive --archive 2 "${files[0]}"
4617 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4618 "$LFS" hsm_release "${files[0]}"
4622 wait_copytools || error "copytools failed to stop"
4624 # Send several archive requests
4625 for file in "${files[@]:1}"; do
4626 "$LFS" hsm_archive "$file"
4629 # Send one restore request
4630 "$LFS" hsm_restore "${files[0]}"
4634 copytool setup --archive-id 2
4636 # Wait for all the requests to complete
4637 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4638 for file in "${files[@]:1}"; do
4639 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4642 # Collect the actions in the order in which the copytool processed them
4644 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4645 "$(copytool_logfile "$SINGLEAGT")")
4648 printf '%s\n' "${actions[@]}"
4651 for action in "${actions[@]:0:3}"; do
4652 [ "$action" == RESTORE ] && return
4655 error "Too many ARCHIVE requests were run before the RESTORE request"
4657 run_test 260b "Restore request have priority over other requests"
4659 # This test is very much tied to the implementation of the current priorisation
4660 # mechanism in the coordinator. It might not make sense to keep it in the future
4663 [ $MDS1_VERSION -lt $(version_code 2.12.0) ] &&
4664 skip "Need MDS version at least 2.12.0"
4666 local -a files=("$DIR/$tdir/$tfile".{0..15})
4669 for file in "${files[@]}"; do
4670 create_small_file "$file"
4673 # Set a few hsm parameters
4675 "set_hsm_param loop_period $(get_hsm_param loop_period)" EXIT
4676 set_hsm_param loop_period 1000
4678 "set_hsm_param max_requests $(get_hsm_param max_requests)" EXIT
4679 set_hsm_param max_requests 3
4682 copytool setup --archive-id 2
4683 "$LFS" hsm_archive --archive 2 "${files[0]}"
4684 wait_request_state "$(path2fid "${files[0]}")" ARCHIVE SUCCEED
4685 "$LFS" hsm_release "${files[0]}"
4689 wait_copytools || error "copytools failed to stop"
4691 # Force the next coordinator run to do housekeeping
4695 "$LFS" hsm_archive "${files[1]}"
4699 copytool setup --archive-id 2
4701 wait_request_state "$(path2fid "${files[1]}")" ARCHIVE SUCCEED
4702 # The coordinator just did a housekeeping run it won't do another one
4703 # for around `loop_period' seconds => requests will not be reordered
4704 # if it costs too much (ie. when the coordinator has to discard a whole
4707 # Send several archive requests
4708 for file in "${files[@]:2}"; do
4709 "$LFS" hsm_archive "$file"
4712 # Send one restore request
4713 "$LFS" hsm_restore "${files[0]}"
4715 # Wait for all the requests to complete
4716 wait_request_state "$(path2fid "${files[0]}")" RESTORE SUCCEED
4717 for file in "${files[@]:2}"; do
4718 wait_request_state "$(path2fid "$file")" ARCHIVE SUCCEED
4721 # Collect the actions in the order in which the copytool processed them
4723 $(do_facet "$SINGLEAGT" grep -o '\"RESTORE\\|ARCHIVE\"' \
4724 "$(copytool_logfile "$SINGLEAGT")")
4727 printf '%s\n' "${actions[@]}"
4730 for action in "${actions[@]:0:3}"; do
4731 [ "$action" == RESTORE ] &&
4732 error "Restore requests should not be prioritised" \
4733 "unless the coordinator is doing housekeeping"
4737 run_test 260c "Requests are not reordered on the 'hot' path of the coordinator"
4740 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4742 # the only way to test ondisk conf is to restart MDS ...
4743 echo "Stop coordinator and remove coordinator state at mount"
4746 # clean on disk conf set by default
4747 cdt_clear_mount_state
4748 cdt_check_state stopped
4750 # check cdt still off after umount/remount
4752 cdt_check_state stopped
4754 echo "Set coordinator start at mount, and start coordinator"
4755 cdt_set_mount_state enabled
4758 cdt_check_state enabled
4760 # check cdt still on after umount/remount
4762 cdt_check_state enabled
4764 # we are back to original state (cdt started at mount)
4766 run_test 300 "On disk coordinator state kept between MDT umount/mount"
4769 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4771 local ai=$(get_hsm_param default_archive_id)
4772 local new=$((ai + 1))
4774 set_hsm_param default_archive_id $new -P
4776 local res=$(get_hsm_param default_archive_id)
4779 set_hsm_param default_archive_id "" "-P -d"
4781 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4783 run_test 301 "HSM tunnable are persistent"
4786 [ "$CLIENTONLY" ] && skip "CLIENTONLY mode" && return
4788 local ai=$(get_hsm_param default_archive_id)
4789 local new=$((ai + 1))
4794 set_hsm_param default_archive_id $new -P
4797 for mdtno in $(seq 1 $MDSCOUNT); do
4802 cdt_check_state enabled
4804 local res=$(get_hsm_param default_archive_id)
4807 set_hsm_param default_archive_id "" "-P -d"
4809 [[ $new == $res ]] || error "Value after MDS restart is $res != $new"
4811 run_test 302 "HSM tunnable are persistent when CDT is off"
4814 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4820 local dir_mdt0=$DIR/$tdir/mdt0
4821 local dir_mdt1=$DIR/$tdir/mdt1
4823 # create 1 dir per MDT
4824 stack_trap "rm -rf $dir_mdt0" EXIT
4825 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4826 stack_trap "rm -rf $dir_mdt1" EXIT
4827 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4829 # create 1 file in each MDT
4830 local fid1=$(create_small_file $dir_mdt0/$tfile)
4831 local fid2=$(create_small_file $dir_mdt1/$tfile)
4833 # check that hsm request on mdt0 is sent to the right MDS
4834 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4835 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4836 echo "archive successful on mdt0"
4838 # check that hsm request on mdt1 is sent to the right MDS
4839 $LFS hsm_archive $dir_mdt1/$tfile || error "lfs hsm_archive"
4840 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4841 echo "archive successful on mdt1"
4843 run_test 400 "Single request is sent to the right MDT"
4846 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4852 local dir_mdt0=$DIR/$tdir/mdt0
4853 local dir_mdt1=$DIR/$tdir/mdt1
4855 # create 1 dir per MDT
4856 stack_trap "rm -rf $dir_mdt0" EXIT
4857 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4858 stack_trap "rm -rf $dir_mdt1" EXIT
4859 $LFS mkdir -i 1 $dir_mdt1 || error "lfs mkdir"
4861 # create 1 file in each MDT
4862 local fid1=$(create_small_file $dir_mdt0/$tfile)
4863 local fid2=$(create_small_file $dir_mdt1/$tfile)
4865 # check that compound requests are shunt to the rights MDTs
4866 $LFS hsm_archive $dir_mdt0/$tfile $dir_mdt1/$tfile ||
4867 error "lfs hsm_archive"
4868 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4869 echo "archive successful on mdt0"
4870 wait_request_state $fid2 ARCHIVE SUCCEED 1 &&
4871 echo "archive successful on mdt1"
4873 run_test 401 "Compound requests split and sent to their respective MDTs"
4875 mdc_change_state() # facet, MDT_pattern, activate|deactivate
4880 local node=$(facet_active_host $facet)
4882 for mdc in $(do_facet $facet "$LCTL dl | grep -E ${pattern}-mdc" |
4883 awk '{print $4}'); do
4884 echo "$3 $mdc on $node"
4885 do_facet $facet "$LCTL --device $mdc $state" || return 1
4890 # deactivate all mdc on agent1
4891 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "deactivate"
4893 copytool setup --no-fail
4895 check_agent_unregistered "uuid" # match any agent
4897 # no expected running copytool
4898 search_copytools $agent && error "Copytool start should have failed"
4901 mdc_change_state $SINGLEAGT "$FSNAME-MDT000." "activate"
4903 run_test 402a "Copytool start fails if all MDTs are inactive"
4910 local f=$DIR/$tdir/$tfile
4911 touch $f || error "touch $f failed"
4912 local fid=$(path2fid $f)
4914 #define OBD_FAIL_MDS_HSM_CT_REGISTER_NET 0x14d
4915 do_facet $SINGLEAGT lctl set_param fail_loc=0x14d
4916 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
4918 # give time for CDT to send request and to keep it for retry
4919 wait_for_loop_period
4921 wait_request_state $fid ARCHIVE WAITING
4923 do_facet $SINGLEAGT lctl set_param fail_loc=0
4925 # request should succeed now
4926 wait_request_state $fid ARCHIVE SUCCEED
4928 run_test 402b "CDT must retry request upon slow start of CT"
4931 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4933 local agent=$(facet_active_host $SINGLEAGT)
4935 # deactivate all mdc for MDT0001
4936 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4939 local uuid=$(get_agent_uuid $agent)
4940 # check the agent is registered on MDT0000, and not on MDT0001
4941 check_agent_registered_by_mdt $uuid 0
4942 check_agent_unregistered_by_mdt $uuid 1
4944 # check running copytool process
4945 search_copytools $agent || error "No running copytools on $agent"
4947 # reactivate all mdc for MDT0001
4948 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4950 # make sure the copytool is now registered to all MDTs
4951 check_agent_registered $uuid
4953 run_test 403 "Copytool starts with inactive MDT and register on reconnect"
4956 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4960 # create files on both MDT0000 and MDT0001
4963 local dir_mdt0=$DIR/$tdir/mdt0
4964 stack_trap "rm -rf $dir_mdt0" EXIT
4965 $LFS mkdir -i 0 $dir_mdt0 || error "lfs mkdir"
4967 # create 1 file on mdt0
4968 local fid1=$(create_small_file $dir_mdt0/$tfile)
4970 # deactivate all mdc for MDT0001
4971 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "deactivate"
4973 # send an HSM request for files in MDT0000
4974 $LFS hsm_archive $dir_mdt0/$tfile || error "lfs hsm_archive"
4976 # check for completion of files in MDT0000
4977 wait_request_state $fid1 ARCHIVE SUCCEED 0 &&
4978 echo "archive successful on mdt0"
4980 # reactivate all mdc for MDT0001
4981 mdc_change_state $SINGLEAGT "$FSNAME-MDT0001" "activate"
4983 run_test 404 "Inactive MDT does not block requests for active MDTs"
4986 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4992 local striped_dir=$DIR/$tdir/striped_dir
4994 # create striped dir on all of MDTs
4995 $LFS mkdir -i 0 -c $MDSCOUNT $striped_dir || error "lfs mkdir"
4997 local fid1=$(create_small_sync_file $striped_dir/${tfile}_0)
4998 local fid2=$(create_small_sync_file $striped_dir/${tfile}_1)
4999 local fid3=$(create_small_sync_file $striped_dir/${tfile}_2)
5000 local fid4=$(create_small_sync_file $striped_dir/${tfile}_3)
5002 local idx1=$($LFS getstripe -m $striped_dir/${tfile}_0)
5003 local idx2=$($LFS getstripe -m $striped_dir/${tfile}_1)
5004 local idx3=$($LFS getstripe -m $striped_dir/${tfile}_2)
5005 local idx4=$($LFS getstripe -m $striped_dir/${tfile}_3)
5007 # check that compound requests are shunt to the rights MDTs
5008 $LFS hsm_archive $striped_dir/${tfile}_0 $striped_dir/${tfile}_1 \
5009 $striped_dir/${tfile}_2 $striped_dir/${tfile}_3 ||
5010 error "lfs hsm_archive"
5012 wait_request_state $fid1 ARCHIVE SUCCEED $idx1 &&
5013 echo "archive successful on $fid1"
5014 wait_request_state $fid2 ARCHIVE SUCCEED $idx2 &&
5015 echo "archive successful on $fid2"
5016 wait_request_state $fid3 ARCHIVE SUCCEED $idx3 &&
5017 echo "archive successful on $fid3"
5018 wait_request_state $fid4 ARCHIVE SUCCEED $idx4 &&
5019 echo "archive successful on $fid4"
5021 $LFS hsm_release $striped_dir/${tfile}_0 || error "lfs hsm_release 1"
5022 $LFS hsm_release $striped_dir/${tfile}_1 || error "lfs hsm_release 2"
5023 $LFS hsm_release $striped_dir/${tfile}_2 || error "lfs hsm_release 3"
5024 $LFS hsm_release $striped_dir/${tfile}_3 || error "lfs hsm_release 4"
5026 cat $striped_dir/${tfile}_0 > /dev/null || error "cat ${tfile}_0 failed"
5027 cat $striped_dir/${tfile}_1 > /dev/null || error "cat ${tfile}_1 failed"
5028 cat $striped_dir/${tfile}_2 > /dev/null || error "cat ${tfile}_2 failed"
5029 cat $striped_dir/${tfile}_3 > /dev/null || error "cat ${tfile}_3 failed"
5031 run_test 405 "archive and release under striped directory"
5034 [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
5036 [ $MDS1_VERSION -lt $(version_code 2.7.64) ] &&
5037 skip "need MDS version at least 2.7.64"
5042 fid=$(create_small_file $DIR/$tdir/$tfile)
5047 $LFS hsm_archive $DIR/$tdir/$tfile
5048 wait_request_state "$fid" ARCHIVE SUCCEED
5049 $LFS hsm_release $DIR/$tdir/$tfile
5051 # Should migrate $tdir but not $tfile.
5052 $LFS migrate -m1 $DIR/$tdir &&
5053 error "migrating HSM an archived file should fail"
5055 $LFS hsm_restore $DIR/$tdir/$tfile
5056 wait_request_state "$fid" RESTORE SUCCEED
5058 $LFS hsm_remove $DIR/$tdir/$tfile
5059 wait_request_state "$fid" REMOVE SUCCEED
5061 cat $DIR/$tdir/$tfile > /dev/null ||
5062 error "cannot read $DIR/$tdir/$tfile"
5064 $LFS migrate -m1 $DIR/$tdir ||
5065 error "cannot complete migration after HSM remove"
5067 mdt_index=$($LFS getstripe -m $DIR/$tdir)
5068 if ((mdt_index != 1)); then
5069 error "expected MDT index 1, got $mdt_index"
5072 # Refresh fid after migration.
5073 fid=$(path2fid $DIR/$tdir/$tfile)
5076 $LFS hsm_archive $DIR/$tdir/$tfile
5077 wait_request_state "$fid" ARCHIVE SUCCEED 1
5079 lctl set_param debug=+trace
5080 $LFS hsm_release $DIR/$tdir/$tfile ||
5081 error "cannot release $DIR/$tdir/$tfile"
5083 $LFS hsm_restore $DIR/$tdir/$tfile
5084 wait_request_state "$fid" RESTORE SUCCEED 1
5086 cat $DIR/$tdir/$tfile > /dev/null ||
5087 error "cannot read $DIR/$tdir/$tfile"
5089 run_test 406 "attempting to migrate HSM archived files is safe"
5092 local f=$DIR/$tdir/$tfile
5093 local f2=$DIR2/$tdir/$tfile
5094 local fid=$(create_empty_file "$f")
5098 $LFS hsm_archive --archive $HSM_ARCHIVE_NUMBER $f
5099 wait_request_state $fid ARCHIVE SUCCEED
5102 #define OBD_FAIL_MDS_HSM_CDT_DELAY 0x164
5103 do_facet $SINGLEMDS $LCTL set_param fail_val=5 fail_loc=0x164
5105 # Prevent restore from completing
5109 # 1st request holds layout lock while appropriate
5110 # RESTORE record is still not added to llog
5114 # after umount hsm_actions->O/x/x log shouldn't have
5115 # double RESTORE records like below
5116 #[0x200000401:0x1:0x0]...0x58d03a0d/0x58d03a0c action=RESTORE...WAITING
5117 #[0x200000401:0x1:0x0]...0x58d03a0c/0x58d03a0d action=RESTORE...WAITING
5119 do_facet $SINGLEMDS "$LCTL get_param $HSM_PARAM.actions"&
5123 wait_request_state $fid RESTORE SUCCEED
5125 run_test 407 "Check for double RESTORE records in llog"
5129 [ $MDS1_VERSION -lt $(version_code 2.6.92) ] &&
5130 skip "HSM migrate is not supported"
5132 test_mkdir -p $DIR/$tdir
5134 if [ $(lustre_version_code client) -lt $(version_code 2.11.56) ] ||
5135 [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ];
5137 llapi_hsm_test -d $DIR/$tdir -b ||
5138 error "One llapi HSM test failed"
5140 llapi_hsm_test -d $DIR/$tdir ||
5141 error "One llapi HSM test failed"
5144 run_test 500 "various LLAPI HSM tests"
5147 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5148 skip "need MDS version at least 2.10.58"
5152 local f=$DIR/$tdir/$tfile
5155 # set changelog_mask to ALL
5156 changelog_chmask "ALL"
5158 chmod 777 $DIR/$tdir
5159 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5160 local fid=$(path2fid $f)
5163 entry=$(changelog_find -type CREAT -target-fid $fid -uid "$RUNAS_ID" \
5164 -gid "$RUNAS_GID") ||
5165 error "No matching CREAT entry"
5167 # Parse the changelog
5168 eval local -A changelog=$(changelog2array $entry)
5169 local nid="${changelog[nid]}"
5172 echo "Got NID '$nid'"
5173 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5174 error "nid '$nid' does not match any client NID:" \
5177 run_test 600 "Changelog fields 'u=' and 'nid='"
5180 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5181 skip "need MDS version at least 2.10.58"
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)
5195 cat $f || error "cat $f failed"
5197 changelog_find -type OPEN -target-fid $fid -mode "r--" ||
5198 error "No matching OPEN entry"
5200 run_test 601 "OPEN Changelog entry"
5203 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5204 skip "need MDS version at least 2.10.58"
5208 local f=$DIR/$tdir/$tfile
5211 # set changelog_mask to ALL
5212 changelog_chmask "ALL"
5214 touch $f || error "touch $f failed"
5215 local fid=$(path2fid $f)
5218 cat $f || error "cat $f failed"
5220 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5224 echo f > $f || error "write $f failed"
5227 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5229 # remove OPEN from changelog_mask
5230 changelog_chmask "-OPEN"
5234 cat $f || error "cat $f failed"
5237 changelog_find -type CLOSE -target-fid $fid &&
5238 error "There should be no CLOSE entry"
5242 echo f > $f || error "write $f failed"
5245 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5247 run_test 602 "Changelog record CLOSE only if open+write or OPEN recorded"
5250 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5251 skip "need MDS version at least 2.10.58"
5255 local f=$DIR/$tdir/$tfile
5258 # set changelog_mask to ALL
5259 changelog_chmask "ALL"
5261 touch $f || error "touch $f failed"
5262 local fid=$(path2fid $f)
5264 setfattr -n user.xattr1 -v "value1" $f || error "setfattr $f failed"
5267 getfattr -n user.xattr1 $f || error "getfattr $f failed"
5269 changelog_find -type GXATR -target-fid $fid -xattr "user.xattr1" ||
5270 error "No matching GXATR entry"
5272 run_test 603 "GETXATTR Changelog entry"
5275 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5276 skip "need MDS version at least 2.10.58"
5280 local f=$DIR/$tdir/$tfile
5281 local f2=$DIR2/$tdir/$tfile
5282 local procname="mdd.$FSNAME-MDT0000.changelog_deniednext"
5284 timeout="$(do_facet mds1 "$LCTL" get_param -n "$procname")"
5285 stack_trap "do_facet mds1 '$LCTL' set_param '$procname=$timeout'" EXIT
5286 do_facet mds1 lctl set_param "$procname=20"
5290 # set changelog_mask to ALL
5291 changelog_chmask "ALL"
5293 touch $f || error "touch $f failed"
5294 local fid=$(path2fid $f)
5300 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5304 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5305 -gid "$RUNAS_GID" -mode "r--") ||
5306 error "No matching NOPEN entry"
5308 # Parse the changelog
5309 eval local -A changelog=$(changelog2array $entry)
5310 local nid="${changelog[nid]}"
5313 echo "Got NID '$nid'"
5314 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5315 error "nid '$nid' does not match any client NID:" \
5320 $RUNAS cat $f2 && error "cat $f2 by user $RUNAS_ID should have failed"
5323 changelog_find -type NOPEN -target-fid $fid &&
5324 error "There should be no NOPEN entry"
5326 # Sleep for `changelog_deniednext` seconds
5331 $RUNAS cat $f2 && error "cat $f by user $RUNAS_ID should have failed"
5334 entry=$(changelog_find -type NOPEN -target-fid $fid -uid "$RUNAS_ID" \
5335 -gid "$RUNAS_GID" -mode "r--") ||
5336 error "No matching NOPEN entry"
5338 # Parse the changelog
5339 eval local -A changelog=$(changelog2array $entry)
5340 local nid="${changelog[nid]}"
5343 echo "Got NID '$nid'"
5344 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5345 error "nid '$nid' does not match any client NID:" \
5348 run_test 604 "NOPEN Changelog entry"
5351 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5352 skip "need MDS version at least 2.10.58"
5356 local f=$DIR/$tdir/$tfile
5357 local f2=$DIR2/$tdir/$tfile
5360 # set changelog_mask to ALL
5361 changelog_chmask "ALL"
5363 touch $f || error "touch $f failed"
5364 local fid=$(path2fid $f)
5368 exec 3<> $f || error "open $f failed"
5372 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5376 exec 4<> $f || error "open $f failed"
5379 changelog_find -type OPEN -target-fid $fid &&
5380 error "There should be no OPEN entry"
5382 exec 4>&- || error "close $f failed"
5385 changelog_find -type CLOSE -target-fid $fid &&
5386 error "There should be no CLOSE entry"
5390 # access in rw, so different access mode should generate entries
5391 cat $f || error "cat $f failed"
5394 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5396 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5400 # same access as first one, should not generate new entries
5401 exec 4<> $f || error "open $f failed"
5404 changelog_find -type OPEN -target-fid $fid &&
5405 error "There should be no OPEN entry"
5407 exec 4>&- || error "close $f failed"
5410 changelog_find -type CLOSE -target-fid $fid &&
5411 error "There should be no CLOSE entry"
5415 # access by different user should generate new entries
5416 $RUNAS cat $f || error "cat $f by user $RUNAS_ID failed"
5419 changelog_find -type OPEN -target-fid $fid || error "No OPEN entry"
5421 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5425 exec 3>&- || error "close $f failed"
5428 changelog_find -type CLOSE -target-fid $fid || error "No CLOSE entry"
5430 run_test 605 "Test OPEN and CLOSE rate limit in Changelogs"
5433 [ $MDS1_VERSION -lt $(version_code 2.10.58) ] &&
5434 skip "need MDS version at least 2.10.58"
5436 local llog_reader=$(do_facet mgs "which llog_reader 2> /dev/null")
5437 llog_reader=${llog_reader:-$LUSTRE/utils/llog_reader}
5438 [ -z $(do_facet mgs ls -d $llog_reader 2> /dev/null) ] &&
5439 skip_env "missing llog_reader" && return
5440 local fstype=$(facet_fstype mds1)
5444 local f=$DIR/$tdir/$tfile
5447 # set changelog_mask to ALL
5448 changelog_chmask "ALL"
5450 chmod 777 $DIR/$tdir
5451 $RUNAS touch $f || error "touch $f failed as $RUNAS_ID"
5452 local fid=$(path2fid $f)
5453 rm $f || error "rm $f failed"
5455 local mntpt=$(facet_mntpt mds1)
5459 #remount mds1 as ldiskfs or zfs type
5460 stack_trap "stop mds1; start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS" EXIT
5461 stop mds1 || error "stop mds1 failed"
5462 mount_fstype mds1 || error "remount mds1 failed"
5464 for ((i = 0; i < 1; i++)); do
5465 do_facet mds1 $llog_reader $mntpt/changelog_catalog
5466 local cat_file=$(do_facet mds1 $llog_reader \
5467 $mntpt/changelog_catalog | awk \
5468 '{match($0,"path=([^ ]+)",a)}END{print a[1]}')
5469 [ -n "$cat_file" ] || error "no catalog file"
5471 entry=$(do_facet mds1 $llog_reader $mntpt/$cat_file |
5472 awk "/CREAT/ && /target:\[$fid\]/ {print}")
5473 [ -n "$entry" ] || error "no CREAT entry"
5476 local uidgid=$(echo $entry |
5477 sed 's+.*\ user:\([0-9][0-9]*:[0-9][0-9]*\)\ .*+\1+')
5478 [ -n "$uidgid" ] || error "uidgid is empty"
5479 echo "Got UID/GID $uidgid"
5480 [ "$uidgid" = "$RUNAS_ID:$RUNAS_GID" ] ||
5481 error "uidgid '$uidgid' != '$RUNAS_ID:$RUNAS_GID'"
5482 local nid=$(echo $entry |
5483 sed 's+.*\ nid:\(\S\S*@\S\S*\)\ .*+\1+')
5484 [ -n "$nid" ] || error "nid is empty"
5486 [ -n "$nid" ] && [[ "${CLIENT_NIDS[*]}" =~ $nid ]] ||
5487 error "nid '$nid' does not match any NID ${CLIENT_NIDS[@]}"
5489 run_test 606 "llog_reader groks changelog fields"
5492 check_and_cleanup_lustre